/* 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 */
/* * ======== 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); }
/* * ======== Clock_wakeup ======== */ Void Clock_wakeup() { unsigned short sr = _get_interrupt_state(); _disable_interrupts(); Clock_TIMER->CCTL[0] |= CCIFG; _set_interrupt_state(sr); }
/* 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 */
/* * ======== 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); }
/* * ======== 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); } }