aboutsummaryrefslogtreecommitdiff
path: root/lib/stm32/f1/timer.c
diff options
context:
space:
mode:
authorKen Sarkies2012-10-09 11:50:57 +1030
committerPiotr Esden-Tempski2012-10-16 14:05:45 -0700
commit0834f41383df854c30f4db973c3632439d7d9cca (patch)
treed30fa4f6851fc8d00984f4c742cbc11021baf7db /lib/stm32/f1/timer.c
parentf94d71efee4afd49e475f056707fa34b0820e664 (diff)
stm32f1:
Add object files to Makefile to include new modules into lib. Correct typo in pwr.c Add two new functions to timer.c to preset the counter (for use with deadman style timeouts) and to identify an interrupt source. Also noticed lib/makefile.include didn't clean lib/stm32, which isn't a target. Added a fix.
Diffstat (limited to 'lib/stm32/f1/timer.c')
-rw-r--r--lib/stm32/f1/timer.c39
1 files changed, 39 insertions, 0 deletions
diff --git a/lib/stm32/f1/timer.c b/lib/stm32/f1/timer.c
index c5ea921..384eaaf 100644
--- a/lib/stm32/f1/timer.c
+++ b/lib/stm32/f1/timer.c
@@ -199,6 +199,31 @@ void timer_disable_irq(u32 timer_peripheral, u32 irq)
}
/*---------------------------------------------------------------------------*/
+/** @brief Return Interrupt Source.
+
+Returns true if the specified interrupt flag (UIF, TIF or CCxIF, with BIF or COMIF
+for advanced timers) was set and the interrupt was enabled. If the specified flag
+is not an interrupt flag, the function returns false.
+
+@todo Timers 6-7, 9-14 have fewer interrupts, but invalid flags are not caught here.
+
+@param[in] timer_peripheral Unsigned int32. Timer register address base @ref tim_reg_base
+@param[in] flag Unsigned int32. Status register flag @ref tim_sr_values.
+@returns boolean: flag set.
+*/
+
+bool timer_interrupt_source(u32 timer_peripheral, u32 flag)
+{
+/* flag not set or interrupt disabled or not an interrupt source */
+ if (((TIM_SR(timer_peripheral) & TIM_DIER(timer_peripheral) & flag) == 0) ||
+ (flag > TIM_SR_BIF)) return false;
+/* Only an interrupt source for advanced timers */
+ if ((flag == TIM_SR_BIF) || (flag == TIM_SR_COMIF))
+ return ((timer_peripheral == TIM1) || (timer_peripheral == TIM8));
+ return true;
+}
+
+/*---------------------------------------------------------------------------*/
/** @brief Read a Status Flag.
@param[in] timer_peripheral Unsigned int32. Timer register address base @ref tim_reg_base
@@ -1672,6 +1697,20 @@ u32 timer_get_counter(u32 timer_peripheral)
}
/*---------------------------------------------------------------------------*/
+/** @brief Set Counter
+
+Set the value of a timer's counter register contents.
+
+@param[in] timer_peripheral Unsigned int32. Timer register address base
+@param[in] Unsigned int32. Counter value.
+*/
+
+void timer_set_counter(u32 timer_peripheral, u32 count)
+{
+ TIM_CNT(timer_peripheral) = count;
+}
+
+/*---------------------------------------------------------------------------*/
/** @brief Set Input Capture Filter Parameters
Set the input filter parameters for an input channel, specifying: