nanolr 2.0.0.0
nanolr.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 NANOLR_H
36#define NANOLR_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 NANOLR_MAP_MIKROBUS( cfg, mikrobus ) \
67 cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
68 cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
69 cfg.st = MIKROBUS( mikrobus, MIKROBUS_AN ); \
70 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
71 cfg.cts = MIKROBUS( mikrobus, MIKROBUS_CS ); \
72 cfg.gp1 = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
73 cfg.rts = MIKROBUS( mikrobus, MIKROBUS_INT )
80#define NANOLR_RETVAL uint8_t
81
82#define NANOLR_OK 0x00
83#define NANOLR_INIT_ERROR 0xFF
90#define NANOLR_CMD_DEV_INFO 0x01
91#define NANOLR_CMD_DEV_STATE 0x04
92#define NANOLR_CMD_RESET 0x05
93#define NANOLR_CMD_FW_VER 0x06
94#define NANOLR_CMD_RESTORE_DEF_SETTINGS 0x07
95#define NANOLR_CMD_SAVE_SETTINGS 0x08
96#define NANOLR_CMD_SERIAL_PORT_CFG 0x09
97#define NANOLR_CMD_OUTPUT_POWER 0x10
98#define NANOLR_CMD_OP_CHAN 0x11
99#define NANOLR_CMD_ENERGY_SAVE 0x13
100#define NANOLR_CMD_PHYSICAL_ADR 0x20
101#define NANOLR_CMD_NETWORK_ADR 0x21
102#define NANOLR_CMD_NETWORK_ID 0x22
103#define NANOLR_CMD_NETWORK_ROLE 0x23
104#define NANOLR_CMD_NETWORK_AUTO_SETTINGS 0x24
105#define NANOLR_CMD_NETWORK_PREF 0x25
106#define NANOLR_CMD_NETWORK_SECURITY 0x26
107#define NANOLR_CMD_NETWORK_JOIN_MODE 0x27
108#define NANOLR_CMD_NETWORK_STOP 0x30
109#define NANOLR_CMD_NETWORK_START 0x31
110#define NANOLR_CMD_SEND_DATA 0x50
111#define NANOLR_CMD_RECEIVED_DATA 0x60
112#define NANOLR_CMD_ENTER_BOOTLOADER 0x70
119#define NANOLR_SET_BOOTLOADER_OPTIONS 0x71
120#define NANOLR_ERASE_MEM 0x78
121#define NANOLR_WRITE_MEM_CHUNK 0x7A
122#define NANOLR_READ_MEM_CHUNK 0x7B
123#define NANOLR_COMMIT_FW 0x7F
130#define NANOLR_SUCCESS 0x00
131#define NANOLR_GENERIC_ERROR 0x01
132#define NANOLR_PARAM_NOT_ACCEPTED 0x02
133#define NANOLR_OPERATION_TIMEOUT 0x03
134#define NANOLR_NO_MEMORY 0x04
135#define NANOLR_UNSUPPORTED 0x05
136#define NANOLR_BUSY 0x06
143#define NANOLR_DEV_INFO_RESP 0x81
144#define NANOLR_DEV_STATE_RESP 0x84
145#define NANOLR_RESET_RESP 0x85
146#define NANOLR_FW_VER_RESP 0x86
147#define NANOLR_RESTORE_DEF_SETTINGS_RESP 0x87
148#define NANOLR_SAVE_SETTINGS_RESP 0x88
149#define NANOLR_SERIAL_PORT_CFG_RESP 0x89
150#define NANOLR_OUTPUT_POWER_RESP 0x90
151#define NANOLR_OP_CHAN_RESP 0x91
152#define NANOLR_ENERGY_SAVE_RESP 0x93
153#define NANOLR_PHYSICAL_ADR_RESP 0xA0
154#define NANOLR_NETWORK_ADR_RESP 0xA1
155#define NANOLR_NETWORK_ID_RESP 0xA2
156#define NANOLR_NETWORK_ROLE_RESP 0xA3
157#define NANOLR_NETWORK_AUTO_SETTINGS_RESP 0xA4
158#define NANOLR_NETWORK_PREF_RESP 0xA5
159#define NANOLR_NETWORK_SECURITY_RESP 0xA6
166#define NANOLR_BAUD_RATE_MAINTAIN_SPEED 0x00
167#define NANOLR_BAUD_RATE_1200 0x01
168#define NANOLR_BAUD_RATE_2400 0x02
169#define NANOLR_BAUD_RATE_4800 0x03
170#define NANOLR_BAUD_RATE_9600 0x04
171#define NANOLR_BAUD_RATE_19200 0x05
172#define NANOLR_BAUD_RATE_38400 0x06
173#define NANOLR_BAUD_RATE_57600 0x07
174#define NANOLR_BAUD_RATE_115200 0x08
181#define NANOLR_DEVICE_ID_UNKNOWN 0x00
182#define NANOLR_DEVICE_ID_EMB_ZRF2XX 0x20
183#define NANOLR_DEVICE_ID_EMB_ZRF231XX 0x24
184#define NANOLR_DEVICE_ID_EMB_ZRF231PA 0x26
185#define NANOLR_DEVICE_ID_EMB_ZRF212XX 0x28
186#define NANOLR_DEVICE_ID_EMB_ZRF212B 0x29
187#define NANOLR_DEVICE_ID_EMB_Z253X 0x30
188#define NANOLR_DEVICE_ID_EMB_Z2530X 0x34
189#define NANOLR_DEVICE_ID_EMB_Z2530PA 0x36
190#define NANOLR_DEVICE_ID_EMB_Z2531X 0x38
191#define NANOLR_DEVICE_ID_EMB_Z2531PA_USB 0x3A
192#define NANOLR_DEVICE_ID_EMB_Z2538X 0x3C
193#define NANOLR_DEVICE_ID_EMB_Z2538PA 0x3D
194#define NANOLR_DEVICE_ID_EMB_WMBX 0x40
195#define NANOLR_DEVICE_ID_EMB_WMB169X 0x44
196#define NANOLR_DEVICE_ID_EMB_WMB169T 0x45
197#define NANOLR_DEVICE_ID_EMB_WMB169PA 0x46
198#define NANOLR_DEVICE_ID_EMB_WMB868X 0x48
199#define NANOLR_DEVICE_ID_EMB_WMB868 0x49
200#define NANOLR_DEVICE_ID_EMB_LRX 0x50
201#define NANOLR_DEVICE_ID_EMB_LR1272 0x54
208#define NANOLR_NETWORK_ROLE_COORDINATOR 0x00
209#define NANOLR_NETWORK_ROLE_RESERVED 0x01
210#define NANOLR_NETWORK_ROLE_END_DEV 0x02
217#define NANOLR_DEV_STATE_BOOTING 0x00
218#define NANOLR_DEV_STATE_INSIDE_BOOTLOADER 0x01
219#define NANOLR_DEV_STATE_RDY_STARTUP_OP_SUCC 0x10
220#define NANOLR_DEV_STATE_RDY_STARTUP_OP_FAILED 0x11
221#define NANOLR_DEV_STATE_OFFLINE 0x20
222#define NANOLR_DEV_STATE_CONNECTING 0x21
223#define NANOLR_DEV_STATE_TRANSPARENT_MODE_STARTUP 0x22
224#define NANOLR_DEV_STATE_ONLINE 0x30
225#define NANOLR_DEV_STATE_DISCONNECTING 0x40
226#define NANOLR_DEV_STATE_RESERVED 0x50
227#define NANOLR_DEV_STATE_END_RECEIVING_WINDOW 0x51
234#define NANOLR_ENERGY_SAVE_MODE_ALWAYS_ON 0x00
235#define NANOLR_ENERGY_SAVE_MODE_RX_WINDOW 0x01
236#define NANOLR_ENERGY_SAVE_MODE_TX_ONLY 0x02
243#define NANOLR_OP_CHANNEL_CH_1_868_1MHz 0x01
244#define NANOLR_OP_CHANNEL_CH_2_868_3MHz 0x02
245#define NANOLR_OP_CHANNEL_CH_3_868_5MHz 0x03
246#define NANOLR_OP_CHANNEL_CH_4_869_525MHz 0x04
247#define NANOLR_OP_CHANNEL_SPR_FCT_128 0x07
248#define NANOLR_OP_CHANNEL_SPR_FCT_256 0x08
249#define NANOLR_OP_CHANNEL_SPR_FCT_512 0x09
250#define NANOLR_OP_CHANNEL_SPR_FCT_1024 0x0A
251#define NANOLR_OP_CHANNEL_SPR_FCT_2048 0x0B
252#define NANOLR_OP_CHANNEL_SPR_FCT_4096 0x0C
253#define NANOLR_OP_CHANNEL_BANDWIDTH_125KHz 0x00
254#define NANOLR_OP_CHANNEL_BANDWIDTH_250KHz 0x01
255#define NANOLR_OP_CHANNEL_CODING_RATE_4_5 0x01
256#define NANOLR_OP_CHANNEL_CODING_RATE_4_6 0x02
257#define NANOLR_OP_CHANNEL_CODING_RATE_4_7 0x03
258#define NANOLR_OP_CHANNEL_CODING_RATE_4_8 0x04
265#define NANOLR_NTW_ROLE_COORDINATOR 0x00
266#define NANOLR_NTW_ROLE_END_DEVICE 0x02
273#define NANOLR_NTW_PREFERENCE_PROTOCOL_LR_EMB 0x00
274#define NANOLR_NTW_PREFERENCE_PROTOCOL_LR_WAN 0x80
275#define NANOLR_NTW_PREFERENCE_AUTO_JOIN_DISABLE 0x00
276#define NANOLR_NTW_PREFERENCE_AUTO_JOIN_ENABLE 0x40
277#define NANOLR_NTW_PREFERENCE_ADAPTIVE_DATA_RATE_DISABLE 0x00
278#define NANOLR_NTW_PREFERENCE_ADAPTIVE_DATA_RATE_ENABLE 0x20
285#define NANOLR_NTW_JOIN_MODE_ABP 0x00
286#define NANOLR_NTW_JOIN_MODE_OTAA 0x01
287
288#define NANOLR_RSP_READY 0x01
289#define NANOLR_RSP_NOT_READY 0x00
290
291#define NANOLR_ERR_CRC 0x01
292#define NANOLR_ERR_STATUS_OK 0x00
299#define DRV_RX_BUFFER_SIZE 500
302 // End group macro
303// --------------------------------------------------------------- PUBLIC TYPES
313#define nanolr_err_t uint8_t
314
318typedef struct
319{
320 // Output pins
321
322 digital_out_t st;
323 digital_out_t rst;
324 digital_out_t cts;
325
326 // Input pins
327
328 digital_in_t gp1;
329 digital_in_t rts;
330
331 // Modules
332
333 uart_t uart;
334
335 char uart_rx_buffer[ DRV_RX_BUFFER_SIZE ];
336 char uart_tx_buffer[ DRV_RX_BUFFER_SIZE ];
337
338 char rx_data[ 256 ];
339 uint16_t rsp_len;
340 uint8_t rsp_rdy;
341
342} nanolr_t;
343
347typedef struct
348{
349 // Communication gpio pins
350
351 pin_name_t rx_pin;
352 pin_name_t tx_pin;
353
354 // Additional gpio pins
355
356 pin_name_t st;
357 pin_name_t rst;
358 pin_name_t cts;
359 pin_name_t gp1;
360 pin_name_t rts;
361
362 // static variable
363
364 uint32_t baud_rate; // Clock speed.
366 uart_data_bits_t data_bit; // Data bits.
367 uart_parity_t parity_bit; // Parity bit.
368 uart_stop_bits_t stop_bit; // Stop bits.
369
371
375typedef struct
376{
377 uint16_t length;
378 uint8_t message_id;
379 uint8_t payload[ 256 ];
380 uint8_t crc;
381
383
387typedef struct
388{
389 uint8_t channel;
391 uint8_t bandwidth;
392 uint8_t coding_rate;
393
395
396 // End types group
397// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
398
404#ifdef __cplusplus
405extern "C"{
406#endif
407
417
427
436
444void nanolr_reset ( nanolr_t *ctx );
445
455void nanolr_generic_write ( nanolr_t *ctx, char *data_buf, uint16_t len );
456
468int32_t nanolr_generic_read ( nanolr_t *ctx, char *data_buf, uint16_t max_len );
469
480
489void nanolr_clear_2_send ( nanolr_t *ctx, uint8_t state );
490
501
510void nanolr_set_st_pin ( nanolr_t *ctx, uint8_t state );
511
520
529
538
547
556
565
574
583
592void nanolr_set_output_power ( nanolr_t *ctx, uint8_t out_pwr );
593
636
647
657
667
676
688void nanolr_set_physical_address ( nanolr_t *ctx, uint8_t *app_eui, uint8_t *dev_eui );
689
708
721void nanolr_set_network_address ( nanolr_t *ctx, uint16_t ntw_addr );
722
740
749void nanolr_set_network_id ( nanolr_t *ctx, uint16_t ntw_id );
750
759
775void nanolr_set_network_role ( nanolr_t *ctx, uint8_t ntw_role );
776
785
794
825void nanolr_set_network_preference ( nanolr_t *ctx, uint8_t prot, uint8_t auto_join, uint8_t adr );
826
835
848void nanolr_set_network_join_mode ( nanolr_t *ctx, uint8_t ntw_join_mode );
849
858
867
876
886
895
904
925void nanolr_send_data ( nanolr_t *ctx, uint8_t *tx_data, uint8_t length );
926
936uint8_t nanolr_rsp_rdy ( nanolr_t *ctx );
937
947
958
959#ifdef __cplusplus
960}
961#endif
962#endif // _NANOLR_H_
963
964 // End public_function group
966
967// ------------------------------------------------------------------------- END
#define DRV_RX_BUFFER_SIZE
Definition nanolr.h:299
#define NANOLR_RETVAL
Definition nanolr.h:80
void nanolr_get_network_preference(nanolr_t *ctx)
Get network preference function.
int32_t nanolr_generic_read(nanolr_t *ctx, char *data_buf, uint16_t max_len)
Generic read function.
void nanolr_get_operating_channel(nanolr_t *ctx)
Get operating channel function.
void nanolr_get_device_state(nanolr_t *ctx)
Get device state function.
void nanolr_network_start(nanolr_t *ctx)
Network start function.
void nanolr_send_data(nanolr_t *ctx, uint8_t *tx_data, uint8_t length)
Send data function.
void nanolr_save_energy_rx_window(nanolr_t *ctx)
Save energy rx window function.
void nanolr_sw_reset(nanolr_t *ctx)
Software reset function.
void nanolr_network_stop(nanolr_t *ctx)
Network stop function.
void nanolr_get_network_address(nanolr_t *ctx)
Get network address function.
void nanolr_save_settings(nanolr_t *ctx)
Restore to factory function.
void nanolr_get_network_id(nanolr_t *ctx)
Get network identifiers function.
uint8_t nanolr_rsp_rdy(nanolr_t *ctx)
Check response ready function.
void nanolr_save_energy_tx_only(nanolr_t *ctx)
Save energy tx only function.
uint8_t nanolr_get_gp1_pin(nanolr_t *ctx)
Get GP1 pin state function.
void nanolr_save_energy_always_on(nanolr_t *ctx)
Save energy on function.
void nanolr_get_network_auto_settings(nanolr_t *ctx)
Get network automated settings function.
void nanolr_get_network_join_mode(nanolr_t *ctx)
Get network join mode function.
void nanolr_restore_2_factory(nanolr_t *ctx)
Restore to factory function.
void nanolr_reset(nanolr_t *ctx)
Reset module.
uint8_t nanolr_request_2_send(nanolr_t *ctx)
Request to Send function.
void nanolr_default_cfg(nanolr_t *ctx)
Click Default Configuration function.
void nanolr_get_wan_network_type(nanolr_t *ctx)
Get LRWAN network type function.
void nanolr_set_network_address(nanolr_t *ctx, uint16_t ntw_addr)
Set network address function.
void nanolr_clear_2_send(nanolr_t *ctx, uint8_t state)
Clear to Send function.
void nanolr_set_network_preference(nanolr_t *ctx, uint8_t prot, uint8_t auto_join, uint8_t adr)
Set network preference function.
void nanolr_set_network_role(nanolr_t *ctx, uint8_t ntw_role)
Set network role function.
void nanolr_get_network_role(nanolr_t *ctx)
Get network role function.
void nanolr_get_output_power(nanolr_t *ctx)
Get output power function.
nanolr_err_t nanolr_parser_rsp(nanolr_t *ctx, nanolr_rsp_t *response)
Response parser function.
NANOLR_RETVAL nanolr_init(nanolr_t *ctx, nanolr_cfg_t *cfg)
Initialization function.
void nanolr_cfg_setup(nanolr_cfg_t *cfg)
Config Object Initialization function.
void nanolr_set_network_id(nanolr_t *ctx, uint16_t ntw_id)
Set network identifiers function.
void nanolr_uart_isr(nanolr_t *ctx)
UART ISR function.
void nanolr_get_device_info(nanolr_t *ctx)
Get device information function.
void nanolr_get_battery_level(nanolr_t *ctx)
Get battery level function.
void nanolr_set_physical_address(nanolr_t *ctx, uint8_t *app_eui, uint8_t *dev_eui)
Set physical address function.
void nanolr_set_st_pin(nanolr_t *ctx, uint8_t state)
Set ST pin state function.
void nanolr_get_physical_address(nanolr_t *ctx)
Get physical address function.
void nanolr_set_output_power(nanolr_t *ctx, uint8_t out_pwr)
Set output power function.
void nanolr_set_operating_channel(nanolr_t *ctx, nanolr_network_t *net)
Set operating channel function.
void nanolr_generic_write(nanolr_t *ctx, char *data_buf, uint16_t len)
Generic write function.
void nanolr_wan_network_private(nanolr_t *ctx)
Set LRWAN network type private function.
void nanolr_wan_network_public(nanolr_t *ctx)
Set LRWAN network type public function.
void nanolr_set_network_join_mode(nanolr_t *ctx, uint8_t ntw_join_mode)
Set network join mode function.
void nanolr_get_fw_ver(nanolr_t *ctx)
Get firmware version function.
#define nanolr_err_t
Driver Error type.
Definition nanolr.h:313
Click configuration structure definition.
Definition nanolr.h:348
pin_name_t rts
Definition nanolr.h:360
pin_name_t st
Definition nanolr.h:356
uint32_t baud_rate
Definition nanolr.h:364
pin_name_t cts
Definition nanolr.h:358
bool uart_blocking
Definition nanolr.h:365
uart_data_bits_t data_bit
Definition nanolr.h:366
pin_name_t tx_pin
Definition nanolr.h:352
pin_name_t rx_pin
Definition nanolr.h:351
uart_stop_bits_t stop_bit
Definition nanolr.h:368
pin_name_t gp1
Definition nanolr.h:359
uart_parity_t parity_bit
Definition nanolr.h:367
pin_name_t rst
Definition nanolr.h:357
Click network structure definition.
Definition nanolr.h:388
uint8_t spreading_factor
Definition nanolr.h:390
uint8_t coding_rate
Definition nanolr.h:392
uint8_t channel
Definition nanolr.h:389
uint8_t bandwidth
Definition nanolr.h:391
Click response structure definition.
Definition nanolr.h:376
uint16_t length
Definition nanolr.h:377
uint8_t message_id
Definition nanolr.h:378
uint8_t crc
Definition nanolr.h:380
Click ctx object definition.
Definition nanolr.h:319
uint16_t rsp_len
Definition nanolr.h:339
digital_in_t gp1
Definition nanolr.h:328
uart_t uart
Definition nanolr.h:333
uint8_t rsp_rdy
Definition nanolr.h:340
digital_in_t rts
Definition nanolr.h:329
digital_out_t st
Definition nanolr.h:322
digital_out_t rst
Definition nanolr.h:323
digital_out_t cts
Definition nanolr.h:324