62 #include "HL_system.h"
64 #pragma diag_suppress 232
104 .pMuxSequenceStart = {0},
153 uint16_t local_remainder = remainder;
155 local_remainder ^= item;
157 for (
int i = 0; i < 16; i++) {
161 if ((local_remainder & 0x8000u) > 0u) {
162 local_remainder = (local_remainder << 1u) ^ ((0x9eb2u << 1u) + 0x1u);
164 local_remainder = (local_remainder << 1u);
168 return (local_remainder);
180 uint16_t remainder = 0;
185 for (
int i = 0; i < (msg->
dataLength - 3); i++) {
203 uint16_t iterator = 0;
205 for (uint8_t stringNumber = 0u; stringNumber <
BS_NR_OF_STRINGS; stringNumber++) {
241 n775_state->
n775Data.
uid[stringNumber][iterator] = 0;
372 switch (returnedValue) {
418 uint16_t readValue = 0u;
419 uint16_t uid[3u] = {0};
428 MC33775_SYS_MODE_OFFSET,
429 (MC33775_SYS_MODE_TARGETMODE_DEEPSLEEP_ENUM_VAL << MC33775_SYS_MODE_TARGETMODE_POS),
446 MC33775_SYS_COM_CFG_OFFSET,
448 (MC33775_SYS_COM_CFG_BUSFW_ENABLED_ENUM_VAL << MC33775_SYS_COM_CFG_BUSFW_POS),
467 MC33775_SYS_COM_TO_CFG_OFFSET,
476 for (uint8_t j = 0u; j <= 3u; j++) {
498 MC33775_I2C_CFG_OFFSET,
499 (MC33775_I2C_CFG_EN_ENABLED_ENUM_VAL << MC33775_I2C_CFG_EN_POS) +
500 (MC33775_I2C_CFG_CLKSEL_F_400K_ENUM_VAL << MC33775_I2C_CFG_CLKSEL_POS),
525 MC33775_ALLM_CFG_OFFSET,
544 uint16_t primaryRawValues[20] = {0u};
545 uint16_t secondaryRawValues[4] = {0u};
546 uint16_t currentRawValue = 0u;
547 int16_t primaryValues[20] = {0u};
548 int16_t secondaryValues[4] = {0u};
549 int16_t currentValue = 0u;
554 bool gpio03Error =
false;
555 bool gpio47Error =
false;
560 MC33775_ALLM_APP_CTRL_OFFSET,
561 (1u << MC33775_ALLM_APP_CTRL_PAUSEBAL_POS) | (0x3FFu << MC33775_PRMM_APP_CTRL_CAPVC_POS) |
562 (MC33775_PRMM_APP_CTRL_VCOLNUM_DISABLED_ENUM_VAL << MC33775_PRMM_APP_CTRL_VCOLNUM_POS),
569 MC33775_ALLM_APP_CTRL_OFFSET,
570 (0u << MC33775_ALLM_APP_CTRL_PAUSEBAL_POS) | (0x3FFu << MC33775_PRMM_APP_CTRL_CAPVC_POS) |
571 (MC33775_PRMM_APP_CTRL_VCOLNUM_DISABLED_ENUM_VAL << MC33775_PRMM_APP_CTRL_VCOLNUM_POS),
577 uint8_t deviceAddress = m + 1u;
579 deviceAddress, 20, 4u, MC33775_PRMM_APP_VC_CNT_OFFSET, primaryRawValues, n775_state);
581 deviceAddress, 4, 4u, MC33775_SECM_APP_AIN4_OFFSET, secondaryRawValues, n775_state);
583 retValSupplyCurrent =
592 primaryValues[c + 1u] = (int16_t)primaryRawValues[c + 1u];
595 (((
float)primaryValues[c + 1u]) * 154.0e-6f * 1000.0f);
600 for (uint8_t g = 0u; g < 4u; g++) {
603 primaryValues[g + 16u] = (int16_t)primaryRawValues[g + 16u];
606 (((
float)primaryValues[g + 16u]) * 154.0e-6f * 1000.0f);
614 primaryValues[15u] = (int16_t)primaryRawValues[15u];
616 (((float)primaryValues[15u]) * 2.58e-3f * 1000.0f);
624 for (uint8_t g = 4u; g < 8u; g++) {
626 secondaryValues[g - 4u] = (int16_t)secondaryRawValues[g - 4u];
629 (((
float)secondaryValues[g - 4u]) * 154.0e-6f * 1000.0f);
640 if (gpio03Error ==
false) {
652 if ((gpio03Error ==
false) && (gpio47Error ==
false)) {
670 currentValue = (int16_t)currentRawValue;
672 (((float)currentValue) * 7.69e-6f * 1000.0f);
697 uint16_t readValue = 0u;
698 uint8_t dataI2c = 0u;
701 uint16_t timeout = 0u;
726 MC33775_I2C_DATA0_OFFSET,
727 (addressI2c_write << MC33775_I2C_DATA0_BYTE0_POS) | (dataI2c << MC33775_I2C_DATA0_BYTE1_POS),
733 MC33775_I2C_DATA1_OFFSET,
734 (addressI2c_read << MC33775_I2C_DATA1_BYTE2_POS) | (
N775_I2C_DUMMY_BYTE << MC33775_I2C_DATA1_BYTE3_POS),
740 MC33775_I2C_CTRL_OFFSET,
742 ((MC33775_I2C_CTRL_STPAFTER_STOP_ENUM_VAL << MC33775_I2C_CTRL_STPAFTER_POS) +
755 }
while ((readValue & MC33775_I2C_STAT_PENDING_MSK) && (returnedValue ==
N775_COMMUNICATION_OK) && (timeout > 0u));
765 readValue = readValue >> MC33775_I2C_DATA1_BYTE3_POS;
769 if (readValue == dataI2c) {
805 MC33775_BAL_GLOB_TO_TMR_OFFSET,
816 MC33775_BAL_TMR_CH_ALL_OFFSET,
817 (MC33775_BAL_TMR_CH_ALL_PWM_PWM100_ENUM_VAL << MC33775_BAL_TMR_CH_ALL_PWM_POS) |
824 MC33775_BAL_GLOB_CFG_OFFSET,
825 (MC33775_BAL_GLOB_CFG_BALEN_ENABLED_ENUM_VAL << MC33775_BAL_GLOB_CFG_BALEN_POS) |
826 (MC33775_BAL_GLOB_CFG_TMRBALEN_STOP_ENUM_VAL << MC33775_BAL_GLOB_CFG_TMRBALEN_POS),
846 uint8_t deviceAddress = m + 1u;
847 uint16_t balancingState = 0u;
851 balancingState |= 1u << c;
Headers for the driver for the general DMA module of monitoring ICs.
#define BS_NR_OF_CELL_BLOCKS_PER_MODULE
number of cells per module
#define BS_NR_OF_STRINGS
Number of parallel strings in the battery pack.
#define BS_NR_OF_TEMP_SENSORS_PER_MODULE
number of temperature sensors per battery module
#define BS_NR_OF_GPIOS_PER_MODULE
Number of GPIOs on the LTC IC.
#define BS_NR_OF_CELL_BLOCKS_PER_STRING
#define BS_NR_OF_MODULES_PER_STRING
number of modules in a string
#define BS_NR_OF_TEMP_SENSORS_PER_STRING
#define DATA_READ_DATA(...)
#define DATA_WRITE_DATA(...)
@ DATA_BLOCK_ID_BALANCING_CONTROL
@ DATA_BLOCK_ID_CELL_TEMPERATURE_BASE
@ DATA_BLOCK_ID_OPEN_WIRE_BASE
@ DATA_BLOCK_ID_SLAVE_CONTROL
@ DATA_BLOCK_ID_CELL_VOLTAGE_BASE
@ DATA_BLOCK_ID_ALL_GPIO_VOLTAGES_BASE
@ DATA_BLOCK_ID_BALANCING_FEEDBACK_BASE
#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 for the driver for the IO module.
Headers for the driver for the MCU module.
N775_COMMUNICATION_STATUS_e N775_CommunicationReadMultiple(uint16_t deviceAddress, uint16_t numberOfItems, uint16_t responseLength, uint16_t registerAddress, uint16_t *pValues, N775_STATE_s *n775_state)
Read multiple values from specific registers in a specific device.
void N775_ResetMessageCounter(uint16_t deviceAddress, uint8_t string)
Reset the message counter for one or all devices.
void N775_CommunicationWrite(uint16_t deviceAddress, uint16_t registerAddress, uint16_t value, SPI_INTERFACE_CONFIG_s *pSpiInterface)
Write a value into a specific register in a specific device.
N775_COMMUNICATION_STATUS_e N775_CommunicationRead(uint16_t deviceAddress, uint16_t registerAddress, uint16_t *pValue, N775_STATE_s *n775_state)
Read a value from a specific register in a specific device.
enum N775_COMMUNICATION_STATUS N775_COMMUNICATION_STATUS_e
@ N775_COMMUNICATION_ERROR_WRONG_CRC
@ N775_COMMUNICATION_ERROR_TIMEOUT
static DATA_BLOCK_SLAVE_CONTROL_s n775_slaveControl
void TEST_N775_SetFirstMeasurementCycleFinished(N775_STATE_s *n775_state)
static N775_ERRORTABLE_s n775_errorTable
void N775_ErrorHandling(N775_STATE_s *n775_state, N775_COMMUNICATION_STATUS_e returnedValue, uint8_t module)
handles error when doing measurements.
uint16_t n775_CrcAddItem(uint16_t remainder, uint16_t item)
Called to calculate the CRC of a message.
void N775_Meas(N775_STATE_s *n775_state)
trigger function for the N775 driver state machine.
N775_STATE_s n775_stateBase
static DATA_BLOCK_ALL_GPIO_VOLTAGES_s n775_allGpioVoltage
STD_RETURN_TYPE_e N775_SetMuxChannel(N775_STATE_s *n775_state)
sets mux channel.
static DATA_BLOCK_MIN_MAX_s n775_minMax
static DATA_BLOCK_CELL_TEMPERATURE_s n775_cellTemperature
void N775_IncrementStringSequence(N775_STATE_s *n775_state)
updates index in string sequence.
uint16_t n775_CalcCrc(const N775_MESSAGE_s *msg)
Calculate the CRC of a message.
static void N775_SetFirstMeasurementCycleFinished(N775_STATE_s *n775_state)
sets the measurement initialization status.
void N775_StartMeasurement(N775_STATE_s *n775_state)
starts the measurement.
static DATA_BLOCK_CELL_VOLTAGE_s n775_cellVoltage
void N775_BalanceControl(N775_STATE_s *n775_state)
manages balancing.
void N775_ResetMuxIndex(N775_STATE_s *n775_state)
resets index in mux sequence.
void N775_IncrementMuxIndex(N775_STATE_s *n775_state)
updates index in mux sequence.
static DATA_BLOCK_BALANCING_CONTROL_s n775_balancingControl
void N775_BalanceSetup(N775_STATE_s *n775_state)
setups balancing.
void N775_I2cInit(N775_STATE_s *n775_state)
init I2C for the N775 slaves.
void N775_CaptureMeasurement(N775_STATE_s *n775_state)
captures the measurement.
static N775_SUPPLY_CURRENT_s n775_supplyCurrent
static DATA_BLOCK_OPEN_WIRE_s n775_openwire
void N775_Init(N775_STATE_s *n775_state)
initializes the N775 driver.
static void N775_InitializeDatabase(N775_STATE_s *n775_state)
in the database, initializes the fields related to the N775 driver.
void N775_ResetStringSequence(N775_STATE_s *n775_state)
reset index in string sequence.
static DATA_BLOCK_BALANCING_FEEDBACK_s n775_balancingFeedback
STD_RETURN_TYPE_e N775_Enumerate(N775_STATE_s *n775_state)
enumerates the N775 slaves.
void N775_waitTime(uint32_t milliseconds)
waits for a definite amount of time in ms.
bool N775_IsFirstMeasurementCycleFinished(N775_STATE_s *n775_state)
gets the measurement initialization status.
Headers for the driver for the MC33775A monitoring chip.
N775_MUX_CH_CFG_s n775_muxSequence[N775_MUX_SEQUENCE_LENGTH]
int16_t N775_ConvertVoltagesToTemperatures(uint16_t adcVoltage_mV)
converts a raw voltage from multiplexer to a temperature value in deci °C.
#define N775_I2C_NR_BYTES_FOR_MUX_WRITE
#define N775_I2C_NR_BYTES_TO_SWITCH_TO_READ_FOR_UX_READ
#define N775_MEASUREMENT_CAPTURE_TIME_MS
#define N775_INVALID_REGISTER_VALUE
#define N775_I2C_DUMMY_BYTE
#define N775_CHECK_SUPPLY_CURRENT
#define N775_TIMEOUT_SWITCH
#define N775_TIMEOUT_TO_SLEEP_10MS
#define N775_CHECK_MUX_STATE
#define N775_DEFAULT_CHAIN_ADDRESS
#define N775_MUXED_TEMP_GPIO_POSITION
#define N775_MEASUREMENT_READY_TIME_MS
#define N775_MUX_SEQUENCE_LENGTH
#define N775_FLAG_READY_TIMEOUT
#define N775_ADG728_ADDRESS_UPPERBITS
#define N775_BROADCAST_ADDRESS
#define N775_USE_MUX_FOR_TEMP
#define N775_PRE_BALANCING_TIMER
#define N775_BALPAUSELEN_10US
#define N775_GLOBAL_BALANCING_TIMER
#define N775_WAKEUP_TIME_MS
#define N775_TIME_AFTER_MEASUREMENT_START_MS
#define N775_ALL_CHANNEL_BALANCING_TIMER
Declaration of the OS wrapper interface.
void OS_DelayTaskUntil(uint32_t *pPreviousWakeTime, uint32_t milliseconds)
Delay a task until a specified time.
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.
Headers for the driver for the SPI module.
SPI_INTERFACE_CONFIG_s spi_nxp775InterfaceTx[BS_NR_OF_STRINGS]
SPI_INTERFACE_CONFIG_s spi_nxp775InterfaceRx[BS_NR_OF_STRINGS]
uint16_t gpioVoltages_mV[BS_NR_OF_STRINGS][BS_NR_OF_MODULES_PER_STRING *BS_NR_OF_GPIOS_PER_MODULE]
DATA_BLOCK_HEADER_s header
DATA_BLOCK_HEADER_s header
uint8_t balancingState[BS_NR_OF_STRINGS][BS_NR_OF_CELL_BLOCKS_PER_STRING]
DATA_BLOCK_HEADER_s header
DATA_BLOCK_HEADER_s header
int16_t cellTemperature_ddegC[BS_NR_OF_STRINGS][BS_NR_OF_TEMP_SENSORS_PER_STRING]
DATA_BLOCK_HEADER_s header
uint32_t moduleVoltage_mV[BS_NR_OF_STRINGS][BS_NR_OF_MODULES_PER_STRING]
int16_t cellVoltage_mV[BS_NR_OF_STRINGS][BS_NR_OF_CELL_BLOCKS_PER_STRING]
int16_t minimumTemperature_ddegC[BS_NR_OF_STRINGS]
uint16_t nrSensorMinimumTemperature[BS_NR_OF_STRINGS]
uint16_t nrModuleMinimumTemperature[BS_NR_OF_STRINGS]
uint16_t nrModuleMaximumTemperature[BS_NR_OF_STRINGS]
int16_t maximumTemperature_ddegC[BS_NR_OF_STRINGS]
uint16_t nrSensorMaximumTemperature[BS_NR_OF_STRINGS]
uint16_t nrCellMaximumCellVoltage[BS_NR_OF_STRINGS]
uint16_t nrCellMinimumCellVoltage[BS_NR_OF_STRINGS]
DATA_BLOCK_HEADER_s header
uint16_t nrModuleMinimumCellVoltage[BS_NR_OF_STRINGS]
uint16_t nrModuleMaximumCellVoltage[BS_NR_OF_STRINGS]
int16_t maximumCellVoltage_mV[BS_NR_OF_STRINGS]
int16_t minimumCellVoltage_mV[BS_NR_OF_STRINGS]
DATA_BLOCK_HEADER_s header
DATA_BLOCK_HEADER_s header
N775_ERRORTABLE_s * errorTable
DATA_BLOCK_BALANCING_CONTROL_s * balancingControl
uint64_t uid[BS_NR_OF_STRINGS][BS_NR_OF_MODULES_PER_STRING]
DATA_BLOCK_CELL_TEMPERATURE_s * cellTemperature
DATA_BLOCK_ALL_GPIO_VOLTAGES_s * allGpioVoltage
N775_SUPPLY_CURRENT_s * supplyCurrent
DATA_BLOCK_MIN_MAX_s * minMax
DATA_BLOCK_CELL_VOLTAGE_s * cellVoltage
bool mux3IsOK[BS_NR_OF_STRINGS][BS_NR_OF_MODULES_PER_STRING]
bool communicationOk[BS_NR_OF_STRINGS][BS_NR_OF_MODULES_PER_STRING]
bool noCommunicationTimeout[BS_NR_OF_STRINGS][BS_NR_OF_MODULES_PER_STRING]
bool mux2IsOK[BS_NR_OF_STRINGS][BS_NR_OF_MODULES_PER_STRING]
bool mux0IsOk[BS_NR_OF_STRINGS][BS_NR_OF_MODULES_PER_STRING]
bool mux1IsOK[BS_NR_OF_STRINGS][BS_NR_OF_MODULES_PER_STRING]
bool crcIsValid[BS_NR_OF_STRINGS][BS_NR_OF_MODULES_PER_STRING]
SPI_INTERFACE_CONFIG_s * pSpiRxSequenceStart
SPI_INTERFACE_CONFIG_s * pSpiTxSequenceStart
N775_MUX_CH_CFG_s * pMuxSequence[BS_NR_OF_STRINGS]
bool firstMeasurementMade
SPI_INTERFACE_CONFIG_s * pSpiTxSequence
SPI_INTERFACE_CONFIG_s * pSpiRxSequence
uint8_t currentMux[BS_NR_OF_STRINGS]
N775_MUX_CH_CFG_s * pMuxSequenceStart[BS_NR_OF_STRINGS]
uint16_t current[BS_NR_OF_STRINGS][BS_NR_OF_MODULES_PER_STRING]