diff options
author | Antonio Borneo <borneo.antonio@gmail.com> | 2021-05-16 15:43:28 +0200 |
---|---|---|
committer | Antonio Borneo <borneo.antonio@gmail.com> | 2021-05-29 21:33:44 +0100 |
commit | 240943c65a1fbfe67cf5bd6bacb72076ffb6f1ce (patch) | |
tree | c17aebb0db54025784243e0588a0ad9d117ab151 /src/rtos/chibios.c | |
parent | 8446e140181e85bab82daa273c1637b1eab01bd5 (diff) | |
download | riscv-openocd-240943c65a1fbfe67cf5bd6bacb72076ffb6f1ce.zip riscv-openocd-240943c65a1fbfe67cf5bd6bacb72076ffb6f1ce.tar.gz riscv-openocd-240943c65a1fbfe67cf5bd6bacb72076ffb6f1ce.tar.bz2 |
rtos: use ARRAY_SIZE() and simplify rtos_type.create()
Use the existing macro ARRAY_SIZE().
Rewrite the functions rtos_type.create() to simplify the logic.
Change-Id: I8833354767045d1642801d26944c9087a77add00
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/6261
Tested-by: jenkins
Diffstat (limited to 'src/rtos/chibios.c')
-rw-r--r-- | src/rtos/chibios.c | 23 |
1 files changed, 9 insertions, 14 deletions
diff --git a/src/rtos/chibios.c b/src/rtos/chibios.c index 29abede..2a23017 100644 --- a/src/rtos/chibios.c +++ b/src/rtos/chibios.c @@ -74,7 +74,7 @@ static const char * const chibios_thread_states[] = { "READY", "CURRENT", "WTEXIT", "WTOREVT", "WTANDEVT", "SNDMSGQ", "SNDMSG", "WTMSG", "FINAL" }; -#define CHIBIOS_NUM_STATES (sizeof(chibios_thread_states)/sizeof(char *)) +#define CHIBIOS_NUM_STATES ARRAY_SIZE(chibios_thread_states) /* Maximum ChibiOS thread name. There is no real limit set by ChibiOS but 64 * chars ought to be enough. @@ -100,7 +100,6 @@ static struct chibios_params chibios_params_list[] = { NULL, /* stacking_info */ } }; -#define CHIBIOS_NUM_PARAMS ((int)(sizeof(chibios_params_list)/sizeof(struct chibios_params))) static bool chibios_detect_rtos(struct target *target); static int chibios_create(struct target *target); @@ -529,17 +528,13 @@ static bool chibios_detect_rtos(struct target *target) static int chibios_create(struct target *target) { - int i = 0; - while ((i < CHIBIOS_NUM_PARAMS) && - (0 != strcmp(chibios_params_list[i].target_name, target->type->name))) { - i++; - } - if (i >= CHIBIOS_NUM_PARAMS) { - LOG_WARNING("Could not find target \"%s\" in ChibiOS compatibility " - "list", target->type->name); - return -1; - } + for (unsigned int i = 0; i < ARRAY_SIZE(chibios_params_list); i++) + if (strcmp(chibios_params_list[i].target_name, target->type->name) == 0) { + target->rtos->rtos_specific_params = (void *)&chibios_params_list[i]; + return 0; + } - target->rtos->rtos_specific_params = (void *) &chibios_params_list[i]; - return 0; + LOG_WARNING("Could not find target \"%s\" in ChibiOS compatibility " + "list", target->type->name); + return -1; } |