diff --git a/arch/8051/src/up_unblocktask.c b/arch/8051/src/up_unblocktask.c index d285ddbd274..cb4e65fc0b5 100644 --- a/arch/8051/src/up_unblocktask.c +++ b/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/arch/arm/src/arm/up_unblocktask.c b/arch/arm/src/arm/up_unblocktask.c index 64536d959d7..3476441b410 100644 --- a/arch/arm/src/arm/up_unblocktask.c +++ b/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/arch/arm/src/armv6-m/up_unblocktask.c b/arch/arm/src/armv6-m/up_unblocktask.c index 0d51d21ca51..7a76a24d834 100644 --- a/arch/arm/src/armv6-m/up_unblocktask.c +++ b/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/arch/arm/src/armv7-a/arm_unblocktask.c b/arch/arm/src/armv7-a/arm_unblocktask.c index f08ceeca37b..c5ca090928b 100644 --- a/arch/arm/src/armv7-a/arm_unblocktask.c +++ b/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/arch/arm/src/armv7-m/up_unblocktask.c b/arch/arm/src/armv7-m/up_unblocktask.c index 551e5b67bd3..f2455e594a9 100644 --- a/arch/arm/src/armv7-m/up_unblocktask.c +++ b/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/arch/arm/src/c5471/c5471_timerisr.c b/arch/arm/src/c5471/c5471_timerisr.c index 1021fb84ad9..fc1143162d8 100644 --- a/arch/arm/src/c5471/c5471_timerisr.c +++ b/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/arch/arm/src/dm320/dm320_timerisr.c b/arch/arm/src/dm320/dm320_timerisr.c index a92478aa335..fae34071486 100644 --- a/arch/arm/src/dm320/dm320_timerisr.c +++ b/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/arch/arm/src/imx/imx_timerisr.c b/arch/arm/src/imx/imx_timerisr.c index 64db2e06d7f..d21b804c60c 100644 --- a/arch/arm/src/imx/imx_timerisr.c +++ b/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/arch/arm/src/kinetis/kinetis_sdhc.c b/arch/arm/src/kinetis/kinetis_sdhc.c index 3ba8c42996e..6ff5092e5cc 100644 --- a/arch/arm/src/kinetis/kinetis_sdhc.c +++ b/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/arch/arm/src/lpc17xx/lpc17_sdcard.c b/arch/arm/src/lpc17xx/lpc17_sdcard.c index 0fd719f24f4..d5b143118d2 100644 --- a/arch/arm/src/lpc17xx/lpc17_sdcard.c +++ b/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/arch/arm/src/sam34/sam_hsmci.c b/arch/arm/src/sam34/sam_hsmci.c index 94d052bd169..d770b2d2be0 100644 --- a/arch/arm/src/sam34/sam_hsmci.c +++ b/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/arch/arm/src/sam34/sam_spi.c b/arch/arm/src/sam34/sam_spi.c index 5e32faf698e..81c73a76f68 100644 --- a/arch/arm/src/sam34/sam_spi.c +++ b/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/arch/arm/src/sama5/sam_hsmci.c b/arch/arm/src/sama5/sam_hsmci.c index f0a0d3be1e5..670c3a69f7e 100644 --- a/arch/arm/src/sama5/sam_hsmci.c +++ b/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/arch/arm/src/sama5/sam_spi.c b/arch/arm/src/sama5/sam_spi.c index 10469107720..3a1a4652a7d 100644 --- a/arch/arm/src/sama5/sam_spi.c +++ b/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/arch/arm/src/sama5/sam_ssc.c b/arch/arm/src/sama5/sam_ssc.c index 475cf06b2e2..570b85078a6 100644 --- a/arch/arm/src/sama5/sam_ssc.c +++ b/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/arch/arm/src/sama5/sam_tsd.c b/arch/arm/src/sama5/sam_tsd.c index c3d45307f00..fe73afc3dc4 100644 --- a/arch/arm/src/sama5/sam_tsd.c +++ b/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/arch/arm/src/sama5/sam_twi.c b/arch/arm/src/sama5/sam_twi.c index 2e1c6a1a92b..eec19f6e60e 100644 --- a/arch/arm/src/sama5/sam_twi.c +++ b/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/arch/arm/src/stm32/stm32_otgfshost.c b/arch/arm/src/stm32/stm32_otgfshost.c index 7866365d927..7fe99c1c37b 100644 --- a/arch/arm/src/stm32/stm32_otgfshost.c +++ b/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/arch/arm/src/stm32/stm32_sdio.c b/arch/arm/src/stm32/stm32_sdio.c index f731ad75cc8..cc164bc8018 100644 --- a/arch/arm/src/stm32/stm32_sdio.c +++ b/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/arch/avr/src/avr/up_unblocktask.c b/arch/avr/src/avr/up_unblocktask.c index 305e057a8c5..6fb2e67e5ca 100644 --- a/arch/avr/src/avr/up_unblocktask.c +++ b/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/arch/avr/src/avr32/up_unblocktask.c b/arch/avr/src/avr32/up_unblocktask.c index 42dc3d52aab..f53550da90d 100644 --- a/arch/avr/src/avr32/up_unblocktask.c +++ b/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/arch/hc/src/common/up_unblocktask.c b/arch/hc/src/common/up_unblocktask.c index 08cefc1d4bc..425db0f9812 100644 --- a/arch/hc/src/common/up_unblocktask.c +++ b/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/arch/mips/src/mips32/up_unblocktask.c b/arch/mips/src/mips32/up_unblocktask.c index 277ec79cf37..dab958b159f 100644 --- a/arch/mips/src/mips32/up_unblocktask.c +++ b/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/arch/rgmp/src/nuttx.c b/arch/rgmp/src/nuttx.c index e6fee5de1da..0178ae58af0 100644 --- a/arch/rgmp/src/nuttx.c +++ b/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/arch/sh/src/common/up_unblocktask.c b/arch/sh/src/common/up_unblocktask.c index 5ba0173fbd2..a4b598499d5 100644 --- a/arch/sh/src/common/up_unblocktask.c +++ b/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/arch/sim/src/up_tickless.c b/arch/sim/src/up_tickless.c index 57a7935347f..4e04cd71e23 100644 --- a/arch/sim/src/up_tickless.c +++ b/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/arch/sim/src/up_unblocktask.c b/arch/sim/src/up_unblocktask.c index 04c2349e476..2da05edcc41 100644 --- a/arch/sim/src/up_unblocktask.c +++ b/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/arch/x86/src/common/up_unblocktask.c b/arch/x86/src/common/up_unblocktask.c index 43b93c4e6db..9e5597f16c9 100644 --- a/arch/x86/src/common/up_unblocktask.c +++ b/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/arch/z16/src/common/up_unblocktask.c b/arch/z16/src/common/up_unblocktask.c index 984e514ad8a..28bb9541784 100644 --- a/arch/z16/src/common/up_unblocktask.c +++ b/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/arch/z80/src/common/up_unblocktask.c b/arch/z80/src/common/up_unblocktask.c index 6c46b0a14d2..bc829db0d07 100644 --- a/arch/z80/src/common/up_unblocktask.c +++ b/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