62 #include "HL_system.h"
78 #define LTC_PORT_EXPANDER_TI_INPUT_REG_ADR (0x00u)
79 #define LTC_PORT_EXPANDER_TI_OUTPUT_REG_ADR (0x01u)
80 #define LTC_PORT_EXPANDER_TI_CONFIG_REG_ADR (0x03u)
87 #define LTC_ICOM_START (0x60u)
88 #define LTC_ICOM_STOP (0x10u)
89 #define LTC_ICOM_BLANK (0x00u)
90 #define LTC_ICOM_NO_TRANSMIT (0x70u)
91 #define LTC_FCOM_MASTER_ACK (0x00u)
92 #define LTC_FCOM_MASTER_NACK (0x08u)
93 #define LTC_FCOM_MASTER_NACK_STOP (0x09u)
97 #define LTC_MAX_SUPPORTED_CELLS (12u)
105 #pragma SET_DATA_SECTION(".sharedRAM")
108 #pragma SET_DATA_SECTION()
132 .minimumPlausibleVoltage_mV = 0,
148 .numberOfMeasuredMux = 32,
150 .ErrRetryCounter = 0,
151 .ErrRequestCounter = 0,
152 .VoltageSampleTime = 0,
154 .commandDataTransferTime = 3,
155 .commandTransferTime = 3,
156 .gpioClocksTransferTime = 3,
159 .muxmeas_nr_end = {0},
160 .first_measurement_made =
false,
164 .transmit_ongoing =
false,
186 .requestedString = 0u,
221 {0x69, 0x18, 0x0F, 0xF0, 0x0F, 0xF9};
224 {0x64, 0x18, 0x0F, 0xF9, 0x7F, 0xF9};
228 {0x03, 0x60, 0xF4, 0x6C};
230 {0x03, 0x70, 0xAF, 0x42};
232 {0x03, 0xE0, 0xB0, 0x4A};
234 {0x03, 0xF0, 0xEB, 0x64};
236 {0x02, 0xE0, 0x38, 0x06};
238 {0x02, 0xF0, 0x63, 0x28};
240 {0x02, 0xE1, 0xb3, 0x34};
260 {0x05, 0xE0, 0x97, 0x86};
298 uint16_t timer_ms_ok,
300 uint8_t substate_nok,
301 uint16_t timer_ms_nok);
308 uint32_t frameLength,
310 uint8_t stringNumber);
317 uint32_t frameLength);
337 uint8_t stringNumber);
342 uint8_t stringNumber);
346 uint16_t *DataBufferSPI_RX_with_PEC,
347 uint8_t stringNumber);
353 uint32_t frameLength);
359 uint32_t frameLength);
366 uint32_t frameLength,
375 uint32_t frameLength,
382 uint32_t frameLength,
390 uint32_t frameLength);
398 uint32_t frameLength,
405 uint32_t frameLength);
411 uint32_t frameLength,
420 uint32_t frameLength,
429 uint8_t stringNumber);
522 ltc_state->
state = state;
524 ltc_state->
timer = timer_ms;
551 uint16_t timer_ms_ok,
553 uint8_t substate_nok,
554 uint16_t timer_ms_nok) {
576 int32_t stringVoltage_mV = 0;
577 uint16_t numberValidMeasurements = 0;
602 numberValidMeasurements++;
628 uint16_t numberValidMeasurements = 0;
644 numberValidMeasurements++;
680 for (uint16_t i = 0; i <
LTC_N_LTC; i++) {
681 const uint16_t val_i = DataBufferSPI_RX[8u + (1u * i * 8u)] |
682 (DataBufferSPI_RX[8u + (1u * i * 8u) + 1u] << 8u);
743 return ltc_state->
state;
797 uint8_t tmpbusID = 0;
810 if (ltc_state->
timer > 0u) {
811 if ((--ltc_state->
timer) > 0u) {
818 if (ltc_state->
timer > 0u) {
819 if ((--ltc_state->
timer) > 0u) {
827 if (continueFunction ==
STD_OK) {
828 switch (ltc_state->
state) {
839 ltc_state->
adcMode = tmpadcMode;
2946 uint8_t stringNumber) {
2947 uint16_t val_ui = 0;
2948 int16_t temperature_ddegC = 0;
2949 uint8_t sensor_idx = 0;
2951 uint16_t buffer_LSB = 0;
2952 uint16_t buffer_MSB = 0;
2956 if (muxseqptr->
muxCh != 0xFF) {
2958 if ((muxseqptr->
muxID == 1) || (muxseqptr->
muxID == 2)) {
2959 for (uint16_t i = 0; i <
LTC_N_LTC; i++) {
2960 if (muxseqptr->
muxID == 1) {
2961 ch_idx = 0 + muxseqptr->
muxCh;
2963 ch_idx = 8 + muxseqptr->
muxCh;
2966 if (ch_idx < (2u * 8u)) {
2967 val_ui = *((uint16_t *)(&pRxBuff[6u + (1u * i * 8u)]));
2973 for (uint16_t i = 0; i <
LTC_N_LTC; i++) {
2974 buffer_MSB = pRxBuff[4u + (i * 8u) + 1u];
2975 buffer_LSB = pRxBuff[4u + (i * 8u)];
2976 val_ui = buffer_LSB | (buffer_MSB << 8);
2992 (~(1u << sensor_idx));
3024 uint8_t registerSet,
3025 uint8_t stringNumber) {
3026 uint16_t cellOffset = 0;
3027 uint16_t voltage_index = 0;
3028 uint16_t val_ui = 0;
3029 uint16_t voltage = 0;
3030 uint32_t bitmask = 0;
3031 uint16_t buffer_LSB = 0;
3032 uint16_t buffer_MSB = 0;
3033 bool continueFunction =
true;
3035 if (registerSet == 0u) {
3038 }
else if (registerSet == 1u) {
3041 }
else if (registerSet == 2u) {
3044 }
else if (registerSet == 3u) {
3047 }
else if (registerSet == 4u) {
3050 }
else if (registerSet == 5u) {
3054 continueFunction =
false;
3057 if (continueFunction ==
true) {
3059 bitmask |= 0x07u << cellOffset;
3062 if (cellOffset == 0u) {
3067 for (uint16_t m = 0u; m <
LTC_N_LTC; m++) {
3068 uint16_t incrementations = 0u;
3071 for (uint8_t c = 0u; c < 3u; c++) {
3073 voltage_index = c + cellOffset;
3076 buffer_MSB = pRxBuff[4u + (2u * c) + (m * 8u) + 1u];
3077 buffer_LSB = pRxBuff[4u + (2u * c) + (m * 8u)];
3078 val_ui = buffer_LSB | (buffer_MSB << 8u);
3080 voltage = ((val_ui)) * 100e-6f * 1000.0f;
3134 uint8_t registerSet,
3135 uint8_t stringNumber) {
3136 uint8_t i_offset = 0;
3137 uint32_t bitmask = 0;
3138 uint16_t buffer_LSB = 0;
3139 uint16_t buffer_MSB = 0;
3141 if (registerSet == 0u) {
3144 bitmask = 0x07u << i_offset;
3146 for (uint16_t i = 0; i <
LTC_N_LTC; i++) {
3152 buffer_MSB = pRxBuff[4u + (i * 8u) + 1u];
3153 buffer_LSB = pRxBuff[4u + (i * 8u)];
3156 ((buffer_LSB | (buffer_MSB << 8u))) / 10u;
3158 buffer_MSB = pRxBuff[6u + (i * 8u) + 1u];
3159 buffer_LSB = pRxBuff[6u + (i * 8u)];
3162 ((buffer_LSB | (buffer_MSB << 8u))) / 10u;
3164 buffer_MSB = pRxBuff[8u + (i * 8u) + 1u];
3165 buffer_LSB = pRxBuff[8u + (i * 8u)];
3168 ((buffer_LSB | (buffer_MSB << 8u))) / 10u;
3174 }
else if (registerSet == 1u) {
3177 bitmask = 0x03u << i_offset;
3179 for (uint16_t i = 0; i <
LTC_N_LTC; i++) {
3185 buffer_MSB = pRxBuff[4u + (i * 8u) + 1u];
3186 buffer_LSB = pRxBuff[4u + (i * 8u)];
3189 ((buffer_LSB | (buffer_MSB << 8u))) / 10u;
3191 buffer_MSB = pRxBuff[6u + (i * 8u) + 1u];
3192 buffer_LSB = pRxBuff[6u + (i * 8u)];
3195 ((buffer_LSB | (buffer_MSB << 8u))) / 10u;
3201 }
else if (registerSet == 2u) {
3204 bitmask = 0x07u << i_offset;
3206 for (uint16_t i = 0; i <
LTC_N_LTC; i++) {
3212 buffer_MSB = pRxBuff[4u + (i * 8u) + 1u];
3213 buffer_LSB = pRxBuff[4u + (i * 8u)];
3216 ((buffer_LSB | (buffer_MSB << 8u))) / 10u;
3218 buffer_MSB = pRxBuff[6u + (i * 8u) + 1u];
3219 buffer_LSB = pRxBuff[6u + (i * 8u)];
3222 ((buffer_LSB | (buffer_MSB << 8u))) / 10u;
3224 buffer_MSB = pRxBuff[8u + (i * 8u) + 1u];
3225 buffer_LSB = pRxBuff[8u + (i * 8u)];
3228 ((buffer_LSB | (buffer_MSB << 8u))) / 10u;
3234 }
else if (registerSet == 3u) {
3237 bitmask = 0x01u << i_offset;
3239 for (uint16_t i = 0; i <
LTC_N_LTC; i++) {
3247 *((uint16_t *)(&pRxBuff[4u + (i * 8u)])) / 10u;
3333 uint32_t frameLength) {
3336 uint8_t PEC_Check[6];
3337 uint16_t PEC_result = 0;
3347 for (uint16_t i = 0u; i <
LTC_N_LTC; i++) {
3349 pTxBuff[4u + (i * 8u)] = 0xFC;
3350 pTxBuff[5u + (i * 8u)] = 0x00;
3351 pTxBuff[6u + (i * 8u)] = 0x00;
3352 pTxBuff[7u + (i * 8u)] = 0x00;
3353 pTxBuff[8u + (i * 8u)] = 0x00;
3354 pTxBuff[9u + (i * 8u)] = 0x00;
3356 PEC_Check[0] = pTxBuff[4u + (i * 8u)];
3357 PEC_Check[1] = pTxBuff[5u + (i * 8u)];
3358 PEC_Check[2] = pTxBuff[6u + (i * 8u)];
3359 PEC_Check[3] = pTxBuff[7u + (i * 8u)];
3360 PEC_Check[4] = pTxBuff[8u + (i * 8u)];
3361 PEC_Check[5] = pTxBuff[9u + (i * 8u)];
3363 PEC_result = LTC_pec15_calc(6, PEC_Check);
3364 pTxBuff[10u + (i * 8u)] = (PEC_result >> 8u) & 0xFFu;
3365 pTxBuff[11u + (i * 8u)] = PEC_result & 0xFFu;
3395 uint32_t frameLength,
3396 uint8_t registerSet,
3397 uint8_t stringNumber) {
3400 uint8_t PEC_Check[6];
3401 uint16_t PEC_result = 0;
3405 if (registerSet == 0u) {
3417 pTxBuff[4u + (reverseModuleNumber * 8u)] = 0xFC;
3418 pTxBuff[5u + (reverseModuleNumber * 8u)] = 0x00;
3419 pTxBuff[6u + (reverseModuleNumber * 8u)] = 0x00;
3420 pTxBuff[7u + (reverseModuleNumber * 8u)] = 0x00;
3421 pTxBuff[8u + (reverseModuleNumber * 8u)] = 0x00;
3422 pTxBuff[9u + (reverseModuleNumber * 8u)] = 0x00;
3426 pTxBuff[8u + (reverseModuleNumber * 8u)] |= 0x01u;
3430 pTxBuff[8u + (reverseModuleNumber * 8u)] |= 0x02u;
3434 pTxBuff[8u + (reverseModuleNumber * 8u)] |= 0x04u;
3438 pTxBuff[8u + (reverseModuleNumber * 8u)] |= 0x08u;
3442 pTxBuff[8u + (reverseModuleNumber * 8u)] |= 0x10u;
3446 pTxBuff[8u + (reverseModuleNumber * 8u)] |= 0x20u;
3450 pTxBuff[8u + (reverseModuleNumber * 8u)] |= 0x40u;
3454 pTxBuff[8u + (reverseModuleNumber * 8u)] |= 0x80u;
3458 pTxBuff[9u + (reverseModuleNumber * 8u)] |= 0x01u;
3462 pTxBuff[9u + (reverseModuleNumber * 8u)] |= 0x02u;
3466 pTxBuff[9u + (reverseModuleNumber * 8u)] |= 0x04u;
3470 pTxBuff[9u + (reverseModuleNumber * 8u)] |= 0x08u;
3473 PEC_Check[0] = pTxBuff[4u + (reverseModuleNumber * 8u)];
3474 PEC_Check[1] = pTxBuff[5u + (reverseModuleNumber * 8u)];
3475 PEC_Check[2] = pTxBuff[6u + (reverseModuleNumber * 8u)];
3476 PEC_Check[3] = pTxBuff[7u + (reverseModuleNumber * 8u)];
3477 PEC_Check[4] = pTxBuff[8u + (reverseModuleNumber * 8u)];
3478 PEC_Check[5] = pTxBuff[9u + (reverseModuleNumber * 8u)];
3480 PEC_result = LTC_pec15_calc(6, PEC_Check);
3481 pTxBuff[10u + (reverseModuleNumber * 8u)] = (PEC_result >> 8u) & 0xFFu;
3482 pTxBuff[11u + (reverseModuleNumber * 8u)] = PEC_result & 0xFFu;
3485 }
else if (registerSet == 1u) {
3497 pTxBuff[4u + (reverseModuleNumber * 8u)] = 0x0F;
3498 pTxBuff[5u + (reverseModuleNumber * 8u)] = 0x00;
3499 pTxBuff[6u + (reverseModuleNumber * 8u)] = 0x00;
3500 pTxBuff[7u + (reverseModuleNumber * 8u)] = 0x00;
3501 pTxBuff[8u + (reverseModuleNumber * 8u)] = 0x00;
3502 pTxBuff[9u + (reverseModuleNumber * 8u)] = 0x00;
3506 pTxBuff[4u + (reverseModuleNumber * 8u)] |= 0x10u;
3510 pTxBuff[4u + (reverseModuleNumber * 8u)] |= 0x20u;
3514 pTxBuff[4u + (reverseModuleNumber * 8u)] |= 0x40u;
3519 pTxBuff[4u + (reverseModuleNumber * 8u)] |= 0x80u;
3523 pTxBuff[5u + (reverseModuleNumber * 8u)] |= 0x01u;
3527 pTxBuff[5u + (reverseModuleNumber * 8u)] |= 0x02u;
3531 PEC_Check[0] = pTxBuff[4u + (reverseModuleNumber * 8u)];
3532 PEC_Check[1] = pTxBuff[5u + (reverseModuleNumber * 8u)];
3533 PEC_Check[2] = pTxBuff[6u + (reverseModuleNumber * 8u)];
3534 PEC_Check[3] = pTxBuff[7u + (reverseModuleNumber * 8u)];
3535 PEC_Check[4] = pTxBuff[8u + (reverseModuleNumber * 8u)];
3536 PEC_Check[5] = pTxBuff[9u + (reverseModuleNumber * 8u)];
3538 PEC_result = LTC_pec15_calc(6, PEC_Check);
3539 pTxBuff[10u + (reverseModuleNumber * 8u)] = (PEC_result >> 8u) & 0xFFu;
3540 pTxBuff[11u + (reverseModuleNumber * 8u)] = PEC_result & 0xFFu;
3559 for (uint16_t i = 0; i <
LTC_N_LTC; i++) {
3767 }
else if (PUP == 1u) {
3797 uint16_t *DataBufferSPI_RX_with_PEC,
3798 uint8_t stringNumber) {
3801 uint16_t PEC_result = 0;
3802 uint8_t PEC_Check[6] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
3805 for (uint16_t i = 0; i <
LTC_N_LTC; i++) {
3806 PEC_Check[0] = DataBufferSPI_RX_with_PEC[4u + (i * 8u)];
3807 PEC_Check[1] = DataBufferSPI_RX_with_PEC[5u + (i * 8u)];
3808 PEC_Check[2] = DataBufferSPI_RX_with_PEC[6u + (i * 8u)];
3809 PEC_Check[3] = DataBufferSPI_RX_with_PEC[7u + (i * 8u)];
3810 PEC_Check[4] = DataBufferSPI_RX_with_PEC[8u + (i * 8u)];
3811 PEC_Check[5] = DataBufferSPI_RX_with_PEC[9u + (i * 8u)];
3813 PEC_result = LTC_pec15_calc(6, PEC_Check);
3814 PEC_TX[0] = (uint8_t)((PEC_result >> 8u) & 0xFFu);
3815 PEC_TX[1] = (uint8_t)(PEC_result & 0xFFu);
3818 if ((PEC_TX[0] != DataBufferSPI_RX_with_PEC[10u + (i * 8u)]) ||
3819 (PEC_TX[1] != DataBufferSPI_RX_with_PEC[11u + (i * 8u)])) {
3862 uint32_t frameLength) {
3873 pTxBuff[0] = Command[0];
3874 pTxBuff[1] = Command[1];
3875 pTxBuff[2] = Command[2];
3876 pTxBuff[3] = Command[3];
3911 uint32_t frameLength) {
3914 uint16_t PEC_result = 0;
3915 uint8_t PEC_Check[6] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
3917 pTxBuff[0] = Command[0];
3918 pTxBuff[1] = Command[1];
3919 pTxBuff[2] = Command[2];
3920 pTxBuff[3] = Command[3];
3923 for (uint16_t i = 0u; i <
LTC_N_LTC; i++) {
3924 PEC_Check[0] = pTxBuff[4u + (i * 8u)];
3925 PEC_Check[1] = pTxBuff[5u + (i * 8u)];
3926 PEC_Check[2] = pTxBuff[6u + (i * 8u)];
3927 PEC_Check[3] = pTxBuff[7u + (i * 8u)];
3928 PEC_Check[4] = pTxBuff[8u + (i * 8u)];
3929 PEC_Check[5] = pTxBuff[9u + (i * 8u)];
3931 PEC_result = LTC_pec15_calc(6, PEC_Check);
3932 pTxBuff[10u + (i * 8u)] = (PEC_result >> 8u) & 0xFFu;
3933 pTxBuff[11u + (i * 8u)] = PEC_result & 0xFFu;
3953 for (uint16_t i = 0; i <
LTC_N_LTC; i++) {
3954 #if SLAVE_BOARD_VERSION == 2u
3957 uint8_t address = 0x98u | ((mux % 4u) << 1u);
3958 uint8_t data = 1u << (channel % 8u);
3959 if (channel == 0xFFu) {
3966 uint8_t address = 0x90u | ((mux % 4u) << 1u);
3967 uint8_t data = 0x08u | (channel % 8u);
3968 if (channel == 0xFFu) {
3974 pTxBuff[4u + (i * 8u)] =
LTC_ICOM_START | ((address >> 4u) & 0x0Fu);
3976 pTxBuff[6u + (i * 8u)] =
LTC_ICOM_BLANK | ((data >> 4u) & 0x0Fu);
3979 pTxBuff[9u + (i * 8u)] = 0x00;
4001 uint32_t frameLength,
4025 address &= 0x3FFFFu;
4026 const uint8_t address0 = address >> 16u;
4027 const uint8_t address1 = (address & 0xFFFFu) >> 8u;
4028 const uint8_t address2 = address & 0xFFu;
4031 for (uint16_t i = 0; i <
LTC_N_LTC; i++) {
4041 for (uint16_t i = 0; i <
LTC_N_LTC; i++) {
4062 for (uint16_t i = 0; i <
LTC_N_LTC; i++) {
4064 ((pRxBuff[7u + (i * 8u)] >> 4u));
4091 uint32_t frameLength,
4115 address &= 0x3FFFFu;
4116 const uint8_t address0 = address >> 16u;
4117 const uint8_t address1 = (address & 0xFFFFu) >> 8u;
4118 const uint8_t address2 = address & 0xFFu;
4121 for (uint16_t i = 0; i <
LTC_N_LTC; i++) {
4131 for (uint16_t i = 0; i <
LTC_N_LTC; i++) {
4168 uint32_t frameLength,
4197 uint32_t frameLength,
4198 uint16_t *cmd_data) {
4202 pTxBuff[4u + (i * 6u)] = cmd_data[0];
4203 pTxBuff[5u + (i * 6u)] = cmd_data[1];
4205 pTxBuff[6u + (i * 6u)] = cmd_data[2];
4206 pTxBuff[7u + (i * 6u)] = cmd_data[3];
4208 pTxBuff[8u + (i * 6u)] = cmd_data[4];
4209 pTxBuff[9u + (i * 6u)] = cmd_data[5];
4230 for (uint16_t i = 0; i <
LTC_N_LTC; i++) {
4231 uint8_t temp_tmp[2];
4232 temp_tmp[0] = (pRxBuff[6u + (i * 8u)] << 4u) | ((pRxBuff[7u + (i * 8u)] >> 4u));
4233 temp_tmp[1] = (pRxBuff[8u + (i * 8u)] << 4u) | ((pRxBuff[9u + (i * 8u)] >> 4u));
4234 uint16_t val_i = (temp_tmp[0] << 8u) | (temp_tmp[1]);
4235 val_i = val_i >> 8u;
4260 uint32_t frameLength) {
4270 pTxBuff[5u + (i * 8u)] =
4273 pTxBuff[6u + (i * 8u)] =
4275 (output_data >> 4u);
4276 pTxBuff[7u + (i * 8u)] =
4277 (uint8_t)(output_data << 4u) |
4281 pTxBuff[9u + (i * 8u)] = 0;
4303 for (uint16_t i = 0; i <
LTC_N_LTC; i++) {
4304 const uint8_t val_i = (pRxBuff[6u + (i * 8u)] << 4u) | ((pRxBuff[7u + (i * 8u)] >> 4u));
4330 uint32_t frameLength,
4348 pTxBuff[9u + (i * 8u)] = (uint8_t)(direction << 4u) |
4376 uint32_t frameLength) {
4394 pTxBuff[9u + (i * 8u)] = (uint8_t)(output_data << 4u) |
4423 uint32_t frameLength,
4439 pTxBuff[9u + (i * 8u)] = 0;
4454 pTxBuff[9u + (i * 8u)] = 0;
4474 for (uint16_t i = 0; i <
LTC_N_LTC; i++) {
4475 const uint8_t val_i = (pTxBuff[6u + (i * 8u)] << 4u) | ((pTxBuff[7u + (i * 8u)] >> 4u));
4495 uint16_t ltc_TXBufferClock[4u + 9u];
4497 for (uint16_t i = 0; i < (4u + 9u); i++) {
4498 ltc_TXBufferClock[i] = 0xFF;
4521 uint32_t SPI_Clock = 0;
4522 uint32_t prescaler = 0;
4547 prescaler = ((pSpiInterface->
pNode->FMT0) >> 8u) & 0xFFu;
4548 SPI_Clock = (uint32_t)(AVCLK1_FREQ * 1000000u) / (prescaler + 1u);
4562 uint32_t transferTime_us = 0;
4563 uint32_t SPI_Clock = 0;
4569 transferTime_us = (8u * 1000u * 1000u) / (SPI_Clock);
4576 transferTime_us = ((4u) * 8u * 1000u * 1000u) / (SPI_Clock);
4582 transferTime_us = ((4u + 9u) * 8u * 1000u * 1000u) / (SPI_Clock);