The unified diff between revisions [a39fe798..] and [8f4e93ab..] is displayed below. It can also be downloaded as a raw diff.
# # old_revision [a39fe7980c8f14b70401f4c97f3e10232dce016a] # new_revision [8f4e93ab4d89edfdbd524b06b83511c6867a9150] # # patch "i2c.c" # from [ebacb54424d6c1bd22ce75978f6c6756eecf488c] # to [7f5362fc29f8f8f81682424c73930b5e3044c994] # # patch "main.c" # from [38594d91649f88377c87a52973d831d9ffeafb70] # to [495b950dc0db657d6169223890154d27de162224] # # patch "timer.c" # from [9ef2a6c50a8a227103c6c98477c1ce62327a0977] # to [345db97155c057df90bcbbdc2386ab54a8a12be7] # # patch "wmp.c" # from [bba0c9cfc92f2ce2c56d9a49d01b47f374a40a29] # to [9acbe9ae30b2b7c95b8a700f4f7bb97c38097e21] # # patch "wmp.h" # from [39e6154ed17c4beed31e71e774f07bac2909b826] # to [1c8449a5057b64d7441e74d3ea43ef2818f9ffe8] # ============================================================ --- i2c.c ebacb54424d6c1bd22ce75978f6c6756eecf488c +++ i2c.c 7f5362fc29f8f8f81682424c73930b5e3044c994 @@ -1,6 +1,7 @@ #include "i2c.h" #include "interrupt.h" +#include "event.h" #define I2CBASE 0xE001C000 @@ -108,6 +109,7 @@ void __attribute__((interrupt("IRQ"))) i i2c_transaction = NULL; IREG(I2CONSET) = STOFLAG; IREG(I2CONCLR) = STAFLAG | AAFLAG | SIFLAG; + event_set(EVENT_I2C_COMPLETE); } } break; @@ -138,6 +140,7 @@ void __attribute__((interrupt("IRQ"))) i i2c_transaction = NULL; IREG(I2CONSET) = STOFLAG; IREG(I2CONCLR) = STAFLAG | AAFLAG | SIFLAG; + event_set(EVENT_I2C_COMPLETE); } break; @@ -150,6 +153,7 @@ void __attribute__((interrupt("IRQ"))) i i2c_transaction = NULL; IREG(I2CONSET) = STOFLAG; IREG(I2CONCLR) = STAFLAG | AAFLAG | SIFLAG; + event_set(EVENT_I2C_COMPLETE); break; /* We don't handle slave mode */ ============================================================ --- main.c 38594d91649f88377c87a52973d831d9ffeafb70 +++ main.c 495b950dc0db657d6169223890154d27de162224 @@ -159,6 +159,11 @@ void average_sample(void) putstr(")\r\n"); } +void timer_event_handler(void) +{ + wmp_start_sample(); +} + void menu_handler(void); int main(void) { @@ -170,6 +175,10 @@ int main(void) { event_register(EVENT_UART_INPUT, menu_handler); + event_register(EVENT_I2C_COMPLETE, wmp_event_handler); + + event_register(EVENT_TIMER, timer_event_handler); + putstr("Your entire life has been a mathematical error... a mathematical error I'm about to correct!\r\n"); putstr("prompt> "); @@ -268,7 +277,7 @@ void menu_handler(void) break; case 'P': putstr("Initialising timer... "); - timer_set_period(10000*TIMER_MS); + timer_set_period(10*TIMER_MS); reply("done"); break; case 'E': ============================================================ --- timer.c 9ef2a6c50a8a227103c6c98477c1ce62327a0977 +++ timer.c 345db97155c057df90bcbbdc2386ab54a8a12be7 @@ -58,7 +58,6 @@ void init_timer(void) TWREG(PC) = 0; TREG(TCR) = TCR_ENABLE; - event_register(EVENT_TIMER, timer_event_handler); } unsigned int timer_read(void) @@ -74,9 +73,10 @@ void timer_set_period(unsigned int perio void timer_set_period(unsigned int period) { + interrupt_register(TIMER0, timer_interrupt_handler); TWREG(MR0) = period; TWREG(MCR) = MR0I | MR0R; - interrupt_register(TIMER0, timer_interrupt_handler); + TWREG(TC) = 0; } void __attribute__((interrupt("IRQ"))) timer_interrupt_handler(void) @@ -87,15 +87,8 @@ void __attribute__((interrupt("IRQ"))) t if (ir & (1<<0)) { /* Match channel 0 */ - putstr(" *timer0* "); + event_set(EVENT_TIMER); } - event_set(EVENT_TIMER); - interrupt_clear(); } - -void timer_event_handler(void) -{ - putstr(" *t0event* "); -} ============================================================ --- wmp.c bba0c9cfc92f2ce2c56d9a49d01b47f374a40a29 +++ wmp.c 9acbe9ae30b2b7c95b8a700f4f7bb97c38097e21 @@ -1,10 +1,12 @@ #include "wmp.h" #include "i2c.h" +#include "uart.h" unsigned char wmp_init_command[2] = {0xfe, 0x04}; i2c_result wmp_result; +unsigned int wmp_generation; struct i2c_transaction wmp_init_transaction = { (0x53 << 1) + 0, /* write */ @@ -105,6 +107,8 @@ bool wmp_sample(void) if (wmp_result != I2C_SUCCESS) return FALSE; + wmp_result = I2C_IN_PROGRESS; + wmp_yaw = ((wmp_sample_data[3]>>2)<<8) + wmp_sample_data[0]; wmp_pitch = ((wmp_sample_data[4]>>2)<<8) + wmp_sample_data[1]; wmp_roll = ((wmp_sample_data[5]>>2)<<8) + wmp_sample_data[2]; @@ -117,3 +121,36 @@ bool wmp_sample(void) return TRUE; } +bool wmp_start_sample(void) +{ + return i2c_start_transaction(&wmp_sample_transaction); +} + +void wmp_event_handler(void) +{ + if (wmp_result != I2C_SUCCESS) + return; + + wmp_result = I2C_IN_PROGRESS; + + wmp_yaw = ((wmp_sample_data[3]>>2)<<8) + wmp_sample_data[0]; + wmp_pitch = ((wmp_sample_data[4]>>2)<<8) + wmp_sample_data[1]; + wmp_roll = ((wmp_sample_data[5]>>2)<<8) + wmp_sample_data[2]; + + /* XXX We don't take into account the fast/slow mode flag here */ + wmp_yaw_fast = !(wmp_sample_data[3] & 0x2); + wmp_pitch_fast = !(wmp_sample_data[3] & 0x1); + wmp_roll_fast = !(wmp_sample_data[4] & 0x2); + + wmp_generation++; + if ((wmp_generation % 100) == 0) { + putstr("("); + puthex(wmp_roll); + putstr(", "); + puthex(wmp_pitch); + putstr(", "); + puthex(wmp_yaw); + putstr(")\r\n"); + + } +} ============================================================ --- wmp.h 39e6154ed17c4beed31e71e774f07bac2909b826 +++ wmp.h 1c8449a5057b64d7441e74d3ea43ef2818f9ffe8 @@ -16,5 +16,7 @@ bool wmp_read_calibration_data(void); bool wmp_init(void); bool wmp_sample(void); bool wmp_read_calibration_data(void); +bool wmp_start_sample(void); +void wmp_event_handler(void); #endif /* __WMP_H */