neomesh868mhz  2.1.0.0
neomesh868mhz.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 NEOMESH868MHZ_H
29 #define NEOMESH868MHZ_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
35 #include "mikrosdk_version.h"
36 
37 #ifdef __GNUC__
38 #if mikroSDK_GET_VERSION < 20800ul
39 #include "rcu_delays.h"
40 #else
41 #include "delays.h"
42 #endif
43 #endif
44 
45 #include "drv_digital_out.h"
46 #include "drv_digital_in.h"
47 #include "drv_uart.h"
48 
69 #define NEOMESH868MHZ_CMD_NACK_SEND 0x02
70 #define NEOMESH868MHZ_CMD_ACK_SEND 0x03
71 #define NEOMESH868MHZ_CMD_NODE_STATUS 0x07
72 #define NEOMESH868MHZ_CMD_NODE_INFO 0x08
73 #define NEOMESH868MHZ_CMD_NEIGHBOUR_LIST 0x09
74 #define NEOMESH868MHZ_CMD_NETWORK_COMMAND 0x0A
75 #define NEOMESH868MHZ_CMD_SAPI_TO_AAPI 0x0B
76 #define NEOMESH868MHZ_CMD_ROUTE_INFO 0x0C
77 #define NEOMESH868MHZ_CMD_WES_COMMAND 0x10
78 #define NEOMESH868MHZ_CMD_WES_SETUP_RSP 0x11
79 #define NEOMESH868MHZ_CMD_GET_SW_VERSION 0x14
80 #define NEOMESH868MHZ_CMD_ALT_MODE 0x20
81 
86 #define NEOMESH868MHZ_RSP_ACK 0x50
87 #define NEOMESH868MHZ_RSP_NACK 0x51
88 #define NEOMESH868MHZ_RSP_ACK_HOST 0x52
89 #define NEOMESH868MHZ_RSP_ACK_HOST_HAPA 0x53
90 #define NEOMESH868MHZ_RSP_NACK_HOST 0x54
91 #define NEOMESH868MHZ_RSP_NACK_HOST_HAPA 0x55
92 #define NEOMESH868MHZ_RSP_NACK_SEND 0x56
93 #define NEOMESH868MHZ_RSP_NACK_DROP 0x57
94 #define NEOMESH868MHZ_RSP_NODE_INFO 0x58
95 #define NEOMESH868MHZ_RSP_NEIGHBOUR_LIST 0x59
96 #define NEOMESH868MHZ_RSP_NETWORK_COMMAND 0x5A
97 #define NEOMESH868MHZ_RSP_ROUTE_INFO 0x5C
98 #define NEOMESH868MHZ_RSP_WES_STATUS 0x60
99 #define NEOMESH868MHZ_RSP_WES_SETUP 0x61
100 #define NEOMESH868MHZ_RSP_GET_SW_VERSION 0x64
101 #define NEOMESH868MHZ_RSP_ALT_MODE 0x70
102 
107 #define NEOMESH868MHZ_SAPI_CMD_LOGIN 0x0103u
108 #define NEOMESH868MHZ_SAPI_CMD_RESET_LIST_ITERATOR 0x0104u
109 #define NEOMESH868MHZ_SAPI_CMD_GET_LIST 0x0105u
110 #define NEOMESH868MHZ_SAPI_CMD_GET_SETTING_FLASH 0x0106u
111 #define NEOMESH868MHZ_SAPI_CMD_GET_SETTING_RAM 0x0107u
112 #define NEOMESH868MHZ_SAPI_CMD_COMMIT_SETTINGS 0x0108u
113 #define NEOMESH868MHZ_SAPI_CMD_DISCARD_SETTINGS 0x0109u
114 #define NEOMESH868MHZ_SAPI_CMD_SET_SETTING 0x010Au
115 #define NEOMESH868MHZ_SAPI_CMD_START_PROTOCOL_STACK 0x0112u
116 #define NEOMESH868MHZ_SAPI_CMD_START_BOOTLOADER 0x0113u
117 #define NEOMESH868MHZ_SAPI_HEADER 0x3E
118 #define NEOMESH868MHZ_SAPI_TRAIL 0x21
119 
124 #define NEOMESH868MHZ_SAPI_RSP_OK 0x0380u
125 #define NEOMESH868MHZ_SAPI_RSP_ERROR 0x0381u
126 #define NEOMESH868MHZ_SAPI_RSP_BOOTLOADER_START 0x0382u
127 #define NEOMESH868MHZ_SAPI_RSP_PROTOCOL_STACK_START 0x0383u
128 #define NEOMESH868MHZ_SAPI_RSP_PROTOCOL_STACK_ERROR 0x0384u
129 #define NEOMESH868MHZ_SAPI_RSP_RESET 0x0385u
130 #define NEOMESH868MHZ_SAPI_RSP_SETTINGS_LIST_OUTPUT 0x0185u
131 #define NEOMESH868MHZ_SAPI_RSP_SETTINGS_VALUE 0x0186u
132 
137 #define NEOMESH868MHZ_SAPI_LOGIN_PASSWORD_0 0x4C
138 #define NEOMESH868MHZ_SAPI_LOGIN_PASSWORD_1 0x76
139 #define NEOMESH868MHZ_SAPI_LOGIN_PASSWORD_2 0x6C
140 #define NEOMESH868MHZ_SAPI_LOGIN_PASSWORD_3 0x31
141 #define NEOMESH868MHZ_SAPI_LOGIN_PASSWORD_4 0x30
142 
147 #define NEOMESH868MHZ_SAPI_SETTINGS_ID_NODE_ID 0x0A
148 
153 #define NEOMESH868MHZ_TIMEOUT_MS 20000ul
154 
159 #define NEOMESH868MHZ_MAX_PAYLOAD_LEN 255
160 
166 #define NEOMESH868MHZ_TX_DRV_BUFFER_SIZE 300u
167 #define NEOMESH868MHZ_RX_DRV_BUFFER_SIZE 300u
168  // neomesh868mhz_cmd
170 
185 #define NEOMESH868MHZ_MAP_MIKROBUS( cfg, mikrobus ) \
186  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
187  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
188  cfg.app = MIKROBUS( mikrobus, MIKROBUS_AN ); \
189  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
190  cfg.wes = MIKROBUS( mikrobus, MIKROBUS_CS ); \
191  cfg.cts = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
192  cfg.wup = MIKROBUS( mikrobus, MIKROBUS_INT );
193  // neomesh868mhz_map // neomesh868mhz
196 
201 typedef struct
202 {
203  // Output pins
204  digital_out_t rst;
205  digital_out_t wes;
207  // Input pins
208  digital_in_t app;
209  digital_in_t cts;
210  digital_in_t wup;
212  // Modules
213  uart_t uart;
215  // Buffers
216  uint8_t uart_rx_buffer[ NEOMESH868MHZ_RX_DRV_BUFFER_SIZE ];
217  uint8_t uart_tx_buffer[ NEOMESH868MHZ_TX_DRV_BUFFER_SIZE ];
220 
225 typedef struct
226 {
227  // Communication gpio pins
228  pin_name_t rx_pin;
229  pin_name_t tx_pin;
231  // Additional gpio pins
232  pin_name_t app;
233  pin_name_t rst;
234  pin_name_t wes;
235  pin_name_t cts;
236  pin_name_t wup;
238  // Static variable
239  uint32_t baud_rate;
241  uart_data_bits_t data_bit;
242  uart_parity_t parity_bit;
243  uart_stop_bits_t stop_bit;
246 
251 typedef struct
252 {
253  uint8_t cmd;
254  uint8_t len;
255  uint8_t payload[ NEOMESH868MHZ_MAX_PAYLOAD_LEN ];
258 
263 typedef struct
264 {
265  uint16_t cmd;
266  uint8_t len;
267  uint8_t payload[ NEOMESH868MHZ_MAX_PAYLOAD_LEN ];
270 
275 typedef enum
276 {
280 
282 
299 
314 
328 
343 
357 
372 
382 void neomesh868mhz_set_rst_pin ( neomesh868mhz_t *ctx, uint8_t state );
383 
393 void neomesh868mhz_set_wes_pin ( neomesh868mhz_t *ctx, uint8_t state );
394 
404 
414 
424 
425 #ifdef __cplusplus
426 }
427 #endif
428 #endif // NEOMESH868MHZ_H
429  // neomesh868mhz
431 
432 // ------------------------------------------------------------------------ END
neomesh868mhz_t::cts
digital_in_t cts
Definition: neomesh868mhz.h:209
neomesh868mhz_get_app_pin
uint8_t neomesh868mhz_get_app_pin(neomesh868mhz_t *ctx)
NeoMesh 868MHz get app pin function.
neomesh868mhz_t::wup
digital_in_t wup
Definition: neomesh868mhz.h:210
neomesh868mhz_aapi_frame_t::cmd
uint8_t cmd
Definition: neomesh868mhz.h:253
neomesh868mhz_cfg_t
NeoMesh 868MHz Click configuration object.
Definition: neomesh868mhz.h:226
neomesh868mhz_t::uart
uart_t uart
Definition: neomesh868mhz.h:213
NEOMESH868MHZ_ERROR
@ NEOMESH868MHZ_ERROR
Definition: neomesh868mhz.h:278
neomesh868mhz_send_sapi_frame
err_t neomesh868mhz_send_sapi_frame(neomesh868mhz_t *ctx, neomesh868mhz_sapi_frame_t *frame)
NeoMesh 868MHz send sapi frame function.
neomesh868mhz_aapi_frame_t
NeoMesh 868MHz Click data frame object.
Definition: neomesh868mhz.h:252
NEOMESH868MHZ_OK
@ NEOMESH868MHZ_OK
Definition: neomesh868mhz.h:277
neomesh868mhz_cfg_t::wup
pin_name_t wup
Definition: neomesh868mhz.h:236
neomesh868mhz_cfg_t::app
pin_name_t app
Definition: neomesh868mhz.h:232
neomesh868mhz_cfg_t::tx_pin
pin_name_t tx_pin
Definition: neomesh868mhz.h:229
neomesh868mhz_t::wes
digital_out_t wes
Definition: neomesh868mhz.h:205
neomesh868mhz_get_cts_pin
uint8_t neomesh868mhz_get_cts_pin(neomesh868mhz_t *ctx)
NeoMesh 868MHz get cts pin function.
neomesh868mhz_send_aapi_frame
err_t neomesh868mhz_send_aapi_frame(neomesh868mhz_t *ctx, neomesh868mhz_aapi_frame_t *frame)
NeoMesh 868MHz send aapi frame function.
neomesh868mhz_t::rst
digital_out_t rst
Definition: neomesh868mhz.h:204
neomesh868mhz_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: neomesh868mhz.h:242
neomesh868mhz_return_value_t
neomesh868mhz_return_value_t
NeoMesh 868MHz Click return value data.
Definition: neomesh868mhz.h:276
NEOMESH868MHZ_TIMEOUT
@ NEOMESH868MHZ_TIMEOUT
Definition: neomesh868mhz.h:279
neomesh868mhz_set_wes_pin
void neomesh868mhz_set_wes_pin(neomesh868mhz_t *ctx, uint8_t state)
NeoMesh 868MHz set wes pin function.
neomesh868mhz_sapi_frame_t::cmd
uint16_t cmd
Definition: neomesh868mhz.h:265
neomesh868mhz_t
NeoMesh 868MHz Click context object.
Definition: neomesh868mhz.h:202
neomesh868mhz_cfg_t::uart_blocking
bool uart_blocking
Definition: neomesh868mhz.h:240
neomesh868mhz_cfg_t::baud_rate
uint32_t baud_rate
Definition: neomesh868mhz.h:239
neomesh868mhz_read_aapi_frame
err_t neomesh868mhz_read_aapi_frame(neomesh868mhz_t *ctx, neomesh868mhz_aapi_frame_t *frame)
NeoMesh 868MHz read aapi frame function.
neomesh868mhz_cfg_t::rst
pin_name_t rst
Definition: neomesh868mhz.h:233
neomesh868mhz_cfg_t::cts
pin_name_t cts
Definition: neomesh868mhz.h:235
neomesh868mhz_sapi_frame_t::len
uint8_t len
Definition: neomesh868mhz.h:266
neomesh868mhz_t::app
digital_in_t app
Definition: neomesh868mhz.h:208
neomesh868mhz_init
err_t neomesh868mhz_init(neomesh868mhz_t *ctx, neomesh868mhz_cfg_t *cfg)
NeoMesh 868MHz initialization function.
neomesh868mhz_set_rst_pin
void neomesh868mhz_set_rst_pin(neomesh868mhz_t *ctx, uint8_t state)
NeoMesh 868MHz set rst pin function.
neomesh868mhz_cfg_setup
void neomesh868mhz_cfg_setup(neomesh868mhz_cfg_t *cfg)
NeoMesh 868MHz configuration object setup function.
neomesh868mhz_cfg_t::wes
pin_name_t wes
Definition: neomesh868mhz.h:234
neomesh868mhz_aapi_frame_t::len
uint8_t len
Definition: neomesh868mhz.h:254
neomesh868mhz_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: neomesh868mhz.h:243
neomesh868mhz_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: neomesh868mhz.h:241
neomesh868mhz_get_wup_pin
uint8_t neomesh868mhz_get_wup_pin(neomesh868mhz_t *ctx)
NeoMesh 868MHz get wup pin function.
neomesh868mhz_sapi_frame_t
NeoMesh 868MHz Click data frame object.
Definition: neomesh868mhz.h:264
neomesh868mhz_cfg_t::rx_pin
pin_name_t rx_pin
Definition: neomesh868mhz.h:228
neomesh868mhz_read_sapi_frame
err_t neomesh868mhz_read_sapi_frame(neomesh868mhz_t *ctx, neomesh868mhz_sapi_frame_t *frame)
NeoMesh 868MHz read sapi frame function.
NEOMESH868MHZ_RX_DRV_BUFFER_SIZE
#define NEOMESH868MHZ_RX_DRV_BUFFER_SIZE
Definition: neomesh868mhz.h:167
NEOMESH868MHZ_MAX_PAYLOAD_LEN
#define NEOMESH868MHZ_MAX_PAYLOAD_LEN
NeoMesh 868MHz payload length.
Definition: neomesh868mhz.h:159
NEOMESH868MHZ_TX_DRV_BUFFER_SIZE
#define NEOMESH868MHZ_TX_DRV_BUFFER_SIZE
NeoMesh 868MHz driver buffer size.
Definition: neomesh868mhz.h:166