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:52 UTC
[09/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/list.h
----------------------------------------------------------------------
diff --git a/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/src/helper/list.h b/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/src/helper/list.h
new file mode 100755
index 0000000..302b910
--- /dev/null
+++ b/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/src/helper/list.h
@@ -0,0 +1,737 @@
+#ifndef _LINUX_LIST_H
+#define _LINUX_LIST_H
+
+/* begin local changes */
+#include <helper/types.h>
+
+#define prefetch(x) ((void)x)
+#define LIST_POISON1 NULL
+#define LIST_POISON2 NULL
+
+struct list_head {
+ struct list_head *next, *prev;
+};
+struct hlist_head {
+ struct hlist_node *first;
+};
+struct hlist_node {
+ struct hlist_node *next, **pprev;
+};
+/* end local changes */
+
+/*
+ * Simple doubly linked list implementation.
+ *
+ * Some of the internal functions ("__xxx") are useful when
+ * manipulating whole lists rather than single entries, as
+ * sometimes we already know the next/prev entries and we can
+ * generate better code by using them directly rather than
+ * using the generic single-entry routines.
+ */
+
+#define LIST_HEAD_INIT(name) { &(name), &(name) }
+
+#define LIST_HEAD(name) \
+ struct list_head name = LIST_HEAD_INIT(name)
+
+static inline void INIT_LIST_HEAD(struct list_head *list)
+{
+ list->next = list;
+ list->prev = list;
+}
+
+/*
+ * Insert a new entry between two known consecutive entries.
+ *
+ * This is only for internal list manipulation where we know
+ * the prev/next entries already!
+ */
+#ifndef CONFIG_DEBUG_LIST
+static inline void __list_add(struct list_head *new,
+ struct list_head *prev,
+ struct list_head *next)
+{
+ next->prev = new;
+ new->next = next;
+ new->prev = prev;
+ prev->next = new;
+}
+#else
+extern void __list_add(struct list_head *new,
+ struct list_head *prev,
+ struct list_head *next);
+#endif
+
+/**
+ * list_add - add a new entry
+ * @new: new entry to be added
+ * @head: list head to add it after
+ *
+ * Insert a new entry after the specified head.
+ * This is good for implementing stacks.
+ */
+static inline void list_add(struct list_head *new, struct list_head *head)
+{
+ __list_add(new, head, head->next);
+}
+
+
+/**
+ * list_add_tail - add a new entry
+ * @new: new entry to be added
+ * @head: list head to add it before
+ *
+ * Insert a new entry before the specified head.
+ * This is useful for implementing queues.
+ */
+static inline void list_add_tail(struct list_head *new, struct list_head *head)
+{
+ __list_add(new, head->prev, head);
+}
+
+/*
+ * Delete a list entry by making the prev/next entries
+ * point to each other.
+ *
+ * This is only for internal list manipulation where we know
+ * the prev/next entries already!
+ */
+static inline void __list_del(struct list_head *prev, struct list_head *next)
+{
+ next->prev = prev;
+ prev->next = next;
+}
+
+/**
+ * list_del - deletes entry from list.
+ * @entry: the element to delete from the list.
+ * Note: list_empty() on entry does not return true after this, the entry is
+ * in an undefined state.
+ */
+#ifndef CONFIG_DEBUG_LIST
+static inline void __list_del_entry(struct list_head *entry)
+{
+ __list_del(entry->prev, entry->next);
+}
+
+static inline void list_del(struct list_head *entry)
+{
+ __list_del(entry->prev, entry->next);
+ entry->next = LIST_POISON1;
+ entry->prev = LIST_POISON2;
+}
+#else
+extern void __list_del_entry(struct list_head *entry);
+extern void list_del(struct list_head *entry);
+#endif
+
+/**
+ * list_replace - replace old entry by new one
+ * @old : the element to be replaced
+ * @new : the new element to insert
+ *
+ * If @old was empty, it will be overwritten.
+ */
+static inline void list_replace(struct list_head *old,
+ struct list_head *new)
+{
+ new->next = old->next;
+ new->next->prev = new;
+ new->prev = old->prev;
+ new->prev->next = new;
+}
+
+static inline void list_replace_init(struct list_head *old,
+ struct list_head *new)
+{
+ list_replace(old, new);
+ INIT_LIST_HEAD(old);
+}
+
+/**
+ * list_del_init - deletes entry from list and reinitialize it.
+ * @entry: the element to delete from the list.
+ */
+static inline void list_del_init(struct list_head *entry)
+{
+ __list_del_entry(entry);
+ INIT_LIST_HEAD(entry);
+}
+
+/**
+ * list_move - delete from one list and add as another's head
+ * @list: the entry to move
+ * @head: the head that will precede our entry
+ */
+static inline void list_move(struct list_head *list, struct list_head *head)
+{
+ __list_del_entry(list);
+ list_add(list, head);
+}
+
+/**
+ * list_move_tail - delete from one list and add as another's tail
+ * @list: the entry to move
+ * @head: the head that will follow our entry
+ */
+static inline void list_move_tail(struct list_head *list,
+ struct list_head *head)
+{
+ __list_del_entry(list);
+ list_add_tail(list, head);
+}
+
+/**
+ * list_is_last - tests whether @list is the last entry in list @head
+ * @list: the entry to test
+ * @head: the head of the list
+ */
+static inline int list_is_last(const struct list_head *list,
+ const struct list_head *head)
+{
+ return list->next == head;
+}
+
+/**
+ * list_empty - tests whether a list is empty
+ * @head: the list to test.
+ */
+static inline int list_empty(const struct list_head *head)
+{
+ return head->next == head;
+}
+
+/**
+ * list_empty_careful - tests whether a list is empty and not being modified
+ * @head: the list to test
+ *
+ * Description:
+ * tests whether a list is empty _and_ checks that no other CPU might be
+ * in the process of modifying either member (next or prev)
+ *
+ * NOTE: using list_empty_careful() without synchronization
+ * can only be safe if the only activity that can happen
+ * to the list entry is list_del_init(). Eg. it cannot be used
+ * if another CPU could re-list_add() it.
+ */
+static inline int list_empty_careful(const struct list_head *head)
+{
+ struct list_head *next = head->next;
+ return (next == head) && (next == head->prev);
+}
+
+/**
+ * list_rotate_left - rotate the list to the left
+ * @head: the head of the list
+ */
+static inline void list_rotate_left(struct list_head *head)
+{
+ struct list_head *first;
+
+ if (!list_empty(head)) {
+ first = head->next;
+ list_move_tail(first, head);
+ }
+}
+
+/**
+ * list_is_singular - tests whether a list has just one entry.
+ * @head: the list to test.
+ */
+static inline int list_is_singular(const struct list_head *head)
+{
+ return !list_empty(head) && (head->next == head->prev);
+}
+
+static inline void __list_cut_position(struct list_head *list,
+ struct list_head *head, struct list_head *entry)
+{
+ struct list_head *new_first = entry->next;
+ list->next = head->next;
+ list->next->prev = list;
+ list->prev = entry;
+ entry->next = list;
+ head->next = new_first;
+ new_first->prev = head;
+}
+
+/**
+ * list_cut_position - cut a list into two
+ * @list: a new list to add all removed entries
+ * @head: a list with entries
+ * @entry: an entry within head, could be the head itself
+ * and if so we won't cut the list
+ *
+ * This helper moves the initial part of @head, up to and
+ * including @entry, from @head to @list. You should
+ * pass on @entry an element you know is on @head. @list
+ * should be an empty list or a list you do not care about
+ * losing its data.
+ *
+ */
+static inline void list_cut_position(struct list_head *list,
+ struct list_head *head, struct list_head *entry)
+{
+ if (list_empty(head))
+ return;
+ if (list_is_singular(head) &&
+ (head->next != entry && head != entry))
+ return;
+ if (entry == head)
+ INIT_LIST_HEAD(list);
+ else
+ __list_cut_position(list, head, entry);
+}
+
+static inline void __list_splice(const struct list_head *list,
+ struct list_head *prev,
+ struct list_head *next)
+{
+ struct list_head *first = list->next;
+ struct list_head *last = list->prev;
+
+ first->prev = prev;
+ prev->next = first;
+
+ last->next = next;
+ next->prev = last;
+}
+
+/**
+ * list_splice - join two lists, this is designed for stacks
+ * @list: the new list to add.
+ * @head: the place to add it in the first list.
+ */
+static inline void list_splice(const struct list_head *list,
+ struct list_head *head)
+{
+ if (!list_empty(list))
+ __list_splice(list, head, head->next);
+}
+
+/**
+ * list_splice_tail - join two lists, each list being a queue
+ * @list: the new list to add.
+ * @head: the place to add it in the first list.
+ */
+static inline void list_splice_tail(struct list_head *list,
+ struct list_head *head)
+{
+ if (!list_empty(list))
+ __list_splice(list, head->prev, head);
+}
+
+/**
+ * list_splice_init - join two lists and reinitialise the emptied list.
+ * @list: the new list to add.
+ * @head: the place to add it in the first list.
+ *
+ * The list at @list is reinitialised
+ */
+static inline void list_splice_init(struct list_head *list,
+ struct list_head *head)
+{
+ if (!list_empty(list)) {
+ __list_splice(list, head, head->next);
+ INIT_LIST_HEAD(list);
+ }
+}
+
+/**
+ * list_splice_tail_init - join two lists and reinitialise the emptied list
+ * @list: the new list to add.
+ * @head: the place to add it in the first list.
+ *
+ * Each of the lists is a queue.
+ * The list at @list is reinitialised
+ */
+static inline void list_splice_tail_init(struct list_head *list,
+ struct list_head *head)
+{
+ if (!list_empty(list)) {
+ __list_splice(list, head->prev, head);
+ INIT_LIST_HEAD(list);
+ }
+}
+
+/**
+ * list_entry - get the struct for this entry
+ * @ptr: the &struct list_head pointer.
+ * @type: the type of the struct this is embedded in.
+ * @member: the name of the list_struct within the struct.
+ */
+#define list_entry(ptr, type, member) \
+ container_of(ptr, type, member)
+
+/**
+ * list_first_entry - get the first element from a list
+ * @ptr: the list head to take the element from.
+ * @type: the type of the struct this is embedded in.
+ * @member: the name of the list_struct within the struct.
+ *
+ * Note, that list is expected to be not empty.
+ */
+#define list_first_entry(ptr, type, member) \
+ list_entry((ptr)->next, type, member)
+
+/**
+ * list_for_each - iterate over a list
+ * @pos: the &struct list_head to use as a loop cursor.
+ * @head: the head for your list.
+ */
+#define list_for_each(pos, head) \
+ for (pos = (head)->next; prefetch(pos->next), pos != (head); \
+ pos = pos->next)
+
+/**
+ * __list_for_each - iterate over a list
+ * @pos: the &struct list_head to use as a loop cursor.
+ * @head: the head for your list.
+ *
+ * This variant differs from list_for_each() in that it's the
+ * simplest possible list iteration code, no prefetching is done.
+ * Use this for code that knows the list to be very short (empty
+ * or 1 entry) most of the time.
+ */
+#define __list_for_each(pos, head) \
+ for (pos = (head)->next; pos != (head); pos = pos->next)
+
+/**
+ * list_for_each_prev - iterate over a list backwards
+ * @pos: the &struct list_head to use as a loop cursor.
+ * @head: the head for your list.
+ */
+#define list_for_each_prev(pos, head) \
+ for (pos = (head)->prev; prefetch(pos->prev), pos != (head); \
+ pos = pos->prev)
+
+/**
+ * list_for_each_safe - iterate over a list safe against removal of list entry
+ * @pos: the &struct list_head to use as a loop cursor.
+ * @n: another &struct list_head to use as temporary storage
+ * @head: the head for your list.
+ */
+#define list_for_each_safe(pos, n, head) \
+ for (pos = (head)->next, n = pos->next; pos != (head); \
+ pos = n, n = pos->next)
+
+/**
+ * list_for_each_prev_safe - iterate over a list backwards safe against removal of list entry
+ * @pos: the &struct list_head to use as a loop cursor.
+ * @n: another &struct list_head to use as temporary storage
+ * @head: the head for your list.
+ */
+#define list_for_each_prev_safe(pos, n, head) \
+ for (pos = (head)->prev, n = pos->prev; \
+ prefetch(pos->prev), pos != (head); \
+ pos = n, n = pos->prev)
+
+/**
+ * list_for_each_entry - iterate over list of given type
+ * @pos: the type * to use as a loop cursor.
+ * @head: the head for your list.
+ * @member: the name of the list_struct within the struct.
+ */
+#define list_for_each_entry(pos, head, member) \
+ for (pos = list_entry((head)->next, typeof(*pos), member); \
+ prefetch(pos->member.next), &pos->member != (head); \
+ pos = list_entry(pos->member.next, typeof(*pos), member))
+
+/**
+ * list_for_each_entry_reverse - iterate backwards over list of given type.
+ * @pos: the type * to use as a loop cursor.
+ * @head: the head for your list.
+ * @member: the name of the list_struct within the struct.
+ */
+#define list_for_each_entry_reverse(pos, head, member) \
+ for (pos = list_entry((head)->prev, typeof(*pos), member); \
+ prefetch(pos->member.prev), &pos->member != (head); \
+ pos = list_entry(pos->member.prev, typeof(*pos), member))
+
+/**
+ * list_prepare_entry - prepare a pos entry for use in list_for_each_entry_continue()
+ * @pos: the type * to use as a start point
+ * @head: the head of the list
+ * @member: the name of the list_struct within the struct.
+ *
+ * Prepares a pos entry for use as a start point in list_for_each_entry_continue().
+ */
+#define list_prepare_entry(pos, head, member) \
+ ((pos) ? : list_entry(head, typeof(*pos), member))
+
+/**
+ * list_for_each_entry_continue - continue iteration over list of given type
+ * @pos: the type * to use as a loop cursor.
+ * @head: the head for your list.
+ * @member: the name of the list_struct within the struct.
+ *
+ * Continue to iterate over list of given type, continuing after
+ * the current position.
+ */
+#define list_for_each_entry_continue(pos, head, member) \
+ for (pos = list_entry(pos->member.next, typeof(*pos), member); \
+ prefetch(pos->member.next), &pos->member != (head); \
+ pos = list_entry(pos->member.next, typeof(*pos), member))
+
+/**
+ * list_for_each_entry_continue_reverse - iterate backwards from the given point
+ * @pos: the type * to use as a loop cursor.
+ * @head: the head for your list.
+ * @member: the name of the list_struct within the struct.
+ *
+ * Start to iterate over list of given type backwards, continuing after
+ * the current position.
+ */
+#define list_for_each_entry_continue_reverse(pos, head, member) \
+ for (pos = list_entry(pos->member.prev, typeof(*pos), member); \
+ prefetch(pos->member.prev), &pos->member != (head); \
+ pos = list_entry(pos->member.prev, typeof(*pos), member))
+
+/**
+ * list_for_each_entry_from - iterate over list of given type from the current point
+ * @pos: the type * to use as a loop cursor.
+ * @head: the head for your list.
+ * @member: the name of the list_struct within the struct.
+ *
+ * Iterate over list of given type, continuing from current position.
+ */
+#define list_for_each_entry_from(pos, head, member) \
+ for (; prefetch(pos->member.next), &pos->member != (head); \
+ pos = list_entry(pos->member.next, typeof(*pos), member))
+
+/**
+ * list_for_each_entry_safe - iterate over list of given type safe against removal of list entry
+ * @pos: the type * to use as a loop cursor.
+ * @n: another type * to use as temporary storage
+ * @head: the head for your list.
+ * @member: the name of the list_struct within the struct.
+ */
+#define list_for_each_entry_safe(pos, n, head, member) \
+ for (pos = list_entry((head)->next, typeof(*pos), member), \
+ n = list_entry(pos->member.next, typeof(*pos), member); \
+ &pos->member != (head); \
+ pos = n, n = list_entry(n->member.next, typeof(*n), member))
+
+/**
+ * list_for_each_entry_safe_continue - continue list iteration safe against removal
+ * @pos: the type * to use as a loop cursor.
+ * @n: another type * to use as temporary storage
+ * @head: the head for your list.
+ * @member: the name of the list_struct within the struct.
+ *
+ * Iterate over list of given type, continuing after current point,
+ * safe against removal of list entry.
+ */
+#define list_for_each_entry_safe_continue(pos, n, head, member) \
+ for (pos = list_entry(pos->member.next, typeof(*pos), member), \
+ n = list_entry(pos->member.next, typeof(*pos), member); \
+ &pos->member != (head); \
+ pos = n, n = list_entry(n->member.next, typeof(*n), member))
+
+/**
+ * list_for_each_entry_safe_from - iterate over list from current point safe against removal
+ * @pos: the type * to use as a loop cursor.
+ * @n: another type * to use as temporary storage
+ * @head: the head for your list.
+ * @member: the name of the list_struct within the struct.
+ *
+ * Iterate over list of given type from current point, safe against
+ * removal of list entry.
+ */
+#define list_for_each_entry_safe_from(pos, n, head, member) \
+ for (n = list_entry(pos->member.next, typeof(*pos), member); \
+ &pos->member != (head); \
+ pos = n, n = list_entry(n->member.next, typeof(*n), member))
+
+/**
+ * list_for_each_entry_safe_reverse - iterate backwards over list safe against removal
+ * @pos: the type * to use as a loop cursor.
+ * @n: another type * to use as temporary storage
+ * @head: the head for your list.
+ * @member: the name of the list_struct within the struct.
+ *
+ * Iterate backwards over list of given type, safe against removal
+ * of list entry.
+ */
+#define list_for_each_entry_safe_reverse(pos, n, head, member) \
+ for (pos = list_entry((head)->prev, typeof(*pos), member), \
+ n = list_entry(pos->member.prev, typeof(*pos), member); \
+ &pos->member != (head); \
+ pos = n, n = list_entry(n->member.prev, typeof(*n), member))
+
+/**
+ * list_safe_reset_next - reset a stale list_for_each_entry_safe loop
+ * @pos: the loop cursor used in the list_for_each_entry_safe loop
+ * @n: temporary storage used in list_for_each_entry_safe
+ * @member: the name of the list_struct within the struct.
+ *
+ * list_safe_reset_next is not safe to use in general if the list may be
+ * modified concurrently (eg. the lock is dropped in the loop body). An
+ * exception to this is if the cursor element (pos) is pinned in the list,
+ * and list_safe_reset_next is called after re-taking the lock and before
+ * completing the current iteration of the loop body.
+ */
+#define list_safe_reset_next(pos, n, member) \
+ n = list_entry(pos->member.next, typeof(*pos), member)
+
+/*
+ * Double linked lists with a single pointer list head.
+ * Mostly useful for hash tables where the two pointer list head is
+ * too wasteful.
+ * You lose the ability to access the tail in O(1).
+ */
+
+#define HLIST_HEAD_INIT { .first = NULL }
+#define HLIST_HEAD(name) struct hlist_head name = { .first = NULL }
+#define INIT_HLIST_HEAD(ptr) ((ptr)->first = NULL)
+static inline void INIT_HLIST_NODE(struct hlist_node *h)
+{
+ h->next = NULL;
+ h->pprev = NULL;
+}
+
+static inline int hlist_unhashed(const struct hlist_node *h)
+{
+ return !h->pprev;
+}
+
+static inline int hlist_empty(const struct hlist_head *h)
+{
+ return !h->first;
+}
+
+static inline void __hlist_del(struct hlist_node *n)
+{
+ struct hlist_node *next = n->next;
+ struct hlist_node **pprev = n->pprev;
+ *pprev = next;
+ if (next)
+ next->pprev = pprev;
+}
+
+static inline void hlist_del(struct hlist_node *n)
+{
+ __hlist_del(n);
+ n->next = LIST_POISON1;
+ n->pprev = LIST_POISON2;
+}
+
+static inline void hlist_del_init(struct hlist_node *n)
+{
+ if (!hlist_unhashed(n)) {
+ __hlist_del(n);
+ INIT_HLIST_NODE(n);
+ }
+}
+
+static inline void hlist_add_head(struct hlist_node *n, struct hlist_head *h)
+{
+ struct hlist_node *first = h->first;
+ n->next = first;
+ if (first)
+ first->pprev = &n->next;
+ h->first = n;
+ n->pprev = &h->first;
+}
+
+/* next must be != NULL */
+static inline void hlist_add_before(struct hlist_node *n,
+ struct hlist_node *next)
+{
+ n->pprev = next->pprev;
+ n->next = next;
+ next->pprev = &n->next;
+ *(n->pprev) = n;
+}
+
+static inline void hlist_add_after(struct hlist_node *n,
+ struct hlist_node *next)
+{
+ next->next = n->next;
+ n->next = next;
+ next->pprev = &n->next;
+
+ if (next->next)
+ next->next->pprev = &next->next;
+}
+
+/* after that we'll appear to be on some hlist and hlist_del will work */
+static inline void hlist_add_fake(struct hlist_node *n)
+{
+ n->pprev = &n->next;
+}
+
+/*
+ * Move a list from one list head to another. Fixup the pprev
+ * reference of the first entry if it exists.
+ */
+static inline void hlist_move_list(struct hlist_head *old,
+ struct hlist_head *new)
+{
+ new->first = old->first;
+ if (new->first)
+ new->first->pprev = &new->first;
+ old->first = NULL;
+}
+
+#define hlist_entry(ptr, type, member) container_of(ptr, type, member)
+
+#define hlist_for_each(pos, head) \
+ for (pos = (head)->first; pos && ({ prefetch(pos->next); 1; }); \
+ pos = pos->next)
+
+#define hlist_for_each_safe(pos, n, head) \
+ for (pos = (head)->first; pos && ({ n = pos->next; 1; }); \
+ pos = n)
+
+/**
+ * hlist_for_each_entry - iterate over list of given type
+ * @tpos: the type * to use as a loop cursor.
+ * @pos: the &struct hlist_node to use as a loop cursor.
+ * @head: the head for your list.
+ * @member: the name of the hlist_node within the struct.
+ */
+#define hlist_for_each_entry(tpos, pos, head, member) \
+ for (pos = (head)->first; \
+ pos && ({ prefetch(pos->next); 1; }) && \
+ ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1; }); \
+ pos = pos->next)
+
+/**
+ * hlist_for_each_entry_continue - iterate over a hlist continuing after current point
+ * @tpos: the type * to use as a loop cursor.
+ * @pos: the &struct hlist_node to use as a loop cursor.
+ * @member: the name of the hlist_node within the struct.
+ */
+#define hlist_for_each_entry_continue(tpos, pos, member) \
+ for (pos = (pos)->next; \
+ pos && ({ prefetch(pos->next); 1; }) && \
+ ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1; }); \
+ pos = pos->next)
+
+/**
+ * hlist_for_each_entry_from - iterate over a hlist continuing from current point
+ * @tpos: the type * to use as a loop cursor.
+ * @pos: the &struct hlist_node to use as a loop cursor.
+ * @member: the name of the hlist_node within the struct.
+ */
+#define hlist_for_each_entry_from(tpos, pos, member) \
+ for (; pos && ({ prefetch(pos->next); 1; }) && \
+ ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1; }); \
+ pos = pos->next)
+
+/**
+ * hlist_for_each_entry_safe - iterate over list of given type safe against removal of list entry
+ * @tpos: the type * to use as a loop cursor.
+ * @pos: the &struct hlist_node to use as a loop cursor.
+ * @n: another &struct hlist_node to use as temporary storage
+ * @head: the head for your list.
+ * @member: the name of the hlist_node within the struct.
+ */
+#define hlist_for_each_entry_safe(tpos, pos, n, head, member) \
+ for (pos = (head)->first; \
+ pos && ({ n = pos->next; 1; }) && \
+ ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1; }); \
+ pos = n)
+
+#endif
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/e302582d/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/src/helper/log.c
----------------------------------------------------------------------
diff --git a/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/src/helper/log.c b/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/src/helper/log.c
new file mode 100755
index 0000000..0bea1c5
--- /dev/null
+++ b/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/src/helper/log.c
@@ -0,0 +1,469 @@
+/***************************************************************************
+ * Copyright (C) 2005 by Dominic Rath *
+ * Dominic.Rath@gmx.de *
+ * *
+ * Copyright (C) 2007-2010 �yvind Harboe *
+ * oyvind.harboe@zylin.com *
+ * *
+ * Copyright (C) 2008 by Spencer Oliver *
+ * spen@spen-soft.co.uk *
+ * *
+ * 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 "log.h"
+#include "command.h"
+#include "time_support.h"
+
+#include <stdarg.h>
+
+#ifdef _DEBUG_FREE_SPACE_
+#ifdef HAVE_MALLOC_H
+#include <malloc.h>
+#else
+#error "malloc.h is required to use --enable-malloc-logging"
+#endif
+#endif
+
+int debug_level = -1;
+
+static FILE *log_output;
+static struct log_callback *log_callbacks;
+
+static long long last_time;
+static long long current_time;
+
+static long long start;
+
+static const char * const log_strings[5] = {
+ "User : ",
+ "Error: ",
+ "Warn : ", /* want a space after each colon, all same width, colons aligned */
+ "Info : ",
+ "Debug: "
+};
+
+static int count;
+
+static struct store_log_forward *log_head;
+static int log_forward_count;
+
+struct store_log_forward {
+ struct store_log_forward *next;
+ const char *file;
+ int line;
+ const char *function;
+ const char *string;
+};
+
+/* either forward the log to the listeners or store it for possible forwarding later */
+static void log_forward(const char *file, unsigned line, const char *function, const char *string)
+{
+ if (log_forward_count == 0) {
+ struct log_callback *cb, *next;
+ cb = log_callbacks;
+ /* DANGER!!!! the log callback can remove itself!!!! */
+ while (cb) {
+ next = cb->next;
+ cb->fn(cb->priv, file, line, function, string);
+ cb = next;
+ }
+ } else {
+ struct store_log_forward *log = malloc(sizeof(struct store_log_forward));
+ log->file = strdup(file);
+ log->line = line;
+ log->function = strdup(function);
+ log->string = strdup(string);
+ log->next = NULL;
+ if (log_head == NULL)
+ log_head = log;
+ else {
+ /* append to tail */
+ struct store_log_forward *t;
+ t = log_head;
+ while (t->next != NULL)
+ t = t->next;
+ t->next = log;
+ }
+ }
+}
+
+/* The log_puts() serves to somewhat different goals:
+ *
+ * - logging
+ * - feeding low-level info to the user in GDB or Telnet
+ *
+ * The latter dictates that strings without newline are not logged, lest there
+ * will be *MANY log lines when sending one char at the time(e.g.
+ * target_request.c).
+ *
+ */
+static void log_puts(enum log_levels level,
+ const char *file,
+ int line,
+ const char *function,
+ const char *string)
+{
+ char *f;
+ if (level == LOG_LVL_OUTPUT) {
+ /* do not prepend any headers, just print out what we were given and return */
+ fputs(string, log_output);
+ fflush(log_output);
+ return;
+ }
+
+ f = strrchr(file, '/');
+ if (f != NULL)
+ file = f + 1;
+
+ if (strlen(string) > 0) {
+ if (debug_level >= LOG_LVL_DEBUG) {
+ /* print with count and time information */
+ int t = (int)(timeval_ms()-start);
+#ifdef _DEBUG_FREE_SPACE_
+ struct mallinfo info;
+ info = mallinfo();
+#endif
+ fprintf(log_output, "%s%d %d %s:%d %s()"
+#ifdef _DEBUG_FREE_SPACE_
+ " %d"
+#endif
+ ": %s", log_strings[level + 1], count, t, file, line, function,
+#ifdef _DEBUG_FREE_SPACE_
+ info.fordblks,
+#endif
+ string);
+ } else {
+ /* if we are using gdb through pipes then we do not want any output
+ * to the pipe otherwise we get repeated strings */
+ fprintf(log_output, "%s%s",
+ (level > LOG_LVL_USER) ? log_strings[level + 1] : "", string);
+ }
+ } else {
+ /* Empty strings are sent to log callbacks to keep e.g. gdbserver alive, here we do
+ *nothing. */
+ }
+
+ fflush(log_output);
+
+ /* Never forward LOG_LVL_DEBUG, too verbose and they can be found in the log if need be */
+ if (level <= LOG_LVL_INFO)
+ log_forward(file, line, function, string);
+}
+
+void log_printf(enum log_levels level,
+ const char *file,
+ unsigned line,
+ const char *function,
+ const char *format,
+ ...)
+{
+ char *string;
+ va_list ap;
+
+ count++;
+ if (level > debug_level)
+ return;
+
+ va_start(ap, format);
+
+ string = alloc_vprintf(format, ap);
+ if (string != NULL) {
+ log_puts(level, file, line, function, string);
+ free(string);
+ }
+
+ va_end(ap);
+}
+
+void log_printf_lf(enum log_levels level,
+ const char *file,
+ unsigned line,
+ const char *function,
+ const char *format,
+ ...)
+{
+ char *string;
+ va_list ap;
+
+ count++;
+ if (level > debug_level)
+ return;
+
+ va_start(ap, format);
+
+ string = alloc_vprintf(format, ap);
+ if (string != NULL) {
+ strcat(string, "\n"); /* alloc_vprintf guaranteed the buffer to be at least one
+ *char longer */
+ log_puts(level, file, line, function, string);
+ free(string);
+ }
+
+ va_end(ap);
+}
+
+COMMAND_HANDLER(handle_debug_level_command)
+{
+ if (CMD_ARGC == 1) {
+ int new_level;
+ COMMAND_PARSE_NUMBER(int, CMD_ARGV[0], new_level);
+ if ((new_level > LOG_LVL_DEBUG) || (new_level < LOG_LVL_SILENT)) {
+ LOG_ERROR("level must be between %d and %d", LOG_LVL_SILENT, LOG_LVL_DEBUG);
+ return ERROR_COMMAND_SYNTAX_ERROR;
+ }
+ debug_level = new_level;
+ } else if (CMD_ARGC > 1)
+ return ERROR_COMMAND_SYNTAX_ERROR;
+
+ command_print(CMD_CTX, "debug_level: %i", debug_level);
+
+ return ERROR_OK;
+}
+
+COMMAND_HANDLER(handle_log_output_command)
+{
+ if (CMD_ARGC == 1) {
+ FILE *file = fopen(CMD_ARGV[0], "w");
+
+ if (file)
+ log_output = file;
+ }
+
+ return ERROR_OK;
+}
+
+static struct command_registration log_command_handlers[] = {
+ {
+ .name = "log_output",
+ .handler = handle_log_output_command,
+ .mode = COMMAND_ANY,
+ .help = "redirect logging to a file (default: stderr)",
+ .usage = "file_name",
+ },
+ {
+ .name = "debug_level",
+ .handler = handle_debug_level_command,
+ .mode = COMMAND_ANY,
+ .help = "Sets the verbosity level of debugging output. "
+ "0 shows errors only; 1 adds warnings; "
+ "2 (default) adds other info; 3 adds debugging.",
+ .usage = "number",
+ },
+ COMMAND_REGISTRATION_DONE
+};
+
+int log_register_commands(struct command_context *cmd_ctx)
+{
+ return register_commands(cmd_ctx, NULL, log_command_handlers);
+}
+
+void log_init(void)
+{
+ /* set defaults for daemon configuration,
+ * if not set by cmdline or cfgfile */
+ if (debug_level == -1)
+ debug_level = LOG_LVL_INFO;
+
+ char *debug_env = getenv("OPENOCD_DEBUG_LEVEL");
+ if (NULL != debug_env) {
+ int value;
+ int retval = parse_int(debug_env, &value);
+ if (ERROR_OK == retval &&
+ debug_level >= LOG_LVL_SILENT &&
+ debug_level <= LOG_LVL_DEBUG)
+ debug_level = value;
+ }
+
+ if (log_output == NULL)
+ log_output = stderr;
+
+ start = last_time = timeval_ms();
+}
+
+int set_log_output(struct command_context *cmd_ctx, FILE *output)
+{
+ log_output = output;
+ return ERROR_OK;
+}
+
+/* add/remove log callback handler */
+int log_add_callback(log_callback_fn fn, void *priv)
+{
+ struct log_callback *cb;
+
+ /* prevent the same callback to be registered more than once, just for sure */
+ for (cb = log_callbacks; cb; cb = cb->next) {
+ if (cb->fn == fn && cb->priv == priv)
+ return ERROR_COMMAND_SYNTAX_ERROR;
+ }
+
+ /* alloc memory, it is safe just to return in case of an error, no need for the caller to
+ *check this */
+ cb = malloc(sizeof(struct log_callback));
+ if (cb == NULL)
+ return ERROR_BUF_TOO_SMALL;
+
+ /* add item to the beginning of the linked list */
+ cb->fn = fn;
+ cb->priv = priv;
+ cb->next = log_callbacks;
+ log_callbacks = cb;
+
+ return ERROR_OK;
+}
+
+int log_remove_callback(log_callback_fn fn, void *priv)
+{
+ struct log_callback *cb, **p;
+
+ for (p = &log_callbacks; (cb = *p); p = &(*p)->next) {
+ if (cb->fn == fn && cb->priv == priv) {
+ *p = cb->next;
+ free(cb);
+ return ERROR_OK;
+ }
+ }
+
+ /* no such item */
+ return ERROR_COMMAND_SYNTAX_ERROR;
+}
+
+/* return allocated string w/printf() result */
+char *alloc_vprintf(const char *fmt, va_list ap)
+{
+ va_list ap_copy;
+ int len;
+ char *string;
+
+ /* determine the length of the buffer needed */
+ va_copy(ap_copy, ap);
+ len = vsnprintf(NULL, 0, fmt, ap_copy);
+ va_end(ap_copy);
+
+ /* allocate and make room for terminating zero. */
+ /* FIXME: The old version always allocated at least one byte extra and
+ * other code depend on that. They should be probably be fixed, but for
+ * now reserve the extra byte. */
+ string = malloc(len + 2);
+ if (string == NULL)
+ return NULL;
+
+ /* do the real work */
+ vsnprintf(string, len + 1, fmt, ap);
+
+ return string;
+}
+
+char *alloc_printf(const char *format, ...)
+{
+ char *string;
+ va_list ap;
+ va_start(ap, format);
+ string = alloc_vprintf(format, ap);
+ va_end(ap);
+ return string;
+}
+
+/* Code must return to the server loop before 1000ms has returned or invoke
+ * this function.
+ *
+ * The GDB connection will time out if it spends >2000ms and you'll get nasty
+ * error messages from GDB:
+ *
+ * Ignoring packet error, continuing...
+ * Reply contains invalid hex digit 116
+ *
+ * While it is possible use "set remotetimeout" to more than the default 2000ms
+ * in GDB, OpenOCD guarantees that it sends keep-alive packages on the
+ * GDB protocol and it is a bug in OpenOCD not to either return to the server
+ * loop or invoke keep_alive() every 1000ms.
+ *
+ * This function will send a keep alive packet if >500ms has passed since last time
+ * it was invoked.
+ *
+ * Note that this function can be invoked often, so it needs to be relatively
+ * fast when invoked more often than every 500ms.
+ *
+ */
+void keep_alive()
+{
+ current_time = timeval_ms();
+ if (current_time-last_time > 1000) {
+ extern int gdb_actual_connections;
+
+ if (gdb_actual_connections)
+ LOG_WARNING("keep_alive() was not invoked in the "
+ "1000ms timelimit. GDB alive packet not "
+ "sent! (%lld). Workaround: increase "
+ "\"set remotetimeout\" in GDB",
+ current_time-last_time);
+ else
+ LOG_DEBUG("keep_alive() was not invoked in the "
+ "1000ms timelimit (%lld). This may cause "
+ "trouble with GDB connections.",
+ current_time-last_time);
+ }
+ if (current_time-last_time > 500) {
+ /* this will keep the GDB connection alive */
+ LOG_USER_N("%s", "");
+
+ /* DANGER!!!! do not add code to invoke e.g. target event processing,
+ * jim timer processing, etc. it can cause infinite recursion +
+ * jim event callbacks need to happen at a well defined time,
+ * not anywhere keep_alive() is invoked.
+ *
+ * These functions should be invoked at a well defined spot in server.c
+ */
+
+ last_time = current_time;
+ }
+}
+
+/* reset keep alive timer without sending message */
+void kept_alive()
+{
+ current_time = timeval_ms();
+ last_time = current_time;
+}
+
+/* if we sleep for extended periods of time, we must invoke keep_alive() intermittantly */
+void alive_sleep(uint64_t ms)
+{
+ uint64_t napTime = 10;
+ for (uint64_t i = 0; i < ms; i += napTime) {
+ uint64_t sleep_a_bit = ms - i;
+ if (sleep_a_bit > napTime)
+ sleep_a_bit = napTime;
+
+ usleep(sleep_a_bit * 1000);
+ keep_alive();
+ }
+}
+
+void busy_sleep(uint64_t ms)
+{
+ uint64_t then = timeval_ms();
+ while (timeval_ms() - then < ms) {
+ /*
+ * busy wait
+ */
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/e302582d/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/src/helper/log.h
----------------------------------------------------------------------
diff --git a/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/src/helper/log.h b/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/src/helper/log.h
new file mode 100755
index 0000000..7f9f32c
--- /dev/null
+++ b/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/src/helper/log.h
@@ -0,0 +1,144 @@
+/***************************************************************************
+ * Copyright (C) 2005 by Dominic Rath *
+ * Dominic.Rath@gmx.de *
+ * *
+ * Copyright (C) 2007,2008 �yvind Harboe *
+ * oyvind.harboe@zylin.com *
+ * *
+ * Copyright (C) 2008 by Spencer Oliver *
+ * spen@spen-soft.co.uk *
+ * *
+ * 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 ERROR_H
+#define ERROR_H
+
+#include <helper/command.h>
+
+/* To achieve C99 printf compatibility in MinGW, gnu_printf should be
+ * used for __attribute__((format( ... ))), with GCC v4.4 or later
+ */
+#if (defined(IS_MINGW) && (((__GNUC__ << 16) + __GNUC_MINOR__) >= 0x00040004))
+#define PRINTF_ATTRIBUTE_FORMAT gnu_printf
+#else
+#define PRINTF_ATTRIBUTE_FORMAT printf
+#endif
+
+/* logging priorities
+ * LOG_LVL_SILENT - turn off all output. In lieu of try + catch this can be used as a
+ * feeble ersatz.
+ * LOG_LVL_USER - user messages. Could be anything from information
+ * to progress messags. These messages do not represent
+ * incorrect or unexpected behaviour, just normal execution.
+ * LOG_LVL_ERROR - fatal errors, that are likely to cause program abort
+ * LOG_LVL_WARNING - non-fatal errors, that may be resolved later
+ * LOG_LVL_INFO - state information, etc.
+ * LOG_LVL_DEBUG - debug statements, execution trace
+ */
+enum log_levels {
+ LOG_LVL_SILENT = -3,
+ LOG_LVL_OUTPUT = -2,
+ LOG_LVL_USER = -1,
+ LOG_LVL_ERROR = 0,
+ LOG_LVL_WARNING = 1,
+ LOG_LVL_INFO = 2,
+ LOG_LVL_DEBUG = 3
+};
+
+void log_printf(enum log_levels level, const char *file, unsigned line,
+ const char *function, const char *format, ...)
+__attribute__ ((format (PRINTF_ATTRIBUTE_FORMAT, 5, 6)));
+void log_printf_lf(enum log_levels level, const char *file, unsigned line,
+ const char *function, const char *format, ...)
+__attribute__ ((format (PRINTF_ATTRIBUTE_FORMAT, 5, 6)));
+
+/**
+ * Initialize logging module. Call during program startup.
+ */
+void log_init(void);
+int set_log_output(struct command_context *cmd_ctx, FILE *output);
+
+int log_register_commands(struct command_context *cmd_ctx);
+
+void keep_alive(void);
+void kept_alive(void);
+
+void alive_sleep(uint64_t ms);
+void busy_sleep(uint64_t ms);
+
+typedef void (*log_callback_fn)(void *priv, const char *file, unsigned line,
+ const char *function, const char *string);
+
+struct log_callback {
+ log_callback_fn fn;
+ void *priv;
+ struct log_callback *next;
+};
+
+int log_add_callback(log_callback_fn fn, void *priv);
+int log_remove_callback(log_callback_fn fn, void *priv);
+
+char *alloc_vprintf(const char *fmt, va_list ap);
+char *alloc_printf(const char *fmt, ...);
+
+extern int debug_level;
+
+/* Avoid fn call and building parameter list if we're not outputting the information.
+ * Matters on feeble CPUs for DEBUG/INFO statements that are involved frequently */
+
+#define LOG_LEVEL_IS(FOO) ((debug_level) >= (FOO))
+
+#define LOG_DEBUG(expr ...) \
+ do { \
+ if (debug_level >= LOG_LVL_DEBUG) \
+ log_printf_lf(LOG_LVL_DEBUG, \
+ __FILE__, __LINE__, __func__, \
+ expr); \
+ } while (0)
+
+#define LOG_INFO(expr ...) \
+ log_printf_lf(LOG_LVL_INFO, __FILE__, __LINE__, __func__, expr)
+
+#define LOG_WARNING(expr ...) \
+ log_printf_lf(LOG_LVL_WARNING, __FILE__, __LINE__, __func__, expr)
+
+#define LOG_ERROR(expr ...) \
+ log_printf_lf(LOG_LVL_ERROR, __FILE__, __LINE__, __func__, expr)
+
+#define LOG_USER(expr ...) \
+ log_printf_lf(LOG_LVL_USER, __FILE__, __LINE__, __func__, expr)
+
+#define LOG_USER_N(expr ...) \
+ log_printf(LOG_LVL_USER, __FILE__, __LINE__, __func__, expr)
+
+#define LOG_OUTPUT(expr ...) \
+ log_printf(LOG_LVL_OUTPUT, __FILE__, __LINE__, __func__, expr)
+
+/* general failures
+ * error codes < 100
+ */
+#define ERROR_OK (0)
+#define ERROR_NO_CONFIG_FILE (-2)
+#define ERROR_BUF_TOO_SMALL (-3)
+/* see "Error:" log entry for meaningful message to the user. The caller should
+ * make no assumptions about what went wrong and try to handle the problem.
+ */
+#define ERROR_FAIL (-4)
+#define ERROR_WAIT (-5)
+
+
+#endif /* LOG_H */
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/e302582d/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/src/helper/options.c
----------------------------------------------------------------------
diff --git a/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/src/helper/options.c b/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/src/helper/options.c
new file mode 100755
index 0000000..b13d466
--- /dev/null
+++ b/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/src/helper/options.c
@@ -0,0 +1,232 @@
+/***************************************************************************
+ * Copyright (C) 2004, 2005 by Dominic Rath *
+ * Dominic.Rath@gmx.de *
+ * *
+ * Copyright (C) 2007-2010 �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. *
+ ***************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "configuration.h"
+#include "log.h"
+#include "command.h"
+
+#include <getopt.h>
+
+static int help_flag, version_flag;
+
+static const struct option long_options[] = {
+ {"help", no_argument, &help_flag, 1},
+ {"version", no_argument, &version_flag, 1},
+ {"debug", optional_argument, 0, 'd'},
+ {"file", required_argument, 0, 'f'},
+ {"search", required_argument, 0, 's'},
+ {"log_output", required_argument, 0, 'l'},
+ {"command", required_argument, 0, 'c'},
+ {"pipe", no_argument, 0, 'p'},
+ {0, 0, 0, 0}
+};
+
+int configuration_output_handler(struct command_context *context, const char *line)
+{
+ LOG_USER_N("%s", line);
+
+ return ERROR_OK;
+}
+
+#ifdef _WIN32
+static char *find_suffix(const char *text, const char *suffix)
+{
+ size_t text_len = strlen(text);
+ size_t suffix_len = strlen(suffix);
+
+ if (suffix_len == 0)
+ return (char *)text + text_len;
+
+ if (suffix_len > text_len || strncmp(text + text_len - suffix_len, suffix, suffix_len) != 0)
+ return NULL; /* Not a suffix of text */
+
+ return (char *)text + text_len - suffix_len;
+}
+#endif
+
+static void add_default_dirs(void)
+{
+ const char *run_prefix;
+ char *path;
+
+#ifdef _WIN32
+ char strExePath[MAX_PATH];
+ GetModuleFileName(NULL, strExePath, MAX_PATH);
+
+ /* Strip executable file name, leaving path */
+ *strrchr(strExePath, '\\') = '\0';
+
+ /* Convert path separators to UNIX style, should work on Windows also. */
+ for (char *p = strExePath; *p; p++) {
+ if (*p == '\\')
+ *p = '/';
+ }
+
+ char *end_of_prefix = find_suffix(strExePath, BINDIR);
+ if (end_of_prefix != NULL)
+ *end_of_prefix = '\0';
+
+ run_prefix = strExePath;
+#else
+ run_prefix = "";
+#endif
+
+ LOG_DEBUG("bindir=%s", BINDIR);
+ LOG_DEBUG("pkgdatadir=%s", PKGDATADIR);
+ LOG_DEBUG("run_prefix=%s", run_prefix);
+
+ /*
+ * The directory containing OpenOCD-supplied scripts should be
+ * listed last in the built-in search order, so the user can
+ * override these scripts with site-specific customizations.
+ */
+ const char *home = getenv("HOME");
+
+ if (home) {
+ path = alloc_printf("%s/.openocd", home);
+ if (path) {
+ add_script_search_dir(path);
+ free(path);
+ }
+ }
+
+ path = getenv("OPENOCD_SCRIPTS");
+
+ if (path)
+ add_script_search_dir(path);
+
+#ifdef _WIN32
+ const char *appdata = getenv("APPDATA");
+
+ if (appdata) {
+ path = alloc_printf("%s/OpenOCD", appdata);
+ if (path) {
+ add_script_search_dir(path);
+ free(path);
+ }
+ }
+#endif
+
+ path = alloc_printf("%s%s%s", run_prefix, PKGDATADIR, "/site");
+ if (path) {
+ add_script_search_dir(path);
+ free(path);
+ }
+
+ path = alloc_printf("%s%s%s", run_prefix, PKGDATADIR, "/scripts");
+ if (path) {
+ add_script_search_dir(path);
+ free(path);
+ }
+}
+
+int parse_cmdline_args(struct command_context *cmd_ctx, int argc, char *argv[])
+{
+ int c;
+
+ while (1) {
+ /* getopt_long stores the option index here. */
+ int option_index = 0;
+
+ c = getopt_long(argc, argv, "hvd::l:f:s:c:p", long_options, &option_index);
+
+ /* Detect the end of the options. */
+ if (c == -1)
+ break;
+
+ switch (c) {
+ case 0:
+ break;
+ case 'h': /* --help | -h */
+ help_flag = 1;
+ break;
+ case 'v': /* --version | -v */
+ version_flag = 1;
+ break;
+ case 'f': /* --file | -f */
+ {
+ char *command = alloc_printf("script {%s}", optarg);
+ add_config_command(command);
+ free(command);
+ break;
+ }
+ case 's': /* --search | -s */
+ add_script_search_dir(optarg);
+ break;
+ case 'd': /* --debug | -d */
+ {
+ char *command = alloc_printf("debug_level %s", optarg ? optarg : "3");
+ command_run_line(cmd_ctx, command);
+ free(command);
+ break;
+ }
+ case 'l': /* --log_output | -l */
+ if (optarg) {
+ char *command = alloc_printf("log_output %s", optarg);
+ command_run_line(cmd_ctx, command);
+ free(command);
+ }
+ break;
+ case 'c': /* --command | -c */
+ if (optarg)
+ add_config_command(optarg);
+ break;
+ case 'p':
+ /* to replicate the old syntax this needs to be synchronous
+ * otherwise the gdb stdin will overflow with the warning message */
+ command_run_line(cmd_ctx, "gdb_port pipe; log_output openocd.log");
+ LOG_WARNING("deprecated option: -p/--pipe. Use '-c \"gdb_port pipe; "
+ "log_output openocd.log\"' instead.");
+ break;
+ }
+ }
+
+ if (help_flag) {
+ LOG_OUTPUT("Open On-Chip Debugger\nLicensed under GNU GPL v2\n");
+ LOG_OUTPUT("--help | -h\tdisplay this help\n");
+ LOG_OUTPUT("--version | -v\tdisplay OpenOCD version\n");
+ LOG_OUTPUT("--file | -f\tuse configuration file <name>\n");
+ LOG_OUTPUT("--search | -s\tdir to search for config files and scripts\n");
+ LOG_OUTPUT("--debug | -d\tset debug level <0-3>\n");
+ LOG_OUTPUT("--log_output | -l\tredirect log output to file <name>\n");
+ LOG_OUTPUT("--command | -c\trun <command>\n");
+ exit(-1);
+ }
+
+ if (version_flag) {
+ /* Nothing to do, version gets printed automatically. */
+ /* It is not an error to request the VERSION number. */
+ exit(0);
+ }
+
+ /* paths specified on the command line take precedence over these
+ * built-in paths
+ */
+ add_default_dirs();
+
+ return ERROR_OK;
+}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/e302582d/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/src/helper/replacements.c
----------------------------------------------------------------------
diff --git a/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/src/helper/replacements.c b/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/src/helper/replacements.c
new file mode 100755
index 0000000..bb23dd9
--- /dev/null
+++ b/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/src/helper/replacements.c
@@ -0,0 +1,320 @@
+/***************************************************************************
+ * Copyright (C) 2006 by Dominic Rath *
+ * Dominic.Rath@gmx.de *
+ * *
+ * Copyright (C) 2007,2008 �yvind Harboe *
+ * oyvind.harboe@zylin.com *
+ * *
+ * Copyright (C) 2008 by Spencer Oliver *
+ * spen@spen-soft.co.uk *
+ * *
+ * 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. *
+ ***************************************************************************/
+/* DANGER!!!! These must be defined *BEFORE* replacements.h and the malloc() macro!!!! */
+
+#include <stdlib.h>
+#include <string.h>
+/*
+ * clear_malloc
+ *
+ * will alloc memory and clear it
+ */
+void *clear_malloc(size_t size)
+{
+ void *t = malloc(size);
+ if (t != NULL)
+ memset(t, 0x00, size);
+ return t;
+}
+
+void *fill_malloc(size_t size)
+{
+ void *t = malloc(size);
+ if (t != NULL) {
+ /* We want to initialize memory to some known bad state.
+ * 0 and 0xff yields 0 and -1 as integers, which often
+ * have meaningful values. 0x5555... is not often a valid
+ * integer and is quite easily spotted in the debugger
+ * also it is almost certainly an invalid address */
+ memset(t, 0x55, size);
+ }
+ return t;
+}
+
+#define IN_REPLACEMENTS_C
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+#ifdef HAVE_STRINGS_H
+#include <strings.h>
+#endif
+
+#ifdef _WIN32
+#include <io.h>
+#endif
+
+/* replacements for gettimeofday */
+#ifndef HAVE_GETTIMEOFDAY
+
+/* Windows */
+#ifdef _WIN32
+
+#ifndef __GNUC__
+#define EPOCHFILETIME (116444736000000000i64)
+#else
+#define EPOCHFILETIME (116444736000000000LL)
+#endif
+
+int gettimeofday(struct timeval *tv, struct timezone *tz)
+{
+ FILETIME ft;
+ LARGE_INTEGER li;
+ __int64 t;
+ static int tzflag;
+
+ if (tv) {
+ GetSystemTimeAsFileTime(&ft);
+ li.LowPart = ft.dwLowDateTime;
+ li.HighPart = ft.dwHighDateTime;
+ t = li.QuadPart; /* In 100-nanosecond intervals */
+ t -= EPOCHFILETIME; /* Offset to the Epoch time */
+ t /= 10; /* In microseconds */
+ tv->tv_sec = (long)(t / 1000000);
+ tv->tv_usec = (long)(t % 1000000);
+ }
+
+ if (tz) {
+ if (!tzflag) {
+ _tzset();
+ tzflag++;
+ }
+ tz->tz_minuteswest = _timezone / 60;
+ tz->tz_dsttime = _daylight;
+ }
+
+ return 0;
+}
+#endif /* _WIN32 */
+
+#endif /* HAVE_GETTIMEOFDAY */
+
+#ifndef HAVE_STRNLEN
+size_t strnlen(const char *s, size_t maxlen)
+{
+ const char *end = (const char *)memchr(s, '\0', maxlen);
+ return end ? (size_t) (end - s) : maxlen;
+}
+#endif
+
+#ifndef HAVE_STRNDUP
+char *strndup(const char *s, size_t n)
+{
+ size_t len = strnlen(s, n);
+ char *new = malloc(len + 1);
+
+ if (new == NULL)
+ return NULL;
+
+ new[len] = '\0';
+ return (char *) memcpy(new, s, len);
+}
+#endif
+
+#ifdef _WIN32
+int win_select(int max_fd, fd_set *rfds, fd_set *wfds, fd_set *efds, struct timeval *tv)
+{
+ DWORD ms_total, limit;
+ HANDLE handles[MAXIMUM_WAIT_OBJECTS];
+ int handle_slot_to_fd[MAXIMUM_WAIT_OBJECTS];
+ int n_handles = 0, i;
+ fd_set sock_read, sock_write, sock_except;
+ fd_set aread, awrite, aexcept;
+ int sock_max_fd = -1;
+ struct timeval tvslice;
+ int retcode;
+
+#define SAFE_FD_ISSET(fd, set) (set != NULL && FD_ISSET(fd, set))
+
+ /* calculate how long we need to wait in milliseconds */
+ if (tv == NULL)
+ ms_total = INFINITE;
+ else {
+ ms_total = tv->tv_sec * 1000;
+ ms_total += tv->tv_usec / 1000;
+ }
+
+ FD_ZERO(&sock_read);
+ FD_ZERO(&sock_write);
+ FD_ZERO(&sock_except);
+
+ /* build an array of handles for non-sockets */
+ for (i = 0; i < max_fd; i++) {
+ if (SAFE_FD_ISSET(i, rfds) || SAFE_FD_ISSET(i, wfds) || SAFE_FD_ISSET(i, efds)) {
+ intptr_t handle = (intptr_t) _get_osfhandle(i);
+ handles[n_handles] = (HANDLE)handle;
+ if (handles[n_handles] == INVALID_HANDLE_VALUE) {
+ /* socket */
+ if (SAFE_FD_ISSET(i, rfds))
+ FD_SET(i, &sock_read);
+ if (SAFE_FD_ISSET(i, wfds))
+ FD_SET(i, &sock_write);
+ if (SAFE_FD_ISSET(i, efds))
+ FD_SET(i, &sock_except);
+ if (i > sock_max_fd)
+ sock_max_fd = i;
+ } else {
+ handle_slot_to_fd[n_handles] = i;
+ n_handles++;
+ }
+ }
+ }
+
+ if (n_handles == 0) {
+ /* plain sockets only - let winsock handle the whole thing */
+ return select(max_fd, rfds, wfds, efds, tv);
+ }
+
+ /* mixture of handles and sockets; lets multiplex between
+ * winsock and waiting on the handles */
+
+ FD_ZERO(&aread);
+ FD_ZERO(&awrite);
+ FD_ZERO(&aexcept);
+
+ limit = GetTickCount() + ms_total;
+ do {
+ retcode = 0;
+
+ if (sock_max_fd >= 0) {
+ /* overwrite the zero'd sets here; the select call
+ * will clear those that are not active */
+ aread = sock_read;
+ awrite = sock_write;
+ aexcept = sock_except;
+
+ tvslice.tv_sec = 0;
+ tvslice.tv_usec = 1000;
+
+ retcode = select(sock_max_fd + 1, &aread, &awrite, &aexcept, &tvslice);
+ }
+
+ if (n_handles > 0) {
+ /* check handles */
+ DWORD wret;
+
+ wret = MsgWaitForMultipleObjects(n_handles,
+ handles,
+ FALSE,
+ retcode > 0 ? 0 : 1,
+ QS_ALLEVENTS);
+
+ if (wret == WAIT_TIMEOUT) {
+ /* set retcode to 0; this is the default.
+ * select() may have set it to something else,
+ * in which case we leave it alone, so this branch
+ * does nothing */
+ ;
+ } else if (wret == WAIT_FAILED) {
+ if (retcode == 0)
+ retcode = -1;
+ } else {
+ if (retcode < 0)
+ retcode = 0;
+ for (i = 0; i < n_handles; i++) {
+ if (WAIT_OBJECT_0 == WaitForSingleObject(handles[i], 0)) {
+ if (SAFE_FD_ISSET(handle_slot_to_fd[i], rfds)) {
+ DWORD dwBytes;
+ intptr_t handle = (intptr_t) _get_osfhandle(
+ handle_slot_to_fd[i]);
+
+ if (PeekNamedPipe((HANDLE)handle, NULL, 0,
+ NULL, &dwBytes, NULL)) {
+ /* check to see if gdb pipe has data available */
+ if (dwBytes) {
+ FD_SET(handle_slot_to_fd[i], &aread);
+ retcode++;
+ }
+ } else {
+ FD_SET(handle_slot_to_fd[i], &aread);
+ retcode++;
+ }
+ }
+ if (SAFE_FD_ISSET(handle_slot_to_fd[i], wfds)) {
+ FD_SET(handle_slot_to_fd[i], &awrite);
+ retcode++;
+ }
+ if (SAFE_FD_ISSET(handle_slot_to_fd[i], efds)) {
+ FD_SET(handle_slot_to_fd[i], &aexcept);
+ retcode++;
+ }
+ }
+ }
+ }
+ }
+ } while (retcode == 0 && (ms_total == INFINITE || GetTickCount() < limit));
+
+ if (rfds)
+ *rfds = aread;
+ if (wfds)
+ *wfds = awrite;
+ if (efds)
+ *efds = aexcept;
+
+ return retcode;
+}
+#endif
+
+#if defined HAVE_LIBUSB1 && !defined HAVE_LIBUSB_ERROR_NAME
+#include <libusb.h>
+/* Verbatim from git://git.libusb.org/libusb.git tag 1.0.9
+ * The libusb_error enum is compatible down to v0.9.1
+ */
+const char *libusb_error_name(int error_code)
+{
+ enum libusb_error error = error_code;
+ switch (error) {
+ case LIBUSB_SUCCESS:
+ return "LIBUSB_SUCCESS";
+ case LIBUSB_ERROR_IO:
+ return "LIBUSB_ERROR_IO";
+ case LIBUSB_ERROR_INVALID_PARAM:
+ return "LIBUSB_ERROR_INVALID_PARAM";
+ case LIBUSB_ERROR_ACCESS:
+ return "LIBUSB_ERROR_ACCESS";
+ case LIBUSB_ERROR_NO_DEVICE:
+ return "LIBUSB_ERROR_NO_DEVICE";
+ case LIBUSB_ERROR_NOT_FOUND:
+ return "LIBUSB_ERROR_NOT_FOUND";
+ case LIBUSB_ERROR_BUSY:
+ return "LIBUSB_ERROR_BUSY";
+ case LIBUSB_ERROR_TIMEOUT:
+ return "LIBUSB_ERROR_TIMEOUT";
+ case LIBUSB_ERROR_OVERFLOW:
+ return "LIBUSB_ERROR_OVERFLOW";
+ case LIBUSB_ERROR_PIPE:
+ return "LIBUSB_ERROR_PIPE";
+ case LIBUSB_ERROR_INTERRUPTED:
+ return "LIBUSB_ERROR_INTERRUPTED";
+ case LIBUSB_ERROR_NO_MEM:
+ return "LIBUSB_ERROR_NO_MEM";
+ case LIBUSB_ERROR_NOT_SUPPORTED:
+ return "LIBUSB_ERROR_NOT_SUPPORTED";
+ case LIBUSB_ERROR_OTHER:
+ return "LIBUSB_ERROR_OTHER";
+ }
+ return "**UNKNOWN**";
+}
+#endif
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/e302582d/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/src/helper/replacements.h
----------------------------------------------------------------------
diff --git a/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/src/helper/replacements.h b/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/src/helper/replacements.h
new file mode 100755
index 0000000..2776602
--- /dev/null
+++ b/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/src/helper/replacements.h
@@ -0,0 +1,285 @@
+/***************************************************************************
+ * Copyright (C) 2006 by Dominic Rath *
+ * Dominic.Rath@gmx.de *
+ * *
+ * Copyright (C) 2007,2008 �yvind Harboe *
+ * oyvind.harboe@zylin.com *
+ * *
+ * Copyright (C) 2008 by Spencer Oliver *
+ * spen@spen-soft.co.uk *
+ * *
+ * 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 REPLACEMENTS_H
+#define REPLACEMENTS_H
+
+/* MIN,MAX macros */
+#ifndef MIN
+#define MIN(a, b) (((a) < (b)) ? (a) : (b))
+#endif
+#ifndef MAX
+#define MAX(a, b) (((a) > (b)) ? (a) : (b))
+#endif
+
+/* for systems that do not support ENOTSUP
+ * win32 being one of them */
+#ifndef ENOTSUP
+#define ENOTSUP 134 /* Not supported */
+#endif
+
+/* for systems that do not support O_BINARY
+ * linux being one of them */
+#ifndef O_BINARY
+#define O_BINARY 0
+#endif
+
+#ifndef HAVE_SYS_TIME_H
+
+#ifndef _TIMEVAL_DEFINED
+#define _TIMEVAL_DEFINED
+
+struct timeval {
+ long tv_sec;
+ long tv_usec;
+};
+
+#endif /* _TIMEVAL_DEFINED */
+
+#endif
+
+/* gettimeofday() */
+#ifndef HAVE_GETTIMEOFDAY
+
+#ifdef _WIN32
+struct timezone {
+ int tz_minuteswest;
+ int tz_dsttime;
+};
+#endif
+struct timezone;
+
+int gettimeofday(struct timeval *tv, struct timezone *tz);
+
+#endif
+
+#ifndef IN_REPLACEMENTS_C
+/**** clear_malloc & fill_malloc ****/
+void *clear_malloc(size_t size);
+void *fill_malloc(size_t size);
+#endif
+
+/*
+ * Now you have 3 ways for the malloc function:
+ *
+ * 1. Do not change anything, use the original malloc
+ *
+ * 2. Use the clear_malloc function instead of the original malloc.
+ * In this case you must use the following define:
+ * #define malloc((_a)) clear_malloc((_a))
+ *
+ * 3. Use the fill_malloc function instead of the original malloc.
+ * In this case you must use the following define:
+ * #define malloc((_a)) fill_malloc((_a))
+ *
+ * We have figured out that there could exist some malloc problems
+ * where variables are using without to be initialise. To find this
+ * places, use the fill_malloc function. With this function we want
+ * to initialize memory to some known bad state. This is quite easily
+ * spotted in the debugger and will trap to an invalid address.
+ *
+ * clear_malloc can be used if you want to set not initialise
+ * variable to 0.
+ *
+ * If you do not want to change the malloc function, to not use one of
+ * the following macros. Which is the default way.
+ */
+
+/* #define malloc(_a) clear_malloc(_a)
+ * #define malloc(_a) fill_malloc(_a) */
+
+/* GNU extensions to the C library that may be missing on some systems */
+#ifndef HAVE_STRNDUP
+char *strndup(const char *s, size_t n);
+#endif /* HAVE_STRNDUP */
+
+#ifndef HAVE_STRNLEN
+size_t strnlen(const char *s, size_t maxlen);
+#endif /* HAVE_STRNLEN */
+
+#ifndef HAVE_USLEEP
+#ifdef _WIN32
+static inline unsigned usleep(unsigned int usecs)
+{
+ Sleep((usecs/1000));
+ return 0;
+}
+#else
+#error no usleep defined for your platform
+#endif
+#endif /* HAVE_USLEEP */
+
+/* Windows specific */
+#ifdef _WIN32
+
+#include <windows.h>
+#include <time.h>
+
+/* Windows does not declare sockaddr_un */
+#define UNIX_PATH_LEN 108
+struct sockaddr_un {
+ uint16_t sun_family;
+ char sun_path[UNIX_PATH_LEN];
+};
+
+/* win32 systems do not support ETIMEDOUT */
+
+#ifndef ETIMEDOUT
+#define ETIMEDOUT WSAETIMEDOUT
+#endif
+
+#if IS_MINGW == 1
+static inline unsigned char inb(unsigned short int port)
+{
+ unsigned char _v;
+ __asm__ __volatile__ ("inb %w1,%0" : "=a" (_v) : "Nd" (port));
+ return _v;
+}
+
+static inline void outb(unsigned char value, unsigned short int port)
+{
+ __asm__ __volatile__ ("outb %b0,%w1" : : "a" (value), "Nd" (port));
+}
+
+/* mingw does not have ffs, so use gcc builtin types */
+#define ffs __builtin_ffs
+
+#endif /* IS_MINGW */
+
+int win_select(int max_fd, fd_set *rfds, fd_set *wfds, fd_set *efds, struct timeval *tv);
+
+#endif /* _WIN32 */
+
+/* generic socket functions for Windows and Posix */
+static inline int write_socket(int handle, const void *buffer, unsigned int count)
+{
+#ifdef _WIN32
+ return send(handle, buffer, count, 0);
+#else
+ return write(handle, buffer, count);
+#endif
+}
+
+static inline int read_socket(int handle, void *buffer, unsigned int count)
+{
+#ifdef _WIN32
+ return recv(handle, buffer, count, 0);
+#else
+ return read(handle, buffer, count);
+#endif
+}
+
+static inline int close_socket(int sock)
+{
+#ifdef _WIN32
+ return closesocket(sock);
+#else
+ return close(sock);
+#endif
+}
+
+static inline void socket_nonblock(int fd)
+{
+#ifdef _WIN32
+ unsigned long nonblock = 1;
+ ioctlsocket(fd, FIONBIO, &nonblock);
+#else
+ int oldopts = fcntl(fd, F_GETFL, 0);
+ fcntl(fd, F_SETFL, oldopts | O_NONBLOCK);
+#endif
+}
+
+static inline int socket_select(int max_fd,
+ fd_set *rfds,
+ fd_set *wfds,
+ fd_set *efds,
+ struct timeval *tv)
+{
+#ifdef _WIN32
+ return win_select(max_fd, rfds, wfds, efds, tv);
+#else
+ return select(max_fd, rfds, wfds, efds, tv);
+#endif
+}
+
+#ifndef HAVE_ELF_H
+
+typedef uint32_t Elf32_Addr;
+typedef uint16_t Elf32_Half;
+typedef uint32_t Elf32_Off;
+typedef int32_t Elf32_Sword;
+typedef uint32_t Elf32_Word;
+typedef uint32_t Elf32_Size;
+typedef Elf32_Off Elf32_Hashelt;
+
+typedef struct {
+ unsigned char e_ident[16]; /* Magic number and other info */
+ Elf32_Half e_type; /* Object file type */
+ Elf32_Half e_machine; /* Architecture */
+ Elf32_Word e_version; /* Object file version */
+ Elf32_Addr e_entry; /* Entry point virtual address */
+ Elf32_Off e_phoff; /* Program header table file offset */
+ Elf32_Off e_shoff; /* Section header table file offset */
+ Elf32_Word e_flags; /* Processor-specific flags */
+ Elf32_Half e_ehsize; /* ELF header size in bytes */
+ Elf32_Half e_phentsize; /* Program header table entry size */
+ Elf32_Half e_phnum; /* Program header table entry count */
+ Elf32_Half e_shentsize; /* Section header table entry size */
+ Elf32_Half e_shnum; /* Section header table entry count */
+ Elf32_Half e_shstrndx; /* Section header string table index */
+} Elf32_Ehdr;
+
+#define ELFMAG "\177ELF"
+#define SELFMAG 4
+
+#define EI_CLASS 4 /* File class byte index */
+#define ELFCLASS32 1 /* 32-bit objects */
+#define ELFCLASS64 2 /* 64-bit objects */
+
+#define EI_DATA 5 /* Data encoding byte index */
+#define ELFDATA2LSB 1 /* 2's complement, little endian */
+#define ELFDATA2MSB 2 /* 2's complement, big endian */
+
+typedef struct {
+ Elf32_Word p_type; /* Segment type */
+ Elf32_Off p_offset; /* Segment file offset */
+ Elf32_Addr p_vaddr; /* Segment virtual address */
+ Elf32_Addr p_paddr; /* Segment physical address */
+ Elf32_Size p_filesz; /* Segment size in file */
+ Elf32_Size p_memsz; /* Segment size in memory */
+ Elf32_Word p_flags; /* Segment flags */
+ Elf32_Size p_align; /* Segment alignment */
+} Elf32_Phdr;
+
+#define PT_LOAD 1 /* Loadable program segment */
+
+#endif /* HAVE_ELF_H */
+
+#if defined HAVE_LIBUSB1 && !defined HAVE_LIBUSB_ERROR_NAME
+const char *libusb_error_name(int error_code);
+#endif /* defined HAVE_LIBUSB1 && !defined HAVE_LIBUSB_ERROR_NAME */
+
+#endif /* REPLACEMENTS_H */
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/e302582d/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/src/helper/startup.tcl
----------------------------------------------------------------------
diff --git a/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/src/helper/startup.tcl b/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/src/helper/startup.tcl
new file mode 100755
index 0000000..4ca2cab
--- /dev/null
+++ b/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/src/helper/startup.tcl
@@ -0,0 +1,66 @@
+# Defines basic Tcl procs that must exist for OpenOCD scripts to work.
+#
+# Embedded into OpenOCD executable
+#
+
+
+# We need to explicitly redirect this to the OpenOCD command
+# as Tcl defines the exit proc
+proc exit {} {
+ ocd_throw exit
+}
+
+# All commands are registered with an 'ocd_' prefix, while the "real"
+# command is a wrapper that calls this function. Its primary purpose is
+# to discard 'handler' command output,
+proc ocd_bouncer {name args} {
+ set cmd [format "ocd_%s" $name]
+ set type [eval ocd_command type $cmd $args]
+ set errcode error
+ if {$type == "native"} {
+ return [eval $cmd $args]
+ } else {if {$type == "simple"} {
+ set errcode [catch {eval $cmd $args}]
+ if {$errcode == 0} {
+ return ""
+ } else {
+ # 'classic' commands output error message as part of progress output
+ set errmsg ""
+ }
+ } else {if {$type == "group"} {
+ catch {eval ocd_usage $name $args}
+ set errmsg [format "%s: command requires more arguments" \
+ [concat $name " " $args]]
+ } else {
+ set errmsg [format "invalid subcommand \"%s\"" $args]
+ }}}
+ return -code $errcode $errmsg
+}
+
+# Try flipping / and \ to find file if the filename does not
+# match the precise spelling
+proc find {filename} {
+ if {[catch {ocd_find $filename} t]==0} {
+ return $t
+ }
+ if {[catch {ocd_find [string map {\ /} $filename} t]==0} {
+ return $t
+ }
+ if {[catch {ocd_find [string map {/ \\} $filename} t]==0} {
+ return $t
+ }
+ # make sure error message matches original input string
+ return -code error "Can't find $filename"
+}
+add_usage_text find "<file>"
+add_help_text find "print full path to file according to OpenOCD search rules"
+
+# Find and run a script
+proc script {filename} {
+ uplevel #0 [list source [find $filename]]
+}
+add_help_text script "filename of OpenOCD script (tcl) to run"
+add_usage_text script "<file>"
+
+#########
+
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/e302582d/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/src/helper/system.h
----------------------------------------------------------------------
diff --git a/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/src/helper/system.h b/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/src/helper/system.h
new file mode 100755
index 0000000..a6dfd7e
--- /dev/null
+++ b/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/src/helper/system.h
@@ -0,0 +1,91 @@
+/***************************************************************************
+ * Copyright (C) 2006 by Dominic Rath <Do...@gmx.de> *
+ * Copyright (C) 2007-2008 by �yvind Harboe <oy...@zylin.com> *
+ * Copyright (C) 2008 by Spencer Oliver <sp...@spen-soft.co.uk> *
+ * Copyright (C) 2009 by 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. *
+ ***************************************************************************/
+
+#ifndef SYSTEM_H
+#define SYSTEM_H
+
+/* standard C library header files */
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+#include <ctype.h>
+#include <errno.h>
+
+/* +++ AC_HEADER_TIME +++ */
+#ifdef TIME_WITH_SYS_TIME
+# include <sys/time.h>
+# include <time.h>
+#else
+# ifdef HAVE_SYS_TIME_H
+# include <sys/time.h>
+# else
+# include <time.h>
+# endif
+#endif
+/* --- AC_HEADER_TIME --- */
+
+/* +++ platform specific headers +++ */
+#ifdef _WIN32
+#include <winsock2.h>
+#include <ws2tcpip.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#endif
+/* --- platform specific headers --- */
+
+#ifdef HAVE_SYS_SOCKET_H
+#include <sys/socket.h>
+#endif
+#ifdef HAVE_POLL_H
+#include <poll.h>
+#endif
+
+#ifdef __ECOS
+/* missing from eCos */
+#ifndef EFAULT
+#define EFAULT 14 /* Bad address */
+#endif
+#endif
+
+#ifdef HAVE_NETINET_IN_H
+#include <netinet/in.h>
+#endif
+#ifdef HAVE_SYS_SELECT_H
+#include <sys/select.h> /* select, FD_SET and friends (POSIX.1-2001) */
+#endif
+#ifdef HAVE_SYS_PARAM_H
+#include <sys/param.h> /* for MIN/MAX macros */
+#endif
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+#ifdef HAVE_FCNTL_H
+#include <fcntl.h>
+#endif
+
+#ifndef true
+#define true 1
+#define false 0
+#endif
+
+#endif /* SYSTEM_H */
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/e302582d/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/src/helper/time_support.c
----------------------------------------------------------------------
diff --git a/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/src/helper/time_support.c b/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/src/helper/time_support.c
new file mode 100755
index 0000000..780eb96
--- /dev/null
+++ b/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/src/helper/time_support.c
@@ -0,0 +1,91 @@
+/***************************************************************************
+ * Copyright (C) 2006 by Dominic Rath *
+ * Dominic.Rath@gmx.de *
+ * *
+ * Copyright (C) 2007,2008 �yvind Harboe *
+ * oyvind.harboe@zylin.com *
+ * *
+ * Copyright (C) 2008 by Spencer Oliver *
+ * spen@spen-soft.co.uk *
+ * *
+ * 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 "time_support.h"
+
+/* calculate difference between two struct timeval values */
+int timeval_subtract(struct timeval *result, struct timeval *x, struct timeval *y)
+{
+ if (x->tv_usec < y->tv_usec) {
+ int nsec = (y->tv_usec - x->tv_usec) / 1000000 + 1;
+ y->tv_usec -= 1000000 * nsec;
+ y->tv_sec += nsec;
+ }
+ if (x->tv_usec - y->tv_usec > 1000000) {
+ int nsec = (x->tv_usec - y->tv_usec) / 1000000;
+ y->tv_usec += 1000000 * nsec;
+ y->tv_sec -= nsec;
+ }
+
+ result->tv_sec = x->tv_sec - y->tv_sec;
+ result->tv_usec = x->tv_usec - y->tv_usec;
+
+ /* Return 1 if result is negative. */
+ return x->tv_sec < y->tv_sec;
+}
+
+int timeval_add_time(struct timeval *result, long sec, long usec)
+{
+ result->tv_sec += sec;
+ result->tv_usec += usec;
+
+ while (result->tv_usec > 1000000) {
+ result->tv_usec -= 1000000;
+ result->tv_sec++;
+ }
+
+ return 0;
+}
+
+int duration_start(struct duration *duration)
+{
+ return gettimeofday(&duration->start, NULL);
+}
+
+int duration_measure(struct duration *duration)
+{
+ struct timeval end;
+ int retval = gettimeofday(&end, NULL);
+ if (0 == retval)
+ timeval_subtract(&duration->elapsed, &end, &duration->start);
+ return retval;
+}
+
+float duration_elapsed(const struct duration *duration)
+{
+ float t = duration->elapsed.tv_sec;
+ t += (float)duration->elapsed.tv_usec / 1000000.0;
+ return t;
+}
+
+float duration_kbps(const struct duration *duration, size_t count)
+{
+ return count / (1024.0 * duration_elapsed(duration));
+}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/e302582d/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/src/helper/time_support.h
----------------------------------------------------------------------
diff --git a/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/src/helper/time_support.h b/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/src/helper/time_support.h
new file mode 100755
index 0000000..5a95e7e
--- /dev/null
+++ b/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/src/helper/time_support.h
@@ -0,0 +1,62 @@
+/***************************************************************************
+ * Copyright (C) 2006 by Dominic Rath *
+ * Dominic.Rath@gmx.de *
+ * *
+ * Copyright (C) 2007,2008 �yvind Harboe *
+ * oyvind.harboe@zylin.com *
+ * *
+ * Copyright (C) 2008 by Spencer Oliver *
+ * spen@spen-soft.co.uk *
+ * *
+ * 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 TIME_SUPPORT_H
+#define TIME_SUPPORT_H
+
+#ifdef TIME_WITH_SYS_TIME
+# include <sys/time.h>
+# include <time.h>
+#else
+# ifdef HAVE_SYS_TIME_H
+# include <sys/time.h>
+# else
+# include <time.h>
+# endif
+#endif
+
+int timeval_subtract(struct timeval *result, struct timeval *x, struct timeval *y);
+int timeval_add_time(struct timeval *result, long sec, long usec);
+
+/** @returns gettimeofday() timeval as 64-bit in ms */
+int64_t timeval_ms(void);
+
+struct duration {
+ struct timeval start;
+ struct timeval elapsed;
+};
+
+/** Update the duration->start field to start the @a duration measurement. */
+int duration_start(struct duration *duration);
+/** Update the duration->elapsed field to finish the @a duration measurment. */
+int duration_measure(struct duration *duration);
+
+/** @returns Elapsed time in seconds. */
+float duration_elapsed(const struct duration *duration);
+/** @returns KB/sec for the elapsed @a duration and @a count bytes. */
+float duration_kbps(const struct duration *duration, size_t count);
+
+#endif /* TIME_SUPPORT_H */
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/e302582d/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/src/helper/time_support_common.c
----------------------------------------------------------------------
diff --git a/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/src/helper/time_support_common.c b/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/src/helper/time_support_common.c
new file mode 100755
index 0000000..fd564e3
--- /dev/null
+++ b/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/src/helper/time_support_common.c
@@ -0,0 +1,43 @@
+/***************************************************************************
+ * Copyright (C) 2006 by Dominic Rath *
+ * Dominic.Rath@gmx.de *
+ * *
+ * Copyright (C) 2007,2008 �yvind Harboe *
+ * oyvind.harboe@zylin.com *
+ * *
+ * Copyright (C) 2008 by Spencer Oliver *
+ * spen@spen-soft.co.uk *
+ * *
+ * 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 "time_support.h"
+
+/* simple and low overhead fetching of ms counter. Use only
+ * the difference between ms counters returned from this fn.
+ */
+int64_t timeval_ms()
+{
+ struct timeval now;
+ int retval = gettimeofday(&now, NULL);
+ if (retval < 0)
+ return retval;
+ return (int64_t)now.tv_sec * 1000 + now.tv_usec / 1000;
+}