comparison src/nucleus/tcd.c @ 7:0f80e1e4dce4

src/nucleus: library C code import from FreeNucleus package
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 15 Jul 2018 20:57:33 +0000
parents
children
comparison
equal deleted inserted replaced
6:8b2a9a374324 7:0f80e1e4dce4
1 /*************************************************************************/
2 /* */
3 /* Copyright Mentor Graphics Corporation 2002 */
4 /* All Rights Reserved. */
5 /* */
6 /* THIS WORK CONTAINS TRADE SECRET AND PROPRIETARY INFORMATION WHICH IS */
7 /* THE PROPERTY OF MENTOR GRAPHICS CORPORATION OR ITS LICENSORS AND IS */
8 /* SUBJECT TO LICENSE TERMS. */
9 /* */
10 /*************************************************************************/
11
12 /*************************************************************************/
13 /* */
14 /* FILE NAME VERSION */
15 /* */
16 /* tcd.c Nucleus PLUS 1.14 */
17 /* */
18 /* COMPONENT */
19 /* */
20 /* TC - Thread Control */
21 /* */
22 /* DESCRIPTION */
23 /* */
24 /* This file contains global data structures for use within this */
25 /* component. */
26 /* */
27 /* DATA STRUCTURES */
28 /* */
29 /* TCD_Created_Tasks_List Pointer to the linked-list */
30 /* of created tasks */
31 /* TCD_Total_Tasks Total number of created tasks*/
32 /* TCD_Priority_List Array of pointers to ready */
33 /* tasks, indexed by priority */
34 /* TCD_Execute_Task Highest priority task to */
35 /* execute */
36 /* TCD_Priority_Groups Bit map of 32 groups of task */
37 /* priority */
38 /* TCD_Sub_Priority_Groups An array of 32 sub-priority */
39 /* groups */
40 /* TCD_Lowest_Set_Bit Lookup table to find the */
41 /* lowest bit set in a byte */
42 /* TCD_Highest_Priority Highest priority ready */
43 /* TCD_Created_HISRs_List Pointer to the linked-list */
44 /* of created HISRs */
45 /* TCD_Total_HISRs Total number of created HISRs*/
46 /* TCD_Active_HISR_Heads Active HISR list head ptrs */
47 /* TCD_Active_HISR_Tails Active HISR list tail ptrs */
48 /* TCD_Execute_HISR Highest priority HISR to */
49 /* execute */
50 /* TCD_Current_Thread Pointer to the currently */
51 /* executing thread */
52 /* TCD_Registered_LISRs List of registered LISRs */
53 /* TCD_LISR_Pointers Actual LISR pointers */
54 /* TCD_Interrupt_Count Count of ISRs in progress */
55 /* TCD_Stack_Switched Flag indicating that stack */
56 /* was switched in an ISR */
57 /* TCD_List_Protect Task list protection */
58 /* TCD_System_Protect System protection */
59 /* TCD_System_Stack System stack pointer - top */
60 /* TCD_LISR_Protect Protect LISR registration */
61 /* TCD_HISR_Protect Protect the list of created */
62 /* HISRs */
63 /* TCD_Interrupt_Level Enable interrupt level */
64 /* TCD_Unhandled_Interrupt Contains the most recent */
65 /* unhandled interrupt in */
66 /* system error conditions */
67 /* */
68 /* FUNCTIONS */
69 /* */
70 /* None */
71 /* */
72 /* DEPENDENCIES */
73 /* */
74 /* cs_defs.h Common Service constants */
75 /* tc_defs.h Thread Control constants */
76 /* */
77 /* HISTORY */
78 /* */
79 /* DATE REMARKS */
80 /* */
81 /* 03-01-1993 Created initial version 1.0 */
82 /* 04-19-1993 Verified version 1.0 */
83 /* 01-01-1993 Added variable to save last */
84 /* unhandled interrupt in system */
85 /* error conditions, resulting in */
86 /* version 1.0a */
87 /* 11-01-1993 Verified version 1.0a */
88 /* 03-01-1994 Change schedule protection to a */
89 /* system protection to improve */
90 /* performance, resulting in */
91 /* version 1.1 */
92 /* */
93 /* 03-18-1994 Verified version 1.1 */
94 /* 04-17-1996 updated to version 1.2 */
95 /* 03-24-1998 Released version 1.3. */
96 /* 03-26-1999 Released 1.11m (new release */
97 /* numbering scheme) */
98 /* 04-23-2001 Made TCD_LISR_Pointers array an exclusive count */
99 /* 04-17-2002 Released version 1.13m */
100 /* 11-07-2002 Released version 1.14 */
101 /*************************************************************************/
102 #define NU_SOURCE_FILE
103
104 #include "cs_defs.h" /* Common Service constants */
105 #include "tc_defs.h" /* Thread Control constants */
106
107
108 /* TCD_Created_Tasks_List is the head pointer of the linked list of
109 created tasks. If the list is NU_NULL, there are no tasks created. */
110
111 CS_NODE *TCD_Created_Tasks_List;
112
113
114 /* TCD_Total_Tasks contains the number of currently created tasks. */
115
116 UNSIGNED TCD_Total_Tasks;
117
118
119 /* TCD_Priority_List is an array of TCB pointers. Each element of the array
120 is effectively the head pointer of the list of tasks ready for execution
121 at that priority. If the pointer is NULL, there are no tasks ready
122 for execution at that priority. The array is indexed by priority. */
123
124 TC_TCB *TCD_Priority_List[TC_PRIORITIES];
125
126
127 /* TCD_Priority_Groups is a 32-bit unsigned integer that is used as a bit
128 map. Each bit corresponds to an 8-priority group. For example, if bit 0
129 is set, at least one task of priority 0 through 8 is ready for execution. */
130
131 UNSIGNED TCD_Priority_Groups;
132
133
134 /* TCD_Sub_Priority_Groups is an array of sub-priority groups. These are
135 also used as bit maps. Index 0 of this array corresponds to priorities
136 0 through 8. Bit 0 of this element represents priority 0, while bit 7
137 represents priority 7. */
138
139 DATA_ELEMENT TCD_Sub_Priority_Groups[TC_MAX_GROUPS];
140
141
142 /* TCD_Lowest_Set_Bit is nothing more than a standard lookup table. The
143 table is indexed by values ranging from 1 to 255. The value at that
144 position in the table indicates the number of the lowest set bit. This is
145 used to determine the highest priority task represented in the previously
146 defined bit maps. */
147
148 UNSIGNED_CHAR TCD_Lowest_Set_Bit[] = {0,
149 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 4, 0, 1, 0, 2, 0, 1, 0, 3, 0,
150 1, 0, 2, 0, 1, 0, 5, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 4, 0, 1,
151 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 6, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0,
152 2, 0, 1, 0, 4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 5, 0, 1, 0, 2,
153 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0,
154 1, 0, 7, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 4, 0, 1, 0, 2, 0, 1,
155 0, 3, 0, 1, 0, 2, 0, 1, 0, 5, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
156 4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 6, 0, 1, 0, 2, 0, 1, 0, 3,
157 0, 1, 0, 2, 0, 1, 0, 4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 5, 0,
158 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1,
159 0, 2, 0, 1, 0};
160
161
162 /* TCD_Highest_Priority contains the highest priority task ready for execution.
163 Note that this does not necessarily represent the priority of the currently
164 executing task. This is true if the currently executing task has preemption
165 disabled. If no tasks are executing, this variable is set to the maximum
166 priority. */
167
168 INT TCD_Highest_Priority;
169
170
171 /* TCD_Execute_Task is a pointer to the task to execute. Note that this
172 pointer does not necessarily point to the currently executing task. There
173 are several points in the system where this is true. One situation is
174 when preemption is about to take place. Another situation can result from
175 a internal protection conflict. */
176
177 TC_TCB *TCD_Execute_Task;
178
179
180 /* TCD_Created_HISRs_List is the head pointer of the list of created High-
181 Level Interrupt Service Routines (HISR). If this pointer is NU_NULL, there
182 are no HISRs currently created. */
183
184 CS_NODE *TCD_Created_HISRs_List;
185
186
187 /* TCD_Total_HISRs contains the number of currently created HISRs. */
188
189 UNSIGNED TCD_Total_HISRs;
190
191
192 /* TCD_Active_HISR_Heads is an array of active HISR list head pointers.
193 There are three HISR priorities available. The HISR priority is an index
194 into this table. Priority/index 0 represents the highest priority. */
195
196 TC_HCB *TCD_Active_HISR_Heads[TC_HISR_PRIORITIES];
197
198
199 /* TCD_Active_HISR_Tails is an array of active HISR list tail pointers.
200 There are three HISR priorities available. The HISR priority is an index
201 into this table. Priority/index 0 represents the highest priority. */
202
203 TC_HCB *TCD_Active_HISR_Tails[TC_HISR_PRIORITIES];
204
205
206 /* TCD_Execute_HISR contains a pointer to the highest priority HISR to execute.
207 If this pointer is NU_NULL, no HISRs are currently activated. Note that
208 the current thread pointer is not always equal to this pointer. */
209
210 TC_HCB *TCD_Execute_HISR;
211
212
213 /* TCD_Current_Thread points to the control block of the currently executing
214 thread of execution. Therefore, this variable points at either a TC_TCB
215 or a TC_HCB structure. Except for initialization, this variable is set
216 and cleared in the target dependent portion of this component. */
217
218 VOID *TCD_Current_Thread;
219
220
221 /* TCD_System_Stack contains the system stack base pointer. When the system
222 is idle or in interrupt processing the system stack pointer is used. This
223 variable is usually setup during target dependent initialization. */
224
225 VOID *TCD_System_Stack;
226
227
228 /* TCD_Registered_LISRs is a list that specifies whether or not a
229 LISR is registered for a given interrupt vector. If the value in the
230 list indexed by the vector is non-zero, then that value can be used
231 as the index into the list of LISR pointers to find the actual registered
232 LISR. */
233
234 UNSIGNED_CHAR TCD_Registered_LISRs[NU_MAX_VECTORS+1];
235
236
237 /* TCD_LISR_Pointers is a list of LISR pointers that indicate the LISR function
238 to call when the interrupt occurs. If the entry is NULL, it is
239 available. */
240
241 VOID (*TCD_LISR_Pointers[NU_MAX_LISRS+1])(INT vector);
242
243
244 /* TCD_Interrupt_Count contains the number of Interrupt Service Routines (ISRs)
245 currently in progress. If the contents of this variable is zero, then no
246 interrupts are in progress. If the contents are greater than 1, nested
247 interrupts are being processed. */
248
249 INT TCD_Interrupt_Count;
250
251
252 /* TCD_Stack_Switched contains a flag indicating that the system stack was
253 switched to after the thread's context was saved. This variable is not
254 used in all ports. */
255
256 INT TCD_Stack_Switched;
257
258
259 /* TCD_List_Protect is a structure that is used to protect against multiple
260 access to the list of established tasks. */
261
262 TC_PROTECT TCD_List_Protect;
263
264
265 /* TCD_System_Protect is a structure that is used to provide protection
266 against multiple threads accessing the same system structures at the
267 same time. */
268
269 TC_PROTECT TCD_System_Protect;
270
271
272 /* TCD_LISR_Protect is a structure that is used to provide protection against
273 multiple threads accessing the LISR registration structures at the same
274 time. */
275
276 TC_PROTECT TCD_LISR_Protect;
277
278
279 /* TCD_HISR_Protect is a structure that is used to provide protection against
280 multiple threads accessing the created HISR linked-list at the same time. */
281
282 TC_PROTECT TCD_HISR_Protect;
283
284
285 /* TCD_Interrupt_Level is a variable that contains the enabled interrupt
286 level. If the target processor does not have multiple enable interrupt
287 levels, this variable is a boolean. */
288
289 INT TCD_Interrupt_Level;
290
291
292 /* TCD_Unhandled_Interrupt is a variable that contains the last unhandled
293 interrupt in system error conditions. */
294
295 INT TCD_Unhandled_Interrupt;
296
297
298
299
300