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

📄 os_task.s

📁 ucos如何移植到单片机mega128
💻 S
📖 第 1 页 / 共 4 页
字号:
	.module OS_TASK.C
	.area text(rom, con, rel)
	.dbfile E:\study\ucos_ii\ucos2_iccavr\iccavr\ucos2_without_cpu\OS_TASK.C
	.dbfunc e OSTaskCreate _OSTaskCreate fc
;            psp -> R10,R11
;            err -> R10
;           prio -> R12
;           ptos -> y+22
;          pdata -> R14,R15
;           task -> R10,R11
	.even
_OSTaskCreate::
	xcall push_gset5
	movw R14,R18
	movw R10,R16
	sbiw R28,12
	ldd R12,y+24
	.dbline -1
	.dbline 159
; /*
; *********************************************************************************************************
; *                                                uC/OS-II
; *                                          The Real-Time Kernel
; *                                            TASK MANAGEMENT
; *
; *                          (c) Copyright 1992-2002, Jean J. Labrosse, Weston, FL
; *                                           All Rights Reserved
; *
; * File : OS_TASK.C
; * By   : Jean J. Labrosse
; *********************************************************************************************************
; */
; 
; #ifndef  OS_MASTER_FILE
; #include "..\ucos2_application\includes.h"
; #endif
; 
; /*
; *********************************************************************************************************
; *                                        CHANGE PRIORITY OF A TASK
; *
; * Description: This function allows you to change the priority of a task dynamically.  Note that the new
; *              priority MUST be available.
; *
; * Arguments  : oldp     is the old priority
; *
; *              newp     is the new priority
; *
; * Returns    : OS_NO_ERR        is the call was successful
; *              OS_PRIO_INVALID  if the priority you specify is higher that the maximum allowed
; *                               (i.e. >= OS_LOWEST_PRIO)
; *              OS_PRIO_EXIST    if the new priority already exist.
; *              OS_PRIO_ERR      there is no task with the specified OLD priority (i.e. the OLD task does
; *                               not exist.
; *********************************************************************************************************
; */
; 
; #if OS_TASK_CHANGE_PRIO_EN > 0
; INT8U  OSTaskChangePrio (INT8U oldprio, INT8U newprio)
; {
; #if OS_CRITICAL_METHOD == 3                      /* Allocate storage for CPU status register           */
;     OS_CPU_SR    cpu_sr;
; #endif
; 
; #if OS_EVENT_EN > 0
;     OS_EVENT    *pevent;
; #endif
; 
;     OS_TCB      *ptcb;
;     INT8U        x;
;     INT8U        y;
;     INT8U        bitx;
;     INT8U        bity;
; 
; 
; 
; #if OS_ARG_CHK_EN > 0
;     if ((oldprio >= OS_LOWEST_PRIO && oldprio != OS_PRIO_SELF)  ||
;          newprio >= OS_LOWEST_PRIO) {
;         return (OS_PRIO_INVALID);
;     }
; #endif
;     OS_ENTER_CRITICAL();
;     if (OSTCBPrioTbl[newprio] != (OS_TCB *)0) {                 /* New priority must not already exist */
;         OS_EXIT_CRITICAL();
;         return (OS_PRIO_EXIST);
;     } else {
;         OSTCBPrioTbl[newprio] = (OS_TCB *)1;                    /* Reserve the entry to prevent others */
;         OS_EXIT_CRITICAL();
;         y    = newprio >> 3;                                    /* Precompute to reduce INT. latency   */
;         bity = OSMapTbl[y];
;         x    = newprio & 0x07;
;         bitx = OSMapTbl[x];
;         OS_ENTER_CRITICAL();
;         if (oldprio == OS_PRIO_SELF) {                          /* See if changing self                */
;             oldprio = OSTCBCur->OSTCBPrio;                      /* Yes, get priority                   */
;         }
;         ptcb = OSTCBPrioTbl[oldprio];
;         if (ptcb != (OS_TCB *)0) {                              /* Task to change must exist           */
;             OSTCBPrioTbl[oldprio] = (OS_TCB *)0;                /* Remove TCB from old priority        */
;             if ((OSRdyTbl[ptcb->OSTCBY] & ptcb->OSTCBBitX) != 0x00) {  /* If task is ready make it not */
;                 if ((OSRdyTbl[ptcb->OSTCBY] &= ~ptcb->OSTCBBitX) == 0x00) {
;                     OSRdyGrp &= ~ptcb->OSTCBBitY;
;                 }
;                 OSRdyGrp    |= bity;                            /* Make new priority ready to run      */
;                 OSRdyTbl[y] |= bitx;
; #if OS_EVENT_EN > 0
;             } else {
;                 pevent = ptcb->OSTCBEventPtr;
;                 if (pevent != (OS_EVENT *)0) {                  /* Remove from event wait list  */
;                     if ((pevent->OSEventTbl[ptcb->OSTCBY] &= ~ptcb->OSTCBBitX) == 0) {
;                         pevent->OSEventGrp &= ~ptcb->OSTCBBitY;
;                     }
;                     pevent->OSEventGrp    |= bity;              /* Add new priority to wait list       */
;                     pevent->OSEventTbl[y] |= bitx;
;                 }
; #endif
;             }
;             OSTCBPrioTbl[newprio] = ptcb;                       /* Place pointer to TCB @ new priority */
;             ptcb->OSTCBPrio       = newprio;                    /* Set new task priority               */
;             ptcb->OSTCBY          = y;
;             ptcb->OSTCBX          = x;
;             ptcb->OSTCBBitY       = bity;
;             ptcb->OSTCBBitX       = bitx;
;             OS_EXIT_CRITICAL();
;             OS_Sched();                                         /* Run highest priority task ready     */
;             return (OS_NO_ERR);
;         } else {
;             OSTCBPrioTbl[newprio] = (OS_TCB *)0;                /* Release the reserved prio.          */
;             OS_EXIT_CRITICAL();
;             return (OS_PRIO_ERR);                               /* Task to change didn't exist         */
;         }
;     }
; }
; #endif
; /*$PAGE*/
; /*
; *********************************************************************************************************
; *                                            CREATE A TASK
; *
; * Description: This function is used to have uC/OS-II manage the execution of a task.  Tasks can either
; *              be created prior to the start of multitasking or by a running task.  A task cannot be
; *              created by an ISR.
; *
; * Arguments  : task     is a pointer to the task's code
; *
; *              pdata    is a pointer to an optional data area which can be used to pass parameters to
; *                       the task when the task first executes.  Where the task is concerned it thinks
; *                       it was invoked and passed the argument 'pdata' as follows:
; *
; *                           void Task (void *pdata)
; *                           {
; *                               for (;;) {
; *                                   Task code;
; *                               }
; *                           }
; *
; *              ptos     is a pointer to the task's top of stack.  If the configuration constant
; *                       OS_STK_GROWTH is set to 1, the stack is assumed to grow downward (i.e. from high
; *                       memory to low memory).  'pstk' will thus point to the highest (valid) memory
; *                       location of the stack.  If OS_STK_GROWTH is set to 0, 'pstk' will point to the
; *                       lowest memory location of the stack and the stack will grow with increasing
; *                       memory locations.
; *
; *              prio     is the task's priority.  A unique priority MUST be assigned to each task and the
; *                       lower the number, the higher the priority.
; *
; * Returns    : OS_NO_ERR        if the function was successful.
; *              OS_PRIO_EXIT     if the task priority already exist
; *                               (each task MUST have a unique priority).
; *              OS_PRIO_INVALID  if the priority you specify is higher that the maximum allowed
; *                               (i.e. >= OS_LOWEST_PRIO)
; *********************************************************************************************************
; */
; 
; #if OS_TASK_CREATE_EN > 0
; INT8U  OSTaskCreate (void (*task)(void *pd), void *pdata, OS_STK *ptos, INT8U prio)
; {
	.dbline 168
; #if OS_CRITICAL_METHOD == 3                  /* Allocate storage for CPU status register               */
;     OS_CPU_SR  cpu_sr;
; #endif
;     OS_STK    *psp;
;     INT8U      err;
; 
; 
; #if OS_ARG_CHK_EN > 0
;     if (prio > OS_LOWEST_PRIO) {             /* Make sure priority is within allowable range           */
	ldi R24,20
	cp R24,R12
	brsh L4
	.dbline 168
	.dbline 169
;         return (OS_PRIO_INVALID);
	ldi R16,42
	xjmp L3
L4:
	.dbline 172
;     }
; #endif
;     OS_ENTER_CRITICAL();
	st -y,r16
	in r16,0x3F
	cli
	push r16
	ld r16,y+
	.dbline 172
	.dbline 173
;     if (OSTCBPrioTbl[prio] == (OS_TCB *)0) { /* Make sure task doesn't already exist at this priority  */
	ldi R24,2
	mul R24,R12
	movw R30,R0
	ldi R24,<_OSTCBPrioTbl
	ldi R25,>_OSTCBPrioTbl
	add R30,R24
	adc R31,R25
	ldd R2,z+0
	ldd R3,z+1
	tst R2
	breq X1
	xjmp L6
X1:
	tst R3
	breq X2
	xjmp L6
X2:
X0:
	.dbline 173
	.dbline 174
;         OSTCBPrioTbl[prio] = (OS_TCB *)1;    /* Reserve the priority to prevent others from doing ...  */
	ldi R24,2
	mul R24,R12
	movw R30,R0
	ldi R24,<_OSTCBPrioTbl
	ldi R25,>_OSTCBPrioTbl
	add R30,R24
	adc R31,R25
	ldi R24,1
	ldi R25,0
	std z+1,R25
	std z+0,R24
	.dbline 176
;                                              /* ... the same thing until task is created.              */
;         OS_EXIT_CRITICAL();
	st -y,r16
	pop r16
	out 0x3F,r16
	ld r16,y+
	.dbline 176
	.dbline 177
;         psp = (OS_STK *)OSTaskStkInit(task, pdata, ptos, 0);    /* Initialize the task's stack         */
	clr R2
	clr R3
	std y+3,R3
	std y+2,R2
	ldd R0,y+22
	ldd R1,y+23
	std y+1,R1
	std y+0,R0
	movw R18,R14
	movw R16,R10
	xcall _OSTaskStkInit
	movw R10,R16
	.dbline 178
;         err = OS_TCBInit(prio, psp, (OS_STK *)0, 0, 0, (void *)0, 0);
	clr R2
	clr R3
	std y+11,R3
	std y+10,R2
	std y+9,R3
	std y+8,R2
	ldi R20,0
	ldi R21,0
	ldi R22,0
	ldi R23,0
	std y+4,R20
	std y+5,R21
	std y+6,R22
	std y+7,R23
	std y+3,R3
	std y+2,R2
	std y+1,R3
	std y+0,R2
	movw R18,R10
	mov R16,R12
	xcall _OS_TCBInit
	mov R10,R16
	.dbline 179
;         if (err == OS_NO_ERR) {
	tst R16
	brne L8
	.dbline 179
	.dbline 180
;             OS_ENTER_CRITICAL();
	st -y,r16
	in r16,0x3F
	cli
	push r16
	ld r16,y+
	.dbline 180
	.dbline 181
;             OSTaskCtr++;                                        /* Increment the #tasks counter        */
	lds R24,_OSTaskCtr
	subi R24,255    ; addi 1
	sts _OSTaskCtr,R24
	.dbline 182
;             OS_EXIT_CRITICAL();
	st -y,r16
	pop r16
	out 0x3F,r16
	ld r16,y+
	.dbline 182
	.dbline 183
;             if (OSRunning == TRUE) {         /* Find highest priority task if multitasking has started */
	lds R24,_OSRunning
	cpi R24,1
	brne L9
	.dbline 183
	.dbline 184
;                 OS_Sched();
	xcall _OS_Sched
	.dbline 185
;             }
	.dbline 186
	xjmp L9
L8:
	.dbline 186
;         } else {
	.dbline 187
;             OS_ENTER_CRITICAL();
	st -y,r16
	in r16,0x3F
	cli
	push r16
	ld r16,y+
	.dbline 187
	.dbline 188
;             OSTCBPrioTbl[prio] = (OS_TCB *)0;/* Make this priority available to others                 */
	ldi R24,2
	mul R24,R12
	movw R30,R0
	ldi R24,<_OSTCBPrioTbl
	ldi R25,>_OSTCBPrioTbl
	add R30,R24
	adc R31,R25
	clr R2
	clr R3
	std z+1,R3
	std z+0,R2
	.dbline 189
;             OS_EXIT_CRITICAL();
	st -y,r16
	pop r16
	out 0x3F,r16
	ld r16,y+
	.dbline 189
	.dbline 190
;         }
L9:
	.dbline 191
;         return (err);
	mov R16,R10
	xjmp L3
L6:
	.dbline 193
;     }
;     OS_EXIT_CRITICAL();
	st -y,r16
	pop r16
	out 0x3F,r16
	ld r16,y+
	.dbline 193
	.dbline 194
;     return (OS_PRIO_EXIST);
	ldi R16,40
	.dbline -2
L3:
	adiw R28,12
	xcall pop_gset5
	.dbline 0 ; func end
	ret
	.dbsym r psp 10 pc
	.dbsym r err 10 c
	.dbsym r prio 12 c
	.dbsym l ptos 22 pc
	.dbsym r pdata 14 pV
	.dbsym r task 10 pfV
	.dbend
	.dbfunc e OSTaskDel _OSTaskDel fc
	.dbstruct 0 10 .2
	.dbfield 0 OSFlagNodeNext pV
	.dbfield 2 OSFlagNodePrev pV
	.dbfield 4 OSFlagNodeTCB pV
	.dbfield 6 OSFlagNodeFlagGrp pV
	.dbfield 8 OSFlagNodeFlags c
	.dbfield 9 OSFlagNodeWaitType c
	.dbend
	.dbstruct 0 18 os_tcb
	.dbfield 0 OSTCBStkPtr pc

⌨️ 快捷键说明

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