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

📄 mboxmain.c

📁 UCOSII V2.52 在三星SNDS4510开发板(国内基本所有的4510b的板子都是抄袭此公板设计的)上移植的成功例子
💻 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"
#include "string.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 *MboxKeyInput;
OS_EVENT *Mbox3;
OS_EVENT *MComRx;

char PassMsg[] = "Example 1";

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

    Printf("ReadKeyTask() called\r\n");

    for (;;)
    {
        /* wait for a message from the input mailbox */
		Msg = (char *)OSMboxPend(Mbox1, 0, &err); //获得对资源的访问权
		if(err==OS_NO_ERR)
		{ 
  		  KeyValue=inport(IOPDATA);
		  if(KeyValue!=NOKEY)
		    {
              strcpy(Msg,"T1 get a Key.\r\n");
              Printf("T%c Read key:%X\r\n", *(char *)Id,KeyValue);              
            }
          else
            Printf("%c\r\n",*(char *)Id);		  
        /* post the input message to the output mailbox */
        OSMboxPost(MboxKeyInput, Msg);
        }
        else
        {
           // MSG error or TIMEOUT
        }
    }
}

void OutputLEDTask(void *Id)
{
    char *Msg;
    INT8U err;
   // U32 KeyValue;

    Printf("OutputLEDTask() called\r\n" );

    for (;;)
    {
        /* wait for a message from the input mailbox */
        Msg = (char *)OSMboxPend(MboxKeyInput, 0, &err);
		if(err==OS_NO_ERR)
		{ // get the MSG
		//	KeyValue=*Msg;
        Printf("%c\r\n", *(char *)Id);
//        if((U32)*Msg==KEY1)
  //        Printf("T1 get %X \r\n",Msg);

        /* post the input message to the output mailbox */
        OSMboxPost(Mbox3, Msg);
        }
        else
        {
          // MSG error or TIMEOUT
        }
    }
}


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

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

        /* print task's id */
        Printf("%c\r\n", *(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(".");		
	//	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("S3C4510b UCOSII MultiTasks DEMO 2005-12-2.\r\n");
	Printf("http://mes.hlju.edu.cn.\r\n");

	Printf("System Initialized.\r\n");
	Printf("Build Date:%s -- Time:%s.\r\n", __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 */
    MboxKeyInput = OSMboxCreate((void *)1);
    Mbox3 = OSMboxCreate((void *)1);    

    /* 
     * 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(ReadKeyTask, (void *)&Id1, Stack1+STACKSIZE, 4);
	OSTaskCreate(OutputLEDTask, (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 + -