STM32G0 MCAL 0.0.1
Tiny MCAL for educational purpose.
Loading...
Searching...
No Matches
Can_Arch.h File Reference

Can Specific Arquitecture Driver More...

#include "Can_Types.h"

Go to the source code of this file.

Macros

#define CAN_FDCAN1   0u
 
#define CAN_FDCAN2   1u
 
#define CAN_SRAMCAN1   0u
 
#define CAN_SRAMCAN2   1u
 
#define CAN_CLOCK_DIV1   0x00u
 
#define CAN_CLOCK_DIV2   0x01u
 
#define CAN_CLOCK_DIV4   0x02u
 
#define CAN_CLOCK_DIV6   0x03u
 
#define CAN_CLOCK_DIV8   0x04u
 
#define CAN_CLOCK_DIV10   0x05u
 
#define CAN_CLOCK_DIV12   0x06u
 
#define CAN_CLOCK_DIV14   0x07u
 
#define CAN_CLOCK_DIV16   0x08u
 
#define CAN_CLOCK_DIV18   0x09u
 
#define CAN_CLOCK_DIV20   0x0Au
 
#define CAN_CLOCK_DIV22   0x0Bu
 
#define CAN_CLOCK_DIV24   0x0Cu
 
#define CAN_CLOCK_DIV26   0x0Du
 
#define CAN_CLOCK_DIV28   0x0Eu
 
#define CAN_CLOCK_DIV30   0x0Fu
 
#define CAN_FRAME_CLASSIC   0u
 
#define CAN_FRAME_FD   1u
 
#define CAN_TX_FIFO_OPERATION   0u
 
#define CAN_TX_QUEUE_OPERATION   1u
 
#define CAN_MODE_NORMAL   0u
 
#define CAN_MODE_RESTRICTED_OPERATION   1u
 
#define CAN_MODE_BUS_MONITORING   2u
 
#define CAN_MODE_INTERNAL_LOOPBACK   3u
 
#define CAN_MODE_EXTERNAL_LOOPBACK   4u
 
#define CAN_TX_BUFFER0   1u
 
#define CAN_TX_BUFFER1   2u
 
#define CAN_TX_BUFFER2   4u
 
#define CAN_INTERRUPT_LINE0   0u
 
#define CAN_INTERRUPT_LINE1   1u
 
#define CAN_IT_GROUP_RX_FIFO0   0u
 
#define CAN_IT_GROUP_RX_FIFO1   1u
 
#define CAN_IT_GROUP_SMSG   2u
 
#define CAN_IT_GROUP_TX_FIFO_ERROR   3u
 
#define CAN_IT_GROUP_MISC   4u
 
#define CAN_IT_GROUP_BIT_LINE_ERROR   5u
 
#define CAN_IT_GROUP_PROTOCOL_ERROR   6u
 
#define CAN_IT_LIST_RX_FIFO0   0x00000007
 
#define CAN_IT_LIST_RX_FIFO1   0x00000038
 
#define CAN_IT_LIST_SMSG   0x000001C0
 
#define CAN_IT_LIST_TX_FIFO_ERROR   0x00001E00
 
#define CAN_IT_LIST_MISC   0x0000E000
 
#define CAN_IT_LIST_BIT_LINE_ERROR   0x00030000
 
#define CAN_IT_LIST_PROTOCOL_ERROR   0x00FC0000
 
#define CAN_IT_RX_FIFO0_MESSAGE_LOST   ( (uint32)1u << 0u )
 
#define CAN_IT_RX_FIFO0_FULL   ( (uint32)1u << 1u )
 
#define CAN_IT_RX_FIFO0_NEW_MESSAGE   ( (uint32)1u << 2u )
 
#define CAN_IT_RX_FIFO1_MESSAGE_LOST   ( (uint32)1u << 3u )
 
#define CAN_IT_RX_FIFO1_FULL   ( (uint32)1u << 4u )
 
#define CAN_IT_RX_FIFO1_NEW_MESSAGE   ( (uint32)1u << 5u )
 
#define CAN_IT_RX_HIGH_PRIORITY_MSG   ( (uint32)1u << 6u )
 
#define CAN_IT_TX_COMPLETE   ( (uint32)1u << 7u )
 
#define CAN_IT_TX_ABORT_COMPLETE   ( (uint32)1u << 8u )
 
#define CAN_IT_TX_FIFO_EMPTY   ( (uint32)1u << 9u )
 
#define CAN_IT_TX_EVT_FIFO_NEW_DATA   ( (uint32)1u << 10 )
 
#define CAN_IT_TX_EVT_FIFO_FULL   ( (uint32)1u << 11 )
 
#define CAN_IT_TX_EVT_FIFO_ELT_LOST   ( (uint32)1u << 12 )
 
#define CAN_IT_TIMESTAMP_WRAPAROUND   ( (uint32)1u << 13u )
 
#define CAN_IT_TIMEOUT_OCCURRED   ( (uint32)1u << 15u )
 
#define CAN_IT_RAM_ACCESS_FAILURE   ( (uint32)1u << 14u )
 
#define CAN_IT_ERROR_LOGGING_OVERFLOW   ( (uint32)1u << 16u )
 
#define CAN_IT_RAM_WATCHDOG   ( (uint32)1u << 20u )
 
#define CAN_IT_ARB_PROTOCOL_ERROR   ( (uint32)1u << 21u )
 
#define CAN_IT_DATA_PROTOCOL_ERROR   ( (uint32)1u << 22u )
 
#define CAN_IT_RESERVED_ADDRESS_ACCESS   ( (uint32)1u << 23u )
 
#define CAN_IT_ERROR_PASSIVE   ( (uint32)1u << 17u )
 
#define CAN_IT_ERROR_WARNING   ( (uint32)1u << 18u )
 
#define CAN_IT_BUS_OFF   ( (uint32)1u << 19u )
 
#define CAN_FILTER_TYPE_RANGE   0x00u
 
#define CAN_FILTER_TYPE_DUAL   0x01u
 
#define CAN_FILTER_TYPE_CLASSIC   0x02u
 
#define CAN_HOH_TYPE_RECEIVE   0u
 
#define CAN_HOH_TYPE_TRANSMIT   1u
 
#define CAN_OBJECT_PL_8   0x08u
 
#define CAN_OBJECT_PL_12   0x09u
 
#define CAN_OBJECT_PL_16   0x0Au
 
#define CAN_OBJECT_PL_20   0x0Bu
 
#define CAN_OBJECT_PL_24   0x0Cu
 
#define CAN_OBJECT_PL_32   0x0Du
 
#define CAN_OBJECT_PL_48   0x0Eu
 
#define CAN_OBJECT_PL_64   0x0Fu
 
#define CAN_ID_STANDARD   0u
 
#define CAN_ID_EXTENDED   1u
 
#define CAN_ID_MIXED   2u
 
#define CAN_FULL   0x00u
 
#define CAN_BASIC   0x01u
 
#define CAN_RX_FIFO0   1u
 
#define CAN_RX_FIFO1   2u
 
#define CAN_OBJ_HTH_TX00   0u
 
#define CAN_OBJ_HRH_RX00   1u
 
#define CAN_OBJ_HRH_RX01   2u
 
#define CAN_OBJ_HTH_TX10   3u
 
#define CAN_OBJ_HRH_RX10   4u
 
#define CAN_OBJ_HRH_RX11   5u
 

Functions

void Can_Arch_Init (Can_HwUnit *HwUnit, const Can_ConfigType *Config, uint8 Controller)
 Can low level Initialization
 
void Can_Arch_DeInit (Can_HwUnit *HwUnit, uint8 Controller)
 Can low level Deinitialization
 
Std_ReturnType Can_Arch_SetBaudrate (Can_HwUnit *HwUnit, uint8 Controller, uint16 BaudRateConfigID)
 Can low level Set Baudrate
 
Std_ReturnType Can_Arch_SetControllerMode (Can_HwUnit *HwUnit, uint8 Controller, Can_ControllerStateType Transition)
 Can low level Set Controller Mode
 
void Can_Arch_DisableControllerInterrupts (Can_HwUnit *HwUnit, uint8 Controller)
 Can low level Disable Controller Interrupts
 
void Can_Arch_EnableControllerInterrupts (Can_HwUnit *HwUnit, uint8 Controller)
 Can low level Enable Controller Interrupts
 
Std_ReturnType Can_Arch_CheckWakeup (Can_HwUnit *HwUnit, uint8 Controller)
 Can low level wakeup check
 
Std_ReturnType Can_Arch_GetControllerErrorState (Can_HwUnit *HwUnit, uint8 ControllerId, Can_ErrorStateType *ErrorStatePtr)
 Can low level Get Controller Error State
 
Std_ReturnType Can_Arch_GetControllerMode (Can_HwUnit *HwUnit, uint8 Controller, Can_ControllerStateType *ControllerModePtr)
 Can low level Get Controller Mode
 
Std_ReturnType Can_Arch_GetControllerRxErrorCounter (Can_HwUnit *HwUnit, uint8 ControllerId, uint8 *RxErrorCounterPtr)
 Can low level Get Controller Rx Error Counter
 
Std_ReturnType Can_Arch_GetControllerTxErrorCounter (Can_HwUnit *HwUnit, uint8 ControllerId, uint8 *TxErrorCounterPtr)
 Can low level Get Controller Tx Error Counter
 
Std_ReturnType Can_Arch_Write (Can_HwUnit *HwUnit, Can_HwHandleType Hth, const Can_PduType *PduInfo)
 Can low level Write
 
Std_ReturnType Can_Arch_GetCurrentTime (Can_HwUnit *HwUnit, uint8 ControllerId, Can_TimeStampType *timeStampPtr)
 Can low level Get Current Time
 
void Can_Arch_EnableEgressTimeStamp (Can_HwUnit *HwUnit, Can_HwHandleType Hth)
 Can low level Enable Egress TimeStamp
 
Std_ReturnType Can_Arch_GetEgressTimeStamp (Can_HwUnit *HwUnit, PduIdType TxPduId, Can_HwHandleType Hth, Can_TimeStampType *timeStampPtr)
 Can low level Get Egress TimeStamp
 
Std_ReturnType Can_Arch_GetIngressTimeStamp (Can_HwUnit *HwUnit, Can_HwHandleType Hrh, Can_TimeStampType *timeStampPtr)
 Can low level Get Ingress TimeStamp
 
void Can_Arch_IsrMainHandler (Can_HwUnit *HwUnit, uint8 Controller)
 Can Interrupt Handler
 

Detailed Description

Can Specific Arquitecture Driver

Author
Diego Perez

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.

Function Documentation

◆ Can_Arch_CheckWakeup()

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.

Parameters
HwUnitPointer to the hardware unit configuration
ControllerCAN controller for which the wakeup shall be checked.
Return values
E_OKwakeup detected E_NOT_OK: no wakeup detected

◆ Can_Arch_DeInit()

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.

Parameters
HwUnitPointer to the hardware unit configuration
ControllerCAN controller to be de-initialized
Requirement
SWS_Can_00223

< Initialization bit

< Initialization bit

< Clock stop request bit

< Clock stop acknowledge bit

< Configuration change enable bit

< Interrupt Line 0

< Interrupt Line 1

◆ Can_Arch_DisableControllerInterrupts()

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.

Parameters
HwUnitPointer to the hardware unit configuration
ControllerCAN controller for which interrupts shall be disabled.
Requirement
SWS_Can_00049

< Interrupt Line 0

< Interrupt Line 1

◆ Can_Arch_EnableControllerInterrupts()

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.

Parameters
HwUnitPointer to the hardware unit configuration
ControllerCAN controller for which interrupts shall be enabled.
Requirement
SWS_Can_00208

< Interrupt Line 0

< Interrupt Line 1

◆ Can_Arch_EnableEgressTimeStamp()

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.

Parameters
HwUnitPointer to the hardware unit configuration
Hthinformation which HW-transmit handle shall be used for enabling the time stamp.
Note
This is the smallest granularity which can be added for enabling the timestamp, at HTH level, without affecting the performance.

◆ Can_Arch_GetControllerErrorState()

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.

Parameters
HwUnitPointer to the hardware unit configuration
ControllerIdCanIf ControllerId which is assigned to a CAN controller, which is requested for ErrorState.
ErrorStatePtrPointer to a memory location, where the error state of the CAN controller will be stored.
Return values
E_OKrequest accepted E_NOT_OK: request not accepted
Requirement
SWS_Can_91008

< Bus_Off bit

< Protocol_Error bit

◆ Can_Arch_GetControllerMode()

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

Parameters
HwUnitPointer to the hardware unit configuration
ControllerCAN controller for which the status shall be read.
ControllerModePtrPointer to a memory location, where the current mode of the CAN
Return values
E_OKrequest accepted E_NOT_OK: request not accepted
Requirement
SWS_Can_91014, SWS_Can_91015

◆ Can_Arch_GetControllerRxErrorCounter()

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

Parameters
HwUnitPointer to the hardware unit configuration
ControllerIdCAN controller, whose current Rx error counter shall be acquired.
RxErrorCounterPtrPointer to a memory location, where the current Rx error counter of the CAN controller will be stored.
Return values
E_OKRx error counter available. E_NOT_OK: Wrong ControllerId, or Rx error counter not available.
Requirement
SWS_Can_00511, SWS_Can_00515

< Receive Error Counter

< Receive Error Counter bitfiled size

< Receive Error Passive

◆ Can_Arch_GetControllerTxErrorCounter()

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

Parameters
HwUnitPointer to the hardware unit configuration
ControllerIdCAN controller, whose current Tx error counter shall be acquired.
TxErrorCounterPtrPointer to a memory location, where the current Tx error counter
Return values
E_OKTx error counter available. E_NOT_OK: Wrong ControllerId, or Tx error counter not
Requirement
SWS_Can_00516, SWS_Can_00520

< Transmit Error Counter

< Transmit Error Counter bitfiled size

◆ Can_Arch_GetCurrentTime()

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.

Parameters
HwUnitPointer to the hardware unit configuration
ControllerIdCAN controller, whose current time shall be acquired.
timeStampPtrPointer to a memory location, where the current time of the CAN
Return values
E_OKsuccessful E_NOT_OK: failed

◆ Can_Arch_GetEgressTimeStamp()

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.

Parameters
HwUnitPointer to the hardware unit configuration
TxPduIdTx-PDU handle of CAN L-PDU that has been transmitted.
Hthinformation which HW-transmit handle shall be used for reading the time stamp.
timeStampPtrPointer to a memory location where the time stamp value shall be stored.
Return values
E_OKsuccess E_NOT_OK: failed to read time stamp.

◆ Can_Arch_GetIngressTimeStamp()

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.

Parameters
HwUnitPointer to the hardware unit configuration
Hrhinformation which HW-receive handle shall be used for reading the time stamp.
timeStampPtrPointer to a memory location where the time stamp value shall be stored.
Return values
E_OKsuccess E_NOT_OK: failed to read time stamp.

◆ Can_Arch_Init()

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.

Parameters
HwUnitPointer to the hardware unit configuration
ConfigPointer to driver configuration
ControllerIndex of the controller to be initialized
Requirement
SWS_Can_00237, SWS_Can_00236, SWS_Can_00238, SWS_Can_00239, SWS_Can_00419, SWS_Can_00250, SWS_Can_00053, SWS_Can_00407, SWS_Can_00021, SWS_Can_00291, SWS_Can_00413, SWS_Can_00223 SWS_Can_00245

< 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

◆ Can_Arch_IsrMainHandler()

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.

Parameters
HwUnitPointer to the hardware unit configuration
ControllerCAN controller for which the status shall be changed.
Requirement
SWS_Can_00420, SWS_Can_00033

◆ Can_Arch_SetBaudrate()

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.

Parameters
HwUnitPointer to the hardware unit configuration
ControllerCAN controller for which the baud rate shall be set.
BaudRateConfigIDreferences a baud rate configuration by ID
Return values
E_OKService request accepted, setting of (new) baud rate started E_NOT_OK: Service request not accepted
Requirement
SWS_Can_00255, SWS_Can_00256, SWS_Can_00260, SWS_Can_00422, SWS_Can_00500 SWS_Can_00062

◆ Can_Arch_SetControllerMode()

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.

Parameters
HwUnitPointer to the hardware unit configuration
ControllerCAN controller for which the status shall be changed.
TransitionTransition value to request new state.
Return values
E_OKrequest accepted E_NOT_OK: request not accepted
Requirement
SWS_Can_00261, SWS_Can_00409, SWS_Can_00265, SWS_Can_00266, SWS_Can_00411, SWS_Can_00017 SWS_Can_00384, SWS_Can_00257, SWS_Can_00282, SWS_Can_00426, SWS_Can_00425

< 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

◆ Can_Arch_Write()

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.

Parameters
HwUnitPointer to the hardware unit configuration
Hthinformation 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.
PduInfoPointer to SDU user memory, Data Length and Identifier
Return values
E_OKWrite 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)
Requirement
SWS_Can_00213, SWS_Can_00214, SWS_Can_00275, SWS_Can_00277, SWS_Can_00401, SWS_Can_00402 SWS_Can_00403, SWS_Can_00011, SWS_Can_00486, SWS_Can_00502, SWS_Can_00276

< 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