Exemple #1
0
struct StateClass handleYellow(enum Event event)
{
	if (event == WAIT)
	{
		handleWait();
		return states[RED];
	}
}
Exemple #2
0
exception_t
handleSyscall(syscall_t syscall)
{
    exception_t ret;
    irq_t irq;

    switch (syscall) {
    case SysSend:
        ret = handleInvocation(false, true);
        if (unlikely(ret != EXCEPTION_NONE)) {
            irq = getActiveIRQ();
            if (irq != irqInvalid) {
                handleInterrupt(irq);
            }
        }
        break;

    case SysNBSend:
        ret = handleInvocation(false, false);
        if (unlikely(ret != EXCEPTION_NONE)) {
            irq = getActiveIRQ();
            if (irq != irqInvalid) {
                handleInterrupt(irq);
            }
        }
        break;

    case SysCall:
        ret = handleInvocation(true, true);
        if (unlikely(ret != EXCEPTION_NONE)) {
            irq = getActiveIRQ();
            if (irq != irqInvalid) {
                handleInterrupt(irq);
            }
        }
        break;

    case SysWait:
        handleWait();
        break;

    case SysReply:
        handleReply();
        break;

    case SysReplyWait:
        handleReply();
        handleWait();
        break;

    case SysYield:
        handleYield();
        break;

    default:
        fail("Invalid syscall");
    }

    schedule();
    activateThread();

    return EXCEPTION_NONE;
}
Exemple #3
0
bool Script::executeCommand(int index, MasterTimer* timer, QList<Universe *> universes)
{
    if (index < 0 || index >= m_lines.size())
    {
        qWarning() << "Invalid command index:" << index;
        return false;
    }

    QList <QStringList> tokens = m_lines[index];
    if (tokens.isEmpty() == true)
        return true; // Empty line

    bool continueLoop = true;
    QString error;
    if (tokens[0].size() < 2)
    {
        error = QString("Syntax error");
    }
    else if (tokens[0][0] == Script::startFunctionCmd)
    {
        error = handleStartFunction(tokens, timer);
    }
    else if (tokens[0][0] == Script::stopFunctionCmd)
    {
        error = handleStopFunction(tokens);
    }
    else if (tokens[0][0] == Script::waitCmd)
    {
        // Waiting should break out of the execution loop to prevent skipping
        // straight to the next command. If there is no error in wait parsing,
        // we must wait at least one cycle.
        error = handleWait(tokens);
        if (error.isEmpty() == true)
            continueLoop = false;
    }
    else if (tokens[0][0] == Script::waitKeyCmd)
    {
        // Waiting for a key should break out of the execution loop to prevent
        // skipping straight to the next command. If there is no error in waitkey
        // parsing,we must wait at least one cycle.
        error = handleWaitKey(tokens);
        if (error.isEmpty() == true)
            continueLoop = false;
    }
    else if (tokens[0][0] == Script::setFixtureCmd)
    {
        error = handleSetFixture(tokens, universes);
    }
    else if (tokens[0][0] == Script::labelCmd)
    {
        error = handleLabel(tokens);
    }
    else if (tokens[0][0] == Script::jumpCmd)
    {
        // Jumping can cause an infinite non-waiting loop, causing starvation
        // among other functions. Therefore, the script must relinquish its
        // time slot after each jump. If there is no error in jumping, the jump
        // must have happened.
        error = handleJump(tokens);
        if (error.isEmpty() == true)
            continueLoop = false;
    }
    else
    {
        error = QString("Unknown command: %1").arg(tokens[0][0]);
    }

    if (error.isEmpty() == false)
        qWarning() << QString("Script:%1, line:%2, error:%3").arg(name()).arg(index).arg(error);

    return continueLoop;
}
Exemple #4
0
exception_t
handleSyscall(syscall_t syscall)
{
    exception_t ret;
    irq_t irq;

//printf("\n=====In handleSyscall funtion======\n");
//printf("syscall num is %d\n", syscall);
//printf("caller is %d of domain %d\n", ksCurThread->tcbPriority, ksCurThread->tcbDomain);

    switch (syscall) {
    case SysSend:
        ret = handleInvocation(false, true);
        if (unlikely(ret != EXCEPTION_NONE)) {
            irq = getActiveIRQ();
            if (irq != irqInvalid) {
                handleInterrupt(irq);
            }
        }
        break;

    case SysNBSend:
        ret = handleInvocation(false, false);
        if (unlikely(ret != EXCEPTION_NONE)) {
            irq = getActiveIRQ();
            if (irq != irqInvalid) {
                handleInterrupt(irq);
            }
        }
        break;

    case SysCall:
        ret = handleInvocation(true, true);
        if (unlikely(ret != EXCEPTION_NONE)) {
            irq = getActiveIRQ();
            if (irq != irqInvalid) {
                handleInterrupt(irq);
            }
        }
        break;

    case SysWait:
//printf("will call handleWait\n");
        handleWait(true);
        break;

    case SysReply:
        handleReply();
        break;

    case SysReplyWait:
        handleReply();
        handleWait(true);
        break;

    case SysPoll:
        handleWait(false);
        break;

    case SysYield:
        handleYield();
        break;

    default:
        fail("Invalid syscall");
    }

    schedule();
    activateThread();

    return EXCEPTION_NONE;
}
Exemple #5
0
/**
 * \see trafficlight.h
 */
void runTrafficLight() 
{
	/* initial state */
	enum Event event = NO_EVENT;
	enum State state = RED;
	toggleLight(RED_LIGHT, ON);

	timer(RED_TIME, STANDBY);
	
	/* state machine loop */
	while (1) 
	{
		event = checkEvent(); // check if an event has been triggered

		switch (event) 
		{
			case STANDBY:
				if (state == RED) 
				{
					state = RED_YELLOW;
					handleStandby();			
				}
				break;
			case GO:
				if (state == RED_YELLOW) 
				{
					state = GREEN;
					handleGo();						            
				}
				break;
			case PREPARE_TO_STOP:
				if (state == GREEN) 
				{
					state = GREEN_BLINKING;
					handlePrepareToStop();
				}
				break;
			case REPEAT:
				if (state == GREEN_BLINKING) 
				{
					handleRepeatGreen();
				}
				else if (state == YELLOW_BLINKING) 
				{
					handleRepeatYellow();
				}
				break;
			case STOP:
				if (state == GREEN_BLINKING) 
				{
					state = YELLOW;
					handleStop();
				}
				break;
			case WAIT:
				if (state == YELLOW) 
				{
					state = RED;
					handleWait();
				}
				break;
			case IDLE:
				if (state == RED) 
				{
					state = YELLOW_BLINKING;
					handleIdle();
				}
			case RESET:
				if (state == YELLOW_BLINKING) 
				{
					state = RED;
					handleReset();
				}
				break;
		}
	}
}