[PATCH] bsp/tms570: unite code duplication in pinmux and clean SCI close per review remarks.

Gedare Bloom gedare at rtems.org
Wed Nov 18 18:38:50 UTC 2015


Applied.

On Wed, Nov 18, 2015 at 12:45 PM, Pavel Pisa <pisa at cmp.felk.cvut.cz> wrote:
> From: Premysl Houdek <kom541000 at gmail.com>
>
> Signed-off-by: Premysl Houdek <kom541000 at gmail.com>
> ---
>  c/src/lib/libbsp/arm/tms570/console/tms570-sci.c    | 12 +++++++-----
>  c/src/lib/libbsp/arm/tms570/include/tms570-pinmux.h |  9 +++++++++
>  c/src/lib/libbsp/arm/tms570/pinmux/pinmux.c         | 18 +++++-------------
>  3 files changed, 21 insertions(+), 18 deletions(-)
>
> diff --git a/c/src/lib/libbsp/arm/tms570/console/tms570-sci.c b/c/src/lib/libbsp/arm/tms570/console/tms570-sci.c
> index a799a66..fac258d 100644
> --- a/c/src/lib/libbsp/arm/tms570/console/tms570-sci.c
> +++ b/c/src/lib/libbsp/arm/tms570/console/tms570-sci.c
> @@ -525,17 +525,19 @@ static void tms570_sci_interrupt_last_close(
>  {
>    tms570_sci_context *ctx = (tms570_sci_context *) base;
>    rtems_interrupt_lock_context lock_context;
> +  rtems_interval tw;
> +  int32_t baudrate;
>
>    /* Turn off RX interrupts */
>    rtems_termios_device_lock_acquire(base, &lock_context);
>    tms570_sci_disable_interrupts(ctx);
>    rtems_termios_device_lock_release(base, &lock_context);
>
> -  if ( 0 /* for flush on close */ ) {
> -    /* Flush device */
> -    while ( ( ctx->regs->FLR & TMS570_SCI_FLR_TX_EMPTY ) == 0 ) {
> -      ;/* Wait until all data has been sent */
> -    }
> +  tw = rtems_clock_get_ticks_per_second();
> +  baudrate = rtems_termios_baud_to_number(cfgetospeed(&tty->termios));
> +  tw = tw * 10 / baudrate + 1;
> +  while ( ( ctx->regs->FLR & TMS570_SCI_FLR_TX_EMPTY ) == 0 ) {
> +     rtems_task_wake_after(tw);
>    }
>
>    /* uninstall ISR */
> diff --git a/c/src/lib/libbsp/arm/tms570/include/tms570-pinmux.h b/c/src/lib/libbsp/arm/tms570/include/tms570-pinmux.h
> index 46c4ae5..8979f23 100644
> --- a/c/src/lib/libbsp/arm/tms570/include/tms570-pinmux.h
> +++ b/c/src/lib/libbsp/arm/tms570/include/tms570-pinmux.h
> @@ -111,6 +111,15 @@ void tms570_bsp_pin_set_function(int pin_num, int pin_fnc);
>
>  void tms570_bsp_pin_clear_function(int pin_num, int pin_fnc);
>
> +static inline void
> +tms570_bsp_pin_to_pinmmrx(volatile uint32_t **pinmmrx, unsigned int *pin_shift,
> +                          int pin_num)
> +{
> +  pin_num = (pin_num & TMS570_PIN_NUM_MASK) >> TMS570_PIN_NUM_SHIFT;
> +  *pinmmrx = &TMS570_IOMM.PINMUX.PINMMR0 + (pin_num >> 2);
> +  *pin_shift = (pin_num & 0x3)*8;
> +}
> +
>  #endif
>
>  /** @} */
> diff --git a/c/src/lib/libbsp/arm/tms570/pinmux/pinmux.c b/c/src/lib/libbsp/arm/tms570/pinmux/pinmux.c
> index 79d6b1e..fed23fa 100644
> --- a/c/src/lib/libbsp/arm/tms570/pinmux/pinmux.c
> +++ b/c/src/lib/libbsp/arm/tms570/pinmux/pinmux.c
> @@ -31,7 +31,7 @@
>   * entries array. Predefined values for pins are in a format
>   * TMS570_BALL_<column><row> (for example TMS570_BALL_N19).
>   * The multiplexer allows to interconnect one pin to multiple
> - * signal sources/sings in the theory but it is usually bad choice.
> + * signal sources/sinks in the theory but it is usually bad choice.
>   * The function sets only specified function and clears all other
>   * connections.
>   *
> @@ -45,16 +45,12 @@ void
>  tms570_bsp_pin_set_function(int pin_num, int pin_fnc)
>  {
>    unsigned int pin_shift;
> -  typeof(TMS570_IOMM.PINMUX.PINMMR0) *pinmmrx;
> +  volatile uint32_t *pinmmrx;
>
>    if ( pin_fnc == TMS570_PIN_FNC_AUTO ) {
>      pin_fnc = (pin_num & TMS570_PIN_FNC_MASK) >> TMS570_PIN_FNC_SHIFT;
>    }
> -  pin_num = (pin_num & TMS570_PIN_NUM_MASK) >> TMS570_PIN_NUM_SHIFT;
> -
> -  pinmmrx = &TMS570_IOMM.PINMUX.PINMMR0;
> -  pinmmrx += (pin_num >> 2);
> -  pin_shift = (pin_num & 0x3)*8;
> +  tms570_bsp_pin_to_pinmmrx(&pinmmrx, &pin_shift, pin_num);
>    *pinmmrx = (*pinmmrx & ~(0xff << pin_shift)) | (1 << (pin_fnc + pin_shift));
>  }
>
> @@ -74,15 +70,11 @@ void
>  tms570_bsp_pin_clear_function(int pin_num, int pin_fnc)
>  {
>    unsigned int pin_shift;
> -  typeof(TMS570_IOMM.PINMUX.PINMMR0) *pinmmrx;
> +  volatile uint32_t *pinmmrx;
>
>    if ( pin_fnc == TMS570_PIN_FNC_AUTO ) {
>      pin_fnc = (pin_num & TMS570_PIN_FNC_MASK) >> TMS570_PIN_FNC_SHIFT;
>    }
> -  pin_num = (pin_num & TMS570_PIN_NUM_MASK) >> TMS570_PIN_NUM_SHIFT;
> -
> -  pinmmrx = &TMS570_IOMM.PINMUX.PINMMR0;
> -  pinmmrx += (pin_num >> 2);
> -  pin_shift = (pin_num & 0x3)*8;
> +  tms570_bsp_pin_to_pinmmrx(&pinmmrx, &pin_shift, pin_num);
>    *pinmmrx = *pinmmrx & ~(1 << (pin_fnc+pin_shift));
>  }
> --
> 1.9.1
>
> _______________________________________________
> devel mailing list
> devel at rtems.org
> http://lists.rtems.org/mailman/listinfo/devel



More information about the devel mailing list