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 
38 #include "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_uart.h"
41 
42 
43 // -------------------------------------------------------------- PUBLIC MACROS
53 #define CANFD5_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  cfg.pwm = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
58  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT );
59 
65 #define CANFD5_RETVAL uint8_t
66 
67 #define CANFD5_OK 0x00
68 #define CANFD5_INIT_ERROR 0xFF
69 
75 #define DRV_RX_BUFFER_SIZE 500
76 
82 #define CANFD5_PIN_STATE_DISABLE 0x00
83 #define CANFD5_PIN_STATE_ENABLE 0x01
84 
90 #define CANFD5_OPERATING_MODE_NORMAL 0x00
91 #define CANFD5_OPERATING_MODE_STAND_BY 0x01
92 #define CANFD5_OPERATING_MODE_SLEEP 0x02
93  // End group macro
96 // --------------------------------------------------------------- PUBLIC TYPES
104 typedef struct
105 {
106  // Output pins
107 
108  digital_out_t cs;
109  digital_out_t pwm;
110 
111 
112  // Input pins
113 
114  digital_in_t int_pin;
115 
116  // Modules
117 
118  uart_t uart;
119 
120  char uart_rx_buffer[ DRV_RX_BUFFER_SIZE ];
121  char uart_tx_buffer[ DRV_RX_BUFFER_SIZE ];
122 
123 } canfd5_t;
124 
128 typedef struct
129 {
130  // Communication gpio pins
131 
132  pin_name_t rx_pin;
133  pin_name_t tx_pin;
134 
135  // Additional gpio pins
136 
137  pin_name_t cs;
138  pin_name_t pwm;
139  pin_name_t int_pin;
140 
141  // static variable
142 
143  uint32_t baud_rate; // Clock speed.
145  uart_data_bits_t data_bit; // Data bits.
146  uart_parity_t parity_bit; // Parity bit.
147  uart_stop_bits_t stop_bit; // Stop bits.
148 
149 } canfd5_cfg_t;
150 
154 typedef uint8_t canfd5_error_t;
155  // End types group
157 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
158 
164 #ifdef __cplusplus
165 extern "C"{
166 #endif
167 
177 
186 
193 void canfd5_generic_write ( canfd5_t *ctx, char *data_buf, uint16_t len );
194 
202 int32_t canfd5_generic_read ( canfd5_t *ctx, char *data_buf, uint16_t max_len );
203 
215 void canfd5_set_slp_pin_state ( canfd5_t *ctx, uint8_t slp_state );
216 
228 void canfd5_set_wak_pin_state ( canfd5_t *ctx, uint8_t wak_state );
229 
242 
252 
262 
272 
285 void canfd5_set_operating_mode ( canfd5_t *ctx, uint8_t op_mode );
286 
287 #ifdef __cplusplus
288 }
289 #endif
290 #endif // _CANFD5_H_
291  // End public_function group
294 
295 // ------------------------------------------------------------------------- END
canfd5_cfg_t::uart_blocking
bool uart_blocking
Definition: canfd5.h:144
DRV_RX_BUFFER_SIZE
#define DRV_RX_BUFFER_SIZE
Definition: canfd5.h:75
canfd5_t::uart
uart_t uart
Definition: canfd5.h:118
canfd5_t::int_pin
digital_in_t int_pin
Definition: canfd5.h:114
canfd5_cfg_t::int_pin
pin_name_t int_pin
Definition: canfd5.h:139
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:133
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:109
canfd5_t::cs
digital_out_t cs
Definition: canfd5.h:108
canfd5_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: canfd5.h:147
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:129
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:132
canfd5_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: canfd5.h:145
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:65
canfd5_cfg_t::cs
pin_name_t cs
Definition: canfd5.h:137
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:105
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:143
canfd5_cfg_t::pwm
pin_name_t pwm
Definition: canfd5.h:138
canfd5_error_t
uint8_t canfd5_error_t
Error type.
Definition: canfd5.h:154
canfd5_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: canfd5.h:146