Esempio n. 1
0
void timerInit(uint8_t timer, int freqHz) {
  // Enable interrupts for the timer (but not any of the timer updates yet)
  nvicEnable(TIMER_MAP[timer].IRQn, 2);

  timerInitHelper(timer, 1, TIMER_PERIOD(freqHz));
  TIM_Cmd(TIMER_MAP[timer].TIMx, ENABLE);
}
Esempio n. 2
0
void pinTimerInit(uint8_t pin) {
  uint8_t timer = PIN_MAP[pin].timer;

  nvicEnable(TIMER_MAP[timer].IRQn, 2);
  // Use the frequency set using analogWriteFrequency
  timerInitHelper(timer, 1, TIMER_PERIOD(TIMER_MAP[timer].freqHz));
  TIM_Cmd(TIMER_MAP[timer].TIMx, ENABLE);
  
  // FIXME: Advanced timers need to be specified in variant.cpp
  // isAdvancedTimer() ir something
  // http://www.disca.upv.es/aperles/arm_cortex_m3/curset/STM32F4xx_DSP_StdPeriph_Lib_V1.0.1/html/group___t_i_m___group4.html
#if defined(SERIES_STM32F4xx)
  if (TIMER_MAP[timer].TIMx == TIM1) {
    TIM_CtrlPWMOutputs(TIM1, ENABLE);
  }
#endif
#if defined(SERIES_STM32F30x)
  if (IS_TIM_LIST6_PERIPH(TIMER_MAP[timer].TIMx)) {
    TIM_CtrlPWMOutputs(TIMER_MAP[timer].TIMx, ENABLE);
  }
#endif
}
Esempio n. 3
0
inline uint64_t usec() {
    return (uint64_t)(1000000 * sec)
         + (MSEC_PER_SEC * msec)
         + (TIMER_PERIOD(USR_TIMER_FREQ) - MSS_TIM1_get_current_value()) / 50;
         //  TimVal * TimPeriod (us) / TimReloadVal
}