示例#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
//*****************************************************************************
//
// 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)
    {
    }
}