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

📄 os_core.s

📁 1.将uC/OS-II操作系统移植到Mega16上 2.建立两个任务
💻 S
📖 第 1 页 / 共 3 页
字号:
	.even
_OSIntExit::
	.dbline -1
	.dbline 146
; /*$PAGE*/
; /*
; *********************************************************************************************************
; *                                               EXIT ISR
; *
; * Description: This function is used to notify uC/OS-II that you have completed serviving an ISR.  When 
; *              the last nested ISR has completed, uC/OS-II will call the scheduler to determine whether
; *              a new, high-priority task, is ready to run.
; *
; * Arguments  : none
; *
; * Returns    : none
; *
; * Notes      : 1) You MUST invoke OSIntEnter() and OSIntExit() in pair.  In other words, for every call
; *                 to OSIntEnter() at the beginning of the ISR you MUST have a call to OSIntExit() at the
; *                 end of the ISR.
; *              2) Rescheduling is prevented when the scheduler is locked (see OSSchedLock())
; *********************************************************************************************************
; */
; 
; void OSIntExit (void)
; {
	.dbline 147
;     OS_ENTER_CRITICAL();
	st -y,r16
	in r16,0x3f
	cli
	push r16
	ld r16,y+
	.dbline 147
	.dbline 148
;     if ((--OSIntNesting | OSLockNesting) == 0) { /* Reschedule only if all ISRs completed & not locked */
	lds R24,_OSIntNesting
	subi R24,1
	mov R2,R24
	sts _OSIntNesting,R2
	lds R4,_OSLockNesting
	or R2,R4
	breq X0
	xjmp L25
X0:
	.dbline 148
	.dbline 149
;         OSIntExitY    = OSUnMapTbl[OSRdyGrp];
	ldi R24,<_OSUnMapTbl
	ldi R25,>_OSUnMapTbl
	lds R30,_OSRdyGrp
	clr R31
	add R30,R24
	adc R31,R25
	lpm R30,Z
	sts _OSIntExitY,R30
	.dbline 150
;         OSPrioHighRdy = (INT8U)((OSIntExitY << 3) + OSUnMapTbl[OSRdyTbl[OSIntExitY]]);
	ldi R24,<_OSRdyTbl
	ldi R25,>_OSRdyTbl
	clr R31
	add R30,R24
	adc R31,R25
	ldd R30,z+0
	clr R31
	ldi R24,<_OSUnMapTbl
	ldi R25,>_OSUnMapTbl
	add R30,R24
	adc R31,R25
	lpm R2,Z
	clr R3
	lds R4,_OSIntExitY
	clr R5
	lsl R4
	rol R5
	lsl R4
	rol R5
	lsl R4
	rol R5
	add R4,R2
	adc R5,R3
	sts _OSPrioHighRdy,R4
	.dbline 151
;         if (OSPrioHighRdy != OSPrioCur) {        /* No context switch if current task is highest ready */
	lds R2,_OSPrioCur
	cp R4,R2
	breq L27
	.dbline 151
	.dbline 152
;             OSTCBHighRdy  = OSTCBPrioTbl[OSPrioHighRdy];
	mov R2,R4
	ldi R24,2
	mul R24,R2
	movw R30,R0
	ldi R24,<_OSTCBPrioTbl
	ldi R25,>_OSTCBPrioTbl
	add R30,R24
	adc R31,R25
	ldd R2,z+0
	ldd R3,z+1
	sts _OSTCBHighRdy+1,R3
	sts _OSTCBHighRdy,R2
	.dbline 153
;             OSCtxSwCtr++;                        /* Keep track of the number of context switches       */
	ldi R24,1
	ldi R25,0
	ldi R26,0
	ldi R27,0
	lds R4,_OSCtxSwCtr+2
	lds R5,_OSCtxSwCtr+2+1
	lds R2,_OSCtxSwCtr
	lds R3,_OSCtxSwCtr+1
	add R2,R24
	adc R3,R25
	adc R4,R26
	adc R5,R27
	sts _OSCtxSwCtr+1,R3
	sts _OSCtxSwCtr,R2
	sts _OSCtxSwCtr+2+1,R5
	sts _OSCtxSwCtr+2,R4
	.dbline 154
;             OSIntCtxSw();                        /* Perform interrupt level context switch             */
	xcall _OSIntCtxSw
	.dbline 155
;         }
L27:
	.dbline 156
;     }
L25:
	.dbline 157
;     OS_EXIT_CRITICAL();
	st -y,r16
	pop r16
	out 0x3F,r16
	ld r16,y+
	.dbline 157
	.dbline -2
	.dbline 158
; }
L24:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e OSSched _OSSched fV
;              y -> R20
	.even
_OSSched::
	xcall push_gset1
	.dbline -1
	.dbline 178
; /*$PAGE*/
; /*
; *********************************************************************************************************
; *                                              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 182
;     INT8U y;
; 
; 
;     OS_ENTER_CRITICAL();
	st -y,r16
	in r16,0x3f
	cli
	push r16
	ld r16,y+
	.dbline 182
	.dbline 183
;     if ((OSLockNesting | OSIntNesting) == 0) {   /* Task scheduling must be enabled and not ISR level  */
	lds R2,_OSIntNesting
	lds R3,_OSLockNesting
	or R3,R2
	breq X1
	xjmp L30
X1:
	.dbline 183
	.dbline 184
;         y             = OSUnMapTbl[OSRdyGrp];    /* Get pointer to highest priority task ready to run  */
	ldi R24,<_OSUnMapTbl
	ldi R25,>_OSUnMapTbl
	lds R30,_OSRdyGrp
	clr R31
	add R30,R24
	adc R31,R25
	lpm R20,Z
	.dbline 185
;         OSPrioHighRdy = (INT8U)((y << 3) + OSUnMapTbl[OSRdyTbl[y]]);
	ldi R24,<_OSRdyTbl
	ldi R25,>_OSRdyTbl
	mov R30,R20
	clr R31
	add R30,R24
	adc R31,R25
	ldd R30,z+0
	clr R31
	ldi R24,<_OSUnMapTbl
	ldi R25,>_OSUnMapTbl
	add R30,R24
	adc R31,R25
	lpm R2,Z
	clr R3
	mov R4,R20
	clr R5
	lsl R4
	rol R5
	lsl R4
	rol R5
	lsl R4
	rol R5
	add R4,R2
	adc R5,R3
	sts _OSPrioHighRdy,R4
	.dbline 186
;         if (OSPrioHighRdy != OSPrioCur) {         /* No context switch if current task is highest ready */
	lds R2,_OSPrioCur
	cp R4,R2
	breq L32
	.dbline 186
	.dbline 187
;             OSTCBHighRdy = OSTCBPrioTbl[OSPrioHighRdy];
	mov R2,R4
	ldi R24,2
	mul R24,R2
	movw R30,R0
	ldi R24,<_OSTCBPrioTbl
	ldi R25,>_OSTCBPrioTbl
	add R30,R24
	adc R31,R25
	ldd R2,z+0
	ldd R3,z+1
	sts _OSTCBHighRdy+1,R3
	sts _OSTCBHighRdy,R2
	.dbline 188
;             OSCtxSwCtr++;                        /* Increment context switch counter                   */
	ldi R24,1
	ldi R25,0
	ldi R26,0
	ldi R27,0
	lds R4,_OSCtxSwCtr+2
	lds R5,_OSCtxSwCtr+2+1
	lds R2,_OSCtxSwCtr
	lds R3,_OSCtxSwCtr+1
	add R2,R24
	adc R3,R25
	adc R4,R26
	adc R5,R27
	sts _OSCtxSwCtr+1,R3
	sts _OSCtxSwCtr,R2
	sts _OSCtxSwCtr+2+1,R5
	sts _OSCtxSwCtr+2,R4
	.dbline 189
;             OS_TASK_SW();                        /* Perform a context switch                           */
	xcall _OSCtxSw
	.dbline 190
;         }
L32:
	.dbline 191
;     }
L30:
	.dbline 192
;     OS_EXIT_CRITICAL();
	st -y,r16
	pop r16
	out 0x3F,r16
	ld r16,y+
	.dbline 192
	.dbline -2
	.dbline 193
; }
L29:
	xcall pop_gset1
	.dbline 0 ; func end
	ret
	.dbsym r y 20 c
	.dbend
	.dbfunc e OSStart _OSStart fV
;              x -> R22
;              y -> R20
	.even
_OSStart::
	xcall push_gset2
	.dbline -1
	.dbline 214
	.dbline 219
	lds R2,_OSRunning
	tst R2
	breq X2
	xjmp L35
X2:
	.dbline 219
	.dbline 220
	ldi R24,<_OSUnMapTbl
	ldi R25,>_OSUnMapTbl
	lds R30,_OSRdyGrp
	clr R31
	add R30,R24
	adc R31,R25
	lpm R20,Z
	.dbline 221
	ldi R24,<_OSRdyTbl
	ldi R25,>_OSRdyTbl
	mov R30,R20
	clr R31
	add R30,R24
	adc R31,R25
	ldd R30,z+0
	clr R31
	ldi R24,<_OSUnMapTbl
	ldi R25,>_OSUnMapTbl
	add R30,R24
	adc R31,R25
	lpm R22,Z
	.dbline 222
	mov R2,R22
	clr R3
	mov R4,R20
	clr R5
	lsl R4
	rol R5
	lsl R4
	rol R5
	lsl R4
	rol R5
	add R4,R2
	adc R5,R3
	sts _OSPrioHighRdy,R4
	.dbline 223
	mov R2,R4
	sts _OSPrioCur,R2
	.dbline 224
	ldi R24,2
	mul R24,R2
	movw R30,R0
	ldi R24,<_OSTCBPrioTbl
	ldi R25,>_OSTCBPrioTbl
	add R30,R24
	adc R31,R25
	ldd R2,z+0
	ldd R3,z+1
	sts _OSTCBHighRdy+1,R3
	sts _OSTCBHighRdy,R2
	.dbline 225
	sts _OSTCBCur+1,R3
	sts _OSTCBCur,R2
	.dbline 226
	xcall _OSStartHighRdy
	.dbline 227
L35:
	.dbline -2
	.dbline 228
; /*$PAGE*/
; /*
; *********************************************************************************************************
; *                                          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)
; {
;     INT8U y;
;     INT8U x;
; 
; 
;     if (OSRunning == FALSE) {
;         y             = OSUnMapTbl[OSRdyGrp];        /* Find highest priority's task priority number   */
;         x             = OSUnMapTbl[OSRdyTbl[y]];
;         OSPrioHighRdy = (INT8U)((y << 3) + x);
;         OSPrioCur     = OSPrioHighRdy;
;         OSTCBHighRdy  = OSTCBPrioTbl[OSPrioHighRdy]; /* Point to highest priority task ready to run    */
;         OSTCBCur      = OSTCBHighRdy;
;         OSStartHighRdy();                            /* Execute target specific code to start task     */
;     }
; }
L34:
	xcall pop_gset2
	.dbline 0 ; func end
	ret
	.dbsym r x 22 c
	.dbsym r y 20 c
	.dbend
	.dbfunc e OSTaskIdle _OSTaskIdle fV
;          pdata -> R16,R17
	.even
_OSTaskIdle::
	.dbline -1
	.dbline 244
; /*$PAGE*/
; /*
; *********************************************************************************************************
; *                                              IDLE TASK
; *
; * Description: This task is internal to uC/OS-II and executes whenever no other higher priority tasks
; *              executes because they are waiting for event(s) to occur.
; *
; * Arguments  : none
; *
; * Returns    : none
; *********************************************************************************************************
; */
; 
; void OSTaskIdle (void *pdata)
; {
	.dbline 245
;     pdata = pdata;                               /* Prevent compiler warning for not using 'pdata'     */
	.dbline 246
L38:
	.dbline 246
	.dbline 247
	st -y,r16
	in r16,0x3f
	cli
	push r16
	ld r16,y+
	.dbline 247
	.dbline 248
	ldi R24,1
	ldi R25,0
	ldi R26,0
	ldi R27,0
	lds R4,_OSIdleCtr+2
	lds R5,_OSIdleCtr+2+1
	lds R2,_OSIdleCtr
	lds R3,_OSIdleCtr+1
	add R2,R24
	adc R3,R25
	adc R4,R26
	adc R5,R27
	sts _OSIdleCtr+1,R3
	sts _OSIdleCtr,R2
	sts _OSIdleCtr+2+1,R5
	sts _OSIdleCtr+2,R4
	.dbline 249
	st -y,r16
	pop r16
	out 0x3F,r16
	ld r16,y+
	.dbline 249
	.dbline 250
	.dbline 246
	.dbline 246
	xjmp L38
X3:
	.dbline -2
L37:
	.dbline 0 ; func end
	ret
	.dbsym r pdata 16 pV
	.dbend
	.dbfunc e OSTCBInit _OSTCBInit fc
;           ptcb -> R20,R21
;            opt -> y+10
;           pext -> y+8
;       stk_size -> y+6
;             id -> y+4
;           pbos -> y+2
;           ptos -> R18,R19
;           prio -> R16
	.even
_OSTCBInit::
	xcall push_gset1
	.dbline -1
	.dbline 297
;     for (;;) {
;         OS_ENTER_CRITICAL();
;         OSIdleCtr++;
;         OS_EXIT_CRITICAL();
;     }
; }
; /*$PAGE*/
; /*
; *********************************************************************************************************
; *                                            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
; *

⌨️ 快捷键说明

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