X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;ds=sidebyside;f=boards%2Farduino-mega%2Ftemplates%2Fkernel%2Fmain.c;fp=boards%2Farduino-mega%2Ftemplates%2Fkernel%2Fmain.c;h=663386f45c0723008699f85f6d76a1abdf6c8d69;hb=450741a2b0b851ba6f71cb6e87fd5f61fe311beb;hp=0000000000000000000000000000000000000000;hpb=fc82096bbc71c4197171bdfa33584df6b69038f6;p=bertos.git diff --git a/boards/arduino-mega/templates/kernel/main.c b/boards/arduino-mega/templates/kernel/main.c new file mode 100644 index 00000000..663386f4 --- /dev/null +++ b/boards/arduino-mega/templates/kernel/main.c @@ -0,0 +1,122 @@ +/** + * \file + * + * + * \author Andrea Righi + * + * \brief Kernel project. + * + * This is a minimalist kernel project: it just initializes the hardware and + * creates an independent process to blink an LED, while the main loop + * continues to monitor the stack utilization of all the processes. + */ + +#include "hw/hw_led.h" + +#include + +#include +#include + +#include +#include + +#include +#include + +static Serial out; + +static void init(void) +{ + /* Enable all the interrupts */ + IRQ_ENABLE; + + /* Initialize debugging module (allow kprintf(), etc.) */ + kdbg_init(); + /* Initialize system timer */ + timer_init(); + /* + * XXX: Arduino has a single UART port that was previously + * initialized for debugging purpose. + * In order to activate the serial driver you should disable + * the debugging module. + */ +#if 0 + /* Initialize UART0 */ + ser_init(&out, SER_UART0); + /* Configure UART0 to work at 115.200 bps */ + ser_setbaudrate(&out, 115200); +#else + (void)out; +#endif + /* Initialize LED driver */ + LED_INIT(); + + /* + * Kernel initialization: processes (allow to create and dispatch + * processes using proc_new()). + */ + proc_init(); +} + +static void NORETURN led_process(void) +{ + int i; + + /* Periodically blink the led (toggle each 100 ms) */ + for (i = 0; ; i = !i) + { + if (i) + LED_ON(); + else + LED_OFF(); + timer_delay(100); + } +} + +int main(void) +{ + /* Hardware initialization */ + init(); + + /* Create a new child process */ + proc_new(led_process, NULL, KERN_MINSTACKSIZE * 2, NULL); + + /* + * The main process is kept to periodically report the stack + * utilization of all the processes (1 probe per second). + */ + while (1) + { + monitor_report(); + timer_delay(1000); + } +}