* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*
- * Copyright 2006 Develer S.r.l. (http://www.develer.com/)
- *
+ * Copyright 2006, 2008 Develer S.r.l. (http://www.develer.com/)
* -->
*
- * \version $Id: demo.c 18242 2007-10-08 17:35:23Z marco $
+ * \brief Multifunction system test for BeRTOS modules.
*
+ * \version $Id: demo.c 18242 2007-10-08 17:35:23Z marco $
* \author Bernie Innocenti <bernie@codewiz.org>
- *
- * \brief Windowing system test.
*/
#include <cfg/macros.h>
#include <emul/emul.h>
+#include <kern/irq.h>
#include <kern/proc.h>
#include <kern/msg.h>
int main(int argc, char *argv[])
{
emul_init(&argc, argv);
+ irq_init();
timer_init();
buz_init();
kbd_init();
TRG += demo
# FIXME: we want to use g++ for C source too
-CC = g++-4.1
-CXX = g++-4.1
+CC = g++-4.3
+CXX = g++-4.3
demo_CXXSRC = \
bertos/emul/emul.cpp \
bertos/mware/observer.c \
bertos/mware/resource.c \
bertos/mware/sprintf.c \
+ bertos/kern/irq.c \
+ bertos/kern/preempt.c \
bertos/kern/proc.c \
bertos/kern/proc_test.c \
- bertos/kern/preempt.c \
bertos/kern/sem.c \
bertos/kern/signal.c \
bertos/kern/monitor.c \
--- /dev/null
+/**
+ * \file
+ * <!--
+ * This file is part of BeRTOS.
+ *
+ * Bertos is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * As a special exception, you may use this file as part of a free software
+ * library without restriction. Specifically, if other files instantiate
+ * templates or use macros or inline functions from this file, or you compile
+ * this file and link it with other files to produce an executable, this
+ * file does not by itself cause the resulting executable to be covered by
+ * the GNU General Public License. This exception does not however
+ * invalidate any other reasons why the executable file might be covered by
+ * the GNU General Public License.
+ *
+ * Copyright 2008 Bernie Innocenti <bernie@codewiz.org>
+ * -->
+ *
+ * \brief Process scheduler (public interface).
+ *
+ * \version $Id: proc.h 1646 2008-08-17 13:49:48Z bernie $
+ * \author Bernie Innocenti <bernie@codewiz.org>
+ */
+#include "irq.h"
+
+#include <cfg/module.h>
+#include <kern/proc_p.h>
+
+#include <cfg/cfg_kern.h>
+
+#include <unistd.h> // FIXME: move POSIX stuff to irq_posix.h
+
+
+MOD_DEFINE(irq)
+
+// FIXME
+static void (*irq_handlers[100])(void);
+
+/* signal handler */
+void irq_entry(int signum)
+{
+ Process * const old_process = CurrentProcess;
+
+ irq_handlers[signum]();
+
+#if CONFIG_KERN_PREEMPT
+ if (!CurrentProcess)
+ {
+ TRACEMSG("no runnable processes!");
+ IRQ_ENABLE;
+ pause();
+ }
+ else
+ {
+ if (old_process != CurrentProcess)
+ {
+ TRACEMSG("switching from %p:%s to %p:%s",
+ old_process, old_process ? old_process->monitor.name : "-",
+ CurrentProcess, CurrentProcess->monitor.name);
+
+ if (old_process)
+ swapcontext(&old_process->context, &CurrentProcess->context);
+ else
+ setcontext(&CurrentProcess->context);
+
+ // not reached
+ }
+ TRACEMSG("keeping %p:%s", CurrentProcess, CurrentProcess->monitor.name);
+ }
+#endif // CONFIG_KERN_PREEMPT
+}
+
+void irq_register(int irq, void (*callback)(void))
+{
+ irq_handlers[irq] = callback;
+}
+
+void irq_init(void)
+{
+ struct sigaction act;
+ act.sa_handler = irq_entry;
+ sigemptyset(&act.sa_mask);
+ //sigaddset(&act.sa_mask, irq);
+ act.sa_flags = SA_RESTART; // | SA_SIGINFO;
+
+ sigaction(SIGUSR1, &act, NULL);
+ #if !(ARCH & ARCH_QT)
+ sigaction(SIGALRM, &act, NULL);
+ #endif
+
+ MOD_INIT(irq);
+}
--- /dev/null
+/**
+ * \file
+ * <!--
+ * This file is part of BeRTOS.
+ *
+ * Bertos is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * As a special exception, you may use this file as part of a free software
+ * library without restriction. Specifically, if other files instantiate
+ * templates or use macros or inline functions from this file, or you compile
+ * this file and link it with other files to produce an executable, this
+ * file does not by itself cause the resulting executable to be covered by
+ * the GNU General Public License. This exception does not however
+ * invalidate any other reasons why the executable file might be covered by
+ * the GNU General Public License.
+ *
+ * Copyright 2008 Bernie Innocenti <bernie@codewiz.org>
+ * -->
+ *
+ * \brief Process scheduler (public interface).
+ *
+ * \version $Id: proc.h 1646 2008-08-17 13:49:48Z bernie $
+ * \author Bernie Innocenti <bernie@codewiz.org>
+ */
+#ifndef KERN_IRQ_H
+#define KERN_IRQ_H
+
+void irq_entry(int irq);
+void irq_register(int irq, void (*handler)(void));
+void irq_init();
+
+#endif // KERN_IRQ_H
#include "proc_p.h"
#include "proc.h"
+#include <kern/irq.h>
#include <cpu/frame.h> // CPU_IDLE
#include <drv/timer.h>
+#include <cfg/module.h>
/*
--CurrentProcess->forbid_cnt;
}
-static void (*irq_handlers[100])(void); // FIXME
-
void proc_preempt(void)
{
proc_exit();
}
-/* signal handler */
-void irq_entry(int signum)
-{
- Process * const old_process = CurrentProcess;
-
- irq_handlers[signum]();
-
- if (!CurrentProcess)
- {
- TRACEMSG("no runnable processes!");
- IRQ_ENABLE;
- pause();
- }
- else
- {
- if (old_process != CurrentProcess)
- {
- TRACEMSG("switching from %p:%s to %p:%s",
- old_process, old_process ? old_process->monitor.name : "-",
- CurrentProcess, CurrentProcess->monitor.name);
-
- if (old_process)
- swapcontext(&old_process->context, &CurrentProcess->context);
- else
- setcontext(&CurrentProcess->context);
-
- /* not reached */
- }
- TRACEMSG("keeping %p:%s", CurrentProcess, CurrentProcess->monitor.name);
- }
-}
-
-void irq_register(int irq, void (*callback)(void))
-{
- irq_handlers[irq] = callback;
-}
-
-void irq_init(void)
-{
- struct sigaction act;
- act.sa_handler = irq_entry;
- sigemptyset(&act.sa_mask);
- //sigaddset(&act.sa_mask, irq);
- act.sa_flags = SA_RESTART; /* | SA_SIGINFO; */
-
- sigaction(SIGUSR1, &act, NULL);
- #if !(ARCH & ARCH_QT)
- sigaction(SIGALRM, &act, NULL);
- #endif
-}
-
void preempt_init(void)
{
- irq_init(); // FIXME: move before
+ MOD_CHECK(irq);
+ MOD_CHECK(timer);
+
irq_register(SIGUSR1, proc_preempt);
- timer_setSoftInt(&preempt_timer, proc_preempt_timer, NULL);
+ timer_setSoftint(&preempt_timer, proc_preempt_timer, NULL);
timer_setDelay(&preempt_timer, CONFIG_KERN_QUANTUM);
timer_add(&preempt_timer);
}
struct Process *proc_new_with_name(UNUSED(const char *, name), void (*entry)(void), iptr_t data, size_t stack_size, cpustack_t *stack_base)
{
Process *proc;
- size_t i;
const size_t PROC_SIZE_WORDS = ROUND2(sizeof(Process), sizeof(cpustack_t)) / sizeof(cpustack_t);
#if CONFIG_KERN_HEAP
bool free_stack = false;
#endif
#endif
-#if CONFIG_KERN_PREEMPT
- // FIXME: proc_exit
- getcontext(&proc->context);
- proc->context.uc_stack.ss_sp = stack_base;
- proc->context.uc_stack.ss_size = stack_size;
- proc->context.uc_link = NULL;
- makecontext(&proc->context, (void (*)(void))proc_entry, 1, entry);
-
-#else // !CONFIG_KERN_PREEMPT
- /* Initialize process stack frame */
- CPU_PUSH_CALL_FRAME(proc->stack, proc_exit);
- CPU_PUSH_CALL_FRAME(proc->stack, entry);
-
- /* Push a clean set of CPU registers for asm_switch_context() */
- for (i = 0; i < CPU_SAVED_REGS_CNT; i++)
- CPU_PUSH_WORD(proc->stack, CPU_REG_INIT_VALUE(i));
-
- /* Add to ready list */
- ATOMIC(SCHED_ENQUEUE(proc));
- ATOMIC(LIST_ASSERT_VALID(&ProcReadyList));
-#endif // CONFIG_KERN_PREEMPT
+ #if CONFIG_KERN_PREEMPT
+ // FIXME: proc_exit
+ getcontext(&proc->context);
+ proc->context.uc_stack.ss_sp = stack_base;
+ proc->context.uc_stack.ss_size = stack_size;
+ proc->context.uc_link = NULL;
+ makecontext(&proc->context, (void (*)(void))proc_entry, 1, entry);
-#if CONFIG_KERN_MONITOR
- monitor_add(proc, name);
-#endif
+ #else // !CONFIG_KERN_PREEMPT
+ {
+ size_t i;
+
+ /* Initialize process stack frame */
+ CPU_PUSH_CALL_FRAME(proc->stack, proc_exit);
+ CPU_PUSH_CALL_FRAME(proc->stack, entry);
+
+ /* Push a clean set of CPU registers for asm_switch_context() */
+ for (i = 0; i < CPU_SAVED_REGS_CNT; i++)
+ CPU_PUSH_WORD(proc->stack, CPU_REG_INIT_VALUE(i));
+
+ /* Add to ready list */
+ ATOMIC(SCHED_ENQUEUE(proc));
+ ATOMIC(LIST_ASSERT_VALID(&ProcReadyList));
+ }
+ #endif // CONFIG_KERN_PREEMPT
+
+ #if CONFIG_KERN_MONITOR
+ monitor_add(proc, name);
+ #endif
return proc;
}
* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*
- * Copyright 2001,2004 Develer S.r.l. (http://www.develer.com/)
- * Copyright 1999,2000,2001 Bernie Innocenti <bernie@codewiz.org>
- *
+ * Copyright 2001, 2004 Develer S.r.l. (http://www.develer.com/)
+ * Copyright 1999, 2000, 2001, 2008 Bernie Innocenti <bernie@codewiz.org>
* -->
*
* \brief Process scheduler (public interface).
*
* \version $Id$
- *
* \author Bernie Innocenti <bernie@codewiz.org>
*/
#ifndef KERN_PROC_H
#error No cpustack_t size supported!
#endif
#endif
-#endif /* KERN_PROC_H */
+#endif /* KERN_PROC_H */