@@ -263,47 +263,47 @@ void FEB_Main_Setup(void)
263263
264264 LOG_I (TAG_MAIN , "Beginning Setup" );
265265
266- // I2C scan for debugging
267- FEB_Console_Printf ("Starting I2C Scanning: \r\n" );
268- for (uint8_t i = 1 ; i < 128 ; i ++ )
269- {
270- HAL_StatusTypeDef ret = HAL_I2C_IsDeviceReady (& hi2c1 , (uint16_t )(i << 1 ), 3 , 5 );
271- if (ret == HAL_OK )
272- {
273- FEB_Console_Printf ("0x%X " , i );
274- }
275- else
276- {
277- FEB_Console_Printf ("- " );
278- }
279- }
280- FEB_Console_Printf ("Done! \r\n\r\n" );
281-
282- // Initialize TPS devices. One attempt per chip; failures are logged and skipped.
283- tps_init_success = FEB_TPS_Init_Devices ();
284- if (tps_init_success )
285- {
286- LOG_I (TAG_MAIN , "TPS2482 I2C init complete" );
287-
288- // Start with all rails disabled (LV has no EN pin and is skipped).
289- for (uint8_t i = 0 ; i < NUM_TPS2482 ; i ++ )
290- {
291- if (tps_handles [i ] != NULL && tps_device_configs [i ].en_port != NULL )
292- {
293- FEB_TPS_Enable (tps_handles [i ], false);
294- }
295- }
296- FEB_TPS_Check_Power_Good ();
297-
298- LOG_I (TAG_MAIN , "TPS2482 power rails configured" );
299- }
300- else
301- {
302- LOG_E (TAG_MAIN , "TPS2482 init failed - all chips unreachable, skipping power rail config" );
303- }
304-
305- // Initialize brake light to be off
306- HAL_GPIO_WritePin (BL_Switch_GPIO_Port , BL_Switch_Pin , GPIO_PIN_RESET );
266+ // // I2C scan for debugging
267+ // FEB_Console_Printf("Starting I2C Scanning: \r\n");
268+ // for (uint8_t i = 1; i < 128; i++)
269+ // {
270+ // HAL_StatusTypeDef ret = HAL_I2C_IsDeviceReady(&hi2c1, (uint16_t)(i << 1), 3, 5);
271+ // if (ret == HAL_OK)
272+ // {
273+ // FEB_Console_Printf("0x%X ", i);
274+ // }
275+ // else
276+ // {
277+ // FEB_Console_Printf("- ");
278+ // }
279+ // }
280+ // FEB_Console_Printf("Done! \r\n\r\n");
281+
282+ // // Initialize TPS devices. One attempt per chip; failures are logged and skipped.
283+ // tps_init_success = FEB_TPS_Init_Devices();
284+ // if (tps_init_success)
285+ // {
286+ // LOG_I(TAG_MAIN, "TPS2482 I2C init complete");
287+
288+ // // Start with all rails disabled (LV has no EN pin and is skipped).
289+ // for (uint8_t i = 0; i < NUM_TPS2482; i++)
290+ // {
291+ // if (tps_handles[i] != NULL && tps_device_configs[i].en_port != NULL)
292+ // {
293+ // FEB_TPS_Enable(tps_handles[i], false);
294+ // }
295+ // }
296+ // FEB_TPS_Check_Power_Good();
297+
298+ // LOG_I(TAG_MAIN, "TPS2482 power rails configured");
299+ // }
300+ // else
301+ // {
302+ // LOG_E(TAG_MAIN, "TPS2482 init failed - all chips unreachable, skipping power rail config");
303+ // }
304+
305+ // // Initialize brake light to be off
306+ // HAL_GPIO_WritePin(BL_Switch_GPIO_Port, BL_Switch_Pin, GPIO_PIN_RESET);
307307
308308 // Initialize CAN library
309309 FEB_CAN_Config_t can_cfg = {
@@ -337,60 +337,61 @@ void FEB_Main_Loop(void)
337337 static uint32_t last_poll_tick = 0 ;
338338 uint32_t now = HAL_GetTick ();
339339
340- if (tps_init_success && (uint32_t )(now - last_poll_tick ) >= MAIN_LOOP_POLL_INTERVAL_MS )
341- {
342- last_poll_tick = now ;
343-
344- uint8_t polled = 0 ;
345- for (uint8_t i = 0 ; i < NUM_TPS2482 ; i ++ )
346- {
347- if (tps_handles [i ] == NULL )
348- {
349- tps2482_bus_voltage_raw [i ] = 0 ;
350- tps2482_current_raw [i ] = 0 ;
351- tps2482_shunt_voltage_raw [i ] = 0 ;
352- continue ;
353- }
354- uint16_t bv ;
355- int16_t cur ;
356- int16_t sv ;
357- if (FEB_TPS_PollRaw (tps_handles [i ], & bv , & cur , & sv ) == FEB_TPS_OK )
358- {
359- tps2482_bus_voltage_raw [i ] = bv ;
360- tps2482_current_raw [i ] = cur ;
361- tps2482_shunt_voltage_raw [i ] = sv ;
362- tps_polled_success [i ] = true;
363- polled ++ ;
364- }
365- else
366- {
367- tps2482_bus_voltage_raw [i ] = 0 ;
368- tps2482_current_raw [i ] = 0 ;
369- tps2482_shunt_voltage_raw [i ] = 0 ;
370- tps_polled_success [i ] = false;
371- }
372- }
373- if (polled < tps_registered_count )
374- {
375- LOG_W (TAG_MAIN , "TPS poll: %u/%u registered devices succeeded" , (unsigned )polled , (unsigned )tps_registered_count );
376- }
377-
378- FEB_Variable_Conversion ();
379- }
380-
381- if (FEB_CAN_DASH_IsDataFresh (250 ))
382- {
383- DASH_State_t dash_state = FEB_CAN_DASH_GetLastState ();
384-
385- // Device handles (in order: LV, SH, LT, BM_L, SM, AF1_AF2, CP_RF)
386- FEB_TPS_Enable (tps_handles [5 ], dash_state .switch1 ); // AF1_AF2
387- FEB_TPS_Enable (tps_handles [6 ], dash_state .switch2 ); // CP_RF
388- }
389-
390- // FEB_TPS_Enable(tps_handles[3], true); // BM_L
391-
392- bool brake_on = FEB_CAN_BRAKE_IsDataFresh (250 ) && (FEB_CAN_BRAKE_GetPercent () > 10 );
393- HAL_GPIO_WritePin (BL_Switch_GPIO_Port , BL_Switch_Pin , brake_on ? GPIO_PIN_SET : GPIO_PIN_RESET );
340+ // if (tps_init_success && (uint32_t)(now - last_poll_tick) >= MAIN_LOOP_POLL_INTERVAL_MS)
341+ // {
342+ // last_poll_tick = now;
343+
344+ // uint8_t polled = 0;
345+ // for (uint8_t i = 0; i < NUM_TPS2482; i++)
346+ // {
347+ // if (tps_handles[i] == NULL)
348+ // {
349+ // tps2482_bus_voltage_raw[i] = 0;
350+ // tps2482_current_raw[i] = 0;
351+ // tps2482_shunt_voltage_raw[i] = 0;
352+ // continue;
353+ // }
354+ // uint16_t bv;
355+ // int16_t cur;
356+ // int16_t sv;
357+ // if (FEB_TPS_PollRaw(tps_handles[i], &bv, &cur, &sv) == FEB_TPS_OK)
358+ // {
359+ // tps2482_bus_voltage_raw[i] = bv;
360+ // tps2482_current_raw[i] = cur;
361+ // tps2482_shunt_voltage_raw[i] = sv;
362+ // tps_polled_success[i] = true;
363+ // polled++;
364+ // }
365+ // else
366+ // {
367+ // tps2482_bus_voltage_raw[i] = 0;
368+ // tps2482_current_raw[i] = 0;
369+ // tps2482_shunt_voltage_raw[i] = 0;
370+ // tps_polled_success[i] = false;
371+ // }
372+ // }
373+ // if (polled < tps_registered_count)
374+ // {
375+ // LOG_W(TAG_MAIN, "TPS poll: %u/%u registered devices succeeded", (unsigned)polled,
376+ // (unsigned)tps_registered_count);
377+ // }
378+
379+ // FEB_Variable_Conversion();
380+ // }
381+
382+ // if (FEB_CAN_DASH_IsDataFresh(250))
383+ // {
384+ // DASH_State_t dash_state = FEB_CAN_DASH_GetLastState();
385+
386+ // // Device handles (in order: LV, SH, LT, BM_L, SM, AF1_AF2, CP_RF)
387+ // FEB_TPS_Enable(tps_handles[5], dash_state.switch1); // AF1_AF2
388+ // FEB_TPS_Enable(tps_handles[6], dash_state.switch2); // CP_RF
389+ // }
390+
391+ // // FEB_TPS_Enable(tps_handles[3], true); // BM_L
392+
393+ // bool brake_on = FEB_CAN_BRAKE_IsDataFresh(250) && (FEB_CAN_BRAKE_GetPercent() > 10);
394+ // HAL_GPIO_WritePin(BL_Switch_GPIO_Port, BL_Switch_Pin, brake_on ? GPIO_PIN_SET : GPIO_PIN_RESET);
394395
395396 FEB_UART_ProcessRx (FEB_UART_INSTANCE_1 );
396397}
@@ -413,53 +414,53 @@ void FEB_1ms_Callback(void)
413414 FEB_CAN_PingPong_Tick ();
414415 }
415416
416- // Process CAN TPS reading every 100ms
417- static uint16_t tps_divider = 0 ;
418- tps_divider ++ ;
419- if (tps_divider >= 99 )
420- {
421- tps_divider = 0 ;
422- if (tps_init_success )
423- {
424- FEB_Variable_Conversion ();
425- FEB_CAN_TPS_Tick (tps2482_current , tps2482_bus_voltage , NUM_TPS2482 );
426- }
427- }
428-
429- static uint16_t heartbeat_divider = 0 ;
430- heartbeat_divider ++ ;
431- if (heartbeat_divider >=
432- 67 ) // not 100ms to offset message from other two statuses (ran into issue where mailbox got full)
433- {
434- heartbeat_divider = 0 ;
435-
436- lvpdb_heartbeat_msg .tps_init_failed = !tps_init_success ;
437-
438- lvpdb_heartbeat_msg .tps_lv_poll_failed = !tps_polled_success [0 ];
439- lvpdb_heartbeat_msg .tps_sh_poll_failed = !tps_polled_success [1 ];
440- lvpdb_heartbeat_msg .tps_lt_poll_failed = !tps_polled_success [2 ];
441- lvpdb_heartbeat_msg .tps_bm_l_poll_failed = !tps_polled_success [3 ];
442- lvpdb_heartbeat_msg .tps_sm_poll_failed = !tps_polled_success [4 ];
443- lvpdb_heartbeat_msg .tps_af1_af2_poll_failed = !tps_polled_success [5 ];
444- lvpdb_heartbeat_msg .tps_cp_rf_poll_failed = !tps_polled_success [6 ];
445-
446- lvpdb_heartbeat_msg .tps_lv_power_not_good = !tps_power_good [0 ];
447- lvpdb_heartbeat_msg .tps_sh_power_not_good = !tps_power_good [1 ];
448- lvpdb_heartbeat_msg .tps_lt_power_not_good = !tps_power_good [2 ];
449- lvpdb_heartbeat_msg .tps_bm_l_power_not_good = !tps_power_good [3 ];
450- lvpdb_heartbeat_msg .tps_sm_power_not_good = !tps_power_good [4 ];
451- lvpdb_heartbeat_msg .tps_af1_af2_power_not_good = !tps_power_good [5 ];
452- lvpdb_heartbeat_msg .tps_cp_rf_power_not_good = !tps_power_good [6 ];
453-
454- lvpdb_heartbeat_msg .dash_state_stale = !FEB_CAN_DASH_IsDataFresh (250 );
455-
456- uint8_t tx_data [FEB_CAN_LVPDB_HEARTBEAT_LENGTH ];
457- memset (tx_data , 0x00 , sizeof (tx_data ));
458- feb_can_lvpdb_heartbeat_pack (tx_data , & lvpdb_heartbeat_msg , sizeof (tx_data ));
459-
460- FEB_CAN_TX_Send (FEB_CAN_INSTANCE_1 , FEB_CAN_LVPDB_HEARTBEAT_FRAME_ID , FEB_CAN_ID_STD , tx_data ,
461- FEB_CAN_LVPDB_HEARTBEAT_LENGTH );
462- }
417+ // // Process CAN TPS reading every 100ms
418+ // static uint16_t tps_divider = 0;
419+ // tps_divider++;
420+ // if (tps_divider >= 99)
421+ // {
422+ // tps_divider = 0;
423+ // if (tps_init_success)
424+ // {
425+ // FEB_Variable_Conversion();
426+ // FEB_CAN_TPS_Tick(tps2482_current, tps2482_bus_voltage, NUM_TPS2482);
427+ // }
428+ // }
429+
430+ // static uint16_t heartbeat_divider = 0;
431+ // heartbeat_divider++;
432+ // if (heartbeat_divider >=
433+ // 67) // not 100ms to offset message from other two statuses (ran into issue where mailbox got full)
434+ // {
435+ // heartbeat_divider = 0;
436+
437+ // lvpdb_heartbeat_msg.tps_init_failed = !tps_init_success;
438+
439+ // lvpdb_heartbeat_msg.tps_lv_poll_failed = !tps_polled_success[0];
440+ // lvpdb_heartbeat_msg.tps_sh_poll_failed = !tps_polled_success[1];
441+ // lvpdb_heartbeat_msg.tps_lt_poll_failed = !tps_polled_success[2];
442+ // lvpdb_heartbeat_msg.tps_bm_l_poll_failed = !tps_polled_success[3];
443+ // lvpdb_heartbeat_msg.tps_sm_poll_failed = !tps_polled_success[4];
444+ // lvpdb_heartbeat_msg.tps_af1_af2_poll_failed = !tps_polled_success[5];
445+ // lvpdb_heartbeat_msg.tps_cp_rf_poll_failed = !tps_polled_success[6];
446+
447+ // lvpdb_heartbeat_msg.tps_lv_power_not_good = !tps_power_good[0];
448+ // lvpdb_heartbeat_msg.tps_sh_power_not_good = !tps_power_good[1];
449+ // lvpdb_heartbeat_msg.tps_lt_power_not_good = !tps_power_good[2];
450+ // lvpdb_heartbeat_msg.tps_bm_l_power_not_good = !tps_power_good[3];
451+ // lvpdb_heartbeat_msg.tps_sm_power_not_good = !tps_power_good[4];
452+ // lvpdb_heartbeat_msg.tps_af1_af2_power_not_good = !tps_power_good[5];
453+ // lvpdb_heartbeat_msg.tps_cp_rf_power_not_good = !tps_power_good[6];
454+
455+ // lvpdb_heartbeat_msg.dash_state_stale = !FEB_CAN_DASH_IsDataFresh(250);
456+
457+ // uint8_t tx_data[FEB_CAN_LVPDB_HEARTBEAT_LENGTH];
458+ // memset(tx_data, 0x00, sizeof(tx_data));
459+ // feb_can_lvpdb_heartbeat_pack(tx_data, &lvpdb_heartbeat_msg, sizeof(tx_data));
460+
461+ // FEB_CAN_TX_Send(FEB_CAN_INSTANCE_1, FEB_CAN_LVPDB_HEARTBEAT_FRAME_ID, FEB_CAN_ID_STD, tx_data,
462+ // FEB_CAN_LVPDB_HEARTBEAT_LENGTH);
463+ // }
463464}
464465
465466/* ============================================================================
0 commit comments