/** * @file fc4xxx_driver_sent.h * @author Flagchip073 * @brief FC7xxx SENT driver type definition and API * @version 0.1.0 * @date 2022-12-14 * * @copyright Copyright (c) 2022 Flagchip Semiconductors Co., Ltd. * */ /* ******************************************************************************** * Revision History: * * Version Date Initials CR# Descriptions * --------- ---------- ------------ ---------- --------------- * 0.1.0 2022-12-14 Flagchip073 N/A First version for FC7300 SENT module ******************************************************************************** */ #ifndef _DRIVER_FC4XXX_DRIVER_SENT_H_ #define _DRIVER_FC4XXX_DRIVER_SENT_H_ #include "device_header.h" #if defined(__cplusplus) extern "C" { #endif /** * @addtogroup fc7xxx_driver_sent * @{ */ /** * @brief SENT buffer address and size in DMA mode * */ #define SENT0_GET_FAST_MSG_DMA_ADDR(echannel) (&(SENT->SENT_CHN[echannel].CHN_DFD)) #define SENT_GET_FAST_MSG_DMA_BYTELENGTH (12U) #define SENT0_GET_SLOW_MSG_DMA_ADDR(echannel) (&(SENT->SENT_CHN[echannel].CHN_DSB3)) #define SENT_GET_SLOW_MSG_DMA_BYTELENGTH (12U) /** * @brief SENT operation return values * */ typedef enum { SENT_RETURN_OK = 0x00U, /*!< The SENT operation is succeeded */ SENT_RETURN_E_NOT_OK = 0x01U, /*!< The SENT operation is failed */ SENT_RETURN_E_ALREADY_INIT = 0x02U, /*!< The SENT has been initialized. */ SENT_RETURN_E_UNINIT = 0x03U, /*!< The SENT is not initialized */ SENT_RETURN_E_PARAM = 0x04U, /*!< The SENT parameter is incorrect or out of range. */ } Sent_ReturnType; /** * @brief SENT Channel index * */ typedef enum { SENT_CHANNEL_0 = 0x00U, /*!< The SENT channel 0 */ SENT_CHANNEL_1 = 0x01U, /*!< The SENT channel 1 */ SENT_CHANNEL_2 = 0x02U, /*!< The SENT channel 2 */ SENT_CHANNEL_3 = 0x03U, /*!< The SENT channel 3 */ SENT_CHANNEL_MAX = SENT_CHANNEL_COUNT } Sent_ChannelType; /** * @brief SENT instance index * */ typedef enum { SENT_INSTANCE_0 = 0x00U, /*!< The SENT channel 0 */ SENT_INSTANCE_1 = 0x01U, /*!< The SENT channel 1 */ SENT_INSTANCE_MAX = SENT_INSTANCE_COUNT } Sent_InstanceType; /** * @brief SENT nibble data mode control. Refer to SENT SAE J2716 2010 for detail protocol definition * */ typedef enum { SENT_DATA_NIBBLE_MODE_A = 0x0U, /*!< Frame format A */ SENT_DATA_NIBBLE_MODE_H1 = 0x1U, /*!< Frame format H1 */ SENT_DATA_NIBBLE_MODE_H2 = 0x2U, /*!< Frame format H2 */ SENT_DATA_NIBBLE_MODE_H3 = 0x3U, /*!< Frame format H3 */ SENT_DATA_NIBBLE_MODE_H4 = 0x4U, /*!< Frame format H4 */ SENT_DATA_NIBBLE_MODE_H5 = 0x5U, /*!< Frame format H5 */ SENT_DATA_NIBBLE_MODE_H6 = 0x6U, /*!< Frame format H6 */ SENT_DATA_NIBBLE_MODE_H7 = 0x7U /*!< Frame format H7 */ } Sent_DataNibbleModeType; /** * @brief SENT calibration valid type * */ typedef enum { SENT_CALIBRATION_VALID_DISABLE = 0x0U, /*!< The successive calibration pulses diagnostic will be disabled */ SENT_CALIBRATION_VALID_WITHIN_20 = 0x1U, /*!< The difference of received calibration pulse and receiver configuration is within 20%, the message is deemed to be valid */ SENT_CALIBRATION_VALID_FROM_20_TO_25 = 0x2U, /*!< The difference of received calibration pulse and receiver configuration is more than 20% but less than 25%, the message is deemed to be valid */ } Sent_CalibrationValidType; /** * @brief SENT Successive calibration pulses diagnostic option * */ typedef enum { SENT_CALIBRATION_PULSE_DIAG_OPTION2 = 0x0U, /*!< Option 2 i.e. Low Latency Option as per SAE Specification */ SENT_CALIBRATION_PULSE_DIAG_OPTION1 = 0x1U, /*!< Option 1 i.e. Preferred but High Latency Option as per SAE Specification */ } Sent_CalDiagOptionType; /** * @brief Determines how long the bus idle flag will assert when SENT bus is idle * */ typedef enum { SENT_IDLE_COUNT_FLAG_DISABLE = 0x0U, /*!< The bus idle flag will never assert */ SENT_IDLE_COUNT_FLAG_254_TICKS = 0x1U, /*!< The bus is idle for more than 127*2 ticks, then the bus idle flag will assert */ SENT_IDLE_COUNT_FLAG_508_TICKS = 0x2U, /*!< The bus is idle for more than 127*2 ticks, then the bus idle flag will assert */ SENT_IDLE_COUNT_FLAG_1016_TICKS = 0x4U, /*!< The bus is idle for more than 127*2 ticks, then the bus idle flag will assert */ SENT_IDLE_COUNT_FLAG_2032_TICKS = 0x8U, /*!< The bus is idle for more than 127*2 ticks, then the bus idle flag will assert */ } Sent_IdleCountType; /** * @brief SENT Slow message type. * */ typedef enum { SENT_SERIAL_MESSAGE_SHORT = 0x0U, /*!< short serial data message */ SENT_SERIAL_MESSAGE_ENHANCE_12DATA_8ID = 0x1U, /*!< enhanced serial data message with 12-bit data and 8-bit ID */ SENT_SERIAL_MESSAGE_ENHANCE_16DATA_4ID = 0x2U, /*!< enhanced serial data message with 16-bit data and 4-bit ID */ } Sent_SerialMessageType; /** * @brief SENT trigger type in SPC mode * */ typedef enum { SENT_SPC_SOFTWARE_TRIGGER = 0x0U, /*!< SPC pulse triggered by software method */ SENT_SPC_EXTERNAL_TRIGGER = 0x1U, /*!< SPC pulse triggered by external trigger */ } Sent_SpcTriggerType; /** * @brief Select the tick base in SPC mode * */ typedef enum { SENT_SPC_TICK_BASE_PRE_MSG = 0x0U, /*!< Previous received message tick base */ SENT_SPC_TICK_BASE_CONFIGURED = 0x1U, /*!< SENT configured tick base */ } Sent_SpcTickBaseType; /** * @brief Sent global interrupt type. * */ typedef enum { SENT_SLOW_MSG_DMA_UF_IT = 0U, /*!< Slow message dma read underflow interrupt enable. */ SENT_FAST_MSG_DMA_DF_IT = 1U, /*!< Fast message dma read underflow interrupt enable. */ SENT_FAST_MSG_READY_IT = 2U, /*!< Fast message ready interrupt enable. */ SENT_SLOW_MSG_READY_IT = 3U, /*!< Slow message ready interrupt enable. */ SENT_FAST_MSG_FIFO_OF_IT = 4U, /*!< Fast message FIFO overflow interrupt enable. */ } Sent_GlobalInterruptType; /** * @brief Structure to enable or disable the channel interrupts. * */ typedef struct { bool bBusIdleITEn; /*!< Bus idle interrupt enable. */ bool bSpcOverrunITEn; /*!< SPC overrun interrupt enable. */ bool bCalResyncErrITEn; /*!< Continuous 2 sync/calibration pulse difference exceed 1.5625% error interrupt enable. */ bool bCalFailITEn; /*!< Calibation 20% pass 25% fail interrupt enable. */ bool bSlowMsgOFITEn; /*!< Slow message overflow interrupt enable. */ bool bFastMsgOFITEn; /*!< Fast message overflow interrupt enable. */ bool bNibbleValueErrITEn; /*!< Nibble value more than 15 or less than 0 error interrupt enable. */ bool bPrePulseDiagErrITEn; /*!< Previous pulse diagnosis error interrupt enable. */ bool bCalDiagErrITEn; /*!< Calibration diagnosis over 25% error interrupt enable. */ bool bCalErrITEn; /*!< Sync/calibration pulse difference eceed 1.5625% error interrupt enable. */ bool bSlowMsgCrcErrITEn; /*!< Slow message CRC check error interrupt enable. */ bool bFastMsgCrcErrITEn; /*!< Fast message CRC check error interrupt enable. */ bool bFallingEdgeNumErrITEn; /*!< Falling edge number error interrupt enable. */ } Sent_ChannelInterruptType; /** * @brief Structure for fast message buffer. * */ typedef struct { uint8_t u8CRC; /*!< Receied fast message CRC data. */ uint8_t u8SC; /*!< Fast message status communication nibble value. */ uint32_t u32Timestamp; /*!< Fast message timestamp value. */ uint32_t u32Data; /*!< Received fast message data nibble. */ } Sent_FastMessageDataType; /** * @brief Structure for slow message buffer. * */ typedef struct { Sent_SerialMessageType eMsgType; /*!< Slow message type. */ uint8_t u8CRC; /*!< Slow message crc data. */ uint8_t u8ID; /*!< Slow message ID. */ uint16_t u16Data; /*!< Slow message data. */ uint32_t u32Timestamp; /*!< Slow message timestamp value. */ } Sent_SlowMessageDataType; /** * @brief SENT Global ISR callback function prototype * */ typedef void (*SENT_GBISRCallbackType)(Sent_ChannelType eChannel, const Sent_GlobalInterruptType eInterrupt); /** * @brief SENT Channel ISR callback function prototype * */ typedef void (*SENT_CHISRCallbackType)(Sent_ChannelType eChannel, const uint32_t u32ChannelStatus); /** * @brief structure to configure the SENT. * */ typedef struct { uint8_t u8PreScaler; /*