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 "mikrosdk_version.h"
39 
40 #ifdef __GNUC__
41 #if mikroSDK_GET_VERSION < 20800ul
42 #include "rcu_delays.h"
43 #else
44 #include "delays.h"
45 #endif
46 #endif
47 
48 #include "drv_digital_out.h"
49 #include "drv_digital_in.h"
50 #include "drv_uart.h"
51 
52 // -------------------------------------------------------------- PUBLIC MACROS
62 #define CANFD3_MAP_MIKROBUS( cfg, mikrobus ) \
63  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
64  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
65  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS )
66 
72 #define CANFD3_RETVAL uint8_t
73 
74 #define CANFD3_OK 0x00
75 #define CANFD3_INIT_ERROR 0xFF
76 
82 #define CANFD3_MODE_NORMAL 0
83 #define CANFD3_MODE_STAND_BY 1
84 
90 #define DRV_RX_BUFFER_SIZE 500
91  // End group macro
94 // --------------------------------------------------------------- PUBLIC TYPES
102 typedef struct
103 {
104  // Output pins
105 
106  digital_out_t cs;
107 
108  // Modules
109 
110  uart_t uart;
111 
112  char uart_rx_buffer[ DRV_RX_BUFFER_SIZE ];
113  char uart_tx_buffer[ DRV_RX_BUFFER_SIZE ];
114 
115 } canfd3_t;
116 
120 typedef struct
121 {
122  // Communication gpio pins
123 
124  pin_name_t rx_pin;
125  pin_name_t tx_pin;
126 
127  // Additional gpio pins
128 
129  pin_name_t cs;
130 
131  // static variable
132 
133  uint32_t baud_rate; // Clock speed.
135  uart_data_bits_t data_bit; // Data bits.
136  uart_parity_t parity_bit; // Parity bit.
137  uart_stop_bits_t stop_bit; // Stop bits.
138 
139 } canfd3_cfg_t;
140 
144 typedef uint8_t canfd3_error_t;
145  // End types group
147 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
148 
154 #ifdef __cplusplus
155 extern "C"{
156 #endif
157 
167 
176 
183 void canfd3_generic_write ( canfd3_t *ctx, char *data_buf, uint16_t len );
184 
192 int32_t canfd3_generic_read ( canfd3_t *ctx, char *data_buf, uint16_t max_len );
193 
199 void canfd3_set_cs_pin ( canfd3_t *ctx, uint8_t mode );
200 
201 #ifdef __cplusplus
202 }
203 #endif
204 #endif // _CANFD3_H_
205  // End public_function group
208 
209 // ------------------------------------------------------------------------- END
DRV_RX_BUFFER_SIZE
#define DRV_RX_BUFFER_SIZE
Definition: canfd3.h:90
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:133
canfd3_error_t
uint8_t canfd3_error_t
Error type.
Definition: canfd3.h:144
canfd3_cfg_t::cs
pin_name_t cs
Definition: canfd3.h:129
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:135
canfd3_cfg_t::tx_pin
pin_name_t tx_pin
Definition: canfd3.h:125
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:121
canfd3_t::cs
digital_out_t cs
Definition: canfd3.h:106
canfd3_cfg_t::rx_pin
pin_name_t rx_pin
Definition: canfd3.h:124
CANFD3_RETVAL
#define CANFD3_RETVAL
Definition: canfd3.h:72
canfd3_t
Click ctx object definition.
Definition: canfd3.h:103
canfd3_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: canfd3.h:136
canfd3_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: canfd3.h:137
canfd3_cfg_t::uart_blocking
bool uart_blocking
Definition: canfd3.h:134
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:110