?? os_flag.lst
字號:
397 /*
398 *********************************************************************************************************
399 * ASSIGN A NAME TO AN EVENT FLAG GROUP
400 *
401 * Description: This function assigns a name to an event flag group.
402 *
403 * Arguments : pgrp is a pointer to the event flag group.
404 *
405 * pname is a pointer to an ASCII string that will be used as the name of the event flag
406 * group. The string must be able to hold at least OS_FLAG_NAME_SIZE characters.
407 *
408 * err is a pointer to an error code that can contain one of the following values:
409 *
410 * OS_NO_ERR if the requested task is resumed
411 * OS_ERR_EVENT_TYPE if 'pevent' is not pointing to an event flag group
412 * OS_ERR_PNAME_NULL You passed a NULL pointer for 'pname'
413 * OS_FLAG_INVALID_PGRP if you passed a NULL pointer for 'pgrp'
414 *
415 * Returns : None
416 *********************************************************************************************************
417 */
418
419 #if OS_FLAG_NAME_SIZE > 0
420 void OSFlagNameSet (OS_FLAG_GRP *pgrp, char *pname, INT8U *err) reentrant //using 0
421 {
422 1 #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
423 1 OS_CPU_SR cpu_sr;
424 1 #endif
C51 COMPILER V7.06 OS_FLAG 07/18/2003 11:05:57 PAGE 8
425 1 INT8U len;
426 1
427 1
428 1 OS_ENTER_CRITICAL();
429 1 #if OS_ARG_CHK_EN > 0
430 1 if (pgrp == (OS_FLAG_GRP *)0) { /* Is 'pgrp' a NULL pointer? */
431 2 OS_EXIT_CRITICAL(); /* Yes */
432 2 *err = OS_FLAG_INVALID_PGRP;
433 2 return;
434 2 }
435 1 if (pname == (char *)0) { /* Is 'pname' a NULL pointer? */
436 2 OS_EXIT_CRITICAL(); /* Yes */
437 2 *err = OS_ERR_PNAME_NULL;
438 2 return;
439 2 }
440 1 #endif
441 1 if (pgrp->OSFlagType != OS_EVENT_TYPE_FLAG) {
442 2 OS_EXIT_CRITICAL();
443 2 *err = OS_ERR_EVENT_TYPE;
444 2 return;
445 2 }
446 1 len = strlen(pname); /* Can we fit the string in the storage area? */
447 1 if (len > (OS_FLAG_NAME_SIZE - 1)) { /* No */
448 2 OS_EXIT_CRITICAL();
449 2 *err = OS_ERR_FLAG_NAME_TOO_LONG;
450 2 return;
451 2 }
452 1 (void)strcpy(pgrp->OSFlagName, pname); /* Yes, copy name from OS_FLAG_GRP */
453 1 OS_EXIT_CRITICAL();
454 1 *err = OS_NO_ERR;
455 1 return;
456 1 }
457 #endif
458
459 /*$PAGE*/
460 /*
461 *********************************************************************************************************
462 * WAIT ON AN EVENT FLAG GROUP
463 *
464 * Description: This function is called to wait for a combination of bits to be set in an event flag
465 * group. Your application can wait for ANY bit to be set or ALL bits to be set.
466 *
467 * Arguments : pgrp is a pointer to the desired event flag group.
468 *
469 * flags Is a bit pattern indicating which bit(s) (i.e. flags) you wish to wait for.
470 * The bits you want are specified by setting the corresponding bits in
471 * 'flags'. e.g. if your application wants to wait for bits 0 and 1 then
472 * 'flags' would contain 0x03.
473 *
474 * wait_type specifies whether you want ALL bits to be set or ANY of the bits to be set.
475 * You can specify the following argument:
476 *
477 * OS_FLAG_WAIT_CLR_ALL You will wait for ALL bits in 'mask' to be clear (0)
478 * OS_FLAG_WAIT_SET_ALL You will wait for ALL bits in 'mask' to be set (1)
479 * OS_FLAG_WAIT_CLR_ANY You will wait for ANY bit in 'mask' to be clear (0)
480 * OS_FLAG_WAIT_SET_ANY You will wait for ANY bit in 'mask' to be set (1)
481 *
482 * NOTE: Add OS_FLAG_CONSUME if you want the event flag to be 'consumed' by
483 * the call. Example, to wait for any flag in a group AND then clear
484 * the flags that are present, set 'wait_type' to:
485 *
486 * OS_FLAG_WAIT_SET_ANY + OS_FLAG_CONSUME
C51 COMPILER V7.06 OS_FLAG 07/18/2003 11:05:57 PAGE 9
487 *
488 * timeout is an optional timeout (in clock ticks) that your task will wait for the
489 * desired bit combination. If you specify 0, however, your task will wait
490 * forever at the specified event flag group or, until a message arrives.
491 *
492 * err is a pointer to an error code and can be:
493 * OS_NO_ERR The desired bits have been set within the specified
494 * 'timeout'.
495 * OS_ERR_PEND_ISR If you tried to PEND from an ISR
496 * OS_FLAG_INVALID_PGRP If 'pgrp' is a NULL pointer.
497 * OS_ERR_EVENT_TYPE You are not pointing to an event flag group
498 * OS_TIMEOUT The bit(s) have not been set in the specified
499 * 'timeout'.
500 * OS_FLAG_ERR_WAIT_TYPE You didn't specify a proper 'wait_type' argument.
501 *
502 * Returns : The new state of the flags in the event flag group when the task is resumed or,
503 * 0 if a timeout or an error occurred.
504 *
505 * Called from: Task ONLY
506 *********************************************************************************************************
507 */
508
509 OS_FLAGS OSFlagPend (OS_FLAG_GRP *pgrp, OS_FLAGS flags, INT8U wait_type, INT16U timeout, INT8U *err) reen
-trant //using 0
510 {
511 1 #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
512 1 OS_CPU_SR cpu_sr;
513 1 #endif
514 1 OS_FLAG_NODE node;
515 1 OS_FLAGS flags_cur;
516 1 OS_FLAGS flags_rdy;
517 1 BOOLEAN consume;
518 1
519 1
520 1 if (OSIntNesting > 0) { /* See if called from ISR ... */
521 2 *err = OS_ERR_PEND_ISR; /* ... can't PEND from an ISR */
522 2 return ((OS_FLAGS)0);
523 2 }
524 1 #if OS_ARG_CHK_EN > 0
525 1 if (pgrp == (OS_FLAG_GRP *)0) { /* Validate 'pgrp' */
526 2 *err = OS_FLAG_INVALID_PGRP;
527 2 return ((OS_FLAGS)0);
528 2 }
529 1 #endif
530 1 if (pgrp->OSFlagType != OS_EVENT_TYPE_FLAG) { /* Validate event block type */
531 2 *err = OS_ERR_EVENT_TYPE;
532 2 return ((OS_FLAGS)0);
533 2 }
534 1 if (wait_type & OS_FLAG_CONSUME) { /* See if we need to consume the flags */
535 2 wait_type &= ~OS_FLAG_CONSUME;
536 2 consume = TRUE;
537 2 } else {
538 2 consume = FALSE;
539 2 }
540 1 /*$PAGE*/
541 1 OS_ENTER_CRITICAL();
542 1 switch (wait_type) {
543 2 case OS_FLAG_WAIT_SET_ALL: /* See if all required flags are set */
544 2 flags_rdy = pgrp->OSFlagFlags & flags; /* Extract only the bits we want */
545 2 if (flags_rdy == flags) { /* Must match ALL the bits that we want */
546 3 if (consume == TRUE) { /* See if we need to consume the flags */
547 4 pgrp->OSFlagFlags &= ~flags_rdy; /* Clear ONLY the flags that we wanted */
C51 COMPILER V7.06 OS_FLAG 07/18/2003 11:05:57 PAGE 10
548 4 }
549 3 flags_cur = pgrp->OSFlagFlags; /* Will return the state of the group */
550 3 OS_EXIT_CRITICAL(); /* Yes, condition met, return to caller */
551 3 *err = OS_NO_ERR;
552 3 return (flags_cur);
553 3 } else { /* Block task until events occur or timeout */
554 3 OS_FlagBlock(pgrp, &node, flags, wait_type, timeout);
555 3 OS_EXIT_CRITICAL();
556 3 }
557 2 break;
558 2
559 2 case OS_FLAG_WAIT_SET_ANY:
560 2 flags_rdy = pgrp->OSFlagFlags & flags; /* Extract only the bits we want */
561 2 if (flags_rdy != (OS_FLAGS)0) { /* See if any flag set */
562 3 if (consume == TRUE) { /* See if we need to consume the flags */
563 4 pgrp->OSFlagFlags &= ~flags_rdy; /* Clear ONLY the flags that we got */
564 4 }
565 3 flags_cur = pgrp->OSFlagFlags; /* Will return the state of the group */
566 3 OS_EXIT_CRITICAL(); /* Yes, condition met, return to caller */
567 3 *err = OS_NO_ERR;
568 3 return (flags_cur);
569 3 } else { /* Block task until events occur or timeout */
570 3 OS_FlagBlock(pgrp, &node, flags, wait_type, timeout);
571 3 OS_EXIT_CRITICAL();
572 3 }
573 2 break;
574 2
575 2 #if OS_FLAG_WAIT_CLR_EN > 0
576 2 case OS_FLAG_WAIT_CLR_ALL: /* See if all required flags are cleared */
577 2 flags_rdy = ~pgrp->OSFlagFlags & flags; /* Extract only the bits we want */
578 2 if (flags_rdy == flags) { /* Must match ALL the bits that we want */
579 3 if (consume == TRUE) { /* See if we need to consume the flags */
580 4 pgrp->OSFlagFlags |= flags_rdy; /* Set ONLY the flags that we wanted */
581 4 }
582 3 flags_cur = pgrp->OSFlagFlags; /* Will return the state of the group */
583 3 OS_EXIT_CRITICAL(); /* Yes, condition met, return to caller */
584 3 *err = OS_NO_ERR;
585 3 return (flags_cur);
586 3 } else { /* Block task until events occur or timeout */
587 3 OS_FlagBlock(pgrp, &node, flags, wait_type, timeout);
588 3 OS_EXIT_CRITICAL();
589 3 }
590 2 break;
591 2
592 2 case OS_FLAG_WAIT_CLR_ANY:
593 2 flags_rdy = ~pgrp->OSFlagFlags & flags; /* Extract only the bits we want */
594 2 if (flags_rdy != (OS_FLAGS)0) { /* See if any flag cleared */
595 3 if (consume == TRUE) { /* See if we need to consume the flags */
596 4 pgrp->OSFlagFlags |= flags_rdy; /* Set ONLY the flags that we got */
597 4 }
598 3 flags_cur = pgrp->OSFlagFlags; /* Will return the state of the group */
599 3 OS_EXIT_CRITICAL(); /* Yes, condition met, return to caller */
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -