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>
54 #include <cpu/detect.h>
56 #include <drv/timer.h>
57 #include <drv/sysirq_at91.h>
71 int direction = FORWARD;
73 static void leds_init(void)
75 #if CPU_ARM_AT91SAM7X256
76 /* Set PB19..22 connected to PIOB */
78 /* Set PB19..22 as output */
81 /* Set PB19..22 to 1 to turn off leds */
84 /* turn first led on (PB19) */
86 #elif CPU_ARM_AT91SAM7S256
87 /* Set PA0..3 connected to PIOA */
88 PIOA_PER = 0x0000001f;
89 /* Set PA0..3 as output */
90 PIOA_OER = 0x0000001f;
92 /* Set PA0..3 to 1 to turn off leds */
93 PIOA_SODR = 0x0000000f;
94 /* turn first led on (PA0) */
95 PIOA_CODR = 0x00000001;
99 #if CPU_ARM_AT91SAM7X256
100 #define GET_PIO_STATUS() (~PIOB_ODSR & 0x780000)
101 #define LAST_LED 0x200000
102 #define FIRST_LED 0x100000
103 #define SET_PIO_BITS PIOB_SODR
104 #define CLEAR_PIO_BITS PIOB_CODR
105 #define AT91SAM7_MSG "BeRTOS is running on AT91SAM7X256..\n"
106 #elif CPU_ARM_AT91SAM7S256
107 #define GET_PIO_STATUS() (~PIOA_ODSR & 0x0000000f)
108 #define LAST_LED 0x00000004
109 #define FIRST_LED 0x00000002
110 #define SET_PIO_BITS PIOA_SODR
111 #define CLEAR_PIO_BITS PIOA_CODR
112 #define AT91SAM7_MSG "BeRTOS is running on AT91SAM7S256..\n"
116 * Knight Rider leds effect..
118 static void leds_toggle(void)
120 uint32_t led_status = GET_PIO_STATUS();
122 // Turn on led in forward direction
123 if (direction == FORWARD)
125 if(led_status == LAST_LED)
126 direction = BACKWARD;
128 SET_PIO_BITS = led_status;
129 CLEAR_PIO_BITS = led_status << 1;
131 // Turn on led in backward direction
132 else if (direction == BACKWARD)
134 if(led_status == FIRST_LED)
137 SET_PIO_BITS = led_status;
138 CLEAR_PIO_BITS = led_status >> 1;
141 /* Wait for interval time */
142 timer_setDelay(&leds_timer, ms_to_ticks(100));
143 timer_add(&leds_timer);
147 { char msg[]="BeRTOS, be fast be beatiful be realtime";
155 ASSERT(!IRQ_ENABLED());
157 /* Open the main communication port */
158 ser_init(&ser_fd, 0);
159 ser_setbaudrate(&ser_fd, 115200);
160 ser_setparity(&ser_fd, SER_PARITY_NONE);
163 ASSERT(IRQ_ENABLED());
166 * Register timer and arm timer interupt.
168 timer_setSoftint(&leds_timer, (Hook)leds_toggle, 0);
169 timer_setDelay(&leds_timer, ms_to_ticks(100));
170 timer_add(&leds_timer);
176 kfile_printf(&ser_fd.fd, "ProcTest..ok!\n");
178 kfile_printf(&ser_fd.fd, "ProcTest..FAIL!\n");
186 kfile_printf(&ser_fd.fd, "From serial 0: %s\r\n", msg);