lr 2.1.0.0
lr.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 LR_H
29#define LR_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 LR_CMD_SYS_GET_VER "sys get ver"
74#define LR_CMD_MAC_PAUSE "mac pause"
75#define LR_CMD_RADIO_SET_WDT "radio set wdt 0"
76#define LR_ARG_0 "0"
77
82#define LR_JM_OTAA "otaa"
83#define LR_JM_ABP "abp"
84
89#define LR_PL_CNF "cnf "
90#define LR_PL_UNCNF "uncnf "
91
96#define LR_INVALID_PARAM 1
97#define LR_NOT_JOINED 2
98#define LR_NO_FREE_CH 3
99#define LR_SILENT 4
100#define LR_ERR_REJOIN_NEEDED 5
101#define LR_BUSY 6
102#define LR_MAC_PAUSED 7
103#define LR_INVALID_PAR_DATA_LEN 8
104#define LR_KEYS_NOT_INIT 9
105#define LR_MAC_ERR 10
106#define LR_MAC_RX 12
107#define LR_INVALID_REPAR_DATA_LEN 13
108#define LR_RADIO_ERR 14
109#define LR_DENIED 18
110
115#define LR_MAX_DATA_SIZE 256
116#define LR_MAX_TRANSFER_SIZE 384
117
118#define LR_MAX_CMD_SIZE 64
119
124#define LR_MAX_RSP_SIZE 20
125
130#define LR_RESP_COUNT 100
131
136#define LR_TIMER_EXPIRED 50000
137
142#define LR_MAC_TX "mac tx "
143#define LR_JOIN "mac join "
144#define LR_RADIO_TX "radio tx "
145#define LR_RADIO_RX "radio rx "
146
152#define DRV_RX_BUFFER_SIZE 300
153
154 // lr_set
155
170#define LR_MAP_MIKROBUS( cfg, mikrobus ) \
171 cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
172 cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
173 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
174 cfg.rts = MIKROBUS( mikrobus, MIKROBUS_CS ); \
175 cfg.cts = MIKROBUS( mikrobus, MIKROBUS_INT )
176
177 // lr_map
178 // lr
179
184typedef struct
185{
186 char tx_buffer[ LR_MAX_TRANSFER_SIZE ];
187 char rx_buffer[ LR_MAX_TRANSFER_SIZE ];
189
191
196typedef struct
197{
201 uint32_t ticker;
202 uint32_t timer_max;
203
204} lr_timer_t;
205
210typedef struct
211{
214
216
221typedef struct
222{
223 bool rsp_f;
226 void ( *callback_resp )( char *response );
227
229
234typedef struct
235{
236 char *payload;
237 char *port_no;
238 char *buffer;
239 char *response;
240
241} lr_mac_t;
242
247typedef struct
248{
249 // Output pins
250 digital_out_t rst;
251 digital_out_t rts;
253 // Input pins
254 digital_in_t cts;
256 // Modules
257 uart_t uart;
259 // Buffers
260 char uart_rx_buffer[ DRV_RX_BUFFER_SIZE ];
261 char uart_tx_buffer[ DRV_RX_BUFFER_SIZE ];
268
269} lr_t;
270
275typedef struct
276{
277 // Communication gpio pins
278 pin_name_t rx_pin;
279 pin_name_t tx_pin;
281 // Additional gpio pins
282 pin_name_t rst;
283 pin_name_t rts;
284 pin_name_t cts;
286 // Static variable
287 uint32_t baud_rate;
289 uart_data_bits_t data_bit;
290 uart_parity_t parity_bit;
291 uart_stop_bits_t stop_bit;
293} lr_cfg_t;
294
299typedef enum
300{
301 LR_OK = 0,
302 LR_ERROR = -1
303
305
321void lr_cfg_setup ( lr_cfg_t *cfg );
322
337err_t lr_init ( lr_t *ctx, lr_cfg_t *cfg );
338
352void lr_default_cfg ( lr_t *ctx, bool cb_default, void ( *response_p )( char *response ) );
353
364void lr_generic_write ( lr_t *ctx, char *data_buf, uint16_t len );
365
377int32_t lr_generic_read ( lr_t *ctx, char *data_buf, uint16_t max_len );
378
390void lr_cmd ( lr_t *ctx, char *cmd, char *response );
391
401uint8_t lr_mac_tx ( lr_t *ctx, lr_mac_t *mac );
402
413uint8_t lr_join ( lr_t *ctx, char *join_mode, char *response );
414
425uint8_t lr_rx ( lr_t *ctx, char *window_size, char *response );
426
436uint8_t lr_tx ( lr_t *ctx, char *buffer );
437
447void lr_rx_isr ( lr_t *ctx, char rx_input );
448
458void lr_tick_isr ( lr_t *ctx );
459
479void lr_tick_conf ( lr_t *ctx, uint32_t timer_limit );
480
489void lr_isr_process ( lr_t *ctx );
490
500void lr_put_char ( lr_t *ctx, char data_in );
501
502#ifdef __cplusplus
503}
504#endif
505#endif // LR_H
506
507 // lr
508
509// ------------------------------------------------------------------------ END
#define LR_MAX_TRANSFER_SIZE
Definition lr.h:116
#define DRV_RX_BUFFER_SIZE
LR driver buffer size.
Definition lr.h:152
uint8_t lr_rx(lr_t *ctx, char *window_size, char *response)
Main receiver function
uint8_t lr_tx(lr_t *ctx, char *buffer)
Main tnanceiver function.
void lr_cmd(lr_t *ctx, char *cmd, char *response)
Send command function.
uint8_t lr_join(lr_t *ctx, char *join_mode, char *response)
Function for setting join mode.
void lr_generic_write(lr_t *ctx, char *data_buf, uint16_t len)
LR data writing function.
int32_t lr_generic_read(lr_t *ctx, char *data_buf, uint16_t max_len)
LR data reading function.
void lr_tick_conf(lr_t *ctx, uint32_t timer_limit)
Timer Configuration.
void lr_isr_process(lr_t *ctx)
Main Process.
void lr_rx_isr(lr_t *ctx, char rx_input)
Receiver.
void lr_tick_isr(lr_t *ctx)
Timer.
void lr_put_char(lr_t *ctx, char data_in)
Function for write char.
void lr_default_cfg(lr_t *ctx, bool cb_default, void(*response_p)(char *response))
LR default configuration function.
uint8_t lr_mac_tx(lr_t *ctx, lr_mac_t *mac)
Function for writing mac parameters.
err_t lr_init(lr_t *ctx, lr_cfg_t *cfg)
LR initialization function.
void lr_cfg_setup(lr_cfg_t *cfg)
LR configuration object setup function.
lr_return_value_t
LR Click return value data.
Definition lr.h:300
@ LR_OK
Definition lr.h:301
@ LR_ERROR
Definition lr.h:302
Click buffers object definition.
Definition lr.h:185
uint16_t rx_buffer_len
Definition lr.h:188
LR Click configuration object.
Definition lr.h:276
pin_name_t rts
Definition lr.h:283
uint32_t baud_rate
Definition lr.h:287
pin_name_t cts
Definition lr.h:284
bool uart_blocking
Definition lr.h:288
uart_data_bits_t data_bit
Definition lr.h:289
pin_name_t tx_pin
Definition lr.h:279
pin_name_t rx_pin
Definition lr.h:278
uart_stop_bits_t stop_bit
Definition lr.h:291
uart_parity_t parity_bit
Definition lr.h:290
pin_name_t rst
Definition lr.h:282
Mac object definition.
Definition lr.h:235
char * response
Definition lr.h:239
char * payload
Definition lr.h:236
char * port_no
Definition lr.h:237
char * buffer
Definition lr.h:238
Process Flags object definition.
Definition lr.h:211
bool rsp_rdy_f
Definition lr.h:212
bool lr_rdy_f
Definition lr.h:213
Response object definition.
Definition lr.h:222
bool callback_default
Definition lr.h:225
bool rsp_f
Definition lr.h:223
char * rsp_buffer
Definition lr.h:224
LR Click context object.
Definition lr.h:248
char data_in
Definition lr.h:267
lr_procces_flags_t flags
Definition lr.h:265
lr_response_t rsp
Definition lr.h:266
digital_out_t rts
Definition lr.h:251
lr_buffers_t buff
Definition lr.h:263
uart_t uart
Definition lr.h:257
digital_in_t cts
Definition lr.h:254
digital_out_t rst
Definition lr.h:250
lr_timer_t tm
Definition lr.h:264
Timer Flags and Counter object definition.
Definition lr.h:197
bool timeout_f
Definition lr.h:199
bool timer_f
Definition lr.h:198
uint32_t ticker
Definition lr.h:201
bool timer_use_f
Definition lr.h:200
uint32_t timer_max
Definition lr.h:202