Merge two at91sam7 project.
authorasterix <asterix@38d2e660-2303-0410-9eaa-f027e97ec537>
Mon, 27 Apr 2009 14:04:57 +0000 (14:04 +0000)
committerasterix <asterix@38d2e660-2303-0410-9eaa-f027e97ec537>
Mon, 27 Apr 2009 14:04:57 +0000 (14:04 +0000)
git-svn-id: https://src.develer.com/svnoss/bertos/trunk@2673 38d2e660-2303-0410-9eaa-f027e97ec537

examples/at91sam7s/at91sam7s.c

index d47264bc83d4ac8be45ec89b15036b641299f942..04ee19f2525614a78d85c84ab581be72f49c14bf 100644 (file)
  * invalidate any other reasons why the executable file might be covered by
  * the GNU General Public License.
  *
- * Copyright 2007 Develer S.r.l. (http://www.develer.com/)
+ * Copyright 2009 Develer S.r.l. (http://www.develer.com/)
  *
  * -->
  *
  * \version $Id$
  *
  * \author Francesco Sacchi <batt@develer.com>
+ * \author Daniele Basile <asterix@develer.com>
+ *
+ * \brief Simple BeRTOS test on AT91SAM7X-EK evaluation board.
+ *
+ * This short program shows you a simple demo of some BeRTOS feature:
+ *
+ * - Debug system
+ * - Timer interrupt
+ * - Serial
+ * - Cooperative BeRTOS Kernel
  *
- * \brief AT91SAM7S-EK porting test.
  */
 
 #include "cfg/cfg_ser.h"
@@ -42,6 +51,8 @@
 
 #include <kern/proc.h>
 
+#include <cpu/detect.h>
+
 #include <drv/timer.h>
 #include <drv/sysirq_at91.h>
 #include <drv/ser.h>
 
 Timer leds_timer;
 Serial ser_fd;
-int roll = 0;
 
-static void leds_toggle(void)
+enum
 {
-       uint8_t a = (~PIOA_ODSR & 0x0f);
+       FORWARD,
+       BACKWARD,
+};
 
-       if (roll == 1)
-       {
-               if(a == 4)
-                       roll = 2;
+int direction = FORWARD;
 
-               PIOA_SODR = a;
-               PIOA_CODR = a << 1;
+static void leds_init(void)
+{
+       #if CPU_ARM_AT91SAM7X256
+               /* Set PB19..22 connected to PIOB */
+               PIOB_PER  = 0x780000;
+               /* Set PB19..22 as output */
+               PIOB_OER  = 0x780000;
+
+               /* Set PB19..22 to 1 to turn off leds */
+               PIOB_SODR  = 0x780000;
+
+               /* turn first led on (PB19) */
+               PIOB_CODR  = 0x80000;
+       #elif CPU_ARM_AT91SAM7S256
+               /* Set PA0..3 connected to PIOA */
+               PIOA_PER  = 0x0000001f;
+               /* Set PA0..3 as output */
+               PIOA_OER  = 0x0000001f;
+
+               /* Set PA0..3 to 1 to turn off leds */
+               PIOA_SODR  = 0x0000000f;
+               /* turn first led on (PA0) */
+               PIOA_CODR  = 0x00000001;
+       #endif
+}
 
-       }
-       else if (roll == 2)
+#if CPU_ARM_AT91SAM7X256
+       #define GET_PIO_STATUS()  (~PIOB_ODSR & 0x780000)
+       #define LAST_LED                        0x200000
+       #define FIRST_LED                       0x100000
+       #define SET_PIO_BITS                    PIOB_SODR
+       #define CLEAR_PIO_BITS                  PIOB_CODR
+       #define AT91SAM7_MSG      "BeRTOS is run on AT91SAM7X256..\n"
+#elif CPU_ARM_AT91SAM7S256
+       #define GET_PIO_STATUS()  (~PIOA_ODSR & 0x0000000f)
+       #define LAST_LED                        0x00000004
+       #define FIRST_LED                       0x00000002
+       #define SET_PIO_BITS                    PIOA_SODR
+       #define CLEAR_PIO_BITS                  PIOA_CODR
+       #define AT91SAM7_MSG      "BeRTOS is run on AT91SAM7S256..\n"
+#endif
+
+/*
+ * Knight Rider leds effect..
+ */
+static void leds_toggle(void)
+{
+       uint32_t led_status = GET_PIO_STATUS();
+
+       // Turn on led in forward direction
+       if (direction == FORWARD)
        {
-               if(a == 2)
-                       roll = 1;
+               if(led_status == LAST_LED)
+                       direction = BACKWARD;
 
-               PIOA_SODR = a;
-               PIOA_CODR = a >> 1;
+               SET_PIO_BITS = led_status;
+               CLEAR_PIO_BITS = led_status << 1;
        }
-       else
+       // Turn on led in backward direction
+       else if (direction == BACKWARD)
        {
-               PIOA_SODR  =  0x0f;
-               /* turn first led on */
-               PIOA_CODR  = 0x00000001;
-               roll = 1;
+               if(led_status == FIRST_LED)
+                       direction = FORWARD;
+
+               SET_PIO_BITS = led_status;
+               CLEAR_PIO_BITS = led_status >> 1;
        }
 
        /* Wait for interval time */
@@ -87,13 +144,13 @@ static void leds_toggle(void)
 }
 
 int main(void)
-{
-       char msg[]="BeRTOS, be fast be beatiful be realtime";
+{      char msg[]="BeRTOS, be fast be beatiful be realtime";
 
 
        kdbg_init();
        timer_init();
        proc_init();
+       leds_init();
 
        ASSERT(!IRQ_ENABLED());
 
@@ -102,24 +159,9 @@ int main(void)
        ser_setbaudrate(&ser_fd, 115200);
        ser_setparity(&ser_fd, SER_PARITY_NONE);
 
-
        IRQ_ENABLE;
        ASSERT(IRQ_ENABLED());
 
-       /* Disable all pullups */
-       PIOA_PUDR = 0xffffffff;
-       /* Set PA0..3 connected to PIOA */
-       PIOA_PER  = 0x0000001f;
-       /* Set PA0..3 as output */
-       PIOA_OER  = 0x0000001f;
-       /* Disable multidrive on all pins */
-       PIOA_MDDR = 0x0000001f;
-
-       /* Set PA0..3 to 1 to turn off leds */
-       PIOA_SODR  = 0x0000000f;
-       /* turn first led on */
-       PIOA_CODR  = 0x00000001;
-
        /*
         * Register timer and arm timer interupt.
         */
@@ -135,6 +177,9 @@ int main(void)
        else
                kfile_printf(&ser_fd.fd, "ProcTest..FAIL!\n");
 
+
+       kputs(AT91SAM7_MSG);
+
        // Main loop
        for(;;)
        {