Example #1
0
/*
 *  ======== Button_disable ========
 *  Disable the specified buttons 
 */
Void Button_disable(Bits8 mask)
{
    unsigned short sr = _get_interrupt_state();
    _disable_interrupts();

    *(Bits8 *)Button_PORT_IE &= ~mask;

    _set_interrupt_state(sr);
}
Example #2
0
/*
 *  ======== Clock_wakeup ========
 */
Void Clock_wakeup()
{
    unsigned short sr = _get_interrupt_state();
    _disable_interrupts();

    Clock_TIMER->CCTL[0] |= CCIFG;

    _set_interrupt_state(sr);
}
Example #3
0
/* OSINT32_LL: Same as OSUINT32_LL but for signed integers. */
INT32 OSINT32_LL(INT32 *memory)
{
  INT32 tmp;
  UINT16 state;
  state = _get_interrupt_state(); // Save interrupt enable bit value
  _OSLLReserveBit = TRUE;         // Mark reserved
  _disable_interrupts();
  tmp = *memory;                  // Return the contents of the memory location
  _set_interrupt_state(state);    // Restore previous interrupt enable bit value
  return tmp;
} /* end of OSINT32_LL */
Example #4
0
/*
 *  ======== Button_read ========
 *  Atomically read and clear the specified buttons
 */
Bits8 Button_read(Bits8 mask)
{
    Bits8 old;
    
    unsigned short sr = _get_interrupt_state();
    _disable_interrupts();

    old = *(Bits8 *)Button_PORT_IFG;
    *(Bits8 *)Button_PORT_IFG = old & ~mask;

    _set_interrupt_state(sr);

    return (old & mask);
}
Example #5
0
/* OSUINT16_SC: Same as OSUINT8_SC but applied to unsigned 16-bit integers. */
BOOL OSUINT16_SC(UINT16 *memory, UINT16 newValue)
{
  UINT16 state;
  state = _get_interrupt_state(); // Save interrupt enable bit value
  _disable_interrupts();
  if (_OSLLReserveBit) {          // Is the reservation still on?
     _OSLLReserveBit = FALSE;
     *memory = newValue;
     _set_interrupt_state(state); // Restore previous interrupt enable bit value
     return TRUE;
  }
  else {
     _set_interrupt_state(state); // Restore previous interrupt enable bit value
     return FALSE;
  }
} /* end of OSUINT16_SC */
Example #6
0
void Dispatcher::Signal(bool reschedule)
{
    cpu_flags fl = DisableInterrupts();
    ASSERT(!_get_interrupt_state());
    fSignalled = true;
    bool threadsWoken = false;
    for (WaitTag *nextDispatcherBlock = static_cast<WaitTag*>(fTags.GetHead());
            nextDispatcherBlock && fSignalled;) {
        WaitTag *dispatcherBlock = nextDispatcherBlock;
        nextDispatcherBlock = static_cast<WaitTag*>(fTags.GetNext(nextDispatcherBlock));

        // See if this thread's wait condition can be satisfied...
        bool wake = true;
        if (dispatcherBlock->fEvent->fFlags & WAIT_FOR_ALL) {
            for (WaitTag *threadBlock = dispatcherBlock->fEvent->fTags; threadBlock;
                    threadBlock = threadBlock->fEventNext) {
                if (!threadBlock->fDispatcher->fSignalled) {
                    wake = false;
                    break;
                }
            }
        }

        if (wake) {
            for (WaitTag *threadBlock = dispatcherBlock->fEvent->fTags; threadBlock;
                    threadBlock = threadBlock->fEventNext) {
                threadBlock->RemoveFromList();
                if (dispatcherBlock->fEvent->fFlags & WAIT_FOR_ALL)
                    threadBlock->fDispatcher->ThreadWoken();
            }

            if ((dispatcherBlock->fEvent->fFlags & WAIT_FOR_ALL) == 0)
                dispatcherBlock->fDispatcher->ThreadWoken();

            dispatcherBlock->fEvent->CancelTimeout();
            gScheduler.EnqueueReadyThread(dispatcherBlock->fEvent->fThread);
            threadsWoken = true;
        }
    }

    RestoreInterrupts(fl);
    if (reschedule && threadsWoken)
        gScheduler.Reschedule();
}
Example #7
0
/*
 *  ======== Clock_sleep ========
 */
Void Clock_sleep(UInt16 usec, UInt lpm)
{
    unsigned short sr;
    
    /* compute the delay increment in clock ticks */
    unsigned int inc = (Clock_slowClockHz * usec + 500000L) / 1000000;
    if (inc == 0) {
        return;
    }
    
    /* atomically clear interrupt flag and set new compare value */
    sr = _get_interrupt_state();
    _disable_interrupts();
    Clock_TIMER->CCTL[0] &= ~CCIFG;             /* clear the interrupt flag */
    Clock_TIMER->CCR[0] = Clock_TIMER->R + inc; /* set new compare value */
    _set_interrupt_state(sr);

    /* loop until interrupt flag is set */
    while(!(Clock_TIMER->CCTL[0] & CCIFG)) {
        _bis_SR_register(lpm);
    }
}