aboutsummaryrefslogtreecommitdiffstats
path: root/libmaple/util.h
diff options
context:
space:
mode:
authorMarti Bolivar <mbolivar@leaflabs.com>2011-04-01 03:15:27 -0400
committerMarti Bolivar <mbolivar@leaflabs.com>2011-04-05 14:13:35 -0400
commitb835b9864d7fa17de8eeaaafbb1b17f2252e68a5 (patch)
treeb35bd53503883d74f44f69847d09eec20a7ea26f /libmaple/util.h
parent6229da7a3ec40fb7d87c0c4edd38bc32da36ef13 (diff)
downloadlibrambutan-b835b9864d7fa17de8eeaaafbb1b17f2252e68a5.tar.gz
librambutan-b835b9864d7fa17de8eeaaafbb1b17f2252e68a5.zip
SysTick refactor.
For the changelog: * util.h is free of __read(), __write(), etc. macros. * systick_resume() was renamed systick_enable().
Diffstat (limited to 'libmaple/util.h')
-rw-r--r--libmaple/util.h37
1 files changed, 15 insertions, 22 deletions
diff --git a/libmaple/util.h b/libmaple/util.h
index 25dd56e..aff70e1 100644
--- a/libmaple/util.h
+++ b/libmaple/util.h
@@ -23,14 +23,12 @@
*****************************************************************************/
/**
- * @file util.h
- *
- * @brief Various macros and utility procedures.
+ * @file util.h
+ * @brief Miscellaneous utility macros and procedures.
*/
#include "libmaple_types.h"
-/* Generally "useful" utility procedures */
#ifndef _UTIL_H_
#define _UTIL_H_
@@ -38,33 +36,23 @@
extern "C"{
#endif
-/* Debug configuration */
-#define DEBUG_NONE 0
-#define DEBUG_FAULT 1
-#define DEBUG_ALL 2
-
-#ifndef DEBUG_LEVEL
-#define DEBUG_LEVEL DEBUG_ALL
-#endif
+/*
+ * Bit manipulation
+ */
#define BIT(shift) (1UL << (shift))
#define BIT_MASK_SHIFT(mask, shift) ((mask) << (shift))
-
-/* Return bits m to n of x */
+/* Bits m to n of x */
#define GET_BITS(x, m, n) ((((uint32)x) << (31 - (n))) >> ((31 - (n)) + (m)))
+#define IS_POWER_OF_TWO(v) (v && !(v & (v - 1)))
/*
* Register reads and writes
*/
-#define __set_bits(addr, mask) (*(volatile uint32*)(addr) |= (uint32)(mask))
-#define __clear_bits(addr, mask) (*(volatile uint32*)(addr) &= (uint32)~(mask))
-#define __get_bits(addr, mask) (*(volatile uint32*)(addr) & (uint32)(mask))
#define __read(reg) (*(volatile uint32*)(reg))
#define __write(reg, value) (*(volatile uint32*)(reg) = (value))
-#define IS_POWER_OF_TWO(v) (v && !(v & (v - 1)))
-
/*
* Failure routines
*/
@@ -77,13 +65,20 @@ void throb(void);
* Asserts and debug levels
*/
+#define DEBUG_NONE 0
+#define DEBUG_FAULT 1
+#define DEBUG_ALL 2
+
+#ifndef DEBUG_LEVEL
+#define DEBUG_LEVEL DEBUG_ALL
+#endif
+
#if DEBUG_LEVEL >= DEBUG_ALL
#define ASSERT(exp) \
if (exp) { \
} else { \
_fail(__FILE__, __LINE__, #exp); \
}
-
#else
#define ASSERT(exp) (void)((0))
#endif
@@ -94,7 +89,6 @@ void throb(void);
} else { \
_fail(__FILE__, __LINE__, #exp); \
}
-
#else
#define ASSERT_FAULT(exp) (void)((0))
#endif
@@ -104,4 +98,3 @@ void throb(void);
#endif
#endif
-