61 #include "HL_system.h"
76 #define LTC_LTC6820CONTROL_GIODIR (hetREG1->DIR)
77 #define LTC_LTC6820CONTROL_GIOPORT (hetREG1->DOUT)
79 #define LTC_LTC6820_FORWARD_ENABLE_PIN (22U)
80 #define LTC_LTC6820_FORWARD_SPI1_MASTER_PIN (24U)
82 #define LTC_LTC6820_REVERSE_ENABLE_PIN (23U)
83 #define LTC_LTC6820_REVERSE_MASTER_PIN (25U)
90 #define LTC_PORT_EXPANDER_TI_INPUT_REG_ADR (0x00u)
91 #define LTC_PORT_EXPANDER_TI_OUTPUT_REG_ADR (0x01u)
92 #define LTC_PORT_EXPANDER_TI_CONFIG_REG_ADR (0x03u)
99 #define LTC_ICOM_START (0x60u)
100 #define LTC_ICOM_STOP (0x10u)
101 #define LTC_ICOM_BLANK (0x00u)
102 #define LTC_ICOM_NO_TRANSMIT (0x70u)
103 #define LTC_FCOM_MASTER_ACK (0x00u)
104 #define LTC_FCOM_MASTER_NACK (0x08u)
105 #define LTC_FCOM_MASTER_NACK_STOP (0x09u)
109 #define LTC_MAX_SUPPORTED_CELLS (12u)
116 #pragma SET_DATA_SECTION(".sharedRAM")
119 #pragma SET_DATA_SECTION()
142 .minimumPlausibleVoltage_mV = 0,
158 .numberOfMeasuredMux = 32,
160 .ErrRetryCounter = 0,
161 .ErrRequestCounter = 0,
162 .VoltageSampleTime = 0,
164 .commandDataTransferTime = 3,
165 .commandTransferTime = 3,
166 .gpioClocksTransferTime = 3,
170 .first_measurement_made =
false,
174 .transmit_ongoing =
false,
196 .requestedString = 0u,
231 {0x69, 0x18, 0x0F, 0xF0, 0x0F, 0xF9};
234 {0x64, 0x18, 0x0F, 0xF9, 0x7F, 0xF9};
238 {0x03, 0x60, 0xF4, 0x6C};
240 {0x03, 0x70, 0xAF, 0x42};
242 {0x03, 0xE0, 0xB0, 0x4A};
244 {0x03, 0xF0, 0xEB, 0x64};
246 {0x02, 0xE0, 0x38, 0x06};
248 {0x02, 0xF0, 0x63, 0x28};
250 {0x02, 0xE1, 0xb3, 0x34};
270 {0x05, 0xE0, 0x97, 0x86};
308 uint16_t timer_ms_ok,
310 uint8_t substate_nok,
311 uint16_t timer_ms_nok);
318 uint32_t frameLength,
320 uint8_t stringNumber);
327 uint32_t frameLength);
347 uint8_t stringNumber);
352 uint8_t stringNumber);
356 uint16_t *DataBufferSPI_RX_with_PEC,
357 uint8_t stringNumber);
363 uint32_t frameLength);
369 uint32_t frameLength);
376 uint32_t frameLength,
385 uint32_t frameLength,
392 uint32_t frameLength,
400 uint32_t frameLength);
408 uint32_t frameLength,
415 uint32_t frameLength);
421 uint32_t frameLength,
430 uint32_t frameLength,
439 uint8_t stringNumber);
458 for (uint8_t stringNumber = 0u; stringNumber <
BS_NR_OF_STRINGS; stringNumber++) {
532 ltc_state->
state = state;
534 ltc_state->
timer = timer_ms;
561 uint16_t timer_ms_ok,
563 uint8_t substate_nok,
564 uint16_t timer_ms_nok) {
586 int32_t stringVoltage_mV = 0;
587 uint16_t numberValidMeasurements = 0;
612 numberValidMeasurements++;
638 uint16_t numberValidMeasurements = 0;
654 numberValidMeasurements++;
690 for (uint16_t i = 0; i <
LTC_N_LTC; i++) {
691 const uint16_t val_i = DataBufferSPI_RX[8u + (1u * i * 8u)] |
692 (DataBufferSPI_RX[8u + (1u * i * 8u) + 1u] << 8u);
753 return ltc_state->
state;
807 uint8_t tmpbusID = 0;
820 if (ltc_state->
timer > 0u) {
821 if ((--ltc_state->
timer) > 0u) {
828 if (ltc_state->
timer > 0u) {
829 if ((--ltc_state->
timer) > 0u) {
837 if (continueFunction ==
STD_OK) {
838 switch (ltc_state->
state) {
849 ltc_state->
adcMode = tmpadcMode;
2948 uint8_t stringNumber) {
2949 uint16_t val_ui = 0;
2950 int16_t temperature_ddegC = 0;
2951 uint8_t sensor_idx = 0;
2953 uint16_t buffer_LSB = 0;
2954 uint16_t buffer_MSB = 0;
2958 if (muxseqptr->
muxCh != 0xFF) {
2960 if ((muxseqptr->
muxID == 1) || (muxseqptr->
muxID == 2)) {
2961 for (uint16_t i = 0; i <
LTC_N_LTC; i++) {
2962 if (muxseqptr->
muxID == 1) {
2963 ch_idx = 0 + muxseqptr->
muxCh;
2965 ch_idx = 8 + muxseqptr->
muxCh;
2968 if (ch_idx < (2u * 8u)) {
2969 val_ui = *((uint16_t *)(&pRxBuff[6u + (1u * i * 8u)]));
2975 for (uint16_t i = 0; i <
LTC_N_LTC; i++) {
2976 buffer_MSB = pRxBuff[4u + (i * 8u) + 1u];
2977 buffer_LSB = pRxBuff[4u + (i * 8u)];
2978 val_ui = buffer_LSB | (buffer_MSB << 8);
2994 (~(1u << sensor_idx));
3026 uint8_t registerSet,
3027 uint8_t stringNumber) {
3028 uint16_t cellOffset = 0;
3029 uint16_t voltage_index = 0;
3030 uint16_t val_ui = 0;
3031 uint16_t voltage = 0;
3032 uint32_t bitmask = 0;
3033 uint16_t buffer_LSB = 0;
3034 uint16_t buffer_MSB = 0;
3035 bool continueFunction =
true;
3037 if (registerSet == 0u) {
3040 }
else if (registerSet == 1u) {
3043 }
else if (registerSet == 2u) {
3046 }
else if (registerSet == 3u) {
3049 }
else if (registerSet == 4u) {
3052 }
else if (registerSet == 5u) {
3056 continueFunction =
false;
3059 if (continueFunction ==
true) {
3061 bitmask |= 0x07u << cellOffset;
3064 if (cellOffset == 0u) {
3069 for (uint16_t m = 0u; m <
LTC_N_LTC; m++) {
3070 uint16_t incrementations = 0u;
3073 for (uint8_t c = 0u; c < 3u; c++) {
3075 voltage_index = c + cellOffset;
3078 buffer_MSB = pRxBuff[4u + (2u * c) + (m * 8u) + 1u];
3079 buffer_LSB = pRxBuff[4u + (2u * c) + (m * 8u)];
3080 val_ui = buffer_LSB | (buffer_MSB << 8u);
3082 voltage = ((val_ui)) * 100e-6f * 1000.0f;
3136 uint8_t registerSet,
3137 uint8_t stringNumber) {
3138 uint8_t i_offset = 0;
3139 uint32_t bitmask = 0;
3140 uint16_t buffer_LSB = 0;
3141 uint16_t buffer_MSB = 0;
3143 if (registerSet == 0u) {
3146 bitmask = 0x07u << i_offset;
3148 for (uint16_t i = 0; i <
LTC_N_LTC; i++) {
3154 buffer_MSB = pRxBuff[4u + (i * 8u) + 1u];
3155 buffer_LSB = pRxBuff[4u + (i * 8u)];
3158 ((buffer_LSB | (buffer_MSB << 8u))) / 10u;
3160 buffer_MSB = pRxBuff[6u + (i * 8u) + 1u];
3161 buffer_LSB = pRxBuff[6u + (i * 8u)];
3164 ((buffer_LSB | (buffer_MSB << 8u))) / 10u;
3166 buffer_MSB = pRxBuff[8u + (i * 8u) + 1u];
3167 buffer_LSB = pRxBuff[8u + (i * 8u)];
3170 ((buffer_LSB | (buffer_MSB << 8u))) / 10u;
3176 }
else if (registerSet == 1u) {
3179 bitmask = 0x03u << i_offset;
3181 for (uint16_t i = 0; i <
LTC_N_LTC; i++) {
3187 buffer_MSB = pRxBuff[4u + (i * 8u) + 1u];
3188 buffer_LSB = pRxBuff[4u + (i * 8u)];
3191 ((buffer_LSB | (buffer_MSB << 8u))) / 10u;
3193 buffer_MSB = pRxBuff[6u + (i * 8u) + 1u];
3194 buffer_LSB = pRxBuff[6u + (i * 8u)];
3197 ((buffer_LSB | (buffer_MSB << 8u))) / 10u;
3203 }
else if (registerSet == 2u) {
3206 bitmask = 0x07u << i_offset;
3208 for (uint16_t i = 0; i <
LTC_N_LTC; i++) {
3214 buffer_MSB = pRxBuff[4u + (i * 8u) + 1u];
3215 buffer_LSB = pRxBuff[4u + (i * 8u)];
3218 ((buffer_LSB | (buffer_MSB << 8u))) / 10u;
3220 buffer_MSB = pRxBuff[6u + (i * 8u) + 1u];
3221 buffer_LSB = pRxBuff[6u + (i * 8u)];
3224 ((buffer_LSB | (buffer_MSB << 8u))) / 10u;
3226 buffer_MSB = pRxBuff[8u + (i * 8u) + 1u];
3227 buffer_LSB = pRxBuff[8u + (i * 8u)];
3230 ((buffer_LSB | (buffer_MSB << 8u))) / 10u;
3236 }
else if (registerSet == 3u) {
3239 bitmask = 0x01u << i_offset;
3241 for (uint16_t i = 0; i <
LTC_N_LTC; i++) {
3249 *((uint16_t *)(&pRxBuff[4u + (i * 8u)])) / 10u;
3335 uint32_t frameLength) {
3338 uint8_t PEC_Check[6];
3339 uint16_t PEC_result = 0;
3349 for (uint16_t i = 0u; i <
LTC_N_LTC; i++) {
3351 pTxBuff[4u + (i * 8u)] = 0xFC;
3352 pTxBuff[5u + (i * 8u)] = 0x00;
3353 pTxBuff[6u + (i * 8u)] = 0x00;
3354 pTxBuff[7u + (i * 8u)] = 0x00;
3355 pTxBuff[8u + (i * 8u)] = 0x00;
3356 pTxBuff[9u + (i * 8u)] = 0x00;
3358 PEC_Check[0] = pTxBuff[4u + (i * 8u)];
3359 PEC_Check[1] = pTxBuff[5u + (i * 8u)];
3360 PEC_Check[2] = pTxBuff[6u + (i * 8u)];
3361 PEC_Check[3] = pTxBuff[7u + (i * 8u)];
3362 PEC_Check[4] = pTxBuff[8u + (i * 8u)];
3363 PEC_Check[5] = pTxBuff[9u + (i * 8u)];
3365 PEC_result = LTC_pec15_calc(6, PEC_Check);
3366 pTxBuff[10u + (i * 8u)] = (PEC_result >> 8u) & 0xFFu;
3367 pTxBuff[11u + (i * 8u)] = PEC_result & 0xFFu;
3397 uint32_t frameLength,
3398 uint8_t registerSet,
3399 uint8_t stringNumber) {
3402 uint8_t PEC_Check[6];
3403 uint16_t PEC_result = 0;
3407 if (registerSet == 0u) {
3416 pTxBuff[4u + (i * 8u)] = 0xFC;
3417 pTxBuff[5u + (i * 8u)] = 0x00;
3418 pTxBuff[6u + (i * 8u)] = 0x00;
3419 pTxBuff[7u + (i * 8u)] = 0x00;
3420 pTxBuff[8u + (i * 8u)] = 0x00;
3421 pTxBuff[9u + (i * 8u)] = 0x00;
3425 pTxBuff[8u + (i * 8u)] |= 0x01u;
3429 pTxBuff[8u + (i * 8u)] |= 0x02u;
3433 pTxBuff[8u + (i * 8u)] |= 0x04u;
3437 pTxBuff[8u + (i * 8u)] |= 0x08u;
3441 pTxBuff[8u + (i * 8u)] |= 0x10u;
3445 pTxBuff[8u + (i * 8u)] |= 0x20u;
3449 pTxBuff[8u + (i * 8u)] |= 0x40u;
3453 pTxBuff[8u + (i * 8u)] |= 0x80u;
3457 pTxBuff[9u + (i * 8u)] |= 0x01u;
3461 pTxBuff[9u + (i * 8u)] |= 0x02u;
3465 pTxBuff[9u + (i * 8u)] |= 0x04u;
3469 pTxBuff[9u + (i * 8u)] |= 0x08u;
3472 PEC_Check[0] = pTxBuff[4u + (i * 8u)];
3473 PEC_Check[1] = pTxBuff[5u + (i * 8u)];
3474 PEC_Check[2] = pTxBuff[6u + (i * 8u)];
3475 PEC_Check[3] = pTxBuff[7u + (i * 8u)];
3476 PEC_Check[4] = pTxBuff[8u + (i * 8u)];
3477 PEC_Check[5] = pTxBuff[9u + (i * 8u)];
3479 PEC_result = LTC_pec15_calc(6, PEC_Check);
3480 pTxBuff[10u + (i * 8u)] = (PEC_result >> 8u) & 0xFFu;
3481 pTxBuff[11u + (i * 8u)] = PEC_result & 0xFFu;
3484 }
else if (registerSet == 1u) {
3493 pTxBuff[4u + (i * 8u)] = 0x0F;
3494 pTxBuff[5u + (i * 8u)] = 0x00;
3495 pTxBuff[6u + (i * 8u)] = 0x00;
3496 pTxBuff[7u + (i * 8u)] = 0x00;
3497 pTxBuff[8u + (i * 8u)] = 0x00;
3498 pTxBuff[9u + (i * 8u)] = 0x00;
3502 pTxBuff[4u + (i * 8u)] |= 0x10u;
3506 pTxBuff[4u + (i * 8u)] |= 0x20u;
3510 pTxBuff[4u + (i * 8u)] |= 0x40u;
3515 pTxBuff[4u + (i * 8u)] |= 0x80u;
3519 pTxBuff[5u + (i * 8u)] |= 0x01u;
3523 pTxBuff[5u + (i * 8u)] |= 0x02u;
3527 PEC_Check[0] = pTxBuff[4u + (i * 8u)];
3528 PEC_Check[1] = pTxBuff[5u + (i * 8u)];
3529 PEC_Check[2] = pTxBuff[6u + (i * 8u)];
3530 PEC_Check[3] = pTxBuff[7u + (i * 8u)];
3531 PEC_Check[4] = pTxBuff[8u + (i * 8u)];
3532 PEC_Check[5] = pTxBuff[9u + (i * 8u)];
3534 PEC_result = LTC_pec15_calc(6, PEC_Check);
3535 pTxBuff[10u + (i * 8u)] = (PEC_result >> 8u) & 0xFFu;
3536 pTxBuff[11u + (i * 8u)] = PEC_result & 0xFFu;
3554 for (uint8_t stringNumber = 0u; stringNumber <
BS_NR_OF_STRINGS; stringNumber++) {
3555 for (uint16_t i = 0; i <
LTC_N_LTC; i++) {
3747 }
else if (PUP == 1u) {
3777 uint16_t *DataBufferSPI_RX_with_PEC,
3778 uint8_t stringNumber) {
3781 uint16_t PEC_result = 0;
3782 uint8_t PEC_Check[6] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
3785 for (uint16_t i = 0; i <
LTC_N_LTC; i++) {
3786 PEC_Check[0] = DataBufferSPI_RX_with_PEC[4u + (i * 8u)];
3787 PEC_Check[1] = DataBufferSPI_RX_with_PEC[5u + (i * 8u)];
3788 PEC_Check[2] = DataBufferSPI_RX_with_PEC[6u + (i * 8u)];
3789 PEC_Check[3] = DataBufferSPI_RX_with_PEC[7u + (i * 8u)];
3790 PEC_Check[4] = DataBufferSPI_RX_with_PEC[8u + (i * 8u)];
3791 PEC_Check[5] = DataBufferSPI_RX_with_PEC[9u + (i * 8u)];
3793 PEC_result = LTC_pec15_calc(6, PEC_Check);
3794 PEC_TX[0] = (uint8_t)((PEC_result >> 8u) & 0xFFu);
3795 PEC_TX[1] = (uint8_t)(PEC_result & 0xFFu);
3798 if ((PEC_TX[0] != DataBufferSPI_RX_with_PEC[10u + (i * 8u)]) ||
3799 (PEC_TX[1] != DataBufferSPI_RX_with_PEC[11u + (i * 8u)])) {
3842 uint32_t frameLength) {
3853 pTxBuff[0] = Command[0];
3854 pTxBuff[1] = Command[1];
3855 pTxBuff[2] = Command[2];
3856 pTxBuff[3] = Command[3];
3891 uint32_t frameLength) {
3894 uint16_t PEC_result = 0;
3895 uint8_t PEC_Check[6] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
3897 pTxBuff[0] = Command[0];
3898 pTxBuff[1] = Command[1];
3899 pTxBuff[2] = Command[2];
3900 pTxBuff[3] = Command[3];
3903 for (uint16_t i = 0u; i <
LTC_N_LTC; i++) {
3904 PEC_Check[0] = pTxBuff[4u + (i * 8u)];
3905 PEC_Check[1] = pTxBuff[5u + (i * 8u)];
3906 PEC_Check[2] = pTxBuff[6u + (i * 8u)];
3907 PEC_Check[3] = pTxBuff[7u + (i * 8u)];
3908 PEC_Check[4] = pTxBuff[8u + (i * 8u)];
3909 PEC_Check[5] = pTxBuff[9u + (i * 8u)];
3911 PEC_result = LTC_pec15_calc(6, PEC_Check);
3912 pTxBuff[10u + (i * 8u)] = (PEC_result >> 8u) & 0xFFu;
3913 pTxBuff[11u + (i * 8u)] = PEC_result & 0xFFu;
3933 for (uint16_t i = 0; i <
LTC_N_LTC; i++) {
3934 #if SLAVE_BOARD_VERSION == 2u
3937 uint8_t address = 0x98u | ((mux % 4u) << 1u);
3938 uint8_t data = 1u << (channel % 8u);
3939 if (channel == 0xFFu) {
3946 uint8_t address = 0x90u | ((mux % 4u) << 1u);
3947 uint8_t data = 0x08u | (channel % 8u);
3948 if (channel == 0xFFu) {
3954 pTxBuff[4u + (i * 8u)] =
LTC_ICOM_START | ((address >> 4u) & 0x0Fu);
3956 pTxBuff[6u + (i * 8u)] =
LTC_ICOM_BLANK | ((data >> 4u) & 0x0Fu);
3959 pTxBuff[9u + (i * 8u)] = 0x00;
3981 uint32_t frameLength,
4005 address &= 0x3FFFFu;
4006 const uint8_t address0 = address >> 16u;
4007 const uint8_t address1 = (address & 0xFFFFu) >> 8u;
4008 const uint8_t address2 = address & 0xFFu;
4011 for (uint16_t i = 0; i <
LTC_N_LTC; i++) {
4021 for (uint16_t i = 0; i <
LTC_N_LTC; i++) {
4042 for (uint16_t i = 0; i <
LTC_N_LTC; i++) {
4044 ((pRxBuff[7u + (i * 8u)] >> 4u));
4071 uint32_t frameLength,
4095 address &= 0x3FFFFu;
4096 const uint8_t address0 = address >> 16u;
4097 const uint8_t address1 = (address & 0xFFFFu) >> 8u;
4098 const uint8_t address2 = address & 0xFFu;
4101 for (uint16_t i = 0; i <
LTC_N_LTC; i++) {
4111 for (uint16_t i = 0; i <
LTC_N_LTC; i++) {
4148 uint32_t frameLength,
4177 uint32_t frameLength,
4178 uint16_t *cmd_data) {
4182 pTxBuff[4u + (i * 6u)] = cmd_data[0];
4183 pTxBuff[5u + (i * 6u)] = cmd_data[1];
4185 pTxBuff[6u + (i * 6u)] = cmd_data[2];
4186 pTxBuff[7u + (i * 6u)] = cmd_data[3];
4188 pTxBuff[8u + (i * 6u)] = cmd_data[4];
4189 pTxBuff[9u + (i * 6u)] = cmd_data[5];
4210 for (uint16_t i = 0; i <
LTC_N_LTC; i++) {
4211 uint8_t temp_tmp[2];
4212 temp_tmp[0] = (pRxBuff[6u + (i * 8u)] << 4u) | ((pRxBuff[7u + (i * 8u)] >> 4u));
4213 temp_tmp[1] = (pRxBuff[8u + (i * 8u)] << 4u) | ((pRxBuff[9u + (i * 8u)] >> 4u));
4214 uint16_t val_i = (temp_tmp[0] << 8u) | (temp_tmp[1]);
4215 val_i = val_i >> 8u;
4240 uint32_t frameLength) {
4250 pTxBuff[5u + (i * 8u)] =
4253 pTxBuff[6u + (i * 8u)] =
4255 (output_data >> 4u);
4256 pTxBuff[7u + (i * 8u)] =
4257 (uint8_t)(output_data << 4u) |
4261 pTxBuff[9u + (i * 8u)] = 0;
4283 for (uint16_t i = 0; i <
LTC_N_LTC; i++) {
4284 const uint8_t val_i = (pRxBuff[6u + (i * 8u)] << 4u) | ((pRxBuff[7u + (i * 8u)] >> 4u));
4310 uint32_t frameLength,
4328 pTxBuff[9u + (i * 8u)] = (uint8_t)(direction << 4u) |
4356 uint32_t frameLength) {
4374 pTxBuff[9u + (i * 8u)] = (uint8_t)(output_data << 4u) |
4403 uint32_t frameLength,
4419 pTxBuff[9u + (i * 8u)] = 0;
4434 pTxBuff[9u + (i * 8u)] = 0;
4454 for (uint16_t i = 0; i <
LTC_N_LTC; i++) {
4455 const uint8_t val_i = (pTxBuff[6u + (i * 8u)] << 4u) | ((pTxBuff[7u + (i * 8u)] >> 4u));
4475 uint16_t ltc_TXBufferClock[4u + 9u];
4477 for (uint16_t i = 0; i < (4u + 9u); i++) {
4478 ltc_TXBufferClock[i] = 0xFF;
4501 uint32_t SPI_Clock = 0;
4502 uint32_t prescaler = 0;
4527 prescaler = ((pSpiInterface->
pNode->FMT0) >> 8u) & 0xFFu;
4528 SPI_Clock = (uint32_t)(AVCLK1_FREQ * 1000000u) / (prescaler + 1u);
4542 uint32_t transferTime_us = 0;
4543 uint32_t SPI_Clock = 0;
4549 transferTime_us = (8u * 1000u * 1000u) / (SPI_Clock);
4556 transferTime_us = ((4u) * 8u * 1000u * 1000u) / (SPI_Clock);
4562 transferTime_us = ((4u + 9u) * 8u * 1000u * 1000u) / (SPI_Clock);
4601 bool retval =
false;