lr9  2.1.0.0
lr9.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 LR9_H
29 #define LR9_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 LR9_CMD_AT "AT"
74 
79 #define LR9_CMD_CGMI "CGMI"
80 #define LR9_CMD_CGMM "CGMM"
81 #define LR9_CMD_CGMR "CGMR"
82 #define LR9_CMD_CGSN "CGSN"
83 #define LR9_CMD_CGBR "CGBR"
84 
89 #define LR9_CMD_CJOINMODE "CJOINMODE"
90 #define LR9_CMD_CDEVEUI "CDEVEUI"
91 #define LR9_CMD_CAPPEUI "CAPPEUI"
92 #define LR9_CMD_CAPPKEY "CAPPKEY"
93 #define LR9_CMD_CDEVADDR "CDEVADDR"
94 #define LR9_CMD_CAPPSKEY "CAPPSKEY"
95 #define LR9_CMD_CNWKSKEY "CNWKSKEY"
96 #define LR9_CMD_CFREQBANDMASK "CFREQBANDMASK"
97 #define LR9_CMD_CULDLMODE "CULDLMODE"
98 #define LR9_CMD_CADDMUTICAST "CADDMUTICAST"
99 #define LR9_CMD_CDELMUTICAST "CDELMUTICAST"
100 #define LR9_CMD_CNUMMUTICAST "CNUMMUTICAST"
101 #define LR9_CMD_CWORKMODE "CWORKMODE"
102 #define LR9_CMD_CCLASS "CCLASS"
103 #define LR9_CMD_CBL "CBL"
104 #define LR9_CMD_CSTATUS "CSTATUS"
105 #define LR9_CMD_CJOIN "CJOIN"
106 #define LR9_CMD_CPINGSLOTINFOREQ "CPINGSLOTINFOREQ"
107 #define LR9_CMD_DTRX "DTRX"
108 #define LR9_CMD_DRX "DRX"
109 
114 #define LR9_CMD_CCONFIRM "CCONFIRM"
115 #define LR9_CMD_CAPPPORT "CAPPPORT"
116 #define LR9_CMD_CDATARATE "CDATARATE"
117 #define LR9_CMD_CRSSI "CRSSI"
118 #define LR9_CMD_CNBTRIALS "CNBTRIALS"
119 #define LR9_CMD_CRM "CRM"
120 #define LR9_CMD_CTXP "CTXP"
121 #define LR9_CMD_CLINKCHECK "CLINKCHECK"
122 #define LR9_CMD_CADR "CADR"
123 #define LR9_CMD_CRXP "CRXP"
124 #define LR9_CMD_CRX1DELAY "CRX1DELAY"
125 #define LR9_CMD_CSAVE "CSAVE"
126 #define LR9_CMD_CRESTORE "CRESTORE"
127 
132 #define LR9_CMD_IREBOOT "IREBOOT"
133 #define LR9_CMD_ILOGLVL "ILOGLVL"
134 
139 #define LR9_CMD_CKEYSPROTECT "CKEYSPROTECT"
140 
145 #define LR9_CMD_CTXADDRSET "CTXADDRSET"
146 #define LR9_CMD_CADDRSET "CADDRSET"
147 #define LR9_CMD_CTX "CTX"
148 #define LR9_CMD_CRX "CRX"
149 #define LR9_CMD_CRXS "CRXS"
150 
155 #define LR9_DTRX_CONFIG "0"
156 #define LR9_DTRX_UNCONFIG "1"
157 
162 #define LR9_DTRX_CONFIG_DATA 0
163 #define LR9_DTRX_UNCONFIG_DATA 1
164 #define LR9_NB_TRIALS_MIN 1
165 #define LR9_NB_TRIALS_2 2
166 #define LR9_NB_TRIALS_MAX 15
167 #define LR9_DATA_FRAME_MAX 10
168 #define LR9_MSG_START_POS 16
169 
174 #define LR9_SYMBOL_END_CMD "\r\n"
175 #define LR9_SYMBOL_QUERY "?"
176 #define LR9_SYMBOL_SET_VAL_CMD "="
177 #define LR9_SYMBOL_PREFIX_CMD "+"
178 #define LR9_SYMBOL_SEPARATOR ","
179 #define LR9_SYMBOL_SPACE " "
180 #define LR9_SYMBOL_NULL ""
181 #define LR9_SYMBOL_QUOTE "\""
182 #define LR9_ASCII_SPACE 0x20
183 #define LR9_ASCII_QUOTE 0x22
184 
190 #define LR9_TX_DRV_BUFFER_SIZE 100
191 #define LR9_RX_DRV_BUFFER_SIZE 300
192  // lr9_cmd
194 
209 #define LR9_MAP_MIKROBUS( cfg, mikrobus ) \
210  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
211  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
212  cfg.bt = MIKROBUS( mikrobus, MIKROBUS_AN ); \
213  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST )
214  // lr9_map // lr9
217 
222 typedef struct
223 {
224  // Output pins
225  digital_out_t bt;
226  digital_out_t rst;
228  // Modules
229  uart_t uart;
231  // Buffers
232  uint8_t uart_rx_buffer[ LR9_RX_DRV_BUFFER_SIZE ];
233  uint8_t uart_tx_buffer[ LR9_TX_DRV_BUFFER_SIZE ];
235 } lr9_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 bt;
249  pin_name_t rst;
251  // Static variable
252  uint32_t baud_rate;
254  uart_data_bits_t data_bit;
255  uart_parity_t parity_bit;
256  uart_stop_bits_t stop_bit;
258 } lr9_cfg_t;
259 
264 typedef enum
265 {
266  LR9_OK = 0,
267  LR9_ERROR = -1
268 
270 
275 typedef enum
276 {
279 
281 
297 void lr9_cfg_setup ( lr9_cfg_t *cfg );
298 
312 err_t lr9_init ( lr9_t *ctx, lr9_cfg_t *cfg );
313 
322 void lr9_hw_reset ( lr9_t *ctx );
323 
333 void lr9_set_boot_pin ( lr9_t *ctx, uint8_t state );
334 
347 err_t lr9_generic_write ( lr9_t *ctx, uint8_t *data_in, uint16_t len );
348 
361 err_t lr9_generic_read ( lr9_t *ctx, uint8_t *data_out, uint16_t len );
362 
375 err_t lr9_write_command ( lr9_t *ctx, uint8_t *command, uint8_t *param );
376 
390 err_t lr9_inquire_command ( lr9_t *ctx, uint8_t *command, lr9_en_set_t en_set );
391 
404 err_t lr9_send_data_frame ( lr9_t *ctx, uint8_t confirm, uint8_t nbtrials, uint8_t *data_frame );
405 
406 #ifdef __cplusplus
407 }
408 #endif
409 #endif // LR9_H
410  // lr9
412 
413 // ------------------------------------------------------------------------ END
lr9_hw_reset
void lr9_hw_reset(lr9_t *ctx)
LR 9 HW reset function.
lr9_t
LR 9 Click context object.
Definition: lr9.h:223
LR9_RX_DRV_BUFFER_SIZE
#define LR9_RX_DRV_BUFFER_SIZE
Definition: lr9.h:191
lr9_t::rst
digital_out_t rst
Definition: lr9.h:226
lr9_inquire_command
err_t lr9_inquire_command(lr9_t *ctx, uint8_t *command, lr9_en_set_t en_set)
LR 9 inquire writing function.
lr9_set_boot_pin
void lr9_set_boot_pin(lr9_t *ctx, uint8_t state)
LR 9 set BOOT pin state function.
lr9_generic_write
err_t lr9_generic_write(lr9_t *ctx, uint8_t *data_in, uint16_t len)
LR 9 data writing function.
LR9_EQUAL_DISABLE
@ LR9_EQUAL_DISABLE
Definition: lr9.h:277
lr9_cfg_t::baud_rate
uint32_t baud_rate
Definition: lr9.h:252
LR9_TX_DRV_BUFFER_SIZE
#define LR9_TX_DRV_BUFFER_SIZE
LR 9 driver buffer size.
Definition: lr9.h:190
lr9_write_command
err_t lr9_write_command(lr9_t *ctx, uint8_t *command, uint8_t *param)
LR 9 command writing function.
lr9_cfg_t::rst
pin_name_t rst
Definition: lr9.h:249
LR9_OK
@ LR9_OK
Definition: lr9.h:266
lr9_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: lr9.h:255
lr9_cfg_t::bt
pin_name_t bt
Definition: lr9.h:248
lr9_t::uart
uart_t uart
Definition: lr9.h:229
lr9_en_set_t
lr9_en_set_t
LR 9 Click enable equal to data symbol.
Definition: lr9.h:276
lr9_cfg_setup
void lr9_cfg_setup(lr9_cfg_t *cfg)
LR 9 configuration object setup function.
lr9_cfg_t
LR 9 Click configuration object.
Definition: lr9.h:242
lr9_t::bt
digital_out_t bt
Definition: lr9.h:225
lr9_init
err_t lr9_init(lr9_t *ctx, lr9_cfg_t *cfg)
LR 9 initialization function.
lr9_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: lr9.h:256
lr9_cfg_t::rx_pin
pin_name_t rx_pin
Definition: lr9.h:244
LR9_EQUAL_ENABLE
@ LR9_EQUAL_ENABLE
Definition: lr9.h:278
lr9_cfg_t::tx_pin
pin_name_t tx_pin
Definition: lr9.h:245
lr9_cfg_t::uart_blocking
bool uart_blocking
Definition: lr9.h:253
lr9_send_data_frame
err_t lr9_send_data_frame(lr9_t *ctx, uint8_t confirm, uint8_t nbtrials, uint8_t *data_frame)
LR 9 send data frame function.
lr9_return_value_t
lr9_return_value_t
LR 9 Click return value data.
Definition: lr9.h:265
lr9_generic_read
err_t lr9_generic_read(lr9_t *ctx, uint8_t *data_out, uint16_t len)
LR 9 data reading function.
lr9_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: lr9.h:254
LR9_ERROR
@ LR9_ERROR
Definition: lr9.h:267