lr10  2.1.0.0
lr10.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 LR10_H
29 #define LR10_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
35 #include "drv_digital_out.h"
36 #include "drv_digital_in.h"
37 #include "drv_uart.h"
38 
59 #define LR10_CMD_AT "AT"
60 #define LR10_CMD_FDEFAULT "FDEFAULT"
61 #define LR10_CMD_RESET "RESET"
62 #define LR10_CMD_LOWPOWER "LOWPOWER"
63 #define LR10_CMD_VER "VER"
64 #define LR10_CMD_MSG "MSG"
65 #define LR10_CMD_MSGHEX "MSGHEX"
66 #define LR10_CMD_CMSG "CMSG"
67 #define LR10_CMD_CMSGHEX "CMSGHEX"
68 #define LR10_CMD_PMSG "PMSG"
69 #define LR10_CMD_PMSGHEX "PMSGHEX"
70 #define LR10_CMD_CH "CH"
71 #define LR10_CMD_DR "DR"
72 #define LR10_CMD_ADR "ADR"
73 #define LR10_CMD_REPT "REPT"
74 #define LR10_CMD_RETRY "RETRY"
75 #define LR10_CMD_POWER "POWER"
76 #define LR10_CMD_RXWIN2 "RXWIN2"
77 #define LR10_CMD_RXWIN1 "RXWIN1"
78 #define LR10_CMD_PORT "PORT"
79 #define LR10_CMD_MODE "MODE"
80 #define LR10_CMD_ID "ID"
81 #define LR10_CMD_KEY "KEY"
82 #define LR10_CMD_CLASS "CLASS"
83 #define LR10_CMD_JOIN "JOIN"
84 #define LR10_CMD_LW "LW"
85 #define LR10_CMD_BEACON "BEACON"
86 #define LR10_CMD_TEST "TEST"
87 #define LR10_CMD_UART "UART"
88 #define LR10_CMD_DELAY "DELAY"
89 #define LR10_CMD_VDD "VDD"
90 #define LR10_CMD_RTC "RTC"
91 #define LR10_CMD_EEPROM "EEPROM"
92 #define LR10_CMD_WDT "WDT"
93 #define LR10_CMD_TEMP "TEMP"
94 #define LR10_CMD_LOG "LOG"
95 
100 #define LR10_SUB_CMD_ID_DEVADDR "DEVADDR"
101 #define LR10_SUB_CMD_ID_DEVEUI "DEVEUI"
102 #define LR10_SUB_CMD_ID_APPEUI "APPEUI"
103 #define LR10_SUB_CMD_CH_NUM "NUM"
104 #define LR10_SUB_CMD_KEY_NWKSKEY "NWKSKEY"
105 #define LR10_SUB_CMD_KEY_APPSKEY "APPSKEY"
106 #define LR10_SUB_CMD_MODE_TEST "TEST"
107 #define LR10_SUB_CMD_MODE_LWOTAA "LWOTAA"
108 #define LR10_SUB_CMD_MODE_LWABP "LWABP"
109 #define LR10_SUB_CMD_JOIN_FORCE "FORCE"
110 #define LR10_SUB_CMD_JOIN_AUTO "AUTO"
111 #define LR10_SUB_CMD_BEACON_DMMUL "DMMUL"
112 #define LR10_SUB_CMD_BEACON_INFO "INFO"
113 #define LR10_SUB_CMD_BEACON_GWGPS "GWGPS"
114 #define LR10_SUB_CMD_DELAY_RX1 "RX1"
115 #define LR10_SUB_CMD_DELAY_RX2 "RX2"
116 #define LR10_SUB_CMD_DELAY_JRX1 "JRX1"
117 #define LR10_SUB_CMD_DELAY_JRX2 "JRX2"
118 #define LR10_SUB_CMD_LW_CDR "CDR"
119 #define LR10_SUB_CMD_LW_ULDL "ULDL"
120 #define LR10_SUB_CMD_LW_DC "DC"
121 #define LR10_SUB_CMD_LW_NET "NET"
122 #define LR10_SUB_CMD_LW_MC "MC"
123 #define LR10_SUB_CMD_LW_THLD "THLD"
124 #define LR10_SUB_CMD_LW_BAT "BAT"
125 #define LR10_SUB_CMD_LW_TPS "TPS"
126 #define LR10_SUB_CMD_LW_SCR "SCR"
127 #define LR10_SUB_CMD_LW_JDC "JDC"
128 #define LR10_SUB_CMD_LW_CT "CT"
129 #define LR10_SUB_CMD_LW_LEN "LEN"
130 #define LR10_SUB_CMD_LW_VER "VER"
131 #define LR10_SUB_CMD_LW_DTR "DTR"
132 #define LR10_SUB_CMD_LW_LCR "LCR"
133 #define LR10_SUB_CMD_LW_LDRO "LDRO"
134 #define LR10_SUB_CMD_LW_DCMRX "DCMRX"
135 #define LR10_SUB_CMD_LW_DUMRX "DUMRX"
136 #define LR10_SUB_CMD_LW_AFPACK "AFPACK"
137 #define LR10_SUB_CMD_LW_CHRB "CHRB"
138 #define LR10_SUB_CMD_RTC_ZONE "ZONE"
139 #define LR10_SUB_CMD_RTC_FULL "FULL"
140 #define LR10_SUB_CMD_RTC_LEAPSEC "LEAPSEC"
141 #define LR10_SUB_CMD_RTC_UTCMS "UTCMS"
142 #define LR10_SUB_CMD_EEPROM_ADDR "ADDR"
143 #define LR10_SUB_CMD_UART_TIMEOUT "TIMEOUT"
144 #define LR10_SUB_CMD_UART_BR "BR"
145 #define LR10_SUB_CMD_TEST_STOP "STOP"
146 #define LR10_SUB_CMD_TEST_HELP "HELP"
147 #define LR10_SUB_CMD_TEST_TXCW "TXCW"
148 #define LR10_SUB_CMD_TEST_TXCLORA "TXCLORA"
149 #define LR10_SUB_CMD_TEST_RFCFG "RFCFG"
150 #define LR10_SUB_CMD_TEST_RX "RXLRPKT"
151 #define LR10_SUB_CMD_TEST_TX_HEX "TXLRPKT"
152 #define LR10_SUB_CMD_TEST_TX_STR "TXLRSTR"
153 #define LR10_SUB_CMD_TEST_RSSI "RSSI"
154 #define LR10_SUB_CMD_LOG_DEBUG "DEBUG"
155 #define LR10_SUB_CMD_LOG_QUIET "QUIET"
156 
161 #define LR10_SYMBOL_END_CMD "\r\n"
162 #define LR10_SYMBOL_QUERY "?"
163 #define LR10_SYMBOL_SET_VAL_CMD "="
164 #define LR10_SYMBOL_PREFIX_CMD "+"
165 #define LR10_SYMBOL_SEPARATOR ","
166 #define LR10_SYMBOL_SPACE " "
167 #define LR10_SYMBOL_NULL ""
168 #define LR10_SYMBOL_QUOTE "\""
169 #define LR10_ASCII_SPACE 0x20
170 #define LR10_ASCII_QUOTE 0x22
171 
172 
178 #define LR10_TX_DRV_BUFFER_SIZE 100
179 #define LR10_RX_DRV_BUFFER_SIZE 300
180  // lr10_cmd
182 
197 #define LR10_MAP_MIKROBUS( cfg, mikrobus ) \
198  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
199  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
200  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST )
201  // lr10_map // lr10
204 
209 typedef struct
210 {
211  // Output pins
212  digital_out_t rst;
214  // Modules
215  uart_t uart;
217  // Buffers
218  uint8_t uart_rx_buffer[ LR10_RX_DRV_BUFFER_SIZE ];
219  uint8_t uart_tx_buffer[ LR10_TX_DRV_BUFFER_SIZE ];
221 } lr10_t;
222 
227 typedef struct
228 {
229  // Communication gpio pins
230  pin_name_t rx_pin;
231  pin_name_t tx_pin;
233  // Additional gpio pins
234  pin_name_t rst;
236  // Static variable
237  uint32_t baud_rate;
239  uart_data_bits_t data_bit;
240  uart_parity_t parity_bit;
241  uart_stop_bits_t stop_bit;
243 } lr10_cfg_t;
244 
249 typedef enum
250 {
251  LR10_OK = 0,
252  LR10_ERROR = -1
253 
255 
260 typedef enum
261 {
264 
266 
283 
297 err_t lr10_init ( lr10_t *ctx, lr10_cfg_t *cfg );
298 
307 void lr10_hw_reset ( lr10_t *ctx );
308 
321 err_t lr10_generic_write ( lr10_t *ctx, uint8_t *data_in, uint16_t len );
322 
335 err_t lr10_generic_read ( lr10_t *ctx, uint8_t *data_out, uint16_t len );
336 
348 err_t lr10_write_cmd ( lr10_t *ctx, uint8_t *command );
349 
362 err_t lr10_write_cmd_param ( lr10_t *ctx, uint8_t *command, uint8_t *param );
363 
380 err_t lr10_write_cmd_sub_param ( lr10_t *ctx, uint8_t *command, uint8_t *sub_param,
381  uint8_t *param, lr10_en_quote_t en_quote );
382 
394 err_t lr10_inquire_cmd ( lr10_t *ctx, uint8_t *command );
395 
396 
397 #ifdef __cplusplus
398 }
399 #endif
400 #endif // LR10_H
401  // lr10
403 
404 // ------------------------------------------------------------------------ END
lr10_cfg_setup
void lr10_cfg_setup(lr10_cfg_t *cfg)
LR 10 configuration object setup function.
lr10_cfg_t::rst
pin_name_t rst
Definition: lr10.h:234
lr10_hw_reset
void lr10_hw_reset(lr10_t *ctx)
LR 10 HW reset function.
lr10_init
err_t lr10_init(lr10_t *ctx, lr10_cfg_t *cfg)
LR 10 initialization function.
lr10_write_cmd_sub_param
err_t lr10_write_cmd_sub_param(lr10_t *ctx, uint8_t *command, uint8_t *sub_param, uint8_t *param, lr10_en_quote_t en_quote)
LR 10 command - subcommands - parameter writing function.
lr10_write_cmd
err_t lr10_write_cmd(lr10_t *ctx, uint8_t *command)
LR 10 command writing function.
lr10_en_quote_t
lr10_en_quote_t
LR 10 Click enable quote value data.
Definition: lr10.h:261
lr10_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: lr10.h:241
lr10_cfg_t::rx_pin
pin_name_t rx_pin
Definition: lr10.h:230
lr10_inquire_cmd
err_t lr10_inquire_cmd(lr10_t *ctx, uint8_t *command)
LR 10 inquire command function.
lr10_cfg_t
LR 10 Click configuration object.
Definition: lr10.h:228
lr10_cfg_t::baud_rate
uint32_t baud_rate
Definition: lr10.h:237
lr10_generic_read
err_t lr10_generic_read(lr10_t *ctx, uint8_t *data_out, uint16_t len)
LR 10 data reading function.
lr10_generic_write
err_t lr10_generic_write(lr10_t *ctx, uint8_t *data_in, uint16_t len)
LR 10 data writing function.
lr10_t
LR 10 Click context object.
Definition: lr10.h:210
lr10_return_value_t
lr10_return_value_t
LR 10 Click return value data.
Definition: lr10.h:250
lr10_write_cmd_param
err_t lr10_write_cmd_param(lr10_t *ctx, uint8_t *command, uint8_t *param)
LR 10 command - parameter writing function.
lr10_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: lr10.h:240
LR10_TX_DRV_BUFFER_SIZE
#define LR10_TX_DRV_BUFFER_SIZE
LR 10 driver buffer size.
Definition: lr10.h:178
LR10_RX_DRV_BUFFER_SIZE
#define LR10_RX_DRV_BUFFER_SIZE
Definition: lr10.h:179
lr10_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: lr10.h:239
lr10_cfg_t::uart_blocking
bool uart_blocking
Definition: lr10.h:238
LR10_ERROR
@ LR10_ERROR
Definition: lr10.h:252
lr10_cfg_t::tx_pin
pin_name_t tx_pin
Definition: lr10.h:231
LR10_OK
@ LR10_OK
Definition: lr10.h:251
lr10_t::uart
uart_t uart
Definition: lr10.h:215
LR10_QUOTE_ENABLE
@ LR10_QUOTE_ENABLE
Definition: lr10.h:263
lr10_t::rst
digital_out_t rst
Definition: lr10.h:212
LR10_QUOTE_DISABLE
@ LR10_QUOTE_DISABLE
Definition: lr10.h:262