STM32G0 MCAL 0.0.1
Tiny MCAL for educational purpose.
Loading...
Searching...
No Matches
CanIf.c File Reference

Header file for the CAN interface. More...

#include "Std_Types.h"
#include "Can.h"
#include "CanIf.h"
#include "CanIf_Can.h"
#include "Bfx.h"

Macros

#define Det_ReportError(ModuleId, InstanceId, ApiId, ErrorId)
 
#define Det_ReportRuntimeError(ModuleId, InstanceId, ApiId, ErrorId)
 

Functions

void CanIf_Init (const CanIf_ConfigType *ConfigPtr)
 Initializes the CAN interface.
 
void CanIf_DeInit (void)
 Deinitializes the CAN interface.
 
Std_ReturnType CanIf_SetControllerMode (uint8 ControllerId, Can_ControllerStateType ControllerMode)
 Sets the CAN controller mode.
 
Std_ReturnType CanIf_GetControllerMode (uint8 ControllerId, Can_ControllerStateType *ControllerModePtr)
 Gets the CAN controller mode.
 
Std_ReturnType CanIf_GetControllerErrorState (uint8 ControllerId, Can_ErrorStateType *ErrorStatePtr)
 Gets the CAN controller error state.
 
Std_ReturnType CanIf_Transmit (PduIdType TxPduId, const PduInfoType *PduInfoPtr)
 Transmits a CAN L-PDU.
 
Std_ReturnType CanIf_SetPduMode (uint8 ControllerId, CanIf_PduModeType PduModeRequest)
 Sets the requested PDU mode.
 
Std_ReturnType CanIf_GetPduMode (uint8 ControllerId, CanIf_PduModeType *PduModePtr)
 Gets the requested PDU mode.
 
void CanIf_SetDynamicTxId (PduIdType CanIfTxSduId, Can_IdType CanId)
 Sets the CAN controller baudrate.
 
CanIf_NotifStatusType CanIf_GetTxConfirmationState (uint8 ControllerId)
 Gets the CAN controller Tx confirmation state.
 
Std_ReturnType CanIf_GetControllerRxErrorCounter (uint8 ControllerId, uint8 *RxErrorCounterPtr)
 Gets the CAN controller Rx error counter.
 
Std_ReturnType CanIf_GetControllerTxErrorCounter (uint8 ControllerId, uint8 *TxErrorCounterPtr)
 Gets the CAN controller Tx error counter.
 
void CanIf_TxConfirmation (PduIdType CanTxPduId)
 Handles the transmit confirmation.
 
void CanIf_RxIndication (const Can_HwType *Mailbox, const PduInfoType *PduInfoPtr)
 Handles the received CAN frame.
 
void CanIf_ControllerBusOff (uint8 ControllerId)
 Handles the bus-off event.
 
void CanIf_ControllerModeIndication (uint8 ControllerId, Can_ControllerStateType ControllerMode)
 Controller mode indication.
 
void CanIf_ControllerErrorStatePassive (uint8 ControllerId, uint16 RxErrorCounter, uint16 TxErrorCounter)
 Signal the error state of the CAN controller.
 
void CanIf_ErrorNotification (uint8 ControllerId, Can_ErrorType CanError)
 Signal the error notification of the CAN controller.
 

Variables

static const CanIf_ConfigTypeLocalConfigPtr = ( (void *)0 )
 Pointer to the configuration structure.
 

Detailed Description

Header file for the CAN interface.

Author
Diego Perez

The CAN Interface module provides CAN communication abstracted access to the CAN Driver and CAN Transceiver Driver services for control and supervision of the CAN network. The CAN Interface forwards downwards the status change requests from the CAN State Manager to the lower layer CAN device drivers, and upwards the CAN Driver / CAN Transceiver Driver events are forwarded by the CAN Interface module to e.g. the corresponding NM module.

Macro Definition Documentation

◆ Det_ReportError

#define Det_ReportError ( ModuleId,
InstanceId,
ApiId,
ErrorId )
Value:
(void)0
Parameters
ModuleIdmodule id number
InstanceIdInstance Id
ApiIdPai id
ErrorIdError code

◆ Det_ReportRuntimeError

#define Det_ReportRuntimeError ( ModuleId,
InstanceId,
ApiId,
ErrorId )
Value:
(void)0
Parameters
ModuleIdmodule id number
InstanceIdInstance Id
ApiIdPai id
ErrorIdError code

Function Documentation

◆ CanIf_ControllerBusOff()

void CanIf_ControllerBusOff ( uint8 ControllerId)

Handles the bus-off event.

This service indicates a Controller BusOff event referring to the corresponding CAN Controller with the abstract CanIf ControllerId.

Parameters
[in]ControllerIdCAN controller for which the status shall be changed.
Requirement
SWS_CANIF_00218, SWS_CANIF_00661, SWS_CANIF_00429

◆ CanIf_ControllerErrorStatePassive()

void CanIf_ControllerErrorStatePassive ( uint8 ControllerId,
uint16 RxErrorCounter,
uint16 TxErrorCounter )

Signal the error state of the CAN controller.

The function derives the ErrorCounterTreshold from RxErrorCounter/ TxErrorCounter values and reports it to the IdsM as security event CANIF_SEV_ERRORSTATE_PASSIVE to the IdsM. It also prepares the context data for the respective security event.

Parameters
[in]ControllerIdAbstracted CanIf ControllerId which is assigned to a CAN controller.
[in]RxErrorCounterValue of the Rx error counter
[in]TxErrorCounterValue of the Tx error counter
Requirement
SWS_CANIF_91008, SWS_CANIF_00661

◆ CanIf_ControllerModeIndication()

void CanIf_ControllerModeIndication ( uint8 ControllerId,
Can_ControllerStateType ControllerMode )

Controller mode indication.

This service indicates a controller state transition referring to the corresponding CAN controller with the abstract CanIf ControllerId.

Parameters
[in]ControllerIdCAN controller for which the status shall be changed.
[in]ControllerModeNew controller mode.
Requirement
SWS_CANIF_00699, SWS_CANIF_00661, SWS_CANIF_00700

◆ CanIf_DeInit()

void CanIf_DeInit ( void )

Deinitializes the CAN interface.

De-initializes the CanIf module. Caller of the CanIf_DeInit() function has to be sure there are no on-going transmissions/receptions, nor any pending transmission confirmations.

Requirement
SWS_CANIF_91002, SWS_CANIF_00661

◆ CanIf_ErrorNotification()

void CanIf_ErrorNotification ( uint8 ControllerId,
Can_ErrorType CanError )

Signal the error notification of the CAN controller.

The function shall derive the bus error source rx or tx from the parameter CanError and report the bus error as security event CANIF_SEV_TX_ERROR_DETECTED or CANIF_SEV_RX_ ERROR_DETECTED. It also prepares the context data for the respective security event.

Parameters
[in]ControllerIdCAN controller for which the status shall be changed.
[in]CanErrorReported CAN error
Requirement
SWS_CANIF_91009, SWS_CANIF_00661, SWS_CANIF_00920, SWS_CANIF_00921

◆ CanIf_GetControllerErrorState()

Std_ReturnType CanIf_GetControllerErrorState ( uint8 ControllerId,
Can_ErrorStateType * ErrorStatePtr )

Gets the CAN controller error state.

This service calls the corresponding CAN Driver service for getting the current CAN controller error state.

Parameters
[in]ControllerIdCAN controller for which the status shall be changed.
[out]ErrorStatePtrPointer to a memory location, where the current error state of the CAN controller will be stored.
Returns
E_OK: Controller mode request has been accepted E_NOT_OK: Controller mode request has not been accepted
Requirement
SWS_CANIF_00005, SWS_CANIF_00661, SWS_CANIF_00898, SWS_CANIF_00899

< Error return value

< OK return value

◆ CanIf_GetControllerMode()

Std_ReturnType CanIf_GetControllerMode ( uint8 ControllerId,
Can_ControllerStateType * ControllerModePtr )

Gets the CAN controller mode.

This service calls the corresponding CAN Driver service for getting the current CAN controller mode.

Parameters
[in]ControllerIdCAN controller for which the status shall be changed.
[out]ControllerModePtrPointer to a memory location, where the current mode of the CAN controller will be stored.
Returns
E_OK: Controller mode request has been accepted E_NOT_OK: Controller mode request has not been accepted
Requirement
SWS_CANIF_00004, SWS_CANIF_00661, SWS_CANIF_00313, SWS_CANIF_00656

< Error return value

< OK return value

◆ CanIf_GetControllerRxErrorCounter()

Std_ReturnType CanIf_GetControllerRxErrorCounter ( uint8 ControllerId,
uint8 * RxErrorCounterPtr )

Gets the CAN controller Rx error counter.

This service calls the corresponding CAN Driver service for obtaining the Rx error counter of the CAN controller.

Parameters
[in]ControllerIdCAN controller for which the status shall be changed.
[out]RxErrorCounterPtrPointer to a memory location, where the current Rx error counter
Returns
E_OK: Rx error counter available. E_NOT_OK: Wrong ControllerId, or Rx error counter not available.
Requirement
SWS_CANIF_91003, SWS_CANIF_00661, SWS_CANIF_00907, SWS_CANIF_00908

< Error return value

< OK return value

◆ CanIf_GetControllerTxErrorCounter()

Std_ReturnType CanIf_GetControllerTxErrorCounter ( uint8 ControllerId,
uint8 * TxErrorCounterPtr )

Gets the CAN controller Tx error counter.

This service calls the corresponding CAN Driver service for obtaining the Tx error counter of the CAN controller.

Parameters
[in]ControllerIdCAN controller for which the status shall be changed.
[out]TxErrorCounterPtrPointer to a memory location, where the current Tx error counter
Returns
E_OK: Rx error counter available. E_NOT_OK: Wrong ControllerId, or Rx error counter not available.
Requirement
SWS_CANIF_91005, SWS_CANIF_00909, SWS_CANIF_00910

< Error return value

< OK return value

◆ CanIf_GetPduMode()

Std_ReturnType CanIf_GetPduMode ( uint8 ControllerId,
CanIf_PduModeType * PduModePtr )

Gets the requested PDU mode.

This service returns the requested mode of the L-PDUs of a predefined logical PDU channel.

Parameters
[in]ControllerIdAll PDUs of the own ECU connected to the corresponding CanIf ControllerId, which is assigned to a physical CAN controller are addressed.
[out]PduModePtrPointer to a memory location, where the requested PDU mode is stored.
Returns
E_OK: PDU mode request has been accepted E_NOT_OK: PDU mode request has not been accepted
Requirement
SWS_CANIF_00009, SWS_CANIF_00661, SWS_CANIF_00346, SWS_CANIF_00657

< Error return value

< OK return value

◆ CanIf_GetTxConfirmationState()

CanIf_NotifStatusType CanIf_GetTxConfirmationState ( uint8 ControllerId)

Gets the CAN controller Tx confirmation state.

This service reports, if any TX confirmation has been done for the whole CAN controller since the last CAN controller start.

Parameters
[in]ControllerIdCAN controller for which the status shall be changed.
Returns
Combined TX confirmation status for all TX PDUs of the CAN controller
Requirement
SWS_CANIF_00734, SWS_CANIF_00661, SWS_CANIF_00736

◆ CanIf_Init()

void CanIf_Init ( const CanIf_ConfigType * ConfigPtr)

Initializes the CAN interface.

This service Initializes internal and external interfaces of the CAN Interface for the further processing.

Parameters
[in]ConfigPtrPointer to the CAN Interface configuration structure.
Requirement
SWS_CANIF_00001

◆ CanIf_RxIndication()

void CanIf_RxIndication ( const Can_HwType * Mailbox,
const PduInfoType * PduInfoPtr )

Handles the received CAN frame.

This service indicates a successful reception of a received CAN Rx L-PDU to the CanIf after passing all filters and validation checks.

Parameters
[in]MailboxIdentifies the HRH and its corresponding CAN Controller
[in]PduInfoPtrPointer to the received L-PDU
Requirement
SWS_CANIF_00006, SWS_CANIF_00661, SWS_CANIF_00416, SWS_CANIF_00417, SWS_CANIF_00419

◆ CanIf_SetControllerMode()

Std_ReturnType CanIf_SetControllerMode ( uint8 ControllerId,
Can_ControllerStateType ControllerMode )

Sets the CAN controller mode.

This service calls the corresponding CAN Driver service for changing of the CAN controller mode.

Parameters
[in]ControllerIdCAN controller for which the status shall be changed.
[in]ControllerModeRequested mode transition.
Returns
E_OK: Controller mode request has been accepted E_NOT_OK: Controller mode request has not been accepted
Requirement
SWS_CANIF_00003, SWS_CANIF_00661, SWS_CANIF_00311, SWS_CANIF_00774

< Error return value

< OK return value

◆ CanIf_SetDynamicTxId()

void CanIf_SetDynamicTxId ( PduIdType CanIfTxSduId,
Can_IdType CanId )

Sets the CAN controller baudrate.

This service reconfigures the corresponding CAN identifier of the requested CAN L-PDU.

Parameters
[in]CanIfTxSduIdL-SDU handle to be transmitted. This handle specifies the corresponding CAN L-SDU ID and implicitly the CAN Driver instance as well as the corresponding CAN controller device.
[in]CanIdStandard/Extended CAN ID of CAN L-SDU that shall be transmitted as FD or conventional CAN frame.
Requirement
SWS_CANIF_00189, SWS_CANIF_00661, SWS_CANIF_00352, SWS_CANIF_00353

◆ CanIf_SetPduMode()

Std_ReturnType CanIf_SetPduMode ( uint8 ControllerId,
CanIf_PduModeType PduModeRequest )

Sets the requested PDU mode.

This service sets the requested mode at the L-PDUs of a predefined logical PDU channel.

Parameters
[in]ControllerIdAll PDUs of the own ECU connected to the corresponding CanIf ControllerId, which is assigned to a physical CAN controller are addressed.
[in]PduModeRequestRequested PDU mode change.
Returns
E_OK: Request for mode transition has been accepted. E_NOT_OK: Request for mode transition has not been accepted.
Requirement
SWS_CANIF_00008, SWS_CANIF_00661, SWS_CANIF_00341, SWS_CANIF_00860, SWS_CANIF_00874

< Error return value

< OK return value

◆ CanIf_Transmit()

Std_ReturnType CanIf_Transmit ( PduIdType TxPduId,
const PduInfoType * PduInfoPtr )

Transmits a CAN L-PDU.

This service calls the corresponding CAN Driver service for transmission of a CAN L-PDU.

Parameters
[in]TxPduIdIdentifier of the PDU to be transmitted
[in]PduInfoPtrLength of and pointer to the PDU data and pointer to MetaData.
Returns
E_OK: Transmit request has been accepted E_NOT_OK: Transmit request has not been accepted
Requirement
SWS_CANIF_00005, SWS_CANIF_00661, SWS_CANIF_00319, SWS_CANIF_00320, SWS_CANIF_00893

< Error return value

< OK return value

◆ CanIf_TxConfirmation()

void CanIf_TxConfirmation ( PduIdType CanTxPduId)

Handles the transmit confirmation.

This service confirms a previously successfully processed transmission of a CAN TxPDU.

Parameters
[in]CanTxPduIdID of the successfully transmitted Tx L-PDU
Requirement
SWS_CANIF_00007, SWS_CANIF_00661, SWS_CANIF_00410

Variable Documentation

◆ LocalConfigPtr

const CanIf_ConfigType* LocalConfigPtr = ( (void *)0 )
static

Pointer to the configuration structure.

< Add static when no testing