63 #include "HL_reg_system.h"
76 #define CAN_TIMING_LOWER_LIMIT_COUNTS (95u)
79 #define CAN_TIMING_UPPER_LIMIT_COUNTS (105u)
82 #define CAN_HAL_RETVAL_NO_DATA_LOST (1u)
92 #define CAN_IF2ARB_STANDARD_IDENTIFIER_SHIFT (18u)
94 #define CAN_IF2ARB_EXTENDED_IDENTIFIER_SHIFT (0u)
105 #define CAN_IF2ARB_SET_TX_DIRECTION ((uint32)1u << 29u)
111 #define CAN_IF2ARB_USE_STANDARD_IDENTIFIER ((uint32)0u << 30u)
113 #define CAN_IF2ARB_USE_EXTENDED_IDENTIFIER ((uint32)1u << 30u)
117 #define CAN_LOWEST_MAILBOX_FOR_EXTENDED_IDENTIFIERS (61u)
118 #define CAN_HIGHEST_MAILBOX_FOR_EXTENDED_IDENTIFIERS (64u)
123 "Lower mailbox number must not be greater than higher mailbox number");
126 "Highest mailbox number must not be larger than total number of mailboxes");
182 #if BS_CURRENT_SENSOR_PRESENT == true
270 canREG1->CTL = (uint32)0x00000000U | (uint32)0x00000000U | (uint32)((uint32)0x0000000AU << 10U) |
274 canREG1->ES |= 0xFFFFFFFFU;
277 canREG1->ABOTR = (uint32)0U;
289 while ((canREG1->IF1STAT & 0x80U) == 0x80U) {
292 canREG1->IF1MSK = 0xC0000000U | (uint32)((uint32)((uint32)0x00000000U & (uint32)0x000007FFU) << (uint32)18U);
293 canREG1->IF1ARB = (uint32)0x80000000U | (uint32)0x00000000U | (uint32)0x00000000U |
294 (uint32)((uint32)((uint32)0U & (uint32)0x000007FFU) << (uint32)18U);
295 canREG1->IF1MCTL = 0x00001000U | (uint32)0x00000400U | (uint32)0x00000000U | (uint32)0x00000000U | (uint32)8U;
296 canREG1->IF1CMD = (uint8)0xF8U;
297 canREG1->IF1NO = 42U;
309 while ((canREG1->IF1STAT & 0x80U) == 0x80U) {
312 canREG1->IF1MSK = 0xC0000000U | (uint32)((uint32)((uint32)0x00000000U & (uint32)0x1FFFFFFFU) << (uint32)0U);
313 canREG1->IF1ARB = (uint32)0x80000000U | (uint32)0x40000000U | (uint32)0x00000000U |
314 (uint32)((uint32)((uint32)0U & (uint32)0x1FFFFFFFU) << (uint32)0U);
315 canREG1->IF1MCTL = 0x00001000U | (uint32)0x00000400U | (uint32)0x00000000U | (uint32)0x00000000U | (uint32)8U;
316 canREG1->IF1CMD = (uint8)0xF8U;
317 canREG1->IF1NO = 61U;
329 while ((canREG1->IF2STAT & 0x80U) == 0x80U) {
332 canREG1->IF2MSK = 0xC0000000U | (uint32)((uint32)((uint32)0x00000000U & (uint32)0x1FFFFFFFU) << (uint32)0U);
333 canREG1->IF2ARB = (uint32)0x80000000U | (uint32)0x40000000U | (uint32)0x00000000U |
334 (uint32)((uint32)((uint32)0U & (uint32)0x1FFFFFFFU) << (uint32)0U);
335 canREG1->IF2MCTL = 0x00001000U | (uint32)0x00000400U | (uint32)0x00000000U | (uint32)0x00000000U | (uint32)8U;
336 canREG1->IF2CMD = (uint8)0xF8U;
337 canREG1->IF2NO = 62U;
349 while ((canREG1->IF1STAT & 0x80U) == 0x80U) {
352 canREG1->IF1MSK = 0xC0000000U | (uint32)((uint32)((uint32)0x00000000U & (uint32)0x1FFFFFFFU) << (uint32)0U);
353 canREG1->IF1ARB = (uint32)0x80000000U | (uint32)0x40000000U | (uint32)0x00000000U |
354 (uint32)((uint32)((uint32)0U & (uint32)0x1FFFFFFFU) << (uint32)0U);
355 canREG1->IF1MCTL = 0x00001000U | (uint32)0x00000400U | (uint32)0x00000000U | (uint32)0x00000000U | (uint32)8U;
356 canREG1->IF1CMD = (uint8)0xF8U;
357 canREG1->IF1NO = 63U;
369 while ((canREG1->IF2STAT & 0x80U) == 0x80U) {
372 canREG1->IF2MSK = 0xC0000000U | (uint32)((uint32)((uint32)0x00000000U & (uint32)0x1FFFFFFFU) << (uint32)0U);
373 canREG1->IF2ARB = (uint32)0x80000000U | (uint32)0x40000000U | (uint32)0x00000000U |
374 (uint32)((uint32)((uint32)0U & (uint32)0x1FFFFFFFU) << (uint32)0U);
375 canREG1->IF2MCTL = 0x00001000U | (uint32)0x00000400U | (uint32)0x00000000U | (uint32)0x00000000U | (uint32)8U;
376 canREG1->IF2CMD = (uint8)0xF8U;
377 canREG1->IF2NO = 64U;
385 while ((canREG1->IF1STAT & 0x80U) == 0x80U) {
387 canREG1->IF1CMD = 0x87U;
395 while ((canREG1->IF2STAT & 0x80U) == 0x80U) {
397 canREG1->IF2CMD = 0x17U;
400 canREG1->CTL &= ~(uint32)(0x00000041U);
421 canREG2->CTL = (uint32)0x00000000U | (uint32)0x00000000U | (uint32)((uint32)0x0000000AU << 10U) | 0x00020043U;
424 canREG2->ES |= 0xFFFFFFFFU;
436 while ((canREG2->IF1STAT & 0x80U) == 0x80U) {
439 canREG2->IF1MSK = 0xC0000000U | (uint32)((uint32)((uint32)0x00000000U & (uint32)0x1FFFFFFFU) << (uint32)0U);
440 canREG2->IF1ARB = (uint32)0x80000000U | (uint32)0x40000000U | (uint32)0x00000000U |
441 (uint32)((uint32)((uint32)0U & (uint32)0x1FFFFFFFU) << (uint32)0U);
442 canREG2->IF1MCTL = 0x00001000U | (uint32)0x00000400U | (uint32)0x00000000U | (uint32)0x00000000U | (uint32)8U;
443 canREG2->IF1CMD = (uint8)0xF8U;
444 canREG2->IF1NO = 61U;
456 while ((canREG2->IF2STAT & 0x80U) == 0x80U) {
459 canREG2->IF2MSK = 0xC0000000U | (uint32)((uint32)((uint32)0x00000000U & (uint32)0x1FFFFFFFU) << (uint32)0U);
460 canREG2->IF2ARB = (uint32)0x80000000U | (uint32)0x40000000U | (uint32)0x00000000U |
461 (uint32)((uint32)((uint32)0U & (uint32)0x1FFFFFFFU) << (uint32)0U);
462 canREG2->IF2MCTL = 0x00001000U | (uint32)0x00000400U | (uint32)0x00000000U | (uint32)0x00000000U | (uint32)8U;
463 canREG2->IF2CMD = (uint8)0xF8U;
464 canREG2->IF2NO = 62U;
476 while ((canREG2->IF1STAT & 0x80U) == 0x80U) {
479 canREG2->IF1MSK = 0xC0000000U | (uint32)((uint32)((uint32)0x00000000U & (uint32)0x1FFFFFFFU) << (uint32)0U);
480 canREG2->IF1ARB = (uint32)0x80000000U | (uint32)0x40000000U | (uint32)0x00000000U |
481 (uint32)((uint32)((uint32)0U & (uint32)0x1FFFFFFFU) << (uint32)0U);
482 canREG2->IF1MCTL = 0x00001000U | (uint32)0x00000400U | (uint32)0x00000000U | (uint32)0x00000000U | (uint32)8U;
483 canREG2->IF1CMD = (uint8)0xF8U;
484 canREG2->IF1NO = 63U;
496 while ((canREG2->IF2STAT & 0x80U) == 0x80U) {
499 canREG2->IF2MSK = 0xC0000000U | (uint32)((uint32)((uint32)0x00000000U & (uint32)0x1FFFFFFFU) << (uint32)0U);
500 canREG2->IF2ARB = (uint32)0x80000000U | (uint32)0x40000000U | (uint32)0x00000000U |
501 (uint32)((uint32)((uint32)0U & (uint32)0x1FFFFFFFU) << (uint32)0U);
502 canREG2->IF2MCTL = 0x00001000U | (uint32)0x00000400U | (uint32)0x00000000U | (uint32)0x00000000U | (uint32)8U;
503 canREG2->IF2CMD = (uint8)0xF8U;
504 canREG2->IF2NO = 64U;
512 while ((canREG2->IF1STAT & 0x80U) == 0x80U) {
514 canREG2->IF1CMD = 0x87U;
522 while ((canREG2->IF2STAT & 0x80U) == 0x80U) {
524 canREG2->IF2CMD = 0x17U;
527 canREG2->CTL &= ~(uint32)(0x00000041U);
583 uint32_t retval = canGetData(pNode, messageBox, (uint8 *)&messageData[0]);
587 CAN_BUFFER_ELEMENT_s can_rxBuffer = {
NULL_PTR, 0u,
CAN_INVALID_TYPE, {0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u}};
625 static uint32_t counterTicks = 0;
648 uint32_t currentTime;
669 #if BS_CURRENT_SENSOR_PRESENT == true
674 #if BS_CURRENT_SENSOR_PRESENT == true
726 if (command ==
true) {
738 if (command ==
true) {
750 if (command ==
true) {
833 CAN_BUFFER_ELEMENT_s can_rxBuffer = {
NULL_PTR, 0u,
CAN_INVALID_TYPE, {0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u}};
850 if (command ==
true) {
889 #ifdef UNITY_UNIT_TEST
#define BS_ENERGY_COUNTING_MEASUREMENT_RESPONSE_TIMEOUT_ms
#define BS_NR_OF_STRINGS
Number of parallel strings in the battery pack.
#define BS_COULOMB_COUNTING_MEASUREMENT_RESPONSE_TIMEOUT_ms
#define BS_CURRENT_MEASUREMENT_RESPONSE_TIMEOUT_ms
#define CAN_IF2ARB_EXTENDED_IDENTIFIER_SHIFT
static CAN_NODE_s * CAN_GetNodeConfigurationStructFromRegisterAddress(canBASE_t *pNodeRegister)
get pointer CAN node configuration struct from register address
static void CAN_RxInterrupt(canBASE_t *pNode, uint32 messageBox)
Called in case of CAN RX interrupt.
bool CAN_IsCurrentSensorCcPresent(uint8_t stringNumber)
get flag if CC message from current sensor is received.
void CAN_MainFunction(void)
Calls the functions to drive the CAN interface. Makes the CAN timing checks and sends the periodic me...
static void CAN_ValidateConfiguredTxMessagePeriod(void)
static void CAN_SetCurrentSensorCcPresent(bool command, uint8_t stringNumber)
Sets flag to indicate current sensor sends C-C values.
static STD_RETURN_TYPE_e CAN_PeriodicTransmit(void)
Handles the processing of messages that are meant to be transmitted.
#define CAN_IF2ARB_USE_EXTENDED_IDENTIFIER
#define CAN_IF2ARB_SET_TX_DIRECTION
CAN_STATE_s * TEST_CAN_GetCANState(void)
#define CAN_HAL_RETVAL_NO_DATA_LOST
static void CAN_CheckCanTiming(void)
Checks if the CAN messages come in the specified time window.
#define CAN_IF2ARB_STANDARD_IDENTIFIER_SHIFT
#define CAN_TIMING_LOWER_LIMIT_COUNTS
static void CAN_InitializeTransceiver(void)
void UNIT_TEST_WEAK_IMPL canMessageNotification(canBASE_t *node, uint32 messageBox)
bool CAN_IsCurrentSensorEcPresent(uint8_t stringNumber)
get flag if EC message from current sensor is received
#define CAN_HIGHEST_MAILBOX_FOR_EXTENDED_IDENTIFIERS
static void CAN_TxInterrupt(canBASE_t *pNode, uint32 messageBox)
Called in case of CAN TX interrupt.
void CAN_ReadRxBuffer(void)
Checks the data received per CAN. A receive buffer is used because CAN frames are received in an inte...
bool CAN_IsCurrentSensorPresent(uint8_t stringNumber)
set flag for presence of current sensor.
static void CAN_SetCurrentSensorEcPresent(bool command, uint8_t stringNumber)
Sets flag to indicate current sensor sends C-C values.
#define CAN_TIMING_UPPER_LIMIT_COUNTS
STD_RETURN_TYPE_e CAN_DataSend(CAN_NODE_s *pNode, uint32_t id, CAN_IDENTIFIER_TYPE_e idType, uint8 *pData)
Sends over CAN the data passed in parameters. This function goes over the message boxes and marks the...
static void CAN_CheckCanTimingOfCurrentSensor(void)
#define CAN_IF2ARB_USE_STANDARD_IDENTIFIER
static void CAN_ConfigureRxMailboxesForExtendedIdentifiers(void)
Initialize RX mailboxes for usage with extended identifiers.
#define CAN_LOWEST_MAILBOX_FOR_EXTENDED_IDENTIFIERS
static void CAN_SetCurrentSensorPresent(bool command, uint8_t stringNumber)
Sets flag to indicate current sensor is present.
void CAN_Initialize(void)
Enables the CAN transceiver.. This function sets th pins to enable the CAN transceiver....
static CAN_STATE_s can_state
FAS_STATIC_ASSERT((CAN_LOWEST_MAILBOX_FOR_EXTENDED_IDENTIFIERS<=CAN_HIGHEST_MAILBOX_FOR_EXTENDED_IDENTIFIERS), "Lower mailbox number must not be greater than higher mailbox number")
void CAN_EnablePeriodic(bool command)
Enables periodic sending per CAN. This is used to prevent sending uninitialized data per CAN (e....
Header for the driver for the CAN module.
#define CAN_NR_OF_TX_MESSAGE_BOX
#define CAN_TOTAL_NUMBER_OF_MESSAGE_BOXES
const CAN_SHIM_s can_kShim
const CAN_NODE_s can_node1
const CAN_NODE_s can_node2Isolated
const CAN_RX_MESSAGE_TYPE_s can_rxMessages[]
const uint8_t can_txLength
const CAN_TX_MESSAGE_TYPE_s can_txMessages[]
const uint8_t can_rxLength
@ CAN_EXTENDED_IDENTIFIER_29_BIT
@ CAN_STANDARD_IDENTIFIER_11_BIT
Headers for the helper functions for the CAN module.
#define CAN_BYTE_2_POSITION
#define CAN_BYTE_4_POSITION
#define CAN_BYTE_0_POSITION
#define CAN_BYTE_6_POSITION
#define CAN_BYTE_7_POSITION
#define CAN_BYTE_3_POSITION
#define CAN_BYTE_5_POSITION
#define CAN_BYTE_1_POSITION
#define DATA_READ_DATA(...)
@ DATA_BLOCK_ID_ERROR_STATE
@ DATA_BLOCK_ID_STATE_REQUEST
@ DATA_BLOCK_ID_CURRENT_SENSOR
DIAG_RETURNTYPE_e DIAG_Handler(DIAG_ID_e diagId, DIAG_EVENT_e event, DIAG_IMPACT_LEVEL_e impact, uint32_t data)
DIAG_Handler provides generic error handling, based on diagnosis group.
@ DIAG_ID_CAN_CC_RESPONDING
@ DIAG_ID_CURRENT_SENSOR_RESPONDING
@ DIAG_ID_CAN_RX_QUEUE_FULL
@ DIAG_ID_CAN_EC_RESPONDING
#define FAS_ASSERT(x)
Assertion macro that asserts that x is true.
#define FAS_TRAP
Define that evaluates to essential boolean false thus tripping an assert.
#define NULL_PTR
Null pointer.
Header of task driver implementation.
volatile bool ftsk_allQueuesCreated
General macros and definitions for the whole platform.
#define GEN_REPEAT_U(x, n)
Macro that helps to generate a series of literals (for array initializers).
#define UNIT_TEST_WEAK_IMPL
OS_STD_RETURN_e OS_ReceiveFromQueue(OS_QUEUE xQueue, void *const pvBuffer, uint32_t ticksToWait)
Receive an item from a queue.
OS_STD_RETURN_e OS_SendToBackOfQueueFromIsr(OS_QUEUE xQueue, const void *const pvItemToQueue, long *const pxHigherPriorityTaskWoken)
Post an item to the back the provided queue during an ISR.
void OS_ExitTaskCritical(void)
Exit Critical interface function for use in FreeRTOS-Tasks and FreeRTOS-ISR.
void OS_EnterTaskCritical(void)
Enter Critical interface function for use in FreeRTOS-Tasks and FreeRTOS-ISR.
uint32_t OS_GetTickCount(void)
Returns OS based system tick value.
void PEX_SetPin(uint8_t portExpander, uint8_t pin)
sets pin to high.
void PEX_SetPinDirectionOutput(uint8_t portExpander, uint8_t pin)
sets pin to input.
Header for the driver for the NXP PCA9539 port expander module.
#define PEX_PORT_EXPANDER2
uint8_t data[CAN_MAX_DLC]
CAN_IDENTIFIER_TYPE_e idType
CAN_IDENTIFIER_TYPE_e idType
canBASE_t * canNodeRegister
CAN_RxCallbackFunction_f callbackFunction
CAN_MESSAGE_PROPERTIES_s message
bool currentSensorCCPresent[BS_NR_OF_STRINGS]
bool currentSensorECPresent[BS_NR_OF_STRINGS]
bool currentSensorPresent[BS_NR_OF_STRINGS]
CAN_TxCallbackFunction_f callbackFunction
CAN_MESSAGE_PROPERTIES_s message
CAN_TX_MESSAGE_TIMING_s timing
uint32_t timestampCurrent[BS_NR_OF_STRINGS]
DATA_BLOCK_HEADER_s header
uint32_t timestampEnergyCounting[BS_NR_OF_STRINGS]
uint32_t timestampCurrentCounting[BS_NR_OF_STRINGS]
DATA_BLOCK_HEADER_s header
DATA_BLOCK_HEADER_s header