28#ifndef LIBOPENCM3_TIMER_H
29#define LIBOPENCM3_TIMER_H
35#define TIMER_SE0 TIMER_SE0_BASE
36#define TIMER_SE1 TIMER_SE1_BASE
94#define TIMER_DIV_MASK (0x3F << 16)
99#define TIMER_CTRL(x) MMIO32(x + 0x0)
102#define TIMER_TARVAL(x) MMIO32(x + 0x4)
104#define TIMER_CURVAL(x) MMIO32(x + 0x8)
106#define TIMER_CAPW(x) MMIO32(x + 0xC)
108#define TIMER_CAPLH(x) MMIO32(x + 0x10)
110#define TIMER_MOD2LF(x) MMIO32(x + 0x14)
112#define TIMER_OUTPVAL(x) MMIO32(x + 0x80)
114#define TIMER_INTCTL(x) MMIO32(x + 0x84)
116#define TIMER_INTSTAT(x) MMIO32(x + 0x88)
118#define TIMER_INTMSKSTAT(x) MMIO32(x + 0x8C)
120#define TIMER_INTFLAG(x) MMIO32(x + 0x90)
125#define TIMER_CTRL_EN 1
127#define TIMER_CTRL_OSCMOD (1 << 8)
129#define TIMER_CTRL_TMOD (1 << 16)
131#define TIMER_CTRL_LMOD (1 << 28)
133#define TIMER_CTRL_OUTMOD_MASK 0x3
134#define TIMER_CTRL_OUTMOD_SHIFT 12
136#define TIMER_CTRL_WMOD_MASK 0x3
137#define TIMER_CTRL_WMOD_SHIFT 4
139#define TIMER_INTCTL_INTMSK (1 << 1)
141#define TIMER_INTCTL_INTEN 1
uint32_t timer_get_cycle_width(uint32_t timer)
Gets the cycle width.
bool timer_int_overflow_status(uint32_t timer)
Gets the interrupt overflow status.
void timer_pwm_target_value(uint32_t timer, uint16_t period0, uint16_t period1)
Sets the target values for PWM mode.
void timer_output_level(uint32_t timer, enum timer_level level)
Selects the initial output level.
void timer_int_mask(uint32_t timer, enum timer_int_masked masked)
Sets the interrupt mask.
void timer_operation_mode(uint32_t timer, enum timer_operation_modes mode)
Selects the mode of operation.
bool timer_int_status(uint32_t timer)
Gets the interrupt status after masking.
void timer_clock_div(uint8_t div)
Set the timer clock divider, based off of the 18MHz oscillator.
enum timer_pwm_period timer_get_pwm_period(uint32_t timer)
Gets the current output period in PWM mode.
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.
void timer_edge_mode(uint32_t timer, enum timer_edge_modes mode)
Selects the edge mode.
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.
void timer_clock_enable(uint32_t timer, bool en)
Enables or disables the timer's internal clock.
void timer_counter_target_value(uint32_t timer, uint32_t target)
Sets the target values for counter mode.
uint32_t timer_get_current_value(uint32_t timer)
Gets the current counter value, and clears the interrupt/interrupt overflow.
void timer_clock_source(uint32_t timer, enum timer_clk_src src)
Selects the clock source for the timer.
void timer_output_mode(uint32_t timer, enum timer_output_modes mode)
Selects the output mode.
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.
void timer_enable(uint32_t timer, bool en)
Enables or disables the timer.
void timer_loop_mode(uint32_t timer, enum timer_loop_modes mode)
Selects the loop mode.
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.
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.
bool timer_int_raw_status(uint32_t timer)
Gets the interrupt status before masking.
void timer_int_enable(uint32_t timer, bool en)
Enable or disable the interrupt.
timer_output_modes
Timer Output Modes.
timer_pwm_period
Timer PWM Periods.
timer_loop_modes
Timer Loop Modes.
timer_edge_modes
Timer Edge Modes.
timer_clk_src
Timer Clock Source.
timer_int_masked
Timer Interrupt Mask.
timer_operation_modes
Timer Operation Modes.
@ TIMER_EDGE_FALLING
Trigger on falling edge.
@ TIMER_EDGE_RISING
Trigger on rising edge.
@ TIMER_MODE_DUTY_CYCLE_CAPTURE
@ TIMER_MODE_PULSE_CAPTURE