diff --git a/common_arm/flash_data/flashmem.h b/common_arm/flash_data/flashmem.h index 2a53e0e4b..a9969bff1 100644 --- a/common_arm/flash_data/flashmem.h +++ b/common_arm/flash_data/flashmem.h @@ -121,10 +121,6 @@ extern uint8_t spi_flash_pages64k; bool FlashDetect(void); -#ifndef ARRAYLEN -# define ARRAYLEN(x) (sizeof(x)/sizeof((x)[0])) -#endif - #endif // #ifndef AS_BOOTROM #endif // FLASHMEM_H_ diff --git a/common_arm/fpga/fpga_gw_jtag.c b/common_arm/fpga/fpga_gw_jtag.c index a08fe78e1..0555cae28 100644 --- a/common_arm/fpga/fpga_gw_jtag.c +++ b/common_arm/fpga/fpga_gw_jtag.c @@ -6,6 +6,7 @@ */ #include +#include "commonutil.h" #include "fpga_gw_jtag.h" #define INST_BYPASS 0xFF @@ -105,12 +106,9 @@ static const device_map_t device_map[] = { // #define ID_GW1NS_2C 0x0300181B }; -// 计算当前设备映射表中的设备型号数量 -#define DEVICE_SIZE (sizeof(device_map) / sizeof(device_map[0])) - // 根据ID索引到具体的设备信息映射表上,如果没有发现对应的设备存在,则返回NULL static const device_map_t *get_device_map_by_idcode(void) { - for (size_t i = 0; i < DEVICE_SIZE; i++) { + for (size_t i = 0; i < ARRAYLEN(device_map); i++) { if (device_map[i].idcode == cached_idcode) { return &device_map[i]; } diff --git a/common_arm/gpio/gpio_hw_at32.h b/common_arm/gpio/gpio_hw_at32.h index 711d0311e..37dfc9bd5 100644 --- a/common_arm/gpio/gpio_hw_at32.h +++ b/common_arm/gpio/gpio_hw_at32.h @@ -2,6 +2,7 @@ #define GPIO_HW_AT32_H_ #include "common.h" +#include "commonutil.h" #include "config_gpio.h" @@ -11,7 +12,7 @@ #define AT32_GPIO_PERIPH_CLKS_ENABLE(...) \ do { \ const crm_periph_clock_type args[] = { __VA_ARGS__ }; \ - for (size_t i = 0; i < sizeof(args) / sizeof(args[0]); ++i) { \ + for (size_t i = 0; i < ARRAYLEN(args); ++i) { \ crm_periph_clock_enable(args[i], TRUE); \ } \ } while(0) diff --git a/common_arm/sys/sys_hw_at32.c b/common_arm/sys/sys_hw_at32.c index 1884ddd2c..e64bfe9d9 100644 --- a/common_arm/sys/sys_hw_at32.c +++ b/common_arm/sys/sys_hw_at32.c @@ -2,6 +2,7 @@ // Created by dxl on 2026/5/23. // +#include "commonutil.h" #include "sys_apis.h" #include "config_gpio_proxmark5.h" @@ -419,7 +420,7 @@ void system_simple_reset(void) { void __NO_RETURN JumpToAnyImage(uint32_t stack_top, uint32_t entry_point) { // Disable and clear all pending interrupts in the Bootloader __disable_irq(); - for (int i = 0; i < sizeof(NVIC->ICER) / sizeof(NVIC->ICER[0]); i++) { + for (int i = 0; i < ARRAYLEN(NVIC->ICER); i++) { NVIC->ICER[i] = 0xFFFFFFFF; NVIC->ICPR[i] = 0xFFFFFFFF; }