comparison src/nucleus/tcse.c @ 0:4e78acac3d88

src/{condat,cs,gpf,nucleus}: import from Selenite
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 16 Oct 2020 06:23:26 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:4e78acac3d88
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 /* tcse.c Nucleus PLUS 1.14 */
17 /* */
18 /* COMPONENT */
19 /* */
20 /* TC - Thread Control */
21 /* */
22 /* DESCRIPTION */
23 /* */
24 /* This file contains error checking routines for the supplemental */
25 /* functions in the Thread Control component. This permits easy */
26 /* removal of error checking logic when it is not needed. */
27 /* */
28 /* DATA STRUCTURES */
29 /* */
30 /* None */
31 /* */
32 /* FUNCTIONS */
33 /* */
34 /* TCSE_Change_Priority Change task's priority */
35 /* TCSE_Change_Preemption Change task's preemption */
36 /* TCSE_Change_Time_Slice Change task's time slice */
37 /* TCSE_Control_Signals Enable and disable signals */
38 /* TCSE_Receive_Signals Receive current signals */
39 /* TCSE_Register_Signal_Handler Register a signal handler */
40 /* TCSE_Send_Signals Send signals to a task */
41 /* TCSE_Activate_HISR Activate an HISR */
42 /* */
43 /* DEPENDENCIES */
44 /* */
45 /* tc_extr.h Thread Control functions */
46 /* */
47 /* HISTORY */
48 /* */
49 /* DATE REMARKS */
50 /* */
51 /* 03-01-1994 Created initial version 1.1 from */
52 /* routines originally in core */
53 /* error checking file */
54 /* */
55 /* 03-18-1994 Verified version 1.1 */
56 /* 04-17-1996 updated to version 1.2 */
57 /* 03-17-1997 Protected Send Signals service */
58 /* from NULL Control Block pointers */
59 /* creating 1.2a. (SPR220) */
60 /* 03-24-1998 Released version 1.3. */
61 /* 04-17-2002 Released version 1.13m */
62 /* 11-07-2002 Released version 1.14 */
63 /*************************************************************************/
64 #define NU_SOURCE_FILE
65
66
67 #include "tc_extr.h" /* Thread control functions */
68
69 /* Define external inner-component global data references. */
70
71 extern TC_TCB *TCD_Execute_Task;
72 extern VOID *TCD_Current_Thread;
73
74
75 /*************************************************************************/
76 /* */
77 /* FUNCTION */
78 /* */
79 /* TCSE_Change_Priority */
80 /* */
81 /* DESCRIPTION */
82 /* */
83 /* This function performs error checking for the change priority */
84 /* service. If an error is detected, this service is ignored and */
85 /* the requested priority is returned. */
86 /* */
87 /* CALLED BY */
88 /* */
89 /* Application */
90 /* */
91 /* CALLS */
92 /* */
93 /* TCS_Change_Priority Actual change priority */
94 /* */
95 /* INPUTS */
96 /* */
97 /* task_ptr Task control block pointer */
98 /* new_priority New priority for task */
99 /* */
100 /* OUTPUTS */
101 /* */
102 /* old_priority Original task priority */
103 /* */
104 /* HISTORY */
105 /* */
106 /* DATE REMARKS */
107 /* */
108 /* 03-01-1993 Created initial version 1.0 */
109 /* 04-19-1993 Verified version 1.0 */
110 /* 03-01-1994 Changed function interface, */
111 /* resulting in version 1.1 */
112 /* */
113 /* 03-18-1994 Verified version 1.1 */
114 /* */
115 /*************************************************************************/
116 OPTION TCSE_Change_Priority(NU_TASK *task_ptr, OPTION new_priority)
117 {
118
119 TC_TCB *task; /* Task control block ptr */
120 OPTION old_priority; /* Previous priority of task */
121
122
123 /* Move input task pointer into internal task pointer. */
124 task = (TC_TCB *) task_ptr;
125
126 /* Determine if the task pointer is valid. */
127 if (task -> tc_id == TC_TASK_ID)
128
129 /* Nothing seems to be wrong, change the priority as specified. */
130 old_priority = TCS_Change_Priority(task_ptr, new_priority);
131
132 else
133
134 /* Copy the new priority into the old priority. */
135 old_priority = new_priority;
136
137 /* Return the previous priority. */
138 return(old_priority);
139 }
140
141
142 /*************************************************************************/
143 /* */
144 /* FUNCTION */
145 /* */
146 /* TCSE_Change_Preemption */
147 /* */
148 /* DESCRIPTION */
149 /* */
150 /* This function performs error checking on the change preemption */
151 /* service. If the current thread is not a task thread, this */
152 /* request is ignored. */
153 /* */
154 /* CALLED BY */
155 /* */
156 /* Application */
157 /* */
158 /* CALLS */
159 /* */
160 /* TCS_Change_Preemption Change the preemption posture*/
161 /* of the calling task */
162 /* */
163 /* INPUTS */
164 /* */
165 /* preempt Preempt selection parameter */
166 /* */
167 /* OUTPUTS */
168 /* */
169 /* old_preempt Original preempt value */
170 /* */
171 /* HISTORY */
172 /* */
173 /* DATE REMARKS */
174 /* */
175 /* 03-01-1993 Created initial version 1.0 */
176 /* 04-19-1993 Verified version 1.0 */
177 /* */
178 /*************************************************************************/
179 OPTION TCSE_Change_Preemption(OPTION preempt)
180 {
181
182 TC_TCB *task; /* Pointer to task */
183 OPTION old_preempt;
184
185 /* Pickup the current thread and place it in the task pointer. */
186 task = (TC_TCB *) TCD_Current_Thread;
187
188 /* Determine if the current thread is really a task thread. */
189 if (task -> tc_id == TC_TASK_ID)
190
191 /* Yes, change the preemption posture. */
192 old_preempt = TCS_Change_Preemption(preempt);
193
194 else
195
196 /* Return the original request. */
197 old_preempt = preempt;
198
199 /* Return the previous preemption posture. */
200 return(old_preempt);
201 }
202
203
204 /*************************************************************************/
205 /* */
206 /* FUNCTION */
207 /* */
208 /* TCSE_Change_Time_Slice */
209 /* */
210 /* DESCRIPTION */
211 /* */
212 /* This function performs error checking on the change time slice */
213 /* service. If the specified task pointer is invalid, this */
214 /* request is ignored. */
215 /* */
216 /* CALLED BY */
217 /* */
218 /* Application */
219 /* */
220 /* CALLS */
221 /* */
222 /* TCS_Change_Time_Slice Change the time slice of the */
223 /* specified task */
224 /* */
225 /* INPUTS */
226 /* */
227 /* task_ptr Task control block pointer */
228 /* time_slice New time slice value */
229 /* */
230 /* OUTPUTS */
231 /* */
232 /* old_time_slice Old time slice value */
233 /* */
234 /* HISTORY */
235 /* */
236 /* DATE REMARKS */
237 /* */
238 /* 03-01-1993 Created initial version 1.0 */
239 /* 04-19-1993 Verified version 1.0 */
240 /* 03-01-1994 Changed function interface, */
241 /* resulting in version 1.1 */
242 /* */
243 /* 03-18-1994 Verified version 1.1 */
244 /* */
245 /*************************************************************************/
246 UNSIGNED TCSE_Change_Time_Slice(NU_TASK *task_ptr, UNSIGNED time_slice)
247 {
248
249 TC_TCB *task; /* Task control block ptr */
250 UNSIGNED old_time_slice; /* Old time slice value */
251
252
253 /* Move input task pointer into internal pointer. */
254 task = (TC_TCB *) task_ptr;
255
256 /* Determine if the task pointer is valid. */
257 if (task -> tc_id == TC_TASK_ID)
258
259 /* Yes, change the time slice. */
260 old_time_slice = TCS_Change_Time_Slice(task_ptr, time_slice);
261
262 else
263
264 /* Return the current request. */
265 old_time_slice = time_slice;
266
267 /* Return the previous time slice value. */
268 return(old_time_slice);
269 }
270
271
272 /*************************************************************************/
273 /* */
274 /* FUNCTION */
275 /* */
276 /* TCSE_Control_Signals */
277 /* */
278 /* DESCRIPTION */
279 /* */
280 /* This function checks to see if the call is being made from a */
281 /* non-task thread. If so, the request is simply ignored. */
282 /* */
283 /* CALLED BY */
284 /* */
285 /* Application */
286 /* */
287 /* CALLS */
288 /* */
289 /* TCS_Control_Signals Actual control signals func */
290 /* */
291 /* INPUTS */
292 /* */
293 /* enable_signal_mask Enable signal mask */
294 /* */
295 /* OUTPUTS */
296 /* */
297 /* Previous signal enable mask */
298 /* */
299 /* HISTORY */
300 /* */
301 /* DATE REMARKS */
302 /* */
303 /* 03-01-1993 Created initial version 1.0 */
304 /* 04-19-1993 Verified version 1.0 */
305 /* */
306 /*************************************************************************/
307 UNSIGNED TCSE_Control_Signals(UNSIGNED enable_signal_mask)
308 {
309
310 UNSIGNED return_mask; /* Return signal mask */
311 TC_TCB *task; /* Task pointer */
312
313
314 /* Pickup the task pointer. */
315 task = (TC_TCB *) TCD_Current_Thread;
316
317 /* Determine if the call is valid. */
318 if (task -> tc_id == TC_TASK_ID)
319
320 /* Valid request- call actual routine to control signals. */
321 return_mask = TCS_Control_Signals(enable_signal_mask);
322 else
323
324 /* Return a cleared mask. */
325 return_mask = 0;
326
327 /* Return the old enable mask. */
328 return(return_mask);
329 }
330
331
332 /*************************************************************************/
333 /* */
334 /* FUNCTION */
335 /* */
336 /* TCSE_Receive_Signals */
337 /* */
338 /* DESCRIPTION */
339 /* */
340 /* This function determines whether or not the call is being made */
341 /* from a task thread of execution. If not, the call is ignored. */
342 /* */
343 /* CALLED BY */
344 /* */
345 /* Application */
346 /* */
347 /* CALLS */
348 /* */
349 /* TCS_Receive_Signals Actual receive signals func */
350 /* */
351 /* INPUTS */
352 /* */
353 /* None */
354 /* */
355 /* OUTPUTS */
356 /* */
357 /* Current signals */
358 /* */
359 /* HISTORY */
360 /* */
361 /* DATE REMARKS */
362 /* */
363 /* 03-01-1993 Created initial version 1.0 */
364 /* 04-19-1993 Verified version 1.0 */
365 /* */
366 /*************************************************************************/
367 UNSIGNED TCSE_Receive_Signals(VOID)
368 {
369
370 TC_TCB *task; /* Task pointer */
371 UNSIGNED signals; /* Current signals */
372
373 /* Pickup the task pointer. */
374 task = (TC_TCB *) TCD_Current_Thread;
375
376 /* Determine if the call is valid. */
377 if (task -> tc_id == TC_TASK_ID)
378
379 /* Valid request- call actual routine to receive signals. */
380 signals = TCS_Receive_Signals();
381 else
382
383 /* Return cleared signals. */
384 signals = 0;
385
386 /* Return the signals to the caller. */
387 return(signals);
388 }
389
390
391 /*************************************************************************/
392 /* */
393 /* FUNCTION */
394 /* */
395 /* TCSE_Register_Signal_Handler */
396 /* */
397 /* DESCRIPTION */
398 /* */
399 /* This function determines whether or not the caller is a task. */
400 /* If the caller is not a task and/or if the supplied signal */
401 /* handling function pointer is NULL, an appropriate error status */
402 /* is returned. */
403 /* */
404 /* CALLED BY */
405 /* */
406 /* Application */
407 /* */
408 /* CALLS */
409 /* */
410 /* TCS_Register_Signal_Handler Actual function to register */
411 /* the signal handler */
412 /* */
413 /* INPUTS */
414 /* */
415 /* signal_handler Signal execution shell */
416 /* */
417 /* OUTPUTS */
418 /* */
419 /* NU_INVALID_TASK Not called from task thread */
420 /* NU_INVALID_POINTER Signal handler pointer NULL */
421 /* */
422 /* HISTORY */
423 /* */
424 /* DATE REMARKS */
425 /* */
426 /* 03-01-1993 Created initial version 1.0 */
427 /* 04-19-1993 Verified version 1.0 */
428 /* */
429 /*************************************************************************/
430 STATUS TCSE_Register_Signal_Handler(VOID (*signal_handler)(UNSIGNED))
431 {
432
433 STATUS status; /* Return status */
434 TC_TCB *task; /* Task pointer */
435
436 /* Pickup the task pointer. */
437 task = (TC_TCB *) TCD_Current_Thread;
438
439 /* Determine if the caller is a task. */
440 if (task -> tc_id != TC_TASK_ID)
441
442 /* Indicate that the caller is invalid. */
443 status = NU_INVALID_TASK;
444
445 else if (signal_handler == NU_NULL)
446
447 /* Indicate that the signal handler is invalid. */
448 status = NU_INVALID_POINTER;
449
450 else
451
452 /* Everything is fine, call the actual function. */
453 status = TCS_Register_Signal_Handler(signal_handler);
454
455 /* Return completion status. */
456 return(status);
457 }
458
459
460 /*************************************************************************/
461 /* */
462 /* FUNCTION */
463 /* */
464 /* TCSE_Send_Signals */
465 /* */
466 /* DESCRIPTION */
467 /* */
468 /* This function checks for an invalid task. If an invalid task */
469 /* is selected and error is returned. */
470 /* */
471 /* CALLED BY */
472 /* */
473 /* Application */
474 /* */
475 /* CALLS */
476 /* */
477 /* TCS_Send_Signals Actual send signal function */
478 /* */
479 /* INPUTS */
480 /* */
481 /* task_ptr Task pointer */
482 /* signals Signals to send to the task */
483 /* */
484 /* OUTPUTS */
485 /* */
486 /* NU_INVALID_TASK Task pointer is invalid */
487 /* */
488 /* HISTORY */
489 /* */
490 /* DATE REMARKS */
491 /* */
492 /* 03-01-1993 Created initial version 1.0 */
493 /* 04-19-1993 Verified version 1.0 */
494 /* 03-01-1994 Changed function interface, */
495 /* resulting in version 1.1 */
496 /* */
497 /* 03-18-1994 Verified version 1.1 */
498 /* 03-17-1997 Corrected SPR220. */
499 /* */
500 /*************************************************************************/
501 STATUS TCSE_Send_Signals(NU_TASK *task_ptr, UNSIGNED signals)
502 {
503
504 TC_TCB *task; /* Task control block ptr */
505 STATUS status; /* Completion status */
506
507
508 /* Move input task pointer into internal pointer. */
509 task = (TC_TCB *) task_ptr;
510
511 /* Determine if the task pointer is valid. */
512 if ((task != NU_NULL) && (task -> tc_id == TC_TASK_ID))
513
514 /* Task pointer is valid, call the actual function. */
515 status = TCS_Send_Signals(task_ptr, signals);
516 else
517
518 /* Task pointer is invalid, return an error status. */
519 status = NU_INVALID_TASK;
520
521 /* Return the completion status. */
522 return(status);
523 }
524
525
526
527