lr5 2.0.0.0
lr5.h
Go to the documentation of this file.
1/*
2 * MikroSDK - MikroE Software Development Kit
3 * Copyright© 2020 MikroElektronika d.o.o.
4 *
5 * Permission is hereby granted, free of charge, to any person
6 * obtaining a copy of this software and associated documentation
7 * files (the "Software"), to deal in the Software without restriction,
8 * including without limitation the rights to use, copy, modify, merge,
9 * publish, distribute, sublicense, and/or sell copies of the Software,
10 * and to permit persons to whom the Software is furnished to do so,
11 * subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be
14 * included in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
22 * OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
33// ----------------------------------------------------------------------------
34
35#ifndef LR5_H
36#define LR5_H
37
42#ifdef PREINIT_SUPPORTED
43#include "preinit.h"
44#endif
45
46#ifdef MikroCCoreVersion
47 #if MikroCCoreVersion >= 1
48 #include "delays.h"
49 #endif
50#endif
51
52#include "drv_digital_out.h"
53#include "drv_digital_in.h"
54#include "drv_uart.h"
55
56// -------------------------------------------------------------- PUBLIC MACROS
66#define LR5_MAP_MIKROBUS( cfg, mikrobus ) \
67 cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
68 cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
69 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
70 cfg.wk = MIKROBUS( mikrobus, MIKROBUS_CS ); \
71 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
78#define LR5_RETVAL uint8_t
79
80#define LR5_OK 0x00
81#define LR5_INIT_ERROR 0xFF
88#define RESPONSE_BIT 0x80
89#define FRAME_HEADER 0xAA
96#define RESET_CMD 0x30
97#define FACTORY_RESET_CMD 0x31
98#define EEPROM_WRITE_CMD 0x32
99#define EEPROM_READ_CMD 0x33
100#define GET_FW_VERSION_CMD 0x34
101#define GET_SERIALNO_CMD 0x35
102#define GET_DEV_EUI_CMD 0x36
103#define JOIN_CMD 0x40
104#define JOIN_IND 0x41
105#define GET_ACT_STATUS_CMD 0x42
106#define SET_APP_KEY_CMD 0x43
107#define SET_APP_SESSION_KEY_CMD 0x44
108#define SET_NWK_SESSION_KEY_CMD 0x45
109#define TX_MSG_CMD 0x46
110#define TX_MSG_CONFIRMED_IND 0x47
111#define TX_MSG_UNCONFIRMED_IND 0x48
112#define RX_MSG_IND 0x49
113#define GET_SESSION_STATUS_CMD 0x4A
114#define SET_NEXT_DR_CMD 0x4B
115#define SET_BATTERY_LVL_CMD 0x50
116#define GET_BATTERY_LVL_CMD 0x51
117#define SET_UPLINK_CNT_CMD 0x52
118#define GET_UPLINK_CNT_CMD 0x53
119#define SET_DOWNLINK_CNT_CMD 0x54
120#define GET_DOWNLINK_CNT_CMD 0x55
121#define SET_CH_MASK_CMD 0x57
122#define GET_CH_PARAM_CMD 0x58
129#define LR5_ABP 0x00
130#define LR5_OTAA 0x01
131#define LR5_UNRELIABLE_DATA_TX 0x00
132#define LR5_RELIABLE_DATA_TX 0x01
133#define LR5_SF10_125KHZ 0x00
134#define LR5_SF9_125KHZ 0x01
135#define LR5_SF8_125KHZ 0x02
136#define LR5_SF7_125KHZ 0x03
137#define LR5_SF8_500KHZ 0x04
138#define LR5_CH_IDX_0 0x00
139#define LR5_CH_IDX_1 0x01
140#define LR5_CH_IDX_2 0x02
141#define LR5_CH_IDX_3 0x03
142#define LR5_CH_IDX_4 0x04
143#define LR5_CH_IDX_5 0x05
144#define LR5_CH_IDX_6 0x06
145#define LR5_CH_IDX_7 0x07
146#define LR5_CH_IDX_8 0x08
147#define LR5_CH_IDX_9 0x09
148#define LR5_CH_IDX_10 0x0A
149#define LR5_CH_IDX_11 0x0B
150#define LR5_CH_IDX_12 0x0C
151#define LR5_CH_IDX_13 0x0D
152#define LR5_CH_IDX_14 0x0E
153#define LR5_CH_IDX_15 0x0F
160#define LR5_FRAME_HEADER_ERR 0xFF
161#define LR5_CMD_RESPONSE_ERR 0xFE
162#define LR5_CHKSUM_ERR 0xFD
163#define LR5_NBYTES_INVALID 0xFC
164#define LR5_CH_IDX_INVALID 0xFB
165#define LR5_OK 0x00
166#define LR5_RESPONSE_NOT_RECEIVED 0x00
167#define LR5_RESPONSE_RECEIVED 0x01
168#define LR5_CMD_RESPONSE_READY 0x01
169#define LR5_IND_RESPONSE_READY 0x02
170#define LR5_DATA_READY 0x00
171#define LR5_DATA_NOT_READY 0x01
178#define DRV_RX_BUFFER_SIZE 500
181 // End group macro
182// --------------------------------------------------------------- PUBLIC TYPES
191typedef void ( *lr5_hdl_t )( uint8_t*, uint8_t*, uint8_t* );
192
196typedef struct
197{
198 // Output pins
199
200 digital_out_t rst;
201 digital_out_t wk;
202
203 // Input pins
204
205 digital_in_t int_pin;
206
207 // Modules
208
209 uart_t uart;
210
211 char uart_rx_buffer[ DRV_RX_BUFFER_SIZE ];
212 char uart_tx_buffer[ DRV_RX_BUFFER_SIZE ];
213
216 uint8_t rx_dat[ 260 ];
217 uint16_t rx_cnt;
219
220} lr5_t;
221
225typedef struct
226{
227 uint8_t cmd_code;
228 uint8_t cmd_length;
229 uint8_t cmd_data[ 256 ];
230
231} lr5_cmd_t;
232
236typedef struct
237{
238 uint8_t options;
239 uint8_t port;
240 uint8_t *msg_data;
241 uint8_t msg_length;
242
243} lr5_msg_t;
244
245
249typedef struct
250{
251 // Communication gpio pins
252
253 pin_name_t rx_pin;
254 pin_name_t tx_pin;
255
256 // Additional gpio pins
257
258 pin_name_t rst;
259 pin_name_t wk;
260 pin_name_t int_pin;
261
262 // static variable
263
264 uint32_t baud_rate; // Clock speed.
266 uart_data_bits_t data_bit; // Data bits.
267 uart_parity_t parity_bit; // Parity bit.
268 uart_stop_bits_t stop_bit; // Stop bits.
269
270} lr5_cfg_t;
271
272
273 // End types group
274// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
275
281#ifdef __cplusplus
282extern "C"{
283#endif
284
294
304
314int32_t lr5_generic_read ( lr5_t *ctx, char *data_buf, uint16_t max_len );
315
324void lr5_response_handler_set ( lr5_t *ctx, void ( *handler )( uint8_t*, uint8_t*, uint8_t* ) );
325
334void lr5_uart_isr ( lr5_t *ctx );
335
345
358
367void lr5_hw_reset ( lr5_t *ctx );
368
378
388void lr5_reset_cmd ( lr5_t *ctx );
389
400
415LR5_RETVAL lr5_eeprom_write_cmd ( lr5_t *ctx, uint8_t start_addr, uint8_t *data_in, uint8_t n_bytes );
416
428LR5_RETVAL lr5_eeprom_read_cmd ( lr5_t *ctx, uint8_t start_addr, uint8_t n_bytes );
429
438
447
456
465void lr5_join_cmd ( lr5_t *ctx, uint8_t mode );
466
475
485void lr5_set_app_key_cmd ( lr5_t *ctx, uint8_t *app_key );
486
496void lr5_set_app_session_key_cmd ( lr5_t *ctx, uint8_t *app_s_key );
497
507void lr5_set_nwk_session_key_cmd ( lr5_t *ctx, uint8_t *nwk_s_key );
508
527
536
547void lr5_set_next_dr_cmd ( lr5_t *ctx, uint8_t data_rate );
548
559void lr5_set_battery_level_cmd ( lr5_t *ctx, uint8_t battery_level );
560
569
578void lr5_set_uplink_cnt_cmd ( lr5_t *ctx, uint32_t uplink_cnt );
579
588
597void lr5_set_downlink_cnt_cmd ( lr5_t *ctx, uint32_t downlink_cnt );
598
607
621void lr5_set_ch_mask_cmd ( lr5_t *ctx, uint8_t *ch_mask );
622
633LR5_RETVAL lr5_get_ch_param_cmd ( lr5_t *ctx, uint8_t ch_idx );
634
635#ifdef __cplusplus
636}
637#endif
638#endif // _LR5_H_
639
640 // End public_function group
642
643// ------------------------------------------------------------------------- END
#define DRV_RX_BUFFER_SIZE
Definition lr5.h:178
#define LR5_RETVAL
Definition lr5.h:78
void lr5_reset_cmd(lr5_t *ctx)
SW Reset Command.
void lr5_get_activation_status_cmd(lr5_t *ctx)
Get Activation Status Command.
void lr5_set_battery_level_cmd(lr5_t *ctx, uint8_t battery_level)
Set Battery Level Command.
void lr5_uart_isr(lr5_t *ctx)
UART ISR function.
void lr5_cfg_setup(lr5_cfg_t *cfg)
Config Object Initialization function.
void lr5_get_dev_eui_cmd(lr5_t *ctx)
Get DevEUI Command.
LR5_RETVAL lr5_get_ch_param_cmd(lr5_t *ctx, uint8_t ch_idx)
Get Channel Parameters Command.
void lr5_set_app_session_key_cmd(lr5_t *ctx, uint8_t *app_s_key)
Set App Session Key Command.
void lr5_join_cmd(lr5_t *ctx, uint8_t mode)
Join Network Command.
void lr5_set_app_key_cmd(lr5_t *ctx, uint8_t *app_key)
Set App Key Command.
void lr5_set_nwk_session_key_cmd(lr5_t *ctx, uint8_t *nwk_s_key)
Set Nwk Session Key Command.
LR5_RETVAL lr5_tx_msg_cmd(lr5_t *ctx, lr5_msg_t *msg)
TX Message Command.
void lr5_get_serial_no_cmd(lr5_t *ctx)
Get Mipot Serial Number Command.
void lr5_get_uplink_cnt_cmd(lr5_t *ctx)
Get Uplink Counter Command.
LR5_RETVAL lr5_eeprom_write_cmd(lr5_t *ctx, uint8_t start_addr, uint8_t *data_in, uint8_t n_bytes)
EEPROM Write Command.
void lr5_get_battery_level_cmd(lr5_t *ctx)
Get Battery Level Command.
void lr5_get_fw_version_cmd(lr5_t *ctx)
Get FW Version Command.
LR5_RETVAL lr5_eeprom_read_cmd(lr5_t *ctx, uint8_t start_addr, uint8_t n_bytes)
EEPROM Read Command.
void lr5_get_session_status_cmd(lr5_t *ctx)
Get Session Status Command.
void lr5_hw_reset(lr5_t *ctx)
HW Reset function.
LR5_RETVAL lr5_task(lr5_t *ctx)
Parser Task function.
int32_t lr5_generic_read(lr5_t *ctx, char *data_buf, uint16_t max_len)
Generic read function.
void lr5_factory_reset_cmd(lr5_t *ctx)
Factory Reset Command.
LR5_RETVAL lr5_response_ready(lr5_t *ctx)
Response Ready function.
void lr5_set_next_dr_cmd(lr5_t *ctx, uint8_t data_rate)
Set Next TX Data Rate Command.
void lr5_get_downlink_cnt_cmd(lr5_t *ctx)
Get Downlink Counter Command.
void lr5_set_downlink_cnt_cmd(lr5_t *ctx, uint32_t downlink_cnt)
Set Downlink Counter Command.
void lr5_set_ch_mask_cmd(lr5_t *ctx, uint8_t *ch_mask)
Set Channels Mask Command.
LR5_RETVAL lr5_data_indication(lr5_t *ctx)
Data Indication function.
void lr5_set_uplink_cnt_cmd(lr5_t *ctx, uint32_t uplink_cnt)
Set Uplink Counter Command.
LR5_RETVAL lr5_init(lr5_t *ctx, lr5_cfg_t *cfg)
Initialization function.
void lr5_response_handler_set(lr5_t *ctx, void(*handler)(uint8_t *, uint8_t *, uint8_t *))
Set Handler function.
void(* lr5_hdl_t)(uint8_t *, uint8_t *, uint8_t *)
Handler definition for data logging.
Definition lr5.h:191
Click configuration structure definition.
Definition lr5.h:250
uint32_t baud_rate
Definition lr5.h:264
pin_name_t wk
Definition lr5.h:259
bool uart_blocking
Definition lr5.h:265
uart_data_bits_t data_bit
Definition lr5.h:266
pin_name_t tx_pin
Definition lr5.h:254
pin_name_t rx_pin
Definition lr5.h:253
uart_stop_bits_t stop_bit
Definition lr5.h:268
pin_name_t int_pin
Definition lr5.h:260
uart_parity_t parity_bit
Definition lr5.h:267
pin_name_t rst
Definition lr5.h:258
Command structure definition.
Definition lr5.h:226
uint8_t cmd_code
Definition lr5.h:227
uint8_t cmd_length
Definition lr5.h:228
Message command definition.
Definition lr5.h:237
uint8_t msg_length
Definition lr5.h:241
uint8_t port
Definition lr5.h:239
uint8_t options
Definition lr5.h:238
uint8_t * msg_data
Definition lr5.h:240
Click ctx object definition.
Definition lr5.h:197
uint16_t rx_cnt
Definition lr5.h:217
uart_t uart
Definition lr5.h:209
digital_in_t int_pin
Definition lr5.h:205
digital_out_t wk
Definition lr5.h:201
digital_out_t rst
Definition lr5.h:200
uint8_t command_code
Definition lr5.h:214
lr5_hdl_t driver_hdl
Definition lr5.h:218
uint8_t received_flag
Definition lr5.h:215