* 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"
#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 */
}
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());
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.
*/
else
kfile_printf(&ser_fd.fd, "ProcTest..FAIL!\n");
+
+ kputs(AT91SAM7_MSG);
+
// Main loop
for(;;)
{