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
35#include "drv_digital_out.h"
36#include "drv_digital_in.h"
37#include "drv_uart.h"
38
64#define WIREPAS_DSAP_DATA_TX_REQUEST 0x01
65#define WIREPAS_DSAP_DATA_TX_CONFIRM 0x81
66#define WIREPAS_DSAP_DATA_TX_TT_REQUEST 0x1F
67#define WIREPAS_DSAP_DATA_TX_TT_CONFIRM 0x9F
68#define WIREPAS_DSAP_DATA_TX_INDICATION 0x02
69#define WIREPAS_DSAP_DATA_TX_RESPONSE 0x82
70#define WIREPAS_DSAP_DATA_RX_INDICATION 0x03
71#define WIREPAS_DSAP_DATA_RX_RESPONSE 0x83
72
77#define WIREPAS_MSAP_INDICATION_POLL_REQUEST 0x04
78#define WIREPAS_MSAP_INDICATION_POLL_CONFIRM 0x84
79#define WIREPAS_MSAP_STACK_START_REQUEST 0x05
80#define WIREPAS_MSAP_STACK_START_CONFIRM 0x85
81#define WIREPAS_MSAP_STACK_STOP_REQUEST 0x06
82#define WIREPAS_MSAP_STACK_STOP_CONFIRM 0x86
83#define WIREPAS_MSAP_STACK_STATE_INDICATION 0x07
84#define WIREPAS_MSAP_STACK_STATE_RESPONSE 0x87
85
90#define WIREPAS_CSAP_ATTRIBUTE_WRITE_REQUEST 0x0D
91#define WIREPAS_CSAP_ATTRIBUTE_WRITE_CONFIRM 0x8D
92#define WIREPAS_CSAP_ATTRIBUTE_READ_REQUEST 0x0E
93#define WIREPAS_CSAP_ATTRIBUTE_READ_CONFIRM 0x8E
94#define WIREPAS_CSAP_FACTORY_RESET_REQUEST 0x16
95#define WIREPAS_CSAP_FACTORY_RESET_CONFIRM 0x96
96
101#define WIREPAS_CSAP_ATTRIBUTE_NODE_ADDRESS 0x01
102#define WIREPAS_CSAP_ATTRIBUTE_NETWORK_ADDRESS 0x02
103#define WIREPAS_CSAP_ATTRIBUTE_NETWORK_CHANNEL 0x03
104#define WIREPAS_CSAP_ATTRIBUTE_NODE_ROLE 0x04
105
110#define WIREPAS_FACTORY_RESET_CODE "DoIt"
111
116#define WIREPAS_ENDCODE_OCTET 0xC0
117
122#define WIREPAS_ROUTER_NODE_MODE 0x02
123#define WIREPAS_SINK_NODE_MODE 0x01
124
129#define WIREPAS_PIN_MODE_HIGH 0x01
130#define WIREPAS_PIN_MODE_LOW 0x00
131
137#define WIREPAS_TX_DRV_BUFFER_SIZE 100
138#define WIREPAS_RX_DRV_BUFFER_SIZE 300
139 // wirepas_cmd
141
156#define WIREPAS_MAP_MIKROBUS( cfg, mikrobus ) \
157 cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
158 cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
159 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
160 cfg.din = MIKROBUS( mikrobus, MIKROBUS_INT );
161 // wirepas_map // wirepas
164
169typedef struct
170{
171 // Output pins
172 digital_out_t rst;
174 // Input pins
175 digital_in_t din;
177 // Modules
178 uart_t uart;
180 // Buffers
181 uint8_t uart_rx_buffer[ WIREPAS_RX_DRV_BUFFER_SIZE ];
182 uint8_t uart_tx_buffer[ WIREPAS_TX_DRV_BUFFER_SIZE ];
184} wirepas_t;
185
190typedef struct
191{
192 // Communication gpio pins
193 pin_name_t rx_pin;
194 pin_name_t tx_pin;
196 // Additional gpio pins
197 pin_name_t rst;
198 pin_name_t din;
200 // Static variable
201 uint32_t baud_rate;
203 uart_data_bits_t data_bit;
204 uart_parity_t parity_bit;
205 uart_stop_bits_t stop_bit;
208
213typedef struct
214{
215 uint16_t pduid;
221
226typedef enum
227{
230 WIREPAS_ERROR = -1
231
233
250
265
277
290err_t wirepas_generic_write ( wirepas_t *ctx, uint8_t *data_in, uint16_t len );
291
304err_t wirepas_generic_read ( wirepas_t *ctx, uint8_t *data_out, uint16_t len );
305
315
325void wirepas_set_rst ( wirepas_t *ctx, uint8_t pin_state );
326
337
354err_t wirepas_send_command ( wirepas_t *ctx, uint8_t primitive_id, uint8_t frame_id,
355 uint8_t payload_length, uint8_t *payload );
356
372err_t wirepas_write_csap_attribute ( wirepas_t *ctx, uint8_t frame_id, uint16_t attribute_id,
373 uint8_t attribute_len, uint8_t *attribute_val );
374
390err_t wirepas_read_csap_attribute ( wirepas_t *ctx, uint8_t frame_id, uint16_t attribute_id,
391 uint8_t *attribute_len, uint8_t *attribute_val );
392
406err_t wirepas_set_node_address ( wirepas_t *ctx, uint8_t frame_id, uint32_t address );
407
421err_t wirepas_set_net_address ( wirepas_t *ctx, uint8_t frame_id, uint32_t net_address );
422
438err_t wirepas_poll_indication ( wirepas_t *ctx, uint8_t frame_id, uint8_t *rx_data, uint8_t *data_rdy );
439
456err_t wirepas_send_data ( wirepas_t *ctx, uint8_t frame_id, wirepas_sink_data sink_data,
457 uint8_t tx_op, uint8_t apdu_length, uint8_t *apdu );
458
459#ifdef __cplusplus
460}
461#endif
462#endif // WIREPAS_H
463 // wirepas
465
466// ------------------------------------------------------------------------ END
#define WIREPAS_TX_DRV_BUFFER_SIZE
Wirepas driver buffer size.
Definition: wirepas.h:137
#define WIREPAS_RX_DRV_BUFFER_SIZE
Definition: wirepas.h:138
void wirepas_hw_reset(wirepas_t *ctx)
Wirepas hardware reset function.
err_t wirepas_write_csap_attribute(wirepas_t *ctx, uint8_t frame_id, uint16_t attribute_id, uint8_t attribute_len, uint8_t *attribute_val)
Wirepas write CSAP attribute function.
err_t wirepas_set_node_address(wirepas_t *ctx, uint8_t frame_id, uint32_t address)
Wirepas set node address function.
err_t wirepas_poll_indication(wirepas_t *ctx, uint8_t frame_id, uint8_t *rx_data, uint8_t *data_rdy)
Wirepas poll indication function.
err_t wirepas_send_data(wirepas_t *ctx, uint8_t frame_id, wirepas_sink_data sink_data, uint8_t tx_op, uint8_t apdu_length, uint8_t *apdu)
Wirepas send data 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.
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_command(wirepas_t *ctx, uint8_t primitive_id, uint8_t frame_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_read_csap_attribute(wirepas_t *ctx, uint8_t frame_id, uint16_t attribute_id, uint8_t *attribute_len, uint8_t *attribute_val)
Wirepas read CSAP attribute function.
err_t wirepas_generic_read(wirepas_t *ctx, uint8_t *data_out, uint16_t len)
Wirepas data reading function.
err_t wirepas_set_net_address(wirepas_t *ctx, uint8_t frame_id, uint32_t net_address)
Wirepas set net address function.
uint8_t frame_id
Definition: main.c:54
Wirepas Click configuration object.
Definition: wirepas.h:191
uint32_t baud_rate
Definition: wirepas.h:201
pin_name_t din
Definition: wirepas.h:198
bool uart_blocking
Definition: wirepas.h:202
uart_data_bits_t data_bit
Definition: wirepas.h:203
pin_name_t tx_pin
Definition: wirepas.h:194
pin_name_t rx_pin
Definition: wirepas.h:193
uart_stop_bits_t stop_bit
Definition: wirepas.h:205
uart_parity_t parity_bit
Definition: wirepas.h:204
pin_name_t rst
Definition: wirepas.h:197
Wirepas Click sink data object.
Definition: wirepas.h:214
uint32_t destination_addr
Definition: wirepas.h:217
uint8_t source_endpoint
Definition: wirepas.h:216
uint16_t pduid
Definition: wirepas.h:215
uint8_t destination_endpoint
Definition: wirepas.h:218
Wirepas Click context object.
Definition: wirepas.h:170
uart_t uart
Definition: wirepas.h:178
digital_out_t rst
Definition: wirepas.h:172
digital_in_t din
Definition: wirepas.h:175
wirepas_return_value_t
Wirepas Click return value data.
Definition: wirepas.h:227
@ WIREPAS_DATA_RDY
Definition: wirepas.h:229
@ WIREPAS_ERROR
Definition: wirepas.h:230
@ WIREPAS_OK
Definition: wirepas.h:228