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 )
56 
62 #define CANFD3_RETVAL uint8_t
63 
64 #define CANFD3_OK 0x00
65 #define CANFD3_INIT_ERROR 0xFF
66 
72 #define CANFD3_MODE_NORMAL 0
73 #define CANFD3_MODE_STAND_BY 1
74 
80 #define DRV_RX_BUFFER_SIZE 500
81  // End group macro
84 // --------------------------------------------------------------- PUBLIC TYPES
92 typedef 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 
110 typedef 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 
129 } canfd3_cfg_t;
130 
134 typedef uint8_t canfd3_error_t;
135  // End types group
137 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
138 
144 #ifdef __cplusplus
145 extern "C"{
146 #endif
147 
156 void canfd3_cfg_setup ( canfd3_cfg_t *cfg );
157 
166 
173 void canfd3_generic_write ( canfd3_t *ctx, char *data_buf, uint16_t len );
174 
182 int32_t canfd3_generic_read ( canfd3_t *ctx, char *data_buf, uint16_t max_len );
183 
189 void 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
DRV_RX_BUFFER_SIZE
#define DRV_RX_BUFFER_SIZE
Definition: canfd3.h:80
canfd3_init
CANFD3_RETVAL canfd3_init(canfd3_t *ctx, canfd3_cfg_t *cfg)
Initialization function.
canfd3_cfg_t::baud_rate
uint32_t baud_rate
Definition: canfd3.h:123
canfd3_error_t
uint8_t canfd3_error_t
Error type.
Definition: canfd3.h:134
canfd3_cfg_t::cs
pin_name_t cs
Definition: canfd3.h:119
canfd3_set_cs_pin
void canfd3_set_cs_pin(canfd3_t *ctx, uint8_t mode)
Sets the CS pin state.
canfd3_generic_write
void canfd3_generic_write(canfd3_t *ctx, char *data_buf, uint16_t len)
Generic write function.
canfd3_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: canfd3.h:125
canfd3_cfg_t::tx_pin
pin_name_t tx_pin
Definition: canfd3.h:115
canfd3_cfg_setup
void canfd3_cfg_setup(canfd3_cfg_t *cfg)
Config Object Initialization function.
canfd3_cfg_t
Click configuration structure definition.
Definition: canfd3.h:110
canfd3_t::cs
digital_out_t cs
Definition: canfd3.h:96
canfd3_cfg_t::rx_pin
pin_name_t rx_pin
Definition: canfd3.h:114
CANFD3_RETVAL
#define CANFD3_RETVAL
Definition: canfd3.h:62
canfd3_t
Click ctx object definition.
Definition: canfd3.h:92
canfd3_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: canfd3.h:126
canfd3_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: canfd3.h:127
canfd3_cfg_t::uart_blocking
bool uart_blocking
Definition: canfd3.h:124
canfd3_generic_read
int32_t canfd3_generic_read(canfd3_t *ctx, char *data_buf, uint16_t max_len)
Generic read function.
canfd3_t::uart
uart_t uart
Definition: canfd3.h:100