APM:Libraries
Macros | Functions | Variables
timer.c File Reference

New-style timer interface. More...

#include "timer.h"
#include "dma.h"
#include <string.h>
#include "nvic.h"
Include dependency graph for timer.c:

Go to the source code of this file.

Macros

#define NR_ADV_HANDLERS   8
 
#define NR_GEN_HANDLERS   7
 
#define NR_BAS_HANDLERS   1
 
#define PRIO_DISABLE_FLAG   0x80
 

Functions

static void disable_channel (const timer_dev *dev, uint8_t channel)
 
static void pwm_mode (const timer_dev *dev, uint8_t channel)
 
static void output_compare_mode (const timer_dev *dev, uint8_t channel)
 
static void enable_irq (const timer_dev *dev, uint8_t interrupt, uint8_t priority)
 
void timer_init (const timer_dev *dev)
 
void timer_reset (const timer_dev *dev)
 
void timer_disable (const timer_dev *dev)
 Disable a timer. More...
 
uint32_t configTimeBase (const timer_dev *dev, uint16_t period, uint16_t khz)
 
static void disable_channel (const timer_dev *dev, timer_Channel channel)
 
static void pwm_mode (const timer_dev *dev, timer_Channel channel)
 
static void output_compare_mode (const timer_dev *dev, timer_Channel channel)
 
void timer_set_mode (const timer_dev *dev, timer_Channel channel, timer_mode mode)
 
void timer_foreach (void(*fn)(const timer_dev *))
 Call a function on timer devices. More...
 
void timer_attach_interrupt (const timer_dev *dev, timer_interrupt_id interrupt, Handler handler, uint8_t priority)
 Attach a timer interrupt. More...
 
void timer_attach_all_interrupts (const timer_dev *dev, Handler handler)
 
void timer_detach_interrupt (const timer_dev *dev, timer_interrupt_id interrupt)
 Detach a timer interrupt. More...
 
static void dispatch_adv_brk (const timer_dev *dev)
 
static void dispatch_adv_up (const timer_dev *dev)
 
static void dispatch_adv_trg_com (const timer_dev *dev)
 
static void dispatch_adv_cc (const timer_dev *dev)
 
static void dispatch_general (const timer_dev *dev)
 
static void dispatch_general_h (const timer_dev *dev)
 
static void dispatch_basic (const timer_dev *dev)
 
void TIM1_BRK_TIM9_IRQHandler (void)
 
void TIM1_UP_TIM10_IRQHandler (void)
 
void TIM1_TRG_COM_TIM11_IRQHandler (void)
 
void TIM1_CC_IRQHandler (void)
 
void TIM2_IRQHandler (void)
 
void TIM3_IRQHandler (void)
 
void TIM4_IRQHandler (void)
 
void TIM5_IRQHandler (void)
 
void TIM6_DAC_IRQHandler (void)
 
void TIM7_IRQHandler (void)
 
void TIM8_BRK_TIM12_IRQHandler (void)
 
void TIM8_CC_IRQHandler (void)
 
void TIM8_UP_TIM13_IRQHandler (void)
 
void TIM8_TRG_COM_TIM14_IRQHandler (void)
 
static INLINE void dispatch_single_irq (const timer_dev *dev, timer_interrupt_id iid, uint32_t irq_mask)
 
static INLINE void handle_irq (const timer_dev *dev, uint32_t dier_sr, uint32_t irq_mask, uint32_t iid)
 
static void enable_advanced_irq (const timer_dev *dev, timer_interrupt_id id, uint8_t priority)
 
static void enable_irq (const timer_dev *dev, timer_interrupt_id iid, uint8_t priority)
 
void timer_enable_NVICirq (const timer_dev *dev, uint8_t interrupt, uint8_t priority)
 
void timer_disable_NVICirq (const timer_dev *dev, uint8_t interrupt)
 

Variables

static Handler tim1_handlers [NR_ADV_HANDLERSIN_CCM
 
const timer_dev timers []
 

Detailed Description

New-style timer interface.

Author
Marti Bolivar mboli.nosp@m.var@.nosp@m.leafl.nosp@m.abs..nosp@m.com

Definition in file timer.c.

Macro Definition Documentation

◆ NR_ADV_HANDLERS

#define NR_ADV_HANDLERS   8

Definition at line 51 of file timer.c.

◆ NR_BAS_HANDLERS

#define NR_BAS_HANDLERS   1

Definition at line 55 of file timer.c.

◆ NR_GEN_HANDLERS

#define NR_GEN_HANDLERS   7

Definition at line 53 of file timer.c.

◆ PRIO_DISABLE_FLAG

#define PRIO_DISABLE_FLAG   0x80

Definition at line 779 of file timer.c.

Referenced by enable_advanced_irq(), enable_irq(), and timer_disable_NVICirq().

Function Documentation

◆ configTimeBase()

uint32_t configTimeBase ( const timer_dev dev,
uint16_t  period,
uint16_t  khz 
)

Definition at line 357 of file timer.c.

Referenced by F4Light::RCOutput::_set_output_mode(), F4Light::RCOutput::_set_pin_output_mode(), Soft_I2C::_start(), F4Light::Scheduler::init(), pwmInitializeInput(), and F4Light::GPIO::write().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ disable_channel() [1/2]

static void disable_channel ( const timer_dev dev,
uint8_t  channel 
)
static

Referenced by timer_set_mode().

Here is the caller graph for this function:

◆ disable_channel() [2/2]

static void disable_channel ( const timer_dev dev,
timer_Channel  channel 
)
static

Definition at line 413 of file timer.c.

Here is the call graph for this function:

◆ dispatch_adv_brk()

static void dispatch_adv_brk ( const timer_dev dev)
inlinestatic

Definition at line 652 of file timer.c.

Referenced by TIM1_BRK_TIM9_IRQHandler(), TIM8_BRK_TIM12_IRQHandler(), and timer_detach_interrupt().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ dispatch_adv_cc()

static void dispatch_adv_cc ( const timer_dev dev)
inlinestatic

Definition at line 699 of file timer.c.

Referenced by TIM1_CC_IRQHandler(), TIM8_CC_IRQHandler(), and timer_detach_interrupt().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ dispatch_adv_trg_com()

static void dispatch_adv_trg_com ( const timer_dev dev)
inlinestatic

Definition at line 676 of file timer.c.

Referenced by TIM1_TRG_COM_TIM11_IRQHandler(), TIM8_TRG_COM_TIM14_IRQHandler(), and timer_detach_interrupt().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ dispatch_adv_up()

static void dispatch_adv_up ( const timer_dev dev)
inlinestatic

Definition at line 664 of file timer.c.

Referenced by TIM1_UP_TIM10_IRQHandler(), TIM8_UP_TIM13_IRQHandler(), and timer_detach_interrupt().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ dispatch_basic()

static void dispatch_basic ( const timer_dev dev)
inlinestatic

Definition at line 769 of file timer.c.

Referenced by TIM6_DAC_IRQHandler(), TIM7_IRQHandler(), and timer_detach_interrupt().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ dispatch_general()

static void dispatch_general ( const timer_dev dev)
inlinestatic

Definition at line 720 of file timer.c.

Referenced by TIM2_IRQHandler(), TIM3_IRQHandler(), TIM4_IRQHandler(), TIM5_IRQHandler(), and timer_detach_interrupt().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ dispatch_general_h()

static void dispatch_general_h ( const timer_dev dev)
inlinestatic

Definition at line 745 of file timer.c.

Referenced by TIM1_BRK_TIM9_IRQHandler(), TIM1_TRG_COM_TIM11_IRQHandler(), TIM1_UP_TIM10_IRQHandler(), TIM8_BRK_TIM12_IRQHandler(), TIM8_TRG_COM_TIM14_IRQHandler(), TIM8_UP_TIM13_IRQHandler(), and timer_detach_interrupt().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ dispatch_single_irq()

static INLINE void dispatch_single_irq ( const timer_dev dev,
timer_interrupt_id  iid,
uint32_t  irq_mask 
)
static

Definition at line 625 of file timer.c.

Referenced by dispatch_adv_brk(), dispatch_adv_up(), and dispatch_basic().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ enable_advanced_irq()

static void enable_advanced_irq ( const timer_dev dev,
timer_interrupt_id  id,
uint8_t  priority 
)
static

Definition at line 812 of file timer.c.

Referenced by dispatch_basic(), and enable_irq().

Here is the caller graph for this function:

◆ enable_irq() [1/2]

static void enable_irq ( const timer_dev dev,
uint8_t  interrupt,
uint8_t  priority 
)
inlinestatic

Referenced by timer_attach_interrupt(), timer_disable_NVICirq(), and timer_enable_NVICirq().

Here is the caller graph for this function:

◆ enable_irq() [2/2]

static void enable_irq ( const timer_dev dev,
timer_interrupt_id  iid,
uint8_t  priority 
)
inlinestatic

Definition at line 781 of file timer.c.

Here is the call graph for this function:

◆ handle_irq()

static INLINE void handle_irq ( const timer_dev dev,
uint32_t  dier_sr,
uint32_t  irq_mask,
uint32_t  iid 
)
static

Definition at line 643 of file timer.c.

Referenced by dispatch_adv_cc(), dispatch_adv_trg_com(), dispatch_general(), and dispatch_general_h().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ output_compare_mode() [1/2]

static void output_compare_mode ( const timer_dev dev,
uint8_t  channel 
)
static

Referenced by timer_set_mode().

Here is the caller graph for this function:

◆ output_compare_mode() [2/2]

static void output_compare_mode ( const timer_dev dev,
timer_Channel  channel 
)
static

Definition at line 424 of file timer.c.

Here is the call graph for this function:

◆ pwm_mode() [1/2]

static void pwm_mode ( const timer_dev dev,
uint8_t  channel 
)
static

Referenced by timer_set_mode().

Here is the caller graph for this function:

◆ pwm_mode() [2/2]

static void pwm_mode ( const timer_dev dev,
timer_Channel  channel 
)
static

Definition at line 418 of file timer.c.

Here is the call graph for this function:

◆ TIM1_BRK_TIM9_IRQHandler()

void TIM1_BRK_TIM9_IRQHandler ( void  )

Definition at line 549 of file timer.c.

Referenced by timer_detach_interrupt().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ TIM1_CC_IRQHandler()

void TIM1_CC_IRQHandler ( void  )

Definition at line 567 of file timer.c.

Referenced by timer_detach_interrupt().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ TIM1_TRG_COM_TIM11_IRQHandler()

void TIM1_TRG_COM_TIM11_IRQHandler ( void  )

Definition at line 561 of file timer.c.

Referenced by timer_detach_interrupt().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ TIM1_UP_TIM10_IRQHandler()

void TIM1_UP_TIM10_IRQHandler ( void  )

Definition at line 556 of file timer.c.

Referenced by timer_detach_interrupt().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ TIM2_IRQHandler()

void TIM2_IRQHandler ( void  )

Definition at line 571 of file timer.c.

Referenced by timer_detach_interrupt().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ TIM3_IRQHandler()

void TIM3_IRQHandler ( void  )

Definition at line 575 of file timer.c.

Referenced by timer_detach_interrupt().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ TIM4_IRQHandler()

void TIM4_IRQHandler ( void  )

Definition at line 579 of file timer.c.

Referenced by timer_detach_interrupt().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ TIM5_IRQHandler()

void TIM5_IRQHandler ( void  )

Definition at line 583 of file timer.c.

Referenced by timer_detach_interrupt().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ TIM6_DAC_IRQHandler()

void TIM6_DAC_IRQHandler ( void  )

Definition at line 587 of file timer.c.

Referenced by timer_detach_interrupt().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ TIM7_IRQHandler()

void TIM7_IRQHandler ( void  )

Definition at line 591 of file timer.c.

Referenced by timer_detach_interrupt().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ TIM8_BRK_TIM12_IRQHandler()

void TIM8_BRK_TIM12_IRQHandler ( void  )

Definition at line 596 of file timer.c.

Referenced by timer_detach_interrupt().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ TIM8_CC_IRQHandler()

void TIM8_CC_IRQHandler ( void  )

Definition at line 601 of file timer.c.

Referenced by timer_detach_interrupt().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ TIM8_TRG_COM_TIM14_IRQHandler()

void TIM8_TRG_COM_TIM14_IRQHandler ( void  )

Definition at line 612 of file timer.c.

Referenced by timer_detach_interrupt().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ TIM8_UP_TIM13_IRQHandler()

void TIM8_UP_TIM13_IRQHandler ( void  )

Definition at line 606 of file timer.c.

Referenced by timer_detach_interrupt().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ timer_attach_all_interrupts()

void timer_attach_all_interrupts ( const timer_dev dev,
Handler  handler 
)

Definition at line 494 of file timer.c.

Referenced by pwmInitializeInput().

Here is the caller graph for this function:

◆ timer_attach_interrupt()

void timer_attach_interrupt ( const timer_dev dev,
timer_interrupt_id  interrupt,
Handler  handler,
uint8_t  priority 
)

Attach a timer interrupt.

Parameters
devTimer device
interruptInterrupt number to attach to; this may be any timer_interrupt_id or timer_channel value appropriate for the timer.
handlerHandler to attach to the given interrupt.
See also
timer_interrupt_id
timer_channel

Definition at line 485 of file timer.c.

Referenced by Soft_I2C::_start(), and F4Light::Scheduler::init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ timer_detach_interrupt()

void timer_detach_interrupt ( const timer_dev dev,
timer_interrupt_id  interrupt 
)

Detach a timer interrupt.

Parameters
devTimer device
interruptInterrupt number to detach; this may be any timer_interrupt_id or timer_channel value appropriate for the timer.
See also
timer_interrupt_id
timer_channel

Definition at line 512 of file timer.c.

Referenced by disable_channel(), and Soft_I2C::wait_done().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ timer_disable()

void timer_disable ( const timer_dev dev)

Disable a timer.

The timer will stop counting, all DMA requests and interrupts will be disabled, and no state changes will be output.

Parameters
devTimer to disable.

Definition at line 340 of file timer.c.

Referenced by timer_disable_all().

Here is the caller graph for this function:

◆ timer_disable_NVICirq()

void timer_disable_NVICirq ( const timer_dev dev,
uint8_t  interrupt 
)

Definition at line 850 of file timer.c.

Here is the call graph for this function:

◆ timer_enable_NVICirq()

void timer_enable_NVICirq ( const timer_dev dev,
uint8_t  interrupt,
uint8_t  priority 
)

Definition at line 845 of file timer.c.

Referenced by pwmInitializeInput().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ timer_foreach()

void timer_foreach ( void(*)(const timer_dev *)  fn)

Call a function on timer devices.

Parameters
fnFunction to call on each timer device.

Definition at line 468 of file timer.c.

Referenced by F4Light::Scheduler::init(), timer_disable_all(), and timer_init_all().

Here is the caller graph for this function:

◆ timer_init()

void timer_init ( const timer_dev dev)

Initialize a timer (enable timer clock)

Parameters
devTimer to initialize

Definition at line 303 of file timer.c.

Referenced by configTimeBase(), and timer_init_all().

Here is the caller graph for this function:

◆ timer_reset()

void timer_reset ( const timer_dev dev)

Initialize a timer, and reset its register map.

Parameters
devTimer to initialize

Definition at line 316 of file timer.c.

Referenced by F4Light::Scheduler::init().

Here is the caller graph for this function:

◆ timer_set_mode()

void timer_set_mode ( const timer_dev dev,
timer_Channel  channel,
timer_mode  mode 
)

Sets the mode of an individual timer channel.

Note that not all timers can be configured in every mode. For example, basic timers cannot be configured to output compare mode. Be sure to use a timer which is appropriate for the mode you want.

Parameters
devTimer whose channel mode to set
channelRelevant channel
modeNew timer mode for channel

Definition at line 442 of file timer.c.

Referenced by F4Light::GPIO::_pinMode(), and F4Light::RCOutput::init_channel().

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ IN_CCM

timerState timer_state [14] IN_CCM
static

Definition at line 58 of file timer.c.

◆ timers

const timer_dev timers[]

Definition at line 75 of file timer.c.

Referenced by timer_foreach().