mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-09 12:35:28 +00:00
gptimer: fix race condition between start and stop
Added state transition in gptimer_start/stop functions. So that it's not possible to make a stopped timer continue to run because of race condition.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
@@ -7,6 +7,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdatomic.h>
|
||||
#include "sdkconfig.h"
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "esp_err.h"
|
||||
@@ -45,8 +46,11 @@ typedef struct gptimer_group_t {
|
||||
} gptimer_group_t;
|
||||
|
||||
typedef enum {
|
||||
GPTIMER_FSM_INIT,
|
||||
GPTIMER_FSM_ENABLE,
|
||||
GPTIMER_FSM_INIT, // Timer is initialized, but not enabled
|
||||
GPTIMER_FSM_ENABLE, // Timer is enabled, but is not running
|
||||
GPTIMER_FSM_ENABLE_WAIT, // Timer is in the middle of the enable process (Intermediate state)
|
||||
GPTIMER_FSM_RUN, // Timer is in running
|
||||
GPTIMER_FSM_RUN_WAIT, // Timer is in the middle of the run process (Intermediate state)
|
||||
} gptimer_fsm_t;
|
||||
|
||||
struct gptimer_t {
|
||||
@@ -57,7 +61,7 @@ struct gptimer_t {
|
||||
uint64_t alarm_count;
|
||||
gptimer_count_direction_t direction;
|
||||
timer_hal_context_t hal;
|
||||
gptimer_fsm_t fsm;
|
||||
_Atomic gptimer_fsm_t fsm;
|
||||
intr_handle_t intr;
|
||||
portMUX_TYPE spinlock; // to protect per-timer resources concurrent accessed by task and ISR handler
|
||||
gptimer_alarm_cb_t on_alarm;
|
||||
|
Reference in New Issue
Block a user