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 )
74#define CANISOLATOR_RETVAL uint8_t
75
76#define CANISOLATOR_OK 0x00
77#define CANISOLATOR_INIT_ERROR 0xFF
84#define DRV_RX_BUFFER_SIZE 500
87 // End group macro
88// --------------------------------------------------------------- PUBLIC TYPES
98typedef 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
108
112typedef 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
129 // End types group
130// ------------------------------------------------------------------ CONSTANTS
138 // End constants group
139// ------------------------------------------------------------------ VARIABLES
146 // End variable group
147// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
148
154#ifdef __cplusplus
155extern "C"{
156#endif
157
167
176
186void canisolator_generic_multi_write ( canisolator_t *ctx, char *data_buf, uint8_t len );
187
197void 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
225 // End public_function group
227
228// ------------------------------------------------------------------------- END
#define DRV_RX_BUFFER_SIZE
Definition canisolator.h:84
#define CANISOLATOR_RETVAL
Definition canisolator.h:74
void canisolator_generic_multi_read(canisolator_t *ctx, char *data_buf, uint8_t len)
Generic multi read function.
void canisolator_generic_single_write(canisolator_t *ctx, char tx_data)
Generic single write function.
void canisolator_generic_multi_write(canisolator_t *ctx, char *data_buf, uint8_t len)
Generic multi write function.
CANISOLATOR_RETVAL canisolator_init(canisolator_t *ctx, canisolator_cfg_t *cfg)
Initialization function.
char canisolator_generic_single_read(canisolator_t *ctx)
Generic single read function.
void canisolator_cfg_setup(canisolator_cfg_t *cfg)
Config Object Initialization function.
Click configuration structure definition.
Definition canisolator.h:113
uint32_t baud_rate
Definition canisolator.h:121
bool uart_blocking
Definition canisolator.h:122
uart_data_bits_t data_bit
Definition canisolator.h:123
pin_name_t tx_pin
Definition canisolator.h:117
pin_name_t rx_pin
Definition canisolator.h:116
uart_stop_bits_t stop_bit
Definition canisolator.h:125
uart_parity_t parity_bit
Definition canisolator.h:124
Click ctx object definition.
Definition canisolator.h:99
uart_t uart
Definition canisolator.h:102