?? os_flag.lst
字號:
193 OS_FLAG_GRP *OSFlagCreate (OS_FLAGS flags, INT8U *err) reentrant //using 0
194 {
195 1 #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
196 1 OS_CPU_SR cpu_sr;
197 1 #endif
198 1 OS_FLAG_GRP *pgrp;
199 1
200 1
201 1 if (OSIntNesting > 0) { /* See if called from ISR ... */
202 2 *err = OS_ERR_CREATE_ISR; /* ... can't CREATE from an ISR */
203 2 return ((OS_FLAG_GRP *)0);
204 2 }
205 1 OS_ENTER_CRITICAL();
206 1 pgrp = OSFlagFreeList; /* Get next free event flag */
207 1 if (pgrp != (OS_FLAG_GRP *)0) { /* See if we have event flag groups available */
208 2 /* Adjust free list */
209 2 OSFlagFreeList = (OS_FLAG_GRP *)OSFlagFreeList->OSFlagWaitList;
210 2 pgrp->OSFlagType = OS_EVENT_TYPE_FLAG; /* Set to event flag group type */
211 2 pgrp->OSFlagFlags = flags; /* Set to desired initial value */
212 2 pgrp->OSFlagWaitList = (void *)0; /* Clear list of tasks waiting on flags */
213 2 #if OS_FLAG_NAME_SIZE > 0
214 2 (void)strcpy(pgrp->OSFlagName, "?");
215 2 #endif
216 2 OS_EXIT_CRITICAL();
217 2 *err = OS_NO_ERR;
218 2 } else {
219 2 OS_EXIT_CRITICAL();
220 2 *err = OS_FLAG_GRP_DEPLETED;
221 2 }
222 1 return (pgrp); /* Return pointer to event flag group */
223 1 }
224
225 /*$PAGE*/
226 /*
227 *********************************************************************************************************
228 * DELETE AN EVENT FLAG GROUP
229 *
230 * Description: This function deletes an event flag group and readies all tasks pending on the event flag
231 * group.
232 *
233 * Arguments : pgrp is a pointer to the desired event flag group.
234 *
235 * opt determines delete options as follows:
236 * opt == OS_DEL_NO_PEND Deletes the event flag group ONLY if no task pending
237 * opt == OS_DEL_ALWAYS Deletes the event flag group even if tasks are
238 * waiting. In this case, all the tasks pending will be
C51 COMPILER V7.06 OS_FLAG 07/18/2003 11:05:57 PAGE 5
239 * readied.
240 *
241 * err is a pointer to an error code that can contain one of the following values:
242 * OS_NO_ERR The call was successful and the event flag group was
243 * deleted
244 * OS_ERR_DEL_ISR If you attempted to delete the event flag group from
245 * an ISR
246 * OS_FLAG_INVALID_PGRP If 'pgrp' is a NULL pointer.
247 * OS_ERR_EVENT_TYPE If you didn't pass a pointer to an event flag group
248 * OS_ERR_INVALID_OPT An invalid option was specified
249 * OS_ERR_TASK_WAITING One or more tasks were waiting on the event flag
250 * group.
251 *
252 * Returns : pevent upon error
253 * (OS_EVENT *)0 if the semaphore was successfully deleted.
254 *
255 * Note(s) : 1) This function must be used with care. Tasks that would normally expect the presence of
256 * the event flag group MUST check the return code of OSFlagAccept() and OSFlagPend().
257 * 2) This call can potentially disable interrupts for a long time. The interrupt disable
258 * time is directly proportional to the number of tasks waiting on the event flag group.
259 *********************************************************************************************************
260 */
261
262 #if OS_FLAG_DEL_EN > 0
263 OS_FLAG_GRP *OSFlagDel (OS_FLAG_GRP *pgrp, INT8U opt, INT8U *err) reentrant //using 0
264 {
265 1 #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
266 1 OS_CPU_SR cpu_sr;
267 1 #endif
268 1 BOOLEAN tasks_waiting;
269 1 OS_FLAG_NODE *pnode;
270 1
271 1
272 1 if (OSIntNesting > 0) { /* See if called from ISR ... */
273 2 *err = OS_ERR_DEL_ISR; /* ... can't DELETE from an ISR */
274 2 return (pgrp);
275 2 }
276 1 #if OS_ARG_CHK_EN > 0
277 1 if (pgrp == (OS_FLAG_GRP *)0) { /* Validate 'pgrp' */
278 2 *err = OS_FLAG_INVALID_PGRP;
279 2 return (pgrp);
280 2 }
281 1 #endif
282 1 if (pgrp->OSFlagType != OS_EVENT_TYPE_FLAG) { /* Validate event group type */
283 2 *err = OS_ERR_EVENT_TYPE;
284 2 return (pgrp);
285 2 }
286 1 OS_ENTER_CRITICAL();
287 1 if (pgrp->OSFlagWaitList != (void *)0) { /* See if any tasks waiting on event flags */
288 2 tasks_waiting = TRUE; /* Yes */
289 2 } else {
290 2 tasks_waiting = FALSE; /* No */
291 2 }
292 1 switch (opt) {
293 2 case OS_DEL_NO_PEND: /* Delete group if no task waiting */
294 2 if (tasks_waiting == FALSE) {
295 3 #if OS_EVENT_NAME_SIZE > 0
296 3 (void)strcpy(pgrp->OSFlagName, "?"); /* Unknown name */
297 3 #endif
298 3 pgrp->OSFlagType = OS_EVENT_TYPE_UNUSED;
299 3 pgrp->OSFlagWaitList = (void *)OSFlagFreeList; /* Return group to free list */
300 3 pgrp->OSFlagFlags = (OS_FLAGS)0;
C51 COMPILER V7.06 OS_FLAG 07/18/2003 11:05:57 PAGE 6
301 3 OSFlagFreeList = pgrp;
302 3 OS_EXIT_CRITICAL();
303 3 *err = OS_NO_ERR;
304 3 return ((OS_FLAG_GRP *)0); /* Event Flag Group has been deleted */
305 3 } else {
306 3 OS_EXIT_CRITICAL();
307 3 *err = OS_ERR_TASK_WAITING;
308 3 return (pgrp);
309 3 }
310 2
311 2 case OS_DEL_ALWAYS: /* Always delete the event flag group */
312 2 pnode = (OS_FLAG_NODE *)pgrp->OSFlagWaitList;
313 2 while (pnode != (OS_FLAG_NODE *)0) { /* Ready ALL tasks waiting for flags */
314 3 OS_FlagTaskRdy(pnode, (OS_FLAGS)0);
315 3 pnode = (OS_FLAG_NODE *)pnode->OSFlagNodeNext;
316 3 }
317 2 #if OS_EVENT_NAME_SIZE > 0
318 2 (void)strcpy(pgrp->OSFlagName, "?"); /* Unknown name */
319 2 #endif
320 2 pgrp->OSFlagType = OS_EVENT_TYPE_UNUSED;
321 2 pgrp->OSFlagWaitList = (void *)OSFlagFreeList;/* Return group to free list */
322 2 pgrp->OSFlagFlags = (OS_FLAGS)0;
323 2 OSFlagFreeList = pgrp;
324 2 OS_EXIT_CRITICAL();
325 2 if (tasks_waiting == TRUE) { /* Reschedule only if task(s) were waiting */
326 3 OS_Sched(); /* Find highest priority task ready to run */
327 3 }
328 2 *err = OS_NO_ERR;
329 2 return ((OS_FLAG_GRP *)0); /* Event Flag Group has been deleted */
330 2
331 2 default:
332 2 OS_EXIT_CRITICAL();
333 2 *err = OS_ERR_INVALID_OPT;
334 2 return (pgrp);
335 2 }
336 1 }
337 #endif
338 /*$PAGE*/
339 /*
340 *********************************************************************************************************
341 * GET THE NAME OF AN EVENT FLAG GROUP
342 *
343 * Description: This function is used to obtain the name assigned to an event flag group
344 *
345 * Arguments : pgrp is a pointer to the event flag group.
346 *
347 * pname is a pointer to an ASCII string that will receive the name of the event flag
348 * group. The string must be able to hold at least OS_FLAG_NAME_SIZE characters.
349 *
350 * err is a pointer to an error code that can contain one of the following values:
351 *
352 * OS_NO_ERR if the requested task is resumed
353 * OS_ERR_EVENT_TYPE if 'pevent' is not pointing to an event flag group
354 * OS_ERR_PNAME_NULL You passed a NULL pointer for 'pname'
355 * OS_FLAG_INVALID_PGRP if you passed a NULL pointer for 'pgrp'
356 *
357 * Returns : The length of the string or 0 if the 'pgrp' is a NULL pointer.
358 *********************************************************************************************************
359 */
360
361 #if OS_FLAG_NAME_SIZE > 0
362 INT8U OSFlagNameGet (OS_FLAG_GRP *pgrp, char *pname, INT8U *err) reentrant //using 0
C51 COMPILER V7.06 OS_FLAG 07/18/2003 11:05:57 PAGE 7
363 {
364 1 #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
365 1 OS_CPU_SR cpu_sr;
366 1 #endif
367 1 INT8U len;
368 1
369 1
370 1 OS_ENTER_CRITICAL();
371 1 #if OS_ARG_CHK_EN > 0
372 1 if (pgrp == (OS_FLAG_GRP *)0) { /* Is 'pgrp' a NULL pointer? */
373 2 OS_EXIT_CRITICAL(); /* Yes */
374 2 *err = OS_FLAG_INVALID_PGRP;
375 2 return (0);
376 2 }
377 1 if (pname == (char *)0) { /* Is 'pname' a NULL pointer? */
378 2 OS_EXIT_CRITICAL(); /* Yes */
379 2 *err = OS_ERR_PNAME_NULL;
380 2 return (0);
381 2 }
382 1 #endif
383 1 if (pgrp->OSFlagType != OS_EVENT_TYPE_FLAG) {
384 2 OS_EXIT_CRITICAL();
385 2 *err = OS_ERR_EVENT_TYPE;
386 2 return (0);
387 2 }
388 1 (void)strcpy(pname, pgrp->OSFlagName); /* Yes, copy name from OS_FLAG_GRP */
389 1 len = strlen(pname);
390 1 OS_EXIT_CRITICAL();
391 1 *err = OS_NO_ERR;
392 1 return (len);
393 1 }
394 #endif
395
396 /*$PAGE*/
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -