NinjaFlight
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
timer.c File Reference
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <platform.h>
#include "common/utils.h"
#include "common/atomic.h"
#include "nvic.h"
#include "gpio.h"
#include "system.h"
#include "timer.h"
#include "timer_impl.h"
Include dependency graph for timer.c:

Data Structures

struct  timerConfig_s
 
struct  timerChannelInfo_t
 
struct  timerInfo_t
 

Macros

#define TIM_N(n)   (1 << (n))
 
#define USED_TIMER_COUNT   BITCOUNT(USED_TIMERS)
 
#define CC_CHANNELS_PER_TIMER   4
 
#define TIM_IT_CCx(ch)   (TIM_IT_CC1 << ((ch) / 4))
 
#define TIMER_INDEX(i)   BITCOUNT((TIM_N(i) - 1) & USED_TIMERS)
 
#define _CASE_SHF   10
 
#define _CASE_(tim, index)   case ((unsigned)tim >> _CASE_SHF): return index; break
 
#define _CASE(i)   _CASE_(TIM##i##_BASE, TIMER_INDEX(i))
 
#define _DEF(i)   TIM##i
 
#define _TIM_IRQ_HANDLER2(name, i, j)
 
#define _TIM_IRQ_HANDLER(name, i)
 

Typedefs

typedef struct timerConfig_s timerConfig_t
 

Functions

void configTimeBase (TIM_TypeDef *tim, uint16_t period, uint8_t mhz)
 
void timerConfigure (const timerHardware_t *timerHardwarePtr, uint16_t period, uint8_t mhz)
 
void timerChInit (const timerHardware_t *timHw, channelType_t type, int irqPriority)
 
void timerChCCHandlerInit (timerCCHandlerRec_t *self, timerCCHandlerCallback *fn)
 
void timerChOvrHandlerInit (timerOvrHandlerRec_t *self, timerOvrHandlerCallback *fn)
 
void timerChConfigCallbacks (const timerHardware_t *timHw, timerCCHandlerRec_t *edgeCallback, timerOvrHandlerRec_t *overflowCallback)
 
void timerChConfigCallbacksDual (const timerHardware_t *timHw, timerCCHandlerRec_t *edgeCallbackLo, timerCCHandlerRec_t *edgeCallbackHi, timerOvrHandlerRec_t *overflowCallback)
 
void timerChITConfigDualLo (const timerHardware_t *timHw, FunctionalState newState)
 
void timerChITConfig (const timerHardware_t *timHw, FunctionalState newState)
 
void timerChClearCCFlag (const timerHardware_t *timHw)
 
void timerChConfigGPIO (const timerHardware_t *timHw, GPIO_Mode mode)
 
void timerChConfigIC (const timerHardware_t *timHw, bool polarityRising, unsigned inputFilterTicks)
 
void timerChConfigICDual (const timerHardware_t *timHw, bool polarityRising, unsigned inputFilterTicks)
 
void timerChICPolarity (const timerHardware_t *timHw, bool polarityRising)
 
volatile timCCR_t * timerChCCRHi (const timerHardware_t *timHw)
 
volatile timCCR_t * timerChCCRLo (const timerHardware_t *timHw)
 
volatile timCCR_t * timerChCCR (const timerHardware_t *timHw)
 
void timerChConfigOC (const timerHardware_t *timHw, bool outEnable, bool stateHigh)
 
void timerInit (void)
 
void timerStart (void)
 
void timerForceOverflow (TIM_TypeDef *tim)
 

Variables

timerConfig_t timerConfig [USED_TIMER_COUNT]
 
timerChannelInfo_t timerChannelInfo [USABLE_TIMER_CHANNEL_COUNT]
 
timerInfo_t timerInfo [USED_TIMER_COUNT]
 
TIM_TypeDef *const usedTimers [USED_TIMER_COUNT]
 

Macro Definition Documentation

#define _CASE (   i)    _CASE_(TIM##i##_BASE, TIMER_INDEX(i))
#define _CASE_ (   tim,
  index 
)    case ((unsigned)tim >> _CASE_SHF): return index; break
#define _CASE_SHF   10
#define _DEF (   i)    TIM##i
#define _TIM_IRQ_HANDLER (   name,
 
)
Value:
void name(void); \
void name(void) \
{ \
timCCxHandler(TIM ## i, &timerConfig[TIMER_INDEX(i)]); \
} struct dummy
timerConfig_t timerConfig[USED_TIMER_COUNT]
Definition: timer.c:405
#define TIMER_INDEX(i)
Definition: timer.c:418
#define _TIM_IRQ_HANDLER2 (   name,
  i,
 
)
Value:
void name(void); \
void name(void) \
{ \
timCCxHandler(TIM ## i, &timerConfig[TIMER_INDEX(i)]); \
timCCxHandler(TIM ## j, &timerConfig[TIMER_INDEX(j)]); \
} struct dummy
timerConfig_t timerConfig[USED_TIMER_COUNT]
Definition: timer.c:405
#define TIMER_INDEX(i)
Definition: timer.c:418
#define CC_CHANNELS_PER_TIMER   4
#define TIM_IT_CCx (   ch)    (TIM_IT_CC1 << ((ch) / 4))
#define TIM_N (   n)    (1 << (n))
#define TIMER_INDEX (   i)    BITCOUNT((TIM_N(i) - 1) & USED_TIMERS)
#define USED_TIMER_COUNT   BITCOUNT(USED_TIMERS)

Typedef Documentation

typedef struct timerConfig_s timerConfig_t

Function Documentation

void configTimeBase ( TIM_TypeDef tim,
uint16_t  period,
uint8_t  mhz 
)
void timerChCCHandlerInit ( timerCCHandlerRec_t self,
timerCCHandlerCallback fn 
)
volatile timCCR_t* timerChCCR ( const timerHardware_t timHw)
volatile timCCR_t* timerChCCRHi ( const timerHardware_t timHw)
volatile timCCR_t* timerChCCRLo ( const timerHardware_t timHw)
void timerChClearCCFlag ( const timerHardware_t timHw)
void timerChConfigCallbacks ( const timerHardware_t timHw,
timerCCHandlerRec_t edgeCallback,
timerOvrHandlerRec_t overflowCallback 
)
void timerChConfigCallbacksDual ( const timerHardware_t timHw,
timerCCHandlerRec_t edgeCallbackLo,
timerCCHandlerRec_t edgeCallbackHi,
timerOvrHandlerRec_t overflowCallback 
)
void timerChConfigGPIO ( const timerHardware_t timHw,
GPIO_Mode  mode 
)

Here is the call graph for this function:

void timerChConfigIC ( const timerHardware_t timHw,
bool  polarityRising,
unsigned  inputFilterTicks 
)
void timerChConfigICDual ( const timerHardware_t timHw,
bool  polarityRising,
unsigned  inputFilterTicks 
)
void timerChConfigOC ( const timerHardware_t timHw,
bool  outEnable,
bool  stateHigh 
)
void timerChICPolarity ( const timerHardware_t timHw,
bool  polarityRising 
)
void timerChInit ( const timerHardware_t timHw,
channelType_t  type,
int  irqPriority 
)

Here is the call graph for this function:

void timerChITConfig ( const timerHardware_t timHw,
FunctionalState  newState 
)
void timerChITConfigDualLo ( const timerHardware_t timHw,
FunctionalState  newState 
)
void timerChOvrHandlerInit ( timerOvrHandlerRec_t self,
timerOvrHandlerCallback fn 
)
void timerConfigure ( const timerHardware_t timerHardwarePtr,
uint16_t  period,
uint8_t  mhz 
)

Here is the call graph for this function:

void timerForceOverflow ( TIM_TypeDef tim)

Force an overflow for a given timer. Saves the current value of the counter in the relevant timerConfig's forcedOverflowTimerValue variable.

Parameters
TIM_Typedef*tim The timer to overflow
Returns
void
void timerInit ( void  )

Here is the call graph for this function:

void timerStart ( void  )

Here is the call graph for this function:

Variable Documentation

TIM_TypeDef* const usedTimers[USED_TIMER_COUNT]
Initial value:
= {
#define _DEF(i)
}