41#ifdef PREINIT_SUPPORTED
45#ifdef MikroCCoreVersion
46 #if MikroCCoreVersion >= 1
51#include "drv_digital_out.h"
52#include "drv_digital_in.h"
54#include "drv_spi_master.h"
67#define CANFD2_MAP_MIKROBUS( cfg, mikrobus ) \
68 cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
69 cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
70 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
71 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
72 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
73 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS )
81#define CANFD2_ERROR -1
88#define CANFD2_DRV_TX_BUFFER_SIZE 100
89#define CANFD2_DRV_RX_BUFFER_SIZE 300
96#define CANFD2_REG_MODE_CTRL 0x01
97#define CANFD2_REG_HW_CTRL 0x02
98#define CANFD2_REG_TXD_TO_CTRL 0x03
99#define CANFD2_REG_SUPPLY_CTRL 0x04
106#define CANFD2_REG_SWK_CTRL_1 0x05
107#define CANFD2_REG_SWK_CTRL_2 0x06
108#define CANFD2_REG_SWK_ID3_CTRL 0x07
109#define CANFD2_REG_SWK_ID2_CTRL 0x08
110#define CANFD2_REG_SWK_ID1_CTRL 0x09
111#define CANFD2_REG_SWK_ID0_CTRL 0x0A
112#define CANFD2_REG_SWK_MASK_ID3_CTRL 0x0B
113#define CANFD2_REG_SWK_MASK_ID2_CTRL 0x0C
114#define CANFD2_REG_SWK_MASK_ID1_CTRL 0x0D
115#define CANFD2_REG_SWK_MASK_ID0_CTRL 0x0E
116#define CANFD2_REG_SWK_DLC_CTRL 0x0F
117#define CANFD2_REG_SWK_DATA7_CTRL 0x10
118#define CANFD2_REG_SWK_DATA6_CTRL 0x11
119#define CANFD2_REG_SWK_DATA5_CTRL 0x12
120#define CANFD2_REG_SWK_DATA4_CTRL 0x13
121#define CANFD2_REG_SWK_DATA3_CTRL 0x14
122#define CANFD2_REG_SWK_DATA2_CTRL 0x15
123#define CANFD2_REG_SWK_DATA1_CTRL 0x16
124#define CANFD2_REG_SWK_DATA0_CTRL 0x17
131#define CANFD2_REG_TRANS_STAT 0x18
132#define CANFD2_REG_TRANS_UV_STAT 0x19
133#define CANFD2_REG_ERR_STAT 0x1A
134#define CANFD2_REG_WAKE_STAT 0x1B
141#define CANFD2_REG_SWK_STAT 0x1C
142#define CANFD2_REG_SWK_ECNT_STAT 0x1D
149#define CANFD2_CTRL_MODE_SLEEP 0x01
150#define CANFD2_CTRL_MODE_STANDBY 0x02
151#define CANFD2_CTRL_MODE_REC_ONLY 0x04
152#define CANFD2_CTRL_MODE_NORMAL_OP 0x08
159#define CANFD2_HW_CTRL_VBAT_CON 0x01
160#define CANFD2_HW_CTRL_WAKE_TOG 0x02
161#define CANFD2_HW_CTRL_LWU_POS 0x20
162#define CANFD2_HW_CTRL_LWU_NEG 0x40
163#define CANFD2_HW_CTRL_STTS_EN 0x80
170#define CANFD2_TXD_TO_1_4 0x01
171#define CANFD2_TXD_TO_2_5 0x02
172#define CANFD2_TXD_TO_5_10 0x03
173#define CANFD2_TXD_TO_DISABLE 0x04
180#define CANFD2_SUP_CTRL_VCC_UV_T_100 0x01
181#define CANFD2_SUP_CTRL_VCC_UV_T_200 0x02
182#define CANFD2_SUP_CTRL_VCC_UV_T_300 0x03
183#define CANFD2_SUP_CTRL_VCC_UV_T_400 0x04
184#define CANFD2_SUP_CTRL_VCC_UV_T_500 0x05
185#define CANFD2_SUP_CTRL_VCC_UV_T_600 0x06
186#define CANFD2_SUP_CTRL_VCC_UV_T_700 0x07
187#define CANFD2_SUP_CTRL_VCC_UV_T_800 0x08
188#define CANFD2_SUP_CTRL_VCC_UV_T_900 0x09
189#define CANFD2_SUP_CTRL_VCC_UV_T_1000 0x0A
190#define CANFD2_SUP_CTRL_VCC_UV_T_1100 0x0B
191#define CANFD2_SUP_CTRL_VCC_UV_T_1200 0x0C
192#define CANFD2_SUP_CTRL_VCC_UV_T_1300 0x0D
193#define CANFD2_SUP_CTRL_VCC_UV_T_1400 0x0E
194#define CANFD2_SUP_CTRL_VCC_UV_T_1500 0x0F
196#define CANFD2_SUP_CTRL_VIO_UV_T_100 0x10
197#define CANFD2_SUP_CTRL_VIO_UV_T_200 0x20
198#define CANFD2_SUP_CTRL_VIO_UV_T_300 0x30
199#define CANFD2_SUP_CTRL_VIO_UV_T_400 0x40
200#define CANFD2_SUP_CTRL_VIO_UV_T_500 0x50
201#define CANFD2_SUP_CTRL_VIO_UV_T_600 0x60
202#define CANFD2_SUP_CTRL_VIO_UV_T_700 0x70
203#define CANFD2_SUP_CTRL_VIO_UV_T_800 0x80
204#define CANFD2_SUP_CTRL_VIO_UV_T_900 0x90
205#define CANFD2_SUP_CTRL_VIO_UV_T_1000 0xA0
206#define CANFD2_SUP_CTRL_VIO_UV_T_1100 0xB0
207#define CANFD2_SUP_CTRL_VIO_UV_T_1200 0xC0
208#define CANFD2_SUP_CTRL_VIO_UV_T_1300 0xD0
209#define CANFD2_SUP_CTRL_VIO_UV_T_1400 0xE0
210#define CANFD2_SUP_CTRL_VIO_UV_T_1500 0xF0
217#define CANFD2_SWK_CTRL_1_CFG_VAL 0x01
224#define CANFD2_SWK_CTRL_2_BR_125K 0x01
225#define CANFD2_SWK_CTRL_2_BR_250K 0x02
226#define CANFD2_SWK_CTRL_2_BR_500K 0x03
227#define CANFD2_SWK_CTRL_2_BR_1M 0x04
228#define CANFD2_SWK_CTRL_2_BR_RATIO_4 0x00
229#define CANFD2_SWK_CTRL_2_BR_RATIO_10 0x10
230#define CANFD2_SWK_CTRL_2_SWK_EN 0x80
237#define CANFD2_SWK_ID3_CTRL_IDE 0x20
244#define CANFD2_SWK_DLC_CTRL_DATA_BYTES_0 0x00
245#define CANFD2_SWK_DLC_CTRL_DATA_BYTES_1 0x01
246#define CANFD2_SWK_DLC_CTRL_DATA_BYTES_2 0x02
247#define CANFD2_SWK_DLC_CTRL_DATA_BYTES_3 0x03
248#define CANFD2_SWK_DLC_CTRL_DATA_BYTES_4 0x04
249#define CANFD2_SWK_DLC_CTRL_DATA_BYTES_5 0x05
250#define CANFD2_SWK_DLC_CTRL_DATA_BYTES_6 0x06
251#define CANFD2_SWK_DLC_CTRL_DATA_BYTES_7 0x07
252#define CANFD2_SWK_DLC_CTRL_DATA_BYTES_8 0x08
259#define CANFD2_TRANS_STAT_TSD 0x02
260#define CANFD2_TRANS_STAT_TXD_TO 0x04
261#define CANFD2_TRANS_STAT_POR 0x80
268#define CANFD2_TRANS_UV_STAT_VIO_STUV 0x01
269#define CANFD2_TRANS_UV_STAT_VIO_LTUV 0x02
270#define CANFD2_TRANS_UV_STAT_VCC_STUV 0x10
271#define CANFD2_TRANS_UV_STAT_VCC_LTUV 0x20
272#define CANFD2_TRANS_UV_STAT_VBAT_UV 0x80
279#define CANFD2_ERR_STAT_CMD_ERR 0x01
280#define CANFD2_ERR_STAT_COM_ERR 0x02
287#define CANFD2_WAKE_STAT_WUF 0x01
288#define CANFD2_WAKE_STAT_WUP 0x02
289#define CANFD2_WAKE_STAT_LWU 0x04
290#define CANFD2_WAKE_STAT_LWU_DIR 0x08
297#define CANFD2_SWK_STAT_SWK_ACT 0x01
298#define CANFD2_SWK_STAT_CANSIL 0x02
299#define CANFD2_SWK_STAT_CANTO 0x04
300#define CANFD2_SWK_STAT_SYNC 0x08
301#define CANFD2_SWK_STAT_SYSERR 0x10
308#define CANFD2_OP_MODE_SLEEP 0x01
309#define CANFD2_OP_MODE_STANDBY 0x02
310#define CANFD2_OP_MODE_RECEIVE_ONLY 0x03
311#define CANFD2_OP_MODE_NORMAL 0x04
312#define CANFD2_OP_MODE_UNKNOWN 0x05
315#define CANFD2_READ_CMD_MASK 0x7F
316#define CANFD2_WRITE_CMD 0x80
327#define CANFD2_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
328#define CANFD2_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
#define CANFD2_DRV_RX_BUFFER_SIZE
Definition canfd2.h:89
#define CANFD2_DRV_TX_BUFFER_SIZE
Definition canfd2.h:88
void canfd2_write_data(canfd2_t *ctx, uint8_t reg_addr, uint8_t write_data)
Generic write the byte of data function.
void canfd2_cfg_setup(canfd2_cfg_t *cfg)
Config Object Initialization function.
uint8_t canfd2_get_mode(canfd2_t *ctx)
Get operating mode function.
uint8_t canfd2_read_data(canfd2_t *ctx, uint8_t reg_addr)
Generic read the byte of data function.
void canfd2_generic_write(canfd2_t *ctx, uint8_t *data_buf, uint16_t len)
Generic write function.
err_t canfd2_init(canfd2_t *ctx, canfd2_cfg_t *cfg)
Initialization function.
void canfd2_set_mode(canfd2_t *ctx, uint8_t op_mode)
Set operating mode function.
int32_t canfd2_generic_read(canfd2_t *ctx, uint8_t *data_buf, uint16_t max_len)
Generic read function.
void canfd2_generic_transfer(canfd2_t *ctx, uint8_t *wr_buf, uint16_t wr_len, uint8_t *rd_buf, uint16_t rd_len)
Generic transfer function.
uint8_t canfd2_error_t
Error type.
Definition canfd2.h:387
This file contains SPI specific macros, functions, etc.
Click configuration structure definition.
Definition canfd2.h:360
uint32_t baud_rate
Definition canfd2.h:372
spi_master_chip_select_polarity_t cs_polarity
Definition canfd2.h:380
bool uart_blocking
Definition canfd2.h:373
pin_name_t sck
Definition canfd2.h:367
uart_data_bits_t data_bit
Definition canfd2.h:374
spi_master_mode_t spi_mode
Definition canfd2.h:379
pin_name_t tx_pin
Definition canfd2.h:364
pin_name_t mosi
Definition canfd2.h:366
uint32_t spi_speed
Definition canfd2.h:378
pin_name_t rx_pin
Definition canfd2.h:363
uart_stop_bits_t stop_bit
Definition canfd2.h:376
pin_name_t miso
Definition canfd2.h:365
uart_parity_t parity_bit
Definition canfd2.h:375
pin_name_t cs
Definition canfd2.h:368
Click ctx object definition.
Definition canfd2.h:340
digital_out_t cs
Definition canfd2.h:343
spi_master_t spi
Definition canfd2.h:348
uart_t uart
Definition canfd2.h:347
pin_name_t chip_select
Definition canfd2.h:349