9ab3dcbf1f24eb4e808d1e1b22c897950a4a8884
[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 README.devlib 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.16  2006/07/19 12:56:27  bernie
19  *#* Convert to new Doxygen style.
20  *#*
21  *#* Revision 1.15  2005/11/27 23:36:19  bernie
22  *#* Use appconfig.h instead of cfg/config.h.
23  *#*
24  *#* Revision 1.14  2005/11/04 16:20:02  bernie
25  *#* Fix reference to README.devlib in header.
26  *#*
27  *#* Revision 1.13  2005/04/11 19:10:28  bernie
28  *#* Include top-level headers from cfg/ subdir.
29  *#*
30  *#* Revision 1.12  2004/12/08 08:57:35  bernie
31  *#* Rename sigset_t to sigmask_t.
32  *#*
33  *#* Revision 1.11  2004/11/16 22:37:14  bernie
34  *#* Replace IPTR with iptr_t.
35  *#*
36  *#* Revision 1.10  2004/10/19 11:47:07  bernie
37  *#* Add missing #endif.
38  *#*
39  *#* Revision 1.9  2004/10/19 08:55:31  bernie
40  *#* Define forbid_cnt.
41  *#*
42  *#* Revision 1.8  2004/10/03 20:39:28  bernie
43  *#* Import changes from sc/firmware.
44  *#*
45  *#* Revision 1.7  2004/08/25 14:12:09  rasky
46  *#* Aggiornato il comment block dei log RCS
47  *#*
48  *#* Revision 1.6  2004/08/24 16:05:15  bernie
49  *#* Add missing headers; Reformat.
50  *#*
51  *#* Revision 1.5  2004/08/14 19:37:57  rasky
52  *#* Merge da SC: macros.h, pool.h, BIT_CHANGE, nome dei processi, etc.
53  *#*
54  *#* Revision 1.4  2004/07/30 14:24:16  rasky
55  *#* Task switching con salvataggio perfetto stato di interrupt (SR)
56  *#* Kernel monitor per dump informazioni su stack dei processi
57  *#*
58  *#* Revision 1.3  2004/07/14 14:18:09  rasky
59  *#* Merge da SC: Rimosso timer dentro il task, che รจ uno spreco di memoria per troppi task
60  *#*
61  *#* Revision 1.2  2004/06/03 11:27:09  bernie
62  *#* Add dual-license information.
63  *#*
64  *#* Revision 1.1  2004/05/23 17:27:00  bernie
65  *#* Import kern/ subdirectory.
66  *#*
67  *#* Revision 1.3  2004/05/14 12:52:13  rasky
68  *#* Importato supporto kernel per AVR da Stefano
69  *#*
70  *#* Revision 1.2  2004/04/28 16:13:49  rasky
71  *#* proc_schedule() is now semi-private (used only within the kernel)
72  *#*
73  *#* Revision 1.1  2004/04/26 18:02:40  rasky
74  *#* Importato microkernel
75  *#*
76  *#* Revision 1.1  2004/04/04 17:40:26  aleph
77  *#* Add multithreading kernel
78  *#*
79  *#*/
80 #ifndef KERN_PROC_P_H
81 #define KERN_PROC_P_H
82
83 #include <cfg/compiler.h>
84 #include <cfg/cpu.h>        /* for cpu_stack_t */
85 #include <mware/list.h>
86 #include <config_kern.h>
87 #include <appconfig.h>
88
89 typedef struct Process
90 {
91         Node         link;        /**< Link Process into scheduler lists */
92         cpustack_t  *stack;       /**< Per-process SP */
93         iptr_t       user_data;   /**< Custom data passed to the process */
94
95 #if CONFIG_KERN_SIGNALS
96         sigmask_t    sig_wait;    /**< Signals the process is waiting for */
97         sigmask_t    sig_recv;    /**< Received signals */
98 #endif
99
100 #if CONFIG_KERN_PREEMPTIVE
101         int          forbid_cnt;  /**< Nesting count for proc_forbid()/proc_permit(). */
102 #endif
103
104 #if CONFIG_KERN_HEAP
105         uint16_t     flags;       /**< Flags */
106         cpustack_t  *stack_base;  /**< Base of process stack */
107         size_t       stack_size;  /**< Size of process stack */
108 #endif
109
110 #if CONFIG_KERN_MONITOR
111         struct ProcMonitor
112         {
113                 Node        link;
114                 const char *name;
115                 cpustack_t *stack_base;
116                 size_t      stack_size;
117         } monitor;
118 #endif
119
120 } Process;
121
122
123 /**
124  * \name Flags for Process.flags.
125  * \{
126  */
127 #define PF_FREESTACK  BV(0)  /**< Free the stack when process dies */
128 /*\}*/
129
130
131 /** Track running processes. */
132 extern REGISTER Process *CurrentProcess;
133
134 /** Track ready processes. */
135 extern REGISTER List     ProcReadyList;
136
137
138 /** Enqueue a task in the ready list. */
139 #define SCHED_ENQUEUE(proc)  ADDTAIL(&ProcReadyList, &(proc)->link)
140
141 /** Schedule to another process *without* adding the current to the ready list. */
142 void proc_schedule(void);
143
144 #if CONFIG_KERN_MONITOR
145         /** Initialize the monitor */
146         void monitor_init(void);
147
148         /** Register a process into the monitor */
149         void monitor_add(Process *proc, const char *name, cpustack_t *stack, size_t stacksize);
150
151         /** Unregister a process from the monitor */
152         void monitor_remove(Process *proc);
153
154         /** Rename a process */
155         void monitor_rename(Process *proc, const char* name);
156 #endif /* CONFIG_KERN_MONITOR */
157
158 #endif /* KERN_PROC_P_H */
159