The foxBMS secondary mcu API documentation
can.c File Reference

Driver for the CAN module. More...

#include "can.h"
Include dependency graph for can.c:

Macros

#define ID_16BIT_FIFO0   (0U)
 
#define ID_16BIT_FIFO1   (1U)
 
#define ID_32BIT_FIFO0   (2U)
 
#define ID_32BIT_FIFO1   (3U)
 
#define MSK_16BIT_FIFO0   (4U)
 
#define MSK_16BIT_FIFO1   (5U)
 
#define MSK_32BIT   (6U)
 

Functions

static uint8_t CAN_GetNextID (CAN_MSG_RX_TYPE_s *can_RxMsgs, uint8_t numberOfRxIDs, uint8_t startIndex, uint8_t filterCase)
 Returns the next index of wished filter ID setting in CAN_MSG_RX_TYPE_t can_RxMsgs[CAN_NUMBER_OF_RX_IDs]. More...
 
static uint8_t CAN_NumberOfNeededFilters (CAN_MSG_RX_TYPE_s *can_RxMsgs, uint8_t *numberOfDifferentIDs, uint32_t *error)
 Returns the number of filters that have to be initialized. More...
 
static uint32_t CAN_InitFilter (CAN_HandleTypeDef *ptrHcan, CAN_MSG_RX_TYPE_s *can_RxMsgs, uint8_t numberOfRxMsgs)
 Initializes message filtering. More...
 
static void CAN_TxCpltCallback (CAN_NodeTypeDef_e canNode)
 Transmission complete callback in non blocking mode. More...
 
static void CAN_RxMsg (CAN_NodeTypeDef_e canNode, CAN_HandleTypeDef *ptrHcan, uint8_t FIFONumber)
 Receives CAN messages and stores them either in RxBuffer or in hcan. More...
 
static STD_RETURN_TYPE_e CAN_BufferBypass (CAN_NodeTypeDef_e canNode, uint32_t msgID, uint8_t *rxData, uint8_t DLC, uint8_t RTR)
 Receives a bypassed CAN message and interprets it. More...
 
static STD_RETURN_TYPE_e CAN_InterpretReceivedMsg (CAN_NodeTypeDef_e canNode, uint32_t msgID, uint8_t *data, uint8_t DLC, uint8_t RTR)
 Interprets the received message. More...
 
uint32_t CAN_Init (void)
 Initializes CAN settings and message filtering. More...
 
void HAL_CAN_TxMailbox0CompleteCallback (CAN_HandleTypeDef *hcan)
 Transmission Mailbox 0 complete callback. More...
 
void HAL_CAN_TxMailbox1CompleteCallback (CAN_HandleTypeDef *hcan)
 Transmission Mailbox 1 complete callback. More...
 
void HAL_CAN_TxMailbox2CompleteCallback (CAN_HandleTypeDef *hcan)
 Transmission Mailbox 2 complete callback. More...
 
void HAL_CAN_RxFifo0MsgPendingCallback (CAN_HandleTypeDef *hcan)
 Rx FIFO 0 message pending callback. More...
 
void HAL_CAN_RxFifo1MsgPendingCallback (CAN_HandleTypeDef *hcan)
 Rx FIFO 1 message pending callback. More...
 
void HAL_CAN_ErrorCallback (CAN_HandleTypeDef *hcan)
 Error CAN callback. More...
 
STD_RETURN_TYPE_e CAN_TxMsg (CAN_NodeTypeDef_e canNode, uint32_t msgID, uint8_t *ptrMsgData, uint32_t msgLength, uint32_t RTR)
 Transmits message directly on the CAN bus. More...
 
STD_RETURN_TYPE_e CAN_Send (CAN_NodeTypeDef_e canNode, uint32_t msgID, uint8_t *ptrMsgData, uint32_t msgLength, uint32_t RTR)
 Add message to transmit buffer, message will be transmitted shortly after. More...
 
STD_RETURN_TYPE_e CAN_TxMsgBuffer (CAN_NodeTypeDef_e canNode)
 Transmits a can message from transmit buffer. More...
 
STD_RETURN_TYPE_e CAN_ReceiveBuffer (CAN_NodeTypeDef_e canNode, Can_PduType *msg)
 Reads a can message from RxBuffer. More...
 
void CAN_SetSleepMode (CAN_NodeTypeDef_e canNode)
 Set CAN to sleep mode. More...
 
void CAN_WakeUp (CAN_NodeTypeDef_e canNode)
 Wake CAN up from sleep mode. More...
 

Variables

uint8_t canNode0_listenonly_mode = 0
 CAN listen only transceiver mode of CAN node 0. More...
 
uint8_t canNode1_listenonly_mode = 0
 CAN listen only transceiver mode of CAN node 1. More...
 
CAN_FilterTypeDef sFilterConfig
 

Detailed Description

Driver for the CAN module.

BSD 3-Clause License Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

We kindly request you to use one or more of the following phrases to refer to foxBMS in your hardware, software, documentation or advertising materials:

″This product uses parts of foxBMS®″

″This product includes parts of foxBMS®″

″This product is derived from foxBMS®″

Author
foxBMS Team
Date
12.07.2015 (date of creation)
Module-prefix CAN

Implementation of the CAN Interrupts, initialization, buffers, receive and transmit interfaces.

Macro Definition Documentation

◆ ID_16BIT_FIFO0

#define ID_16BIT_FIFO0   (0U)

◆ ID_16BIT_FIFO1

#define ID_16BIT_FIFO1   (1U)

◆ ID_32BIT_FIFO0

#define ID_32BIT_FIFO0   (2U)

◆ ID_32BIT_FIFO1

#define ID_32BIT_FIFO1   (3U)

◆ MSK_16BIT_FIFO0

#define MSK_16BIT_FIFO0   (4U)

◆ MSK_16BIT_FIFO1

#define MSK_16BIT_FIFO1   (5U)

◆ MSK_32BIT

#define MSK_32BIT   (6U)

Function Documentation

◆ CAN_BufferBypass()

static STD_RETURN_TYPE_e CAN_BufferBypass ( CAN_NodeTypeDef_e  canNode,
uint32_t  msgID,
uint8_t *  rxData,
uint8_t  DLC,
uint8_t  RTR 
)
static

Receives a bypassed CAN message and interprets it.

Parameters
canNodecanNode on which the message has been received
msgIDmessage ID
datapointer to the message data
DLClength of received data
RTRRTR bit of received message
Return values
E_OKif interpreting was successful, otherwise E_NOT_OK

◆ CAN_GetNextID()

static uint8_t CAN_GetNextID ( CAN_MSG_RX_TYPE_s *  can_RxMsgs,
uint8_t  numberOfRxIDs,
uint8_t  startIndex,
uint8_t  filterCase 
)
static

Returns the next index of wished filter ID setting in CAN_MSG_RX_TYPE_t can_RxMsgs[CAN_NUMBER_OF_RX_IDs].

Parameters
can_RxMsgspointer to receive message struct
numberOfRxIDscount of that type of receive message in can_RxMsgs struct
startIndexindex where to start searching
filterCasespecifies the object what will be found
Return values
returnsindex

◆ CAN_Init()

uint32_t CAN_Init ( void  )

Initializes CAN settings and message filtering.

Return values
0if initialization successful, otherwise errorcode
Here is the call graph for this function:

◆ CAN_InitFilter()

static uint32_t CAN_InitFilter ( CAN_HandleTypeDef *  ptrHcan,
CAN_MSG_RX_TYPE_s *  can_RxMsgs,
uint8_t  numberOfRxMsgs 
)
static

Initializes message filtering.

Return values
0if no error occurred, otherwise error code
Here is the call graph for this function:

◆ CAN_InterpretReceivedMsg()

static STD_RETURN_TYPE_e CAN_InterpretReceivedMsg ( CAN_NodeTypeDef_e  canNode,
uint32_t  msgID,
uint8_t *  data,
uint8_t  DLC,
uint8_t  RTR 
)
static

Interprets the received message.

Parameters
canNodecanNode on which the message has been received
msgIDmessage ID
datapointer to the message data
DLClength of received data
RTRRTR bit of received message
Returns
E_OK if interpretation successful, otherwise E_NOT_OK

◆ CAN_NumberOfNeededFilters()

static uint8_t CAN_NumberOfNeededFilters ( CAN_MSG_RX_TYPE_s *  can_RxMsgs,
uint8_t *  numberOfDifferentIDs,
uint32_t *  error 
)
static

Returns the number of filters that have to be initialized.

Parameters
can_RxMsgspointer to receive message struct
numberOfDifferentIDspointer to array, where to store the specific number of different IDs
Return values
numberof needed filters

◆ CAN_ReceiveBuffer()

STD_RETURN_TYPE_e CAN_ReceiveBuffer ( CAN_NodeTypeDef_e  canNode,
Can_PduType *  msg 
)

Reads a can message from RxBuffer.

Parameters
canNodecanNode on which a message has been received
msgmessage that has been received
Return values
E_OKif reception successful, if buffer empty or invalid pointer E_NOT_OK

◆ CAN_RxMsg()

static void CAN_RxMsg ( CAN_NodeTypeDef_e  canNode,
CAN_HandleTypeDef *  ptrHcan,
uint8_t  FIFONumber 
)
static

Receives CAN messages and stores them either in RxBuffer or in hcan.

Parameters
canNodecanNode which received the message
ptrHcanpointer to a CAN_HandleTypeDef structure that contains the message information of the specified CAN.
FIFONumberFIFO in which the message has been received
Return values
none(void)
Here is the call graph for this function:

◆ CAN_Send()

STD_RETURN_TYPE_e CAN_Send ( CAN_NodeTypeDef_e  canNode,
uint32_t  msgID,
uint8_t *  ptrMsgData,
uint32_t  msgLength,
uint32_t  RTR 
)

Add message to transmit buffer, message will be transmitted shortly after.

---------------------— IMPORTANT!!!! -----------------------------— Make sure that this function is not interrupted by the operating system during its execution.

Parameters
canNodecanNode on which the message shall be transmitted
msgIDID of the message that will be transmitted
ptrMsgDatapointer to a uint8_t array that contains the message that will be transmitted
msgLengthlength of the message that will be transmitted This parameter can be a value of CAN_identifier_type.
RTRSpecifies the type of frame for the message that will be transmitted. This parameter can be a value of CAN_remote_transmission_request
Return values
E_OKif successful, E_NOT_OK if buffer is full or error occurred

◆ CAN_SetSleepMode()

void CAN_SetSleepMode ( CAN_NodeTypeDef_e  canNode)

Set CAN to sleep mode.

Parameters
canNodecanNode which shall be put to sleep mode
Return values
none(void)

◆ CAN_TxCpltCallback()

static void CAN_TxCpltCallback ( CAN_NodeTypeDef_e  canNode)
static

Transmission complete callback in non blocking mode.

Parameters
canNodecanNode that transmitted a message
Return values
none(void)
Here is the call graph for this function:

◆ CAN_TxMsg()

STD_RETURN_TYPE_e CAN_TxMsg ( CAN_NodeTypeDef_e  canNode,
uint32_t  msgID,
uint8_t *  ptrMsgData,
uint32_t  msgLength,
uint32_t  RTR 
)

Transmits message directly on the CAN bus.

Parameters
canNodecanNode on which the message shall be transmitted
msgIDID of the message that will be transmitted
ptrMsgDatapointer to the data that shall be transmitted
msgLengthSpecifies the data length
RTRSpecifies the type of frame for the message that will be transmitted.
Return values
E_OKif transmission successful, otherwise E_NOT_OK

◆ CAN_TxMsgBuffer()

STD_RETURN_TYPE_e CAN_TxMsgBuffer ( CAN_NodeTypeDef_e  canNode)

Transmits a can message from transmit buffer.

---------------------— IMPORTANT!!!! -----------------------------— Make sure that this function is not interrupted by the operating system during its execution.

Parameters
canNodecanNode on which the message shall be transmitted
Return values
E_OKif transmission successful, otherwise E_NOT_OK

◆ CAN_WakeUp()

void CAN_WakeUp ( CAN_NodeTypeDef_e  canNode)

Wake CAN up from sleep mode.

Parameters
canNodecanNode which shall be waken up from sleep mode
Return values
none.

◆ HAL_CAN_ErrorCallback()

void HAL_CAN_ErrorCallback ( CAN_HandleTypeDef *  hcan)

Error CAN callback.

Parameters
hcanpointer to a CAN_HandleTypeDef structure that contains the configuration information for the specified CAN.
Return values
None

◆ HAL_CAN_RxFifo0MsgPendingCallback()

void HAL_CAN_RxFifo0MsgPendingCallback ( CAN_HandleTypeDef *  hcan)

Rx FIFO 0 message pending callback.

Parameters
hcanpointer to a CAN_HandleTypeDef structure that contains the configuration information for the specified CAN.
Return values
None
Here is the call graph for this function:

◆ HAL_CAN_RxFifo1MsgPendingCallback()

void HAL_CAN_RxFifo1MsgPendingCallback ( CAN_HandleTypeDef *  hcan)

Rx FIFO 1 message pending callback.

Parameters
hcanpointer to a CAN_HandleTypeDef structure that contains the configuration information for the specified CAN.
Return values
None
Here is the call graph for this function:

◆ HAL_CAN_TxMailbox0CompleteCallback()

void HAL_CAN_TxMailbox0CompleteCallback ( CAN_HandleTypeDef *  hcan)

Transmission Mailbox 0 complete callback.

Parameters
hcanpointer to a CAN_HandleTypeDef structure that contains the configuration information for the specified CAN.
Return values
None
Here is the call graph for this function:

◆ HAL_CAN_TxMailbox1CompleteCallback()

void HAL_CAN_TxMailbox1CompleteCallback ( CAN_HandleTypeDef *  hcan)

Transmission Mailbox 1 complete callback.

Parameters
hcanpointer to a CAN_HandleTypeDef structure that contains the configuration information for the specified CAN.
Return values
None
Here is the call graph for this function:

◆ HAL_CAN_TxMailbox2CompleteCallback()

void HAL_CAN_TxMailbox2CompleteCallback ( CAN_HandleTypeDef *  hcan)

Transmission Mailbox 2 complete callback.

Parameters
hcanpointer to a CAN_HandleTypeDef structure that contains the configuration information for the specified CAN.
Return values
None
Here is the call graph for this function:

Variable Documentation

◆ canNode0_listenonly_mode

uint8_t canNode0_listenonly_mode = 0

CAN listen only transceiver mode of CAN node 0.

◆ canNode1_listenonly_mode

uint8_t canNode1_listenonly_mode = 0

CAN listen only transceiver mode of CAN node 1.

◆ sFilterConfig

CAN_FilterTypeDef sFilterConfig
Initial value:
= {
.FilterActivation = ENABLE,
}