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

📄 main_entry.c

📁 非常实用的参考资料
💻 C
字号:
/*
*********************************************************************************************************
*                                                uC/OS-II
*                                          The Real-Time Kernel
*
description:	这个shell从skyeye项目中的ucos测试程序Genie shell移植过来
				目前的genie shell带有两条命令:
				hostname命令在屏幕上打印一句话,很简单。
				hello 命令可以带多个参数,如hello a b c d,回车后会显示:
				hello,I am Genie
				your argv is:
				a
				b
				c
				d
				这个例子具体请看原作者写的《Genie shell for UCOS II 详细说明及使用指南》
				具体在skyeye项目中有下载
				移植此shell的目的是为下一步移植文件系统做准备

date:			20050409
author:		文佳 Email:ganganwen@163.com 
*********************************************************************************************************
*/

#include "includes.h"
#include "shelltask.h"
/*
*********************************************************************************************************
*                                               CONSTANTS
*********************************************************************************************************
*/

#define  TASK_STK_SIZE                 1024       /* Size of each task's stacks (# of WORDs)            */
#define  N_TASKS                        10       /* Number of identical tasks                          */

#define TaskStart_Prio	1
#define Task1_Prio		2

/*
*********************************************************************************************************
*                                               VARIABLES
*********************************************************************************************************
*/

OS_STK  TaskStk[N_TASKS][TASK_STK_SIZE];    // Tasks stacks


BOOLEAN FlagEn = 1;		//增加一个全局变量,做为是否时钟调度的标志
char bufchar; 
OS_EVENT *sem1;
/*
*********************************************************************************************************
*                                           FUNCTION PROTOTYPES
*********************************************************************************************************
*/
void TaskStart(void * pParam) ;
void Task1(void * pParam) ;                            /* Function prototypes of tasks                  */

void VCInit(void);						//初始化相关变量,一定需要

/*$PAGE*/
/*
*********************************************************************************************************
*                                                MAIN
*********************************************************************************************************
*/

int main(int argc, char **argv)
{
	VCInit();	//初始化一些变量
	
	OSInit();
	OSTaskCreate(TaskStart, 0, &TaskStk[0][TASK_STK_SIZE-1], TaskStart_Prio);
	OSTaskCreate(shelltask, 0, &TaskStk[1][TASK_STK_SIZE-1], Task1_Prio);

	OSStart();	//start never return
	
	return 0;
}

void VCInit(void)
{
	HANDLE cp,ct;
	Context.ContextFlags = CONTEXT_CONTROL;
	cp = GetCurrentProcess();	//得到当前进程句柄
	ct = GetCurrentThread();	//得到当前线程伪句柄
	DuplicateHandle(cp, ct, cp, &mainhandle, 0, TRUE, 2);	//伪句柄转换,得到线程真句柄
		
}

void TaskStart(void * pParam) 
{	
	char err;	

	timeSetEvent(1000/OS_TICKS_PER_SEC, 0, OSTickISR, 0, TIME_PERIODIC);	//开启一个定时器线程,感觉10 ticks/s比较好
	sem1 = OSSemCreate(0);
	while(1)
	{
		
		OSSemPend(sem1, 0, &err);   //sleep ,wait for sem1
		OS_ENTER_CRITICAL();	//调用printf函数最好关中断
		printf( "Task1 running... Your input char: \"%c\"\n", bufchar );
		OS_EXIT_CRITICAL();
	}
}

⌨️ 快捷键说明

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