예제 #1
0
/**
 \brief Schedule the callback to be called in some specified time.

 The delay is expressed relative to the last compare event. It doesn't matter
 how long it took to call this function after the last compare, the timer will
 expire precisely delayTicks after the last one.

 The only possible problem is that it took so long to call this function that
 the delay specified is shorter than the time already elapsed since the last
 compare. In that case, this function triggers the interrupt to fire right away.

 This means that the interrupt may fire a bit off, but this inaccuracy does not
 propagate to subsequent timers.

 \param delayTicks Number of ticks before the timer expired, relative to the
 last compare event.
 */
void bsp_timer_scheduleIn(PORT_TIMER_WIDTH delayTicks) {
	PORT_TIMER_WIDTH newCompareValue, current;
	PORT_TIMER_WIDTH temp_last_compare_value;

	if (!bsp_timer_vars.initiated){
		//as the timer runs forever the first time it is turned on has a weired value
		bsp_timer_vars.last_compare_value=SleepModeTimerCountGet();
		bsp_timer_vars.initiated=true;
	}

	temp_last_compare_value = bsp_timer_vars.last_compare_value;

	newCompareValue = bsp_timer_vars.last_compare_value + delayTicks + 1;
	bsp_timer_vars.last_compare_value = newCompareValue;

	current = SleepModeTimerCountGet();

	if (delayTicks < current - temp_last_compare_value) {

		// we're already too late, schedule the ISR right now manually
		// setting the interrupt flag triggers an interrupt
		bsp_timer_vars.tooclose++;
		bsp_timer_vars.diff=(current - temp_last_compare_value);
		bsp_timer_vars.last_compare_value = current;
		IntPendSet(INT_SMTIM);
	} else {
		// this is the normal case, have timer expire at newCompareValue
		SleepModeTimerCompareSet(newCompareValue);
	}
	//enable interrupt
	IntEnable(INT_SMTIM);
}
예제 #2
0
/**************************************************************************//**
* @brief    Restart 32 kHz timer. Timer interval is set using halTimer32kInit().
*
* @return   None
******************************************************************************/
void halTimer32kRestart(void)
{
    // Set sleep mode timer compare value
    SleepModeTimerCompareSet((SleepModeTimerCountGet()+ulHalTimer32kInterval));

    // Clear pending interrupts
    IntPendClear(INT_SMTIM);
}
예제 #3
0
/**************************************************************************//**
* @brief    Set up sleep mode timer to generate interrupt every \c cycles
*           32768 Hz. Use halTimer32kIntConnect() to connect an ISR to the
*           interrupt and halTimer32kIntEnable() to enable timer interrupts.
*
* @param    cycles      Number of cycles between every timer interrupt.
*
* @return   None
******************************************************************************/
void halTimer32kInit(uint16 cycles)
{
    // Store cycle count
    ulHalTimer32kInterval = cycles;

    // Disable sleep mode timer interrupts
    IntDisable(INT_SMTIM);

    // Set compare value
    SleepModeTimerCompareSet((SleepModeTimerCountGet() + cycles));
}
예제 #4
0
/**************************************************************************//**
* @brief    Timer interrupt service routine. Sets new compare value and
*           executes user's custom ISR if any.
*
* @return   None
******************************************************************************/
static void halTimer32kIsr(void)
{
    // Set new compare value
    SleepModeTimerCompareSet((SleepModeTimerCountGet()+ulHalTimer32kInterval));

    // Run custom ISR
    if(pFptr) {
        (pFptr)();
    }
    // Not necessary to clear interrupt flag
}
예제 #5
0
bool Board::isExpiredTicks(uint32_t futureTicks)
{
    uint32_t currentTicks;
    int32_t remainingTicks;

    // Get the current number of ticks
    currentTicks = SleepModeTimerCountGet();

    // Calculte the number of remaining ticks
    remainingTicks = (int32_t) (futureTicks - currentTicks);

    // Returns true if it has expired
    return (remainingTicks < 0);
}
예제 #6
0
/**
 \brief Return the current value of the timer's counter.

 \returns The current value of the timer's counter.
 */
PORT_TIMER_WIDTH bsp_timer_get_currentValue() {
	return SleepModeTimerCountGet();
}
예제 #7
0
//*****************************************************************************
//
// Configure sleep timer, put system into deep sleep and watch sleep timer 
// interrupt wakeup system again
//
//*****************************************************************************
int
main(void)
{
    uint32_t ui32Val;
  
    //
    // Set the clocking to run directly from the external crystal/oscillator.
    // (no ext 32k osc, no internal osc)
    //
    SysCtrlClockSet(false, false, SYS_CTRL_SYSDIV_32MHZ);

    //
    // Set IO clock to the same as system clock
    //
    SysCtrlIOClockSet(SYS_CTRL_SYSDIV_32MHZ);
   
    //
    // Set up the serial console to use for displaying messages.  This is
    // just for this example program and is not needed for SSI operation.
    //
    InitConsole();
    
    //
    // Display the setup on the console.
    //
    UARTprintf("Sleepmode timer\n");

    //
    // Disable UART0 when in deep sleep
    //
    SysCtrlPeripheralDeepSleepDisable(SYS_CTRL_PERIPH_UART0);
    
    //
    // Let system enter powermode 2 when going to deep sleep
    //
    SysCtrlPowerModeSet(SYS_CTRL_PM_2);

    //
    // Enable the Sleep Timer wakeup
    //
    GPIOIntWakeupEnable(GPIO_IWE_SM_TIMER); 

    //
    // Enable sleep mode interrupt
    //
    IntEnable(INT_SMTIM);
    
    //
    // Set timer to 10000 above current value
    //
    ui32Val = SleepModeTimerCountGet();
    SleepModeTimerCompareSet(ui32Val + 10000);

    //
    // Display the timer value on the console.
    //
    UARTprintf("Timer val = %d\n", ui32Val);
    
    //
    // Wait for UART to be flushed
    //
    while(UARTBusy(UART0_BASE))
    {
    }
    
    //
    // Go to sleep
    //
    SysCtrlDeepSleep();

    //
    // Display the timer value on the console.
    //    
    ui32Val = SleepModeTimerCountGet();
    UARTprintf("Timer val = %d (after wakeup)\n", ui32Val);
    
    //
    // Done - enter an infinite loop.
    //
    while(1)
    {
    }
}
예제 #8
0
uint32_t Board::getCurrentTicks(void)
{
    // Get the current number of ticks
    return SleepModeTimerCountGet();
}