From 368b5a0d273a9dc64e06d28e073b2577ba4c06fe Mon Sep 17 00:00:00 2001 From: bernie Date: Fri, 22 Aug 2008 12:31:38 +0000 Subject: [PATCH] preempt: Move idle process to its own source file git-svn-id: https://src.develer.com/svnoss/bertos/trunk@1672 38d2e660-2303-0410-9eaa-f027e97ec537 --- app/demo/demo.mk | 5 ++-- bertos/kern/idle.c | 70 +++++++++++++++++++++++++++++++++++++++++++ bertos/kern/preempt.c | 30 ++++--------------- 3 files changed, 78 insertions(+), 27 deletions(-) create mode 100644 bertos/kern/idle.c diff --git a/app/demo/demo.mk b/app/demo/demo.mk index 51b71bd0..920f2a6a 100644 --- a/app/demo/demo.mk +++ b/app/demo/demo.mk @@ -1,10 +1,10 @@ # -# $Id: demo.mk 18234 2007-10-08 13:39:48Z rasky $ # Copyright 2003, 2004, 2005, 2006 Develer S.r.l. (http://www.develer.com/) -# All rights reserved. +# Copyright 2008 Bernie Innocenti # # Makefile fragment for DevLib demo application. # +# Version: $Id: demo.mk 18234 2007-10-08 13:39:48Z rasky $ # Author: Bernie Innocenti # @@ -52,6 +52,7 @@ demo_CSRC = \ bertos/mware/observer.c \ bertos/mware/resource.c \ bertos/mware/sprintf.c \ + bertos/kern/idle.c \ bertos/kern/irq.c \ bertos/kern/preempt.c \ bertos/kern/proc.c \ diff --git a/bertos/kern/idle.c b/bertos/kern/idle.c new file mode 100644 index 00000000..ede234c3 --- /dev/null +++ b/bertos/kern/idle.c @@ -0,0 +1,70 @@ +/** + * \file + * + * + * \brief Idle loop for preemptive scheduling + * + * \version $Id: proc.c 1616 2008-08-10 19:41:26Z bernie $ + * \author Bernie Innocenti + */ + +#include "proc.h" + +#include + + +static cpustack_t idle_stack[CONFIG_PROC_DEFSTACKSIZE / sizeof(cpustack_t)]; + +/** + * The idle process + * + * This process never dies and never sleeps. It's also quite lazy, apathic + * and sometimes even a little antisocial. + * + * Having an idle process costs us some stack space, but simplifies the + * interrupt-driven preemption logic because there is always a user + * context to which we can return. + * + * The idle process is not required for cooperative task switching. + */ +static NORETURN void idle(void) +{ + for (;;) + { + TRACE; + //monitor_report(); + proc_yield(); // FIXME: CPU_IDLE + } +} + +void idle_init(void) +{ + proc_new(idle, NULL, sizeof(idle_stack), idle_stack); +} diff --git a/bertos/kern/preempt.c b/bertos/kern/preempt.c index 756a38fe..cde33651 100644 --- a/bertos/kern/preempt.c +++ b/bertos/kern/preempt.c @@ -51,6 +51,10 @@ int preempt_forbid_cnt; Timer preempt_timer; +// fwd decl from idle.c +void idle_init(void); + + void proc_preempt(void) { IRQ_DISABLE; @@ -118,30 +122,6 @@ void proc_entry(void (*user_entry)(void)) proc_exit(); } - -static cpustack_t idle_stack[CONFIG_PROC_DEFSTACKSIZE / sizeof(cpustack_t)]; - -// FIXME: move this to kern/idle.c -/** - * The idle process - * - * This process never dies and never sleeps. It's also quite lazy, apathic - * and a bit antisocial. - * - * Having an idle process costs some stack space, but simplifies the - * interrupt-driven preemption logic because there is always a user - * context to which we can return. - */ -static NORETURN void idle(void) -{ - for (;;) - { - TRACE; - //monitor_report(); - proc_yield(); // FIXME: CPU_IDLE - } -} - void preempt_init(void) { MOD_CHECK(irq); @@ -153,5 +133,5 @@ void preempt_init(void) timer_setDelay(&preempt_timer, CONFIG_KERN_QUANTUM); timer_add(&preempt_timer); - proc_new(idle, NULL, sizeof(idle_stack), idle_stack); + idle_init(); } -- 2.25.1