[PATCH v2 12/32] bsp/leon3: Use new GPTIMER register block API

Martin Åberg maberg at gaisler.com
Fri Jul 7 16:20:34 UTC 2023


Below is a suggested update for gptimer_tlib_reset().

OK otherwise.


On 2023-07-05 13:18, Sebastian Huber wrote:
> ---
>   bsps/shared/grlib/btimer/gptimer.c   | 177 +++++++++++++--------------
>   bsps/sparc/leon3/btimer/btimer.c     |  13 +-
>   bsps/sparc/leon3/btimer/watchdog.c   |  27 ++--
>   bsps/sparc/leon3/clock/ckinit.c      |  33 ++---
>   bsps/sparc/leon3/include/bsp/leon3.h |  44 ++++++-
>   bsps/sparc/leon3/include/leon.h      |  24 ----
>   bsps/sparc/leon3/start/amba.c        |   9 +-
>   bsps/sparc/leon3/start/bspdelay.c    |   8 +-
>   bsps/sparc/leon3/start/cpucounter.c  |  20 +--
>   9 files changed, 188 insertions(+), 167 deletions(-)
> 
> diff --git a/bsps/shared/grlib/btimer/gptimer.c b/bsps/shared/grlib/btimer/gptimer.c
> index f31b7c052f..ca87780d2c 100644
> --- a/bsps/shared/grlib/btimer/gptimer.c
> +++ b/bsps/shared/grlib/btimer/gptimer.c

>   /* GPTIMER timer private */
> -struct gptimer_timer {
> +struct gptimer_timer_priv {
>   	struct tlib_dev tdev;	/* Must be first in struct */
> -	struct gptimer_timer_regs *tregs;
> +	gptimer_timer *tregs;
>   	char index; /* Timer Index in this driver */
>   	char tindex; /* Timer Index In Hardware */
> -	unsigned char irq_ack_mask;
> +	uint32_t irq_ack_mask;
>   };

OK, irq_ack_mask is now wider.



> @@ -406,12 +379,14 @@ void gptimer_isr(void *data)
>   
>   static void gptimer_tlib_reset(struct tlib_dev *hand)
>   {
> -	struct gptimer_timer *timer = (struct gptimer_timer *)hand;
> -
> -	timer->tregs->ctrl = (timer->tregs->ctrl & timer->irq_ack_mask) &
> -			     GPTIMER_CTRL_IP;
> -	timer->tregs->reload = 0xffffffff;
> -	timer->tregs->ctrl = GPTIMER_CTRL_LD;
> +	struct gptimer_timer_priv *timer = (struct gptimer_timer_priv *)hand;
> +	uint32_t tctrl;
> +
> +	tctrl = grlib_load_32(&timer->tregs->tctrl);
> +	tctrl &= timer->irq_ack_mask | GPTIMER_TCTRL_IP;
> +	grlib_store_32(&timer->tregs->tctrl, tctrl);
> +	grlib_store_32(&timer->tregs->trldval, 0xffffffff);
> +	grlib_store_32(&timer->tregs->tctrl, GPTIMER_TCTRL_LD);
>   }

This transformation of the trctrl calculation does not look quite right. 
I think the final tctrl assignment should be like this instead:
     tctrl &= timer->irq_ack_mask & GPTIMER_TCTRL_IP;
The desired side effect is to stop the subtimer, disable its interrupt 
generation and unpend a possibly pending interrupt indication.


-- 
Best regards,

Martin Åberg
Software Engineer
Frontgrade Gaisler
martin.aberg at gaisler.com

Frontgrade Gaisler AB, Kungsgatan 12, SE-411 19 GÖTEBORG, Sweden.
+46 (0) 31 775 8650, www.gaisler.com


More information about the devel mailing list