From f4f8030be0af79250de05d323106dd34a5e7dc85 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 7 Aug 2014 18:00:38 -0600 Subject: Change all time conversions. Yech. New timer units in microseconds breaks all existing logic that used milliseconds in the conversions. Something likely got broken doing this, probably because I confused a MSEC2TICK conversion with a TICK2MSEC conversion. Also, the tickless OS no appears fully functional and passes the OS test on the simulator with no errors --- apps/examples/ostest/ostest_main.c | 2 +- apps/examples/ostest/restart.c | 2 +- nuttx/arch/8051/src/up_unblocktask.c | 2 +- nuttx/arch/arm/src/arm/up_unblocktask.c | 2 +- nuttx/arch/arm/src/armv6-m/up_unblocktask.c | 2 +- nuttx/arch/arm/src/armv7-a/arm_unblocktask.c | 2 +- nuttx/arch/arm/src/armv7-m/up_unblocktask.c | 2 +- nuttx/arch/arm/src/c5471/c5471_timerisr.c | 4 +-- nuttx/arch/arm/src/dm320/dm320_timerisr.c | 2 +- nuttx/arch/arm/src/imx/imx_timerisr.c | 4 +-- nuttx/arch/arm/src/kinetis/kinetis_sdhc.c | 2 +- nuttx/arch/arm/src/lpc17xx/lpc17_sdcard.c | 2 +- nuttx/arch/arm/src/sam34/sam_hsmci.c | 2 +- nuttx/arch/arm/src/sam34/sam_spi.c | 2 +- nuttx/arch/arm/src/sama5/sam_hsmci.c | 2 +- nuttx/arch/arm/src/sama5/sam_spi.c | 2 +- nuttx/arch/arm/src/sama5/sam_ssc.c | 2 +- nuttx/arch/arm/src/sama5/sam_tsd.c | 2 +- nuttx/arch/arm/src/sama5/sam_twi.c | 2 +- nuttx/arch/arm/src/stm32/stm32_otgfshost.c | 4 +-- nuttx/arch/arm/src/stm32/stm32_sdio.c | 2 +- nuttx/arch/avr/src/avr/up_unblocktask.c | 2 +- nuttx/arch/avr/src/avr32/up_unblocktask.c | 2 +- nuttx/arch/hc/src/common/up_unblocktask.c | 2 +- nuttx/arch/mips/src/mips32/up_unblocktask.c | 2 +- nuttx/arch/rgmp/src/nuttx.c | 2 +- nuttx/arch/sh/src/common/up_unblocktask.c | 2 +- nuttx/arch/sim/src/up_tickless.c | 39 +++++++++++------------ nuttx/arch/sim/src/up_unblocktask.c | 2 +- nuttx/arch/x86/src/common/up_unblocktask.c | 2 +- nuttx/arch/z16/src/common/up_unblocktask.c | 2 +- nuttx/arch/z80/src/common/up_unblocktask.c | 2 +- nuttx/configs/mikroe-stm32f4/src/up_touchscreen.c | 10 +++--- nuttx/configs/pic32mx7mmb/src/up_touchscreen.c | 8 ++--- nuttx/configs/sam4s-xplained-pro/src/sam_tc.c | 4 +-- nuttx/drivers/audio/wm8904.c | 3 ++ nuttx/drivers/input/ads7843e.h | 2 +- nuttx/drivers/input/max11802.h | 2 +- nuttx/drivers/input/stmpe811.h | 2 +- nuttx/drivers/mtd/sst39vf.c | 12 +++---- nuttx/include/nuttx/clock.h | 13 +++++--- nuttx/sched/Kconfig | 3 ++ nuttx/sched/clock_getres.c | 13 ++------ nuttx/sched/clock_gettime.c | 4 +-- nuttx/sched/clock_initialize.c | 4 +-- nuttx/sched/clock_systimer.c | 6 ++-- nuttx/sched/pthread_create.c | 2 +- nuttx/sched/sched_processtimer.c | 4 +-- nuttx/sched/sched_setscheduler.c | 2 +- nuttx/sched/sched_timerexpiration.c | 18 ++++++++--- nuttx/sched/sched_unlock.c | 16 +++++----- nuttx/sched/sig_timedwait.c | 2 +- 52 files changed, 121 insertions(+), 116 deletions(-) diff --git a/apps/examples/ostest/ostest_main.c b/apps/examples/ostest/ostest_main.c index a234e50e6..f7879ed3a 100644 --- a/apps/examples/ostest/ostest_main.c +++ b/apps/examples/ostest/ostest_main.c @@ -322,7 +322,7 @@ static int user_main(int argc, char *argv[]) #endif #ifdef CONFIG_ARCH_FPU - /* Check that the FPU is properly supported during context switching */ + /* Check that the FPU is properly supported during context switching */ printf("\nuser_main: FPU test\n"); fpu_test(); diff --git a/apps/examples/ostest/restart.c b/apps/examples/ostest/restart.c index 2193c8108..0d0f90d07 100644 --- a/apps/examples/ostest/restart.c +++ b/apps/examples/ostest/restart.c @@ -189,5 +189,5 @@ void restart_test(void) sleep(1); } - printf("restart_main: Exitting\n"); + printf("restart_main: Exiting\n"); } diff --git a/nuttx/arch/8051/src/up_unblocktask.c b/nuttx/arch/8051/src/up_unblocktask.c index d285ddbd2..cb4e65fc0 100644 --- a/nuttx/arch/8051/src/up_unblocktask.c +++ b/nuttx/arch/8051/src/up_unblocktask.c @@ -100,7 +100,7 @@ void up_unblock_task(FAR struct tcb_s *tcb) */ #if CONFIG_RR_INTERVAL > 0 - tcb->timeslice = CONFIG_RR_INTERVAL / MSEC_PER_TICK; + tcb->timeslice = MSEC2TICK(CONFIG_RR_INTERVAL); #endif /* Add the task in the correct location in the prioritized diff --git a/nuttx/arch/arm/src/arm/up_unblocktask.c b/nuttx/arch/arm/src/arm/up_unblocktask.c index 64536d959..3476441b4 100644 --- a/nuttx/arch/arm/src/arm/up_unblocktask.c +++ b/nuttx/arch/arm/src/arm/up_unblocktask.c @@ -97,7 +97,7 @@ void up_unblock_task(struct tcb_s *tcb) */ #if CONFIG_RR_INTERVAL > 0 - tcb->timeslice = CONFIG_RR_INTERVAL / MSEC_PER_TICK; + tcb->timeslice = MSEC2TICK(CONFIG_RR_INTERVAL); #endif /* Add the task in the correct location in the prioritized diff --git a/nuttx/arch/arm/src/armv6-m/up_unblocktask.c b/nuttx/arch/arm/src/armv6-m/up_unblocktask.c index 0d51d21ca..7a76a24d8 100644 --- a/nuttx/arch/arm/src/armv6-m/up_unblocktask.c +++ b/nuttx/arch/arm/src/armv6-m/up_unblocktask.c @@ -96,7 +96,7 @@ void up_unblock_task(struct tcb_s *tcb) */ #if CONFIG_RR_INTERVAL > 0 - tcb->timeslice = CONFIG_RR_INTERVAL / MSEC_PER_TICK; + tcb->timeslice = MSEC2TICK(CONFIG_RR_INTERVAL); #endif /* Add the task in the correct location in the prioritized diff --git a/nuttx/arch/arm/src/armv7-a/arm_unblocktask.c b/nuttx/arch/arm/src/armv7-a/arm_unblocktask.c index f08ceeca3..c5ca09092 100644 --- a/nuttx/arch/arm/src/armv7-a/arm_unblocktask.c +++ b/nuttx/arch/arm/src/armv7-a/arm_unblocktask.c @@ -97,7 +97,7 @@ void up_unblock_task(struct tcb_s *tcb) */ #if CONFIG_RR_INTERVAL > 0 - tcb->timeslice = CONFIG_RR_INTERVAL / MSEC_PER_TICK; + tcb->timeslice = MSEC2TICK(CONFIG_RR_INTERVAL); #endif /* Add the task in the correct location in the prioritized diff --git a/nuttx/arch/arm/src/armv7-m/up_unblocktask.c b/nuttx/arch/arm/src/armv7-m/up_unblocktask.c index 551e5b67b..f2455e594 100644 --- a/nuttx/arch/arm/src/armv7-m/up_unblocktask.c +++ b/nuttx/arch/arm/src/armv7-m/up_unblocktask.c @@ -97,7 +97,7 @@ void up_unblock_task(struct tcb_s *tcb) */ #if CONFIG_RR_INTERVAL > 0 - tcb->timeslice = CONFIG_RR_INTERVAL / MSEC_PER_TICK; + tcb->timeslice = MSEC2TICK(CONFIG_RR_INTERVAL); #endif /* Add the task in the correct location in the prioritized diff --git a/nuttx/arch/arm/src/c5471/c5471_timerisr.c b/nuttx/arch/arm/src/c5471/c5471_timerisr.c index 1021fb84a..fc1143162 100644 --- a/nuttx/arch/arm/src/c5471/c5471_timerisr.c +++ b/nuttx/arch/arm/src/c5471/c5471_timerisr.c @@ -53,7 +53,7 @@ ************************************************************/ /* We want the general purpose timer running at the rate - * MSEC_PER_TICK. The C5471 clock is 47.5MHz and we're using + * USEC_PER_TICK. The C5471 clock is 47.5MHz and we're using * a timer PTV value of 3 (3 == divide incoming frequency by * 16) which then yields a 16 bitCLKS_PER_INT value * of 29687. @@ -114,7 +114,7 @@ void up_timer_initialize(void) up_disable_irq(C5471_IRQ_SYSTIMER); /* Start the general purpose timer running in auto-reload mode - * so that an interrupt is generated at the rate MSEC_PER_TICK. + * so that an interrupt is generated at the rate USEC_PER_TICK. */ val = ((CLKS_PER_INT-1) << CLKS_PER_INT_SHIFT) | AR | ST | PTV; diff --git a/nuttx/arch/arm/src/dm320/dm320_timerisr.c b/nuttx/arch/arm/src/dm320/dm320_timerisr.c index a92478aa3..fae340714 100644 --- a/nuttx/arch/arm/src/dm320/dm320_timerisr.c +++ b/nuttx/arch/arm/src/dm320/dm320_timerisr.c @@ -139,7 +139,7 @@ void up_timer_initialize(void) up_disable_irq(DM320_IRQ_SYSTIMER); /* Start timer0 running so that an interrupt is generated at - * the rate MSEC_PER_TICK. + * the rate USEC_PER_TICK. */ putreg16(DM320_TMR0_PRSCL, DM320_TIMER0_TMPRSCL); /* Timer 0 Prescalar */ diff --git a/nuttx/arch/arm/src/imx/imx_timerisr.c b/nuttx/arch/arm/src/imx/imx_timerisr.c index 64db2e06d..d21b804c6 100644 --- a/nuttx/arch/arm/src/imx/imx_timerisr.c +++ b/nuttx/arch/arm/src/imx/imx_timerisr.c @@ -138,11 +138,11 @@ void up_timer_initialize(void) * putreg(0, IMX_TIMER1_TPRER); -- already the case * * Set the compare register so that the COMP interrupt is generated - * with a period of MSEC_PER_TICK. The value IMX_PERCLK1_FREQ/1000 + * with a period of USEC_PER_TICK. The value IMX_PERCLK1_FREQ/1000 * (defined in board.h) is the number of counts in millisecond, so: */ - putreg32((IMX_PERCLK1_FREQ / 1000) * MSEC_PER_TICK, IMX_TIMER1_TCMP); + putreg32(MSEC2TICK(IMX_PERCLK1_FREQ / 1000), IMX_TIMER1_TCMP); /* Configure to provide timer COMP interrupts when TCN increments * to TCMP. diff --git a/nuttx/arch/arm/src/kinetis/kinetis_sdhc.c b/nuttx/arch/arm/src/kinetis/kinetis_sdhc.c index 3ba8c4299..6ff5092e5 100644 --- a/nuttx/arch/arm/src/kinetis/kinetis_sdhc.c +++ b/nuttx/arch/arm/src/kinetis/kinetis_sdhc.c @@ -2409,7 +2409,7 @@ static sdio_eventset_t kinetis_eventwait(FAR struct sdio_dev_s *dev, /* Start the watchdog timer */ - delay = (timeout + (MSEC_PER_TICK-1)) / MSEC_PER_TICK; + delay = MSEC2TICK(timeout); ret = wd_start(priv->waitwdog, delay, (wdentry_t)kinetis_eventtimeout, 1, (uint32_t)priv); if (ret != OK) diff --git a/nuttx/arch/arm/src/lpc17xx/lpc17_sdcard.c b/nuttx/arch/arm/src/lpc17xx/lpc17_sdcard.c index 0fd719f24..d5b143118 100644 --- a/nuttx/arch/arm/src/lpc17xx/lpc17_sdcard.c +++ b/nuttx/arch/arm/src/lpc17xx/lpc17_sdcard.c @@ -2266,7 +2266,7 @@ static sdio_eventset_t lpc17_eventwait(FAR struct sdio_dev_s *dev, /* Start the watchdog timer */ - delay = (timeout + (MSEC_PER_TICK-1)) / MSEC_PER_TICK; + delay = MSEC2TICK(timeout); ret = wd_start(priv->waitwdog, delay, (wdentry_t)lpc17_eventtimeout, 1, (uint32_t)priv); if (ret != OK) diff --git a/nuttx/arch/arm/src/sam34/sam_hsmci.c b/nuttx/arch/arm/src/sam34/sam_hsmci.c index 94d052bd1..d770b2d2b 100644 --- a/nuttx/arch/arm/src/sam34/sam_hsmci.c +++ b/nuttx/arch/arm/src/sam34/sam_hsmci.c @@ -2273,7 +2273,7 @@ static sdio_eventset_t sam_eventwait(FAR struct sdio_dev_s *dev, /* Start the watchdog timer */ - delay = (timeout + (MSEC_PER_TICK-1)) / MSEC_PER_TICK; + delay = MSEC2TICK(timeout); ret = wd_start(priv->waitwdog, delay, (wdentry_t)sam_eventtimeout, 1, (uint32_t)priv); if (ret != OK) diff --git a/nuttx/arch/arm/src/sam34/sam_spi.c b/nuttx/arch/arm/src/sam34/sam_spi.c index 5e32faf69..81c73a76f 100644 --- a/nuttx/arch/arm/src/sam34/sam_spi.c +++ b/nuttx/arch/arm/src/sam34/sam_spi.c @@ -127,7 +127,7 @@ */ #define DMA_TIMEOUT_MS (800) -#define DMA_TIMEOUT_TICKS ((DMA_TIMEOUT_MS + (MSEC_PER_TICK-1)) / MSEC_PER_TICK) +#define DMA_TIMEOUT_TICKS MSEC2TICK(DMA_TIMEOUT_MS) /* Debug *******************************************************************/ /* Check if SPI debut is enabled (non-standard.. no support in diff --git a/nuttx/arch/arm/src/sama5/sam_hsmci.c b/nuttx/arch/arm/src/sama5/sam_hsmci.c index f0a0d3be1..670c3a69f 100644 --- a/nuttx/arch/arm/src/sama5/sam_hsmci.c +++ b/nuttx/arch/arm/src/sama5/sam_hsmci.c @@ -2737,7 +2737,7 @@ static sdio_eventset_t sam_eventwait(FAR struct sdio_dev_s *dev, timeout = MAX(5000, timeout); } - delay = (timeout + (MSEC_PER_TICK-1)) / MSEC_PER_TICK; + delay = MSEC2TICK(timeout); ret = wd_start(priv->waitwdog, delay, (wdentry_t)sam_eventtimeout, 1, (uint32_t)priv); if (ret != OK) diff --git a/nuttx/arch/arm/src/sama5/sam_spi.c b/nuttx/arch/arm/src/sama5/sam_spi.c index 104691077..3a1a4652a 100644 --- a/nuttx/arch/arm/src/sama5/sam_spi.c +++ b/nuttx/arch/arm/src/sama5/sam_spi.c @@ -120,7 +120,7 @@ */ #define DMA_TIMEOUT_MS (800) -#define DMA_TIMEOUT_TICKS ((DMA_TIMEOUT_MS + (MSEC_PER_TICK-1)) / MSEC_PER_TICK) +#define DMA_TIMEOUT_TICKS MSEC2TICK(DMA_TIMEOUT_MS) /* Debug *******************************************************************/ /* Check if SPI debut is enabled (non-standard.. no support in diff --git a/nuttx/arch/arm/src/sama5/sam_ssc.c b/nuttx/arch/arm/src/sama5/sam_ssc.c index 475cf06b2..570b85078 100644 --- a/nuttx/arch/arm/src/sama5/sam_ssc.c +++ b/nuttx/arch/arm/src/sama5/sam_ssc.c @@ -390,7 +390,7 @@ */ #define DMA_TIMEOUT_MS (800) -#define DMA_TIMEOUT_TICKS ((DMA_TIMEOUT_MS + (MSEC_PER_TICK-1)) / MSEC_PER_TICK) +#define DMA_TIMEOUT_TICKS MSEC2TICK(DMA_TIMEOUT_MS) /* Debug *******************************************************************/ /* Check if SSC debut is enabled (non-standard.. no support in diff --git a/nuttx/arch/arm/src/sama5/sam_tsd.c b/nuttx/arch/arm/src/sama5/sam_tsd.c index c3d45307f..fe73afc3d 100644 --- a/nuttx/arch/arm/src/sama5/sam_tsd.c +++ b/nuttx/arch/arm/src/sama5/sam_tsd.c @@ -89,7 +89,7 @@ /* Poll the pen position while the pen is down at this rate (50MS): */ -#define TSD_WDOG_DELAY ((50 + (MSEC_PER_TICK-1))/ MSEC_PER_TICK) +#define TSD_WDOG_DELAY MSEC2TICK(50) /* This is a value for the threshold that guantees a big difference on the * first pendown (but can't overflow). diff --git a/nuttx/arch/arm/src/sama5/sam_twi.c b/nuttx/arch/arm/src/sama5/sam_twi.c index 2e1c6a1a9..eec19f6e6 100644 --- a/nuttx/arch/arm/src/sama5/sam_twi.c +++ b/nuttx/arch/arm/src/sama5/sam_twi.c @@ -527,7 +527,7 @@ static int twi_wait(struct twi_dev_s *priv, unsigned int size) * There is no concern about arithmetic overflow for reasonable transfer sizes. */ - timeout = (TWI_TIMEOUT_MSPB * size) / MSEC_PER_TICK; + timeout = MSEC2TICK(TWI_TIMEOUT_MSPB); if (timeout < 1) { timeout = 1; diff --git a/nuttx/arch/arm/src/stm32/stm32_otgfshost.c b/nuttx/arch/arm/src/stm32/stm32_otgfshost.c index 7866365d9..7fe99c1c3 100644 --- a/nuttx/arch/arm/src/stm32/stm32_otgfshost.c +++ b/nuttx/arch/arm/src/stm32/stm32_otgfshost.c @@ -151,8 +151,8 @@ #define STM32_READY_DELAY 200000 /* In loop counts */ #define STM32_FLUSH_DELAY 200000 /* In loop counts */ -#define STM32_SETUP_DELAY (5000 / MSEC_PER_TICK) /* 5 seconds in system ticks */ -#define STM32_DATANAK_DELAY (5000 / MSEC_PER_TICK) /* 5 seconds in system ticks */ +#define STM32_SETUP_DELAY SEC2TICK(5) /* 5 seconds in system ticks */ +#define STM32_DATANAK_DELAY SEC2TICK(5) /* 5 seconds in system ticks */ /* Ever-present MIN/MAX macros */ diff --git a/nuttx/arch/arm/src/stm32/stm32_sdio.c b/nuttx/arch/arm/src/stm32/stm32_sdio.c index f731ad75c..cc164bc80 100644 --- a/nuttx/arch/arm/src/stm32/stm32_sdio.c +++ b/nuttx/arch/arm/src/stm32/stm32_sdio.c @@ -2315,7 +2315,7 @@ static sdio_eventset_t stm32_eventwait(FAR struct sdio_dev_s *dev, /* Start the watchdog timer */ - delay = (timeout + (MSEC_PER_TICK-1)) / MSEC_PER_TICK; + delay = MSEC2TICK(timeout); ret = wd_start(priv->waitwdog, delay, (wdentry_t)stm32_eventtimeout, 1, (uint32_t)priv); if (ret != OK) diff --git a/nuttx/arch/avr/src/avr/up_unblocktask.c b/nuttx/arch/avr/src/avr/up_unblocktask.c index 305e057a8..6fb2e67e5 100644 --- a/nuttx/arch/avr/src/avr/up_unblocktask.c +++ b/nuttx/arch/avr/src/avr/up_unblocktask.c @@ -97,7 +97,7 @@ void up_unblock_task(struct tcb_s *tcb) */ #if CONFIG_RR_INTERVAL > 0 - tcb->timeslice = CONFIG_RR_INTERVAL / MSEC_PER_TICK; + tcb->timeslice = MSEC2TICK(CONFIG_RR_INTERVAL); #endif /* Add the task in the correct location in the prioritized diff --git a/nuttx/arch/avr/src/avr32/up_unblocktask.c b/nuttx/arch/avr/src/avr32/up_unblocktask.c index 42dc3d52a..f53550da9 100644 --- a/nuttx/arch/avr/src/avr32/up_unblocktask.c +++ b/nuttx/arch/avr/src/avr32/up_unblocktask.c @@ -97,7 +97,7 @@ void up_unblock_task(struct tcb_s *tcb) */ #if CONFIG_RR_INTERVAL > 0 - tcb->timeslice = CONFIG_RR_INTERVAL / MSEC_PER_TICK; + tcb->timeslice = MSEC2TICK(CONFIG_RR_INTERVAL); #endif /* Add the task in the correct location in the prioritized diff --git a/nuttx/arch/hc/src/common/up_unblocktask.c b/nuttx/arch/hc/src/common/up_unblocktask.c index 08cefc1d4..425db0f98 100644 --- a/nuttx/arch/hc/src/common/up_unblocktask.c +++ b/nuttx/arch/hc/src/common/up_unblocktask.c @@ -97,7 +97,7 @@ void up_unblock_task(struct tcb_s *tcb) */ #if CONFIG_RR_INTERVAL > 0 - tcb->timeslice = CONFIG_RR_INTERVAL / MSEC_PER_TICK; + tcb->timeslice = MSEC2TICK(CONFIG_RR_INTERVAL); #endif /* Add the task in the correct location in the prioritized diff --git a/nuttx/arch/mips/src/mips32/up_unblocktask.c b/nuttx/arch/mips/src/mips32/up_unblocktask.c index 277ec79cf..dab958b15 100644 --- a/nuttx/arch/mips/src/mips32/up_unblocktask.c +++ b/nuttx/arch/mips/src/mips32/up_unblocktask.c @@ -99,7 +99,7 @@ void up_unblock_task(struct tcb_s *tcb) */ #if CONFIG_RR_INTERVAL > 0 - tcb->timeslice = CONFIG_RR_INTERVAL / MSEC_PER_TICK; + tcb->timeslice = MSEC2TICK(CONFIG_RR_INTERVAL); #endif /* Add the task in the correct location in the prioritized diff --git a/nuttx/arch/rgmp/src/nuttx.c b/nuttx/arch/rgmp/src/nuttx.c index e6fee5de1..0178ae58a 100644 --- a/nuttx/arch/rgmp/src/nuttx.c +++ b/nuttx/arch/rgmp/src/nuttx.c @@ -326,7 +326,7 @@ void up_unblock_task(struct tcb_s *tcb) * robin tasks but it doesn't here to do it for everything */ #if CONFIG_RR_INTERVAL > 0 - tcb->timeslice = CONFIG_RR_INTERVAL / MSEC_PER_TICK; + tcb->timeslice = MSEC2TICK(CONFIG_RR_INTERVAL); #endif // Add the task in the correct location in the prioritized diff --git a/nuttx/arch/sh/src/common/up_unblocktask.c b/nuttx/arch/sh/src/common/up_unblocktask.c index 5ba0173fb..a4b598499 100644 --- a/nuttx/arch/sh/src/common/up_unblocktask.c +++ b/nuttx/arch/sh/src/common/up_unblocktask.c @@ -97,7 +97,7 @@ void up_unblock_task(struct tcb_s *tcb) */ #if CONFIG_RR_INTERVAL > 0 - tcb->timeslice = CONFIG_RR_INTERVAL / MSEC_PER_TICK; + tcb->timeslice = MSEC2TICK(CONFIG_RR_INTERVAL); #endif /* Add the task in the correct location in the prioritized diff --git a/nuttx/arch/sim/src/up_tickless.c b/nuttx/arch/sim/src/up_tickless.c index 57a793534..4e04cd71e 100644 --- a/nuttx/arch/sim/src/up_tickless.c +++ b/nuttx/arch/sim/src/up_tickless.c @@ -66,6 +66,7 @@ #include #include +#include #ifdef CONFIG_SCHED_TICKLESS @@ -74,12 +75,12 @@ ****************************************************************************/ #if defined(CONFIG_SIM_WALLTIME) || defined(CONFIG_SIM_X11FB) -# define TICK_USEC (1000000 / CLK_TCK) -# define TICK_SEC (TICK_USEC / 1000000) -# define TICK_NSEC ((TICK_USEC % 1000) * 1000) +# define TICK_USEC (USEC_PER_SEC / CLK_TCK) +# define TICK_SEC (TICK_USEC / USEC_PER_SEC) +# define TICK_NSEC ((TICK_USEC % NSEC_PER_USEC) * NSEC_PER_USEC) #else -# define TICK_SEC 0 -# define TICK_NSEC (128 * 1000) +# define TICK_SEC 0 +# define TICK_NSEC NSEC_PER_TICK #endif /**************************************************************************** @@ -209,8 +210,8 @@ int up_timer_cancel(FAR struct timespec *ts) if (g_timer_active) { - ts->tv_sec = g_interval_delay.tv_nsec; - ts->tv_nsec = g_interval_delay.tv_sec; + ts->tv_sec = g_interval_delay.tv_sec; + ts->tv_nsec = g_interval_delay.tv_nsec; } else { @@ -220,8 +221,8 @@ int up_timer_cancel(FAR struct timespec *ts) /* Disable and reset the simulated timer */ - g_interval_delay.tv_nsec = 0; g_interval_delay.tv_sec = 0; + g_interval_delay.tv_nsec = 0; g_timer_active = false; } #endif @@ -253,8 +254,8 @@ int up_timer_cancel(FAR struct timespec *ts) #ifdef CONFIG_SCHED_TICKLESS int up_timer_start(FAR const struct timespec *ts) { - g_interval_delay.tv_nsec = ts->tv_nsec; g_interval_delay.tv_sec = ts->tv_sec; + g_interval_delay.tv_nsec = ts->tv_nsec; g_timer_active = true; } #endif @@ -278,10 +279,10 @@ void up_timer_update(void) /* Increment the elapsed time */ g_elapsed_time.tv_nsec += TICK_NSEC; - if (g_elapsed_time.tv_nsec >= 1000000000) + if (g_elapsed_time.tv_nsec >= NSEC_PER_SEC) { - g_elapsed_time.tv_nsec++; - g_elapsed_time.tv_sec -= 1000000000; + g_elapsed_time.tv_sec++; + g_elapsed_time.tv_nsec -= NSEC_PER_SEC; } g_elapsed_time.tv_sec += TICK_SEC; @@ -307,7 +308,7 @@ void up_timer_update(void) /* Decrement nanoseconds */ - if (g_interval_delay.tv_nsec > TICK_NSEC) + if (g_interval_delay.tv_nsec >= TICK_NSEC) { g_interval_delay.tv_nsec -= TICK_NSEC; } @@ -316,14 +317,10 @@ void up_timer_update(void) else if (g_interval_delay.tv_sec > 0) { - if (g_interval_delay.tv_nsec >= TICK_NSEC) - { - g_interval_delay.tv_nsec = 0; - } - else - { - g_interval_delay.tv_sec--; - } + g_interval_delay.tv_nsec += NSEC_PER_SEC; + g_interval_delay.tv_sec--; + + g_interval_delay.tv_nsec -= TICK_NSEC; } /* Otherwise the timer has expired */ diff --git a/nuttx/arch/sim/src/up_unblocktask.c b/nuttx/arch/sim/src/up_unblocktask.c index 04c2349e4..2da05edcc 100644 --- a/nuttx/arch/sim/src/up_unblocktask.c +++ b/nuttx/arch/sim/src/up_unblocktask.c @@ -99,7 +99,7 @@ void up_unblock_task(struct tcb_s *tcb) */ #if CONFIG_RR_INTERVAL > 0 - tcb->timeslice = CONFIG_RR_INTERVAL / MSEC_PER_TICK; + tcb->timeslice = MSEC2TICK(CONFIG_RR_INTERVAL); #endif /* Add the task in the correct location in the prioritized diff --git a/nuttx/arch/x86/src/common/up_unblocktask.c b/nuttx/arch/x86/src/common/up_unblocktask.c index 43b93c4e6..9e5597f16 100644 --- a/nuttx/arch/x86/src/common/up_unblocktask.c +++ b/nuttx/arch/x86/src/common/up_unblocktask.c @@ -96,7 +96,7 @@ void up_unblock_task(struct tcb_s *tcb) */ #if CONFIG_RR_INTERVAL > 0 - tcb->timeslice = CONFIG_RR_INTERVAL / MSEC_PER_TICK; + tcb->timeslice = MSEC2TICK(CONFIG_RR_INTERVAL); #endif /* Add the task in the correct location in the prioritized diff --git a/nuttx/arch/z16/src/common/up_unblocktask.c b/nuttx/arch/z16/src/common/up_unblocktask.c index 984e514ad..28bb95417 100644 --- a/nuttx/arch/z16/src/common/up_unblocktask.c +++ b/nuttx/arch/z16/src/common/up_unblocktask.c @@ -101,7 +101,7 @@ void up_unblock_task(FAR struct tcb_s *tcb) */ #if CONFIG_RR_INTERVAL > 0 - tcb->timeslice = CONFIG_RR_INTERVAL / MSEC_PER_TICK; + tcb->timeslice = MSEC2TICK(CONFIG_RR_INTERVAL); #endif /* Add the task in the correct location in the prioritized diff --git a/nuttx/arch/z80/src/common/up_unblocktask.c b/nuttx/arch/z80/src/common/up_unblocktask.c index 6c46b0a14..bc829db0d 100644 --- a/nuttx/arch/z80/src/common/up_unblocktask.c +++ b/nuttx/arch/z80/src/common/up_unblocktask.c @@ -102,7 +102,7 @@ void up_unblock_task(FAR struct tcb_s *tcb) */ #if CONFIG_RR_INTERVAL > 0 - tcb->timeslice = CONFIG_RR_INTERVAL / MSEC_PER_TICK; + tcb->timeslice = MSEC2TICK(CONFIG_RR_INTERVAL); #endif /* Add the task in the correct location in the prioritized diff --git a/nuttx/configs/mikroe-stm32f4/src/up_touchscreen.c b/nuttx/configs/mikroe-stm32f4/src/up_touchscreen.c index 095168c89..52edd65de 100644 --- a/nuttx/configs/mikroe-stm32f4/src/up_touchscreen.c +++ b/nuttx/configs/mikroe-stm32f4/src/up_touchscreen.c @@ -156,11 +156,11 @@ /* Delays ***************************************************************************/ /* All values will be increased by one system timer tick (probably 10MS). */ -#define TC_PENUP_POLL_TICKS (70 / MSEC_PER_TICK) /* IDLE polling rate: 100 MSec */ -#define TC_PENDOWN_POLL_TICKS (40 / MSEC_PER_TICK) /* Active polling rate: 60 MSec */ -#define TC_DEBOUNCE_TICKS (16 / MSEC_PER_TICK) /* Delay before re-sampling: 30 MSec */ -#define TC_SAMPLE_TICKS (4 / MSEC_PER_TICK) /* Delay for A/D sampling: 4 MSec */ -#define TC_SETTLE_TICKS (10 / MSEC_PER_TICK) /* Delay for A/D settling: 4 MSec */ +#define TC_PENUP_POLL_TICKS MSEC2TICK(70) /* IDLE polling rate: 70 MSec */ +#define TC_PENDOWN_POLL_TICKS MSEC2TICK(40) /* Active polling rate: 40 MSec */ +#define TC_DEBOUNCE_TICKS MSEC2TICK(16) /* Delay before re-sampling: 16 MSec */ +#define TC_SAMPLE_TICKS MSEC2TICK(4) /* Delay for A/D sampling: 4 MSec */ +#define TC_SETTLE_TICKS MSECT2TICK(10) /* Delay for A/D settling: 10 MSec */ #define TC_RESAMPLE_TICKS TC_SAMPLE_TICKS /************************************************************************************ diff --git a/nuttx/configs/pic32mx7mmb/src/up_touchscreen.c b/nuttx/configs/pic32mx7mmb/src/up_touchscreen.c index d29111f67..99b35151c 100644 --- a/nuttx/configs/pic32mx7mmb/src/up_touchscreen.c +++ b/nuttx/configs/pic32mx7mmb/src/up_touchscreen.c @@ -142,10 +142,10 @@ /* Delays ***************************************************************************/ /* All values will be increased by one system timer tick (probably 10MS). */ -#define TC_PENUP_POLL_TICKS (100 / MSEC_PER_TICK) /* IDLE polling rate: 100 MSec */ -#define TC_PENDOWN_POLL_TICKS (60 / MSEC_PER_TICK) /* Active polling rate: 60 MSec */ -#define TC_DEBOUNCE_TICKS (30 / MSEC_PER_TICK) /* Delay before re-sampling: 30 MSec */ -#define TC_SAMPLE_TICKS (4 / MSEC_PER_TICK) /* Delay for A/D sampling: 4 MSec */ +#define TC_PENUP_POLL_TICKS MSEC2TICK(100) /* IDLE polling rate: 100 MSec */ +#define TC_PENDOWN_POLL_TICKS MSEC2TICK(60) /* Active polling rate: 60 MSec */ +#define TC_DEBOUNCE_TICKS MSEC2TICK(30) /* Delay before re-sampling: 30 MSec */ +#define TC_SAMPLE_TICKS MSEC2TICK(4) /* Delay for A/D sampling: 4 MSec */ #define TC_RESAMPLE_TICKS TC_SAMPLE_TICKS /************************************************************************************ diff --git a/nuttx/configs/sam4s-xplained-pro/src/sam_tc.c b/nuttx/configs/sam4s-xplained-pro/src/sam_tc.c index 4012bb80d..bad80cc3e 100755 --- a/nuttx/configs/sam4s-xplained-pro/src/sam_tc.c +++ b/nuttx/configs/sam4s-xplained-pro/src/sam_tc.c @@ -218,8 +218,8 @@ int sam_timerinitialize(void) /* Set the timeout */ - tcvdbg("Interval = %d us.\n", (unsigned long)MSEC_PER_TICK * 1000); - ret = ioctl(fd, TCIOC_SETTIMEOUT, (unsigned long)MSEC_PER_TICK * 1000); + tcvdbg("Interval = %d us.\n", (unsigned long)USEC_PER_TICK); + ret = ioctl(fd, TCIOC_SETTIMEOUT, (unsigned long)USEC_PER_TICK); if (ret < 0) { tcdbg("ioctl(TCIOC_SETTIMEOUT) failed: %d\n", errno); diff --git a/nuttx/drivers/audio/wm8904.c b/nuttx/drivers/audio/wm8904.c index 0d7a79c87..707f5fd28 100644 --- a/nuttx/drivers/audio/wm8904.c +++ b/nuttx/drivers/audio/wm8904.c @@ -1475,6 +1475,9 @@ static int wm8904_sendbuffer(FAR struct wm8904_dev_s *priv) * REVISIT: Does this take into account the number channels? Perhaps * saving an reusing the bitrate would give a better and simpler * calculation. + * + * REVISIT: Should not use MSEC_PER_TICK. It can be inaccurate with + * microsecond resolution timer. */ timeout = (((uint32_t)(apb->nbytes - apb->curbyte) << 14) / diff --git a/nuttx/drivers/input/ads7843e.h b/nuttx/drivers/input/ads7843e.h index d3c82816f..97c45d042 100644 --- a/nuttx/drivers/input/ads7843e.h +++ b/nuttx/drivers/input/ads7843e.h @@ -100,7 +100,7 @@ /* Poll the pen position while the pen is down at this rate (50MS): */ -#define ADS7843E_WDOG_DELAY ((50 + (MSEC_PER_TICK-1))/ MSEC_PER_TICK) +#define ADS7843E_WDOG_DELAY MSEC2TICK(50) /******************************************************************************************** * Public Types diff --git a/nuttx/drivers/input/max11802.h b/nuttx/drivers/input/max11802.h index 075631799..8a6da0468 100644 --- a/nuttx/drivers/input/max11802.h +++ b/nuttx/drivers/input/max11802.h @@ -90,7 +90,7 @@ /* Poll the pen position while the pen is down at this rate (50MS): */ -#define MAX11802_WDOG_DELAY ((50 + (MSEC_PER_TICK-1))/ MSEC_PER_TICK) +#define MAX11802_WDOG_DELAY MSEC2TICK(50) /******************************************************************************************** * Public Types diff --git a/nuttx/drivers/input/stmpe811.h b/nuttx/drivers/input/stmpe811.h index f6d646527..fb686ee44 100644 --- a/nuttx/drivers/input/stmpe811.h +++ b/nuttx/drivers/input/stmpe811.h @@ -96,7 +96,7 @@ /* Timeout to detect missing pen up events */ -#define STMPE811_PENUP_TICKS ((100 + (MSEC_PER_TICK-1)) / MSEC_PER_TICK) +#define STMPE811_PENUP_TICKS MSEC2TICK(100) /******************************************************************************************** * Public Types diff --git a/nuttx/drivers/mtd/sst39vf.c b/nuttx/drivers/mtd/sst39vf.c index b404a9435..e2fe862c9 100644 --- a/nuttx/drivers/mtd/sst39vf.c +++ b/nuttx/drivers/mtd/sst39vf.c @@ -435,7 +435,7 @@ static int sst39vf_chiperase(FAR struct sst39vf_dev_s *priv) wrinfo.data = 0xffff; start = clock_systimer(); - while (delay < SST39VF_TSCE_MSEC * MSEC_PER_TICK) + while (delay < MSEC2TICK(SST39VF_TSCE_MSEC)) { /* Check if the erase is complete */ @@ -447,14 +447,14 @@ static int sst39vf_chiperase(FAR struct sst39vf_dev_s *priv) /* No, check if the timeout has elapsed */ elapsed = clock_systimer() - start; - if (elapsed > SST39VF_TSCE_MSEC * MSEC_PER_TICK) + if (elapsed > MSEC2TICK(SST39VF_TSCE_MSEC)) { return -ETIMEDOUT; } /* No, wait one system clock tick */ - usleep(MSEC_PER_TICK * USEC_PER_MSEC); + usleep(USEC_PER_TICK); } #else /* Delay the maximum amount of time for the chip erase to complete. */ @@ -511,7 +511,7 @@ static int sst39vf_sectorerase(FAR struct sst39vf_dev_s *priv, #if 0 start = clock_systimer(); - while (delay < SST39VF_TSE_MSEC * MSEC_PER_TICK) + while (delay < MSEC2TICK(SST39VF_TSE_MSEC)) { /* Check if the erase is complete */ @@ -523,14 +523,14 @@ static int sst39vf_sectorerase(FAR struct sst39vf_dev_s *priv, /* No, check if the timeout has elapsed */ elapsed = clock_systimer() - start; - if (elapsed > SST39VF_TSE_MSEC * MSEC_PER_TICK) + if (elapsed > MSEC2TICK(SST39VF_TSE_MSEC)) { return -ETIMEDOUT; } /* No, wait one system clock tick */ - usleep(MSEC_PER_TICK * USEC_PER_MSEC); + usleep(USEC_PER_TICK); } #else /* Delay the maximum amount of time for the sector erase to complete. */ diff --git a/nuttx/include/nuttx/clock.h b/nuttx/include/nuttx/clock.h index 509d624d2..fcd8c5c58 100644 --- a/nuttx/include/nuttx/clock.h +++ b/nuttx/include/nuttx/clock.h @@ -115,13 +115,12 @@ #define TICK_PER_DSEC (USEC_PER_DSEC / USEC_PER_TICK) /* Truncates! */ #define TICK_PER_SEC (USEC_PER_SEC / USEC_PER_TICK) /* Truncates! */ -#define MSEC_PER_TICK (USEC_PER_MSEC / USEC_PER_TICK) /* Truncates! */ +#define TICK_PER_MSEC (USEC_PER_MSEC / USEC_PER_TICK) /* Truncates! */ +#define MSEC_PER_TICK (USEC_PER_TICK / USEC_PER_MSEC) /* Truncates! */ #define NSEC_PER_TICK (USEC_PER_TICK * NSEC_PER_USEC) /* Exact */ #define NSEC2TICK(nsec) (((nsec)+(NSEC_PER_TICK/2))/NSEC_PER_TICK) /* Rounds */ #define USEC2TICK(usec) (((usec)+(USEC_PER_TICK/2))/USEC_PER_TICK) /* Rounds */ -#define DSEC2TICK(dsec) MSEC2TICK((dsec)*MSEC_PER_DSEC) /* Exact */ -#define SEC2TICK(sec) MSEC2TICK((sec)*MSEC_PER_SEC) /* Exact */ #if (MSEC_PER_TICK * USEC_PER_MSEC) == USEC_PER_TICK # define MSEC2TICK(msec) (((msec)+(MSEC_PER_TICK/2))/MSEC_PER_TICK) /* Rounds */ @@ -129,10 +128,11 @@ # define MSEC2TICK(msec) USEC2TICK(msec * 1000) /* Rounds */ #endif +#define DSEC2TICK(dsec) MSEC2TICK((dsec)*MSEC_PER_DSEC) /* Exact */ +#define SEC2TICK(sec) MSEC2TICK((sec)*MSEC_PER_SEC) /* Exact */ + #define TICK2NSEC(tick) ((tick)*NSEC_PER_TICK) /* Exact */ #define TICK2USEC(tick) ((tick)*USEC_PER_TICK) /* Exact */ -#define TICK2DSEC(tick) (((tick)+(TICK_PER_DSEC/2))/TICK_PER_DSEC) /* Rounds */ -#define TICK2SEC(tick) (((tick)+(TICK_PER_SEC/2))/TICK_PER_SEC) /* Rounds */ #if (MSEC_PER_TICK * USEC_PER_MSEC) == USEC_PER_TICK #define TICK2USEC(tick) ((tick)*MSEC_PER_TICK) /* Exact */ @@ -140,6 +140,9 @@ # define TICK2MSEC(tick) (((tick)*USEC_PER_TICK)/USEC_PER_MSEC) /* Rounds */ #endif +#define TICK2DSEC(tick) (((tick)+(TICK_PER_DSEC/2))/TICK_PER_DSEC) /* Rounds */ +#define TICK2SEC(tick) (((tick)+(TICK_PER_SEC/2))/TICK_PER_SEC) /* Rounds */ + /**************************************************************************** * Public Types ****************************************************************************/ diff --git a/nuttx/sched/Kconfig b/nuttx/sched/Kconfig index 7568e6f25..4f7a88bd3 100644 --- a/nuttx/sched/Kconfig +++ b/nuttx/sched/Kconfig @@ -93,6 +93,9 @@ config USEC_PER_TICK The default, 100 microseconds, will provide for a range of delays up to 120 hours. + This value should never be less than the underlying resolution of + the timer. Error may ensue. + if !SCHED_TICKLESS config SYSTEMTICK_EXTCLK diff --git a/nuttx/sched/clock_getres.c b/nuttx/sched/clock_getres.c index a76b14ab6..edbc87bf0 100644 --- a/nuttx/sched/clock_getres.c +++ b/nuttx/sched/clock_getres.c @@ -88,7 +88,6 @@ int clock_getres(clockid_t clock_id, struct timespec *res) { - uint32_t time_res; int ret = OK; sdbg("clock_id=%d\n", clock_id); @@ -103,18 +102,12 @@ int clock_getres(clockid_t clock_id, struct timespec *res) } else { - /* Get the clock resolution in nanoseconds */ - - time_res = MSEC_PER_TICK * NSEC_PER_MSEC; - - /* And return this as a timespec. */ + /* Form the timspec using clock resolution in nanoseconds */ res->tv_sec = 0; - res->tv_nsec = time_res; + res->tv_nsec = NSEC_PER_TICK; - sdbg("Returning res=(%d,%d) time_res=%d\n", - (int)res->tv_sec, (int)res->tv_nsec, - (int)time_res); + sdbg("Returning res=(%d,%d)\n", (int)res->tv_sec, (int)res->tv_nsec); } return ret; diff --git a/nuttx/sched/clock_gettime.c b/nuttx/sched/clock_gettime.c index 7f6cdba62..5244bc531 100644 --- a/nuttx/sched/clock_gettime.c +++ b/nuttx/sched/clock_gettime.c @@ -124,7 +124,7 @@ int clock_gettime(clockid_t clock_id, struct timespec *tp) { /* Get the time since power-on in seconds and milliseconds */ - msecs = MSEC_PER_TICK * clock_systimer(); + msecs = TICK2MSEC(clock_systimer()); secs = msecs / MSEC_PER_SEC; /* Return the elapsed time in seconds and nanoseconds */ @@ -174,7 +174,7 @@ int clock_gettime(clockid_t clock_id, struct timespec *tp) * when the time-of-day was last set. */ - msecs = MSEC_PER_TICK * (clock_systimer() - g_tickbias); + msecs = TICK2MSEC((clock_systimer() - g_tickbias)); sdbg("msecs = %d g_tickbias=%d\n", (int)msecs, (int)g_tickbias); diff --git a/nuttx/sched/clock_initialize.c b/nuttx/sched/clock_initialize.c index 0b21fd56a..374e675ac 100644 --- a/nuttx/sched/clock_initialize.c +++ b/nuttx/sched/clock_initialize.c @@ -266,7 +266,7 @@ void clock_synchronize(void) * Description: * This function must be called once every time the real time clock * interrupt occurs. The interval of this clock interrupt must be - * MSEC_PER_TICK + * USEC_PER_TICK * ****************************************************************************/ @@ -277,4 +277,4 @@ void clock_timer(void) g_system_timer++; } -#endif \ No newline at end of file +#endif diff --git a/nuttx/sched/clock_systimer.c b/nuttx/sched/clock_systimer.c index 126c12ce6..65487da6e 100644 --- a/nuttx/sched/clock_systimer.c +++ b/nuttx/sched/clock_systimer.c @@ -87,8 +87,7 @@ uint32_t clock_systimer(void) /* Convert to a 64- then 32-bit value */ - tmp = (1000 * (uint64_t)ts.tv_sec + (uint64_t)ts.tv_nsec / 1000000) / - MSEC_PER_TICK; + tmp = MSEC2TICK(1000 * (uint64_t)ts.tv_sec + (uint64_t)ts.tv_nsec / 1000000); return (uint32_t)(tmp & 0x00000000ffffffff); #else @@ -136,8 +135,7 @@ uint64_t clock_systimer64(void) /* Convert to a 64- then 32-bit value */ - return (1000 * (uint64_t)ts.tv_sec + (uint64_t)ts.tv_nsec / 1000000) / - MSEC_PER_TICK; + return MSEC2TICK(1000 * (uint64_t)ts.tv_sec + (uint64_t)ts.tv_nsec / 1000000); #else /* Return the current system time */ diff --git a/nuttx/sched/pthread_create.c b/nuttx/sched/pthread_create.c index 8c9292cfc..78142a6ed 100644 --- a/nuttx/sched/pthread_create.c +++ b/nuttx/sched/pthread_create.c @@ -381,7 +381,7 @@ int pthread_create(FAR pthread_t *thread, FAR pthread_attr_t *attr, if (policy == SCHED_RR) { ptcb->cmn.flags |= TCB_FLAG_ROUND_ROBIN; - ptcb->cmn.timeslice = CONFIG_RR_INTERVAL / MSEC_PER_TICK; + ptcb->cmn.timeslice = MSEC2TICK(CONFIG_RR_INTERVAL); } #endif diff --git a/nuttx/sched/sched_processtimer.c b/nuttx/sched/sched_processtimer.c index e16d17e71..a8a3b917f 100644 --- a/nuttx/sched/sched_processtimer.c +++ b/nuttx/sched/sched_processtimer.c @@ -115,7 +115,7 @@ static inline void sched_process_timeslice(void) { /* Reset the timeslice in any case. */ - rtcb->timeslice = CONFIG_RR_INTERVAL / MSEC_PER_TICK; + rtcb->timeslice = MSEC2TICK(CONFIG_RR_INTERVAL); /* We know we are at the head of the ready to run * prioritized list. We must be the highest priority @@ -170,7 +170,7 @@ static inline void sched_process_timeslice(void) * The timer interrupt logic itself is implemented in the * architecture specific code, but must call the following OS * function periodically -- the calling interval must be - * MSEC_PER_TICK + * USEC_PER_TICK * * Inputs: * None diff --git a/nuttx/sched/sched_setscheduler.c b/nuttx/sched/sched_setscheduler.c index 682f50530..cabf81bec 100644 --- a/nuttx/sched/sched_setscheduler.c +++ b/nuttx/sched/sched_setscheduler.c @@ -157,7 +157,7 @@ int sched_setscheduler(pid_t pid, int policy, /* Set round robin scheduling */ tcb->flags |= TCB_FLAG_ROUND_ROBIN; - tcb->timeslice = CONFIG_RR_INTERVAL / MSEC_PER_TICK; + tcb->timeslice = MSEC2TICK(CONFIG_RR_INTERVAL); } else { diff --git a/nuttx/sched/sched_timerexpiration.c b/nuttx/sched/sched_timerexpiration.c index 7f2a5b863..03cdfceef 100644 --- a/nuttx/sched/sched_timerexpiration.c +++ b/nuttx/sched/sched_timerexpiration.c @@ -171,7 +171,7 @@ sched_process_timeslice(unsigned int ticks, bool noswitches) { /* Reset the timeslice. */ - rtcb->timeslice = CONFIG_RR_INTERVAL / MSEC_PER_TICK; + rtcb->timeslice = MSEC2TICK(CONFIG_RR_INTERVAL); ret = rtcb->timeslice; /* We know we are at the head of the ready to run @@ -287,7 +287,7 @@ static void sched_timer_process(unsigned int ticks, bool noswitches) * understand. */ - msecs = MSEC_PER_TICK * nextime; + msecs = TICK2MSEC(nextime); secs = msecs / MSEC_PER_SEC; nsecs = (msecs - (secs * MSEC_PER_SEC)) * NSEC_PER_MSEC; @@ -327,7 +327,11 @@ static void sched_timer_process(unsigned int ticks, bool noswitches) void sched_timer_expiration(void) { - sched_timer_process(g_timer_interval, false); + unsigned int elapsed; + + elapsed = g_timer_interval; + g_timer_interval = 0; + sched_timer_process(elapsed, false); } /**************************************************************************** @@ -358,6 +362,7 @@ void sched_timer_reassess(void) { struct timespec ts; unsigned int ticks; + unsigned int elapsed; /* Get the time remaining on the interval timer and cancel the timer. */ @@ -367,13 +372,16 @@ void sched_timer_reassess(void) ticks = SEC2TICK(ts.tv_sec); ticks += NSEC2TICK(ts.tv_nsec); + DEBUGASSERT(ticks <= g_timer_interval); /* Handle the partial timer. This will reassess all timer conditions and * re-start the interval timer with the correct delay. Context switches * are not permitted in this case because we are not certain of the * calling conditions. */ - - sched_timer_process(g_timer_interval - ticks, true); + + elapsed = g_timer_interval - ticks; + g_timer_interval = 0; + sched_timer_process(elapsed, true); } #endif /* CONFIG_SCHED_TICKLESS */ diff --git a/nuttx/sched/sched_unlock.c b/nuttx/sched/sched_unlock.c index 91aa555ef..df3b966e7 100644 --- a/nuttx/sched/sched_unlock.c +++ b/nuttx/sched/sched_unlock.c @@ -45,7 +45,7 @@ #include "os_internal.h" /************************************************************************ - * Definitions + * Pre-processor Definitions ************************************************************************/ /************************************************************************ @@ -65,7 +65,7 @@ ************************************************************************/ /************************************************************************ - * Private Functionss + * Private Functions ************************************************************************/ /************************************************************************ @@ -125,11 +125,11 @@ int sched_unlock(void) } #if CONFIG_RR_INTERVAL > 0 - /* If (1) the task that was running running supported round-robin - * scheduling and (2) if its time slice has already expired, but (3) - * it could not slice out because pre-emption was disabled, then - * we need to swap the task out now and reassess the interval timer - * for the next time slice. + /* If (1) the task that was running supported round-robin + * scheduling and (2) if its time slice has already expired, but + * (3) it could not slice out because pre-emption was disabled, + * then we need to swap the task out now and reassess the interval + * timer for the next time slice. */ if ((rtcb->flags & TCB_FLAG_ROUND_ROBIN) != 0 && @@ -144,7 +144,7 @@ int sched_unlock(void) if (rtcb != (FAR struct tcb_s*)g_readytorun.head) { - rtcb->timeslice = CONFIG_RR_INTERVAL / MSEC_PER_TICK; + rtcb->timeslice = MSEC2TICK(CONFIG_RR_INTERVAL); } #ifdef CONFIG_SCHED_TICKLESS else diff --git a/nuttx/sched/sig_timedwait.c b/nuttx/sched/sig_timedwait.c index 3952e42c2..85b870642 100644 --- a/nuttx/sched/sig_timedwait.c +++ b/nuttx/sched/sig_timedwait.c @@ -254,7 +254,7 @@ int sigtimedwait(FAR const sigset_t *set, FAR struct siginfo *info, DEBUGASSERT(timeout->tv_sec < UINT32_MAX / MSEC_PER_SEC); waitmsec = timeout->tv_sec * MSEC_PER_SEC + (timeout->tv_nsec + NSEC_PER_MSEC - 1) / NSEC_PER_MSEC; - waitticks = (waitmsec + MSEC_PER_TICK - 1) / MSEC_PER_TICK; + waitticks = MSEC2TICK(waitmsec); #endif /* Create a watchdog */ -- cgit v1.2.3