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/Makefile | 2 +- n/avr/utils/test_utils.c | 6 ++++++ n/avr/utils/utils.h | 17 +++++++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) (limited to 'n/avr') diff --git a/n/avr/utils/Makefile b/n/avr/utils/Makefile index 2be5002..eff599f 100644 --- a/n/avr/utils/Makefile +++ b/n/avr/utils/Makefile @@ -4,7 +4,7 @@ DOC = utils.html EXTRACTDOC = utils.h avrconfig.h MODULES = # atmega8, atmega8535, atmega128... -MCU_TARGET = atmega8 +MCU_TARGET = atmega128 # -O2 : speed # -Os : size OPTIMIZE = -O2 diff --git a/n/avr/utils/test_utils.c b/n/avr/utils/test_utils.c index 7b2ea09..0636e0a 100644 --- a/n/avr/utils/test_utils.c +++ b/n/avr/utils/test_utils.c @@ -22,6 +22,7 @@ * Email: * }}} */ #include "utils.h" +#include /* +AutoDec */ /* -AutoDec */ @@ -29,6 +30,11 @@ int main (void) { + /* Test regv, the first one should generate a warning. */ + TCCR0 = regv (FOC0, WGM00, COM01, COM0, WGM01, CS02, CS00, CS01, + 0, 0, 0, 0, 0, 1, 1, 1); + TCCR0 = regv (FOC0, WGM00, COM01, COM0, WGM01, CS02, CS01, CS00, + 0, 0, 0, 0, 0, 1, 1, 1); //delay_ns (1); //delay_ns (1000); //delay_ns (1000000); 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