canfd4  2.0.0.0
canfd4.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 CANFD4_H
36 #define CANFD4_H
37 
38 #include "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_uart.h"
41 
42 
43 // -------------------------------------------------------------- PUBLIC MACROS
53 #define CANFD4_MAP_MIKROBUS( cfg, mikrobus ) \
54  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
55  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
56  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS )
57 
63 #define CANFD4_RETVAL uint8_t
64 
65 #define CANFD4_OK 0x00
66 #define CANFD4_INIT_ERROR 0xFF
67 
73 #define CANFD4_NORMAL_MODE 0
74 #define CANFD4_STANDBY_MODE 1
75 
81 #define DRV_RX_BUFFER_SIZE 500
82  // End group macro
85 // --------------------------------------------------------------- PUBLIC TYPES
93 typedef struct
94 {
95  // Output pins
96 
97  digital_out_t cs;
98 
99  // Modules
100 
101  uart_t uart;
102 
103  char uart_rx_buffer[ DRV_RX_BUFFER_SIZE ];
104  char uart_tx_buffer[ DRV_RX_BUFFER_SIZE ];
105 
106 } canfd4_t;
107 
111 typedef struct
112 {
113  // Communication gpio pins
114 
115  pin_name_t rx_pin;
116  pin_name_t tx_pin;
117 
118  // Additional gpio pins
119 
120  pin_name_t cs;
121 
122  // static variable
123 
124  uint32_t baud_rate; // Clock speed.
126  uart_data_bits_t data_bit; // Data bits.
127  uart_parity_t parity_bit; // Parity bit.
128  uart_stop_bits_t stop_bit; // Stop bits.
129 
130 } canfd4_cfg_t;
131 
135 typedef uint8_t canfd4_error_t;
136  // End types group
138 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
139 
145 #ifdef __cplusplus
146 extern "C"{
147 #endif
148 
157 void canfd4_cfg_setup ( canfd4_cfg_t *cfg );
158 
167 
174 void canfd4_generic_write ( canfd4_t *ctx, char *data_buf, uint16_t len );
175 
183 int32_t canfd4_generic_read ( canfd4_t *ctx, char *data_buf, uint16_t max_len );
184 
190 void canfd4_set_dev_mode ( canfd4_t *ctx, uint8_t mode );
191 
192 
193 #ifdef __cplusplus
194 }
195 #endif
196 #endif // _CANFD4_H_
197  // End public_function group
200 
201 // ------------------------------------------------------------------------- END
DRV_RX_BUFFER_SIZE
#define DRV_RX_BUFFER_SIZE
Definition: canfd4.h:81
canfd4_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: canfd4.h:127
canfd4_generic_write
void canfd4_generic_write(canfd4_t *ctx, char *data_buf, uint16_t len)
Generic write function.
canfd4_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: canfd4.h:128
canfd4_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: canfd4.h:126
canfd4_cfg_t::uart_blocking
bool uart_blocking
Definition: canfd4.h:125
canfd4_generic_read
int32_t canfd4_generic_read(canfd4_t *ctx, char *data_buf, uint16_t max_len)
Generic read function.
canfd4_cfg_t::rx_pin
pin_name_t rx_pin
Definition: canfd4.h:115
canfd4_error_t
uint8_t canfd4_error_t
Error type.
Definition: canfd4.h:135
canfd4_set_dev_mode
void canfd4_set_dev_mode(canfd4_t *ctx, uint8_t mode)
Set mode function.
canfd4_cfg_t
Click configuration structure definition.
Definition: canfd4.h:111
CANFD4_RETVAL
#define CANFD4_RETVAL
Definition: canfd4.h:63
canfd4_cfg_t::cs
pin_name_t cs
Definition: canfd4.h:120
canfd4_t::uart
uart_t uart
Definition: canfd4.h:101
canfd4_cfg_setup
void canfd4_cfg_setup(canfd4_cfg_t *cfg)
Config Object Initialization function.
canfd4_cfg_t::tx_pin
pin_name_t tx_pin
Definition: canfd4.h:116
canfd4_cfg_t::baud_rate
uint32_t baud_rate
Definition: canfd4.h:124
canfd4_init
CANFD4_RETVAL canfd4_init(canfd4_t *ctx, canfd4_cfg_t *cfg)
Initialization function.
canfd4_t::cs
digital_out_t cs
Definition: canfd4.h:97
canfd4_t
Click ctx object definition.
Definition: canfd4.h:93