#include <cyg/hal/hal_io.h> // low level i/o
-#include <cyg/hal/var_io.h> // common registers
-#include <cyg/hal/plf_io.h> // platform registers
#include <cyg/hal/hal_diag.h>
#include <stdlib.h>
+#define ZYLIN_VERSION "1.48"
+#define ZYLIN_DATE __DATE__
+#define ZYLIN_TIME __TIME__
+#define ZYLIN_OPENOCD "$Revision: 1241 $"
+#define ZYLIN_OPENOCD_VERSION "Zylin JTAG ZY1000 " ZYLIN_VERSION " " ZYLIN_DATE " " ZYLIN_TIME
+const char *zylin_config_dir="/config/settings";
extern int jtag_error;
return ERROR_OK;
}
-static bool readPowerDropout()
+static bool readPowerDropout(void)
{
cyg_uint32 state;
// sample and clear power dropout
- HAL_WRITE_UINT32(0x08000010, 0x80);
- HAL_READ_UINT32(0x08000010, state);
+ HAL_WRITE_UINT32(ZY1000_JTAG_BASE+0x10, 0x80);
+ HAL_READ_UINT32(ZY1000_JTAG_BASE+0x10, state);
bool powerDropout;
powerDropout = (state & 0x80) != 0;
return powerDropout;
}
-static bool readSRST()
+static bool readSRST(void)
{
cyg_uint32 state;
// sample and clear SRST sensing
- HAL_WRITE_UINT32(0x08000010, 0x00000040);
- HAL_READ_UINT32(0x08000010, state);
+ HAL_WRITE_UINT32(ZY1000_JTAG_BASE+0x10, 0x00000040);
+ HAL_READ_UINT32(ZY1000_JTAG_BASE+0x10, state);
bool srstAsserted;
srstAsserted = (state & 0x40) != 0;
return srstAsserted;
}
+static int zy1000_srst_asserted(int *srst_asserted)
+{
+ *srst_asserted=readSRST();
+ return ERROR_OK;
+}
+
static int zy1000_power_dropout(int *dropout)
{
- *dropout=readPowerDropout(); /* by default we can't detect power dropout */
+ *dropout=readPowerDropout();
return ERROR_OK;
}
.khz = zy1000_khz,
.speed_div = zy1000_speed_div,
.power_dropout = zy1000_power_dropout,
+ .srst_asserted = zy1000_srst_asserted,
};
bitbang_interface_t zy1000_bitbang =
return -1;
}
-extern bool readSRST();
+extern bool readSRST(void);
void zy1000_reset(int trst, int srst)
{
LOG_DEBUG("zy1000 trst=%d, srst=%d", trst, srst);
if(!srst)
{
- ZY1000_POKE(0x08000014, 0x00000001);
+ ZY1000_POKE(ZY1000_JTAG_BASE+0x14, 0x00000001);
}
else
{
/* Danger!!! if clk!=0 when in
- * idle in TAP_RTI, reset halt on str912 will fail.
+ * idle in TAP_IDLE, reset halt on str912 will fail.
*/
- ZY1000_POKE(0x08000010, 0x00000001);
+ ZY1000_POKE(ZY1000_JTAG_BASE+0x10, 0x00000001);
}
if(!trst)
{
- ZY1000_POKE(0x08000014, 0x00000002);
+ ZY1000_POKE(ZY1000_JTAG_BASE+0x14, 0x00000002);
}
else
{
/* assert reset */
- ZY1000_POKE(0x08000010, 0x00000002);
+ ZY1000_POKE(ZY1000_JTAG_BASE+0x10, 0x00000002);
}
if (trst||(srst&&(jtag_reset_config & RESET_SRST_PULLS_TRST)))
{
waitIdle();
- /* we're now in the TLR state until trst is deasserted */
- ZY1000_POKE(0x08000020, TAP_TLR);
+ /* we're now in the RESET state until trst is deasserted */
+ ZY1000_POKE(ZY1000_JTAG_BASE+0x20, TAP_RESET);
} else
{
/* We'll get RCLK failure when we assert TRST, so clear any false positives here */
- ZY1000_POKE(0x08000014, 0x400);
+ ZY1000_POKE(ZY1000_JTAG_BASE+0x14, 0x400);
}
/* wait for srst to float back up */
{
/*0 means RCLK*/
speed = 0;
- ZY1000_POKE(0x08000010, 0x100);
+ ZY1000_POKE(ZY1000_JTAG_BASE+0x10, 0x100);
LOG_DEBUG("jtag_speed using RCLK");
}
else
{
if(speed > 8190 || speed < 2)
{
- LOG_ERROR("valid ZY1000 jtag_speed=[8190,2]. Divisor is 64MHz / even values between 8190-2, i.e. min 7814Hz, max 32MHz");
+ LOG_USER("valid ZY1000 jtag_speed=[8190,2]. Divisor is 64MHz / even values between 8190-2, i.e. min 7814Hz, max 32MHz");
return ERROR_INVALID_ARGUMENTS;
}
LOG_USER("jtag_speed %d => JTAG clk=%f", speed, 64.0/(float)speed);
- ZY1000_POKE(0x08000014, 0x100);
- ZY1000_POKE(0x0800001c, speed&~1);
+ ZY1000_POKE(ZY1000_JTAG_BASE+0x14, 0x100);
+ ZY1000_POKE(ZY1000_JTAG_BASE+0x1c, speed&~1);
}
return ERROR_OK;
}
-int zy1000_register_commands(struct command_context_s *cmd_ctx)
+static bool savePower;
+
+
+static void setPower(bool power)
{
- return ERROR_OK;
+ savePower = power;
+ if (power)
+ {
+ HAL_WRITE_UINT32(ZY1000_JTAG_BASE+0x14, 0x8);
+ } else
+ {
+ HAL_WRITE_UINT32(ZY1000_JTAG_BASE+0x10, 0x8);
+ }
}
-
-int zy1000_init(void)
+int handle_power_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
{
- ZY1000_POKE(0x08000010, 0x30); // Turn on LED1 & LED2
+ if (argc > 1)
+ {
+ return ERROR_INVALID_ARGUMENTS;
+ }
- /* deassert resets. Important to avoid infinite loop waiting for SRST to deassert */
- zy1000_reset(0, 0);
- zy1000_speed(jtag_speed);
+ if (argc == 1)
+ {
+ if (strcmp(args[0], "on") == 0)
+ {
+ setPower(1);
+ }
+ else if (strcmp(args[0], "off") == 0)
+ {
+ setPower(0);
+ } else
+ {
+ command_print(cmd_ctx, "arg is \"on\" or \"off\"");
+ return ERROR_INVALID_ARGUMENTS;
+ }
+ }
- bitbang_interface = &zy1000_bitbang;
+ command_print(cmd_ctx, "Target power %s", savePower ? "on" : "off");
return ERROR_OK;
}
-int zy1000_quit(void)
+
+/* Give TELNET a way to find out what version this is */
+int handle_zy1000_version_command(struct command_context_s *cmd_ctx, char *cmd,
+ char **args, int argc)
{
+ if (argc > 1)
+ {
+ return ERROR_COMMAND_SYNTAX_ERROR;
+ }
+ if (argc == 0)
+ {
+ command_print(cmd_ctx, ZYLIN_OPENOCD_VERSION);
+ }
+ else if (strcmp("openocd", args[0]) == 0)
+ {
+ int revision;
+ revision = atol(ZYLIN_OPENOCD+strlen("XRevision: "));
+ command_print(cmd_ctx, "%d", revision);
+ }
+ else if (strcmp("zy1000", args[0]) == 0)
+ {
+ command_print(cmd_ctx, "%s", ZYLIN_VERSION);
+ }
+ else if (strcmp("date", args[0]) == 0)
+ {
+ command_print(cmd_ctx, "%s", ZYLIN_DATE);
+ }
+ else
+ {
+ return ERROR_COMMAND_SYNTAX_ERROR;
+ }
return ERROR_OK;
}
-
-/* loads a file and returns a pointer to it in memory. The file contains
- * a 0 byte(sentinel) after len bytes - the length of the file. */
-int loadFile(const char *fileName, void **data, int *len)
+static int
+zylinjtag_Jim_Command_powerstatus(Jim_Interp *interp,
+ int argc,
+ Jim_Obj * const *argv)
{
- FILE * pFile;
- pFile = fopen (fileName,"rb");
- if (pFile==NULL)
+ if (argc != 1)
{
- LOG_ERROR("Can't open %s\n", fileName);
- return ERROR_JTAG_DEVICE_ERROR;
+ Jim_WrongNumArgs(interp, 1, argv, "powerstatus");
+ return JIM_ERR;
}
- if (fseek (pFile, 0, SEEK_END)!=0)
- {
- LOG_ERROR("Can't open %s\n", fileName);
- fclose(pFile);
- return ERROR_JTAG_DEVICE_ERROR;
- }
- *len=ftell (pFile);
- if (*len==-1)
- {
- LOG_ERROR("Can't open %s\n", fileName);
- fclose(pFile);
- return ERROR_JTAG_DEVICE_ERROR;
- }
- if (fseek (pFile, 0, SEEK_SET)!=0)
- {
- LOG_ERROR("Can't open %s\n", fileName);
- fclose(pFile);
- return ERROR_JTAG_DEVICE_ERROR;
- }
- *data=malloc(*len+1);
- if (*data==NULL)
- {
- LOG_ERROR("Can't open %s\n", fileName);
- fclose(pFile);
- return ERROR_JTAG_DEVICE_ERROR;
- }
+ cyg_uint32 status;
+ ZY1000_PEEK(ZY1000_JTAG_BASE+0x10, status);
- if (fread(*data, 1, *len, pFile)!=*len)
- {
- fclose(pFile);
- free(*data);
- LOG_ERROR("Can't open %s\n", fileName);
- return ERROR_JTAG_DEVICE_ERROR;
- }
- fclose (pFile);
- *(((char *)(*data))+*len)=0; /* sentinel */
+ Jim_SetResult(interp, Jim_NewIntObj(interp, (status&0x80)!=0));
- return ERROR_OK;
+ return JIM_OK;
+}
+int zy1000_register_commands(struct command_context_s *cmd_ctx)
+{
+ register_command(cmd_ctx, NULL, "power", handle_power_command, COMMAND_ANY,
+ "power <on/off> - turn power switch to target on/off. No arguments - print status.");
+ register_command(cmd_ctx, NULL, "zy1000_version", handle_zy1000_version_command,
+ COMMAND_EXEC, "show zy1000 version numbers");
+ Jim_CreateCommand(interp, "powerstatus", zylinjtag_Jim_Command_powerstatus, NULL, NULL);
+ return ERROR_OK;
+}
+
+
+
+
+int zy1000_init(void)
+{
+ LOG_USER("%s", ZYLIN_OPENOCD_VERSION);
+
+ ZY1000_POKE(ZY1000_JTAG_BASE+0x10, 0x30); // Turn on LED1 & LED2
+
+ setPower(true); // on by default
+
+
+ /* deassert resets. Important to avoid infinite loop waiting for SRST to deassert */
+ zy1000_reset(0, 0);
+ zy1000_speed(jtag_speed);
+
+ bitbang_interface = &zy1000_bitbang;
+
+ return ERROR_OK;
+}
+
+int zy1000_quit(void)
+{
+
+ return ERROR_OK;
}
cyg_uint32 empty;
waitIdle();
- ZY1000_PEEK(0x08000010, empty);
+ ZY1000_PEEK(ZY1000_JTAG_BASE+0x10, empty);
/* clear JTAG error register */
- ZY1000_POKE(0x08000014, 0x400);
+ ZY1000_POKE(ZY1000_JTAG_BASE+0x14, 0x400);
if ((empty&0x400)!=0)
{
-static cyg_uint32 getShiftValue()
+static cyg_uint32 getShiftValue(void)
{
cyg_uint32 value;
waitIdle();
- ZY1000_PEEK(0x0800000c, value);
+ ZY1000_PEEK(ZY1000_JTAG_BASE+0xc, value);
VERBOSE(LOG_INFO("getShiftValue %08x", value));
return value;
}
#if 0
-static cyg_uint32 getShiftValueFlip()
+static cyg_uint32 getShiftValueFlip(void)
{
cyg_uint32 value;
waitIdle();
- ZY1000_PEEK(0x08000018, value);
+ ZY1000_PEEK(ZY1000_JTAG_BASE+0x18, value);
VERBOSE(LOG_INFO("getShiftValue %08x (flipped)", value));
return value;
}
#if 0
static void shiftValueInnerFlip(const enum tap_state state, const enum tap_state endState, int repeat, cyg_uint32 value)
{
- VERBOSE(LOG_INFO("shiftValueInner %s %s %d %08x (flipped)", tap_state_strings[state], tap_state_strings[endState], repeat, value));
+ VERBOSE(LOG_INFO("shiftValueInner %s %s %d %08x (flipped)", jtag_state_name(state), jtag_state_name(endState), repeat, value));
cyg_uint32 a,b;
a=state;
b=endState;
- ZY1000_POKE(0x0800000c, value);
- ZY1000_POKE(0x08000008, (1<<15)|(repeat<<8)|(a<<4)|b);
+ ZY1000_POKE(ZY1000_JTAG_BASE+0xc, value);
+ ZY1000_POKE(ZY1000_JTAG_BASE+0x8, (1<<15)|(repeat<<8)|(a<<4)|b);
VERBOSE(getShiftValueFlip());
}
#endif
extern int jtag_check_value(u8 *captured, void *priv);
-static void gotoEndState()
+static void gotoEndState(void)
{
setCurrentState(cmd_queue_end_state);
}
enum tap_state pause_state;
int l;
k=num_bits-j;
- pause_state=(shiftState==TAP_SD)?TAP_SD:TAP_SI;
+ pause_state=(shiftState==TAP_DRSHIFT)?TAP_DRSHIFT:TAP_IRSHIFT;
if (k>32)
{
k=32;
} else if (pause&&(i == num_fields-1))
{
/* this was the last to shift out this time */
- pause_state=(shiftState==TAP_SD)?TAP_PD:TAP_PI;
+ pause_state=(shiftState==TAP_DRSHIFT)?TAP_DRPAUSE:TAP_IRPAUSE;
}
// we have (num_bits+7)/8 bytes of bits to toggle out.
int r=fields[i].in_handler(inBuffer, fields[i].in_handler_priv, fields+i);
if (r!=ERROR_OK)
{
- /* this will cause jtag_execute_queue() to return an error */
+ /* this will cause jtag_execute_queue() to return an error */
jtag_error=r;
}
}
int interface_jtag_add_ir_scan(int num_fields, scan_field_t *fields, enum tap_state state)
{
- int i, j;
+ int j;
int scan_size = 0;
- jtag_device_t *device;
-
- for (i=0; i < jtag_num_devices; i++)
+ jtag_tap_t *tap, *nextTap;
+ for(tap = jtag_NextEnabledTap(NULL); tap!= NULL; tap=nextTap)
{
- int pause=i==(jtag_num_devices-1);
+ nextTap=jtag_NextEnabledTap(tap);
+ int pause=(nextTap==NULL);
+
int found = 0;
- device = jtag_get_device(i);
- scan_size = device->ir_length;
+
+ scan_size = tap->ir_length;
/* search the list */
for (j=0; j < num_fields; j++)
{
- if (i == fields[j].device)
+ if (tap == fields[j].tap)
{
found = 1;
if ((jtag_verify_capture_ir)&&(fields[j].in_handler==NULL))
{
- jtag_set_check_value(fields+j, device->expected, device->expected_mask, NULL);
+ jtag_set_check_value(fields+j, tap->expected, tap->expected_mask, NULL);
} else if (jtag_verify_capture_ir)
{
- fields[j].in_check_value = device->expected;
- fields[j].in_check_mask = device->expected_mask;
+ fields[j].in_check_value = tap->expected;
+ fields[j].in_check_mask = tap->expected_mask;
}
- scanFields(1, fields+j, TAP_SI, pause);
+ scanFields(1, fields+j, TAP_IRSHIFT, pause);
/* update device information */
- buf_cpy(fields[j].out_value, jtag_get_device(i)->cur_instr, scan_size);
+ buf_cpy(fields[j].out_value, tap->cur_instr, scan_size);
- device->bypass = 0;
+ tap->bypass = 0;
break;
}
}
memset(&tmp, 0, sizeof(tmp));
tmp.out_value = ones;
tmp.num_bits = scan_size;
- scanFields(1, &tmp, TAP_SI, pause);
+ scanFields(1, &tmp, TAP_IRSHIFT, pause);
/* update device information */
- buf_cpy(tmp.out_value, jtag_get_device(i)->cur_instr, scan_size);
- device->bypass = 1;
+ buf_cpy(tmp.out_value, tap->cur_instr, scan_size);
+ tap->bypass = 1;
}
}
gotoEndState();
int interface_jtag_add_plain_ir_scan(int num_fields, scan_field_t *fields, enum tap_state state)
{
- scanFields(num_fields, fields, TAP_SI, 1);
+ scanFields(num_fields, fields, TAP_IRSHIFT, 1);
gotoEndState();
return ERROR_OK;
int interface_jtag_add_dr_scan(int num_fields, scan_field_t *fields, enum tap_state state)
{
- int i, j;
- for (i=0; i < jtag_num_devices; i++)
+
+ int j;
+ jtag_tap_t *tap, *nextTap;
+ for(tap = jtag_NextEnabledTap(NULL); tap!= NULL; tap=nextTap)
{
- int found = 0;
- int pause = (i==(jtag_num_devices-1));
+ nextTap=jtag_NextEnabledTap(tap);
+ int found=0;
+ int pause=(nextTap==NULL);
for (j=0; j < num_fields; j++)
{
- if (i == fields[j].device)
+ if (tap == fields[j].tap)
{
found = 1;
- scanFields(1, fields+j, TAP_SD, pause);
+ scanFields(1, fields+j, TAP_DRSHIFT, pause);
}
}
if (!found)
{
-#ifdef _DEBUG_JTAG_IO_
- /* if a device isn't listed, the BYPASS register should be selected */
- if (!jtag_get_device(i)->bypass)
- {
- LOG_ERROR("BUG: no scan data for a device not in BYPASS");
- exit(-1);
- }
-#endif
-
scan_field_t tmp;
/* program the scan field to 1 bit length, and ignore it's value */
tmp.num_bits = 1;
tmp.in_handler = NULL;
tmp.in_handler_priv = NULL;
- scanFields(1, &tmp, TAP_SD, pause);
+ scanFields(1, &tmp, TAP_DRSHIFT, pause);
}
else
{
-#ifdef _DEBUG_JTAG_IO_
- /* if a device is listed, the BYPASS register must not be selected */
- if (jtag_get_device(i)->bypass)
- {
- LOG_WARNING("scan data for a device in BYPASS");
- }
-#endif
}
}
gotoEndState();
int interface_jtag_add_plain_dr_scan(int num_fields, scan_field_t *fields, enum tap_state state)
{
- scanFields(num_fields, fields, TAP_SD, 1);
+ scanFields(num_fields, fields, TAP_DRSHIFT, 1);
gotoEndState();
return ERROR_OK;
}
int interface_jtag_add_tlr()
{
- setCurrentState(TAP_TLR);
+ setCurrentState(TAP_RESET);
return ERROR_OK;
}
return ERROR_OK;
}
-int interface_jtag_add_runtest(int num_cycles, enum tap_state state)
+static int zy1000_jtag_add_clocks(int num_cycles, enum tap_state state, enum tap_state clockstate)
{
/* num_cycles can be 0 */
- setCurrentState(TAP_RTI);
+ setCurrentState(clockstate);
/* execute num_cycles, 32 at the time. */
int i;
{
num=num_cycles-i;
}
- shiftValueInner(TAP_RTI, TAP_RTI, num, 0);
+ shiftValueInner(clockstate, clockstate, num, 0);
}
#if !TEST_MANUAL()
/* finish in end_state */
setCurrentState(state);
#else
- enum tap_state t=TAP_RTI;
+ enum tap_state t=TAP_IDLE;
/* test manual drive code on any target */
int tms;
u8 tms_scan = TAP_MOVE(t, state);
{
tms = (tms_scan >> i) & 1;
waitIdle();
- ZY1000_POKE(0x08000028, tms);
+ ZY1000_POKE(ZY1000_JTAG_BASE+0x28, tms);
}
waitIdle();
- ZY1000_POKE(0x08000020, state);
+ ZY1000_POKE(ZY1000_JTAG_BASE+0x20, state);
#endif
return ERROR_OK;
}
+int interface_jtag_add_runtest(int num_cycles, enum tap_state state)
+{
+ return zy1000_jtag_add_clocks(num_cycles, state, TAP_IDLE);
+}
+
+int interface_jtag_add_clocks(int num_cycles)
+{
+ return zy1000_jtag_add_clocks(num_cycles, cmd_queue_cur_state, cmd_queue_end_state);
+}
+
int interface_jtag_add_sleep(u32 us)
{
jtag_sleep(us);
}
else
{
- LOG_ERROR("BUG: %s -> %s isn't a valid TAP transition", tap_state_strings[cur_state], tap_state_strings[path[state_count]]);
+ LOG_ERROR("BUG: %s -> %s isn't a valid TAP transition", jtag_state_name(cur_state), jtag_state_name(path[state_count]));
exit(-1);
}
waitIdle();
- ZY1000_POKE(0x08000028, tms);
+ ZY1000_POKE(ZY1000_JTAG_BASE+0x28, tms);
cur_state = path[state_count];
state_count++;
}
waitIdle();
- ZY1000_POKE(0x08000020, cur_state);
+ ZY1000_POKE(ZY1000_JTAG_BASE+0x20, cur_state);
return ERROR_OK;
}
-void embeddedice_write_dcc(int chain_pos, int reg_addr, u8 *buffer, int little, int count)
+void embeddedice_write_dcc(jtag_tap_t *tap, int reg_addr, u8 *buffer, int little, int count)
{
// static int const reg_addr=0x5;
enum tap_state end_state=cmd_queue_end_state;
- if (jtag_num_devices==1)
+ if (jtag_NextEnabledTap(jtag_NextEnabledTap(NULL))==NULL)
{
/* better performance via code duplication */
if (little)
int i;
for (i = 0; i < count; i++)
{
- shiftValueInner(TAP_SD, TAP_SD, 32, fast_target_buffer_get_u32(buffer, 1));
- shiftValueInner(TAP_SD, end_state, 6, reg_addr|(1<<5));
+ shiftValueInner(TAP_DRSHIFT, TAP_DRSHIFT, 32, fast_target_buffer_get_u32(buffer, 1));
+ shiftValueInner(TAP_DRSHIFT, end_state, 6, reg_addr|(1<<5));
buffer+=4;
}
} else
int i;
for (i = 0; i < count; i++)
{
- shiftValueInner(TAP_SD, TAP_SD, 32, fast_target_buffer_get_u32(buffer, 0));
- shiftValueInner(TAP_SD, end_state, 6, reg_addr|(1<<5));
+ shiftValueInner(TAP_DRSHIFT, TAP_DRSHIFT, 32, fast_target_buffer_get_u32(buffer, 0));
+ shiftValueInner(TAP_DRSHIFT, end_state, 6, reg_addr|(1<<5));
buffer+=4;
}
}
int i;
for (i = 0; i < count; i++)
{
- embeddedice_write_reg_inner(chain_pos, reg_addr, fast_target_buffer_get_u32(buffer, little));
+ embeddedice_write_reg_inner(tap, reg_addr, fast_target_buffer_get_u32(buffer, little));
buffer += 4;
}
}
}
+int loadFile(const char *fileName, void **data, int *len);
+
+/* boolean parameter stored on config */
+int boolParam(char *var)
+{
+ bool result = false;
+ char *name = alloc_printf("%s/%s", zylin_config_dir, var);
+ if (name == NULL)
+ return result;
+
+ void *data;
+ int len;
+ if (loadFile(name, &data, &len) == ERROR_OK)
+ {
+ if (len > 1)
+ len = 1;
+ result = strncmp((char *) data, "1", len) == 0;
+ free(data);
+ }
+ free(name);
+ return result;
+}
+
+