soc: separate abstraction, description and implementation
This commit is contained in:
parent
2e8a894ea7
commit
1f2e2fe8af
|
@ -27,8 +27,9 @@ INCLUDE_DIRS := \
|
|||
esp_rom/include \
|
||||
xtensa/include \
|
||||
xtensa/esp32/include \
|
||||
soc/esp32/include \
|
||||
soc/soc/esp32/include \
|
||||
soc/include \
|
||||
soc/soc/include \
|
||||
esp32/include \
|
||||
esp_common/include \
|
||||
bootloader_support/include \
|
||||
|
|
|
@ -1,16 +1,6 @@
|
|||
idf_build_get_property(soc_name IDF_TARGET)
|
||||
idf_build_get_property(target IDF_TARGET)
|
||||
|
||||
if(EXISTS "${COMPONENT_DIR}/${soc_name}")
|
||||
include(${COMPONENT_DIR}/${soc_name}/sources.cmake)
|
||||
|
||||
spaces2list(SOC_SRCS)
|
||||
add_prefix(srcs "${soc_name}/" ${SOC_SRCS})
|
||||
set(include_dirs ${soc_name}/include)
|
||||
endif()
|
||||
|
||||
list(APPEND include_dirs include)
|
||||
list(APPEND srcs
|
||||
"src/memory_layout_utils.c"
|
||||
idf_component_register(SRCS "src/memory_layout_utils.c"
|
||||
"src/lldesc.c"
|
||||
"src/hal/rmt_hal.c"
|
||||
"src/hal/rtc_io_hal.c"
|
||||
|
@ -36,21 +26,18 @@ list(APPEND srcs
|
|||
"src/hal/spi_flash_hal.c"
|
||||
"src/hal/spi_flash_hal_iram.c"
|
||||
"src/compare_set.c"
|
||||
)
|
||||
|
||||
if(IDF_TARGET STREQUAL "esp32")
|
||||
list(APPEND srcs "src/hal/mcpwm_hal.c"
|
||||
"src/hal/sdio_slave_hal.c"
|
||||
"src/hal/can_hal.c"
|
||||
)
|
||||
endif()
|
||||
|
||||
if(IDF_TARGET STREQUAL "esp32s2")
|
||||
list(APPEND srcs "src/hal/spi_flash_hal_gpspi.c"
|
||||
"esp32s2/hal/usb_hal.c")
|
||||
endif()
|
||||
|
||||
idf_component_register(SRCS "${srcs}"
|
||||
INCLUDE_DIRS "${include_dirs}"
|
||||
PRIV_REQUIRES ${soc_name}
|
||||
PRIV_REQUIRES ${target}
|
||||
LDFRAGMENTS linker.lf)
|
||||
|
||||
if(CONFIG_IDF_TARGET_ESP32)
|
||||
target_sources(${COMPONENT_LIB} PRIVATE "src/hal/can_hal.c"
|
||||
"src/hal/mcpwm_hal.c"
|
||||
"src/hal/sdio_slave_hal.c")
|
||||
elseif(CONFIG_IDF_TARGET_ESP32S2)
|
||||
target_sources(${COMPONENT_LIB} PRIVATE "src/hal/spi_flash_hal_gpspi.c")
|
||||
endif()
|
||||
|
||||
add_subdirectory(soc)
|
||||
target_link_libraries(${COMPONENT_LIB} PUBLIC "soc_${target}")
|
||||
|
||||
add_subdirectory(src/${target})
|
||||
|
|
44
components/soc/README.md
Normal file
44
components/soc/README.md
Normal file
|
@ -0,0 +1,44 @@
|
|||
## `soc` ##
|
||||
|
||||
The `soc` component provides abstraction, hardware description and implementation for targets suppported by ESP-IDF. This is reflected in
|
||||
the component's subdirectories:
|
||||
|
||||
- `soc/include` - abstraction
|
||||
- `soc/soc` - description
|
||||
- `soc/src` - implementation
|
||||
|
||||
#### `soc/include` ####
|
||||
|
||||
`soc/include` contains header files which provide a hardware-agnostic interface to the SoC. The interface consists of
|
||||
function declarations and abstracted types that other, higher level components can make use of in order to have code portable to
|
||||
all targets ESP-IDF supports.
|
||||
|
||||
The `hal` subdirectory contains an abstraction layer for interacting with/driving the hardware found in the SoC such as the peripherals
|
||||
and 'core' hardware such as the CPU, MPU, caches, etc. It contains `xxx_hal.h` files for the function declarations and `xxx_types.h` for the abstracted types.
|
||||
The abstraction design is actually two levels -- oftentimes `xxx_hal.h` includes a lower-level header from a
|
||||
`xxx_ll.h`, which resides in the implementation, `soc/src` subdirectory. More on this abstraction design in the [`hal` subdirectory's README](include/hal/readme.md).
|
||||
|
||||
The `soc` subdirectory contains other useful interface for SoC-level operations or concepts, such as the memory layout, spinlocks, etc.
|
||||
|
||||
#### `soc/soc` ####
|
||||
|
||||
The `soc/soc` subdirectory contains description of the underlying hardware:
|
||||
|
||||
- `xxx_reg.h` - defines registers related to the hardware
|
||||
- `xxx_struct.h` - hardware description in C `struct`
|
||||
- `xxx_channel.h` - definitions for hardware with multiple channels
|
||||
- `xxx_caps.h` - features/capabilities of the hardware
|
||||
- `xxx_pins.h` - pin definitions
|
||||
- `xxx_periph.h/*.c` - includes all headers related to a peripheral; declaration and definition of IO mapping for that hardware
|
||||
|
||||
Since the hardware description is target-specific, there are subdirectories for each target containing copies of the files above.
|
||||
Furthermore, the files in this directory should be standalone, i.e. should not include files from outside directories.
|
||||
|
||||
#### `soc/src` ####
|
||||
|
||||
Provides the implementation of the hardware-agnostic interface in the abstraction. Target-specific subdirectories exist for wildly different implementations between targets; while code that are common/very similar might be placed in the top-level of `soc/src`, using some amount of conditional preprocessors. It is up to the developers' discretion on which strategy to use. Code usually reside in source files with same names to header files whose interfaces they implement, ex. `xxx_hal.c` for `xxx_hal.h`.
|
||||
|
||||
As mentioned previously, the lower-level abstraction header `xxx_ll.h` resides in this directory, since they contain hardware-specific details.
|
||||
However, what these can do is provide some abstraction among implementations, so that more code can be moved to the common, non-target-specific subdirectories.
|
||||
|
||||
This can also contain target-specific extensions to the HAL headers. These target-specific HAL headers have the same name and include the abstraction layer HAL header via `include_next`. These extensions might add more function declarations or override some things using macro magic.
|
|
@ -1,9 +1,10 @@
|
|||
SOC_NAME := $(IDF_TARGET)
|
||||
|
||||
COMPONENT_SRCDIRS := $(SOC_NAME) src src/hal
|
||||
COMPONENT_SRCDIRS := src src/hal
|
||||
|
||||
COMPONENT_ADD_INCLUDEDIRS := $(SOC_NAME)/include include
|
||||
COMPONENT_ADD_INCLUDEDIRS := include
|
||||
|
||||
-include $(COMPONENT_PATH)/$(SOC_NAME)/component.mk
|
||||
-include $(COMPONENT_PATH)/soc/component.mk
|
||||
-include $(COMPONENT_PATH)/src/$(SOC_NAME)/component.mk
|
||||
|
||||
COMPONENT_ADD_LDFRAGMENTS += linker.lf
|
||||
|
|
|
@ -1,5 +0,0 @@
|
|||
ifndef CONFIG_ETH_USE_ESP32_EMAC
|
||||
COMPONENT_OBJEXCLUDE += esp32/emac_hal.o
|
||||
endif
|
||||
|
||||
esp32/rtc_clk.o: CFLAGS += -fno-jump-tables -fno-tree-switch-conversion
|
|
@ -1,34 +0,0 @@
|
|||
set(SOC_SRCS "adc_periph.c"
|
||||
"brownout_hal.c"
|
||||
"dac_periph.c"
|
||||
"cpu_util.c"
|
||||
"gpio_periph.c"
|
||||
"rtc_clk.c"
|
||||
"rtc_clk_init.c"
|
||||
"rtc_init.c"
|
||||
"rtc_io_periph.c"
|
||||
"rtc_periph.c"
|
||||
"rtc_pm.c"
|
||||
"rtc_sleep.c"
|
||||
"rtc_time.c"
|
||||
"rtc_wdt.c"
|
||||
"sdio_slave_periph.c"
|
||||
"sdmmc_periph.c"
|
||||
"interrupts.c"
|
||||
"soc_memory_layout.c"
|
||||
"spi_periph.c"
|
||||
"ledc_periph.c"
|
||||
"i2s_periph.c"
|
||||
"i2c_periph.c"
|
||||
"uart_periph.c"
|
||||
"touch_sensor_hal.c"
|
||||
"touch_sensor_periph.c")
|
||||
|
||||
if(NOT BOOTLOADER_BUILD AND CONFIG_ETH_USE_ESP32_EMAC)
|
||||
list(APPEND SOC_SRCS "emac_hal.c")
|
||||
endif()
|
||||
|
||||
if(NOT CMAKE_BUILD_EARLY_EXPANSION)
|
||||
set_source_files_properties("esp32/rtc_clk.c" PROPERTIES
|
||||
COMPILE_FLAGS "-fno-jump-tables -fno-tree-switch-conversion")
|
||||
endif()
|
|
@ -1 +0,0 @@
|
|||
esp32s2/rtc_clk.o: CFLAGS += -fno-jump-tables -fno-tree-switch-conversion
|
|
@ -1,28 +0,0 @@
|
|||
set(SOC_SRCS "adc_periph.c"
|
||||
"brownout_hal.c"
|
||||
"dac_periph.c"
|
||||
"cpu_util.c"
|
||||
"gpio_periph.c"
|
||||
"rtc_clk.c"
|
||||
"rtc_init.c"
|
||||
"rtc_io_periph.c"
|
||||
"rtc_periph.c"
|
||||
"rtc_pm.c"
|
||||
"rtc_sleep.c"
|
||||
"rtc_time.c"
|
||||
"rtc_wdt.c"
|
||||
"interrupts.c"
|
||||
"soc_memory_layout.c"
|
||||
"spi_periph.c"
|
||||
"ledc_periph.c"
|
||||
"i2s_periph.c"
|
||||
"i2c_periph.c"
|
||||
"uart_periph.c"
|
||||
"usb_periph.c"
|
||||
"touch_sensor_hal.c"
|
||||
"touch_sensor_periph.c")
|
||||
|
||||
if(NOT CMAKE_BUILD_EARLY_EXPANSION)
|
||||
set_source_files_properties("esp32s2/rtc_clk.c" PROPERTIES
|
||||
COMPILE_FLAGS "-fno-jump-tables -fno-tree-switch-conversion")
|
||||
endif()
|
|
@ -15,7 +15,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <esp_types.h>
|
||||
#include "hal/esp_flash_err.h"
|
||||
#include "esp_flash_err.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
|
|
@ -22,8 +22,25 @@
|
|||
* this header file provides wrappers for logging functions.
|
||||
*/
|
||||
|
||||
#ifdef ESP_PLATFORM
|
||||
#include "esp_log.h"
|
||||
#define SOC_LOGE(tag, fmt, ...) ESP_EARLY_LOGE(tag, fmt, ##__VA_ARGS__)
|
||||
#define SOC_LOGW(tag, fmt, ...) ESP_EARLY_LOGW(tag, fmt, ##__VA_ARGS__)
|
||||
#define SOC_LOGI(tag, fmt, ...) ESP_EARLY_LOGI(tag, fmt, ##__VA_ARGS__)
|
||||
#define SOC_LOGD(tag, fmt, ...) ESP_EARLY_LOGD(tag, fmt, ##__VA_ARGS__)
|
||||
#define SOC_LOGV(tag, fmt, ...) ESP_EARLY_LOGV(tag, fmt, ##__VA_ARGS__)
|
||||
|
||||
#else
|
||||
|
||||
#ifdef CONFIG_IDF_TARGET_ESPP32
|
||||
#include "esp32/rom/ets_sys.h"
|
||||
#elif CONFIG_IDF_TARGET_ESP32S2
|
||||
#include "esp32s2/rom/ets_sys.h"
|
||||
#endif
|
||||
|
||||
#define SOC_LOGE(tag, fmt, ...) ets_printf("%s(err): " fmt, tag, ##__VA_ARGS__)
|
||||
#define SOC_LOGW(tag, fmt, ...) ets_printf("%s(warn): " fmt, tag, ##__VA_ARGS__)
|
||||
#define SOC_LOGI(tag, fmt, ...) ets_printf("%s(info): " fmt, tag, ##__VA_ARGS__)
|
||||
#define SOC_LOGD(tag, fmt, ...) ets_printf("%s(dbg): " fmt, tag, ##__VA_ARGS__)
|
||||
#define SOC_LOGV(tag, fmt, ...) ets_printf("%s: " fmt, tag, ##__VA_ARGS__)
|
||||
#endif //ESP_PLATFORM
|
2
components/soc/soc/CMakeLists.txt
Normal file
2
components/soc/soc/CMakeLists.txt
Normal file
|
@ -0,0 +1,2 @@
|
|||
idf_build_get_property(target IDF_TARGET)
|
||||
add_subdirectory(${target})
|
2
components/soc/soc/component.mk
Normal file
2
components/soc/soc/component.mk
Normal file
|
@ -0,0 +1,2 @@
|
|||
COMPONENT_ADD_INCLUDEDIRS += soc/include soc/$(SOC_NAME) soc/$(SOC_NAME)/include
|
||||
COMPONENT_SRCDIRS += soc/$(SOC_NAME)
|
17
components/soc/soc/esp32/CMakeLists.txt
Normal file
17
components/soc/soc/esp32/CMakeLists.txt
Normal file
|
@ -0,0 +1,17 @@
|
|||
add_library(soc_esp32 STATIC
|
||||
"adc_periph.c"
|
||||
"dac_periph.c"
|
||||
"gpio_periph.c"
|
||||
"rtc_io_periph.c"
|
||||
"rtc_periph.c"
|
||||
"sdio_slave_periph.c"
|
||||
"sdmmc_periph.c"
|
||||
"interrupts.c"
|
||||
"spi_periph.c"
|
||||
"ledc_periph.c"
|
||||
"i2s_periph.c"
|
||||
"i2c_periph.c"
|
||||
"uart_periph.c"
|
||||
"touch_sensor_periph.c")
|
||||
|
||||
target_include_directories(soc_esp32 PUBLIC . include ../include)
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue