LPC2: add a UART driver testcase to the example.
[bertos.git] / examples / lpc2378 / main.c
index baf48c5c666e7e6655e4d9bb523589dd1e3e8368..81be7c5b2fdd14aab4b561c6df9c5d242dabc6a1 100644 (file)
@@ -1,44 +1,94 @@
 // Emtpy main.c file generated by the wizard
 #include <cpu/irq.h>
 #include <cfg/debug.h>
-
+#include <drv/timer.h>
+#include <drv/ser.h>
 #include <io/lpc23xx.h>
 
+#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();
-               for (int j = 0; j < 200000; j++ );
-               
+               timer_delay(250);
+
                LED_OFF();
-               for (int j = 0; j < 200000; j++ );
+               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;
 }
-