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

📄 os_task.s

📁 ucos如何移植到单片机mega128
💻 S
📖 第 1 页 / 共 4 页
字号:
	pop r16
	out 0x3F,r16
	ld r16,y+
	.dbline 557
	.dbline 558
;         return (OS_TASK_RESUME_PRIO);
	ldi R16,100
	xjmp L42
L45:
	.dbline 560
;     }
;     if ((ptcb->OSTCBStat & OS_STAT_SUSPEND) != OS_STAT_RDY) {              /* Task must be suspended   */
	movw R30,R20
	ldd R2,z+11
	sbrs R2,3
	rjmp L47
	.dbline 560
	.dbline 561
;         if (((ptcb->OSTCBStat &= ~OS_STAT_SUSPEND) == OS_STAT_RDY) &&      /* Remove suspension        */
	movw R24,R20
	adiw R24,11
	movw R30,R24
	ldd R24,z+0
	andi R24,247
	mov R4,R24
	std z+0,R4
	tst R24
	breq X10
	xjmp L49
X10:
	movw R30,R20
	ldd R2,z+9
	ldd R3,z+10
	tst R2
	brne L49
	tst R3
	brne L49
X9:
	.dbline 562
;              (ptcb->OSTCBDly  == 0)) {                                     /* Must not be delayed      */
	.dbline 563
;             OSRdyGrp               |= ptcb->OSTCBBitY;                     /* Make task ready to run   */
	movw R30,R20
	ldd R2,z+16
	lds R3,_OSRdyGrp
	or R3,R2
	sts _OSRdyGrp,R3
	.dbline 564
;             OSRdyTbl[ptcb->OSTCBY] |= ptcb->OSTCBBitX;
	ldi R24,<_OSRdyTbl
	ldi R25,>_OSRdyTbl
	movw R30,R20
	ldd R2,z+14
	clr R3
	add R2,R24
	adc R3,R25
	movw R30,R20
	ldd R4,z+15
	movw R30,R2
	ldd R5,z+0
	or R5,R4
	std z+0,R5
	.dbline 565
;             OS_EXIT_CRITICAL();
	st -y,r16
	pop r16
	out 0x3F,r16
	ld r16,y+
	.dbline 565
	.dbline 566
;             OS_Sched();
	xcall _OS_Sched
	.dbline 567
	xjmp L50
L49:
	.dbline 567
;         } else {
	.dbline 568
;             OS_EXIT_CRITICAL();
	st -y,r16
	pop r16
	out 0x3F,r16
	ld r16,y+
	.dbline 568
	.dbline 569
;         }
L50:
	.dbline 570
;         return (OS_NO_ERR);
	clr R16
	xjmp L42
L47:
	.dbline 572
;     }
;     OS_EXIT_CRITICAL();
	st -y,r16
	pop r16
	out 0x3F,r16
	ld r16,y+
	.dbline 572
	.dbline 573
;     return (OS_TASK_NOT_SUSPENDED);
	ldi R16,101
	.dbline -2
L42:
	xcall pop_gset1
	.dbline 0 ; func end
	ret
	.dbsym r ptcb 20 pS[os_tcb]
	.dbsym r prio 20 c
	.dbend
	.dbfunc e OSTaskSuspend _OSTaskSuspend fc
;           self -> R20
;           ptcb -> R22,R23
;           prio -> R22
	.even
_OSTaskSuspend::
	xcall push_gset2
	mov R22,R16
	.dbline -1
	.dbline 670
; }
; #endif
; /*$PAGE*/
; /*
; *********************************************************************************************************
; *                                             STACK CHECKING
; *
; * Description: This function is called to check the amount of free memory left on the specified task's
; *              stack.
; *
; * Arguments  : prio     is the task priority
; *
; *              pdata    is a pointer to a data structure of type OS_STK_DATA.
; *
; * Returns    : OS_NO_ERR           upon success
; *              OS_PRIO_INVALID     if the priority you specify is higher that the maximum allowed
; *                                  (i.e. > OS_LOWEST_PRIO) or, you have not specified OS_PRIO_SELF.
; *              OS_TASK_NOT_EXIST   if the desired task has not been created
; *              OS_TASK_OPT_ERR     if you did NOT specified OS_TASK_OPT_STK_CHK when the task was created
; *********************************************************************************************************
; */
; #if OS_TASK_CREATE_EXT_EN > 0
; INT8U  OSTaskStkChk (INT8U prio, OS_STK_DATA *pdata)
; {
; #if OS_CRITICAL_METHOD == 3                      /* Allocate storage for CPU status register           */
;     OS_CPU_SR  cpu_sr;
; #endif
;     OS_TCB    *ptcb;
;     OS_STK    *pchk;
;     INT32U     free;
;     INT32U     size;
; 
; 
; #if OS_ARG_CHK_EN > 0
;     if (prio > OS_LOWEST_PRIO && prio != OS_PRIO_SELF) {        /* Make sure task priority is valid    */
;         return (OS_PRIO_INVALID);
;     }
; #endif
;     pdata->OSFree = 0;                                          /* Assume failure, set to 0 size       */
;     pdata->OSUsed = 0;
;     OS_ENTER_CRITICAL();
;     if (prio == OS_PRIO_SELF) {                        /* See if check for SELF                        */
;         prio = OSTCBCur->OSTCBPrio;
;     }
;     ptcb = OSTCBPrioTbl[prio];
;     if (ptcb == (OS_TCB *)0) {                         /* Make sure task exist                         */
;         OS_EXIT_CRITICAL();
;         return (OS_TASK_NOT_EXIST);
;     }
;     if ((ptcb->OSTCBOpt & OS_TASK_OPT_STK_CHK) == 0) { /* Make sure stack checking option is set       */
;         OS_EXIT_CRITICAL();
;         return (OS_TASK_OPT_ERR);
;     }
;     free = 0;
;     size = ptcb->OSTCBStkSize;
;     pchk = ptcb->OSTCBStkBottom;
;     OS_EXIT_CRITICAL();
; #if OS_STK_GROWTH == 1
;     while (*pchk++ == (OS_STK)0) {                    /* Compute the number of zero entries on the stk */
;         free++;
;     }
; #else
;     while (*pchk-- == (OS_STK)0) {
;         free++;
;     }
; #endif
;     pdata->OSFree = free * sizeof(OS_STK);            /* Compute number of free bytes on the stack     */
;     pdata->OSUsed = (size - free) * sizeof(OS_STK);   /* Compute number of bytes used on the stack     */
;     return (OS_NO_ERR);
; }
; #endif
; /*$PAGE*/
; /*
; *********************************************************************************************************
; *                                            SUSPEND A TASK
; *
; * Description: This function is called to suspend a task.  The task can be the calling task if the
; *              priority passed to OSTaskSuspend() is the priority of the calling task or OS_PRIO_SELF.
; *
; * Arguments  : prio     is the priority of the task to suspend.  If you specify OS_PRIO_SELF, the
; *                       calling task will suspend itself and rescheduling will occur.
; *
; * Returns    : OS_NO_ERR                if the requested task is suspended
; *              OS_TASK_SUSPEND_IDLE     if you attempted to suspend the idle task which is not allowed.
; *              OS_PRIO_INVALID          if the priority you specify is higher that the maximum allowed
; *                                       (i.e. >= OS_LOWEST_PRIO) or, you have not specified OS_PRIO_SELF.
; *              OS_TASK_SUSPEND_PRIO     if the task to suspend does not exist
; *
; * Note       : You should use this function with great care.  If you suspend a task that is waiting for
; *              an event (i.e. a message, a semaphore, a queue ...) you will prevent this task from
; *              running when the event arrives.
; *********************************************************************************************************
; */
; 
; #if OS_TASK_SUSPEND_EN > 0
; INT8U  OSTaskSuspend (INT8U prio)
; {
	.dbline 679
; #if OS_CRITICAL_METHOD == 3                      /* Allocate storage for CPU status register           */
;     OS_CPU_SR  cpu_sr;
; #endif
;     BOOLEAN    self;
;     OS_TCB    *ptcb;
; 
; 
; #if OS_ARG_CHK_EN > 0
;     if (prio == OS_IDLE_PRIO) {                                 /* Not allowed to suspend idle task    */
	cpi R22,20
	brne L52
	.dbline 679
	.dbline 680
;         return (OS_TASK_SUSPEND_IDLE);
	ldi R16,91
	xjmp L51
L52:
	.dbline 682
;     }
;     if (prio >= OS_LOWEST_PRIO && prio != OS_PRIO_SELF) {       /* Task priority valid ?               */
	cpi R22,20
	brlo L54
	cpi R22,255
	breq L54
	.dbline 682
	.dbline 683
;         return (OS_PRIO_INVALID);
	ldi R16,42
	xjmp L51
L54:
	.dbline 686
;     }
; #endif
;     OS_ENTER_CRITICAL();
	st -y,r16
	in r16,0x3F
	cli
	push r16
	ld r16,y+
	.dbline 686
	.dbline 687
;     if (prio == OS_PRIO_SELF) {                                 /* See if suspend SELF                 */
	cpi R22,255
	brne L56
	.dbline 687
	.dbline 688
;         prio = OSTCBCur->OSTCBPrio;
	lds R30,_OSTCBCur
	lds R31,_OSTCBCur+1
	ldd R22,z+12
	.dbline 689
;         self = TRUE;
	ldi R20,1
	.dbline 690
	xjmp L57
L56:
	.dbline 690
;     } else if (prio == OSTCBCur->OSTCBPrio) {                   /* See if suspending self              */
	lds R30,_OSTCBCur
	lds R31,_OSTCBCur+1
	ldd R2,z+12
	cp R22,R2
	brne L58
	.dbline 690
	.dbline 691
;         self = TRUE;
	ldi R20,1
	.dbline 692
	xjmp L59
L58:
	.dbline 692
;     } else {
	.dbline 693
;         self = FALSE;                                           /* No suspending another task          */
	clr R20
	.dbline 694
;     }
L59:
L57:
	.dbline 695
;     ptcb = OSTCBPrioTbl[prio];
	ldi R24,2
	mul R24,R22
	movw R30,R0
	ldi R24,<_OSTCBPrioTbl
	ldi R25,>_OSTCBPrioTbl
	add R30,R24
	adc R31,R25
	ldd R22,z+0
	ldd R23,z+1
	.dbline 696
;     if (ptcb == (OS_TCB *)0) {                                  /* Task to suspend must exist          */
	cpi R22,0
	cpc R22,R23
	brne L60
X11:
	.dbline 696
	.dbline 697
;         OS_EXIT_CRITICAL();
	st -y,r16
	pop r16
	out 0x3F,r16
	ld r16,y+
	.dbline 697
	.dbline 698
;         return (OS_TASK_SUSPEND_PRIO);
	ldi R16,90
	xjmp L51
L60:
	.dbline 700
;     }
;     if ((OSRdyTbl[ptcb->OSTCBY] &= ~ptcb->OSTCBBitX) == 0x00) { /* Make task not ready                 */
	ldi R24,<_OSRdyTbl
	ldi R25,>_OSRdyTbl
	movw R30,R22
	ldd R2,z+14
	clr R3
	add R2,R24
	adc R3,R25
	movw R30,R22
	ldd R4,z+15
	com R4
	movw R30,R2
	ldd R5,z+0
	and R5,R4
	mov R4,R5
	std z+0,R4
	tst R5
	brne L62
	.dbline 700
	.dbline 701
;         OSRdyGrp &= ~ptcb->OSTCBBitY;
	movw R30,R22
	ldd R2,z+16
	com R2
	lds R3,_OSRdyGrp
	and R3,R2
	sts _OSRdyGrp,R3
	.dbline 702
;     }
L62:
	.dbline 703
;     ptcb->OSTCBStat |= OS_STAT_SUSPEND;                         /* Status of task is 'SUSPENDED'       */
	movw R24,R22
	adiw R24,11
	movw R30,R24
	ldd R24,z+0
	ori R24,8
	std z+0,R24
	.dbline 704
;     OS_EXIT_CRITICAL();
	st -y,r16
	pop r16
	out 0x3F,r16
	ld r16,y+
	.dbline 704
	.dbline 705
;     if (self == TRUE) {                                         /* Context switch only if SELF         */
	cpi R20,1
	brne L64
	.dbline 705
	.dbline 706
;         OS_Sched();
	xcall _OS_Sched
	.dbline 707
;     }
L64:
	.dbline 708
;     return (OS_NO_ERR);
	clr R16
	.dbline -2
L51:
	xcall pop_gset2
	.dbline 0 ; func end
	ret
	.dbsym r self 20 c
	.dbsym r ptcb 22 pS[os_tcb]
	.dbsym r prio 22 c
	.dbend

⌨️ 快捷键说明

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