Fix some coding issues and a possible race condition

This commit is contained in:
Mario Hüttel 2021-10-15 21:16:26 +02:00
parent 6fde4cfd66
commit d9c145ec81
3 changed files with 10 additions and 9 deletions

View File

@ -122,12 +122,6 @@ enum analog_value_monitor {
*/ */
#define SAFETY_MIN_STACK_FREE 0x100 #define SAFETY_MIN_STACK_FREE 0x100
#define PID_CONTROLLER_ERR_CAREMASK (ERR_FLAG_STACK | ERR_FLAG_AMON_UC_TEMP | ERR_FLAG_AMON_VREF | \
ERR_FLAG_TIMING_PID | ERR_FLAG_TIMING_MEAS_ADC | ERR_FLAG_MEAS_ADC_OFF | \
ERR_FLAG_MEAS_ADC_OVERFLOW)
#define HALTING_CAREMASK (ERR_FLAG_STACK | ERR_FLAG_AMON_UC_TEMP)
#define SAFETY_ADC_VREF_MVOLT (2500.0f) #define SAFETY_ADC_VREF_MVOLT (2500.0f)
#define SAFETY_ADC_VREF_TOL_MVOLT (100.0f) #define SAFETY_ADC_VREF_TOL_MVOLT (100.0f)
#define SAFETY_ADC_TEMP_LOW_LIM (0.0f) #define SAFETY_ADC_TEMP_LOW_LIM (0.0f)

View File

@ -53,6 +53,7 @@ void button_init()
enum button_state button_read_event() enum button_state button_read_event()
{ {
uint64_t time_delta; uint64_t time_delta;
uint64_t activation_stmp;
enum button_state temp_state; enum button_state temp_state;
if (override_state != BUTTON_IDLE) { if (override_state != BUTTON_IDLE) {
@ -66,7 +67,13 @@ enum button_state button_read_event()
int_state = BUTTON_IDLE; int_state = BUTTON_IDLE;
return temp_state; return temp_state;
} else { } else {
time_delta = systick_get_global_tick() - to_active_timestamp; /* Unfortunately I don't jave a better idea for now to ensure,
* that to_active_timestamp is read atomically
*/
__disable_irq();
activation_stmp = to_active_timestamp;
__enable_irq();
time_delta = systick_get_global_tick() - activation_stmp;
if (time_delta >= BUTTON_LONG_ON_TIME_MS) if (time_delta >= BUTTON_LONG_ON_TIME_MS)
return BUTTON_LONG; return BUTTON_LONG;
else if (time_delta >= BUTTON_SHORT_ON_TIME_MS) else if (time_delta >= BUTTON_SHORT_ON_TIME_MS)

View File

@ -791,7 +791,7 @@ static void gui_menu_root_entry(struct lcd_menu *menu, enum menu_entry_func_entr
} }
} }
int gui_handle() int gui_handle(void)
{ {
int32_t rot_delta; int32_t rot_delta;
enum button_state button; enum button_state button;
@ -813,7 +813,7 @@ int gui_handle()
return 1; return 1;
} }
void gui_init() void gui_init(void)
{ {
rotary_encoder_setup(); rotary_encoder_setup();
button_init(); button_init();