wirepas 2.1.0.0
wirepas.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 WIREPAS_H
29#define WIREPAS_H
30
31#ifdef __cplusplus
32extern "C"{
33#endif
34
39#ifdef PREINIT_SUPPORTED
40#include "preinit.h"
41#endif
42
43#ifdef MikroCCoreVersion
44 #if MikroCCoreVersion >= 1
45 #include "delays.h"
46 #endif
47#endif
48
49#include "drv_digital_out.h"
50#include "drv_digital_in.h"
51#include "drv_uart.h"
52
78#define WIREPAS_DSAP_DATA_TX_REQUEST 0x01
79#define WIREPAS_DSAP_DATA_TX_CONFIRM 0x81
80#define WIREPAS_DSAP_DATA_TX_TT_REQUEST 0x1F
81#define WIREPAS_DSAP_DATA_TX_TT_CONFIRM 0x9F
82#define WIREPAS_DSAP_DATA_TX_INDICATION 0x02
83#define WIREPAS_DSAP_DATA_TX_RESPONSE 0x82
84#define WIREPAS_DSAP_DATA_RX_INDICATION 0x03
85#define WIREPAS_DSAP_DATA_RX_RESPONSE 0x83
86
91#define WIREPAS_MSAP_INDICATION_POLL_REQUEST 0x04
92#define WIREPAS_MSAP_INDICATION_POLL_CONFIRM 0x84
93#define WIREPAS_MSAP_STACK_START_REQUEST 0x05
94#define WIREPAS_MSAP_STACK_START_CONFIRM 0x85
95#define WIREPAS_MSAP_STACK_STOP_REQUEST 0x06
96#define WIREPAS_MSAP_STACK_STOP_CONFIRM 0x86
97#define WIREPAS_MSAP_STACK_STATE_INDICATION 0x07
98#define WIREPAS_MSAP_STACK_STATE_RESPONSE 0x87
99#define WIREPAS_MSAP_APP_CONFIG_DATA_RX_IND 0x3F
100#define WIREPAS_MSAP_APP_CONFIG_DATA_RX_RESP 0xBF
101#define WIREPAS_MSAP_SCAN_NBORS_INDICATION 0x22
102#define WIREPAS_MSAP_SCAN_NBORS_RESPONSE 0xA2
103
108#define WIREPAS_CSAP_ATTRIBUTE_WRITE_REQUEST 0x0D
109#define WIREPAS_CSAP_ATTRIBUTE_WRITE_CONFIRM 0x8D
110#define WIREPAS_CSAP_ATTRIBUTE_READ_REQUEST 0x0E
111#define WIREPAS_CSAP_ATTRIBUTE_READ_CONFIRM 0x8E
112#define WIREPAS_CSAP_FACTORY_RESET_REQUEST 0x16
113#define WIREPAS_CSAP_FACTORY_RESET_CONFIRM 0x96
114
119#define WIREPAS_CSAP_ATTRIBUTE_NODE_ADDRESS 0x01
120#define WIREPAS_CSAP_ATTRIBUTE_NETWORK_ADDRESS 0x02
121#define WIREPAS_CSAP_ATTRIBUTE_NETWORK_CHANNEL 0x03
122#define WIREPAS_CSAP_ATTRIBUTE_NODE_ROLE 0x04
123
128#define WIREPAS_FACTORY_RESET_CODE "DoIt"
129
134#define WIREPAS_ENDCODE_OCTET 0xC0
135
140#define WIREPAS_ROUTER_NODE_MODE 0x02
141#define WIREPAS_SINK_NODE_MODE 0x01
142
147#define WIREPAS_PIN_MODE_HIGH 0x01
148#define WIREPAS_PIN_MODE_LOW 0x00
149
155#define WIREPAS_TX_DRV_BUFFER_SIZE 200
156#define WIREPAS_RX_DRV_BUFFER_SIZE 500
157
158 // wirepas_cmd
159
174#define WIREPAS_MAP_MIKROBUS( cfg, mikrobus ) \
175 cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
176 cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
177 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
178 cfg.din = MIKROBUS( mikrobus, MIKROBUS_INT );
179
180 // wirepas_map
181 // wirepas
182
187typedef struct
188{
189 uint8_t primitive_id;
190 uint8_t frame_id;
191 uint8_t payload_len;
192 uint8_t payload[ 256 ];
193
195
200typedef struct
201{
202 // Output pins
203 digital_out_t rst;
205 // Input pins
206 digital_in_t din;
208 // Modules
209 uart_t uart;
211 // Buffers
212 uint8_t uart_rx_buffer[ WIREPAS_RX_DRV_BUFFER_SIZE ];
213 uint8_t uart_tx_buffer[ WIREPAS_TX_DRV_BUFFER_SIZE ];
216 uint8_t tx_frame_id;
217
218} wirepas_t;
219
224typedef struct
225{
226 // Communication gpio pins
227 pin_name_t rx_pin;
228 pin_name_t tx_pin;
230 // Additional gpio pins
231 pin_name_t rst;
232 pin_name_t din;
234 // Static variable
235 uint32_t baud_rate;
237 uart_data_bits_t data_bit;
238 uart_parity_t parity_bit;
239 uart_stop_bits_t stop_bit;
242
247typedef struct
248{
249 uint16_t pduid;
255
267
284
299
311
324err_t wirepas_generic_write ( wirepas_t *ctx, uint8_t *data_in, uint16_t len );
325
338err_t wirepas_generic_read ( wirepas_t *ctx, uint8_t *data_out, uint16_t len );
339
349
359void wirepas_set_rst ( wirepas_t *ctx, uint8_t pin_state );
360
371
385err_t wirepas_send_command ( wirepas_t *ctx, uint8_t primitive_id,
386 uint8_t payload_length, uint8_t *payload );
387
401err_t wirepas_send_ack ( wirepas_t *ctx, uint8_t primitive_id, uint8_t frame_id, uint8_t result );
402
416err_t wirepas_write_csap_attribute ( wirepas_t *ctx, uint16_t attribute_id,
417 uint8_t attribute_len, uint8_t *attribute_val );
418
432err_t wirepas_read_csap_attribute ( wirepas_t *ctx, uint16_t attribute_id,
433 uint8_t *attribute_len, uint8_t *attribute_val );
434
446err_t wirepas_set_node_address ( wirepas_t *ctx, uint32_t address );
447
459err_t wirepas_set_net_address ( wirepas_t *ctx, uint32_t net_address );
460
473
489 uint8_t tx_op, uint8_t apdu_length, uint8_t *apdu );
490
491#ifdef __cplusplus
492}
493#endif
494#endif // WIREPAS_H
495
496 // wirepas
497
498// ------------------------------------------------------------------------ END
#define WIREPAS_TX_DRV_BUFFER_SIZE
Wirepas driver buffer size.
Definition wirepas.h:155
#define WIREPAS_RX_DRV_BUFFER_SIZE
Definition wirepas.h:156
err_t wirepas_read_csap_attribute(wirepas_t *ctx, uint16_t attribute_id, uint8_t *attribute_len, uint8_t *attribute_val)
Wirepas read CSAP attribute function.
void wirepas_hw_reset(wirepas_t *ctx)
Wirepas hardware reset function.
err_t wirepas_send_ack(wirepas_t *ctx, uint8_t primitive_id, uint8_t frame_id, uint8_t result)
Wirepas send ack function.
err_t wirepas_set_node_address(wirepas_t *ctx, uint32_t address)
Wirepas set node address function.
uint8_t wirepas_get_din_state(wirepas_t *ctx)
Wirepas get DIN state function.
void wirepas_default_cfg(wirepas_t *ctx)
Wirepas default configuration function.
err_t wirepas_init(wirepas_t *ctx, wirepas_cfg_t *cfg)
Wirepas initialization function.
err_t wirepas_write_csap_attribute(wirepas_t *ctx, uint16_t attribute_id, uint8_t attribute_len, uint8_t *attribute_val)
Wirepas write CSAP attribute function.
err_t wirepas_read_frame(wirepas_t *ctx, wirepas_frame_t *frame)
Wirepas read frame function.
void wirepas_cfg_setup(wirepas_cfg_t *cfg)
Wirepas configuration object setup function.
void wirepas_set_rst(wirepas_t *ctx, uint8_t pin_state)
Wirepas set RST pin state function.
err_t wirepas_send_data(wirepas_t *ctx, wirepas_sink_data sink_data, uint8_t tx_op, uint8_t apdu_length, uint8_t *apdu)
Wirepas send data function.
err_t wirepas_send_command(wirepas_t *ctx, uint8_t primitive_id, uint8_t payload_length, uint8_t *payload)
Wirepas send command function.
err_t wirepas_generic_write(wirepas_t *ctx, uint8_t *data_in, uint16_t len)
Wirepas data writing function.
err_t wirepas_set_net_address(wirepas_t *ctx, uint32_t net_address)
Wirepas set net address function.
err_t wirepas_generic_read(wirepas_t *ctx, uint8_t *data_out, uint16_t len)
Wirepas data reading function.
uint8_t frame_id
Definition main.c:55
Wirepas Click configuration object.
Definition wirepas.h:225
uint32_t baud_rate
Definition wirepas.h:235
pin_name_t din
Definition wirepas.h:232
bool uart_blocking
Definition wirepas.h:236
uart_data_bits_t data_bit
Definition wirepas.h:237
pin_name_t tx_pin
Definition wirepas.h:228
pin_name_t rx_pin
Definition wirepas.h:227
uart_stop_bits_t stop_bit
Definition wirepas.h:239
uart_parity_t parity_bit
Definition wirepas.h:238
pin_name_t rst
Definition wirepas.h:231
Wirepas Click frame data object.
Definition wirepas.h:188
uint8_t frame_id
Definition wirepas.h:190
uint8_t primitive_id
Definition wirepas.h:189
uint8_t payload_len
Definition wirepas.h:191
Wirepas Click sink data object.
Definition wirepas.h:248
uint32_t destination_addr
Definition wirepas.h:251
uint8_t source_endpoint
Definition wirepas.h:250
uint16_t pduid
Definition wirepas.h:249
uint8_t destination_endpoint
Definition wirepas.h:252
Wirepas Click context object.
Definition wirepas.h:201
uart_t uart
Definition wirepas.h:209
digital_out_t rst
Definition wirepas.h:203
wirepas_frame_t frame
Definition wirepas.h:215
uint8_t tx_frame_id
Definition wirepas.h:216
digital_in_t din
Definition wirepas.h:206
wirepas_return_value_t
Wirepas Click return value data.
Definition wirepas.h:261
@ WIREPAS_DATA_RDY
Definition wirepas.h:263
@ WIREPAS_ERROR
Definition wirepas.h:264
@ WIREPAS_OK
Definition wirepas.h:262