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