Beispiel #1
0
void TMR_StartTimer
(
tmrTimerID_t timerID,                       /* IN: */
tmrTimerType_t timerType,                   /* IN: */
tmrTimeInMilliseconds_t timeInMilliseconds, /* IN: */
void (*pfTimerCallBack)(tmrTimerID_t)       /* IN: */
)
{
  tmrTimerTicks32_t intervalInTicks;
  
  /* Stopping an already stopped timer is harmless. */
  TMR_StopTimer(timerID);
  
  intervalInTicks = TmrTicksFromMilliseconds(timeInMilliseconds);
  if (!intervalInTicks) {
    intervalInTicks = 1;
  }
  
  TMR_SetTimerType(timerID, timerType);
  maTmrTimerTable[timerID].intervalInTicks = intervalInTicks;
  maTmrTimerTable[timerID].remainingTicks = intervalInTicks;
  maTmrTimerTable[timerID].pfCallBack = pfTimerCallBack;
 
  /* Enable timer, the timer task will do the rest of the work. */
  TMR_EnableTimer(timerID);
}                                       /* TMR_StartTimer() */
Beispiel #2
0
/******************************************************************************
* Keyboard Enable/Disable key scanning timer. 
* Used for Low Power mode
*
* Parameters:
*   bool_t enable: TRUE  - The Key Scan is enabled
*                  FALSE - The Key Scan is disabled
******************************************************************************/
void KBD_EnableDisableKeyScan(bool_t enable)
{

 if(mKeyScanTimerID != gTmrInvalidTimerID_c)
 {  
  if(enable == TRUE) 
  {     
    TMR_EnableTimer(mKeyScanTimerID);   
  }
  else
  {
    if(CRM_WU_CNTL.extWuIEn  == gSWITCH_MASK_c)
    {
     /* disable scan timer here only if the KBD interrupts are all enabled.
      * With this timer disabled, the low power mode can be enetered. 
      * with the KBD interrupts disabled, the callback won't be called at the exist from low power
      */
     TMR_StopTimer(mKeyScanTimerID);
    }
  }
 }
 #if (gJoystickSupported_d == TRUE) 
  mPollTimerState = enable;
 #endif 
}
Beispiel #3
0
/* Free any timer. Harmless if the timer is already free. */
void TMR_FreeTimer
(
tmrTimerID_t timerID
)
{
  TMR_StopTimer(timerID);
  TMR_MarkTimerFree(timerID);
}                                       /* TMR_FreeTimer() */
Beispiel #4
0
/******************************************************************************
* LED_ExitSerialFlash
*
* Stop serial flashing mode. Leaves all LEDs off. Only exits if actually in 
* serial mode.
*******************************************************************************/
void LED_ExitSerialFlash(void)
{
  if(mfLedInSerialMode) 
  {
    mLedFlashingLEDs = 0;   /* no LEDs are currently flashing */
    LED_TurnOffAllLeds();
    TMR_StopTimer(mLEDTimerID);
    mfLedInSerialMode = FALSE;
  }
}
Beispiel #5
0
/******************************************************************************
* LED_StopFlash
*
* Stop an LED from flashing.
******************************************************************************/
void LED_StopFlash
  (
  LED_t LEDNr /* IN: LED Number. */
  )
{
  /* leave stopped LEDs in the off state */
  LED_TurnOffLed(LEDNr);

  /* stop flashing on one or more LEDs */
  mLedFlashingLEDs &= (~LEDNr);

  /* if ALL LEDs have stopped flashing, then stop timer */
  if(!mLedFlashingLEDs)
    TMR_StopTimer(mLEDTimerID);
}
Beispiel #6
0
/******************************************************************************
* LED_DecrementBlip
*
* Decrements the blink count.
******************************************************************************/
static void LED_DecrementBlip(void)
{
  uint8_t iLedIndex;

  for(iLedIndex = 0; iLedIndex < 4; ++iLedIndex) 
  {
    if(mLedBlips[iLedIndex]) 
    {
      --mLedBlips[iLedIndex];
      if(!mLedBlips[iLedIndex])
        mLedFlashingLEDs &= ~(1 << iLedIndex);
    }
  }

  /* done, stop the timer */
  if(!mLedFlashingLEDs)
    TMR_StopTimer(mLEDTimerID);
}
Beispiel #7
0
/******************************************************************************
* Called when a key is pressed. Determines when the key is up (lifted).
******************************************************************************/
static void KeyScan
(
uint8_t timerId
)
{
  uint8_t nowScan;
  uint8_t keyBase = 0;
  uint8_t changedScan;
  
  /* Detect the center key from joystick */
#if gJoystickSupported_d
  uint8_t centerKeyDetect;
  static uint8_t markLongPress = FALSE;
  /* Detect if a long or short press is done  */
  centerKeyDetect = mNoKey_c; 
  if( 0 == KbReadCenterKey() ) 
  {
    /*key is pressed*/
    if(mLongCenterKeyCount > gLongKeyIterations_c) 
    {   
      /*Is marked as being pressed?*/
      if(!markLongPress)
      {
        /*long keypress*/
        #if gMapJoystickCenterKeyOnSW2
         centerKeyDetect = gKBD_EventLongSW2_c;
        #else
         centerKeyDetect = gJoystick_CenterKeyLong_c;
        #endif
        /*mark the key as being press to send only an event to call back*/
        markLongPress =TRUE;
      }
    }
    else
    {
      mLongCenterKeyCount++;
    }
  }
  /*the key is not pressed*/
  else 
  { 
    /*It was a short key?*/ 
    if ((0 < mLongCenterKeyCount)&& 
        (mLongCenterKeyCount < gLongKeyIterations_c))
    {
      /* short keypress */
      #if gMapJoystickCenterKeyOnSW2
       centerKeyDetect = gKBD_EventSW2_c;
      #else
       centerKeyDetect = gJoystick_CenterKey_c;
      #endif
    }
    mLongCenterKeyCount = 0;  
    /*mark as not being pressed*/  
    markLongPress =FALSE;
  }
  /*Send the detected event*/  
  if( centerKeyDetect != mNoKey_c )
  {
    mpfKeyFunction(centerKeyDetect);
  }
#endif /* gJoystickSupported_d */
  
  /*Detect if a key is pressed or released;
  Every key that is pressed is marked (when is relesed is unmarked)*/
  switch(mKeyState) {
    
    /* got a fresh key */
  case mStateKeyIdle:
    /* Check if a fresh key is pressed and treat it (some keys can still be pressed) */
    mSwitch_SCAN = KeySwitchPortGet() & (~mKeysStillPressed);
    if ( mSwitch_SCAN )
    {   
      mKeyState = mStateKeyDetected;
      mLongKeyCount = 0;  /* assume no key */
    }
    else
    {
      /* No fresh key is pressed */
      /*check if one or more keys was released and unmark those (update mKeysStillPressed) */
      mKeyState = mStateKeyCheckRelease;
    }
    break;
    
    /* A fresh key was detected. Has the key been released or is it still being pressed? */
  case mStateKeyDetected:
    nowScan = KeySwitchPortGet()& (~mKeysStillPressed);
    if( nowScan & mSwitch_SCAN ) {
      mLongKeyCount++;
      
      if(mLongKeyCount >= gLongKeyIterations_c) {
        /*long keypress*/ 
        keyBase = gKBD_EventLongSW1_c;
      }
      
    }
    else {
      /* short keypress */
      keyBase = gKBD_EventSW1_c;
    }
    
    if(keyBase) {
      
      /* does it match a key?; mark it as being pressed */
      if(mSwitch_SCAN & gSWITCH1_MASK_c)
      {
        mKeysStillPressed |= mSwitch_SCAN;
        mpfKeyFunction(keyBase + 0);
      }
      if(mSwitch_SCAN & gSWITCH2_MASK_c)
      {
        mKeysStillPressed |= mSwitch_SCAN;
        mpfKeyFunction(keyBase + 1);
      }
      if(mSwitch_SCAN & gSWITCH3_MASK_c)
      {
        mKeysStillPressed |= mSwitch_SCAN;
        mpfKeyFunction(keyBase + 2);
      }
      if(mSwitch_SCAN & gSWITCH4_MASK_c)
      {
        mKeysStillPressed |= mSwitch_SCAN;
        mpfKeyFunction(keyBase + 3);
      }
      
      /* go and check if it was released  */
      mKeyState = mStateKeyCheckRelease;
    }
    
    break;
    
    /* check if one and more key was released;
    only the keys marked as released are treated for next time*/
  case mStateKeyCheckRelease:
    /*No key are pressed, so stop the timer*/ 
    if ( !mKeysStillPressed )
    {      
      /* Don't stop the timer for joystick to 
      detect the center key that doesn't has external interrupt capability*/            
#if (gJoystickSupported_d == FALSE)
      TMR_StopTimer(timerId);
#else
      if(mPollTimerState == FALSE)
      {
       /* Stop timer if it was requested */ 
       TMR_StopTimer(timerId);
      }      
#endif /* gJoystickSupported_d */
      
    }
    
    else
    { 
      
      /* Check if one or more keys was released and notify this; only keys that are not 
      still pressed are treated for next time*/
      nowScan = KeySwitchPortGet();
      changedScan = (nowScan & mKeysStillPressed)^mKeysStillPressed;
      if(changedScan) { 
        mKeysStillPressed &=~changedScan;
      }
    }
    /*Enable all interrupt but only the released (unmarked) keys will be treated*/
    KbEnableAllIrq();
    
    break;
  default:
    
    break;
  }
}
Beispiel #8
0
/*****************************************************************************
* Timer task. Called by the kernel when the timer ISR posts a timer event.
******************************************************************************/
void TMR_Task
(
event_t events
)
{
  static bool_t timerHardwareIsRunning = FALSE;
  tmrTimerTicks16_t nextInterruptTime;
  pfTmrCallBack_t pfCallBack;
  tmrTimerTicks16_t currentTimeInTicks;
  tmrTimerStatus_t status;
  tmrTimerTicks16_t ticksSinceLastHere, ticksdiff; 
  uint8_t timerID;
  unsigned int saveInt;
  tmrTimerType_t timerType;
  (void)events;
  
  TmrReadValue(gTmrNumber_d,&currentTimeInTicks);
  /* calculate difference between current and previous.  */
  ticksSinceLastHere = (currentTimeInTicks - previousTimeInTicks);
  /* remember for next time */
  previousTimeInTicks = currentTimeInTicks;
  
  for (timerID = 0; timerID < NumberOfElements(maTmrTimerTable); ++timerID) {
    saveInt = IntDisableAll();
    status = TMR_GetTimerStatus(timerID);
    /* If TMR_StartTimer() has been called for this timer, start it's count */
    /* down as of now. */
    if (status == mTmrStatusReady_c) {
      TMR_SetTimerStatus(timerID, mTmrStatusActive_c);
      IntRestoreAll(saveInt);
      continue;
    }
    IntRestoreAll(saveInt);
    
    /* Ignore any timer that is not active. */
    if (status != mTmrStatusActive_c) {
      continue;
    }
    
    /* This timer is active. Decrement it's countdown.. */
    if (maTmrTimerTable[timerID].remainingTicks > ticksSinceLastHere) {
      maTmrTimerTable[timerID].remainingTicks -= ticksSinceLastHere;
      continue;
    }
    
    timerType = TMR_GetTimerType(timerID);
    /* If this is an interval timer, restart it. Otherwise, mark it as inactive. */
    if ( (timerType & gTmrSingleShotTimer_c) ||
         (timerType & gTmrSetMinuteTimer_c) ||
         (timerType & gTmrSetSecondTimer_c)  ) {
      TMR_StopTimer(timerID);
    } else {
      maTmrTimerTable[timerID].remainingTicks = maTmrTimerTable[timerID].intervalInTicks;
    }
    /* This timer has expired. */
    pfCallBack = maTmrTimerTable[timerID].pfCallBack;
    /*Call callback if it is not NULL
    This is done after the timer got updated,
    in case the timer gets stopped or restarted in the callback*/
    if (pfCallBack) {
      pfCallBack(timerID);
    }
    
  }  /* for (timerID = 0; timerID < ... */
  
  /* Find the shortest active timer. */
  nextInterruptTime = mMaxToCountDown_c;
  for (timerID = 0; timerID < NumberOfElements(maTmrTimerTable); ++timerID) {
    if (TMR_GetTimerStatus(timerID) == mTmrStatusActive_c) {
      if (nextInterruptTime > maTmrTimerTable[timerID].remainingTicks) {
        nextInterruptTime = maTmrTimerTable[timerID].remainingTicks;
      }
    }
  }
  
  /* Check to be sure that the timer is not programmed in the past */    
  saveInt = IntDisableAll();
  TmrReadValue(gTmrNumber_d,&ticksdiff);
  /* Number of ticks to be here */
  ticksdiff = (uint16_t)(ticksdiff - currentTimeInTicks); 
   /* Next ticks to count already expired?? */
  if(ticksdiff >= nextInterruptTime)
  {  
    /* Is assumed that a task has to be executed in 4ms...
       so if the ticks already expired enter in TMR_Task() after 4ms*/
    nextInterruptTime = ticksdiff + mTicksFor4ms;
  } 
  else 
  {
    /* Time reference is 4ms...
       so be sure that won't be loaded in Cmp Reg. less that 4ms in ticks 
    */
     if((nextInterruptTime - ticksdiff) < mTicksFor4ms) 
     {
       nextInterruptTime = ticksdiff + mTicksFor4ms;
     }
  
  }
  /* Update the compare register */
  nextInterruptTime += currentTimeInTicks;
  SetComp1Val(gTmrNumber_d, nextInterruptTime);
  IntRestoreAll(saveInt);
  
  if (!numberOfActiveTimers && !numberOfLowPowerActiveTimers)
  {
    TmrStopTimerHardware();
    timerHardwareIsRunning = FALSE;
  } 
  else 
    if (!timerHardwareIsRunning) 
    {
      TmrStartTimerHardware();
      timerHardwareIsRunning = TRUE;
    }
}                                       /* TMR_Task() */