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

📄 main_entry.c

📁 ucos_vc.rar
💻 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                        20       /* Number of identical tasks                          */

#define TaskStart_Prio	3
#define Task1_Prio		5
#define Task2_Prio		8
#define MUTEX_PRIO      6
#define Task3_Prio		10
/*
*********************************************************************************************************
*                                               VARIABLES
*********************************************************************************************************
*/

OS_STK  TaskStk[N_TASKS][TASK_STK_SIZE];    // Tasks stacks
BOOLEAN FlagEn = 1;		//增加一个全局变量,做为是否时钟调度的标志
char bufchar; 
OS_EVENT *sem1;
OS_EVENT *sem2;
OS_EVENT *sem3;
OS_EVENT *mutex;
char biaozhi=1;
/*
*********************************************************************************************************
*                                           FUNCTION PROTOTYPES
*********************************************************************************************************
*/
void TaskStart(void * pParam) ;
void Task1(void * pParam) ;                            /* Function prototypes of tasks                  */
void Task2(void * pParam) ;    
void Task3(void * pParam) ; 
void VCInit(void);	
int err;					//初始化相关变量,一定需要

/*$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);
    OSTaskCreate(Task1, 0, &TaskStk[1][TASK_STK_SIZE-1], Task1_Prio);
    OSTaskCreate(Task2, 0, &TaskStk[2][TASK_STK_SIZE-1], Task2_Prio);
	OSTaskCreate(Task3, 0, &TaskStk[3][TASK_STK_SIZE-1], Task3_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();
		//OSTimeDly(1);
	}
	
}*/
void Task1(void * pParam) 
{	char err;
    
    timeSetEvent(1000/OS_TICKS_PER_SEC, 0, OSTickISR, 0, TIME_PERIODIC);
	sem2=OSSemCreate(0);//建立信号量
	sem3=OSSemCreate(0);
	//mutex=OSMutexCreate(MUTEX_PRIO,&err);
    if(biaozhi==1){
	while(1){
    OS_ENTER_CRITICAL();
	OSSemPend(sem2,0,&err);
	printf("TASK1正在运行\n\n\n\n\n");
 	OS_EXIT_CRITICAL();
	OSTimeDly(1);
	}
	}
}
void Task2(void * pParam) 
{	
	int i=0;
	while(1){
	printf("请输入1,让任务1运行\n输入3,让任务3运行\n\n\n");
	OS_ENTER_CRITICAL();
	scanf("%d",&i);
	switch(i)
	{
	case 1:		
		OSSemPost(sem2);
		break;
	case 2:		
		printf("请重新输入\n\n\n");
		//OSSemPost(sem2);
		break;
	case 3:		
		OSSemPost(sem3);
		break;
	default:
		printf("请重新输入\n\n\n");
		break;
	}
	OS_EXIT_CRITICAL();
	OSTimeDly (1);
	}
}
void Task3(void * pParam) 
{	
    char err;
	while(1){
		OS_ENTER_CRITICAL();
		OSSemPend(sem3,0,&err);
	    printf("任务三正在运行\n\n\n\n\n");
		OS_EXIT_CRITICAL();
	    OSTimeDly (1);
		}
}

⌨️ 快捷键说明

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