canfd5  2.0.0.0
canfd5.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 CANFD5_H
36 #define CANFD5_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 
57 // -------------------------------------------------------------- PUBLIC MACROS
67 #define CANFD5_MAP_MIKROBUS( cfg, mikrobus ) \
68  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
69  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
70  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
71  cfg.pwm = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
72  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT );
73 
79 #define CANFD5_RETVAL uint8_t
80 
81 #define CANFD5_OK 0x00
82 #define CANFD5_INIT_ERROR 0xFF
83 
89 #define DRV_RX_BUFFER_SIZE 500
90 
96 #define CANFD5_PIN_STATE_DISABLE 0x00
97 #define CANFD5_PIN_STATE_ENABLE 0x01
98 
104 #define CANFD5_OPERATING_MODE_NORMAL 0x00
105 #define CANFD5_OPERATING_MODE_STAND_BY 0x01
106 #define CANFD5_OPERATING_MODE_SLEEP 0x02
107  // End group macro
110 // --------------------------------------------------------------- PUBLIC TYPES
118 typedef struct
119 {
120  // Output pins
121 
122  digital_out_t cs;
123  digital_out_t pwm;
124 
125 
126  // Input pins
127 
128  digital_in_t int_pin;
129 
130  // Modules
131 
132  uart_t uart;
133 
134  char uart_rx_buffer[ DRV_RX_BUFFER_SIZE ];
135  char uart_tx_buffer[ DRV_RX_BUFFER_SIZE ];
136 
137 } canfd5_t;
138 
142 typedef struct
143 {
144  // Communication gpio pins
145 
146  pin_name_t rx_pin;
147  pin_name_t tx_pin;
148 
149  // Additional gpio pins
150 
151  pin_name_t cs;
152  pin_name_t pwm;
153  pin_name_t int_pin;
154 
155  // static variable
156 
157  uint32_t baud_rate; // Clock speed.
159  uart_data_bits_t data_bit; // Data bits.
160  uart_parity_t parity_bit; // Parity bit.
161  uart_stop_bits_t stop_bit; // Stop bits.
162 
163 } canfd5_cfg_t;
164 
168 typedef uint8_t canfd5_error_t;
169  // End types group
171 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
172 
178 #ifdef __cplusplus
179 extern "C"{
180 #endif
181 
191 
200 
207 void canfd5_generic_write ( canfd5_t *ctx, char *data_buf, uint16_t len );
208 
216 int32_t canfd5_generic_read ( canfd5_t *ctx, char *data_buf, uint16_t max_len );
217 
229 void canfd5_set_slp_pin_state ( canfd5_t *ctx, uint8_t slp_state );
230 
242 void canfd5_set_wak_pin_state ( canfd5_t *ctx, uint8_t wak_state );
243 
256 
266 
276 
286 
299 void canfd5_set_operating_mode ( canfd5_t *ctx, uint8_t op_mode );
300 
301 #ifdef __cplusplus
302 }
303 #endif
304 #endif // _CANFD5_H_
305  // End public_function group
308 
309 // ------------------------------------------------------------------------- END
canfd5_cfg_t::uart_blocking
bool uart_blocking
Definition: canfd5.h:158
DRV_RX_BUFFER_SIZE
#define DRV_RX_BUFFER_SIZE
Definition: canfd5.h:89
canfd5_t::uart
uart_t uart
Definition: canfd5.h:132
canfd5_t::int_pin
digital_in_t int_pin
Definition: canfd5.h:128
canfd5_cfg_t::int_pin
pin_name_t int_pin
Definition: canfd5.h:153
canfd5_set_sleep_operating_mode
void canfd5_set_sleep_operating_mode(canfd5_t *ctx)
Set sleep operating mode function.
canfd5_generic_write
void canfd5_generic_write(canfd5_t *ctx, char *data_buf, uint16_t len)
Generic write function.
canfd5_set_wak_pin_state
void canfd5_set_wak_pin_state(canfd5_t *ctx, uint8_t wak_state)
Set WAK pin state function.
canfd5_cfg_t::tx_pin
pin_name_t tx_pin
Definition: canfd5.h:147
canfd5_set_standby_operating_mode
void canfd5_set_standby_operating_mode(canfd5_t *ctx)
Set stand-by operating mode function.
canfd5_set_operating_mode
void canfd5_set_operating_mode(canfd5_t *ctx, uint8_t op_mode)
Set operating mode function.
canfd5_t::pwm
digital_out_t pwm
Definition: canfd5.h:123
canfd5_t::cs
digital_out_t cs
Definition: canfd5.h:122
canfd5_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: canfd5.h:161
canfd5_generic_read
int32_t canfd5_generic_read(canfd5_t *ctx, char *data_buf, uint16_t max_len)
Generic read function.
canfd5_cfg_t
Click configuration structure definition.
Definition: canfd5.h:143
canfd5_set_normal_operating_mode
void canfd5_set_normal_operating_mode(canfd5_t *ctx)
Set normal operating mode function.
canfd5_cfg_t::rx_pin
pin_name_t rx_pin
Definition: canfd5.h:146
canfd5_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: canfd5.h:159
canfd5_set_slp_pin_state
void canfd5_set_slp_pin_state(canfd5_t *ctx, uint8_t slp_state)
Set SLP pin state function.
canfd5_cfg_setup
void canfd5_cfg_setup(canfd5_cfg_t *cfg)
Config Object Initialization function.
CANFD5_RETVAL
#define CANFD5_RETVAL
Definition: canfd5.h:79
canfd5_cfg_t::cs
pin_name_t cs
Definition: canfd5.h:151
canfd5_get_cts_pin_state
uint8_t canfd5_get_cts_pin_state(canfd5_t *ctx)
Set WAK pin state function.
canfd5_t
Click ctx object definition.
Definition: canfd5.h:119
canfd5_init
CANFD5_RETVAL canfd5_init(canfd5_t *ctx, canfd5_cfg_t *cfg)
Initialization function.
canfd5_cfg_t::baud_rate
uint32_t baud_rate
Definition: canfd5.h:157
canfd5_cfg_t::pwm
pin_name_t pwm
Definition: canfd5.h:152
canfd5_error_t
uint8_t canfd5_error_t
Error type.
Definition: canfd5.h:168
canfd5_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: canfd5.h:160