canfd3 2.0.0.0
canfd3.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 CANFD3_H
36#define CANFD3_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_digital_in.h"
54#include "drv_uart.h"
55
56// -------------------------------------------------------------- PUBLIC MACROS
66#define CANFD3_MAP_MIKROBUS( cfg, mikrobus ) \
67 cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
68 cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
69 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS )
76#define CANFD3_RETVAL uint8_t
77
78#define CANFD3_OK 0x00
79#define CANFD3_INIT_ERROR 0xFF
86#define CANFD3_MODE_NORMAL 0
87#define CANFD3_MODE_STAND_BY 1
94#define DRV_RX_BUFFER_SIZE 500
97 // End group macro
98// --------------------------------------------------------------- PUBLIC TYPES
106typedef struct
107{
108 // Output pins
109
110 digital_out_t cs;
111
112 // Modules
113
114 uart_t uart;
115
116 char uart_rx_buffer[ DRV_RX_BUFFER_SIZE ];
117 char uart_tx_buffer[ DRV_RX_BUFFER_SIZE ];
118
119} canfd3_t;
120
124typedef struct
125{
126 // Communication gpio pins
127
128 pin_name_t rx_pin;
129 pin_name_t tx_pin;
130
131 // Additional gpio pins
132
133 pin_name_t cs;
134
135 // static variable
136
137 uint32_t baud_rate; // Clock speed.
139 uart_data_bits_t data_bit; // Data bits.
140 uart_parity_t parity_bit; // Parity bit.
141 uart_stop_bits_t stop_bit; // Stop bits.
142
144
148typedef uint8_t canfd3_error_t;
149
150 // End types group
151// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
152
158#ifdef __cplusplus
159extern "C"{
160#endif
161
171
180
187void canfd3_generic_write ( canfd3_t *ctx, char *data_buf, uint16_t len );
188
196int32_t canfd3_generic_read ( canfd3_t *ctx, char *data_buf, uint16_t max_len );
197
203void canfd3_set_cs_pin ( canfd3_t *ctx, uint8_t mode );
204
205#ifdef __cplusplus
206}
207#endif
208#endif // _CANFD3_H_
209
210 // End public_function group
212
213// ------------------------------------------------------------------------- END
#define DRV_RX_BUFFER_SIZE
Definition canfd3.h:94
#define CANFD3_RETVAL
Definition canfd3.h:76
CANFD3_RETVAL canfd3_init(canfd3_t *ctx, canfd3_cfg_t *cfg)
Initialization function.
void canfd3_cfg_setup(canfd3_cfg_t *cfg)
Config Object Initialization function.
int32_t canfd3_generic_read(canfd3_t *ctx, char *data_buf, uint16_t max_len)
Generic read function.
void canfd3_set_cs_pin(canfd3_t *ctx, uint8_t mode)
Sets the CS pin state.
void canfd3_generic_write(canfd3_t *ctx, char *data_buf, uint16_t len)
Generic write function.
uint8_t canfd3_error_t
Error type.
Definition canfd3.h:148
Click configuration structure definition.
Definition canfd3.h:125
uint32_t baud_rate
Definition canfd3.h:137
bool uart_blocking
Definition canfd3.h:138
uart_data_bits_t data_bit
Definition canfd3.h:139
pin_name_t tx_pin
Definition canfd3.h:129
pin_name_t rx_pin
Definition canfd3.h:128
uart_stop_bits_t stop_bit
Definition canfd3.h:141
uart_parity_t parity_bit
Definition canfd3.h:140
pin_name_t cs
Definition canfd3.h:133
Click ctx object definition.
Definition canfd3.h:107
digital_out_t cs
Definition canfd3.h:110
uart_t uart
Definition canfd3.h:114