00001
00034 #ifndef __SILICON_LABS_EM_PCNT_H_
00035 #define __SILICON_LABS_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
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
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_PRSCH4 )
00124 pcntPRSCh4 = 4,
00125 #endif
00126 #if defined( PCNT_INPUT_S0PRSSEL_PRSCH5 )
00127 pcntPRSCh5 = 5,
00128 #endif
00129 #if defined( PCNT_INPUT_S0PRSSEL_PRSCH6 )
00130 pcntPRSCh6 = 6,
00131 #endif
00132 #if defined( PCNT_INPUT_S0PRSSEL_PRSCH7 )
00133 pcntPRSCh7 = 7,
00134 #endif
00135 #if defined( PCNT_INPUT_S0PRSSEL_PRSCH8 )
00136 pcntPRSCh8 = 8,
00137 #endif
00138 #if defined( PCNT_INPUT_S0PRSSEL_PRSCH9 )
00139 pcntPRSCh9 = 9,
00140 #endif
00141 #if defined( PCNT_INPUT_S0PRSSEL_PRSCH10 )
00142 pcntPRSCh10 = 10,
00143 #endif
00144 #if defined( PCNT_INPUT_S0PRSSEL_PRSCH11 )
00145 pcntPRSCh11 = 11
00146 #endif
00147 } PCNT_PRSSel_TypeDef;
00148
00149
00151 typedef enum
00152 {
00153 pcntPRSInputS0 = 0,
00154 pcntPRSInputS1 = 1
00155 } PCNT_PRSInput_TypeDef;
00156 #endif
00157
00158
00159
00160
00161
00162
00164 typedef struct
00165 {
00167 PCNT_Mode_TypeDef mode;
00168
00173 uint32_t counter;
00174
00179 uint32_t top;
00180
00185 bool negEdge;
00186
00189 bool countDown;
00190
00192 bool filter;
00193
00194 #if defined( PCNT_CTRL_HYST )
00195
00197 bool hyst;
00198
00203 bool s1CntDir;
00204
00207 PCNT_CntEvent_TypeDef cntEvent;
00208
00211 PCNT_CntEvent_TypeDef auxCntEvent;
00212
00214 PCNT_PRSSel_TypeDef s0PRS;
00215
00217 PCNT_PRSSel_TypeDef s1PRS;
00218 #endif
00219 } PCNT_Init_TypeDef;
00220
00221 #if !defined ( PCNT_CTRL_HYST )
00222
00223 #define PCNT_INIT_DEFAULT \
00224 { pcntModeDisable, \
00225 _PCNT_CNT_RESETVALUE, \
00226 _PCNT_TOP_RESETVALUE, \
00227 false, \
00228 false, \
00229 false \
00230 }
00231 #else
00232
00233 #define PCNT_INIT_DEFAULT \
00234 { pcntModeDisable, \
00235 _PCNT_CNT_RESETVALUE, \
00236 _PCNT_TOP_RESETVALUE, \
00237 false, \
00238 false, \
00239 false, \
00240 false, \
00241 true, \
00242 pcntCntEventUp, \
00243 pcntCntEventNone, \
00244 pcntPRSCh0, \
00245 pcntPRSCh0 \
00246 }
00247 #endif
00248
00249
00250
00251
00252
00253
00254
00264 __STATIC_INLINE uint32_t PCNT_CounterGet(PCNT_TypeDef *pcnt)
00265 {
00266 return pcnt->CNT;
00267 }
00268
00269
00270 #if defined( _PCNT_AUXCNT_MASK )
00271
00281 __STATIC_INLINE uint32_t PCNT_AuxCounterGet(PCNT_TypeDef *pcnt)
00282 {
00283 return pcnt->AUXCNT;
00284 }
00285 #endif
00286
00287
00288 void PCNT_CounterReset(PCNT_TypeDef *pcnt);
00289 void PCNT_CounterTopSet(PCNT_TypeDef *pcnt, uint32_t count, uint32_t top);
00290
00291
00292
00313 __STATIC_INLINE void PCNT_CounterSet(PCNT_TypeDef *pcnt, uint32_t count)
00314 {
00315 PCNT_CounterTopSet(pcnt, count, pcnt->TOP);
00316 }
00317
00318
00319 void PCNT_Enable(PCNT_TypeDef *pcnt, PCNT_Mode_TypeDef mode);
00320 void PCNT_FreezeEnable(PCNT_TypeDef *pcnt, bool enable);
00321 void PCNT_Init(PCNT_TypeDef *pcnt, const PCNT_Init_TypeDef *init);
00322
00323 #if defined( _PCNT_INPUT_MASK )
00324 void PCNT_PRSInputEnable(PCNT_TypeDef *pcnt,
00325 PCNT_PRSInput_TypeDef prsInput,
00326 bool enable);
00327 #endif
00328
00329
00330
00341 __STATIC_INLINE void PCNT_IntClear(PCNT_TypeDef *pcnt, uint32_t flags)
00342 {
00343 pcnt->IFC = flags;
00344 }
00345
00346
00347
00358 __STATIC_INLINE void PCNT_IntDisable(PCNT_TypeDef *pcnt, uint32_t flags)
00359 {
00360 pcnt->IEN &= ~(flags);
00361 }
00362
00363
00364
00380 __STATIC_INLINE void PCNT_IntEnable(PCNT_TypeDef *pcnt, uint32_t flags)
00381 {
00382 pcnt->IEN |= flags;
00383 }
00384
00385
00386
00400 __STATIC_INLINE uint32_t PCNT_IntGet(PCNT_TypeDef *pcnt)
00401 {
00402 return pcnt->IF;
00403 }
00404
00405
00406
00427 __STATIC_INLINE uint32_t PCNT_IntGetEnabled(PCNT_TypeDef *pcnt)
00428 {
00429 uint32_t tmp = 0U;
00430
00431
00432
00433
00434 tmp = pcnt->IEN;
00435
00436
00437 return pcnt->IF & tmp;
00438 }
00439
00440
00441
00452 __STATIC_INLINE void PCNT_IntSet(PCNT_TypeDef *pcnt, uint32_t flags)
00453 {
00454 pcnt->IFS = flags;
00455 }
00456
00457 void PCNT_Reset(PCNT_TypeDef *pcnt);
00458
00459
00460
00470 __STATIC_INLINE uint32_t PCNT_TopBufferGet(PCNT_TypeDef *pcnt)
00471 {
00472 return pcnt->TOPB;
00473 }
00474
00475 void PCNT_TopBufferSet(PCNT_TypeDef *pcnt, uint32_t val);
00476
00477
00487 __STATIC_INLINE uint32_t PCNT_TopGet(PCNT_TypeDef *pcnt)
00488 {
00489 return pcnt->TOP;
00490 }
00491
00492 void PCNT_TopSet(PCNT_TypeDef *pcnt, uint32_t val);
00493
00494
00498 #ifdef __cplusplus
00499 }
00500 #endif
00501
00502 #endif
00503 #endif