command context: fix errors when running certain commands on startup
[fw/openocd] / src / helper / types.h
index a8753c5f149115c539e2e39d3eeb07256344f172..1010dcd967b6365f198ce9738ac431b6fcc11b8d 100644 (file)
@@ -60,6 +60,16 @@ typedef bool _Bool;
 #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.
@@ -73,6 +83,15 @@ typedef bool _Bool;
        (type *)( (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
@@ -153,6 +172,7 @@ static inline void h_u16_to_be(uint8_t* buf, int val)
 #define SCNx32 "x"
 #define PRIi32 "i"
 #define PRIu32 "u"
+#define PRId8 PRId32
 
 typedef CYG_ADDRWORD intptr_t;
 typedef int64_t intmax_t;