mirror of
https://github.com/espressif/esp-idf.git
synced 2026-10-02 03:00:34 +03:00
refactor(esp_common): centralize ALIGN_UP/ALIGN_DOWN into esp_macros.h
Remove ~50 duplicate local definitions of ALIGN_UP/ALIGN_DOWN/ALIGN_UP_BY/ ALIGN_DOWN_BY across the codebase and replace them with canonical ESP_ALIGN_UP/ESP_ALIGN_DOWN from esp_macros.h.
This commit is contained in:
@@ -91,6 +91,20 @@ static inline __attribute__((always_inline, __noreturn__)) void esp_infinite_loo
|
||||
}
|
||||
#define ESP_INFINITE_LOOP() esp_infinite_loop()
|
||||
|
||||
/**
|
||||
* @brief Round value up to a given alignment (must be a power of 2)
|
||||
* @param val Value to align
|
||||
* @param align Alignment value (must be a power of 2)
|
||||
*/
|
||||
#define ESP_ALIGN_UP(val, align) (((val) + ((align) - 1)) & ~((align) - 1))
|
||||
|
||||
/**
|
||||
* @brief Round value down to a given alignment (must be a power of 2)
|
||||
* @param val Value to align
|
||||
* @param align Alignment value (must be a power of 2)
|
||||
*/
|
||||
#define ESP_ALIGN_DOWN(val, align) ((val) & ~((align) - 1))
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -13,12 +13,11 @@
|
||||
#include "hal/cache_ll.h"
|
||||
#include "hal/cache_hal.h"
|
||||
#include "esp_cache.h"
|
||||
#include "esp_macros.h"
|
||||
#if CONFIG_IDF_TARGET_ESP32
|
||||
#include "esp_private/esp_psram_extram.h"
|
||||
#endif
|
||||
|
||||
#define ALIGN_UP(num, align) (((num) + ((align) - 1)) & ~((align) - 1))
|
||||
|
||||
ESP_LOG_ATTR_TAG(TAG, "attr_test");
|
||||
|
||||
extern int _rtc_noinit_start;
|
||||
@@ -107,7 +106,7 @@ static void write_spiram_and_reset(void)
|
||||
#else
|
||||
size_t psram_alignment = cache_hal_get_cache_line_size(CACHE_LL_LEVEL_EXT_MEM, CACHE_TYPE_DATA);
|
||||
uint32_t ext_noinit_size = sizeof(s_noinit_buffer);
|
||||
TEST_ESP_OK(esp_cache_msync(&s_noinit_buffer, ALIGN_UP(ext_noinit_size, psram_alignment), ESP_CACHE_MSYNC_FLAG_DIR_C2M));
|
||||
TEST_ESP_OK(esp_cache_msync(&s_noinit_buffer, ESP_ALIGN_UP(ext_noinit_size, psram_alignment), ESP_CACHE_MSYNC_FLAG_DIR_C2M));
|
||||
#endif
|
||||
|
||||
printf("Restarting\n");
|
||||
|
||||
Reference in New Issue
Block a user