Replace nxsem_timedwait with nxsem_tickwait
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
This commit is contained in:
parent
22e4f1c59a
commit
816ce73ab4
@ -508,7 +508,6 @@ static useconds_t am335x_i2c_tousecs(int msgc, struct i2c_msg_s *msgs)
|
|||||||
#ifndef CONFIG_I2C_POLLED
|
#ifndef CONFIG_I2C_POLLED
|
||||||
static inline int am335x_i2c_sem_waitdone(struct am335x_i2c_priv_s *priv)
|
static inline int am335x_i2c_sem_waitdone(struct am335x_i2c_priv_s *priv)
|
||||||
{
|
{
|
||||||
struct timespec abstime;
|
|
||||||
irqstate_t flags;
|
irqstate_t flags;
|
||||||
uint32_t regval;
|
uint32_t regval;
|
||||||
int ret;
|
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
|
/* Signal the interrupt handler that we are waiting. NOTE: Interrupts
|
||||||
* are currently disabled but will be temporarily re-enabled below when
|
* are currently disabled but will be temporarily re-enabled below when
|
||||||
* nxsem_timedwait() sleeps.
|
* nxsem_tickwait() sleeps.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
priv->intstate = INTSTATE_WAITING;
|
priv->intstate = INTSTATE_WAITING;
|
||||||
do
|
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 */
|
/* 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)
|
if (ret < 0 && ret != -EINTR)
|
||||||
{
|
{
|
||||||
/* Break out of the loop on irrecoverable errors. This would
|
/* 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).
|
* NOTE that we try again if we are awakened by a signal (EINTR).
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -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)
|
static int cxd56_gnss_wait_notify(sem_t *sem, time_t waitsec)
|
||||||
{
|
{
|
||||||
int ret;
|
return nxsem_tickwait(sem, SEC2TICK(waitsec));
|
||||||
struct timespec timeout;
|
|
||||||
|
|
||||||
ret = clock_gettime(CLOCK_REALTIME, &timeout);
|
|
||||||
if (ret < 0)
|
|
||||||
{
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
timeout.tv_sec += waitsec; /* <waitsec> seconds timeout for wait */
|
|
||||||
|
|
||||||
return nxsem_timedwait(sem, &timeout);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
|
@ -350,7 +350,7 @@ static inline int
|
|||||||
|
|
||||||
/* Signal the interrupt handler that we are waiting. NOTE: Interrupts
|
/* Signal the interrupt handler that we are waiting. NOTE: Interrupts
|
||||||
* are currently disabled but will be temporarily re-enabled below when
|
* are currently disabled but will be temporarily re-enabled below when
|
||||||
* sem_timedwait() sleeps.
|
* nxsem_tickwait() sleeps.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
start = clock_systime_ticks();
|
start = clock_systime_ticks();
|
||||||
|
@ -196,25 +196,16 @@ void rtw_up_sema_from_isr(void **sema)
|
|||||||
|
|
||||||
uint32_t rtw_down_timeout_sema(void **sema, uint32_t timeout)
|
uint32_t rtw_down_timeout_sema(void **sema, uint32_t timeout)
|
||||||
{
|
{
|
||||||
struct timespec abstime;
|
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
if (timeout == 0xffffffff)
|
if (timeout == 0xffffffff)
|
||||||
{
|
{
|
||||||
ret = sem_wait(*sema);
|
ret = nxsem_wait(*sema);
|
||||||
}
|
}
|
||||||
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
clock_gettime(CLOCK_REALTIME, &abstime);
|
ret = nxsem_tickwait(*sema, MSEC2TICK(timeout));
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return !ret;
|
return !ret;
|
||||||
|
@ -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)
|
static int i2c_wait_for_bus(struct sam_i2c_dev_s *priv, unsigned int size)
|
||||||
{
|
{
|
||||||
struct timespec ts;
|
|
||||||
int ret;
|
int ret;
|
||||||
long usec;
|
|
||||||
|
|
||||||
clock_gettime(CLOCK_REALTIME, &ts);
|
ret = nxsem_tickwait(&priv->waitsem, USEC2TICK(size * I2C_TIMEOUT_MSPB));
|
||||||
|
|
||||||
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);
|
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
i2cinfo("timedwait error %d\n", ret);
|
i2cinfo("nxsem_tickwait error %d\n", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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)
|
static int i2c_wait_for_bus(struct sam_i2c_dev_s *priv, unsigned int size)
|
||||||
{
|
{
|
||||||
struct timespec ts;
|
|
||||||
int ret;
|
int ret;
|
||||||
long usec;
|
|
||||||
|
|
||||||
clock_gettime(CLOCK_REALTIME, &ts);
|
ret = nxsem_tickwait(&priv->waitsem, USEC2TICK(size * I2C_TIMEOUT_MSPB));
|
||||||
|
|
||||||
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);
|
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
i2cinfo("timedwait error %d\n", ret);
|
i2cinfo("nxsem_tickwait error %d\n", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -776,7 +776,6 @@ static int stm32_1wire_process(struct stm32_1wire_priv_s *priv,
|
|||||||
int count)
|
int count)
|
||||||
{
|
{
|
||||||
irqstate_t irqs;
|
irqstate_t irqs;
|
||||||
struct timespec abstime;
|
|
||||||
int indx;
|
int indx;
|
||||||
int ret;
|
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 */
|
/* Wait. Break on timeout if TX line closed to GND */
|
||||||
|
|
||||||
clock_gettime(CLOCK_REALTIME, &abstime);
|
nxsem_tickwait(&priv->sem_isr, SEC2TICK(BUS_TIMEOUT));
|
||||||
abstime.tv_sec += BUS_TIMEOUT;
|
|
||||||
nxsem_timedwait(&priv->sem_isr, &abstime);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ONEWIRETASK_WRITE:
|
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 */
|
/* Wait. Break on timeout if TX line closed to GND */
|
||||||
|
|
||||||
clock_gettime(CLOCK_REALTIME, &abstime);
|
nxsem_tickwait(&priv->sem_isr, SEC2TICK(BUS_TIMEOUT));
|
||||||
abstime.tv_sec += BUS_TIMEOUT;
|
|
||||||
nxsem_timedwait(&priv->sem_isr, &abstime);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ONEWIRETASK_READ:
|
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 */
|
/* Wait. Break on timeout if TX line closed to GND */
|
||||||
|
|
||||||
clock_gettime(CLOCK_REALTIME, &abstime);
|
nxsem_tickwait(&priv->sem_isr, SEC2TICK(BUS_TIMEOUT));
|
||||||
abstime.tv_sec += BUS_TIMEOUT;
|
|
||||||
nxsem_timedwait(&priv->sem_isr, &abstime);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -696,7 +696,6 @@ static int stm32_1wire_process(struct stm32_1wire_priv_s *priv,
|
|||||||
int count)
|
int count)
|
||||||
{
|
{
|
||||||
irqstate_t irqs;
|
irqstate_t irqs;
|
||||||
struct timespec abstime;
|
|
||||||
int indx;
|
int indx;
|
||||||
int ret;
|
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 */
|
/* Wait. Break on timeout if TX line closed to GND */
|
||||||
|
|
||||||
clock_gettime(CLOCK_REALTIME, &abstime);
|
nxsem_tickwait(&priv->sem_isr, SEC2TICK(BUS_TIMEOUT));
|
||||||
abstime.tv_sec += BUS_TIMEOUT;
|
|
||||||
nxsem_timedwait(&priv->sem_isr, &abstime);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ONEWIRETASK_WRITE:
|
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 */
|
/* Wait. Break on timeout if TX line closed to GND */
|
||||||
|
|
||||||
clock_gettime(CLOCK_REALTIME, &abstime);
|
nxsem_tickwait(&priv->sem_isr, SEC2TICK(BUS_TIMEOUT));
|
||||||
abstime.tv_sec += BUS_TIMEOUT;
|
|
||||||
nxsem_timedwait(&priv->sem_isr, &abstime);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ONEWIRETASK_READ:
|
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 */
|
/* Wait. Break on timeout if TX line closed to GND */
|
||||||
|
|
||||||
clock_gettime(CLOCK_REALTIME, &abstime);
|
nxsem_tickwait(&priv->sem_isr, SEC2TICK(BUS_TIMEOUT));
|
||||||
abstime.tv_sec += BUS_TIMEOUT;
|
|
||||||
nxsem_timedwait(&priv->sem_isr, &abstime);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1461,7 +1461,6 @@ void bl_os_sem_delete(void *semphr)
|
|||||||
int32_t bl_os_sem_take(void *semphr, uint32_t ticks)
|
int32_t bl_os_sem_take(void *semphr, uint32_t ticks)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
struct timespec timeout;
|
|
||||||
sem_t *sem = (sem_t *)semphr;
|
sem_t *sem = (sem_t *)semphr;
|
||||||
|
|
||||||
if (ticks == BL_OS_WAITING_FOREVER)
|
if (ticks == BL_OS_WAITING_FOREVER)
|
||||||
@ -1474,19 +1473,7 @@ int32_t bl_os_sem_take(void *semphr, uint32_t ticks)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ret = clock_gettime(CLOCK_REALTIME, &timeout);
|
ret = nxsem_tickwait(sem, ticks);
|
||||||
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);
|
|
||||||
if (ret)
|
if (ret)
|
||||||
{
|
{
|
||||||
wlerr("ERROR: Failed to wait sem in %lu ticks\n", ticks);
|
wlerr("ERROR: Failed to wait sem in %lu ticks\n", ticks);
|
||||||
|
@ -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)
|
static int semphr_take_wrapper(void *semphr, uint32_t block_time_ms)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
struct timespec timeout;
|
|
||||||
struct bt_sem_s *bt_sem = (struct bt_sem_s *)semphr;
|
struct bt_sem_s *bt_sem = (struct bt_sem_s *)semphr;
|
||||||
|
|
||||||
if (block_time_ms == OSI_FUNCS_TIME_BLOCKING)
|
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)
|
if (block_time_ms > 0)
|
||||||
{
|
{
|
||||||
ret = clock_gettime(CLOCK_REALTIME, &timeout);
|
ret = nxsem_tickwait(&bt_sem->sem, MSEC2TICK(block_time_ms));
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ret = sem_trywait(&bt_sem->sem);
|
ret = nxsem_trywait(&bt_sem->sem);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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)
|
static int esp32c3_i2c_polling_waitdone(struct esp32c3_i2c_priv_s *priv)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
struct timespec current_time;
|
clock_t current;
|
||||||
struct timespec timeout;
|
clock_t timeout;
|
||||||
uint64_t current_us;
|
|
||||||
uint64_t timeout_us;
|
|
||||||
uint32_t status = 0;
|
uint32_t status = 0;
|
||||||
|
|
||||||
/* Get the current absolute time and add an offset as timeout.
|
/* 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.
|
* forward and backwards.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
clock_systime_timespec(¤t_time);
|
current = clock_systime_ticks();
|
||||||
|
timeout = current + SEC2TICK(10);
|
||||||
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);
|
|
||||||
|
|
||||||
/* Loop while a transfer is in progress
|
/* Loop while a transfer is in progress
|
||||||
* and an error didn't occur within the timeout
|
* 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
|
/* Check if any interrupt triggered, clear them
|
||||||
* process the operation.
|
* process the operation.
|
||||||
@ -891,8 +884,7 @@ static int esp32c3_i2c_polling_waitdone(struct esp32c3_i2c_priv_s *priv)
|
|||||||
|
|
||||||
/* Update current time */
|
/* Update current time */
|
||||||
|
|
||||||
clock_systime_timespec(¤t_time);
|
current = clock_systime_ticks();
|
||||||
current_us = TIMESPEC_TO_US(current_time.tv_sec, current_time.tv_nsec);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Return a negated value in case of timeout, and in the other scenarios
|
/* 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.
|
* scenarios.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (current_us >= timeout_us)
|
if (current >= timeout)
|
||||||
{
|
{
|
||||||
ret = -ETIMEDOUT;
|
ret = -ETIMEDOUT;
|
||||||
}
|
}
|
||||||
|
@ -1209,7 +1209,6 @@ static void esp_semphr_delete(void *semphr)
|
|||||||
static int32_t esp_semphr_take(void *semphr, uint32_t ticks)
|
static int32_t esp_semphr_take(void *semphr, uint32_t ticks)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
struct timespec timeout;
|
|
||||||
sem_t *sem = (sem_t *)semphr;
|
sem_t *sem = (sem_t *)semphr;
|
||||||
|
|
||||||
if (ticks == OSI_FUNCS_TIME_BLOCKING)
|
if (ticks == OSI_FUNCS_TIME_BLOCKING)
|
||||||
@ -1222,19 +1221,7 @@ static int32_t esp_semphr_take(void *semphr, uint32_t ticks)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ret = clock_gettime(CLOCK_REALTIME, &timeout);
|
ret = nxsem_tickwait(sem, ticks);
|
||||||
if (ret < 0)
|
|
||||||
{
|
|
||||||
wlerr("ERROR: Failed to get time\n");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ticks)
|
|
||||||
{
|
|
||||||
esp_update_time(&timeout, ticks);
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = nxsem_timedwait(sem, &timeout);
|
|
||||||
if (ret)
|
if (ret)
|
||||||
{
|
{
|
||||||
wlerr("ERROR: Failed to wait sem in %lu ticks\n", ticks);
|
wlerr("ERROR: Failed to wait sem in %lu ticks\n", ticks);
|
||||||
|
@ -251,7 +251,6 @@ int esp_wifi_start_scan(struct iwreq *iwr)
|
|||||||
int esp_wifi_get_scan_results(struct iwreq *iwr)
|
int esp_wifi_get_scan_results(struct iwreq *iwr)
|
||||||
{
|
{
|
||||||
int ret = OK;
|
int ret = OK;
|
||||||
struct timespec abstime;
|
|
||||||
static bool scan_block = false;
|
static bool scan_block = false;
|
||||||
struct wifi_scan_result_s *priv = &g_scan_priv;
|
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;
|
scan_block = true;
|
||||||
leave_critical_section(irqstate);
|
leave_critical_section(irqstate);
|
||||||
clock_gettime(CLOCK_REALTIME, &abstime);
|
nxsem_tickwait(&priv->scan_signal, SEC2TICK(SCAN_TIME_SEC));
|
||||||
abstime.tv_sec += SCAN_TIME_SEC;
|
|
||||||
nxsem_timedwait(&priv->scan_signal, &abstime);
|
|
||||||
scan_block = false;
|
scan_block = false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -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)
|
static int semphr_take_wrapper(void *semphr, uint32_t block_time_ms)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
struct timespec timeout;
|
|
||||||
sem_t *sem = (sem_t *)semphr;
|
sem_t *sem = (sem_t *)semphr;
|
||||||
|
|
||||||
if (block_time_ms == OSI_FUNCS_TIME_BLOCKING)
|
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
|
else
|
||||||
{
|
{
|
||||||
ret = clock_gettime(CLOCK_REALTIME, &timeout);
|
ret = nxsem_tickwait(sem, MSEC2TICK(block_time_ms));
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return esp_errno_trans(ret);
|
return esp_errno_trans(ret);
|
||||||
|
@ -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)
|
static int esp32_i2c_polling_waitdone(struct esp32_i2c_priv_s *priv)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
struct timespec current_time;
|
clock_t current;
|
||||||
struct timespec timeout;
|
clock_t timeout;
|
||||||
uint64_t current_us;
|
|
||||||
uint64_t timeout_us;
|
|
||||||
uint32_t status = 0;
|
uint32_t status = 0;
|
||||||
|
|
||||||
/* Get the current absolute time and add an offset as timeout.
|
/* 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.
|
* forward and backwards.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
clock_systime_timespec(¤t_time);
|
current = clock_systime_ticks();
|
||||||
|
timeout = current + SEC2TICK(10);
|
||||||
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);
|
|
||||||
|
|
||||||
/* Loop while a transfer is in progress
|
/* Loop while a transfer is in progress
|
||||||
* and an error didn't occur within the timeout
|
* 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
|
/* Check if any interrupt triggered, clear them
|
||||||
* process the operation.
|
* process the operation.
|
||||||
@ -825,8 +818,7 @@ static int esp32_i2c_polling_waitdone(struct esp32_i2c_priv_s *priv)
|
|||||||
|
|
||||||
/* Update current time */
|
/* Update current time */
|
||||||
|
|
||||||
clock_systime_timespec(¤t_time);
|
current = clock_systime_ticks();
|
||||||
current_us = TIMESPEC_TO_US(current_time.tv_sec, current_time.tv_nsec);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Return a negated value in case of timeout, and in the other scenarios
|
/* 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.
|
* scenarios.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (current_us >= timeout_us)
|
if (current >= timeout)
|
||||||
{
|
{
|
||||||
ret = -ETIMEDOUT;
|
ret = -ETIMEDOUT;
|
||||||
}
|
}
|
||||||
|
@ -1125,7 +1125,6 @@ static void esp_semphr_delete(void *semphr)
|
|||||||
static int32_t esp_semphr_take(void *semphr, uint32_t ticks)
|
static int32_t esp_semphr_take(void *semphr, uint32_t ticks)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
struct timespec timeout;
|
|
||||||
sem_t *sem = (sem_t *)semphr;
|
sem_t *sem = (sem_t *)semphr;
|
||||||
|
|
||||||
if (ticks == OSI_FUNCS_TIME_BLOCKING)
|
if (ticks == OSI_FUNCS_TIME_BLOCKING)
|
||||||
@ -1138,19 +1137,7 @@ static int32_t esp_semphr_take(void *semphr, uint32_t ticks)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ret = clock_gettime(CLOCK_REALTIME, &timeout);
|
ret = nxsem_tickwait(sem, ticks);
|
||||||
if (ret < 0)
|
|
||||||
{
|
|
||||||
wlerr("Failed to get time\n");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ticks)
|
|
||||||
{
|
|
||||||
esp_update_time(&timeout, ticks);
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = nxsem_timedwait(sem, &timeout);
|
|
||||||
if (ret)
|
if (ret)
|
||||||
{
|
{
|
||||||
wlerr("Failed to wait sem in %d ticks\n", ticks);
|
wlerr("Failed to wait sem in %d ticks\n", ticks);
|
||||||
|
@ -251,7 +251,6 @@ int esp_wifi_start_scan(struct iwreq *iwr)
|
|||||||
int esp_wifi_get_scan_results(struct iwreq *iwr)
|
int esp_wifi_get_scan_results(struct iwreq *iwr)
|
||||||
{
|
{
|
||||||
int ret = OK;
|
int ret = OK;
|
||||||
struct timespec abstime;
|
|
||||||
static bool scan_block = false;
|
static bool scan_block = false;
|
||||||
struct wifi_scan_result *priv = &g_scan_priv;
|
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)
|
if (scan_block == false)
|
||||||
{
|
{
|
||||||
scan_block = true;
|
scan_block = true;
|
||||||
clock_gettime(CLOCK_REALTIME, &abstime);
|
nxsem_tickwait(&priv->scan_signal, SEC2TICK(SCAN_TIME_SEC));
|
||||||
abstime.tv_sec += SCAN_TIME_SEC;
|
|
||||||
nxsem_timedwait(&priv->scan_signal, &abstime);
|
|
||||||
scan_block = false;
|
scan_block = false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -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_dev_s *dev = filep->f_inode->i_private;
|
||||||
FAR struct can_rtrwait_s *wait = NULL;
|
FAR struct can_rtrwait_s *wait = NULL;
|
||||||
struct timespec abstimeout;
|
|
||||||
irqstate_t flags;
|
irqstate_t flags;
|
||||||
int i;
|
int i;
|
||||||
int sval;
|
int sval;
|
||||||
@ -1002,15 +1001,9 @@ static inline ssize_t can_rtrread(FAR struct file *filep,
|
|||||||
{
|
{
|
||||||
/* Then wait for the response */
|
/* Then wait for the response */
|
||||||
|
|
||||||
ret = clock_gettime(CLOCK_REALTIME, &abstimeout);
|
ret = nxsem_tickwait(&wait->cr_sem,
|
||||||
|
SEC2TICK(request->ci_timeout.tv_sec) +
|
||||||
if (ret >= 0)
|
NSEC2TICK(request->ci_timeout.tv_nsec));
|
||||||
{
|
|
||||||
clock_timespec_add(&abstimeout,
|
|
||||||
&request->ci_timeout,
|
|
||||||
&abstimeout);
|
|
||||||
ret = nxsem_timedwait(&wait->cr_sem, &abstimeout);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -297,10 +297,7 @@ static int pn532_wait_rx_ready(FAR struct pn532_dev_s *dev, int timeout)
|
|||||||
int ret = OK;
|
int ret = OK;
|
||||||
|
|
||||||
#ifdef CONFIG_PN532_USE_IRQ_FLOW_CONTROL
|
#ifdef CONFIG_PN532_USE_IRQ_FLOW_CONTROL
|
||||||
struct timespec ts;
|
nxsem_tickwait(dev->sem_rx, SEC2TICK(1));
|
||||||
clock_gettime(CLOCK_REALTIME, &ts);
|
|
||||||
ts.tv_sec += 1;
|
|
||||||
nxsem_timedwait(dev->sem_rx, &ts);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* TODO: Handle Exception bits 2, 3 */
|
/* TODO: Handle Exception bits 2, 3 */
|
||||||
|
@ -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)
|
int bcmf_sem_wait(sem_t *sem, unsigned int timeout_ms)
|
||||||
{
|
{
|
||||||
struct timespec abstime;
|
return nxsem_tickwait(sem, MSEC2TICK(timeout_ms));
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void bcmf_dqueue_push(dq_queue_t *queue, dq_entry_t *entry)
|
void bcmf_dqueue_push(dq_queue_t *queue, dq_entry_t *entry)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user