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 Context switch benchmark
35 * \author Andrea Righi <arighi@develer.com>
36 * \author Daniele Basiele <asterix@develer.com>
39 #include "context_switch.h"
41 #include "hw/hw_led.h"
43 #include "cfg/cfg_context_switch.h"
44 #include <cfg/debug.h>
47 #include <cpu/power.h>
49 #include <drv/timer.h>
50 #if CONFIG_USE_HP_TIMER
55 #include <kern/proc.h>
57 #define PROC_STACK_SIZE KERN_MINSTACKSIZE
59 static PROC_DEFINE_STACK(hp_stack, PROC_STACK_SIZE);
60 static PROC_DEFINE_STACK(lp_stack, PROC_STACK_SIZE);
62 static Process *hp_proc, *lp_proc, *main_proc;
63 #if CONFIG_USE_HP_TIMER
64 static hptime_t start, end;
67 static void NORETURN hp_process(void)
75 #if CONFIG_USE_HP_TIMER
76 end = timer_hw_hpread();
78 sig_send(main_proc, SIG_USER0);
82 static void NORETURN lp_process(void)
91 #if CONFIG_USE_HP_TIMER
92 start = timer_hw_hpread();
94 sig_send(hp_proc, SIG_USER0);
99 void NORETURN context_switch(void)
105 #if CONFIG_USE_HP_TIMER
106 ser_init(&out, CONFIG_CTX_DEBUG_PORT);
107 ser_setbaudrate(&out, CONFIG_CTX_DEBUG_BAUDRATE);
115 hp_proc = proc_new(hp_process, NULL, PROC_STACK_SIZE, hp_stack);
116 lp_proc = proc_new(lp_process, NULL, PROC_STACK_SIZE, lp_stack);
117 main_proc = proc_current();
118 proc_setPri(hp_proc, 2);
119 proc_setPri(lp_proc, 1);
126 sig_send(lp_proc, SIG_USER0);
129 #if CONFIG_USE_HP_TIMER
130 kfile_printf(&out.fd,
131 "Switch: %lu.%lu usec\n\r",
132 hptime_to_us((end - start)),
133 hptime_to_us((end - start) * 1000) % 1000);