target: Use proper data types for timer callback

Change-Id: I5ca6da767f9e96180c43b179b2c682b1b7c98563
Signed-off-by: Marc Schink <openocd-dev@marcschink.de>
Reviewed-on: http://openocd.zylin.com/4920
Tested-by: jenkins
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
reverse-resume-order
Marc Schink 2019-02-15 14:31:19 +01:00 committed by Tomas Vanek
parent f21c12abec
commit 17a052d6fe
2 changed files with 13 additions and 7 deletions

View File

@ -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)

View File

@ -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);
/**