From e13b9ba42de78ef57f11ad0a2f45f4f4648fce77 Mon Sep 17 00:00:00 2001 From: schodet Date: Mon, 20 Sep 2004 22:20:35 +0000 Subject: Ajout de regv. --- n/avr/utils/utils.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'n/avr/utils/utils.h') 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 #include +/** 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) { -- cgit v1.2.3