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

📄 example1.c

📁 各种硬件平台上的us OS移植实例(arm6)
💻 C
字号:
/*> example1.c <*//*---------------------------------------------------------------------------*//* This is a modified version of example1 from the uC/OS book. As * "armsd" does not emulate a terminal there is no screen location * that a task can put its ID onto. Therefore the IDs are simply * output as they arrive. * * $Revision: 0.1 $ *   $Author: jsmith $ *     $Date: 0.1 $ * * Copyright (c) 1994, VLSI Technoloy Inc. All Rights Reserved. *//*---------------------------------------------------------------------------*/#include	"ucos.h" 	/* uC/OS interface */#include	"osdefs.h"  /* uC/OS ARM interface *//* * P r o t o t y p e s */void	Task(void *id);void	Timer_IRQ( void );/* allocate memory for tasks' stacks */#define	STACKSIZE	128		/* was 64 */uint	Stack1[STACKSIZE];uint	Stack2[STACKSIZE];uint	Stack3[STACKSIZE];/* * G l o b a l   V a r i a b l e s */OS_EVENT	*DispSem;IRQHandlerFn prev_hand;	/* function pointer to previous handler *//* mailbox event control blocks */OS_EVENT *Mbox1;OS_EVENT *Mbox2;OS_EVENT *Mbox3;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;	uint	err;	for (;;) {		/* wait for a message from the input mailbox */		Msg = (char *)OSMboxPend(Mbox1, 0, &err);		/* print task's id */		SWI_WriteC(*(int *)Id);			/* print task's id */		/* post the input message to the output mailbox */		OSMboxPost(Mbox2, Msg);	}}void	Task2(void *Id){	char	*Msg;	uint	err;	for (;;) {		/* wait for a message from the input mailbox */		Msg = (char *)OSMboxPend(Mbox2, 0, &err);		/* print task's id */		SWI_WriteC(*(int *)Id);			/* print task's id */		/* post the input message to the output mailbox */		OSMboxPost(Mbox3, Msg);	}}void	Task3(void *Id){	char	*Msg;	uint	err;	for (;;) {		/* wait for a message from the input mailbox */		Msg = (char *)OSMboxPend(Mbox3, 0, &err);		/* print task's id */		SWI_WriteC(*(int *)Id);			/* print task's id */		/* post the input message to the output mailbox */		OSMboxPost(Mbox1, Msg);	}}/* * m a i n */int	main( void ){ char	Id1 = '2'; char	Id2 = '4'; char	Id3 = '8'; union gp	{			unsigned char	*b;			unsigned int	*w;			} p; 	p.b = (unsigned char *) IOBase;		SWI_Write0("\nExample1 using uC/OS for PID600\n\n\0");		SWI_Write0("\nDoing an OSInit()...\0");		OSInit();					/* needed by uC/OS */	SWI_Write0("\nCreating the mailboxes...\0");		/* 	 * 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);	SWI_Write0("\nCreating the tasks...\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, (void *)&Stack1[STACKSIZE - 1], 3);	OSTaskCreate(Task2, (void *)&Id2, (void *)&Stack2[STACKSIZE - 1], 2);	OSTaskCreate(Task3, (void *)&Id3, (void *)&Stack3[STACKSIZE - 1], 1); 	SWI_Write0("\nHooking into the C-DEMON's TIMER...\0");		/*	 * Now HOOK the DEMON's TIMER to uC/OS	 */	*(p.b + IRQM) = 0;		/* stop the TIMER interrupt */	/*	 * TIMER is bit position 1 in FIQ (vecnum = FIQbitvector+bit1 = 0x20 + 1)	 */    if ((prev_hand = ARMInstallIRQHandler(1,Timer_IRQ)) == NULL)     {      SWI_Write0("\nError: Unable to install timer handler.\n") ;     }	*(p.b + IRQM) = TimerIT;		/* restart the TIMER interrupt */	SWI_Write0("\nDoing an OSStart()...\0");		OSStart();					/* start the game */	/*----------------- never reached -----------------------------------------	 *	 * Following code is here to show how to restore the original timer vector	 */	 	*(p.b + IRQM) = 0;		/* remove the TIMER interrupt */	/*	 * TIMER is bit position 1 in FIQ (vecnum = FIQbitvector+bit1 = 0x20 + 1)	 */    if (ARMInstallIRQHandler(1,prev_hand) == NULL)     {      SWI_Write0("\nError: Unable to reinstall handler.\n") ;     }		*(p.b + IRQM) = TimerIT;	/* restart the TIMER interrupt */}/****************************************************************************** * * T i m e r _ I R Q * * ENTER:	void * EXIT:	void * * Timer interrupt routine */void	Timer_IRQ( void ){	OSTimeTick();		/* do uC/OS tick routine */}/*---------------------------------------------------------------------------*//*> EOF example1.c <*/

⌨️ 快捷键说明

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