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

📄 os_task.lis

📁 ucos如何移植到单片机mega128
💻 LIS
📖 第 1 页 / 共 5 页
字号:
                        .module OS_TASK.C
                        .area text(rom, con, rel)
 0000                   .dbfile E:\study\ucos_ii\ucos2_iccavr\iccavr\ucos2_without_cpu\OS_TASK.C
 0000                   .dbfunc e OSTaskCreate _OSTaskCreate fc
 0000           ;            psp -> R10,R11
 0000           ;            err -> R10
 0000           ;           prio -> R12
 0000           ;           ptos -> y+22
 0000           ;          pdata -> R14,R15
 0000           ;           task -> R10,R11
                        .even
 0000           _OSTaskCreate::
 0000 0E940000          xcall push_gset5
 0004 7901              movw R14,R18
 0006 5801              movw R10,R16
 0008 2C97              sbiw R28,12
 000A C88C              ldd R12,y+24
 000C                   .dbline -1
 000C                   .dbline 159
 000C           ; /*
 000C           ; *********************************************************************************************************
 000C           ; *                                                uC/OS-II
 000C           ; *                                          The Real-Time Kernel
 000C           ; *                                            TASK MANAGEMENT
 000C           ; *
 000C           ; *                          (c) Copyright 1992-2002, Jean J. Labrosse, Weston, FL
 000C           ; *                                           All Rights Reserved
 000C           ; *
 000C           ; * File : OS_TASK.C
 000C           ; * By   : Jean J. Labrosse
 000C           ; *********************************************************************************************************
 000C           ; */
 000C           ; 
 000C           ; #ifndef  OS_MASTER_FILE
 000C           ; #include "..\ucos2_application\includes.h"
 000C           ; #endif
 000C           ; 
 000C           ; /*
 000C           ; *********************************************************************************************************
 000C           ; *                                        CHANGE PRIORITY OF A TASK
 000C           ; *
 000C           ; * Description: This function allows you to change the priority of a task dynamically.  Note that the new
 000C           ; *              priority MUST be available.
 000C           ; *
 000C           ; * Arguments  : oldp     is the old priority
 000C           ; *
 000C           ; *              newp     is the new priority
 000C           ; *
 000C           ; * Returns    : OS_NO_ERR        is the call was successful
 000C           ; *              OS_PRIO_INVALID  if the priority you specify is higher that the maximum allowed
 000C           ; *                               (i.e. >= OS_LOWEST_PRIO)
 000C           ; *              OS_PRIO_EXIST    if the new priority already exist.
 000C           ; *              OS_PRIO_ERR      there is no task with the specified OLD priority (i.e. the OLD task does
 000C           ; *                               not exist.
 000C           ; *********************************************************************************************************
 000C           ; */
 000C           ; 
 000C           ; #if OS_TASK_CHANGE_PRIO_EN > 0
 000C           ; INT8U  OSTaskChangePrio (INT8U oldprio, INT8U newprio)
 000C           ; {
 000C           ; #if OS_CRITICAL_METHOD == 3                      /* Allocate storage for CPU status register           */
 000C           ;     OS_CPU_SR    cpu_sr;
 000C           ; #endif
 000C           ; 
 000C           ; #if OS_EVENT_EN > 0
 000C           ;     OS_EVENT    *pevent;
 000C           ; #endif
 000C           ; 
 000C           ;     OS_TCB      *ptcb;
 000C           ;     INT8U        x;
 000C           ;     INT8U        y;
 000C           ;     INT8U        bitx;
 000C           ;     INT8U        bity;
 000C           ; 
 000C           ; 
 000C           ; 
 000C           ; #if OS_ARG_CHK_EN > 0
 000C           ;     if ((oldprio >= OS_LOWEST_PRIO && oldprio != OS_PRIO_SELF)  ||
 000C           ;          newprio >= OS_LOWEST_PRIO) {
 000C           ;         return (OS_PRIO_INVALID);
 000C           ;     }
 000C           ; #endif
 000C           ;     OS_ENTER_CRITICAL();
 000C           ;     if (OSTCBPrioTbl[newprio] != (OS_TCB *)0) {                 /* New priority must not already exist */
 000C           ;         OS_EXIT_CRITICAL();
 000C           ;         return (OS_PRIO_EXIST);
 000C           ;     } else {
 000C           ;         OSTCBPrioTbl[newprio] = (OS_TCB *)1;                    /* Reserve the entry to prevent others */
 000C           ;         OS_EXIT_CRITICAL();
 000C           ;         y    = newprio >> 3;                                    /* Precompute to reduce INT. latency   */
 000C           ;         bity = OSMapTbl[y];
 000C           ;         x    = newprio & 0x07;
 000C           ;         bitx = OSMapTbl[x];
 000C           ;         OS_ENTER_CRITICAL();
 000C           ;         if (oldprio == OS_PRIO_SELF) {                          /* See if changing self                */
 000C           ;             oldprio = OSTCBCur->OSTCBPrio;                      /* Yes, get priority                   */
 000C           ;         }
 000C           ;         ptcb = OSTCBPrioTbl[oldprio];
 000C           ;         if (ptcb != (OS_TCB *)0) {                              /* Task to change must exist           */
 000C           ;             OSTCBPrioTbl[oldprio] = (OS_TCB *)0;                /* Remove TCB from old priority        */
 000C           ;             if ((OSRdyTbl[ptcb->OSTCBY] & ptcb->OSTCBBitX) != 0x00) {  /* If task is ready make it not */
 000C           ;                 if ((OSRdyTbl[ptcb->OSTCBY] &= ~ptcb->OSTCBBitX) == 0x00) {
 000C           ;                     OSRdyGrp &= ~ptcb->OSTCBBitY;
 000C           ;                 }
 000C           ;                 OSRdyGrp    |= bity;                            /* Make new priority ready to run      */
 000C           ;                 OSRdyTbl[y] |= bitx;
 000C           ; #if OS_EVENT_EN > 0
 000C           ;             } else {
 000C           ;                 pevent = ptcb->OSTCBEventPtr;
 000C           ;                 if (pevent != (OS_EVENT *)0) {                  /* Remove from event wait list  */
 000C           ;                     if ((pevent->OSEventTbl[ptcb->OSTCBY] &= ~ptcb->OSTCBBitX) == 0) {
 000C           ;                         pevent->OSEventGrp &= ~ptcb->OSTCBBitY;
 000C           ;                     }
 000C           ;                     pevent->OSEventGrp    |= bity;              /* Add new priority to wait list       */
 000C           ;                     pevent->OSEventTbl[y] |= bitx;
 000C           ;                 }
 000C           ; #endif
 000C           ;             }
 000C           ;             OSTCBPrioTbl[newprio] = ptcb;                       /* Place pointer to TCB @ new priority */
 000C           ;             ptcb->OSTCBPrio       = newprio;                    /* Set new task priority               */
 000C           ;             ptcb->OSTCBY          = y;
 000C           ;             ptcb->OSTCBX          = x;
 000C           ;             ptcb->OSTCBBitY       = bity;
 000C           ;             ptcb->OSTCBBitX       = bitx;
 000C           ;             OS_EXIT_CRITICAL();
 000C           ;             OS_Sched();                                         /* Run highest priority task ready     */
 000C           ;             return (OS_NO_ERR);
 000C           ;         } else {
 000C           ;             OSTCBPrioTbl[newprio] = (OS_TCB *)0;                /* Release the reserved prio.          */
 000C           ;             OS_EXIT_CRITICAL();
 000C           ;             return (OS_PRIO_ERR);                               /* Task to change didn't exist         */
 000C           ;         }
 000C           ;     }
 000C           ; }
 000C           ; #endif
 000C           ; /*$PAGE*/
 000C           ; /*
 000C           ; *********************************************************************************************************
 000C           ; *                                            CREATE A TASK
 000C           ; *
 000C           ; * Description: This function is used to have uC/OS-II manage the execution of a task.  Tasks can either
 000C           ; *              be created prior to the start of multitasking or by a running task.  A task cannot be
 000C           ; *              created by an ISR.
 000C           ; *
 000C           ; * Arguments  : task     is a pointer to the task's code
 000C           ; *
 000C           ; *              pdata    is a pointer to an optional data area which can be used to pass parameters to
 000C           ; *                       the task when the task first executes.  Where the task is concerned it thinks
 000C           ; *                       it was invoked and passed the argument 'pdata' as follows:
 000C           ; *
 000C           ; *                           void Task (void *pdata)
 000C           ; *                           {
 000C           ; *                               for (;;) {
 000C           ; *                                   Task code;
 000C           ; *                               }
 000C           ; *                           }
 000C           ; *
 000C           ; *              ptos     is a pointer to the task's top of stack.  If the configuration constant
 000C           ; *                       OS_STK_GROWTH is set to 1, the stack is assumed to grow downward (i.e. from high
 000C           ; *                       memory to low memory).  'pstk' will thus point to the highest (valid) memory
 000C           ; *                       location of the stack.  If OS_STK_GROWTH is set to 0, 'pstk' will point to the
 000C           ; *                       lowest memory location of the stack and the stack will grow with increasing
 000C           ; *                       memory locations.
 000C           ; *
 000C           ; *              prio     is the task's priority.  A unique priority MUST be assigned to each task and the
 000C           ; *                       lower the number, the higher the priority.
 000C           ; *
 000C           ; * Returns    : OS_NO_ERR        if the function was successful.
 000C           ; *              OS_PRIO_EXIT     if the task priority already exist
 000C           ; *                               (each task MUST have a unique priority).
 000C           ; *              OS_PRIO_INVALID  if the priority you specify is higher that the maximum allowed
 000C           ; *                               (i.e. >= OS_LOWEST_PRIO)
 000C           ; *********************************************************************************************************
 000C           ; */
 000C           ; 
 000C           ; #if OS_TASK_CREATE_EN > 0
 000C           ; INT8U  OSTaskCreate (void (*task)(void *pd), void *pdata, OS_STK *ptos, INT8U prio)
 000C           ; {
 000C                   .dbline 168
 000C           ; #if OS_CRITICAL_METHOD == 3                  /* Allocate storage for CPU status register               */
 000C           ;     OS_CPU_SR  cpu_sr;
 000C           ; #endif
 000C           ;     OS_STK    *psp;
 000C           ;     INT8U      err;
 000C           ; 
 000C           ; 
 000C           ; #if OS_ARG_CHK_EN > 0
 000C           ;     if (prio > OS_LOWEST_PRIO) {             /* Make sure priority is within allowable range           */
 000C 84E1              ldi R24,20
 000E 8C15              cp R24,R12
 0010 10F4              brsh L4
 0012                   .dbline 168
 0012                   .dbline 169
 0012           ;         return (OS_PRIO_INVALID);
 0012 0AE2              ldi R16,42
 0014 79C0              xjmp L3
 0016           L4:
 0016                   .dbline 172
 0016           ;     }
 0016           ; #endif
 0016           ;     OS_ENTER_CRITICAL();
 0016 0A93              st -y,r16
 0018 0FB7              in r16,0x3F
 001A F894              cli
 001C 0F93              push r16
 001E 0991              ld r16,y+
 0020                   .dbline 172
 0020                   .dbline 173
 0020           ;     if (OSTCBPrioTbl[prio] == (OS_TCB *)0) { /* Make sure task doesn't already exist at this priority  */
 0020 82E0              ldi R24,2
 0022 8C9D              mul R24,R12
 0024 F001              movw R30,R0
 0026 80E0              ldi R24,<_OSTCBPrioTbl
 0028 90E0              ldi R25,>_OSTCBPrioTbl
 002A E80F              add R30,R24
 002C F91F              adc R31,R25
 002E 2080              ldd R2,z+0
 0030 3180              ldd R3,z+1
 0032 2220              tst R2
 0034 09F0              breq X1
 0036 63C0              xjmp L6
 0038           X1:
 0038 3320              tst R3
 003A 09F0              breq X2
 003C 60C0              xjmp L6
 003E           X2:
 003E           X0:
 003E                   .dbline 173
 003E                   .dbline 174
 003E           ;         OSTCBPrioTbl[prio] = (OS_TCB *)1;    /* Reserve the priority to prevent others from doing ...  */
 003E 82E0              ldi R24,2
 0040 8C9D              mul R24,R12
 0042 F001              movw R30,R0
 0044 80E0              ldi R24,<_OSTCBPrioTbl
 0046 90E0              ldi R25,>_OSTCBPrioTbl
 0048 E80F              add R30,R24
 004A F91F              adc R31,R25
 004C 81E0              ldi R24,1
 004E 90E0              ldi R25,0
 0050 9183              std z+1,R25
 0052 8083              std z+0,R24
 0054                   .dbline 176
 0054           ;                                              /* ... the same thing until task is created.              */
 0054           ;         OS_EXIT_CRITICAL();
 0054 0A93              st -y,r16
 0056 0F91              pop r16
 0058 0FBF              out 0x3F,r16
 005A 0991              ld r16,y+
 005C                   .dbline 176
 005C                   .dbline 177
 005C           ;         psp = (OS_STK *)OSTaskStkInit(task, pdata, ptos, 0);    /* Initialize the task's stack         */
 005C 2224              clr R2
 005E 3324              clr R3
 0060 3B82              std y+3,R3
 0062 2A82              std y+2,R2
 0064 0E88              ldd R0,y+22
 0066 1F88              ldd R1,y+23
 0068 1982              std y+1,R1
 006A 0882              std y+0,R0

⌨️ 快捷键说明

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