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

📄 os_core.c

📁 UCOS-III
💻 C
📖 第 1 页 / 共 5 页
字号:
        p_obj->DbgNamePtr = p_tcb1->NamePtr;                /* ... Save in object                                     */
    } else {
        switch (p_tcb->PendOn) {
            case OS_TASK_PEND_ON_TASK_Q:
                 p_tcb->DbgNamePtr = (CPU_CHAR *)((void *)"Task Q");
                 break;

            case OS_TASK_PEND_ON_TASK_SEM:
                 p_tcb->DbgNamePtr = (CPU_CHAR *)((void *)"Task Sem");
                 break;

            default:
                 p_tcb->DbgNamePtr = (CPU_CHAR *)((void *)" ");
                 break;
        }
    }
}



void  OS_PendDbgNameRemove (OS_PEND_OBJ  *p_obj,
                            OS_TCB       *p_tcb)
{
    OS_PEND_LIST  *p_pend_list;
    OS_PEND_DATA  *p_pend_data;
    OS_TCB        *p_tcb1;


    p_tcb->DbgNamePtr = (CPU_CHAR *)((void *)" ");          /* Remove name of object pended on for readied task       */
    p_pend_list       = &p_obj->PendList;
    p_pend_data       =  p_pend_list->HeadPtr;
    if (p_pend_data  != (OS_PEND_DATA *)0) {
        p_tcb1            = p_pend_data->TCBPtr;
        p_obj->DbgNamePtr = p_tcb1->NamePtr;
    } else {
        p_obj->DbgNamePtr = (CPU_CHAR *)((void *)" ");      /* No other task pending on object                        */
    }
}
#endif

/*$PAGE*/
/*
************************************************************************************************************************
*                               CHANGE THE PRIORITY OF A TASK WAITING IN ONE OR MORE PEND LISTS
*
* Description: This function is called to change the position of a task waiting in one or more pend lists.  Because a
*              task can be waiting on multiple objects then each pend list needs to be updated.  Specifically, the
*              task can be the highest priority task waiting on one pend list, the lowest priority task waiting in yet
*              another pend list or somewhere else in another pend list.  Because of this, we need to be able to change
*              each of those pend lists individually.
*
*              The drawing below shows an example of a task (OS_TCB) that belongs to 3 separate pend lists.  Each
*              pend list can contain multiple tasks (the .PrevPtr and .NextPtr show a '?' to indicate this).  The OS_TCB
*              contains a pointer (.PendDataTblPtr) to the first entry in the list of pend lists.
*
*                                                                                                          OS_TCB
*                                                                                                   +--------------------+
*                                                                                                   |                    |
*                                                                                                   +--------------------+
*                                                                                                   | PendDataTblEntries |
*                                      Point to first entry in the OS_PEND_DATA table (i.e. [0])    +--------------------+
*                                          /-----------------------------<------------------------- | PendDataTblPtr     |
*                                          |                                                        +--------------------+
*                                          |                                                                 ^
*              OS_PEND_LIST                |                                                                 |
*              +------------+              |                                                                 |
*              | TailPtr    |              |                                                                 |
*              +------------+              |                                                                 |
*              | HeadPtr    |              |                                                                 |
*              +------------+              |                                        /---------->-------------/
*              | NbrEntries |              |                                        |                        |
*              +------------+     [0]      V   OS_PEND_DATA                         |                        |
*                                     +---------+------------+-------+---------+--------+---------+          |
*                             ? <---- | PrevPtr | PendObjPtr |       |         | TCBPtr | NextPtr | --> ?    |
*                                     +---------+------------+-------+---------+--------+---------+          |
*                                                                                                            |
*                                                                                                            |
*                                                                                                            |
*                                                                                                            |
*                                                                                                            |
*              OS_PEND_LIST                                                                Point back to TCB |
*              +------------+                                                                                |
*              | TailPtr    |                                                                                |
*              +------------+                                                                                |
*              | HeadPtr    |                                                                                |
*              +------------+                                                      /----------->-------------/
*              | NbrEntries |                                                      |                         |
*              +------------+     [1]          OS_PEND_DATA                        |                         |
*                                     +---------+------------+-------+---------+--------+---------+          |
*                             ? <---- | PrevPtr | PendObjPtr |       |         | TCBPtr | NextPtr | --> ?    |
*                                     +---------+------------+-------+---------+--------+---------+          |
*                                                                                                            |
*                                                                                                            |
*                                                                                                            |
*                                                                                                            |
*                                                                                                            |
*              OS_PEND_LIST                                                                                  |
*              +------------+                                                                                |
*              | TailPtr    |                                                                                |
*              +------------+                                                                                |
*              | HeadPtr    |                                                                                |
*              +------------+                                                      /----------->-------------/
*              | NbrEntries |                                                      |
*              +------------+     [2]          OS_PEND_DATA                        |
*                                     +---------+------------+-------+---------+--------+---------+
*                             ? <---- | PrevPtr | PendObjPtr |       |         | TCBPtr | NextPtr | ----> ?
*                                     +---------+------------+-------+---------+--------+---------+
*
*
* Arguments  : p_tcb       is a pointer to the TCB of the task to move
*              -----
*
*              prio_new    is the new priority for the task
*
* Returns    : none
*
* Note(s)    : 1) This function is INTERNAL to uC/OS-III and your application MUST NOT call it.
*
*              2) It's assumed that the TCB contains the NEW priority in its .Prio field.
************************************************************************************************************************
*/

void  OS_PendListChangePrio (OS_TCB  *p_tcb,
                             OS_PRIO  prio_new)
{
    OS_OBJ_QTY      n_pend_list;                                    /* Number of pend lists                           */
    OS_PEND_DATA   *p_pend_data;
    OS_PEND_LIST   *p_pend_list;
    OS_PEND_OBJ    *p_obj;


    p_tcb->Prio = prio_new;
    p_pend_data = p_tcb->PendDataTblPtr;                            /* Point to first wait list entry                 */
    n_pend_list = p_tcb->PendDataTblEntries;                        /* Get the number of pend list task is in         */

    while (n_pend_list > 0u) {
        p_obj       =  p_pend_data->PendObjPtr;                     /* Get pointer to pend list                       */
        p_pend_list = &p_obj->PendList;
        if (p_pend_list->NbrEntries > 1u) {                         /* Only move if multiple entries in the list      */
            OS_PendListRemove1(p_pend_list,                         /* Remove entry from current position             */
                               p_pend_data);
            OS_PendListInsertPrio(p_pend_list,                      /* INSERT it back in the list                     */
                                  p_pend_data);
        }
        p_pend_data++;                                              /* Point to next wait list                        */
        n_pend_list--;
    }
}

/*$PAGE*/
/*
************************************************************************************************************************
*                                                INITIALIZE A WAIT LIST
*
* Description: This function is called to initialize the fields of an OS_PEND_LIST.
*
* Arguments  : p_pend_list   is a pointer to an OS_PEND_LIST
*              -----------
*
* Returns    : none
*
* Note(s)    : 1) This function is INTERNAL to uC/OS-III and your application must not call it.
************************************************************************************************************************
*/

void  OS_PendListInit (OS_PEND_LIST  *p_pend_list)
{
    p_pend_list->HeadPtr    = (OS_PEND_DATA *)0;
    p_pend_list->TailPtr    = (OS_PEND_DATA *)0;
    p_pend_list->NbrEntries = (OS_OBJ_QTY    )0;
}

/*$PAGE*/
/*
************************************************************************************************************************
*                                     INSERT PEND DATA AT THE BEGINNING OF A WAIT LIST
*
* Description: This function is called to place an OS_PEND_DATA entry at the beginning of a linked list as follows:
*
*              CASE 0: Insert in an empty list.
*
*                     OS_PEND_LIST
*                     +--------------+
*                     | TailPtr      |-> 0
*                     +--------------+
*                     | HeadPtr      |-> 0
*                     +--------------+
*                     | NbrEntries=0 |
*                     +--------------+
*
*
*
*              CASE 1: Insert BEFORE the current head of list
*
*                     OS_PEND_LIST
*                     +--------------+         OS_PEND_DATA
*                     | TailPtr      |--+---> +------------+
*                     +--------------+  |     | NextPtr    |->0
*                     | HeadPtr      |--/     +------------+
*                     +--------------+     0<-| PrevPtr    |
*                     | NbrEntries=1 |        +------------+
*                     +--------------+        |            |
*                                             +------------+
*                                             |            |
*                                             +------------+
*
*
* Arguments  : p_pend_list    is a pointer to a wait list found inside an object.  The OS_PEND_DATA entry will be
*              -----------    inserted at the head of the list.
*
*              p_pend_data    is a pointer to the OS_PEND_DATA entry to add to the list
*              -----------
*
* Returns    : none
*
* Note(s)    : 1) This function is INTERNAL to uC/OS-III and your application MUST NOT call it.
************************************************************************************************************************
*/

void  OS_PendListInsertHead (OS_PEND_LIST  *p_pend_list,
                             OS_PEND_DATA  *p_pend_data)
{
    OS_PEND_DATA  *p_pend_data_next;



    p_pend_list->NbrEntries++;                              /* One more entry in the list                             */
    p_pend_data->NextPtr  = p_pend_list->HeadPtr;           /* Adjust new entry's links                               */
    p_pend_data->PrevPtr  = (OS_PEND_DATA  *)0;
    p_pend_data_next      = p_pend_list->HeadPtr;           /* Adjust old head of list's links                        */
    if (p_pend_data_next != (OS_PEND_DATA *)0) {            /* See if we already have a head to replace               */
        p_pend_data_next->PrevPtr = p_pend_data;            /* Yes, point to new entry                                */
    }
    p_pend_list->HeadPtr = p_pend_data;                     /* We have a new list head                                */
    if (p_pend_list->NbrEntries == 1u) {
        p_pend_list->TailPtr = p_pend_data;
    }
}

/*$PAGE*/
/*
************************************************************************************************************************
*                                   INSERT PEND DATA BASED ON IT'S PRIORITY IN A LIST
*
* Description: This function is called to place an OS_PEND_DATA entry in a linked list based on its priority.  The
*              highest priority being placed at the head of the list.  It's assumed that the OS_PEND_DATA entry to
*              insert points to the TCB of the task being inserted.  The TCB is also assumed to contain the priority
*              of the task in its .Prio field.
*
*              CASE 0: Insert in an empty list.
*
*                     OS_PEND_LIST
*                     +---------------+
*                     | TailPtr       |-> 0
*                     +---------------+
*                     | HeadPtr       |-> 0
*                     +---------------+
*                     | NbrEntries=0  |
*                     +---------------+
*
*
*
*              CASE 1: Insert BEFORE or AFTER an OS_TCB
*
*                     OS_PEND_LIST
*                     +--------------+         OS_PEND_DATA
*                     | TailPtr      |--+---> +------------+
*                     +--------------+  |     | NextPtr    |->0
*                     | HeadPtr      |--/     +------------+
*                     +--------------+     0<-| PrevPtr    |
*                     | NbrEntries=1 |        +------------+
*                     +--------------+        |            |
*                                             +------------+
*                                             |            |
*                                             +------------+
*
*
*                     OS_PEND_LIST
*                     +----

⌨️ 快捷键说明

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