foxBMS  1.0.0
The foxBMS Battery Management System API Documentation
can.c File Reference

Driver for the CAN module. More...

#include "can.h"
#include "HL_het.h"
#include "bender_iso165c.h"
#include "database.h"
#include "diag.h"
#include "io.h"
#include "mcu.h"
Include dependency graph for can.c:

Go to the source code of this file.

Functions

static void CAN_TxInterrupt (canBASE_t *pNode, uint32 messageBox)
 Called in case of CAN TX interrupt. More...
 
static void CAN_RxInterrupt (canBASE_t *pNode, uint32 messageBox)
 Called in case of CAN RX interrupt. More...
 
static STD_RETURN_TYPE_e CAN_PeriodicTransmit (void)
 Handles the processing of messages that are meant to be transmitted. This function looks for the repetition times and the repetition phase of messages that are intended to be sent periodically. If a comparison with an internal counter (i.e., the counter how often this function has been called) states that a transmit is pending, the message is composed by call of CANS_ComposeMessage and transferred to the buffer of the CAN module. If a callback function is declared in configuration, this callback is called after successful transmission. More...
 
static bool CAN_CheckCanTiming (void)
 Checks if the CAN messages come in the specified time window If the (current time stamp) - (previous time stamp) > 96ms and < 104ms, the check is true, false otherwise. More...
 
static void CAN_SetCurrentSensorPresent (bool command, uint8_t stringNumber)
 Sets flag to indicate current sensor is present. More...
 
static void CAN_SetCurrentSensorCcPresent (bool command, uint8_t stringNumber)
 Sets flag to indicate current sensor sends C-C values. More...
 
static void CAN_SetCurrentSensorEcPresent (bool command, uint8_t stringNumber)
 Sets flag to indicate current sensor sends C-C values. More...
 
static void CAN_InitializeTransceiver (void)
 
void CAN_Initialize (void)
 Enables the CAN transceiver.. This function sets th pins to enable the CAN transceiver. It must be called before using the CAN interface. More...
 
STD_RETURN_TYPE_e CAN_DataSend (canBASE_t *pNode, uint32_t id, uint8 *pData)
 Sends over CAN the data passed in parameters. This function goes over the messageboxes and marks the ones that should be sent. More...
 
void CAN_MainFunction (void)
 Calls the functions to drive the CAN interface. Makes the CAN timing checks and sends the periodic messages. More...
 
void CAN_ReadRxBuffer (void)
 Checks the data received per CAN. A receive buffer is used because CAN frames are received in an interrupt routine. The TMS570LC4357 does not allow nested interrupts, so interrupts are deactivated during receive. Calls to the database do not work when interrupts are disabled. Receive callbacks are made within this function: as it is not called during an interrupt routine, calls to the database can be made. More...
 
void CAN_EnablePeriodic (bool command)
 enable/disable the periodic transmit/receive. More...
 
bool CAN_IsCurrentSensorPresent (uint8_t stringNumber)
 set flag for presence of current sensor. More...
 
bool CAN_IsCurrentSensorCcPresent (uint8_t stringNumber)
 get flag if CC message from current sensor is received. More...
 
bool CAN_IsCurrentSensorEcPresent (uint8_t stringNumber)
 get flag if EC message from current sensor is received More...
 
void UNIT_TEST_WEAK_IMPL canMessageNotification (canBASE_t *node, uint32 messageBox)
 

Variables

static CAN_STATE_s can_state
 
static CAN_BUFFERELEMENT_s can_rxBufferData [CAN0_RX_BUFFER_LENGTH]
 
static CAN_RX_BUFFER_s can_rxBuffer
 

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
2019-12-04 (date of creation)
Updated
2021-03-29 (date of last update)
Prefix
CAN

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

Definition in file can.c.

Function Documentation

◆ CAN_CheckCanTiming()

static bool CAN_CheckCanTiming ( void  )
static

Checks if the CAN messages come in the specified time window If the (current time stamp) - (previous time stamp) > 96ms and < 104ms, the check is true, false otherwise.

Returns
true if timing is in tolerance range, false otherwise

Definition at line 243 of file can.c.

Here is the call graph for this function:

◆ CAN_DataSend()

STD_RETURN_TYPE_e CAN_DataSend ( canBASE_t *  pNode,
uint32_t  id,
uint8 *  pData 
)

Sends over CAN the data passed in parameters. This function goes over the messageboxes and marks the ones that should be sent.

Parameters
[in,out]pNodeCAN interface to use
[in]idID of message to send
[out]pDatadata to send (8 bytes)
Returns
STD_OK if a message box was free to send, STD_NOT_OK otherwise

Definition at line 192 of file can.c.

◆ CAN_EnablePeriodic()

void CAN_EnablePeriodic ( bool  command)

enable/disable the periodic transmit/receive.

Enables periodic sending per CAN. This is used to prevent sending uninitialized data per CAN (e.g., before the first LTC measurement cycle was completed).

Definition at line 347 of file can.c.

◆ CAN_Initialize()

void CAN_Initialize ( void  )

Enables the CAN transceiver.. This function sets th pins to enable the CAN transceiver. It must be called before using the CAN interface.

Definition at line 188 of file can.c.

Here is the call graph for this function:

◆ CAN_InitializeTransceiver()

static void CAN_InitializeTransceiver ( void  )
static

initialize the SPI interface to the CAN transceiver

Definition at line 164 of file can.c.

Here is the call graph for this function:

◆ CAN_IsCurrentSensorCcPresent()

bool CAN_IsCurrentSensorCcPresent ( uint8_t  stringNumber)

get flag if CC message from current sensor is received.

Parameters
stringNumberaddressed string
Returns
true if CC message is being received, false otherwise

Definition at line 398 of file can.c.

◆ CAN_IsCurrentSensorEcPresent()

bool CAN_IsCurrentSensorEcPresent ( uint8_t  stringNumber)

get flag if EC message from current sensor is received

Parameters
stringNumberaddressed string
Returns
true if EC message is being received, false otherwise

Definition at line 403 of file can.c.

◆ CAN_IsCurrentSensorPresent()

bool CAN_IsCurrentSensorPresent ( uint8_t  stringNumber)

set flag for presence of current sensor.

Returns
retval true if a current sensor is present, false otherwise

Definition at line 393 of file can.c.

◆ CAN_MainFunction()

void CAN_MainFunction ( void  )

Calls the functions to drive the CAN interface. Makes the CAN timing checks and sends the periodic messages.

Definition at line 210 of file can.c.

Here is the call graph for this function:

◆ CAN_PeriodicTransmit()

static STD_RETURN_TYPE_e CAN_PeriodicTransmit ( void  )
static

Handles the processing of messages that are meant to be transmitted. This function looks for the repetition times and the repetition phase of messages that are intended to be sent periodically. If a comparison with an internal counter (i.e., the counter how often this function has been called) states that a transmit is pending, the message is composed by call of CANS_ComposeMessage and transferred to the buffer of the CAN module. If a callback function is declared in configuration, this callback is called after successful transmission.

Returns
STD_OK if a CAN transfer was made, STD_NOT_OK otherwise

Definition at line 217 of file can.c.

Here is the call graph for this function:

◆ CAN_ReadRxBuffer()

void CAN_ReadRxBuffer ( void  )

Checks the data received per CAN. A receive buffer is used because CAN frames are received in an interrupt routine. The TMS570LC4357 does not allow nested interrupts, so interrupts are deactivated during receive. Calls to the database do not work when interrupts are disabled. Receive callbacks are made within this function: as it is not called during an interrupt routine, calls to the database can be made.

Definition at line 323 of file can.c.

◆ CAN_RxInterrupt()

static void CAN_RxInterrupt ( canBASE_t *  pNode,
uint32  messageBox 
)
static

Called in case of CAN RX interrupt.

Parameters
pNodeCAN interface on which message was received
messageBoxmessage box on which message was received

Definition at line 411 of file can.c.

◆ CAN_SetCurrentSensorCcPresent()

static void CAN_SetCurrentSensorCcPresent ( bool  command,
uint8_t  stringNumber 
)
static

Sets flag to indicate current sensor sends C-C values.

Parameters
commandtrue if coulomb counting message detected, otherwise false
stringNumberstring addressed
Returns
none

Definition at line 368 of file can.c.

Here is the call graph for this function:

◆ CAN_SetCurrentSensorEcPresent()

static void CAN_SetCurrentSensorEcPresent ( bool  command,
uint8_t  stringNumber 
)
static

Sets flag to indicate current sensor sends C-C values.

Parameters
commandtrue if energy counting message detected, otherwise false
stringNumberstring addressed
Returns
none

Definition at line 380 of file can.c.

Here is the call graph for this function:

◆ CAN_SetCurrentSensorPresent()

static void CAN_SetCurrentSensorPresent ( bool  command,
uint8_t  stringNumber 
)
static

Sets flag to indicate current sensor is present.

Parameters
commandtrue if current sensor present, otherwise false
stringNumberstring addressed
Returns
none

Definition at line 356 of file can.c.

Here is the call graph for this function:

◆ CAN_TxInterrupt()

static void CAN_TxInterrupt ( canBASE_t *  pNode,
uint32  messageBox 
)
static

Called in case of CAN TX interrupt.

Parameters
pNodeCAN interface on which message was sent
messageBoxmessage box on which message was sent

Definition at line 408 of file can.c.

◆ canMessageNotification()

void UNIT_TEST_WEAK_IMPL canMessageNotification ( canBASE_t *  node,
uint32  messageBox 
)

called in case of CAN interrupt, defined as weak in HAL

Definition at line 440 of file can.c.

Here is the call graph for this function:

Variable Documentation

◆ can_rxBuffer

CAN_RX_BUFFER_s can_rxBuffer
static
Initial value:
= {
.pRead = &can_rxBufferData[0],
.pWrite = &can_rxBufferData[0],
}

interface object for can_rxBufferData

Definition at line 83 of file can.c.

◆ can_rxBufferData

CAN_BUFFERELEMENT_s can_rxBufferData[CAN0_RX_BUFFER_LENGTH]
static

local buffer for receiving data from CAN

Definition at line 80 of file can.c.

◆ can_state

CAN_STATE_s can_state
static
Initial value:
= {
.periodicEnable = false,
.currentSensorPresent = false,
.currentSensorCCPresent = false,
.currentSensorECPresent = false,
}

tracks the local state of the can module

Definition at line 72 of file can.c.

CAN0_RX_BUFFER_LENGTH
#define CAN0_RX_BUFFER_LENGTH
Definition: can.h:78
can_rxBufferData
static CAN_BUFFERELEMENT_s can_rxBufferData[CAN0_RX_BUFFER_LENGTH]
Definition: can.c:80