* \author Daniele Basile <asterix@develer.com>\r
*\r
* \brief Simple BeRTOS test on AT91SAM7X-EK evaluation board.\r
- * \r
+ *\r
* This short program shows you a simple demo of some BeRTOS feature:\r
- * \r
+ *\r
* - Debug system\r
* - Timer interrupt\r
* - Serial\r
* - Cooperative BeRTOS Kernel\r
- * \r
+ *\r
*/\r
\r
#include "cfg/cfg_ser.h"\r
\r
#include <kern/proc.h>\r
\r
+#include <cpu/detect.h>\r
+\r
#include <drv/timer.h>\r
#include <drv/sysirq_at91.h>\r
#include <drv/ser.h>\r
\r
Timer leds_timer;\r
Serial ser_fd;\r
-int roll = 0;\r
+\r
+enum\r
+{\r
+ FORWARD,\r
+ BACKWARD,\r
+};\r
+\r
+int direction = FORWARD;\r
+\r
+static void leds_init(void)\r
+{\r
+ #if CPU_ARM_AT91SAM7X256\r
+ /* Set PB19..22 connected to PIOB */\r
+ PIOB_PER = 0x780000;\r
+ /* Set PB19..22 as output */\r
+ PIOB_OER = 0x780000;\r
+\r
+ /* Set PB19..22 to 1 to turn off leds */\r
+ PIOB_SODR = 0x780000;\r
+\r
+ /* turn first led on (PB19) */\r
+ PIOB_CODR = 0x80000;\r
+ #elif CPU_ARM_AT91SAM7S256\r
+ /* Set PA0..3 connected to PIOA */\r
+ PIOA_PER = 0x0000001f;\r
+ /* Set PA0..3 as output */\r
+ PIOA_OER = 0x0000001f;\r
+\r
+ /* Set PA0..3 to 1 to turn off leds */\r
+ PIOA_SODR = 0x0000000f;\r
+ /* turn first led on (PA0) */\r
+ PIOA_CODR = 0x00000001;\r
+ #endif\r
+}\r
+\r
+#if CPU_ARM_AT91SAM7X256\r
+ #define GET_PIO_STATUS() (~PIOB_ODSR & 0x780000)\r
+ #define LAST_LED 0x200000\r
+ #define FIRST_LED 0x100000\r
+ #define SET_PIO_BITS PIOB_SODR\r
+ #define CLEAR_PIO_BITS PIOB_CODR\r
+ #define AT91SAM7_MSG "BeRTOS is run on AT91SAM7X256..\n"\r
+#elif CPU_ARM_AT91SAM7S256\r
+ #define GET_PIO_STATUS() (~PIOA_ODSR & 0x0000000f)\r
+ #define LAST_LED 0x00000004\r
+ #define FIRST_LED 0x00000002\r
+ #define SET_PIO_BITS PIOA_SODR\r
+ #define CLEAR_PIO_BITS PIOA_CODR\r
+ #define AT91SAM7_MSG "BeRTOS is run on AT91SAM7S256..\n"\r
+#endif\r
\r
/*\r
- * Supercar leds effect..\r
+ * Knight Rider leds effect..\r
*/\r
static void leds_toggle(void)\r
{\r
- uint32_t a = (~PIOB_ODSR & 0x780000);\r
+ uint32_t led_status = GET_PIO_STATUS();\r
\r
// Turn on led in forward direction\r
- if (roll == 1)\r
+ if (direction == FORWARD)\r
{\r
- if(a == 0x200000)\r
- roll = 2;\r
+ if(led_status == LAST_LED)\r
+ direction = BACKWARD;\r
\r
- PIOB_SODR = a;\r
- PIOB_CODR = a << 1;\r
+ SET_PIO_BITS = led_status;\r
+ CLEAR_PIO_BITS = led_status << 1;\r
}\r
// Turn on led in backward direction\r
- else if (roll == 2)\r
+ else if (direction == BACKWARD)\r
{\r
- if(a == 0x100000)\r
- roll = 1;\r
+ if(led_status == FIRST_LED)\r
+ direction = FORWARD;\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
+ SET_PIO_BITS = led_status;\r
+ CLEAR_PIO_BITS = led_status >> 1;\r
}\r
\r
/* Wait for interval time */\r
kdbg_init();\r
timer_init();\r
proc_init();\r
+ leds_init();\r
\r
ASSERT(!IRQ_ENABLED());\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
else\r
kfile_printf(&ser_fd.fd, "ProcTest..FAIL!\n");\r
\r
+\r
+ kputs(AT91SAM7_MSG);\r
+\r
// Main loop\r
for(;;)\r
{\r