jtag: linuxgpiod: drop extra parenthesis
[openocd.git] / src / rtos / chibios.c
index a56d3ce0581ee2f3c28a65492ea0ec614197aa79..20378274ec0c03bd7a4665589cea3008be05ba44 100644 (file)
@@ -1,22 +1,11 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+
 /***************************************************************************
  *   Copyright (C) 2012 by Matthias Blaicher                               *
  *   Matthias Blaicher - matthias@blaicher.com                             *
  *                                                                         *
  *   Copyright (C) 2011 by Broadcom Corporation                            *
  *   Evan Hunter - ehunter@broadcom.com                                    *
- *                                                                         *
- *   This program is free software; you can redistribute it and/or modify  *
- *   it under the terms of the GNU General Public License as published by  *
- *   the Free Software Foundation; either version 2 of the License, or     *
- *   (at your option) any later version.                                   *
- *                                                                         *
- *   This program is distributed in the hope that it will be useful,       *
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
- *   GNU General Public License for more details.                          *
- *                                                                         *
- *   You should have received a copy of the GNU General Public License     *
- *   along with this program.  If not, see <http://www.gnu.org/licenses/>. *
  ***************************************************************************/
 
 #ifdef HAVE_CONFIG_H
@@ -62,9 +51,9 @@ struct chibios_chdebug {
        uint8_t   cf_off_time;            /**< @brief Offset of @p p_time field.  */
 };
 
-#define GET_CH_KERNEL_MAJOR(codedVersion) ((codedVersion >> 11) & 0x1f)
-#define GET_CH_KERNEL_MINOR(codedVersion) ((codedVersion >> 6) & 0x1f)
-#define GET_CH_KERNEL_PATCH(codedVersion) ((codedVersion >> 0) & 0x3f)
+#define GET_CH_KERNEL_MAJOR(coded_version) ((coded_version >> 11) & 0x1f)
+#define GET_CH_KERNEL_MINOR(coded_version) ((coded_version >> 6) & 0x1f)
+#define GET_CH_KERNEL_PATCH(coded_version) ((coded_version >> 0) & 0x3f)
 
 /**
  * @brief ChibiOS thread states.
@@ -74,7 +63,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.
@@ -91,25 +80,24 @@ struct chibios_params {
 static struct chibios_params chibios_params_list[] = {
        {
        "cortex_m",                                                     /* target_name */
-       0,
+       NULL,
        NULL,                                                                   /* stacking_info */
        },
        {
        "hla_target",                                                   /* target_name */
-       0,
+       NULL,
        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);
 static int chibios_update_threads(struct rtos *rtos);
 static int chibios_get_thread_reg_list(struct rtos *rtos, int64_t thread_id,
                struct rtos_reg **reg_list, int *num_regs);
-static int chibios_get_symbol_list_to_lookup(symbol_table_elem_t *symbol_list[]);
+static int chibios_get_symbol_list_to_lookup(struct symbol_table_elem *symbol_list[]);
 
-struct rtos_type chibios_rtos = {
+const struct rtos_type chibios_rtos = {
        .name = "chibios",
 
        .detect_rtos = chibios_detect_rtos,
@@ -131,7 +119,7 @@ enum chibios_symbol_values {
        CHIBIOS_VAL_CH_DEBUG = 2
 };
 
-static symbol_table_elem_t chibios_symbol_list[] = {
+static struct symbol_table_elem chibios_symbol_list[] = {
        { "rlist", 0, true},            /* Thread ready list */
        { "ch", 0, true},                       /* System data structure */
        { "ch_debug", 0, false},        /* Memory Signature containing offsets of fields in rlist */
@@ -185,10 +173,10 @@ static int chibios_update_memory_signature(struct rtos *rtos)
        }
 
        /* Convert endianness of version field */
-       const uint8_t *versionTarget = (const uint8_t *)
+       const uint8_t *versiontarget = (const uint8_t *)
                                                                                &signature->ch_version;
        signature->ch_version = rtos->target->endianness == TARGET_LITTLE_ENDIAN ?
-                       le_to_h_u32(versionTarget) : be_to_h_u32(versionTarget);
+                       le_to_h_u32(versiontarget) : be_to_h_u32(versiontarget);
 
        const uint16_t ch_version = signature->ch_version;
        LOG_INFO("Successfully loaded memory map of ChibiOS/RT target "
@@ -210,7 +198,7 @@ static int chibios_update_memory_signature(struct rtos *rtos)
 errfree:
        /* Error reading the ChibiOS memory structure */
        free(signature);
-       param->signature = 0;
+       param->signature = NULL;
        return -1;
 }
 
@@ -470,8 +458,8 @@ static int chibios_get_thread_reg_list(struct rtos *rtos, int64_t thread_id,
        const struct chibios_params *param;
        uint32_t stack_ptr = 0;
 
-       if ((rtos == NULL) || (thread_id == 0) ||
-                       (rtos->rtos_specific_params == NULL))
+       if ((!rtos) || (thread_id == 0) ||
+                       (!rtos->rtos_specific_params))
                return -1;
 
        param = (const struct chibios_params *) rtos->rtos_specific_params;
@@ -480,7 +468,7 @@ static int chibios_get_thread_reg_list(struct rtos *rtos, int64_t thread_id,
                return -1;
 
        /* Update stacking if it can only be determined from runtime information */
-       if ((param->stacking_info == 0) &&
+       if (!param->stacking_info &&
                (chibios_update_stacking(rtos) != ERROR_OK)) {
                LOG_ERROR("Failed to determine exact stacking for the target type %s", rtos->target->type->name);
                return -1;
@@ -497,11 +485,11 @@ static int chibios_get_thread_reg_list(struct rtos *rtos, int64_t thread_id,
        return rtos_generic_stack_read(rtos->target, param->stacking_info, stack_ptr, reg_list, num_regs);
 }
 
-static int chibios_get_symbol_list_to_lookup(symbol_table_elem_t *symbol_list[])
+static int chibios_get_symbol_list_to_lookup(struct symbol_table_elem *symbol_list[])
 {
        *symbol_list = malloc(sizeof(chibios_symbol_list));
 
-       if (*symbol_list == NULL)
+       if (!*symbol_list)
                return ERROR_FAIL;
 
        memcpy(*symbol_list, chibios_symbol_list, sizeof(chibios_symbol_list));
@@ -510,7 +498,7 @@ static int chibios_get_symbol_list_to_lookup(symbol_table_elem_t *symbol_list[])
 
 static bool chibios_detect_rtos(struct target *target)
 {
-       if ((target->rtos->symbols != NULL) &&
+       if ((target->rtos->symbols) &&
                        ((target->rtos->symbols[CHIBIOS_VAL_RLIST].address != 0) ||
                         (target->rtos->symbols[CHIBIOS_VAL_CH].address != 0))) {
 
@@ -529,17 +517,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;
 }

Linking to existing account procedure

If you already have an account and want to add another login method you MUST first sign in with your existing account and then change URL to read https://review.openocd.org/login/?link to get to this page again but this time it'll work for linking. Thank you.

SSH host keys fingerprints

1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=..              |
|+o..   .         |
|*.o   . .        |
|+B . . .         |
|Bo. = o S        |
|Oo.+ + =         |
|oB=.* = . o      |
| =+=.+   + E     |
|. .=o   . o      |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)