Refactor BeRTOS to be in his own directory.
[bertos.git] / bertos / kern / proc_p.h
1 /**
2  * \file
3  * <!--
4  * This file is part of BeRTOS.
5  *
6  * Bertos is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19  *
20  * As a special exception, you may use this file as part of a free software
21  * library without restriction.  Specifically, if other files instantiate
22  * templates or use macros or inline functions from this file, or you compile
23  * this file and link it with other files to produce an executable, this
24  * file does not by itself cause the resulting executable to be covered by
25  * the GNU General Public License.  This exception does not however
26  * invalidate any other reasons why the executable file might be covered by
27  * the GNU General Public License.
28  *
29  * Copyright 2001, 2004 Develer S.r.l. (http://www.develer.com/)
30  * Copyright 1999, 2000, 2001 Bernardo Innocenti <bernie@develer.com>
31  *
32  * -->
33  *
34  * \brief Internal scheduler structures and definitions for processes.
35  *
36  * \version $Id$
37  *
38  * \author Bernardo Innocenti <bernie@develer.com>
39  */
40
41 #ifndef KERN_PROC_P_H
42 #define KERN_PROC_P_H
43
44 #include <cfg/compiler.h>
45 #include <cpu/types.h>        /* for cpu_stack_t */
46 #include <mware/list.h>
47 #include <config_kern.h>
48 #include <appconfig.h>
49
50 typedef struct Process
51 {
52         Node         link;        /**< Link Process into scheduler lists */
53         cpustack_t  *stack;       /**< Per-process SP */
54         iptr_t       user_data;   /**< Custom data passed to the process */
55
56 #if CONFIG_KERN_SIGNALS
57         sigmask_t    sig_wait;    /**< Signals the process is waiting for */
58         sigmask_t    sig_recv;    /**< Received signals */
59 #endif
60
61 #if CONFIG_KERN_PREEMPTIVE
62         int          forbid_cnt;  /**< Nesting count for proc_forbid()/proc_permit(). */
63 #endif
64
65 #if CONFIG_KERN_HEAP
66         uint16_t     flags;       /**< Flags */
67         cpustack_t  *stack_base;  /**< Base of process stack */
68         size_t       stack_size;  /**< Size of process stack */
69 #endif
70
71 #if CONFIG_KERN_MONITOR
72         struct ProcMonitor
73         {
74                 Node        link;
75                 const char *name;
76                 cpustack_t *stack_base;
77                 size_t      stack_size;
78         } monitor;
79 #endif
80
81 } Process;
82
83
84 /**
85  * \name Flags for Process.flags.
86  * \{
87  */
88 #define PF_FREESTACK  BV(0)  /**< Free the stack when process dies */
89 /*\}*/
90
91
92 /** Track running processes. */
93 extern REGISTER Process *CurrentProcess;
94
95 /** Track ready processes. */
96 extern REGISTER List     ProcReadyList;
97
98
99 /** Enqueue a task in the ready list. */
100 #define SCHED_ENQUEUE(proc)  ADDTAIL(&ProcReadyList, &(proc)->link)
101
102 /** Schedule to another process *without* adding the current to the ready list. */
103 void proc_schedule(void);
104
105 #if CONFIG_KERN_MONITOR
106         /** Initialize the monitor */
107         void monitor_init(void);
108
109         /** Register a process into the monitor */
110         void monitor_add(Process *proc, const char *name, cpustack_t *stack, size_t stacksize);
111
112         /** Unregister a process from the monitor */
113         void monitor_remove(Process *proc);
114
115         /** Rename a process */
116         void monitor_rename(Process *proc, const char* name);
117 #endif /* CONFIG_KERN_MONITOR */
118
119 #endif /* KERN_PROC_P_H */
120