2018-05-03 16:59:12 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018 Alexander Wachter
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2018-09-15 01:43:44 +08:00
|
|
|
#ifndef ZEPHYR_DRIVERS_CAN_STM32_CAN_H_
|
|
|
|
#define ZEPHYR_DRIVERS_CAN_STM32_CAN_H_
|
2018-05-03 16:59:12 +08:00
|
|
|
|
2019-06-26 03:53:46 +08:00
|
|
|
#include <drivers/can.h>
|
2018-05-03 16:59:12 +08:00
|
|
|
|
|
|
|
#define DEV_DATA(dev) ((struct can_stm32_data *const)(dev)->driver_data)
|
|
|
|
#define DEV_CFG(dev) \
|
|
|
|
((const struct can_stm32_config *const)(dev)->config->config_info)
|
|
|
|
|
2019-07-01 22:44:33 +08:00
|
|
|
#define BIT_SEG_LENGTH(cfg) ((cfg)->prop_ts1 + (cfg)->ts2 + 1)
|
2018-05-03 16:59:12 +08:00
|
|
|
|
|
|
|
#define CAN_NUMBER_OF_FILTER_BANKS (14)
|
2019-01-19 21:30:54 +08:00
|
|
|
#define CAN_MAX_NUMBER_OF_FILTERS (CAN_NUMBER_OF_FILTER_BANKS * 4)
|
2018-05-03 16:59:12 +08:00
|
|
|
|
|
|
|
#define CAN_FIRX_STD_IDE_POS (3U)
|
|
|
|
#define CAN_FIRX_STD_RTR_POS (4U)
|
|
|
|
#define CAN_FIRX_STD_ID_POS (5U)
|
|
|
|
|
|
|
|
#define CAN_FIRX_EXT_IDE_POS (2U)
|
|
|
|
#define CAN_FIRX_EXT_RTR_POS (1U)
|
|
|
|
#define CAN_FIRX_EXT_STD_ID_POS (21U)
|
|
|
|
#define CAN_FIRX_EXT_EXT_ID_POS (3U)
|
|
|
|
|
|
|
|
#define CAN_BANK_IS_EMPTY(usage, bank_nr) (((usage >> ((bank_nr) * 4)) & 0x0F) == 0x0F)
|
|
|
|
#define CAN_BANK_IN_LIST_MODE(can, bank) ((can)->FM1R & (1U << (bank)))
|
|
|
|
#define CAN_BANK_IN_32BIT_MODE(can, bank) ((can)->FS1R & (1U << (bank)))
|
|
|
|
#define CAN_IN_16BIT_LIST_MODE(can, bank) (CAN_BANK_IN_LIST_MODE(can, bank) && \
|
|
|
|
!CAN_BANK_IN_32BIT_MODE(can, bank))
|
|
|
|
#define CAN_IN_16BIT_MASK_MODE(can, bank) (!CAN_BANK_IN_LIST_MODE(can, bank) && \
|
|
|
|
!CAN_BANK_IN_32BIT_MODE(can, bank))
|
|
|
|
#define CAN_IN_32BIT_LIST_MODE(can, bank) (CAN_BANK_IN_LIST_MODE(can, bank) && \
|
|
|
|
CAN_BANK_IN_32BIT_MODE(can, bank))
|
|
|
|
#define CAN_IN_32BIT_MASK_MODE(can, bank) (!CAN_BANK_IN_LIST_MODE(can, bank) && \
|
|
|
|
CAN_BANK_IN_32BIT_MODE(can, bank))
|
|
|
|
struct can_mailbox {
|
|
|
|
can_tx_callback_t tx_callback;
|
2019-02-13 17:26:17 +08:00
|
|
|
void *callback_arg;
|
2018-05-03 16:59:12 +08:00
|
|
|
struct k_sem tx_int_sem;
|
|
|
|
u32_t error_flags;
|
|
|
|
};
|
|
|
|
|
2019-02-07 05:34:59 +08:00
|
|
|
|
|
|
|
/* number = FSCx | FMBx */
|
2018-05-03 16:59:12 +08:00
|
|
|
enum can_filter_type {
|
2019-02-07 05:34:59 +08:00
|
|
|
CAN_FILTER_STANDARD_MASKED = 0,
|
|
|
|
CAN_FILTER_STANDARD = 1,
|
|
|
|
CAN_FILTER_EXTENDED_MASKED = 2,
|
|
|
|
CAN_FILTER_EXTENDED = 3
|
2018-05-03 16:59:12 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct can_stm32_data {
|
2018-06-20 00:26:31 +08:00
|
|
|
struct k_mutex inst_mutex;
|
2018-05-03 16:59:12 +08:00
|
|
|
struct k_sem tx_int_sem;
|
|
|
|
struct can_mailbox mb0;
|
|
|
|
struct can_mailbox mb1;
|
|
|
|
struct can_mailbox mb2;
|
|
|
|
u64_t filter_usage;
|
2019-03-18 05:51:13 +08:00
|
|
|
can_rx_callback_t rx_cb[CONFIG_CAN_MAX_FILTER];
|
2019-02-11 21:40:28 +08:00
|
|
|
void *cb_arg[CONFIG_CAN_MAX_FILTER];
|
2018-06-20 00:26:31 +08:00
|
|
|
can_state_change_isr_t state_change_isr;
|
2018-05-03 16:59:12 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct can_stm32_config {
|
|
|
|
CAN_TypeDef *can; /*!< CAN Registers*/
|
|
|
|
u32_t bus_speed;
|
2019-02-04 23:39:46 +08:00
|
|
|
u8_t sjw;
|
2019-07-01 22:44:33 +08:00
|
|
|
u8_t prop_ts1;
|
|
|
|
u8_t ts2;
|
2018-05-03 16:59:12 +08:00
|
|
|
struct stm32_pclken pclken;
|
|
|
|
void (*config_irq)(CAN_TypeDef *can);
|
|
|
|
};
|
|
|
|
|
2018-09-15 01:43:44 +08:00
|
|
|
#endif /*ZEPHYR_DRIVERS_CAN_STM32_CAN_H_*/
|