diff mbox

[v2,2/7] STM32F2xx: Display PWM duty cycle from timer

Message ID eafae90b0cb1a4e8f5d0c941f3b6e72de37d809e.1432963735.git.alistair@alistair23.me
State New
Headers show

Commit Message

Alistair Francis May 30, 2015, 5:45 a.m. UTC
If correctly configured allow the STM32F2xx timer to print
out the PWM duty cycle information.

Signed-off-by: Alistair Francis <alistair@alistair23.me>
---
V2:
 - Fix up if statement braces
 - Remove stm32f2xx_timer_set_alarm() call

 hw/timer/stm32f2xx_timer.c | 9 +++++++++
 1 file changed, 9 insertions(+)

Comments

Peter Crosthwaite May 30, 2015, 6:42 a.m. UTC | #1
On Fri, May 29, 2015 at 10:45 PM, Alistair Francis <alistair23@gmail.com> wrote:
> If correctly configured allow the STM32F2xx timer to print
> out the PWM duty cycle information.
>
> Signed-off-by: Alistair Francis <alistair@alistair23.me>
> ---
> V2:
>  - Fix up if statement braces
>  - Remove stm32f2xx_timer_set_alarm() call
>
>  hw/timer/stm32f2xx_timer.c | 9 +++++++++
>  1 file changed, 9 insertions(+)
>
> diff --git a/hw/timer/stm32f2xx_timer.c b/hw/timer/stm32f2xx_timer.c
> index ecadf9d..de4b8af 100644
> --- a/hw/timer/stm32f2xx_timer.c
> +++ b/hw/timer/stm32f2xx_timer.c
> @@ -49,6 +49,15 @@ static void stm32f2xx_timer_interrupt(void *opaque)
>          qemu_irq_pulse(s->irq);
>          stm32f2xx_timer_set_alarm(s, s->hit_time);
>      }
> +
> +    if (s->tim_ccmr1 & (TIM_CCMR1_OC2M2 + TIM_CCMR1_OC2M1) &&

Use | to combine multiple masks together (to show you are doing bit
operations rather than arithmetic).

> +        !(s->tim_ccmr1 & TIM_CCMR1_OC2M0) &&
> +        s->tim_ccmr1 & TIM_CCMR1_OC2PE &&
> +        s->tim_ccer & TIM_CCER_CC2E) {
> +        /* PWM 2 - Mode 1 */
> +        DB_PRINT("Duty Cycle: %d%%\n",
> +                s->tim_ccr2 / (100 * (s->tim_psc + 1)));

You should be more descriptive and give more context to the print. Add
the timer name and "PWM" in there.

Otherwise:

Reviewed-by: Peter Crosthwaite <peter.crosthwaite@xilinx.com>

Regards,
Peter


> +    }
>  }
>
>  static inline int64_t stm32f2xx_ns_to_ticks(STM32F2XXTimerState *s, int64_t t)
> --
> 2.1.4
>
>
diff mbox

Patch

diff --git a/hw/timer/stm32f2xx_timer.c b/hw/timer/stm32f2xx_timer.c
index ecadf9d..de4b8af 100644
--- a/hw/timer/stm32f2xx_timer.c
+++ b/hw/timer/stm32f2xx_timer.c
@@ -49,6 +49,15 @@  static void stm32f2xx_timer_interrupt(void *opaque)
         qemu_irq_pulse(s->irq);
         stm32f2xx_timer_set_alarm(s, s->hit_time);
     }
+
+    if (s->tim_ccmr1 & (TIM_CCMR1_OC2M2 + TIM_CCMR1_OC2M1) &&
+        !(s->tim_ccmr1 & TIM_CCMR1_OC2M0) &&
+        s->tim_ccmr1 & TIM_CCMR1_OC2PE &&
+        s->tim_ccer & TIM_CCER_CC2E) {
+        /* PWM 2 - Mode 1 */
+        DB_PRINT("Duty Cycle: %d%%\n",
+                s->tim_ccr2 / (100 * (s->tim_psc + 1)));
+    }
 }
 
 static inline int64_t stm32f2xx_ns_to_ticks(STM32F2XXTimerState *s, int64_t t)