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

📄 ucos2avr.lss

📁 atmega单片机用的ucos系统 占用内存适中 是atmega单片机合适的操作系统
💻 LSS
📖 第 1 页 / 共 5 页
字号:
/*
*********************************************************************************************************
*                                              IDLE TASK
*
* Description: This task is internal to uC/OS-II and executes whenever no other higher priority tasks
*              executes because they are ALL waiting for event(s) to occur.
*
* Arguments  : none
*
* Returns    : none
*
* Note(s)    : 1) OSTaskIdleHook() is called after the critical section to ensure that interrupts will be
*                 enabled for at least a few instructions.  On some processors (ex. Philips XA), enabling
*                 and then disabling interrupts didn't allow the processor enough time to have interrupts
*                 enabled before they were disabled again.  uC/OS-II would thus never recognize
*                 interrupts.
*              2) This hook has been added to allow you to do such things as STOP the CPU to conserve 
*                 power.
*********************************************************************************************************
*/

void  OS_TaskIdle (void *parg)
{
#if OS_CRITICAL_METHOD == 3                      /* Allocate storage for CPU status register           */
    OS_CPU_SR  cpu_sr;
    
    

    cpu_sr = 0;                                  /* Prevent compiler warning                           */
#endif    
    parg   = parg;                               /* Prevent compiler warning for not using 'parg'      */
    for (;;) {
        OS_ENTER_CRITICAL();
     92e:	0f b6       	in	r0, 0x3f	; 63
     930:	f8 94       	cli
     932:	0f 92       	push	r0
        OSIdleCtr++;
     934:	80 91 2a 03 	lds	r24, 0x032A
     938:	90 91 2b 03 	lds	r25, 0x032B
     93c:	a0 91 2c 03 	lds	r26, 0x032C
     940:	b0 91 2d 03 	lds	r27, 0x032D
     944:	01 96       	adiw	r24, 0x01	; 1
     946:	a1 1d       	adc	r26, r1
     948:	b1 1d       	adc	r27, r1
     94a:	80 93 2a 03 	sts	0x032A, r24
     94e:	90 93 2b 03 	sts	0x032B, r25
     952:	a0 93 2c 03 	sts	0x032C, r26
     956:	b0 93 2d 03 	sts	0x032D, r27
        OS_EXIT_CRITICAL();
     95a:	0f 90       	pop	r0
     95c:	0f be       	out	0x3f, r0	; 63
        OSTaskIdleHook();                        /* Call user definable HOOK                           */
     95e:	0e 94 92 0c 	call	0x1924
     962:	e5 cf       	rjmp	.-54     	; 0x92e

00000964 <OS_TaskStat>:
    }
}
/*$PAGE*/
/*
*********************************************************************************************************
*                                            STATISTICS TASK
*
* Description: This task is internal to uC/OS-II and is used to compute some statistics about the
*              multitasking environment.  Specifically, OS_TaskStat() computes the CPU usage.
*              CPU usage is determined by:
*
*                                          OSIdleCtr
*                 OSCPUUsage = 100 * (1 - ------------)     (units are in %)
*                                         OSIdleCtrMax
*
* Arguments  : parg     this pointer is not used at this time.
*
* Returns    : none
*
* Notes      : 1) This task runs at a priority level higher than the idle task.  In fact, it runs at the
*                 next higher priority, OS_IDLE_PRIO-1.
*              2) You can disable this task by setting the configuration #define OS_TASK_STAT_EN to 0.
*              3) You MUST have at least a delay of 2/10 seconds to allow for the system to establish the 
*                 maximum value for the idle counter.
*********************************************************************************************************
*/

#if OS_TASK_STAT_EN > 0
void  OS_TaskStat (void *parg)
{
     964:	ef 92       	push	r14
     966:	ff 92       	push	r15
     968:	0f 93       	push	r16
     96a:	1f 93       	push	r17
    INT32U     run;
    INT32U     max;
    INT8S      usage;
#if OS_CRITICAL_METHOD == 3                      /* Allocate storage for CPU status register           */
    OS_CPU_SR  cpu_sr;



    cpu_sr = 0;                                  /* Prevent compiler warning                           */
#endif    
    parg   = parg;                               /* Prevent compiler warning for not using 'parg'      */
    while (OSStatRdy == FALSE) {
        OSTimeDly(2 * OS_TICKS_PER_SEC / 10);    /* Wait until statistic task is ready                 */
     96c:	80 91 34 05 	lds	r24, 0x0534
     970:	88 23       	and	r24, r24
     972:	29 f4       	brne	.+10     	; 0x97e
     974:	84 e1       	ldi	r24, 0x14	; 20
     976:	90 e0       	ldi	r25, 0x00	; 0
     978:	0e 94 83 0b 	call	0x1706
     97c:	f7 cf       	rjmp	.-18     	; 0x96c
    }
    max = OSIdleCtrMax / 100L;
     97e:	80 91 d6 03 	lds	r24, 0x03D6
     982:	90 91 d7 03 	lds	r25, 0x03D7
     986:	a0 91 d8 03 	lds	r26, 0x03D8
     98a:	b0 91 d9 03 	lds	r27, 0x03D9
     98e:	bc 01       	movw	r22, r24
     990:	cd 01       	movw	r24, r26
     992:	24 e6       	ldi	r18, 0x64	; 100
     994:	30 e0       	ldi	r19, 0x00	; 0
     996:	40 e0       	ldi	r20, 0x00	; 0
     998:	50 e0       	ldi	r21, 0x00	; 0
     99a:	0e 94 ad 10 	call	0x215a
     99e:	79 01       	movw	r14, r18
     9a0:	8a 01       	movw	r16, r20
    for (;;) {
        OS_ENTER_CRITICAL();
     9a2:	0f b6       	in	r0, 0x3f	; 63
     9a4:	f8 94       	cli
     9a6:	0f 92       	push	r0
        OSIdleCtrRun = OSIdleCtr;                /* Obtain the of the idle counter for the past second */
     9a8:	80 91 2a 03 	lds	r24, 0x032A
     9ac:	90 91 2b 03 	lds	r25, 0x032B
     9b0:	a0 91 2c 03 	lds	r26, 0x032C
     9b4:	b0 91 2d 03 	lds	r27, 0x032D
     9b8:	80 93 b5 05 	sts	0x05B5, r24
     9bc:	90 93 b6 05 	sts	0x05B6, r25
     9c0:	a0 93 b7 05 	sts	0x05B7, r26
     9c4:	b0 93 b8 05 	sts	0x05B8, r27
        run          = OSIdleCtr;
     9c8:	60 91 2a 03 	lds	r22, 0x032A
     9cc:	70 91 2b 03 	lds	r23, 0x032B
     9d0:	80 91 2c 03 	lds	r24, 0x032C
     9d4:	90 91 2d 03 	lds	r25, 0x032D
        OSIdleCtr    = 0L;                       /* Reset the idle counter for the next second         */
     9d8:	10 92 2a 03 	sts	0x032A, r1
     9dc:	10 92 2b 03 	sts	0x032B, r1
     9e0:	10 92 2c 03 	sts	0x032C, r1
     9e4:	10 92 2d 03 	sts	0x032D, r1
        OS_EXIT_CRITICAL();
     9e8:	0f 90       	pop	r0
     9ea:	0f be       	out	0x3f, r0	; 63
        if (max > 0L) {
     9ec:	e1 14       	cp	r14, r1
     9ee:	f1 04       	cpc	r15, r1
     9f0:	01 05       	cpc	r16, r1
     9f2:	11 05       	cpc	r17, r1
     9f4:	81 f0       	breq	.+32     	; 0xa16
            usage = (INT8S)(100L - run / max);
     9f6:	a8 01       	movw	r20, r16
     9f8:	97 01       	movw	r18, r14
     9fa:	0e 94 ad 10 	call	0x215a
     9fe:	da 01       	movw	r26, r20
     a00:	c9 01       	movw	r24, r18
     a02:	24 e6       	ldi	r18, 0x64	; 100
     a04:	28 1b       	sub	r18, r24
            if (usage >= 0) {                    /* Make sure we don't have a negative percentage      */
     a06:	27 fd       	sbrc	r18, 7
     a08:	03 c0       	rjmp	.+6      	; 0xa10
                OSCPUUsage = usage;
     a0a:	20 93 dc 03 	sts	0x03DC, r18
     a0e:	17 c0       	rjmp	.+46     	; 0xa3e
            } else {
                OSCPUUsage = 0;
     a10:	10 92 dc 03 	sts	0x03DC, r1
     a14:	14 c0       	rjmp	.+40     	; 0xa3e
            }
        } else {
            OSCPUUsage = 0;
     a16:	10 92 dc 03 	sts	0x03DC, r1
            max        = OSIdleCtrMax / 100L;
     a1a:	80 91 d6 03 	lds	r24, 0x03D6
     a1e:	90 91 d7 03 	lds	r25, 0x03D7
     a22:	a0 91 d8 03 	lds	r26, 0x03D8
     a26:	b0 91 d9 03 	lds	r27, 0x03D9
     a2a:	bc 01       	movw	r22, r24
     a2c:	cd 01       	movw	r24, r26
     a2e:	24 e6       	ldi	r18, 0x64	; 100
     a30:	30 e0       	ldi	r19, 0x00	; 0
     a32:	40 e0       	ldi	r20, 0x00	; 0
     a34:	50 e0       	ldi	r21, 0x00	; 0
     a36:	0e 94 ad 10 	call	0x215a
     a3a:	79 01       	movw	r14, r18
     a3c:	8a 01       	movw	r16, r20
        }
        OSTaskStatHook();                        /* Invoke user definable hook                         */
     a3e:	0e 94 93 0c 	call	0x1926
#if (OS_TASK_STAT_STK_CHK_EN > 0) && (OS_TASK_CREATE_EXT_EN > 0)
        OS_TaskStatStkChk();                     /* Check the stacks for each task                     */
#endif
        OSTimeDly(OS_TICKS_PER_SEC / 10);        /* Accumulate OSIdleCtr for the next 1/10 second      */
     a42:	8a e0       	ldi	r24, 0x0A	; 10
     a44:	90 e0       	ldi	r25, 0x00	; 0
     a46:	0e 94 83 0b 	call	0x1706
     a4a:	ab cf       	rjmp	.-170    	; 0x9a2

00000a4c <OS_TCBInit>:
    }
}
#endif
/*$PAGE*/
/*
*********************************************************************************************************
*                                      CHECK ALL TASK STACKS
*
* Description: This function is called by OS_TaskStat() to check the stacks of each active task.
*
* Arguments  : none
*
* Returns    : none
*********************************************************************************************************
*/

#if (OS_TASK_STAT_STK_CHK_EN > 0) && (OS_TASK_CREATE_EXT_EN > 0)
void  OS_TaskStatStkChk (void)
{
    OS_TCB      *ptcb;
    OS_STK_DATA  stk_data;
    INT8U        err;
    INT8U        prio;


    for (prio = 0; prio <= OS_IDLE_PRIO; prio++) {
        err = OSTaskStkChk(prio, &stk_data);
        if (err == OS_NO_ERR) {
            ptcb = OSTCBPrioTbl[prio];
            if (ptcb != (OS_TCB *)0) {                               /* Make sure task 'ptcb' is ...   */
                if (ptcb != (OS_TCB *)1) {                           /* ... still valid.               */
#if OS_TASK_PROFILE_EN > 0
                    #if OS_STK_GROWTH == 1
                    ptcb->OSTCBStkBase = ptcb->OSTCBStkBottom + ptcb->OSTCBStkSize;
                    #else
                    ptcb->OSTCBStkBase = ptcb->OSTCBStkBottom - ptcb->OSTCBStkSize;
                    #endif
                    ptcb->OSTCBStkUsed = (INT32U)stk_data.OSUsed;    /* Store the number of bytes used */
#endif
                }
            }
        }
    }
}
#endif
/*$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
*
*              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  OS_TCBInit (INT8U prio, OS_STK *ptos, OS_STK *pbos, INT16U id, INT32U stk_size, void *pext, INT16U opt)
{
     a4c:	1f 93       	push	r17
     a4e:	cf 93       	push	r28
     a50:	df 93       	push	r29
     a52:	18 2f       	mov	r17, r24
    OS_TCB    *ptcb;
#if OS_CRITICAL_METHOD == 3                                /* Allocate storage for CPU status register */
    OS_CPU_SR  cpu_sr;



    cpu_sr = 0;                                            /* Prevent compiler warning                 */
#endif    
    OS_ENTER_CRITICAL();
     a54:	0f b6       	in	r0, 0x3f	; 63
     a56:	f8 94       	cli
     a58:	0f 92       	push	r0
    ptcb = OSTCBFreeList;                                  /* Get a free TCB from the free TCB list    */
     a5a:	c0 91 da 03 	lds	r28, 0x03DA
     a5e:	d0 91 db 03 	lds	r29, 0x03DB
    if (ptcb != (OS_TCB *)0) {
     a62:	20 97       	sbiw	r28, 0x00	; 0
     a64:	09 f4       	brne	.+2      	; 0xa68
     a66:	64 c0       	rjmp	.+200    	; 0xb30
        OSTCBFreeList        = ptcb->OSTCBNext;            /* Update pointer to free TCB list          */
     a68:	8a 81       	ldd	r24, Y+2	; 0x02
     a6a:	9b 81       	ldd	r25, Y+3	; 0x03
     a6c:	90 93 db 03 	sts	0x03DB, r25
     a70:	80 93 da 03 	sts	0x03DA, r24

⌨️ 快捷键说明

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