summaryrefslogtreecommitdiff
path: root/n/avr/utils/utils.h
diff options
context:
space:
mode:
Diffstat (limited to 'n/avr/utils/utils.h')
-rw-r--r--n/avr/utils/utils.h17
1 files changed, 17 insertions, 0 deletions
diff --git a/n/avr/utils/utils.h b/n/avr/utils/utils.h
index 69c504b..3445d3c 100644
--- a/n/avr/utils/utils.h
+++ b/n/avr/utils/utils.h
@@ -29,6 +29,22 @@
#include <avr/wdt.h>
#include <inttypes.h>
+/** Helper macro to build register value. Call it like this :
+ *
+ * TCCR0 = regv (FOC0, WGM00, COM01, COM0, WGM01, CS02, CS01, CS00,
+ * 0, 0, 0, 0, 0, 1, 1, 1);
+ *
+ * The macro check that the bits are given in the right order and compute the
+ * register value. If the bits are false, the compiler will generate an
+ * warning about a constant being to large.
+ */
+#define regv(b7, b6, b5, b4, b3, b2, b1, b0, v7, v6, v5, v4, v3, v2, v1, v0) \
+ ((b7) == 7 && (b6) == 6 && (b5) == 5 && (b4) == 4 \
+ && (b3) == 3 && (b2) == 2 && (b1) == 1 && (b0) == 0 \
+ ? (v7) << 7 | (v6) << 6 | (v5) << 5 | (v4) << 4 \
+ | (v3) << 3 | (v2) << 2 | (v1) << 1 | (v0) << 0 \
+ : -1024 * 1024)
+
/** Delay in ns. Do not call this macro with a variable parameter. If you
* want a variable delay, prefer looping over a fixed delay.
*
@@ -96,6 +112,7 @@ delay_s (uint8_t s)
extern inline void
reset (void) __attribute__ ((noreturn));
+/** Reset the avr using the watchdog. */
extern inline void
reset (void)
{