drivers/video/isx019: Use clock function instead of gettimeofday

Change to use clock_systime_timespec() to avoid using libc API
from the driver layer.
This commit is contained in:
SPRESENSE 2022-10-25 15:47:49 +09:00 committed by Xiang Xiao
parent 8a0ce3f000
commit 6eb0ef618d

View File

@ -23,7 +23,6 @@
****************************************************************************/ ****************************************************************************/
#include <nuttx/config.h> #include <nuttx/config.h>
#include <sys/time.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <assert.h> #include <assert.h>
@ -31,6 +30,7 @@
#include <debug.h> #include <debug.h>
#include <nuttx/i2c/i2c_master.h> #include <nuttx/i2c/i2c_master.h>
#include <nuttx/signal.h> #include <nuttx/signal.h>
#include <nuttx/clock.h>
#include <arch/board/board.h> #include <arch/board/board.h>
#include <nuttx/video/isx019.h> #include <nuttx/video/isx019.h>
#include <nuttx/video/imgsensor.h> #include <nuttx/video/imgsensor.h>
@ -1086,34 +1086,42 @@ static int set_drive_mode(void)
static bool try_repeat(int sec, int usec, CODE int (*trial_func)(void)) static bool try_repeat(int sec, int usec, CODE int (*trial_func)(void))
{ {
int ret; int ret;
struct timeval start; struct timespec start;
struct timeval now; struct timespec now;
struct timeval delta; struct timespec delta;
struct timeval wait;
wait.tv_sec = sec; ret = clock_systime_timespec(&start);
wait.tv_usec = usec; if (ret < 0)
{
return false;
}
gettimeofday(&start, NULL);
while (1) while (1)
{ {
ret = trial_func(); ret = trial_func();
if (ret != -ENODEV) if (ret >= 0)
{ {
break; return true;
} }
else else
{ {
gettimeofday(&now, NULL); ret = clock_systime_timespec(&now);
timersub(&now, &start, &delta); if (ret < 0)
if (timercmp(&delta, &wait, >)) {
return false;
}
clock_timespec_subtract(&now, &start, &delta);
if ((delta.tv_sec > sec) ||
((delta.tv_sec == sec) &&
(delta.tv_nsec > (usec * NSEC_PER_USEC))))
{ {
break; break;
} }
} }
}; };
return (ret == OK); return false;
} }
static int try_isx019_i2c(void) static int try_isx019_i2c(void)