Commit 94d45b3c authored by Alessandro Rubini's avatar Alessandro Rubini

timeout: lift the requirement for the value to not be zero

We don't zero timer any more (see preceding commit), no need
to special case anything.
Signed-off-by: Alessandro Rubini's avatarAlessandro Rubini <rubini@gnudd.com>
parent c5de0748
...@@ -197,7 +197,6 @@ struct pp_time_operations { ...@@ -197,7 +197,6 @@ struct pp_time_operations {
int (*adjust_offset)(struct pp_instance *ppi, long offset_ns); int (*adjust_offset)(struct pp_instance *ppi, long offset_ns);
int (*adjust_freq)(struct pp_instance *ppi, long freq_ppb); int (*adjust_freq)(struct pp_instance *ppi, long freq_ppb);
int (*init_servo)(struct pp_instance *ppi); int (*init_servo)(struct pp_instance *ppi);
/* calc_timeout cannot return zero */
unsigned long (*calc_timeout)(struct pp_instance *ppi, int millisec); unsigned long (*calc_timeout)(struct pp_instance *ppi, int millisec);
}; };
......
...@@ -92,15 +92,11 @@ static unsigned long bare_calc_timeout(struct pp_instance *ppi, int millisec) ...@@ -92,15 +92,11 @@ static unsigned long bare_calc_timeout(struct pp_instance *ppi, int millisec)
{ {
struct bare_timespec now; struct bare_timespec now;
uint64_t now_ms; uint64_t now_ms;
unsigned long result;
if (!millisec)
millisec = 1;
sys_clock_gettime(CLOCK_MONOTONIC, &now); sys_clock_gettime(CLOCK_MONOTONIC, &now);
now_ms = 1000LL * now.tv_sec + now.tv_nsec / 1000 / 1000; now_ms = 1000LL * now.tv_sec + now.tv_nsec / 1000 / 1000;
result = now_ms + millisec; return now_ms + millisec;
return result ? result : 1; /* cannot return 0 */
} }
struct pp_time_operations bare_time_ops = { struct pp_time_operations bare_time_ops = {
......
...@@ -110,10 +110,7 @@ static inline int sim_init_servo(struct pp_instance *ppi) ...@@ -110,10 +110,7 @@ static inline int sim_init_servo(struct pp_instance *ppi)
static unsigned long sim_calc_timeout(struct pp_instance *ppi, int millisec) static unsigned long sim_calc_timeout(struct pp_instance *ppi, int millisec)
{ {
unsigned long res; return millisec + SIM_PPI_ARCH(ppi)->time.current_ns / 1000LL / 1000LL;
res = millisec + SIM_PPI_ARCH(ppi)->time.current_ns / 1000LL / 1000LL;
return res ? res : 1;
} }
struct pp_time_operations sim_time_ops = { struct pp_time_operations sim_time_ops = {
......
...@@ -117,15 +117,11 @@ static unsigned long unix_calc_timeout(struct pp_instance *ppi, int millisec) ...@@ -117,15 +117,11 @@ static unsigned long unix_calc_timeout(struct pp_instance *ppi, int millisec)
{ {
struct timespec now; struct timespec now;
uint64_t now_ms; uint64_t now_ms;
unsigned long result;
if (!millisec)
millisec = 1;
clock_gettime(CLOCK_MONOTONIC, &now); clock_gettime(CLOCK_MONOTONIC, &now);
now_ms = 1000LL * now.tv_sec + now.tv_nsec / 1000 / 1000; now_ms = 1000LL * now.tv_sec + now.tv_nsec / 1000 / 1000;
result = now_ms + millisec; return now_ms + millisec;
return result ? result : 1; /* cannot return 0 */
} }
struct pp_time_operations unix_time_ops = { struct pp_time_operations unix_time_ops = {
......
...@@ -61,10 +61,7 @@ static int wrpc_time_adjust(struct pp_instance *ppi, long offset_ns, ...@@ -61,10 +61,7 @@ static int wrpc_time_adjust(struct pp_instance *ppi, long offset_ns,
static unsigned long wrpc_calc_timeout(struct pp_instance *ppi, int millisec) static unsigned long wrpc_calc_timeout(struct pp_instance *ppi, int millisec)
{ {
unsigned long now_ms = timer_get_tics(); return timer_get_tics() + millisec;
now_ms += millisec;
return now_ms ? now_ms : 1; /* cannot return 0 */
} }
struct pp_time_operations wrpc_time_ops = { struct pp_time_operations wrpc_time_ops = {
......
...@@ -105,9 +105,8 @@ void pp_timeout_setall(struct pp_instance *ppi) ...@@ -105,9 +105,8 @@ void pp_timeout_setall(struct pp_instance *ppi)
int pp_timeout(struct pp_instance *ppi, int index) int pp_timeout(struct pp_instance *ppi, int index)
{ {
int ret = ppi->timeouts[index] && int ret = time_after_eq(ppi->t_ops->calc_timeout(ppi, 0),
time_after_eq(ppi->t_ops->calc_timeout(ppi, 0), ppi->timeouts[index]);
ppi->timeouts[index]);
if (ret) if (ret)
pp_timeout_log(ppi, index); pp_timeout_log(ppi, index);
...@@ -119,9 +118,6 @@ int pp_ms_to_timeout(struct pp_instance *ppi, int index) ...@@ -119,9 +118,6 @@ int pp_ms_to_timeout(struct pp_instance *ppi, int index)
{ {
signed long ret; signed long ret;
if (!ppi->timeouts[index]) /* not pending, nothing to wait for */
return 0;
ret = ppi->timeouts[index] - ppi->t_ops->calc_timeout(ppi, 0); ret = ppi->timeouts[index] - ppi->t_ops->calc_timeout(ppi, 0);
return ret <= 0 ? 0 : ret; return ret <= 0 ? 0 : ret;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment