libopencm3
A free/libre/open-source firmware library for various ARM Cortex-M3 microcontrollers.
|
SWM050 Timer API. More...
Functions | |
static void | timer_setup_internal (uint32_t timer, bool timer_int_en, enum timer_operation_modes op_mode, 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) |
Internal function for timer setup. More... | |
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 period0, uint16_t period1) |
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... | |
SWM050 Timer API.
LGPL License Terms libopencm3 License
void timer_clock_div | ( | uint8_t | div | ) |
Set the timer clock divider, based off of the 18MHz oscillator.
div | Timer clock divider. Only the 6 least-significant bits are used, Takes values from 0 to 63 (in reality the possible values are the even numbers from 2 to 62, as well as the number 1). Anything after the 6 least-significant bits are stripped off of the value. If the value is 0, it will be treated as a 1. All odd values other than 1 are rounded down to the closest even value, due to the fact that all odd values are treated by the register as a 1, which would likely be unexpected. A value of 0 would also normally be treated as a 2, which would also be unexpected behavior. |
Definition at line 185 of file timer.c.
References SYSCTL_SYS_CFG_0.
void timer_clock_enable | ( | uint32_t | timer, |
bool | en | ||
) |
Enables or disables the timer's internal clock.
timer | Select timer Timer Select |
en | Enable or disable the internal clock |
Definition at line 212 of file timer.c.
References SYSCTL_SYS_CFG_1, SYSCTL_SYS_CFG_1_TIMERSE0, SYSCTL_SYS_CFG_1_TIMERSE1, and TIMER_SE1.
Referenced by timer_setup_internal().
void timer_clock_source | ( | uint32_t | timer, |
enum timer_clk_src | src | ||
) |
Selects the clock source for the timer.
timer | Select timer Timer Select |
src | Select the internal or external clock source timer_clk_src |
Definition at line 311 of file timer.c.
References TIMER_CTRL, and TIMER_CTRL_OSCMOD.
Referenced by timer_setup_internal().
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.
timer | Select timer Timer Select |
timer_int_en | Passed to timer_int_enable() |
edge_mode | Passed to timer_edge_mode() |
loop_mode | Passed to timer_loop_mode() |
clk_src | Passed to timer_clock_source() |
output_mode | Passed to timer_output_mode() |
output_level | Passed to timer_output_level() |
target | Passed to timer_counter_target_value() |
Definition at line 83 of file timer.c.
References timer_counter_target_value(), TIMER_MODE_COUNTER, and timer_setup_internal().
void timer_counter_target_value | ( | uint32_t | timer, |
uint32_t | target | ||
) |
Sets the target values for counter mode.
timer | Select timer Timer Select |
target | The value to count up to |
Definition at line 325 of file timer.c.
References TIMER_TARVAL.
Referenced by timer_counter_setup(), and timer_pwm_target_value().
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.
timer | Select timer Timer Select |
timer_int_en | Passed to timer_int_enable() |
edge_mode | Passed to timer_edge_mode() |
loop_mode | Passed to timer_loop_mode() |
Definition at line 163 of file timer.c.
References TIMER_CLK_INTERNAL, TIMER_LEVEL_LOW, TIMER_MODE_DUTY_CYCLE_CAPTURE, TIMER_OUTPUT_NONE, and timer_setup_internal().
void timer_edge_mode | ( | uint32_t | timer, |
enum timer_edge_modes | mode | ||
) |
Selects the edge mode.
timer | Select timer Timer Select |
mode | The edge mode timer_edge_modes |
Definition at line 274 of file timer.c.
References TIMER_CTRL, and TIMER_CTRL_TMOD.
Referenced by timer_setup_internal().
void timer_enable | ( | uint32_t | timer, |
bool | en | ||
) |
Enables or disables the timer.
timer | Select timer Timer Select |
en | Enable or disable the timer |
Definition at line 198 of file timer.c.
References TIMER_CTRL, and TIMER_CTRL_EN.
Referenced by timer_setup_internal().
uint32_t timer_get_current_value | ( | uint32_t | timer | ) |
Gets the current counter value, and clears the interrupt/interrupt overflow.
If in PWM mode, this is only used for clearing the interrupt.
timer | Select timer Timer Select |
Definition at line 383 of file timer.c.
References TIMER_CURVAL.
uint32_t timer_get_cycle_width | ( | uint32_t | timer | ) |
Gets the cycle width.
Only used in duty cycle capture mode.
timer | Select timer Timer Select |
Definition at line 395 of file timer.c.
References TIMER_CAPW.
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.
timer | Select timer Timer Select |
Definition at line 407 of file timer.c.
References TIMER_CAPLH.
enum timer_pwm_period timer_get_pwm_period | ( | uint32_t | timer | ) |
Gets the current output period in PWM mode.
timer | Select timer Timer Select |
Definition at line 417 of file timer.c.
References TIMER_MOD2LF.
void timer_int_enable | ( | uint32_t | timer, |
bool | en | ||
) |
Enable or disable the interrupt.
In counter mode, when the count has been completed, an interrupt is generated. In PWM mode, on a level change, an interupt is generated. In either capture mode, when a capture is complete, an interrupt is generated.
timer | Select timer Timer Select |
en | Enable or disable the interrupt |
Definition at line 354 of file timer.c.
References TIMER_INTCTL, and TIMER_INTCTL_INTEN.
Referenced by timer_setup_internal().
void timer_int_mask | ( | uint32_t | timer, |
enum timer_int_masked | masked | ||
) |
Sets the interrupt mask.
timer | Select timer Timer Select |
masked | Whether or not to mask the interrupt timer_int_masked |
Definition at line 368 of file timer.c.
References TIMER_INTCTL, and TIMER_INTCTL_INTMSK.
Referenced by timer_setup_internal().
bool timer_int_overflow_status | ( | uint32_t | timer | ) |
Gets the interrupt overflow status.
Overflow will occur if the interrupt has not been cleared when a second interrupt happens.
timer | Select timer Timer Select |
Definition at line 449 of file timer.c.
References TIMER_INTFLAG.
bool timer_int_raw_status | ( | uint32_t | timer | ) |
Gets the interrupt status before masking.
timer | Select timer Timer Select |
Definition at line 437 of file timer.c.
References TIMER_INTSTAT.
bool timer_int_status | ( | uint32_t | timer | ) |
Gets the interrupt status after masking.
timer | Select timer Timer Select |
Definition at line 427 of file timer.c.
References TIMER_INTMSKSTAT.
void timer_loop_mode | ( | uint32_t | timer, |
enum timer_loop_modes | mode | ||
) |
Selects the loop mode.
This has no use in PWM mode. In loop mode with counter mode, the counter will constantly loop. In loop mode with the capture modes, the values will be captured again and again. In single mode, these operations happen only once.
timer | Select timer Timer Select |
mode | The loop mode timer_loop_modes |
Definition at line 292 of file timer.c.
References TIMER_CTRL, and TIMER_CTRL_LMOD.
Referenced by timer_setup_internal().
void timer_operation_mode | ( | uint32_t | timer, |
enum timer_operation_modes | mode | ||
) |
Selects the mode of operation.
timer | Select timer Timer Select |
mode | The mode of operation timer_operation_modes |
Definition at line 234 of file timer.c.
References TIMER_CTRL, TIMER_CTRL_OUTMOD_MASK, and TIMER_CTRL_OUTMOD_SHIFT.
Referenced by timer_setup_internal().
void timer_output_level | ( | uint32_t | timer, |
enum timer_level | level | ||
) |
Selects the initial output level.
Only used in counter and PWM modes.
timer | Select timer Timer Select |
level | The initial output level timer_level |
Definition at line 264 of file timer.c.
References TIMER_OUTPVAL.
Referenced by timer_setup_internal().
void timer_output_mode | ( | uint32_t | timer, |
enum timer_output_modes | mode | ||
) |
Selects the output mode.
Only used in counter mode. When done counting, the pin can be set to no output, to invert the current pin level, to set the pin high, or to set the pin low.
timer | Select timer Timer Select |
mode | The output mode timer_output_modes |
Definition at line 252 of file timer.c.
References TIMER_CTRL, TIMER_CTRL_WMOD_MASK, and TIMER_CTRL_WMOD_SHIFT.
Referenced by timer_setup_internal().
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.
timer | Select timer Timer Select |
timer_int_en | Passed to timer_int_enable() |
edge_mode | Passed to timer_edge_mode() |
loop_mode | Passed to timer_loop_mode() |
Definition at line 140 of file timer.c.
References TIMER_CLK_INTERNAL, TIMER_LEVEL_LOW, TIMER_MODE_PULSE_CAPTURE, TIMER_OUTPUT_NONE, and timer_setup_internal().
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 | period0, | ||
uint16_t | period1 | ||
) |
Setup the timer in PWM mode.
timer | Select timer Timer Select |
timer_int_en | Passed to timer_int_enable() |
edge_mode | Passed to timer_edge_mode() |
clk_src | Passed to timer_clock_source() |
output_level | Passed to timer_output_level() |
period0 | Passed to timer_pwm_target_value() |
period1 | Passed to timer_pwm_target_value() |
Definition at line 113 of file timer.c.
References TIMER_LOOP_MODE, TIMER_MODE_PWM, TIMER_OUTPUT_NONE, timer_pwm_target_value(), and timer_setup_internal().
void timer_pwm_target_value | ( | uint32_t | timer, |
uint16_t | period0, | ||
uint16_t | period1 | ||
) |
Sets the target values for PWM mode.
timer | Select timer Timer Select |
period0 | length of period 0 in clock cycles. Whether it is high or low is set in timer_output_level() |
period1 | length of period 1 |
Definition at line 337 of file timer.c.
References timer_counter_target_value().
Referenced by timer_pwm_setup().
|
static |
Internal function for timer setup.
timer | Select timer Timer Select |
timer_int_en | Passed to timer_int_enable() |
op_mode | Passed to timer_operation_mode() |
edge_mode | Passed to timer_edge_mode() |
loop_mode | Passed to timer_loop_mode() |
clk_src | Passed to timer_clock_source() |
output_mode | Passed to timer_output_mode() |
output_level | Passed to timer_output_level() |
Definition at line 42 of file timer.c.
References TIMER_CLK_INTERNAL, timer_clock_enable(), timer_clock_source(), timer_edge_mode(), timer_enable(), timer_int_enable(), timer_int_mask(), timer_loop_mode(), timer_operation_mode(), timer_output_level(), timer_output_mode(), and TIMER_UNMASKED.
Referenced by timer_counter_setup(), timer_duty_cycle_capture_setup(), timer_pulse_capture_setup(), and timer_pwm_setup().