From 816ce73ab48bd9ad440a9d6cf8ca9a2ac98463e0 Mon Sep 17 00:00:00 2001 From: Xiang Xiao Date: Tue, 10 May 2022 13:20:32 +0800 Subject: [PATCH] Replace nxsem_timedwait with nxsem_tickwait Signed-off-by: Xiang Xiao --- arch/arm/src/am335x/am335x_i2c.c | 43 +++++-------------- arch/arm/src/cxd56xx/cxd56_gnss.c | 13 +----- arch/arm/src/lc823450/lc823450_i2c.c | 2 +- arch/arm/src/rtl8720c/amebaz_depend.c | 15 ++----- arch/arm/src/samd2l2/sam_i2c_master.c | 17 +------- arch/arm/src/samd5e5/sam_i2c_master.c | 17 +------- arch/arm/src/stm32/stm32_1wire.c | 13 ++---- arch/arm/src/stm32l4/stm32l4_1wire.c | 13 ++---- arch/risc-v/src/bl602/bl602_os_hal.c | 15 +------ arch/risc-v/src/esp32c3/esp32c3_ble_adapter.c | 12 +----- arch/risc-v/src/esp32c3/esp32c3_i2c.c | 22 +++------- .../risc-v/src/esp32c3/esp32c3_wifi_adapter.c | 15 +------ arch/risc-v/src/esp32c3/esp32c3_wifi_utils.c | 5 +-- arch/xtensa/src/esp32/esp32_ble_adapter.c | 15 +------ arch/xtensa/src/esp32/esp32_i2c.c | 22 +++------- arch/xtensa/src/esp32/esp32_wifi_adapter.c | 15 +------ arch/xtensa/src/esp32/esp32_wifi_utils.c | 5 +-- drivers/can/can.c | 13 ++---- drivers/contactless/pn532.c | 5 +-- .../wireless/ieee80211/bcm43xxx/bcmf_utils.c | 19 +------- 20 files changed, 52 insertions(+), 244 deletions(-) diff --git a/arch/arm/src/am335x/am335x_i2c.c b/arch/arm/src/am335x/am335x_i2c.c index e8831a55c1..b906629332 100644 --- a/arch/arm/src/am335x/am335x_i2c.c +++ b/arch/arm/src/am335x/am335x_i2c.c @@ -508,7 +508,6 @@ static useconds_t am335x_i2c_tousecs(int msgc, struct i2c_msg_s *msgs) #ifndef CONFIG_I2C_POLLED static inline int am335x_i2c_sem_waitdone(struct am335x_i2c_priv_s *priv) { - struct timespec abstime; irqstate_t flags; uint32_t regval; int ret; @@ -546,48 +545,26 @@ static inline int am335x_i2c_sem_waitdone(struct am335x_i2c_priv_s *priv) /* Signal the interrupt handler that we are waiting. NOTE: Interrupts * are currently disabled but will be temporarily re-enabled below when - * nxsem_timedwait() sleeps. + * nxsem_tickwait() sleeps. */ priv->intstate = INTSTATE_WAITING; do { - /* Get the current time */ - - clock_gettime(CLOCK_REALTIME, &abstime); - - /* Calculate a time in the future */ - -#if CONFIG_AM335X_I2CTIMEOSEC > 0 - abstime.tv_sec += CONFIG_AM335X_I2CTIMEOSEC; -#endif - - /* Add a value proportional to the number of bytes in the transfer */ - -#ifdef CONFIG_AM335X_I2C_DYNTIMEO - abstime.tv_nsec += 1000 * am335x_i2c_tousecs(priv->msgc, priv->msgv); - if (abstime.tv_nsec >= 1000 * 1000 * 1000) - { - abstime.tv_sec++; - abstime.tv_nsec -= 1000 * 1000 * 1000; - } - -#elif CONFIG_AM335X_I2CTIMEOMS > 0 - abstime.tv_nsec += CONFIG_AM335X_I2CTIMEOMS * 1000 * 1000; - if (abstime.tv_nsec >= 1000 * 1000 * 1000) - { - abstime.tv_sec++; - abstime.tv_nsec -= 1000 * 1000 * 1000; - } -#endif - /* Wait until either the transfer is complete or the timeout expires */ - ret = nxsem_timedwait(&priv->sem_isr, &abstime); +#ifdef CONFIG_AM335X_I2C_DYNTIMEO + ret = nxsem_tickwait(&priv->sem_isr, + USEC2TICK(am335x_i2c_tousecs(priv->msgc, + priv->msgv)); +#else + ret = nxsem_tickwait(&priv->sem_isr, + CONFIG_AM335X_I2CTIMEOTICKS); +#endif if (ret < 0 && ret != -EINTR) { /* Break out of the loop on irrecoverable errors. This would - * include timeouts and mystery errors reported by nxsem_timedwait. + * include timeouts and mystery errors reported by nxsem_tickwait. * NOTE that we try again if we are awakened by a signal (EINTR). */ diff --git a/arch/arm/src/cxd56xx/cxd56_gnss.c b/arch/arm/src/cxd56xx/cxd56_gnss.c index 65c0887945..41fb3cb5ae 100644 --- a/arch/arm/src/cxd56xx/cxd56_gnss.c +++ b/arch/arm/src/cxd56xx/cxd56_gnss.c @@ -2108,18 +2108,7 @@ static int cxd56_gnss_get_1pps_output(struct file *filep, static int cxd56_gnss_wait_notify(sem_t *sem, time_t waitsec) { - int ret; - struct timespec timeout; - - ret = clock_gettime(CLOCK_REALTIME, &timeout); - if (ret < 0) - { - return ret; - } - - timeout.tv_sec += waitsec; /* seconds timeout for wait */ - - return nxsem_timedwait(sem, &timeout); + return nxsem_tickwait(sem, SEC2TICK(waitsec)); } /**************************************************************************** diff --git a/arch/arm/src/lc823450/lc823450_i2c.c b/arch/arm/src/lc823450/lc823450_i2c.c index 922fb36336..c308ed905a 100644 --- a/arch/arm/src/lc823450/lc823450_i2c.c +++ b/arch/arm/src/lc823450/lc823450_i2c.c @@ -350,7 +350,7 @@ static inline int /* Signal the interrupt handler that we are waiting. NOTE: Interrupts * are currently disabled but will be temporarily re-enabled below when - * sem_timedwait() sleeps. + * nxsem_tickwait() sleeps. */ start = clock_systime_ticks(); diff --git a/arch/arm/src/rtl8720c/amebaz_depend.c b/arch/arm/src/rtl8720c/amebaz_depend.c index c12450bfa6..35c902aff8 100644 --- a/arch/arm/src/rtl8720c/amebaz_depend.c +++ b/arch/arm/src/rtl8720c/amebaz_depend.c @@ -196,25 +196,16 @@ void rtw_up_sema_from_isr(void **sema) uint32_t rtw_down_timeout_sema(void **sema, uint32_t timeout) { - struct timespec abstime; int ret; + if (timeout == 0xffffffff) { - ret = sem_wait(*sema); + ret = nxsem_wait(*sema); } else { - clock_gettime(CLOCK_REALTIME, &abstime); - abstime.tv_sec += timeout / 1000; - abstime.tv_nsec += (timeout % 1000) * 1000 * 1000; - if (abstime.tv_nsec >= (1000 * 1000000)) - { - abstime.tv_sec += 1; - abstime.tv_nsec -= (1000 * 1000000); - } - - ret = sem_timedwait(*sema, &abstime); + ret = nxsem_tickwait(*sema, MSEC2TICK(timeout)); } return !ret; diff --git a/arch/arm/src/samd2l2/sam_i2c_master.c b/arch/arm/src/samd2l2/sam_i2c_master.c index e371141870..83b7d334e5 100644 --- a/arch/arm/src/samd2l2/sam_i2c_master.c +++ b/arch/arm/src/samd2l2/sam_i2c_master.c @@ -642,25 +642,12 @@ static inline void i2c_putrel(struct sam_i2c_dev_s *priv, static int i2c_wait_for_bus(struct sam_i2c_dev_s *priv, unsigned int size) { - struct timespec ts; int ret; - long usec; - clock_gettime(CLOCK_REALTIME, &ts); - - usec = size * I2C_TIMEOUT_MSPB + ts.tv_nsec / 1000; - while (usec >= USEC_PER_SEC) - { - ts.tv_sec += 1; - usec -= USEC_PER_SEC; - } - - ts.tv_nsec = usec * 1000; - - ret = nxsem_timedwait(&priv->waitsem, (const struct timespec *)&ts); + ret = nxsem_tickwait(&priv->waitsem, USEC2TICK(size * I2C_TIMEOUT_MSPB)); if (ret < 0) { - i2cinfo("timedwait error %d\n", ret); + i2cinfo("nxsem_tickwait error %d\n", ret); return ret; } diff --git a/arch/arm/src/samd5e5/sam_i2c_master.c b/arch/arm/src/samd5e5/sam_i2c_master.c index 72e2827b4c..cb4db72537 100644 --- a/arch/arm/src/samd5e5/sam_i2c_master.c +++ b/arch/arm/src/samd5e5/sam_i2c_master.c @@ -660,25 +660,12 @@ static inline void i2c_putrel(struct sam_i2c_dev_s *priv, static int i2c_wait_for_bus(struct sam_i2c_dev_s *priv, unsigned int size) { - struct timespec ts; int ret; - long usec; - clock_gettime(CLOCK_REALTIME, &ts); - - usec = size * I2C_TIMEOUT_MSPB + ts.tv_nsec / 1000; - while (usec > USEC_PER_SEC) - { - ts.tv_sec += 1; - usec -= USEC_PER_SEC; - } - - ts.tv_nsec = usec * 1000; - - ret = nxsem_timedwait(&priv->waitsem, (const struct timespec *)&ts); + ret = nxsem_tickwait(&priv->waitsem, USEC2TICK(size * I2C_TIMEOUT_MSPB)); if (ret < 0) { - i2cinfo("timedwait error %d\n", ret); + i2cinfo("nxsem_tickwait error %d\n", ret); return ret; } diff --git a/arch/arm/src/stm32/stm32_1wire.c b/arch/arm/src/stm32/stm32_1wire.c index 75c90c318d..d8697ba496 100644 --- a/arch/arm/src/stm32/stm32_1wire.c +++ b/arch/arm/src/stm32/stm32_1wire.c @@ -776,7 +776,6 @@ static int stm32_1wire_process(struct stm32_1wire_priv_s *priv, int count) { irqstate_t irqs; - struct timespec abstime; int indx; int ret; @@ -814,9 +813,7 @@ static int stm32_1wire_process(struct stm32_1wire_priv_s *priv, /* Wait. Break on timeout if TX line closed to GND */ - clock_gettime(CLOCK_REALTIME, &abstime); - abstime.tv_sec += BUS_TIMEOUT; - nxsem_timedwait(&priv->sem_isr, &abstime); + nxsem_tickwait(&priv->sem_isr, SEC2TICK(BUS_TIMEOUT)); break; case ONEWIRETASK_WRITE: @@ -839,9 +836,7 @@ static int stm32_1wire_process(struct stm32_1wire_priv_s *priv, /* Wait. Break on timeout if TX line closed to GND */ - clock_gettime(CLOCK_REALTIME, &abstime); - abstime.tv_sec += BUS_TIMEOUT; - nxsem_timedwait(&priv->sem_isr, &abstime); + nxsem_tickwait(&priv->sem_isr, SEC2TICK(BUS_TIMEOUT)); break; case ONEWIRETASK_READ: @@ -863,9 +858,7 @@ static int stm32_1wire_process(struct stm32_1wire_priv_s *priv, /* Wait. Break on timeout if TX line closed to GND */ - clock_gettime(CLOCK_REALTIME, &abstime); - abstime.tv_sec += BUS_TIMEOUT; - nxsem_timedwait(&priv->sem_isr, &abstime); + nxsem_tickwait(&priv->sem_isr, SEC2TICK(BUS_TIMEOUT)); break; } diff --git a/arch/arm/src/stm32l4/stm32l4_1wire.c b/arch/arm/src/stm32l4/stm32l4_1wire.c index fea618a5e1..40aea59220 100644 --- a/arch/arm/src/stm32l4/stm32l4_1wire.c +++ b/arch/arm/src/stm32l4/stm32l4_1wire.c @@ -696,7 +696,6 @@ static int stm32_1wire_process(struct stm32_1wire_priv_s *priv, int count) { irqstate_t irqs; - struct timespec abstime; int indx; int ret; @@ -734,9 +733,7 @@ static int stm32_1wire_process(struct stm32_1wire_priv_s *priv, /* Wait. Break on timeout if TX line closed to GND */ - clock_gettime(CLOCK_REALTIME, &abstime); - abstime.tv_sec += BUS_TIMEOUT; - nxsem_timedwait(&priv->sem_isr, &abstime); + nxsem_tickwait(&priv->sem_isr, SEC2TICK(BUS_TIMEOUT)); break; case ONEWIRETASK_WRITE: @@ -759,9 +756,7 @@ static int stm32_1wire_process(struct stm32_1wire_priv_s *priv, /* Wait. Break on timeout if TX line closed to GND */ - clock_gettime(CLOCK_REALTIME, &abstime); - abstime.tv_sec += BUS_TIMEOUT; - nxsem_timedwait(&priv->sem_isr, &abstime); + nxsem_tickwait(&priv->sem_isr, SEC2TICK(BUS_TIMEOUT)); break; case ONEWIRETASK_READ: @@ -783,9 +778,7 @@ static int stm32_1wire_process(struct stm32_1wire_priv_s *priv, /* Wait. Break on timeout if TX line closed to GND */ - clock_gettime(CLOCK_REALTIME, &abstime); - abstime.tv_sec += BUS_TIMEOUT; - nxsem_timedwait(&priv->sem_isr, &abstime); + nxsem_tickwait(&priv->sem_isr, SEC2TICK(BUS_TIMEOUT)); break; } diff --git a/arch/risc-v/src/bl602/bl602_os_hal.c b/arch/risc-v/src/bl602/bl602_os_hal.c index 8b32067f39..2d3e84ad99 100644 --- a/arch/risc-v/src/bl602/bl602_os_hal.c +++ b/arch/risc-v/src/bl602/bl602_os_hal.c @@ -1461,7 +1461,6 @@ void bl_os_sem_delete(void *semphr) int32_t bl_os_sem_take(void *semphr, uint32_t ticks) { int ret; - struct timespec timeout; sem_t *sem = (sem_t *)semphr; if (ticks == BL_OS_WAITING_FOREVER) @@ -1474,19 +1473,7 @@ int32_t bl_os_sem_take(void *semphr, uint32_t ticks) } else { - ret = clock_gettime(CLOCK_REALTIME, &timeout); - if (ret < 0) - { - wlerr("ERROR: Failed to get time\n"); - return false; - } - - if (ticks) - { - bl_os_update_time(&timeout, ticks); - } - - ret = nxsem_timedwait(sem, &timeout); + ret = nxsem_tickwait(sem, ticks); if (ret) { wlerr("ERROR: Failed to wait sem in %lu ticks\n", ticks); diff --git a/arch/risc-v/src/esp32c3/esp32c3_ble_adapter.c b/arch/risc-v/src/esp32c3/esp32c3_ble_adapter.c index e7d50e4d6c..cb29a5a414 100644 --- a/arch/risc-v/src/esp32c3/esp32c3_ble_adapter.c +++ b/arch/risc-v/src/esp32c3/esp32c3_ble_adapter.c @@ -915,7 +915,6 @@ static void esp_update_time(struct timespec *timespec, uint32_t ticks) static int semphr_take_wrapper(void *semphr, uint32_t block_time_ms) { int ret; - struct timespec timeout; struct bt_sem_s *bt_sem = (struct bt_sem_s *)semphr; if (block_time_ms == OSI_FUNCS_TIME_BLOCKING) @@ -930,18 +929,11 @@ static int semphr_take_wrapper(void *semphr, uint32_t block_time_ms) { if (block_time_ms > 0) { - ret = clock_gettime(CLOCK_REALTIME, &timeout); - if (ret < 0) - { - wlerr("Failed to get time\n"); - return false; - } - esp_update_time(&timeout, MSEC2TICK(block_time_ms)); - ret = sem_timedwait(&bt_sem->sem, &timeout); + ret = nxsem_tickwait(&bt_sem->sem, MSEC2TICK(block_time_ms)); } else { - ret = sem_trywait(&bt_sem->sem); + ret = nxsem_trywait(&bt_sem->sem); } } diff --git a/arch/risc-v/src/esp32c3/esp32c3_i2c.c b/arch/risc-v/src/esp32c3/esp32c3_i2c.c index 7621caf437..8b7865dc3b 100644 --- a/arch/risc-v/src/esp32c3/esp32c3_i2c.c +++ b/arch/risc-v/src/esp32c3/esp32c3_i2c.c @@ -838,10 +838,8 @@ static int esp32c3_i2c_sem_waitdone(struct esp32c3_i2c_priv_s *priv) static int esp32c3_i2c_polling_waitdone(struct esp32c3_i2c_priv_s *priv) { int ret; - struct timespec current_time; - struct timespec timeout; - uint64_t current_us; - uint64_t timeout_us; + clock_t current; + clock_t timeout; uint32_t status = 0; /* Get the current absolute time and add an offset as timeout. @@ -850,19 +848,14 @@ static int esp32c3_i2c_polling_waitdone(struct esp32c3_i2c_priv_s *priv) * forward and backwards. */ - clock_systime_timespec(¤t_time); - - timeout.tv_sec = current_time.tv_sec + 10; - timeout.tv_nsec = current_time.tv_nsec + 0; - - current_us = TIMESPEC_TO_US(current_time.tv_sec, current_time.tv_nsec); - timeout_us = TIMESPEC_TO_US(timeout.tv_sec, timeout.tv_nsec); + current = clock_systime_ticks(); + timeout = current + SEC2TICK(10); /* Loop while a transfer is in progress * and an error didn't occur within the timeout */ - while ((current_us < timeout_us) && (priv->error == 0)) + while ((current < timeout) && (priv->error == 0)) { /* Check if any interrupt triggered, clear them * process the operation. @@ -891,8 +884,7 @@ static int esp32c3_i2c_polling_waitdone(struct esp32c3_i2c_priv_s *priv) /* Update current time */ - clock_systime_timespec(¤t_time); - current_us = TIMESPEC_TO_US(current_time.tv_sec, current_time.tv_nsec); + current = clock_systime_ticks(); } /* Return a negated value in case of timeout, and in the other scenarios @@ -901,7 +893,7 @@ static int esp32c3_i2c_polling_waitdone(struct esp32c3_i2c_priv_s *priv) * scenarios. */ - if (current_us >= timeout_us) + if (current >= timeout) { ret = -ETIMEDOUT; } diff --git a/arch/risc-v/src/esp32c3/esp32c3_wifi_adapter.c b/arch/risc-v/src/esp32c3/esp32c3_wifi_adapter.c index 42483bdac7..3f80fde166 100644 --- a/arch/risc-v/src/esp32c3/esp32c3_wifi_adapter.c +++ b/arch/risc-v/src/esp32c3/esp32c3_wifi_adapter.c @@ -1209,7 +1209,6 @@ static void esp_semphr_delete(void *semphr) static int32_t esp_semphr_take(void *semphr, uint32_t ticks) { int ret; - struct timespec timeout; sem_t *sem = (sem_t *)semphr; if (ticks == OSI_FUNCS_TIME_BLOCKING) @@ -1222,19 +1221,7 @@ static int32_t esp_semphr_take(void *semphr, uint32_t ticks) } else { - ret = clock_gettime(CLOCK_REALTIME, &timeout); - if (ret < 0) - { - wlerr("ERROR: Failed to get time\n"); - return false; - } - - if (ticks) - { - esp_update_time(&timeout, ticks); - } - - ret = nxsem_timedwait(sem, &timeout); + ret = nxsem_tickwait(sem, ticks); if (ret) { wlerr("ERROR: Failed to wait sem in %lu ticks\n", ticks); diff --git a/arch/risc-v/src/esp32c3/esp32c3_wifi_utils.c b/arch/risc-v/src/esp32c3/esp32c3_wifi_utils.c index 07ef6bb84f..1a4e6e3ba5 100644 --- a/arch/risc-v/src/esp32c3/esp32c3_wifi_utils.c +++ b/arch/risc-v/src/esp32c3/esp32c3_wifi_utils.c @@ -251,7 +251,6 @@ int esp_wifi_start_scan(struct iwreq *iwr) int esp_wifi_get_scan_results(struct iwreq *iwr) { int ret = OK; - struct timespec abstime; static bool scan_block = false; struct wifi_scan_result_s *priv = &g_scan_priv; @@ -262,9 +261,7 @@ int esp_wifi_get_scan_results(struct iwreq *iwr) { scan_block = true; leave_critical_section(irqstate); - clock_gettime(CLOCK_REALTIME, &abstime); - abstime.tv_sec += SCAN_TIME_SEC; - nxsem_timedwait(&priv->scan_signal, &abstime); + nxsem_tickwait(&priv->scan_signal, SEC2TICK(SCAN_TIME_SEC)); scan_block = false; } else diff --git a/arch/xtensa/src/esp32/esp32_ble_adapter.c b/arch/xtensa/src/esp32/esp32_ble_adapter.c index a5a6237207..2d074c9b61 100644 --- a/arch/xtensa/src/esp32/esp32_ble_adapter.c +++ b/arch/xtensa/src/esp32/esp32_ble_adapter.c @@ -1261,7 +1261,6 @@ static void esp_update_time(struct timespec *timespec, uint32_t ticks) static int semphr_take_wrapper(void *semphr, uint32_t block_time_ms) { int ret; - struct timespec timeout; sem_t *sem = (sem_t *)semphr; if (block_time_ms == OSI_FUNCS_TIME_BLOCKING) @@ -1274,19 +1273,7 @@ static int semphr_take_wrapper(void *semphr, uint32_t block_time_ms) } else { - ret = clock_gettime(CLOCK_REALTIME, &timeout); - if (ret < 0) - { - wlerr("Failed to get time\n"); - return esp_errno_trans(ret); - } - - if (block_time_ms) - { - esp_update_time(&timeout, MSEC2TICK(block_time_ms)); - } - - ret = sem_timedwait(sem, &timeout); + ret = nxsem_tickwait(sem, MSEC2TICK(block_time_ms)); } return esp_errno_trans(ret); diff --git a/arch/xtensa/src/esp32/esp32_i2c.c b/arch/xtensa/src/esp32/esp32_i2c.c index 6417d58f5d..c665c8d3de 100644 --- a/arch/xtensa/src/esp32/esp32_i2c.c +++ b/arch/xtensa/src/esp32/esp32_i2c.c @@ -772,10 +772,8 @@ static int esp32_i2c_sem_waitdone(struct esp32_i2c_priv_s *priv) static int esp32_i2c_polling_waitdone(struct esp32_i2c_priv_s *priv) { int ret; - struct timespec current_time; - struct timespec timeout; - uint64_t current_us; - uint64_t timeout_us; + clock_t current; + clock_t timeout; uint32_t status = 0; /* Get the current absolute time and add an offset as timeout. @@ -784,19 +782,14 @@ static int esp32_i2c_polling_waitdone(struct esp32_i2c_priv_s *priv) * forward and backwards. */ - clock_systime_timespec(¤t_time); - - timeout.tv_sec = current_time.tv_sec + 10; - timeout.tv_nsec = current_time.tv_nsec + 0; - - current_us = TIMESPEC_TO_US(current_time.tv_sec, current_time.tv_nsec); - timeout_us = TIMESPEC_TO_US(timeout.tv_sec, timeout.tv_nsec); + current = clock_systime_ticks(); + timeout = current + SEC2TICK(10); /* Loop while a transfer is in progress * and an error didn't occur within the timeout */ - while ((current_us < timeout_us) && (priv->error == 0)) + while ((current < timeout) && (priv->error == 0)) { /* Check if any interrupt triggered, clear them * process the operation. @@ -825,8 +818,7 @@ static int esp32_i2c_polling_waitdone(struct esp32_i2c_priv_s *priv) /* Update current time */ - clock_systime_timespec(¤t_time); - current_us = TIMESPEC_TO_US(current_time.tv_sec, current_time.tv_nsec); + current = clock_systime_ticks(); } /* Return a negated value in case of timeout, and in the other scenarios @@ -835,7 +827,7 @@ static int esp32_i2c_polling_waitdone(struct esp32_i2c_priv_s *priv) * scenarios. */ - if (current_us >= timeout_us) + if (current >= timeout) { ret = -ETIMEDOUT; } diff --git a/arch/xtensa/src/esp32/esp32_wifi_adapter.c b/arch/xtensa/src/esp32/esp32_wifi_adapter.c index b752ca0e55..35792e4d5a 100644 --- a/arch/xtensa/src/esp32/esp32_wifi_adapter.c +++ b/arch/xtensa/src/esp32/esp32_wifi_adapter.c @@ -1125,7 +1125,6 @@ static void esp_semphr_delete(void *semphr) static int32_t esp_semphr_take(void *semphr, uint32_t ticks) { int ret; - struct timespec timeout; sem_t *sem = (sem_t *)semphr; if (ticks == OSI_FUNCS_TIME_BLOCKING) @@ -1138,19 +1137,7 @@ static int32_t esp_semphr_take(void *semphr, uint32_t ticks) } else { - ret = clock_gettime(CLOCK_REALTIME, &timeout); - if (ret < 0) - { - wlerr("Failed to get time\n"); - return false; - } - - if (ticks) - { - esp_update_time(&timeout, ticks); - } - - ret = nxsem_timedwait(sem, &timeout); + ret = nxsem_tickwait(sem, ticks); if (ret) { wlerr("Failed to wait sem in %d ticks\n", ticks); diff --git a/arch/xtensa/src/esp32/esp32_wifi_utils.c b/arch/xtensa/src/esp32/esp32_wifi_utils.c index 9ceb90eaff..d88c089b64 100644 --- a/arch/xtensa/src/esp32/esp32_wifi_utils.c +++ b/arch/xtensa/src/esp32/esp32_wifi_utils.c @@ -251,7 +251,6 @@ int esp_wifi_start_scan(struct iwreq *iwr) int esp_wifi_get_scan_results(struct iwreq *iwr) { int ret = OK; - struct timespec abstime; static bool scan_block = false; struct wifi_scan_result *priv = &g_scan_priv; @@ -260,9 +259,7 @@ int esp_wifi_get_scan_results(struct iwreq *iwr) if (scan_block == false) { scan_block = true; - clock_gettime(CLOCK_REALTIME, &abstime); - abstime.tv_sec += SCAN_TIME_SEC; - nxsem_timedwait(&priv->scan_signal, &abstime); + nxsem_tickwait(&priv->scan_signal, SEC2TICK(SCAN_TIME_SEC)); scan_block = false; } else diff --git a/drivers/can/can.c b/drivers/can/can.c index bebc59b777..cb9316b932 100644 --- a/drivers/can/can.c +++ b/drivers/can/can.c @@ -923,7 +923,6 @@ static inline ssize_t can_rtrread(FAR struct file *filep, { FAR struct can_dev_s *dev = filep->f_inode->i_private; FAR struct can_rtrwait_s *wait = NULL; - struct timespec abstimeout; irqstate_t flags; int i; int sval; @@ -1002,15 +1001,9 @@ static inline ssize_t can_rtrread(FAR struct file *filep, { /* Then wait for the response */ - ret = clock_gettime(CLOCK_REALTIME, &abstimeout); - - if (ret >= 0) - { - clock_timespec_add(&abstimeout, - &request->ci_timeout, - &abstimeout); - ret = nxsem_timedwait(&wait->cr_sem, &abstimeout); - } + ret = nxsem_tickwait(&wait->cr_sem, + SEC2TICK(request->ci_timeout.tv_sec) + + NSEC2TICK(request->ci_timeout.tv_nsec)); } } diff --git a/drivers/contactless/pn532.c b/drivers/contactless/pn532.c index e48ea4707d..2552bd16f4 100644 --- a/drivers/contactless/pn532.c +++ b/drivers/contactless/pn532.c @@ -297,10 +297,7 @@ static int pn532_wait_rx_ready(FAR struct pn532_dev_s *dev, int timeout) int ret = OK; #ifdef CONFIG_PN532_USE_IRQ_FLOW_CONTROL - struct timespec ts; - clock_gettime(CLOCK_REALTIME, &ts); - ts.tv_sec += 1; - nxsem_timedwait(dev->sem_rx, &ts); + nxsem_tickwait(dev->sem_rx, SEC2TICK(1)); #endif /* TODO: Handle Exception bits 2, 3 */ diff --git a/drivers/wireless/ieee80211/bcm43xxx/bcmf_utils.c b/drivers/wireless/ieee80211/bcm43xxx/bcmf_utils.c index f0bd937fcc..878434190d 100644 --- a/drivers/wireless/ieee80211/bcm43xxx/bcmf_utils.c +++ b/drivers/wireless/ieee80211/bcm43xxx/bcmf_utils.c @@ -85,24 +85,7 @@ void bcmf_hexdump(uint8_t *data, unsigned int len, unsigned long offset) int bcmf_sem_wait(sem_t *sem, unsigned int timeout_ms) { - struct timespec abstime; - unsigned int timeout_sec; - - /* Get the current time */ - - clock_gettime(CLOCK_REALTIME, &abstime); - - timeout_sec = timeout_ms / 1000; - abstime.tv_sec += timeout_sec; - abstime.tv_nsec += 1000 * 1000 * (timeout_ms % 1000); - - if (abstime.tv_nsec >= 1000 * 1000 * 1000) - { - abstime.tv_sec++; - abstime.tv_nsec -= 1000 * 1000 * 1000; - } - - return nxsem_timedwait(sem, &abstime); + return nxsem_tickwait(sem, MSEC2TICK(timeout_ms)); } void bcmf_dqueue_push(dq_queue_t *queue, dq_entry_t *entry)