From d7fe0127b0e6eec7480b33799ecec0b320a81a03 Mon Sep 17 00:00:00 2001 From: Xiang Xiao Date: Tue, 15 Feb 2022 13:38:56 +0800 Subject: [PATCH] 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 --- arch/arm/src/cxd56xx/cxd56_cisif.c | 2 +- arch/arm/src/lc823450/lc823450_dvfs2.c | 2 +- arch/risc-v/src/bl602/bl602_os_hal.c | 2 +- .../arm/cxd56xx/drivers/audio/cxd56_audio_analog.c | 4 ++-- crypto/random_pool.c | 2 +- drivers/audio/cxd56.c | 4 ++-- drivers/contactless/mfrc522.c | 8 ++++---- drivers/sensors/scd30.c | 2 +- drivers/sensors/sgp30.c | 12 ++++++------ drivers/sensors/sht21.c | 2 +- drivers/sensors/sht3x.c | 2 +- drivers/sensors/sps30.c | 2 +- drivers/sensors/t67xx.c | 6 +++--- drivers/wireless/lpwan/sx127x/sx127x.c | 4 ++-- 14 files changed, 27 insertions(+), 27 deletions(-) diff --git a/arch/arm/src/cxd56xx/cxd56_cisif.c b/arch/arm/src/cxd56xx/cxd56_cisif.c index b3f8cbd83b..ac47b8e07d 100644 --- a/arch/arm/src/cxd56xx/cxd56_cisif.c +++ b/arch/arm/src/cxd56xx/cxd56_cisif.c @@ -271,7 +271,7 @@ static uint64_t cisif_get_msec_time(void) { struct timespec tp; - if (clock_gettime(CLOCK_REALTIME, &tp)) + if (clock_systime_timespec(&tp) < 0) { return 0; } diff --git a/arch/arm/src/lc823450/lc823450_dvfs2.c b/arch/arm/src/lc823450/lc823450_dvfs2.c index 46a4ce39c6..af2b6ba2b7 100644 --- a/arch/arm/src/lc823450/lc823450_dvfs2.c +++ b/arch/arm/src/lc823450/lc823450_dvfs2.c @@ -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) diff --git a/arch/risc-v/src/bl602/bl602_os_hal.c b/arch/risc-v/src/bl602/bl602_os_hal.c index 6288ef72f8..08056fcf67 100644 --- a/arch/risc-v/src/bl602/bl602_os_hal.c +++ b/arch/risc-v/src/bl602/bl602_os_hal.c @@ -1147,7 +1147,7 @@ int bl_os_workqueue_submit_lpwork(void *work, uint64_t bl_os_clock_gettime_ms(void) { struct timespec ts; - clock_gettime(CLOCK_REALTIME, &ts); + clock_systime_timespec(&ts); return ts.tv_sec * 1000 + ts.tv_nsec / 1000000; } diff --git a/boards/arm/cxd56xx/drivers/audio/cxd56_audio_analog.c b/boards/arm/cxd56xx/drivers/audio/cxd56_audio_analog.c index 54eae7a74e..c9cc5c21fe 100644 --- a/boards/arm/cxd56xx/drivers/audio/cxd56_audio_analog.c +++ b/boards/arm/cxd56xx/drivers/audio/cxd56_audio_analog.c @@ -62,7 +62,7 @@ static void clear_mic_boot_time(void) static void set_mic_boot_time(void) { struct timespec start; - if (clock_gettime(CLOCK_REALTIME, &start) < 0) + if (clock_systime_timespec(&start) < 0) { g_mic_boot_start_time = 0x0ull; return; @@ -77,7 +77,7 @@ static void wait_mic_boot_finish(void) if (g_mic_boot_start_time != 0x0ull) { struct timespec end; - if (clock_gettime(CLOCK_REALTIME, &end) < 0) + if (clock_systime_timespec(&end) < 0) { return; } diff --git a/crypto/random_pool.c b/crypto/random_pool.c index d0afa5c144..c9fc1e8558 100644 --- a/crypto/random_pool.c +++ b/crypto/random_pool.c @@ -446,7 +446,7 @@ void up_rngaddentropy(enum rnd_source_t kindof, FAR const uint32_t *buf, * 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(kindof, 27); tbuf[0] += ROTL_32((uintptr_t)&tbuf[0], 11); diff --git a/drivers/audio/cxd56.c b/drivers/audio/cxd56.c index 1acf621326..2bf83659d7 100644 --- a/drivers/audio/cxd56.c +++ b/drivers/audio/cxd56.c @@ -2054,7 +2054,7 @@ static int cxd56_power_on_micbias(FAR struct cxd56_dev_s *dev) /* Set mic boot time */ - if (clock_gettime(CLOCK_REALTIME, &start) < 0) + if (clock_systime_timespec(&start) < 0) { 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) { 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)end.tv_nsec / 1000000 - diff --git a/drivers/contactless/mfrc522.c b/drivers/contactless/mfrc522.c index a3030cb65d..50dec23a46 100644 --- a/drivers/contactless/mfrc522.c +++ b/drivers/contactless/mfrc522.c @@ -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 */ - clock_gettime(CLOCK_REALTIME, &tstart); + clock_systime_timespec(&tstart); tstart.tv_nsec += 200000; 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 */ - clock_gettime(CLOCK_REALTIME, &tend); + clock_systime_timespec(&tend); 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. */ - clock_gettime(CLOCK_REALTIME, &tstart); + clock_systime_timespec(&tstart); tstart.tv_nsec += 200000; 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 */ - clock_gettime(CLOCK_REALTIME, &tend); + clock_systime_timespec(&tend); if ((tend.tv_sec > tstart.tv_sec) && (tend.tv_nsec > tstart.tv_nsec)) diff --git a/drivers/sensors/scd30.c b/drivers/sensors/scd30.c index 6f355120fb..352c669f6c 100644 --- a/drivers/sensors/scd30.c +++ b/drivers/sensors/scd30.c @@ -443,7 +443,7 @@ static int scd30_read_values(FAR struct scd30_dev_s *priv, FAR float *temp, struct timespec ts; int ret; - clock_gettime(CLOCK_REALTIME, &ts); + clock_systime_timespec(&ts); if (wait || !priv->valid || has_time_passed(ts, priv->last_update, diff --git a/drivers/sensors/sgp30.c b/drivers/sensors/sgp30.c index 12f85a944d..1c345a3873 100644 --- a/drivers/sensors/sgp30.c +++ b/drivers/sensors/sgp30.c @@ -592,7 +592,7 @@ static int sgp30_open(FAR struct file *filep) add_sensor_randomness((buf[0].crc << 24) ^ (serial[0].crc << 16) ^ (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); if (ret < 0) { @@ -602,7 +602,7 @@ static int sgp30_open(FAR struct file *filep) else { 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"); while (repeat-- && 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); - clock_gettime(CLOCK_REALTIME, &start); + clock_systime_timespec(&start); ret = sgp30_write_cmd(priv, SGP30_CMD_INIT_AIR_QUALITY, NULL, 0); - clock_gettime(CLOCK_REALTIME, &curr); + clock_systime_timespec(&curr); if (ret < 0) { 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. */ - clock_gettime(CLOCK_REALTIME, &ts); + clock_systime_timespec(&ts); 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); diff --git a/drivers/sensors/sht21.c b/drivers/sensors/sht21.c index a48b964d1b..75f010cd84 100644 --- a/drivers/sensors/sht21.c +++ b/drivers/sensors/sht21.c @@ -313,7 +313,7 @@ static int sht21_read_values(FAR struct sht21_dev_s *priv, FAR int *temp, struct timespec ts; int ret; - clock_gettime(CLOCK_REALTIME, &ts); + clock_systime_timespec(&ts); /* 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 diff --git a/drivers/sensors/sht3x.c b/drivers/sensors/sht3x.c index f9898edff2..9432b82f7b 100644 --- a/drivers/sensors/sht3x.c +++ b/drivers/sensors/sht3x.c @@ -391,7 +391,7 @@ static int sht3x_read_values(FAR struct sht3x_dev_s *priv, struct timespec ts; int ret; - clock_gettime(CLOCK_REALTIME, &ts); + clock_systime_timespec(&ts); /* Read the raw data */ diff --git a/drivers/sensors/sps30.c b/drivers/sensors/sps30.c index 29d4f848bb..2d870537e1 100644 --- a/drivers/sensors/sps30.c +++ b/drivers/sensors/sps30.c @@ -455,7 +455,7 @@ static int sps30_read_values(FAR struct sps30_dev_s *priv, struct timespec ts; int ret; - clock_gettime(CLOCK_REALTIME, &ts); + clock_systime_timespec(&ts); if (wait || !priv->valid || has_time_passed(ts, priv->last_update, SPS30_MEASUREMENT_INTERVAL)) diff --git a/drivers/sensors/t67xx.c b/drivers/sensors/t67xx.c index ab611cfaeb..1b35f4af40 100644 --- a/drivers/sensors/t67xx.c +++ b/drivers/sensors/t67xx.c @@ -428,7 +428,7 @@ static int t67xx_read_gas_ppm(FAR struct t67xx_dev_s *priv, struct timespec ts; int ret; - clock_gettime(CLOCK_REALTIME, &ts); + clock_systime_timespec(&ts); 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. */ - clock_gettime(CLOCK_REALTIME, &priv->boot_time); + clock_systime_timespec(&priv->boot_time); 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); - clock_gettime(CLOCK_REALTIME, &priv->boot_time); + clock_systime_timespec(&priv->boot_time); /* Register the character driver. */ diff --git a/drivers/wireless/lpwan/sx127x/sx127x.c b/drivers/wireless/lpwan/sx127x/sx127x.c index bc64b09dd7..7841cc710e 100644 --- a/drivers/wireless/lpwan/sx127x/sx127x.c +++ b/drivers/wireless/lpwan/sx127x/sx127x.c @@ -3738,7 +3738,7 @@ static bool sx127x_channel_scan(FAR struct sx127x_dev_s *dev, /* Get start time */ - clock_gettime(CLOCK_REALTIME, &tstart); + clock_systime_timespec(&tstart); /* Initialize min/max */ @@ -3749,7 +3749,7 @@ static bool sx127x_channel_scan(FAR struct sx127x_dev_s *dev, { /* Get time now */ - clock_gettime(CLOCK_REALTIME, &tnow); + clock_systime_timespec(&tnow); /* Check RSSI */