canisolator  2.0.0.0
canisolator.h
Go to the documentation of this file.
1 /*
2  * MikroSDK - MikroE Software Development Kit
3  * Copyright© 2020 MikroElektronika d.o.o.
4  *
5  * Permission is hereby granted, free of charge, to any person
6  * obtaining a copy of this software and associated documentation
7  * files (the "Software"), to deal in the Software without restriction,
8  * including without limitation the rights to use, copy, modify, merge,
9  * publish, distribute, sublicense, and/or sell copies of the Software,
10  * and to permit persons to whom the Software is furnished to do so,
11  * subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be
14  * included in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
22  * OR OTHER DEALINGS IN THE SOFTWARE.
23  */
24 
33 // ----------------------------------------------------------------------------
34 
35 #ifndef CANISOLATOR_H
36 #define CANISOLATOR_H
37 
38 #include "mikrosdk_version.h"
39 
40 #ifdef __GNUC__
41 #if mikroSDK_GET_VERSION < 20800ul
42 #include "rcu_delays.h"
43 #else
44 #include "delays.h"
45 #endif
46 #endif
47 
48 #include "drv_digital_out.h"
49 #include "drv_uart.h"
50 
51 // -------------------------------------------------------------- PUBLIC MACROS
61 #define CANISOLATOR_MAP_MIKROBUS( cfg, mikrobus ) \
62  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
63  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX )
64 
70 #define CANISOLATOR_RETVAL uint8_t
71 
72 #define CANISOLATOR_OK 0x00
73 #define CANISOLATOR_INIT_ERROR 0xFF
74 
80 #define DRV_RX_BUFFER_SIZE 500
81  // End group macro
84 // --------------------------------------------------------------- PUBLIC TYPES
94 typedef struct
95 {
96  // Modules
97 
98  uart_t uart;
99 
100  char uart_rx_buffer[ DRV_RX_BUFFER_SIZE ];
101  char uart_tx_buffer[ DRV_RX_BUFFER_SIZE ];
102 
103 } canisolator_t;
104 
108 typedef struct
109 {
110  // Communication gpio pins
111 
112  pin_name_t rx_pin;
113  pin_name_t tx_pin;
114 
115  // static variable
116 
117  uint32_t baud_rate; // Clock speed.
119  uart_data_bits_t data_bit; // Data bits.
120  uart_parity_t parity_bit; // Parity bit.
121  uart_stop_bits_t stop_bit; // Stop bits.
122 
124  // End types group
126 // ------------------------------------------------------------------ CONSTANTS // End constants group
135 // ------------------------------------------------------------------ VARIABLES // End variable group
143 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
144 
150 #ifdef __cplusplus
151 extern "C"{
152 #endif
153 
163 
172 
182 void canisolator_generic_multi_write ( canisolator_t *ctx, char *data_buf, uint8_t len );
183 
193 void canisolator_generic_multi_read ( canisolator_t *ctx, char *data_buf, uint8_t len );
194 
195 
205 
215 
216 #ifdef __cplusplus
217 }
218 #endif
219 #endif // _CANISOLATOR_H_
220  // End public_function group
223 
224 // ------------------------------------------------------------------------- END
DRV_RX_BUFFER_SIZE
#define DRV_RX_BUFFER_SIZE
Definition: canisolator.h:80
canisolator_generic_multi_read
void canisolator_generic_multi_read(canisolator_t *ctx, char *data_buf, uint8_t len)
Generic multi read function.
canisolator_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: canisolator.h:121
canisolator_generic_single_read
char canisolator_generic_single_read(canisolator_t *ctx)
Generic single read function.
canisolator_t
Click ctx object definition.
Definition: canisolator.h:95
canisolator_init
CANISOLATOR_RETVAL canisolator_init(canisolator_t *ctx, canisolator_cfg_t *cfg)
Initialization function.
canisolator_generic_single_write
void canisolator_generic_single_write(canisolator_t *ctx, char tx_data)
Generic single write function.
canisolator_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: canisolator.h:120
canisolator_cfg_t::tx_pin
pin_name_t tx_pin
Definition: canisolator.h:113
CANISOLATOR_RETVAL
#define CANISOLATOR_RETVAL
Definition: canisolator.h:70
canisolator_cfg_t::rx_pin
pin_name_t rx_pin
Definition: canisolator.h:112
canisolator_cfg_t::baud_rate
uint32_t baud_rate
Definition: canisolator.h:117
canisolator_cfg_t
Click configuration structure definition.
Definition: canisolator.h:109
canisolator_generic_multi_write
void canisolator_generic_multi_write(canisolator_t *ctx, char *data_buf, uint8_t len)
Generic multi write function.
canisolator_t::uart
uart_t uart
Definition: canisolator.h:98
canisolator_cfg_setup
void canisolator_cfg_setup(canisolator_cfg_t *cfg)
Config Object Initialization function.
canisolator_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: canisolator.h:119
canisolator_cfg_t::uart_blocking
bool uart_blocking
Definition: canisolator.h:118