4 * This file is part of BeRTOS.
6 * Bertos is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 * As a special exception, you may use this file as part of a free software
21 * library without restriction. Specifically, if other files instantiate
22 * templates or use macros or inline functions from this file, or you compile
23 * this file and link it with other files to produce an executable, this
24 * file does not by itself cause the resulting executable to be covered by
25 * the GNU General Public License. This exception does not however
26 * invalidate any other reasons why the executable file might be covered by
27 * the GNU General Public License.
29 * Copyright 2009 Develer S.r.l. (http://www.develer.com/)
35 * \author Francesco Sacchi <batt@develer.com>
36 * \author Daniele Basile <asterix@develer.com>
38 * \brief Simple BeRTOS test on AT91SAM7X-EK evaluation board.
40 * This short program shows you a simple demo of some BeRTOS feature:
45 * - Cooperative BeRTOS Kernel
49 #include "cfg/cfg_ser.h"
50 #include <cfg/macros.h>
52 #include <kern/proc.h>
53 #include <kern/signal.h>
55 #include <cpu/detect.h>
57 #include <drv/timer.h>
58 #include <drv/sysirq_at91.h>
72 int direction = FORWARD;
74 static void leds_init(void)
76 #if CPU_ARM_AT91SAM7X256
77 /* Set PB19..22 connected to PIOB */
79 /* Set PB19..22 as output */
82 /* Set PB19..22 to 1 to turn off leds */
85 /* turn first led on (PB19) */
87 #elif CPU_ARM_AT91SAM7S256
88 /* Set PA0..3 connected to PIOA */
89 PIOA_PER = 0x0000001f;
90 /* Set PA0..3 as output */
91 PIOA_OER = 0x0000001f;
93 /* Set PA0..3 to 1 to turn off leds */
94 PIOA_SODR = 0x0000000f;
95 /* turn first led on (PA0) */
96 PIOA_CODR = 0x00000001;
100 #if CPU_ARM_AT91SAM7X256
101 #define GET_PIO_STATUS() (~PIOB_ODSR & 0x780000)
102 #define LAST_LED 0x200000
103 #define FIRST_LED 0x100000
104 #define SET_PIO_BITS PIOB_SODR
105 #define CLEAR_PIO_BITS PIOB_CODR
106 #define AT91SAM7_MSG "BeRTOS is running on AT91SAM7X256..\n"
107 #elif CPU_ARM_AT91SAM7S256
108 #define GET_PIO_STATUS() (~PIOA_ODSR & 0x0000000f)
109 #define LAST_LED 0x00000004
110 #define FIRST_LED 0x00000002
111 #define SET_PIO_BITS PIOA_SODR
112 #define CLEAR_PIO_BITS PIOA_CODR
113 #define AT91SAM7_MSG "BeRTOS is running on AT91SAM7S256..\n"
117 * Knight Rider leds effect..
119 static void leds_toggle(void)
121 uint32_t led_status = GET_PIO_STATUS();
123 // Turn on led in forward direction
124 if (direction == FORWARD)
126 if(led_status == LAST_LED)
127 direction = BACKWARD;
129 SET_PIO_BITS = led_status;
130 CLEAR_PIO_BITS = led_status << 1;
132 // Turn on led in backward direction
133 else if (direction == BACKWARD)
135 if(led_status == FIRST_LED)
138 SET_PIO_BITS = led_status;
139 CLEAR_PIO_BITS = led_status >> 1;
142 /* Wait for interval time */
143 timer_setDelay(&leds_timer, ms_to_ticks(100));
144 timer_add(&leds_timer);
148 { char msg[]="BeRTOS, be fast be beatiful be realtime";
156 ASSERT(!IRQ_ENABLED());
158 /* Open the main communication port */
159 ser_init(&ser_fd, 0);
160 ser_setbaudrate(&ser_fd, 115200);
161 ser_setparity(&ser_fd, SER_PARITY_NONE);
164 ASSERT(IRQ_ENABLED());
167 * Register timer and arm timer interupt.
169 timer_setSoftint(&leds_timer, (Hook)leds_toggle, 0);
170 timer_setDelay(&leds_timer, ms_to_ticks(100));
171 timer_add(&leds_timer);
177 kfile_printf(&ser_fd.fd, "ProcTest..ok!\n");
179 kfile_printf(&ser_fd.fd, "ProcTest..FAIL!\n");
183 if(!signal_testRun())
184 kfile_printf(&ser_fd.fd, "SignalTest..ok!\n");
186 kfile_printf(&ser_fd.fd, "SignalTest..FAIL!\n");
193 kfile_printf(&ser_fd.fd, "From serial 0: %s\r\n", msg);