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

📄 main.c

📁 一个很好的ucos核心代码
💻 C
字号:
/*
 * File:        example1.c
 *
 * uC/OS Real-time multitasking kernel for the ARM processor.
 *
 * Simple example of using multiple tasks and mailboxes.
 *
 * Created by Marco Graziano (marcog@crl.com).
 *
 */

#include "includes.h"               /* uC/OS interface */

#include "s3c4510.h"
#include "serial.h"
#include "timer.h"

/* allocate memory for tasks' stacks */

#define	STACKSIZE	256		//256*4 Bytes

OS_STK Stack1[STACKSIZE];
OS_STK Stack2[STACKSIZE];
OS_STK Stack3[STACKSIZE];

/* mailbox event control blocks */
OS_EVENT *Mbox1;
OS_EVENT *Mbox2;
OS_EVENT *Mbox3;
OS_EVENT *MComRx;

char PassMsg[] = "Example 1";

/*
 * Task running at the lowest priority. 
 * Wait for a message in the first mailbox and post
 * a messages to the third mailbox.
 */
void Task1(void *Id)
{
    char *Msg;
    INT8U err;

    Printf("\nTask1() called\n");

    for (;;)
    {
        /* wait for a message from the input mailbox */
        Msg = (char *)OSMboxPend(Mbox1, 0, &err);

        /* print task's id */
        Printf("%c", *(char *)Id);

        /* post the input message to the output mailbox */
        OSMboxPost(Mbox2, Msg);
    }
}

void Task2(void *Id)
{
    char *Msg;
    INT8U err;

    Printf("\nTask2() called" );

    for (;;)
    {
        /* wait for a message from the input mailbox */
        Msg = (char *)OSMboxPend(Mbox2, 0, &err);

        /* print task's id */
        Printf("%c", *(char *)Id);

        /* post the input message to the output mailbox */
        OSMboxPost(Mbox3, Msg);
    }
}


void Task3(void *Id)
{
    char *Msg;
    INT8U err;	
    
    Printf("\nTask3() called");   

    for (;;)
    {
        /* wait for a message from the input mailbox */
        Msg = (char *)OSMboxPend(Mbox3, 0, &err);

        /* print task's id */
        Printf("%c", *(char *)Id);

        /* post the input message to the output mailbox */
        OSMboxPost(Mbox1, Msg);
    }
}

OS_STK SysTimerStk[STACKSIZE];
void SysTimerTask(void *Id)
{
	//char *Msg;
	//U8 err;
	static U8 Led = 0;
	U32 key   = 0xffffffff;	
	
	InitTimer(0, 1000, 0);
	InitTimer(1, 100, 0);	
	
	outport(INTMSK, ~(1<<INT_TIMER1|1<<INT_GLOBAL));
	//outport(INTMSK, ~(1<<INT_UARTRX0|1<<INT_GLOBAL));
	Printf("\nBegin Run...");	
	
	for(;;)
	{
	//	Printf("\nI am here!");		
	//	outport(IOPDATA, Led);
		Led ^= 1;
		OSTimeDly(5);
		key = inport(IOPDATA);		
		{
			U32 led;
			led  = (key&(1<<9))?0x81:0;
			led |= (key&(1<<10))?0x42:0;
			led |= (key&(1<<11))?0x24:0;			
			led |= (key&(1<<16))?0x18:0;
			outport(IOPDATA, led);				
		}
	}
}
////////////////////////////////////////////////////////
void WaitGameStart(void)
{
	
}


/* Main function. */
int main(void)
//#pragma import(__use_no_semihosting_swi)
{
	char Id1 = '1';
	char Id2 = '2';
	char Id3 = '3';	
/*	{
	//	U32 i;  
	//	while(1)
	//		i = inportw(0x4004000);
		outportw((0x3fd4000+0xa*2), 0);
		Printf("%x\n", inportw((0x3fd4000+0xc*2)));
	
	}	  	
*/

	Printf("\n FS4510 UCOSII 与 按键演示程序 2003-9-22.");
	Printf("\n www.uCdragon.com.");

	Printf("\n System Initialized.");
	Printf("\n Build Date:%s -- Time:%s.", __DATE__, __TIME__);
	
//	WaitGameStart();	

    /* needed by uC/OS */
    OSInit();
	
    /* 
     * create the first mailbox in the pipeline with a message 
     * in it to get the first task started.
     */
    Mbox1 = OSMboxCreate(PassMsg);

    /* create the remaining mailboxes empty */
    Mbox2 = OSMboxCreate((void *)0);
    Mbox3 = OSMboxCreate((void *)0);    

    /* 
     * create the tasks in uC/OS and assign increasing
     * priorities to them so that Task3 at the end of
     * the pipeline has the highest priority.
     */
     
	OSTaskCreate(Task1, (void *)&Id1, Stack1+STACKSIZE, 4);
	OSTaskCreate(Task2, (void *)&Id2, Stack2+STACKSIZE, 3);
	OSTaskCreate(Task3, (void *)&Id3, Stack3+STACKSIZE, 2);
	
	OSTaskCreate(SysTimerTask, (void *)0, SysTimerStk+STACKSIZE, 1);    
   
    /* start the game */
    OSStart();

    /* never reached */
    return	0;
}                               /* main */

void IrqStart(void);
PrVoid IrqFinish(void);

PrVoid pIrqStart = IrqStart, pIrqHandler = OSTimeTick;
PrPrVoid pIrqFinish = IrqFinish;

⌨️ 快捷键说明

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