+// 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, write to the *
- * Free Software Foundation, Inc., *
- * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#ifdef HAVE_CONFIG_H
#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; }
#define CHECK_HALT(target) if (target->state != TARGET_HALTED) HALT_FAIL
#define check_halt_and_debug(target) { CHECK_HALT(target); CHECK_DBG; }
-int dsp5680xx_execute_queue(void)
+static int dsp5680xx_execute_queue(void)
{
int retval;
}
/**
- *Reset state machine
+ * Reset state machine
*/
static int reset_jtag(void)
{
static int dsp5680xx_drscan(struct target *target, uint8_t *d_in,
uint8_t *d_out, int len)
{
- /** -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
+ /* -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
*
*Inputs:
* - d_in: This is the data that will be shifted into the JTAG DR reg.
*/
int retval = ERROR_OK;
- if (NULL == target->tap) {
+ if (!target->tap) {
retval = ERROR_FAIL;
err_check(retval, DSP5680XX_ERROR_JTAG_INVALID_TAP,
"Invalid tap");
if (len > 32) {
retval = ERROR_FAIL;
err_check(retval, DSP5680XX_ERROR_JTAG_DR_LEN_OVERFLOW,
- "dr_len overflow, maxium is 32");
+ "dr_len overflow, maximum is 32");
}
/* TODO what values of len are valid for jtag_add_plain_dr_scan? */
/* can i send as many bits as i want? */
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.");
return retval;
}
-/** -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
- *Inputs:
- * - data_to_shift_into_ir: This is the data that will be shifted into the JTAG IR reg.
- * - data_shifted_out_of_ir: The data that will be shifted out of the JTAG IR reg will be
- * stored here
- * - len: Length of the data to be shifted to JTAG IR.
+/**
+ * Test func
+ *
+ * @param target
+ * @param d_in This is the data that will be shifted into the JTAG IR reg.
+ * @param d_out The data that will be shifted out of the JTAG IR reg will be stored here.
+ * @param ir_len Length of the data to be shifted to JTAG IR.
*
- *-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
*/
static int dsp5680xx_irscan(struct target *target, uint32_t *d_in,
uint32_t *d_out, uint8_t ir_len)
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");
} 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,
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;
}
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;
}
#define jtag_data_write32(target, instr, data_read) jtag_data_write(target, instr, 32, data_read)
/**
- *Executes EOnCE instruction.
+ * Executes EOnCE instruction.
*
- *@param target
- *@param instr Instruction to execute.
- *@param rw
- *@param go
- *@param ex
- *@param eonce_status Value read from the EOnCE status register.
+ * @param target
+ * @param instr Instruction to execute.
+ * @param rw
+ * @param go
+ * @param ex
+ * @param eonce_status Value read from the EOnCE status register.
*
- *@return
+ * @return
*/
static int eonce_instruction_exec_single(struct target *target, uint8_t instr,
uint8_t rw, uint8_t go, uint8_t ex,
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;
}
return retval;
}
-/**
+/*
*--------------- Real-time data exchange ---------------
- *The EOnCE Transmit (OTX) and Receive (ORX) registers are data memory mapped, each with an upper
- *and lower 16 bit word.
- *Transmit and receive directions are defined from the core’s perspective.
- *The core writes to the Transmit register and reads the Receive register, and the host through
- *JTAG writes to the Receive register and reads the Transmit register.
- *Both registers have a combined data memory mapped OTXRXSR which provides indication when
- *each may be accessed.
- *ref: eonce_rev.1.0_0208081.pdf@36
+ * The EOnCE Transmit (OTX) and Receive (ORX) registers are data memory mapped, each with an upper
+ * and lower 16 bit word.
+ * Transmit and receive directions are defined from the core’s perspective.
+ * The core writes to the Transmit register and reads the Receive register, and the host through
+ * JTAG writes to the Receive register and reads the Transmit register.
+ * Both registers have a combined data memory mapped OTXRXSR which provides indication when
+ * each may be accessed.
+ * ref: eonce_rev.1.0_0208081.pdf@36
*/
/* writes data into upper ORx register of the target */
/**
*
- *@param target
- *@param data_read: Returns the data read from the upper OTX register via JTAG.
- *@return: Returns an error code (see error code documentation)
+ * @param target
+ * @param data_read: Returns the data read from the upper OTX register via JTAG.
+ * @return: Returns an error code (see error code documentation)
*/
static int core_rx_upper_data(struct target *target, uint8_t *data_read)
{
/**
*
- *@param target
- *@param data_read: Returns the data read from the lower OTX register via JTAG.
- *@return: Returns an error code (see error code documentation)
+ * @param target
+ * @param data_read: Returns the data read from the lower OTX register via JTAG.
+ * @return: Returns an error code (see error code documentation)
*/
static int core_rx_lower_data(struct target *target, uint8_t *data_read)
{
return retval;
}
-/**
+/*
*-- -- -- -- --- -- -- -- --- -- -- -- --- -- -- -- --- -- -- -- --- --
*-- -- -- -- --- -- -- -Core Instructions- -- -- -- --- -- -- -- --- --
*-- -- -- -- --- -- -- -- --- -- -- -- --- -- -- -- --- -- -- -- --- --
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;
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;
}
/**
- *Takes the core out of debug mode.
+ * Takes the core out of debug mode.
*
- *@param target
- *@param eonce_status Data read from the EOnCE status register.
+ * @param target
+ * @param eonce_status Data read from the EOnCE status register.
*
- *@return
+ * @return
*/
static int eonce_exit_debug_mode(struct target *target, uint8_t *eonce_status)
{
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.";
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.");
}
/**
- *Puts the core into debug mode, enabling the EOnCE module.
- *This will not always work, eonce_enter_debug_mode executes much
- *more complicated routine, which is guaranteed to work, but requires
- *a reset. This will complicate comm with the flash module, since
- *after a reset clock divisors must be set again.
- *This implementation works most of the time, and is not accesible to the
- *user.
+ * Puts the core into debug mode, enabling the EOnCE module.
+ * This will not always work, eonce_enter_debug_mode executes much
+ * more complicated routine, which is guaranteed to work, but requires
+ * a reset. This will complicate comm with the flash module, since
+ * after a reset clock divisors must be set again.
+ * This implementation works most of the time, and is not accessible to the
+ * user.
*
- *@param target
- *@param eonce_status Data read from the EOnCE status register.
+ * @param target
+ * @param eonce_status Data read from the EOnCE status register.
*
- *@return
+ * @return
*/
static int eonce_enter_debug_mode_without_reset(struct target *target,
uint16_t *eonce_status)
*/
err_check_propagate(retval);
}
- if (eonce_status != NULL)
+ if (eonce_status)
*eonce_status = data_read_from_dr;
return retval;
}
/**
- *Puts the core into debug mode, enabling the EOnCE module.
+ * Puts the core into debug mode, enabling the EOnCE module.
*
- *@param target
- *@param eonce_status Data read from the EOnCE status register.
+ * @param target
+ * @param eonce_status Data read from the EOnCE status register.
*
- *@return
+ * @return
*/
static int eonce_enter_debug_mode(struct target *target,
uint16_t *eonce_status)
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.");
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;
}
/**
- *Reads the current value of the program counter and stores it.
+ * Reads the current value of the program counter and stores it.
*
- *@param target
+ * @param target
*
- *@return
+ * @return
*/
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);
dsp5680xx_context.debug_mode_enabled = false;
LOG_DEBUG("target initiated!");
/* TODO core tap must be enabled before running these commands, currently
- this is done in the .cfg tcl script. */
+ * this is done in the .cfg tcl script. */
return ERROR_OK;
}
return ERROR_OK;
}
-int dsp5680xx_target_status(struct target *target, uint8_t *jtag_st,
- uint16_t *eonce_st)
-{
- return target->state;
-}
-
static int dsp5680xx_assert_reset(struct target *target)
{
target->state = TARGET_RESET;
__func__);
target->state = TARGET_UNKNOWN;
return ERROR_TARGET_FAILURE;
- };
+ }
if (target->state == TARGET_UNKNOWN) {
LOG_ERROR("%s: Target status invalid - communication failure",
__func__);
return ERROR_TARGET_FAILURE;
- };
+ }
return ERROR_OK;
}
static int dsp5680xx_resume(struct target *target, int current,
- uint32_t address, int hb, int d)
+ target_addr_t address, int hb, int d)
{
if (target->state == TARGET_RUNNING) {
LOG_USER("Target already running.");
}
LOG_DEBUG("EOnCE status: 0x%02X.", eonce_status);
} else {
- /**
- *If debug mode was not enabled but target was halted, then it is most likely that
- *access to eonce registers is locked.
- *Reset target to make it run again.
+ /*
+ * If debug mode was not enabled but target was halted, then it is most likely that
+ * access to eonce registers is locked.
+ * Reset target to make it run again.
*/
jtag_add_reset(0, 1);
jtag_add_sleep(TIME_DIV_FREESCALE * 200 * 1000);
}
/**
- *The value of @address determines if it corresponds to P: (program) or X: (dat) memory.
- *If the address is over 0x200000 then it is considered X: memory, and @pmem = 0.
- *The special case of 0xFFXXXX is not modified, since it allows to read out the
+ * The value of @a address determines if it corresponds to P: (program) or X: (dat) memory.
+ * If the address is over 0x200000 then it is considered X: memory, and @a pmem = 0.
+ * The special case of 0xFFXXXX is not modified, since it allows to read out the
* memory mapped EOnCE registers.
*
- *@param address
- *@param pmem
+ * @param address
+ * @param pmem
*
- *@return
+ * @return
*/
static int dsp5680xx_convert_address(uint32_t *address, int *pmem)
{
- /**
- *Distinguish data memory (x) from program memory (p) by the address.
- *Addresses over S_FILE_DATA_OFFSET are considered (x) memory.
+ /*
+ * Distinguish data memory (x) from program memory (p) by the address.
+ * Addresses over S_FILE_DATA_OFFSET are considered (x) memory.
*/
if (*address >= S_FILE_DATA_OFFSET) {
*pmem = 0;
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);
/* at this point the data i want is at the reg eonce can read */
retval = core_rx_lower_data(target, data_read);
err_check_propagate(retval);
- LOG_DEBUG("%s:Data read from 0x%06X: 0x%02X%02X", __func__, address,
+ LOG_DEBUG("%s:Data read from 0x%06" PRIX32 ": 0x%02X%02X", __func__, address,
data_read[1], data_read[0]);
return retval;
}
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);
return retval;
}
-static int dsp5680xx_read(struct target *t, uint32_t a, unsigned size,
- unsigned count, uint8_t *buf)
+static int dsp5680xx_read(struct target *t, target_addr_t a, uint32_t size,
+ uint32_t count, uint8_t *buf)
{
struct target *target = t;
dsp5680xx_write_16_single(target, address + iter, data_16,
pmem);
if (retval != ERROR_OK) {
- LOG_ERROR("%s: Could not write to p:0x%04X", __func__,
+ LOG_ERROR("%s: Could not write to p:0x%04" PRIX32, __func__,
address);
dsp5680xx_context.flush = 1;
return retval;
dsp5680xx_write_16_single(target, address + iter,
data[iter], pmem);
if (retval != ERROR_OK) {
- LOG_ERROR("%s: Could not write to p:0x%04X", __func__,
+ LOG_ERROR("%s: Could not write to p:0x%04" PRIX32, __func__,
address);
dsp5680xx_context.flush = 1;
return retval;
dsp5680xx_write_32_single(target, address + (iter << 1),
data[iter], pmem);
if (retval != ERROR_OK) {
- LOG_ERROR("%s: Could not write to p:0x%04X", __func__,
+ LOG_ERROR("%s: Could not write to p:0x%04" PRIX32, __func__,
address);
dsp5680xx_context.flush = 1;
return retval;
}
/**
- *Writes @buffer to memory.
- *The parameter @address determines whether @buffer should be written to
- *P: (program) memory or X: (dat) memory.
+ * Writes @a buffer to memory.
+ * The parameter @a address determines whether @a buffer should be written to
+ * P: (program) memory or X: (dat) memory.
*
- *@param target
- *@param address
- *@param size Bytes (1), Half words (2), Words (4).
- *@param count In bytes.
- *@param buffer
+ * @param target
+ * @param a address
+ * @param size Bytes (1), Half words (2), Words (4).
+ * @param count In bytes.
+ * @param b buffer
*
- *@return
+ * @return
*/
-static int dsp5680xx_write(struct target *t, uint32_t a, uint32_t s, uint32_t c,
+static int dsp5680xx_write(struct target *target, target_addr_t a, uint32_t size, uint32_t count,
const uint8_t *b)
{
/* TODO Cannot write 32bit to odd address, will write 0x12345678 as 0x5678 0x0012 */
- struct target *target = t;
-
uint32_t address = a;
- uint32_t count = c;
-
uint8_t const *buffer = b;
- uint32_t size = s;
-
check_halt_and_debug(target);
int retval = 0;
return retval;
}
-static int dsp5680xx_bulk_write_memory(struct target *t, uint32_t a,
- uint32_t al, const uint8_t *b)
-{
- LOG_ERROR("Not implemented yet.");
- return ERROR_FAIL;
-}
-
-static int dsp5680xx_write_buffer(struct target *t, uint32_t a, uint32_t size,
+static int dsp5680xx_write_buffer(struct target *t, target_addr_t a, uint32_t size,
const uint8_t *b)
{
check_halt_and_debug(t);
}
/**
- *This function is called by verify_image, it is used to read data from memory.
+ * This function is called by verify_image, it is used to read data from memory.
*
- *@param target
- *@param address Word addressing.
- *@param size In bytes.
- *@param buffer
+ * @param target
+ * @param address Word addressing.
+ * @param size In bytes.
+ * @param buffer
*
- *@return
+ * @return
*/
-static int dsp5680xx_read_buffer(struct target *t, uint32_t a, uint32_t size,
- uint8_t *buf)
+static int dsp5680xx_read_buffer(struct target *target, target_addr_t address, uint32_t size,
+ uint8_t *buffer)
{
- check_halt_and_debug(t);
+ check_halt_and_debug(target);
/* The "/2" solves the byte/word addressing issue.*/
- return dsp5680xx_read(t, a, 2, size / 2, buf);
+ return dsp5680xx_read(target, address, 2, size / 2, buffer);
}
/**
- *This function is not implemented.
- *It returns an error in order to get OpenOCD to do read out the data
+ * This function is not implemented.
+ * It returns an error in order to get OpenOCD to do read out the data
* and calculate the CRC, or try a binary comparison.
*
- *@param target
- *@param address Start address of the image.
- *@param size In bytes.
- *@param checksum
+ * @param target
+ * @param address Start address of the image.
+ * @param size In bytes.
+ * @param checksum
*
- *@return
+ * @return
*/
-static int dsp5680xx_checksum_memory(struct target *t, uint32_t a, uint32_t s,
+static int dsp5680xx_checksum_memory(struct target *target, target_addr_t address, uint32_t size,
uint32_t *checksum)
{
return ERROR_FAIL;
}
/**
- *Calculates a signature over @word_count words in the data from @buff16.
- * The algorithm used is the same the FM uses, so the @return may be used to compare
+ * Calculates a signature over @a word_count words in the data from @a buff8.
+ * The algorithm used is the same the FM uses, so the @a return may be used to compare
* with the one generated by the FM module, and check if flashing was successful.
- *This algorithm is based on the perl script available from the Freescale website at FAQ 25630.
+ * This algorithm is based on the perl script available from the Freescale website at FAQ 25630.
*
- *@param buff16
- *@param word_count
+ * @param buff8
+ * @param word_count
*
- *@return
+ * @return
*/
-static int perl_crc(uint8_t *buff8, uint32_t word_count)
+static int perl_crc(const uint8_t *buff8, uint32_t word_count)
{
uint16_t checksum = 0xffff;
}
/**
- *Resets the SIM. (System Integration Modul).
+ * Resets the SIM. (System Integration Modul).
*
- *@param target
+ * @param target
*
- *@return
+ * @return
*/
-int dsp5680xx_f_SIM_reset(struct target *target)
+static int dsp5680xx_f_sim_reset(struct target *target)
{
int retval = ERROR_OK;
}
/**
- *Halts the core and resets the SIM. (System Integration Modul).
+ * Halts the core and resets the SIM. (System Integration Modul).
*
- *@param target
+ * @param target
*
- *@return
+ * @return
*/
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;
}
int retval;
check_halt_and_debug(target);
- if (protected == NULL) {
+ if (!protected) {
const char *msg = "NULL pointer not valid.";
err_check(ERROR_FAIL,
}
/**
- *Executes a command on the FM module.
- *Some commands use the parameters @address and @data, others ignore them.
+ * Executes a command on the FM module.
+ * Some commands use the parameters @a address and @a data, others ignore them.
*
- *@param target
- *@param command Command to execute.
- *@param address Command parameter.
- *@param data Command parameter.
- *@param hfm_ustat FM status register.
- *@param pmem Address is P: (program) memory (@pmem == 1) or X: (dat) memory (@pmem == 0)
+ * @param target
+ * @param c Command to execute.
+ * @param address Command parameter.
+ * @param data Command parameter.
+ * @param hfm_ustat FM status register.
+ * @param pmem Address is P: (program) memory (@a pmem == 1) or X: (dat) memory (@a pmem == 0)
*
- *@return
+ * @return
*/
-static int dsp5680xx_f_ex(struct target *t, uint16_t c, uint32_t a, uint32_t d,
- uint16_t *h, int p)
+static int dsp5680xx_f_ex(struct target *target, uint16_t c, uint32_t address, uint32_t data,
+ uint16_t *hfm_ustat, int pmem)
{
- struct target *target = t;
-
uint32_t command = c;
-
- uint32_t address = a;
-
- uint32_t data = d;
-
- uint16_t *hfm_ustat = h;
-
- int pmem = p;
-
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);
}
/**
- *Prior to the execution of any Flash module command, the Flash module Clock Divider (CLKDIV) register must be initialized. The values of this register determine the speed of the internal Flash Clock (FCLK). FCLK must be in the range of 150kHz ≤ FCLK ≤ 200kHz for proper operation of the Flash module. (Running FCLK too slowly wears out the module, while running it too fast under programs Flash leading to bit errors.)
+ * Prior to the execution of any Flash module command, the Flash module Clock
+ * Divider (CLKDIV) register must be initialized. The values of this register
+ * determine the speed of the internal Flash Clock (FCLK). FCLK must be in the
+ * range of 150kHz ≤ FCLK ≤ 200kHz for proper operation of the Flash module.
+ * (Running FCLK too slowly wears out the module, while running it too fast
+ * under programs Flash leading to bit errors.)
*
- *@param target
+ * @param target
*
- *@return
+ * @return
*/
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);
}
/**
- *Executes the FM calculate signature command. The FM will calculate over the data from @address to @address + @words -1. The result is written to a register, then read out by this function and returned in @signature. The value @signature may be compared to the the one returned by perl_crc to verify the flash was written correctly.
+ * Executes the FM calculate signature command. The FM will calculate over the
+ * data from @a address to @a address + @a words -1. The result is written to a
+ * register, then read out by this function and returned in @a signature. The
+ * value @a signature may be compared to the one returned by perl_crc to
+ * verify the flash was written correctly.
*
- *@param target
- *@param address Start of flash array where the signature should be calculated.
- *@param words Number of words over which the signature should be calculated.
- *@param signature Value calculated by the FM.
+ * @param target
+ * @param address Start of flash array where the signature should be calculated.
+ * @param words Number of words over which the signature should be calculated.
+ * @param signature Value calculated by the FM.
*
- *@return
+ * @return
*/
-static int dsp5680xx_f_signature(struct target *t, uint32_t a, uint32_t words,
+static int dsp5680xx_f_signature(struct target *target, uint32_t address, uint32_t words,
uint16_t *signature)
{
- struct target *target = t;
-
- uint32_t address = a;
-
int retval;
uint16_t hfm_ustat;
if (!dsp5680xx_context.debug_mode_enabled) {
retval = eonce_enter_debug_mode_without_reset(target, NULL);
- /**
- *Generate error here, since it is not done in eonce_enter_debug_mode_without_reset
+ /*
+ * Generate error here, since it is not done in eonce_enter_debug_mode_without_reset
*/
err_check(retval, DSP5680XX_ERROR_HALT,
"Failed to halt target.");
}
retval = set_fm_ck_div(target);
err_check_propagate(retval);
- /**
- *Check if chip is already erased.
+ /*
+ * Check if chip is already erased.
*/
tmp = HFM_FLASH_BASE_ADDR + sector * HFM_SECTOR_SIZE / 2;
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;
}
/**
- *Executes the FM page erase command.
+ * Executes the FM page erase command.
*
- *@param target
- *@param sector Page to erase.
- *@param hfm_ustat FM module status register.
+ * @param target
+ * @param sector Page to erase.
+ * @param hfm_ustat FM module status register.
*
- *@return
+ * @return
*/
static int erase_sector(struct target *target, int sector, uint16_t *hfm_ustat)
{
}
/**
- *Executes the FM mass erase command. Erases the flash array completely.
+ * Executes the FM mass erase command. Erases the flash array completely.
*
- *@param target
- *@param hfm_ustat FM module status register.
+ * @param target
+ * @param hfm_ustat FM module status register.
*
- *@return
+ * @return
*/
static int mass_erase(struct target *target, uint16_t *hfm_ustat)
{
retval = dsp5680xx_halt(target);
err_check_propagate(retval);
}
- /** -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
+ /*
* Reset SIM
- * -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
+ *
*/
- retval = dsp5680xx_f_SIM_reset(target);
+ retval = dsp5680xx_f_sim_reset(target);
err_check_propagate(retval);
- /** -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
+ /*
* Set hfmdiv
- * -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
+ *
*/
retval = set_fm_ck_div(target);
err_check_propagate(retval);
return ERROR_OK;
}
-/**
- *Algorithm for programming normal p: flash
- *Follow state machine from "56F801x Peripheral Reference Manual"@163.
- *Registers to set up before calling:
+/*
+ * Algorithm for programming normal p: flash
+ * Follow state machine from "56F801x Peripheral Reference Manual"@163.
+ * Registers to set up before calling:
* r0: TX/RX high address.
* r2: FM module base address.
* r3: Destination address in flash.
* brclr #0x10, A, hfm_wait // access error check
* bfset #0x10, X:(R2+0x13) // clear accerr
* bra hfm_wait // loop
- *0x00000000 0x8A460013807D brclr #0x80, X:(R2+0x13),*+0
- *0x00000003 0xE700 nop
- *0x00000004 0xE700 nop
- *0x00000005 0x8A44FFFE017B brclr #1, X:(R0-2),*-2
- *0x00000008 0xE700 nop
- *0x00000009 0xF514 move.w X:(R0), Y0
- *0x0000000A 0x8563 move.w Y0, P:(R3)+
- *0x0000000B 0x864600200014 move.w #32, X:(R2+0x14)
- *0x0000000E 0x864600800013 move.w #128, X:(R2+0x13)
- *0x00000011 0xF0420013 move.w X:(R2+0x13), A
- *0x00000013 0x8B402004 brclr #0x20, A,*+6
- *0x00000015 0x824600130020 bfset #0x20, X:(R2+0x13)
- *0x00000018 0xA967 bra *-24
- *0x00000019 0x8B401065 brclr #0x10, A,*-25
- *0x0000001B 0x824600130010 bfset #0x10, X:(R2+0x13)
- *0x0000001E 0xA961 bra *-30
+ * 0x00000000 0x8A460013807D brclr #0x80, X:(R2+0x13),*+0
+ * 0x00000003 0xE700 nop
+ * 0x00000004 0xE700 nop
+ * 0x00000005 0x8A44FFFE017B brclr #1, X:(R0-2),*-2
+ * 0x00000008 0xE700 nop
+ * 0x00000009 0xF514 move.w X:(R0), Y0
+ * 0x0000000A 0x8563 move.w Y0, P:(R3)+
+ * 0x0000000B 0x864600200014 move.w #32, X:(R2+0x14)
+ * 0x0000000E 0x864600800013 move.w #128, X:(R2+0x13)
+ * 0x00000011 0xF0420013 move.w X:(R2+0x13), A
+ * 0x00000013 0x8B402004 brclr #0x20, A,*+6
+ * 0x00000015 0x824600130020 bfset #0x20, X:(R2+0x13)
+ * 0x00000018 0xA967 bra *-24
+ * 0x00000019 0x8B401065 brclr #0x10, A,*-25
+ * 0x0000001B 0x824600130010 bfset #0x10, X:(R2+0x13)
+ * 0x0000001E 0xA961 bra *-30
*/
-const uint16_t pgm_write_pflash[] = { 0x8A46, 0x0013, 0x807D, 0xE700,
+static const uint16_t pgm_write_pflash[] = {
+ 0x8A46, 0x0013, 0x807D, 0xE700,
0xE700, 0x8A44, 0xFFFE, 0x017B,
0xE700, 0xF514, 0x8563, 0x8646,
0x0020, 0x0014, 0x8646, 0x0080,
0x0013, 0x0010, 0xA961
};
-const uint32_t pgm_write_pflash_length = 31;
+static const uint32_t pgm_write_pflash_length = 31;
-int dsp5680xx_f_wr(struct target *t, uint8_t *b, uint32_t a, uint32_t count,
+int dsp5680xx_f_wr(struct target *t, const uint8_t *b, uint32_t a, uint32_t count,
int is_flash_lock)
{
struct target *target = t;
uint32_t address = a;
- uint8_t *buffer = b;
+ const uint8_t *buffer = b;
int retval = ERROR_OK;
retval = eonce_enter_debug_mode(target, NULL);
err_check_propagate(retval);
}
- /** -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
+ /*
* Download the pgm that flashes.
- * -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
+ *
*/
const uint32_t len = pgm_write_pflash_length;
uint32_t ram_addr = 0x8700;
- /**
+ /*
* This seems to be a safe address.
- *This one is the one used by codewarrior in 56801x_flash.cfg
+ * This one is the one used by codewarrior in 56801x_flash.cfg
*/
if (!is_flash_lock) {
retval =
retval = dsp5680xx_execute_queue();
err_check_propagate(retval);
}
- /** -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
+ /*
* Set hfmdiv
- * -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
+ *
*/
retval = set_fm_ck_div(target);
err_check_propagate(retval);
- /** -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
+ /*
* Setup registers needed by pgm_write_pflash
- * -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
+ *
*/
dsp5680xx_context.flush = 0;
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);
- /** -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
+ /*
* Run flashing program.
- * -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
+ *
*/
/* write to HFM_CNFG (lock=0, select bank) */
retval = core_move_value_at_r2_disp(target, 0x00, HFM_CNFG);
}
dsp5680xx_context.flush = 1;
if (!is_flash_lock) {
- /** -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
+ /*
*Verify flash (skip when exec lock sequence)
- * -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
+ *
*/
uint16_t signature;
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.");
err_check_propagate(retval);
instr = HFM_CLK_DEFAULT;
- retval =
- dsp5680xx_drscan(target, (uint8_t *) &instr, (uint8_t *) &ir_out,
- 16);
+ retval = dsp5680xx_drscan(target, (uint8_t *) &instr, (uint8_t *) &ir_out, 16);
err_check_propagate(retval);
jtag_add_sleep(TIME_DIV_FREESCALE * 150 * 1000);
jtag_add_sleep(150);
instr = 0x0606ffff;
- retval =
- dsp5680xx_drscan(target, (uint8_t *) &instr, (uint8_t *) &ir_out,
+ retval = dsp5680xx_drscan(target, (uint8_t *) &instr, (uint8_t *) &ir_out,
32);
err_check_propagate(retval);
DSP5680XX_JTAG_MASTER_TAP_IRLEN);
err_check_propagate(retval);
instr = 0x2;
- retval =
- dsp5680xx_drscan(target, (uint8_t *) &instr, (uint8_t *) &ir_out,
+ retval = dsp5680xx_drscan(target, (uint8_t *) &instr, (uint8_t *) &ir_out,
4);
err_check_propagate(retval);
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);
+ retval = dsp5680xx_f_wr(target, (uint8_t *) (lock_word), HFM_LOCK_ADDR_L, 2, 1);
err_check_propagate(retval);
jtag_add_reset(0, 1);
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.");
return retval;
}
-static int dsp5680xx_step(struct target *target, int current, uint32_t address,
+static int dsp5680xx_step(struct target *target, int current, target_addr_t address,
int handle_breakpoints)
{
err_check(ERROR_FAIL, DSP5680XX_ERROR_NOT_IMPLEMENTED_STEP,
.poll = dsp5680xx_poll,
.arch_state = dsp5680xx_arch_state,
- .target_request_data = NULL,
-
.halt = dsp5680xx_halt,
.resume = dsp5680xx_resume,
.step = dsp5680xx_step,
.read_memory = dsp5680xx_read,
.write_memory = dsp5680xx_write,
- .bulk_write_memory = dsp5680xx_bulk_write_memory,
.checksum_memory = dsp5680xx_checksum_memory,