From 24d11d4976062e965fb64861808548c39f53714b Mon Sep 17 00:00:00 2001 From: Lars-Dominik Braun Date: Mon, 10 Mar 2014 17:30:31 +0100 Subject: Add common.h --- Makefile | 2 +- accel.c | 7 ++----- common.h | 13 +++++++++++++ gyro.c | 7 ++----- main.c | 8 +------- 5 files changed, 19 insertions(+), 18 deletions(-) create mode 100644 common.h diff --git a/Makefile b/Makefile index 3e37a57..addea24 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ MCU = atmega88 all: sanduhr.hex -sanduhr.elf: main.c i2c.c i2c.h uart.c uart.h timer.c timer.h gyro.c gyro.h accel.c accel.h +sanduhr.elf: main.c i2c.c i2c.h uart.c uart.h timer.c timer.h gyro.c gyro.h accel.c accel.h common.h avr-gcc -std=gnu99 -mmcu=$(MCU) -Os -o $@ $^ sanduhr.hex: sanduhr.elf diff --git a/accel.c b/accel.c index dc408a3..a178fa3 100644 --- a/accel.c +++ b/accel.c @@ -1,3 +1,5 @@ +#include "common.h" + #include #include #include @@ -14,11 +16,6 @@ #define LIS302DL_CTRLREG1 0x20 #define LIS302DL_UNUSED1 0x28 -#define sleepwhile(cond) \ - sleep_enable (); \ - while (cond) { sleep_cpu (); } \ - sleep_disable (); - /* the first interrupt is lost */ static volatile bool drdy = true; /* 0, 2 and 4 are zero, as they contain the dummy register’s content */ diff --git a/common.h b/common.h new file mode 100644 index 0000000..ecf2c27 --- /dev/null +++ b/common.h @@ -0,0 +1,13 @@ +#ifndef COMMON_H +#define COMMON_H + +/* cpu runs at 1mhz */ +#define F_CPU 1000000 + +#define sleepwhile(cond) \ + sleep_enable (); \ + while (cond) { sleep_cpu (); } \ + sleep_disable (); + +#endif /* COMMON_H */ + diff --git a/gyro.c b/gyro.c index d6a8b48..bbcb0fe 100644 --- a/gyro.c +++ b/gyro.c @@ -1,3 +1,5 @@ +#include "common.h" + #include #include #include @@ -27,11 +29,6 @@ #define L3GD20_CTRLREG3 0x22 #define L3GD20_CTRLREG4 0x23 -#define sleepwhile(cond) \ - sleep_enable (); \ - while (cond) { sleep_cpu (); } \ - sleep_disable (); - /* the first interrupt is lost */ static volatile bool drdy = true; static volatile int16_t val[3] = {0, 0, 0}; diff --git a/main.c b/main.c index 2e894d3..aadd91e 100644 --- a/main.c +++ b/main.c @@ -1,5 +1,4 @@ -/* cpu runs at 1mhz */ -#define F_CPU 1000000 +#include "common.h" #include #include @@ -33,11 +32,6 @@ static void cpuInit () { CLKPR = 0b00000011; } -#define sleepwhile(cond) \ - sleep_enable (); \ - while (cond) { sleep_cpu (); } \ - sleep_disable (); - int main () { cpuInit (); ledInit (); -- cgit v1.2.3