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
38#include "drv_digital_out.h"
39#include "drv_digital_in.h"
40#include "drv_uart.h"
41
42// -------------------------------------------------------------- PUBLIC MACROS
52#define CANFD3_MAP_MIKROBUS( cfg, mikrobus ) \
53 cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
54 cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
55 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS )
62#define CANFD3_RETVAL uint8_t
63
64#define CANFD3_OK 0x00
65#define CANFD3_INIT_ERROR 0xFF
72#define CANFD3_MODE_NORMAL 0
73#define CANFD3_MODE_STAND_BY 1
80#define DRV_RX_BUFFER_SIZE 500 // End group macro
84// --------------------------------------------------------------- PUBLIC TYPES
92typedef struct
93{
94 // Output pins
95
96 digital_out_t cs;
97
98 // Modules
99
100 uart_t uart;
101
102 char uart_rx_buffer[ DRV_RX_BUFFER_SIZE ];
103 char uart_tx_buffer[ DRV_RX_BUFFER_SIZE ];
104
105} canfd3_t;
106
110typedef struct
111{
112 // Communication gpio pins
113
114 pin_name_t rx_pin;
115 pin_name_t tx_pin;
116
117 // Additional gpio pins
118
119 pin_name_t cs;
120
121 // static variable
122
123 uint32_t baud_rate; // Clock speed.
125 uart_data_bits_t data_bit; // Data bits.
126 uart_parity_t parity_bit; // Parity bit.
127 uart_stop_bits_t stop_bit; // Stop bits.
128
130
134typedef uint8_t canfd3_error_t;
135 // End types group
137// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
138
144#ifdef __cplusplus
145extern "C"{
146#endif
147
157
166
173void canfd3_generic_write ( canfd3_t *ctx, char *data_buf, uint16_t len );
174
182int32_t canfd3_generic_read ( canfd3_t *ctx, char *data_buf, uint16_t max_len );
183
189void canfd3_set_cs_pin ( canfd3_t *ctx, uint8_t mode );
190
191#ifdef __cplusplus
192}
193#endif
194#endif // _CANFD3_H_
195 // End public_function group
198
199// ------------------------------------------------------------------------- END
#define DRV_RX_BUFFER_SIZE
Definition: canfd3.h:80
#define CANFD3_RETVAL
Definition: canfd3.h:62
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:134
Click configuration structure definition.
Definition: canfd3.h:111
uint32_t baud_rate
Definition: canfd3.h:123
bool uart_blocking
Definition: canfd3.h:124
uart_data_bits_t data_bit
Definition: canfd3.h:125
pin_name_t tx_pin
Definition: canfd3.h:115
pin_name_t rx_pin
Definition: canfd3.h:114
uart_stop_bits_t stop_bit
Definition: canfd3.h:127
uart_parity_t parity_bit
Definition: canfd3.h:126
pin_name_t cs
Definition: canfd3.h:119
Click ctx object definition.
Definition: canfd3.h:93
digital_out_t cs
Definition: canfd3.h:96
uart_t uart
Definition: canfd3.h:100