STM32Cube Expansion Pack CAN Stack
CanDrv_bxCAN Class Reference

driver class to work with the STM32 bxCAN controller module More...

#include <CanDrv_bxCAN.h>

Inheritance diagram for CanDrv_bxCAN:
Collaboration diagram for CanDrv_bxCAN:

Public Member Functions

 CanDrv_bxCAN ()
 standard constructor for a bxCAN controller object
 
virtual ~CanDrv_bxCAN ()
 standard destructor for a bxCAN controller object
 
void TxTask (void)
 task function to push the tx message from software buffer to tx mailbox More...
 
Std_ReturnType Init (const CanConfigType *ptr2Config=NULL_PTR, const ComIf *ptr2ComIfObject=NULL_PTR)
 Init function for the bxCAN. More...
 
Std_ReturnType SetControllerMode (ECU_CanController Controller, CanControllerStates Transition)
 The API to set a controller mode. More...
 
Std_ReturnType Write (ECU_CanController Controller, const ComStack_CanMessageType *ptr2PduInfo)
 The API to write a message to tx FIFO. More...
 
Std_ReturnType SetFilterByBitmask (ECU_CanController Controller, ComStack_CanIdType FilterId, ComStack_CanIdType FilterMask)
 configure a free hardware filter using bit masking More...
 
Std_ReturnType SetFilterByCanId (ECU_CanController Controller, ComStack_CanIdType FilterId)
 configure a free hardware filter using single CAN Id filtering More...
 
- Public Member Functions inherited from Can
 Can ()
 Standard Constructor.
 
virtual ~Can ()
 basic destructor
 
CanDrvStates GetDrvState (void)
 To get the the software module state.
 
void SetDrvStateReady (void)
 Switch driver state to ready.
 
void SetDrvStateUninit (void)
 Switch driver state to uninit.
 
virtual void Deinit (void)
 The API function for Deinit. More...
 
virtual Std_ReturnType SetBaudrate (ECU_CanController Controller, CanControllerBaudRateConfigID BaudrateId)
 The API to set baudrate on a controller. More...
 
virtual void DisableControllerInterrupts (ECU_CanController Controller)
 The API to disable all interrupts of a controller. More...
 
virtual void EnableControllerInterrupts (ECU_CanController Controller)
 The API to enable all interrupts of a controller. More...
 
virtual Std_ReturnType CheckWakeup (ECU_CanController Controller)
 The API checks the controller for wakeup events. More...
 
virtual Std_ReturnType GetControllerErrorState (ECU_CanController Controller, uint8_t *ErrorStatePtr)
 The API returns the error state of the CAN controller. More...
 
virtual Std_ReturnType GetControllerMode (ECU_CanController Controller, CanControllerStates *ControllerModePtr)
 The API returns the error state of the CAN controller. More...
 

Private Member Functions

Std_ReturnType FindFreeFilter (const uint8_t *ptr2FilterBankNumber, const uint8_t *ptr2FilterNumber, const uint8_t *ptr2FilterMode)
 to find a free CAN hardware filter More...
 
uint32_t CanIdToStmRegisterFormat (ComStack_CanIdType CanId)
 change the 32bit format to use with STM Registers More...
 

Private Attributes

CAN_HandleTypeDef bxCanHdl [2]
 we need a handle to hold the information for the bxCAN controller
 
bxCan_TxMessageType canTxBuffer [CAN_TX_SW_BUFFER_SIZE]
 we want a Tx software buffer More...
 

Detailed Description

driver class to work with the STM32 bxCAN controller module

Definition at line 183 of file CanDrv_bxCAN.h.

Member Function Documentation

◆ CanIdToStmRegisterFormat()

uint32_t CanDrv_bxCAN::CanIdToStmRegisterFormat ( ComStack_CanIdType  CanId)
private

change the 32bit format to use with STM Registers

Parameters
[in]CanIdshould be a CanIf formated CanId
Returns
CanId in STM bxCAN Register format

Definition at line 432 of file CanDrv_bxCAN.cpp.

References bxCan_IdSelectType::common, bxCan_StdCanIdType::Id11bit, bxCan_ExtCanIdType::Id29bit, bxCan_ExtCanIdType::IDE, bxCan_StdCanIdType::RTR, bxCan_ExtCanIdType::RTR, bxCan_IdSelectType::stm_ExtId, bxCan_IdSelectType::stm_StdId, and TRUE.

Referenced by SetFilterByBitmask(), and SetFilterByCanId().

◆ FindFreeFilter()

Std_ReturnType CanDrv_bxCAN::FindFreeFilter ( const uint8_t *  ptr2FilterBankNumber,
const uint8_t *  ptr2FilterNumber,
const uint8_t *  ptr2FilterMode 
)
private

to find a free CAN hardware filter

STM hasn't a function like this in the HAL.
We find a free hardware filter and returns the filter bank to use the filter.
We returns the filter number to use it on fast selection in IRQ routine.
The filter mode is used to search for mask or identifier filter. If searching for identifier filter we returns also if there is a FR2 is empty

Parameters
[out]ptr2FilterBankNumberreturns the number of the first free filter bank
[out]ptr2FilterNumberreturns the filter number according to the previous filter configuration
[in,out]ptr2FilterModeselects the search for Mask filter (aka deactivated filter) or Identifier Filter. on Identifier Filter search it returns if the FR1 register is already in use
Returns
  • E_OK ........... we found an unused filter
  • E_NOT_OK ........... we can't find an unused filter
Todo:
we need to clean up the filter number CAN1_USED_RX_HW_FILTER
Todo:
we need a readable implementation for the "second identifier filter bit" inside ptr2FilterMode

Definition at line 281 of file CanDrv_bxCAN.cpp.

References AUTOMATIC, bxCanHdl, E_NOT_OK, E_OK, FALSE, P2VAR, and TRUE.

Referenced by SetFilterByBitmask(), and SetFilterByCanId().

◆ Init()

Std_ReturnType CanDrv_bxCAN::Init ( const CanConfigType ptr2Config = NULL_PTR,
const ComIf ptr2ComIfObject = NULL_PTR 
)
virtual

Init function for the bxCAN.

Todo:
we need a generic mode for IRQ activation
Warning
here will be done the unique connection to the interrupt handles we need a good C++ way for this we will switch to function pointer inside the Init-structure later

Implements Can.

Definition at line 65 of file CanDrv_bxCAN.cpp.

References AUTOMATIC, bxCanHdl, CAN_DET_REPORTERROR, CAN_INIT_ID, E_INIT_FAILED, E_NOT_OK, E_TRANSITION, Can::GetDrvState(), NULL_PTR, P2CONST, ptr2ComIf, and Uninit.

Here is the call graph for this function:

◆ SetControllerMode()

Std_ReturnType CanDrv_bxCAN::SetControllerMode ( ECU_CanController  Controller,
CanControllerStates  Transition 
)
virtual

The API to set a controller mode.

Parameters
[in]Controllerselects the controller
[in]Transitionselects the transition per name/id
See also
CAN_SET_CONTROLLER_MODE_ID
Todo:
maybe we add the possibility to call the function with Controller == ECU_CanController::NBROF_CanController

Implements Can.

Definition at line 145 of file CanDrv_bxCAN.cpp.

References bxCanHdl, CAN_DET_REPORTERROR, CAN_SET_CONTROLLER_MODE_ID, CS_Started, E_NOT_OK, E_OK, and E_TRANSITION.

◆ SetFilterByBitmask()

Std_ReturnType CanDrv_bxCAN::SetFilterByBitmask ( ECU_CanController  Controller,
ComStack_CanIdType  FilterId,
ComStack_CanIdType  FilterMask 
)
virtual

configure a free hardware filter using bit masking

set hardware filter

Attention
This isn't the same like inside STM register access. But the function manages the correct use for STM HAL
  • bit 31 is IDE
  • bit 30 is RTR
Parameters
[in]Controllerselect the controller where the filter should be applied
[in]FilterIdthe selected filter bits
[in]FilterMaskthe filter mask to select valid filter bits
Returns
E_OK if the filter is applied, E_NOT_OK no hardware filter free
Todo:
we need a handling to select different Rx Fifo

Reimplemented from Can.

Definition at line 339 of file CanDrv_bxCAN.cpp.

References bxCanHdl, CanIdToStmRegisterFormat(), E_NOT_OK, E_OK, and FindFreeFilter().

Here is the call graph for this function:

◆ SetFilterByCanId()

Std_ReturnType CanDrv_bxCAN::SetFilterByCanId ( ECU_CanController  Controller,
ComStack_CanIdType  FilterId 
)
virtual

configure a free hardware filter using single CAN Id filtering

set hardware filter

Parameters
[in]Controllerselect the controller where the filter should be applied
[in]FilterIdthe selected filter bits
Returns
E_OK if the filter is applied, E_NOT_OK no hardware filter free
Todo:
we need a handling to select different Rx Fifo

Reimplemented from Can.

Definition at line 383 of file CanDrv_bxCAN.cpp.

References bxCanHdl, CanIdToStmRegisterFormat(), E_NOT_OK, E_OK, and FindFreeFilter().

Here is the call graph for this function:

◆ TxTask()

void CanDrv_bxCAN::TxTask ( void  )
virtual

task function to push the tx message from software buffer to tx mailbox

Todo:
the Tx Task need handling to transmit to other CAN controller then the bxCanMaster

Reimplemented from Can.

Definition at line 233 of file CanDrv_bxCAN.cpp.

References bxCanHdl, canTxBuffer, Can::GetDrvState(), bxCan_TxMessageType::Header, bxCan_TxMessageType::Mailbox, Ready, bxCan_TxMessageType::State, TxMessage_free, TxMessage_rdy2tx, TxMessage_transmit, TxMessage_txerr, and TxMessage_txok.

Here is the call graph for this function:

◆ Write()

Std_ReturnType CanDrv_bxCAN::Write ( ECU_CanController  Controller,
const ComStack_CanMessageType ptr2PduInfo 
)
virtual

The API to write a message to tx FIFO.

Parameters
[in]Controllerselect the controller for tx
[in]PduInfothe CAN message to send

Reimplemented from Can.

Definition at line 186 of file CanDrv_bxCAN.cpp.

References CAN_DET_REPORTERROR, CAN_WRITE_ID, canTxBuffer, bxCan_TxMessageType::Controller, bxCan_TxMessageType::Data, E_NOT_OK, E_OK, E_UNINIT, Can::GetDrvState(), bxCan_TxMessageType::Header, Ready, bxCan_TxMessageType::State, TRUE, TxMessage_free, TxMessage_rdy2tx, and TxMessage_write.

Here is the call graph for this function:

Member Data Documentation

◆ canTxBuffer

bxCan_TxMessageType CanDrv_bxCAN::canTxBuffer[CAN_TX_SW_BUFFER_SIZE]
private

we want a Tx software buffer

we start with a fix size. Later it would be go to the IDE

Todo:
bring the buffers to save class

Definition at line 276 of file CanDrv_bxCAN.h.

Referenced by TxTask(), and Write().


The documentation for this class was generated from the following files: