From 16398c2d067ebbb462a2b864ceb81f00d7c32fb6 Mon Sep 17 00:00:00 2001 From: Armando Date: Fri, 23 Sep 2022 17:28:36 +0800 Subject: [PATCH] mmu: move mem_caps macro to hal/mmu_types.h as an enum type --- components/esp_psram/ext_mem_layout.c | 2 +- components/esp_psram/mmu.c | 4 ++-- components/esp_psram/mmu.h | 10 ++-------- components/hal/include/hal/mmu_types.h | 9 +++++++++ 4 files changed, 14 insertions(+), 11 deletions(-) diff --git a/components/esp_psram/ext_mem_layout.c b/components/esp_psram/ext_mem_layout.c index 1a5a61dc89..6afbdca131 100644 --- a/components/esp_psram/ext_mem_layout.c +++ b/components/esp_psram/ext_mem_layout.c @@ -8,7 +8,7 @@ #include "sdkconfig.h" #include "soc/ext_mem_defs.h" #include "ext_mem_layout.h" -#include "mmu.h" +#include "hal/mmu_types.h" #if CONFIG_IDF_TARGET_ESP32 diff --git a/components/esp_psram/mmu.c b/components/esp_psram/mmu.c index 383ad8409f..863b950ba8 100644 --- a/components/esp_psram/mmu.c +++ b/components/esp_psram/mmu.c @@ -184,7 +184,7 @@ void esp_mmu_init(void) assert(available_region_idx == region_num); } -esp_err_t esp_mmu_get_max_consecutive_free_block(int caps, size_t *out_len) +esp_err_t esp_mmu_get_max_consecutive_free_block(mmu_mem_caps_t caps, size_t *out_len) { ESP_RETURN_ON_FALSE(out_len, ESP_ERR_INVALID_ARG, TAG, "null pointer"); if (caps & MMU_MEM_CAP_EXEC) { @@ -210,7 +210,7 @@ esp_err_t esp_mmu_get_max_consecutive_free_block(int caps, size_t *out_len) return ESP_OK; } -esp_err_t esp_mmu_reserve_block_with_caps(size_t size, uint32_t caps, const void **out_ptr) +esp_err_t esp_mmu_reserve_block_with_caps(size_t size, mmu_mem_caps_t caps, const void **out_ptr) { ESP_RETURN_ON_FALSE(out_ptr, ESP_ERR_INVALID_ARG, TAG, "null pointer"); if (caps & MMU_MEM_CAP_EXEC) { diff --git a/components/esp_psram/mmu.h b/components/esp_psram/mmu.h index 39e77782f9..705f3cc2e5 100644 --- a/components/esp_psram/mmu.h +++ b/components/esp_psram/mmu.h @@ -24,12 +24,6 @@ extern "C" { */ -#define MMU_MEM_CAP_EXEC (1<<0) -#define MMU_MEM_CAP_READ (1<<1) -#define MMU_MEM_CAP_WRITE (1<<2) -#define MMU_MEM_CAP_32BIT (1<<3) -#define MMU_MEM_CAP_8BIT (1<<4) - /** * @brief Initialise the MMU driver * @@ -47,7 +41,7 @@ void esp_mmu_init(void); * - ESP_OK: On success * - ESP_ERR_INVALID_ARG: Invalid arguments, could be null pointer */ -esp_err_t esp_mmu_get_max_consecutive_free_block(int caps, size_t *out_len); +esp_err_t esp_mmu_get_max_consecutive_free_block(mmu_mem_caps_t caps, size_t *out_len); /** * @brief Reserve a consecutive external virtual memory block, with given capabilities and size @@ -61,7 +55,7 @@ esp_err_t esp_mmu_get_max_consecutive_free_block(int caps, size_t *out_len); * - ESP_ERR_INVALID_ARG: Invalid arguments, could be wrong caps makeup, or null pointer * - ESP_ERR_NOT_FOUND: Didn't find enough memory with give caps */ -esp_err_t esp_mmu_reserve_block_with_caps(size_t size, uint32_t caps, const void **out_ptr); +esp_err_t esp_mmu_reserve_block_with_caps(size_t size, mmu_mem_caps_t caps, const void **out_ptr); /** * @brief Dump internal memory region usage diff --git a/components/hal/include/hal/mmu_types.h b/components/hal/include/hal/mmu_types.h index 37a3a2cd5d..8fbd02c566 100644 --- a/components/hal/include/hal/mmu_types.h +++ b/components/hal/include/hal/mmu_types.h @@ -6,11 +6,20 @@ #pragma once +#include "esp_bit_defs.h" #ifdef __cplusplus extern "C" { #endif +typedef enum { + MMU_MEM_CAP_EXEC = BIT(0), + MMU_MEM_CAP_READ = BIT(1), + MMU_MEM_CAP_WRITE = BIT(2), + MMU_MEM_CAP_32BIT = BIT(3), + MMU_MEM_CAP_8BIT = BIT(4), +} mmu_mem_caps_t; + /** * MMU Page size */