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

📄 os-task-switch.s

📁 ucos-ii-at90S-icc-avr
💻 S
📖 第 1 页 / 共 2 页
字号:
	.module os-task-switch.c
	.area text(rom, con, rel)
	.dbfile G:\编程2002-10-15-HOME\做过的项目\2002-10-22\home-c\software\ucos-ii-at90S-icc-avr\os-task-switch\os-task-switch.c
	.dbfunc e OSInit _OSInit fV
;              i -> R16
	.even
_OSInit::
	.dbline -1
	.dbline 8
; //os主要代码
; #define  OS_GLOBALS                           /* Declare GLOBAL variables                              */
; #include "includes.h"
; 
; #define  OS_MASTER_FILE                       /* Prevent the following files from including includes.h */
; 
; void        OSInit(void)
; {
	.dbline 11
;   INT8U i;
; 
;   OSIntNesting=0;             /* Interrupt nesting level                              */
	clr R2
	sts _OSIntNesting,R2
	.dbline 12
;   OSLockNesting=0;            /* Multitasking lock nesting level                      */
	sts _OSLockNesting,R2
	.dbline 13
;   OSPrioCur=0xff;                /* Priority of current task                             */
	ldi R24,255
	sts _OSPrioCur,R24
	.dbline 14
;   OSPrioHighRdy=0xff;            /* Priority of highest priority task                    */
	sts _OSPrioHighRdy,R24
	.dbline 15
;   OSRunning = FALSE;
	sts _OSRunning,R2
	.dbline 17
; 
;   OSTCBCur=0;                        /* Pointer to currently running TCB              */
	clr R3
	sts _OSTCBCur+1,R3
	sts _OSTCBCur,R2
	.dbline 18
;   OSTCBHighRdy=0;                    /* Pointer to highest priority TCB ready to run  */
	sts _OSTCBHighRdy+1,R3
	sts _OSTCBHighRdy,R2
	.dbline 20
; /*init task tcb pointers list*/
;   for(i=0;i<OS_TASK_COUNT;i++)
	clr R16
	rjmp L5
L2:
	.dbline 21
	ldi R24,<_OSpTCBList
	ldi R25,>_OSpTCBList
	mov R30,R16
	clr R31
	lsl R30
	rol R31
	add R30,R24
	adc R31,R25
	clr R2
	clr R3
	std z+0,R2
	std z+1,R3
L3:
	.dbline 20
	inc R16
L5:
	.dbline 20
	cpi R16,3
	brlo L2
	.dbline -2
	.dbline 22
;     OSpTCBList[i]=(OS_TCB*)0;
; }
L1:
	.dbline 0 ; func end
	ret
	.dbsym r i 16 c
	.dbend
	.dbfunc e OSTaskCreate _OSTaskCreate fc
;            psp -> R10,R11
;            err -> R20
;           prio -> R22
;       stk_size -> y+14
;           ptos -> y+12
;          pdata -> y+10
;           task -> R10,R11
;           ptcb -> R20,R21
	.even
_OSTaskCreate::
	rcall push_gset3
	mov R10,R18
	mov R11,R19
	mov R20,R16
	mov R21,R17
	sbiw R28,4
	ldd R22,y+16
	.dbline -1
	.dbline 29
; /*
; OS_STK *	OSTaskStkInit (void (*task)(void *pd),void *pdata, OS_STK *ptos);
; INT8U       OSTCBInit(OS_TCB *ptcb,INT8U prio, OS_STK *ptos,INT16U stk_size);
; */
; 
; INT8U       OSTaskCreate(OS_TCB *ptcb,void (*task)(void *pd), void *pdata, OS_STK *ptos,INT16U stk_size, INT8U prio)
; {
	.dbline 33
;     void   *psp;
;     INT8U   err;
; 
;     if (prio > OS_LOWEST_PRIO) {             /* Make sure priority is within allowable range           */
	ldi R24,2
	cp R24,R22
	brsh L7
	.dbline 33
	.dbline 34
;         return (OSERR_PRIO_INVALID);
	ldi R16,1
	rjmp L6
L7:
	.dbline 36
;     }
;     OS_ENTER_CRITICAL();
	st -y,r16
	 in r16,0x3f
	 cli
	 push r16
	ld r16,y+
	.dbline 36
	.dbline 37
;     if (OSpTCBList[prio] == (OS_TCB *)0) { /* Make sure task doesn't already exist at this priority  */
	ldi R24,<_OSpTCBList
	ldi R25,>_OSpTCBList
	mov R30,R22
	clr R31
	lsl R30
	rol R31
	add R30,R24
	adc R31,R25
	ldd R2,z+0
	ldd R3,z+1
	tst R2
	brne L9
	tst R3
	brne L9
X0:
	.dbline 37
	.dbline 38
;         OSpTCBList[prio] = ptcb;    /* Reserve the priority to prevent others from doing ...  */
	ldi R24,<_OSpTCBList
	ldi R25,>_OSpTCBList
	mov R30,R22
	clr R31
	lsl R30
	rol R31
	add R30,R24
	adc R31,R25
	std z+0,R20
	std z+1,R21
	.dbline 39
;         OS_EXIT_CRITICAL();
	st -y,r16
	pop r16
	out 0x3F,r16
	ld r16,y+
	.dbline 39
	.dbline 40
;         psp = (void *)OSTaskStkInit(task, pdata, ptos, stk_size); /* Initialize the task's stack              */
	ldd R0,y+14
	ldd R1,y+15
	std y+2,R0
	std y+3,R1
	ldd R0,y+12
	ldd R1,y+13
	std y+0,R0
	std y+1,R1
	ldd R18,y+10
	ldd R19,y+11
	mov R16,R10
	mov R17,R11
	rcall _OSTaskStkInit
	mov R10,R16
	mov R11,R17
	.dbline 41
;         err = OSTCBInit(ptcb,prio, psp,stk_size);         
	ldd R0,y+14
	ldd R1,y+15
	std y+2,R0
	std y+3,R1
	std y+0,R10
	std y+1,R11
	mov R18,R22
	mov R16,R20
	mov R17,R21
	rcall _OSTCBInit
	mov R20,R16
	.dbline 42
;         if (err == OS_NO_ERR) {
	tst R16
	brne L11
	.dbline 42
	.dbline 43
;             if (OSRunning) {                 /* Find highest priority task if multitasking has started */
	lds R2,_OSRunning
	tst R2
	breq L12
	.dbline 43
	.dbline 44
;                 OSSched();
	rcall _OSSched
	.dbline 45
;             }
	.dbline 46
L11:
	.dbline 46
;         } else {
	.dbline 47
;         }
L12:
	.dbline 48
;         return (err);
	mov R16,R20
	rjmp L6
L9:
	.dbline 49
;     } else {
	.dbline 50
;         OS_EXIT_CRITICAL();
	st -y,r16
	pop r16
	out 0x3F,r16
	ld r16,y+
	.dbline 50
	.dbline 51
;         return (OSERR_PRIO_EXIST);
	ldi R16,3
	.dbline -2
L6:
	adiw R28,4
	rcall pop_gset3
	.dbline 0 ; func end
	ret
	.dbsym r psp 10 pV
	.dbsym r err 20 c
	.dbsym r prio 22 c
	.dbsym l stk_size 14 i
	.dbsym l ptos 12 pc
	.dbsym l pdata 10 pV
	.dbsym r task 10 pfV
	.dbsym r ptcb 20 pX
	.dbend
	.dbfunc e OSTCBInit _OSTCBInit fc
;       stk_size -> y+6
;           ptos -> y+4
;           prio -> R22
;           ptcb -> R20,R21
	.even
_OSTCBInit::
	rcall push_gset2
	mov R22,R18
	mov R20,R16
	mov R21,R17
	.dbline -1
	.dbline 99
;     }
; }
; 
; /*
; *********************************************************************************************************
; *                                            INITIALIZE TCB
; *
; * Description: This function is internal to uC/OS-II and is used to initialize a Task Control Block when
; *              a task is created (see OSTaskCreate() and OSTaskCreateExt()).
; *
; * Arguments  : prio          is the priority of the task being created
; *
; *              ptos          is a pointer to the task's top-of-stack assuming that the CPU registers
; *                            have been placed on the stack.  Note that the top-of-stack corresponds to a 
; *                            'high' memory location is OS_STK_GROWTH is set to 1 and a 'low' memory
; *                            location if OS_STK_GROWTH is set to 0.  Note that stack growth is CPU
; *                            specific.
; *
; *              pbos          is a pointer to the bottom of stack.  A NULL pointer is passed if called by
; *                            'OSTaskCreate()'.
; *
; *              id            is the task's ID (0..65535)
; *
; *              stk_size      is the size of the stack (in 'stack units').  If the stack units are INT8Us
; *                            then, 'stk_size' contains the number of bytes for the stack.  If the stack
; *                            units are INT32Us then, the stack contains '4 * stk_size' bytes.  The stack
; *                            units are established by the #define constant OS_STK which is CPU
; *                            specific.  'stk_size' is 0 if called by 'OSTaskCreate()'.
; *
; *              pext          is a pointer to a user supplied memory area that is used to extend the task
; *                            control block.  This allows you to store the contents of floating-point
; *                            registers, MMU registers or anything else you could find useful during a 
; *                            context switch.  You can even assign a name to each task and store this name
; *                            in this TCB extension.  A NULL pointer is passed if called by OSTaskCreate().
; *
; *              opt           options as passed to 'OSTaskCreateExt()' or, 
; *                            0 if called from 'OSTaskCreate()'.
; *
; * Returns    : OS_NO_ERR         if the call was successful
; *              OS_NO_MORE_TCB    if there are no more free TCBs to be allocated and thus, the task cannot
; *                                be created.
; *
; * Note       : This function is INTERNAL to uC/OS-II and your application should not call it.
; *********************************************************************************************************
; */
; 
; INT8U OSTCBInit (OS_TCB *ptcb,INT8U prio, OS_STK *ptos, INT16U stk_size)
; {
	.dbline 101
; #if OS_STRICT
;   if((0==ptcb)||(prio>OS_LOWEST_PRIO)||((INT16U)ptos<OS_HARDWARE_STACK_SIZE+40)||(stk_size<OS_HARDWARE_STACK_SIZE+40))
	cpi R20,0
	cpc R20,R21
	breq L20
X1:
	ldi R24,2
	cp R24,R22
	brlo L20
	ldd R24,y+4
	ldd R25,y+5
	cpi R24,104
	ldi R30,0
	cpc R25,R30
	brlo L20
	ldd R24,y+6
	ldd R25,y+7
	cpi R24,104
	ldi R30,0
	cpc R25,R30
	brsh L16
L20:
	.dbline 102
;     OSError(0);
	clr R16
	rcall _OSError
L16:
	.dbline 104
; #endif
;     OS_ENTER_CRITICAL();
	st -y,r16
	 in r16,0x3f
	 cli
	 push r16
	ld r16,y+
	.dbline 104
	.dbline 105
;     if ((OS_TCB *)0!=ptcb) {
	cpi R20,0
	cpc R20,R21
	breq L21
X2:
	.dbline 105
	.dbline 106
;         OS_EXIT_CRITICAL();
	st -y,r16
	pop r16
	out 0x3F,r16
	ld r16,y+
	.dbline 106
	.dbline 107
;         ptcb->OSTCBStkPtr    = ptos;                       /* Load Stack pointer in TCB                */
	mov R30,R20
	mov R31,R21
	ldd R0,y+4
	ldd R1,y+5
	std z+0,R0
	std z+1,R1
	.dbline 108
;         ptcb->OSTCBPrio      = (INT8U)prio;                /* Load task priority into TCB              */
	std z+5,R22
	.dbline 109
;         ptcb->OSTCBStat      = OS_STAT_RDY;                /* Task is ready to run                     */
	ldi R24,1
	std z+4,R24
	.dbline 110
;         ptcb->OSTCBDly       = 0;                          /* Task is not delayed                      */
	clr R2
	clr R3
	std z+2,R2
	std z+3,R3
	.dbline 112
; 
;         return (OS_NO_ERR);
	clr R16
	rjmp L15
L21:
	.dbline 113
;     } else {
	.dbline 114
;         OS_EXIT_CRITICAL();
	st -y,r16
	pop r16
	out 0x3F,r16
	ld r16,y+
	.dbline 114
	.dbline 115
;         return (OSERR_TCB_INVALID);
	ldi R16,2
	.dbline -2
L15:
	rcall pop_gset2
	.dbline 0 ; func end
	ret
	.dbsym l stk_size 6 i
	.dbsym l ptos 4 pc
	.dbsym r prio 22 c
	.dbsym r ptcb 20 pX
	.dbend
	.dbfunc e OSSched _OSSched fV
	.even
_OSSched::
	.dbline -1
	.dbline 137
;     }
; }
; 
; /*
; *********************************************************************************************************
; *                                              SCHEDULER
; *
; * Description: This function is called by other uC/OS-II services to determine whether a new, high
; *              priority task has been made ready to run.  This function is invoked by TASK level code
; *              and is not used to reschedule tasks from ISRs (see OSIntExit() for ISR rescheduling).
; *
; * Arguments  : none
; *
; * Returns    : none
; *
; * Notes      : 1) This function is INTERNAL to uC/OS-II and your application should not call it.
; *              2) Rescheduling is prevented when the scheduler is locked (see OSSchedLock())
; *********************************************************************************************************
; */
; 
; void OSSched (void)
; {
	.dbline 138
;     OS_ENTER_CRITICAL();
	st -y,r16
	 in r16,0x3f
	 cli
	 push r16
	ld r16,y+
	.dbline 138
	.dbline 139
;     if ((OSLockNesting | OSIntNesting) == 0) {   /* Task scheduling must be enabled and not ISR level  */
	lds R2,_OSIntNesting
	lds R3,_OSLockNesting
	or R3,R2
	brne L24
	.dbline 139
	.dbline 140
;         OSPrioHighRdy=OSGetPrioRdy();
	rcall _OSGetPrioRdy
	sts _OSPrioHighRdy,R16
	.dbline 141
; 		if(OSPrioHighRdy>OS_LOWEST_PRIO)
	ldi R24,2
	cp R24,R16
	brsh L26
	.dbline 142
; 		{
	.dbline 144
; #if OS_STRICT
; 		  OSError(0);
	clr R16
	rcall _OSError
	.dbline 146
	rjmp L27
L26:
	.dbline 146
; #endif
; 		}else if (OSPrioHighRdy != OSPrioCur) {         /* No context switch if current task is highest ready */
	lds R2,_OSPrioCur
	lds R3,_OSPrioHighRdy
	cp R3,R2
	breq L28
	.dbline 146
	.dbline 147
;             OSTCBHighRdy = OSpTCBList[OSPrioHighRdy];
	ldi R24,<_OSpTCBList
	ldi R25,>_OSpTCBList
	mov R30,R3
	clr R31
	lsl R30
	rol R31
	add R30,R24
	adc R31,R25
	ldd R2,z+0
	ldd R3,z+1
	sts _OSTCBHighRdy+1,R3
	sts _OSTCBHighRdy,R2
	.dbline 149
; #if OS_STRICT
; 		  	if(0==OSTCBHighRdy)
	tst R2
	brne L30
	tst R3
	brne L30
X3:
	.dbline 150
; 			  OSError(0);
	clr R16
	rcall _OSError
L30:
	.dbline 152
; #endif			
; 			OS_TASK_SW();                        /* Perform a context switch                           */
	rcall _OSCtxSw
	.dbline 153
;         }//end OSPrioHighRdy != OSPrioCur
L28:
L27:
	.dbline 154
;     }//end nesting==0
L24:
	.dbline 155
;     OS_EXIT_CRITICAL();
	st -y,r16
	pop r16
	out 0x3F,r16
	ld r16,y+
	.dbline 155
	.dbline -2
	.dbline 156
; }
L23:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e OSStart _OSStart fV
	.even
_OSStart::
	.dbline -1
	.dbline 177
; 
; /*
; *********************************************************************************************************
; *                                          START MULTITASKING
; *
; * Description: This function is used to start the multitasking process which lets uC/OS-II manages the
; *              task that you have created.  Before you can call OSStart(), you MUST have called OSInit()
; *              and you MUST have created at least one task.
; *
; * Arguments  : none
; *
; * Returns    : none
; *
; * Note       : OSStartHighRdy() MUST:
; *                 a) Call OSTaskSwHook() then,
; *                 b) Set OSRunning to TRUE.
; *********************************************************************************************************
; */
; 
; void OSStart (void)
; {
	.dbline 178
;     if (OSRunning == FALSE) {
	lds R2,_OSRunning
	tst R2
	brne L33
	.dbline 178
	.dbline 179
;         OSPrioHighRdy = 0;
	clr R2
	sts _OSPrioHighRdy,R2
	.dbline 180
;         OSPrioCur     = 0;
	sts _OSPrioCur,R2
	.dbline 181
;         OSTCBHighRdy  = OSpTCBList[OSPrioHighRdy]; /* Point to highest priority task ready to run    */
	ldi R24,<_OSpTCBList
	ldi R25,>_OSpTCBList
	mov R30,R2
	clr R31
	lsl R30
	rol R31
	add R30,R24
	adc R31,R25
	ldd R2,z+0
	ldd R3,z+1
	sts _OSTCBHighRdy+1,R3
	sts _OSTCBHighRdy,R2
	.dbline 182
;         OSTCBCur      = OSTCBHighRdy;

⌨️ 快捷键说明

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