Example #1
0
void handleNewPieceTask()
{
	int type;
	
	while(1) 
	{
		//wait for a new piece to be created
		YKSemPend(newPieceSEM);
		YKEnterMutex();
		type = NewPieceType;
		/*printString("NEW PIECE id = ");
		printInt(NewPieceID);
		printString(" type = ");
		printInt(NewPieceType);
		printString(" column = ");
		printInt(NewPieceColumn);
		printString(" Orientation = ");
		printInt(NewPieceOrientation);
		printNewLine();//*/
		YKExitMutex();
		
		//Accessing global variables, so better be in mutex
		if(type) //Straight piece
		{
			straightPieceHandler();
		}
		else //square piece
		{
			cornerPieceHandler();
		}
			
	}
}
Example #2
0
void handleSendMovementTask()
{
    struct movement *tmp;  //movement vs Movement capitalized -> don't know which

    while(1) 
	{
		
		YKSemPend(receivedSEM);
		
        tmp = (struct movement*) YKQPend(MsgQPtr); // get next msg
		/*printString("send id = ");
		printInt(tmp->id);
		printString(" slide = ");
		printInt(tmp->slide);
		printString(" rotate = ");
		printInt(tmp->rotate);
		printNewLine();//*/
		if(tmp->slide > -1) //slide the piece
		{
			SlidePiece(tmp->id, tmp->slide);
		}
		else // rotate the piece
		{
			RotatePiece(tmp->id, tmp->rotate);
		}
    }

}
Example #3
0
void TaskWord(void)
{
    while (1)
    {
        YKSemPend(WSemPtr);
        printString("Hey");
        YKSemPost(PSemPtr);
                
        YKSemPend(WSemPtr); 
        printString("it");
        YKSemPost(SSemPtr);
                
        YKSemPend(WSemPtr); 
        printString("works");
        YKSemPost(PSemPtr);
    }
}
Example #4
0
void TaskSpace(void)
{
    while (1)
    {
        YKSemPend(SSemPtr);
        printChar(' ');
        YKSemPost(WSemPtr);
    }
}
Example #5
0
void TaskPunc(void)
{
    while (1)
    {
        YKSemPend(PSemPtr);
        printChar('"');
        YKSemPost(WSemPtr);
                
        YKSemPend(PSemPtr);
        printChar(',');
        YKSemPost(SSemPtr);
                
        YKSemPend(PSemPtr);
        printString("!\"\r\n");
        YKSemPost(PSemPtr);
                
        YKDelayTask(6);
    }
}
Example #6
0
void* YKQPend(YKQ *queue){
	void* msg;
	//check if head == tail
	YKSemPend(queue->sem);
	if(queue->head == -1){
		printString("null value returned");
		return NULL;
	}
	msg = queue->queue[queue->head++];
	//update head(increment)
	if(queue->head == queue->length)
		queue->head = 0;
	if(queue->head == queue->tail) // empty
		queue->head = -1;
	return msg;
}
Example #7
0
/*
 * Communicates with simptris
 */
void CommunicationTask(void) {
	scmd* ncmd;

	SeedSimptris((long) SEED);
	StartSimptris();
	printString("\nSimptris Started!\n");
	
	while(1) {

		ncmd = (scmd*) YKQPend(CmdQPtr);
		if (ncmd->command == ROTATE) {
			RotatePiece(ncmd->id, ncmd->parameter);
		}
		else {
			SlidePiece(ncmd->id, ncmd->parameter);
		}
		YKSemPend(commandReceivedSem);
	}
}
Example #8
0
void TaskPrime(void)            /* task that actually computes primes */
{
	//stops at 32497
    int curval = 1001;
    int j,flag,lncnt;
    int endval;
    
    while (1)
    {
        YKSemPend(NSemPtr);
	
        /* compute next range of primes */
        lncnt = 0;
        endval = curval + 500;
        for ( ; curval < endval; curval += 2)
        {
            flag = 0;
            for (j = 3; (j*j) < curval; j += 2)
            {
                if (curval % j == 0)
                {
                    flag = 1;
                    break;
                }
            }
            if (!flag)
            {
                printChar(' ');
                printInt(curval);
                lncnt++;
                if (lncnt > 9)
                {
                    printNewLine();
                    lncnt = 0;
                }
            }
        }
        printNewLine();
    }
}