/* @(/2/0/2/2) .............................................................*/
QState Philo_hungry(Philo *me, QEvent const *e) {
    switch (e->sig) {
        /* @(/2/0/2/2) */
        case Q_ENTRY_SIG: {
            TableEvt *pe = Q_NEW(TableEvt, HUNGRY_SIG);
            pe->philoNum = PHILO_ID(me);
            QACTIVE_POST(AO_Table, (QEvent const *)pe, me);
            return Q_HANDLED();
        }
        /* @(/2/0/2/2/0) */
        case EAT_SIG: {
            /* @(/2/0/2/2/0/0) */
            if (((TableEvt const *)e)->philoNum == PHILO_ID(me)) {
                BSP_busyDelay();
                return Q_TRAN(&Philo_eating);
            }
            break;
        }
        /* @(/2/0/2/2/1) */
        case TERMINATE_SIG: /* intentionally fall through */
        case DONE_SIG: {
            Q_ERROR();
            return Q_HANDLED();
        }
    }
    return Q_SUPER(&QHsm_top);
}
/* @(/2/0/2/3) .............................................................*/
QState Philo_eating(Philo *me, QEvent const *e) {
    switch (e->sig) {
        /* @(/2/0/2/3) */
        case Q_ENTRY_SIG: {
            QTimeEvt_postIn(&me->timeEvt, &me->super, EAT_TIME);
            return Q_HANDLED();
        }
        /* @(/2/0/2/3) */
        case Q_EXIT_SIG: {
            TableEvt *pe = Q_NEW(TableEvt, DONE_SIG);
            pe->philoNum = PHILO_ID(me);
            QF_PUBLISH((QEvent const *)pe, me);
            return Q_HANDLED();
        }
        /* @(/2/0/2/3/0) */
        case TIMEOUT_SIG: {
            BSP_busyDelay();
            return Q_TRAN(&Philo_thinking);
        }
        /* @(/2/0/2/3/1) */
        case TERMINATE_SIG: /* intentionally fall through */
        case DONE_SIG: {
            Q_ERROR();
            return Q_HANDLED();
        }
        /* @(/2/0/2/3/2) */
        case EAT_SIG: {
            Q_ASSERT(((TableEvt const *)e)->philoNum != PHILO_ID(me));
            return Q_HANDLED();
        }
    }
    return Q_SUPER(&QHsm_top);
}
示例#3
0
/*..........................................................................*/
QState Philo_eating(Philo *me, QEvt const *e) {
    switch (e->sig) {
        case Q_ENTRY_SIG: {
            QTimeEvt_postIn(&me->timeEvt, (QActive *)me, EAT_TIME);
            return Q_HANDLED();
        }
        case Q_EXIT_SIG: {
            TableEvt *pe = Q_NEW(TableEvt, DONE_SIG);
            pe->philoNum = PHILO_ID(me);
            QF_PUBLISH((QEvt *)pe, me);
            return Q_HANDLED();
        }
        case TIMEOUT_SIG: {
            BSP_busyDelay();
            return Q_TRAN(&Philo_thinking);
        }
        case EAT_SIG:                         /* intentionally fall-through */
        case DONE_SIG: {
                      /* EAT or DONE must be for other Philos than this one */
            Q_ASSERT(((TableEvt const *)e)->philoNum != PHILO_ID(me));
            return Q_HANDLED();
        }
    }
    return Q_SUPER(&QHsm_top);
}
/* @(/2/0/2/1) .............................................................*/
QState Philo_thinking(Philo *me, QEvent const *e) {
    switch (e->sig) {
        /* @(/2/0/2/1) */
        case Q_ENTRY_SIG: {
            QTimeEvt_postIn(&me->timeEvt, &me->super, THINK_TIME);
            return Q_HANDLED();
        }
        /* @(/2/0/2/1/0) */
        case TIMEOUT_SIG: {
            BSP_busyDelay();
            return Q_TRAN(&Philo_hungry);
        }
        /* @(/2/0/2/1/1) */
        case TERMINATE_SIG: /* intentionally fall through */
        case DONE_SIG: {
            Q_ERROR();
            return Q_HANDLED();
        }
        /* @(/2/0/2/1/2) */
        case EAT_SIG: {
            Q_ASSERT(((TableEvt const *)e)->philoNum != PHILO_ID(me));
            return Q_HANDLED();
        }
    }
    return Q_SUPER(&QHsm_top);
}
示例#5
0
//............................................................................
QState Philo::eating(Philo *me, QEvt const *e) {
    switch (e->sig) {
        case Q_ENTRY_SIG: {
            me->m_timeEvt.postIn(me, EAT_TIME);
            return Q_HANDLED();
        }
        case Q_EXIT_SIG: {
            TableEvt *pe = Q_NEW(TableEvt, DONE_SIG);
            pe->philoNum = PHILO_ID(me);
            QF::PUBLISH(pe, me);
            return Q_HANDLED();
        }
        case TIMEOUT_SIG: {
            BSP_busyDelay();
            return Q_TRAN(&Philo::thinking);
        }
        case EAT_SIG:                            // intentionally fall-through
        case DONE_SIG: {
                         // EAT or DONE must be for other Philos than this one
            Q_ASSERT(((TableEvt const *)e)->philoNum != PHILO_ID(me));
            return Q_HANDLED();
        }
    }
    return Q_SUPER(&QHsm::top);
}
示例#6
0
/*..........................................................................*/
static void interrupt tmrISR(void) {
    dispPreemptions(TMR_ISR_PRIO);              /* for testing only, NOTE01 */
    QK_ISR_ENTRY();                /* inform QK-nano about entering the ISR */

    QF_tick();                             /* process all armed time events */
    BSP_busyDelay();                                 /* for testing, NOTE02 */

    QK_ISR_EXIT();                  /* inform QK-nano about exiting the ISR */
}
示例#7
0
/*..........................................................................*/
QState Philo_hungry(Philo *me) {
    switch (Q_SIG(me)) {
        case Q_ENTRY_SIG: {
            QActive_post((QActive *)&AO_Table, HUNGRY_SIG, me->super.prio);
            return Q_HANDLED();
        }
        case EAT_SIG: {
            BSP_busyDelay();
            return Q_TRAN(&Philo_eating);
        }
//        case DONE_SIG: {
//            Q_ERROR();      /* thes event should never arrive in this state */
//            return Q_HANDLED();
//        }
    }
    return Q_IGNORED();
}
示例#8
0
/*..........................................................................*/
QState Philo_thinking(Philo *me) {
    switch (Q_SIG(me)) {
        case Q_ENTRY_SIG: {
            QActive_arm((QActive *)me, THINK_TIME);
            return Q_HANDLED();
        }
        case Q_TIMEOUT_SIG: {
            BSP_busyDelay();
            return Q_TRAN(&Philo_hungry);
        }
//        case EAT_SIG:
//        case DONE_SIG: {
//            Q_ERROR();    /* these events should never arrive in this state */
//            return Q_HANDLED();
//        }
    }
    return Q_IGNORED();
}
示例#9
0
/*..........................................................................*/
static void interrupt kbdISR() {
    uint8_t key = inport(0x60);   /* key scan code from 8042 kbd controller */
    uint8_t kcr = inport(0x61);            /* get keyboard control register */

    dispPreemptions(KBD_ISR_PRIO);              /* for testing only, NOTE01 */
    QK_ISR_ENTRY();                /* inform QK-nano about entering the ISR */

    outportb(0x61, (uint8_t)(kcr | 0x80));   /* toggle acknowledge bit high */
    outportb(0x61, kcr);                      /* toggle acknowledge bit low */

    if (key == (uint8_t)129) {                          /* ESC key pressed? */
        QActive_postISR((QActive *)&AO_Table, TERMINATE_SIG, 0);
    }
    Video_printNumAt(60, 12 + 0, VIDEO_FGND_YELLOW, key);/* display the key */

    BSP_busyDelay();                                 /* for testing, NOTE02 */

    QK_ISR_EXIT();                  /* inform QK-nano about exiting the ISR */
}
示例#10
0
/*..........................................................................*/
QState Philo_eating(Philo *me) {
    switch (Q_SIG(me)) {
        case Q_ENTRY_SIG: {
            QActive_arm((QActive *)me, EAT_TIME);
            return Q_HANDLED();
        }
        case Q_EXIT_SIG: {
            BSP_busyDelay();
            QActive_post((QActive *)&AO_Table, DONE_SIG, me->super.prio);
            return Q_HANDLED();
        }
        case Q_TIMEOUT_SIG: {
            return Q_TRAN(&Philo_thinking);
        }
        case EAT_SIG:
        case DONE_SIG: {
            Q_ERROR();    /* these events should never arrive in this state */
        }
    }
    return Q_SUPER(&QHsm_top);
}
示例#11
0
/*..........................................................................*/
QState Philo_hungry(Philo *me, QEvt const *e) {
    switch (e->sig) {
        case Q_ENTRY_SIG: {
            TableEvt *pe = Q_NEW(TableEvt, HUNGRY_SIG);
            pe->philoNum = PHILO_ID(me);
            QACTIVE_POST(AO_Table, (QEvt *)pe, me);
            return Q_HANDLED();
        }
        case EAT_SIG: {
            if (((TableEvt const *)e)->philoNum == PHILO_ID(me)) {
                BSP_busyDelay();
                return Q_TRAN(&Philo_eating);
            }
            break;
        }
        case DONE_SIG: {
                             /* DONE must be for other Philos than this one */
            Q_ASSERT(((TableEvt const *)e)->philoNum != PHILO_ID(me));
            return Q_HANDLED();
        }
    }
    return Q_SUPER(&QHsm_top);
}