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

📄 main.c

📁 一个移植了UCOS 2.51的程序,全部都是源码,没有任何库文件,方便学习者研究.
💻 C
字号:
#include	"includes.h"               /* uC/OS interface */
#include    "Sems.h"
//task stack size
#ifdef SEMIHOSTED
	#define	TASK_STACK_SIZE	(64+SEMIHOSTED_STACK_NEEDS)
#else
	#define		TASK_STACK_SIZE	10*1024
#endif

//Task definition

/* allocate memory for tasks' stacks */
#define STACKSIZE 64

/* Global Variable */
unsigned int Stack1[STACKSIZE];
unsigned int Stack2[STACKSIZE];
unsigned int Stack3[STACKSIZE];
unsigned int StackMain[STACKSIZE];

void Task1(void *Id)
{
    OSSemPend(UART_sem, 0, &err);
    uHALr_printf("  Task%c Called.\n", *(char *)Id);
    OSSemPost(UART_sem);
	while(1)
	{

		leds_on();
		OSTimeDly(800);
		leds_off();
		OSTimeDly(130);
	}
}

void Task2(void *Id)
{
	int i;
	  OSSemPend(UART_sem, 0, &err);
      uHALr_printf("  Task%c Called.\n", *(char *)Id);
     OSSemPost(UART_sem);
	while(1)
	{
       	for(i=0; i<16; i++)
	  {
		Digit_Led_Symbol(i);
		OSTimeDly(150);
	  }
	}
}

void Task3(void *Id)
{
//	char *Msg;
	int i=0;
	OSSemPend(UART_sem, 0, &err);
	uHALr_printf("task%c called \n",*(char *)Id);
	OSSemPost(UART_sem);
	while(1)
	{
       	i++;
      	uHALr_printf("           **** %d ****\r",i);
 		OSTimeDly(190);
	}
}

void TaskStart (void *i)
{

     char Id1 = '1';
     char Id2 = '2';
     char Id3 = '3';
     
     
     UART_sem=OSSemCreate(1);
     uHALr_InitTimers();            // enable timer counter interrupt
                
     /*
     * create the tasks in uC/OS and assign decreasing
     * priority to them
     */

    OSTaskCreate(Task1, (void *)0, &Stack1[STACKSIZE - 1], 2);
    OSTaskCreate(Task2, (void *)0, &Stack2[STACKSIZE - 1], 3);
    OSTaskCreate(Task3, (void *)0, &Stack3[STACKSIZE - 1], 4);
    
    // Delete current task
    OSTaskDel(OS_PRIO_SELF);
}

int Main(void)//int argc, char **argv
{
	char Id4 = '4';
	ARMTargetInit();
	
	/* needed by uC/OS */
	OSInit();
	
	OSTimeSet(0);
	
	/* create the start task */
	OSTaskCreate(TaskStart,(void *)0, &StackMain[STACKSIZE - 1], 0);
	
	ARMTargetStart();
	
	/* start the operating system */
	OSStart();
	
	return(0);
	
//* End
}                              


⌨️ 快捷键说明

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