lr10  2.1.0.0
lr10.h
Go to the documentation of this file.
1 /****************************************************************************
2 ** Copyright (C) 2020 MikroElektronika d.o.o.
3 ** Contact: https://www.mikroe.com/contact
4 **
5 ** Permission is hereby granted, free of charge, to any person obtaining a copy
6 ** of this software and associated documentation files (the "Software"), to deal
7 ** in the Software without restriction, including without limitation the rights
8 ** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 ** copies of the Software, and to permit persons to whom the Software is
10 ** furnished to do so, subject to the following conditions:
11 ** The above copyright notice and this permission notice shall be
12 ** included in all copies or substantial portions of the Software.
13 **
14 ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16 ** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17 ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 ** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19 ** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20 ** USE OR OTHER DEALINGS IN THE SOFTWARE.
21 ****************************************************************************/
22 
28 #ifndef LR10_H
29 #define LR10_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
39 #ifdef PREINIT_SUPPORTED
40 #include "preinit.h"
41 #endif
42 
43 #ifdef MikroCCoreVersion
44  #if MikroCCoreVersion >= 1
45  #include "delays.h"
46  #endif
47 #endif
48 
49 #include "drv_digital_out.h"
50 #include "drv_digital_in.h"
51 #include "drv_uart.h"
52 
73 #define LR10_CMD_AT "AT"
74 #define LR10_CMD_FDEFAULT "FDEFAULT"
75 #define LR10_CMD_RESET "RESET"
76 #define LR10_CMD_LOWPOWER "LOWPOWER"
77 #define LR10_CMD_VER "VER"
78 #define LR10_CMD_MSG "MSG"
79 #define LR10_CMD_MSGHEX "MSGHEX"
80 #define LR10_CMD_CMSG "CMSG"
81 #define LR10_CMD_CMSGHEX "CMSGHEX"
82 #define LR10_CMD_PMSG "PMSG"
83 #define LR10_CMD_PMSGHEX "PMSGHEX"
84 #define LR10_CMD_CH "CH"
85 #define LR10_CMD_DR "DR"
86 #define LR10_CMD_ADR "ADR"
87 #define LR10_CMD_REPT "REPT"
88 #define LR10_CMD_RETRY "RETRY"
89 #define LR10_CMD_POWER "POWER"
90 #define LR10_CMD_RXWIN2 "RXWIN2"
91 #define LR10_CMD_RXWIN1 "RXWIN1"
92 #define LR10_CMD_PORT "PORT"
93 #define LR10_CMD_MODE "MODE"
94 #define LR10_CMD_ID "ID"
95 #define LR10_CMD_KEY "KEY"
96 #define LR10_CMD_CLASS "CLASS"
97 #define LR10_CMD_JOIN "JOIN"
98 #define LR10_CMD_LW "LW"
99 #define LR10_CMD_BEACON "BEACON"
100 #define LR10_CMD_TEST "TEST"
101 #define LR10_CMD_UART "UART"
102 #define LR10_CMD_DELAY "DELAY"
103 #define LR10_CMD_VDD "VDD"
104 #define LR10_CMD_RTC "RTC"
105 #define LR10_CMD_EEPROM "EEPROM"
106 #define LR10_CMD_WDT "WDT"
107 #define LR10_CMD_TEMP "TEMP"
108 #define LR10_CMD_LOG "LOG"
109 
114 #define LR10_SUB_CMD_ID_DEVADDR "DEVADDR"
115 #define LR10_SUB_CMD_ID_DEVEUI "DEVEUI"
116 #define LR10_SUB_CMD_ID_APPEUI "APPEUI"
117 #define LR10_SUB_CMD_CH_NUM "NUM"
118 #define LR10_SUB_CMD_KEY_NWKSKEY "NWKSKEY"
119 #define LR10_SUB_CMD_KEY_APPSKEY "APPSKEY"
120 #define LR10_SUB_CMD_MODE_TEST "TEST"
121 #define LR10_SUB_CMD_MODE_LWOTAA "LWOTAA"
122 #define LR10_SUB_CMD_MODE_LWABP "LWABP"
123 #define LR10_SUB_CMD_JOIN_FORCE "FORCE"
124 #define LR10_SUB_CMD_JOIN_AUTO "AUTO"
125 #define LR10_SUB_CMD_BEACON_DMMUL "DMMUL"
126 #define LR10_SUB_CMD_BEACON_INFO "INFO"
127 #define LR10_SUB_CMD_BEACON_GWGPS "GWGPS"
128 #define LR10_SUB_CMD_DELAY_RX1 "RX1"
129 #define LR10_SUB_CMD_DELAY_RX2 "RX2"
130 #define LR10_SUB_CMD_DELAY_JRX1 "JRX1"
131 #define LR10_SUB_CMD_DELAY_JRX2 "JRX2"
132 #define LR10_SUB_CMD_LW_CDR "CDR"
133 #define LR10_SUB_CMD_LW_ULDL "ULDL"
134 #define LR10_SUB_CMD_LW_DC "DC"
135 #define LR10_SUB_CMD_LW_NET "NET"
136 #define LR10_SUB_CMD_LW_MC "MC"
137 #define LR10_SUB_CMD_LW_THLD "THLD"
138 #define LR10_SUB_CMD_LW_BAT "BAT"
139 #define LR10_SUB_CMD_LW_TPS "TPS"
140 #define LR10_SUB_CMD_LW_SCR "SCR"
141 #define LR10_SUB_CMD_LW_JDC "JDC"
142 #define LR10_SUB_CMD_LW_CT "CT"
143 #define LR10_SUB_CMD_LW_LEN "LEN"
144 #define LR10_SUB_CMD_LW_VER "VER"
145 #define LR10_SUB_CMD_LW_DTR "DTR"
146 #define LR10_SUB_CMD_LW_LCR "LCR"
147 #define LR10_SUB_CMD_LW_LDRO "LDRO"
148 #define LR10_SUB_CMD_LW_DCMRX "DCMRX"
149 #define LR10_SUB_CMD_LW_DUMRX "DUMRX"
150 #define LR10_SUB_CMD_LW_AFPACK "AFPACK"
151 #define LR10_SUB_CMD_LW_CHRB "CHRB"
152 #define LR10_SUB_CMD_RTC_ZONE "ZONE"
153 #define LR10_SUB_CMD_RTC_FULL "FULL"
154 #define LR10_SUB_CMD_RTC_LEAPSEC "LEAPSEC"
155 #define LR10_SUB_CMD_RTC_UTCMS "UTCMS"
156 #define LR10_SUB_CMD_EEPROM_ADDR "ADDR"
157 #define LR10_SUB_CMD_UART_TIMEOUT "TIMEOUT"
158 #define LR10_SUB_CMD_UART_BR "BR"
159 #define LR10_SUB_CMD_TEST_STOP "STOP"
160 #define LR10_SUB_CMD_TEST_HELP "HELP"
161 #define LR10_SUB_CMD_TEST_TXCW "TXCW"
162 #define LR10_SUB_CMD_TEST_TXCLORA "TXCLORA"
163 #define LR10_SUB_CMD_TEST_RFCFG "RFCFG"
164 #define LR10_SUB_CMD_TEST_RX "RXLRPKT"
165 #define LR10_SUB_CMD_TEST_TX_HEX "TXLRPKT"
166 #define LR10_SUB_CMD_TEST_TX_STR "TXLRSTR"
167 #define LR10_SUB_CMD_TEST_RSSI "RSSI"
168 #define LR10_SUB_CMD_LOG_DEBUG "DEBUG"
169 #define LR10_SUB_CMD_LOG_QUIET "QUIET"
170 
175 #define LR10_SYMBOL_END_CMD "\r\n"
176 #define LR10_SYMBOL_QUERY "?"
177 #define LR10_SYMBOL_SET_VAL_CMD "="
178 #define LR10_SYMBOL_PREFIX_CMD "+"
179 #define LR10_SYMBOL_SEPARATOR ","
180 #define LR10_SYMBOL_SPACE " "
181 #define LR10_SYMBOL_NULL ""
182 #define LR10_SYMBOL_QUOTE "\""
183 #define LR10_ASCII_SPACE 0x20
184 #define LR10_ASCII_QUOTE 0x22
185 
186 
192 #define LR10_TX_DRV_BUFFER_SIZE 100
193 #define LR10_RX_DRV_BUFFER_SIZE 300
194  // lr10_cmd
196 
211 #define LR10_MAP_MIKROBUS( cfg, mikrobus ) \
212  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
213  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
214  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST )
215  // lr10_map // lr10
218 
223 typedef struct
224 {
225  // Output pins
226  digital_out_t rst;
228  // Modules
229  uart_t uart;
231  // Buffers
232  uint8_t uart_rx_buffer[ LR10_RX_DRV_BUFFER_SIZE ];
233  uint8_t uart_tx_buffer[ LR10_TX_DRV_BUFFER_SIZE ];
235 } lr10_t;
236 
241 typedef struct
242 {
243  // Communication gpio pins
244  pin_name_t rx_pin;
245  pin_name_t tx_pin;
247  // Additional gpio pins
248  pin_name_t rst;
250  // Static variable
251  uint32_t baud_rate;
253  uart_data_bits_t data_bit;
254  uart_parity_t parity_bit;
255  uart_stop_bits_t stop_bit;
257 } lr10_cfg_t;
258 
263 typedef enum
264 {
265  LR10_OK = 0,
266  LR10_ERROR = -1
267 
269 
274 typedef enum
275 {
278 
280 
297 
311 err_t lr10_init ( lr10_t *ctx, lr10_cfg_t *cfg );
312 
321 void lr10_hw_reset ( lr10_t *ctx );
322 
335 err_t lr10_generic_write ( lr10_t *ctx, uint8_t *data_in, uint16_t len );
336 
349 err_t lr10_generic_read ( lr10_t *ctx, uint8_t *data_out, uint16_t len );
350 
362 err_t lr10_write_cmd ( lr10_t *ctx, uint8_t *command );
363 
376 err_t lr10_write_cmd_param ( lr10_t *ctx, uint8_t *command, uint8_t *param );
377 
394 err_t lr10_write_cmd_sub_param ( lr10_t *ctx, uint8_t *command, uint8_t *sub_param,
395  uint8_t *param, lr10_en_quote_t en_quote );
396 
408 err_t lr10_inquire_cmd ( lr10_t *ctx, uint8_t *command );
409 
410 
411 #ifdef __cplusplus
412 }
413 #endif
414 #endif // LR10_H
415  // lr10
417 
418 // ------------------------------------------------------------------------ END
lr10_cfg_setup
void lr10_cfg_setup(lr10_cfg_t *cfg)
LR 10 configuration object setup function.
lr10_cfg_t::rst
pin_name_t rst
Definition: lr10.h:248
lr10_hw_reset
void lr10_hw_reset(lr10_t *ctx)
LR 10 HW reset function.
lr10_init
err_t lr10_init(lr10_t *ctx, lr10_cfg_t *cfg)
LR 10 initialization function.
lr10_write_cmd_sub_param
err_t lr10_write_cmd_sub_param(lr10_t *ctx, uint8_t *command, uint8_t *sub_param, uint8_t *param, lr10_en_quote_t en_quote)
LR 10 command - subcommands - parameter writing function.
lr10_write_cmd
err_t lr10_write_cmd(lr10_t *ctx, uint8_t *command)
LR 10 command writing function.
lr10_en_quote_t
lr10_en_quote_t
LR 10 Click enable quote value data.
Definition: lr10.h:275
lr10_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: lr10.h:255
lr10_cfg_t::rx_pin
pin_name_t rx_pin
Definition: lr10.h:244
lr10_inquire_cmd
err_t lr10_inquire_cmd(lr10_t *ctx, uint8_t *command)
LR 10 inquire command function.
lr10_cfg_t
LR 10 Click configuration object.
Definition: lr10.h:242
lr10_cfg_t::baud_rate
uint32_t baud_rate
Definition: lr10.h:251
lr10_generic_read
err_t lr10_generic_read(lr10_t *ctx, uint8_t *data_out, uint16_t len)
LR 10 data reading function.
lr10_generic_write
err_t lr10_generic_write(lr10_t *ctx, uint8_t *data_in, uint16_t len)
LR 10 data writing function.
lr10_t
LR 10 Click context object.
Definition: lr10.h:224
lr10_return_value_t
lr10_return_value_t
LR 10 Click return value data.
Definition: lr10.h:264
lr10_write_cmd_param
err_t lr10_write_cmd_param(lr10_t *ctx, uint8_t *command, uint8_t *param)
LR 10 command - parameter writing function.
lr10_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: lr10.h:254
LR10_TX_DRV_BUFFER_SIZE
#define LR10_TX_DRV_BUFFER_SIZE
LR 10 driver buffer size.
Definition: lr10.h:192
LR10_RX_DRV_BUFFER_SIZE
#define LR10_RX_DRV_BUFFER_SIZE
Definition: lr10.h:193
lr10_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: lr10.h:253
lr10_cfg_t::uart_blocking
bool uart_blocking
Definition: lr10.h:252
LR10_ERROR
@ LR10_ERROR
Definition: lr10.h:266
lr10_cfg_t::tx_pin
pin_name_t tx_pin
Definition: lr10.h:245
LR10_OK
@ LR10_OK
Definition: lr10.h:265
lr10_t::uart
uart_t uart
Definition: lr10.h:229
LR10_QUOTE_ENABLE
@ LR10_QUOTE_ENABLE
Definition: lr10.h:277
lr10_t::rst
digital_out_t rst
Definition: lr10.h:226
LR10_QUOTE_DISABLE
@ LR10_QUOTE_DISABLE
Definition: lr10.h:276