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
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 
74 #define WIREPAS_DSAP_DATA_TX_REQUEST 0x01
75 #define WIREPAS_DSAP_DATA_TX_CONFIRM 0x81
76 #define WIREPAS_DSAP_DATA_TX_TT_REQUEST 0x1F
77 #define WIREPAS_DSAP_DATA_TX_TT_CONFIRM 0x9F
78 #define WIREPAS_DSAP_DATA_TX_INDICATION 0x02
79 #define WIREPAS_DSAP_DATA_TX_RESPONSE 0x82
80 #define WIREPAS_DSAP_DATA_RX_INDICATION 0x03
81 #define WIREPAS_DSAP_DATA_RX_RESPONSE 0x83
82 
87 #define WIREPAS_MSAP_INDICATION_POLL_REQUEST 0x04
88 #define WIREPAS_MSAP_INDICATION_POLL_CONFIRM 0x84
89 #define WIREPAS_MSAP_STACK_START_REQUEST 0x05
90 #define WIREPAS_MSAP_STACK_START_CONFIRM 0x85
91 #define WIREPAS_MSAP_STACK_STOP_REQUEST 0x06
92 #define WIREPAS_MSAP_STACK_STOP_CONFIRM 0x86
93 #define WIREPAS_MSAP_STACK_STATE_INDICATION 0x07
94 #define WIREPAS_MSAP_STACK_STATE_RESPONSE 0x87
95 
100 #define WIREPAS_CSAP_ATTRIBUTE_WRITE_REQUEST 0x0D
101 #define WIREPAS_CSAP_ATTRIBUTE_WRITE_CONFIRM 0x8D
102 #define WIREPAS_CSAP_ATTRIBUTE_READ_REQUEST 0x0E
103 #define WIREPAS_CSAP_ATTRIBUTE_READ_CONFIRM 0x8E
104 #define WIREPAS_CSAP_FACTORY_RESET_REQUEST 0x16
105 #define WIREPAS_CSAP_FACTORY_RESET_CONFIRM 0x96
106 
111 #define WIREPAS_CSAP_ATTRIBUTE_NODE_ADDRESS 0x01
112 #define WIREPAS_CSAP_ATTRIBUTE_NETWORK_ADDRESS 0x02
113 #define WIREPAS_CSAP_ATTRIBUTE_NETWORK_CHANNEL 0x03
114 #define WIREPAS_CSAP_ATTRIBUTE_NODE_ROLE 0x04
115 
120 #define WIREPAS_FACTORY_RESET_CODE "DoIt"
121 
126 #define WIREPAS_ENDCODE_OCTET 0xC0
127 
132 #define WIREPAS_ROUTER_NODE_MODE 0x02
133 #define WIREPAS_SINK_NODE_MODE 0x01
134 
139 #define WIREPAS_PIN_MODE_HIGH 0x01
140 #define WIREPAS_PIN_MODE_LOW 0x00
141 
147 #define WIREPAS_TX_DRV_BUFFER_SIZE 100
148 #define WIREPAS_RX_DRV_BUFFER_SIZE 300
149  // wirepas_cmd
151 
166 #define WIREPAS_MAP_MIKROBUS( cfg, mikrobus ) \
167  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
168  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
169  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
170  cfg.din = MIKROBUS( mikrobus, MIKROBUS_INT );
171  // wirepas_map // wirepas
174 
179 typedef struct
180 {
181  // Output pins
182  digital_out_t rst;
184  // Input pins
185  digital_in_t din;
187  // Modules
188  uart_t uart;
190  // Buffers
191  uint8_t uart_rx_buffer[ WIREPAS_RX_DRV_BUFFER_SIZE ];
192  uint8_t uart_tx_buffer[ WIREPAS_TX_DRV_BUFFER_SIZE ];
194 } wirepas_t;
195 
200 typedef struct
201 {
202  // Communication gpio pins
203  pin_name_t rx_pin;
204  pin_name_t tx_pin;
206  // Additional gpio pins
207  pin_name_t rst;
208  pin_name_t din;
210  // Static variable
211  uint32_t baud_rate;
213  uart_data_bits_t data_bit;
214  uart_parity_t parity_bit;
215  uart_stop_bits_t stop_bit;
217 } wirepas_cfg_t;
218 
223 typedef struct
224 {
225  uint16_t pduid;
226  uint8_t source_endpoint;
227  uint32_t destination_addr;
231 
236 typedef enum
237 {
240  WIREPAS_ERROR = -1
241 
243 
260 
274 err_t wirepas_init ( wirepas_t *ctx, wirepas_cfg_t *cfg );
275 
287 
300 err_t wirepas_generic_write ( wirepas_t *ctx, uint8_t *data_in, uint16_t len );
301 
314 err_t wirepas_generic_read ( wirepas_t *ctx, uint8_t *data_out, uint16_t len );
315 
325 
335 void wirepas_set_rst ( wirepas_t *ctx, uint8_t pin_state );
336 
347 
364 err_t wirepas_send_command ( wirepas_t *ctx, uint8_t primitive_id, uint8_t frame_id,
365  uint8_t payload_length, uint8_t *payload );
366 
382 err_t wirepas_write_csap_attribute ( wirepas_t *ctx, uint8_t frame_id, uint16_t attribute_id,
383  uint8_t attribute_len, uint8_t *attribute_val );
384 
400 err_t wirepas_read_csap_attribute ( wirepas_t *ctx, uint8_t frame_id, uint16_t attribute_id,
401  uint8_t *attribute_len, uint8_t *attribute_val );
402 
416 err_t wirepas_set_node_address ( wirepas_t *ctx, uint8_t frame_id, uint32_t address );
417 
431 err_t wirepas_set_net_address ( wirepas_t *ctx, uint8_t frame_id, uint32_t net_address );
432 
448 err_t wirepas_poll_indication ( wirepas_t *ctx, uint8_t frame_id, uint8_t *rx_data, uint8_t *data_rdy );
449 
466 err_t wirepas_send_data ( wirepas_t *ctx, uint8_t frame_id, wirepas_sink_data sink_data,
467  uint8_t tx_op, uint8_t apdu_length, uint8_t *apdu );
468 
469 #ifdef __cplusplus
470 }
471 #endif
472 #endif // WIREPAS_H
473  // wirepas
475 
476 // ------------------------------------------------------------------------ END
wirepas_cfg_setup
void wirepas_cfg_setup(wirepas_cfg_t *cfg)
Wirepas configuration object setup function.
wirepas_cfg_t::uart_blocking
bool uart_blocking
Definition: wirepas.h:212
wirepas_set_rst
void wirepas_set_rst(wirepas_t *ctx, uint8_t pin_state)
Wirepas set RST pin state function.
wirepas_t::din
digital_in_t din
Definition: wirepas.h:185
wirepas_cfg_t
Wirepas Click configuration object.
Definition: wirepas.h:201
frame_id
uint8_t frame_id
Definition: main.c:53
wirepas_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: wirepas.h:215
WIREPAS_DATA_RDY
@ WIREPAS_DATA_RDY
Definition: wirepas.h:239
wirepas_default_cfg
void wirepas_default_cfg(wirepas_t *ctx)
Wirepas default configuration function.
wirepas_send_command
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.
wirepas_sink_data::destination_endpoint
uint8_t destination_endpoint
Definition: wirepas.h:228
wirepas_hw_reset
void wirepas_hw_reset(wirepas_t *ctx)
Wirepas hardware reset function.
WIREPAS_TX_DRV_BUFFER_SIZE
#define WIREPAS_TX_DRV_BUFFER_SIZE
Wirepas driver buffer size.
Definition: wirepas.h:147
wirepas_cfg_t::rst
pin_name_t rst
Definition: wirepas.h:207
wirepas_t::rst
digital_out_t rst
Definition: wirepas.h:182
wirepas_set_node_address
err_t wirepas_set_node_address(wirepas_t *ctx, uint8_t frame_id, uint32_t address)
Wirepas set node address function.
WIREPAS_ERROR
@ WIREPAS_ERROR
Definition: wirepas.h:240
wirepas_read_csap_attribute
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.
wirepas_cfg_t::rx_pin
pin_name_t rx_pin
Definition: wirepas.h:203
wirepas_get_din_state
uint8_t wirepas_get_din_state(wirepas_t *ctx)
Wirepas get DIN state function.
wirepas_generic_write
err_t wirepas_generic_write(wirepas_t *ctx, uint8_t *data_in, uint16_t len)
Wirepas data writing function.
wirepas_set_net_address
err_t wirepas_set_net_address(wirepas_t *ctx, uint8_t frame_id, uint32_t net_address)
Wirepas set net address function.
wirepas_cfg_t::tx_pin
pin_name_t tx_pin
Definition: wirepas.h:204
wirepas_send_data
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.
wirepas_generic_read
err_t wirepas_generic_read(wirepas_t *ctx, uint8_t *data_out, uint16_t len)
Wirepas data reading function.
wirepas_sink_data::source_endpoint
uint8_t source_endpoint
Definition: wirepas.h:226
wirepas_t::uart
uart_t uart
Definition: wirepas.h:188
wirepas_poll_indication
err_t wirepas_poll_indication(wirepas_t *ctx, uint8_t frame_id, uint8_t *rx_data, uint8_t *data_rdy)
Wirepas poll indication function.
wirepas_cfg_t::baud_rate
uint32_t baud_rate
Definition: wirepas.h:211
wirepas_t
Wirepas Click context object.
Definition: wirepas.h:180
wirepas_sink_data::pduid
uint16_t pduid
Definition: wirepas.h:225
wirepas_cfg_t::din
pin_name_t din
Definition: wirepas.h:208
wirepas_write_csap_attribute
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.
WIREPAS_RX_DRV_BUFFER_SIZE
#define WIREPAS_RX_DRV_BUFFER_SIZE
Definition: wirepas.h:148
wirepas_return_value_t
wirepas_return_value_t
Wirepas Click return value data.
Definition: wirepas.h:237
wirepas_sink_data
Wirepas Click sink data object.
Definition: wirepas.h:224
WIREPAS_OK
@ WIREPAS_OK
Definition: wirepas.h:238
wirepas_sink_data::destination_addr
uint32_t destination_addr
Definition: wirepas.h:227
wirepas_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: wirepas.h:213
wirepas_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: wirepas.h:214
wirepas_init
err_t wirepas_init(wirepas_t *ctx, wirepas_cfg_t *cfg)
Wirepas initialization function.