📄 os_flag.lst
字号:
335 (void)OS_FlagTaskRdy(pnode, (OS_FLAGS)0);
336 pnode = (OS_FLAG_NODE *)pnode->OSFlagNodeNext;
337 }
338 #if OS_FLAG_NAME_SIZE > 1
339 pgrp->OSFlagName[0] = '?'; /* Unknown name */
340 pgrp->OSFlagName[1] = OS_ASCII_NUL;
341 #endif
342 pgrp->OSFlagType = OS_EVENT_TYPE_UNUSED;
343 pgrp->OSFlagWaitList = (void *)OSFlagFreeList;/* Return group to free list */
344 pgrp->OSFlagFlags = (OS_FLAGS)0;
345 OSFlagFreeList = pgrp;
346 OS_EXIT_CRITICAL();
347 if (tasks_waiting == TRUE) { /* Reschedule only if task(s) were waiting */
348 OS_Sched(); /* Find highest priority task ready to run */
349 }
350 *err = OS_NO_ERR;
351 pgrp_return = (OS_FLAG_GRP *)0; /* Event Flag Group has been deleted */
352 break;
353
354 default:
355 OS_EXIT_CRITICAL();
356 *err = OS_ERR_INVALID_OPT;
357 pgrp_return = pgrp;
358 break;
359 }
360 return (pgrp_return);
361 }
362 #endif
363 /*$PAGE*/
364 /*
365 *********************************************************************************************************
366 * GET THE NAME OF AN EVENT FLAG GROUP
367 *
368 * Description: This function is used to obtain the name assigned to an event flag group
C51 COMPILER V8.08 OS_FLAG 08/04/2008 21:49:51 PAGE 8
369 *
370 * Arguments : pgrp is a pointer to the event flag group.
371 *
372 * pname is a pointer to an ASCII string that will receive the name of the event flag
373 * group. The string must be able to hold at least OS_FLAG_NAME_SIZE characters.
374 *
375 * err is a pointer to an error code that can contain one of the following values:
376 *
377 * OS_NO_ERR if the requested task is resumed
378 * OS_ERR_EVENT_TYPE if 'pevent' is not pointing to an event flag group
379 * OS_ERR_PNAME_NULL You passed a NULL pointer for 'pname'
380 * OS_FLAG_INVALID_PGRP if you passed a NULL pointer for 'pgrp'
381 *
382 * Returns : The length of the string or 0 if the 'pgrp' is a NULL pointer.
383 *********************************************************************************************************
384 */
385
386 #if OS_FLAG_NAME_SIZE > 1
387 INT8U OSFlagNameGet (OS_FLAG_GRP *pgrp, INT8U *pname, INT8U *err)
388 {
389 INT8U len;
390 #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
OS_CPU_SR cpu_sr = 0;
#endif
393
394
395
396 OS_ENTER_CRITICAL();
397 #if OS_ARG_CHK_EN > 0
398 if (err == (INT8U *)0) { /* Validate 'err' */
399 OS_EXIT_CRITICAL();
400 return (0);
401 }
402 if (pgrp == (OS_FLAG_GRP *)0) { /* Is 'pgrp' a NULL pointer? */
403 OS_EXIT_CRITICAL(); /* Yes */
404 *err = OS_FLAG_INVALID_PGRP;
405 return (0);
406 }
407 if (pname == (INT8U *)0) { /* Is 'pname' a NULL pointer? */
408 OS_EXIT_CRITICAL(); /* Yes */
409 *err = OS_ERR_PNAME_NULL;
410 return (0);
411 }
412 #endif
413 if (pgrp->OSFlagType != OS_EVENT_TYPE_FLAG) {
414 OS_EXIT_CRITICAL();
415 *err = OS_ERR_EVENT_TYPE;
416 return (0);
417 }
418 len = OS_StrCopy(pname, pgrp->OSFlagName); /* Copy name from OS_FLAG_GRP */
419 OS_EXIT_CRITICAL();
420 *err = OS_NO_ERR;
421 return (len);
422 }
423 #endif
424
425 /*$PAGE*/
426 /*
427 *********************************************************************************************************
428 * ASSIGN A NAME TO AN EVENT FLAG GROUP
429 *
430 * Description: This function assigns a name to an event flag group.
C51 COMPILER V8.08 OS_FLAG 08/04/2008 21:49:51 PAGE 9
431 *
432 * Arguments : pgrp is a pointer to the event flag group.
433 *
434 * pname is a pointer to an ASCII string that will be used as the name of the event flag
435 * group. The string must be able to hold at least OS_FLAG_NAME_SIZE characters.
436 *
437 * err is a pointer to an error code that can contain one of the following values:
438 *
439 * OS_NO_ERR if the requested task is resumed
440 * OS_ERR_EVENT_TYPE if 'pevent' is not pointing to an event flag group
441 * OS_ERR_PNAME_NULL You passed a NULL pointer for 'pname'
442 * OS_FLAG_INVALID_PGRP if you passed a NULL pointer for 'pgrp'
443 *
444 * Returns : None
445 *********************************************************************************************************
446 */
447
448 #if OS_FLAG_NAME_SIZE > 1
449 void OSFlagNameSet (OS_FLAG_GRP *pgrp, INT8U *pname, INT8U *err)
450 {
451 INT8U len;
452 #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
OS_CPU_SR cpu_sr = 0;
#endif
455
456
457
458 OS_ENTER_CRITICAL();
459 #if OS_ARG_CHK_EN > 0
460 if (err == (INT8U *)0) { /* Validate 'err' */
461 OS_EXIT_CRITICAL();
462 return;
463 }
464 if (pgrp == (OS_FLAG_GRP *)0) { /* Is 'pgrp' a NULL pointer? */
465 OS_EXIT_CRITICAL(); /* Yes */
466 *err = OS_FLAG_INVALID_PGRP;
467 return;
468 }
469 if (pname == (INT8U *)0) { /* Is 'pname' a NULL pointer? */
470 OS_EXIT_CRITICAL(); /* Yes */
471 *err = OS_ERR_PNAME_NULL;
472 return;
473 }
474 #endif
475 if (pgrp->OSFlagType != OS_EVENT_TYPE_FLAG) {
476 OS_EXIT_CRITICAL();
477 *err = OS_ERR_EVENT_TYPE;
478 return;
479 }
480 len = OS_StrLen(pname); /* Can we fit the string in the storage area? */
481 if (len > (OS_FLAG_NAME_SIZE - 1)) { /* No */
482 OS_EXIT_CRITICAL();
483 *err = OS_ERR_FLAG_NAME_TOO_LONG;
484 return;
485 }
486 (void)OS_StrCopy(pgrp->OSFlagName, pname); /* Yes, copy name from OS_FLAG_GRP */
487 OS_EXIT_CRITICAL();
488 *err = OS_NO_ERR;
489 return;
490 }
491 #endif
492
C51 COMPILER V8.08 OS_FLAG 08/04/2008 21:49:51 PAGE 10
493 /*$PAGE*/
494 /*
495 *********************************************************************************************************
496 * WAIT ON AN EVENT FLAG GROUP
497 *
498 * Description: This function is called to wait for a combination of bits to be set in an event flag
499 * group. Your application can wait for ANY bit to be set or ALL bits to be set.
500 *
501 * Arguments : pgrp is a pointer to the desired event flag group.
502 *
503 * flags Is a bit pattern indicating which bit(s) (i.e. flags) you wish to wait for.
504 * The bits you want are specified by setting the corresponding bits in
505 * 'flags'. e.g. if your application wants to wait for bits 0 and 1 then
506 * 'flags' would contain 0x03.
507 *
508 * wait_type specifies whether you want ALL bits to be set or ANY of the bits to be set.
509 * You can specify the following argument:
510 *
511 * OS_FLAG_WAIT_CLR_ALL You will wait for ALL bits in 'mask' to be clear (0)
512 * OS_FLAG_WAIT_SET_ALL You will wait for ALL bits in 'mask' to be set (1)
513 * OS_FLAG_WAIT_CLR_ANY You will wait for ANY bit in 'mask' to be clear (0)
514 * OS_FLAG_WAIT_SET_ANY You will wait for ANY bit in 'mask' to be set (1)
515 *
516 * NOTE: Add OS_FLAG_CONSUME if you want the event flag to be 'consumed' by
517 * the call. Example, to wait for any flag in a group AND then clear
518 * the flags that are present, set 'wait_type' to:
519 *
520 * OS_FLAG_WAIT_SET_ANY + OS_FLAG_CONSUME
521 *
522 * timeout is an optional timeout (in clock ticks) that your task will wait for the
523 * desired bit combination. If you specify 0, however, your task will wait
524 * forever at the specified event flag group or, until a message arrives.
525 *
526 * err is a pointer to an error code and can be:
527 * OS_NO_ERR The desired bits have been set within the specified
528 * 'timeout'.
529 * OS_ERR_PEND_ISR If you tried to PEND from an ISR
530 * OS_FLAG_INVALID_PGRP If 'pgrp' is a NULL pointer.
531 * OS_ERR_EVENT_TYPE You are not pointing to an event flag group
532 * OS_TIMEOUT The bit(s) have not been set in the specified
533 * 'timeout'.
534 * OS_FLAG_ERR_WAIT_TYPE You didn't specify a proper 'wait_type' argument.
535 *
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -