From 98787f4717a18a7b9b16612769bc85b67c9e4fef Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 9 May 2013 14:23:34 -0600 Subject: [PATCH] Various changes and bigfixes for problems detected by CppCheck --- arch/arm/src/imx/imx_spi.c | 9 ++++++--- arch/arm/src/kinetis/kinetis_pindma.c | 10 +++++++++- arch/arm/src/kinetis/kinetis_pinirq.c | 2 +- arch/arm/src/kl/kl_gpio.h | 7 ++++++- arch/z80/src/z8/z8_lowuart.c | 5 +++-- 5 files changed, 25 insertions(+), 8 deletions(-) diff --git a/arch/arm/src/imx/imx_spi.c b/arch/arm/src/imx/imx_spi.c index 5ee601263d..4d846af3ce 100644 --- a/arch/arm/src/imx/imx_spi.c +++ b/arch/arm/src/imx/imx_spi.c @@ -1,7 +1,7 @@ /**************************************************************************** * arch/arm/src/imx/imx_spi.c * - * Copyright (C) 2009-2010 Gregory Nutt. All rights reserved. + * Copyright (C) 2009-2010, 2013 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -728,9 +728,12 @@ static int spi_lock(FAR struct spi_dev_s *dev, bool lock) static uint32_t spi_setfrequency(FAR struct spi_dev_s *dev, uint32_t frequency) { struct imx_spidev_s *priv = (struct imx_spidev_s *)dev; - uint32_t actual = priv->actual; + uint32_t actual; - if (priv && frequency != priv->frequency) + DEBUGASSERT(priv); + actual = priv->actual; + + if (frequency != priv->frequency) { uint32_t freqbits; uint32_t regval; diff --git a/arch/arm/src/kinetis/kinetis_pindma.c b/arch/arm/src/kinetis/kinetis_pindma.c index 91132a6a74..40acdc036b 100644 --- a/arch/arm/src/kinetis/kinetis_pindma.c +++ b/arch/arm/src/kinetis/kinetis_pindma.c @@ -1,7 +1,7 @@ /**************************************************************************** * arch/arm/src/kinetis/kinetis_pindma.c * - * Copyright (C) 2011 Gregory Nutt. All rights reserved. + * Copyright (C) 201, 2013 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -84,6 +84,10 @@ void kinetis_pindmaenable(uint32_t pinset) DEBUGASSERT(port < KINETIS_NPORTS); if (port < KINETIS_NPORTS) { + /* Get the base address of PORT block for this port */ + + base = KINETIS_PORT_BASE(port); + /* Modify the IRQC field of the port PCR register in order to enable DMA. */ regval = getreg32(base + KINETIS_PORT_PCR_OFFSET(pin)); @@ -134,6 +138,10 @@ void kinetis_pindmadisable(uint32_t pinset) DEBUGASSERT(port < KINETIS_NPORTS); if (port < KINETIS_NPORTS) { + /* Get the base address of PORT block for this port */ + + base = KINETIS_PORT_BASE(port); + /* Clear the IRQC field of the port PCR register in order to disable DMA. */ regval = getreg32(base + KINETIS_PORT_PCR_OFFSET(pin)); diff --git a/arch/arm/src/kinetis/kinetis_pinirq.c b/arch/arm/src/kinetis/kinetis_pinirq.c index 537e7be9f2..6535ac3a20 100644 --- a/arch/arm/src/kinetis/kinetis_pinirq.c +++ b/arch/arm/src/kinetis/kinetis_pinirq.c @@ -1,7 +1,7 @@ /**************************************************************************** * arch/arm/src/kinetis/kinetis_pinirq.c * - * Copyright (C) 2011 Gregory Nutt. All rights reserved. + * Copyright (C) 2011, 2013 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without diff --git a/arch/arm/src/kl/kl_gpio.h b/arch/arm/src/kl/kl_gpio.h index 647fbe45d0..e1db46d9ab 100644 --- a/arch/arm/src/kl/kl_gpio.h +++ b/arch/arm/src/kl/kl_gpio.h @@ -313,7 +313,8 @@ typedef uint32_t gpio_cfgset_t; #undef EXTERN #if defined(__cplusplus) #define EXTERN extern "C" -extern "C" { +extern "C" +{ #else #define EXTERN extern #endif @@ -353,5 +354,9 @@ void kl_gpiowrite(uint32_t pinset, bool value); bool kl_gpioread(uint32_t pinset); +#undef EXTERN +#if defined(__cplusplus) +} +#endif #endif /* __ASSEMBLY__ */ #endif /* __ARCH_ARM_SRC_KL_KINETIS_GPIO_H */ diff --git a/arch/z80/src/z8/z8_lowuart.c b/arch/z80/src/z8/z8_lowuart.c index cf3f9b3247..730ed1b4cd 100644 --- a/arch/z80/src/z8/z8_lowuart.c +++ b/arch/z80/src/z8/z8_lowuart.c @@ -80,11 +80,10 @@ void up_lowserialinit(void) uint8_t val; #ifdef CONFIG_UART0_SERIAL_CONSOLE + /* Set the baudrate */ brg = (freq +(uint32_t)CONFIG_UART0_BAUD * 8) /((uint32_t)CONFIG_UART0_BAUD * 16) ; - /* Set the baudrate */ - putreg8(brg >> 8, U0BRH); putreg8(brg & 0xff, U0BRL); @@ -107,6 +106,8 @@ void up_lowserialinit(void) #elif defined(EZ8_UART1) && defined(CONFIG_UART1_SERIAL_CONSOLE) /* Set the baudrate */ + brg = (freq +(uint32_t)CONFIG_UART1_BAUD * 8) /((uint32_t)CONFIG_UART1_BAUD * 16) ; + putreg8(brg >> 8, U1BRH); putreg8(brg & 0xff, U1BRL);