nuttx: replace all ARRAY_SIZE()/ARRAYSIZE() to nitems()

Signed-off-by: chao an <anchao@xiaomi.com>
This commit is contained in:
chao an
2023-02-02 20:31:22 +08:00
committed by Xiang Xiao
parent cf0769d613
commit 3a0fdb019d
95 changed files with 291 additions and 451 deletions
@@ -27,6 +27,8 @@
#include <stdbool.h>
#include <debug.h>
#include <sys/param.h>
#include <nuttx/board.h>
#include <arch/board/board.h>
@@ -35,12 +37,6 @@
#ifdef CONFIG_ARCH_LEDS
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#define ARRAYSIZE(x) (sizeof((x)) / sizeof((x)[0]))
/****************************************************************************
* Private Data
****************************************************************************/
@@ -81,7 +77,7 @@ void board_autoled_initialize(void)
/* Configure the LD1 GPIO for output. Initial state is OFF */
for (i = 0; i < ARRAYSIZE(g_ledmap); i++)
for (i = 0; i < nitems(g_ledmap); i++)
{
stm32_configgpio(g_ledmap[i]);
}
@@ -27,6 +27,8 @@
#include <stdbool.h>
#include <debug.h>
#include <sys/param.h>
#include <nuttx/board.h>
#include <arch/board/board.h>
@@ -35,12 +37,6 @@
#ifndef CONFIG_ARCH_LEDS
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#define ARRAYSIZE(x) (sizeof((x)) / sizeof((x)[0]))
/****************************************************************************
* Private Data
****************************************************************************/
@@ -77,7 +73,7 @@ uint32_t board_userled_initialize(void)
/* Configure LED1-3 GPIOs for output */
for (i = 0; i < ARRAYSIZE(g_ledcfg); i++)
for (i = 0; i < nitems(g_ledcfg); i++)
{
stm32_configgpio(g_ledcfg[i]);
}
@@ -97,7 +93,7 @@ uint32_t board_userled_initialize(void)
void board_userled(int led, bool ledon)
{
if ((unsigned)led < ARRAYSIZE(g_ledcfg))
if ((unsigned)led < nitems(g_ledcfg))
{
stm32_gpiowrite(g_ledcfg[led], ledon);
}
@@ -120,7 +116,7 @@ void board_userled_all(uint32_t ledset)
/* Configure LED1-3 GPIOs for output */
for (i = 0; i < ARRAYSIZE(g_ledcfg); i++)
for (i = 0; i < nitems(g_ledcfg); i++)
{
stm32_gpiowrite(g_ledcfg[i], (ledset & (1 << i)) != 0);
}
@@ -27,6 +27,8 @@
#include <stdbool.h>
#include <debug.h>
#include <sys/param.h>
#include <nuttx/board.h>
#include <arch/board/board.h>
@@ -35,12 +37,6 @@
#ifdef CONFIG_ARCH_LEDS
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#define ARRAYSIZE(x) (sizeof((x)) / sizeof((x)[0]))
/****************************************************************************
* Private Data
****************************************************************************/
@@ -81,7 +77,7 @@ void board_autoled_initialize(void)
/* Configure the LD1 GPIO for output. Initial state is OFF */
for (i = 0; i < ARRAYSIZE(g_ledmap); i++)
for (i = 0; i < nitems(g_ledmap); i++)
{
stm32_configgpio(g_ledmap[i]);
}
@@ -27,6 +27,8 @@
#include <stdbool.h>
#include <debug.h>
#include <sys/param.h>
#include <nuttx/board.h>
#include <arch/board/board.h>
@@ -35,12 +37,6 @@
#ifndef CONFIG_ARCH_LEDS
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#define ARRAYSIZE(x) (sizeof((x)) / sizeof((x)[0]))
/****************************************************************************
* Private Data
****************************************************************************/
@@ -77,7 +73,7 @@ uint32_t board_userled_initialize(void)
/* Configure LED1-3 GPIOs for output */
for (i = 0; i < ARRAYSIZE(g_ledcfg); i++)
for (i = 0; i < nitems(g_ledcfg); i++)
{
stm32_configgpio(g_ledcfg[i]);
}
@@ -97,7 +93,7 @@ uint32_t board_userled_initialize(void)
void board_userled(int led, bool ledon)
{
if ((unsigned)led < ARRAYSIZE(g_ledcfg))
if ((unsigned)led < nitems(g_ledcfg))
{
stm32_gpiowrite(g_ledcfg[led], ledon);
}
@@ -120,7 +116,7 @@ void board_userled_all(uint32_t ledset)
/* Configure LED1-3 GPIOs for output */
for (i = 0; i < ARRAYSIZE(g_ledcfg); i++)
for (i = 0; i < nitems(g_ledcfg); i++)
{
stm32_gpiowrite(g_ledcfg[i], (ledset & (1 << i)) != 0);
}
@@ -27,6 +27,8 @@
#include <stdbool.h>
#include <debug.h>
#include <sys/param.h>
#include <nuttx/board.h>
#include <arch/board/board.h>
@@ -34,12 +36,6 @@
#include "nucleo-144.h"
#ifdef CONFIG_ARCH_LEDS
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#define ARRAYSIZE(x) (sizeof((x)) / sizeof((x)[0]))
/****************************************************************************
* Private Data
****************************************************************************/
@@ -80,7 +76,7 @@ void board_autoled_initialize(void)
/* Configure the LD1 GPIO for output. Initial state is OFF */
for (i = 0; i < ARRAYSIZE(g_ledmap); i++)
for (i = 0; i < nitems(g_ledmap); i++)
{
stm32_configgpio(g_ledmap[i]);
}
@@ -36,6 +36,8 @@
#include <debug.h>
#include <syslog.h>
#include <sys/param.h>
#include <nuttx/fs/fs.h>
#include "arm_internal.h"
@@ -102,15 +104,13 @@
0 \
}
#define ARRAYSIZE(a) (sizeof((a))/sizeof(a[0]))
/* For Assert keep this much of the file name */
#define MAX_FILE_PATH_LENGTH 40
#define HEADER_TIME_FMT "%Y-%m-%d-%H:%M:%S"
#define HEADER_TIME_FMT_NUM (2+ 0+ 0+ 0+ 0+ 0)
#define HEADER_TIME_FMT_LEN (((ARRAYSIZE(HEADER_TIME_FMT)-1) + \
#define HEADER_TIME_FMT_LEN (((nitems(HEADER_TIME_FMT)-1) + \
HEADER_TIME_FMT_NUM))
/****************************************************************************
@@ -465,8 +465,8 @@ void board_crashdump(uintptr_t sp, struct tcb_s *tcb,
if ((pdump->info.flags & INTSTACK_PRESENT) != 0)
{
stack_word_t *ps = (stack_word_t *) pdump->info.stacks.interrupt.sp;
copy_reverse(pdump->istack, &ps[ARRAYSIZE(pdump->istack) / 2],
ARRAYSIZE(pdump->istack));
copy_reverse(pdump->istack, &ps[nitems(pdump->istack) / 2],
nitems(pdump->istack));
}
/* Is it Invalid? */
@@ -487,8 +487,8 @@ void board_crashdump(uintptr_t sp, struct tcb_s *tcb,
if ((pdump->info.flags & USERSTACK_PRESENT) != 0)
{
stack_word_t *ps = (stack_word_t *) pdump->info.stacks.user.sp;
copy_reverse(pdump->ustack, &ps[ARRAYSIZE(pdump->ustack) / 2],
ARRAYSIZE(pdump->ustack));
copy_reverse(pdump->ustack, &ps[nitems(pdump->ustack) / 2],
nitems(pdump->ustack));
}
/* Is it Invalid? */
@@ -29,6 +29,8 @@
#include <errno.h>
#include <debug.h>
#include <sys/param.h>
#include <nuttx/spi/spi.h>
#include <arch/board/board.h>
@@ -45,8 +47,6 @@
* Pre-processor Definitions
****************************************************************************/
#define ARRAYSIZE(x) (sizeof((x)) / sizeof((x)[0]))
#if defined(CONFIG_NUCLEO_SPI1_TEST)
# if defined(CONFIG_NUCLEO_SPI1_TEST_MODE0)
# define CONFIG_NUCLEO_SPI1_TEST_MODE SPIDEV_MODE0
@@ -200,7 +200,7 @@ void weak_function stm32_spidev_initialize(void)
/* Configure SPI CS GPIO for output */
#if defined(CONFIG_STM32F4_SPI1)
for (int i = 0; i < ARRAYSIZE(g_spi1gpio); i++)
for (int i = 0; i < nitems(g_spi1gpio); i++)
{
if (g_spi1gpio[i] != 0)
{
@@ -210,7 +210,7 @@ void weak_function stm32_spidev_initialize(void)
#endif
#if defined(CONFIG_STM32F4_SPI2)
for (int i = 0; i < ARRAYSIZE(g_spi2gpio); i++)
for (int i = 0; i < nitems(g_spi2gpio); i++)
{
if (g_spi2gpio[i] != 0)
{
@@ -220,7 +220,7 @@ void weak_function stm32_spidev_initialize(void)
#endif
#if defined(CONFIG_STM32F4_SPI3)
for (int i = 0; i < ARRAYSIZE(g_spi3gpio); i++)
for (int i = 0; i < nitems(g_spi3gpio); i++)
{
if (g_spi3gpio[i] != 0)
{
@@ -451,7 +451,7 @@ int stm32_spidev_bus_test(void)
SPI_SETFREQUENCY(spi1, CONFIG_NUCLEO_SPI1_TEST_FREQ);
SPI_SETBITS(spi1, CONFIG_NUCLEO_SPI1_TEST_BITS);
SPI_SETMODE(spi1, CONFIG_NUCLEO_SPI1_TEST_MODE);
SPI_EXCHANGE(spi1, tx, NULL, ARRAYSIZE(CONFIG_NUCLEO_SPI_TEST_MESSAGE));
SPI_EXCHANGE(spi1, tx, NULL, nitems(CONFIG_NUCLEO_SPI_TEST_MESSAGE));
#endif
#if defined(CONFIG_NUCLEO_SPI2_TEST)
@@ -468,7 +468,7 @@ int stm32_spidev_bus_test(void)
SPI_SETFREQUENCY(spi2, CONFIG_NUCLEO_SPI2_TEST_FREQ);
SPI_SETBITS(spi2, CONFIG_NUCLEO_SPI2_TEST_BITS);
SPI_SETMODE(spi2, CONFIG_NUCLEO_SPI2_TEST_MODE);
SPI_EXCHANGE(spi2, tx, NULL, ARRAYSIZE(CONFIG_NUCLEO_SPI_TEST_MESSAGE));
SPI_EXCHANGE(spi2, tx, NULL, nitems(CONFIG_NUCLEO_SPI_TEST_MESSAGE));
#endif
#if defined(CONFIG_NUCLEO_SPI3_TEST)
@@ -485,7 +485,7 @@ int stm32_spidev_bus_test(void)
SPI_SETFREQUENCY(spi3, CONFIG_NUCLEO_SPI3_TEST_FREQ);
SPI_SETBITS(spi3, CONFIG_NUCLEO_SPI3_TEST_BITS);
SPI_SETMODE(spi3, CONFIG_NUCLEO_SPI3_TEST_MODE);
SPI_EXCHANGE(spi3, tx, NULL, ARRAYSIZE(CONFIG_NUCLEO_SPI_TEST_MESSAGE));
SPI_EXCHANGE(spi3, tx, NULL, nitems(CONFIG_NUCLEO_SPI_TEST_MESSAGE));
#endif
return OK;
@@ -27,6 +27,8 @@
#include <stdbool.h>
#include <debug.h>
#include <sys/param.h>
#include <nuttx/board.h>
#include <arch/board/board.h>
@@ -35,12 +37,6 @@
#ifndef CONFIG_ARCH_LEDS
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#define ARRAYSIZE(x) (sizeof((x)) / sizeof((x)[0]))
/****************************************************************************
* Private Data
****************************************************************************/
@@ -77,7 +73,7 @@ uint32_t board_userled_initialize(void)
/* Configure LED1-3 GPIOs for output */
for (i = 0; i < ARRAYSIZE(g_ledcfg); i++)
for (i = 0; i < nitems(g_ledcfg); i++)
{
stm32_configgpio(g_ledcfg[i]);
}
@@ -97,7 +93,7 @@ uint32_t board_userled_initialize(void)
void board_userled(int led, bool ledon)
{
if ((unsigned)led < ARRAYSIZE(g_ledcfg))
if ((unsigned)led < nitems(g_ledcfg))
{
stm32_gpiowrite(g_ledcfg[led], ledon);
}
@@ -121,7 +117,7 @@ void board_userled_all(uint32_t ledset)
/* Configure LED1-3 GPIOs for output */
for (i = 0; i < ARRAYSIZE(g_ledcfg); i++)
for (i = 0; i < nitems(g_ledcfg); i++)
{
stm32_gpiowrite(g_ledcfg[i], (ledset & (1 << i)) != 0);
}