Esempio n. 1
0
                            void main(void)
{
    OSInit();

	TMOD = (TMOD & 0XF0) | 0X01;
	TL0 = 0x0;
	TH0 = 0x0;
	TR0 = 1;
	ET0 = 1;
	TF0 = 0;

	PC_DispClrScr(DISP_FGND_WHITE + DISP_BGND_BLACK); 
    PC_DispStr(15,  0, "Small RTOS(51), the Real-Time Kernel(For Keil c51)", DISP_FGND_WHITE + DISP_BGND_RED + DISP_BLINK);
    PC_DispStr(35,  1, "ChenMingJi", DISP_FGND_WHITE);
    PC_DispStr(35,  3, "EXAMPLE #2", DISP_FGND_WHITE);

    OSTaskCreate(TaskA, NULL, 0);
    OSTaskCreate(TaskB, NULL, 1);
    OSTaskCreate(TaskC, NULL, 2);
    OSTaskCreate(TaskD, NULL, 3);
    OSTaskCreate(TaskE, NULL, 4);

    while(1)
    {
        PCON = PCON | 0x01;                     /* CPU进入休眠状态 */
    }
}
Esempio n. 2
0
File: TEST.C Progetto: yylea/UCOS2
void  main (void)
{
    PC_DispClrScr(DISP_BGND_BLACK);                        /* Clear the screen                         */

    OSInit();                                              /* Initialize uC/OS-II                      */

    PC_DOSSaveReturn();                                    /* Save environment to return to DOS        */

    PC_VectSet(uCOS, OSCtxSw);                             /* Install uC/OS-II's context switch vector */

    //Initialized elapsed time measurement function that is used to
    //measure the execution time of OSTaskStkChk()
    PC_ElapsedInit();                                      /* Initialized elapsed time measurement     */

    strcpy(TaskUserData[TASK_START_ID].TaskName, "StartTask");
    OSTaskCreateExt(TaskStart,                             //pointer to task's function
                    (void *)0,                             //the parameter to the task's function
                    &TaskStartStk[TASK_STK_SIZE - 1],      //top of the stack
                    TASK_START_PRIO,                       //priority
                    TASK_START_ID,                         //task ID
                    &TaskStartStk[0],                      //bottom of the stack
                    TASK_STK_SIZE,                         //stack size
                    &TaskUserData[TASK_START_ID],          //Task Control Block TCB can store a pointer to a user-provided data structure
                                                           //this allows to extend the functionality of UCOSII
                    0);                                    //a set of additional options
    OSStart();                                             /* Start multitasking                       */
}
Esempio n. 3
0
void main (void) {
	int far *bootend;
	int result;
	int *test1, *test2;
	
	msgIndex = tickCnt = 0;
	init_queue(&osqueue1);
	init_queue(&osqueue2);
	bootend = MK_FP(0x7c0, 510);
	result = *bootend;
	if(result == 0xAA55)
		isFunnyOS = 1;

	//test1 = osMalloc(10);
	//strcpy(test1, "testmallcabcdefghi");
	//test2 = osMalloc(20);
	//strcpy(test2, "test2malloc");
	
    PC_DispClrScr(DISP_FGND_WHITE + DISP_BGND_BLACK);      /* Clear the screen                         */

    PC_DispStr( 0,  0, "                                  Funny OS Demo                                 ", DISP_FGND_WHITE + DISP_BGND_RED + DISP_BLINK);
	//PC_DispChar( 10,  0, '0' + isFunnyOS , DISP_FGND_WHITE + DISP_BGND_RED + DISP_BLINK);
	//PC_DispStr( 15,  0, test1, DISP_FGND_WHITE + DISP_BGND_RED + DISP_BLINK);	
	//PC_DispStr( 15,  1, test2, DISP_FGND_WHITE + DISP_BGND_RED + DISP_BLINK);	
	//PC_DispChar( 14,  0, *bootend , DISP_FGND_WHITE + DISP_BGND_RED + DISP_BLINK);
	PC_SetTickRate(18);                      /* Reprogram tick rate                      */
	//PC_TickISR = &TickISR;
	PC_TickISR   = PC_VectGet(0x8);  
	PC_VectSet(0x8, &TickISR); //asm {int 08h};
	
//	ptask1 = &testTask1;
//	ptask2 = &testTask2;
	task[0].ptask = &gameSnake;//&testTask1;
	task[0].stack_SS = 0x9000;
	task[0].stack_SP = 0x100;
	taskCount++;
	
	task[1].ptask = &gameTetris;//&task_bubble_sort;//&testTask2;
	task[1].stack_SS = 0x8000;
	task[1].stack_SP = 0x100;
	taskCount++;

	task[2].ptask = &taskReadKeyBoard; //&task_select_sort;
	task[2].stack_SS = 0x7000;
	task[2].stack_SP = 0x100;
	taskCount++;
	
	task[3].ptask = &task_quick_sort;
	task[3].stack_SS = 0x6000;
	task[3].stack_SP = 0x100;
	//taskCount++;
	for(;;);
}
Esempio n. 4
0
void main ( void )
{
	memset(sRunning, 0x01, 10);                            // flag all task will run at kernel starting

	PC_DispClrScr(DISP_FGND_WHITE + DISP_BGND_BLACK); 	   /* Clear the screen                         */
	OSInit();                                              /* Initialize uC/OS-II                      */
	PC_DOSSaveReturn();                                    /* Save environment to return to DOS        */
	PC_VectSet(uCOS, OSCtxSw);                             /* Install uC/OS-II's context switch vector */
	RandomSem = OSSemCreate(1);                            /* Random number semaphore                  */
	OSTaskCreate(TaskStart, (void *)0, (void *)&TaskStartStk[TASK_STK_SIZE - 1], 0);
	OSStart();                                             /* Start multitasking                       */
}
Esempio n. 5
0
void  main (void) {
    PC_DispClrScr(DISP_FGND_WHITE + DISP_BGND_BLACK);      /* Clear the screen                         */

    OSInit();                                              /* Initialize uC/OS-II                      */

    PC_DOSSaveReturn();                                    /* Save environment to return to DOS        */
    PC_VectSet(uCOS, OSCtxSw);                             /* Install uC/OS-II's context switch vector */

    RandomSem   = OSSemCreate(1);                          /* Random number semaphore                  */
	MSGQ		= OSQCreate(MSGQGrp, N_TASKS);
	OSQFlush(MSGQ);
	
    OSTaskCreate(TaskStart, (void *)0, &TaskStartStk[TASK_STK_SIZE - 1], 0);
    OSStart();                                             /* Start multitasking                       */
}
/*
 * Application
 */
void  main (void) {

    PC_DispClrScr(DISP_FGND_WHITE + DISP_BGND_BLACK);      	/* Clear the screen                         */

    OSInit();                                              	/* Initialize uC/OS-II                      */

    PC_DOSSaveReturn();                                    	/* Save environment to return to DOS        */
    PC_VectSet(uCOS, OSCtxSw);                             	/* Install uC/OS-II's context switch vector */
	PC_ElapsedInit();
	
	CarMbox = OSMboxCreate((void *)0);					   	/* Create an empty mailbox for communication between car lane sensors and the controller*/
	PedMbox = OSMboxCreate((void *)0);					   	/* Create an empty mailbox for communication between pedestrian lane sensors and the controller*/
	Car1ToCar2Mbox = OSMboxCreate((void *)0);				/* Create an empty mailbox for communication from car1 to car2*/
	Car2ToCar3Mbox = OSMboxCreate((void *)0);				/* Create an empty mailbox for communication from car2 to car3*/

    OSTaskCreate(TaskStart, (void *)0, &TaskStartStk[TASK_STK_SIZE - 1], 0);
    OSStart();                                             	/* Start multitasking                       */
}
Esempio n. 7
0
File: TEST.C Progetto: yylea/UCOS2
void  main (void)
{
    PC_DispClrScr(DISP_FGND_WHITE + DISP_BGND_BLACK);      /* Clear the screen                         */

    OSInit();                                              /* Initialize uC/OS-II                      */

    PC_DOSSaveReturn();                                    /* Save environment to return to DOS        */
    PC_VectSet(uCOS, OSCtxSw);                             /* Install uC/OS-II's context switch vector */

    OSTaskCreateExt(TaskStart,
                    (void *)0,
                    &TaskStartStk[TASK_STK_SIZE - 1],
                    0,                                     /* Task priority = 0                        */
                    0,
                    &TaskStartStk[0],
                    TASK_STK_SIZE,
                    (void *)0,
                    OS_TASK_OPT_SAVE_FP);
    OSStart();                                             /* Start multitasking                       */
}
Esempio n. 8
0
/*
*********************************************************************************************************
*                                        SAVE DOS RETURN LOCATION
*
* Description : This function saves the location of where we are in DOS so that it can be recovered.
*               This allows us to abort multitasking under uC/OS-II and return back to DOS as if we had
*               never left.  When this function is called by 'main()', it sets 'PC_ExitFlag' to FALSE
*               so that we don't take the 'if' branch.  Instead, the CPU registers are saved in the
*               long jump buffer 'PC_JumpBuf' and we simply return to the caller.  If a 'long jump' is
*               performed using the jump buffer then, execution would resume at the 'if' statement and
*               this time, if 'PC_ExitFlag' is set to TRUE then we would execute the 'if' statements and
*               restore the DOS environment.
*
* Arguments   : None
*
* Returns     : None
*********************************************************************************************************
*/
void PC_DOSSaveReturn (void)
{
    PC_ExitFlag  = FALSE;                                  /* Indicate that we are not exiting yet!    */
    OSTickDOSCtr =     1;                                  /* Initialize the DOS tick counter          */
    PC_TickISR   = PC_VectGet(VECT_TICK);                  /* Get MS-DOS's tick vector                 */
    
    OS_ENTER_CRITICAL();
    PC_VectSet(VECT_DOS_CHAIN, PC_TickISR);                /* Store MS-DOS's tick to chain             */
    OS_EXIT_CRITICAL();
    
    setjmp(PC_JumpBuf);                                    /* Capture where we are in DOS              */
    if (PC_ExitFlag == TRUE) {                             /* See if we are exiting back to DOS        */
        OS_ENTER_CRITICAL();
        PC_SetTickRate(18);                                /* Restore tick rate to 18.2 Hz             */
        PC_VectSet(VECT_TICK, PC_TickISR);                 /* Restore DOS's tick vector                */
        OS_EXIT_CRITICAL();
        PC_DispClrScr(DISP_FGND_WHITE + DISP_BGND_BLACK);  /* Clear the display                        */
        exit(0);                                           /* Return to DOS                            */
    }
}
Esempio n. 9
0
File: test.c Progetto: palmerc/lab
int main (void)
{
    PC_DispClrScr(DISP_BGND_BLACK);                        /* Clear the screen                         */

    OSInit();                                              /* Initialize uC/OS-II                      */

    PC_ElapsedInit();                                      /* Initialized elapsed time measurement     */

    strcpy(TaskUserData[TASK_START_ID].TaskName, "StartTask");
    OSTaskCreateExt(TaskStart,
                    (void *)0,
                    &TaskStartStk[TASK_STK_SIZE - 1],
                    TASK_START_PRIO,
                    TASK_START_ID,
                    &TaskStartStk[0],
                    TASK_STK_SIZE,
                    &TaskUserData[TASK_START_ID],
                    0);
    OSStart();                                             /* Start multitasking                       */

    return 0;
}
Esempio n. 10
0
File: TEST.C Progetto: AaronXCh/code
void  main (void)
{
    PC_DispClrScr(DISP_BGND_BLACK);                        /* Clear the screen                         */

    OSInit();                                              /* Initialize uC/OS-II                      */

    PC_DOSSaveReturn();                                    /* Save environment to return to DOS        */

    PC_VectSet(uCOS, OSCtxSw);                             /* Install uC/OS-II's context switch vector */

    PC_ElapsedInit();                                      /* Initialized elapsed time measurement     */

    strcpy(TaskUserData[TASK_START_ID].TaskName, "StartTask");
    OSTaskCreateExt(TaskStart,
                    (void *)0,
                    &TaskStartStk[TASK_STK_SIZE - 1],
                    TASK_START_PRIO,
                    TASK_START_ID,
                    &TaskStartStk[0],
                    TASK_STK_SIZE,
                    &TaskUserData[TASK_START_ID],
                    0);
    OSStart();                                             /* Start multitasking                       */
}
Esempio n. 11
0
/*
*********************************************************************************************************
*                                                  RECEIVETASK
*********************************************************************************************************
*/
void ReceiveTask(void *pdata) {
	INT8U err;
	INT8U pos_x = 0, pos_y = 0;	
	INT8U font_color;
	char *str_receiv;
	INT16U recev;
	float result;
	char avg[10];
	char attention[2];
	INT16U i = 0; 										///used for row control
	char str_print[10];
	
	INT16U number = 0;									//used for calculating averages in receiving data.
	
	FILE* fp;	
	char filename[25];
	
	INT16U data_iter = 0;										//data_iter/10 is the row and data_iter%10 is the col
	static INT16U times[10];									//used for count the times received
	static INT16U data[10];									//used for record all the data.
	static INT16U max[10];
	static INT16U min[10];
	static INT16U sumr[10];	
	
    pdata = pdata;
	memset(min,1000,sizeof(min));							//initialize the min array
    for (;;) {
		GetDate(filename);
		strcat(filename,"Rv.dat");
		fp = fopen(filename, "a");
		str_receiv = OSQPend(MSGQ,20,&err);				//request message
		pos_x = i;
		i ++;
		i %= 10;
		if (pos_y/10 == 7) {
			pos_y = 0;
			
			PC_DispClrScr(DISP_FGND_BLACK + DISP_BGND_LIGHT_GRAY);
			TaskStartDispInit();
		}
        PC_DispStr(5+6*pos_x, 10 + pos_y/10, str_receiv, DISP_FGND_BLACK + DISP_BGND_LIGHT_GRAY);
		fprintf(fp, "%s", str_receiv);
		recev = atoi(str_receiv);
		
		
		if (data_iter == 70) {
			data_iter = 0;
		}
		data[data_iter%10] = recev;

		PntIntNum((++ times[data_iter%10]),5+6*pos_x, 17);
		
		if (times[9] == 100) {
			TaskSuspend();
		}
		
		max[data_iter%10] = (max[data_iter%10] < recev) ? recev : max[data_iter%10];
		PntIntNum(max[data_iter%10],5+6*pos_x, 18);
		
		min[data_iter%10] = (min[data_iter%10] > recev) ? recev : min[data_iter%10];
		PntIntNum(min[data_iter%10],5+6*pos_x, 19);
		
		sumr[data_iter%10] += recev;
		PntFltNum((float)sumr[data_iter%10]/(float)times[data_iter%10],5+6*pos_x,20);
		DrawGraph(sumr[data_iter%10]/times[data_iter%10], pos_x);
		
		data_iter ++;
			
		number += recev;
		result = (float)number/10.0;
		sprintf(avg,"%6.2f",result);
		
		attention[0] = Classify((unsigned int)result);
		attention[1] = 0;								//the string ending
		strcat(avg,attention);
		font_color = 0x00 + ((*attention) - 'A');
		
		PC_DispStr(68, 10 + pos_y/10, avg, font_color + DISP_BGND_LIGHT_GRAY);
		if (pos_y%10 == 9) {
			fprintf(fp, "%8s\n%6s",avg," "); 
			memset(avg,0,sizeof(avg));
			number = 0;
			RemoveGraph();
		}
		
        OSTimeDlyHMSM(0, 0, 0, 100);
		pos_y ++;
		fclose(fp);
    }
	
}