diff --git a/components/app_trace/app_trace_util.c b/components/app_trace/app_trace_util.c index da0a8d58a4..0558351b75 100644 --- a/components/app_trace/app_trace_util.c +++ b/components/app_trace/app_trace_util.c @@ -15,7 +15,7 @@ #include "freertos/FreeRTOS.h" #include "freertos/task.h" #include "esp_app_trace_util.h" -#include "esp_clk.h" +#include "esp32/clk.h" /////////////////////////////////////////////////////////////////////////////// ///////////////////////////////// TIMEOUT ///////////////////////////////////// diff --git a/components/app_trace/sys_view/Sample/Config/SEGGER_SYSVIEW_Config_FreeRTOS.c b/components/app_trace/sys_view/Sample/Config/SEGGER_SYSVIEW_Config_FreeRTOS.c index 2df7ee0c12..6c4a53eb9b 100644 --- a/components/app_trace/sys_view/Sample/Config/SEGGER_SYSVIEW_Config_FreeRTOS.c +++ b/components/app_trace/sys_view/Sample/Config/SEGGER_SYSVIEW_Config_FreeRTOS.c @@ -67,7 +67,7 @@ Revision: $Rev: 3734 $ #include "esp_app_trace.h" #include "esp_app_trace_util.h" #include "esp_intr_alloc.h" -#include "esp_clk.h" +#include "esp32/clk.h" extern const SEGGER_SYSVIEW_OS_API SYSVIEW_X_OS_TraceAPI; diff --git a/components/bt/bt.c b/components/bt/bt.c index dc17d9b025..a7126bdf09 100644 --- a/components/bt/bt.c +++ b/components/bt/bt.c @@ -42,7 +42,7 @@ #include "soc/rtc.h" #include "soc/rtc_cntl_reg.h" #include "soc/soc_memory_layout.h" -#include "esp_clk.h" +#include "esp32/clk.h" #include "esp_coexist_internal.h" diff --git a/components/driver/uart.c b/components/driver/uart.c index de872d881d..7761089b86 100644 --- a/components/driver/uart.c +++ b/components/driver/uart.c @@ -18,7 +18,7 @@ #include "esp_intr_alloc.h" #include "esp_log.h" #include "esp_err.h" -#include "esp_clk.h" +#include "esp32/clk.h" #include "malloc.h" #include "freertos/FreeRTOS.h" #include "freertos/semphr.h" diff --git a/components/esp32/cache_err_int.c b/components/esp32/cache_err_int.c index a6de81ce65..b844c72f71 100644 --- a/components/esp32/cache_err_int.c +++ b/components/esp32/cache_err_int.c @@ -29,7 +29,7 @@ #include "esp_attr.h" #include "soc/dport_reg.h" #include "sdkconfig.h" -#include "esp_dport_access.h" +#include "esp32/dport_access.h" void esp_cache_err_int_init() { diff --git a/components/esp32/clk.c b/components/esp32/clk.c index c965511cbf..d8120ebad2 100644 --- a/components/esp32/clk.c +++ b/components/esp32/clk.c @@ -19,7 +19,7 @@ #include "sdkconfig.h" #include "esp_attr.h" #include "esp_log.h" -#include "esp_clk.h" +#include "esp32/clk.h" #include "esp_clk_internal.h" #include "rom/ets_sys.h" #include "rom/uart.h" diff --git a/components/esp32/cpu_start.c b/components/esp32/cpu_start.c index 7e45abb037..b4d067c461 100644 --- a/components/esp32/cpu_start.c +++ b/components/esp32/cpu_start.c @@ -49,23 +49,23 @@ #include "esp_spi_flash.h" #include "esp_ipc.h" #include "esp_crosscore_int.h" -#include "esp_dport_access.h" +#include "esp32/dport_access.h" #include "esp_log.h" #include "esp_vfs_dev.h" #include "esp_newlib.h" -#include "esp_brownout.h" +#include "esp32/brownout.h" #include "esp_int_wdt.h" #include "esp_task.h" #include "esp_task_wdt.h" #include "esp_phy_init.h" -#include "esp_cache_err_int.h" +#include "esp32/cache_err_int.h" #include "esp_coexist_internal.h" #include "esp_panic.h" #include "esp_core_dump.h" #include "esp_app_trace.h" #include "esp_dbg_stubs.h" #include "esp_efuse.h" -#include "esp_spiram.h" +#include "esp32/spiram.h" #include "esp_clk_internal.h" #include "esp_timer.h" #include "esp_pm.h" diff --git a/components/esp32/esp_himem.c b/components/esp32/esp_himem.c index 89e5b3237b..b2a55d385e 100644 --- a/components/esp32/esp_himem.c +++ b/components/esp32/esp_himem.c @@ -14,10 +14,10 @@ #include "freertos/FreeRTOS.h" #include "freertos/task.h" -#include "esp_spiram.h" +#include "esp32/spiram.h" #include "rom/cache.h" #include "sdkconfig.h" -#include "esp_himem.h" +#include "esp32/himem.h" #include "soc/soc.h" #include "esp_log.h" @@ -161,7 +161,7 @@ void __attribute__((constructor)) esp_himem_init() free(s_range_descriptor); return; } - ESP_EARLY_LOGI(TAG, "Initialized. Using last %d 32KB address blocks for bank switching on %d KB of physical memory.", + ESP_EARLY_LOGI(TAG, "Initialized. Using last %d 32KB address blocks for bank switching on %d KB of physical memory.", SPIRAM_BANKSWITCH_RESERVE, (paddr_end - paddr_start)/1024); } diff --git a/components/esp32/esp_timer_esp32.c b/components/esp32/esp_timer_esp32.c index 75e3a58fa5..70b840370f 100644 --- a/components/esp32/esp_timer_esp32.c +++ b/components/esp32/esp_timer_esp32.c @@ -19,7 +19,7 @@ #include "esp_attr.h" #include "esp_intr_alloc.h" #include "esp_log.h" -#include "esp_clk.h" +#include "esp32/clk.h" #include "esp_timer_impl.h" #include "soc/frc_timer_reg.h" #include "soc/rtc.h" diff --git a/components/esp32/hw_random.c b/components/esp32/hw_random.c index 1bd0e6300a..faf297503a 100644 --- a/components/esp32/hw_random.c +++ b/components/esp32/hw_random.c @@ -18,7 +18,7 @@ #include #include #include "esp_attr.h" -#include "esp_clk.h" +#include "esp32/clk.h" #include "soc/wdev_reg.h" #include "freertos/FreeRTOSConfig.h" #include "xtensa/core-macros.h" diff --git a/components/esp32/include/esp_brownout.h b/components/esp32/include/esp32/brownout.h similarity index 100% rename from components/esp32/include/esp_brownout.h rename to components/esp32/include/esp32/brownout.h diff --git a/components/esp32/include/esp_cache_err_int.h b/components/esp32/include/esp32/cache_err_int.h similarity index 100% rename from components/esp32/include/esp_cache_err_int.h rename to components/esp32/include/esp32/cache_err_int.h diff --git a/components/esp32/include/esp32/clk.h b/components/esp32/include/esp32/clk.h new file mode 100644 index 0000000000..9393fc1f5d --- /dev/null +++ b/components/esp32/include/esp32/clk.h @@ -0,0 +1,87 @@ +// Copyright 2015-2017 Espressif Systems (Shanghai) PTE LTD +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#pragma once +#include + +/** + * @file esp32/clk.h + * + * This file contains declarations of clock related functions. + */ + +/** + * @brief Get the calibration value of RTC slow clock + * + * The value is in the same format as returned by rtc_clk_cal (microseconds, + * in Q13.19 fixed-point format). + * + * @return the calibration value obtained using rtc_clk_cal, at startup time + */ +uint32_t esp_clk_slowclk_cal_get(); + +/** + * @brief Update the calibration value of RTC slow clock + * + * The value has to be in the same format as returned by rtc_clk_cal (microseconds, + * in Q13.19 fixed-point format). + * This value is used by timekeeping functions (such as gettimeofday) to + * calculate current time based on RTC counter value. + * @param value calibration value obtained using rtc_clk_cal + */ +void esp_clk_slowclk_cal_set(uint32_t value); + +/** + * @brief Return current CPU clock frequency + * When frequency switching is performed, this frequency may change. + * However it is guaranteed that the frequency never changes with a critical + * section. + * + * @return CPU clock frequency, in Hz + */ +int esp_clk_cpu_freq(void); + +/** + * @brief Return current APB clock frequency + * + * When frequency switching is performed, this frequency may change. + * However it is guaranteed that the frequency never changes with a critical + * section. + * + * @return APB clock frequency, in Hz + */ +int esp_clk_apb_freq(void); + +/** + * @brief Return frequency of the main XTAL + * + * Frequency of the main XTAL can be either auto-detected or set at compile + * time (see CONFIG_ESP32_XTAL_FREQ_SEL sdkconfig option). In both cases, this + * function returns the actual value at run time. + * + * @return XTAL frequency, in Hz + */ +int esp_clk_xtal_freq(void); + + +/** + * @brief Read value of RTC counter, converting it to microseconds + * @attention The value returned by this function may change abruptly when + * calibration value of RTC counter is updated via esp_clk_slowclk_cal_set + * function. This should not happen unless application calls esp_clk_slowclk_cal_set. + * In ESP-IDF, esp_clk_slowclk_cal_set is only called in startup code. + * + * @return Value or RTC counter, expressed in microseconds + */ +uint64_t esp_clk_rtc_time(); diff --git a/components/esp32/include/esp_dport_access.h b/components/esp32/include/esp32/dport_access.h similarity index 100% rename from components/esp32/include/esp_dport_access.h rename to components/esp32/include/esp32/dport_access.h diff --git a/components/esp32/include/esp32/himem.h b/components/esp32/include/esp32/himem.h new file mode 100644 index 0000000000..099d926015 --- /dev/null +++ b/components/esp32/include/esp32/himem.h @@ -0,0 +1,152 @@ +// Copyright 2018 Espressif Systems (Shanghai) PTE LTD +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +#pragma once + +#include +#include "esp_err.h" + +#ifdef __cplusplus +extern "C" { +#endif + +//Opaque pointers as handles for ram/range data +typedef struct esp_himem_ramdata_t *esp_himem_handle_t; +typedef struct esp_himem_rangedata_t *esp_himem_rangehandle_t; + +//ESP32 MMU block size +#define ESP_HIMEM_BLKSZ (0x8000) + +#define ESP_HIMEM_MAPFLAG_RO 1 /*!< Indicates that a mapping will only be read from. Note that this is unused for now. */ + +/** + * @brief Allocate a block in high memory + * + * @param size Size of the to-be-allocated block, in bytes. Note that this needs to be + * a multiple of the external RAM mmu block size (32K). + * @param[out] handle_out Handle to be returned + * @returns - ESP_OK if succesful + * - ESP_ERR_NO_MEM if out of memory + * - ESP_ERR_INVALID_SIZE if size is not a multiple of 32K + */ +esp_err_t esp_himem_alloc(size_t size, esp_himem_handle_t *handle_out); + + +/** + * @brief Allocate a memory region to map blocks into + * + * This allocates a contiguous CPU memory region that can be used to map blocks + * of physical memory into. + * + * @param size Size of the range to be allocated. Note this needs to be a multiple of + * the external RAM mmu block size (32K). + * @param[out] handle_out Handle to be returned + * @returns - ESP_OK if succesful + * - ESP_ERR_NO_MEM if out of memory or address space + * - ESP_ERR_INVALID_SIZE if size is not a multiple of 32K + */ +esp_err_t esp_himem_alloc_map_range(size_t size, esp_himem_rangehandle_t *handle_out); + +/** + * @brief Map a block of high memory into the CPUs address space + * + * This effectively makes the block available for read/write operations. + * + * @note The region to be mapped needs to have offsets and sizes that are aligned to the + * SPI RAM MMU block size (32K) + * + * @param handle Handle to the block of memory, as given by esp_himem_alloc + * @param range Range handle to map the memory in + * @param ram_offset Offset into the block of physical memory of the block to map + * @param range_offset Offset into the address range where the block will be mapped + * @param len Length of region to map + * @param flags One of ESP_HIMEM_MAPFLAG_* + * @param[out] out_ptr Pointer to variable to store resulting memory pointer in + * @returns - ESP_OK if the memory could be mapped + * - ESP_ERR_INVALID_ARG if offset, range or len aren't MMU-block-aligned (32K) + * - ESP_ERR_INVALID_SIZE if the offsets/lengths don't fit in the allocated memory or range + * - ESP_ERR_INVALID_STATE if a block in the selected ram offset/length is already mapped, or + * if a block in the selected range offset/length already has a mapping. + */ +esp_err_t esp_himem_map(esp_himem_handle_t handle, esp_himem_rangehandle_t range, size_t ram_offset, size_t range_offset, size_t len, int flags, void **out_ptr); + + +/** + * @brief Free a block of physical memory + * + * This clears out the associated handle making the memory available for re-allocation again. + * This will only succeed if none of the memory blocks currently have a mapping. + * + * @param handle Handle to the block of memory, as given by esp_himem_alloc + * @returns - ESP_OK if the memory is succesfully freed + * - ESP_ERR_INVALID_ARG if the handle still is (partially) mapped + */ +esp_err_t esp_himem_free(esp_himem_handle_t handle); + + + +/** + * @brief Free a mapping range + * + * This clears out the associated handle making the range available for re-allocation again. + * This will only succeed if none of the range blocks currently are used for a mapping. + * + * @param handle Handle to the range block, as given by esp_himem_alloc_map_range + * @returns - ESP_OK if the memory is succesfully freed + * - ESP_ERR_INVALID_ARG if the handle still is (partially) mapped to + */ +esp_err_t esp_himem_free_map_range(esp_himem_rangehandle_t handle); + + +/** + * @brief Unmap a region + * + * @param range Range handle + * @param ptr Pointer returned by esp_himem_map + * @param len Length of the block to be unmapped. Must be aligned to the SPI RAM MMU blocksize (32K) + * @returns - ESP_OK if the memory is succesfully unmapped, + * - ESP_ERR_INVALID_ARG if ptr or len are invalid. + */ +esp_err_t esp_himem_unmap(esp_himem_rangehandle_t range, void *ptr, size_t len); + + +/** + * @brief Get total amount of memory under control of himem API + * + * @returns Amount of memory, in bytes + */ +size_t esp_himem_get_phys_size(); + +/** + * @brief Get free amount of memory under control of himem API + * + * @returns Amount of free memory, in bytes + */ +size_t esp_himem_get_free_size(); + + +/** + * @brief Get amount of SPI memory address space needed for bankswitching + * + * @note This is also weakly defined in esp32/spiram.c and returns 0 there, so + * if no other function in this file is used, no memory is reserved. + * + * @returns Amount of reserved area, in bytes + */ +size_t esp_himem_reserved_area_size(); + + +#ifdef __cplusplus +} +#endif + diff --git a/components/esp32/include/esp32/spiram.h b/components/esp32/include/esp32/spiram.h new file mode 100644 index 0000000000..a55872cd4d --- /dev/null +++ b/components/esp32/include/esp32/spiram.h @@ -0,0 +1,116 @@ +// Copyright 2015-2017 Espressif Systems (Shanghai) PTE LTD +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at + +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + + +#ifndef __ESP_SPIRAM_H +#define __ESP_SPIRAM_H + +#include +#include +#include +#include "esp_err.h" + +typedef enum { + ESP_SPIRAM_SIZE_16MBITS = 0, /*!< SPI RAM size is 16 MBits */ + ESP_SPIRAM_SIZE_32MBITS = 1, /*!< SPI RAM size is 32 MBits */ + ESP_SPIRAM_SIZE_64MBITS = 2, /*!< SPI RAM size is 64 MBits */ + ESP_SPIRAM_SIZE_INVALID, /*!< SPI RAM size is invalid */ +} esp_spiram_size_t; + +/** + * @brief get SPI RAM size + * @return + * - ESP_SPIRAM_SIZE_INVALID if SPI RAM not enabled or not valid + * - SPI RAM size + */ +esp_spiram_size_t esp_spiram_get_chip_size(); + +/** + * @brief Initialize spiram interface/hardware. Normally called from cpu_start.c. + * + * @return ESP_OK on success + */ +esp_err_t esp_spiram_init(); + +/** + * @brief Configure Cache/MMU for access to external SPI RAM. + * + * Normally this function is called from cpu_start, if CONFIG_SPIRAM_BOOT_INIT + * option is enabled. Applications which need to enable SPI RAM at run time + * can disable CONFIG_SPIRAM_BOOT_INIT, and call this function later. + * + * @attention this function must be called with flash cache disabled. + */ +void esp_spiram_init_cache(); + + +/** + * @brief Memory test for SPI RAM. Should be called after SPI RAM is initialized and + * (in case of a dual-core system) the app CPU is online. This test overwrites the + * memory with crap, so do not call after e.g. the heap allocator has stored important + * stuff in SPI RAM. + * + * @return true on success, false on failed memory test + */ +bool esp_spiram_test(); + + +/** + * @brief Add the initialized SPI RAM to the heap allocator. + */ +esp_err_t esp_spiram_add_to_heapalloc(); + + +/** + * @brief Get the size of the attached SPI RAM chip selected in menuconfig + * + * @return Size in bytes, or 0 if no external RAM chip support compiled in. + */ +size_t esp_spiram_get_size(); + + +/** + * @brief Force a writeback of the data in the SPI RAM cache. This is to be called whenever + * cache is disabled, because disabling cache on the ESP32 discards the data in the SPI + * RAM cache. + * + * This is meant for use from within the SPI flash code. + */ +void esp_spiram_writeback_cache(); + + + +/** + * @brief Reserve a pool of internal memory for specific DMA/internal allocations + * + * @param size Size of reserved pool in bytes + * + * @return + * - ESP_OK on success + * - ESP_ERR_NO_MEM when no memory available for pool + */ +esp_err_t esp_spiram_reserve_dma_pool(size_t size); + + +/** + * @brief If SPI RAM(PSRAM) has been initialized + * + * @return + * - true SPI RAM has been initialized successfully + * - false SPI RAM hasn't been initialized or initialized failed + */ +bool esp_spiram_is_initialized(void); + + +#endif diff --git a/components/esp32/include/esp_clk.h b/components/esp32/include/esp_clk.h index 99e4f3078c..920f310c92 100644 --- a/components/esp32/include/esp_clk.h +++ b/components/esp32/include/esp_clk.h @@ -1,87 +1,2 @@ -// Copyright 2015-2017 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#pragma once -#include - -/** - * @file esp_clk.h - * - * This file contains declarations of clock related functions. - */ - -/** - * @brief Get the calibration value of RTC slow clock - * - * The value is in the same format as returned by rtc_clk_cal (microseconds, - * in Q13.19 fixed-point format). - * - * @return the calibration value obtained using rtc_clk_cal, at startup time - */ -uint32_t esp_clk_slowclk_cal_get(); - -/** - * @brief Update the calibration value of RTC slow clock - * - * The value has to be in the same format as returned by rtc_clk_cal (microseconds, - * in Q13.19 fixed-point format). - * This value is used by timekeeping functions (such as gettimeofday) to - * calculate current time based on RTC counter value. - * @param value calibration value obtained using rtc_clk_cal - */ -void esp_clk_slowclk_cal_set(uint32_t value); - -/** - * @brief Return current CPU clock frequency - * When frequency switching is performed, this frequency may change. - * However it is guaranteed that the frequency never changes with a critical - * section. - * - * @return CPU clock frequency, in Hz - */ -int esp_clk_cpu_freq(void); - -/** - * @brief Return current APB clock frequency - * - * When frequency switching is performed, this frequency may change. - * However it is guaranteed that the frequency never changes with a critical - * section. - * - * @return APB clock frequency, in Hz - */ -int esp_clk_apb_freq(void); - -/** - * @brief Return frequency of the main XTAL - * - * Frequency of the main XTAL can be either auto-detected or set at compile - * time (see CONFIG_ESP32_XTAL_FREQ_SEL sdkconfig option). In both cases, this - * function returns the actual value at run time. - * - * @return XTAL frequency, in Hz - */ -int esp_clk_xtal_freq(void); - - -/** - * @brief Read value of RTC counter, converting it to microseconds - * @attention The value returned by this function may change abruptly when - * calibration value of RTC counter is updated via esp_clk_slowclk_cal_set - * function. This should not happen unless application calls esp_clk_slowclk_cal_set. - * In ESP-IDF, esp_clk_slowclk_cal_set is only called in startup code. - * - * @return Value or RTC counter, expressed in microseconds - */ -uint64_t esp_clk_rtc_time(); +#warning esp_clk.h has been replaced by esp32/clk.h, please include esp32/clk.h instead +#include "esp32/clk.h" diff --git a/components/esp32/include/esp_himem.h b/components/esp32/include/esp_himem.h index 099d926015..c3ac9f52eb 100644 --- a/components/esp32/include/esp_himem.h +++ b/components/esp32/include/esp_himem.h @@ -1,152 +1,2 @@ -// Copyright 2018 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -#pragma once - -#include -#include "esp_err.h" - -#ifdef __cplusplus -extern "C" { -#endif - -//Opaque pointers as handles for ram/range data -typedef struct esp_himem_ramdata_t *esp_himem_handle_t; -typedef struct esp_himem_rangedata_t *esp_himem_rangehandle_t; - -//ESP32 MMU block size -#define ESP_HIMEM_BLKSZ (0x8000) - -#define ESP_HIMEM_MAPFLAG_RO 1 /*!< Indicates that a mapping will only be read from. Note that this is unused for now. */ - -/** - * @brief Allocate a block in high memory - * - * @param size Size of the to-be-allocated block, in bytes. Note that this needs to be - * a multiple of the external RAM mmu block size (32K). - * @param[out] handle_out Handle to be returned - * @returns - ESP_OK if succesful - * - ESP_ERR_NO_MEM if out of memory - * - ESP_ERR_INVALID_SIZE if size is not a multiple of 32K - */ -esp_err_t esp_himem_alloc(size_t size, esp_himem_handle_t *handle_out); - - -/** - * @brief Allocate a memory region to map blocks into - * - * This allocates a contiguous CPU memory region that can be used to map blocks - * of physical memory into. - * - * @param size Size of the range to be allocated. Note this needs to be a multiple of - * the external RAM mmu block size (32K). - * @param[out] handle_out Handle to be returned - * @returns - ESP_OK if succesful - * - ESP_ERR_NO_MEM if out of memory or address space - * - ESP_ERR_INVALID_SIZE if size is not a multiple of 32K - */ -esp_err_t esp_himem_alloc_map_range(size_t size, esp_himem_rangehandle_t *handle_out); - -/** - * @brief Map a block of high memory into the CPUs address space - * - * This effectively makes the block available for read/write operations. - * - * @note The region to be mapped needs to have offsets and sizes that are aligned to the - * SPI RAM MMU block size (32K) - * - * @param handle Handle to the block of memory, as given by esp_himem_alloc - * @param range Range handle to map the memory in - * @param ram_offset Offset into the block of physical memory of the block to map - * @param range_offset Offset into the address range where the block will be mapped - * @param len Length of region to map - * @param flags One of ESP_HIMEM_MAPFLAG_* - * @param[out] out_ptr Pointer to variable to store resulting memory pointer in - * @returns - ESP_OK if the memory could be mapped - * - ESP_ERR_INVALID_ARG if offset, range or len aren't MMU-block-aligned (32K) - * - ESP_ERR_INVALID_SIZE if the offsets/lengths don't fit in the allocated memory or range - * - ESP_ERR_INVALID_STATE if a block in the selected ram offset/length is already mapped, or - * if a block in the selected range offset/length already has a mapping. - */ -esp_err_t esp_himem_map(esp_himem_handle_t handle, esp_himem_rangehandle_t range, size_t ram_offset, size_t range_offset, size_t len, int flags, void **out_ptr); - - -/** - * @brief Free a block of physical memory - * - * This clears out the associated handle making the memory available for re-allocation again. - * This will only succeed if none of the memory blocks currently have a mapping. - * - * @param handle Handle to the block of memory, as given by esp_himem_alloc - * @returns - ESP_OK if the memory is succesfully freed - * - ESP_ERR_INVALID_ARG if the handle still is (partially) mapped - */ -esp_err_t esp_himem_free(esp_himem_handle_t handle); - - - -/** - * @brief Free a mapping range - * - * This clears out the associated handle making the range available for re-allocation again. - * This will only succeed if none of the range blocks currently are used for a mapping. - * - * @param handle Handle to the range block, as given by esp_himem_alloc_map_range - * @returns - ESP_OK if the memory is succesfully freed - * - ESP_ERR_INVALID_ARG if the handle still is (partially) mapped to - */ -esp_err_t esp_himem_free_map_range(esp_himem_rangehandle_t handle); - - -/** - * @brief Unmap a region - * - * @param range Range handle - * @param ptr Pointer returned by esp_himem_map - * @param len Length of the block to be unmapped. Must be aligned to the SPI RAM MMU blocksize (32K) - * @returns - ESP_OK if the memory is succesfully unmapped, - * - ESP_ERR_INVALID_ARG if ptr or len are invalid. - */ -esp_err_t esp_himem_unmap(esp_himem_rangehandle_t range, void *ptr, size_t len); - - -/** - * @brief Get total amount of memory under control of himem API - * - * @returns Amount of memory, in bytes - */ -size_t esp_himem_get_phys_size(); - -/** - * @brief Get free amount of memory under control of himem API - * - * @returns Amount of free memory, in bytes - */ -size_t esp_himem_get_free_size(); - - -/** - * @brief Get amount of SPI memory address space needed for bankswitching - * - * @note This is also weakly defined in esp32/spiram.c and returns 0 there, so - * if no other function in this file is used, no memory is reserved. - * - * @returns Amount of reserved area, in bytes - */ -size_t esp_himem_reserved_area_size(); - - -#ifdef __cplusplus -} -#endif - +#warning esp_himem.h has been replaced by esp32/himem.h, please include esp32/himem.h instead +#include "esp32/himem.h" diff --git a/components/esp32/include/esp_spiram.h b/components/esp32/include/esp_spiram.h index a55872cd4d..eabd6b6b35 100644 --- a/components/esp32/include/esp_spiram.h +++ b/components/esp32/include/esp_spiram.h @@ -1,116 +1,2 @@ -// Copyright 2015-2017 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at - -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - - -#ifndef __ESP_SPIRAM_H -#define __ESP_SPIRAM_H - -#include -#include -#include -#include "esp_err.h" - -typedef enum { - ESP_SPIRAM_SIZE_16MBITS = 0, /*!< SPI RAM size is 16 MBits */ - ESP_SPIRAM_SIZE_32MBITS = 1, /*!< SPI RAM size is 32 MBits */ - ESP_SPIRAM_SIZE_64MBITS = 2, /*!< SPI RAM size is 64 MBits */ - ESP_SPIRAM_SIZE_INVALID, /*!< SPI RAM size is invalid */ -} esp_spiram_size_t; - -/** - * @brief get SPI RAM size - * @return - * - ESP_SPIRAM_SIZE_INVALID if SPI RAM not enabled or not valid - * - SPI RAM size - */ -esp_spiram_size_t esp_spiram_get_chip_size(); - -/** - * @brief Initialize spiram interface/hardware. Normally called from cpu_start.c. - * - * @return ESP_OK on success - */ -esp_err_t esp_spiram_init(); - -/** - * @brief Configure Cache/MMU for access to external SPI RAM. - * - * Normally this function is called from cpu_start, if CONFIG_SPIRAM_BOOT_INIT - * option is enabled. Applications which need to enable SPI RAM at run time - * can disable CONFIG_SPIRAM_BOOT_INIT, and call this function later. - * - * @attention this function must be called with flash cache disabled. - */ -void esp_spiram_init_cache(); - - -/** - * @brief Memory test for SPI RAM. Should be called after SPI RAM is initialized and - * (in case of a dual-core system) the app CPU is online. This test overwrites the - * memory with crap, so do not call after e.g. the heap allocator has stored important - * stuff in SPI RAM. - * - * @return true on success, false on failed memory test - */ -bool esp_spiram_test(); - - -/** - * @brief Add the initialized SPI RAM to the heap allocator. - */ -esp_err_t esp_spiram_add_to_heapalloc(); - - -/** - * @brief Get the size of the attached SPI RAM chip selected in menuconfig - * - * @return Size in bytes, or 0 if no external RAM chip support compiled in. - */ -size_t esp_spiram_get_size(); - - -/** - * @brief Force a writeback of the data in the SPI RAM cache. This is to be called whenever - * cache is disabled, because disabling cache on the ESP32 discards the data in the SPI - * RAM cache. - * - * This is meant for use from within the SPI flash code. - */ -void esp_spiram_writeback_cache(); - - - -/** - * @brief Reserve a pool of internal memory for specific DMA/internal allocations - * - * @param size Size of reserved pool in bytes - * - * @return - * - ESP_OK on success - * - ESP_ERR_NO_MEM when no memory available for pool - */ -esp_err_t esp_spiram_reserve_dma_pool(size_t size); - - -/** - * @brief If SPI RAM(PSRAM) has been initialized - * - * @return - * - true SPI RAM has been initialized successfully - * - false SPI RAM hasn't been initialized or initialized failed - */ -bool esp_spiram_is_initialized(void); - - -#endif +#warning esp_spiram.h has been replaced by esp32/spiram.h, please include esp32/spiram.h instead +#include "esp32/spiram.h" diff --git a/components/esp32/panic.c b/components/esp32/panic.c index 64383f5624..880d219a10 100644 --- a/components/esp32/panic.c +++ b/components/esp32/panic.c @@ -38,7 +38,7 @@ #include "esp_err.h" #include "esp_core_dump.h" #include "esp_spi_flash.h" -#include "esp_cache_err_int.h" +#include "esp32/cache_err_int.h" #include "esp_app_trace.h" #include "esp_system_internal.h" #include "sdkconfig.h" diff --git a/components/esp32/pm_esp32.c b/components/esp32/pm_esp32.c index 0cf7e2d20d..78ac02232c 100644 --- a/components/esp32/pm_esp32.c +++ b/components/esp32/pm_esp32.c @@ -22,7 +22,7 @@ #include "esp_pm.h" #include "esp_log.h" #include "esp_crosscore_int.h" -#include "esp_clk.h" +#include "esp32/clk.h" #include "soc/rtc.h" diff --git a/components/esp32/sleep_modes.c b/components/esp32/sleep_modes.c index d460365905..9bd754e8be 100644 --- a/components/esp32/sleep_modes.c +++ b/components/esp32/sleep_modes.c @@ -19,7 +19,7 @@ #include "esp_sleep.h" #include "esp_timer_impl.h" #include "esp_log.h" -#include "esp_clk.h" +#include "esp32/clk.h" #include "esp_newlib.h" #include "esp_spi_flash.h" #include "rom/cache.h" diff --git a/components/esp32/spiram.c b/components/esp32/spiram.c index 7dacfa0503..ee60ab08ad 100644 --- a/components/esp32/spiram.c +++ b/components/esp32/spiram.c @@ -24,7 +24,7 @@ we add more types of external RAM memory, this can be made into a more intellige #include "sdkconfig.h" #include "esp_attr.h" #include "esp_err.h" -#include "esp_spiram.h" +#include "esp32/spiram.h" #include "spiram_psram.h" #include "esp_log.h" #include "freertos/FreeRTOS.h" @@ -34,7 +34,7 @@ we add more types of external RAM memory, this can be made into a more intellige #include "soc/soc_memory_layout.h" #include "soc/dport_reg.h" #include "rom/cache.h" -#include "esp_himem.h" +#include "esp32/himem.h" #if CONFIG_FREERTOS_UNICORE #define PSRAM_MODE PSRAM_VADDR_MODE_NORMAL diff --git a/components/esp32/test/test_aes_sha_rsa.c b/components/esp32/test/test_aes_sha_rsa.c index a2ca6b3b5e..003d58419e 100644 --- a/components/esp32/test/test_aes_sha_rsa.c +++ b/components/esp32/test/test_aes_sha_rsa.c @@ -2,7 +2,7 @@ #include #include #include "esp_types.h" -#include "esp_clk.h" +#include "esp32/clk.h" #include "freertos/FreeRTOS.h" #include "freertos/task.h" diff --git a/components/esp32/test/test_dport.c b/components/esp32/test/test_dport.c index 418cd4202d..ab81d7230a 100644 --- a/components/esp32/test/test_dport.c +++ b/components/esp32/test/test_dport.c @@ -1,7 +1,7 @@ #include #include #include "esp_types.h" -#include "esp_clk.h" +#include "esp32/clk.h" #include "freertos/FreeRTOS.h" #include "freertos/task.h" diff --git a/components/esp32/test/test_himem.c b/components/esp32/test/test_himem.c index 95ed27d5ae..496d09588f 100644 --- a/components/esp32/test/test_himem.c +++ b/components/esp32/test/test_himem.c @@ -7,7 +7,7 @@ #include "esp_system.h" #include "rom/cache.h" #include "sdkconfig.h" -#include "esp_himem.h" +#include "esp32/himem.h" #if CONFIG_SPIRAM_BANKSWITCH_ENABLE diff --git a/components/esp32/test/test_pm.c b/components/esp32/test/test_pm.c index e34658b7ef..01e1e17bc9 100644 --- a/components/esp32/test/test_pm.c +++ b/components/esp32/test/test_pm.c @@ -5,7 +5,7 @@ #include #include "unity.h" #include "esp_pm.h" -#include "esp_clk.h" +#include "esp32/clk.h" #include "freertos/FreeRTOS.h" #include "freertos/task.h" #include "freertos/semphr.h" diff --git a/components/esp32/test/test_sha.c b/components/esp32/test/test_sha.c index d64b867602..db9754b531 100644 --- a/components/esp32/test/test_sha.c +++ b/components/esp32/test/test_sha.c @@ -2,7 +2,7 @@ #include #include #include "esp_types.h" -#include "esp_clk.h" +#include "esp32/clk.h" #include "esp_log.h" #include "esp_timer.h" #include "esp_heap_caps.h" diff --git a/components/esp32/test/test_sleep.c b/components/esp32/test/test_sleep.c index d2e2d9b279..57aad6ab62 100644 --- a/components/esp32/test/test_sleep.c +++ b/components/esp32/test/test_sleep.c @@ -2,7 +2,7 @@ #include #include #include "esp_sleep.h" -#include "esp_clk.h" +#include "esp32/clk.h" #include "driver/rtc_io.h" #include "soc/gpio_reg.h" #include "soc/rtc.h" diff --git a/components/espcoredump/src/core_dump_uart.c b/components/espcoredump/src/core_dump_uart.c index 2c1f4cbfc2..dfc62d9a88 100644 --- a/components/espcoredump/src/core_dump_uart.c +++ b/components/espcoredump/src/core_dump_uart.c @@ -15,7 +15,7 @@ #include "soc/uart_reg.h" #include "soc/io_mux_reg.h" #include "driver/gpio.h" -#include "esp_clk.h" +#include "esp32/clk.h" #include "esp_core_dump_priv.h" const static DRAM_ATTR char TAG[] __attribute__((unused)) = "esp_core_dump_uart"; diff --git a/components/ethernet/emac_main.c b/components/ethernet/emac_main.c index 8cfbec972e..dc9a42b887 100644 --- a/components/ethernet/emac_main.c +++ b/components/ethernet/emac_main.c @@ -39,7 +39,7 @@ #include "esp_eth.h" #include "esp_intr_alloc.h" #include "esp_pm.h" -#include "esp_spiram.h" +#include "esp32/spiram.h" #include "driver/periph_ctrl.h" diff --git a/components/freertos/xtensa_init.c b/components/freertos/xtensa_init.c index 624f242b1e..c503b7c37a 100644 --- a/components/freertos/xtensa_init.c +++ b/components/freertos/xtensa_init.c @@ -34,7 +34,7 @@ that are implemented in C. #endif #include "xtensa_rtos.h" -#include "esp_clk.h" +#include "esp32/clk.h" #ifdef XT_RTOS_TIMER_INT diff --git a/components/newlib/test/test_time.c b/components/newlib/test/test_time.c index a6c2b80bb3..fb7ccbf7f6 100644 --- a/components/newlib/test/test_time.c +++ b/components/newlib/test/test_time.c @@ -10,7 +10,7 @@ #include "freertos/semphr.h" #include "sdkconfig.h" #include "soc/rtc.h" -#include "esp_clk.h" +#include "esp32/clk.h" #include "esp_system.h" #include "test_utils.h" diff --git a/components/newlib/time.c b/components/newlib/time.c index 892ab2ff83..a8364367a3 100644 --- a/components/newlib/time.c +++ b/components/newlib/time.c @@ -25,7 +25,7 @@ #include #include "esp_attr.h" #include "esp_intr_alloc.h" -#include "esp_clk.h" +#include "esp32/clk.h" #include "esp_timer.h" #include "soc/soc.h" #include "soc/rtc.h" diff --git a/components/soc/esp32/include/soc/dport_access.h b/components/soc/esp32/include/soc/dport_access.h index 00e7c83810..544560fdfb 100644 --- a/components/soc/esp32/include/soc/dport_access.h +++ b/components/soc/esp32/include/soc/dport_access.h @@ -17,7 +17,7 @@ #include #include "esp_attr.h" -#include "esp_dport_access.h" +#include "esp32/dport_access.h" #include "soc.h" #include "uart_reg.h" #include "xtensa/xtruntime.h" diff --git a/components/soc/esp32/test/test_rtc_clk.c b/components/soc/esp32/test/test_rtc_clk.c index ee05a302bf..eb5c1b1ddb 100644 --- a/components/soc/esp32/test/test_rtc_clk.c +++ b/components/soc/esp32/test/test_rtc_clk.c @@ -13,7 +13,7 @@ #include "freertos/task.h" #include "freertos/semphr.h" #include "../esp_clk_internal.h" -#include "esp_clk.h" +#include "esp32/clk.h" diff --git a/components/spi_flash/flash_mmap.c b/components/spi_flash/flash_mmap.c index 534a7e3d35..c1e68cbedb 100644 --- a/components/spi_flash/flash_mmap.c +++ b/components/spi_flash/flash_mmap.c @@ -31,7 +31,7 @@ #include "esp_flash_encrypt.h" #include "esp_log.h" #include "cache_utils.h" -#include "esp_spiram.h" +#include "esp32/spiram.h" #ifndef NDEBUG // Enable built-in checks in queue.h in debug builds diff --git a/components/spi_flash/flash_ops.c b/components/spi_flash/flash_ops.c index 29dbb2fd60..6529a750d9 100644 --- a/components/spi_flash/flash_ops.c +++ b/components/spi_flash/flash_ops.c @@ -30,7 +30,7 @@ #include "esp_attr.h" #include "esp_spi_flash.h" #include "esp_log.h" -#include "esp_clk.h" +#include "esp32/clk.h" #include "esp_flash_partitions.h" #include "esp_ota_ops.h" #include "cache_utils.h" diff --git a/components/ulp/ulp.c b/components/ulp/ulp.c index 3424da21ec..ad1e083ee2 100644 --- a/components/ulp/ulp.c +++ b/components/ulp/ulp.c @@ -19,7 +19,7 @@ #include "esp_attr.h" #include "esp_err.h" #include "esp_log.h" -#include "esp_clk.h" +#include "esp32/clk.h" #include "esp32/ulp.h" #include "soc/soc.h" diff --git a/components/unity/unity_port_esp32.c b/components/unity/unity_port_esp32.c index 024dbc7e51..535d63bccd 100644 --- a/components/unity/unity_port_esp32.c +++ b/components/unity/unity_port_esp32.c @@ -15,7 +15,7 @@ #include "unity.h" #include "sdkconfig.h" #include "rom/uart.h" -#include "esp_clk.h" +#include "esp32/clk.h" #include "soc/cpu.h" static uint32_t s_test_start, s_test_stop; diff --git a/components/wear_levelling/test/test_wl.c b/components/wear_levelling/test/test_wl.c index 0c2bf39dcc..09ef23bfec 100644 --- a/components/wear_levelling/test/test_wl.c +++ b/components/wear_levelling/test/test_wl.c @@ -6,7 +6,7 @@ #include "freertos/portable.h" #include "freertos/task.h" #include "freertos/semphr.h" -#include "esp_clk.h" +#include "esp32/clk.h" #include "soc/cpu.h" TEST_CASE("wl_unmount doesn't leak memory", "[wear_levelling]") diff --git a/docs/Doxyfile b/docs/Doxyfile index b79aa3e2c3..97705f264c 100644 --- a/docs/Doxyfile +++ b/docs/Doxyfile @@ -152,7 +152,7 @@ INPUT = \ ../../components/heap/include/esp_heap_caps_init.h \ ../../components/heap/include/multi_heap.h \ ## Himem - ../../components/esp32/include/esp_himem.h \ + ../../components/esp32/include/esp32/himem.h \ ## Interrupt Allocation ../../components/esp32/include/esp_intr_alloc.h \ ## Watchdogs diff --git a/docs/en/api-reference/system/himem.rst b/docs/en/api-reference/system/himem.rst index a3eba8be3b..1c5dd0129a 100644 --- a/docs/en/api-reference/system/himem.rst +++ b/docs/en/api-reference/system/himem.rst @@ -30,4 +30,4 @@ An example doing a simple memory test of the high memory range is available in e API Reference ------------- -.. include:: /_build/inc/esp_himem.inc +.. include:: /_build/inc/himem.inc diff --git a/examples/system/himem/main/himem_test_main.c b/examples/system/himem/main/himem_test_main.c index c5f8c97a2a..98955725a6 100644 --- a/examples/system/himem/main/himem_test_main.c +++ b/examples/system/himem/main/himem_test_main.c @@ -15,10 +15,10 @@ #include "esp_system.h" #include "nvs_flash.h" #include "esp_heap_caps.h" -#include "esp_spiram.h" +#include "esp32/spiram.h" #include "rom/cache.h" #include "sdkconfig.h" -#include "esp_himem.h" +#include "esp32/himem.h" //Fill memory with pseudo-random data generated from the given seed.