From 17a052d6fe44fc265d48e94bdd3356d6f25ca064 Mon Sep 17 00:00:00 2001 From: Marc Schink Date: Fri, 15 Feb 2019 14:31:19 +0100 Subject: [PATCH] target: Use proper data types for timer callback Change-Id: I5ca6da767f9e96180c43b179b2c682b1b7c98563 Signed-off-by: Marc Schink Reviewed-on: http://openocd.zylin.com/4920 Tested-by: jenkins Reviewed-by: Tomas Vanek --- src/target/target.c | 9 +++++---- src/target/target.h | 11 ++++++++--- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/target/target.c b/src/target/target.c index 693eb519e..a3230d248 100644 --- a/src/target/target.c +++ b/src/target/target.c @@ -1460,7 +1460,8 @@ int target_register_trace_callback(int (*callback)(struct target *target, return ERROR_OK; } -int target_register_timer_callback(int (*callback)(void *priv), int time_ms, int periodic, void *priv) +int target_register_timer_callback(int (*callback)(void *priv), + unsigned int time_ms, enum target_timer_type type, void *priv) { struct target_timer_callback **callbacks_p = &target_timer_callbacks; @@ -1475,7 +1476,7 @@ int target_register_timer_callback(int (*callback)(void *priv), int time_ms, int (*callbacks_p) = malloc(sizeof(struct target_timer_callback)); (*callbacks_p)->callback = callback; - (*callbacks_p)->periodic = periodic; + (*callbacks_p)->type = type; (*callbacks_p)->time_ms = time_ms; (*callbacks_p)->removed = false; @@ -1625,7 +1626,7 @@ static int target_call_timer_callback(struct target_timer_callback *cb, { cb->callback(cb->priv); - if (cb->periodic) + if (cb->type == TARGET_TIMER_TYPE_PERIODIC) return target_timer_callback_periodic_restart(cb, now); return target_unregister_timer_callback(cb->callback, cb->priv); @@ -1659,7 +1660,7 @@ static int target_call_timer_callbacks_check_time(int checktime) } bool call_it = (*callback)->callback && - ((!checktime && (*callback)->periodic) || + ((!checktime && (*callback)->type == TARGET_TIMER_TYPE_PERIODIC) || timeval_compare(&now, &(*callback)->when) >= 0); if (call_it) diff --git a/src/target/target.h b/src/target/target.h index 983f450ac..36b131aa9 100644 --- a/src/target/target.h +++ b/src/target/target.h @@ -314,10 +314,15 @@ struct target_trace_callback { int (*callback)(struct target *target, size_t len, uint8_t *data, void *priv); }; +enum target_timer_type { + TARGET_TIMER_TYPE_ONESHOT, + TARGET_TIMER_TYPE_PERIODIC +}; + struct target_timer_callback { int (*callback)(void *priv); - int time_ms; - int periodic; + unsigned int time_ms; + enum target_timer_type type; bool removed; struct timeval when; void *priv; @@ -385,7 +390,7 @@ int target_call_trace_callbacks(struct target *target, size_t len, uint8_t *data * or much more rarely than specified */ int target_register_timer_callback(int (*callback)(void *priv), - int time_ms, int periodic, void *priv); + unsigned int time_ms, enum target_timer_type type, void *priv); int target_unregister_timer_callback(int (*callback)(void *priv), void *priv); int target_call_timer_callbacks(void); /**