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 
42 #ifdef PREINIT_SUPPORTED
43 #include "preinit.h"
44 #endif
45 
46 #ifdef MikroCCoreVersion
47  #if MikroCCoreVersion >= 1
48  #include "delays.h"
49  #endif
50 #endif
51 
52 #include "drv_digital_out.h"
53 #include "drv_uart.h"
54 
55 // -------------------------------------------------------------- PUBLIC MACROS
65 #define CANISOLATOR_MAP_MIKROBUS( cfg, mikrobus ) \
66  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
67  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX )
68 
74 #define CANISOLATOR_RETVAL uint8_t
75 
76 #define CANISOLATOR_OK 0x00
77 #define CANISOLATOR_INIT_ERROR 0xFF
78 
84 #define DRV_RX_BUFFER_SIZE 500
85  // End group macro
88 // --------------------------------------------------------------- PUBLIC TYPES
98 typedef struct
99 {
100  // Modules
101 
102  uart_t uart;
103 
104  char uart_rx_buffer[ DRV_RX_BUFFER_SIZE ];
105  char uart_tx_buffer[ DRV_RX_BUFFER_SIZE ];
106 
107 } canisolator_t;
108 
112 typedef struct
113 {
114  // Communication gpio pins
115 
116  pin_name_t rx_pin;
117  pin_name_t tx_pin;
118 
119  // static variable
120 
121  uint32_t baud_rate; // Clock speed.
123  uart_data_bits_t data_bit; // Data bits.
124  uart_parity_t parity_bit; // Parity bit.
125  uart_stop_bits_t stop_bit; // Stop bits.
126 
128  // End types group
130 // ------------------------------------------------------------------ CONSTANTS // End constants group
139 // ------------------------------------------------------------------ VARIABLES // End variable group
147 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
148 
154 #ifdef __cplusplus
155 extern "C"{
156 #endif
157 
167 
176 
186 void canisolator_generic_multi_write ( canisolator_t *ctx, char *data_buf, uint8_t len );
187 
197 void canisolator_generic_multi_read ( canisolator_t *ctx, char *data_buf, uint8_t len );
198 
199 
209 
219 
220 #ifdef __cplusplus
221 }
222 #endif
223 #endif // _CANISOLATOR_H_
224  // End public_function group
227 
228 // ------------------------------------------------------------------------- END
DRV_RX_BUFFER_SIZE
#define DRV_RX_BUFFER_SIZE
Definition: canisolator.h:84
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:125
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:99
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:124
canisolator_cfg_t::tx_pin
pin_name_t tx_pin
Definition: canisolator.h:117
CANISOLATOR_RETVAL
#define CANISOLATOR_RETVAL
Definition: canisolator.h:74
canisolator_cfg_t::rx_pin
pin_name_t rx_pin
Definition: canisolator.h:116
canisolator_cfg_t::baud_rate
uint32_t baud_rate
Definition: canisolator.h:121
canisolator_cfg_t
Click configuration structure definition.
Definition: canisolator.h:113
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:102
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:123
canisolator_cfg_t::uart_blocking
bool uart_blocking
Definition: canisolator.h:122