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 );
79#define CANFD5_RETVAL uint8_t
80
81#define CANFD5_OK 0x00
82#define CANFD5_INIT_ERROR 0xFF
89#define DRV_RX_BUFFER_SIZE 500
96#define CANFD5_PIN_STATE_DISABLE 0x00
97#define CANFD5_PIN_STATE_ENABLE 0x01
104#define CANFD5_OPERATING_MODE_NORMAL 0x00
105#define CANFD5_OPERATING_MODE_STAND_BY 0x01
106#define CANFD5_OPERATING_MODE_SLEEP 0x02
109 // End group macro
110// --------------------------------------------------------------- PUBLIC TYPES
118typedef 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
142typedef 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
164
168typedef uint8_t canfd5_error_t;
169
170 // End types group
171// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
172
178#ifdef __cplusplus
179extern "C"{
180#endif
181
191
200
207void canfd5_generic_write ( canfd5_t *ctx, char *data_buf, uint16_t len );
208
216int32_t canfd5_generic_read ( canfd5_t *ctx, char *data_buf, uint16_t max_len );
217
229void canfd5_set_slp_pin_state ( canfd5_t *ctx, uint8_t slp_state );
230
242void canfd5_set_wak_pin_state ( canfd5_t *ctx, uint8_t wak_state );
243
256
266
276
286
299void canfd5_set_operating_mode ( canfd5_t *ctx, uint8_t op_mode );
300
301#ifdef __cplusplus
302}
303#endif
304#endif // _CANFD5_H_
305
306 // End public_function group
308
309// ------------------------------------------------------------------------- END
#define DRV_RX_BUFFER_SIZE
Definition canfd5.h:89
#define CANFD5_RETVAL
Definition canfd5.h:79
void canfd5_generic_write(canfd5_t *ctx, char *data_buf, uint16_t len)
Generic write function.
void canfd5_set_wak_pin_state(canfd5_t *ctx, uint8_t wak_state)
Set WAK pin state function.
void canfd5_cfg_setup(canfd5_cfg_t *cfg)
Config Object Initialization function.
void canfd5_set_normal_operating_mode(canfd5_t *ctx)
Set normal operating mode function.
int32_t canfd5_generic_read(canfd5_t *ctx, char *data_buf, uint16_t max_len)
Generic read function.
void canfd5_set_slp_pin_state(canfd5_t *ctx, uint8_t slp_state)
Set SLP pin state function.
CANFD5_RETVAL canfd5_init(canfd5_t *ctx, canfd5_cfg_t *cfg)
Initialization function.
void canfd5_set_standby_operating_mode(canfd5_t *ctx)
Set stand-by operating mode function.
void canfd5_set_sleep_operating_mode(canfd5_t *ctx)
Set sleep operating mode function.
uint8_t canfd5_get_cts_pin_state(canfd5_t *ctx)
Set WAK pin state function.
void canfd5_set_operating_mode(canfd5_t *ctx, uint8_t op_mode)
Set operating mode function.
uint8_t canfd5_error_t
Error type.
Definition canfd5.h:168
Click configuration structure definition.
Definition canfd5.h:143
uint32_t baud_rate
Definition canfd5.h:157
bool uart_blocking
Definition canfd5.h:158
uart_data_bits_t data_bit
Definition canfd5.h:159
pin_name_t tx_pin
Definition canfd5.h:147
pin_name_t rx_pin
Definition canfd5.h:146
uart_stop_bits_t stop_bit
Definition canfd5.h:161
pin_name_t int_pin
Definition canfd5.h:153
pin_name_t pwm
Definition canfd5.h:152
uart_parity_t parity_bit
Definition canfd5.h:160
pin_name_t cs
Definition canfd5.h:151
Click ctx object definition.
Definition canfd5.h:119
digital_out_t cs
Definition canfd5.h:122
digital_out_t pwm
Definition canfd5.h:123
uart_t uart
Definition canfd5.h:132
digital_in_t int_pin
Definition canfd5.h:128