Advertisement
EdizonTN

Untitled

Oct 26th, 2020
1,808
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.20 KB | None | 0 0
  1. // ------------------------------------------------------------------------------------------------------
  2. // CTimer(Num) Enable/disable
  3. // result is true:successfull otherwise false
  4. bool _Chip_Timer_Enable(void *pPeri, uint32_t ChannelBitMask, bool NewState)
  5. {
  6.     //bool res = false;
  7.     int32_t PeriIndex = _Chip_CTimer_Get_PeriIndex(pPeri);
  8.    
  9.     // Check:
  10.     SYS_ASSERT( pPeri != NULL);                                                     // check
  11.  
  12.     if(NewState == true)   
  13.     {
  14.         NVIC_ClearPendingIRQ((IRQn_Type) CTIM_IRQ[PeriIndex]);                      // Clear pending NVIC interrupt flag
  15.         NVIC_EnableIRQ(((IRQn_Type) CTIM_IRQ[PeriIndex]));                          // Enable NVIC interrupt
  16.        
  17.         ((_CHIP_CTIMER_T*)pPeri)->TCR &= ~(1 << 1);                                 // Clear reset counter
  18.         ((_CHIP_CTIMER_T*)pPeri)->TCR |= (1 << 0);                                  // Run Timer - must be after clear reset bit !!!!!!!!!!!
  19.     }
  20.     else
  21.     {
  22.         // ToDo: check active channel. If nothing active stop timer and disable complette:
  23.         ((_CHIP_CTIMER_T*)pPeri)->TCR &= ~(1 << 0);                                 // Stop Timer
  24.         ((_CHIP_CTIMER_T*)pPeri)->TCR &= ~(1 << 1);                                 // Clear reset counter     
  25.         NVIC_DisableIRQ((IRQn_Type) (CTIM_IRQ[PeriIndex]));                         // Disable NVIC interrupt
  26.     }
  27.  
  28.     return(true);                                                                   // nothing to check. return Seccess
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement