Skip to content

Commit

Permalink
Merge pull request #340 from tinymovr/firmware/reent_warning
Browse files Browse the repository at this point in the history
Demote schedule reentrance error to warning
  • Loading branch information
yconst authored Apr 19, 2024
2 parents 09be975 + abc0cf5 commit d589813
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 29 deletions.
4 changes: 2 additions & 2 deletions docs/protocol/reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ Processor load in ticks per PWM cycle.



scheduler.errors
scheduler.warnings
-------------------------------------------------------------------

ID: 17
Expand All @@ -242,7 +242,7 @@ Type: uint8



Any scheduler errors, as a bitmask
Any scheduler warnings, as a bitmask

Flags:

Expand Down
6 changes: 3 additions & 3 deletions firmware/src/can/can_endpoints.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include <src/can/can_endpoints.h>


uint8_t (*avlos_endpoints[96])(uint8_t * buffer, uint8_t * buffer_len, Avlos_Command cmd) = {&avlos_protocol_hash, &avlos_uid, &avlos_fw_version, &avlos_hw_revision, &avlos_Vbus, &avlos_Ibus, &avlos_power, &avlos_temp, &avlos_calibrated, &avlos_errors, &avlos_warnings, &avlos_save_config, &avlos_erase_config, &avlos_reset, &avlos_enter_dfu, &avlos_config_size, &avlos_scheduler_load, &avlos_scheduler_errors, &avlos_controller_state, &avlos_controller_mode, &avlos_controller_warnings, &avlos_controller_errors, &avlos_controller_position_setpoint, &avlos_controller_position_p_gain, &avlos_controller_velocity_setpoint, &avlos_controller_velocity_limit, &avlos_controller_velocity_p_gain, &avlos_controller_velocity_i_gain, &avlos_controller_velocity_deadband, &avlos_controller_velocity_increment, &avlos_controller_current_Iq_setpoint, &avlos_controller_current_Id_setpoint, &avlos_controller_current_Iq_limit, &avlos_controller_current_Iq_estimate, &avlos_controller_current_bandwidth, &avlos_controller_current_Iq_p_gain, &avlos_controller_current_max_Ibus_regen, &avlos_controller_current_max_Ibrake, &avlos_controller_voltage_Vq_setpoint, &avlos_controller_calibrate, &avlos_controller_idle, &avlos_controller_position_mode, &avlos_controller_velocity_mode, &avlos_controller_current_mode, &avlos_controller_set_pos_vel_setpoints, &avlos_comms_can_rate, &avlos_comms_can_id, &avlos_comms_can_heartbeat, &avlos_motor_R, &avlos_motor_L, &avlos_motor_pole_pairs, &avlos_motor_type, &avlos_motor_calibrated, &avlos_motor_I_cal, &avlos_motor_errors, &avlos_sensors_user_frame_position_estimate, &avlos_sensors_user_frame_velocity_estimate, &avlos_sensors_user_frame_offset, &avlos_sensors_user_frame_multiplier, &avlos_sensors_setup_onboard_calibrated, &avlos_sensors_setup_onboard_errors, &avlos_sensors_setup_external_spi_type, &avlos_sensors_setup_external_spi_calibrated, &avlos_sensors_setup_external_spi_errors, &avlos_sensors_setup_hall_calibrated, &avlos_sensors_setup_hall_errors, &avlos_sensors_select_position_sensor_connection, &avlos_sensors_select_position_sensor_bandwidth, &avlos_sensors_select_position_sensor_raw_angle, &avlos_sensors_select_position_sensor_position_estimate, &avlos_sensors_select_position_sensor_velocity_estimate, &avlos_sensors_select_commutation_sensor_connection, &avlos_sensors_select_commutation_sensor_bandwidth, &avlos_sensors_select_commutation_sensor_raw_angle, &avlos_sensors_select_commutation_sensor_position_estimate, &avlos_sensors_select_commutation_sensor_velocity_estimate, &avlos_traj_planner_max_accel, &avlos_traj_planner_max_decel, &avlos_traj_planner_max_vel, &avlos_traj_planner_t_accel, &avlos_traj_planner_t_decel, &avlos_traj_planner_t_total, &avlos_traj_planner_move_to, &avlos_traj_planner_move_to_tlimit, &avlos_traj_planner_errors, &avlos_homing_velocity, &avlos_homing_max_homing_t, &avlos_homing_retract_dist, &avlos_homing_warnings, &avlos_homing_stall_detect_velocity, &avlos_homing_stall_detect_delta_pos, &avlos_homing_stall_detect_t, &avlos_homing_home, &avlos_watchdog_enabled, &avlos_watchdog_triggered, &avlos_watchdog_timeout };
uint8_t (*avlos_endpoints[96])(uint8_t * buffer, uint8_t * buffer_len, Avlos_Command cmd) = {&avlos_protocol_hash, &avlos_uid, &avlos_fw_version, &avlos_hw_revision, &avlos_Vbus, &avlos_Ibus, &avlos_power, &avlos_temp, &avlos_calibrated, &avlos_errors, &avlos_warnings, &avlos_save_config, &avlos_erase_config, &avlos_reset, &avlos_enter_dfu, &avlos_config_size, &avlos_scheduler_load, &avlos_scheduler_warnings, &avlos_controller_state, &avlos_controller_mode, &avlos_controller_warnings, &avlos_controller_errors, &avlos_controller_position_setpoint, &avlos_controller_position_p_gain, &avlos_controller_velocity_setpoint, &avlos_controller_velocity_limit, &avlos_controller_velocity_p_gain, &avlos_controller_velocity_i_gain, &avlos_controller_velocity_deadband, &avlos_controller_velocity_increment, &avlos_controller_current_Iq_setpoint, &avlos_controller_current_Id_setpoint, &avlos_controller_current_Iq_limit, &avlos_controller_current_Iq_estimate, &avlos_controller_current_bandwidth, &avlos_controller_current_Iq_p_gain, &avlos_controller_current_max_Ibus_regen, &avlos_controller_current_max_Ibrake, &avlos_controller_voltage_Vq_setpoint, &avlos_controller_calibrate, &avlos_controller_idle, &avlos_controller_position_mode, &avlos_controller_velocity_mode, &avlos_controller_current_mode, &avlos_controller_set_pos_vel_setpoints, &avlos_comms_can_rate, &avlos_comms_can_id, &avlos_comms_can_heartbeat, &avlos_motor_R, &avlos_motor_L, &avlos_motor_pole_pairs, &avlos_motor_type, &avlos_motor_calibrated, &avlos_motor_I_cal, &avlos_motor_errors, &avlos_sensors_user_frame_position_estimate, &avlos_sensors_user_frame_velocity_estimate, &avlos_sensors_user_frame_offset, &avlos_sensors_user_frame_multiplier, &avlos_sensors_setup_onboard_calibrated, &avlos_sensors_setup_onboard_errors, &avlos_sensors_setup_external_spi_type, &avlos_sensors_setup_external_spi_calibrated, &avlos_sensors_setup_external_spi_errors, &avlos_sensors_setup_hall_calibrated, &avlos_sensors_setup_hall_errors, &avlos_sensors_select_position_sensor_connection, &avlos_sensors_select_position_sensor_bandwidth, &avlos_sensors_select_position_sensor_raw_angle, &avlos_sensors_select_position_sensor_position_estimate, &avlos_sensors_select_position_sensor_velocity_estimate, &avlos_sensors_select_commutation_sensor_connection, &avlos_sensors_select_commutation_sensor_bandwidth, &avlos_sensors_select_commutation_sensor_raw_angle, &avlos_sensors_select_commutation_sensor_position_estimate, &avlos_sensors_select_commutation_sensor_velocity_estimate, &avlos_traj_planner_max_accel, &avlos_traj_planner_max_decel, &avlos_traj_planner_max_vel, &avlos_traj_planner_t_accel, &avlos_traj_planner_t_decel, &avlos_traj_planner_t_total, &avlos_traj_planner_move_to, &avlos_traj_planner_move_to_tlimit, &avlos_traj_planner_errors, &avlos_homing_velocity, &avlos_homing_max_homing_t, &avlos_homing_retract_dist, &avlos_homing_warnings, &avlos_homing_stall_detect_velocity, &avlos_homing_stall_detect_delta_pos, &avlos_homing_stall_detect_t, &avlos_homing_home, &avlos_watchdog_enabled, &avlos_watchdog_triggered, &avlos_watchdog_timeout };

uint32_t _avlos_get_proto_hash(void)
{
Expand Down Expand Up @@ -206,11 +206,11 @@ if (AVLOS_CMD_READ == cmd) {
return AVLOS_RET_NOACTION;
}

uint8_t avlos_scheduler_errors(uint8_t * buffer, uint8_t * buffer_len, Avlos_Command cmd)
uint8_t avlos_scheduler_warnings(uint8_t * buffer, uint8_t * buffer_len, Avlos_Command cmd)
{
if (AVLOS_CMD_READ == cmd) {
uint8_t v;
v = scheduler_get_errors();
v = scheduler_get_warnings();
*buffer_len = sizeof(v);
memcpy(buffer, &v, sizeof(v));
return AVLOS_RET_READ;
Expand Down
8 changes: 4 additions & 4 deletions firmware/src/can/can_endpoints.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include <src/common.h>
#include <src/tm_enums.h>

static const uint32_t avlos_proto_hash = 3066507445;
static const uint32_t avlos_proto_hash = 318558145;
extern uint8_t (*avlos_endpoints[96])(uint8_t * buffer, uint8_t * buffer_len, Avlos_Command cmd);
extern uint32_t _avlos_get_proto_hash(void);

Expand Down Expand Up @@ -219,16 +219,16 @@ uint8_t avlos_config_size(uint8_t * buffer, uint8_t * buffer_len, Avlos_Command
uint8_t avlos_scheduler_load(uint8_t * buffer, uint8_t * buffer_len, Avlos_Command cmd);

/*
* avlos_scheduler_errors
* avlos_scheduler_warnings
*
* Any scheduler errors, as a bitmask
* Any scheduler warnings, as a bitmask
*
* Endpoint ID: 17
*
* @param buffer
* @param buffer_len
*/
uint8_t avlos_scheduler_errors(uint8_t * buffer, uint8_t * buffer_len, Avlos_Command cmd);
uint8_t avlos_scheduler_warnings(uint8_t * buffer, uint8_t * buffer_len, Avlos_Command cmd);

/*
* avlos_controller_state
Expand Down
16 changes: 5 additions & 11 deletions firmware/src/scheduler/scheduler.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,19 +92,13 @@ void wait_for_control_loop_interrupt(void)
void ADC_IRQHandler(void)
{
PAC55XX_ADC->ADCINT.ADCIRQ0IF = 1;
// Only in case the gate driver is enabled, ensure
// the control deadline is not missed,
// i.e. the previous control loop is complete prior
// to the ADC triggering the next
scheduler_state.adc_interrupt = true;
// Only in case the gate driver is enabled, raise a
// warning if the control loop is about to be
// reentered
if (gate_driver_is_enabled() && scheduler_state.busy)
{
scheduler_state.errors |= SCHEDULER_ERRORS_CONTROL_BLOCK_REENTERED;
// We do not change the control state here, to
// avoid any concurrency issues
}
else
{
scheduler_state.adc_interrupt = true;
scheduler_state.warnings |= SCHEDULER_WARNINGS_CONTROL_BLOCK_REENTERED;
}
}

Expand Down
6 changes: 3 additions & 3 deletions firmware/src/scheduler/scheduler.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,16 @@ typedef struct
bool busy;
uint32_t load;

uint8_t errors;
uint8_t warnings;
} SchedulerState;

extern volatile SchedulerState scheduler_state;

void wait_for_control_loop_interrupt(void);

static inline uint8_t scheduler_get_errors(void)
static inline uint8_t scheduler_get_warnings(void)
{
return scheduler_state.errors;
return scheduler_state.warnings;
}

static inline uint32_t scheduler_get_load(void)
Expand Down
6 changes: 3 additions & 3 deletions firmware/src/tm_enums.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ typedef enum

typedef enum
{
SCHEDULER_ERRORS_NONE = 0,
SCHEDULER_ERRORS_CONTROL_BLOCK_REENTERED = (1 << 0)
} scheduler_errors_flags;
SCHEDULER_WARNINGS_NONE = 0,
SCHEDULER_WARNINGS_CONTROL_BLOCK_REENTERED = (1 << 0)
} scheduler_warnings_flags;

typedef enum
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,11 @@ remote_attributes:
getter_name: scheduler_get_load
meta: {dynamic: True}
dtype: uint32
- name: errors
- name: warnings
flags: [CONTROL_BLOCK_REENTERED]
meta: {dynamic: True}
getter_name: scheduler_get_errors
summary: Any scheduler errors, as a bitmask
getter_name: scheduler_get_warnings
summary: Any scheduler warnings, as a bitmask
- name: controller
remote_attributes:
- name: state
Expand Down

0 comments on commit d589813

Please sign in to comment.