Skip to content

Commit

Permalink
optimize apply_speed_limit()
Browse files Browse the repository at this point in the history
  • Loading branch information
dzid26 committed Jul 11, 2024
1 parent 08878fb commit b700ed3
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions src/ebike_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -1444,16 +1444,18 @@ static void apply_temperature_limiting(void)
}


static void apply_speed_limit(void)
{
if (m_configuration_variables.ui8_wheel_speed_max) {
// set battery current target
ui8_adc_battery_current_target = map_ui16((uint16_t) ui16_wheel_speed_x10,
(uint16_t) (((uint8_t)(m_configuration_variables.ui8_wheel_speed_max) * (uint8_t)10U) - (uint8_t)20U),
(uint16_t) (((uint8_t)(m_configuration_variables.ui8_wheel_speed_max) * (uint8_t)10U) + (uint8_t)20U),
static void apply_speed_limit(void) {
if (m_configuration_variables.ui8_wheel_speed_max > 0U) {
uint16_t speed_limit_low = (uint16_t)(m_configuration_variables.ui8_wheel_speed_max * (uint8_t)10U) - 20U; // casting literal to uint8_t ensures usage of MUL X,A
uint16_t speed_limit_high = (uint16_t)(m_configuration_variables.ui8_wheel_speed_max * (uint8_t)10U) + 20U;

ui8_adc_battery_current_target = (uint8_t)map_ui16(ui16_wheel_speed_x10,
speed_limit_low,
speed_limit_high,
ui8_adc_battery_current_target,
0);
if (ui16_wheel_speed_x10 > ((uint16_t) (((uint8_t)(m_configuration_variables.ui8_wheel_speed_max) * (uint8_t)10U) - (uint8_t)20U))) {
0U);

if (ui16_wheel_speed_x10 > speed_limit_high) {
ui8_duty_cycle_target = 0;
}
}
Expand Down

0 comments on commit b700ed3

Please sign in to comment.