main.c

来自「UCOS2.71, UCOS_II : UCOS_II UCOS_II S」· C语言 代码 · 共 113 行

C
113
字号
/*
 * File:        main.c
 *
 * uC/OS Real-time multitasking kernel for the ARM processor.
 *
 *
 * Created by hgxxx
 *
 */
#include	"../ucos_ii/ucos_ii.h"               /* uC/OS interface */
#include	"../inc/44blib.h"
#include	"../inc/44b.h"
#include	"../inc/option.h"
#include	"../inc/target.h"

/* allocate memory for tasks' stacks */
#ifdef SEMIHOSTED
#define STACKSIZE       (SEMIHOSTED_STACK_NEEDS+64)
#else
#define	STACKSIZE_H  8192
#define STACKSIZE_L  512
#endif

OS_STK Stack0[STACKSIZE_L];
OS_STK Stack1[STACKSIZE_L];
OS_STK Stack2[STACKSIZE_L];


OS_EVENT *UartSem;
OS_EVENT *KeySem;
/*-----------------------------------------------------------------------------------*/

void TaskLED(void *i)
{
    for (;;)
    {
		rPDATE=rPDATE&0x17f;
		OSTimeDly(500);
		rPDATE=rPDATE|0x80;
		OSTimeDly(500);
    }
}


void TaskKey(void *i)
{
	INT8U err;
	void *msg;
	
	for (;;)
	{
		msg = OSMboxPend(KeySem, 0, &err);
		OSSemPend(UartSem, 0, &err);
		Uart_Printf("msg = %d\n", msg);
		OSSemPost(UartSem);
	}
}

void TaskStart(void *i)
{
	INT8U err;
	
	ARMStartTimer();
	OSStatInit();
	
	for(;;)
	{
		OSTimeDly(2000);
		OSSemPend(UartSem, 0, &err);
		Uart_Printf("++++++++++++++++++++++++++++++++++++++ ");
		Uart_Printf("OSCPUUsage = %d%% \n",OSCPUUsage);
		OSSemPost(UartSem);
	}
}

/*
 * Main function.
 */
void Main(void)
{

	char Id0 = '1';
	char Id1 = '2';
	char Id2 = '3';

	ARMTargetInit();

	Uart_Printf("OSrunning\n");

	OSInit();

	OSTimeSet(0);
    
	UartSem = OSSemCreate(1);
	KeySem = OSMboxCreate((void *)0);
    /* 
     * create the tasks in uC/OS and assign decreasing
     * priority to them 
     */
	OSTaskCreate(TaskStart, (void *)&Id0, (void *)&Stack0[STACKSIZE_L - 1], 1);
	OSTaskCreate(TaskLED, (void *)&Id1, (void *)&Stack1[STACKSIZE_L - 1], 51);
	OSTaskCreate(TaskKey, (void *)&Id2, (void *)&Stack2[STACKSIZE_L - 1], 50);
        
    /* Start the  system running */
	ARMTargetStart();

    /* start the system */

	OSStart();

    /* never reached */
}                               /* main */

⌨️ 快捷键说明

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