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
35#include "drv_digital_out.h"
36#include "drv_digital_in.h"
37#include "drv_uart.h"
38
59#define LR_CMD_SYS_GET_VER "sys get ver"
60#define LR_CMD_MAC_PAUSE "mac pause"
61#define LR_CMD_RADIO_SET_WDT "radio set wdt 0"
62#define LR_ARG_0 "0"
63
68#define LR_JM_OTAA "otaa"
69#define LR_JM_ABP "abp"
70
75#define LR_PL_CNF "cnf "
76#define LR_PL_UNCNF "uncnf "
77
82#define LR_INVALID_PARAM 1
83#define LR_NOT_JOINED 2
84#define LR_NO_FREE_CH 3
85#define LR_SILENT 4
86#define LR_ERR_REJOIN_NEEDED 5
87#define LR_BUSY 6
88#define LR_MAC_PAUSED 7
89#define LR_INVALID_PAR_DATA_LEN 8
90#define LR_KEYS_NOT_INIT 9
91#define LR_MAC_ERR 10
92#define LR_MAC_RX 12
93#define LR_INVALID_REPAR_DATA_LEN 13
94#define LR_RADIO_ERR 14
95#define LR_DENIED 18
96
101#define LR_MAX_DATA_SIZE 256
102#define LR_MAX_TRANSFER_SIZE 384
103
104#define LR_MAX_CMD_SIZE 64
105
110#define LR_MAX_RSP_SIZE 20
111
116#define LR_RESP_COUNT 100
117
122#define LR_TIMER_EXPIRED 50000
123
128#define LR_MAC_TX "mac tx "
129#define LR_JOIN "mac join "
130#define LR_RADIO_TX "radio tx "
131#define LR_RADIO_RX "radio rx "
132
138#define DRV_RX_BUFFER_SIZE 300
139 // lr_set
141
156#define LR_MAP_MIKROBUS( cfg, mikrobus ) \
157 cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
158 cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
159 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
160 cfg.rts = MIKROBUS( mikrobus, MIKROBUS_CS ); \
161 cfg.cts = MIKROBUS( mikrobus, MIKROBUS_INT )
162 // lr_map // lr
165
170typedef struct
171{
172 char tx_buffer[ LR_MAX_TRANSFER_SIZE ];
173 char rx_buffer[ LR_MAX_TRANSFER_SIZE ];
175
177
182typedef struct
183{
187 uint32_t ticker;
188 uint32_t timer_max;
189
190} lr_timer_t;
191
196typedef struct
197{
200
202
207typedef struct
208{
209 bool rsp_f;
212 void ( *callback_resp )( char *response );
213
215
220typedef struct
221{
222 char *payload;
223 char *port_no;
224 char *buffer;
225 char *response;
226
227} lr_mac_t;
228
233typedef struct
234{
235 // Output pins
236 digital_out_t rst;
237 digital_out_t rts;
239 // Input pins
240 digital_in_t cts;
242 // Modules
243 uart_t uart;
245 // Buffers
246 char uart_rx_buffer[ DRV_RX_BUFFER_SIZE ];
247 char uart_tx_buffer[ DRV_RX_BUFFER_SIZE ];
254
255} lr_t;
256
261typedef struct
262{
263 // Communication gpio pins
264 pin_name_t rx_pin;
265 pin_name_t tx_pin;
267 // Additional gpio pins
268 pin_name_t rst;
269 pin_name_t rts;
270 pin_name_t cts;
272 // Static variable
273 uint32_t baud_rate;
275 uart_data_bits_t data_bit;
276 uart_parity_t parity_bit;
277 uart_stop_bits_t stop_bit;
279} lr_cfg_t;
280
285typedef enum
286{
287 LR_OK = 0,
288 LR_ERROR = -1
289
291
307void lr_cfg_setup ( lr_cfg_t *cfg );
308
323err_t lr_init ( lr_t *ctx, lr_cfg_t *cfg );
324
338void lr_default_cfg ( lr_t *ctx, bool cb_default, void ( *response_p )( char *response ) );
339
350void lr_generic_write ( lr_t *ctx, char *data_buf, uint16_t len );
351
363int32_t lr_generic_read ( lr_t *ctx, char *data_buf, uint16_t max_len );
364
376void lr_cmd ( lr_t *ctx, char *cmd, char *response );
377
387uint8_t lr_mac_tx ( lr_t *ctx, lr_mac_t *mac );
388
399uint8_t lr_join ( lr_t *ctx, char *join_mode, char *response );
400
411uint8_t lr_rx ( lr_t *ctx, char *window_size, char *response );
412
422uint8_t lr_tx ( lr_t *ctx, char *buffer );
423
433void lr_rx_isr ( lr_t *ctx, char rx_input );
434
444void lr_tick_isr ( lr_t *ctx );
445
465void lr_tick_conf ( lr_t *ctx, uint32_t timer_limit );
466
475void lr_isr_process ( lr_t *ctx );
476
486void lr_put_char ( lr_t *ctx, char data_in );
487
488#ifdef __cplusplus
489}
490#endif
491#endif // LR_H
492 // lr
494
495// ------------------------------------------------------------------------ END
#define LR_MAX_TRANSFER_SIZE
Definition: lr.h:102
#define DRV_RX_BUFFER_SIZE
LR driver buffer size.
Definition: lr.h:138
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:286
@ LR_OK
Definition: lr.h:287
@ LR_ERROR
Definition: lr.h:288
Click buffers object definition.
Definition: lr.h:171
uint16_t rx_buffer_len
Definition: lr.h:174
LR Click configuration object.
Definition: lr.h:262
pin_name_t rts
Definition: lr.h:269
uint32_t baud_rate
Definition: lr.h:273
pin_name_t cts
Definition: lr.h:270
bool uart_blocking
Definition: lr.h:274
uart_data_bits_t data_bit
Definition: lr.h:275
pin_name_t tx_pin
Definition: lr.h:265
pin_name_t rx_pin
Definition: lr.h:264
uart_stop_bits_t stop_bit
Definition: lr.h:277
uart_parity_t parity_bit
Definition: lr.h:276
pin_name_t rst
Definition: lr.h:268
Mac object definition.
Definition: lr.h:221
char * response
Definition: lr.h:225
char * payload
Definition: lr.h:222
char * port_no
Definition: lr.h:223
char * buffer
Definition: lr.h:224
Process Flags object definition.
Definition: lr.h:197
bool rsp_rdy_f
Definition: lr.h:198
bool lr_rdy_f
Definition: lr.h:199
Response object definition.
Definition: lr.h:208
bool callback_default
Definition: lr.h:211
bool rsp_f
Definition: lr.h:209
char * rsp_buffer
Definition: lr.h:210
LR Click context object.
Definition: lr.h:234
char data_in
Definition: lr.h:253
lr_procces_flags_t flags
Definition: lr.h:251
lr_response_t rsp
Definition: lr.h:252
digital_out_t rts
Definition: lr.h:237
lr_buffers_t buff
Definition: lr.h:249
uart_t uart
Definition: lr.h:243
digital_in_t cts
Definition: lr.h:240
digital_out_t rst
Definition: lr.h:236
lr_timer_t tm
Definition: lr.h:250
Timer Flags and Counter object definition.
Definition: lr.h:183
bool timeout_f
Definition: lr.h:185
bool timer_f
Definition: lr.h:184
uint32_t ticker
Definition: lr.h:187
bool timer_use_f
Definition: lr.h:186
uint32_t timer_max
Definition: lr.h:188