Replece clock_gettime(CLOCK_REALTIME) with clock_systime_timespec if suitable

it's better to call the kernrel api insteaad user space api in kernel

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
This commit is contained in:
Xiang Xiao 2022-02-15 13:38:56 +08:00 committed by Xiang Xiao
parent 43f57240e0
commit d7fe0127b0
14 changed files with 27 additions and 27 deletions

View File

@ -271,7 +271,7 @@ static uint64_t cisif_get_msec_time(void)
{ {
struct timespec tp; struct timespec tp;
if (clock_gettime(CLOCK_REALTIME, &tp)) if (clock_systime_timespec(&tp) < 0)
{ {
return 0; return 0;
} }

View File

@ -120,7 +120,7 @@ uint32_t g_dvfs_freq_stat[3] =
****************************************************************************/ ****************************************************************************/
/**************************************************************************** /****************************************************************************
* Name: up_get_current_time() * Name: _get_current_time64()
****************************************************************************/ ****************************************************************************/
static uint64_t _get_current_time64(void) static uint64_t _get_current_time64(void)

View File

@ -1147,7 +1147,7 @@ int bl_os_workqueue_submit_lpwork(void *work,
uint64_t bl_os_clock_gettime_ms(void) uint64_t bl_os_clock_gettime_ms(void)
{ {
struct timespec ts; struct timespec ts;
clock_gettime(CLOCK_REALTIME, &ts); clock_systime_timespec(&ts);
return ts.tv_sec * 1000 + ts.tv_nsec / 1000000; return ts.tv_sec * 1000 + ts.tv_nsec / 1000000;
} }

View File

@ -62,7 +62,7 @@ static void clear_mic_boot_time(void)
static void set_mic_boot_time(void) static void set_mic_boot_time(void)
{ {
struct timespec start; struct timespec start;
if (clock_gettime(CLOCK_REALTIME, &start) < 0) if (clock_systime_timespec(&start) < 0)
{ {
g_mic_boot_start_time = 0x0ull; g_mic_boot_start_time = 0x0ull;
return; return;
@ -77,7 +77,7 @@ static void wait_mic_boot_finish(void)
if (g_mic_boot_start_time != 0x0ull) if (g_mic_boot_start_time != 0x0ull)
{ {
struct timespec end; struct timespec end;
if (clock_gettime(CLOCK_REALTIME, &end) < 0) if (clock_systime_timespec(&end) < 0)
{ {
return; return;
} }

View File

@ -446,7 +446,7 @@ void up_rngaddentropy(enum rnd_source_t kindof, FAR const uint32_t *buf,
* reseeding too fast. * reseeding too fast.
*/ */
clock_gettime(CLOCK_REALTIME, &ts); clock_systime_timespec(&ts);
tbuf[0] = ROTL_32((uint32_t)ts.tv_nsec, 17) ^ ROTL_32(ts.tv_sec, 3); tbuf[0] = ROTL_32((uint32_t)ts.tv_nsec, 17) ^ ROTL_32(ts.tv_sec, 3);
tbuf[0] += ROTL_32(kindof, 27); tbuf[0] += ROTL_32(kindof, 27);
tbuf[0] += ROTL_32((uintptr_t)&tbuf[0], 11); tbuf[0] += ROTL_32((uintptr_t)&tbuf[0], 11);

View File

@ -2054,7 +2054,7 @@ static int cxd56_power_on_micbias(FAR struct cxd56_dev_s *dev)
/* Set mic boot time */ /* Set mic boot time */
if (clock_gettime(CLOCK_REALTIME, &start) < 0) if (clock_systime_timespec(&start) < 0)
{ {
dev->mic_boot_start = 0x0ull; dev->mic_boot_start = 0x0ull;
} }
@ -2922,7 +2922,7 @@ static int cxd56_start(FAR struct audio_lowerhalf_s *lower)
if (priv->mic_boot_start != 0x0ull) if (priv->mic_boot_start != 0x0ull)
{ {
struct timespec end; struct timespec end;
if (clock_gettime(CLOCK_REALTIME, &end) >= 0) if (clock_systime_timespec(&end) == 0)
{ {
uint64_t time = (uint64_t)end.tv_sec * 1000 + uint64_t time = (uint64_t)end.tv_sec * 1000 +
(uint64_t)end.tv_nsec / 1000000 - (uint64_t)end.tv_nsec / 1000000 -

View File

@ -355,7 +355,7 @@ int mfrc522_calc_crc(FAR struct mfrc522_dev_s *dev, uint8_t *buffer,
/* Wait for CRC completion or 200ms time-out */ /* Wait for CRC completion or 200ms time-out */
clock_gettime(CLOCK_REALTIME, &tstart); clock_systime_timespec(&tstart);
tstart.tv_nsec += 200000; tstart.tv_nsec += 200000;
if (tstart.tv_nsec >= 1000 * 1000 * 1000) if (tstart.tv_nsec >= 1000 * 1000 * 1000)
{ {
@ -375,7 +375,7 @@ int mfrc522_calc_crc(FAR struct mfrc522_dev_s *dev, uint8_t *buffer,
/* Get time now */ /* Get time now */
clock_gettime(CLOCK_REALTIME, &tend); clock_systime_timespec(&tend);
if ((tend.tv_sec > tstart.tv_sec) && (tend.tv_nsec > tstart.tv_nsec)) if ((tend.tv_sec > tstart.tv_sec) && (tend.tv_nsec > tstart.tv_nsec))
{ {
@ -454,7 +454,7 @@ int mfrc522_comm_picc(FAR struct mfrc522_dev_s *dev, uint8_t command,
* hardware fault, let us to use a NuttX timeout as well. * hardware fault, let us to use a NuttX timeout as well.
*/ */
clock_gettime(CLOCK_REALTIME, &tstart); clock_systime_timespec(&tstart);
tstart.tv_nsec += 200000; tstart.tv_nsec += 200000;
if (tstart.tv_nsec >= 1000 * 1000 * 1000) if (tstart.tv_nsec >= 1000 * 1000 * 1000)
{ {
@ -495,7 +495,7 @@ int mfrc522_comm_picc(FAR struct mfrc522_dev_s *dev, uint8_t command,
/* Get time now */ /* Get time now */
clock_gettime(CLOCK_REALTIME, &tend); clock_systime_timespec(&tend);
if ((tend.tv_sec > tstart.tv_sec) && if ((tend.tv_sec > tstart.tv_sec) &&
(tend.tv_nsec > tstart.tv_nsec)) (tend.tv_nsec > tstart.tv_nsec))

View File

@ -443,7 +443,7 @@ static int scd30_read_values(FAR struct scd30_dev_s *priv, FAR float *temp,
struct timespec ts; struct timespec ts;
int ret; int ret;
clock_gettime(CLOCK_REALTIME, &ts); clock_systime_timespec(&ts);
if (wait || !priv->valid || if (wait || !priv->valid ||
has_time_passed(ts, priv->last_update, has_time_passed(ts, priv->last_update,

View File

@ -592,7 +592,7 @@ static int sgp30_open(FAR struct file *filep)
add_sensor_randomness((buf[0].crc << 24) ^ (serial[0].crc << 16) ^ add_sensor_randomness((buf[0].crc << 24) ^ (serial[0].crc << 16) ^
(serial[1].crc << 8) ^ (serial[2].crc << 0)); (serial[1].crc << 8) ^ (serial[2].crc << 0));
clock_gettime(CLOCK_REALTIME, &start); clock_systime_timespec(&start);
ret = sgp30_write_cmd(priv, SGP30_CMD_INIT_AIR_QUALITY, NULL, 0); ret = sgp30_write_cmd(priv, SGP30_CMD_INIT_AIR_QUALITY, NULL, 0);
if (ret < 0) if (ret < 0)
{ {
@ -602,7 +602,7 @@ static int sgp30_open(FAR struct file *filep)
else else
{ {
uint32_t repeat = SGP30_INIT_RETRIES; uint32_t repeat = SGP30_INIT_RETRIES;
clock_gettime(CLOCK_REALTIME, &curr); clock_systime_timespec(&curr);
sgp30_dbg("sgp30_write_cmd(SGP30_CMD_INIT_AIR_QUALITY)\n"); sgp30_dbg("sgp30_write_cmd(SGP30_CMD_INIT_AIR_QUALITY)\n");
while (repeat-- && while (repeat-- &&
time_has_passed_ms(&curr, &start, SGP30_INIT_LIMIT_MS)) time_has_passed_ms(&curr, &start, SGP30_INIT_LIMIT_MS))
@ -627,10 +627,10 @@ static int sgp30_open(FAR struct file *filep)
nxsig_usleep(CONFIG_SGP30_RESET_DELAY_US); nxsig_usleep(CONFIG_SGP30_RESET_DELAY_US);
clock_gettime(CLOCK_REALTIME, &start); clock_systime_timespec(&start);
ret = sgp30_write_cmd(priv, SGP30_CMD_INIT_AIR_QUALITY, ret = sgp30_write_cmd(priv, SGP30_CMD_INIT_AIR_QUALITY,
NULL, 0); NULL, 0);
clock_gettime(CLOCK_REALTIME, &curr); clock_systime_timespec(&curr);
if (ret < 0) if (ret < 0)
{ {
sgp30_dbg("sgp30_write_cmd(SGP30_CMD_INIT_AIR_QUALITY)" sgp30_dbg("sgp30_write_cmd(SGP30_CMD_INIT_AIR_QUALITY)"
@ -739,7 +739,7 @@ static ssize_t sgp30_read(FAR struct file *filep, FAR char *buffer,
* to run measurement command every 1 second. * to run measurement command every 1 second.
*/ */
clock_gettime(CLOCK_REALTIME, &ts); clock_systime_timespec(&ts);
while (!has_time_passed(&ts, &priv->last_update, 1)) while (!has_time_passed(&ts, &priv->last_update, 1))
{ {
@ -767,7 +767,7 @@ static ssize_t sgp30_read(FAR struct file *filep, FAR char *buffer,
} }
} }
clock_gettime(CLOCK_REALTIME, &ts); clock_systime_timespec(&ts);
} }
ret = sgp30_measure_airq(priv, &data); ret = sgp30_measure_airq(priv, &data);

View File

@ -313,7 +313,7 @@ static int sht21_read_values(FAR struct sht21_dev_s *priv, FAR int *temp,
struct timespec ts; struct timespec ts;
int ret; int ret;
clock_gettime(CLOCK_REALTIME, &ts); clock_systime_timespec(&ts);
/* Datasheet section 2.3: "To keep self heating below 0.1°C, SHT2x /* Datasheet section 2.3: "To keep self heating below 0.1°C, SHT2x
* should not be active for more than 10% of the time e.g. maximum * should not be active for more than 10% of the time e.g. maximum

View File

@ -391,7 +391,7 @@ static int sht3x_read_values(FAR struct sht3x_dev_s *priv,
struct timespec ts; struct timespec ts;
int ret; int ret;
clock_gettime(CLOCK_REALTIME, &ts); clock_systime_timespec(&ts);
/* Read the raw data */ /* Read the raw data */

View File

@ -455,7 +455,7 @@ static int sps30_read_values(FAR struct sps30_dev_s *priv,
struct timespec ts; struct timespec ts;
int ret; int ret;
clock_gettime(CLOCK_REALTIME, &ts); clock_systime_timespec(&ts);
if (wait || !priv->valid || if (wait || !priv->valid ||
has_time_passed(ts, priv->last_update, SPS30_MEASUREMENT_INTERVAL)) has_time_passed(ts, priv->last_update, SPS30_MEASUREMENT_INTERVAL))

View File

@ -428,7 +428,7 @@ static int t67xx_read_gas_ppm(FAR struct t67xx_dev_s *priv,
struct timespec ts; struct timespec ts;
int ret; int ret;
clock_gettime(CLOCK_REALTIME, &ts); clock_systime_timespec(&ts);
if (!has_time_passed(ts, priv->boot_time, T67XX_UPTIME_MINIMAL_SEC)) if (!has_time_passed(ts, priv->boot_time, T67XX_UPTIME_MINIMAL_SEC))
{ {
@ -562,7 +562,7 @@ static int t67xx_reset(FAR struct t67xx_dev_s *priv)
/* Sensor uptime starting again from zero. */ /* Sensor uptime starting again from zero. */
clock_gettime(CLOCK_REALTIME, &priv->boot_time); clock_systime_timespec(&priv->boot_time);
return ret; return ret;
} }
@ -770,7 +770,7 @@ int t67xx_register(FAR const char *devpath, FAR struct i2c_master_s *i2c,
nxsem_init(&priv->devsem, 0, 1); nxsem_init(&priv->devsem, 0, 1);
clock_gettime(CLOCK_REALTIME, &priv->boot_time); clock_systime_timespec(&priv->boot_time);
/* Register the character driver. */ /* Register the character driver. */

View File

@ -3738,7 +3738,7 @@ static bool sx127x_channel_scan(FAR struct sx127x_dev_s *dev,
/* Get start time */ /* Get start time */
clock_gettime(CLOCK_REALTIME, &tstart); clock_systime_timespec(&tstart);
/* Initialize min/max */ /* Initialize min/max */
@ -3749,7 +3749,7 @@ static bool sx127x_channel_scan(FAR struct sx127x_dev_s *dev,
{ {
/* Get time now */ /* Get time now */
clock_gettime(CLOCK_REALTIME, &tnow); clock_systime_timespec(&tnow);
/* Check RSSI */ /* Check RSSI */