Browse Source

Use events to invoke menu handling on UART receive. We now have a basic

main dispatch loop.
master
Gavan Fantom 14 years ago
parent
commit
fda1b2a672
  1. 3
      event.h
  2. 29
      main.c
  3. 2
      uart.c

3
event.h

@ -5,8 +5,9 @@
#define EVENT_TIMER 0 #define EVENT_TIMER 0
#define EVENT_I2C_COMPLETE 1 #define EVENT_I2C_COMPLETE 1
#define EVENT_UART_INPUT 2
#define EVENT_MAX 1 #define EVENT_MAX 2
typedef void event_handler(void); typedef void event_handler(void);

29
main.c

@ -159,21 +159,35 @@ void average_sample(void)
putstr(")\r\n"); putstr(")\r\n");
} }
int main(void) { void menu_handler(void);
int i;
int main(void) {
init_interrupt(); init_interrupt();
init_uart(); init_uart();
init_i2c(); init_i2c();
init_pins(); init_pins();
init_timer(); init_timer();
event_register(EVENT_UART_INPUT, menu_handler);
putstr("Your entire life has been a mathematical error... a mathematical error I'm about to correct!\r\n"); putstr("Your entire life has been a mathematical error... a mathematical error I'm about to correct!\r\n");
putstr("prompt> ");
while (1) { while (1) {
char c; FP0XVAL ^= 0x04000000;
putstr("prompt> "); event_dispatch();
while (!getch(&c)) }
FP0XVAL ^= 0x04000000;
return 0;
}
void menu_handler(void)
{
int i;
char c;
while (getch(&c)) {
if (c == 0x0a) if (c == 0x0a)
continue; continue;
putch(c); putch(c);
@ -265,7 +279,6 @@ int main(void) {
reply("Unrecognised command."); reply("Unrecognised command.");
break; break;
} }
putstr("prompt> ");
} }
return 0;
} }

2
uart.c

@ -1,6 +1,7 @@
#include "uart.h" #include "uart.h"
#include "types.h" #include "types.h"
#include "interrupt.h" #include "interrupt.h"
#include "event.h"
#define UARTBASE 0xE000C000 #define UARTBASE 0xE000C000
@ -112,6 +113,7 @@ void __attribute__((interrupt("IRQ"))) uart_interrupt_handler(void)
} }
} }
uart_rxwrite = local_rxwrite; uart_rxwrite = local_rxwrite;
event_set(EVENT_UART_INPUT);
break; break;
case 0x2: /* THRE interrupt */ case 0x2: /* THRE interrupt */

Loading…
Cancel
Save