|
SemiDrive SSDK Appication Program Interface PTG3.0
|
#include <stdbool.h>#include <types.h>#include "../source/flexcan/sdrv_flexcan_priv.h"#include <sdrv_common.h>Go to the source code of this file.
Data Structures | |
| struct | flexcan_fd_config_t |
| struct | flexcan_pn_id_filter_t |
| struct | flexcan_pn_payload_filter_t |
| struct | flexcan_pn_config_t |
| struct | flexcan_timing_config_t |
| struct | flexcan_config_t |
| struct | flexcan_rx_fifo_filter_table |
| struct | flexcan_rx_fifo_config_t |
| struct | _flexcan_rx_mb_config |
| struct | _flexcan_frame |
| struct | _flexcan_mb_transfer |
| struct | _flexcan_fifo_transfer |
| struct | _flexcan_handle |
Typedefs | |
| typedef struct _flexcan_rx_mb_config | flexcan_rx_mb_config_t |
| typedef void(* | flexcan_transfer_callback_t) (flexcan_handle_t *handle, flexcan_status_e status, uint32_t result, void *userData) |
| #define CORE_LITTLE_ENDIAN 1 |
| #define EXTENDED_DATA_ID 1U |
| #define EXTENDED_REMOTE_ID 3U |
| #define FLEXCAN_COPY_USE_BURST 1 |
| #define FLEXCAN_HAS_DOZE_MODE_SUPPORT 1 |
| #define FlexCanRxFifoAcceptExtFrame 1UL |
| #define FlexCanRxFifoAcceptRemoteFrame 1UL |
| #define IDX_CONVERT | ( | x | ) | (((x) & 0xFCU) + 3U - ((x) & 3U)) |
| #define MAKE_TYPE_A_FILTER | ( | id, | |
| type | |||
| ) | (((type) << 30) | ((id) << (((type)&1U) ? 1 : 19))) |
| #define MAKE_TYPE_B_FILTER | ( | id1, | |
| id2, | |||
| type1, | |||
| type2 | |||
| ) |
| #define MAKE_TYPE_C_FILTER | ( | id1, | |
| id2, | |||
| id3, | |||
| id4 | |||
| ) | (((id1)&0xFFU) | ((id2)&0xFFU) | ((id3)&0xFFU) | ((id4)&0xFFU)) |
| #define STANDARD_DATA_ID 0U |
| #define STANDARD_REMOTE_ID 2U |
| typedef enum flexcan_clock_source flexcan_clock_source_e |
FlexCAN clock source.
| typedef struct flexcan_config_t flexcan_config_t |
| typedef enum flexcan_controller_id flexcan_controller_id_e |
| typedef struct flexcan_fd_config_t flexcan_fd_config_t |
| typedef enum flexcan_fd_data_size flexcan_fd_data_size_e |
| typedef struct _flexcan_fifo_transfer flexcan_fifo_transfer_t |
FlexCAN Rx FIFO transfer.
| typedef enum flexcan_frame_format flexcan_frame_format_e |
FlexCAN frame format.
| typedef struct _flexcan_frame flexcan_frame_t |
| typedef enum flexcan_frame_type flexcan_frame_type_e |
FlexCAN frame type.
| typedef struct _flexcan_handle flexcan_handle_t |
FlexCAN handle structure definition.
| typedef struct _flexcan_mb_transfer flexcan_mb_transfer_t |
FlexCAN Message Buffer transfer.
| typedef struct flexcan_pn_config_t flexcan_pn_config_t |
| typedef struct flexcan_rx_fifo_config_t flexcan_rx_fifo_config_t |
| typedef struct flexcan_rx_fifo_filter_table flexcan_rx_fifo_filter_table_t |
| typedef enum flexcan_rx_fifo_filter_type flexcan_rx_fifo_filter_type_e |
| typedef enum flexcan_rx_fifo_priority flexcan_rx_fifo_priority_e |
| typedef struct _flexcan_rx_mb_config flexcan_rx_mb_config_t |
FlexCAN Receive Message Buffer configuration structure.
This structure is used as the parameter of FLEXCAN_SetRxMbConfig() function. The FLEXCAN_SetRxMbConfig() function is used to configure FlexCAN Receive Message Buffer. The function abort previous receiving process, clean the Message Buffer and activate the Rx Message Buffer using given Message Buffer setting.
| typedef enum _flexcan_status flexcan_status_e |
FlexCAN transfer status.
| typedef struct flexcan_timing_config_t flexcan_timing_config_t |
| typedef void(* flexcan_transfer_callback_t) (flexcan_handle_t *handle, flexcan_status_e status, uint32_t result, void *userData) |
FlexCAN transfer callback function.
The FlexCAN transfer callback will return value from the underlying layer. If the status equals to FLEXCAN_ERROR_STATUS, the result parameter will be the Content of FlexCAN status register which can be used to get the working status(or error status) of FlexCAN module. If the status equals to other FlexCAN Message Buffer transfer status, the result will be the index of Message Buffer that generate transfer event. If the status equals to other FlexCAN Message Buffer transfer status, the result is meaningless and should be Ignored.
FlexCAN interrupt configuration structure, default settings all disabled.
This structure contains the settings for all of the FlexCAN Module interrupt configurations. Note: FlexCAN Message Buffers and Rx FIFO have their own interrupts.
| enum _flexcan_status |
FlexCAN transfer status.
| enum flexcan_clock_source |
| enum flexcan_fd_data_size |
| enum flexcan_frame_format |
| enum flexcan_frame_type |
Pretended Networking filtering combinations.
Pretended Networking matching schemes.
| void flexcan_abort_mb_receive | ( | flexcan_handle_t * | handle, |
| uint8_t | mbIdx | ||
| ) |
Abort interrupt driven message receive process.
This function abort interrupt driven message receive process.
| [in] | handle | FlexCAN handle. |
| [in] | mbIdx | The FlexCAN Message Buffer index. |
| void flexcan_abort_mb_send | ( | flexcan_handle_t * | handle, |
| uint8_t | mbIdx | ||
| ) |
Abort interrupt driven message send process.
This function aborts interrupt driven message send process.
| [in] | handle | FlexCAN handle. |
| [in] | mbIdx | The FlexCAN Message Buffer index. |
| void flexcan_abort_receive_fifo | ( | flexcan_handle_t * | handle | ) |
Abort interrupt driven message receive from Rx FIFO process.
This function abort interrupt driven message receive from Rx FIFO process.
| [in] | handle | FlexCAN handle. |
| void flexcan_classic_set_timing_config | ( | flexcan_handle_t * | handle, |
| const flexcan_timing_config_t * | config | ||
| ) |
Setting FlexCAN classic protocol timing characteristic.
This function give user fine settings to CAN bus timing characteristic. The function is for user who is really versed in CAN protocol, for these users who just what to establish CAN communication among MCUs, just call flexcan_init() and fill the baud rate field with desired one. Doing this, default timing characteristic will provide to the module.
Note: Calling flexcan_classic_set_timing_config() will override the baud rate setted in flexcan_init().
| [in] | handle | FlexCAN handle. |
| [in] | config | Pointer to the timing configuration structure. |
| void flexcan_clear_err_status_flag | ( | flexcan_handle_t * | handle, |
| uint32_t | mask | ||
| ) |
Clear all error interrupt status.
| [in] | handle | FlexCAN handle. |
| [in] | mask | FlexCAN status flags. |
| void flexcan_create_handle | ( | flexcan_handle_t * | handle, |
| uint8_t | controller_id, | ||
| void * | reg_base, | ||
| uint8_t | irq_num, | ||
| flexcan_transfer_callback_t | callback, | ||
| void * | userData | ||
| ) |
Initialize the FlexCAN handle.
This function initializes the FlexCAN handle which can be used for other FlexCAN APIs. Usually, for a specified FlexCAN instance, user only need to call this API once to get the initialized handle. NOTE: This function should be called before all the other FlexCAN APIs.
| [in] | handle | FlexCAN handle pointer. |
| [in] | controller_id | FlexCAN controller_id. |
| [in] | reg_base | FlexCAN peripheral base address. |
| [in] | irq_num | irq number. |
| [in] | callback | The callback function. |
| [in] | userData | The parameter of the callback function. |
| void flexcan_deinit | ( | flexcan_handle_t * | handle | ) |
De-initializes a FlexCAN instance.
This function disable the FlexCAN module clock and set all register value to reset value.
| [in] | handle | FlexCAN handle. |
| void flexcan_disable_interrupts | ( | flexcan_handle_t * | handle, |
| uint32_t | mask | ||
| ) |
Disable FlexCAN interrupts according to provided mask.
This function disables the FlexCAN interrupts according to provided mask. The mask is a logical OR of enumeration members, see _flexcan_interrupt_enable.
| [in] | handle | FlexCAN handle. |
| [in] | mask | The interrupts to disable. Logical OR of _flexcan_interrupt_enable. |
| flexcan_status_e flexcan_enable | ( | flexcan_handle_t * | handle, |
| bool | enable | ||
| ) |
Enables or disable the FlexCAN module operation.
This function enables or disables the FlexCAN module.
| [in] | handle | FlexCAN handle. |
| [in] | enable | true to enable, false to disable. |
| FLEXCAN_SUCCESS | operate successfully |
| FLEXCAN_FAIL | operate timeout |
| void flexcan_enable_interrupts | ( | flexcan_handle_t * | handle, |
| uint32_t | mask | ||
| ) |
Enable FlexCAN interrupts according to provided mask.
This function enables the FlexCAN interrupts according to provided mask. The mask is a logical OR of enumeration members, see _flexcan_interrupt_enable.
| [in] | handle | FlexCAN handle. |
| [in] | mask | The interrupts to enable. Logical OR of _flexcan_interrupt_enable. |
| void flexcan_fd_set_timing_config | ( | flexcan_handle_t * | handle, |
| const flexcan_timing_config_t * | arbitrPhaseConfig, | ||
| const flexcan_timing_config_t * | dataPhaseConfig | ||
| ) |
Setting FlexCAN FD protocol timing characteristic.
This function give user fine settings to CAN bus timing characteristic. The function is for user who is really versed in CAN protocol, for these users who just what to establish CAN communication among MCUs, just call flexcan_init() and fill the baud rate field with desired one. Doing this, default timing characteristic will provide to the module.
Note: Calling flexcan_fd_set_timing_config() will override the baud rate setted in flexcan_init().
| [in] | handle | FlexCAN handle. |
| [in] | arbitrPhaseConfig | Pointer to the arbitration phase timing configuration structure. |
| [in] | dataPhaseConfig | Pointer to the data phase timing configuration structure. |
| flexcan_status_e flexcan_freeze | ( | flexcan_handle_t * | handle, |
| bool | freeze | ||
| ) |
Enter or exit freeze mode.
This function makes the FlexCAN work under Freeze Mode if param freeze is true, or work under Normal Mode if param freeze is false.
| [in] | handle | FlexCAN handle. |
| [in] | freeze | true to enter freeze mode, false to exit freeze mode |
| FLEXCAN_SUCCESS | operate successfully |
| FLEXCAN_FAIL | operate timeout |
| uint32_t flexcan_get_error_status | ( | flexcan_handle_t * | handle | ) |
Get reported error conditons detected in the reception and transmission.
| [in] | handle | FlexCAN handle. |
| value | of register ESR1. |
| uint32_t flexcan_get_mb_iflag | ( | flexcan_handle_t * | handle, |
| uint8_t | msgBufId | ||
| ) |
Get mailbox interrupt flag.
| [in] | handle | FlexCAN handle. |
| [in] | msgBufId | The FlexCAN Message Buffer index. |
| flag | value of MB. |
| uint8_t flexcan_get_mb_state | ( | flexcan_handle_t * | handle, |
| uint8_t | mbIdx | ||
| ) |
Get MB state.
| [in] | handle | FlexCAN handle. |
| [in] | mbIdx | The FlexCAN Message Buffer index. |
| flexcan_status_e flexcan_init | ( | flexcan_handle_t * | handle, |
| const flexcan_config_t * | config | ||
| ) |
Initializes a FlexCAN instance.
This function initializes the FlexCAN module with user-defined settings. This example shows how to set up the flexcan_config_t parameters and how to call the flexcan_init function by passing in these parameters:
NOTE: The FlexCAN handle must be created before initializing self.
| [in] | handle | FlexCAN handle. |
| [in] | config | Pointer to user-defined configuration structure. |
| FLEXCAN_SUCCESS | operate successfully |
| FLEXCAN_FAIL | operate timeout |
| int flexcan_irq_handler | ( | uint32_t | irq, |
| void * | arg | ||
| ) |
FlexCAN IRQ handle function.
This function handles the FlexCAN Error, Message Buffer and Rx FIFO IRQ request.
| [in] | irq | irq number. |
| [in] | arg | FlexCAN handle. |
| bool flexcan_is_mb_occupied | ( | flexcan_handle_t * | handle, |
| uint8_t | mbIdx | ||
| ) |
check whether mb is occupied by fifo along with filter table.
| [in] | handle | FlexCAN handle. |
| [in] | mbIdx | The FlexCAN Message Buffer index. |
| TRUE | - MB is occupied. |
| FALSE | - MB isn't occupied. |
| uint32_t flexcan_read_mb_int_status | ( | flexcan_handle_t * | handle, |
| uint8_t | mbIdx | ||
| ) |
Read MB interrupt status.
| [in] | handle | FlexCAN handle. |
| [in] | mbIdx | The FlexCAN Message Buffer index. |
| flexcan_status_e flexcan_read_rx_fifo | ( | flexcan_handle_t * | handle, |
| flexcan_frame_t * | rxFrame | ||
| ) |
Read a FlexCAN Message from Rx FIFO.
This function Read a CAN message from the FlexCAN build-in Rx FIFO.
| [in] | handle | FlexCAN handle. |
| [out] | rxFrame | Pointer to CAN message frame structure. |
| FLEXCAN_SUCCESS | - Read Message from Rx FIFO successfully. |
| FLEXCAN_FAIL | - Rx FIFO is not enabled. |
| flexcan_status_e flexcan_read_rx_mb | ( | flexcan_handle_t * | handle, |
| uint8_t | mbIdx, | ||
| flexcan_frame_t * | rxFrame | ||
| ) |
Read a FlexCAN Message from Receive Message Buffer.
This function read a CAN message from a specified Receive Message Buffer. The function will fill receive CAN message frame structure with just received data and activate the Message Buffer again. The function will return immediately.
| [in] | handle | FlexCAN handle. |
| [in] | mbIdx | The FlexCAN Message Buffer index. |
| [out] | rxFrame | Pointer to CAN message frame structure. |
| FLEXCAN_SUCCESS | - Rx Message Buffer is full and has been read successfully. |
| FLEXCAN_RX_OVERFLOW | - Rx Message Buffer is already overflowed and has been read successfully. |
| FLEXCAN_FAIL | - Rx Message Buffer is empty. |
| void flexcan_read_wmb | ( | flexcan_handle_t * | handle, |
| uint8_t | wmbIndex, | ||
| flexcan_frame_t * | wmb | ||
| ) |
read a can message from wakeup message buffer.
| [in] | handle | FlexCAN handle. |
| [in] | wmbIndex | The FlexCAN wakeup message Buffer Index. |
| [out] | wmb | Pointer to frame buffer to store information of incoming rx message. |
| flexcan_status_e flexcan_receive_fifo_nonblocking | ( | flexcan_handle_t * | handle, |
| flexcan_fifo_transfer_t * | xfer | ||
| ) |
Receive message from Rx FIFO using IRQ.
This function receive message using IRQ, this is non-blocking function, will return right away, when all messages have been received, the receive callback function will be called.
| [in] | handle | FlexCAN handle. |
| [in] | xfer | FlexCAN Rx FIFO transfer structure, refer to flexcan_fifo_transfer_t. |
| FLEXCAN_SUCCESS | - Start Rx FIFO receiving process successfully. |
| FLEXCAN_RX_FIFO_BUSY | - Rx FIFO is currently in use. |
| flexcan_status_e flexcan_receive_nonblocking | ( | flexcan_handle_t * | handle, |
| flexcan_mb_transfer_t * | xfer | ||
| ) |
Receive message using IRQ.
This function receive message using IRQ, this is non-blocking function, will return right away, when message have been received, the receive callback function will be called.
| [in] | handle | FlexCAN handle. |
| [in] | xfer | FlexCAN Message Buffer transfer structure, refer to flexcan_mb_transfer_t. |
| FLEXCAN_SUCCESS | Start Rx Message Buffer receiving process successfully. |
| FLEXCAN_RX_BUSY | Rx Message Buffer is in use. |
| flexcan_status_e flexcan_request_sleep | ( | flexcan_handle_t * | handle, |
| bool | request | ||
| ) |
Enter or exit lowpower mode.
This function makes the FlexCAN work under lowpower Mode if param request is true, or exit sleep Mode if param request is false.
| [in] | handle | FlexCAN handle. |
| [in] | request | true to enter lowpower mode, false to exit lowpower mode. |
| FLEXCAN_SUCCESS | operate successfully |
| FLEXCAN_FAIL | operate timeout |
| flexcan_status_e flexcan_reset | ( | flexcan_handle_t * | handle | ) |
Reset the FlexCAN Instance.
Restores the FlexCAN module to reset state, notice that this function will set all the registers to reset state so the FlexCAN module can not work after calling this API.
| [in] | handle | FlexCAN handle. |
| FLEXCAN_SUCCESS | operate successfully |
| FLEXCAN_FAIL | operate timeout |
| flexcan_status_e flexcan_send_nonblocking | ( | flexcan_handle_t * | handle, |
| flexcan_mb_transfer_t * | xfer, | ||
| uint8_t | padding_val | ||
| ) |
send message using IRQ
This function send message using IRQ, this is non-blocking function, will return right away, when message have been sent out, the send callback function will be called.
| [in] | handle | FlexCAN handle. |
| [in] | xfer | FlexCAN Message Buffer transfer structure, refer to flexcan_mb_transfer_t. |
| [in] | padding_val | value used to pad unspecified data in CAN FD frames > 8bytes. |
| FLEXCAN_SUCCESS | Start Tx Message Buffer sending process successfully. |
| FLEXCAN_FAIL | Write Tx Message Buffer failed. |
| FLEXCAN_TX_BUSY | Tx Message Buffer is in use. |
| void flexcan_set_rx_fifo_config | ( | flexcan_handle_t * | handle, |
| const flexcan_rx_fifo_config_t * | config | ||
| ) |
Configure the FlexCAN Rx FIFO.
This function Configure the Rx FIFO with given Rx FIFO configuration.
| [in] | handle | FlexCAN handle. |
| [in] | config | Pointer to FlexCAN Rx FIFO configuration structure. |
| void flexcan_set_rx_fifo_global_mask | ( | flexcan_handle_t * | handle, |
| uint32_t | mask | ||
| ) |
Set the FlexCAN Receive FIFO Global Mask.
This function Set the global mask for FlexCAN FIFO in matching process.
| [in] | handle | FlexCAN handle. |
| [in] | mask | Rx Fifo Global Mask value. |
| void flexcan_set_rx_individual_mask | ( | flexcan_handle_t * | handle, |
| uint8_t | maskIdx, | ||
| uint32_t | mask | ||
| ) |
Set the FlexCAN Receive Individual Mask.
This function Set the Individual mask for FlexCAN matching process. The configuration is only effective when Rx Individual Mask is enabled in FLEXCAN_Init(). If Rx FIFO is disabled, the Individual Mask is applied to corresponding Message Buffer. If Rx FIFO is enabled, the Individual Mask for Rx FIFO occupied Message Buffer will be applied to Rx Filter with same index. What calls for special attention is that only the first 32 Individual Mask can be used as Rx FIFO Filter Mask.
| [in] | handle | FlexCAN handle. |
| [in] | maskIdx | The Index of individual Mask. |
| [in] | mask | Rx Individual Mask value. |
| void flexcan_set_rx_mb_config | ( | flexcan_handle_t * | handle, |
| uint8_t | mbIdx, | ||
| const flexcan_rx_mb_config_t * | config | ||
| ) |
Configure a FlexCAN Receive Message Buffer.
This function clean a FlexCAN build-in Message Buffer and configure it as a Receive Message Buffer.
| [in] | handle | FlexCAN handle. |
| [in] | mbIdx | The Message Buffer index. |
| [in] | config | Pointer to FlexCAN Message Buffer configuration structure. |
| void flexcan_set_rx_mb_global_mask | ( | flexcan_handle_t * | handle, |
| uint32_t | mask | ||
| ) |
Set the FlexCAN Receive Message Buffer Global Mask.
This function Set the global mask for FlexCAN Message Buffer in matching process. The configuration is only effective when Rx Individual Mask is disabled in flexcan_init().
| [in] | handle | FlexCAN handle. |
| [in] | mask | Rx Message Buffer Global Mask value. |
| void flexcan_set_tx_mb_config | ( | flexcan_handle_t * | handle, |
| uint8_t | mbIdx, | ||
| bool | tx_by_interrupt | ||
| ) |
Configure a FlexCAN Transmit Message Buffer.
This function abort privious transmission, clean the Message Buffer and configure it as a Transmit Message Buffer.
| [in] | handle | FlexCAN handle. |
| [in] | mbIdx | The Message Buffer index. |
| [in] | tx_by_interrupt | Tx by interrupt (true) or polling (false). |
| flexcan_status_e flexcan_write_tx_mb | ( | flexcan_handle_t * | handle, |
| uint8_t | mbIdx, | ||
| const flexcan_frame_t * | txFrame, | ||
| uint8_t | padding_val | ||
| ) |
Write FlexCAN Message to Transmit Message Buffer.
This function write a CAN Message to the specified Transmit Message Buffer. and change the Message Buffer state to start CAN Message transmit, after that the function will return immediately.
| [in] | handle | FlexCAN handle. |
| [in] | mbIdx | The FlexCAN Message Buffer index. |
| [in] | txFrame | Pointer to CAN message frame to be sent. |
| [in] | padding_val | value used to pad unspecified data in CAN FD frames > 8bytes. |