X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;ds=sidebyside;f=examples%2Fat91sam7s%2Fat91sam7s.c;h=04ee19f2525614a78d85c84ab581be72f49c14bf;hb=c9d1a7e9cc28f4d94fff284a4ca09a23f8eea855;hp=275af6e565faf6246d980d8d198ed674a8af9ac7;hpb=24c21c92d29b76a3f0de0a107f4bafef7bb0f812;p=bertos.git diff --git a/examples/at91sam7s/at91sam7s.c b/examples/at91sam7s/at91sam7s.c index 275af6e5..04ee19f2 100644 --- a/examples/at91sam7s/at91sam7s.c +++ b/examples/at91sam7s/at91sam7s.c @@ -26,42 +26,116 @@ * 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 + * \author Daniele Basile + * + * \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 + +#include + +#include + #include #include -#include #include -#include + #include Timer leds_timer; Serial ser_fd; +enum +{ + FORWARD, + BACKWARD, +}; + +int direction = FORWARD; + +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 +} + +#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) { - uint8_t a = (~PIOA_ODSR & 0x0f); + uint32_t led_status = GET_PIO_STATUS(); - if (a) + // Turn on led in forward direction + if (direction == FORWARD) { - PIOA_SODR = a; - PIOA_CODR = a << 1; + if(led_status == LAST_LED) + direction = BACKWARD; + + 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; + if(led_status == FIRST_LED) + direction = FORWARD; + + SET_PIO_BITS = led_status; + CLEAR_PIO_BITS = led_status >> 1; } /* Wait for interval time */ @@ -69,14 +143,15 @@ static void leds_toggle(void) timer_add(&leds_timer); } - 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()); /* Open the main communication port */ @@ -84,29 +159,27 @@ 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; - - timer_setSoftint(&leds_timer, (Hook)leds_toggle, 0); - timer_setDelay(&leds_timer, ms_to_ticks(100)); - timer_add(&leds_timer); - - ASSERT(proc_testRun() == 0); + /* + * Register timer and arm timer interupt. + */ + timer_setSoftint(&leds_timer, (Hook)leds_toggle, 0); + timer_setDelay(&leds_timer, ms_to_ticks(100)); + timer_add(&leds_timer); + + /* + * Run process test. + */ + if(!proc_testRun()) + kfile_printf(&ser_fd.fd, "ProcTest..ok!\n"); + else + kfile_printf(&ser_fd.fd, "ProcTest..FAIL!\n"); + + + kputs(AT91SAM7_MSG); + // Main loop for(;;) {