STM32G0 MCAL 0.0.1
Tiny MCAL for educational purpose.
|
Can Specific Arquitecture Driver More...
#include "Can_Types.h"
Go to the source code of this file.
Can Specific Arquitecture Driver
Can driver implementation for the STM32G0xx family of microcontrollers. This file contains the hardware specific implementation of the Can driver. The file is implemented as a means of abstraction from the hardware, this way we can avoid to include Arch headers in the actual driver header, making the low level interfaces available only for the inmediate upper layer.
Std_ReturnType Can_Arch_CheckWakeup | ( | Can_HwUnit * | HwUnit, |
uint8 | Controller ) |
Can low level wakeup check
This function checks if a wakeup has occurred for the given controller.
HwUnit | Pointer to the hardware unit configuration |
Controller | CAN controller for which the wakeup shall be checked. |
E_OK | wakeup detected E_NOT_OK: no wakeup detected |
void Can_Arch_DeInit | ( | Can_HwUnit * | HwUnit, |
uint8 | Controller ) |
Can low level Deinitialization
This function deinitializes the CAN controller. It sets the complete CAN controller into a state comparable to power on reset. All CAN controller registers will be reset to their reset values.
HwUnit | Pointer to the hardware unit configuration |
Controller | CAN controller to be de-initialized |
< Initialization bit
< Initialization bit
< Clock stop request bit
< Clock stop acknowledge bit
< Configuration change enable bit
< Interrupt Line 0
< Interrupt Line 1
void Can_Arch_DisableControllerInterrupts | ( | Can_HwUnit * | HwUnit, |
uint8 | Controller ) |
Can low level Disable Controller Interrupts
This function disables all interrupts for this CAN controller. The function will only disable the internals interrupt lines zero and one, the external interrupt line must be disabled by the application using the Nvic Driver.
HwUnit | Pointer to the hardware unit configuration |
Controller | CAN controller for which interrupts shall be disabled. |
< Interrupt Line 0
< Interrupt Line 1
void Can_Arch_EnableControllerInterrupts | ( | Can_HwUnit * | HwUnit, |
uint8 | Controller ) |
Can low level Enable Controller Interrupts
This function enables all interrupts for this CAN controller. The function will only enable the internals interrupt lines zero and one, the external interrupt line must be enabled by the application using the Nvic Driver.
HwUnit | Pointer to the hardware unit configuration |
Controller | CAN controller for which interrupts shall be enabled. |
< Interrupt Line 0
< Interrupt Line 1
void Can_Arch_EnableEgressTimeStamp | ( | Can_HwUnit * | HwUnit, |
Can_HwHandleType | Hth ) |
Can low level Enable Egress TimeStamp
Activates egress time stamping on the messages to be transmitted.
HwUnit | Pointer to the hardware unit configuration |
Hth | information which HW-transmit handle shall be used for enabling the time stamp. |
Std_ReturnType Can_Arch_GetControllerErrorState | ( | Can_HwUnit * | HwUnit, |
uint8 | ControllerId, | ||
Can_ErrorStateType * | ErrorStatePtr ) |
Can low level Get Controller Error State
This function returns the error state of the CAN controller reading the internal registers.
HwUnit | Pointer to the hardware unit configuration |
ControllerId | CanIf ControllerId which is assigned to a CAN controller, which is requested for ErrorState. |
ErrorStatePtr | Pointer to a memory location, where the error state of the CAN controller will be stored. |
E_OK | request accepted E_NOT_OK: request not accepted |
< Bus_Off bit
< Protocol_Error bit
Std_ReturnType Can_Arch_GetControllerMode | ( | Can_HwUnit * | HwUnit, |
uint8 | Controller, | ||
Can_ControllerStateType * | ControllerModePtr ) |
Can low level Get Controller Mode
The fucntion only returns the current software flag which stores the mode of the CAN controller set by the Can_Arch_SetControllerMode() function. It does not read any hardware registers
HwUnit | Pointer to the hardware unit configuration |
Controller | CAN controller for which the status shall be read. |
ControllerModePtr | Pointer to a memory location, where the current mode of the CAN |
E_OK | request accepted E_NOT_OK: request not accepted |
Std_ReturnType Can_Arch_GetControllerRxErrorCounter | ( | Can_HwUnit * | HwUnit, |
uint8 | ControllerId, | ||
uint8 * | RxErrorCounterPtr ) |
Can low level Get Controller Rx Error Counter
Reads and return the Rx internal error counter of the can peripheral
HwUnit | Pointer to the hardware unit configuration |
ControllerId | CAN controller, whose current Rx error counter shall be acquired. |
RxErrorCounterPtr | Pointer to a memory location, where the current Rx error counter of the CAN controller will be stored. |
E_OK | Rx error counter available. E_NOT_OK: Wrong ControllerId, or Rx error counter not available. |
< Receive Error Counter
< Receive Error Counter bitfiled size
< Receive Error Passive
Std_ReturnType Can_Arch_GetControllerTxErrorCounter | ( | Can_HwUnit * | HwUnit, |
uint8 | ControllerId, | ||
uint8 * | TxErrorCounterPtr ) |
Can low level Get Controller Tx Error Counter
Reads and return the Tx internal error counter of the can peripheral
HwUnit | Pointer to the hardware unit configuration |
ControllerId | CAN controller, whose current Tx error counter shall be acquired. |
TxErrorCounterPtr | Pointer to a memory location, where the current Tx error counter |
E_OK | Tx error counter available. E_NOT_OK: Wrong ControllerId, or Tx error counter not |
< Transmit Error Counter
< Transmit Error Counter bitfiled size
Std_ReturnType Can_Arch_GetCurrentTime | ( | Can_HwUnit * | HwUnit, |
uint8 | ControllerId, | ||
Can_TimeStampType * | timeStampPtr ) |
Can low level Get Current Time
Returns a time value out of the HW registers.
HwUnit | Pointer to the hardware unit configuration |
ControllerId | CAN controller, whose current time shall be acquired. |
timeStampPtr | Pointer to a memory location, where the current time of the CAN |
E_OK | successful E_NOT_OK: failed |
Std_ReturnType Can_Arch_GetEgressTimeStamp | ( | Can_HwUnit * | HwUnit, |
PduIdType | TxPduId, | ||
Can_HwHandleType | Hth, | ||
Can_TimeStampType * | timeStampPtr ) |
Can low level Get Egress TimeStamp
Reads back the egress time stamp on a dedicated message object. It needs to be called within the TxConfirmation() function.
HwUnit | Pointer to the hardware unit configuration |
TxPduId | Tx-PDU handle of CAN L-PDU that has been transmitted. |
Hth | information which HW-transmit handle shall be used for reading the time stamp. |
timeStampPtr | Pointer to a memory location where the time stamp value shall be stored. |
E_OK | success E_NOT_OK: failed to read time stamp. |
Std_ReturnType Can_Arch_GetIngressTimeStamp | ( | Can_HwUnit * | HwUnit, |
Can_HwHandleType | Hrh, | ||
Can_TimeStampType * | timeStampPtr ) |
Can low level Get Ingress TimeStamp
Reads back the ingress time stamp on a dedicated message object. It needs to be called within the RxIndication() function.
HwUnit | Pointer to the hardware unit configuration |
Hrh | information which HW-receive handle shall be used for reading the time stamp. |
timeStampPtr | Pointer to a memory location where the time stamp value shall be stored. |
E_OK | success E_NOT_OK: failed to read time stamp. |
void Can_Arch_Init | ( | Can_HwUnit * | HwUnit, |
const Can_ConfigType * | Config, | ||
uint8 | Controller ) |
Can low level Initialization
Set up the internal register for the CAN controller inside the microcontroller. This function shall take out the controller from the reset mode, set operation mode and initialize the baudrate according to the parameters in config structure, enable the interrupts for the controller and initialize all message objects as free.
HwUnit | Pointer to the hardware unit configuration |
Config | Pointer to driver configuration |
Controller | Index of the controller to be initialized |
< Clock stop request bit
< Clock stop acknowledge bit
< Initialization bit
< Initialization bit
< Configuration change enable bit
< Disable automatic retransmission bit
< Transmit pause bit
< Protocol exception handling disable bit
< FD operation enable bit
< Test mode enable bit
< Bus monitoring mode bit
< Restricted operation mode bit
< Loop back mode bit
< Restricted Operation mode
< Restricted operation mode bit
< Normal mode
< Bus Monitoring mode
< Test mode enable bit
< Loop back mode bit
< Internal LoopBack mode
< Bus monitoring mode bit
< Bus monitoring mode bit
< Tx FIFO/Queue Mode bit
< Reject Remote Frames Standard
< Reject Remote Frames Extended
< Reject Remote Frames Standard
< Reject Remote Frames Extended
void Can_Arch_IsrMainHandler | ( | Can_HwUnit * | HwUnit, |
uint8 | Controller ) |
Can Interrupt Handler
This function is the interrupt handler for the Can controller, it will check the interrupt flags and call the corresponding callback functions.
HwUnit | Pointer to the hardware unit configuration |
Controller | CAN controller for which the status shall be changed. |
Std_ReturnType Can_Arch_SetBaudrate | ( | Can_HwUnit * | HwUnit, |
uint8 | Controller, | ||
uint16 | BaudRateConfigID ) |
Can low level Set Baudrate
This function sets the baudrate configuration of the CAN controller. The fucntion will determine if FD baud rate configuration is required and will set the baud rate accordingly. Function does not check if the baud rate configuration is valid.
HwUnit | Pointer to the hardware unit configuration |
Controller | CAN controller for which the baud rate shall be set. |
BaudRateConfigID | references a baud rate configuration by ID |
E_OK | Service request accepted, setting of (new) baud rate started E_NOT_OK: Service request not accepted |
Std_ReturnType Can_Arch_SetControllerMode | ( | Can_HwUnit * | HwUnit, |
uint8 | Controller, | ||
Can_ControllerStateType | Transition ) |
Can low level Set Controller Mode
This function performs software triggered state transitions of the CAN controller State machine. Trnasitions are: Start, Stop, Wakeup, Reset. It is required a previous state in order to proceed with the requested transition, otherwise the function will return E_NOT_OK.
HwUnit | Pointer to the hardware unit configuration |
Controller | CAN controller for which the status shall be changed. |
Transition | Transition value to request new state. |
E_OK | request accepted E_NOT_OK: request not accepted |
< Initialization bit
< Initialization bit
< Initialization bit
< Clock stop request bit
< Clock stop acknowledge bit
< Configuration change enable bit
< Clock stop request bit
< Clock stop acknowledge bit
Std_ReturnType Can_Arch_Write | ( | Can_HwUnit * | HwUnit, |
Can_HwHandleType | Hth, | ||
const Can_PduType * | PduInfo ) |
Can low level Write
The function stores the message pointed to by PduInfo into the internal Tx message buffer of the CAN Sram area and activates the corresponding hardware transmit bits. It reades the hardware fifo index to know which of the three buffers is available for transmission. The function will return CAN_BUSY if no buffer is available.
HwUnit | Pointer to the hardware unit configuration |
Hth | information which HW-transmit handle shall be used for transmit. Implicitly this is also the information about the controller to use because the Hth numbers are unique inside one hardware unit. |
PduInfo | Pointer to SDU user memory, Data Length and Identifier |
E_OK | Write command has been accepted E_NOT_OK: development error occurred CAN_BUSY: No TX hardware buffer available or pre-emptive call of Can_Write that can't be implemented re-entrant (see Can_ReturnType) |
< Tx FIFO/Queue Full
< Tx FIFO/Queue Put Index
< Tx FIFO/Queue Put Index bitfiled size
< ID bit
< Standard ID
< Tx standard ID bit
< Tx standard ID bitfield size
< Extended identifier bit
< Tx extended ID bit
< Tx extended ID bitfield size
< Extended identifier bit
< Message Marker bit
< Message Marker bitfield size
< Fromat ID bit
< Classic mode
< FD format bit
< FD format bit
< Bit rate switch enable bit
< Bit rate switch bit
< Event FIFO Control bit
< Data length code bit
< Data length code bitfield size