The foxBMS secondary mcu API documentation
cansignal.c File Reference

Messages and signal settings for the CAN driver. More...

#include "cansignal.h"
#include "database.h"
#include "diag.h"
#include "foxmath.h"
#include "os.h"
Include dependency graph for cansignal.c:

Functions

static STD_RETURN_TYPE_e CANS_PeriodicTransmit (void)
 
static STD_RETURN_TYPE_e CANS_PeriodicReceive (void)
 
static void CANS_SetSignalData (CANS_signal_s signal, uint64_t value, uint8_t *dataPtr)
 
static void CANS_GetSignalData (uint64_t *dst, CANS_signal_s signal, uint8_t *dataPtr)
 
static void CANS_ComposeMessage (CAN_NodeTypeDef_e canNode, CANS_messagesTx_e msgIdx, uint8_t dataptr[])
 
static void CANS_ParseMessage (CAN_NodeTypeDef_e canNode, CANS_messagesRx_e msgIdx, uint8_t dataptr[])
 parses signal data from message associated with this msgIdx More...
 
static uint8_t CANS_CheckCanTiming (void)
 Checks if the CAN messages come in the specified time window. More...
 
static void CANS_SetCurrentSensorPresent (uint8_t command)
 set flag for presence of current sensor. More...
 
static void CANS_SetCurrentSensorCCPresent (uint8_t command)
 set flag for sending of C-C by current sensor. More...
 
void CANS_Init (void)
 
void CANS_MainFunction (void)
 
STD_RETURN_TYPE_e CANS_AddMessage (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 CANS_TransmitBuffer (CAN_NodeTypeDef_e canNode)
 Transmits canNode transmit buffer. More...
 
STD_RETURN_TYPE_e CANS_TransmitMessage (CAN_NodeTypeDef_e canNode, uint32_t msgID, uint8_t *ptrMsgData, uint32_t msgLength, uint32_t RTR)
 Transmits message directly on the CAN bus. More...
 
static uint64_t CANS_GetBitmask (uint8_t bitlength)
 generates bitfield, which masks the bits where the actual signal (defined by its bitlength) is located More...
 
void CANS_Enable_Periodic (uint8_t command)
 enable/disable the periodic transmit/receive. More...
 
uint8_t CANS_IsCurrentSensorPresent (void)
 set flag for presence of current sensor. More...
 
uint8_t CANS_IsCurrentSensorCCPresent (void)
 set flag for sending of C-C by current sensor. More...
 

Variables

static CANS_STATE_s cans_state
 
static DATA_BLOCK_STATEREQUEST_s canstatereq_tab
 

Detailed Description

Messages and signal settings for the CAN driver.

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
01.10.2015 (date of creation)
Module-prefix CANS

generic conversion module of Can signals from CAN buffered reception to DATA Manager and vice versa

Function Documentation

◆ CANS_AddMessage()

STD_RETURN_TYPE_e CANS_AddMessage ( 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.

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
Here is the call graph for this function:

◆ CANS_CheckCanTiming()

static uint8_t CANS_CheckCanTiming ( void  )
static

Checks if the CAN messages come in the specified time window.

if actual time stamp- previous time stamp is > 96 and < 104 check is good else the check is bad

Returns
TRUE if timing is in tolerance range, FLASE if not
Here is the call graph for this function:

◆ CANS_ComposeMessage()

static void CANS_ComposeMessage ( CAN_NodeTypeDef_e  canNode,
CANS_messagesTx_e  msgIdx,
uint8_t  dataptr[] 
)
static

composes message data from all signals associated with this msgIdx

signal data is received by callback getter functions

Parameters
[in]msgIdxmessage index for which the data should be composed
[out]dataptrpointer where the message data should be stored to
Here is the call graph for this function:

◆ CANS_Enable_Periodic()

void CANS_Enable_Periodic ( uint8_t  command)

enable/disable the periodic transmit/receive.

Returns
none

◆ CANS_GetBitmask()

static uint64_t CANS_GetBitmask ( uint8_t  bitlength)
static

generates bitfield, which masks the bits where the actual signal (defined by its bitlength) is located

Parameters
bitlengthlength of the signal in bits
Returns
bitmask bitfield mask

◆ CANS_GetSignalData()

static void CANS_GetSignalData ( uint64_t *  dst,
CANS_signal_s  signal,
uint8_t *  dataPtr 
)
static

extracts signal data from CAN message data

Parameters
[out]dstpointer where the signal data should be copied to
[in]signalsignal identifier
[in]dataPtrCAN message data, from which signal data is extracted
Here is the call graph for this function:

◆ CANS_Init()

void CANS_Init ( void  )

initializes local variables and module internals needed to use conversion of can signals. Until now no initialization is needed and thus the function does nothing.

◆ CANS_IsCurrentSensorCCPresent()

uint8_t CANS_IsCurrentSensorCCPresent ( void  )

set flag for sending of C-C by current sensor.

Returns
retval TRUE if C-C is being sent, FALSE otherwise

◆ CANS_IsCurrentSensorPresent()

uint8_t CANS_IsCurrentSensorPresent ( void  )

set flag for presence of current sensor.

Returns
retval TRUE if a current sensor is present, FALSE otherwise

◆ CANS_MainFunction()

void CANS_MainFunction ( void  )

handles the conversion of can signals from and to datamanager database or other modules defined by the getter and setter configuration.

Here is the call graph for this function:

◆ CANS_ParseMessage()

static void CANS_ParseMessage ( CAN_NodeTypeDef_e  canNode,
CANS_messagesRx_e  msgIdx,
uint8_t  dataptr[] 
)
static

parses signal data from message associated with this msgIdx

signal data is received by callback setter functions

Parameters
[in]msgIdxmessage index for which the data should be parsed
[in]dataptrpointer where the message data is stored
Here is the call graph for this function:

◆ CANS_PeriodicReceive()

static STD_RETURN_TYPE_e CANS_PeriodicReceive ( void  )
static

handles the processing of received CAN messages.

This function gets the messages in the receive buffer of the CAN module. If a message ID is matching one of the IDs in the configuration of CANS module, the signal processing is executed by call to CANS_ParseMessage.

Returns
E_OK, if a message has been received and parsed, E_NOT_OK otherwise
Here is the call graph for this function:

◆ CANS_PeriodicTransmit()

static STD_RETURN_TYPE_e CANS_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 transfered to the buffer of the CAN module. If a callback function is declared in configuration, this callback is called after successful transmission.

Returns
E_OK if a successful transfer to CAN buffer occured, E_NOT_OK otherwise
Here is the call graph for this function:

◆ CANS_SetCurrentSensorCCPresent()

static void CANS_SetCurrentSensorCCPresent ( uint8_t  command)
static

set flag for sending of C-C by current sensor.

Returns
none

◆ CANS_SetCurrentSensorPresent()

static void CANS_SetCurrentSensorPresent ( uint8_t  command)
static

set flag for presence of current sensor.

Returns
none

◆ CANS_SetSignalData()

static void CANS_SetSignalData ( CANS_signal_s  signal,
uint64_t  value,
uint8_t *  dataPtr 
)
static

assembles signal data in CAN message data

Parameters
signalsignal identifier
valuesignal value data
dataPtrCAN message data, in which the signal data is inserted
Here is the call graph for this function:

◆ CANS_TransmitBuffer()

STD_RETURN_TYPE_e CANS_TransmitBuffer ( CAN_NodeTypeDef_e  canNode)

Transmits canNode transmit buffer.

Parameters
canNodecanNode on which the message shall be transmitted
Return values
E_OKif transmission successful, otherwise E_NOT_OK
Here is the call graph for this function:

◆ CANS_TransmitMessage()

STD_RETURN_TYPE_e CANS_TransmitMessage ( 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
Here is the call graph for this function:

Variable Documentation

◆ cans_state

CANS_STATE_s cans_state
static
Initial value:
= {
.periodic_enable = FALSE,
.current_sensor_present = FALSE,
.current_sensor_cc_present = FALSE,
}
#define FALSE
Definition: std_types.h:65

◆ canstatereq_tab

DATA_BLOCK_STATEREQUEST_s canstatereq_tab
static