mirror of
https://github.com/apache/nuttx.git
synced 2026-06-05 15:58:59 +08:00
xtensa/esp32: Reorganize the timer logic for wireless use
This commit is contained in:
@@ -57,6 +57,7 @@
|
|||||||
#define RT_TIMER_TASK_STACK_SIZE CONFIG_ESP32_RT_TIMER_TASK_STACK_SIZE
|
#define RT_TIMER_TASK_STACK_SIZE CONFIG_ESP32_RT_TIMER_TASK_STACK_SIZE
|
||||||
|
|
||||||
#define ESP32_TIMER_PRESCALER (APB_CLK_FREQ / (1000 * 1000))
|
#define ESP32_TIMER_PRESCALER (APB_CLK_FREQ / (1000 * 1000))
|
||||||
|
#define ESP32_RT_TIMER 0 /* Timer 0 */
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Private Data
|
* Private Data
|
||||||
@@ -597,7 +598,7 @@ int esp32_rt_timer_init(void)
|
|||||||
irqstate_t flags;
|
irqstate_t flags;
|
||||||
struct esp32_tim_dev_s *tim;
|
struct esp32_tim_dev_s *tim;
|
||||||
|
|
||||||
tim = esp32_tim0_init();
|
tim = esp32_tim_init(ESP32_RT_TIMER);
|
||||||
if (!tim)
|
if (!tim)
|
||||||
{
|
{
|
||||||
tmrerr("ERROR: Failed to initialize ESP32 timer0\n");
|
tmrerr("ERROR: Failed to initialize ESP32 timer0\n");
|
||||||
@@ -669,6 +670,7 @@ void esp32_rt_timer_deinit(void)
|
|||||||
flags = enter_critical_section();
|
flags = enter_critical_section();
|
||||||
|
|
||||||
ESP32_TIM_STOP(s_esp32_tim_dev);
|
ESP32_TIM_STOP(s_esp32_tim_dev);
|
||||||
|
esp32_tim_deinit(s_esp32_tim_dev);
|
||||||
s_esp32_tim_dev = NULL;
|
s_esp32_tim_dev = NULL;
|
||||||
|
|
||||||
leave_critical_section(flags);
|
leave_critical_section(flags);
|
||||||
|
|||||||
@@ -732,9 +732,7 @@ static int esp32_tim_checkint(FAR struct esp32_tim_dev_s *dev)
|
|||||||
* Name: esp32_tim_init
|
* Name: esp32_tim_init
|
||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
* Initialize TIMER device, if software real-time timer
|
* Initialize TIMER device.
|
||||||
* (CONFIG_ESP32_RT_TIMER) is enabled, then timer0 can't
|
|
||||||
* be initialized by this function directly.
|
|
||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
@@ -746,7 +744,7 @@ FAR struct esp32_tim_dev_s *esp32_tim_init(int timer)
|
|||||||
|
|
||||||
switch (timer)
|
switch (timer)
|
||||||
{
|
{
|
||||||
#if defined(CONFIG_ESP32_TIMER0) && !defined(CONFIG_ESP32_RT_TIMER)
|
#ifdef CONFIG_ESP32_TIMER0
|
||||||
case 0:
|
case 0:
|
||||||
{
|
{
|
||||||
tim = &g_esp32_tim0_priv;
|
tim = &g_esp32_tim0_priv;
|
||||||
@@ -819,29 +817,3 @@ void esp32_tim_deinit(FAR struct esp32_tim_dev_s *dev)
|
|||||||
|
|
||||||
tim->inuse = false;
|
tim->inuse = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Name: esp32_tim0_init
|
|
||||||
*
|
|
||||||
* Description:
|
|
||||||
* Initialize TIMER0 device, this function is only used by software
|
|
||||||
* real-time timer(esp32_rt_timer.c).
|
|
||||||
*
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
#ifdef CONFIG_ESP32_RT_TIMER
|
|
||||||
|
|
||||||
FAR struct esp32_tim_dev_s *esp32_tim0_init(void)
|
|
||||||
{
|
|
||||||
FAR struct esp32_tim_priv_s *tim = &g_esp32_tim0_priv;
|
|
||||||
|
|
||||||
if (tim->inuse == true)
|
|
||||||
{
|
|
||||||
tmrerr("ERROR: Timer0 is already in use\n");
|
|
||||||
tim = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (FAR struct esp32_tim_dev_s *)tim;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif /* CONFIG_ESP32_RT_TIMER */
|
|
||||||
|
|||||||
@@ -116,6 +116,5 @@ struct esp32_tim_ops_s
|
|||||||
|
|
||||||
FAR struct esp32_tim_dev_s *esp32_tim_init(int timer);
|
FAR struct esp32_tim_dev_s *esp32_tim_init(int timer);
|
||||||
void esp32_tim_deinit(FAR struct esp32_tim_dev_s *dev);
|
void esp32_tim_deinit(FAR struct esp32_tim_dev_s *dev);
|
||||||
FAR struct esp32_tim_dev_s *esp32_tim0_init(void);
|
|
||||||
|
|
||||||
#endif /* __ARCH_XTENSA_SRC_ESP32_ESP32_TIM_H */
|
#endif /* __ARCH_XTENSA_SRC_ESP32_ESP32_TIM_H */
|
||||||
|
|||||||
@@ -202,7 +202,7 @@ int esp32_bringup(void)
|
|||||||
|
|
||||||
#ifdef CONFIG_TIMER
|
#ifdef CONFIG_TIMER
|
||||||
|
|
||||||
#ifdef CONFIG_ESP32_TIMER0
|
#if defined(CONFIG_ESP32_TIMER0) && !defined(CONFIG_ESP32_RT_TIMER)
|
||||||
ret = esp32_timer_initialize("/dev/timer0", TIMER0);
|
ret = esp32_timer_initialize("/dev/timer0", TIMER0);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -169,7 +169,7 @@ int esp32_bringup(void)
|
|||||||
|
|
||||||
#ifdef CONFIG_TIMER
|
#ifdef CONFIG_TIMER
|
||||||
|
|
||||||
#ifdef CONFIG_ESP32_TIMER0
|
#if defined(CONFIG_ESP32_TIMER0) && !defined(CONFIG_ESP32_RT_TIMER)
|
||||||
ret = esp32_timer_initialize("/dev/timer0", TIMER0);
|
ret = esp32_timer_initialize("/dev/timer0", TIMER0);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -189,7 +189,7 @@ int esp32_bringup(void)
|
|||||||
|
|
||||||
#ifdef CONFIG_TIMER
|
#ifdef CONFIG_TIMER
|
||||||
|
|
||||||
#ifdef CONFIG_ESP32_TIMER0
|
#if defined(CONFIG_ESP32_TIMER0) && !defined(CONFIG_ESP32_RT_TIMER)
|
||||||
ret = esp32_timer_initialize("/dev/timer0", TIMER0);
|
ret = esp32_timer_initialize("/dev/timer0", TIMER0);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user