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

📄 os_task.s

📁 ucos如何移植到单片机mega128
💻 S
📖 第 1 页 / 共 4 页
字号:
L29:
	.dbline 419
;         OSTaskDelHook(ptcb);                                    /* Call user defined hook              */
	movw R16,R20
	xcall _OSTaskDelHook
	.dbline 420
;         OSTaskCtr--;                                            /* One less task being managed         */
	lds R24,_OSTaskCtr
	subi R24,1
	sts _OSTaskCtr,R24
	.dbline 421
;         OSTCBPrioTbl[prio] = (OS_TCB *)0;                       /* Clear old priority entry            */
	ldi R24,2
	mul R24,R22
	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 422
;         if (ptcb->OSTCBPrev == (OS_TCB *)0) {                   /* Remove from TCB chain               */
	movw R30,R20
	ldd R2,z+4
	ldd R3,z+5
	tst R2
	brne L31
	tst R3
	brne L31
X5:
	.dbline 422
	.dbline 423
;             ptcb->OSTCBNext->OSTCBPrev = (OS_TCB *)0;
	clr R2
	clr R3
	movw R30,R20
	ldd R26,z+2
	ldd R27,z+3
	adiw R26,4
	st x+,R2
	st x,R3
	.dbline 424
;             OSTCBList                  = ptcb->OSTCBNext;
	movw R30,R20
	ldd R2,z+2
	ldd R3,z+3
	sts _OSTCBList+1,R3
	sts _OSTCBList,R2
	.dbline 425
	xjmp L32
L31:
	.dbline 425
;         } else {
	.dbline 426
;             ptcb->OSTCBPrev->OSTCBNext = ptcb->OSTCBNext;
	movw R30,R20
	ldd R2,z+2
	ldd R3,z+3
	movw R30,R20
	ldd R26,z+4
	ldd R27,z+5
	adiw R26,2
	st x+,R2
	st x,R3
	.dbline 427
;             ptcb->OSTCBNext->OSTCBPrev = ptcb->OSTCBPrev;
	movw R30,R20
	ldd R2,z+4
	ldd R3,z+5
	movw R30,R20
	ldd R26,z+2
	ldd R27,z+3
	adiw R26,4
	st x+,R2
	st x,R3
	.dbline 428
;         }
L32:
	.dbline 429
;         ptcb->OSTCBNext = OSTCBFreeList;                        /* Return TCB to free TCB list         */
	lds R2,_OSTCBFreeList
	lds R3,_OSTCBFreeList+1
	movw R30,R20
	std z+3,R3
	std z+2,R2
	.dbline 430
;         OSTCBFreeList   = ptcb;
	sts _OSTCBFreeList+1,R21
	sts _OSTCBFreeList,R20
	.dbline 431
;         OS_EXIT_CRITICAL();
	st -y,r16
	pop r16
	out 0x3F,r16
	ld r16,y+
	.dbline 431
	.dbline 432
;         OS_Sched();                                             /* Find new highest priority task      */
	xcall _OS_Sched
	.dbline 433
;         return (OS_NO_ERR);
	clr R16
	xjmp L12
L21:
	.dbline 435
;     }
;     OS_EXIT_CRITICAL();
	st -y,r16
	pop r16
	out 0x3F,r16
	ld r16,y+
	.dbline 435
	.dbline 436
;     return (OS_TASK_DEL_ERR);
	ldi R16,60
	.dbline -2
L12:
	xcall pop_gset3
	.dbline 0 ; func end
	ret
	.dbsym l self 1 c
	.dbsym r pnode 10 pS[.2]
	.dbsym r ptcb 20 pS[os_tcb]
	.dbsym r prio 22 c
	.dbend
	.dbfunc e OSTaskDelReq _OSTaskDelReq fc
;           stat -> R20
;            err -> R20
;           ptcb -> R20,R21
;           prio -> R16
	.even
_OSTaskDelReq::
	xcall push_gset1
	.dbline -1
	.dbline 487
; }
; #endif
; /*$PAGE*/
; /*
; *********************************************************************************************************
; *                                    REQUEST THAT A TASK DELETE ITSELF
; *
; * Description: This function is used to:
; *                   a) notify a task to delete itself.
; *                   b) to see if a task requested that the current task delete itself.
; *              This function is a little tricky to understand.  Basically, you have a task that needs
; *              to be deleted however, this task has resources that it has allocated (memory buffers,
; *              semaphores, mailboxes, queues etc.).  The task cannot be deleted otherwise these
; *              resources would not be freed.  The requesting task calls OSTaskDelReq() to indicate that
; *              the task needs to be deleted.  Deleting of the task is however, deferred to the task to
; *              be deleted.  For example, suppose that task #10 needs to be deleted.  The requesting task
; *              example, task #5, would call OSTaskDelReq(10).  When task #10 gets to execute, it calls
; *              this function by specifying OS_PRIO_SELF and monitors the returned value.  If the return
; *              value is OS_TASK_DEL_REQ, another task requested a task delete.  Task #10 would look like
; *              this:
; *
; *                   void Task(void *data)
; *                   {
; *                       .
; *                       .
; *                       while (1) {
; *                           OSTimeDly(1);
; *                           if (OSTaskDelReq(OS_PRIO_SELF) == OS_TASK_DEL_REQ) {
; *                               Release any owned resources;
; *                               De-allocate any dynamic memory;
; *                               OSTaskDel(OS_PRIO_SELF);
; *                           }
; *                       }
; *                   }
; *
; * Arguments  : prio    is the priority of the task to request the delete from
; *
; * Returns    : OS_NO_ERR          if the task exist and the request has been registered
; *              OS_TASK_NOT_EXIST  if the task has been deleted.  This allows the caller to know whether
; *                                 the request has been executed.
; *              OS_TASK_DEL_IDLE   if you requested to delete uC/OS-II's idle task
; *              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_DEL_REQ    if a task (possibly another task) requested that the running task be
; *                                 deleted.
; *********************************************************************************************************
; */
; /*$PAGE*/
; #if OS_TASK_DEL_EN > 0
; INT8U  OSTaskDelReq (INT8U prio)
; {
	.dbline 497
; #if OS_CRITICAL_METHOD == 3                      /* Allocate storage for CPU status register           */
;     OS_CPU_SR  cpu_sr;
; #endif
;     BOOLEAN    stat;
;     INT8U      err;
;     OS_TCB    *ptcb;
; 
; 
; #if OS_ARG_CHK_EN > 0
;     if (prio == OS_IDLE_PRIO) {                                 /* Not allowed to delete idle task     */
	cpi R16,20
	brne L34
	.dbline 497
	.dbline 498
;         return (OS_TASK_DEL_IDLE);
	ldi R16,61
	xjmp L33
L34:
	.dbline 500
;     }
;     if (prio >= OS_LOWEST_PRIO && prio != OS_PRIO_SELF) {       /* Task priority valid ?               */
	cpi R16,20
	brlo L36
	cpi R16,255
	breq L36
	.dbline 500
	.dbline 501
;         return (OS_PRIO_INVALID);
	ldi R16,42
	xjmp L33
L36:
	.dbline 504
;     }
; #endif
;     if (prio == OS_PRIO_SELF) {                                 /* See if a task is requesting to ...  */
	cpi R16,255
	brne L38
	.dbline 504
	.dbline 505
;         OS_ENTER_CRITICAL();                                    /* ... this task to delete itself      */
	st -y,r16
	in r16,0x3F
	cli
	push r16
	ld r16,y+
	.dbline 505
	.dbline 506
;         stat = OSTCBCur->OSTCBDelReq;                           /* Return request status to caller     */
	lds R30,_OSTCBCur
	lds R31,_OSTCBCur+1
	ldd R20,z+17
	.dbline 507
;         OS_EXIT_CRITICAL();
	st -y,r16
	pop r16
	out 0x3F,r16
	ld r16,y+
	.dbline 507
	.dbline 508
;         return (stat);
	mov R16,R20
	xjmp L33
L38:
	.dbline 510
;     }
;     OS_ENTER_CRITICAL();
	st -y,r16
	in r16,0x3F
	cli
	push r16
	ld r16,y+
	.dbline 510
	.dbline 511
;     ptcb = OSTCBPrioTbl[prio];
	ldi R24,2
	mul R24,R16
	movw R30,R0
	ldi R24,<_OSTCBPrioTbl
	ldi R25,>_OSTCBPrioTbl
	add R30,R24
	adc R31,R25
	ldd R20,z+0
	ldd R21,z+1
	.dbline 512
;     if (ptcb != (OS_TCB *)0) {                                  /* Task to delete must exist           */
	cpi R20,0
	cpc R20,R21
	breq L40
X7:
	.dbline 512
	.dbline 513
;         ptcb->OSTCBDelReq = OS_TASK_DEL_REQ;                    /* Set flag indicating task to be DEL. */
	ldi R24,62
	movw R30,R20
	std z+17,R24
	.dbline 514
;         err               = OS_NO_ERR;
	clr R20
	.dbline 515
	xjmp L41
L40:
	.dbline 515
;     } else {
	.dbline 516
;         err               = OS_TASK_NOT_EXIST;                  /* Task must be deleted                */
	ldi R20,11
	.dbline 517
;     }
L41:
	.dbline 518
;     OS_EXIT_CRITICAL();
	st -y,r16
	pop r16
	out 0x3F,r16
	ld r16,y+
	.dbline 518
	.dbline 519
;     return (err);
	mov R16,R20
	.dbline -2
L33:
	xcall pop_gset1
	.dbline 0 ; func end
	ret
	.dbsym r stat 20 c
	.dbsym r err 20 c
	.dbsym r ptcb 20 pS[os_tcb]
	.dbsym r prio 16 c
	.dbend
	.dbfunc e OSTaskResume _OSTaskResume fc
;           ptcb -> R20,R21
;           prio -> R20
	.even
_OSTaskResume::
	xcall push_gset1
	mov R20,R16
	.dbline -1
	.dbline 542
; }
; #endif
; /*$PAGE*/
; /*
; *********************************************************************************************************
; *                                        RESUME A SUSPENDED TASK
; *
; * Description: This function is called to resume a previously suspended task.  This is the only call that
; *              will remove an explicit task suspension.
; *
; * Arguments  : prio     is the priority of the task to resume.
; *
; * Returns    : OS_NO_ERR                if the requested task is resumed
; *              OS_PRIO_INVALID          if the priority you specify is higher that the maximum allowed
; *                                       (i.e. >= OS_LOWEST_PRIO)
; *              OS_TASK_RESUME_PRIO      if the task to resume does not exist
; *              OS_TASK_NOT_SUSPENDED    if the task to resume has not been suspended
; *********************************************************************************************************
; */
; 
; #if OS_TASK_SUSPEND_EN > 0
; INT8U  OSTaskResume (INT8U prio)
; {
	.dbline 550
; #if OS_CRITICAL_METHOD == 3                      /* Allocate storage for CPU status register           */
;     OS_CPU_SR  cpu_sr;
; #endif
;     OS_TCB    *ptcb;
; 
; 
; #if OS_ARG_CHK_EN > 0
;     if (prio >= OS_LOWEST_PRIO) {                               /* Make sure task priority is valid    */
	cpi R20,20
	brlo L43
	.dbline 550
	.dbline 551
;         return (OS_PRIO_INVALID);
	ldi R16,42
	xjmp L42
L43:
	.dbline 554
;     }
; #endif
;     OS_ENTER_CRITICAL();
	st -y,r16
	in r16,0x3F
	cli
	push r16
	ld r16,y+
	.dbline 554
	.dbline 555
;     ptcb = OSTCBPrioTbl[prio];
	ldi R24,2
	mul R24,R20
	movw R30,R0
	ldi R24,<_OSTCBPrioTbl
	ldi R25,>_OSTCBPrioTbl
	add R30,R24
	adc R31,R25
	ldd R20,z+0
	ldd R21,z+1
	.dbline 556
;     if (ptcb == (OS_TCB *)0) {                                  /* Task to suspend must exist          */
	cpi R20,0
	cpc R20,R21
	brne L45
X8:
	.dbline 556
	.dbline 557
;         OS_EXIT_CRITICAL();
	st -y,r16

⌨️ 快捷键说明

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