diff options
author | Lars-Dominik Braun <lars@6xq.net> | 2014-03-31 11:18:32 +0200 |
---|---|---|
committer | Lars-Dominik Braun <lars@6xq.net> | 2014-04-22 16:51:13 +0200 |
commit | e3897565c342bee4765f921240b7ca91cd9b23f1 (patch) | |
tree | e7e328ee9452d54db9cfe66cccdb031cb704030f /main.c | |
parent | 24d11d4976062e965fb64861808548c39f53714b (diff) | |
download | hourglass-e3897565c342bee4765f921240b7ca91cd9b23f1.tar.gz hourglass-e3897565c342bee4765f921240b7ca91cd9b23f1.tar.bz2 hourglass-e3897565c342bee4765f921240b7ca91cd9b23f1.zip |
Activate accel + timer
Diffstat (limited to 'main.c')
-rw-r--r-- | main.c | 32 |
1 files changed, 24 insertions, 8 deletions
@@ -11,6 +11,7 @@ #include "uart.h" #include "timer.h" #include "gyro.h" +#include "accel.h" static void ledInit () { /* set led1,led2 to output */ @@ -38,6 +39,7 @@ int main () { twInit (); uartInit (); gyroInit (); + accelInit (); set_sleep_mode (SLEEP_MODE_IDLE); printf ("initialization done\n"); @@ -45,18 +47,32 @@ int main () { /* global interrupt enable */ sei (); gyroStart (); + accelStart (); - //timerStart (); + timerStart (); + bool checkGyro = false; while (1) { - //sleepwhile (!timerHit ()); - //printf ("running for %u seconds\n", seconds); - - sleepwhile (!gyroProcess()); - volatile const int16_t *val = gyroGetAngle (); - printf ("%i/%i/%i\n", val[0], val[1], val[2]); + while (!timerHit ()) { + /* round-robin to prevent starvation */ + if (checkGyro) { + gyroProcess (); + accelProcess(); + } else { + accelProcess(); + gyroProcess (); + } + checkGyro = !checkGyro; + sleep_enable (); + sleep_cpu (); + sleep_disable (); + } + volatile const int16_t *gyroval = gyroGetAngle (); + volatile const int8_t *accelval = accelGet (); + printf ("%i/%i/%i - %i/%i/%i\n", gyroval[0], gyroval[1], gyroval[2], + accelval[1], accelval[3], accelval[5]); gyroResetAngle (); } - //timerStop (); + timerStop (); /* global interrupt disable */ cli (); |