⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 os_task.lst

📁 在51上运行的小的OS系统
💻 LST
📖 第 1 页 / 共 5 页
字号:
 543                  OS_ENTER_CRITICAL();                                    /* ... this task to delete itself      */
 544                  stat = OSTCBCur->OSTCBDelReq;                           /* Return request status to caller     */
 545                  OS_EXIT_CRITICAL();
 546                  return (stat);
 547              }
 548              OS_ENTER_CRITICAL();
 549              ptcb = OSTCBPrioTbl[prio];
 550              if (ptcb == (OS_TCB *)0) {                                  /* Task to delete must exist           */
 551                  OS_EXIT_CRITICAL();
 552                  return (OS_TASK_NOT_EXIST);                             /* Task must already be deleted        */
 553              }
 554              if (ptcb == (OS_TCB *)1) {                                  /* Must NOT be assigned to a Mutex     */
 555                  OS_EXIT_CRITICAL();
C51 COMPILER V8.08   OS_TASK                                                               08/04/2008 21:49:52 PAGE 11  

 556                  return (OS_TASK_DEL_ERR);
 557              }
 558              ptcb->OSTCBDelReq = OS_TASK_DEL_REQ;                        /* Set flag indicating task to be DEL. */
 559              OS_EXIT_CRITICAL();
 560              return (OS_NO_ERR);
 561          }
 562          #endif
 563          /*$PAGE*/
 564          /*
 565          *********************************************************************************************************
 566          *                                        GET THE NAME OF A TASK
 567          *
 568          * Description: This function is called to obtain the name of a task.
 569          *
 570          * Arguments  : prio      is the priority of the task that you want to obtain the name from.
 571          *
 572          *              pname     is a pointer to an ASCII string that will receive the name of the task.  The
 573          *                        string must be able to hold at least OS_TASK_NAME_SIZE characters.
 574          *
 575          *              err       is a pointer to an error code that can contain one of the following values:
 576          *
 577          *                        OS_NO_ERR                  if the requested task is resumed
 578          *                        OS_TASK_NOT_EXIST          if the task has not been created or is assigned to a M
             -utex
 579          *                        OS_PRIO_INVALID            if you specified an invalid priority:
 580          *                                                   A higher value than the idle task or not OS_PRIO_SELF.
 581          *                        OS_ERR_PNAME_NULL          You passed a NULL pointer for 'pname'
 582          *
 583          * Returns    : The length of the string or 0 if the task does not exist.
 584          *********************************************************************************************************
 585          */
 586          
 587          #if OS_TASK_NAME_SIZE > 1
 588          INT8U  OSTaskNameGet (INT8U prio, INT8U *pname, INT8U *err)
 589          {
 590              OS_TCB    *ptcb;
 591              INT8U      len;
 592          #if OS_CRITICAL_METHOD == 3                              /* Allocate storage for CPU status register   */
                  OS_CPU_SR  cpu_sr = 0;
              #endif
 595          
 596          
 597          
 598          #if OS_ARG_CHK_EN > 0
 599              if (err == (INT8U *)0) {                             /* Validate 'err'                             */
 600                  return (0);
 601              }
 602              if (prio > OS_LOWEST_PRIO) {                         /* Task priority valid ?                      */
 603                  if (prio != OS_PRIO_SELF) {
 604                      *err = OS_PRIO_INVALID;                      /* No                                         */
 605                      return (0);
 606                  }
 607              }
 608              if (pname == (INT8U *)0) {                             /* Is 'pname' a NULL pointer?                */
 609                  *err = OS_ERR_PNAME_NULL;                          /* Yes                                       */
 610                  return (0);
 611              }
 612          #endif
 613              OS_ENTER_CRITICAL();
 614              if (prio == OS_PRIO_SELF) {                           /* See if caller desires it's own name       */
 615                  prio = OSTCBCur->OSTCBPrio;
 616              }
C51 COMPILER V8.08   OS_TASK                                                               08/04/2008 21:49:52 PAGE 12  

 617              ptcb = OSTCBPrioTbl[prio];
 618              if (ptcb == (OS_TCB *)0) {                            /* Does task exist?                          */
 619                  OS_EXIT_CRITICAL();                               /* No                                        */
 620                  *err = OS_TASK_NOT_EXIST;
 621                  return (0);
 622              }
 623              if (ptcb == (OS_TCB *)1) {                            /* Task assigned to a Mutex?                 */
 624                  OS_EXIT_CRITICAL();                               /* Yes                                       */
 625                  *err = OS_TASK_NOT_EXIST;
 626                  return (0);
 627              }
 628              len  = OS_StrCopy(pname, ptcb->OSTCBTaskName);        /* Yes, copy name from TCB                   */
 629              OS_EXIT_CRITICAL();
 630              *err = OS_NO_ERR;
 631              return (len);
 632          }
 633          #endif
 634          
 635          /*$PAGE*/
 636          /*
 637          *********************************************************************************************************
 638          *                                        ASSIGN A NAME TO A TASK
 639          *
 640          * Description: This function is used to set the name of a task.
 641          *
 642          * Arguments  : prio      is the priority of the task that you want the assign a name to.
 643          *
 644          *              pname     is a pointer to an ASCII string that contains the name of the task.  The ASCII
 645          *                        string must be NUL terminated.
 646          *
 647          *              err       is a pointer to an error code that can contain one of the following values:
 648          *
 649          *                        OS_NO_ERR                  if the requested task is resumed
 650          *                        OS_TASK_NOT_EXIST          if the task has not been created or is assigned to a M
             -utex
 651          *                        OS_ERR_TASK_NAME_TOO_LONG  if the name you are giving to the task exceeds the
 652          *                                                   storage capacity of a task name as specified by
 653          *                                                   OS_TASK_NAME_SIZE.
 654          *                        OS_ERR_PNAME_NULL          You passed a NULL pointer for 'pname'
 655          *                        OS_PRIO_INVALID            if you specified an invalid priority:
 656          *                                                   A higher value than the idle task or not OS_PRIO_SELF.
 657          *
 658          * Returns    : None
 659          *********************************************************************************************************
 660          */
 661          #if OS_TASK_NAME_SIZE > 1
 662          void  OSTaskNameSet (INT8U prio, INT8U *pname, INT8U *err)
 663          {
 664              INT8U      len;
 665              OS_TCB    *ptcb;
 666          #if OS_CRITICAL_METHOD == 3                          /* Allocate storage for CPU status register       */
                  OS_CPU_SR  cpu_sr = 0;
              #endif
 669          
 670          
 671          
 672          #if OS_ARG_CHK_EN > 0
 673              if (err == (INT8U *)0) {                         /* Validate 'err'                                 */
 674                  return;
 675              }
 676              if (prio > OS_LOWEST_PRIO) {                     /* Task priority valid ?                          */
 677                  if (prio != OS_PRIO_SELF) {
C51 COMPILER V8.08   OS_TASK                                                               08/04/2008 21:49:52 PAGE 13  

 678                      *err = OS_PRIO_INVALID;                  /* No                                             */
 679                      return;
 680                  }
 681              }
 682              if (pname == (INT8U *)0) {                        /* Is 'pname' a NULL pointer?                     */
 683                  *err = OS_ERR_PNAME_NULL;                     /* Yes                                            */
 684                  return;
 685              }
 686          #endif
 687              OS_ENTER_CRITICAL();
 688              if (prio == OS_PRIO_SELF) {                      /* See if caller desires to set it's own name     */
 689                  prio = OSTCBCur->OSTCBPrio;
 690              }
 691              ptcb = OSTCBPrioTbl[prio];
 692              if (ptcb == (OS_TCB *)0) {                       /* Does task exist?                               */
 693                  OS_EXIT_CRITICAL();                          /* No                                             */
 694                  *err = OS_TASK_NOT_EXIST;
 695                  return;
 696              }
 697              if (ptcb == (OS_TCB *)1) {                       /* Task assigned to a Mutex?                      */
 698                  OS_EXIT_CRITICAL();                          /* Yes                                            */
 699                  *err = OS_TASK_NOT_EXIST;
 700                  return;
 701              }
 702              len = OS_StrLen(pname);                          /* Yes, Can we fit the string in the TCB?         */
 703              if (len > (OS_TASK_NAME_SIZE - 1)) {             /*      No                                        */
 704                  OS_EXIT_CRITICAL();
 705                  *err = OS_ERR_TASK_NAME_TOO_LONG;
 706                  return;
 707              }
 708              (void)OS_StrCopy(ptcb->OSTCBTaskName, pname);    /*      Yes, copy to TCB                          */
 709              OS_EXIT_CRITICAL();
 710              *err = OS_NO_ERR;
 711          }
 712          #endif
 713          
 714          /*$PAGE*/
 715          /*
 716          *********************************************************************************************************
 717          *                                        RESUME A SUSPENDED TASK
 718          *
 719          * Description: This function is called to resume a previously suspended task.  This is the only call that
 720          *              will remove an explicit task suspension.
 721          *
 722          * Arguments  : prio     is the priority of the task to resume.
 723          *
 724          * Returns    : OS_NO_ERR                if the requested task is resumed
 725          *              OS_PRIO_INVALID          if the priority you specify is higher that the maximum allowed
 726          *                                       (i.e. >= OS_LOWEST_PRIO)
 727          *              OS_TASK_RESUME_PRIO      if the task to resume does not exist
 728          *              OS_TASK_NOT_EXIST        if the task is assigned to a Mutex PIP
 729          *              OS_TASK_NOT_SUSPENDED    if the task to resume has not been suspended
 730          *********************************************************************************************************
 731          */
 732          
 733          #if OS_TASK_SUSPEND_EN > 0
 734          INT8U  OSTaskResume (INT8U prio)
 735          {
 736              OS_TCB    *ptcb;
 737          #if OS_CRITICAL_METHOD == 3                                   /* Storage for CPU status register       */
                  OS_CPU_SR  cpu_sr = 0;
              #endif
C51 COMPILER V8.08   OS_TASK                                                               08/04/2008 21:49:52 PAGE 14  

 740          
 741          

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -