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