Skip to content

Commit

Permalink
chore: first release v0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
federico-carbone committed Jun 27, 2023
1 parent c8a4982 commit 5465f5b
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 28 deletions.
1 change: 1 addition & 0 deletions Core/Inc/L9963E_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ void L9963E_utils_read_cells(uint8_t read_gpio);
uint16_t const* L9963E_utils_get_gpios(uint8_t *len);
uint16_t const* L9963E_utils_get_cells(uint8_t *len);
float L9963E_utils_get_cell_v(uint8_t index);
float L9963E_utils_get_batt_v(void);

#endif // L9963E_UTILS_H
29 changes: 15 additions & 14 deletions Core/Src/can_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,23 +67,24 @@ void can_send_msg(uint32_t id) {
switch (id)
{
case SC22_EVO_CANLV_BMSLV_TEMP_FRAME_ID:
msgs.bmslv_temp.ntc_is_first_message=1,
msgs.bmslv_temp.ntc1_resistance = sc22_evo_canlv_bmslv_temp_ntc1_resistance_encode(ntc_get_ext_resistance(0)),
msgs.bmslv_temp.ntc2_resistance = sc22_evo_canlv_bmslv_temp_ntc2_resistance_encode(ntc_get_ext_resistance(1)),
msgs.bmslv_temp.ntc3_resistance = sc22_evo_canlv_bmslv_temp_ntc3_resistance_encode(ntc_get_ext_resistance(2)),
msgs.bmslv_temp.ntc4_resistance = sc22_evo_canlv_bmslv_temp_ntc4_resistance_encode(ntc_get_ext_resistance(3)),
msgs.bmslv_temp.ntc5_resistance = sc22_evo_canlv_bmslv_temp_ntc5_resistance_encode(ntc_get_ext_resistance(4)),
msgs.bmslv_temp.ntc6_resistance = sc22_evo_canlv_bmslv_temp_ntc6_resistance_encode(ntc_get_ext_resistance(5)),
msgs.bmslv_temp.ntc_is_first_message = 1;
msgs.bmslv_temp.ntc1_resistance = sc22_evo_canlv_bmslv_temp_ntc1_resistance_encode(ntc_get_ext_resistance(0));
msgs.bmslv_temp.ntc2_resistance = sc22_evo_canlv_bmslv_temp_ntc2_resistance_encode(ntc_get_ext_resistance(1));
msgs.bmslv_temp.ntc3_resistance = sc22_evo_canlv_bmslv_temp_ntc3_resistance_encode(ntc_get_ext_resistance(2));
msgs.bmslv_temp.ntc4_resistance = sc22_evo_canlv_bmslv_temp_ntc4_resistance_encode(ntc_get_ext_resistance(3));
msgs.bmslv_temp.ntc5_resistance = sc22_evo_canlv_bmslv_temp_ntc5_resistance_encode(ntc_get_ext_resistance(4));
msgs.bmslv_temp.ntc6_resistance = sc22_evo_canlv_bmslv_temp_ntc6_resistance_encode(ntc_get_ext_resistance(5));

tx_header.DLC = sc22_evo_canlv_bmslv_temp_pack(buffer, &msgs.bmslv_temp, SC22_EVO_CANLV_BMSLV_TEMP_LENGTH);
can_send(&hcan1, buffer, &tx_header);

msgs.bmslv_temp.ntc_is_first_message=0,
msgs.bmslv_temp.ntc1_resistance = sc22_evo_canlv_bmslv_temp_ntc1_resistance_encode(ntc_get_ext_resistance(6)),
msgs.bmslv_temp.ntc2_resistance = sc22_evo_canlv_bmslv_temp_ntc2_resistance_encode(ntc_get_int_resistance(0)),
msgs.bmslv_temp.ntc3_resistance = sc22_evo_canlv_bmslv_temp_ntc3_resistance_encode(ntc_get_int_resistance(1)),
msgs.bmslv_temp.ntc4_resistance = sc22_evo_canlv_bmslv_temp_ntc4_resistance_encode(ntc_get_int_resistance(2)),
msgs.bmslv_temp.ntc5_resistance = sc22_evo_canlv_bmslv_temp_ntc5_resistance_encode(ntc_get_int_resistance(3)),
msgs.bmslv_temp.ntc6_resistance = sc22_evo_canlv_bmslv_temp_ntc6_resistance_encode(ntc_get_int_resistance(4)),
msgs.bmslv_temp.ntc_is_first_message = 0;
msgs.bmslv_temp.ntc1_resistance = sc22_evo_canlv_bmslv_temp_ntc1_resistance_encode(ntc_get_ext_resistance(6));
msgs.bmslv_temp.ntc2_resistance = sc22_evo_canlv_bmslv_temp_ntc2_resistance_encode(ntc_get_int_resistance(0));
msgs.bmslv_temp.ntc3_resistance = sc22_evo_canlv_bmslv_temp_ntc3_resistance_encode(ntc_get_int_resistance(1));
msgs.bmslv_temp.ntc4_resistance = sc22_evo_canlv_bmslv_temp_ntc4_resistance_encode(ntc_get_int_resistance(2));
msgs.bmslv_temp.ntc5_resistance = sc22_evo_canlv_bmslv_temp_ntc5_resistance_encode(ntc_get_int_resistance(3));
msgs.bmslv_temp.ntc6_resistance = sc22_evo_canlv_bmslv_temp_ntc6_resistance_encode(ntc_get_int_resistance(4));

tx_header.DLC = sc22_evo_canlv_bmslv_temp_pack(buffer, &msgs.bmslv_temp, SC22_EVO_CANLV_BMSLV_TEMP_LENGTH);
can_send(&hcan1, buffer, &tx_header);
Expand Down
8 changes: 0 additions & 8 deletions Core/Src/data_reading_timebase.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,6 @@

TIMEBASE_HandleTypeDef data_reading_timebase_handle;

STMLIBS_StatusTypeDef data_reading_lem_cb(void) {
// logger_log(LOGGER_INFO, "curr: %f", lem_get_current_ampere());
// logger_log(LOGGER_INFO, "ohm1: %f", ntc_get_int_resistance(0));
// logger_log(LOGGER_INFO, "ohm2: %f", ntc_get_ext_resistance(4));
return STMLIBS_OK;
}

STMLIBS_StatusTypeDef data_reading_l9963e_cb(void) {
uint16_t const *cells;
uint8_t cells_n;
Expand Down Expand Up @@ -65,7 +58,6 @@ void data_reading_timebase_init(void) {

TIMEBASE_add_interval(&data_reading_timebase_handle, 1000, &interval);
TIMEBASE_register_callback(&data_reading_timebase_handle, interval, data_reading_l9963e_cb);
TIMEBASE_register_callback(&data_reading_timebase_handle, interval, data_reading_lem_cb);
}

void data_reading_timebase_routine(void) {
Expand Down
3 changes: 3 additions & 0 deletions Core/Src/errors.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,17 @@ void global_toggle_cb(uint8_t error_index, uint8_t instance_index) {
logger_log(LOGGER_DEBUG, "global_toggle, error_index: %d, instance: %d", error_index, instance_index);
}
void undervoltage_exp_cb(uint8_t error_index, uint8_t instance_index) {
logger_log(LOGGER_ERROR, "undervoltage on cell %d", instance_index);
}
void undervoltage_toggle_cb(uint8_t error_index, uint8_t instance_index) {
}
void overvoltage_exp_cb(uint8_t error_index, uint8_t instance_index) {
logger_log(LOGGER_ERROR, "overvoltage on cell %d", instance_index);
}
void overvoltage_toggle_cb(uint8_t error_index, uint8_t instance_index) {
}
void overtemp_exp_cb(uint8_t error_index, uint8_t instance_index) {
logger_log(LOGGER_ERROR, "overtemp on temp %d", instance_index);
}
void overtemp_toggle_cb(uint8_t error_index, uint8_t instance_index) {
}
Expand Down
36 changes: 30 additions & 6 deletions Core/Src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ int main(void)
HAL_GPIO_WritePin(LV_CMD_GPIO_OUT_GPIO_Port, LV_CMD_GPIO_OUT_Pin, GPIO_PIN_SET);

L9963E_utils_init();

float battery_v;
HAL_GPIO_WritePin(LED_ERR_GPIO_OUT_GPIO_Port, LED_ERR_GPIO_OUT_Pin, GPIO_PIN_SET);
/* USER CODE END 2 */

/* Infinite loop */
Expand All @@ -137,12 +140,33 @@ int main(void)
data_reading_timebase_routine();
can_send_timebase_routine();

HAL_GPIO_TogglePin(LED_STAT1_GPIO_OUT_GPIO_Port, LED_STAT1_GPIO_OUT_Pin);
HAL_GPIO_TogglePin(LED_STAT2_GPIO_OUT_GPIO_Port, LED_STAT2_GPIO_OUT_Pin);
HAL_GPIO_TogglePin(LED_STAT3_GPIO_OUT_GPIO_Port, LED_STAT3_GPIO_OUT_Pin);
HAL_GPIO_TogglePin(LED_WARN_GPIO_OUT_GPIO_Port, LED_WARN_GPIO_OUT_Pin);
HAL_GPIO_TogglePin(LED_ERR_GPIO_OUT_GPIO_Port, LED_ERR_GPIO_OUT_Pin);

battery_v = L9963E_utils_get_batt_v();

if(battery_v > 21.56) {
HAL_GPIO_WritePin(LED_WARN_GPIO_OUT_GPIO_Port, LED_WARN_GPIO_OUT_Pin, GPIO_PIN_SET);
} else {
HAL_GPIO_WritePin(LED_WARN_GPIO_OUT_GPIO_Port, LED_WARN_GPIO_OUT_Pin, GPIO_PIN_RESET);
}

if(battery_v > 23.52) {
HAL_GPIO_WritePin(LED_STAT3_GPIO_OUT_GPIO_Port, LED_STAT3_GPIO_OUT_Pin, GPIO_PIN_SET);
} else {
HAL_GPIO_WritePin(LED_STAT3_GPIO_OUT_GPIO_Port, LED_STAT3_GPIO_OUT_Pin, GPIO_PIN_RESET);
}

if(battery_v > 25.48) {
HAL_GPIO_WritePin(LED_STAT2_GPIO_OUT_GPIO_Port, LED_STAT2_GPIO_OUT_Pin, GPIO_PIN_SET);
} else {
HAL_GPIO_WritePin(LED_STAT2_GPIO_OUT_GPIO_Port, LED_STAT2_GPIO_OUT_Pin, GPIO_PIN_RESET);
}

if(battery_v > 27.44) {
HAL_GPIO_WritePin(LED_STAT1_GPIO_OUT_GPIO_Port, LED_STAT1_GPIO_OUT_Pin, GPIO_PIN_SET);
} else {
HAL_GPIO_WritePin(LED_STAT1_GPIO_OUT_GPIO_Port, LED_STAT1_GPIO_OUT_Pin, GPIO_PIN_RESET);
}

logger_log(LOGGER_INFO, "battery_v: %f", battery_v);
logger_routine();

// HAL_Delay(500);
Expand Down

0 comments on commit 5465f5b

Please sign in to comment.