comparison src/nucleus/tcce.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 /* tcce.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 functions in */
25 /* the Thread Control component. This permits easy removal of */
26 /* error checking logic when it is not needed. */
27 /* */
28 /* DATA STRUCTURES */
29 /* */
30 /* None */
31 /* */
32 /* FUNCTIONS */
33 /* */
34 /* TCCE_Create_Task Create a task */
35 /* TCCE_Create_HISR Create HISR */
36 /* TCCE_Delete_HISR Delete HISR */
37 /* TCCE_Delete_Task Delete a task */
38 /* TCCE_Reset_Task Reset a task */
39 /* TCCE_Terminate_Task Terminate a task */
40 /* TCCE_Resume_Service Resume a task service call */
41 /* TCCE_Suspend_Service Suspend a task service call */
42 /* TCCE_Relinquish Relinquish task execution */
43 /* TCCE_Task_Sleep Task sleep request */
44 /* TCCE_Suspend_Error Check for suspend req error */
45 /* TCCE_Activate_HISR Activate an HISR */
46 /* TCCE_Validate_Resume Validates resume requests */
47 /* */
48 /* DEPENDENCIES */
49 /* */
50 /* tc_extr.h Thread Control functions */
51 /* */
52 /* HISTORY */
53 /* */
54 /* DATE REMARKS */
55 /* */
56 /* 03-01-1993 Created initial version 1.0 */
57 /* 04-19-1993 Verified version 1.0 */
58 /* 03-01-1994 Modified logic that checked task */
59 /* status without protection of */
60 /* scheduling structures, */
61 /* resulting in version 1.0a */
62 /* 03-01-1994 Verified version 1.0a */
63 /* 03-01-1994 Moved non-core error checking */
64 /* functions to a supplemental */
65 /* file, and modified function */
66 /* interfaces, added validate */
67 /* resume service, resulting in */
68 /* version 1.1 */
69 /* */
70 /* 03-18-1994 Verified version 1.1 */
71 /* 03-19-1996 Added error checking to */
72 /* TCCE_Task_Sleep, resulting */
73 /* in version 1.1+ (spr037) */
74 /* 04-17-1996 updated to version 1.2 */
75 /* 10-16-1996 Modified to save the current */
76 /* thread's protection rather */
77 /* than that of the task being */
78 /* resumed (SPR212)(SPR268) */
79 /* 03-24-1998 Released version 1.3. */
80 /* 04-17-2002 Released version 1.13m */
81 /* 11-07-2002 Released version 1.14 */
82 /*************************************************************************/
83 #define NU_SOURCE_FILE
84
85
86 #include "tc_extr.h" /* Thread control functions */
87
88 /* Define external inner-component global data references. */
89
90 extern TC_TCB *TCD_Execute_Task;
91 extern VOID *TCD_Current_Thread;
92
93
94
95 /*************************************************************************/
96 /* */
97 /* FUNCTION */
98 /* */
99 /* TCCE_Create_Task */
100 /* */
101 /* DESCRIPTION */
102 /* */
103 /* This function performs error checking on the parameters supplied */
104 /* to the create task function. */
105 /* */
106 /* CALLED BY */
107 /* */
108 /* Application */
109 /* */
110 /* CALLS */
111 /* */
112 /* TCC_Create_Task Actual create task function */
113 /* */
114 /* INPUTS */
115 /* */
116 /* task_ptr Task control block pointer */
117 /* name Task name */
118 /* task_entry Entry function of the task */
119 /* argc Optional task parameter */
120 /* argv Optional task parameter */
121 /* stack_address Pointer to start of stack */
122 /* stack_size Size of task stack in bytes */
123 /* priority Task priority */
124 /* time_slice Task time slice */
125 /* preempt Task preemptability flag */
126 /* auto_start Automatic task start */
127 /* */
128 /* OUTPUTS */
129 /* */
130 /* NU_SUCCESS Successful request */
131 /* NU_INVALID_TASK Task control block pointer */
132 /* is NULL */
133 /* NU_INVALID_ENTRY Task entry function is NULL */
134 /* NU_INVALID_MEMORY Stack pointer is NULL */
135 /* NU_INVALID_SIZE Stack size is too small */
136 /* NU_INVALID_PRIORITY Invalid task priority */
137 /* NU_INVALID_PREEMPT Invalid preemption selection */
138 /* NU_INVALID_START Invalid start selection */
139 /* */
140 /* HISTORY */
141 /* */
142 /* DATE REMARKS */
143 /* */
144 /* 03-01-1993 Created initial version 1.0 */
145 /* 04-19-1993 Verified version 1.0 */
146 /* 03-01-1994 Modified function interface, */
147 /* added register optimizations, */
148 /* resulting in version 1.1 */
149 /* */
150 /* 03-18-1994 Verified version 1.1 */
151 /* */
152 /*************************************************************************/
153 STATUS TCCE_Create_Task(NU_TASK *task_ptr, CHAR *name,
154 VOID (*task_entry)(UNSIGNED, VOID *), UNSIGNED argc, VOID *argv,
155 VOID *stack_address, UNSIGNED stack_size,
156 OPTION priority, UNSIGNED time_slice,
157 OPTION preempt, OPTION auto_start)
158 {
159
160 TC_TCB *task; /* Task control block ptr */
161 STATUS status; /* Completion status */
162
163
164 /* Move input task control block pointer into internal pointer. */
165 task = (TC_TCB *) task_ptr;
166
167 /* Check each parameter. */
168 if ((task == NU_NULL) || (task -> tc_id == TC_TASK_ID))
169
170 /* Invalid task control block pointer. */
171 status = NU_INVALID_TASK;
172
173 else if (task_entry == NU_NULL)
174
175 /* Invalid task entry function pointer. */
176 status = NU_INVALID_ENTRY;
177
178 else if (stack_address == NU_NULL)
179
180 /* Invalid stack starting address. */
181 status = NU_INVALID_MEMORY;
182
183 else if (stack_size < NU_MIN_STACK_SIZE)
184
185 /* Invalid stack size. */
186 status = NU_INVALID_SIZE;
187
188
189 else if ((preempt != NU_PREEMPT) && (preempt != NU_NO_PREEMPT))
190
191 /* Invalid preemption. */
192 status = NU_INVALID_PREEMPT;
193
194 else if ((auto_start != NU_START) && (auto_start != NU_NO_START))
195
196 /* Invalid start selection. */
197 status = NU_INVALID_START;
198
199 else
200
201 /* Call the actual function to create a task. All the parameters
202 appear to be correct. */
203 status = TCC_Create_Task(task_ptr, name, task_entry, argc, argv,
204 stack_address, stack_size, priority, time_slice, preempt, auto_start);
205
206 /* Return completion status. */
207 return(status);
208 }
209
210
211 /*************************************************************************/
212 /* */
213 /* FUNCTION */
214 /* */
215 /* TCCE_Create_HISR */
216 /* */
217 /* DESCRIPTION */
218 /* */
219 /* This function performs error checking on the parameters supplied */
220 /* to the create HISR function. */
221 /* */
222 /* CALLED BY */
223 /* */
224 /* Application */
225 /* */
226 /* CALLS */
227 /* */
228 /* TCC_Create_HISR Actual create HISR function */
229 /* */
230 /* INPUTS */
231 /* */
232 /* hisr_ptr HISR control block pointer */
233 /* name HISR name */
234 /* hisr_entry Entry function of the HISR */
235 /* priority Task priority */
236 /* stack_address Pointer to start of stack */
237 /* stack_size Size of HISR stack in bytes */
238 /* */
239 /* OUTPUTS */
240 /* */
241 /* NU_INVALID_HISR Invalid HISR pointer */
242 /* NU_INVALID_ENTRY Invalid HISR entry point */
243 /* NU_INVALID_PRIORITY Invalid HISR priority */
244 /* NU_INVALID_MEMORY Indicates stack pointer NULL */
245 /* NU_INVALID_SIZE Indicates stack size is too */
246 /* small */
247 /* */
248 /* HISTORY */
249 /* */
250 /* DATE REMARKS */
251 /* */
252 /* 03-01-1993 Created initial version 1.0 */
253 /* 04-19-1993 Verified version 1.0 */
254 /* 03-01-1994 Modified function interface, */
255 /* added register optimizations, */
256 /* resulting in version 1.1 */
257 /* */
258 /* 03-18-1994 Verified version 1.1 */
259 /* */
260 /*************************************************************************/
261 STATUS TCCE_Create_HISR(NU_HISR *hisr_ptr, CHAR *name,
262 VOID (*hisr_entry)(VOID), OPTION priority,
263 VOID *stack_address, UNSIGNED stack_size)
264 {
265
266 TC_HCB *hisr; /* HISR control block ptr */
267 STATUS status; /* Completion status */
268
269
270
271 /* Move input HISR pointer into internal pointer. */
272 hisr = (TC_HCB *) hisr_ptr;
273
274 /* Check each parameter. */
275 if ((hisr == NU_NULL) || (hisr -> tc_id == TC_HISR_ID))
276
277 /* Invalid HISR control block pointer. */
278 status = NU_INVALID_HISR;
279
280 else if (hisr_entry == NU_NULL)
281
282 /* Invalid HISR entry function pointer. */
283 status = NU_INVALID_ENTRY;
284
285 else if (stack_address == NU_NULL)
286
287 /* Invalid stack starting address. */
288 status = NU_INVALID_MEMORY;
289
290 else if (stack_size < NU_MIN_STACK_SIZE)
291
292 /* Invalid stack size. */
293 status = NU_INVALID_SIZE;
294
295 else if (((INT) priority) >= TC_HISR_PRIORITIES)
296
297 /* Invalid HISR priority. */
298 status = NU_INVALID_PRIORITY;
299
300 else
301
302 /* Call the actual function to create a HISR. All the parameters
303 appear to be correct. */
304 status = TCC_Create_HISR(hisr_ptr, name, hisr_entry, priority,
305 stack_address, stack_size);
306
307 /* Return completion status. */
308 return(status);
309 }
310
311
312 /*************************************************************************/
313 /* */
314 /* FUNCTION */
315 /* */
316 /* TCCE_Delete_Task */
317 /* */
318 /* DESCRIPTION */
319 /* */
320 /* This function performs error checking on the parameters supplied */
321 /* to the delete task function. */
322 /* */
323 /* CALLED BY */
324 /* */
325 /* Application */
326 /* */
327 /* CALLS */
328 /* */
329 /* TCC_Delete_Task Actual delete task function */
330 /* */
331 /* INPUTS */
332 /* */
333 /* task_ptr Task control block pointer */
334 /* */
335 /* OUTPUTS */
336 /* */
337 /* NU_SUCCESS If successful completion */
338 /* NU_INVALID_TASK Task pointer is invalid */
339 /* NU_INVALID_DELETE Task not in a finished or */
340 /* terminated state */
341 /* */
342 /* HISTORY */
343 /* */
344 /* DATE REMARKS */
345 /* */
346 /* 03-01-1993 Created initial version 1.0 */
347 /* 04-19-1993 Verified version 1.0 */
348 /* 03-01-1994 Modified function interface, */
349 /* added register optimizations, */
350 /* resulting in version 1.1 */
351 /* */
352 /* 03-18-1994 Verified version 1.1 */
353 /* */
354 /*************************************************************************/
355 STATUS TCCE_Delete_Task(NU_TASK *task_ptr)
356 {
357
358 TC_TCB *task; /* Task control block ptr */
359 STATUS status; /* Completion status */
360
361
362 /* Move input task control block pointer into internal pointer. */
363 task = (TC_TCB *) task_ptr;
364
365 /* Determine if the supplied task pointer is valid. */
366 if ((task == NU_NULL) || (task -> tc_id != TC_TASK_ID))
367
368 /* Invalid task pointer supplied. */
369 status = NU_INVALID_TASK;
370
371 else if ((task -> tc_status != NU_FINISHED) &&
372 (task -> tc_status != NU_TERMINATED))
373
374 /* A task that is not in the finished or terminated state cannot
375 be deleted. */
376 status = NU_INVALID_DELETE;
377
378 else
379
380 /* Valid task pointer, call the function to delete the task. */
381 status = TCC_Delete_Task(task_ptr);
382
383 /* Return the completion status. */
384 return(status);
385 }
386
387
388 /*************************************************************************/
389 /* */
390 /* FUNCTION */
391 /* */
392 /* TCCE_Delete_HISR */
393 /* */
394 /* DESCRIPTION */
395 /* */
396 /* This function performs error checking on the parameters supplied */
397 /* to the delete HISR function. */
398 /* */
399 /* CALLED BY */
400 /* */
401 /* Application */
402 /* */
403 /* CALLS */
404 /* */
405 /* TCC_Delete_HISR Actual delete HISR function */
406 /* */
407 /* INPUTS */
408 /* */
409 /* hisr_ptr HISR control block pointer */
410 /* */
411 /* OUTPUTS */
412 /* */
413 /* NU_INVALID_HISR Indicates HISR pointer is */
414 /* invalid */
415 /* */
416 /* HISTORY */
417 /* */
418 /* DATE REMARKS */
419 /* */
420 /* 03-01-1993 Created initial version 1.0 */
421 /* 04-19-1993 Verified version 1.0 */
422 /* 03-01-1994 Modified function interface, */
423 /* added register optimizations, */
424 /* resulting in version 1.1 */
425 /* */
426 /* 03-18-1994 Verified version 1.1 */
427 /* */
428 /*************************************************************************/
429 STATUS TCCE_Delete_HISR(NU_HISR *hisr_ptr)
430 {
431
432 TC_HCB *hisr; /* HISR control block ptr */
433 STATUS status; /* Completion status */
434
435
436 /* Move input HISR control block pointer into internal pointer. */
437 hisr = (TC_HCB *) hisr_ptr;
438
439 /* Determine if the supplied HISR pointer is valid. */
440 if ((hisr) && (hisr -> tc_id == TC_HISR_ID))
441
442 /* Valid HISR pointer, call the function to delete the HISR. */
443 status = TCC_Delete_HISR(hisr_ptr);
444 else
445
446 /* Invalid HISR pointer, indicate with the status. */
447 status = NU_INVALID_HISR;
448
449 /* Return the completion status. */
450 return(status);
451 }
452
453
454 /*************************************************************************/
455 /* */
456 /* FUNCTION */
457 /* */
458 /* TCCE_Reset_Task */
459 /* */
460 /* DESCRIPTION */
461 /* */
462 /* This function performs error checking on the parameters supplied */
463 /* to the reset task function. */
464 /* */
465 /* CALLED BY */
466 /* */
467 /* Application */
468 /* */
469 /* CALLS */
470 /* */
471 /* TCC_Reset_Task Actual reset task function */
472 /* */
473 /* INPUTS */
474 /* */
475 /* task_ptr Task control block pointer */
476 /* argc Optional task parameter */
477 /* argv Optional task parameter */
478 /* */
479 /* OUTPUTS */
480 /* */
481 /* NU_INVALID_TASK Indicates task pointer is */
482 /* invalid */
483 /* */
484 /* HISTORY */
485 /* */
486 /* DATE REMARKS */
487 /* */
488 /* 03-01-1993 Created initial version 1.0 */
489 /* 04-19-1993 Verified version 1.0 */
490 /* 03-01-1994 Modified function interface, */
491 /* added register optimizations, */
492 /* resulting in version 1.1 */
493 /* */
494 /* 03-18-1994 Verified version 1.1 */
495 /* */
496 /*************************************************************************/
497 STATUS TCCE_Reset_Task(NU_TASK *task_ptr, UNSIGNED argc, VOID *argv)
498 {
499
500 TC_TCB *task; /* Task control block ptr */
501 STATUS status; /* Status of the request */
502
503
504 /* Move input task control block pointer into internal pointer. */
505 task = (TC_TCB *) task_ptr;
506
507 /* Determine if the task pointer is valid. */
508 if ((task == NU_NULL) || (task -> tc_id != TC_TASK_ID))
509
510 /* Task pointer is invalid. */
511 status = NU_INVALID_TASK;
512 else
513
514 /* Call actual function to reset the task. */
515 status = TCC_Reset_Task(task_ptr, argc, argv);
516
517 /* Return completion status. */
518 return(status);
519 }
520
521
522 /*************************************************************************/
523 /* */
524 /* FUNCTION */
525 /* */
526 /* TCCE_Terminate_Task */
527 /* */
528 /* DESCRIPTION */
529 /* */
530 /* This function performs error checking on the parameters supplied */
531 /* to the terminate task function. */
532 /* */
533 /* CALLED BY */
534 /* */
535 /* Application */
536 /* */
537 /* CALLS */
538 /* */
539 /* TCC_Terminate_Task Actual terminate task funct */
540 /* */
541 /* INPUTS */
542 /* */
543 /* task_ptr Task control block pointer */
544 /* */
545 /* OUTPUTS */
546 /* */
547 /* NU_INVALID_TASK Indicates task pointer is */
548 /* invalid */
549 /* */
550 /* HISTORY */
551 /* */
552 /* DATE REMARKS */
553 /* */
554 /* 03-01-1993 Created initial version 1.0 */
555 /* 04-19-1993 Verified version 1.0 */
556 /* 03-01-1994 Modified function interface, */
557 /* added register optimizations, */
558 /* resulting in version 1.1 */
559 /* */
560 /* 03-18-1994 Verified version 1.1 */
561 /* */
562 /*************************************************************************/
563 STATUS TCCE_Terminate_Task(NU_TASK *task_ptr)
564 {
565
566 TC_TCB *task; /* Task control block ptr */
567 STATUS status; /* Status return */
568
569
570 /* Move input task control block pointer into internal pointer. */
571 task = (TC_TCB *) task_ptr;
572
573 /* Determine if the task pointer is valid. */
574 if ((task == NU_NULL) || (task -> tc_id != TC_TASK_ID))
575
576 /* Task pointer is invalid. */
577 status = NU_INVALID_TASK;
578 else
579
580 /* Call actual function to terminate the task. */
581 status = TCC_Terminate_Task(task_ptr);
582
583 /* Return completion status. */
584 return(status);
585 }
586
587
588 /*************************************************************************/
589 /* */
590 /* FUNCTION */
591 /* */
592 /* TCCE_Resume_Service */
593 /* */
594 /* DESCRIPTION */
595 /* */
596 /* This function performs error checking on the parameters supplied */
597 /* to the resume task function. */
598 /* */
599 /* CALLED BY */
600 /* */
601 /* Application */
602 /* */
603 /* CALLS */
604 /* */
605 /* TCCE_Validate_Resume Function that checks the */
606 /* current task status for a */
607 /* valid resume request */
608 /* TCC_Resume_Service Actual task resume service */
609 /* */
610 /* INPUTS */
611 /* */
612 /* task_ptr Task control block pointer */
613 /* */
614 /* OUTPUTS */
615 /* */
616 /* NU_SUCCESS If successful completion */
617 /* NU_INVALID_TASK Task pointer is invalid */
618 /* NU_INVALID_RESUME Not previously suspended */
619 /* */
620 /* HISTORY */
621 /* */
622 /* DATE REMARKS */
623 /* */
624 /* 03-01-1993 Created initial version 1.0 */
625 /* 04-19-1993 Verified version 1.0 */
626 /* 03-01-1994 Modified logic that checked task */
627 /* status without protection of */
628 /* scheduling structures, */
629 /* resulting in version 1.0a */
630 /* 03-01-1994 Verified version 1.0a */
631 /* 03-01-1994 Modified function interface, */
632 /* added register optimizations, */
633 /* moved validate resume function */
634 /* to this file, resulting in */
635 /* version 1.1 */
636 /* 03-18-1994 Verified version 1.1 */
637 /* */
638 /*************************************************************************/
639 STATUS TCCE_Resume_Service(NU_TASK *task_ptr)
640 {
641
642 TC_TCB *task; /* Task control block ptr */
643 STATUS status; /* Completion status */
644
645
646
647 /* Move task control block pointer into internal pointer. */
648 task = (TC_TCB *) task_ptr;
649
650 /* Determine if the task pointer is valid. */
651 if ((task == NU_NULL) || (task -> tc_id != TC_TASK_ID))
652
653 /* Task pointer is invalid. */
654 status = NU_INVALID_TASK;
655
656 /* Make sure that the task is suspended in an identical manner. */
657 else if (TCCE_Validate_Resume(NU_PURE_SUSPEND, task_ptr))
658
659 /* Task is not unconditionally suspended, return error status. */
660 status = NU_INVALID_RESUME;
661
662 else
663
664 /* Call the actual resume service. */
665 status = TCC_Resume_Service(task_ptr);
666
667 /* Return the completion status. */
668 return(status);
669 }
670
671
672 /*************************************************************************/
673 /* */
674 /* FUNCTION */
675 /* */
676 /* TCCE_Suspend_Service */
677 /* */
678 /* DESCRIPTION */
679 /* */
680 /* This function performs error checking on the suspend service. */
681 /* */
682 /* CALLED BY */
683 /* */
684 /* Application */
685 /* */
686 /* CALLS */
687 /* */
688 /* TCC_Suspend_Service Actual suspend service */
689 /* function */
690 /* */
691 /* INPUTS */
692 /* */
693 /* task_ptr Task control block pointer */
694 /* */
695 /* OUTPUTS */
696 /* */
697 /* NU_SUCCESS If successful completion */
698 /* NU_INVALID_TASK Task pointer is invalid */
699 /* */
700 /* HISTORY */
701 /* */
702 /* DATE REMARKS */
703 /* */
704 /* 03-01-1993 Created initial version 1.0 */
705 /* 04-19-1993 Verified version 1.0 */
706 /* 03-01-1994 Modified function interface, */
707 /* added register optimizations, */
708 /* resulting in version 1.1 */
709 /* */
710 /* 03-18-1994 Verified version 1.1 */
711 /* */
712 /*************************************************************************/
713 STATUS TCCE_Suspend_Service(NU_TASK *task_ptr)
714 {
715
716 TC_TCB *task; /* Task control block ptr */
717 STATUS status; /* Completion status */
718
719
720
721 /* Move task control block pointer into internal pointer. */
722 task = (TC_TCB *) task_ptr;
723
724 /* Determine if the task pointer is valid. */
725 if ((task == NU_NULL) || (task -> tc_id != TC_TASK_ID))
726
727 /* Task pointer is invalid. */
728 status = NU_INVALID_TASK;
729
730 else
731
732 if ((task->tc_status == NU_FINISHED) || (task->tc_status == NU_TERMINATED))
733
734 /* Can't suspend a task in a finished or terminated state */
735 status = NU_INVALID_SUSPEND;
736
737
738 else
739
740 /* Call the actual service routine. */
741 status = TCC_Suspend_Service(task_ptr);
742
743 /* Return completion status. */
744 return(status);
745 }
746
747
748 /*************************************************************************/
749 /* */
750 /* FUNCTION */
751 /* */
752 /* TCCE_Relinquish */
753 /* */
754 /* DESCRIPTION */
755 /* */
756 /* This function performs error checking for the relinquish */
757 /* function. If the current thread is not a task, this request */
758 /* is ignored. */
759 /* */
760 /* CALLED BY */
761 /* */
762 /* Application */
763 /* */
764 /* CALLS */
765 /* */
766 /* TCC_Relinquish Actual relinquish function */
767 /* */
768 /* INPUTS */
769 /* */
770 /* None */
771 /* */
772 /* OUTPUTS */
773 /* */
774 /* None */
775 /* */
776 /* HISTORY */
777 /* */
778 /* DATE REMARKS */
779 /* */
780 /* 03-01-1993 Created initial version 1.0 */
781 /* 04-19-1993 Verified version 1.0 */
782 /* */
783 /*************************************************************************/
784 VOID TCCE_Relinquish(VOID)
785 {
786
787 TC_TCB *task; /* Pointer to task */
788
789 /* Pickup the current thread and place it in the task pointer. */
790 task = (TC_TCB *) TCD_Current_Thread;
791
792 /* Determine if the current thread is a task. If so, call the actual
793 relinquish routine. Otherwise, ignore the request. */
794 if ((task) && (task -> tc_id == TC_TASK_ID))
795
796 /* Valid request, call the relinquish function. */
797 TCC_Relinquish();
798 }
799
800
801 /*************************************************************************/
802 /* */
803 /* FUNCTION */
804 /* */
805 /* TCCE_Task_Sleep */
806 /* */
807 /* DESCRIPTION */
808 /* */
809 /* This function performs error checking for the task sleep */
810 /* function. If the current thread is not a task, this request */
811 /* is ignored. */
812 /* */
813 /* CALLED BY */
814 /* */
815 /* Application */
816 /* */
817 /* CALLS */
818 /* */
819 /* TCC_Task_Sleep Actual task sleep function */
820 /* */
821 /* INPUTS */
822 /* */
823 /* ticks Number of ticks to sleep for */
824 /* */
825 /* OUTPUTS */
826 /* */
827 /* None */
828 /* */
829 /* HISTORY */
830 /* */
831 /* DATE REMARKS */
832 /* */
833 /* 03-01-1993 Created initial version 1.0 */
834 /* 04-19-1993 Verified version 1.0 */
835 /* 03-19-1996 Added check for parameter of 0 */
836 /* or negative number, resulting */
837 /* in version 1.1+ (spr037) */
838 /* */
839 /*************************************************************************/
840 VOID TCCE_Task_Sleep(UNSIGNED ticks)
841 {
842
843 TC_TCB *task; /* Pointer to task */
844
845 /* If parameter is zero, return */
846 if (ticks == 0)
847 return;
848
849 /* Pickup the current thread and place it in the task pointer. */
850 task = (TC_TCB *) TCD_Current_Thread;
851
852 /* Determine if the current thread is a task. If so, call the actual
853 task sleep routine. Otherwise, ignore the request. */
854 if ((task) && (task -> tc_id == TC_TASK_ID))
855
856 /* Valid request, call the sleep function. */
857 TCC_Task_Sleep(ticks);
858 }
859
860
861 /*************************************************************************/
862 /* */
863 /* FUNCTION */
864 /* */
865 /* TCCE_Suspend_Error */
866 /* */
867 /* DESCRIPTION */
868 /* */
869 /* This function checks for a suspend request error. Suspension */
870 /* requests are only allowed from task threads. A suspend request */
871 /* from any other thread is an error. */
872 /* */
873 /* CALLED BY */
874 /* */
875 /* Other Components */
876 /* */
877 /* CALLS */
878 /* */
879 /* None */
880 /* */
881 /* INPUTS */
882 /* */
883 /* None */
884 /* */
885 /* OUTPUTS */
886 /* */
887 /* NU_TRUE If an error is detected */
888 /* NU_FALSE If no error is detected */
889 /* */
890 /* HISTORY */
891 /* */
892 /* DATE REMARKS */
893 /* */
894 /* 03-01-1993 Created initial version 1.0 */
895 /* 04-19-1993 Verified version 1.0 */
896 /* */
897 /*************************************************************************/
898 INT TCCE_Suspend_Error(VOID)
899 {
900
901 TC_TCB *task; /* Task pointer */
902 INT status = NU_FALSE; /* Initialize to no error */
903
904
905 /* Setup the task pointer. */
906 task = (TC_TCB *) TCD_Current_Thread;
907
908 /* Check for suspension errors. */
909 if (task == NU_NULL)
910
911 /* Error, suspend request probably from initialization. */
912 status = NU_TRUE;
913
914 else if (task -> tc_id != TC_TASK_ID)
915
916 /* Control block is probably an HISR not a task. */
917 status = NU_TRUE;
918
919 else if (task -> tc_signal_active)
920
921 /* Called from a signal handler. */
922 status = NU_TRUE;
923
924 /* Return status to caller. */
925 return(status);
926 }
927
928
929 /*************************************************************************/
930 /* */
931 /* FUNCTION */
932 /* */
933 /* TCCE_Activate_HISR */
934 /* */
935 /* DESCRIPTION */
936 /* */
937 /* This function performs error checking on the parameters supplied */
938 /* to the activate HISR function. */
939 /* */
940 /* CALLED BY */
941 /* */
942 /* Application */
943 /* */
944 /* CALLS */
945 /* */
946 /* TCT_Activate_HISR Actual HISR activate call */
947 /* */
948 /* INPUTS */
949 /* */
950 /* hisr_ptr HISR control block pointer */
951 /* */
952 /* OUTPUTS */
953 /* */
954 /* NU_INVALID_HISR Invalid HISR pointer */
955 /* */
956 /* HISTORY */
957 /* */
958 /* DATE REMARKS */
959 /* */
960 /* 03-01-1993 Created initial version 1.0 */
961 /* 04-19-1993 Verified version 1.0 */
962 /* 03-01-1994 Modified function interface, */
963 /* added register optimizations, */
964 /* resulting in version 1.1 */
965 /* */
966 /* 03-18-1994 Verified version 1.1 */
967 /* */
968 /*************************************************************************/
969 STATUS TCCE_Activate_HISR(NU_HISR *hisr_ptr)
970 {
971
972 TC_HCB *hisr; /* HISR control block ptr */
973 STATUS status; /* Completion status */
974 NU_SUPERV_USER_VARIABLES
975
976 NU_SUPERVISOR_MODE();
977 /* Move input HISR control block pointer into internal pointer. */
978 hisr = (TC_HCB *) hisr_ptr;
979
980 /* Check each parameter. */
981 if (hisr == NU_NULL)
982
983 /* Invalid HISR control block pointer. */
984 status = NU_INVALID_HISR;
985
986 else if (hisr -> tc_id != TC_HISR_ID)
987
988 /* Invalid HISR control block pointer. */
989 status = NU_INVALID_HISR;
990
991 else
992
993 /* Call the routine to activate the HISR. */
994 status = TCT_Activate_HISR(hisr_ptr);
995
996 /* Return to user mode */
997 NU_USER_MODE();
998
999 /* Return completion status. */
1000 return(status);
1001 }
1002
1003
1004 /*************************************************************************/
1005 /* */
1006 /* FUNCTION */
1007 /* */
1008 /* TCCE_Validate_Resume */
1009 /* */
1010 /* DESCRIPTION */
1011 /* */
1012 /* This function validates the resume service and resume driver */
1013 /* calls with scheduling protection around the examination of the */
1014 /* task status. */
1015 /* */
1016 /* CALLED BY */
1017 /* */
1018 /* IOCE_Resume_Driver Driver error checking funct. */
1019 /* TCCE_Resume_Service Error checking function */
1020 /* */
1021 /* CALLS */
1022 /* */
1023 /* TCT_Set_Current_Protect Setup current protect pointer*/
1024 /* TCT_System_Protect Protect from system access */
1025 /* TCT_System_Unprotect Release system protection */
1026 /* TCT_Unprotect Release current protection */
1027 /* */
1028 /* INPUTS */
1029 /* */
1030 /* resume_type Type of resume request */
1031 /* task_ptr Task control block pointer */
1032 /* */
1033 /* OUTPUTS */
1034 /* */
1035 /* NU_TRUE Invalid resume */
1036 /* NU_FALSE Valid resume */
1037 /* */
1038 /* HISTORY */
1039 /* */
1040 /* DATE REMARKS */
1041 /* */
1042 /* 03-01-1994 Created initial version of */
1043 /* function for version 1.0g */
1044 /* 03-01-1994 Verified version 1.0g */
1045 /* 03-01-1994 Modified function interface, */
1046 /* added register optimizations, */
1047 /* added system protection logic, */
1048 /* moved to TCCE since it is an */
1049 /* error interface function, */
1050 /* resulting in version 1.1 */
1051 /* */
1052 /* 03-18-1994 Verified version 1.1 */
1053 /* 10-16-1996 Modified to save the current */
1054 /* thread's protection rather */
1055 /* than that of the task being */
1056 /* resumed (SPR212)(SPR268) */
1057 /* */
1058 /*************************************************************************/
1059 STATUS TCCE_Validate_Resume(OPTION resume_type, NU_TASK *task_ptr)
1060 {
1061
1062 R1 TC_TCB *task; /* Task control block ptr */
1063 TC_PROTECT *save_protect; /* Save current protection */
1064 STATUS status; /* Return status variable */
1065 NU_SUPERV_USER_VARIABLES
1066
1067 NU_SUPERVISOR_MODE();
1068
1069 /* Move input task pointer into internal pointer. */
1070 task = (TC_TCB *) task_ptr;
1071
1072 /* Save current protection. */
1073 if (TCD_Current_Thread != NU_NULL)
1074 {
1075 save_protect = TCT_Get_Current_Protect();
1076 }
1077 else
1078 {
1079 save_protect = NU_NULL;
1080 }
1081
1082 /* Protect the scheduling structures from multiple access. */
1083 TCT_System_Protect();
1084
1085 /* Does the resume type match the current status? */
1086 if (task -> tc_status == resume_type)
1087
1088 /* Indicate that there is no error. */
1089 status = NU_FALSE;
1090
1091 /* Check for a resumption of a delayed pure suspend. */
1092 else if ((resume_type == NU_PURE_SUSPEND) && (task -> tc_delayed_suspend))
1093
1094 /* Indicate that there is no error. */
1095 status = NU_FALSE;
1096
1097 /* Check for a signal active and the saved status the same as
1098 the resume request. */
1099 else if ((resume_type == task -> tc_saved_status) &&
1100 (task -> tc_signal_active))
1101
1102 /* Indicate that there is no error. */
1103 status = NU_FALSE;
1104
1105 else
1106
1107 /* Indicate that there is an error. */
1108 status = NU_TRUE;
1109
1110 /* Determine how to get out of protection. */
1111 if (save_protect)
1112 {
1113
1114 /* Restore current protection. */
1115 TCT_Set_Current_Protect(save_protect);
1116
1117 /* Release system protect. */
1118 TCT_System_Unprotect();
1119 }
1120 else
1121
1122 /* Release protection of system structures. */
1123 TCT_Unprotect();
1124
1125 /* Return to user mode */
1126 NU_USER_MODE();
1127
1128 /* Return status to caller. */
1129 return(status);
1130 }
1131
1132
1133
1134