canisolator3  2.1.0.0
canisolator3.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 CANISOLATOR3_H
29 #define CANISOLATOR3_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 CANISOLATOR3_PIN_STATE_HIGH 0x01
70 #define CANISOLATOR3_PIN_STATE_LOW 0x00
71 
77 #define CANISOLATOR3_TX_DRV_BUFFER_SIZE 100
78 #define CANISOLATOR3_RX_DRV_BUFFER_SIZE 300
79  // canisolator3_cmd
81 
96 #define CANISOLATOR3_MAP_MIKROBUS( cfg, mikrobus ) \
97  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
98  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
99  cfg.pol = MIKROBUS( mikrobus, MIKROBUS_PWM )
100  // canisolator3_map // canisolator3
103 
108 typedef struct
109 {
110  // Output pins
111  digital_out_t pol;
113  // Modules
114  uart_t uart;
116  // Buffers
117  uint8_t uart_rx_buffer[ CANISOLATOR3_RX_DRV_BUFFER_SIZE ];
118  uint8_t uart_tx_buffer[ CANISOLATOR3_TX_DRV_BUFFER_SIZE ];
121 
126 typedef struct
127 {
128  // Communication gpio pins
129  pin_name_t rx_pin;
130  pin_name_t tx_pin;
132  // Additional gpio pins
133  pin_name_t pol;
135  // Static variable
136  uint32_t baud_rate;
138  uart_data_bits_t data_bit;
139  uart_parity_t parity_bit;
140  uart_stop_bits_t stop_bit;
143 
148 typedef enum
149 {
151  CANISOLATOR3_ERROR = -1
152 
154 
171 
186 
198 
211 err_t canisolator3_generic_write ( canisolator3_t *ctx, uint8_t *data_in, uint16_t len );
212 
225 err_t canisolator3_generic_read ( canisolator3_t *ctx, uint8_t *data_out, uint16_t len );
226 
236 void canisolator3_set_pol_pin ( canisolator3_t *ctx, uint8_t pin_state );
237 
238 #ifdef __cplusplus
239 }
240 #endif
241 #endif // CANISOLATOR3_H
242  // canisolator3
244 
245 // ------------------------------------------------------------------------ END
CANISOLATOR3_OK
@ CANISOLATOR3_OK
Definition: canisolator3.h:150
CANISOLATOR3_ERROR
@ CANISOLATOR3_ERROR
Definition: canisolator3.h:151
canisolator3_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: canisolator3.h:139
canisolator3_cfg_t::uart_blocking
bool uart_blocking
Definition: canisolator3.h:137
CANISOLATOR3_RX_DRV_BUFFER_SIZE
#define CANISOLATOR3_RX_DRV_BUFFER_SIZE
Definition: canisolator3.h:78
canisolator3_generic_write
err_t canisolator3_generic_write(canisolator3_t *ctx, uint8_t *data_in, uint16_t len)
CAN Isolator 3 data writing function.
canisolator3_t::pol
digital_out_t pol
Definition: canisolator3.h:111
canisolator3_cfg_t
CAN Isolator 3 Click configuration object.
Definition: canisolator3.h:127
canisolator3_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: canisolator3.h:140
canisolator3_t
CAN Isolator 3 Click context object.
Definition: canisolator3.h:109
canisolator3_cfg_t::rx_pin
pin_name_t rx_pin
Definition: canisolator3.h:129
CANISOLATOR3_TX_DRV_BUFFER_SIZE
#define CANISOLATOR3_TX_DRV_BUFFER_SIZE
CAN Isolator 3 driver buffer size.
Definition: canisolator3.h:77
canisolator3_cfg_t::baud_rate
uint32_t baud_rate
Definition: canisolator3.h:136
canisolator3_generic_read
err_t canisolator3_generic_read(canisolator3_t *ctx, uint8_t *data_out, uint16_t len)
CAN Isolator 3 data reading function.
canisolator3_return_value_t
canisolator3_return_value_t
CAN Isolator 3 Click return value data.
Definition: canisolator3.h:149
canisolator3_cfg_t::tx_pin
pin_name_t tx_pin
Definition: canisolator3.h:130
canisolator3_default_cfg
void canisolator3_default_cfg(canisolator3_t *ctx)
CAN Isolator 3 default configuration function.
canisolator3_cfg_t::pol
pin_name_t pol
Definition: canisolator3.h:133
canisolator3_init
err_t canisolator3_init(canisolator3_t *ctx, canisolator3_cfg_t *cfg)
CAN Isolator 3 initialization function.
canisolator3_cfg_setup
void canisolator3_cfg_setup(canisolator3_cfg_t *cfg)
CAN Isolator 3 configuration object setup function.
canisolator3_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: canisolator3.h:138
canisolator3_t::uart
uart_t uart
Definition: canisolator3.h:114
canisolator3_set_pol_pin
void canisolator3_set_pol_pin(canisolator3_t *ctx, uint8_t pin_state)
CAN Isolator 3 set polarity function.