Fix some coding issues and a possible race condition
This commit is contained in:
@@ -53,6 +53,7 @@ void button_init()
|
||||
enum button_state button_read_event()
|
||||
{
|
||||
uint64_t time_delta;
|
||||
uint64_t activation_stmp;
|
||||
enum button_state temp_state;
|
||||
|
||||
if (override_state != BUTTON_IDLE) {
|
||||
@@ -66,7 +67,13 @@ enum button_state button_read_event()
|
||||
int_state = BUTTON_IDLE;
|
||||
return temp_state;
|
||||
} 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)
|
||||
return BUTTON_LONG;
|
||||
else if (time_delta >= BUTTON_SHORT_ON_TIME_MS)
|
||||
|
||||
Reference in New Issue
Block a user