+void zy1000_jtag_add_callback(jtag_callback1_t callback, jtag_callback_data_t data0)
+{
+ zy1000_jtag_add_callback4(zy1000_jtag_convert_to_callback4, data0, (jtag_callback_data_t)callback, 0, 0);
+}
+
+void zy1000_flush_callbackqueue(void)
+{
+ /* we have to flush the read queue so we have access to
+ the data the callbacks will use
+ */
+ zy1000_flush_readqueue();
+ int i;
+ for (i = 0; i < callbackqueue_pos; i++)
+ {
+ struct callbackentry *entry = &callbackqueue[i];
+ jtag_set_error(entry->callback(entry->data0, entry->data1, entry->data2, entry->data3));
+ }
+ callbackqueue_pos = 0;
+}
+
+static void writeShiftValue(uint8_t *data, int bits)
+{
+ waitIdle();
+
+ if (!writeLong((ZY1000_CMD_PEEK << 24) | (ZY1000_JTAG_BASE + 0xc)))
+ {
+ fprintf(stderr, "Could not read from zy1000 server\n");
+ exit(-1);
+ }
+
+ if (readqueue_pos >= readqueue_size)
+ {
+ zy1000_flush_readqueue();
+ }
+
+ readqueue[readqueue_pos].dest = data;
+ readqueue[readqueue_pos].bits = bits;
+ readqueue_pos++;
+
+ /* KLUDGE!!! minidriver requires readqueue to be synchronous */
+ zy1000_flush_readqueue();
+}
+
+#else
+
+static void writeShiftValue(uint8_t *data, int bits)
+{
+ uint32_t value;
+ waitIdle();
+ ZY1000_PEEK(ZY1000_JTAG_BASE + 0xc, value);
+ VERBOSE(LOG_INFO("getShiftValue %08x", value));
+
+ // data in, LSB to MSB
+ // we're shifting in data to MSB, shift data to be aligned for returning the value
+ value >>= 32 - bits;
+
+ for (int l = 0; l < bits; l += 8)
+ {
+ data[l/8]=(value >> l)&0xff;
+ }
+}
+
+#endif
+
+#if BUILD_ZY1000_MASTER
+
+#if BUILD_ECOSBOARD
+static char watchdog_stack[2048];
+static cyg_thread watchdog_thread_object;
+static cyg_handle_t watchdog_thread_handle;
+#endif
+
+#ifdef WATCHDOG_BASE
+/* If we connect to port 8888 we must send a char every 10s or the board resets itself */
+static void watchdog_server(cyg_addrword_t data)