The unified diff between revisions [a39fe798..] and [24d5b9f4..] is displayed below. It can also be downloaded as a raw diff.
This diff has been restricted to the following files: 'main.c'
# # old_revision [a39fe7980c8f14b70401f4c97f3e10232dce016a] # new_revision [24d5b9f4dff9135787b198fe1127d9c1e3326b9c] # # patch "main.c" # from [38594d91649f88377c87a52973d831d9ffeafb70] # to [8284ca89102568b2ae6f26e057ab296621f87e6a] # ============================================================ --- main.c 38594d91649f88377c87a52973d831d9ffeafb70 +++ main.c 8284ca89102568b2ae6f26e057ab296621f87e6a @@ -1,3 +1,4 @@ +/* main.c */ #include "wmp.h" #include "i2c.h" @@ -5,8 +6,13 @@ #include "uart.h" #include "interrupt.h" #include "event.h" +#include "led.h" +#include "status.h" +#include "watchdog.h" +#include "thrust.h" -#define PINSEL0 (*((volatile unsigned char *) 0xE002C000)) +#define PINSEL0 (*((volatile unsigned int *) 0xE002C000)) +#define PINSEL1 (*((volatile unsigned int *) 0xE002C004)) #define FP0XDIR (*((volatile unsigned int *) 0x3FFFC000)) #define FP0XVAL (*((volatile unsigned int *) 0x3FFFC014)) @@ -15,18 +21,26 @@ void init_pins(void) void init_pins(void) { - PINSEL0 = 0x00000055; /* P0.0 and P0.1 assigned to UART */ + PINSEL0 = 0x00a88055; /* P0.0 and P0.1 assigned to UART */ /* P0.2 and P0.3 assigned to I2C */ + /* P0.7 and P0.9 assigned to MAT2.[02] */ + /* P0.10 and P0.11 assigned to CAP1.[01] */ + PINSEL1 = 0x20000828; /* P0.21 and P0.30 assigned to MAT3.[03] */ + /* P0.17 and P0.18 assigned to CAP1.[23] */ SCS = 1; FP0XDIR = 0x04000000; /* P0.26 is an output */ FP0XVAL = 0x0; } +#ifdef USE_UART void reply(char *str) { putstr(str); putstr("\r\n"); } +#else +#define reply(x) ((void)0) +#endif unsigned int count = 0; @@ -159,6 +173,11 @@ void average_sample(void) putstr(")\r\n"); } +void timer_event_handler(void) +{ + wmp_start_sample(); +} + void menu_handler(void); int main(void) { @@ -167,27 +186,51 @@ int main(void) { init_i2c(); init_pins(); init_timer(); + init_status(); 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> "); + timer_delay_ms(1000); + if (!wmp_init()) + putstr("WMP initialisation failed\r\n"); + + /* Flight is potentially live after this. */ + timer_set_period(5*TIMER_MS); + wmp_start_zero(); + + led_init(); + + init_watchdog(); + + /* Good luck! */ while (1) { - FP0XVAL ^= 0x04000000; + led_update(); event_dispatch(); + watchdog_check(); } return 0; } +static int power = 0; + void menu_handler(void) { int i; char c; while (getch(&c)) { +#if 1 + continue; /* Yes, let's just ignore UART input now. */ +#endif if (c == 0x0a) continue; putch(c); @@ -268,13 +311,85 @@ void menu_handler(void) break; case 'P': putstr("Initialising timer... "); - timer_set_period(10000*TIMER_MS); + /* We want a 100Hz loop but two samples per iteration. + * So, we go for 200Hz. */ + timer_set_period(5*TIMER_MS); reply("done"); + wmp_start_zero(); break; - case 'E': - event_dispatch(); - reply("done"); + case 'W': + for (i = 0; i < 4; i++) { + putstr("Width "); + putint(i); + putstr(": "); + putint(timer_input(i)); + if (!timer_valid(i)) + putstr(" (invalid)"); + putstr("\r\n"); + } + if (!timer_allvalid()) { + putstr("ALL INVALID!\r\n"); + } break; + case '0' & 0xdf: + set_thrust(0, 0.0); + set_thrust(1, 0.0); + set_thrust(2, 0.0); + set_thrust(3, 0.0); + power = 0; + break; +#if 0 + case '1' & 0xdf: + power--; + if (power < 0) + power = 15; + power = power % 16; + putstr("Power setting: "); + putint(power); + putstr("\r\n"); + set_thrust(0, ((float)power)/16.0); + break; + case '2' & 0xdf: + power++; + power = power % 16; + putstr("Power setting: "); + putint(power); + putstr("\r\n"); + set_thrust(0, ((float)power)/16.0); + break; +#endif +#if 0 + case '1' & 0xdf: + set_thrust(0, 0.5); + break; + case '2' & 0xdf: + set_thrust(1, 0.5); + break; + case '3' & 0xdf: + set_thrust(2, 0.5); + break; + case '4' & 0xdf: + set_thrust(3, 0.5); + break; + case '5' & 0xdf: + set_thrust(0, 1.0); + break; + case '6' & 0xdf: + set_thrust(1, 1.0); + break; + case '7' & 0xdf: + set_thrust(2, 1.0); + break; + case '8' & 0xdf: + set_thrust(3, 1.0); + break; +#endif + case '9' & 0xdf: + timer_set_pwm_invalid(0); + timer_set_pwm_invalid(1); + timer_set_pwm_invalid(2); + timer_set_pwm_invalid(3); + break; default: reply("Unrecognised command."); break;