Import changes from sc/firmware.
[bertos.git] / kern / proc_p.h
1 /*!
2  * \file
3  * <!--
4  * Copyright 2001, 2004 Develer S.r.l. (http://www.develer.com/)
5  * Copyright 1999, 2000, 2001 Bernardo Innocenti <bernie@develer.com>
6  * This file is part of DevLib - See devlib/README for information.
7  * -->
8  *
9  * \brief Internal scheduler structures and definitions for processes.
10  *
11  * \version $Id$
12  *
13  * \author Bernardo Innocenti <bernie@develer.com>
14  */
15
16 /*#*
17  *#* $Log$
18  *#* Revision 1.8  2004/10/03 20:39:28  bernie
19  *#* Import changes from sc/firmware.
20  *#*
21  *#* Revision 1.7  2004/08/25 14:12:09  rasky
22  *#* Aggiornato il comment block dei log RCS
23  *#*
24  *#* Revision 1.6  2004/08/24 16:05:15  bernie
25  *#* Add missing headers; Reformat.
26  *#*
27  *#* Revision 1.5  2004/08/14 19:37:57  rasky
28  *#* Merge da SC: macros.h, pool.h, BIT_CHANGE, nome dei processi, etc.
29  *#*
30  *#* Revision 1.4  2004/07/30 14:24:16  rasky
31  *#* Task switching con salvataggio perfetto stato di interrupt (SR)
32  *#* Kernel monitor per dump informazioni su stack dei processi
33  *#*
34  *#* Revision 1.3  2004/07/14 14:18:09  rasky
35  *#* Merge da SC: Rimosso timer dentro il task, che รจ uno spreco di memoria per troppi task
36  *#*
37  *#* Revision 1.2  2004/06/03 11:27:09  bernie
38  *#* Add dual-license information.
39  *#*
40  *#* Revision 1.1  2004/05/23 17:27:00  bernie
41  *#* Import kern/ subdirectory.
42  *#*
43  *#* Revision 1.3  2004/05/14 12:52:13  rasky
44  *#* Importato supporto kernel per AVR da Stefano
45  *#*
46  *#* Revision 1.2  2004/04/28 16:13:49  rasky
47  *#* proc_schedule() is now semi-private (used only within the kernel)
48  *#*
49  *#* Revision 1.1  2004/04/26 18:02:40  rasky
50  *#* Importato microkernel
51  *#*
52  *#* Revision 1.1  2004/04/04 17:40:26  aleph
53  *#* Add multithreading kernel
54  *#*
55  *#*/
56 #ifndef KERN_PROC_P_H
57 #define KERN_PROC_P_H
58
59 #include "compiler.h"
60 #include "cpu.h"        /* for cpu_stack_t */
61 #include "config.h"
62 #include "config_kern.h"
63 #include <mware/list.h>
64
65 typedef struct Process
66 {
67         Node         link;        /*!< Link Process into scheduler lists */
68         cpustack_t  *stack;       /*!< Per-process SP */
69         IPTR         user_data;   /*!< Custom data passed to the process */
70
71 #if CONFIG_KERN_SIGNALS
72         sigset_t     sig_wait;    /*!< Signals the process is waiting for */
73         sigset_t     sig_recv;    /*!< Received signals */
74 #endif
75
76 #if CONFIG_KERN_HEAP
77         uint16_t     flags;       /*!< Flags */
78         cpustack_t  *stack_base;  /*!< Base of process stack */
79         size_t       stack_size;  /*!< Size of process stack */
80 #endif
81
82 #if CONFIG_KERN_MONITOR
83         struct ProcMonitor
84         {
85                 Node        link;
86                 const char *name;
87                 cpustack_t *stack_base;
88                 size_t      stack_size;
89         } monitor;
90 #endif
91
92 } Process;
93
94
95 /*!
96  * \name Flags for Process.flags
97  * \{
98  */
99 #define PF_FREESTACK  BV(0)  /*!< Free the stack when process dies */
100 /*\}*/
101
102
103 /*! Track running processes */
104 extern REGISTER Process *CurrentProcess;
105
106 /*! Track ready processes */
107 extern REGISTER List     ProcReadyList;
108
109
110 /*!
111  * Enqueue a task in the ready list
112  */
113 #define SCHED_ENQUEUE(proc)  ADDTAIL(&ProcReadyList, &(proc)->link)
114
115 /*! Schedule to another process *without* adding the current to the ready list */
116 void proc_schedule(void);
117
118 #if CONFIG_KERN_MONITOR
119         /*! Initialize the monitor */
120         void monitor_init(void);
121
122         /*! Register a process into the monitor */
123         void monitor_add(Process *proc, const char *name, cpustack_t *stack, size_t stacksize);
124
125         /*! Deregister a process from the monitor */
126         void monitor_remove(Process *proc);
127 #endif /* CONFIG_KERN_MONITOR */
128
129 #endif /* KERN_PROC_P_H */
130