lr3 2.0.0.0
lr3.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 LR3_H
36#define LR3_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 LR3_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 LR3_RETVAL uint8_t
79
80#define LR3_OK 0x00
81#define LR3_INIT_ERROR 0xFF
88#define FRAME_HEADER 0xAA
89#define RESPONSE_BIT 0x80
96#define LR3_CMD_RESET 0x30
97#define LR3_CMD_FACTORY_RESET 0x31
98#define LR3_CMD_EEPROM_WRITE 0x32
99#define LR3_CMD_EEPROM_READ 0x33
100#define LR3_CMD_GET_FW_VERSION 0x34
101#define LR3_CMD_GET_SERIAL_NO 0x35
102#define LR3_ENABLE_PAIRING 0x40
103#define LR3_GET_NETWORK_TABLE_SIZE 0x42
104#define LR3_GET_NETWORK_TABLE_ROW 0x43
105#define LR3_DEL_NET_TABLE_ROW 0x44
106#define LR3_DEL_ALL_NETWORK_TABLE 0x45
107#define LR3_GET_PAIRING_REQUEST 0x48
108#define LR3_GET_ACTIVATION_STATUS 0x4A
109#define LR3_TX_MESSAGE 0x50
110#define LR3_CHECK_LINK_REQUEST 0x56
111#define LR3_SET_APP_KEY 0x58
112
113#define LR3_INDICATES_DEVICE_PAIRING 0x41
114#define LR3_INDICATES_PAIRING_CONFIRM 0x49
115#define LR3_INDICATES_TX_MSG_CONFIRMED 0x51
116#define LR3_INDICATES_TX_MSG_UNCONFIRMED 0x52
117#define LR3_INDICATES_RX_MSG 0x53
118#define LR3_INDICATES_LINK_CHECK 0x57
119#define LR3_INDICATES_TX_SESSION_ABORT 0x59
120
121#define LR3_OK 0x00
122#define LR3_ERR_ADDR_RANGE 0x01
123#define LR3_ERR_NOT_IDLE 0x02
124
125#define LR3_ERR_PL_LEN 0xFC
126#define LR3_ERR_CHKSUM 0xFD
127#define LR3_ERR_RESPONSE 0xFE
128#define LR3_ERR_HEADER 0xFF
129
130#define LR3_UNCONFIRMED_DATA_TX 0x00
131#define LR3_CONFIRMED_DATA_TX 0x01
132
133#define LR3_BROADCAST_MESSAGE 0xFFFFFFFF
140#define LR3_MODULE_POWER_ON 1
141#define LR3_MODULE_POWER_OFF 0
148#define DRV_RX_BUFFER_SIZE 500
151 // End group macro
152// --------------------------------------------------------------- PUBLIC TYPES
161typedef void ( *lr3_ind_hdl_t )( uint8_t *cmd, uint8_t* p_load_size, uint8_t *p_load );
162
166typedef struct
167{
168 // Output pins
169
170 digital_out_t rst;
171 digital_out_t wk;
172
173 // Input pins
174
175 digital_in_t int_pin;
176
177 // Modules
178
179 uart_t uart;
180
181 char uart_rx_buffer[ DRV_RX_BUFFER_SIZE ];
182 char uart_tx_buffer[ DRV_RX_BUFFER_SIZE ];
183
185} lr3_t;
186
190typedef struct
191{
192 // Communication gpio pins
193
194 pin_name_t rx_pin;
195 pin_name_t tx_pin;
196
197 // Additional gpio pins
198
199 pin_name_t rst;
200 pin_name_t wk;
201 pin_name_t int_pin;
202
203 // static variable
204
205 uint32_t baud_rate; // Clock speed.
207 uart_data_bits_t data_bit; // Data bits.
208 uart_parity_t parity_bit; // Parity bit.
209 uart_stop_bits_t stop_bit; // Stop bits.
210
211} lr3_cfg_t;
212
213typedef struct {
214
215 uint8_t command;
217 uint8_t payload[ 255 ];
218
220
221typedef struct {
222
223 uint8_t *data_in;
224 uint8_t n_bytes;
226 uint8_t option;
227
229
230 // End types group
231// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
232
238#ifdef __cplusplus
239extern "C"{
240#endif
241
251
261
272uint8_t lr3_chk_sum ( lr3_message_t *cmd );
273
285int32_t lr3_generic_read ( lr3_t *ctx, char *data_buf, uint16_t max_len );
286
293void lr3_generic_write ( lr3_t *ctx, char *data_buf, uint16_t len );
294
302void lr3_hard_reset ( lr3_t *ctx );
303
312void lr3_wake_up ( lr3_t *ctx, uint8_t state );
313
323
336uint8_t lr3_command ( lr3_t *ctx, lr3_message_t *msg, lr3_message_t *rsp );
337
347
358
370
384LR3_RETVAL lr3_write_eeprom ( lr3_t *ctx, uint8_t address, uint8_t n_bytes, uint8_t *data_in );
385
399LR3_RETVAL lr3_read_eeprom ( lr3_t *ctx, uint8_t address, uint8_t n_bytes, uint8_t *data_out );
400
411LR3_RETVAL lr3_get_fw_version ( lr3_t *ctx, uint32_t *fw_version );
412
423LR3_RETVAL lr3_get_serial_no ( lr3_t *ctx, uint32_t *serial_no );
424
439LR3_RETVAL lr3_enable_pairing ( lr3_t *ctx, uint8_t state );
440
452
465LR3_RETVAL lr3_get_network_table_row( lr3_t *ctx, uint8_t index, uint8_t *data_out );
466
478LR3_RETVAL lr3_delete_network_table_row ( lr3_t *ctx, uint8_t *device_id );
479
490
511
522
534LR3_RETVAL lr3_get_activation_status ( lr3_t *ctx, uint8_t *data_out );
535
550LR3_RETVAL lr3_check_link_request ( lr3_t *ctx, uint8_t power, uint8_t message_num, uint8_t message_th );
551
563LR3_RETVAL lr3_set_app_key ( lr3_t *ctx, uint8_t *app_key );
564
565#ifdef __cplusplus
566}
567#endif
568#endif // _LR3_H_
569
570 // End public_function group
572
573// ------------------------------------------------------------------------- END
#define DRV_RX_BUFFER_SIZE
Definition lr3.h:148
#define LR3_RETVAL
Definition lr3.h:78
void lr3_generic_write(lr3_t *ctx, char *data_buf, uint16_t len)
Generic write function.
void lr3_set_ind_handler(lr3_t *ctx, lr3_ind_hdl_t hdl)
Set indication handler function.
void lr3_wake_up(lr3_t *ctx, uint8_t state)
Wake Up function.
uint8_t lr3_command(lr3_t *ctx, lr3_message_t *msg, lr3_message_t *rsp)
Command function.
LR3_RETVAL lr3_delete_network_table_row(lr3_t *ctx, uint8_t *device_id)
Delete Network Table Row function.
void lr3_cfg_setup(lr3_cfg_t *cfg)
Config Object Initialization function.
int32_t lr3_generic_read(lr3_t *ctx, char *data_buf, uint16_t max_len)
Generic read function.
LR3_RETVAL lr3_read_eeprom(lr3_t *ctx, uint8_t address, uint8_t n_bytes, uint8_t *data_out)
EEPROM read function.
uint8_t lr3_chk_sum(lr3_message_t *cmd)
Check sum function.
LR3_RETVAL lr3_get_serial_no(lr3_t *ctx, uint32_t *serial_no)
Get Serial Number function.
LR3_RETVAL lr3_factory_reset(lr3_t *ctx)
Factory reset function.
LR3_RETVAL lr3_init(lr3_t *ctx, lr3_cfg_t *cfg)
Initialization function.
LR3_RETVAL lr3_write_eeprom(lr3_t *ctx, uint8_t address, uint8_t n_bytes, uint8_t *data_in)
EEPROM write function.
LR3_RETVAL lr3_soft_reset(lr3_t *ctx)
Software reset function.
LR3_RETVAL lr3_get_pairing_request(lr3_t *ctx)
Get Pairing Request function.
LR3_RETVAL lr3_check_link_request(lr3_t *ctx, uint8_t power, uint8_t message_num, uint8_t message_th)
Radio frame Transmission function.
uint8_t lr3_read_message_process(lr3_t *ctx)
Process function.
LR3_RETVAL lr3_get_activation_status(lr3_t *ctx, uint8_t *data_out)
Get Activation Status function.
LR3_RETVAL lr3_get_fw_version(lr3_t *ctx, uint32_t *fw_version)
Get FW Version function.
LR3_RETVAL lr3_enable_pairing(lr3_t *ctx, uint8_t state)
Enable Pairing function.
LR3_RETVAL lr3_set_app_key(lr3_t *ctx, uint8_t *app_key)
Set App Key function.
LR3_RETVAL lr3_delete_all_network_table(lr3_t *ctx)
Delete All Network Table function.
void lr3_hard_reset(lr3_t *ctx)
Hardware reset function.
LR3_RETVAL lr3_tx_message(lr3_t *ctx, lr3_tx_msg_t *tx_msg)
Radio frame Transmission function.
LR3_RETVAL lr3_get_network_table_row(lr3_t *ctx, uint8_t index, uint8_t *data_out)
Get Network Table Row function.
LR3_RETVAL lr3_get_network_table_size(lr3_t *ctx)
Get Network Table Size function.
void(* lr3_ind_hdl_t)(uint8_t *cmd, uint8_t *p_load_size, uint8_t *p_load)
LR3_TYPES Types.
Definition lr3.h:161
Click configuration structure definition.
Definition lr3.h:191
uint32_t baud_rate
Definition lr3.h:205
pin_name_t wk
Definition lr3.h:200
bool uart_blocking
Definition lr3.h:206
uart_data_bits_t data_bit
Definition lr3.h:207
pin_name_t tx_pin
Definition lr3.h:195
pin_name_t rx_pin
Definition lr3.h:194
uart_stop_bits_t stop_bit
Definition lr3.h:209
pin_name_t int_pin
Definition lr3.h:201
uart_parity_t parity_bit
Definition lr3.h:208
pin_name_t rst
Definition lr3.h:199
Definition lr3.h:213
uint8_t command
Definition lr3.h:215
uint8_t payload_size
Definition lr3.h:216
Click ctx object definition.
Definition lr3.h:167
uart_t uart
Definition lr3.h:179
digital_in_t int_pin
Definition lr3.h:175
digital_out_t wk
Definition lr3.h:171
digital_out_t rst
Definition lr3.h:170
lr3_ind_hdl_t ind_handler
Definition lr3.h:184
Definition lr3.h:221
uint8_t option
Definition lr3.h:226
uint8_t n_bytes
Definition lr3.h:224
uint8_t * data_in
Definition lr3.h:223
uint32_t destination_id
Definition lr3.h:225