canbus 2.0.0.0
canbus.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 CANBUS_H
29#define CANBUS_H
30
31#ifdef __cplusplus
32extern "C"{
33#endif
34
39#ifdef PREINIT_SUPPORTED
40#include "preinit.h"
41#endif
42
43#ifdef MikroCCoreVersion
44 #if MikroCCoreVersion >= 1
45 #include "delays.h"
46 #endif
47#endif
48
49#include "drv_digital_out.h"
50#include "drv_digital_in.h"
51#include "drv_uart.h"
52
74#define DRV_BUFFER_SIZE 200
75
76 // canbus_set
77
92#define CANBUS_MAP_MIKROBUS( cfg, mikrobus ) \
93 cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
94 cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
95 cfg.stb = MIKROBUS( mikrobus, MIKROBUS_AN )
96
97 // canbus_map
98 // canbus
99
104typedef struct
105{
106 // Output pins
107
108 digital_out_t stb;
110 // Modules
111
112 uart_t uart;
114 // Buffers
115
116 char uart_rx_buffer[ DRV_BUFFER_SIZE ];
117 char uart_tx_buffer[ DRV_BUFFER_SIZE ];
119} canbus_t;
120
125typedef struct
126{
127 // Communication gpio pins
128
129 pin_name_t rx_pin;
130 pin_name_t tx_pin;
132 // Additional gpio pins
133
134 pin_name_t stb;
138 // Static variable
139
140 uint32_t baud_rate;
142 uart_data_bits_t data_bit;
143 uart_parity_t parity_bit;
144 uart_stop_bits_t stop_bit;
147
152typedef enum
153{
155 CANBUS_ERROR = -1
156
158
175
190err_t canbus_init ( canbus_t *ctx, canbus_cfg_t *cfg );
191
206
220err_t canbus_generic_write ( canbus_t *ctx, char *data_buf, uint16_t len );
221
235err_t canbus_generic_read ( canbus_t *ctx, char *data_buf, uint16_t max_len );
236
251
266
279err_t canbus_send_data ( canbus_t *ctx, char *tx_data );
280
281#ifdef __cplusplus
282}
283#endif
284#endif // CANBUS_H
285
286 // canbus
287
288// ------------------------------------------------------------------------ END
canbus_return_value_t
CAN Bus Click return value data.
Definition canbus.h:153
@ CANBUS_ERROR
Definition canbus.h:155
@ CANBUS_OK
Definition canbus.h:154
#define DRV_BUFFER_SIZE
CAN Bus driver buffer size.
Definition canbus.h:74
void canbus_cfg_setup(canbus_cfg_t *cfg)
CAN Bus configuration object setup function.
err_t canbus_generic_read(canbus_t *ctx, char *data_buf, uint16_t max_len)
CAN Bus data reading function.
err_t canbus_send_data(canbus_t *ctx, char *tx_data)
CAN Bus send data function.
err_t canbus_default_cfg(canbus_t *ctx)
CAN Bus default configuration function.
err_t canbus_set_high_speed_mode(canbus_t *ctx)
CAN Bus high speed mode function.
err_t canbus_init(canbus_t *ctx, canbus_cfg_t *cfg)
CAN Bus initialization function.
err_t canbus_set_low_current_standby_mode(canbus_t *ctx)
CAN Bus low current standby mode function.
err_t canbus_generic_write(canbus_t *ctx, char *data_buf, uint16_t len)
CAN Bus data writing function.
CAN Bus Click configuration object.
Definition canbus.h:126
uint32_t baud_rate
Definition canbus.h:140
bool uart_blocking
Definition canbus.h:141
uart_data_bits_t data_bit
Definition canbus.h:142
pin_name_t tx_pin
Definition canbus.h:130
pin_name_t rx_pin
Definition canbus.h:129
uart_stop_bits_t stop_bit
Definition canbus.h:144
uart_parity_t parity_bit
Definition canbus.h:143
pin_name_t stb
Definition canbus.h:134
CAN Bus Click context object.
Definition canbus.h:105
digital_out_t stb
Definition canbus.h:108
uart_t uart
Definition canbus.h:112