libopencm3
A free/libre/open-source firmware library for various ARM Cortex-M3 microcontrollers.
timer.h File Reference
Include dependency graph for timer.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define TIMER_SE0   TIMER_SE0_BASE
 
#define TIMER_SE1   TIMER_SE1_BASE
 
#define TIMER_DIV_MASK   (0x3F << 16)
 Timer Clock Divider Mask. More...
 
#define TIMER_CTRL(x)   MMIO32(x + 0x0)
 Timer control register. More...
 
#define TIMER_TARVAL(x)   MMIO32(x + 0x4)
 The target value(s). More...
 
#define TIMER_CURVAL(x)   MMIO32(x + 0x8)
 Current count value in modes 0, 2, and 3. More...
 
#define TIMER_CAPW(x)   MMIO32(x + 0xC)
 Cycle width in mode 3. More...
 
#define TIMER_CAPLH(x)   MMIO32(x + 0x10)
 Pulse width in modes 2 and 3. More...
 
#define TIMER_MOD2LF(x)   MMIO32(x + 0x14)
 PWM state in mode 1. More...
 
#define TIMER_OUTPVAL(x)   MMIO32(x + 0x80)
 Timer output pin value. More...
 
#define TIMER_INTCTL(x)   MMIO32(x + 0x84)
 Interrupt enable and mask. More...
 
#define TIMER_INTSTAT(x)   MMIO32(x + 0x88)
 Interrupt status before masking. More...
 
#define TIMER_INTMSKSTAT(x)   MMIO32(x + 0x8C)
 Interrupt status after masking. More...
 
#define TIMER_INTFLAG(x)   MMIO32(x + 0x90)
 Interrupt overflow; 1 if interrupt occurs again without being cleared. More...
 
#define TIMER_CTRL_EN   1
 
#define TIMER_CTRL_OSCMOD   (1 << 8)
 Clock source selection. More...
 
#define TIMER_CTRL_TMOD   (1 << 16)
 Valid edge selection. More...
 
#define TIMER_CTRL_LMOD   (1 << 28)
 Loop mode selection. More...
 
#define TIMER_CTRL_OUTMOD_MASK   0x3
 Timer Output Mode Mask. More...
 
#define TIMER_CTRL_OUTMOD_SHIFT   12
 
#define TIMER_CTRL_WMOD_MASK   0x3
 Timer Operation Mode Mask. More...
 
#define TIMER_CTRL_WMOD_SHIFT   4
 
#define TIMER_INTCTL_INTMSK   (1 << 1)
 Interrupt mask. More...
 
#define TIMER_INTCTL_INTEN   1
 Interrupt enable. More...
 

Enumerations

enum  timer_level { TIMER_LEVEL_LOW , TIMER_LEVEL_HIGH }
 Timer Level. More...
 
enum  timer_edge_modes { TIMER_EDGE_RISING , TIMER_EDGE_FALLING }
 Timer Edge Modes. More...
 
enum  timer_operation_modes { TIMER_MODE_COUNTER , TIMER_MODE_PWM , TIMER_MODE_PULSE_CAPTURE , TIMER_MODE_DUTY_CYCLE_CAPTURE }
 Timer Operation Modes. More...
 
enum  timer_clk_src { TIMER_CLK_INTERNAL , TIMER_CLK_EXTERNAL }
 Timer Clock Source. More...
 
enum  timer_int_masked { TIMER_UNMASKED , TIMER_MASKED }
 Timer Interrupt Mask. More...
 
enum  timer_loop_modes { TIMER_LOOP_MODE , TIMER_SINGLE_MODE }
 Timer Loop Modes. More...
 
enum  timer_output_modes { TIMER_OUTPUT_NONE , TIMER_OUTPUT_INVERT , TIMER_OUTPUT_HIGH , TIMER_OUTPUT_LOW }
 Timer Output Modes. More...
 
enum  timer_pwm_period { TIMER_PERIOD_0 , TIMER_PERIOD_1 }
 Timer PWM Periods. More...
 

Functions

void timer_counter_setup (uint32_t timer, bool timer_int_en, enum timer_edge_modes edge_mode, enum timer_loop_modes loop_mode, enum timer_clk_src clk_src, enum timer_output_modes output_mode, enum timer_level output_level, uint32_t target)
 Setup the timer in counter mode. More...
 
void timer_pwm_setup (uint32_t timer, bool timer_int_en, enum timer_edge_modes edge_mode, enum timer_clk_src clk_src, enum timer_level output_level, uint16_t target1, uint16_t target2)
 Setup the timer in PWM mode. More...
 
void timer_pulse_capture_setup (uint32_t timer, bool timer_int_en, enum timer_edge_modes edge_mode, enum timer_loop_modes loop_mode)
 Setup the timer in pulse capture mode. More...
 
void timer_duty_cycle_capture_setup (uint32_t timer, bool timer_int_en, enum timer_edge_modes edge_mode, enum timer_loop_modes loop_mode)
 Setup the timer in duty cycle capture mode. More...
 
void timer_clock_div (uint8_t div)
 Set the timer clock divider, based off of the 18MHz oscillator. More...
 
void timer_enable (uint32_t timer, bool en)
 Enables or disables the timer. More...
 
void timer_clock_enable (uint32_t timer, bool en)
 Enables or disables the timer's internal clock. More...
 
void timer_operation_mode (uint32_t timer, enum timer_operation_modes mode)
 Selects the mode of operation. More...
 
void timer_output_mode (uint32_t timer, enum timer_output_modes mode)
 Selects the output mode. More...
 
void timer_output_level (uint32_t timer, enum timer_level level)
 Selects the initial output level. More...
 
void timer_edge_mode (uint32_t timer, enum timer_edge_modes mode)
 Selects the edge mode. More...
 
void timer_loop_mode (uint32_t timer, enum timer_loop_modes mode)
 Selects the loop mode. More...
 
void timer_clock_source (uint32_t timer, enum timer_clk_src src)
 Selects the clock source for the timer. More...
 
void timer_counter_target_value (uint32_t timer, uint32_t target)
 Sets the target values for counter mode. More...
 
void timer_pwm_target_value (uint32_t timer, uint16_t period0, uint16_t period1)
 Sets the target values for PWM mode. More...
 
void timer_int_enable (uint32_t timer, bool en)
 Enable or disable the interrupt. More...
 
void timer_int_mask (uint32_t timer, enum timer_int_masked masked)
 Sets the interrupt mask. More...
 
uint32_t timer_get_current_value (uint32_t timer)
 Gets the current counter value, and clears the interrupt/interrupt overflow. More...
 
uint32_t timer_get_cycle_width (uint32_t timer)
 Gets the cycle width. More...
 
uint32_t timer_get_pulse_width (uint32_t timer)
 Gets the pulse width in pulse capture mode, or gets the period width in duty cycle capture mode. More...
 
enum timer_pwm_period timer_get_pwm_period (uint32_t timer)
 Gets the current output period in PWM mode. More...
 
bool timer_int_status (uint32_t timer)
 Gets the interrupt status after masking. More...
 
bool timer_int_raw_status (uint32_t timer)
 Gets the interrupt status before masking. More...
 
bool timer_int_overflow_status (uint32_t timer)
 Gets the interrupt overflow status. More...