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 
35 #include "mikrosdk_version.h"
36 
37 #ifdef __GNUC__
38 #if mikroSDK_GET_VERSION < 20800ul
39 #include "rcu_delays.h"
40 #else
41 #include "delays.h"
42 #endif
43 #endif
44 
45 #include "drv_digital_out.h"
46 #include "drv_digital_in.h"
47 #include "drv_uart.h"
48 
69 #define LR9_CMD_AT "AT"
70 
75 #define LR9_CMD_CGMI "CGMI"
76 #define LR9_CMD_CGMM "CGMM"
77 #define LR9_CMD_CGMR "CGMR"
78 #define LR9_CMD_CGSN "CGSN"
79 #define LR9_CMD_CGBR "CGBR"
80 
85 #define LR9_CMD_CJOINMODE "CJOINMODE"
86 #define LR9_CMD_CDEVEUI "CDEVEUI"
87 #define LR9_CMD_CAPPEUI "CAPPEUI"
88 #define LR9_CMD_CAPPKEY "CAPPKEY"
89 #define LR9_CMD_CDEVADDR "CDEVADDR"
90 #define LR9_CMD_CAPPSKEY "CAPPSKEY"
91 #define LR9_CMD_CNWKSKEY "CNWKSKEY"
92 #define LR9_CMD_CFREQBANDMASK "CFREQBANDMASK"
93 #define LR9_CMD_CULDLMODE "CULDLMODE"
94 #define LR9_CMD_CADDMUTICAST "CADDMUTICAST"
95 #define LR9_CMD_CDELMUTICAST "CDELMUTICAST"
96 #define LR9_CMD_CNUMMUTICAST "CNUMMUTICAST"
97 #define LR9_CMD_CWORKMODE "CWORKMODE"
98 #define LR9_CMD_CCLASS "CCLASS"
99 #define LR9_CMD_CBL "CBL"
100 #define LR9_CMD_CSTATUS "CSTATUS"
101 #define LR9_CMD_CJOIN "CJOIN"
102 #define LR9_CMD_CPINGSLOTINFOREQ "CPINGSLOTINFOREQ"
103 #define LR9_CMD_DTRX "DTRX"
104 #define LR9_CMD_DRX "DRX"
105 
110 #define LR9_CMD_CCONFIRM "CCONFIRM"
111 #define LR9_CMD_CAPPPORT "CAPPPORT"
112 #define LR9_CMD_CDATARATE "CDATARATE"
113 #define LR9_CMD_CRSSI "CRSSI"
114 #define LR9_CMD_CNBTRIALS "CNBTRIALS"
115 #define LR9_CMD_CRM "CRM"
116 #define LR9_CMD_CTXP "CTXP"
117 #define LR9_CMD_CLINKCHECK "CLINKCHECK"
118 #define LR9_CMD_CADR "CADR"
119 #define LR9_CMD_CRXP "CRXP"
120 #define LR9_CMD_CRX1DELAY "CRX1DELAY"
121 #define LR9_CMD_CSAVE "CSAVE"
122 #define LR9_CMD_CRESTORE "CRESTORE"
123 
128 #define LR9_CMD_IREBOOT "IREBOOT"
129 #define LR9_CMD_ILOGLVL "ILOGLVL"
130 
135 #define LR9_CMD_CKEYSPROTECT "CKEYSPROTECT"
136 
141 #define LR9_CMD_CTXADDRSET "CTXADDRSET"
142 #define LR9_CMD_CADDRSET "CADDRSET"
143 #define LR9_CMD_CTX "CTX"
144 #define LR9_CMD_CRX "CRX"
145 #define LR9_CMD_CRXS "CRXS"
146 
151 #define LR9_DTRX_CONFIG "0"
152 #define LR9_DTRX_UNCONFIG "1"
153 
158 #define LR9_DTRX_CONFIG_DATA 0
159 #define LR9_DTRX_UNCONFIG_DATA 1
160 #define LR9_NB_TRIALS_MIN 1
161 #define LR9_NB_TRIALS_2 2
162 #define LR9_NB_TRIALS_MAX 15
163 #define LR9_DATA_FRAME_MAX 10
164 #define LR9_MSG_START_POS 16
165 
170 #define LR9_SYMBOL_END_CMD "\r\n"
171 #define LR9_SYMBOL_QUERY "?"
172 #define LR9_SYMBOL_SET_VAL_CMD "="
173 #define LR9_SYMBOL_PREFIX_CMD "+"
174 #define LR9_SYMBOL_SEPARATOR ","
175 #define LR9_SYMBOL_SPACE " "
176 #define LR9_SYMBOL_NULL ""
177 #define LR9_SYMBOL_QUOTE "\""
178 #define LR9_ASCII_SPACE 0x20
179 #define LR9_ASCII_QUOTE 0x22
180 
186 #define LR9_TX_DRV_BUFFER_SIZE 100
187 #define LR9_RX_DRV_BUFFER_SIZE 300
188  // lr9_cmd
190 
205 #define LR9_MAP_MIKROBUS( cfg, mikrobus ) \
206  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
207  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
208  cfg.bt = MIKROBUS( mikrobus, MIKROBUS_AN ); \
209  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST )
210  // lr9_map // lr9
213 
218 typedef struct
219 {
220  // Output pins
221  digital_out_t bt;
222  digital_out_t rst;
224  // Modules
225  uart_t uart;
227  // Buffers
228  uint8_t uart_rx_buffer[ LR9_RX_DRV_BUFFER_SIZE ];
229  uint8_t uart_tx_buffer[ LR9_TX_DRV_BUFFER_SIZE ];
231 } lr9_t;
232 
237 typedef struct
238 {
239  // Communication gpio pins
240  pin_name_t rx_pin;
241  pin_name_t tx_pin;
243  // Additional gpio pins
244  pin_name_t bt;
245  pin_name_t rst;
247  // Static variable
248  uint32_t baud_rate;
250  uart_data_bits_t data_bit;
251  uart_parity_t parity_bit;
252  uart_stop_bits_t stop_bit;
254 } lr9_cfg_t;
255 
260 typedef enum
261 {
262  LR9_OK = 0,
263  LR9_ERROR = -1
264 
266 
271 typedef enum
272 {
275 
277 
293 void lr9_cfg_setup ( lr9_cfg_t *cfg );
294 
308 err_t lr9_init ( lr9_t *ctx, lr9_cfg_t *cfg );
309 
318 void lr9_hw_reset ( lr9_t *ctx );
319 
329 void lr9_set_boot_pin ( lr9_t *ctx, uint8_t state );
330 
343 err_t lr9_generic_write ( lr9_t *ctx, uint8_t *data_in, uint16_t len );
344 
357 err_t lr9_generic_read ( lr9_t *ctx, uint8_t *data_out, uint16_t len );
358 
371 err_t lr9_write_command ( lr9_t *ctx, uint8_t *command, uint8_t *param );
372 
386 err_t lr9_inquire_command ( lr9_t *ctx, uint8_t *command, lr9_en_set_t en_set );
387 
400 err_t lr9_send_data_frame ( lr9_t *ctx, uint8_t confirm, uint8_t nbtrials, uint8_t *data_frame );
401 
402 #ifdef __cplusplus
403 }
404 #endif
405 #endif // LR9_H
406  // lr9
408 
409 // ------------------------------------------------------------------------ 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:219
LR9_RX_DRV_BUFFER_SIZE
#define LR9_RX_DRV_BUFFER_SIZE
Definition: lr9.h:187
lr9_t::rst
digital_out_t rst
Definition: lr9.h:222
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:273
lr9_cfg_t::baud_rate
uint32_t baud_rate
Definition: lr9.h:248
LR9_TX_DRV_BUFFER_SIZE
#define LR9_TX_DRV_BUFFER_SIZE
LR 9 driver buffer size.
Definition: lr9.h:186
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:245
LR9_OK
@ LR9_OK
Definition: lr9.h:262
lr9_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: lr9.h:251
lr9_cfg_t::bt
pin_name_t bt
Definition: lr9.h:244
lr9_t::uart
uart_t uart
Definition: lr9.h:225
lr9_en_set_t
lr9_en_set_t
LR 9 Click enable equal to data symbol.
Definition: lr9.h:272
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:238
lr9_t::bt
digital_out_t bt
Definition: lr9.h:221
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:252
lr9_cfg_t::rx_pin
pin_name_t rx_pin
Definition: lr9.h:240
LR9_EQUAL_ENABLE
@ LR9_EQUAL_ENABLE
Definition: lr9.h:274
lr9_cfg_t::tx_pin
pin_name_t tx_pin
Definition: lr9.h:241
lr9_cfg_t::uart_blocking
bool uart_blocking
Definition: lr9.h:249
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:261
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:250
LR9_ERROR
@ LR9_ERROR
Definition: lr9.h:263