You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by ad...@apache.org on 2016/06/15 22:03:51 UTC

[08/51] [partial] incubator-mynewt-site git commit: Fixed broken Quick Start link and added OpenOCD option for Arduino Primo debugging

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/e302582d/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/src/helper/types.h
----------------------------------------------------------------------
diff --git a/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/src/helper/types.h b/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/src/helper/types.h
new file mode 100755
index 0000000..3f0724c
--- /dev/null
+++ b/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/src/helper/types.h
@@ -0,0 +1,341 @@
+/***************************************************************************
+ *   Copyright (C) 2004, 2005 by Dominic Rath                              *
+ *   Dominic.Rath@gmx.de                                                   *
+ *                                                                         *
+ *   Copyright (C) 2007,2008 �yvind Harboe                                 *
+ *   oyvind.harboe@zylin.com                                               *
+ *                                                                         *
+ *   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.,                                       *
+ *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.           *
+ ***************************************************************************/
+#ifndef TYPES_H
+#define TYPES_H
+
+#include <stddef.h>
+#ifdef HAVE_SYS_TYPES_H
+#include <sys/types.h>
+#endif
+#ifdef HAVE_STDINT_H
+#include <stdint.h>
+#endif
+#ifdef HAVE_INTTYPES_H
+#include <inttypes.h>
+#endif
+
+#ifdef HAVE_STDBOOL_H
+#include <stdbool.h>
+#else	/* HAVE_STDBOOL_H */
+#define __bool_true_false_are_defined 1
+
+#ifndef HAVE__BOOL
+#ifndef __cplusplus
+
+#define false	0
+#define true		1
+
+typedef int _Bool;
+#else
+typedef bool _Bool;
+#endif	/* __cplusplus */
+#endif	/* HAVE__BOOL */
+
+#define bool _Bool
+
+#endif	/* HAVE_STDBOOL_H */
+
+/// turns a macro argument into a string constant
+#define stringify(s) __stringify(s)
+#define __stringify(s) #s
+
+
+/**
+ * Compute the number of elements of a variable length array.
+ * <code>
+ * const char *strs[] = { "a", "b", "c" };
+ * unsigned num_strs = ARRAY_SIZE(strs);
+ * </code>
+ */
+#define ARRAY_SIZE(x) (sizeof(x) / sizeof(*(x)))
+
+
+/**
+ * Cast a member of a structure out to the containing structure.
+ * @param ptr The pointer to the member.
+ * @param type The type of the container struct this is embedded in.
+ * @param member The name of the member within the struct.
+ *
+ * This is a mechanism which is used throughout the Linux kernel.
+ */
+#define container_of(ptr, type, member) ({			\
+	const typeof( ((type *)0)->member ) *__mptr = (ptr);	\
+	(type *)( (void *) ( (char *)__mptr - offsetof(type,member) ) );})
+
+
+/**
+ * Rounds @c m up to the nearest multiple of @c n using division.
+ * @param m The value to round up to @c n.
+ * @param n Round @c m up to a multiple of this number.
+ * @returns The rounded integer value.
+ */
+#define DIV_ROUND_UP(m, n)	(((m) + (n) - 1) / (n))
+
+
+/* DANGER!!!! here be dragons!
+ *
+ * Leave these fn's as byte accesses because it is safe
+ * across architectures. Clever usage of 32 bit access
+ * will create problems on some hosts.
+ *
+ * Note that the "buf" pointer in memory is probably unaligned.
+ *
+ * Were these functions to be re-written to take a 32 bit wide or 16 bit wide
+ * memory access shortcut, then on some CPU's, i.e. ARM7, the 2 lsbytes of the address are
+ * ignored for 32 bit access, whereas on other CPU's a 32 bit wide unaligned memory access
+ * will cause an exception, and lastly on x86, an unaligned "greater than bytewide"
+ * memory access works as if aligned.  So what follows below will work for all
+ * platforms and gives the compiler leeway to do its own platform specific optimizations.
+ *
+ * Again, note that the "buf" pointer in memory is probably unaligned.
+ */
+
+static inline uint64_t le_to_h_u64(const uint8_t *buf)
+{
+	return (uint64_t)((uint64_t)buf[0] |
+			  (uint64_t)buf[1] << 8 |
+			  (uint64_t)buf[2] << 16 |
+			  (uint64_t)buf[3] << 24 |
+			  (uint64_t)buf[4] << 32 |
+			  (uint64_t)buf[5] << 40 |
+			  (uint64_t)buf[6] << 48 |
+			  (uint64_t)buf[7] << 56);
+}
+
+static inline uint32_t le_to_h_u32(const uint8_t* buf)
+{
+	return (uint32_t)(buf[0] | buf[1] << 8 | buf[2] << 16 | buf[3] << 24);
+}
+
+static inline uint32_t le_to_h_u24(const uint8_t* buf)
+{
+	return (uint32_t)(buf[0] | buf[1] << 8 | buf[2] << 16);
+}
+
+static inline uint16_t le_to_h_u16(const uint8_t* buf)
+{
+	return (uint16_t)(buf[0] | buf[1] << 8);
+}
+
+static inline uint64_t be_to_h_u64(const uint8_t *buf)
+{
+	return (uint64_t)((uint64_t)buf[7] |
+			  (uint64_t)buf[6] << 8 |
+			  (uint64_t)buf[5] << 16 |
+			  (uint64_t)buf[4] << 24 |
+			  (uint64_t)buf[3] << 32 |
+			  (uint64_t)buf[2] << 40 |
+			  (uint64_t)buf[1] << 48 |
+			  (uint64_t)buf[0] << 56);
+}
+
+static inline uint32_t be_to_h_u32(const uint8_t* buf)
+{
+	return (uint32_t)(buf[3] | buf[2] << 8 | buf[1] << 16 | buf[0] << 24);
+}
+
+static inline uint32_t be_to_h_u24(const uint8_t* buf)
+{
+	return (uint32_t)(buf[2] | buf[1] << 8 | buf[0] << 16);
+}
+
+static inline uint16_t be_to_h_u16(const uint8_t* buf)
+{
+	return (uint16_t)(buf[1] | buf[0] << 8);
+}
+
+static inline void h_u64_to_le(uint8_t *buf, int64_t val)
+{
+	buf[7] = (uint8_t) (val >> 56);
+	buf[6] = (uint8_t) (val >> 48);
+	buf[5] = (uint8_t) (val >> 40);
+	buf[4] = (uint8_t) (val >> 32);
+	buf[3] = (uint8_t) (val >> 24);
+	buf[2] = (uint8_t) (val >> 16);
+	buf[1] = (uint8_t) (val >> 8);
+	buf[0] = (uint8_t) (val >> 0);
+}
+
+static inline void h_u64_to_be(uint8_t *buf, int64_t val)
+{
+	buf[0] = (uint8_t) (val >> 56);
+	buf[1] = (uint8_t) (val >> 48);
+	buf[2] = (uint8_t) (val >> 40);
+	buf[3] = (uint8_t) (val >> 32);
+	buf[4] = (uint8_t) (val >> 24);
+	buf[5] = (uint8_t) (val >> 16);
+	buf[6] = (uint8_t) (val >> 8);
+	buf[7] = (uint8_t) (val >> 0);
+}
+
+static inline void h_u32_to_le(uint8_t* buf, int val)
+{
+	buf[3] = (uint8_t) (val >> 24);
+	buf[2] = (uint8_t) (val >> 16);
+	buf[1] = (uint8_t) (val >> 8);
+	buf[0] = (uint8_t) (val >> 0);
+}
+
+static inline void h_u32_to_be(uint8_t* buf, int val)
+{
+	buf[0] = (uint8_t) (val >> 24);
+	buf[1] = (uint8_t) (val >> 16);
+	buf[2] = (uint8_t) (val >> 8);
+	buf[3] = (uint8_t) (val >> 0);
+}
+
+static inline void h_u24_to_le(uint8_t* buf, int val)
+{
+	buf[2] = (uint8_t) (val >> 16);
+	buf[1] = (uint8_t) (val >> 8);
+	buf[0] = (uint8_t) (val >> 0);
+}
+
+static inline void h_u24_to_be(uint8_t* buf, int val)
+{
+	buf[0] = (uint8_t) (val >> 16);
+	buf[1] = (uint8_t) (val >> 8);
+	buf[2] = (uint8_t) (val >> 0);
+}
+
+static inline void h_u16_to_le(uint8_t* buf, int val)
+{
+	buf[1] = (uint8_t) (val >> 8);
+	buf[0] = (uint8_t) (val >> 0);
+}
+
+static inline void h_u16_to_be(uint8_t* buf, int val)
+{
+	buf[0] = (uint8_t) (val >> 8);
+	buf[1] = (uint8_t) (val >> 0);
+}
+
+/**
+ * Byte-swap buffer 16-bit.
+ *
+ * Len must be even, dst and src must be either the same or non-overlapping.
+ *
+ * @param dst Destination buffer.
+ * @param src Source buffer.
+ * @param len Length of source (and destination) buffer, in bytes.
+ */
+static inline void buf_bswap16(uint8_t *dst, const uint8_t *src, size_t len)
+{
+	assert(len % 2 == 0);
+	assert(dst == src || dst + len <= src || src + len <= dst);
+
+	for (size_t n = 0; n < len; n += 2) {
+		uint16_t x = be_to_h_u16(src + n);
+		h_u16_to_le(dst + n, x);
+	}
+}
+
+/**
+ * Byte-swap buffer 32-bit.
+ *
+ * Len must be divisible by four, dst and src must be either the same or non-overlapping.
+ *
+ * @param dst Destination buffer.
+ * @param src Source buffer.
+ * @param len Length of source (and destination) buffer, in bytes.
+ */
+static inline void buf_bswap32(uint8_t *dst, const uint8_t *src, size_t len)
+{
+	assert(len % 4 == 0);
+	assert(dst == src || dst + len <= src || src + len <= dst);
+
+	for (size_t n = 0; n < len; n += 4) {
+		uint32_t x = be_to_h_u32(src + n);
+		h_u32_to_le(dst + n, x);
+	}
+}
+
+/**
+ * Calculate the (even) parity of a 32-bit datum.
+ * @param x The datum.
+ * @return 1 if the number of set bits in x is odd, 0 if it is even.
+ */
+static inline int parity_u32(uint32_t x)
+{
+#ifdef __GNUC__
+	return __builtin_parityl(x);
+#else
+	x ^= x >> 16;
+	x ^= x >> 8;
+	x ^= x >> 4;
+	x ^= x >> 2;
+	x ^= x >> 1;
+	return x & 1;
+#endif
+}
+
+#if defined(__ECOS)
+
+/* eCos plain lacks these definition... A series of upstream patches
+ * could probably repair it, but it seems like too much work to be
+ * worth it.
+ */
+
+#if !defined(_STDINT_H)
+#define PRIx32 "x"
+#define PRId32 "d"
+#define SCNx32 "x"
+#define PRIi32 "i"
+#define PRIu32 "u"
+#define PRId8 PRId32
+#define SCNx64 "llx"
+#define PRIx64 "llx"
+
+typedef CYG_ADDRWORD intptr_t;
+typedef int64_t intmax_t;
+typedef uint64_t uintmax_t;
+#define INT8_MAX 0x7f
+#define INT8_MIN (-INT8_MAX - 1)
+# define UINT8_MAX		(255)
+#define INT16_MAX 0x7fff
+#define INT16_MIN (-INT16_MAX - 1)
+# define UINT16_MAX		(65535)
+#define INT32_MAX 0x7fffffffL
+#define INT32_MIN (-INT32_MAX - 1L)
+# define UINT32_MAX		(4294967295U)
+#define INT64_MAX 0x7fffffffffffffffLL
+#define INT64_MIN (-INT64_MAX - 1LL)
+#define UINT64_MAX (__CONCAT(INT64_MAX, U) * 2ULL + 1ULL)
+#endif
+
+	#ifndef LLONG_MAX
+	#define ULLONG_MAX	UINT64_C(0xFFFFFFFFFFFFFFFF)
+	#define LLONG_MAX	INT64_C(0x7FFFFFFFFFFFFFFF)
+	#define LLONG_MIN	ULLONG_MAX
+	#endif
+
+
+#define ULLONG_MAX 18446744073709551615
+
+/* C99, eCos is C90 compliant (with bits of C99) */
+#define isblank(c) ((c) == ' ' || (c) == '\t')
+
+
+#endif
+
+#endif /* TYPES_H */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/e302582d/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/src/helper/update_jep106.pl
----------------------------------------------------------------------
diff --git a/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/src/helper/update_jep106.pl b/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/src/helper/update_jep106.pl
new file mode 100755
index 0000000..caec066
--- /dev/null
+++ b/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/src/helper/update_jep106.pl
@@ -0,0 +1,35 @@
+#!/usr/bin/perl
+use strict;
+use warnings;
+use File::Basename;
+
+if (@ARGV != 1) {
+	die "Usage: $0 <JEP106 PDF document>\n\n"
+	. "Convert the JEDEC document containing manufacturer identification codes\n"
+	. "to an array initializer suitable for incusion into jep106.c. The latest\n"
+	. "version of the document can be found here:\n"
+	. "http://www.jedec.org/standards-documents/results/jep106\n";
+};
+
+my $outfile = dirname($0) . "/jep106.inc";
+
+open(my $out, ">", $outfile) || die "Cannot open $outfile: $!\n";
+open(my $pdftotext, "pdftotext -layout $ARGV[0] - |") || die "Cannot fork: $!\n";
+
+print $out "/* Autogenerated with " . basename($0) . "*/\n";
+
+my $bank = -1;
+
+while (<$pdftotext>) {
+	if (/^[0-9]+[[:space:]]+(.*?)[[:space:]]+([01][[:space:]]+){8}([0-9A-F]{2})$/) {
+		if ($3 eq "01") {
+			$bank++
+		}
+		my $id=sprintf("0x%02x",hex($3)&0x7f);
+		print $out "[$bank][$id - 1] = \"$1\",\n";
+	}
+}
+
+close $pdftotext || die "Error: $! $?\n";
+
+print $out "/* EOF */\n";

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/e302582d/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/src/helper/util.c
----------------------------------------------------------------------
diff --git a/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/src/helper/util.c b/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/src/helper/util.c
new file mode 100755
index 0000000..55b92a7
--- /dev/null
+++ b/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/src/helper/util.c
@@ -0,0 +1,61 @@
+/***************************************************************************
+ *   Copyright (C) 2010 by �yvind Harboe                                   *
+ *                                                                         *
+ *   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.,                                       *
+ *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.           *
+ ***************************************************************************/
+
+/* this file contains various functionality useful to standalone systems */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "log.h"
+#include "time_support.h"
+
+static int util_Jim_Command_ms(Jim_Interp *interp,
+	int argc,
+	Jim_Obj * const *argv)
+{
+	if (argc != 1) {
+		Jim_WrongNumArgs(interp, 1, argv, "ls ?dir?");
+		return JIM_ERR;
+	}
+
+	/* Cast from 64 to 32 bit int works for 2's-compliment
+	 * when calculating differences*/
+	Jim_SetResult(interp, Jim_NewIntObj(interp, (int)timeval_ms()));
+
+	return JIM_OK;
+}
+
+static const struct command_registration util_command_handlers[] = {
+	/* jim handlers */
+	{
+		.name = "ms",
+		.mode = COMMAND_ANY,
+		.jim_handler = util_Jim_Command_ms,
+		.help =
+			"Returns ever increasing milliseconds. Used to calculuate differences in time.",
+		.usage = "",
+	},
+	COMMAND_REGISTRATION_DONE
+};
+
+int util_init(struct command_context *cmd_ctx)
+{
+	return register_commands(cmd_ctx, NULL, util_command_handlers);
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/e302582d/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/src/helper/util.h
----------------------------------------------------------------------
diff --git a/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/src/helper/util.h b/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/src/helper/util.h
new file mode 100755
index 0000000..48db725
--- /dev/null
+++ b/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/src/helper/util.h
@@ -0,0 +1,27 @@
+/***************************************************************************
+ *   Copyright (C) 2010 by �yvind Harboe                                   *
+ *                                                                         *
+ *   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.,                                       *
+ *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.           *
+ ***************************************************************************/
+
+#ifndef HELPER_UTILS_H
+#define HELPER_UTILS_H
+
+struct command_context;
+
+int util_init(struct command_context *cmd_ctx);
+
+#endif	/* HELPER_UTILS_H */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/e302582d/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/src/jtag/Makefile.am
----------------------------------------------------------------------
diff --git a/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/src/jtag/Makefile.am b/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/src/jtag/Makefile.am
new file mode 100755
index 0000000..db3e6ff
--- /dev/null
+++ b/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/src/jtag/Makefile.am
@@ -0,0 +1,86 @@
+include $(top_srcdir)/common.mk
+
+METASOURCES = AUTO
+noinst_LTLIBRARIES = libjtag.la
+
+SUBDIRS =
+DRIVERFILES =
+libjtag_la_LIBADD =
+
+CLEANFILES =
+
+BUILT_SOURCES =
+
+BUILT_SOURCES += minidriver_imp.h
+CLEANFILES += minidriver_imp.h
+
+if MINIDRIVER
+
+if ZY1000
+DRIVERFILES += zy1000/zy1000.c
+JTAG_MINIDRIVER_DIR = $(srcdir)/zy1000
+endif
+if MINIDRIVER_DUMMY
+DRIVERFILES += minidummy/minidummy.c commands.c
+JTAG_MINIDRIVER_DIR = $(srcdir)/minidummy
+endif
+
+MINIDRIVER_IMP_DIR = $(srcdir)/minidriver
+
+jtag_minidriver.h: $(JTAG_MINIDRIVER_DIR)/jtag_minidriver.h
+	cp $< $@
+
+BUILT_SOURCES += jtag_minidriver.h
+
+CLEANFILES += jtag_minidriver.h
+
+else
+
+MINIDRIVER_IMP_DIR = $(srcdir)/drivers
+DRIVERFILES += commands.c
+
+if HLADAPTER
+SUBDIRS += hla
+libjtag_la_LIBADD += $(top_builddir)/src/jtag/hla/libocdhla.la
+endif
+
+if AICE
+SUBDIRS += aice
+libjtag_la_LIBADD += $(top_builddir)/src/jtag/aice/libocdaice.la
+endif
+
+SUBDIRS += drivers
+libjtag_la_LIBADD += $(top_builddir)/src/jtag/drivers/libocdjtagdrivers.la
+
+
+endif
+
+# endif // MINIDRIVER
+
+minidriver_imp.h: $(MINIDRIVER_IMP_DIR)/minidriver_imp.h
+	cp $< $@
+
+
+libjtag_la_SOURCES = \
+	adapter.c \
+	core.c \
+	interface.c \
+	interfaces.c \
+	tcl.c \
+	$(DRIVERFILES)
+
+noinst_HEADERS = \
+	commands.h \
+	driver.h \
+	interface.h \
+	interfaces.h \
+	minidriver.h \
+	jtag.h \
+	minidriver/minidriver_imp.h \
+	minidummy/jtag_minidriver.h \
+	swd.h \
+	tcl.h
+
+EXTRA_DIST = startup.tcl
+
+MAINTAINERCLEANFILES = $(srcdir)/Makefile.in

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/e302582d/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/src/jtag/adapter.c
----------------------------------------------------------------------
diff --git a/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/src/jtag/adapter.c b/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/src/jtag/adapter.c
new file mode 100755
index 0000000..2f5f6b4
--- /dev/null
+++ b/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/src/jtag/adapter.c
@@ -0,0 +1,537 @@
+/***************************************************************************
+ *   Copyright (C) 2005 by Dominic Rath                                    *
+ *   Dominic.Rath@gmx.de                                                   *
+ *                                                                         *
+ *   Copyright (C) 2007-2010 �yvind Harboe                                 *
+ *   oyvind.harboe@zylin.com                                               *
+ *                                                                         *
+ *   Copyright (C) 2009 SoftPLC Corporation                                *
+ *       http://softplc.com                                                *
+ *   dick@softplc.com                                                      *
+ *                                                                         *
+ *   Copyright (C) 2009 Zachary T Welch                                    *
+ *   zw@superlucidity.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.,                                       *
+ *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.           *
+ ***************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "jtag.h"
+#include "minidriver.h"
+#include "interface.h"
+#include "interfaces.h"
+#include <transport/transport.h>
+
+#ifdef HAVE_STRINGS_H
+#include <strings.h>
+#endif
+
+/**
+ * @file
+ * Holds support for configuring debug adapters from TCl scripts.
+ */
+
+extern struct jtag_interface *jtag_interface;
+const char * const jtag_only[] = { "jtag", NULL };
+
+static int jim_adapter_name(Jim_Interp *interp, int argc, Jim_Obj * const *argv)
+{
+	Jim_GetOptInfo goi;
+	Jim_GetOpt_Setup(&goi, interp, argc-1, argv + 1);
+
+	/* return the name of the interface */
+	/* TCL code might need to know the exact type... */
+	/* FUTURE: we allow this as a means to "set" the interface. */
+	if (goi.argc != 0) {
+		Jim_WrongNumArgs(goi.interp, 1, goi.argv-1, "(no params)");
+		return JIM_ERR;
+	}
+	const char *name = jtag_interface ? jtag_interface->name : NULL;
+	Jim_SetResultString(goi.interp, name ? : "undefined", -1);
+	return JIM_OK;
+}
+
+static int default_khz(int khz, int *jtag_speed)
+{
+	LOG_ERROR("Translation from khz to jtag_speed not implemented");
+	return ERROR_FAIL;
+}
+
+static int default_speed_div(int speed, int *khz)
+{
+	LOG_ERROR("Translation from jtag_speed to khz not implemented");
+	return ERROR_FAIL;
+}
+
+static int default_power_dropout(int *dropout)
+{
+	*dropout = 0; /* by default we can't detect power dropout */
+	return ERROR_OK;
+}
+
+static int default_srst_asserted(int *srst_asserted)
+{
+	*srst_asserted = 0; /* by default we can't detect srst asserted */
+	return ERROR_OK;
+}
+
+COMMAND_HANDLER(interface_transport_command)
+{
+	char **transports;
+	int retval;
+
+	retval = CALL_COMMAND_HANDLER(transport_list_parse, &transports);
+	if (retval != ERROR_OK)
+		return retval;
+
+	retval = allow_transports(CMD_CTX, (const char **)transports);
+
+	if (retval != ERROR_OK) {
+		for (unsigned i = 0; transports[i]; i++)
+			free(transports[i]);
+		free(transports);
+	}
+	return retval;
+}
+
+COMMAND_HANDLER(handle_interface_list_command)
+{
+	if (strcmp(CMD_NAME, "interface_list") == 0 && CMD_ARGC > 0)
+		return ERROR_COMMAND_SYNTAX_ERROR;
+
+	command_print(CMD_CTX, "The following debug interfaces are available:");
+	for (unsigned i = 0; NULL != jtag_interfaces[i]; i++) {
+		const char *name = jtag_interfaces[i]->name;
+		command_print(CMD_CTX, "%u: %s", i + 1, name);
+	}
+
+	return ERROR_OK;
+}
+
+COMMAND_HANDLER(handle_interface_command)
+{
+	int retval;
+
+	/* check whether the interface is already configured */
+	if (jtag_interface) {
+		LOG_WARNING("Interface already configured, ignoring");
+		return ERROR_OK;
+	}
+
+	/* interface name is a mandatory argument */
+	if (CMD_ARGC != 1 || CMD_ARGV[0][0] == '\0')
+		return ERROR_COMMAND_SYNTAX_ERROR;
+
+	for (unsigned i = 0; NULL != jtag_interfaces[i]; i++) {
+		if (strcmp(CMD_ARGV[0], jtag_interfaces[i]->name) != 0)
+			continue;
+
+		if (NULL != jtag_interfaces[i]->commands) {
+			retval = register_commands(CMD_CTX, NULL,
+					jtag_interfaces[i]->commands);
+			if (ERROR_OK != retval)
+				return retval;
+		}
+
+		jtag_interface = jtag_interfaces[i];
+
+	/* LEGACY SUPPORT ... adapter drivers  must declare what
+	 * transports they allow.  Until they all do so, assume
+	 * the legacy drivers are JTAG-only
+	 */
+	if (!jtag_interface->transports)
+		LOG_WARNING("Adapter driver '%s' did not declare "
+			"which transports it allows; assuming "
+			"legacy JTAG-only", jtag_interface->name);
+		retval = allow_transports(CMD_CTX, jtag_interface->transports
+						? jtag_interface->transports : jtag_only);
+			if (ERROR_OK != retval)
+				return retval;
+
+		if (jtag_interface->khz == NULL)
+			jtag_interface->khz = default_khz;
+		if (jtag_interface->speed_div == NULL)
+			jtag_interface->speed_div = default_speed_div;
+		if (jtag_interface->power_dropout == NULL)
+			jtag_interface->power_dropout = default_power_dropout;
+		if (jtag_interface->srst_asserted == NULL)
+			jtag_interface->srst_asserted = default_srst_asserted;
+
+		return ERROR_OK;
+	}
+
+	/* no valid interface was found (i.e. the configuration option,
+	 * didn't match one of the compiled-in interfaces
+	 */
+	LOG_ERROR("The specified debug interface was not found (%s)",
+				CMD_ARGV[0]);
+	CALL_COMMAND_HANDLER(handle_interface_list_command);
+	return ERROR_JTAG_INVALID_INTERFACE;
+}
+
+COMMAND_HANDLER(handle_reset_config_command)
+{
+	int new_cfg = 0;
+	int mask = 0;
+
+	/* Original versions cared about the order of these tokens:
+	 *   reset_config signals [combination [trst_type [srst_type]]]
+	 * They also clobbered the previous configuration even on error.
+	 *
+	 * Here we don't care about the order, and only change values
+	 * which have been explicitly specified.
+	 */
+	for (; CMD_ARGC; CMD_ARGC--, CMD_ARGV++) {
+		int tmp = 0;
+		int m;
+
+		/* gating */
+		m = RESET_SRST_NO_GATING;
+		if (strcmp(*CMD_ARGV, "srst_gates_jtag") == 0)
+			/* default: don't use JTAG while SRST asserted */;
+		else if (strcmp(*CMD_ARGV, "srst_nogate") == 0)
+			tmp = RESET_SRST_NO_GATING;
+		else
+			m = 0;
+		if (mask & m) {
+			LOG_ERROR("extra reset_config %s spec (%s)",
+					"gating", *CMD_ARGV);
+			return ERROR_COMMAND_SYNTAX_ERROR;
+		}
+		if (m)
+			goto next;
+
+		/* signals */
+		m = RESET_HAS_TRST | RESET_HAS_SRST;
+		if (strcmp(*CMD_ARGV, "none") == 0)
+			tmp = RESET_NONE;
+		else if (strcmp(*CMD_ARGV, "trst_only") == 0)
+			tmp = RESET_HAS_TRST;
+		else if (strcmp(*CMD_ARGV, "srst_only") == 0)
+			tmp = RESET_HAS_SRST;
+		else if (strcmp(*CMD_ARGV, "trst_and_srst") == 0)
+			tmp = RESET_HAS_TRST | RESET_HAS_SRST;
+		else
+			m = 0;
+		if (mask & m) {
+			LOG_ERROR("extra reset_config %s spec (%s)",
+					"signal", *CMD_ARGV);
+			return ERROR_COMMAND_SYNTAX_ERROR;
+		}
+		if (m)
+			goto next;
+
+		/* combination (options for broken wiring) */
+		m = RESET_SRST_PULLS_TRST | RESET_TRST_PULLS_SRST;
+		if (strcmp(*CMD_ARGV, "separate") == 0)
+			/* separate reset lines - default */;
+		else if (strcmp(*CMD_ARGV, "srst_pulls_trst") == 0)
+			tmp |= RESET_SRST_PULLS_TRST;
+		else if (strcmp(*CMD_ARGV, "trst_pulls_srst") == 0)
+			tmp |= RESET_TRST_PULLS_SRST;
+		else if (strcmp(*CMD_ARGV, "combined") == 0)
+			tmp |= RESET_SRST_PULLS_TRST | RESET_TRST_PULLS_SRST;
+		else
+			m = 0;
+		if (mask & m) {
+			LOG_ERROR("extra reset_config %s spec (%s)",
+					"combination", *CMD_ARGV);
+			return ERROR_COMMAND_SYNTAX_ERROR;
+		}
+		if (m)
+			goto next;
+
+		/* trst_type (NOP without HAS_TRST) */
+		m = RESET_TRST_OPEN_DRAIN;
+		if (strcmp(*CMD_ARGV, "trst_open_drain") == 0)
+			tmp |= RESET_TRST_OPEN_DRAIN;
+		else if (strcmp(*CMD_ARGV, "trst_push_pull") == 0)
+			/* push/pull from adapter - default */;
+		else
+			m = 0;
+		if (mask & m) {
+			LOG_ERROR("extra reset_config %s spec (%s)",
+					"trst_type", *CMD_ARGV);
+			return ERROR_COMMAND_SYNTAX_ERROR;
+		}
+		if (m)
+			goto next;
+
+		/* srst_type (NOP without HAS_SRST) */
+		m = RESET_SRST_PUSH_PULL;
+		if (strcmp(*CMD_ARGV, "srst_push_pull") == 0)
+			tmp |= RESET_SRST_PUSH_PULL;
+		else if (strcmp(*CMD_ARGV, "srst_open_drain") == 0)
+			/* open drain from adapter - default */;
+		else
+			m = 0;
+		if (mask & m) {
+			LOG_ERROR("extra reset_config %s spec (%s)",
+					"srst_type", *CMD_ARGV);
+			return ERROR_COMMAND_SYNTAX_ERROR;
+		}
+		if (m)
+			goto next;
+
+		/* connect_type - only valid when srst_nogate */
+		m = RESET_CNCT_UNDER_SRST;
+		if (strcmp(*CMD_ARGV, "connect_assert_srst") == 0)
+			tmp |= RESET_CNCT_UNDER_SRST;
+		else if (strcmp(*CMD_ARGV, "connect_deassert_srst") == 0)
+			/* connect normally - default */;
+		else
+			m = 0;
+		if (mask & m) {
+			LOG_ERROR("extra reset_config %s spec (%s)",
+					"connect_type", *CMD_ARGV);
+			return ERROR_COMMAND_SYNTAX_ERROR;
+		}
+		if (m)
+			goto next;
+
+		/* caller provided nonsense; fail */
+		LOG_ERROR("unknown reset_config flag (%s)", *CMD_ARGV);
+		return ERROR_COMMAND_SYNTAX_ERROR;
+
+next:
+		/* Remember the bits which were specified (mask)
+		 * and their new values (new_cfg).
+		 */
+		mask |= m;
+		new_cfg |= tmp;
+	}
+
+	/* clear previous values of those bits, save new values */
+	if (mask) {
+		int old_cfg = jtag_get_reset_config();
+
+		old_cfg &= ~mask;
+		new_cfg |= old_cfg;
+		jtag_set_reset_config(new_cfg);
+	} else
+		new_cfg = jtag_get_reset_config();
+
+	/*
+	 * Display the (now-)current reset mode
+	 */
+	char *modes[6];
+
+	/* minimal JTAG has neither SRST nor TRST (so that's the default) */
+	switch (new_cfg & (RESET_HAS_TRST | RESET_HAS_SRST)) {
+		case RESET_HAS_SRST:
+			modes[0] = "srst_only";
+			break;
+		case RESET_HAS_TRST:
+			modes[0] = "trst_only";
+			break;
+		case RESET_TRST_AND_SRST:
+			modes[0] = "trst_and_srst";
+			break;
+		default:
+			modes[0] = "none";
+			break;
+	}
+
+	/* normally SRST and TRST are decoupled; but bugs happen ... */
+	switch (new_cfg & (RESET_SRST_PULLS_TRST | RESET_TRST_PULLS_SRST)) {
+		case RESET_SRST_PULLS_TRST:
+			modes[1] = "srst_pulls_trst";
+			break;
+		case RESET_TRST_PULLS_SRST:
+			modes[1] = "trst_pulls_srst";
+			break;
+		case RESET_SRST_PULLS_TRST | RESET_TRST_PULLS_SRST:
+			modes[1] = "combined";
+			break;
+		default:
+			modes[1] = "separate";
+			break;
+	}
+
+	/* TRST-less connectors include Altera, Xilinx, and minimal JTAG */
+	if (new_cfg & RESET_HAS_TRST) {
+		if (new_cfg & RESET_TRST_OPEN_DRAIN)
+			modes[3] = " trst_open_drain";
+		else
+			modes[3] = " trst_push_pull";
+	} else
+		modes[3] = "";
+
+	/* SRST-less connectors include TI-14, Xilinx, and minimal JTAG */
+	if (new_cfg & RESET_HAS_SRST) {
+		if (new_cfg & RESET_SRST_NO_GATING)
+			modes[2] = " srst_nogate";
+		else
+			modes[2] = " srst_gates_jtag";
+
+		if (new_cfg & RESET_SRST_PUSH_PULL)
+			modes[4] = " srst_push_pull";
+		else
+			modes[4] = " srst_open_drain";
+
+		if (new_cfg & RESET_CNCT_UNDER_SRST)
+			modes[5] = " connect_assert_srst";
+		else
+			modes[5] = " connect_deassert_srst";
+	} else {
+		modes[2] = "";
+		modes[4] = "";
+		modes[5] = "";
+	}
+
+	command_print(CMD_CTX, "%s %s%s%s%s%s",
+			modes[0], modes[1],
+			modes[2], modes[3], modes[4], modes[5]);
+
+	return ERROR_OK;
+}
+
+COMMAND_HANDLER(handle_adapter_nsrst_delay_command)
+{
+	if (CMD_ARGC > 1)
+		return ERROR_COMMAND_SYNTAX_ERROR;
+	if (CMD_ARGC == 1) {
+		unsigned delay;
+		COMMAND_PARSE_NUMBER(uint, CMD_ARGV[0], delay);
+
+		jtag_set_nsrst_delay(delay);
+	}
+	command_print(CMD_CTX, "adapter_nsrst_delay: %u", jtag_get_nsrst_delay());
+	return ERROR_OK;
+}
+
+COMMAND_HANDLER(handle_adapter_nsrst_assert_width_command)
+{
+	if (CMD_ARGC > 1)
+		return ERROR_COMMAND_SYNTAX_ERROR;
+	if (CMD_ARGC == 1) {
+		unsigned width;
+		COMMAND_PARSE_NUMBER(uint, CMD_ARGV[0], width);
+
+		jtag_set_nsrst_assert_width(width);
+	}
+	command_print(CMD_CTX, "adapter_nsrst_assert_width: %u", jtag_get_nsrst_assert_width());
+	return ERROR_OK;
+}
+
+COMMAND_HANDLER(handle_adapter_khz_command)
+{
+	if (CMD_ARGC > 1)
+		return ERROR_COMMAND_SYNTAX_ERROR;
+
+	int retval = ERROR_OK;
+	if (CMD_ARGC == 1) {
+		unsigned khz = 0;
+		COMMAND_PARSE_NUMBER(uint, CMD_ARGV[0], khz);
+
+		retval = jtag_config_khz(khz);
+		if (ERROR_OK != retval)
+			return retval;
+	}
+
+	int cur_speed = jtag_get_speed_khz();
+	retval = jtag_get_speed_readable(&cur_speed);
+	if (ERROR_OK != retval)
+		return retval;
+
+	if (cur_speed)
+		command_print(CMD_CTX, "adapter speed: %d kHz", cur_speed);
+	else
+		command_print(CMD_CTX, "adapter speed: RCLK - adaptive");
+
+	return retval;
+}
+
+static const struct command_registration interface_command_handlers[] = {
+	{
+		.name = "adapter_khz",
+		.handler = handle_adapter_khz_command,
+		.mode = COMMAND_ANY,
+		.help = "With an argument, change to the specified maximum "
+			"jtag speed.  For JTAG, 0 KHz signifies adaptive "
+			" clocking. "
+			"With or without argument, display current setting.",
+		.usage = "[khz]",
+	},
+	{
+		.name = "adapter_name",
+		.mode = COMMAND_ANY,
+		.jim_handler = jim_adapter_name,
+		.help = "Returns the name of the currently "
+			"selected adapter (driver)",
+	},
+	{
+		.name = "adapter_nsrst_delay",
+		.handler = handle_adapter_nsrst_delay_command,
+		.mode = COMMAND_ANY,
+		.help = "delay after deasserting SRST in ms",
+		.usage = "[milliseconds]",
+	},
+	{
+		.name = "adapter_nsrst_assert_width",
+		.handler = handle_adapter_nsrst_assert_width_command,
+		.mode = COMMAND_ANY,
+		.help = "delay after asserting SRST in ms",
+		.usage = "[milliseconds]",
+	},
+	{
+		.name = "interface",
+		.handler = handle_interface_command,
+		.mode = COMMAND_CONFIG,
+		.help = "Select a debug adapter interface (driver)",
+		.usage = "driver_name",
+	},
+	{
+		.name = "interface_transports",
+		.handler = interface_transport_command,
+		.mode = COMMAND_CONFIG,
+		.help = "Declare transports the interface supports.",
+		.usage = "transport ... ",
+	},
+	{
+		.name = "interface_list",
+		.handler = handle_interface_list_command,
+		.mode = COMMAND_ANY,
+		.help = "List all built-in debug adapter interfaces (drivers)",
+	},
+	{
+		.name = "reset_config",
+		.handler = handle_reset_config_command,
+		.mode = COMMAND_ANY,
+		.help = "configure adapter reset behavior",
+		.usage = "[none|trst_only|srst_only|trst_and_srst] "
+			"[srst_pulls_trst|trst_pulls_srst|combined|separate] "
+			"[srst_gates_jtag|srst_nogate] "
+			"[trst_push_pull|trst_open_drain] "
+			"[srst_push_pull|srst_open_drain] "
+			"[connect_deassert_srst|connect_assert_srst]",
+	},
+	COMMAND_REGISTRATION_DONE
+};
+
+/**
+ * Register the commands which deal with arbitrary debug adapter drivers.
+ *
+ * @todo Remove internal assumptions that all debug adapters use JTAG for
+ * transport.  Various types and data structures are not named generically.
+ */
+int interface_register_commands(struct command_context *ctx)
+{
+	return register_commands(ctx, NULL, interface_command_handlers);
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/e302582d/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/src/jtag/aice/Makefile.am
----------------------------------------------------------------------
diff --git a/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/src/jtag/aice/Makefile.am b/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/src/jtag/aice/Makefile.am
new file mode 100755
index 0000000..7b9469d
--- /dev/null
+++ b/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/src/jtag/aice/Makefile.am
@@ -0,0 +1,27 @@
+include $(top_srcdir)/common.mk
+
+AM_CPPFLAGS += -I$(top_srcdir)/src/jtag/drivers $(LIBUSB1_CFLAGS) $(LIBUSB0_CFLAGS)
+
+noinst_LTLIBRARIES = libocdaice.la
+
+libocdaice_la_SOURCES = \
+	$(AICEFILES)
+
+AICEFILES =
+
+if AICE
+AICEFILES += aice_transport.c
+AICEFILES += aice_interface.c
+AICEFILES += aice_port.c
+AICEFILES += aice_usb.c
+AICEFILES += aice_pipe.c
+endif
+
+noinst_HEADERS = \
+	aice_transport.h \
+	aice_interface.h \
+	aice_port.h \
+	aice_usb.h \
+	aice_pipe.h
+
+MAINTAINERCLEANFILES = $(srcdir)/Makefile.in

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/e302582d/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/src/jtag/aice/aice_interface.c
----------------------------------------------------------------------
diff --git a/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/src/jtag/aice/aice_interface.c b/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/src/jtag/aice/aice_interface.c
new file mode 100755
index 0000000..363b208
--- /dev/null
+++ b/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/src/jtag/aice/aice_interface.c
@@ -0,0 +1,509 @@
+/***************************************************************************
+ *   Copyright (C) 2013 by Andes Technology                                *
+ *   Hsiangkai Wang <hk...@andestech.com>                                 *
+ *                                                                         *
+ *   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.,                                       *
+ *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.           *
+ ***************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <jtag/interface.h>
+#include <jtag/commands.h>
+#include <transport/transport.h>
+#include <target/target.h>
+#include <jtag/aice/aice_transport.h>
+#include <jtag/drivers/libusb_common.h>
+#include "aice_usb.h"
+
+#define AICE_KHZ_TO_SPEED_MAP_SIZE	16
+static const int aice_khz_to_speed_map[AICE_KHZ_TO_SPEED_MAP_SIZE] = {
+	30000,
+	15000,
+	7500,
+	3750,
+	1875,
+	937,
+	468,
+	234,
+	48000,
+	24000,
+	12000,
+	6000,
+	3000,
+	1500,
+	750,
+	375,
+};
+
+static const struct aice_port *aice_port;
+static struct aice_port_param_s param;
+static uint32_t retry_times;
+static uint32_t count_to_check_dbger;
+
+/***************************************************************************/
+/* External interface implementation */
+static uint32_t aice_target_id_codes[AICE_MAX_NUM_CORE];
+static uint8_t aice_num_of_target_id_codes;
+
+/***************************************************************************/
+/* AICE operations */
+int aice_init_targets(void)
+{
+	int res;
+	struct target *target;
+	struct aice_port_s *aice;
+
+	LOG_DEBUG("aice_init_targets");
+
+	if (aice_num_of_target_id_codes == 0) {
+		res = aice_port->api->idcode(aice_target_id_codes, &aice_num_of_target_id_codes);
+		if (res != ERROR_OK) {
+			LOG_ERROR("<-- TARGET ERROR! Failed to identify AndesCore "
+					"JTAG Manufacture ID in the JTAG scan chain. "
+					"Failed to access EDM registers. -->");
+			return res;
+		}
+	}
+
+	for (target = all_targets; target; target = target->next) {
+		target->tap->idcode = aice_target_id_codes[target->tap->abs_chain_position];
+
+		unsigned ii, limit = target->tap->expected_ids_cnt;
+		int found = 0;
+
+		for (ii = 0; ii < limit; ii++) {
+			uint32_t expected = target->tap->expected_ids[ii];
+
+			/* treat "-expected-id 0" as a "don't-warn" wildcard */
+			if (!expected || (target->tap->idcode == expected)) {
+				found = 1;
+				break;
+			}
+		}
+
+		if (found == 0) {
+			LOG_ERROR
+				("aice_init_targets: target not found: idcode: %" PRIx32,
+				 target->tap->idcode);
+			return ERROR_FAIL;
+		}
+
+		aice = calloc(1, sizeof(struct aice_port_s));
+		aice->port = aice_port;
+		aice->coreid = target->tap->abs_chain_position;
+
+		target->tap->priv = aice;
+		target->tap->hasidcode = 1;
+	}
+
+	return ERROR_OK;
+}
+
+/***************************************************************************/
+/* End of External interface implementation */
+
+/* initial aice
+ * 1. open usb
+ * 2. get/show version number
+ * 3. reset
+ */
+static int aice_init(void)
+{
+	if (ERROR_OK != aice_port->api->open(&param)) {
+		LOG_ERROR("Cannot find AICE Interface! Please check "
+				"connection and permissions.");
+		return ERROR_JTAG_INIT_FAILED;
+	}
+
+	aice_port->api->set_retry_times(retry_times);
+	aice_port->api->set_count_to_check_dbger(count_to_check_dbger);
+
+	LOG_INFO("AICE JTAG Interface ready");
+
+	return ERROR_OK;
+}
+
+/* cleanup aice resource
+ * close usb
+ */
+static int aice_quit(void)
+{
+	aice_port->api->close();
+	return ERROR_OK;
+}
+
+static int aice_execute_reset(struct jtag_command *cmd)
+{
+	static int last_trst;
+	int retval = ERROR_OK;
+
+	DEBUG_JTAG_IO("reset trst: %d", cmd->cmd.reset->trst);
+
+	if (cmd->cmd.reset->trst != last_trst) {
+		if (cmd->cmd.reset->trst)
+			retval = aice_port->api->reset();
+
+		last_trst = cmd->cmd.reset->trst;
+	}
+
+	return retval;
+}
+
+static int aice_execute_command(struct jtag_command *cmd)
+{
+	int retval;
+
+	switch (cmd->type) {
+		case JTAG_RESET:
+			retval = aice_execute_reset(cmd);
+			break;
+		default:
+			retval = ERROR_OK;
+			break;
+	}
+	return retval;
+}
+
+/* aice has no need to implement jtag execution model
+*/
+static int aice_execute_queue(void)
+{
+	struct jtag_command *cmd = jtag_command_queue;	/* currently processed command */
+	int retval;
+
+	retval = ERROR_OK;
+
+	while (cmd) {
+		if (aice_execute_command(cmd) != ERROR_OK)
+			retval = ERROR_JTAG_QUEUE_FAILED;
+
+		cmd = cmd->next;
+	}
+
+	return retval;
+}
+
+/* set jtag frequency(base frequency/frequency divider) to your jtag adapter */
+static int aice_speed(int speed)
+{
+	return aice_port->api->set_jtag_clock(speed);
+}
+
+/* convert jtag adapter frequency(base frequency/frequency divider) to
+ * human readable KHz value */
+static int aice_speed_div(int speed, int *khz)
+{
+	*khz = aice_khz_to_speed_map[speed];
+
+	return ERROR_OK;
+}
+
+/* convert human readable KHz value to jtag adapter frequency
+ * (base frequency/frequency divider) */
+static int aice_khz(int khz, int *jtag_speed)
+{
+	int i;
+	for (i = 0 ; i < AICE_KHZ_TO_SPEED_MAP_SIZE ; i++) {
+		if (khz == aice_khz_to_speed_map[i]) {
+			if (8 <= i)
+				*jtag_speed = i | AICE_TCK_CONTROL_TCK3048;
+			else
+				*jtag_speed = i;
+			break;
+		}
+	}
+
+	if (i == AICE_KHZ_TO_SPEED_MAP_SIZE) {
+		LOG_INFO("No support the jtag clock: %d", khz);
+		LOG_INFO("Supported jtag clocks are:");
+
+		for (i = 0 ; i < AICE_KHZ_TO_SPEED_MAP_SIZE ; i++)
+			LOG_INFO("* %d", aice_khz_to_speed_map[i]);
+
+		return ERROR_FAIL;
+	}
+
+	return ERROR_OK;
+}
+
+/***************************************************************************/
+/* Command handlers */
+COMMAND_HANDLER(aice_handle_aice_info_command)
+{
+	LOG_DEBUG("aice_handle_aice_info_command");
+
+	command_print(CMD_CTX, "Description: %s", param.device_desc);
+	command_print(CMD_CTX, "Serial number: %s", param.serial);
+	if (strncmp(aice_port->name, "aice_pipe", 9) == 0)
+		command_print(CMD_CTX, "Adapter: %s", param.adapter_name);
+
+	return ERROR_OK;
+}
+
+COMMAND_HANDLER(aice_handle_aice_port_command)
+{
+	LOG_DEBUG("aice_handle_aice_port_command");
+
+	if (CMD_ARGC != 1) {
+		LOG_ERROR("Need exactly one argument to 'aice port'");
+		return ERROR_COMMAND_SYNTAX_ERROR;
+	}
+
+	for (const struct aice_port *l = aice_port_get_list(); l->name; l++) {
+		if (strcmp(l->name, CMD_ARGV[0]) == 0) {
+			aice_port = l;
+			return ERROR_OK;
+		}
+	}
+
+	LOG_ERROR("No AICE port '%s' found", CMD_ARGV[0]);
+	return ERROR_FAIL;
+}
+
+COMMAND_HANDLER(aice_handle_aice_desc_command)
+{
+	LOG_DEBUG("aice_handle_aice_desc_command");
+
+	if (CMD_ARGC == 1)
+		param.device_desc = strdup(CMD_ARGV[0]);
+	else
+		LOG_ERROR("expected exactly one argument to aice desc <description>");
+
+	return ERROR_OK;
+}
+
+COMMAND_HANDLER(aice_handle_aice_serial_command)
+{
+	LOG_DEBUG("aice_handle_aice_serial_command");
+
+	if (CMD_ARGC == 1)
+		param.serial = strdup(CMD_ARGV[0]);
+	else
+		LOG_ERROR("expected exactly one argument to aice serial <serial-number>");
+
+	return ERROR_OK;
+}
+
+COMMAND_HANDLER(aice_handle_aice_vid_pid_command)
+{
+	LOG_DEBUG("aice_handle_aice_vid_pid_command");
+
+	if (CMD_ARGC != 2) {
+		LOG_WARNING("ignoring extra IDs in aice vid_pid (maximum is 1 pair)");
+		return ERROR_COMMAND_SYNTAX_ERROR;
+	}
+
+	COMMAND_PARSE_NUMBER(u16, CMD_ARGV[0], param.vid);
+	COMMAND_PARSE_NUMBER(u16, CMD_ARGV[1], param.pid);
+
+	return ERROR_OK;
+}
+
+COMMAND_HANDLER(aice_handle_aice_adapter_command)
+{
+	LOG_DEBUG("aice_handle_aice_adapter_command");
+
+	if (CMD_ARGC == 1)
+		param.adapter_name = strdup(CMD_ARGV[0]);
+	else
+		LOG_ERROR("expected exactly one argument to aice adapter <adapter-name>");
+
+	return ERROR_OK;
+}
+
+COMMAND_HANDLER(aice_handle_aice_retry_times_command)
+{
+	LOG_DEBUG("aice_handle_aice_retry_times_command");
+
+	if (CMD_ARGC == 1)
+		COMMAND_PARSE_NUMBER(u32, CMD_ARGV[0], retry_times);
+	else
+		LOG_ERROR("expected exactly one argument to aice retry_times <num_of_retry>");
+
+	return ERROR_OK;
+}
+
+COMMAND_HANDLER(aice_handle_aice_count_to_check_dbger_command)
+{
+	LOG_DEBUG("aice_handle_aice_count_to_check_dbger_command");
+
+	if (CMD_ARGC == 1)
+		COMMAND_PARSE_NUMBER(u32, CMD_ARGV[0], count_to_check_dbger);
+	else
+		LOG_ERROR("expected exactly one argument to aice count_to_check_dbger "
+				"<count_of_checking>");
+
+	return ERROR_OK;
+}
+
+COMMAND_HANDLER(aice_handle_aice_custom_srst_script_command)
+{
+	LOG_DEBUG("aice_handle_aice_custom_srst_script_command");
+
+	if (CMD_ARGC > 0) {
+		aice_port->api->set_custom_srst_script(CMD_ARGV[0]);
+		return ERROR_OK;
+	}
+
+	return ERROR_FAIL;
+}
+
+COMMAND_HANDLER(aice_handle_aice_custom_trst_script_command)
+{
+	LOG_DEBUG("aice_handle_aice_custom_trst_script_command");
+
+	if (CMD_ARGC > 0) {
+		aice_port->api->set_custom_trst_script(CMD_ARGV[0]);
+		return ERROR_OK;
+	}
+
+	return ERROR_FAIL;
+}
+
+COMMAND_HANDLER(aice_handle_aice_custom_restart_script_command)
+{
+	LOG_DEBUG("aice_handle_aice_custom_restart_script_command");
+
+	if (CMD_ARGC > 0) {
+		aice_port->api->set_custom_restart_script(CMD_ARGV[0]);
+		return ERROR_OK;
+	}
+
+	return ERROR_FAIL;
+}
+
+COMMAND_HANDLER(aice_handle_aice_reset_command)
+{
+	LOG_DEBUG("aice_handle_aice_reset_command");
+
+	return aice_port->api->reset();
+}
+
+
+static const struct command_registration aice_subcommand_handlers[] = {
+	{
+		.name = "info",
+		.handler = &aice_handle_aice_info_command,
+		.mode = COMMAND_EXEC,
+		.help = "show aice info",
+		.usage = "aice info",
+	},
+	{
+		.name = "port",
+		.handler = &aice_handle_aice_port_command,
+		.mode = COMMAND_CONFIG,
+		.help = "set the port of the AICE",
+		.usage = "aice port ['aice_pipe'|'aice_usb']",
+	},
+	{
+		.name = "desc",
+		.handler = &aice_handle_aice_desc_command,
+		.mode = COMMAND_CONFIG,
+		.help = "set the aice device description",
+		.usage = "aice desc [desciption string]",
+	},
+	{
+		.name = "serial",
+		.handler = &aice_handle_aice_serial_command,
+		.mode = COMMAND_CONFIG,
+		.help = "set the serial number of the AICE device",
+		.usage = "aice serial [serial string]",
+	},
+	{
+		.name = "vid_pid",
+		.handler = &aice_handle_aice_vid_pid_command,
+		.mode = COMMAND_CONFIG,
+		.help = "the vendor and product ID of the AICE device",
+		.usage = "aice vid_pid (vid pid)*",
+	},
+	{
+		.name = "adapter",
+		.handler = &aice_handle_aice_adapter_command,
+		.mode = COMMAND_CONFIG,
+		.help = "set the file name of adapter",
+		.usage = "aice adapter [adapter name]",
+	},
+	{
+		.name = "retry_times",
+		.handler = &aice_handle_aice_retry_times_command,
+		.mode = COMMAND_CONFIG,
+		.help = "set retry times as AICE timeout",
+		.usage = "aice retry_times num_of_retry",
+	},
+	{
+		.name = "count_to_check_dbger",
+		.handler = &aice_handle_aice_count_to_check_dbger_command,
+		.mode = COMMAND_CONFIG,
+		.help = "set retry times as checking $DBGER status",
+		.usage = "aice count_to_check_dbger count_of_checking",
+	},
+	{
+		.name = "custom_srst_script",
+		.handler = &aice_handle_aice_custom_srst_script_command,
+		.mode = COMMAND_CONFIG,
+		.usage = "custom_srst_script script_file_name",
+		.help = "set custom srst script",
+	},
+	{
+		.name = "custom_trst_script",
+		.handler = &aice_handle_aice_custom_trst_script_command,
+		.mode = COMMAND_CONFIG,
+		.usage = "custom_trst_script script_file_name",
+		.help = "set custom trst script",
+	},
+	{
+		.name = "custom_restart_script",
+		.handler = &aice_handle_aice_custom_restart_script_command,
+		.mode = COMMAND_CONFIG,
+		.usage = "custom_restart_script script_file_name",
+		.help = "set custom restart script",
+	},
+	{
+		.name = "reset",
+		.handler = &aice_handle_aice_reset_command,
+		.mode = COMMAND_EXEC,
+		.usage = "aice reset",
+		.help = "reset AICE",
+	},
+	COMMAND_REGISTRATION_DONE
+};
+
+static const struct command_registration aice_command_handlers[] = {
+	{
+		.name = "aice",
+		.mode = COMMAND_ANY,
+		.help = "perform aice management",
+		.usage = "aice [subcommand]",
+		.chain = aice_subcommand_handlers,
+	},
+	COMMAND_REGISTRATION_DONE
+};
+/***************************************************************************/
+/* End of Command handlers */
+
+struct jtag_interface aice_interface = {
+	.name = "aice",
+	.commands = aice_command_handlers,
+	.transports = aice_transports,
+	.init = aice_init,
+	.quit = aice_quit,
+	.execute_queue = aice_execute_queue,
+	.speed = aice_speed,		/* set interface speed */
+	.speed_div = aice_speed_div,	/* return readable value */
+	.khz = aice_khz,		/* convert khz to interface speed value */
+};

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/e302582d/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/src/jtag/aice/aice_interface.h
----------------------------------------------------------------------
diff --git a/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/src/jtag/aice/aice_interface.h b/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/src/jtag/aice/aice_interface.h
new file mode 100755
index 0000000..ddb6ad4
--- /dev/null
+++ b/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/src/jtag/aice/aice_interface.h
@@ -0,0 +1,36 @@
+/***************************************************************************
+ *   Copyright (C) 2013 by Andes Technology                                *
+ *   Hsiangkai Wang <hk...@andestech.com>                                 *
+ *                                                                         *
+ *   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.,                                       *
+ *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.           *
+ ***************************************************************************/
+#ifndef __AICE_INTERFACE_H__
+#define __AICE_INTERFACE_H__
+
+struct aice_interface_param_s {
+	/** */
+	const char *device_desc;
+	/** */
+	const char *serial;
+	/** */
+	uint16_t vid;
+	/** */
+	uint16_t pid;
+};
+
+int aice_init_targets(void);
+
+#endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/e302582d/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/src/jtag/aice/aice_pipe.c
----------------------------------------------------------------------
diff --git a/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/src/jtag/aice/aice_pipe.c b/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/src/jtag/aice/aice_pipe.c
new file mode 100755
index 0000000..3180ad0
--- /dev/null
+++ b/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/src/jtag/aice/aice_pipe.c
@@ -0,0 +1,895 @@
+/***************************************************************************
+ *   Copyright (C) 2013 by Andes Technology                                *
+ *   Hsiangkai Wang <hk...@andestech.com>                                 *
+ *                                                                         *
+ *   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.,                                       *
+ *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.           *
+ ***************************************************************************/
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#ifdef _WIN32
+#include <windows.h>
+#else
+#include <signal.h>
+#endif
+
+#include <helper/log.h>
+#include <helper/time_support.h>
+#include "aice_port.h"
+#include "aice_pipe.h"
+
+#define AICE_PIPE_MAXLINE 8192
+
+#ifdef _WIN32
+PROCESS_INFORMATION proc_info;
+
+HANDLE aice_pipe_output[2];
+HANDLE aice_pipe_input[2];
+
+static int aice_pipe_write(const void *buffer, int count)
+{
+	BOOL success;
+	DWORD written;
+
+	success = WriteFile(aice_pipe_output[1], buffer, count, &written, NULL);
+	if (!success) {
+		LOG_ERROR("(WIN32) write to pipe failed, error code: 0x%08l" PRIx32, GetLastError());
+		return -1;
+	}
+
+	return written;
+}
+
+static int aice_pipe_read(void *buffer, int count)
+{
+	BOOL success;
+	DWORD has_read;
+
+	success = ReadFile(aice_pipe_input[0], buffer, count, &has_read, NULL);
+	if (!success || (has_read == 0)) {
+		LOG_ERROR("(WIN32) read from pipe failed, error code: 0x%08l" PRIx32, GetLastError());
+		return -1;
+	}
+
+	return has_read;
+}
+
+static int aice_pipe_child_init(struct aice_port_param_s *param)
+{
+	STARTUPINFO start_info;
+	BOOL success;
+
+	ZeroMemory(&proc_info, sizeof(PROCESS_INFORMATION));
+	ZeroMemory(&start_info, sizeof(STARTUPINFO));
+	start_info.cb = sizeof(STARTUPINFO);
+	start_info.hStdError = aice_pipe_input[1];
+	start_info.hStdOutput = aice_pipe_input[1];
+	start_info.hStdInput = aice_pipe_output[0];
+	start_info.dwFlags |= STARTF_USESTDHANDLES;
+
+	success = CreateProcess(NULL,
+			param->adapter_name,
+			NULL,
+			NULL,
+			TRUE,
+			0,
+			NULL,
+			NULL,
+			&start_info,
+			&proc_info);
+
+	if (!success) {
+		LOG_ERROR("Create new process failed");
+		return ERROR_FAIL;
+	}
+
+	return ERROR_OK;
+}
+
+static int aice_pipe_parent_init(struct aice_port_param_s *param)
+{
+	/* send open to adapter */
+	char line[AICE_PIPE_MAXLINE];
+	char command[AICE_PIPE_MAXLINE];
+
+	command[0] = AICE_OPEN;
+	set_u16(command + 1, param->vid);
+	set_u16(command + 3, param->pid);
+
+	if (aice_pipe_write(command, 5) != 5) {
+		LOG_ERROR("write failed\n");
+		return ERROR_FAIL;
+	}
+
+	if (aice_pipe_read(line, AICE_PIPE_MAXLINE) < 0) {
+		LOG_ERROR("read failed\n");
+		return ERROR_FAIL;
+	}
+
+	if (line[0] == AICE_OK)
+		return ERROR_OK;
+	else
+		return ERROR_FAIL;
+}
+
+static int aice_pipe_open(struct aice_port_param_s *param)
+{
+	SECURITY_ATTRIBUTES attribute;
+
+	attribute.nLength = sizeof(SECURITY_ATTRIBUTES);
+	attribute.bInheritHandle = TRUE;
+	attribute.lpSecurityDescriptor = NULL;
+
+	if (!CreatePipe(&aice_pipe_output[0], &aice_pipe_output[1],
+				&attribute, AICE_PIPE_MAXLINE)) {
+		LOG_ERROR("Create pipes failed");
+		return ERROR_FAIL;
+	}
+	if (!CreatePipe(&aice_pipe_input[0], &aice_pipe_input[1],
+				&attribute, AICE_PIPE_MAXLINE)) {
+		LOG_ERROR("Create pipes failed");
+		return ERROR_FAIL;
+	}
+
+	/* do not inherit aice_pipe_output[1] & aice_pipe_input[0] to child process */
+	if (!SetHandleInformation(aice_pipe_output[1], HANDLE_FLAG_INHERIT, 0))
+		return ERROR_FAIL;
+	if (!SetHandleInformation(aice_pipe_input[0], HANDLE_FLAG_INHERIT, 0))
+		return ERROR_FAIL;
+
+	aice_pipe_child_init(param);
+
+	aice_pipe_parent_init(param);
+
+	return ERROR_OK;
+}
+
+#else
+
+int aice_pipe_output[2];
+int aice_pipe_input[2];
+
+static int aice_pipe_write(const void *buffer, int count)
+{
+	if (write(aice_pipe_output[1], buffer, count) != count) {
+		LOG_ERROR("write to pipe failed");
+		return -1;
+	}
+
+	return count;
+}
+
+static int aice_pipe_read(void *buffer, int count)
+{
+	int n;
+	long long then, cur;
+
+	then = timeval_ms();
+
+	while (1) {
+		n = read(aice_pipe_input[0], buffer, count);
+
+		if ((n == -1) && (errno == EAGAIN)) {
+			cur = timeval_ms();
+			if (cur - then > 500)
+				keep_alive();
+			continue;
+		} else if (n > 0)
+			break;
+		else {
+			LOG_ERROR("read from pipe failed");
+			break;
+		}
+	}
+
+	return n;
+}
+
+static int aice_pipe_child_init(struct aice_port_param_s *param)
+{
+	close(aice_pipe_output[1]);
+	close(aice_pipe_input[0]);
+
+	if (aice_pipe_output[0] != STDIN_FILENO) {
+		if (dup2(aice_pipe_output[0], STDIN_FILENO) != STDIN_FILENO) {
+			LOG_ERROR("Map aice_pipe to STDIN failed");
+			return ERROR_FAIL;
+		}
+		close(aice_pipe_output[0]);
+	}
+
+	if (aice_pipe_input[1] != STDOUT_FILENO) {
+		if (dup2(aice_pipe_input[1], STDOUT_FILENO) != STDOUT_FILENO) {
+			LOG_ERROR("Map aice_pipe to STDOUT failed");
+			return ERROR_FAIL;
+		}
+		close(aice_pipe_input[1]);
+	}
+
+	if (execl(param->adapter_name, param->adapter_name, (char *)0) < 0) {
+		LOG_ERROR("Execute aice_pipe failed");
+		return ERROR_FAIL;
+	}
+
+	return ERROR_OK;
+}
+
+static int aice_pipe_parent_init(struct aice_port_param_s *param)
+{
+	close(aice_pipe_output[0]);
+	close(aice_pipe_input[1]);
+
+	/* set read end of pipe as non-blocking */
+	if (fcntl(aice_pipe_input[0], F_SETFL, O_NONBLOCK))
+		return ERROR_FAIL;
+
+	/* send open to adapter */
+	char line[AICE_PIPE_MAXLINE];
+	char command[AICE_PIPE_MAXLINE];
+
+	command[0] = AICE_OPEN;
+	set_u16(command + 1, param->vid);
+	set_u16(command + 3, param->pid);
+
+	if (aice_pipe_write(command, 5) != 5) {
+		LOG_ERROR("write failed\n");
+		return ERROR_FAIL;
+	}
+
+	if (aice_pipe_read(line, AICE_PIPE_MAXLINE) < 0) {
+		LOG_ERROR("read failed\n");
+		return ERROR_FAIL;
+	}
+
+	if (line[0] == AICE_OK)
+		return ERROR_OK;
+	else
+		return ERROR_FAIL;
+}
+
+static void sig_pipe(int signo)
+{
+	exit(1);
+}
+
+static int aice_pipe_open(struct aice_port_param_s *param)
+{
+	pid_t pid;
+
+	if (signal(SIGPIPE, sig_pipe) == SIG_ERR) {
+		LOG_ERROR("Register SIGPIPE handler failed");
+		return ERROR_FAIL;
+	}
+
+	if (pipe(aice_pipe_output) < 0 || pipe(aice_pipe_input) < 0) {
+		LOG_ERROR("Create pipes failed");
+		return ERROR_FAIL;
+	}
+
+	pid = fork();
+	if (pid < 0) {
+		LOG_ERROR("Fork new process failed");
+		return ERROR_FAIL;
+	} else if (pid == 0) {
+		if (aice_pipe_child_init(param) != ERROR_OK) {
+			LOG_ERROR("AICE_PIPE child process initial error");
+			return ERROR_FAIL;
+		} else {
+			if (aice_pipe_parent_init(param) != ERROR_OK) {
+				LOG_ERROR("AICE_PIPE parent process initial error");
+				return ERROR_FAIL;
+			}
+		}
+	}
+
+	return ERROR_OK;
+}
+#endif
+
+static int aice_pipe_close(void)
+{
+	char line[AICE_PIPE_MAXLINE];
+	char command[AICE_PIPE_MAXLINE];
+
+	command[0] = AICE_CLOSE;
+
+	if (aice_pipe_write(command, 1) != 1)
+		return ERROR_FAIL;
+
+	if (aice_pipe_read(line, AICE_PIPE_MAXLINE) < 0)
+		return ERROR_FAIL;
+
+	if (line[0] == AICE_OK) {
+#ifdef _WIN32
+		WaitForSingleObject(proc_info.hProcess, INFINITE);
+		CloseHandle(proc_info.hProcess);
+		CloseHandle(proc_info.hThread);
+#endif
+		return ERROR_OK;
+	} else
+		return ERROR_FAIL;
+}
+
+static int aice_pipe_idcode(uint32_t *idcode, uint8_t *num_of_idcode)
+{
+	char line[AICE_PIPE_MAXLINE];
+	char command[AICE_PIPE_MAXLINE];
+
+	command[0] = AICE_IDCODE;
+
+	if (aice_pipe_write(command, 1) != 1)
+		return ERROR_FAIL;
+
+	if (aice_pipe_read(line, AICE_PIPE_MAXLINE) < 0)
+		return ERROR_FAIL;
+
+	*num_of_idcode = line[0];
+
+	if ((*num_of_idcode == 0) || (*num_of_idcode >= 16))
+		return ERROR_FAIL;
+
+	for (int i = 0 ; i < *num_of_idcode ; i++)
+		idcode[i] = get_u32(line + i * 4 + 1);
+
+	return ERROR_OK;
+}
+
+static int aice_pipe_state(uint32_t coreid, enum aice_target_state_s *state)
+{
+	char line[AICE_PIPE_MAXLINE];
+	char command[AICE_PIPE_MAXLINE];
+
+	command[0] = AICE_STATE;
+
+	if (aice_pipe_write(command, 1) != 1)
+		return ERROR_FAIL;
+
+	if (aice_pipe_read(line, AICE_PIPE_MAXLINE) < 0)
+		return ERROR_FAIL;
+
+	*state = (enum aice_target_state_s)line[0];
+
+	return ERROR_OK;
+}
+
+static int aice_pipe_reset(void)
+{
+	char line[AICE_PIPE_MAXLINE];
+	char command[AICE_PIPE_MAXLINE];
+
+	command[0] = AICE_RESET;
+
+	if (aice_pipe_write(command, 1) != 1)
+		return ERROR_FAIL;
+
+	if (aice_pipe_read(line, AICE_PIPE_MAXLINE) < 0)
+		return ERROR_FAIL;
+
+	if (line[0] == AICE_OK)
+		return ERROR_OK;
+	else
+		return ERROR_FAIL;
+}
+
+static int aice_pipe_assert_srst(uint32_t coreid, enum aice_srst_type_s srst)
+{
+	char line[AICE_PIPE_MAXLINE];
+	char command[AICE_PIPE_MAXLINE];
+
+	command[0] = AICE_ASSERT_SRST;
+	command[1] = srst;
+
+	if (aice_pipe_write(command, 2) != 2)
+		return ERROR_FAIL;
+
+	if (aice_pipe_read(line, AICE_PIPE_MAXLINE) < 0)
+		return ERROR_FAIL;
+
+	if (line[0] == AICE_OK)
+		return ERROR_OK;
+	else
+		return ERROR_FAIL;
+}
+
+static int aice_pipe_run(uint32_t coreid)
+{
+	char line[AICE_PIPE_MAXLINE];
+	char command[AICE_PIPE_MAXLINE];
+
+	command[0] = AICE_RUN;
+
+	if (aice_pipe_write(command, 1) != 1)
+		return ERROR_FAIL;
+
+	if (aice_pipe_read(line, AICE_PIPE_MAXLINE) < 0)
+		return ERROR_FAIL;
+
+	if (line[0] == AICE_OK)
+		return ERROR_OK;
+	else
+		return ERROR_FAIL;
+}
+
+static int aice_pipe_halt(uint32_t coreid)
+{
+	char line[AICE_PIPE_MAXLINE];
+	char command[AICE_PIPE_MAXLINE];
+
+	command[0] = AICE_HALT;
+
+	if (aice_pipe_write(command, 1) != 1)
+		return ERROR_FAIL;
+
+	if (aice_pipe_read(line, AICE_PIPE_MAXLINE) < 0)
+		return ERROR_FAIL;
+
+	if (line[0] == AICE_OK)
+		return ERROR_OK;
+	else
+		return ERROR_FAIL;
+}
+
+static int aice_pipe_read_reg(uint32_t coreid, uint32_t num, uint32_t *val)
+{
+	char line[AICE_PIPE_MAXLINE];
+	char command[AICE_PIPE_MAXLINE];
+
+	command[0] = AICE_READ_REG;
+	set_u32(command + 1, num);
+
+	if (aice_pipe_write(command, 5) != 5)
+		return ERROR_FAIL;
+
+	if (aice_pipe_read(line, AICE_PIPE_MAXLINE) < 0)
+		return ERROR_FAIL;
+
+	*val = get_u32(line);
+
+	return ERROR_OK;
+}
+
+static int aice_pipe_write_reg(uint32_t coreid, uint32_t num, uint32_t val)
+{
+	char line[AICE_PIPE_MAXLINE];
+	char command[AICE_PIPE_MAXLINE];
+
+	command[0] = AICE_WRITE_REG;
+	set_u32(command + 1, num);
+	set_u32(command + 5, val);
+
+	if (aice_pipe_write(command, 9) != 9)
+		return ERROR_FAIL;
+
+	if (aice_pipe_read(line, AICE_PIPE_MAXLINE) < 0)
+		return ERROR_FAIL;
+
+	if (line[0] == AICE_OK)
+		return ERROR_OK;
+	else
+		return ERROR_FAIL;
+}
+
+static int aice_pipe_read_reg_64(uint32_t coreid, uint32_t num, uint64_t *val)
+{
+	char line[AICE_PIPE_MAXLINE];
+	char command[AICE_PIPE_MAXLINE];
+
+	command[0] = AICE_READ_REG_64;
+	set_u32(command + 1, num);
+
+	if (aice_pipe_write(command, 5) != 5)
+		return ERROR_FAIL;
+
+	if (aice_pipe_read(line, AICE_PIPE_MAXLINE) < 0)
+		return ERROR_FAIL;
+
+	*val = (((uint64_t)get_u32(line + 4)) << 32) | get_u32(line);
+
+	return ERROR_OK;
+}
+
+static int aice_pipe_write_reg_64(uint32_t coreid, uint32_t num, uint64_t val)
+{
+	char line[AICE_PIPE_MAXLINE];
+	char command[AICE_PIPE_MAXLINE];
+
+	command[0] = AICE_WRITE_REG_64;
+	set_u32(command + 1, num);
+	set_u32(command + 5, val & 0xFFFFFFFF);
+	set_u32(command + 9, (val >> 32) & 0xFFFFFFFF);
+
+	if (aice_pipe_write(command, 13) != 9)
+		return ERROR_FAIL;
+
+	if (aice_pipe_read(line, AICE_PIPE_MAXLINE) < 0)
+		return ERROR_FAIL;
+
+	if (line[0] == AICE_OK)
+		return ERROR_OK;
+	else
+		return ERROR_FAIL;
+}
+
+static int aice_pipe_step(uint32_t coreid)
+{
+	char line[AICE_PIPE_MAXLINE];
+	char command[AICE_PIPE_MAXLINE];
+
+	command[0] = AICE_STEP;
+
+	if (aice_pipe_write(command, 1) != 1)
+		return ERROR_FAIL;
+
+	if (aice_pipe_read(line, AICE_PIPE_MAXLINE) < 0)
+		return ERROR_FAIL;
+
+	if (line[0] == AICE_OK)
+		return ERROR_OK;
+	else
+		return ERROR_FAIL;
+}
+
+static int aice_pipe_read_mem_unit(uint32_t coreid, uint32_t addr, uint32_t size,
+		uint32_t count, uint8_t *buffer)
+{
+	char command[AICE_PIPE_MAXLINE];
+
+	command[0] = AICE_READ_MEM_UNIT;
+	set_u32(command + 1, addr);
+	set_u32(command + 5, size);
+	set_u32(command + 9, count);
+
+	if (aice_pipe_write(command, 13) != 13)
+		return ERROR_FAIL;
+
+	if (aice_pipe_read(buffer, size * count) < 0)
+		return ERROR_FAIL;
+
+	return ERROR_OK;
+}
+
+static int aice_pipe_write_mem_unit(uint32_t coreid, uint32_t addr, uint32_t size,
+		uint32_t count, const uint8_t *buffer)
+{
+	char line[AICE_PIPE_MAXLINE];
+	char command[AICE_PIPE_MAXLINE];
+
+	command[0] = AICE_WRITE_MEM_UNIT;
+	set_u32(command + 1, addr);
+	set_u32(command + 5, size);
+	set_u32(command + 9, count);
+
+	/* WRITE_MEM_UNIT|addr|size|count|data */
+	memcpy(command + 13, buffer, size * count);
+
+	if (aice_pipe_write(command, 13 + size * count) < 0)
+		return ERROR_FAIL;
+
+	if (aice_pipe_read(line, AICE_PIPE_MAXLINE) < 0)
+		return ERROR_FAIL;
+
+	if (line[0] == AICE_OK)
+		return ERROR_OK;
+	else
+		return ERROR_FAIL;
+
+	return ERROR_OK;
+}
+
+static int aice_pipe_read_mem_bulk(uint32_t coreid, uint32_t addr,
+		uint32_t length, uint8_t *buffer)
+{
+	char line[AICE_PIPE_MAXLINE + 1];
+	char command[AICE_PIPE_MAXLINE];
+	uint32_t remain_len = length;
+	uint32_t prepare_len;
+	char *received_line;
+	uint32_t received_len;
+	int read_len;
+
+	command[0] = AICE_READ_MEM_BULK;
+	set_u32(command + 1, addr);
+	set_u32(command + 5, length);
+
+	if (aice_pipe_write(command, 9) < 0)
+		return ERROR_FAIL;
+
+	while (remain_len > 0) {
+		if (remain_len > AICE_PIPE_MAXLINE)
+			prepare_len = AICE_PIPE_MAXLINE;
+		else
+			prepare_len = remain_len;
+
+		prepare_len++;
+		received_len = 0;
+		received_line = line;
+		do {
+			read_len = aice_pipe_read(received_line, prepare_len - received_len);
+			if (read_len < 0)
+				return ERROR_FAIL;
+			received_line += read_len;
+			received_len += read_len;
+		} while (received_len < prepare_len);
+
+		if (line[0] != AICE_OK)
+			return ERROR_FAIL;
+
+		prepare_len--;
+		memcpy(buffer, line + 1, prepare_len);
+		remain_len -= prepare_len;
+		buffer += prepare_len;
+	}
+
+	return ERROR_OK;
+}
+
+static int aice_pipe_write_mem_bulk(uint32_t coreid, uint32_t addr,
+		uint32_t length, const uint8_t *buffer)
+{
+	char line[AICE_PIPE_MAXLINE];
+	char command[AICE_PIPE_MAXLINE + 4];
+	uint32_t remain_len = length;
+	uint32_t written_len = 0;
+	uint32_t write_len;
+
+	command[0] = AICE_WRITE_MEM_BULK;
+	set_u32(command + 1, addr);
+	set_u32(command + 5, length);
+
+	/* Send command first */
+	if (aice_pipe_write(command, 9) < 0)
+		return ERROR_FAIL;
+
+	if (aice_pipe_read(line, AICE_PIPE_MAXLINE) < 0)
+		return ERROR_FAIL;
+
+	if (line[0] == AICE_ERROR)
+		return ERROR_FAIL;
+
+	while (remain_len > 0) {
+		if (remain_len > AICE_PIPE_MAXLINE)
+			write_len = AICE_PIPE_MAXLINE;
+		else
+			write_len = remain_len;
+
+		set_u32(command, write_len);
+		memcpy(command + 4, buffer + written_len, write_len); /* data only */
+
+		if (aice_pipe_write(command, write_len + 4) < 0)
+			return ERROR_FAIL;
+
+		if (aice_pipe_read(line, AICE_PIPE_MAXLINE) < 0)
+			return ERROR_FAIL;
+
+		if (line[0] == AICE_ERROR)
+			return ERROR_FAIL;
+
+		remain_len -= write_len;
+		written_len += write_len;
+	}
+
+	if (line[0] == AICE_OK)
+		return ERROR_OK;
+	else
+		return ERROR_FAIL;
+}
+
+static int aice_pipe_read_debug_reg(uint32_t coreid, uint32_t addr, uint32_t *val)
+{
+	char line[AICE_PIPE_MAXLINE];
+	char command[AICE_PIPE_MAXLINE];
+
+	command[0] = AICE_READ_DEBUG_REG;
+	set_u32(command + 1, addr);
+
+	if (aice_pipe_write(command, 5) != 5)
+		return ERROR_FAIL;
+
+	if (aice_pipe_read(line, AICE_PIPE_MAXLINE) < 0)
+		return ERROR_FAIL;
+
+	*val = get_u32(line);
+
+	return ERROR_OK;
+}
+
+static int aice_pipe_write_debug_reg(uint32_t coreid, uint32_t addr, const uint32_t val)
+{
+	char line[AICE_PIPE_MAXLINE];
+	char command[AICE_PIPE_MAXLINE];
+
+	command[0] = AICE_WRITE_DEBUG_REG;
+	set_u32(command + 1, addr);
+	set_u32(command + 5, val);
+
+	if (aice_pipe_write(command, 9) != 9)
+		return ERROR_FAIL;
+
+	if (aice_pipe_read(line, AICE_PIPE_MAXLINE) < 0)
+		return ERROR_FAIL;
+
+	if (line[0] == AICE_OK)
+		return ERROR_OK;
+	else
+		return ERROR_FAIL;
+}
+
+static int aice_pipe_set_jtag_clock(uint32_t a_clock)
+{
+	char line[AICE_PIPE_MAXLINE];
+	char command[AICE_PIPE_MAXLINE];
+
+	command[0] = AICE_SET_JTAG_CLOCK;
+	set_u32(command + 1, a_clock);
+
+	if (aice_pipe_write(command, 5) != 5)
+		return ERROR_FAIL;
+
+	if (aice_pipe_read(line, AICE_PIPE_MAXLINE) < 0)
+		return ERROR_FAIL;
+
+	if (line[0] == AICE_OK)
+		return ERROR_OK;
+	else
+		return ERROR_FAIL;
+}
+
+static int aice_pipe_memory_access(uint32_t coreid, enum nds_memory_access access_channel)
+{
+	char line[AICE_PIPE_MAXLINE];
+	char command[AICE_PIPE_MAXLINE];
+
+	command[0] = AICE_MEMORY_ACCESS;
+	set_u32(command + 1, access_channel);
+
+	if (aice_pipe_write(command, 5) != 5)
+		return ERROR_FAIL;
+
+	if (aice_pipe_read(line, AICE_PIPE_MAXLINE) < 0)
+		return ERROR_FAIL;
+
+	if (line[0] == AICE_OK)
+		return ERROR_OK;
+	else
+		return ERROR_FAIL;
+}
+
+static int aice_pipe_memory_mode(uint32_t coreid, enum nds_memory_select mem_select)
+{
+	char line[AICE_PIPE_MAXLINE];
+	char command[AICE_PIPE_MAXLINE];
+
+	command[0] = AICE_MEMORY_MODE;
+	set_u32(command + 1, mem_select);
+
+	if (aice_pipe_write(command, 5) != 5)
+		return ERROR_FAIL;
+
+	if (aice_pipe_read(line, AICE_PIPE_MAXLINE) < 0)
+		return ERROR_FAIL;
+
+	if (line[0] == AICE_OK)
+		return ERROR_OK;
+	else
+		return ERROR_FAIL;
+}
+
+static int aice_pipe_read_tlb(uint32_t coreid, uint32_t virtual_address,
+		uint32_t *physical_address)
+{
+	char line[AICE_PIPE_MAXLINE];
+	char command[AICE_PIPE_MAXLINE];
+
+	command[0] = AICE_READ_TLB;
+	set_u32(command + 1, virtual_address);
+
+	if (aice_pipe_write(command, 5) != 5)
+		return ERROR_FAIL;
+
+	if (aice_pipe_read(line, AICE_PIPE_MAXLINE) < 0)
+		return ERROR_FAIL;
+
+	if (line[0] == AICE_OK) {
+		*physical_address = get_u32(line + 1);
+		return ERROR_OK;
+	} else
+		return ERROR_FAIL;
+}
+
+static int aice_pipe_cache_ctl(uint32_t coreid, uint32_t subtype, uint32_t address)
+{
+	char line[AICE_PIPE_MAXLINE];
+	char command[AICE_PIPE_MAXLINE];
+
+	command[0] = AICE_CACHE_CTL;
+	set_u32(command + 1, subtype);
+	set_u32(command + 5, address);
+
+	if (aice_pipe_write(command, 9) != 9)
+		return ERROR_FAIL;
+
+	if (aice_pipe_read(line, AICE_PIPE_MAXLINE) < 0)
+		return ERROR_FAIL;
+
+	if (line[0] == AICE_OK)
+		return ERROR_OK;
+	else
+		return ERROR_FAIL;
+}
+
+static int aice_pipe_set_retry_times(uint32_t a_retry_times)
+{
+	return ERROR_OK;
+}
+
+/** */
+struct aice_port_api_s aice_pipe = {
+	/** */
+	.open = aice_pipe_open,
+	/** */
+	.close = aice_pipe_close,
+	/** */
+	.idcode = aice_pipe_idcode,
+	/** */
+	.set_jtag_clock = aice_pipe_set_jtag_clock,
+	/** */
+	.state = aice_pipe_state,
+	/** */
+	.reset = aice_pipe_reset,
+	/** */
+	.assert_srst = aice_pipe_assert_srst,
+	/** */
+	.run = aice_pipe_run,
+	/** */
+	.halt = aice_pipe_halt,
+	/** */
+	.step = aice_pipe_step,
+	/** */
+	.read_reg = aice_pipe_read_reg,
+	/** */
+	.write_reg = aice_pipe_write_reg,
+	/** */
+	.read_reg_64 = aice_pipe_read_reg_64,
+	/** */
+	.write_reg_64 = aice_pipe_write_reg_64,
+	/** */
+	.read_mem_unit = aice_pipe_read_mem_unit,
+	/** */
+	.write_mem_unit = aice_pipe_write_mem_unit,
+	/** */
+	.read_mem_bulk = aice_pipe_read_mem_bulk,
+	/** */
+	.write_mem_bulk = aice_pipe_write_mem_bulk,
+	/** */
+	.read_debug_reg = aice_pipe_read_debug_reg,
+	/** */
+	.write_debug_reg = aice_pipe_write_debug_reg,
+
+	/** */
+	.memory_access = aice_pipe_memory_access,
+	/** */
+	.memory_mode = aice_pipe_memory_mode,
+
+	/** */
+	.read_tlb = aice_pipe_read_tlb,
+
+	/** */
+	.cache_ctl = aice_pipe_cache_ctl,
+
+	/** */
+	.set_retry_times = aice_pipe_set_retry_times,
+};

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/e302582d/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/src/jtag/aice/aice_pipe.h
----------------------------------------------------------------------
diff --git a/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/src/jtag/aice/aice_pipe.h b/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/src/jtag/aice/aice_pipe.h
new file mode 100755
index 0000000..48b0c49
--- /dev/null
+++ b/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/src/jtag/aice/aice_pipe.h
@@ -0,0 +1,32 @@
+/***************************************************************************
+ *   Copyright (C) 2013 by Andes Technology                                *
+ *   Hsiangkai Wang <hk...@andestech.com>                                 *
+ *                                                                         *
+ *   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.,                                       *
+ *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.           *
+ ***************************************************************************/
+#ifndef _AICE_PIPE_H_
+#define _AICE_PIPE_H_
+
+#include <helper/types.h>
+
+#define set_u32(buffer, value) h_u32_to_le((uint8_t *)buffer, value)
+#define set_u16(buffer, value) h_u16_to_le((uint8_t *)buffer, value)
+#define get_u32(buffer) le_to_h_u32((const uint8_t *)buffer)
+#define get_u16(buffer) le_to_h_u16((const uint8_t *)buffer)
+
+extern struct aice_port_api_s aice_pipe;
+
+#endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/e302582d/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/src/jtag/aice/aice_port.c
----------------------------------------------------------------------
diff --git a/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/src/jtag/aice/aice_port.c b/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/src/jtag/aice/aice_port.c
new file mode 100755
index 0000000..b61275c
--- /dev/null
+++ b/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/src/jtag/aice/aice_port.c
@@ -0,0 +1,47 @@
+/***************************************************************************
+ *   Copyright (C) 2013 by Andes Technology                                *
+ *   Hsiangkai Wang <hk...@andestech.com>                                 *
+ *                                                                         *
+ *   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.,                                       *
+ *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.           *
+ ***************************************************************************/
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <helper/log.h>
+#include "aice_usb.h"
+#include "aice_pipe.h"
+#include "aice_port.h"
+
+static const struct aice_port aice_ports[] = {
+	{
+		.name = "aice_usb",
+		.type = AICE_PORT_AICE_USB,
+		.api = &aice_usb_api,
+	},
+	{
+		.name = "aice_pipe",
+		.type = AICE_PORT_AICE_PIPE,
+		.api = &aice_pipe,
+	},
+	{.name = NULL, /* END OF TABLE */ },
+};
+
+/** */
+const struct aice_port *aice_port_get_list(void)
+{
+	return aice_ports;
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/e302582d/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/src/jtag/aice/aice_port.h
----------------------------------------------------------------------
diff --git a/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/src/jtag/aice/aice_port.h b/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/src/jtag/aice/aice_port.h
new file mode 100755
index 0000000..d29e9e1
--- /dev/null
+++ b/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/src/jtag/aice/aice_port.h
@@ -0,0 +1,238 @@
+/***************************************************************************
+ *   Copyright (C) 2013 by Andes Technology                                *
+ *   Hsiangkai Wang <hk...@andestech.com>                                 *
+ *                                                                         *
+ *   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.,                                       *
+ *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.           *
+ ***************************************************************************/
+#ifndef _AICE_PORT_H_
+#define _AICE_PORT_H_
+
+#include <target/nds32_edm.h>
+
+#define AICE_MAX_NUM_CORE      (0x10)
+
+#define ERROR_AICE_DISCONNECT  (-200)
+#define ERROR_AICE_TIMEOUT     (-201)
+
+enum aice_target_state_s {
+	AICE_DISCONNECT = 0,
+	AICE_TARGET_DETACH,
+	AICE_TARGET_UNKNOWN,
+	AICE_TARGET_RUNNING,
+	AICE_TARGET_HALTED,
+	AICE_TARGET_RESET,
+	AICE_TARGET_DEBUG_RUNNING,
+};
+
+enum aice_srst_type_s {
+	AICE_SRST = 0x1,
+	AICE_RESET_HOLD = 0x8,
+};
+
+enum aice_target_endian {
+	AICE_LITTLE_ENDIAN = 0,
+	AICE_BIG_ENDIAN,
+};
+
+enum aice_api_s {
+	AICE_OPEN = 0x0,
+	AICE_CLOSE,
+	AICE_RESET,
+	AICE_IDCODE,
+	AICE_SET_JTAG_CLOCK,
+	AICE_ASSERT_SRST,
+	AICE_RUN,
+	AICE_HALT,
+	AICE_STEP,
+	AICE_READ_REG,
+	AICE_WRITE_REG,
+	AICE_READ_REG_64,
+	AICE_WRITE_REG_64,
+	AICE_READ_MEM_UNIT,
+	AICE_WRITE_MEM_UNIT,
+	AICE_READ_MEM_BULK,
+	AICE_WRITE_MEM_BULK,
+	AICE_READ_DEBUG_REG,
+	AICE_WRITE_DEBUG_REG,
+	AICE_STATE,
+	AICE_MEMORY_ACCESS,
+	AICE_MEMORY_MODE,
+	AICE_READ_TLB,
+	AICE_CACHE_CTL,
+	AICE_SET_RETRY_TIMES,
+	AICE_PROGRAM_EDM,
+	AICE_SET_COMMAND_MODE,
+	AICE_EXECUTE,
+	AICE_SET_CUSTOM_SRST_SCRIPT,
+	AICE_SET_CUSTOM_TRST_SCRIPT,
+	AICE_SET_CUSTOM_RESTART_SCRIPT,
+	AICE_SET_COUNT_TO_CHECK_DBGER,
+	AICE_SET_DATA_ENDIAN,
+};
+
+enum aice_error_s {
+	AICE_OK,
+	AICE_ACK,
+	AICE_ERROR,
+};
+
+enum aice_cache_ctl_type {
+	AICE_CACHE_CTL_L1D_INVALALL = 0,
+	AICE_CACHE_CTL_L1D_VA_INVAL,
+	AICE_CACHE_CTL_L1D_WBALL,
+	AICE_CACHE_CTL_L1D_VA_WB,
+	AICE_CACHE_CTL_L1I_INVALALL,
+	AICE_CACHE_CTL_L1I_VA_INVAL,
+};
+
+enum aice_command_mode {
+	AICE_COMMAND_MODE_NORMAL,
+	AICE_COMMAND_MODE_PACK,
+	AICE_COMMAND_MODE_BATCH,
+};
+
+struct aice_port_param_s {
+	/** */
+	const char *device_desc;
+	/** */
+	const char *serial;
+	/** */
+	uint16_t vid;
+	/** */
+	uint16_t pid;
+	/** */
+	char *adapter_name;
+};
+
+struct aice_port_s {
+	/** */
+	uint32_t coreid;
+	/** */
+	const struct aice_port *port;
+};
+
+/** */
+extern struct aice_port_api_s aice_usb_layout_api;
+
+/** */
+struct aice_port_api_s {
+	/** */
+	int (*open)(struct aice_port_param_s *param);
+	/** */
+	int (*close)(void);
+	/** */
+	int (*reset)(void);
+	/** */
+	int (*idcode)(uint32_t *idcode, uint8_t *num_of_idcode);
+	/** */
+	int (*set_jtag_clock)(uint32_t a_clock);
+	/** */
+	int (*assert_srst)(uint32_t coreid, enum aice_srst_type_s srst);
+	/** */
+	int (*run)(uint32_t coreid);
+	/** */
+	int (*halt)(uint32_t coreid);
+	/** */
+	int (*step)(uint32_t coreid);
+	/** */
+	int (*read_reg)(uint32_t coreid, uint32_t num, uint32_t *val);
+	/** */
+	int (*write_reg)(uint32_t coreid, uint32_t num, uint32_t val);
+	/** */
+	int (*read_reg_64)(uint32_t coreid, uint32_t num, uint64_t *val);
+	/** */
+	int (*write_reg_64)(uint32_t coreid, uint32_t num, uint64_t val);
+	/** */
+	int (*read_mem_unit)(uint32_t coreid, uint32_t addr, uint32_t size,
+			uint32_t count, uint8_t *buffer);
+	/** */
+	int (*write_mem_unit)(uint32_t coreid, uint32_t addr, uint32_t size,
+			uint32_t count, const uint8_t *buffer);
+	/** */
+	int (*read_mem_bulk)(uint32_t coreid, uint32_t addr, uint32_t length,
+			uint8_t *buffer);
+	/** */
+	int (*write_mem_bulk)(uint32_t coreid, uint32_t addr, uint32_t length,
+			const uint8_t *buffer);
+	/** */
+	int (*read_debug_reg)(uint32_t coreid, uint32_t addr, uint32_t *val);
+	/** */
+	int (*write_debug_reg)(uint32_t coreid, uint32_t addr, const uint32_t val);
+
+	/** */
+	int (*state)(uint32_t coreid, enum aice_target_state_s *state);
+
+	/** */
+	int (*memory_access)(uint32_t coreid, enum nds_memory_access a_access);
+	/** */
+	int (*memory_mode)(uint32_t coreid, enum nds_memory_select mem_select);
+
+	/** */
+	int (*read_tlb)(uint32_t coreid, uint32_t virtual_address, uint32_t *physical_address);
+
+	/** */
+	int (*cache_ctl)(uint32_t coreid, uint32_t subtype, uint32_t address);
+
+	/** */
+	int (*set_retry_times)(uint32_t a_retry_times);
+
+	/** */
+	int (*program_edm)(uint32_t coreid, char *command_sequence);
+
+	/** */
+	int (*set_command_mode)(enum aice_command_mode command_mode);
+
+	/** */
+	int (*execute)(uint32_t coreid, uint32_t *instructions, uint32_t instruction_num);
+
+	/** */
+	int (*set_custom_srst_script)(const char *script);
+
+	/** */
+	int (*set_custom_trst_script)(const char *script);
+
+	/** */
+	int (*set_custom_restart_script)(const char *script);
+
+	/** */
+	int (*set_count_to_check_dbger)(uint32_t count_to_check);
+
+	/** */
+	int (*set_data_endian)(uint32_t coreid, enum aice_target_endian target_data_endian);
+
+	/** */
+	int (*profiling)(uint32_t coreid, uint32_t interval, uint32_t iteration,
+		uint32_t reg_no, uint32_t *samples, uint32_t *num_samples);
+};
+
+#define AICE_PORT_UNKNOWN	0
+#define AICE_PORT_AICE_USB	1
+#define AICE_PORT_AICE_PIPE	2
+
+/** */
+struct aice_port {
+	/** */
+	const char *name;
+	/** */
+	int type;
+	/** */
+	struct aice_port_api_s *const api;
+};
+
+/** */
+const struct aice_port *aice_port_get_list(void);
+
+#endif