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 )
70 
76 #define CANFD3_RETVAL uint8_t
77 
78 #define CANFD3_OK 0x00
79 #define CANFD3_INIT_ERROR 0xFF
80 
86 #define CANFD3_MODE_NORMAL 0
87 #define CANFD3_MODE_STAND_BY 1
88 
94 #define DRV_RX_BUFFER_SIZE 500
95  // End group macro
98 // --------------------------------------------------------------- PUBLIC TYPES
106 typedef 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 
124 typedef 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 
143 } canfd3_cfg_t;
144 
148 typedef uint8_t canfd3_error_t;
149  // End types group
151 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
152 
158 #ifdef __cplusplus
159 extern "C"{
160 #endif
161 
171 
180 
187 void canfd3_generic_write ( canfd3_t *ctx, char *data_buf, uint16_t len );
188 
196 int32_t canfd3_generic_read ( canfd3_t *ctx, char *data_buf, uint16_t max_len );
197 
203 void canfd3_set_cs_pin ( canfd3_t *ctx, uint8_t mode );
204 
205 #ifdef __cplusplus
206 }
207 #endif
208 #endif // _CANFD3_H_
209  // End public_function group
212 
213 // ------------------------------------------------------------------------- END
DRV_RX_BUFFER_SIZE
#define DRV_RX_BUFFER_SIZE
Definition: canfd3.h:94
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:137
canfd3_error_t
uint8_t canfd3_error_t
Error type.
Definition: canfd3.h:148
canfd3_cfg_t::cs
pin_name_t cs
Definition: canfd3.h:133
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:139
canfd3_cfg_t::tx_pin
pin_name_t tx_pin
Definition: canfd3.h:129
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:125
canfd3_t::cs
digital_out_t cs
Definition: canfd3.h:110
canfd3_cfg_t::rx_pin
pin_name_t rx_pin
Definition: canfd3.h:128
CANFD3_RETVAL
#define CANFD3_RETVAL
Definition: canfd3.h:76
canfd3_t
Click ctx object definition.
Definition: canfd3.h:107
canfd3_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: canfd3.h:140
canfd3_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: canfd3.h:141
canfd3_cfg_t::uart_blocking
bool uart_blocking
Definition: canfd3.h:138
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:114