示例#1
0
文件: TEST.C 项目: 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                       */
}
/*
*********************************************************************************************************
*                                              STARTUP TASK
*********************************************************************************************************
*/
void  TaskStart (void *pdata)
{
#if OS_CRITICAL_METHOD == 3                                /* Allocate storage for CPU status register */
    OS_CPU_SR  cpu_sr;
#endif
    char       s[100];
    INT16S     key;


    pdata = pdata;                                         /* Prevent compiler warning                 */

    TaskStartDispInit();                                   /* Initialize the display                   */

    OS_ENTER_CRITICAL();								   /* Used to disable interrupts (see chapter 13)*/
    PC_VectSet(0x08, OSTickISR);                           /* Install uC/OS-II's clock tick ISR        */
    PC_SetTickRate(OS_TICKS_PER_SEC);                      /* Reprogram tick rate                      */
    OS_EXIT_CRITICAL();									   /* Re-enable interrupts*/

    OSStatInit();                                          /* Initialize uC/OS-II's statistics         */

    TaskStartCreateTasks();                                /* Create all the application tasks         */

    for (;;) {


        if (PC_GetKey(&key) == TRUE) {                     /* See if key has been pressed              */
            if (key == 0x1B) {                             /* Yes, see if it's the ESCAPE key          */
                PC_DOSReturn();                            /* Return to DOS                            */
            }
        }

        OSCtxSwCtr = 0;                                    /* Clear context switch counter             */
        OSTimeDlyHMSM(0, 0, 1, 0);                         /* Wait one second                          */
    }
}
示例#3
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                            */
    }
}
示例#4
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(;;);
}
示例#5
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                       */
}
示例#6
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                       */
}
示例#8
0
文件: TEST.C 项目: 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                       */
}
示例#9
0
/*
*********************************************************************************************************
*                                              STARTUP TASK
*********************************************************************************************************
*/
void  TaskStart (void *pdata) {
#if OS_CRITICAL_METHOD == 3                                /* Allocate storage for CPU status register */
    OS_CPU_SR  cpu_sr;
#endif
    char       s[100];
    INT16S     key;

    pdata = pdata;                                         /* Prevent compiler warning                 */

    TaskStartDispInit();                                   /* Initialize the display                   */

    OS_ENTER_CRITICAL();
    PC_VectSet(0x08, OSTickISR);                           /* Install uC/OS-II's clock tick ISR        */
    PC_SetTickRate(OS_TICKS_PER_SEC);                      /* Reprogram tick rate                      */
    OS_EXIT_CRITICAL();

    OSStatInit();                                          /* Initialize uC/OS-II's statistics         */
	FileContentInit();									   /* Initialize fileContent				   */
    TaskStartCreateTasks();                                /* Create all the application tasks         */
	
	OSTaskCreate(ReceiveTask,(void *)0, &ReceiveTaskStk[TASK_STK_SIZE - 1], 11);

    for (;;) {
        TaskStartDisp();                                  /* Update the display                       */


        if (PC_GetKey(&key) == TRUE) {                     /* See if key has been pressed              */
            if (key == 'q')                                /* Yes, see if it's the ESCAPE key          */
                PC_DOSReturn();                            /* Return to DOS                            */
			if (key == 'b')								   /* See if it's b and then stop the tasks	   */
				TaskSuspend();
			if (key == 'r')								   /* See if it's r and then resume the tasks	   */
				TaskResume();
        }

        OSCtxSwCtr = 0;                                    /* Clear context switch counter             */
        OSTimeDlyHMSM(0, 0, 0, 100);                         /* Wait one second                          */
    }
}
示例#10
0
文件: TEST.C 项目: yylea/UCOS2
void  TaskStart (void *pdata)
{
#if OS_CRITICAL_METHOD == 3                                /* Allocate storage for CPU status register */
    OS_CPU_SR  cpu_sr;
#endif
    INT16S     key;


    pdata = pdata;                                         /* Prevent compiler warning                 */

    TaskStartDispInit();                                   /* Setup the display                        */

    OS_ENTER_CRITICAL();                                   /* Install uC/OS-II's clock tick ISR        */
    PC_VectSet(0x08, OSTickISR);
    PC_SetTickRate(OS_TICKS_PER_SEC);                      /* Reprogram tick rate                      */
    OS_EXIT_CRITICAL();

    OSStatInit();                                          /* Initialize uC/OS-II's statistics         */

    MsgQueue = OSQCreate(&MsgQueueTbl[0], MSG_QUEUE_SIZE); /* Create a message queue                   */

    TaskStartCreateTasks();

    for (;;) {
        TaskStartDisp();                                  /* Update the display                       */

        if (PC_GetKey(&key)) {                             /* See if key has been pressed              */
            if (key == 0x1B) {                             /* Yes, see if it's the ESCAPE key          */
                PC_DOSReturn();                            /* Yes, return to DOS                       */
            }
        }

        OSCtxSwCtr = 0;                                    /* Clear the context switch counter         */
        OSTimeDly(OS_TICKS_PER_SEC);                       /* Wait one second                          */
    }
}
示例#11
0
文件: TEST.C 项目: 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                       */
}
示例#12
0
void TaskStart ( void *data )
{
	PWINDOWS ptr = GetActiveWindow();
	UBYTE  i;
	char   sCmd[MAX_X];
	WORD   key;
	WORD   index, pos = 0x00;

	data = data;                                           /* Prevent compiler warning                 */

	OS_ENTER_CRITICAL();
	PC_VectSet(0x08, OSTickISR);                           /* Install uC/OS-II's clock tick ISR        */
	PC_SetTickRate(OS_TICKS_PER_SEC);                      /* Reprogram tick rate                      */
	OS_EXIT_CRITICAL();

    PC_DispChar(0, 0, ' ', 0x00);               
	PC_DispStr (8, 16, "Determining  CPU's capacity ...", DISP_FGND_WHITE);
	CreateWindow (0, StartY, MAX_X, EndY, DISP_FGND_WHITE, DISP_BGND_BLUE, "[ Prompt Window ]");
	CreateTaskWindows();
	OSStatInit();                                          /* Initialize uC/OS-II's statistics         */

	for (i = 0; i < N_TASKS; i ++)
	{                                                      /* Create N_TASKS identical tasks           */
		TaskData[i] = '0' + i;                             /* Each task will display its own letter    */
		OSTaskCreate(Task, (void *)&TaskData[i], (void *)&TaskStk[i][TASK_STK_SIZE - 1], i + 1);
	}

	DisplayTitle();

	ClearWindow();
	memset(sCmd, 0x00, MAX_X);
	DisplayPrompt();
	for (;;)
	{
		DisplayStatus();                                   // display status of tasks

		if (PC_GetKey(&key) == TRUE)
		{                                                  /* See if key has been pressed              */
			if (key == 0x1B)
			{                                              /* Yes, see if it's the ESCAPE key          */
				PC_DOSReturn();                            /* Return to DOS                            */
			}
			else if (key == 0x08)                           // backspace
			{
				pos --;
				pos = pos <= 0x00 ? 0x00 : pos;
				sCmd[pos] = '\0';
				PC_DispChar(ptr->cx + pos + strlen(sCmdPrompt), ptr->cy, ' ', ptr->color);
				DisplayCursor(ptr->cx + pos + strlen(sCmdPrompt), ptr->cy);
			}
			else if (key == 0x0d || key == 0x0a)                           // enter
			{
				if (pos)
				{
					index = ParseCommand(sCmd);
					HandleCommand(index);
				}
				memset(sCmd, 0x00, MAX_X);
				pos = 0x00;
				ptr->cy ++;
				if (ptr->cy == ptr->ey - 1)
					ClearWindow();
				DisplayPrompt();
			}
			else if ((key >= '0' && key <= '9') ||
				(key >= 'a' && key <= 'z') || (key >= 'A' && key <= 'Z'))
			{
				if (pos < MAX_X)
				{
					sCmd[pos] = (char)key;
					PC_DispChar(ptr->cx + pos + strlen(sCmdPrompt), ptr->cy, key, ptr->color);
	                DisplayCursor (ptr->cx + pos + strlen(sCmdPrompt) + 1, ptr->cy);
				}
				pos ++;
			}

		}
		OSTimeDlyHMSM(0, 0, 0, 200);                         /* Wait 200 ms                          */
	}
}