target: Add a debug_reason command
[openocd.git] / src / target / dsp5680xx.c
index 62844ea3b74c2ed5d138fabcd9daffe099476dae..c90bca3c1f9ae72f631962b852cbc7095cfebce5 100644 (file)
@@ -1,22 +1,11 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+
 /***************************************************************************
  *  Copyright (C) 2011 by Rodrigo L. Rosa                                 *
  *  rodrigorosa.LG@gmail.com                                              *
  *                                                                        *
  *  Based on dsp563xx_once.h written by Mathias Kuester                   *
  *  mkdorg@users.sourceforge.net                                          *
- *                                                                        *
- *  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
@@ -27,7 +16,7 @@
 #include "target_type.h"
 #include "dsp5680xx.h"
 
-struct dsp5680xx_common dsp5680xx_context;
+static struct dsp5680xx_common dsp5680xx_context;
 
 #define _E "DSP5680XX_ERROR:%d\nAt:%s:%d:%s"
 #define err_check(r, c, m) if (r != ERROR_OK) {LOG_ERROR(_E, c, __func__, __LINE__, m); return r; }
@@ -85,7 +74,7 @@ static int dsp5680xx_drscan(struct target *target, uint8_t *d_in,
         */
        int retval = ERROR_OK;
 
-       if (NULL == target->tap) {
+       if (!target->tap) {
                retval = ERROR_FAIL;
                err_check(retval, DSP5680XX_ERROR_JTAG_INVALID_TAP,
                          "Invalid tap");
@@ -104,7 +93,7 @@ static int dsp5680xx_drscan(struct target *target, uint8_t *d_in,
                err_check(retval, DSP5680XX_ERROR_JTAG_DRSCAN,
                          "drscan failed!");
        }
-       if (d_out != NULL)
+       if (d_out)
                LOG_DEBUG("Data read (%d bits): 0x%04X", len, *d_out);
        else
                LOG_DEBUG("Data read was discarded.");
@@ -127,7 +116,7 @@ static int dsp5680xx_irscan(struct target *target, uint32_t *d_in,
 
        uint16_t tap_ir_len = DSP5680XX_JTAG_MASTER_TAP_IRLEN;
 
-       if (NULL == target->tap) {
+       if (!target->tap) {
                retval = ERROR_FAIL;
                err_check(retval, DSP5680XX_ERROR_JTAG_INVALID_TAP,
                          "Invalid tap");
@@ -140,7 +129,7 @@ static int dsp5680xx_irscan(struct target *target, uint32_t *d_in,
                } else {
                        struct jtag_tap *t =
                                jtag_tap_by_string("dsp568013.chp");
-                       if ((t == NULL)
+                       if ((!t)
                            || ((t->enabled) && (ir_len != tap_ir_len))) {
                                retval = ERROR_FAIL;
                                err_check(retval,
@@ -172,7 +161,7 @@ static int dsp5680xx_jtag_status(struct target *target, uint8_t *status)
                dsp5680xx_irscan(target, &instr, &read_from_ir,
                                 DSP5680XX_JTAG_CORE_TAP_IRLEN);
        err_check_propagate(retval);
-       if (status != NULL)
+       if (status)
                *status = (uint8_t) read_from_ir;
        return ERROR_OK;
 }
@@ -205,7 +194,7 @@ static int jtag_data_write(struct target *target, uint32_t instr, int num_bits,
                dsp5680xx_drscan(target, (uint8_t *) &instr,
                                 (uint8_t *) &data_read_dummy, num_bits);
        err_check_propagate(retval);
-       if (data_read != NULL)
+       if (data_read)
                *data_read = data_read_dummy;
        return retval;
 }
@@ -239,7 +228,7 @@ static int eonce_instruction_exec_single(struct target *target, uint8_t instr,
 
        retval = jtag_data_write(target, instr_with_flags, 8, &dr_out_tmp);
        err_check_propagate(retval);
-       if (eonce_status != NULL)
+       if (eonce_status)
                *eonce_status = (uint8_t) dr_out_tmp;
        return retval;
 }
@@ -501,7 +490,7 @@ static int core_move_value_to_pc(struct target *target, uint32_t value)
        return retval;
 }
 
-static int eonce_load_TX_RX_to_r0(struct target *target)
+static int eonce_load_tx_rx_to_r0(struct target *target)
 {
        int retval;
 
@@ -512,7 +501,7 @@ static int eonce_load_TX_RX_to_r0(struct target *target)
        return retval;
 }
 
-static int core_load_TX_RX_high_addr_to_r0(struct target *target)
+static int core_load_tx_rx_high_addr_to_r0(struct target *target)
 {
        int retval = 0;
 
@@ -577,9 +566,9 @@ static int switch_tap(struct target *target, struct jtag_tap *master_tap,
 
        uint32_t ir_out;        /* not used, just to make jtag happy. */
 
-       if (master_tap == NULL) {
+       if (!master_tap) {
                master_tap = jtag_tap_by_string("dsp568013.chp");
-               if (master_tap == NULL) {
+               if (!master_tap) {
                        retval = ERROR_FAIL;
                        const char *msg = "Failed to get master tap.";
 
@@ -587,9 +576,9 @@ static int switch_tap(struct target *target, struct jtag_tap *master_tap,
                                  msg);
                }
        }
-       if (core_tap == NULL) {
+       if (!core_tap) {
                core_tap = jtag_tap_by_string("dsp568013.cpu");
-               if (core_tap == NULL) {
+               if (!core_tap) {
                        retval = ERROR_FAIL;
                        err_check(retval, DSP5680XX_ERROR_JTAG_TAP_FIND_CORE,
                                  "Failed to get core tap.");
@@ -695,7 +684,7 @@ static int eonce_enter_debug_mode_without_reset(struct target *target,
                 */
                err_check_propagate(retval);
        }
-       if (eonce_status != NULL)
+       if (eonce_status)
                *eonce_status = data_read_from_dr;
        return retval;
 }
@@ -731,13 +720,13 @@ static int eonce_enter_debug_mode(struct target *target,
        struct jtag_tap *tap_cpu;
 
        tap_chp = jtag_tap_by_string("dsp568013.chp");
-       if (tap_chp == NULL) {
+       if (!tap_chp) {
                retval = ERROR_FAIL;
                err_check(retval, DSP5680XX_ERROR_JTAG_TAP_FIND_MASTER,
                          "Failed to get master tap.");
        }
        tap_cpu = jtag_tap_by_string("dsp568013.cpu");
-       if (tap_cpu == NULL) {
+       if (!tap_cpu) {
                retval = ERROR_FAIL;
                err_check(retval, DSP5680XX_ERROR_JTAG_TAP_FIND_CORE,
                          "Failed to get master tap.");
@@ -833,7 +822,7 @@ static int eonce_enter_debug_mode(struct target *target,
                retval = ERROR_TARGET_FAILURE;
                err_check(retval, DSP5680XX_ERROR_ENTER_DEBUG_MODE, msg);
        }
-       if (eonce_status != NULL)
+       if (eonce_status)
                *eonce_status = data_read_from_dr;
        return retval;
 }
@@ -855,7 +844,7 @@ static int eonce_pc_store(struct target *target)
        err_check_propagate(retval);
        retval = core_move_r4_to_y(target);
        err_check_propagate(retval);
-       retval = eonce_load_TX_RX_to_r0(target);
+       retval = eonce_load_tx_rx_to_r0(target);
        err_check_propagate(retval);
        retval = core_move_y0_at_r0(target);
        err_check_propagate(retval);
@@ -1110,7 +1099,7 @@ static int dsp5680xx_read_16_single(struct target *t, uint32_t a,
        else
                retval = core_move_at_r0_to_y0(target);
        err_check_propagate(retval);
-       retval = eonce_load_TX_RX_to_r0(target);
+       retval = eonce_load_tx_rx_to_r0(target);
        err_check_propagate(retval);
        retval = core_move_y0_at_r0(target);
        err_check_propagate(retval);
@@ -1147,7 +1136,7 @@ static int dsp5680xx_read_32_single(struct target *t, uint32_t a,
                err_check_propagate(retval);
        }
        /* Get lower part of data to TX/RX */
-       retval = eonce_load_TX_RX_to_r0(target);
+       retval = eonce_load_tx_rx_to_r0(target);
        err_check_propagate(retval);
        retval = core_move_y0_at_r0_inc(target);    /* This also load TX/RX high to r0 */
        err_check_propagate(retval);
@@ -1543,7 +1532,7 @@ static int perl_crc(const uint8_t *buff8, uint32_t word_count)
  *
  * @return
  */
-static int dsp5680xx_f_SIM_reset(struct target *target)
+static int dsp5680xx_f_sim_reset(struct target *target)
 {
        int retval = ERROR_OK;
 
@@ -1575,7 +1564,7 @@ static int dsp5680xx_soft_reset_halt(struct target *target)
 
        retval = dsp5680xx_halt(target);
        err_check_propagate(retval);
-       retval = dsp5680xx_f_SIM_reset(target);
+       retval = dsp5680xx_f_sim_reset(target);
        err_check_propagate(retval);
        return retval;
 }
@@ -1585,7 +1574,7 @@ int dsp5680xx_f_protect_check(struct target *target, uint16_t *protected)
        int retval;
 
        check_halt_and_debug(target);
-       if (protected == NULL) {
+       if (!protected) {
                const char *msg = "NULL pointer not valid.";
 
                err_check(ERROR_FAIL,
@@ -1617,7 +1606,7 @@ static int dsp5680xx_f_ex(struct target *target, uint16_t c, uint32_t address, u
        uint32_t command = c;
        int retval;
 
-       retval = core_load_TX_RX_high_addr_to_r0(target);
+       retval = core_load_tx_rx_high_addr_to_r0(target);
        err_check_propagate(retval);
        retval = core_move_long_to_r2(target, HFM_BASE_ADDR);
        err_check_propagate(retval);
@@ -1727,7 +1716,7 @@ static int set_fm_ck_div(struct target *target)
 
        retval = core_move_long_to_r2(target, HFM_BASE_ADDR);
        err_check_propagate(retval);
-       retval = core_load_TX_RX_high_addr_to_r0(target);
+       retval = core_load_tx_rx_high_addr_to_r0(target);
        err_check_propagate(retval);
        /* read HFM_CLKD */
        retval = core_move_at_r2_to_y0(target);
@@ -1829,7 +1818,7 @@ int dsp5680xx_f_erase_check(struct target *target, uint8_t *erased,
        retval =
                dsp5680xx_f_ex(target, HFM_ERASE_VERIFY, tmp, 0, &hfm_ustat, 1);
        err_check_propagate(retval);
-       if (erased != NULL)
+       if (erased)
                *erased = (uint8_t) (hfm_ustat & HFM_USTAT_MASK_BLANK);
        return retval;
 }
@@ -1882,7 +1871,7 @@ int dsp5680xx_f_erase(struct target *target, int first, int last)
         * Reset SIM
         *
         */
-       retval = dsp5680xx_f_SIM_reset(target);
+       retval = dsp5680xx_f_sim_reset(target);
        err_check_propagate(retval);
        /*
         * Set hfmdiv
@@ -2014,7 +2003,7 @@ int dsp5680xx_f_wr(struct target *t, const uint8_t *b, uint32_t a, uint32_t coun
 
        retval = core_move_long_to_r3(target, address); /* Destination address to r3 */
        err_check_propagate(retval);
-       core_load_TX_RX_high_addr_to_r0(target); /* TX/RX reg address to r0 */
+       core_load_tx_rx_high_addr_to_r0(target); /* TX/RX reg address to r0 */
        err_check_propagate(retval);
        retval = core_move_long_to_r2(target, HFM_BASE_ADDR); /* FM base address to r2 */
        err_check_propagate(retval);
@@ -2118,13 +2107,13 @@ int dsp5680xx_f_unlock(struct target *target)
        struct jtag_tap *tap_cpu;
 
        tap_chp = jtag_tap_by_string("dsp568013.chp");
-       if (tap_chp == NULL) {
+       if (!tap_chp) {
                retval = ERROR_FAIL;
                err_check(retval, DSP5680XX_ERROR_JTAG_TAP_ENABLE_MASTER,
                          "Failed to get master tap.");
        }
        tap_cpu = jtag_tap_by_string("dsp568013.cpu");
-       if (tap_cpu == NULL) {
+       if (!tap_cpu) {
                retval = ERROR_FAIL;
                err_check(retval, DSP5680XX_ERROR_JTAG_TAP_ENABLE_CORE,
                          "Failed to get master tap.");
@@ -2211,8 +2200,8 @@ int dsp5680xx_f_lock(struct target *target)
        struct jtag_tap *tap_chp;
 
        struct jtag_tap *tap_cpu;
-       uint16_t lock_word[] = { HFM_LOCK_FLASH };
-       retval = dsp5680xx_f_wr(target, (uint8_t *) (lock_word), HFM_LOCK_ADDR_L, 2, 1);
+       uint16_t lock_word = HFM_LOCK_FLASH;
+       retval = dsp5680xx_f_wr(target, (uint8_t *)&lock_word, HFM_LOCK_ADDR_L, 2, 1);
        err_check_propagate(retval);
 
        jtag_add_reset(0, 1);
@@ -2226,13 +2215,13 @@ int dsp5680xx_f_lock(struct target *target)
        jtag_add_sleep(TIME_DIV_FREESCALE * 300 * 1000);
 
        tap_chp = jtag_tap_by_string("dsp568013.chp");
-       if (tap_chp == NULL) {
+       if (!tap_chp) {
                retval = ERROR_FAIL;
                err_check(retval, DSP5680XX_ERROR_JTAG_TAP_ENABLE_MASTER,
                          "Failed to get master tap.");
        }
        tap_cpu = jtag_tap_by_string("dsp568013.cpu");
-       if (tap_cpu == NULL) {
+       if (!tap_cpu) {
                retval = ERROR_FAIL;
                err_check(retval, DSP5680XX_ERROR_JTAG_TAP_ENABLE_CORE,
                          "Failed to get master tap.");

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)