risc-v/esp32-c3: Reorganize the timer logic for wireless use

This commit is contained in:
Sara Souza 2021-04-14 08:23:10 -03:00 committed by Xiang Xiao
parent 0c440cfdfe
commit 5c562c1068
3 changed files with 13 additions and 49 deletions

View File

@ -57,6 +57,7 @@
#define RT_TIMER_TASK_STACK_SIZE CONFIG_ESP32C3_RT_TIMER_TASK_STACK_SIZE
#define ESP32C3_TIMER_PRESCALER (APB_CLK_FREQ / (1000 * 1000))
#define ESP32C3_RT_TIMER 0 /* Timer 0 */
/****************************************************************************
* Private Data
@ -597,7 +598,7 @@ int esp32c3_rt_timer_init(void)
irqstate_t flags;
struct esp32c3_tim_dev_s *tim;
tim = esp32c3_tim0_init();
tim = esp32c3_tim_init(ESP32C3_RT_TIMER);
if (!tim)
{
tmrerr("ERROR: Failed to initialize ESP32 timer0\n");
@ -669,6 +670,7 @@ void esp32c3_rt_timer_deinit(void)
flags = enter_critical_section();
ESP32C3_TIM_STOP(s_esp32c3_tim_dev);
esp32c3_tim_deinit(s_esp32c3_tim_dev);
s_esp32c3_tim_dev = NULL;
leave_critical_section(flags);

View File

@ -662,9 +662,7 @@ static void esp32c3_tim_ackint(FAR struct esp32c3_tim_dev_s *dev)
* Name: esp32c3_tim_init
*
* Description:
* Initialize TIMER device, if software real-time timer
* (CONFIG_ESP32C3_RT_TIMER) is enabled, then timer0 can't
* be initialized by this function directly.
* Initialize TIMER device.
*
* Parameters:
* timer - Timer instance to be initialized.
@ -681,11 +679,11 @@ FAR struct esp32c3_tim_dev_s *esp32c3_tim_init(int timer)
{
FAR struct esp32c3_tim_priv_s *tim = NULL;
/* Get timer instance */
/* First, take the data structure associated with the timer instance */
switch (timer)
{
#if defined(CONFIG_ESP32C3_TIMER0) && !defined(CONFIG_ESP32C3_RT_TIMER)
#ifdef CONFIG_ESP32C3_TIMER0
case 0:
{
tim = &g_esp32c3_tim0_priv;
@ -708,7 +706,13 @@ FAR struct esp32c3_tim_dev_s *esp32c3_tim_init(int timer)
}
}
if (tim->inuse == true)
/* Verify if it is in use */
if (tim->inuse == false)
{
tim->inuse = true; /* If it was not, now it is */
}
else
{
tmrerr("ERROR: TIMER %d is already in use\n", timer);
tim = NULL;
@ -738,37 +742,3 @@ void esp32c3_tim_deinit(FAR struct esp32c3_tim_dev_s *dev)
tim = (FAR struct esp32c3_tim_priv_s *)dev;
tim->inuse = false;
}
/****************************************************************************
* Name: esp32c3_tim0_init
*
* Description:
* Initialize TIMER0 device, if software real-time timer
* (CONFIG_ESP32C3_RT_TIMER) is enabled.
*
* Parameters:
* None
*
* Returned Values:
* If the initialization is successful, return a pointer to the timer
* driver struct associated to that timer instance.
* In case it fails, return NULL.
*
****************************************************************************/
#ifdef CONFIG_ESP32C3_RT_TIMER
FAR struct esp32c3_tim_dev_s *esp32c3_tim0_init(void)
{
FAR struct esp32c3_tim_priv_s *tim = &g_esp32c3_tim0_priv;
if (tim->inuse == true)
{
tmrerr("ERROR: TIMER0 is already in use\n");
tim = NULL;
}
return (FAR struct esp32c3_tim_dev_s *)tim;
}
#endif

View File

@ -135,12 +135,4 @@ struct esp32c3_tim_ops_s
FAR struct esp32c3_tim_dev_s *esp32c3_tim_init(int timer);
void esp32c3_tim_deinit(FAR struct esp32c3_tim_dev_s *dev);
/****************************************************************************
* The Timer0 is used by RT-Timer of wireless driver, so please don't use it
* in any other components.
****************************************************************************/
#ifdef CONFIG_ESP32C3_RT_TIMER
FAR struct esp32c3_tim_dev_s *esp32c3_tim0_init(void);
#endif
#endif /* __ARCH_RISCV_SRC_ESP32C3_ESP32C3_TIM_H */