Пример #1
0
void ItcInit(void)
{
  ITC_Init();
  IntDisableAll();
  
  IntAssignHandler(gMacaInt_c, (IntHandlerFunc_t)MACA_Interrupt);
  ITC_SetPriority(gMacaInt_c, gItcNormalPriority_c);
  ITC_EnableInterrupt(gMacaInt_c);
  IntAssignHandler(gTmrInt_c, (IntHandlerFunc_t)/*TmrIsr*/TMR_Interrupt);
  ITC_SetPriority(gTmrInt_c, gItcNormalPriority_c);
  ITC_EnableInterrupt(gTmrInt_c);
}
Пример #2
0
/* Enable or disable the timer tmrID
   If enable = TRUE timer is active
   Else timer is inactive 
*/
void TMR_EnableTimer(tmrTimerID_t tmrID)
{    
  unsigned int saveInt;
  saveInt = IntDisableAll();
  if (TMR_GetTimerStatus(tmrID) == mTmrStatusInactive_c)
  {      
    IncrementActiveTimerNumber(TMR_GetTimerType(tmrID));    
    TMR_SetTimerStatus(tmrID, mTmrStatusReady_c);
    TS_SendEvent(mTimerTaskID, mTMR_Event_c);
  }  
 IntRestoreAll(saveInt);
}
Пример #3
0
/* Stop a timer. Does not free the timer; does not call the timer's callback
* function.
*
* Harmless if the timer is already inactive.
*/
void TMR_StopTimer
(
tmrTimerID_t timerID
)
{
  tmrStatus_t status;
  unsigned int saveInt;
  saveInt = IntDisableAll();
  status = TMR_GetTimerStatus(timerID);
  if (   status == mTmrStatusActive_c
      || status == mTmrStatusReady_c) {
        TMR_SetTimerStatus(timerID, mTmrStatusInactive_c);
        DecrementActiveTimerNumber(TMR_GetTimerType(timerID));
        /* if no sw active timers are enabled, */
        /* call the TMR_Task() to countdown the ticks and stop the hw timer*/
    		if (!numberOfActiveTimers && !numberOfLowPowerActiveTimers) 
           TS_SendEvent(mTimerTaskID, mTMR_Event_c);
      }
  IntRestoreAll(saveInt);    
}                                       /* TMR_StopTimer() */
Пример #4
0
void Main(void)
 {
  InterruptInit();
  IntDisableAll();
  Platform_Init();
  

  TS_Init();                            /* Init the kernel. */
  TMR_Init();                           /* Init the TMR module */							
  NvModuleInit();
  Uart_ModuleInit();
  /* This only creates the MAC TS thread. */
  MacInit();
  /* Use TS for MAC  - the MAC TS ID must be known at this step. */
  Init_802_15_4(TRUE);

  #if gZtcIncluded_d
  Ztc_TaskInit();
  #endif /* gZtcIncluded_d */ 

  /*initialize the application*/ 
  gAppTaskID_c = TS_CreateTask(gTsAppTaskPriority_c, AppTask);
 
  MApp_init();
  #if (gLpmIncluded_d == 1)
    /*do not allow the device to enter sleep mode*/
    PWR_DisallowDeviceToSleep();
  #endif /* gLpmIncluded_d == 1 */
 
  /*All LED's are switched OFF*/
  Led1Off();
  Led2Off();
  Led3Off();
  Led4Off();
  
  /* Start the task scheduler. Does not return. */
  TS_Scheduler(); 
 
}
Пример #5
0
void InitDevice(void)
{
    IntDisableAll();
    WDT_INIT();
    Digitals_Init();  
    ItcInit();
    NVM_FlashInit();
    CRM_Init();  
    TMR_Init();
    ASM_Init();
    UART1_Init();
    UART2_Init();
    SPI_Init();
    MACA_Init(); 
    
///    DMAP_ResetStack(0);
  // WirelessHART Stack Initialisation
    NVM_ReadRecords(); // persistent data reading
    APP_Init();
    DLL_Init();   // reset the modem inside
    TL_Init();
    NET_Init();
    HART_DLL_Init(HART_ROLE_DECIDED);
  
  #if ( SHT1X_MODE != 0 )
    SHT1x_INIT();
  #endif
 
  #if ( (BOARD_TYPE == BOARD_TYPE_HART_DEV_KIT) )
    #if (!defined (IS_VN220))
      ADC_Extern_Init();
    #endif
  #endif
    
    IntEnableAll(); 
}    
Пример #6
0
///////////////////////////////////////////////////////////////////////////////////
// Name: MAIN Function
///////////////////////////////////////////////////////////////////////////////////
  void main(void)
  {
    IntDisableAll();
  
    WDT_INIT();  
             
    Digitals_Init();
   
    ItcInit();
    
    NVM_FlashInit();
    
    CRM_Init();  
        
    TMR_Init();
    ASM_Init();
    UART1_Init();
    UART2_Init();
    SPI_Init();
    
    PROVISION_Init();
        
    MACA_Init(); 
    
    DAQ_Init();
        
    DMAP_ResetStack(0);
    
    IntEnableAll();
    
    //--------------------------------------------------------------------
    // Main Loop
    //--------------------------------------------------------------------
    for (;;)
    {           
        NLDE_Task();        // as fast as possible, keep this task first on loop
  
        DMAP_Task();        //
        ASLDE_ASLTask();    //
 
        UART_LINK_Task();   //
        UART2_CommControl();
        
        DAQ_RxHandler();
        
        if( g_uc250msFlag ) // 250ms Tasks
        {
            g_uc250msFlag = 0;
            
            // Handle DAQ after all other stack related tasks.
            DAQ_TxHandler();            
            UAP_MainTask();     
            
            ARMO_Task();
            
            if( !g_stTAI.m_uc250msStep ) // first 250ms slot from each second -> 1sec Tasks
            {
                ASLDE_PerformOneSecondOperations();
                DMAP_DMO_CheckNewDevInfoTTL();
    
                DMAP_CheckSecondCounter();
                
                ARMO_OneSecondTask();
    
                SLME_KeyUpdateTask();
                
                DMO_PerformOneSecondTasks();  
                
                MACA_WachDog();
            }
        }

        FEED_WDT();
    }
  }
Пример #7
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() */