FreeCalypso > hg > ffs-editor
comparison src/nucleus/smce.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 /* smce.c Nucleus PLUS 1.14 */ | |
17 /* */ | |
18 /* COMPONENT */ | |
19 /* */ | |
20 /* SM - Semaphore Management */ | |
21 /* */ | |
22 /* DESCRIPTION */ | |
23 /* */ | |
24 /* This file contains the error checking routines for the core */ | |
25 /* functions of the Semaphore component. This permits easy removal */ | |
26 /* of error checking logic when it is not needed. */ | |
27 /* */ | |
28 /* DATA STRUCTURES */ | |
29 /* */ | |
30 /* None */ | |
31 /* */ | |
32 /* FUNCTIONS */ | |
33 /* */ | |
34 /* SMCE_Create_Semaphore Create a semaphore */ | |
35 /* SMCE_Delete_Semaphore Delete a semaphore */ | |
36 /* SMCE_Obtain_Semaphore Obtain an instance of a */ | |
37 /* semaphore */ | |
38 /* SMCE_Release_Semaphore Release an instance of a */ | |
39 /* semaphore */ | |
40 /* */ | |
41 /* DEPENDENCIES */ | |
42 /* */ | |
43 /* cs_extr.h Common Service functions */ | |
44 /* tc_extr.h Thread Control functions */ | |
45 /* sm_extr.h Semaphore functions */ | |
46 /* */ | |
47 /* HISTORY */ | |
48 /* */ | |
49 /* DATE REMARKS */ | |
50 /* */ | |
51 /* 03-01-1993 Created initial version 1.0 */ | |
52 /* 04-19-1993 Verified version 1.0 */ | |
53 /* 05-15-1993 Corrected comment problem in */ | |
54 /* the header, making the new */ | |
55 /* version 1.0a */ | |
56 /* 05-15-1993 Verified version 1.0a */ | |
57 /* 03-01-1994 Split original error checking */ | |
58 /* file and changed function */ | |
59 /* interfaces, resulting in */ | |
60 /* version 1.1 */ | |
61 /* */ | |
62 /* 03-18-1994 Verified version 1.1 */ | |
63 /* 04-17-1996 updated to version 1.2 */ | |
64 /* 03-24-1998 Released version 1.3. */ | |
65 /* 04-17-2002 Released version 1.13m */ | |
66 /* 11-07-2002 Released version 1.14 */ | |
67 /*************************************************************************/ | |
68 #define NU_SOURCE_FILE | |
69 | |
70 | |
71 #include "cs_extr.h" /* Common service functions */ | |
72 #include "tc_extr.h" /* Thread control functions */ | |
73 #include "sm_extr.h" /* Semaphore functions */ | |
74 | |
75 | |
76 | |
77 /*************************************************************************/ | |
78 /* */ | |
79 /* FUNCTION */ | |
80 /* */ | |
81 /* SMCE_Create_Semaphore */ | |
82 /* */ | |
83 /* DESCRIPTION */ | |
84 /* */ | |
85 /* This function performs error checking on the parameters supplied */ | |
86 /* to the create semaphore function. */ | |
87 /* */ | |
88 /* CALLED BY */ | |
89 /* */ | |
90 /* Application */ | |
91 /* */ | |
92 /* CALLS */ | |
93 /* */ | |
94 /* SMC_Create_Semaphore Actual semaphore create func.*/ | |
95 /* */ | |
96 /* INPUTS */ | |
97 /* */ | |
98 /* semaphore_ptr Semaphore control block ptr */ | |
99 /* name Semaphore name */ | |
100 /* initial_count Initial semaphore instance */ | |
101 /* count */ | |
102 /* suspend_type Suspension type */ | |
103 /* */ | |
104 /* OUTPUTS */ | |
105 /* */ | |
106 /* NU_INVALID_SEMAPHORE Semaphore control block ptr */ | |
107 /* is NULL */ | |
108 /* NU_INVALID_SUSPEND Semaphore suspension is */ | |
109 /* invalid */ | |
110 /* */ | |
111 /* HISTORY */ | |
112 /* */ | |
113 /* DATE REMARKS */ | |
114 /* */ | |
115 /* 03-01-1993 Created initial version 1.0 */ | |
116 /* 04-19-1993 Verified version 1.0 */ | |
117 /* 03-01-1994 Modified function interface, */ | |
118 /* resulting in version 1.1 */ | |
119 /* */ | |
120 /* 03-18-1994 Verified version 1.1 */ | |
121 /* */ | |
122 /*************************************************************************/ | |
123 STATUS SMCE_Create_Semaphore(NU_SEMAPHORE *semaphore_ptr, CHAR *name, | |
124 UNSIGNED initial_count, OPTION suspend_type) | |
125 { | |
126 | |
127 SM_SCB *semaphore; /* Semaphore control blk ptr */ | |
128 STATUS status; /* Completion status */ | |
129 | |
130 | |
131 /* Move input semaphore pointer into internal pointer. */ | |
132 semaphore = (SM_SCB *) semaphore_ptr; | |
133 | |
134 /* Check for a NULL semaphore pointer or an already created semaphore. */ | |
135 if ((semaphore == NU_NULL) || (semaphore -> sm_id == SM_SEMAPHORE_ID)) | |
136 | |
137 /* Invalid semaphore control block pointer. */ | |
138 status = NU_INVALID_SEMAPHORE; | |
139 | |
140 else if ((suspend_type != NU_FIFO) && (suspend_type != NU_PRIORITY)) | |
141 | |
142 /* Invalid suspension type. */ | |
143 status = NU_INVALID_SUSPEND; | |
144 | |
145 else | |
146 | |
147 /* Call the actual service to create the semaphore. */ | |
148 status = SMC_Create_Semaphore(semaphore_ptr, name, initial_count, | |
149 suspend_type); | |
150 | |
151 /* Return completion status. */ | |
152 return(status); | |
153 } | |
154 | |
155 | |
156 /*************************************************************************/ | |
157 /* */ | |
158 /* FUNCTION */ | |
159 /* */ | |
160 /* SMCE_Delete_Semaphore */ | |
161 /* */ | |
162 /* DESCRIPTION */ | |
163 /* */ | |
164 /* This function performs error checking on the parameters supplied */ | |
165 /* to the delete semaphore function. */ | |
166 /* */ | |
167 /* CALLED BY */ | |
168 /* */ | |
169 /* Application */ | |
170 /* */ | |
171 /* CALLS */ | |
172 /* */ | |
173 /* SMC_Delete_Semaphore Actual delete semaphore func.*/ | |
174 /* */ | |
175 /* INPUTS */ | |
176 /* */ | |
177 /* semaphore_ptr Semaphore control block ptr */ | |
178 /* */ | |
179 /* OUTPUTS */ | |
180 /* */ | |
181 /* NU_INVALID_SEMAPHORE Invalid semaphore pointer */ | |
182 /* */ | |
183 /* HISTORY */ | |
184 /* */ | |
185 /* DATE REMARKS */ | |
186 /* */ | |
187 /* 03-01-1993 Created initial version 1.0 */ | |
188 /* 04-19-1993 Verified version 1.0 */ | |
189 /* 03-01-1994 Modified function interface, */ | |
190 /* resulting in version 1.1 */ | |
191 /* */ | |
192 /* 03-18-1994 Verified version 1.1 */ | |
193 /* */ | |
194 /*************************************************************************/ | |
195 STATUS SMCE_Delete_Semaphore(NU_SEMAPHORE *semaphore_ptr) | |
196 { | |
197 | |
198 SM_SCB *semaphore; /* Semaphore control blk ptr */ | |
199 STATUS status; /* Completion status */ | |
200 | |
201 | |
202 /* Move input semaphore pointer into internal pointer. */ | |
203 semaphore = (SM_SCB *) semaphore_ptr; | |
204 | |
205 /* Determine if the semaphore pointer is valid. */ | |
206 if ((semaphore) && (semaphore -> sm_id == SM_SEMAPHORE_ID)) | |
207 | |
208 /* Semaphore pointer is valid, call function to delete it. */ | |
209 status = SMC_Delete_Semaphore(semaphore_ptr); | |
210 | |
211 else | |
212 | |
213 /* Semaphore pointer is invalid, indicate in completion status. */ | |
214 status = NU_INVALID_SEMAPHORE; | |
215 | |
216 /* Return completion status. */ | |
217 return(status); | |
218 } | |
219 | |
220 | |
221 /*************************************************************************/ | |
222 /* */ | |
223 /* FUNCTION */ | |
224 /* */ | |
225 /* SMCE_Obtain_Semaphore */ | |
226 /* */ | |
227 /* DESCRIPTION */ | |
228 /* */ | |
229 /* This function performs error checking on the parameters supplied */ | |
230 /* to the obtain semaphore function. */ | |
231 /* */ | |
232 /* CALLED BY */ | |
233 /* */ | |
234 /* Application */ | |
235 /* */ | |
236 /* CALLS */ | |
237 /* */ | |
238 /* SMC_Obtain_Semaphore Actual function to obtain an */ | |
239 /* instance of the semaphore */ | |
240 /* TCCE_Suspend_Error Check for illegal suspend */ | |
241 /* */ | |
242 /* INPUTS */ | |
243 /* */ | |
244 /* semaphore_ptr Semaphore control block ptr */ | |
245 /* suspend Suspension option if full */ | |
246 /* */ | |
247 /* OUTPUTS */ | |
248 /* */ | |
249 /* NU_INVALID_SEMAPHORE Invalid semaphore pointer */ | |
250 /* NU_INVALID_SUSPEND Suspension from non-task */ | |
251 /* */ | |
252 /* HISTORY */ | |
253 /* */ | |
254 /* DATE REMARKS */ | |
255 /* */ | |
256 /* 03-01-1993 Created initial version 1.0 */ | |
257 /* 04-19-1993 Verified version 1.0 */ | |
258 /* 03-01-1994 Modified function interface, */ | |
259 /* resulting in version 1.1 */ | |
260 /* */ | |
261 /* 03-18-1994 Verified version 1.1 */ | |
262 /* */ | |
263 /*************************************************************************/ | |
264 STATUS SMCE_Obtain_Semaphore(NU_SEMAPHORE *semaphore_ptr, UNSIGNED suspend) | |
265 { | |
266 | |
267 SM_SCB *semaphore; /* Semaphore control blk ptr */ | |
268 STATUS status; /* Completion status */ | |
269 | |
270 | |
271 /* Move input semaphore pointer into internal pointer. */ | |
272 semaphore = (SM_SCB *) semaphore_ptr; | |
273 | |
274 /* Determine if semaphore pointer is invalid. */ | |
275 if (semaphore == NU_NULL) | |
276 | |
277 /* Semaphore pointer is invalid, indicate in completion status. */ | |
278 status = NU_INVALID_SEMAPHORE; | |
279 | |
280 else if (semaphore -> sm_id != SM_SEMAPHORE_ID) | |
281 | |
282 /* Semaphore pointer is invalid, indicate in completion status. */ | |
283 status = NU_INVALID_SEMAPHORE; | |
284 | |
285 else if ((suspend) && (TCCE_Suspend_Error())) | |
286 | |
287 /* Suspension from an non-task thread. */ | |
288 status = NU_INVALID_SUSPEND; | |
289 | |
290 else | |
291 { | |
292 | |
293 /* Parameters are valid, call actual function. */ | |
294 status = SMC_Obtain_Semaphore(semaphore_ptr, suspend); | |
295 } | |
296 | |
297 /* Return the completion status. */ | |
298 return(status); | |
299 } | |
300 | |
301 | |
302 /*************************************************************************/ | |
303 /* */ | |
304 /* FUNCTION */ | |
305 /* */ | |
306 /* SMCE_Release_Semaphore */ | |
307 /* */ | |
308 /* DESCRIPTION */ | |
309 /* */ | |
310 /* This function performs error checking on the parameters supplied */ | |
311 /* to the release semaphore function. */ | |
312 /* */ | |
313 /* CALLED BY */ | |
314 /* */ | |
315 /* Application */ | |
316 /* */ | |
317 /* CALLS */ | |
318 /* */ | |
319 /* SMC_Release_Semaphore Actual release semaphore fct.*/ | |
320 /* */ | |
321 /* INPUTS */ | |
322 /* */ | |
323 /* semaphore_ptr Semaphore control block ptr */ | |
324 /* */ | |
325 /* OUTPUTS */ | |
326 /* */ | |
327 /* NU_INVALID_SEMAPHORE Invalid semaphore pointer */ | |
328 /* */ | |
329 /* HISTORY */ | |
330 /* */ | |
331 /* DATE REMARKS */ | |
332 /* */ | |
333 /* 03-01-1993 Created initial version 1.0 */ | |
334 /* 04-19-1993 Verified version 1.0 */ | |
335 /* 03-01-1994 Modified function interface, */ | |
336 /* resulting in version 1.1 */ | |
337 /* */ | |
338 /* 03-18-1994 Verified version 1.1 */ | |
339 /* */ | |
340 /*************************************************************************/ | |
341 STATUS SMCE_Release_Semaphore(NU_SEMAPHORE *semaphore_ptr) | |
342 { | |
343 | |
344 SM_SCB *semaphore; /* Semaphore control blk ptr */ | |
345 STATUS status; /* Completion status */ | |
346 | |
347 | |
348 /* Move input semaphore pointer into internal pointer. */ | |
349 semaphore = (SM_SCB *) semaphore_ptr; | |
350 | |
351 /* Determine if semaphore pointer is invalid. */ | |
352 if (semaphore == NU_NULL) | |
353 | |
354 /* Semaphore pointer is invalid, indicate in completion status. */ | |
355 status = NU_INVALID_SEMAPHORE; | |
356 | |
357 else if (semaphore -> sm_id != SM_SEMAPHORE_ID) | |
358 | |
359 /* Semaphore pointer is invalid, indicate in completion status. */ | |
360 status = NU_INVALID_SEMAPHORE; | |
361 | |
362 else | |
363 { | |
364 | |
365 /* Parameters are valid, call actual function. */ | |
366 status = SMC_Release_Semaphore(semaphore_ptr); | |
367 } | |
368 | |
369 /* Return the completion status. */ | |
370 return(status); | |
371 } | |
372 | |
373 | |
374 | |
375 | |
376 | |
377 |