56 #include <netinet/tcp.h> 59 #define ZYLIN_KHZ 60000 88 speed = (speed + 1) / 2;
116 powerDropout = (state & 0x80) != 0;
128 srstAsserted = (state & 0x40) != 0;
150 const char *
mode = asserted ?
"assert" :
"deassert";
154 if ((asserted && srstAsserted) || (!asserted && !srstAsserted)) {
156 LOG_USER(
"SRST took %dms to %s", (
int)total, mode);
170 LOG_ERROR(
"SRST took too long to %s: %" PRId64
"ms", mode, total);
178 LOG_DEBUG(
"zy1000 trst=%d, srst=%d", trst, srst);
231 if (speed > 8190 || speed < 2) {
233 "valid ZY1000 jtag_speed=[8190,2]. With divisor is %dkHz / even values between 8190-2, i.e. min %dHz, max %dMHz",
243 LOG_USER(
"jtag_speed %d => JTAG clk=%d kHz", speed, khz);
280 #if !BUILD_ZY1000_MASTER 295 Jim_Obj *
const *argv)
298 Jim_WrongNumArgs(interp, 1, argv,
"powerstatus");
304 Jim_SetResult(interp, Jim_NewIntObj(interp, dropout));
337 if ((empty&0x400) != 0) {
351 static inline void scanBits(
const uint8_t *out_value,
359 for (
int j = 0; j < num_bits; j += 32) {
360 int k = num_bits - j;
364 }
else if (pause_now) {
366 pause_state = end_state;
373 if (out_value !=
NULL) {
374 for (
int l = 0; l < k; l += 8)
375 value |= out_value[(j + l)/8]<<l;
379 value &= ~(((uint32_t)0xffffffff) << k);
387 if (in_value !=
NULL)
397 for (
int i = 0; i < num_fields; i++) {
430 assert(scan_size <= 32);
446 const uint8_t *out_bits,
481 const uint8_t *out_bits,
508 for (i = 0; i < num_cycles; i += 32) {
511 if (num_cycles-i < num)
526 for (i = 0; i < tms_count; i++) {
527 tms = (tms_scan >> i) & 1;
553 for (
unsigned i = 0; i < num_bits; i++) {
556 if (((seq[i/8] >> (i % 8)) & 1) == 0)
585 memset(seq, 0,
sizeof(seq));
586 assert(num_states < (
int)((
sizeof(seq) * 8)));
594 LOG_ERROR(
"BUG: %s -> %s isn't a valid TAP transition",
599 seq[state_count/8] = seq[state_count/8] | (tms << (state_count % 8));
601 cur_state = path[state_count];
640 for (i = 0; i <
count; i++) {
650 if ((pre_bits > 32) || (post_bits + 6 > 32)) {
652 for (i = 0; i <
count; i++) {
659 for (i = 0; i <
count; i++) {
668 (reg_addr | (1 << 5)));
686 if ((pre_bits > 32) || (post_bits > 32)) {
688 uint32_t opcode, uint32_t *data,
size_t count);
691 static const uint8_t zero;
695 const uint8_t *t = (
const uint8_t *)data;
697 while (--count > 0) {
742 { .num_bits = 2, .out_value = &zero },
752 arm11_MOVE_DRPAUSE_IDLE_DRPAUSE_with_delay);
758 { .num_bits = 2, .out_value = &zero },
776 .handler = handle_power_command,
778 .help =
"Turn power switch to target on/off. " 779 "With no arguments, prints status.",
780 .usage =
"('on'|'off)",
782 #if !BUILD_ZY1000_MASTER 784 .name =
"zy1000_server",
787 .help =
"Tcpip address for ZY1000 server.",
792 .name =
"powerstatus",
795 .help =
"Returns power status of target",
800 #if !BUILD_ZY1000_MASTER 821 for (i = 0; i < 4; i++) {
822 uint8_t c = (l >> (i*8))&0xff;
836 for (i = 0; i < 4; i++) {
857 data |= (c << (i*8));
870 #include <sys/socket.h> 871 #include <arpa/inet.h> 881 struct sockaddr_in echoServAddr;
884 tcp_ip = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
886 fprintf(stderr,
"Failed to connect to zy1000 server\n");
891 memset(&echoServAddr, 0,
sizeof(echoServAddr));
892 echoServAddr.sin_family = AF_INET;
893 echoServAddr.sin_addr.s_addr = inet_addr(
tcp_server);
894 echoServAddr.sin_port = htons(7777);
897 if (connect(tcp_ip, (
struct sockaddr *) &echoServAddr,
sizeof(echoServAddr)) < 0) {
898 fprintf(stderr,
"Failed to connect to zy1000 server\n");
916 fprintf(stderr,
"Could not write to zy1000 server\n");
929 fprintf(stderr,
"Could not write to zy1000 server\n");
942 fprintf(stderr,
"Could not read from zy1000 server\n");
952 fprintf(stderr,
"Could not read from zy1000 server\n");
959 #define readqueue_size 16384 982 fprintf(stderr,
"Could not read from zy1000 server\n");
992 for (
int l = 0; l < k; l += 8)
993 in_value[l/8] = (value >> l)&0xff;
1003 #define callbackqueue_size 128 1070 callbackqueue_pos = 0;
1078 fprintf(stderr,
"Could not read from zy1000 server\n");
1104 value >>= 32 -
bits;
1106 for (
int l = 0; l <
bits; l += 8)
1107 data[l/8] = (value >> l)&0xff;
1112 #if BUILD_ZY1000_MASTER 1114 #ifdef WATCHDOG_BASE 1116 static void watchdog_server(cyg_addrword_t data)
1118 int so_reuseaddr_option = 1;
1120 int fd = socket(AF_INET, SOCK_STREAM, 0);
1122 LOG_ERROR(
"error creating socket: %s", strerror(errno));
1126 setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (
void *) &so_reuseaddr_option,
1129 struct sockaddr_in sin;
1130 unsigned int address_size;
1131 address_size =
sizeof(sin);
1132 memset(&sin, 0,
sizeof(sin));
1133 sin.sin_family = AF_INET;
1134 sin.sin_addr.s_addr = INADDR_ANY;
1135 sin.sin_port = htons(8888);
1137 if (bind(fd, (
struct sockaddr *) &sin,
sizeof(sin)) == -1) {
1138 LOG_ERROR(
"couldn't bind to socket: %s", strerror(errno));
1142 if (listen(fd, 1) == -1) {
1143 LOG_ERROR(
"couldn't listen on socket: %s", strerror(errno));
1149 int watchdog_ip = accept(fd, (
struct sockaddr *) &sin, &address_size);
1152 HAL_WRITE_UINT32(WATCHDOG_BASE + 4, 4);
1154 if (watchdog_ip < 0) {
1155 LOG_ERROR(
"couldn't open watchdog socket: %s", strerror(errno));
1160 setsockopt(watchdog_ip,
1169 if (read(watchdog_ip, &buf, 1) == 1) {
1171 HAL_WRITE_UINT32(WATCHDOG_BASE + 8, 0x1234);
1173 write(watchdog_ip, &buf, 1);
1190 #if BUILD_ZY1000_MASTER 1198 #if BUILD_ZY1000_MASTER 1199 volatile void *zy1000_jtag_master;
1200 #include <sys/mman.h> 1205 #if BUILD_ZY1000_MASTER 1206 int fd = open(
"/dev/mem", O_RDWR | O_SYNC);
1211 #ifndef REGISTERS_BASE 1212 #define REGISTERS_BASE 0x9002000 1213 #define REGISTERS_SPAN 128 1216 zy1000_jtag_master = mmap(0,
1218 PROT_READ | PROT_WRITE,
1223 if (zy1000_jtag_master == (
void *) -1) {
1242 .execute_queue =
NULL,
void zy1000_flush_readqueue(void)
int(* jtag_callback_t)(jtag_callback_data_t data0, jtag_callback_data_t data1, jtag_callback_data_t data2, jtag_callback_data_t data3)
Defines the interface of the JTAG callback mechanism.
static bool readSRST(void)
void zy1000_jtag_add_callback4(jtag_callback_t callback, jtag_callback_data_t data0, jtag_callback_data_t data1, jtag_callback_data_t data2, jtag_callback_data_t data3)
void zy1000_jtag_add_callback(jtag_callback1_t callback, jtag_callback_data_t data0)
int interface_jtag_add_dr_scan(struct jtag_tap *active, int num_fields, const struct scan_field *fields, tap_state_t state)
see jtag_add_dr_scan()
static void scanFields(int num_fields, const struct scan_field *fields, tap_state_t shiftState, tap_state_t end_state)
Represents a driver for a debugging interface.
#define LOG_USER(expr ...)
static uint32_t fast_target_buffer_get_u32(const void *p, bool le)
const char *const jtag_only[]
void zy1000_reset(int trst, int srst)
int interface_jtag_add_reset(int req_trst, int req_srst)
This drives the actual srst and trst pins.
void * buf_cpy(const void *from, void *_to, unsigned size)
Copies size bits out of from and into to.
#define ZY1000_PEEK(a, b)
jtag_callback_data_t data2
static void setCurrentState(enum tap_state state)
static void tcpip_open(void)
void * buf_set_ones(void *_buf, unsigned size)
Set the contents of buf with count bits, all set to 1.
void jtag_add_dr_scan(struct jtag_tap *active, int in_num_fields, const struct scan_field *in_fields, tap_state_t state)
Generate a DR SCAN using the fields passed to the function.
int tap_get_tms_path_len(tap_state_t from, tap_state_t to)
Function int tap_get_tms_path_len returns the total number of bits that represents a TMS path transit...
void zy1000_tcpout(uint32_t address, uint32_t data)
void embeddedice_write_dcc(struct jtag_tap *tap, int reg_addr, const uint8_t *buffer, int little, int count)
int interface_jtag_add_plain_ir_scan(int num_bits, const uint8_t *out_bits, uint8_t *in_bits, tap_state_t state)
#define COMMAND_PARSE_ON_OFF(in, out)
parses an on/off command argument
int ir_length
size of instruction register
static int callbackqueue_pos
struct jtag_tap * jtag_tap_next_enabled(struct jtag_tap *p)
int interface_jtag_add_clocks(int num_cycles)
#define CMD_ARGV
Use this macro to access the arguments for the command being handled, rather than accessing the varia...
void(* jtag_callback1_t)(jtag_callback_data_t data0)
Defines a simple JTAG callback that can allow conversions on data scanned in from an interface...
#define CMD_ARGC
Use this macro to access the number of arguments for the command being handled, rather than accessing...
static void shiftValueInner(const enum tap_state state, const enum tap_state endState, int repeat, uint32_t value)
void jtag_add_pathmove(int num_states, const tap_state_t *path)
Application code must assume that interfaces will implement transitions between states with different...
COMMAND_HANDLER(handle_power_command)
int zy1000_speed(int speed)
This structure defines a single scan field in the scan.
jtag_callback_data_t data3
#define LOG_INFO(expr ...)
int arm11_run_instr_data_to_core_noack_inner(struct jtag_tap *tap, uint32_t opcode, uint32_t *data, size_t count)
int interface_jtag_add_plain_dr_scan(int num_bits, const uint8_t *out_bits, uint8_t *in_bits, tap_state_t state)
const char * tap_state_name(tap_state_t state)
Function tap_state_name Returns a string suitable for display representing the JTAG tap_state...
#define callbackqueue_size
static bool readPowerDropout(void)
static void waitSRST(bool asserted)
int interface_add_tms_seq(unsigned num_bits, const uint8_t *seq, enum tap_state state)
static void jtag_pre_post_bits(struct jtag_tap *tap, int *pre, int *post)
static int zy1000_srst_asserted(int *srst_asserted)
#define LOG_ERROR(expr ...)
int interface_jtag_add_tlr(void)
static int jim_zy1000_server(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
int num_bits
The number of bits this field specifies.
jtag_callback_data_t data0
uint32_t zy1000_tcpin(uint32_t address)
static const struct command_registration zy1000_commands[]
tap_state
Defines JTAG Test Access Port states.
static void setPower(bool power)
static uint8_t in_buffer[16384]
struct adapter_driver zy1000_adapter_driver
tap_state_t cmd_queue_cur_state
The current TAP state of the pending JTAG command queue.
#define ZY1000_POKE(a, b)
Represents a driver for a debugging interface.
jtag_callback_data_t data1
int tap_get_tms_path(tap_state_t from, tap_state_t to)
This function provides a "bit sequence" indicating what has to be done with TMS during a sequence of ...
#define COMMAND_REGISTRATION_DONE
Use this as the last entry in an array of command_registration records.
uint8_t * cur_instr
current instruction
static int zy1000_khz(int khz, int *jtag_speed)
static void writeShiftValue(uint8_t *data, int bits)
static int zy1000_jtag_add_clocks(int num_cycles, tap_state_t state, tap_state_t clockstate)
#define ERROR_COMMAND_SYNTAX_ERROR
#define LOG_WARNING(expr ...)
static uint8_t out_buffer[16384]
static int zy1000_power_dropout(int *dropout)
static int zy1000_jtag_convert_to_callback4(jtag_callback_data_t data0, jtag_callback_data_t data1, jtag_callback_data_t data2, jtag_callback_data_t data3)
enum reset_types jtag_get_reset_config(void)
int interface_jtag_execute_queue(void)
static bool flush_writes(void)
int interface_jtag_add_pathmove(int num_states, const tap_state_t *path)
static bool writeLong(uint32_t l)
int interface_jtag_add_sleep(uint32_t us)
unsigned supported
Bit vector listing capabilities exposed by this driver.
tap_state_t tap_state_transition(tap_state_t cur_state, bool tms)
Function tap_state_transition takes a current TAP state and returns the next state according to the t...
enum tap_state tap_state_t
Defines JTAG Test Access Port states.
int interface_jtag_add_runtest(int num_cycles, tap_state_t state)
const char *const name
The name of the interface driver.
static struct callbackentry callbackqueue[callbackqueue_size]
static struct jtag_interface zy1000_interface
int interface_jtag_add_ir_scan(struct jtag_tap *active, const struct scan_field *fields, tap_state_t state)
see jtag_add_ir_scan()
int bypass
Bypass register selected.
int jtag_execute_queue(void)
For software FIFO implementations, the queued commands can be executed during this call or earlier...
tap_state_t tap_get_state(void)
This function gets the state of the "state follower" which tracks the state of the TAPs connected to ...
static void scanBits(const uint8_t *out_value, uint8_t *in_value, int num_bits, bool pause_now, tap_state_t shiftState, tap_state_t end_state)
#define ARRAY_SIZE(x)
Compute the number of elements of a variable length array.
intptr_t jtag_callback_data_t
Defines the type of data passed to the jtag_callback_t interface.
#define DEBUG_CAP_TMS_SEQ
void jtag_sleep(uint32_t us)
void zy1000_flush_callbackqueue(void)
static int zy1000_speed_div(int speed, int *khz)
#define LOG_DEBUG(expr ...)
tap_state_t tap_get_end_state(void)
For more information,.
static void embeddedice_write_reg_inner(struct jtag_tap *tap, int reg_addr, uint32_t value)
static struct @30 readqueue[readqueue_size]
int arm11_run_instr_data_to_core_noack_inner_default(struct jtag_tap *tap, uint32_t opcode, uint32_t *data, size_t count)
void jtag_set_error(int error)
Set the current JTAG core execution error, unless one was set by a previous call previously.
static int zylinjtag_Jim_Command_powerstatus(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
static bool readLong(uint32_t *out_data)
static const tap_state_t arm11_MOVE_DRPAUSE_IDLE_DRPAUSE_with_delay[]
JTAG path for arm11_run_instr_data_to_core_noack.