新闻  |   论坛  |   博客  |   在线研讨会
任哲书例子6-1
chen3bing | 2024-05-07 14:30:26    阅读:31   发布文章

代码:

/*
*********************************************************************************************************
*                                                uC/OS-II
*                                          The Real-Time Kernel
*
*                           (c) Copyright 1992-2002, Jean J. Labrosse, Weston, FL
*                                           All Rights Reserved
*
*                                               EXAMPLE #1
*********************************************************************************************************
*/

#include "includes.h"

/*
*********************************************************************************************************
*                                               CONSTANTS
*********************************************************************************************************
*/

#define  TASK_STK_SIZE                 512       /* Size of each task's stacks (# of WORDs)            */
                       
OS_STK StartTaskStk[TASK_STK_SIZE];
OS_STK MyTaskStk[TASK_STK_SIZE];
OS_STK YouTaskStk[TASK_STK_SIZE];
OS_STK HerTaskStk[TASK_STK_SIZE];

INT16S key;
char *s1="MyTask running";
char *s2="YouTask  running";
char *s3="HerTask running";


INT8U err;

INT8U	y=0;


OS_EVENT *Sem_F;



void StartTask(void *data);
void MyTask(void *data);
void YouTask(void *data);
void HerTask(void *data);

void  main (void)
{
    


    OSInit();                                              /* Initialize uC/OS-II                      */
	
    PC_DOSSaveReturn();                                    /* Save environment to return to DOS        */
    PC_VectSet(uCOS, OSCtxSw);                             /* Install uC/OS-II's context switch vector */

    Sem_F=OSFlagCreate(0,&err);

    OSTaskCreate(StartTask, 
		(void*)0, 
		&StartTaskStk[TASK_STK_SIZE - 1], 
		0);
    OSStart();                                             /* Start multitasking                       */
}

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


    pdata = pdata;                                         /* Prevent compiler warning                 */

    

    OS_ENTER_CRITICAL();
    PC_VectSet(0x08, OSTickISR);                           /* Install uC/OS-II's clock tick ISR        */
    PC_SetTickRate(OS_TICKS_PER_SEC);                      /* Reprogram tick rate                      */
    OS_EXIT_CRITICAL();
	
    OSStatInit();                                          /* Initialize uC/OS-II's statistics         */
	OSTaskCreate(MyTask, 
				(void*)0, 
				&MyTaskStk[TASK_STK_SIZE - 1], 
				3);
    OSTaskCreate(YouTask, 
				(void*)0, 
				&YouTaskStk[TASK_STK_SIZE - 1], 
				4);
	OSTaskCreate(HerTask, 
				(void*)0, 
				&HerTaskStk[TASK_STK_SIZE - 1], 
				5);

    for (;;) 
	{
        if (PC_GetKey(&key) == TRUE) {                     /* See if key has been pressed              */
            if (key == 0x1B) {                             /* Yes, see if it's the ESCAPE key          */
                PC_DOSReturn();                            /* Return to DOS                            */
            }
        }

        
        OSTimeDlyHMSM(0,0,3,0);                         /* Wait one second                          */
    }
}
/*
*********************************************************************************************************
*                                              STARTUP TASK
*********************************************************************************************************
*/
void  MyTask(void *pdata)
{
	
#if OS_CRITICAL_METHOD == 3                                /* Allocate storage for CPU status register */
    OS_CPU_SR  cpu_sr;
#endif
    


    pdata = pdata;                                         /* Prevent compiler warning                 */

    

    

    for (;;) 
	{
		 
		   OSFlagPend(
		   				Sem_F,
						(OS_FLAGS)3,
						OS_FLAG_WAIT_SET_ALL,
						0,
						&err);
	        PC_DispStr(
					10,++y,
					s1,
					DISP_BGND_BLACK+DISP_FGND_WHITE
					);	
			
		
        

        
        OSTimeDlyHMSM(0,0,2,0);                         /* Wait one second                          */
    }
}

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


    pdata = pdata;                                         /* Prevent compiler warning                 */

    

    
    for (;;) 
	{
        
			
		   	PC_DispStr(
				10,++y,
				s2,
				DISP_BGND_BLACK+DISP_FGND_WHITE
				);
		OSTimeDlyHMSM(0,0,8,0);
        OSFlagPost(
					Sem_F,
					(OS_FLAGS)2,
					OS_FLAG_SET,
					&err
					);
        OSTimeDlyHMSM(0,0,2,0);                         /* Wait one second                          */
    }
}

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


    pdata = pdata;                                         /* Prevent compiler warning                 */

    

    
    for (;;) 
	{
        
			
		   	PC_DispStr(
				10,++y,
				s3,
				DISP_BGND_BLACK+DISP_FGND_WHITE
				);
		
        OSFlagPost(
					Sem_F,
					(OS_FLAGS)1,
					OS_FLAG_SET,
					&err
					); 
        OSTimeDlyHMSM(0,0,1,0);                         /* Wait one second                          */
    }
}

运行

1710053127961.jpg

*博客内容为网友个人发布,仅代表博主个人观点,如有侵权请联系工作人员删除。

参与讨论
登录后参与讨论
1
最近文章
方波振荡电路
2024-09-14 14:59:39
6V3A电路
2024-09-14 14:18:10
MOS管点灯仿真
2024-09-12 15:43:13
推荐文章
最近访客