canisolator2  2.0.0.0
canisolator2.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 CANISOLATOR2_H
29 #define CANISOLATOR2_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 
70 #define DRV_BUFFER_SIZE 200
71  // canisolator2_set
73 
88 #define CANISOLATOR2_MAP_MIKROBUS( cfg, mikrobus ) \
89  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
90  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX );
91  // canisolator2_map // canisolator2
94 
99 typedef struct
100 {
101  // Modules
102 
103  uart_t uart;
105  // Buffers
106 
107  char uart_rx_buffer[ DRV_BUFFER_SIZE ];
108  char uart_tx_buffer[ DRV_BUFFER_SIZE ];
111 
116 typedef struct
117 {
118  // Communication gpio pins
119 
120  pin_name_t rx_pin;
121  pin_name_t tx_pin;
123  // Static variable
124 
125  uint32_t baud_rate;
127  uart_data_bits_t data_bit;
128  uart_parity_t parity_bit;
129  uart_stop_bits_t stop_bit;
132 
137 typedef enum
138 {
140  CANISOLATOR2_ERROR = -1
141 
143 
160 
176 
190 err_t canisolator2_generic_write ( canisolator2_t *ctx, char *data_buf, uint16_t len );
191 
205 err_t canisolator2_generic_read ( canisolator2_t *ctx, char *data_buf, uint16_t max_len );
206 
219 err_t canisolator2_send_data ( canisolator2_t *ctx, char *tx_data );
220 
221 #ifdef __cplusplus
222 }
223 #endif
224 #endif // CANISOLATOR2_H
225  // canisolator2
227 
228 // ------------------------------------------------------------------------ END
canisolator2_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: canisolator2.h:129
canisolator2_t
CAN Isolator 2 Click context object.
Definition: canisolator2.h:100
canisolator2_generic_read
err_t canisolator2_generic_read(canisolator2_t *ctx, char *data_buf, uint16_t max_len)
CAN Isolator 2 data reading function.
CANISOLATOR2_OK
@ CANISOLATOR2_OK
Definition: canisolator2.h:139
DRV_BUFFER_SIZE
#define DRV_BUFFER_SIZE
CAN Isolator 2 driver buffer size.
Definition: canisolator2.h:70
canisolator2_t::uart
uart_t uart
Definition: canisolator2.h:103
canisolator2_send_data
err_t canisolator2_send_data(canisolator2_t *ctx, char *tx_data)
CAN Isolator 2 send data function.
canisolator2_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: canisolator2.h:128
canisolator2_cfg_t::baud_rate
uint32_t baud_rate
Definition: canisolator2.h:125
canisolator2_cfg_t::rx_pin
pin_name_t rx_pin
Definition: canisolator2.h:120
canisolator2_init
err_t canisolator2_init(canisolator2_t *ctx, canisolator2_cfg_t *cfg)
CAN Isolator 2 initialization function.
canisolator2_return_value_t
canisolator2_return_value_t
CAN Isolator 2 Click return value data.
Definition: canisolator2.h:138
canisolator2_generic_write
err_t canisolator2_generic_write(canisolator2_t *ctx, char *data_buf, uint16_t len)
CAN Isolator 2 data writing function.
canisolator2_cfg_t::uart_blocking
bool uart_blocking
Definition: canisolator2.h:126
canisolator2_cfg_t
CAN Isolator 2 Click configuration object.
Definition: canisolator2.h:117
canisolator2_cfg_setup
void canisolator2_cfg_setup(canisolator2_cfg_t *cfg)
CAN Isolator 2 configuration object setup function.
canisolator2_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: canisolator2.h:127
canisolator2_cfg_t::tx_pin
pin_name_t tx_pin
Definition: canisolator2.h:121
CANISOLATOR2_ERROR
@ CANISOLATOR2_ERROR
Definition: canisolator2.h:140