FreeCalypso > hg > ffs-editor
comparison src/nucleus/sms.c @ 0:92470e5d0b9e
src: partial import from FC Selenite
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Fri, 15 May 2020 01:28:16 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:92470e5d0b9e |
---|---|
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 /* sms.c Nucleus PLUS 1.14 */ | |
17 /* */ | |
18 /* COMPONENT */ | |
19 /* */ | |
20 /* SM - Semaphore Management */ | |
21 /* */ | |
22 /* DESCRIPTION */ | |
23 /* */ | |
24 /* This file contains the supplemental routines for the Semaphore */ | |
25 /* Management component. */ | |
26 /* */ | |
27 /* DATA STRUCTURES */ | |
28 /* */ | |
29 /* None */ | |
30 /* */ | |
31 /* FUNCTIONS */ | |
32 /* */ | |
33 /* SMS_Reset_Semaphore Reset semaphore */ | |
34 /* terminate condition */ | |
35 /* */ | |
36 /* DEPENDENCIES */ | |
37 /* */ | |
38 /* cs_extr.h Common Service functions */ | |
39 /* tc_extr.h Thread Control functions */ | |
40 /* sm_extr.h Semaphore functions */ | |
41 /* hi_extr.h History functions */ | |
42 /* */ | |
43 /* HISTORY */ | |
44 /* */ | |
45 /* DATE REMARKS */ | |
46 /* */ | |
47 /* 03-01-1994 Created initial version 1.1 from */ | |
48 /* routines originally in core */ | |
49 /* */ | |
50 /* 03-18-1994 Verified version 1.1 */ | |
51 /* 04-17-1996 updated to version 1.2 */ | |
52 /* 03-24-1998 Released version 1.3. */ | |
53 /* 03-26-1999 Released 1.11m (new release */ | |
54 /* numbering scheme) */ | |
55 /* 04-17-2002 Released version 1.13m */ | |
56 /* 11-07-2002 Released version 1.14 */ | |
57 /*************************************************************************/ | |
58 #define NU_SOURCE_FILE | |
59 | |
60 | |
61 #include "cs_extr.h" /* Common service functions */ | |
62 #include "tc_extr.h" /* Thread control functions */ | |
63 #include "sm_extr.h" /* Semaphore functions */ | |
64 #include "hi_extr.h" /* History functions */ | |
65 #include "profiler.h" /* ProView interface */ | |
66 | |
67 | |
68 | |
69 /*************************************************************************/ | |
70 /* */ | |
71 /* FUNCTION */ | |
72 /* */ | |
73 /* SMS_Reset_Semaphore */ | |
74 /* */ | |
75 /* DESCRIPTION */ | |
76 /* */ | |
77 /* This function resets a semaphore back to the initial state. All */ | |
78 /* tasks suspended on the semaphore are resumed with the reset */ | |
79 /* completion status. */ | |
80 /* */ | |
81 /* CALLED BY */ | |
82 /* */ | |
83 /* Application */ | |
84 /* SMSE_Reset_Semaphore Error checking shell */ | |
85 /* */ | |
86 /* CALLS */ | |
87 /* */ | |
88 /* [HIC_Make_History_Entry] Make entry in history log */ | |
89 /* TCC_Resume_Task Resume a suspended task */ | |
90 /* [TCT_Check_Stack] Stack checking function */ | |
91 /* TCT_Control_To_System Transfer control to system */ | |
92 /* TCT_System_Protect Protect semaphore */ | |
93 /* TCT_Unprotect Release protection */ | |
94 /* */ | |
95 /* INPUTS */ | |
96 /* */ | |
97 /* semaphore_ptr Semaphore control block ptr */ | |
98 /* initial_count Initial count to reset the */ | |
99 /* semaphore to */ | |
100 /* */ | |
101 /* OUTPUTS */ | |
102 /* */ | |
103 /* NU_SUCCESS */ | |
104 /* */ | |
105 /* HISTORY */ | |
106 /* */ | |
107 /* DATE REMARKS */ | |
108 /* */ | |
109 /* 03-01-1993 Created initial version 1.0 */ | |
110 /* 04-19-1993 Verified version 1.0 */ | |
111 /* 03-01-1994 Changed function interface to */ | |
112 /* match the prototype, added */ | |
113 /* register variable logic, */ | |
114 /* optimized protection logic, */ | |
115 /* resulting in version 1.1 */ | |
116 /* */ | |
117 /* 03-18-1994 Verified version 1.1 */ | |
118 /* */ | |
119 /*************************************************************************/ | |
120 STATUS SMS_Reset_Semaphore(NU_SEMAPHORE *semaphore_ptr, | |
121 UNSIGNED initial_count) | |
122 { | |
123 | |
124 R1 SM_SCB *semaphore; /* Semaphore control blk ptr */ | |
125 R2 SM_SUSPEND *suspend_ptr; /* Suspend block pointer */ | |
126 R3 SM_SUSPEND *next_ptr; /* Next suspend block pointer*/ | |
127 STATUS preempt; /* Status for resume call */ | |
128 NU_SUPERV_USER_VARIABLES | |
129 | |
130 /* Switch to supervisor mode */ | |
131 NU_SUPERVISOR_MODE(); | |
132 | |
133 /* Move input semaphore pointer into internal pointer. */ | |
134 semaphore = (SM_SCB *) semaphore_ptr; | |
135 | |
136 #ifdef NU_ENABLE_STACK_CHECK | |
137 | |
138 /* Call stack checking function to check for an overflow condition. */ | |
139 TCT_Check_Stack(); | |
140 | |
141 #endif | |
142 | |
143 #ifdef NU_ENABLE_HISTORY | |
144 | |
145 /* Make an entry that corresponds to this function in the system history | |
146 log. */ | |
147 HIC_Make_History_Entry(NU_RESET_SEMAPHORE_ID, (UNSIGNED) semaphore, | |
148 (UNSIGNED) initial_count, (UNSIGNED) 0); | |
149 | |
150 #endif | |
151 | |
152 /* Protect against access to the semaphore. */ | |
153 TCT_System_Protect(); | |
154 | |
155 /* Pickup the suspended task pointer list. */ | |
156 suspend_ptr = semaphore -> sm_suspension_list; | |
157 | |
158 /* Walk the chain task(s) currently suspended on the semaphore. */ | |
159 preempt = 0; | |
160 while (suspend_ptr) | |
161 { | |
162 | |
163 /* Resume the suspended task. Insure that the status returned is | |
164 NU_SEMAPHORE_RESET. */ | |
165 suspend_ptr -> sm_return_status = NU_SEMAPHORE_RESET; | |
166 | |
167 /* Point to the next suspend structure in the link. */ | |
168 next_ptr = (SM_SUSPEND *) (suspend_ptr -> sm_suspend_link.cs_next); | |
169 | |
170 /* Resume the specified task. */ | |
171 preempt = preempt | | |
172 TCC_Resume_Task((NU_TASK *) suspend_ptr -> sm_suspended_task, | |
173 NU_SEMAPHORE_SUSPEND); | |
174 | |
175 /* Determine if the next is the same as the current pointer. */ | |
176 if (next_ptr == semaphore -> sm_suspension_list) | |
177 | |
178 /* Clear the suspension pointer to signal the end of the list | |
179 traversal. */ | |
180 suspend_ptr = NU_NULL; | |
181 else | |
182 | |
183 /* Move the next pointer into the suspend block pointer. */ | |
184 suspend_ptr = next_ptr; | |
185 } | |
186 | |
187 /* Initialize the semaphore. */ | |
188 semaphore -> sm_semaphore_count = initial_count; | |
189 semaphore -> sm_tasks_waiting = 0; | |
190 semaphore -> sm_suspension_list = NU_NULL; | |
191 | |
192 #ifdef INCLUDE_PROVIEW | |
193 _RTProf_DumpSema(RT_PROF_RESET_SEMAPHORE,(SM_SCB *) semaphore, RT_PROF_OK); | |
194 #endif | |
195 | |
196 /* Determine if preemption needs to occur. */ | |
197 if (preempt) | |
198 | |
199 /* Transfer control to system to facilitate preemption. */ | |
200 TCT_Control_To_System(); | |
201 | |
202 /* Release protection against access to the semaphore. */ | |
203 TCT_Unprotect(); | |
204 | |
205 /* Return to user mode */ | |
206 NU_USER_MODE(); | |
207 | |
208 /* Return a successful completion. */ | |
209 return(NU_SUCCESS); | |
210 } | |
211 | |
212 | |
213 | |
214 |