lr2 2.1.0.0
lr2.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 LR2_H
29#define LR2_H
30
31#ifdef __cplusplus
32extern "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 LR2_CMD_SYS_GET_VER "sys get ver"
74#define LR2_CMD_MAC_PAUSE "mac pause"
75#define LR2_CMD_RADIO_SET_WDT "radio set wdt 0"
76#define LR2_ARG_0 "0"
77
82#define LR2_JM_OTAA "otaa"
83#define LR2_JM_ABP "abp"
84
89#define LR2_PL_CNF "cnf "
90#define LR2_PL_UNCNF "uncnf "
91
96#define LR2_INVALID_PARAM 1
97#define LR2_NOT_JOINED 2
98#define LR2_NO_FREE_CH 3
99#define LR2_SILENT 4
100#define LR2_ERR_REJOIN_NEEDED 5
101#define LR2_BUSY 6
102#define LR2_MAC_PAUSED 7
103#define LR2_INVALID_PAR_DATA_LEN 8
104#define LR2_KEYS_NOT_INIT 9
105#define LR2_MAC_ERR 10
106#define LR2_MAC_RX 12
107#define LR2_INVALID_REPAR_DATA_LEN 13
108#define LR2_RADIO_ERR 14
109#define LR2_DENIED 18
110
115#define LR2_MAX_DATA_SIZE 256
116#define LR2_MAX_TRANSFER_SIZE 384
117
118#define LR2_MAX_CMD_SIZE 64
119
124#define LR2_MAX_RSP_SIZE 20
125
130#define LR2_RESP_COUNT 100
131
136#define LR2_TIMER_EXPIRED 50000
137
142#define LR2_MAC_TX "mac tx "
143#define LR2_JOIN "mac join "
144#define LR2_RADIO_TX "radio tx "
145#define LR2_RADIO_RX "radio rx "
146
152#define LR2_DRV_RX_BUFFER_SIZE 300
153#define LR2_DRV_TX_BUFFER_SIZE 100
154
155 // lr2_set
156
171#define LR2_MAP_MIKROBUS( cfg, mikrobus ) \
172 cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
173 cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
174 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
175 cfg.rts = MIKROBUS( mikrobus, MIKROBUS_CS ); \
176 cfg.cts = MIKROBUS( mikrobus, MIKROBUS_INT )
177
178 // lr2_map
179 // lr2
180
185typedef struct
186{
187 char tx_buffer[ LR2_MAX_TRANSFER_SIZE ];
188 char rx_buffer[ LR2_MAX_TRANSFER_SIZE ];
190
192
197typedef struct
198{
202 uint32_t ticker;
203 uint32_t timer_max;
204
206
211typedef struct
212{
215
217
222typedef struct
223{
224 bool rsp_f;
227 void ( *callback_resp )( char *response );
228
230
235typedef struct
236{
237 char *payload;
238 char *port_no;
239 char *buffer;
240 char *response;
241
242} lr2_mac_t;
243
248typedef struct
249{
250 // Output pins
251 digital_out_t rst;
252 digital_out_t rts;
254 // Input pins
255 digital_in_t cts;
257 // Modules
258 uart_t uart;
260 // Buffers
261 char uart_rx_buffer[ LR2_DRV_RX_BUFFER_SIZE ];
262 char uart_tx_buffer[ LR2_DRV_TX_BUFFER_SIZE ];
269
270} lr2_t;
271
276typedef struct
277{
278 // Communication gpio pins
279 pin_name_t rx_pin;
280 pin_name_t tx_pin;
282 // Additional gpio pins
283 pin_name_t rst;
284 pin_name_t rts;
285 pin_name_t cts;
287 // Static variable
288 uint32_t baud_rate;
290 uart_data_bits_t data_bit;
291 uart_parity_t parity_bit;
292 uart_stop_bits_t stop_bit;
294} lr2_cfg_t;
295
300typedef enum
301{
303 LR2_ERROR = -1
304
306
323
338err_t lr2_init ( lr2_t *ctx, lr2_cfg_t *cfg );
339
353void lr2_default_cfg ( lr2_t *ctx, bool cb_default, void ( *response_p )( char *response ) );
354
365void lr2_generic_write ( lr2_t *ctx, char *data_buf, uint16_t len );
366
378int32_t lr2_generic_read ( lr2_t *ctx, char *data_buf, uint16_t max_len );
379
391void lr2_cmd ( lr2_t *ctx, char *cmd, char *response );
392
402uint8_t lr2_mac_tx ( lr2_t *ctx, lr2_mac_t *mac );
403
414uint8_t lr2_join ( lr2_t *ctx, char *join_mode, char *response );
415
426uint8_t lr2_rx ( lr2_t *ctx, char *window_size, char *response );
427
437uint8_t lr2_tx ( lr2_t *ctx, char *buffer );
438
448void lr2_rx_isr ( lr2_t *ctx, char rx_input );
449
459void lr2_tick_isr ( lr2_t *ctx );
460
480void lr2_tick_conf ( lr2_t *ctx, uint32_t timer_limit );
481
490void lr2_isr_process ( lr2_t *ctx );
491
501void lr2_put_char ( lr2_t *ctx, char data_in );
502
503#ifdef __cplusplus
504}
505#endif
506#endif // LR2_H
507
508 // lr2
509
510// ------------------------------------------------------------------------ END
#define LR2_DRV_TX_BUFFER_SIZE
Definition lr2.h:153
#define LR2_DRV_RX_BUFFER_SIZE
LR 2 driver buffer size.
Definition lr2.h:152
#define LR2_MAX_TRANSFER_SIZE
Definition lr2.h:116
uint8_t lr2_join(lr2_t *ctx, char *join_mode, char *response)
Function for setting join mode.
int32_t lr2_generic_read(lr2_t *ctx, char *data_buf, uint16_t max_len)
LR 2 data reading function.
void lr2_generic_write(lr2_t *ctx, char *data_buf, uint16_t len)
LR 2 data writing function.
uint8_t lr2_rx(lr2_t *ctx, char *window_size, char *response)
Main receiver function
err_t lr2_init(lr2_t *ctx, lr2_cfg_t *cfg)
LR 2 initialization function.
void lr2_cfg_setup(lr2_cfg_t *cfg)
LR 2 configuration object setup function.
void lr2_tick_conf(lr2_t *ctx, uint32_t timer_limit)
Timer Configuration.
void lr2_put_char(lr2_t *ctx, char data_in)
Function for write char.
void lr2_default_cfg(lr2_t *ctx, bool cb_default, void(*response_p)(char *response))
LR 2 default configuration function.
void lr2_tick_isr(lr2_t *ctx)
Timer.
void lr2_isr_process(lr2_t *ctx)
Main Process.
uint8_t lr2_tx(lr2_t *ctx, char *buffer)
Main tnanceiver function.
void lr2_cmd(lr2_t *ctx, char *cmd, char *response)
Send command function.
void lr2_rx_isr(lr2_t *ctx, char rx_input)
Receiver.
uint8_t lr2_mac_tx(lr2_t *ctx, lr2_mac_t *mac)
Function for writing mac parameters.
lr2_return_value_t
LR 2 Click return value data.
Definition lr2.h:301
@ LR2_ERROR
Definition lr2.h:303
@ LR2_OK
Definition lr2.h:302
Click buffers object definition.
Definition lr2.h:186
uint16_t rx_buffer_len
Definition lr2.h:189
LR 2 Click configuration object.
Definition lr2.h:277
pin_name_t rts
Definition lr2.h:284
uint32_t baud_rate
Definition lr2.h:288
pin_name_t cts
Definition lr2.h:285
bool uart_blocking
Definition lr2.h:289
uart_data_bits_t data_bit
Definition lr2.h:290
pin_name_t tx_pin
Definition lr2.h:280
pin_name_t rx_pin
Definition lr2.h:279
uart_stop_bits_t stop_bit
Definition lr2.h:292
uart_parity_t parity_bit
Definition lr2.h:291
pin_name_t rst
Definition lr2.h:283
Mac object definition.
Definition lr2.h:236
char * response
Definition lr2.h:240
char * payload
Definition lr2.h:237
char * port_no
Definition lr2.h:238
char * buffer
Definition lr2.h:239
Process Flags object definition.
Definition lr2.h:212
bool rsp_rdy_f
Definition lr2.h:213
bool lr2_rdy_f
Definition lr2.h:214
Response object definition.
Definition lr2.h:223
bool callback_default
Definition lr2.h:226
bool rsp_f
Definition lr2.h:224
char * rsp_buffer
Definition lr2.h:225
LR 2 Click context object.
Definition lr2.h:249
char data_in
Definition lr2.h:268
lr2_procces_flags_t flags
Definition lr2.h:266
lr2_timer_t tm
Definition lr2.h:265
digital_out_t rts
Definition lr2.h:252
uart_t uart
Definition lr2.h:258
lr2_buffers_t buff
Definition lr2.h:264
digital_in_t cts
Definition lr2.h:255
digital_out_t rst
Definition lr2.h:251
lr2_response_t rsp
Definition lr2.h:267
Timer Flags and Counter object definition.
Definition lr2.h:198
bool timeout_f
Definition lr2.h:200
bool timer_f
Definition lr2.h:199
uint32_t ticker
Definition lr2.h:202
bool timer_use_f
Definition lr2.h:201
uint32_t timer_max
Definition lr2.h:203