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 "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 
53 // -------------------------------------------------------------- PUBLIC MACROS
63 #define CANFD5_MAP_MIKROBUS( cfg, mikrobus ) \
64  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
65  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
66  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
67  cfg.pwm = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
68  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT );
69 
75 #define CANFD5_RETVAL uint8_t
76 
77 #define CANFD5_OK 0x00
78 #define CANFD5_INIT_ERROR 0xFF
79 
85 #define DRV_RX_BUFFER_SIZE 500
86 
92 #define CANFD5_PIN_STATE_DISABLE 0x00
93 #define CANFD5_PIN_STATE_ENABLE 0x01
94 
100 #define CANFD5_OPERATING_MODE_NORMAL 0x00
101 #define CANFD5_OPERATING_MODE_STAND_BY 0x01
102 #define CANFD5_OPERATING_MODE_SLEEP 0x02
103  // End group macro
106 // --------------------------------------------------------------- PUBLIC TYPES
114 typedef struct
115 {
116  // Output pins
117 
118  digital_out_t cs;
119  digital_out_t pwm;
120 
121 
122  // Input pins
123 
124  digital_in_t int_pin;
125 
126  // Modules
127 
128  uart_t uart;
129 
130  char uart_rx_buffer[ DRV_RX_BUFFER_SIZE ];
131  char uart_tx_buffer[ DRV_RX_BUFFER_SIZE ];
132 
133 } canfd5_t;
134 
138 typedef struct
139 {
140  // Communication gpio pins
141 
142  pin_name_t rx_pin;
143  pin_name_t tx_pin;
144 
145  // Additional gpio pins
146 
147  pin_name_t cs;
148  pin_name_t pwm;
149  pin_name_t int_pin;
150 
151  // static variable
152 
153  uint32_t baud_rate; // Clock speed.
155  uart_data_bits_t data_bit; // Data bits.
156  uart_parity_t parity_bit; // Parity bit.
157  uart_stop_bits_t stop_bit; // Stop bits.
158 
159 } canfd5_cfg_t;
160 
164 typedef uint8_t canfd5_error_t;
165  // End types group
167 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
168 
174 #ifdef __cplusplus
175 extern "C"{
176 #endif
177 
187 
196 
203 void canfd5_generic_write ( canfd5_t *ctx, char *data_buf, uint16_t len );
204 
212 int32_t canfd5_generic_read ( canfd5_t *ctx, char *data_buf, uint16_t max_len );
213 
225 void canfd5_set_slp_pin_state ( canfd5_t *ctx, uint8_t slp_state );
226 
238 void canfd5_set_wak_pin_state ( canfd5_t *ctx, uint8_t wak_state );
239 
252 
262 
272 
282 
295 void canfd5_set_operating_mode ( canfd5_t *ctx, uint8_t op_mode );
296 
297 #ifdef __cplusplus
298 }
299 #endif
300 #endif // _CANFD5_H_
301  // End public_function group
304 
305 // ------------------------------------------------------------------------- END
canfd5_cfg_t::uart_blocking
bool uart_blocking
Definition: canfd5.h:154
DRV_RX_BUFFER_SIZE
#define DRV_RX_BUFFER_SIZE
Definition: canfd5.h:85
canfd5_t::uart
uart_t uart
Definition: canfd5.h:128
canfd5_t::int_pin
digital_in_t int_pin
Definition: canfd5.h:124
canfd5_cfg_t::int_pin
pin_name_t int_pin
Definition: canfd5.h:149
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:143
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:119
canfd5_t::cs
digital_out_t cs
Definition: canfd5.h:118
canfd5_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: canfd5.h:157
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:139
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:142
canfd5_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: canfd5.h:155
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:75
canfd5_cfg_t::cs
pin_name_t cs
Definition: canfd5.h:147
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:115
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:153
canfd5_cfg_t::pwm
pin_name_t pwm
Definition: canfd5.h:148
canfd5_error_t
uint8_t canfd5_error_t
Error type.
Definition: canfd5.h:164
canfd5_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: canfd5.h:156