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

📄 os_task.src

📁 uCOS-II_2.52在51上的移植程序
💻 SRC
字号:
; .\OS_TASK.SRC generated from: OS_TASK.C
; COMPILER INVOKED BY:
;        C:\Keil\C51\BIN\C51.EXE OS_TASK.C LARGE BROWSE ORDER NOAREGS DEBUG OBJECTEXTEND SRC(.\OS_TASK.SRC)

$NOMOD51

NAME	OS_TASK

P0	DATA	080H
P1	DATA	090H
P2	DATA	0A0H
P3	DATA	0B0H
PSW	DATA	0D0H
ACC	DATA	0E0H
B	DATA	0F0H
SP	DATA	081H
DPL	DATA	082H
DPH	DATA	083H
PCON	DATA	087H
TCON	DATA	088H
TMOD	DATA	089H
TL0	DATA	08AH
TL1	DATA	08BH
TH0	DATA	08CH
TH1	DATA	08DH
IE	DATA	0A8H
IP	DATA	0B8H
SCON	DATA	098H
SBUF	DATA	099H
CY	BIT	0D0H.7
AC	BIT	0D0H.6
F0	BIT	0D0H.5
RS1	BIT	0D0H.4
RS0	BIT	0D0H.3
OV	BIT	0D0H.2
P	BIT	0D0H.0
TF1	BIT	088H.7
TR1	BIT	088H.6
TF0	BIT	088H.5
TR0	BIT	088H.4
IE1	BIT	088H.3
IT1	BIT	088H.2
IE0	BIT	088H.1
IT0	BIT	088H.0
EA	BIT	0A8H.7
ES	BIT	0A8H.4
ET1	BIT	0A8H.3
EX1	BIT	0A8H.2
ET0	BIT	0A8H.1
EX0	BIT	0A8H.0
PS	BIT	0B8H.4
PT1	BIT	0B8H.3
PX1	BIT	0B8H.2
PT0	BIT	0B8H.1
PX0	BIT	0B8H.0
RD	BIT	0B0H.7
WR	BIT	0B0H.6
T1	BIT	0B0H.5
T0	BIT	0B0H.4
INT1	BIT	0B0H.3
INT0	BIT	0B0H.2
TXD	BIT	0B0H.1
RXD	BIT	0B0H.0
SM0	BIT	098H.7
SM1	BIT	098H.6
SM2	BIT	098H.5
REN	BIT	098H.4
TB8	BIT	098H.3
RB8	BIT	098H.2
TI	BIT	098H.1
RI	BIT	098H.0
?PR?_OSTaskCreate?OS_TASK                SEGMENT CODE 
?XD?_OSTaskCreate?OS_TASK                SEGMENT XDATA OVERLAYABLE 
	EXTRN	IDATA (OSRunning)
	EXTRN	XDATA (OSTaskCtr)
	EXTRN	XDATA (OSTCBPrioTbl)
	EXTRN	CODE (OS_Sched)
	EXTRN	CODE (_OS_TCBInit)
	EXTRN	XDATA (?_OS_TCBInit?BYTE)
	EXTRN	CODE (_?OSTaskStkInit)
	EXTRN	CODE (?C?ADDXBP)
	EXTRN	CODE (?C?LSTKXDATA)
	PUBLIC	?_OSTaskCreate?BYTE
	PUBLIC	_OSTaskCreate

	RSEG  ?XD?_OSTaskCreate?OS_TASK
?_OSTaskCreate?BYTE:
       task?040:   DS   3
     ppdata?041:   DS   3
       ptos?042:   DS   3
       prio?043:   DS   1
	ORG  10
        err?045:   DS   1
; /*
; *********************************************************************************************************
; *                                                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 "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_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 *ppdata, OS_STK *ptos, INT8U prio)

	RSEG  ?PR?_OSTaskCreate?OS_TASK
_OSTaskCreate:
	USING	0
			; SOURCE LINE # 156
	MOV  	DPTR,#task?040
	MOV  	A,R3
	MOVX 	@DPTR,A
	INC  	DPTR
	MOV  	A,R2
	MOVX 	@DPTR,A
	INC  	DPTR
	MOV  	A,R1
	MOVX 	@DPTR,A
; {
			; SOURCE LINE # 157
; 
;     OS_STK    *psp;
;     INT8U      err;
; 
; 
; #if OS_ARG_CHK_EN > 0
;     if (prio > OS_LOWEST_PRIO) {             /* Make sure priority is within allowable range           */
;         return (OS_PRIO_INVALID);
;     }
; #endif
;     OS_ENTER_CRITICAL();
			; SOURCE LINE # 168
	CLR  	EA
;     if (OSTCBPrioTbl[prio] == (OS_TCB *)0) { /* Make sure task doesn't already exist at this priority  */
			; SOURCE LINE # 169
	MOV  	DPTR,#prio?043
	MOVX 	A,@DPTR
	MOV  	R7,A
	MOV  	B,#03H
	MUL  	AB
	ADD  	A,#LOW (OSTCBPrioTbl)
	MOV  	DPL,A
	CLR  	A
	ADDC 	A,#HIGH (OSTCBPrioTbl)
	MOV  	DPH,A
	MOVX 	A,@DPTR
	MOV  	R3,A
	INC  	DPTR
	MOVX 	A,@DPTR
	MOV  	R2,A
	INC  	DPTR
	MOVX 	A,@DPTR
	ORL  	A,R2
	ORL  	A,R3
	JZ   	$ + 5H
	LJMP 	?C0001
;         OSTCBPrioTbl[prio] = (OS_TCB *)1;    /* Reserve the priority to prevent others from doing ...  */
			; SOURCE LINE # 170
	MOV  	R1,#01H
	MOV  	A,R7
	MOV  	B,#03H
	MUL  	AB
	ADD  	A,#LOW (OSTCBPrioTbl)
	MOV  	DPL,A
	CLR  	A
	ADDC 	A,#HIGH (OSTCBPrioTbl)
	MOV  	DPH,A
	CLR  	A
	MOVX 	@DPTR,A
	INC  	DPTR
	MOVX 	@DPTR,A
	INC  	DPTR
	INC  	A
	MOVX 	@DPTR,A
;                                              /* ... the same thing until task is created.              */
;         OS_EXIT_CRITICAL();
			; SOURCE LINE # 172
	SETB 	EA
;         psp = (OS_STK *)OSTaskStkInit(task, ppdata, ptos, 0);    /* Initialize the task's stack         */
			; SOURCE LINE # 173
	MOV  	DPTR,#0FFFEH
	LCALL	?C?ADDXBP
	CLR  	A
	MOVX 	@DPTR,A
	INC  	DPTR
	MOVX 	@DPTR,A
	MOV  	DPTR,#ptos?042
	MOVX 	A,@DPTR
	MOV  	R3,A
	INC  	DPTR
	MOVX 	A,@DPTR
	MOV  	R2,A
	INC  	DPTR
	MOVX 	A,@DPTR
	MOV  	R1,A
	MOV  	DPTR,#0FFFDH
	LCALL	?C?ADDXBP
	MOV  	A,R3
	MOVX 	@DPTR,A
	INC  	DPTR
	MOV  	A,R2
	MOVX 	@DPTR,A
	INC  	DPTR
	MOV  	A,R1
	MOVX 	@DPTR,A
	MOV  	DPTR,#ppdata?041
	MOVX 	A,@DPTR
	MOV  	R3,A
	INC  	DPTR
	MOVX 	A,@DPTR
	MOV  	R2,A
	INC  	DPTR
	MOVX 	A,@DPTR
	MOV  	R1,A
	MOV  	DPTR,#0FFFDH
	LCALL	?C?ADDXBP
	MOV  	A,R3
	MOVX 	@DPTR,A
	INC  	DPTR
	MOV  	A,R2
	MOVX 	@DPTR,A
	INC  	DPTR
	MOV  	A,R1
	MOVX 	@DPTR,A
	MOV  	DPTR,#task?040
	MOVX 	A,@DPTR
	MOV  	R3,A
	INC  	DPTR
	MOVX 	A,@DPTR
	MOV  	R2,A
	INC  	DPTR
	MOVX 	A,@DPTR
	MOV  	R1,A
	LCALL	_?OSTaskStkInit
;---- Variable 'psp?044' assigned to Register 'R1/R2/R3' ----
;         err = OS_TCBInit(prio, psp, (OS_STK *)0, 0, 0, (void *)0, 0);
			; SOURCE LINE # 174
	MOV  	DPTR,#?_OS_TCBInit?BYTE+04H
	CLR  	A
	MOVX 	@DPTR,A
	INC  	DPTR
	MOVX 	@DPTR,A
	INC  	DPTR
	MOVX 	@DPTR,A
	INC  	DPTR
	MOVX 	@DPTR,A
	INC  	DPTR
	MOVX 	@DPTR,A
	INC  	DPTR
	LCALL	?C?LSTKXDATA
	DB   	00H
	DB   	00H
	DB   	00H
	DB   	00H
	MOV  	DPTR,#?_OS_TCBInit?BYTE+0DH
	CLR  	A
	MOVX 	@DPTR,A
	INC  	DPTR
	MOVX 	@DPTR,A
	INC  	DPTR
	MOVX 	@DPTR,A
	INC  	DPTR
	MOVX 	@DPTR,A
	INC  	DPTR
	MOVX 	@DPTR,A
	MOV  	DPTR,#prio?043
	MOVX 	A,@DPTR
	MOV  	R7,A
	LCALL	_OS_TCBInit
	MOV  	DPTR,#err?045
	MOV  	A,R7
	MOVX 	@DPTR,A
;         if (err == OS_NO_ERR) {
			; SOURCE LINE # 175
	JNZ  	?C0002
;             OS_ENTER_CRITICAL();
			; SOURCE LINE # 176
	CLR  	EA
;             OSTaskCtr++;                                        /* Increment the #tasks counter        */
			; SOURCE LINE # 177
	MOV  	DPTR,#OSTaskCtr
	MOVX 	A,@DPTR
	INC  	A
	MOVX 	@DPTR,A
;             OS_EXIT_CRITICAL();
			; SOURCE LINE # 178
	SETB 	EA
;             if (OSRunning == TRUE) {         /* Find highest priority task if multitasking has started */
			; SOURCE LINE # 179
	MOV  	R0,#LOW (OSRunning)
	MOV  	A,@R0
	CJNE 	A,#01H,?C0004
;                 OS_Sched();
			; SOURCE LINE # 180
	LCALL	OS_Sched
;             }
			; SOURCE LINE # 181
;         } else {
			; SOURCE LINE # 182
	SJMP 	?C0004
?C0002:
;             OS_ENTER_CRITICAL();
			; SOURCE LINE # 183
	CLR  	EA
;             OSTCBPrioTbl[prio] = (OS_TCB *)0;/* Make this priority available to others                 */
			; SOURCE LINE # 184
	MOV  	DPTR,#prio?043
	MOVX 	A,@DPTR
	MOV  	B,#03H
	MUL  	AB
	ADD  	A,#LOW (OSTCBPrioTbl)
	MOV  	DPL,A
	CLR  	A
	ADDC 	A,#HIGH (OSTCBPrioTbl)
	MOV  	DPH,A
	CLR  	A
	MOVX 	@DPTR,A
	INC  	DPTR
	MOVX 	@DPTR,A
	INC  	DPTR
	MOVX 	@DPTR,A
;             OS_EXIT_CRITICAL();
			; SOURCE LINE # 185
	SETB 	EA
;         }
			; SOURCE LINE # 186
?C0004:
;         return (err);
			; SOURCE LINE # 187
	MOV  	DPTR,#err?045
	MOVX 	A,@DPTR
	MOV  	R7,A
	RET  	
;     }
			; SOURCE LINE # 188
?C0001:
;     OS_EXIT_CRITICAL();
			; SOURCE LINE # 189
	SETB 	EA
;     return (OS_PRIO_EXIST);
			; SOURCE LINE # 190
	MOV  	R7,#028H
; }
			; SOURCE LINE # 191
?C0005:
	RET  	
; END OF _OSTaskCreate

	END

⌨️ 快捷键说明

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