mirror of
https://github.com/apache/nuttx.git
synced 2026-08-12 07:55:32 +00:00
Revert "Use small lock to protect resources related to timers in arch risc-v, xtensa and tricore."
This reverts commit ecaddbb0aa.
This commit is contained in:
parent
9e687ca896
commit
191e3ba1f7
5 changed files with 78 additions and 129 deletions
|
|
@ -34,7 +34,6 @@
|
|||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <sched.h>
|
||||
|
||||
#include <nuttx/nuttx.h>
|
||||
#include <nuttx/irq.h>
|
||||
|
|
@ -219,8 +218,7 @@ static int IRAM_ATTR esp_hr_timer_isr(int irq, void *context, void *arg)
|
|||
|
||||
systimer_ll_clear_alarm_int(priv->hal.dev, SYSTIMER_ALARM_ESPTIMER);
|
||||
|
||||
flags = spin_lock_irqsave(&priv->lock);
|
||||
sched_lock();
|
||||
flags = enter_critical_section();
|
||||
|
||||
/* Check if there is a timer running */
|
||||
|
||||
|
|
@ -290,8 +288,7 @@ static int IRAM_ATTR esp_hr_timer_isr(int irq, void *context, void *arg)
|
|||
}
|
||||
}
|
||||
|
||||
spin_unlock_irqrestore(&priv->lock, flags);
|
||||
sched_unlock();
|
||||
leave_critical_section(flags);
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
|
@ -713,7 +710,7 @@ void IRAM_ATTR esp_hr_timer_calibration(uint64_t time_us)
|
|||
|
||||
int esp_hr_timer_init(void)
|
||||
{
|
||||
struct esp_hr_timer_context_s *priv = &g_hr_timer_context;
|
||||
struct esp_hr_timer_context_s *priv;
|
||||
int pid;
|
||||
|
||||
if (g_hr_timer_initialized)
|
||||
|
|
@ -723,8 +720,6 @@ int esp_hr_timer_init(void)
|
|||
return OK;
|
||||
}
|
||||
|
||||
spin_lock_init(&priv->lock);
|
||||
|
||||
pid = kthread_create(CONFIG_ESPRESSIF_HR_TIMER_TASK_NAME,
|
||||
CONFIG_ESPRESSIF_HR_TIMER_TASK_PRIORITY,
|
||||
CONFIG_ESPRESSIF_HR_TIMER_TASK_STACK_SIZE,
|
||||
|
|
@ -737,6 +732,8 @@ int esp_hr_timer_init(void)
|
|||
return pid;
|
||||
}
|
||||
|
||||
priv = &g_hr_timer_context;
|
||||
|
||||
list_initialize(&priv->runlist);
|
||||
list_initialize(&priv->toutlist);
|
||||
|
||||
|
|
|
|||
|
|
@ -34,10 +34,9 @@
|
|||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <debug.h>
|
||||
#include <sched.h>
|
||||
|
||||
#include <nuttx/nuttx.h>
|
||||
#include <nuttx/spinlock.h>
|
||||
#include <nuttx/irq.h>
|
||||
#include <nuttx/kthread.h>
|
||||
#include <nuttx/kmalloc.h>
|
||||
#include <nuttx/semaphore.h>
|
||||
|
|
@ -77,7 +76,6 @@ struct esp32c3_rt_priv_s
|
|||
struct list_node runlist;
|
||||
struct list_node toutlist;
|
||||
struct esp32c3_tim_dev_s *timer;
|
||||
spinlock_t lock;
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
|
|
@ -111,15 +109,18 @@ static struct esp32c3_rt_priv_s g_rt_priv =
|
|||
*
|
||||
****************************************************************************/
|
||||
|
||||
static void start_rt_timer_nolock(struct rt_timer_s *timer,
|
||||
uint64_t timeout,
|
||||
bool repeat)
|
||||
static void start_rt_timer(struct rt_timer_s *timer,
|
||||
uint64_t timeout,
|
||||
bool repeat)
|
||||
{
|
||||
irqstate_t flags;
|
||||
struct rt_timer_s *p;
|
||||
bool inserted = false;
|
||||
uint64_t counter;
|
||||
struct esp32c3_rt_priv_s *priv = &g_rt_priv;
|
||||
|
||||
flags = enter_critical_section();
|
||||
|
||||
/* Only idle timer can be started */
|
||||
|
||||
if (timer->state == RT_TIMER_IDLE)
|
||||
|
|
@ -177,18 +178,8 @@ static void start_rt_timer_nolock(struct rt_timer_s *timer,
|
|||
ESP32C3_TIM_SETALRM(priv->timer, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void start_rt_timer(struct rt_timer_s *timer,
|
||||
uint64_t timeout,
|
||||
bool repeat)
|
||||
{
|
||||
irqstate_t flags;
|
||||
struct esp32c3_rt_priv_s *priv = &g_rt_priv;
|
||||
|
||||
flags = spin_lock_irqsave(&priv->lock);
|
||||
start_rt_timer_nolock(timer, timeout, repeat);
|
||||
spin_unlock_irqrestore(&priv->lock, flags);
|
||||
leave_critical_section(flags);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
|
|
@ -206,13 +197,16 @@ static void start_rt_timer(struct rt_timer_s *timer,
|
|||
*
|
||||
****************************************************************************/
|
||||
|
||||
static void stop_rt_timer_nolock(struct rt_timer_s *timer)
|
||||
static void stop_rt_timer(struct rt_timer_s *timer)
|
||||
{
|
||||
irqstate_t flags;
|
||||
bool ishead;
|
||||
struct rt_timer_s *next_timer;
|
||||
uint64_t alarm;
|
||||
struct esp32c3_rt_priv_s *priv = &g_rt_priv;
|
||||
|
||||
flags = enter_critical_section();
|
||||
|
||||
/* "start" function can set the timer's repeat flag, and "stop" function
|
||||
* should remove this flag.
|
||||
*/
|
||||
|
|
@ -259,16 +253,8 @@ static void stop_rt_timer_nolock(struct rt_timer_s *timer)
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void stop_rt_timer(struct rt_timer_s *timer)
|
||||
{
|
||||
irqstate_t flags;
|
||||
struct esp32c3_rt_priv_s *priv = &g_rt_priv;
|
||||
|
||||
flags = spin_lock_irqsave(&priv->lock);
|
||||
stop_rt_timer_nolock(timer);
|
||||
spin_unlock_irqrestore(&priv->lock, flags);
|
||||
leave_critical_section(flags);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
|
|
@ -294,12 +280,11 @@ static void delete_rt_timer(struct rt_timer_s *timer)
|
|||
|
||||
struct esp32c3_rt_priv_s *priv = &g_rt_priv;
|
||||
|
||||
flags = spin_lock_irqsave(&priv->lock);
|
||||
sched_lock();
|
||||
flags = enter_critical_section();
|
||||
|
||||
if (timer->state == RT_TIMER_READY)
|
||||
{
|
||||
stop_rt_timer_nolock(timer);
|
||||
stop_rt_timer(timer);
|
||||
}
|
||||
else if (timer->state == RT_TIMER_TIMEOUT)
|
||||
{
|
||||
|
|
@ -322,8 +307,7 @@ static void delete_rt_timer(struct rt_timer_s *timer)
|
|||
}
|
||||
|
||||
exit:
|
||||
spin_unlock_irqrestore(&priv->lock, flags);
|
||||
sched_unlock();
|
||||
leave_critical_section(flags);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
|
|
@ -361,7 +345,7 @@ static int rt_timer_thread(int argc, char *argv[])
|
|||
ASSERT(0);
|
||||
}
|
||||
|
||||
flags = spin_lock_irqsave(&priv->lock);
|
||||
flags = enter_critical_section();
|
||||
|
||||
/* Process all the timers in list */
|
||||
|
||||
|
|
@ -384,7 +368,7 @@ static int rt_timer_thread(int argc, char *argv[])
|
|||
|
||||
timer->state = RT_TIMER_IDLE;
|
||||
|
||||
spin_unlock_irqrestore(&priv->lock, flags);
|
||||
leave_critical_section(flags);
|
||||
|
||||
if (raw_state == RT_TIMER_TIMEOUT)
|
||||
{
|
||||
|
|
@ -397,7 +381,7 @@ static int rt_timer_thread(int argc, char *argv[])
|
|||
|
||||
/* Enter critical section for next scanning list */
|
||||
|
||||
flags = spin_lock_irqsave(&priv->lock);
|
||||
flags = enter_critical_section();
|
||||
|
||||
if (raw_state == RT_TIMER_TIMEOUT)
|
||||
{
|
||||
|
|
@ -405,12 +389,12 @@ static int rt_timer_thread(int argc, char *argv[])
|
|||
|
||||
if (timer->flags & RT_TIMER_REPEAT)
|
||||
{
|
||||
start_rt_timer_nolock(timer, timer->timeout, true);
|
||||
start_rt_timer(timer, timer->timeout, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
spin_unlock_irqrestore(&priv->lock, flags);
|
||||
leave_critical_section(flags);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
@ -446,8 +430,7 @@ static int rt_timer_isr(int irq, void *context, void *arg)
|
|||
|
||||
ESP32C3_TIM_ACKINT(priv->timer);
|
||||
|
||||
flags = spin_lock_irqsave(&priv->lock);
|
||||
sched_lock();
|
||||
flags = enter_critical_section();
|
||||
|
||||
/* Check if there is a timer running */
|
||||
|
||||
|
|
@ -506,8 +489,7 @@ static int rt_timer_isr(int irq, void *context, void *arg)
|
|||
}
|
||||
}
|
||||
|
||||
spin_unlock_irqrestore(&priv->lock, flags);
|
||||
sched_unlock();
|
||||
leave_critical_section(flags);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -663,7 +645,7 @@ uint64_t IRAM_ATTR rt_timer_get_alarm(void)
|
|||
struct esp32c3_rt_priv_s *priv = &g_rt_priv;
|
||||
uint64_t alarm_value = 0;
|
||||
|
||||
flags = spin_lock_irqsave(&priv->lock);
|
||||
flags = enter_critical_section();
|
||||
|
||||
ESP32C3_TIM_GETCTR(priv->timer, &counter);
|
||||
counter = CYCLES_TO_USEC(counter);
|
||||
|
|
@ -679,7 +661,7 @@ uint64_t IRAM_ATTR rt_timer_get_alarm(void)
|
|||
alarm_value -= counter;
|
||||
}
|
||||
|
||||
spin_unlock_irqrestore(&priv->lock, flags);
|
||||
leave_critical_section(flags);
|
||||
|
||||
return alarm_value;
|
||||
}
|
||||
|
|
@ -704,13 +686,13 @@ void IRAM_ATTR rt_timer_calibration(uint64_t time_us)
|
|||
struct esp32c3_rt_priv_s *priv = &g_rt_priv;
|
||||
irqstate_t flags;
|
||||
|
||||
flags = spin_lock_irqsave(&priv->lock);
|
||||
flags = enter_critical_section();
|
||||
ESP32C3_TIM_GETCTR(priv->timer, &counter);
|
||||
counter = CYCLES_TO_USEC(counter);
|
||||
counter += time_us;
|
||||
ESP32C3_TIM_SETCTR(priv->timer, USEC_TO_CYCLES(counter));
|
||||
ESP32C3_TIM_RLD_NOW(priv->timer);
|
||||
spin_unlock_irqrestore(&priv->lock, flags);
|
||||
leave_critical_section(flags);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
|
|
@ -733,7 +715,6 @@ int esp32c3_rt_timer_init(void)
|
|||
irqstate_t flags;
|
||||
struct esp32c3_rt_priv_s *priv = &g_rt_priv;
|
||||
|
||||
spin_lock_init(&priv->lock);
|
||||
priv->timer = esp32c3_tim_init(ESP32C3_RT_TIMER);
|
||||
if (priv->timer == NULL)
|
||||
{
|
||||
|
|
@ -758,7 +739,7 @@ int esp32c3_rt_timer_init(void)
|
|||
|
||||
priv->pid = (pid_t)pid;
|
||||
|
||||
flags = spin_lock_irqsave(&priv->lock);
|
||||
flags = enter_critical_section();
|
||||
|
||||
/* ESP32-C3 hardware timer configuration:
|
||||
* 1 count = 1/16 us
|
||||
|
|
@ -775,7 +756,7 @@ int esp32c3_rt_timer_init(void)
|
|||
ESP32C3_TIM_ENABLEINT(priv->timer);
|
||||
ESP32C3_TIM_START(priv->timer);
|
||||
|
||||
spin_unlock_irqrestore(&priv->lock, flags);
|
||||
leave_critical_section(flags);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -799,7 +780,7 @@ void esp32c3_rt_timer_deinit(void)
|
|||
irqstate_t flags;
|
||||
struct esp32c3_rt_priv_s *priv = &g_rt_priv;
|
||||
|
||||
flags = spin_lock_irqsave(&priv->lock);
|
||||
flags = enter_critical_section();
|
||||
|
||||
ESP32C3_TIM_STOP(priv->timer);
|
||||
ESP32C3_TIM_DISABLEINT(priv->timer);
|
||||
|
|
@ -807,7 +788,7 @@ void esp32c3_rt_timer_deinit(void)
|
|||
esp32c3_tim_deinit(priv->timer);
|
||||
priv->timer = NULL;
|
||||
|
||||
spin_unlock_irqrestore(&priv->lock, flags);
|
||||
leave_critical_section(flags);
|
||||
|
||||
if (priv->pid != INVALID_PROCESS_ID)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -263,7 +263,7 @@ static void delete_rt_timer(struct rt_timer_s *timer)
|
|||
irqstate_t flags;
|
||||
struct esp32_rt_priv_s *priv = &g_rt_priv;
|
||||
|
||||
flags = spin_lock_irqsave(&priv->lock);
|
||||
flags = enter_critical_section();
|
||||
|
||||
if (timer->state == RT_TIMER_READY)
|
||||
{
|
||||
|
|
@ -282,7 +282,7 @@ static void delete_rt_timer(struct rt_timer_s *timer)
|
|||
timer->state = RT_TIMER_DELETE;
|
||||
|
||||
exit:
|
||||
spin_unlock_irqrestore(&priv->lock, flags);
|
||||
leave_critical_section(flags);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
|
|
@ -684,7 +684,6 @@ int esp32_rt_timer_init(void)
|
|||
struct esp32_tim_dev_s *tim;
|
||||
struct esp32_rt_priv_s *priv = &g_rt_priv;
|
||||
|
||||
spin_lock_init(&priv->lock);
|
||||
tim = esp32_tim_init(ESP32_RT_TIMER);
|
||||
if (!tim)
|
||||
{
|
||||
|
|
@ -710,7 +709,7 @@ int esp32_rt_timer_init(void)
|
|||
priv->timer = tim;
|
||||
priv->pid = (pid_t)pid;
|
||||
|
||||
flags = spin_lock_irqsave(&priv->lock);
|
||||
flags = enter_critical_section();
|
||||
|
||||
/* ESP32 hardware timer configuration:
|
||||
* - 1 counter = 1us
|
||||
|
|
@ -728,7 +727,7 @@ int esp32_rt_timer_init(void)
|
|||
|
||||
ESP32_TIM_START(tim);
|
||||
|
||||
spin_unlock_irqrestore(&priv->lock, flags);
|
||||
leave_critical_section(flags);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,10 +32,9 @@
|
|||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <debug.h>
|
||||
#include <sched.h>
|
||||
|
||||
#include <nuttx/nuttx.h>
|
||||
#include <nuttx/spinlock.h>
|
||||
#include <nuttx/irq.h>
|
||||
#include <nuttx/kthread.h>
|
||||
#include <nuttx/kmalloc.h>
|
||||
#include <nuttx/semaphore.h>
|
||||
|
|
@ -81,7 +80,6 @@ struct esp32s2_rt_priv_s
|
|||
struct list_node runlist;
|
||||
struct list_node toutlist;
|
||||
struct esp32s2_tim_dev_s *timer;
|
||||
spinlock_t lock;
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
|
|
@ -116,15 +114,18 @@ static struct esp32s2_rt_priv_s g_rt_priv =
|
|||
*
|
||||
****************************************************************************/
|
||||
|
||||
static void start_rt_timer_nolock(struct rt_timer_s *timer,
|
||||
uint64_t timeout,
|
||||
bool repeat)
|
||||
static void start_rt_timer(struct rt_timer_s *timer,
|
||||
uint64_t timeout,
|
||||
bool repeat)
|
||||
{
|
||||
irqstate_t flags;
|
||||
struct rt_timer_s *temp_p;
|
||||
bool inserted = false;
|
||||
uint64_t counter;
|
||||
struct esp32s2_rt_priv_s *priv = &g_rt_priv;
|
||||
|
||||
flags = enter_critical_section();
|
||||
|
||||
/* Only idle timer can be started */
|
||||
|
||||
if (timer->state == RT_TIMER_IDLE)
|
||||
|
|
@ -187,20 +188,8 @@ static void start_rt_timer_nolock(struct rt_timer_s *timer,
|
|||
tmrwarn("WARN: Timer not in idle mode.\n"\
|
||||
"Only idle timer can be started!\n");
|
||||
}
|
||||
}
|
||||
|
||||
static void start_rt_timer(struct rt_timer_s *timer,
|
||||
uint64_t timeout,
|
||||
bool repeat)
|
||||
{
|
||||
irqstate_t flags;
|
||||
struct esp32s2_rt_priv_s *priv = &g_rt_priv;
|
||||
|
||||
flags = spin_lock_irqsave(&priv->lock);
|
||||
sched_lock();
|
||||
start_rt_timer_nolock(timer, timeout, repeat);
|
||||
spin_unlock_irqrestore(&priv->lock, flags);
|
||||
sched_unlock();
|
||||
leave_critical_section(flags);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
|
|
@ -218,13 +207,16 @@ static void start_rt_timer(struct rt_timer_s *timer,
|
|||
*
|
||||
****************************************************************************/
|
||||
|
||||
static void stop_rt_timer_nolock(struct rt_timer_s *timer)
|
||||
static void stop_rt_timer(struct rt_timer_s *timer)
|
||||
{
|
||||
irqstate_t flags;
|
||||
bool ishead;
|
||||
struct rt_timer_s *next_timer;
|
||||
uint64_t alarm;
|
||||
struct esp32s2_rt_priv_s *priv = &g_rt_priv;
|
||||
|
||||
flags = enter_critical_section();
|
||||
|
||||
/* "start" function can set the timer's repeat flag, and "stop" function
|
||||
* should remove this flag.
|
||||
*/
|
||||
|
|
@ -271,16 +263,8 @@ static void stop_rt_timer_nolock(struct rt_timer_s *timer)
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void stop_rt_timer(struct rt_timer_s *timer)
|
||||
{
|
||||
irqstate_t flags;
|
||||
struct esp32s2_rt_priv_s *priv = &g_rt_priv;
|
||||
|
||||
flags = spin_lock_irqsave(&priv->lock);
|
||||
stop_rt_timer_nolock(timer);
|
||||
spin_unlock_irqrestore(&priv->lock, flags);
|
||||
leave_critical_section(flags);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
|
|
@ -305,12 +289,11 @@ static void delete_rt_timer(struct rt_timer_s *timer)
|
|||
irqstate_t flags;
|
||||
struct esp32s2_rt_priv_s *priv = &g_rt_priv;
|
||||
|
||||
flags = spin_lock_irqsave(&priv->lock);
|
||||
sched_lock();
|
||||
flags = enter_critical_section();
|
||||
|
||||
if (timer->state == RT_TIMER_READY)
|
||||
{
|
||||
stop_rt_timer_nolock(timer);
|
||||
stop_rt_timer(timer);
|
||||
}
|
||||
else if (timer->state == RT_TIMER_TIMEOUT)
|
||||
{
|
||||
|
|
@ -333,8 +316,7 @@ static void delete_rt_timer(struct rt_timer_s *timer)
|
|||
}
|
||||
|
||||
exit:
|
||||
spin_unlock_irqrestore(&priv->lock, flags);
|
||||
sched_unlock();
|
||||
leave_critical_section(flags);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
|
|
@ -372,7 +354,7 @@ static int rt_timer_thread(int argc, char *argv[])
|
|||
ASSERT(0);
|
||||
}
|
||||
|
||||
flags = spin_lock_irqsave(&priv->lock);
|
||||
flags = enter_critical_section();
|
||||
|
||||
/* Process all the timers in list */
|
||||
|
||||
|
|
@ -395,7 +377,7 @@ static int rt_timer_thread(int argc, char *argv[])
|
|||
|
||||
timer->state = RT_TIMER_IDLE;
|
||||
|
||||
spin_unlock_irqrestore(&priv->lock, flags);
|
||||
leave_critical_section(flags);
|
||||
|
||||
if (raw_state == RT_TIMER_TIMEOUT)
|
||||
{
|
||||
|
|
@ -408,7 +390,7 @@ static int rt_timer_thread(int argc, char *argv[])
|
|||
|
||||
/* Enter critical section for next scanning list */
|
||||
|
||||
flags = spin_lock_irqsave(&priv->lock);
|
||||
flags = enter_critical_section();
|
||||
|
||||
if (raw_state == RT_TIMER_TIMEOUT)
|
||||
{
|
||||
|
|
@ -416,12 +398,12 @@ static int rt_timer_thread(int argc, char *argv[])
|
|||
|
||||
if (timer->flags & RT_TIMER_REPEAT)
|
||||
{
|
||||
start_rt_timer_nolock(timer, timer->timeout, true);
|
||||
start_rt_timer(timer, timer->timeout, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
spin_unlock_irqrestore(&priv->lock, flags);
|
||||
leave_critical_section(flags);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
@ -457,8 +439,7 @@ static int rt_timer_isr(int irq, void *context, void *arg)
|
|||
|
||||
ESP32S2_TIM_ACKINT(priv->timer);
|
||||
|
||||
flags = spin_lock_irqsave(&priv->lock);
|
||||
sched_lock();
|
||||
flags = enter_critical_section();
|
||||
|
||||
/* Check if there is a timer running */
|
||||
|
||||
|
|
@ -517,8 +498,7 @@ static int rt_timer_isr(int irq, void *context, void *arg)
|
|||
}
|
||||
}
|
||||
|
||||
spin_unlock_irqrestore(&priv->lock, flags);
|
||||
sched_unlock();
|
||||
leave_critical_section(flags);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -674,7 +654,7 @@ uint64_t IRAM_ATTR rt_timer_get_alarm(void)
|
|||
struct esp32s2_rt_priv_s *priv = &g_rt_priv;
|
||||
uint64_t alarm_value = 0;
|
||||
|
||||
flags = spin_lock_irqsave(&priv->lock);
|
||||
flags = enter_critical_section();
|
||||
|
||||
ESP32S2_TIM_GETCTR(priv->timer, &counter);
|
||||
counter = CYCLES_TO_USEC(counter);
|
||||
|
|
@ -690,7 +670,7 @@ uint64_t IRAM_ATTR rt_timer_get_alarm(void)
|
|||
alarm_value -= counter;
|
||||
}
|
||||
|
||||
spin_unlock_irqrestore(&priv->lock, flags);
|
||||
leave_critical_section(flags);
|
||||
|
||||
return alarm_value;
|
||||
}
|
||||
|
|
@ -715,13 +695,13 @@ void IRAM_ATTR rt_timer_calibration(uint64_t time_us)
|
|||
struct esp32s2_rt_priv_s *priv = &g_rt_priv;
|
||||
irqstate_t flags;
|
||||
|
||||
flags = spin_lock_irqsave(&priv->lock);
|
||||
flags = enter_critical_section();
|
||||
ESP32S2_TIM_GETCTR(priv->timer, &counter);
|
||||
counter = CYCLES_TO_USEC(counter);
|
||||
counter += time_us;
|
||||
ESP32S2_TIM_SETCTR(priv->timer, USEC_TO_CYCLES(counter));
|
||||
ESP32S2_TIM_RLD_NOW(priv->timer);
|
||||
spin_unlock_irqrestore(&priv->lock, flags);
|
||||
leave_critical_section(flags);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
|
|
@ -748,7 +728,6 @@ int esp32s2_rt_timer_init(void)
|
|||
uint16_t pre;
|
||||
uint16_t ticks;
|
||||
|
||||
spin_lock_init(&priv->lock);
|
||||
tim = esp32s2_tim_init(SYSTIMER_COMP0);
|
||||
|
||||
if (tim == NULL)
|
||||
|
|
@ -775,7 +754,7 @@ int esp32s2_rt_timer_init(void)
|
|||
priv->pid = (pid_t)pid;
|
||||
priv->timer = tim;
|
||||
|
||||
flags = spin_lock_irqsave(&priv->lock);
|
||||
flags = enter_critical_section();
|
||||
|
||||
/* ESP32-S2 hardware timer configuration, acc. TRM V1.0
|
||||
* Systimer is clocked by APB_CLK.
|
||||
|
|
@ -819,7 +798,7 @@ int esp32s2_rt_timer_init(void)
|
|||
ESP32S2_TIM_SETISR(priv->timer, rt_timer_isr, NULL);
|
||||
ESP32S2_TIM_ENABLEINT(priv->timer);
|
||||
|
||||
spin_unlock_irqrestore(&priv->lock, flags);
|
||||
leave_critical_section(flags);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -843,14 +822,14 @@ void esp32s2_rt_timer_deinit(void)
|
|||
irqstate_t flags;
|
||||
struct esp32s2_rt_priv_s *priv = &g_rt_priv;
|
||||
|
||||
flags = spin_lock_irqsave(&priv->lock);
|
||||
flags = enter_critical_section();
|
||||
|
||||
ESP32S2_TIM_DISABLEINT(priv->timer);
|
||||
ESP32S2_TIM_SETISR(priv->timer, NULL, NULL);
|
||||
esp32s2_tim_deinit(priv->timer);
|
||||
priv->timer = NULL;
|
||||
|
||||
spin_unlock_irqrestore(&priv->lock, flags);
|
||||
leave_critical_section(flags);
|
||||
|
||||
if (priv->pid != INVALID_PROCESS_ID)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -32,10 +32,9 @@
|
|||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <sched.h>
|
||||
|
||||
#include <nuttx/nuttx.h>
|
||||
#include <nuttx/spinlock.h>
|
||||
#include <nuttx/irq.h>
|
||||
#include <nuttx/kmalloc.h>
|
||||
#include <nuttx/kthread.h>
|
||||
#include <nuttx/semaphore.h>
|
||||
|
|
@ -612,8 +611,7 @@ static int rt_timer_isr(int irq, void *context, void *arg)
|
|||
|
||||
modifyreg32(SYSTIMER_INT_CLR_REG, 0, SYSTIMER_TARGET2_INT_CLR);
|
||||
|
||||
flags = spin_lock_irqsave(&priv->lock);
|
||||
sched_lock();
|
||||
flags = enter_critical_section();
|
||||
|
||||
/* Check if there is a timer running */
|
||||
|
||||
|
|
@ -674,8 +672,7 @@ static int rt_timer_isr(int irq, void *context, void *arg)
|
|||
}
|
||||
}
|
||||
|
||||
spin_unlock_irqrestore(&priv->lock, flags);
|
||||
sched_unlock();
|
||||
leave_critical_section(flags);
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
|
@ -808,8 +805,7 @@ void esp32s3_rt_timer_delete(struct rt_timer_s *timer)
|
|||
irqstate_t flags;
|
||||
struct esp32s3_rt_priv_s *priv = &g_rt_priv;
|
||||
|
||||
flags = spin_lock_irqsave(&priv->lock);
|
||||
sched_lock();
|
||||
flags = enter_critical_section();
|
||||
|
||||
if (timer->state == RT_TIMER_READY)
|
||||
{
|
||||
|
|
@ -836,8 +832,7 @@ void esp32s3_rt_timer_delete(struct rt_timer_s *timer)
|
|||
}
|
||||
|
||||
exit:
|
||||
spin_unlock_irqrestore(&priv->lock, flags);
|
||||
sched_unlock();
|
||||
leave_critical_section(flags);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
|
|
@ -954,8 +949,6 @@ int esp32s3_rt_timer_init(void)
|
|||
irqstate_t flags;
|
||||
struct esp32s3_rt_priv_s *priv = &g_rt_priv;
|
||||
|
||||
spin_lock_init(&priv->lock);
|
||||
|
||||
pid = kthread_create(RT_TIMER_TASK_NAME,
|
||||
RT_TIMER_TASK_PRIORITY,
|
||||
RT_TIMER_TASK_STACK_SIZE,
|
||||
|
|
@ -972,7 +965,7 @@ int esp32s3_rt_timer_init(void)
|
|||
|
||||
priv->pid = (pid_t)pid;
|
||||
|
||||
flags = spin_lock_irqsave(&priv->lock);
|
||||
flags = enter_critical_section();
|
||||
|
||||
/* ESP32-S3 hardware timer configuration:
|
||||
* 1 count = 1/16 us
|
||||
|
|
@ -1014,7 +1007,7 @@ int esp32s3_rt_timer_init(void)
|
|||
|
||||
modifyreg32(SYSTIMER_CONF_REG, 0, SYSTIMER_TIMER_UNIT1_WORK_EN);
|
||||
|
||||
spin_unlock_irqrestore(&priv->lock, flags);
|
||||
leave_critical_section(flags);
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue