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 2010 Develer S.r.l. (http://www.develer.com/)
33 * \brief LM3S1968 Cortex-M3 testcase
35 * \author Andrea Righi <arighi@develer.com>
39 #include <drv/timer.h>
41 #include <drv/lcd_rit128x96.h>
45 #include <icons/logo.h>
48 #include "cfg/compiler.h"
49 #include "cfg/cfg_gfx.h"
51 #include "hw/hw_rit128x96.h"
53 #define PROC_STACK_SIZE KERN_MINSTACKSIZE
58 #define ser_stack NULL
59 #define led_stack NULL
61 static PROC_DEFINE_STACK(hp_stack, PROC_STACK_SIZE);
62 static PROC_DEFINE_STACK(lp_stack, PROC_STACK_SIZE);
63 static PROC_DEFINE_STACK(ser_stack, PROC_STACK_SIZE);
64 static PROC_DEFINE_STACK(led_stack, PROC_STACK_SIZE);
67 extern Font font_helvB10;
68 static uint8_t raster[RAST_SIZE(LCD_WIDTH, LCD_HEIGHT)];
71 static Process *hp_proc, *lp_proc, *res_proc;
72 static hptime_t start, end;
74 static Serial ser_port;
76 static void led_init(void)
78 /* Enable the GPIO port that is used for the on-board LED */
79 SYSCTL_RCGC2_R = SYSCTL_RCGC2_GPIOG;
81 * Perform a dummy read to insert a few cycles delay before enabling
85 /* Enable the GPIO pin for the LED */
86 GPIO_PORTG_DIR_R = 0x04;
87 GPIO_PORTG_DEN_R = 0x04;
90 INLINE void led_on(void)
92 GPIO_PORTG_DATA_R |= 0x04;
95 INLINE void led_off(void)
97 GPIO_PORTG_DATA_R &= ~0x04;
100 static void NORETURN led_process(void)
114 static void NORETURN ser_process(void)
119 ser_init(&ser_port, SER_UART0);
120 ser_setbaudrate(&ser_port, 115200);
122 /* BeRTOS terminal */
125 kfile_printf(&ser_port.fd, "\n\r[%03d] BeRTOS:~$ ", i);
126 kfile_gets_echo(&ser_port.fd, buf, sizeof(buf), true);
127 kfile_printf(&ser_port.fd, "%s", buf);
131 INLINE hptime_t get_hp_ticks(void)
133 return (TIMER_HW_CNT - timer_hw_hpread()) +
134 timer_clock_unlocked() * TIMER_HW_CNT;
137 static void NORETURN res_process(void)
139 const char spinner[] = {'/', '-', '\\', '|'};
147 clock = timer_clock_unlocked();
149 /* Display uptime (in ticks) */
150 buffer[sizeof(buffer) - 1] = '\0';
151 snprintf(buffer, sizeof(buffer) - 1,
152 "uptime: %lu sec", clock / 1000);
153 text_xprintf(&bm, 2, 0, TEXT_FILL, buffer);
155 /* Show context switch (in clock cycles) */
156 c = spinner[i % countof(spinner)];
157 buffer[sizeof(buffer) - 1] = '\0';
158 snprintf(buffer, sizeof(buffer) - 1,
159 "%c Context switch %c", c, c);
160 text_xprintf(&bm, 4, 0, TEXT_CENTER | TEXT_FILL, buffer);
161 buffer[sizeof(buffer) - 1] = '\0';
162 snprintf(buffer, sizeof(buffer) - 1,
163 " %lu clock cycles", end - start);
164 text_xprintf(&bm, 6, 0, TEXT_FILL, buffer);
166 /* Show context switch (in usec) */
167 buffer[sizeof(buffer) - 1] = '\0';
168 snprintf(buffer, sizeof(buffer) - 1,
170 ((end - start) * 1000000) / CPU_FREQ,
171 ((end - start) * (100000000 / CPU_FREQ)) % 100);
172 text_xprintf(&bm, 7, 0, TEXT_FILL, buffer);
173 rit128x96_lcd_blitBitmap(&bm);
177 static void NORETURN hp_process(void)
182 end = get_hp_ticks();
184 sig_send(lp_proc, SIG_USER0);
188 static void NORETURN lp_process(void)
192 start = get_hp_ticks();
193 sig_send(hp_proc, SIG_USER0);
199 * Show the splash screen
201 static void bouncing_logo(Bitmap *bm)
203 const long SPEED_SCALE = 1000;
204 const long GRAVITY_ACCEL = 100;
205 const long BOUNCE_ELASTICITY = 2;
206 const long TOT_FRAMES = 100;
207 long h = (long)(-bertos_logo.height) * SPEED_SCALE;
210 for (i = 0; i < TOT_FRAMES; i++)
215 /* Gravity acceleration */
216 speed += GRAVITY_ACCEL;
218 if (h > 0 && speed > 0)
221 speed = -(speed / BOUNCE_ELASTICITY);
224 /* Update graphics */
227 (LCD_WIDTH - bertos_logo.width) / 2,
228 (LCD_HEIGHT - bertos_logo.height) / 2 + h / SPEED_SCALE,
230 rit128x96_lcd_blitBitmap(bm);
245 kputs("Init Timer..");
248 kputs("Init Process..");
251 kputs("Init OLED display..");
252 rit128x96_lcd_init();
253 gfx_bitmapInit(&bm, raster, LCD_WIDTH, LCD_HEIGHT);
254 gfx_setFont(&bm, &font_helvB10);
255 rit128x96_lcd_blitBitmap(&bm);
259 gfx_bitmapClear(&bm);
261 text_xprintf(&bm, 4, 0, TEXT_CENTER | TEXT_FILL, "BeRTOS up & running!");
262 rit128x96_lcd_blitBitmap(&bm);
265 snprintf(buffer, sizeof(buffer),
266 "CPU: Cortex-M3 %luMHz", CPU_FREQ / 1000000);
267 text_xprintf(&bm, 0, 0, TEXT_FILL, buffer);
268 rit128x96_lcd_blitBitmap(&bm);
269 text_xprintf(&bm, 1, 0, TEXT_FILL, "Board: LM3S1968 EVB");
270 rit128x96_lcd_blitBitmap(&bm);
272 hp_proc = proc_new(hp_process, NULL, PROC_STACK_SIZE, hp_stack);
273 lp_proc = proc_new(lp_process, NULL, PROC_STACK_SIZE, lp_stack);
274 proc_new(led_process, NULL, PROC_STACK_SIZE, led_stack);
275 proc_new(ser_process, NULL, PROC_STACK_SIZE, ser_stack);
277 res_proc = proc_current();
279 proc_setPri(hp_proc, 2);
280 proc_setPri(lp_proc, 1);