X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;f=examples%2Flpc2378%2Fmain.c;h=81be7c5b2fdd14aab4b561c6df9c5d242dabc6a1;hb=452d25b78e551f18eb70bff8c9b764630cbc5161;hp=7ab7b8594bdb31f6fac10102e2358d509635c751;hpb=60609e66c309f6b6f5583a7cee0c89705785a275;p=bertos.git diff --git a/examples/lpc2378/main.c b/examples/lpc2378/main.c index 7ab7b859..81be7c5b 100644 --- a/examples/lpc2378/main.c +++ b/examples/lpc2378/main.c @@ -2,44 +2,93 @@ #include #include #include +#include #include +#define PRIO_HIGH 1 +#define PRIO_LOW 0 + #define STATUS_LED (1<<19) #define LED_ON() do { IOCLR1 = STATUS_LED; } while (0) #define LED_OFF() do { IOSET1 = STATUS_LED; } while (0) +static Serial ser_port; + static void init(void) { IRQ_ENABLE; kdbg_init(); timer_init(); + proc_init(); + + timer_delay(3000); kprintf("NXP LPC2378 BeRTOS port test\n"); + timer_delay(3000); /* Turn off boot led */ - IODIR0 = (1<<21); - IOCLR0 = (1<<21); + IODIR0 = (1<<21); + IOCLR0 = (1<<21); /* Init status led */ IODIR1 |= STATUS_LED; LED_OFF(); } -int main(void) +static void NORETURN ser_prompt(void) +{ + char buf[32]; + int i; + + ser_init(&ser_port, SER_UART1); + ser_setbaudrate(&ser_port, 115200); + + /* BeRTOS "echo" terminal */ + kfile_printf(&ser_port.fd, "\n\rBeRTOS echo terminal\n\r"); + proc_setPri(proc_current(), PRIO_HIGH); + for (i = 0; ; i++) + { + kfile_printf(&ser_port.fd, "\n\r[%03d] BeRTOS:~$ ", i); + kfile_gets_echo(&ser_port.fd, buf, sizeof(buf), true); + kfile_printf(&ser_port.fd, "%s", buf); + } +} + +static void NORETURN bertos_up(void) { char spinner[] = {'/', '-', '\\', '|'}; int i = 0; - - init(); while (1) { i++; + proc_forbid(); kprintf("BeRTOS is up & running: %c\r", spinner[i % countof(spinner)]); + proc_permit(); + timer_delay(100); + } +} + +static void NORETURN status(void) +{ + while (1) + { LED_ON(); - timer_delay(500); - + timer_delay(250); + LED_OFF(); - timer_delay(500); + timer_delay(250); + } +} + +int main(void) +{ + + init(); + proc_testRun(); + proc_new(bertos_up, NULL, KERN_MINSTACKSIZE * 3, NULL); + proc_new(ser_prompt, NULL, KERN_MINSTACKSIZE * 3, NULL); + proc_new(status, NULL, 0, NULL); + while (1) + { } return 0; } -