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

Can Driver More...

#include "Can_Cfg.h"

Go to the source code of this file.

Functions

void Can_Init (const Can_ConfigType *Config)
 Can Initialization
 
void Can_DeInit (void)
 Can Deinitialization
 
Std_ReturnType Can_SetBaudrate (uint8 Controller, uint16 BaudRateConfigID)
 Can Set Baudrate
 
Std_ReturnType Can_SetControllerMode (uint8 Controller, Can_ControllerStateType Transition)
 Can Set Controller Mode
 
void Can_DisableControllerInterrupts (uint8 Controller)
 Can Disable Controller Interrupts
 
void Can_EnableControllerInterrupts (uint8 Controller)
 Can Enable Controller Interrupts
 
Std_ReturnType Can_CheckWakeup (uint8 Controller)
 Can wakeup check
 
Std_ReturnType Can_GetControllerErrorState (uint8 ControllerId, Can_ErrorStateType *ErrorStatePtr)
 Can Get Controller Error State
 
Std_ReturnType Can_GetControllerMode (uint8 Controller, Can_ControllerStateType *ControllerModePtr)
 Can Get Controller Mode
 
Std_ReturnType Can_GetControllerRxErrorCounter (uint8 ControllerId, uint8 *RxErrorCounterPtr)
 Can Get Controller Rx Error Counter
 
Std_ReturnType Can_GetControllerTxErrorCounter (uint8 ControllerId, uint8 *TxErrorCounterPtr)
 Can Get Controller Tx Error Counter
 
Std_ReturnType Can_Write (Can_HwHandleType Hth, const Can_PduType *PduInfo)
 Can Write
 
void Can_GetVersionInfo (Std_VersionInfoType *versioninfo)
 Can Get Version
 
Std_ReturnType Can_GetCurrentTime (uint8 ControllerId, Can_TimeStampType *timeStampPtr)
 Can Get Current Time
 
void Can_EnableEgressTimeStamp (Can_HwHandleType Hth)
 Can Enable Egress TimeStamp
 
Std_ReturnType Can_GetEgressTimeStamp (PduIdType TxPduId, Can_HwHandleType Hth, Can_TimeStampType *timeStampPtr)
 Can Get Egress TimeStamp
 
Std_ReturnType Can_GetIngressTimeStamp (Can_HwHandleType Hrh, Can_TimeStampType *timeStampPtr)
 Can Get Ingress TimeStamp
 

Detailed Description

Can Driver

Author
Diego Perez

The Can module provides services for initiating transmissions and calls the callback functions of the CanIf module for notifying events, independently from the hardware. Furthermore, it provides services to control the behavior and state of the CAN controllers that are belonging to the same CAN Hardware Unit. Several CAN controllers can be controlled by a single Can module as long as they belong to the same CAN Hardware Unit.

Function Documentation

◆ Can_CheckWakeup()

Std_ReturnType Can_CheckWakeup ( uint8 Controller)

Can wakeup check

This function checks if a wakeup has occurred for the given controller.

Parameters
ControllerCAN controller for which the wakeup shall be checked.
Return values
E_OKwakeup detected E_NOT_OK: no wakeup detected
Requirement
SWS_Can_00360, SWS_Can_00362, SWS_Can_00363

◆ Can_DeInit()

void Can_DeInit ( void )

Can Deinitialization

This function de-initializes the module.

Requirement
SWS_Can_91002, SWS_Can_91011, SWS_Can_9101

◆ Can_DisableControllerInterrupts()

void Can_DisableControllerInterrupts ( uint8 Controller)

Can Disable Controller Interrupts

This function disables all interrupts for this CAN controller.

Parameters
ControllerCAN controller for which interrupts shall be disabled.
Requirement
SWS_Can_00231, SWS_Can_00205, SWS_Can_00206

◆ Can_EnableControllerInterrupts()

void Can_EnableControllerInterrupts ( uint8 Controller)

Can Enable Controller Interrupts

This function enables all interrupts for this CAN controller.

Parameters
ControllerCAN controller for which interrupts shall be enabled.
Requirement
SWS_Can_00232, SWS_Can_00209, SWS_Can_00210

◆ Can_EnableEgressTimeStamp()

void Can_EnableEgressTimeStamp ( Can_HwHandleType Hth)

Can Enable Egress TimeStamp

Activates egress time stamping on a dedicated HTH. Some HW does store once the egress time stamp marker and some HW needs it always before transmission. There will be no "disable" functionality, due to the fact, that the message type is always "time stamped" by network design.

Parameters
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.
Requirement
SWS_CAN_91025, SWS_CAN_00525, SWS_CAN_00526

< Transmit object

◆ Can_GetControllerErrorState()

Std_ReturnType Can_GetControllerErrorState ( uint8 ControllerId,
Can_ErrorStateType * ErrorStatePtr )

Can Get Controller Error State

This function returns the error state of the CAN controller.

Parameters
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_91004, SWS_Can_91005, SWS_Can_91006, SWS_Can_91007

◆ Can_GetControllerMode()

Std_ReturnType Can_GetControllerMode ( uint8 Controller,
Can_ControllerStateType * ControllerModePtr )

Can Get Controller Mode

This service reports about the current status of the requested CAN controller.

Parameters
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_91016, SWS_Can_91017, SWS_Can_91018

◆ Can_GetControllerRxErrorCounter()

Std_ReturnType Can_GetControllerRxErrorCounter ( uint8 ControllerId,
uint8 * RxErrorCounterPtr )

Can Get Controller Rx Error Counter

Returns the Rx error counter for a CAN controller. This value might not be available for all CAN controllers, in which case E_NOT_OK would be returned. Please note that the value of the counter might not be correct at the moment the API returns it, because the Rx counter is handled asynchronously in hardware. Applications should not trust this value for any assumption about the current bus state.

Parameters
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_00512, SWS_Can_00513, SWS_Can_00514

◆ Can_GetControllerTxErrorCounter()

Std_ReturnType Can_GetControllerTxErrorCounter ( uint8 ControllerId,
uint8 * TxErrorCounterPtr )

Can Get Controller Tx Error Counter

Returns the Tx error counter for a CAN controller. This value might not be available for all CAN controllers, in which case E_NOT_OK would be returned. Please note that the value of the counter might not be correct at the moment the API returns it, because the Tx counter is handled asynchronously in hardware. Applications should not trust this value for any assumption about the current bus state.

Parameters
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_00517, SWS_Can_00518, SWS_Can_00519

◆ Can_GetCurrentTime()

Std_ReturnType Can_GetCurrentTime ( uint8 ControllerId,
Can_TimeStampType * timeStampPtr )

Can Get Current Time

Returns a time value out of the HW registers according to the capability of the HW

Parameters
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
Requirement
SWS_CAN_91026, SWS_CAN_00521, SWS_CAN_00522, SWS_CAN_00523

◆ Can_GetEgressTimeStamp()

Std_ReturnType Can_GetEgressTimeStamp ( PduIdType TxPduId,
Can_HwHandleType Hth,
Can_TimeStampType * timeStampPtr )

Can Get Egress TimeStamp

Reads back the egress time stamp on a dedicated message object. It needs to be called within the TxConfirmation() function.

Parameters
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.
Requirement
SWS_CAN_91027, SWS_CAN_00529, SWS_CAN_00530, SWS_CAN_00531, SWS_CAN_00532
Todo
need to define what is a invalid TxPduId

< Transmit object

◆ Can_GetIngressTimeStamp()

Std_ReturnType Can_GetIngressTimeStamp ( Can_HwHandleType Hrh,
Can_TimeStampType * timeStampPtr )

Can Get Ingress TimeStamp

Reads back the ingress time stamp on a dedicated message object. It needs to be called within the RxIndication() function.

Parameters
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
Requirement
SWS_CAN_91028, SWS_CAN_00535, SWS_CAN_00536, SWS_CAN_00537

< Receive object

◆ Can_GetVersionInfo()

void Can_GetVersionInfo ( Std_VersionInfoType * versioninfo)

Can Get Version

This function returns the version information of this module.

Parameters
versioninfoPointer to where to store the version information of this module.
Requirement
SWS_Can_00224, SWS_Can_00177

◆ Can_Init()

void Can_Init ( const Can_ConfigType * Config)

Can Initialization

This function initializes the module and the CAN controller. The CAN controller is initialized according to the parameter Config.

Parameters
ConfigPointer to driver configuration
Requirement
SWS_Can_00223, SWS_Can_00174, SWS_Can_00408

◆ Can_SetBaudrate()

Std_ReturnType Can_SetBaudrate ( uint8 Controller,
uint16 BaudRateConfigID )

Can Set Baudrate

This service shall set the baud rate configuration of the CAN controller. Depending on necessary baud rate modifications the controller might have to reset.

Parameters
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_00491, SWS_Can_00492,SWS_Can_00493, SWS_Can_00494

◆ Can_SetControllerMode()

Std_ReturnType Can_SetControllerMode ( uint8 Controller,
Can_ControllerStateType Transition )

Can Set Controller Mode

This function performs software triggered state transitions of the CAN controller State machine.

Parameters
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_00230, SWS_Can_00198, SWS_Can_00199, SWS_Can_00200

◆ Can_Write()

Std_ReturnType Can_Write ( Can_HwHandleType Hth,
const Can_PduType * PduInfo )

Can Write

This function is called by CanIf to pass a CAN message to CanDrv for transmission.

Parameters
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)
Note
To detect if controller is in FD mode we use a custom field in Config structure instead of a valid CanControllerFdBaudrateConfig
Requirement
SWS_Can_00233, SWS_Can_00216, SWS_Can_00217, SWS_Can_00219, SWS_Can_00218

< Transmit object

< Classic mode

< Classic mode