From: asterix Date: Wed, 12 May 2010 14:08:30 +0000 (+0000) Subject: Add switch context module. X-Git-Tag: 2.5.0~253 X-Git-Url: https://codewiz.org/gitweb?a=commitdiff_plain;h=8e9b1ada815064b18774695225d12986bc36bb10;p=bertos.git Add switch context module. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@3664 38d2e660-2303-0410-9eaa-f027e97ec537 --- diff --git a/bertos/benchmark/context_switch.c b/bertos/benchmark/context_switch.c new file mode 100644 index 00000000..92d9d9dc --- /dev/null +++ b/bertos/benchmark/context_switch.c @@ -0,0 +1,135 @@ +/** + * \file + * + * + * \brief Context switch benchmark + * + * \author Andrea Righi + * \author Daniele Basiele + */ + +#include "context_switch.h" + +#include "hw/hw_led.h" + +#include "cfg/cfg_context_switch.h" +#include + +#include +#include + +#include +#include + +#include + +#define PROC_STACK_SIZE 1024 + +static PROC_DEFINE_STACK(hp_stack, PROC_STACK_SIZE); +static PROC_DEFINE_STACK(lp_stack, PROC_STACK_SIZE); + +static Process *hp_proc, *lp_proc, *main_proc; +Serial out; + +#if CONFIG_USE_HP_TIMER + +static hptime_t start, end; + +#endif + +static void NORETURN hp_process(void) +{ + proc_setPri(hp_proc, 2); + + while (1) + { + sig_wait(SIG_USER0); + #if CONFIG_USE_HP_TIMER + end = timer_clock_hp(); + #endif + #if CONFIG_USE_LED + LED_ON(); + #endif + timer_delay(100); + sig_send(main_proc, SIG_USER1); + } +} + +static void NORETURN lp_process(void) +{ + proc_setPri(lp_proc, 1); + + while (1) + { + sig_wait(SIG_USER1); + #if CONFIG_USE_HP_TIMER + start = timer_clock_hp(); + #endif + #if CONFIG_USE_LED + LED_ON(); + LED_OFF(); + #endif + + sig_send(hp_proc, SIG_USER0); + } +} + + +void NORETURN context_switch(void) +{ + IRQ_ENABLE; + timer_init(); + proc_init(); + + ser_init(&out, CONFIG_CTX_DEBUG_PORT); + ser_setbaudrate(&out, CONFIG_CTX_DEBUG_BAUDRATE); + + #if CONFIG_USE_LED + LED_INIT(); + #endif + + hp_proc = proc_new(hp_process, NULL, PROC_STACK_SIZE, hp_stack); + lp_proc = proc_new(lp_process, NULL, PROC_STACK_SIZE, lp_stack); + main_proc = proc_current(); + + while (1) + { + #if CONFIG_USE_HP_TIMER + kfile_printf(&out.fd, "Switch: %lu.%lu usec\n", + hptime_to_us((end - start)), + hptime_to_us((end - start) * 1000) % 1000); + #endif + + sig_send(lp_proc, SIG_USER1); + sig_wait(SIG_USER1); + } + +} diff --git a/bertos/benchmark/context_switch.h b/bertos/benchmark/context_switch.h new file mode 100644 index 00000000..e17921ae --- /dev/null +++ b/bertos/benchmark/context_switch.h @@ -0,0 +1,49 @@ +/** + * \file + * + * + * \brief Context switch benchmark + * + * \author Andrea Righi + * \author Daniele Basiele + * + * $WIZ$ module_name = "context_switch" + * $WIZ$ module_depends = "kfile", "kern", "signal", "timer", "ser" + * $WIZ$ module_configuration = "bertos/cfg/cfg_context_switch.h" + * $WIZ$ module_hw = "bertos/hw/hw_led.h" + */ + +#ifndef BENCHMARK_CONTEXT_SWITCH_H +#define BENCHMARK_CONTEXT_SWITCH_H + +void context_switch(void); + +#endif /* BENCHMARK_CONTEXT_SWITCH_H */ diff --git a/bertos/cfg/cfg_context_switch.h b/bertos/cfg/cfg_context_switch.h new file mode 100644 index 00000000..05386929 --- /dev/null +++ b/bertos/cfg/cfg_context_switch.h @@ -0,0 +1,69 @@ +/** + * \file + * + * + * \brief Configuration file for the context switch benchmark. + * + * \author Daniele Basile + */ + +#ifndef CFG_CONTEXT_SWITCH_H +#define CFG_CONTEXT_SWITCH_H + +/** + * Use hp timer for the bechmark. + * + * $WIZ$ type = "boolean" + */ +#define CONFIG_USE_HP_TIMER 1 + + +/** + * Use board led for benchmark. + * + * $WIZ$ type = "boolean" + */ +#define CONFIG_USE_LED 1 + + +/** + * Debug console port. + * $WIZ$ type = "int"; min = 0 + */ +#define CONFIG_CTX_DEBUG_PORT 0 + +/** + * Baudrate for the debug console. + * $WIZ$ type = "int"; min = 300 + */ +#define CONFIG_CTX_DEBUG_BAUDRATE 115200UL + +#endif /* CFG_CONTEXT_SWITCH_H */