diff --git a/include/libopencm3/stm32/timer.h b/include/libopencm3/stm32/timer.h index b6f89497..61d40e91 100644 --- a/include/libopencm3/stm32/timer.h +++ b/include/libopencm3/stm32/timer.h @@ -1028,6 +1028,7 @@ BEGIN_DECLS void timer_reset(u32 timer_peripheral); void timer_enable_irq(u32 timer_peripheral, u32 irq); void timer_disable_irq(u32 timer_peripheral, u32 irq); +bool timer_return_interrupt_source(u32 timer_peripheral, u32 flag); bool timer_get_flag(u32 timer_peripheral, u32 flag); void timer_clear_flag(u32 timer_peripheral, u32 flag); void timer_set_mode(u32 timer_peripheral, u32 clock_div, @@ -1090,6 +1091,7 @@ void timer_set_break_lock(u32 timer_peripheral, u32 lock); void timer_set_deadtime(u32 timer_peripheral, u32 deadtime); void timer_generate_event(u32 timer_peripheral, u32 event); u32 timer_get_counter(u32 timer_peripheral); +void timer_set_counter(u32 timer_peripheral, u32 count); void timer_ic_set_filter(u32 timer, enum tim_ic_id ic, enum tim_ic_filter flt); void timer_ic_set_prescaler(u32 timer, enum tim_ic_id ic, enum tim_ic_psc psc); diff --git a/lib/Makefile.include b/lib/Makefile.include index f2f1f7b2..9fbea244 100644 --- a/lib/Makefile.include +++ b/lib/Makefile.include @@ -40,7 +40,7 @@ $(SRCLIBDIR)/$(LIBNAME).ld: $(LIBNAME).ld clean: @printf " CLEAN lib/stm32/f1\n" - $(Q)rm -f *.o *.d + $(Q)rm -f *.o *.d ../*.o ../*.d $(Q)rm -f $(SRCLIBDIR)/$(LIBNAME).a $(Q)rm -f $(SRCLIBDIR)/$(LIBNAME).ld $(Q)rm -f $(SRCLIBDIR)/$(LIBNAME)_rom_to_ram.ld diff --git a/lib/stm32/f1/Makefile b/lib/stm32/f1/Makefile index 4fdbf434..a2f7bf28 100644 --- a/lib/stm32/f1/Makefile +++ b/lib/stm32/f1/Makefile @@ -31,7 +31,7 @@ ARFLAGS = rcs OBJS = vector.o rcc.o gpio.o usart.o adc.o spi.o flash.o nvic.o \ rtc.o i2c.o dma.o systick.o exti.o scb.o ethernet.o \ usb_f103.o usb.o usb_control.o usb_standard.o can.o \ - timer.o usb_f107.o desig.o crc.o assert.o + timer.o usb_f107.o desig.o crc.o assert.o dac.o iwdg.o pwr.o VPATH += ../../usb:../:../../cm3 diff --git a/lib/stm32/f1/pwr.c b/lib/stm32/f1/pwr.c index 83c3dba5..451ed1cf 100644 --- a/lib/stm32/f1/pwr.c +++ b/lib/stm32/f1/pwr.c @@ -157,7 +157,7 @@ The wakeup pin is used for waking the processor from standby mode. void pwr_enable_wakeup_pin(void) { - PWR_CSR |= PWR_CR_EWUP; + PWR_CSR |= PWR_CSR_EWUP; } /*---------------------------------------------------------------------------*/ @@ -168,7 +168,7 @@ The wakeup pin is used for general purpose I/O. void pwr_disable_wakeup_pin(void) { - PWR_CSR &= ~PWR_CR_EWUP; + PWR_CSR &= ~PWR_CSR_EWUP; } /*---------------------------------------------------------------------------*/ @@ -183,7 +183,7 @@ threshold. bool pwr_voltage_high(void) { - return (PWR_CSR & PWR_CR_PVDO); + return (PWR_CSR & PWR_CSR_PVDO); } /*---------------------------------------------------------------------------*/ @@ -197,7 +197,7 @@ cleared by software (see @ref pwr_clear_standby_flag). bool pwr_get_standby_flag(void) { - return (PWR_CSR & PWR_CR_SBF); + return (PWR_CSR & PWR_CSR_SBF); } /*---------------------------------------------------------------------------*/ @@ -211,7 +211,7 @@ cleared by software (see @ref pwr_clear_wakeup_flag). bool pwr_get_wakeup_flag(void) { - return (PWR_CSR & PWR_CR_WUF); + return (PWR_CSR & PWR_CSR_WUF); } /**@}*/ diff --git a/lib/stm32/f1/timer.c b/lib/stm32/f1/timer.c index c5ea921f..384eaaf0 100644 --- a/lib/stm32/f1/timer.c +++ b/lib/stm32/f1/timer.c @@ -198,6 +198,31 @@ void timer_disable_irq(u32 timer_peripheral, u32 irq) TIM_DIER(timer_peripheral) &= ~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. @@ -1671,6 +1696,20 @@ u32 timer_get_counter(u32 timer_peripheral) return TIM_CNT(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