em_pcnt.h

Go to the documentation of this file.
00001 /***************************************************************************/
00034 #ifndef __EM_PCNT_H
00035 #define __EM_PCNT_H
00036 
00037 #include "em_device.h"
00038 #if defined(PCNT_COUNT) && (PCNT_COUNT > 0)
00039 
00040 #include <stdbool.h>
00041 
00042 #ifdef __cplusplus
00043 extern "C" {
00044 #endif
00045 
00046 /***************************************************************************/
00051 /***************************************************************************/
00056 /*******************************************************************************
00057  *******************************   DEFINES   ***********************************
00058  ******************************************************************************/
00060 #if defined _EFM32_GECKO_FAMILY
00061 #define PCNT0_CNT_SIZE    (8)   
00062 #else
00063 #define PCNT0_CNT_SIZE   (16)   
00064 #endif
00065 #ifdef PCNT1
00066 #define PCNT1_CNT_SIZE    (8)   
00067 #endif
00068 #ifdef PCNT2
00069 #define PCNT2_CNT_SIZE    (8)   
00070 #endif
00071 
00072 
00073 /*******************************************************************************
00074  ********************************   ENUMS   ************************************
00075  ******************************************************************************/
00076 
00078 typedef enum
00079 {
00081   pcntModeDisable   = _PCNT_CTRL_MODE_DISABLE,
00082 
00084   pcntModeOvsSingle = _PCNT_CTRL_MODE_OVSSINGLE,
00085 
00087   pcntModeExtSingle = _PCNT_CTRL_MODE_EXTCLKSINGLE,
00088 
00090   pcntModeExtQuad   = _PCNT_CTRL_MODE_EXTCLKQUAD
00091 } PCNT_Mode_TypeDef;
00092 
00093 
00094 #if defined( _PCNT_CTRL_CNTEV_MASK)
00095 
00098 typedef enum
00099 {
00101   pcntCntEventBoth = _PCNT_CTRL_CNTEV_BOTH,
00102 
00104   pcntCntEventUp   = _PCNT_CTRL_CNTEV_UP,
00105 
00107   pcntCntEventDown = _PCNT_CTRL_CNTEV_DOWN,
00108 
00110   pcntCntEventNone = _PCNT_CTRL_CNTEV_NONE
00111 } PCNT_CntEvent_TypeDef;
00112 #endif
00113 
00114 
00115 #if defined( _PCNT_INPUT_MASK )
00116 
00117 typedef enum
00118 {
00119   pcntPRSCh0 = 0,     
00120   pcntPRSCh1 = 1,     
00121   pcntPRSCh2 = 2,     
00122   pcntPRSCh3 = 3,     
00123 #if defined( PCNT_INPUT_S0PRSSEL_PRSCH7 )
00124   pcntPRSCh4 = 4,     
00125   pcntPRSCh5 = 5,     
00126   pcntPRSCh6 = 6,     
00127   pcntPRSCh7 = 7,     
00128 #endif
00129 #if defined( PCNT_INPUT_S0PRSSEL_PRSCH11 )
00130   pcntPRSCh8 = 8,     
00131   pcntPRSCh9 = 9,     
00132   pcntPRSCh10 = 10,   
00133   pcntPRSCh11 = 11    
00134 #endif
00135 } PCNT_PRSSel_TypeDef;
00136 
00137 
00139 typedef enum
00140 {
00141   pcntPRSInputS0 = 0, 
00142   pcntPRSInputS1 = 1  
00143 } PCNT_PRSInput_TypeDef;
00144 #endif
00145 
00146 
00147 /*******************************************************************************
00148  *******************************   STRUCTS   ***********************************
00149  ******************************************************************************/
00150 
00152 typedef struct
00153 {
00155   PCNT_Mode_TypeDef     mode;
00156 
00161   uint32_t              counter;
00162 
00167   uint32_t              top;
00168 
00173   bool                  negEdge;
00174 
00177   bool                  countDown;
00178 
00180   bool                  filter;
00181 
00182 #if defined( PCNT_CTRL_HYST )
00183 
00185   bool                  hyst;
00186 
00191   bool                  s1CntDir;
00192 
00195   PCNT_CntEvent_TypeDef cntEvent;
00196 
00199   PCNT_CntEvent_TypeDef auxCntEvent;
00200 
00202   PCNT_PRSSel_TypeDef   s0PRS;
00203 
00205   PCNT_PRSSel_TypeDef   s1PRS;
00206 #endif
00207 } PCNT_Init_TypeDef;
00208 
00209 #if defined (_EFM32_GECKO_FAMILY)
00210 
00211 #define PCNT_INIT_DEFAULT                                                           \
00212   { pcntModeDisable,                          /* Disabled by default. */            \
00213     _PCNT_CNT_RESETVALUE,                     /* Default counter HW reset value. */ \
00214     _PCNT_TOP_RESETVALUE,                     /* Default counter HW reset value. */ \
00215     false,                                    /* Use positive edge. */              \
00216     false,                                    /* Up-counting. */                    \
00217     false                                     /* Filter disabled. */                \
00218   }
00219 #else
00220 
00221 #define PCNT_INIT_DEFAULT                                                                        \
00222   { pcntModeDisable,                          /* Disabled by default. */                         \
00223     _PCNT_CNT_RESETVALUE,                     /* Default counter HW reset value. */              \
00224     _PCNT_TOP_RESETVALUE,                     /* Default counter HW reset value. */              \
00225     false,                                    /* Use positive edge. */                           \
00226     false,                                    /* Up-counting. */                                 \
00227     false,                                    /* Filter disabled. */                             \
00228     false,                                    /* Hysteresis disabled. */                         \
00229     true,                                     /* Counter direction is given by CNTDIR. */        \
00230     pcntCntEventUp,                           /* Regular counter counts up on upcount events. */ \
00231     pcntCntEventNone,                         /* Auxiliary counter doesn't respond to events. */ \
00232     pcntPRSCh0,                               /* PRS channel 0 selected as S0IN. */              \
00233     pcntPRSCh0                                /* PRS channel 0 selected as S1IN. */              \
00234   }
00235 #endif
00236 
00237 
00238 /*******************************************************************************
00239  *****************************   PROTOTYPES   **********************************
00240  ******************************************************************************/
00241 
00242 /***************************************************************************/
00252 __STATIC_INLINE uint32_t PCNT_CounterGet(PCNT_TypeDef *pcnt)
00253 {
00254   return pcnt->CNT;
00255 }
00256 
00257 
00258 #if defined( _PCNT_AUXCNT_MASK )
00259 /***************************************************************************/
00269 __STATIC_INLINE uint32_t PCNT_AuxCounterGet(PCNT_TypeDef *pcnt)
00270 {
00271   return pcnt->AUXCNT;
00272 }
00273 #endif
00274 
00275 
00276 void PCNT_CounterReset(PCNT_TypeDef *pcnt);
00277 void PCNT_CounterTopSet(PCNT_TypeDef *pcnt, uint32_t count, uint32_t top);
00278 
00279 
00280 /***************************************************************************/
00301 __STATIC_INLINE void PCNT_CounterSet(PCNT_TypeDef *pcnt, uint32_t count)
00302 {
00303   PCNT_CounterTopSet(pcnt, count, pcnt->TOP);
00304 }
00305 
00306 
00307 void PCNT_Enable(PCNT_TypeDef *pcnt, PCNT_Mode_TypeDef mode);
00308 void PCNT_FreezeEnable(PCNT_TypeDef *pcnt, bool enable);
00309 void PCNT_Init(PCNT_TypeDef *pcnt, const PCNT_Init_TypeDef *init);
00310 
00311 #if defined( _PCNT_INPUT_MASK )
00312 void PCNT_PRSInputEnable(PCNT_TypeDef *pcnt,
00313                          PCNT_PRSInput_TypeDef prsInput,
00314                          bool enable);
00315 #endif
00316 
00317 
00318 /***************************************************************************/
00329 __STATIC_INLINE void PCNT_IntClear(PCNT_TypeDef *pcnt, uint32_t flags)
00330 {
00331   pcnt->IFC = flags;
00332 }
00333 
00334 
00335 /***************************************************************************/
00346 __STATIC_INLINE void PCNT_IntDisable(PCNT_TypeDef *pcnt, uint32_t flags)
00347 {
00348   pcnt->IEN &= ~(flags);
00349 }
00350 
00351 
00352 /***************************************************************************/
00368 __STATIC_INLINE void PCNT_IntEnable(PCNT_TypeDef *pcnt, uint32_t flags)
00369 {
00370   pcnt->IEN |= flags;
00371 }
00372 
00373 
00374 /***************************************************************************/
00388 __STATIC_INLINE uint32_t PCNT_IntGet(PCNT_TypeDef *pcnt)
00389 {
00390   return pcnt->IF;
00391 }
00392 
00393 
00394 /***************************************************************************/
00415 __STATIC_INLINE uint32_t PCNT_IntGetEnabled(PCNT_TypeDef *pcnt)
00416 {
00417   uint32_t tmp = 0U;
00418 
00419 
00420   /* Store pcnt->IEN in temporary variable in order to define explicit order
00421    * of volatile accesses. */
00422   tmp = pcnt->IEN;
00423 
00424   /* Bitwise AND of pending and enabled interrupts */
00425   return pcnt->IF & tmp;
00426 }
00427 
00428 
00429 /***************************************************************************/
00440 __STATIC_INLINE void PCNT_IntSet(PCNT_TypeDef *pcnt, uint32_t flags)
00441 {
00442   pcnt->IFS = flags;
00443 }
00444 
00445 void PCNT_Reset(PCNT_TypeDef *pcnt);
00446 
00447 
00448 /***************************************************************************/
00458 __STATIC_INLINE uint32_t PCNT_TopBufferGet(PCNT_TypeDef *pcnt)
00459 {
00460   return pcnt->TOPB;
00461 }
00462 
00463 void PCNT_TopBufferSet(PCNT_TypeDef *pcnt, uint32_t val);
00464 
00465 /***************************************************************************/
00475 __STATIC_INLINE uint32_t PCNT_TopGet(PCNT_TypeDef *pcnt)
00476 {
00477   return pcnt->TOP;
00478 }
00479 
00480 void PCNT_TopSet(PCNT_TypeDef *pcnt, uint32_t val);
00481 
00482 
00486 #ifdef __cplusplus
00487 }
00488 #endif
00489 
00490 #endif /* defined(PCNT_COUNT) && (PCNT_COUNT > 0) */
00491 #endif /* __EM_PCNT_H */