diff --git a/Documentation/reference/os/nuttx.rst b/Documentation/reference/os/nuttx.rst index 8651d00a7d6..5678d2d9bac 100644 --- a/Documentation/reference/os/nuttx.rst +++ b/Documentation/reference/os/nuttx.rst @@ -32,16 +32,6 @@ OS List Management APIs **Assumptions**: Base code implementation assumes that this function is called from interrupt handling logic with interrupts disabled. -.. c:function:: void nxsched_alarm_expiration(void); - - If ``CONFIG_SCHED_TICKLESS`` is defined, then this - function is provided by the RTOS base code and called from - platform-specific code when the interval timer used to implemented - the tick-less OS expires. - - **Assumptions**: Base code implementation assumes that this - function is called from interrupt handling logic with interrupts disabled. - .. c:function:: void irq_dispatch(int irq, FAR void *context) This function must be called from the diff --git a/Documentation/reference/os/time_clock.rst b/Documentation/reference/os/time_clock.rst index 49d88b057a4..7b09710ca17 100644 --- a/Documentation/reference/os/time_clock.rst +++ b/Documentation/reference/os/time_clock.rst @@ -372,7 +372,6 @@ In addition to these imported interfaces, the RTOS will export the following interfaces for use by the platform-specific interval timer implementation: -- ``nxsched_alarm_expiration()``: called by the platform-specific logic when the alarm expires. - ``nxsched_timer_expiration()``: called by the platform-specific logic when the interval time expires. .. c:function:: void archname_timer_initialize(void) diff --git a/arch/arm/src/imxrt/imxrt_tickless.c b/arch/arm/src/imxrt/imxrt_tickless.c index 038bf29dbfd..406bd23cb08 100644 --- a/arch/arm/src/imxrt/imxrt_tickless.c +++ b/arch/arm/src/imxrt/imxrt_tickless.c @@ -168,7 +168,6 @@ static uint64_t imxrt_get_counter(void) static void imxrt_interval_handler(void) { - struct timespec tv; uint32_t regval; /* Disable the compare interrupt for now */ @@ -184,8 +183,7 @@ static void imxrt_interval_handler(void) g_tickless.pending = false; - up_timer_gettime(&tv); - nxsched_alarm_expiration(&tv); + nxsched_timer_expiration(); } /**************************************************************************** @@ -479,7 +477,7 @@ int up_timer_gettime(struct timespec *ts) * Name: up_alarm_start * * Description: - * Start the alarm. nxsched_alarm_expiration() will be called when the + * Start the alarm. nxsched_timer_expiration() will be called when the * alarm occurs (unless up_alaram_cancel is called to stop it). * * Provided by platform-specific code and called from the RTOS base code. @@ -487,7 +485,7 @@ int up_timer_gettime(struct timespec *ts) * Input Parameters: * ts - The time in the future at the alarm is expected to occur. When * the alarm occurs the timer logic will call - * nxsched_alarm_expiration(). + * nxsched_timer_expiration(). * * Returned Value: * Zero (OK) is returned on success; a negated errno value is returned on @@ -555,7 +553,7 @@ int up_alarm_start(const struct timespec *ts) * Description: * Cancel the alarm and return the time of cancellation of the alarm. * These two steps need to be as nearly atomic as possible. - * nxsched_alarm_expiration() will not be called unless the alarm is + * nxsched_timer_expiration() will not be called unless the alarm is * restarted with up_alarm_start(). * * If, as a race condition, the alarm has already expired when this diff --git a/arch/arm/src/lpc43xx/lpc43_rit.c b/arch/arm/src/lpc43xx/lpc43_rit.c index 5ffd836a18c..0188723a8d5 100644 --- a/arch/arm/src/lpc43xx/lpc43_rit.c +++ b/arch/arm/src/lpc43xx/lpc43_rit.c @@ -68,7 +68,6 @@ static double sec_per_tick; static uint64_t g_internal_timer; static uint64_t g_alarm; -struct timespec g_ts; /**************************************************************************** * Private Functions @@ -87,9 +86,7 @@ static int lpc43_rit_isr(int irq, void *context, void *arg) { /* handle expired alarm */ - g_ts.tv_sec = (uint32_t)(g_internal_timer / 1000000000); - g_ts.tv_nsec = (uint32_t)(g_internal_timer % 1000000000); - nxsched_alarm_expiration(&g_ts); + nxsched_timer_expiration(); } leave_critical_section(flags); diff --git a/arch/arm/src/lpc43xx/lpc43_tickless_rit.c b/arch/arm/src/lpc43xx/lpc43_tickless_rit.c index 953329223eb..8c08db6b8b6 100644 --- a/arch/arm/src/lpc43xx/lpc43_tickless_rit.c +++ b/arch/arm/src/lpc43xx/lpc43_tickless_rit.c @@ -496,13 +496,7 @@ static inline void lpc43_tl_alarm(uint32_t curr) lpc43_tl_init_timer_vars(); lpc43_tl_set_default_compare(curr); -#ifdef CONFIG_SCHED_TICKLESS_ALARM - struct timespec ts; - up_timer_gettime(&ts); - nxsched_alarm_expiration(&ts); -#else nxsched_timer_expiration(); -#endif } /* Interrupt handler */ diff --git a/arch/arm/src/lpc54xx/lpc54_tickless.c b/arch/arm/src/lpc54xx/lpc54_tickless.c index b9559840bdc..dedd2a00db9 100644 --- a/arch/arm/src/lpc54xx/lpc54_tickless.c +++ b/arch/arm/src/lpc54xx/lpc54_tickless.c @@ -539,13 +539,7 @@ static inline void lpc54_tl_alarm(uint64_t curr) lpc54_init_timer_vars(); lpc54_set_default_compare(curr); -#ifdef CONFIG_SCHED_TICKLESS_ALARM - struct timespec ts; - up_timer_gettime(&ts); - nxsched_alarm_expiration(&ts); -#else nxsched_timer_expiration(); -#endif } /* Interrupt handler */ diff --git a/arch/arm/src/nrf52/nrf52_tickless_rtc.c b/arch/arm/src/nrf52/nrf52_tickless_rtc.c index fb87024b7c9..78aeb7f6888 100644 --- a/arch/arm/src/nrf52/nrf52_tickless_rtc.c +++ b/arch/arm/src/nrf52/nrf52_tickless_rtc.c @@ -187,6 +187,25 @@ static void rtc_prepare_alarm(void) } } +/**************************************************************************** + * Name: rtc_cancel_ack + ****************************************************************************/ + +static void rtc_cancel_ack(void) +{ + irqstate_t flags; + + flags = enter_critical_section(); + + NRF52_RTC_DISABLEINT(g_tickless_dev.rtc, NRF52_RTC_EVT_COMPARE0); + NRF52_RTC_ACKINT(g_tickless_dev.rtc, NRF52_RTC_EVT_COMPARE0); + g_tickless_dev.alarm_set = false; + + leave_critical_section(flags); + + return OK; +} + /**************************************************************************** * Name: rtc_handler ****************************************************************************/ @@ -221,15 +240,13 @@ static int rtc_handler(int irq, void *context, void *arg) if (NRF52_RTC_CHECKINT(g_tickless_dev.rtc, NRF52_RTC_EVT_COMPARE0)) { - struct timespec now; + /* cancel the alarm and ack the event */ - /* cancel alarm and get current time */ - - up_alarm_cancel(&now); + rtc_cancel_ack(); /* let scheduler now of alarm firing */ - nxsched_alarm_expiration(&now); + nxsched_timer_expiration(); } leave_critical_section(flags); @@ -254,13 +271,14 @@ int up_alarm_cancel(struct timespec *ts) NRF52_RTC_DISABLEINT(g_tickless_dev.rtc, NRF52_RTC_EVT_COMPARE0); NRF52_RTC_GETCOUNTER(g_tickless_dev.rtc, &counter); - rtc_counter_to_ts(counter, ts); NRF52_RTC_ACKINT(g_tickless_dev.rtc, NRF52_RTC_EVT_COMPARE0); g_tickless_dev.alarm_set = false; leave_critical_section(flags); + rtc_counter_to_ts(counter, ts); + return OK; } @@ -310,8 +328,6 @@ int up_timer_gettime(struct timespec *ts) void up_timer_initialize(void) { - struct timespec ts; - memset(&g_tickless_dev, 0, sizeof(struct nrf52_tickless_dev_s)); g_tickless_dev.rtc = nrf52_rtc_init(CONFIG_NRF52_SYSTIMER_RTC_INSTANCE); @@ -341,6 +357,5 @@ void up_timer_initialize(void) /* kick off alarm scheduling */ - ts.tv_sec = ts.tv_nsec = 0; - nxsched_alarm_expiration(&ts); + nxsched_timer_expiration(); } diff --git a/arch/arm/src/nrf53/nrf53_tickless_rtc.c b/arch/arm/src/nrf53/nrf53_tickless_rtc.c index 5ef56ef4196..0af41431673 100644 --- a/arch/arm/src/nrf53/nrf53_tickless_rtc.c +++ b/arch/arm/src/nrf53/nrf53_tickless_rtc.c @@ -185,6 +185,25 @@ static void rtc_prepare_alarm(void) } } +/**************************************************************************** + * Name: rtc_cancel_ack + ****************************************************************************/ + +static void rtc_cancel_ack(void) +{ + irqstate_t flags; + + flags = enter_critical_section(); + + NRF53_RTC_DISABLEINT(g_tickless_dev.rtc, NRF53_RTC_EVT_COMPARE0); + NRF53_RTC_ACKINT(g_tickless_dev.rtc, NRF53_RTC_EVT_COMPARE0); + g_tickless_dev.alarm_set = false; + + leave_critical_section(flags); + + return OK; +} + /**************************************************************************** * Name: rtc_handler ****************************************************************************/ @@ -219,15 +238,13 @@ static int rtc_handler(int irq, void *context, void *arg) if (NRF53_RTC_CHECKINT(g_tickless_dev.rtc, NRF53_RTC_EVT_COMPARE0)) { - struct timespec now; + /* cancel the alarm and ack the event */ - /* cancel alarm and get current time */ - - up_alarm_cancel(&now); + rtc_cancel_ack(); /* let scheduler now of alarm firing */ - nxsched_alarm_expiration(&now); + nxsched_timer_expiration(); } leave_critical_section(flags); @@ -252,13 +269,14 @@ int up_alarm_cancel(struct timespec *ts) NRF53_RTC_DISABLEINT(g_tickless_dev.rtc, NRF53_RTC_EVT_COMPARE0); NRF53_RTC_GETCOUNTER(g_tickless_dev.rtc, &counter); - rtc_counter_to_ts(counter, ts); NRF53_RTC_ACKINT(g_tickless_dev.rtc, NRF53_RTC_EVT_COMPARE0); g_tickless_dev.alarm_set = false; leave_critical_section(flags); + rtc_counter_to_ts(counter, ts); + return OK; } @@ -308,8 +326,6 @@ int up_timer_gettime(struct timespec *ts) void up_timer_initialize(void) { - struct timespec ts; - memset(&g_tickless_dev, 0, sizeof(struct nrf53_tickless_dev_s)); g_tickless_dev.rtc = nrf53_rtc_init(CONFIG_NRF53_SYSTIMER_RTC_INSTANCE); @@ -339,6 +355,5 @@ void up_timer_initialize(void) /* kick off alarm scheduling */ - ts.tv_sec = ts.tv_nsec = 0; - nxsched_alarm_expiration(&ts); + nxsched_timer_expiration(); } diff --git a/arch/arm/src/nrf91/nrf91_tickless_rtc.c b/arch/arm/src/nrf91/nrf91_tickless_rtc.c index 227059058e3..4165c01f361 100644 --- a/arch/arm/src/nrf91/nrf91_tickless_rtc.c +++ b/arch/arm/src/nrf91/nrf91_tickless_rtc.c @@ -185,6 +185,21 @@ static void rtc_prepare_alarm(void) } } +static void rtc_cancel_ack(void) +{ + irqstate_t flags; + + flags = enter_critical_section(); + + NRF91_RTC_DISABLEINT(g_tickless_dev.rtc, NRF91_RTC_EVT_COMPARE0); + NRF91_RTC_ACKINT(g_tickless_dev.rtc, NRF91_RTC_EVT_COMPARE0); + g_tickless_dev.alarm_set = false; + + leave_critical_section(flags); + + return OK; +} + /**************************************************************************** * Name: rtc_handler ****************************************************************************/ @@ -219,15 +234,13 @@ static int rtc_handler(int irq, void *context, void *arg) if (NRF91_RTC_CHECKINT(g_tickless_dev.rtc, NRF91_RTC_EVT_COMPARE0)) { - struct timespec now; + /* cancel the alarm and ack the event */ - /* cancel alarm and get current time */ - - up_alarm_cancel(&now); + rtc_cancel_ack(); /* let scheduler now of alarm firing */ - nxsched_alarm_expiration(&now); + nxsched_timer_expiration(); } leave_critical_section(flags); @@ -252,13 +265,14 @@ int up_alarm_cancel(struct timespec *ts) NRF91_RTC_DISABLEINT(g_tickless_dev.rtc, NRF91_RTC_EVT_COMPARE0); NRF91_RTC_GETCOUNTER(g_tickless_dev.rtc, &counter); - rtc_counter_to_ts(counter, ts); NRF91_RTC_ACKINT(g_tickless_dev.rtc, NRF91_RTC_EVT_COMPARE0); g_tickless_dev.alarm_set = false; leave_critical_section(flags); + rtc_counter_to_ts(counter, ts); + return OK; } @@ -308,8 +322,6 @@ int up_timer_gettime(struct timespec *ts) void up_timer_initialize(void) { - struct timespec ts; - memset(&g_tickless_dev, 0, sizeof(struct nrf91_tickless_dev_s)); g_tickless_dev.rtc = nrf91_rtc_init(CONFIG_NRF91_SYSTIMER_RTC_INSTANCE); @@ -339,6 +351,5 @@ void up_timer_initialize(void) /* kick off alarm scheduling */ - ts.tv_sec = ts.tv_nsec = 0; - nxsched_alarm_expiration(&ts); + nxsched_timer_expiration(); } diff --git a/arch/arm/src/stm32f7/stm32_tickless.c b/arch/arm/src/stm32f7/stm32_tickless.c index cd2306799e2..fcb9d1b5e3d 100644 --- a/arch/arm/src/stm32f7/stm32_tickless.c +++ b/arch/arm/src/stm32f7/stm32_tickless.c @@ -313,9 +313,6 @@ static int stm32_tickless_setchannel(uint8_t channel) static void stm32_interval_handler(void) { -#ifdef CONFIG_SCHED_TICKLESS_ALARM - struct timespec tv; -#endif tmrinfo("Expired...\n"); /* Disable the compare interrupt now. */ @@ -325,12 +322,7 @@ static void stm32_interval_handler(void) g_tickless.pending = false; -#ifndef CONFIG_SCHED_TICKLESS_ALARM nxsched_timer_expiration(); -#else - up_timer_gettime(&tv); - nxsched_alarm_expiration(&tv); -#endif } /**************************************************************************** diff --git a/arch/arm/src/stm32h7/stm32_tickless.c b/arch/arm/src/stm32h7/stm32_tickless.c index df430af24d6..feb5d85c754 100644 --- a/arch/arm/src/stm32h7/stm32_tickless.c +++ b/arch/arm/src/stm32h7/stm32_tickless.c @@ -300,9 +300,6 @@ static int stm32_tickless_setchannel(uint8_t channel) static void stm32_interval_handler(void) { -#ifdef CONFIG_SCHED_TICKLESS_ALARM - struct timespec tv; -#endif tmrinfo("Expired...\n"); /* Disable the compare interrupt now. */ @@ -312,12 +309,7 @@ static void stm32_interval_handler(void) g_tickless.pending = false; -#ifndef CONFIG_SCHED_TICKLESS_ALARM nxsched_timer_expiration(); -#else - up_timer_gettime(&tv); - nxsched_alarm_expiration(&tv); -#endif } /**************************************************************************** diff --git a/arch/arm/src/xmc4/xmc4_tickless.c b/arch/arm/src/xmc4/xmc4_tickless.c index c05a9c3a2ae..ce7e35b0a8d 100644 --- a/arch/arm/src/xmc4/xmc4_tickless.c +++ b/arch/arm/src/xmc4/xmc4_tickless.c @@ -385,7 +385,7 @@ int up_timer_gettime(struct timespec *ts) * Name: up_alarm_start * * Description: - * Start the alarm. nxsched_alarm_expiration() will be called when the + * Start the alarm. nxsched_timer_expiration() will be called when the * alarm occurs (unless up_alaram_cancel is called to stop it). * * Provided by platform-specific code and called from the RTOS base code. @@ -393,7 +393,7 @@ int up_timer_gettime(struct timespec *ts) * Input Parameters: * ts - The time in the future at the alarm is expected to occur. When * the alarm occurs the timer logic will call - * nxsched_alarm_expiration(). + * nxsched_timer_expiration(). * * Returned Value: * Zero (OK) is returned on success; a negated errno value is returned on @@ -466,7 +466,7 @@ int up_timer_start(const struct timespec *ts) * Description: * Cancel the alarm and return the time of cancellation of the alarm. * These two steps need to be as nearly atomic as possible. - * nxsched_alarm_expiration() will not be called unless the alarm is + * nxsched_timer_expiration() will not be called unless the alarm is * restarted with up_alarm_start(). * * If, as a race condition, the alarm has already expired when this diff --git a/arch/avr/src/avrdx/avrdx_timerisr_tickless_alarm.c b/arch/avr/src/avrdx/avrdx_timerisr_tickless_alarm.c index 1555fa11e45..070dc00f345 100644 --- a/arch/avr/src/avrdx/avrdx_timerisr_tickless_alarm.c +++ b/arch/avr/src/avrdx/avrdx_timerisr_tickless_alarm.c @@ -277,8 +277,7 @@ static void avrdx_check_alarm_expired(uint8_t context) */ avrdx_deactivate_alarm(); - up_timer_gettime(&tv); - nxsched_alarm_expiration(&tv); + nxsched_timer_expiration(); } else { diff --git a/drivers/timers/arch_alarm.c b/drivers/timers/arch_alarm.c index 8d6e0eeb29a..46b2c60d06e 100644 --- a/drivers/timers/arch_alarm.c +++ b/drivers/timers/arch_alarm.c @@ -301,7 +301,7 @@ int weak_function up_timer_gettime(struct timespec *ts) * Description: * Cancel the alarm and return the time of cancellation of the alarm. * These two steps need to be as nearly atomic as possible. - * nxsched_alarm_expiration() will not be called unless the alarm is + * nxsched_timer_expiration() will not be called unless the alarm is * restarted with up_alarm_start(). * * If, as a race condition, the alarm has already expired when this @@ -348,14 +348,14 @@ int weak_function up_alarm_tick_cancel(FAR clock_t *ticks) * Name: up_alarm_start * * Description: - * Start the alarm. nxsched_alarm_expiration() will be called when the + * Start the alarm. nxsched_timer_expiration() will be called when the * alarm occurs (unless up_alaram_cancel is called to stop it). * * Provided by platform-specific code and called from the RTOS base code. * * Input Parameters: * ts - The time in the future at the alarm is expected to occur. When the - * alarm occurs the timer logic will call nxsched_alarm_expiration(). + * alarm occurs the timer logic will call nxsched_timer_expiration(). * * Returned Value: * Zero (OK) is returned on success; a negated errno value is returned on diff --git a/include/nuttx/arch.h b/include/nuttx/arch.h index e4660bb03f8..5121d0aa83b 100644 --- a/include/nuttx/arch.h +++ b/include/nuttx/arch.h @@ -1885,13 +1885,8 @@ void up_timer_initialize(void); * The RTOS will provide the following interfaces for use by the platform- * specific interval timer implementation: * - * #ifdef CONFIG_SCHED_TICKLESS_ALARM - * void nxsched_alarm_expiration(FAR const struct timespec *ts): Called - * by the platform-specific logic when the alarm expires. - * #else * void nxsched_timer_expiration(void): Called by the platform-specific * logic when the interval timer expires. - * #endif * ****************************************************************************/ @@ -1938,7 +1933,7 @@ void up_timer_getmask(FAR clock_t *mask); * Description: * Cancel the alarm and return the time of cancellation of the alarm. * These two steps need to be as nearly atomic as possible. - * nxsched_alarm_expiration() will not be called unless the alarm is + * nxsched_timer_expiration() will not be called unless the alarm is * restarted with up_alarm_start(). * * If, as a race condition, the alarm has already expired when this @@ -1978,7 +1973,7 @@ int up_alarm_tick_cancel(FAR clock_t *ticks); * Name: up_alarm_start * * Description: - * Start the alarm. nxsched_alarm_expiration() will be called when the + * Start the alarm. nxsched_timer_expiration() will be called when the * alarm occurs (unless up_alaram_cancel is called to stop it). * * Provided by platform-specific code and called from the RTOS base code. @@ -1986,7 +1981,7 @@ int up_alarm_tick_cancel(FAR clock_t *ticks); * Input Parameters: * ts - The time in the future at the alarm is expected to occur. When * the alarm occurs the timer logic will call - * nxsched_alarm_expiration(). + * nxsched_timer_expiration(). * * Returned Value: * Zero (OK) is returned on success; a negated errno value is returned on @@ -2466,30 +2461,6 @@ void nxsched_process_timer(void); void nxsched_timer_expiration(void); #endif -/**************************************************************************** - * Name: nxsched_alarm_expiration - * - * Description: - * if CONFIG_SCHED_TICKLESS is defined, then this function is provided by - * the RTOS base code and called from platform-specific code when the - * alarm used to implement the tick-less OS expires. - * - * Input Parameters: - * ts - The time that the alarm expired - * - * Returned Value: - * None - * - * Assumptions/Limitations: - * Base code implementation assumes that this function is called from - * interrupt handling logic with interrupts disabled. - * - ****************************************************************************/ - -#if defined(CONFIG_SCHED_TICKLESS) && defined(CONFIG_SCHED_TICKLESS_ALARM) -void nxsched_alarm_expiration(FAR const struct timespec *ts); -#endif - /**************************************************************************** * Name: nxsched_get_next_expired * diff --git a/sched/sched/sched_timerexpiration.c b/sched/sched/sched_timerexpiration.c index a139f154edb..82c86450e1f 100644 --- a/sched/sched/sched_timerexpiration.c +++ b/sched/sched/sched_timerexpiration.c @@ -451,38 +451,6 @@ clock_t nxsched_timer_update(clock_t ticks, bool noswitches) * Public Functions ****************************************************************************/ -/**************************************************************************** - * Name: nxsched_alarm_expiration - * - * Description: - * if CONFIG_SCHED_TICKLESS is defined, then this function is provided by - * the RTOS base code and called from platform-specific code when the - * alarm used to implement the tick-less OS expires. - * - * Input Parameters: - * ts - The time that the alarm expired - * - * Returned Value: - * None - * - * Assumptions/Limitations: - * Base code implementation assumes that this function is called from - * interrupt handling logic with interrupts disabled. - * - ****************************************************************************/ - -#ifdef CONFIG_SCHED_TICKLESS_ALARM -void nxsched_alarm_expiration(FAR const struct timespec *ts) -{ - clock_t ticks; - - DEBUGASSERT(ts); - - ticks = clock_time2ticks_floor(ts); - nxsched_timer_update(ticks, false); -} -#endif - /**************************************************************************** * Name: nxsched_timer_expiration *