+/**\r
+ * \file\r
+ * <!--\r
+ * This file is part of BeRTOS.\r
+ *\r
+ * Bertos is free software; you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation; either version 2 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA\r
+ *\r
+ * As a special exception, you may use this file as part of a free software\r
+ * library without restriction. Specifically, if other files instantiate\r
+ * templates or use macros or inline functions from this file, or you compile\r
+ * this file and link it with other files to produce an executable, this\r
+ * file does not by itself cause the resulting executable to be covered by\r
+ * the GNU General Public License. This exception does not however\r
+ * invalidate any other reasons why the executable file might be covered by\r
+ * the GNU General Public License.\r
+ *\r
+ * Copyright 2009 Develer S.r.l. (http://www.develer.com/)\r
+ *\r
+ * -->\r
+ *\r
+ * \version $Id: at91sam7s.c 2663 2009-04-24 16:30:11Z asterix $\r
+ *\r
+ * \author Francesco Sacchi <batt@develer.com>\r
+ * \author Daniele Basile <asterix@develer.com>\r
+ *\r
+ * \brief Simple BeRTOS test on AT91SAM7X-EK evaluation board.\r
+ * \r
+ * This short program shows you a simple demo of some BeRTOS feature:\r
+ * \r
+ * - Debug system\r
+ * - Timer interrupt\r
+ * - Serial\r
+ * - Cooperative BeRTOS Kernel\r
+ * \r
+ */\r
+\r
+#include "cfg/cfg_ser.h"\r
+#include <cfg/macros.h>\r
+\r
+#include <kern/proc.h>\r
+\r
+#include <drv/timer.h>\r
+#include <drv/sysirq_at91.h>\r
+#include <drv/ser.h>\r
+\r
+#include <io/arm.h>\r
+\r
+Timer leds_timer;\r
+Serial ser_fd;\r
+int roll = 0;\r
+\r
+/*\r
+ * Supercar leds effect..\r
+ */\r
+static void leds_toggle(void)\r
+{\r
+ uint32_t a = (~PIOB_ODSR & 0x780000);\r
+\r
+ // Turn on led in forward direction\r
+ if (roll == 1)\r
+ {\r
+ if(a == 0x200000)\r
+ roll = 2;\r
+\r
+ PIOB_SODR = a;\r
+ PIOB_CODR = a << 1;\r
+ }\r
+ // Turn on led in backward direction\r
+ else if (roll == 2)\r
+ {\r
+ if(a == 0x100000)\r
+ roll = 1;\r
+\r
+ PIOB_SODR = a;\r
+ PIOB_CODR = a >> 1;\r
+ }\r
+ // Start to turn on first led\r
+ else\r
+ {\r
+ PIOB_SODR = 0x780000;\r
+ /* turn first led on */\r
+ PIOB_CODR = 0x80000;\r
+ roll = 1;\r
+ }\r
+\r
+ /* Wait for interval time */\r
+ timer_setDelay(&leds_timer, ms_to_ticks(100));\r
+ timer_add(&leds_timer);\r
+}\r
+\r
+int main(void)\r
+{ char msg[]="BeRTOS, be fast be beatiful be realtime";\r
+\r
+\r
+ kdbg_init();\r
+ timer_init();\r
+ proc_init();\r
+\r
+ ASSERT(!IRQ_ENABLED());\r
+\r
+ /* Open the main communication port */\r
+ ser_init(&ser_fd, 0);\r
+ ser_setbaudrate(&ser_fd, 115200);\r
+ ser_setparity(&ser_fd, SER_PARITY_NONE);\r
+\r
+ IRQ_ENABLE;\r
+ ASSERT(IRQ_ENABLED());\r
+\r
+ /* Disable all pullups */\r
+ PIOB_PUDR = 0xffffffff;\r
+ /* Set PB0..3 connected to PIOA */\r
+ PIOB_PER = 0x780000;\r
+ /* Set PB0..3 as output */\r
+ PIOB_OER = 0x780000;\r
+ /* Disable multidrive on all pins */\r
+ PIOB_MDDR = 0xffffffff;\r
+\r
+ /* Set PA0..3 to 1 to turn off leds */\r
+ PIOB_SODR = 0x780000;\r
+ \r
+ /* turn first led on */\r
+ PIOB_CODR = 0x80000;\r
+\r
+ /*\r
+ * Register timer and arm timer interupt.\r
+ */\r
+ timer_setSoftint(&leds_timer, (Hook)leds_toggle, 0);\r
+ timer_setDelay(&leds_timer, ms_to_ticks(100));\r
+ timer_add(&leds_timer);\r
+\r
+ /*\r
+ * Run process test.\r
+ */\r
+ if(!proc_testRun())\r
+ kfile_printf(&ser_fd.fd, "ProcTest..ok!\n");\r
+ else\r
+ kfile_printf(&ser_fd.fd, "ProcTest..FAIL!\n");\r
+\r
+ // Main loop\r
+ for(;;)\r
+ {\r
+ kfile_printf(&ser_fd.fd, "From serial 0: %s\r\n", msg);\r
+ }\r
+ return 0;\r
+}\r