Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/esp_system_linux' into 'master'
esp_system partially buildable on Linux Closes IDF-5983 See merge request espressif/esp-idf!21055
- Loading branch information
Showing
19 changed files
with
305 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
components/esp_system/host_test/test_esp_system/CMakeLists.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# For more information about build system see | ||
# https://docs.espressif.com/projects/esp-idf/en/latest/api-guides/build-system.html | ||
# The following five lines of boilerplate have to be in your project's | ||
# CMakeLists in this exact order for cmake to work correctly | ||
cmake_minimum_required(VERSION 3.16) | ||
|
||
include($ENV{IDF_PATH}/tools/cmake/project.cmake) | ||
set(COMPONENTS main) | ||
project(test_esp_system) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
| Supported Targets | Linux | | ||
| ----------------- | ----- | |
3 changes: 3 additions & 0 deletions
3
components/esp_system/host_test/test_esp_system/main/CMakeLists.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
idf_component_register(SRCS "esp_system_test.c" | ||
INCLUDE_DIRS "." | ||
PRIV_REQUIRES unity esp_system) |
120 changes: 120 additions & 0 deletions
120
components/esp_system/host_test/test_esp_system/main/esp_system_test.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <setjmp.h> | ||
#include "unity.h" | ||
|
||
#include "esp_system.h" | ||
|
||
static jmp_buf env; | ||
static uint32_t token; | ||
|
||
static void jump_back_shutdown_handler(void) | ||
{ | ||
longjmp(env, 1); | ||
} | ||
|
||
static void dummy_shutdown_handler_0(void) { } | ||
static void dummy_shutdown_handler_1(void) { } | ||
static void dummy_shutdown_handler_2(void) { } | ||
static void dummy_shutdown_handler_3(void) { } | ||
static void dummy_shutdown_handler_4(void) { } | ||
|
||
static void action(void) | ||
{ | ||
token++; | ||
} | ||
|
||
static void cleanup(void) | ||
{ | ||
esp_unregister_shutdown_handler(jump_back_shutdown_handler); | ||
esp_unregister_shutdown_handler(dummy_shutdown_handler_0); | ||
esp_unregister_shutdown_handler(dummy_shutdown_handler_1); | ||
esp_unregister_shutdown_handler(dummy_shutdown_handler_2); | ||
esp_unregister_shutdown_handler(dummy_shutdown_handler_3); | ||
esp_unregister_shutdown_handler(dummy_shutdown_handler_4); | ||
esp_unregister_shutdown_handler(action); | ||
} | ||
|
||
void test_reset_reason(void) | ||
{ | ||
TEST_ASSERT_EQUAL(ESP_RST_POWERON, esp_reset_reason()); | ||
} | ||
|
||
void test_unregister_handler_works(void) | ||
{ | ||
token = 0; | ||
// for some reason, the handlers are executed in reverse order of adding handlers, so we always | ||
// register the jumping handler at first to make it execute last | ||
TEST_ASSERT_EQUAL(ESP_OK, esp_register_shutdown_handler(jump_back_shutdown_handler)); | ||
TEST_ASSERT_EQUAL(ESP_OK, esp_register_shutdown_handler(action)); | ||
TEST_ASSERT_EQUAL(ESP_OK, esp_unregister_shutdown_handler(action)); | ||
|
||
if (setjmp(env) == 0) { | ||
esp_restart(); | ||
} | ||
|
||
// fist unregister before any assert to avoid skipping by assert's longjmp | ||
cleanup(); | ||
|
||
TEST_ASSERT_EQUAL(0, token); | ||
} | ||
|
||
void test_register_shutdown_handler_twice_fails(void) | ||
{ | ||
TEST_ASSERT_EQUAL(ESP_OK, esp_register_shutdown_handler(jump_back_shutdown_handler)); | ||
TEST_ASSERT_EQUAL(ESP_ERR_INVALID_STATE, esp_register_shutdown_handler(jump_back_shutdown_handler)); | ||
|
||
cleanup(); | ||
} | ||
|
||
void test_register_shutdown_handler_works(void) | ||
{ | ||
token = 0; | ||
TEST_ASSERT_EQUAL(esp_register_shutdown_handler(jump_back_shutdown_handler), ESP_OK); | ||
TEST_ASSERT_EQUAL(esp_register_shutdown_handler(action), ESP_OK); | ||
|
||
if (setjmp(env) == 0) { | ||
esp_restart(); | ||
} | ||
|
||
cleanup(); | ||
|
||
TEST_ASSERT_EQUAL(1, token); | ||
} | ||
|
||
void test_register_too_many_shutdown_handler_fails(void) | ||
{ | ||
TEST_ASSERT_EQUAL(ESP_OK, esp_register_shutdown_handler(dummy_shutdown_handler_0)); | ||
TEST_ASSERT_EQUAL(ESP_OK, esp_register_shutdown_handler(dummy_shutdown_handler_1)); | ||
TEST_ASSERT_EQUAL(ESP_OK, esp_register_shutdown_handler(dummy_shutdown_handler_2)); | ||
TEST_ASSERT_EQUAL(ESP_OK, esp_register_shutdown_handler(dummy_shutdown_handler_3)); | ||
TEST_ASSERT_EQUAL(ESP_OK, esp_register_shutdown_handler(dummy_shutdown_handler_4)); | ||
|
||
TEST_ASSERT_EQUAL(esp_register_shutdown_handler(jump_back_shutdown_handler), ESP_ERR_NO_MEM); | ||
|
||
cleanup(); | ||
} | ||
|
||
void test_heap_size_stubs(void) | ||
{ | ||
TEST_ASSERT_EQUAL(47000, esp_get_free_heap_size()); | ||
TEST_ASSERT_EQUAL(47000, esp_get_free_internal_heap_size()); | ||
TEST_ASSERT_EQUAL(47000, esp_get_minimum_free_heap_size()); | ||
} | ||
|
||
void app_main(void) | ||
{ | ||
UNITY_BEGIN(); | ||
RUN_TEST(test_reset_reason); | ||
RUN_TEST(test_unregister_handler_works); | ||
RUN_TEST(test_register_shutdown_handler_twice_fails); | ||
RUN_TEST(test_register_shutdown_handler_works); | ||
RUN_TEST(test_register_too_many_shutdown_handler_fails); | ||
RUN_TEST(test_heap_size_stubs); | ||
UNITY_END(); | ||
} |
2 changes: 2 additions & 0 deletions
2
components/esp_system/host_test/test_esp_system/sdkconfig.defaults
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
CONFIG_IDF_TARGET="linux" | ||
CONFIG_UNITY_ENABLE_IDF_TEST_RUNNER=n |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#include <stdint.h> | ||
#include "esp_cpu.h" | ||
#include "soc/rtc.h" | ||
#include "esp_private/panic_internal.h" | ||
#include "esp_private/system_internal.h" | ||
#include "esp_heap_caps.h" | ||
#include "esp_rom_uart.h" | ||
#include "esp_rom_sys.h" | ||
#include "sdkconfig.h" | ||
|
||
void IRAM_ATTR esp_restart_noos_dig(void) | ||
{ | ||
// make sure all the panic handler output is sent from UART FIFO | ||
if (CONFIG_ESP_CONSOLE_UART_NUM >= 0) { | ||
esp_rom_uart_tx_wait_idle(CONFIG_ESP_CONSOLE_UART_NUM); | ||
} | ||
|
||
// switch to XTAL (otherwise we will keep running from the PLL) | ||
rtc_clk_cpu_freq_set_xtal(); | ||
|
||
#if CONFIG_IDF_TARGET_ESP32 | ||
esp_cpu_unstall(PRO_CPU_NUM); | ||
#endif | ||
// reset the digital part | ||
esp_rom_software_reset_system(); | ||
while (true) { | ||
; | ||
} | ||
} | ||
|
||
uint32_t esp_get_free_heap_size( void ) | ||
{ | ||
return heap_caps_get_free_size( MALLOC_CAP_DEFAULT ); | ||
} | ||
|
||
uint32_t esp_get_free_internal_heap_size( void ) | ||
{ | ||
return heap_caps_get_free_size( MALLOC_CAP_8BIT | MALLOC_CAP_DMA | MALLOC_CAP_INTERNAL ); | ||
} | ||
|
||
uint32_t esp_get_minimum_free_heap_size( void ) | ||
{ | ||
return heap_caps_get_minimum_free_size( MALLOC_CAP_DEFAULT ); | ||
} | ||
|
||
const char *esp_get_idf_version(void) | ||
{ | ||
return IDF_VER; | ||
} | ||
|
||
void __attribute__((noreturn)) esp_system_abort(const char *details) | ||
{ | ||
panic_abort(details); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
/* | ||
* All functions presented here are stubs for the POSIX/Linux implementation of FReeRTOS. | ||
* They are meant to allow to compile, but they DO NOT return any meaningful value. | ||
*/ | ||
|
||
#include <stdlib.h> | ||
#include <stdint.h> | ||
#include "esp_private/system_internal.h" | ||
|
||
static const uint32_t MAGIC_HEAP_SIZE = 47000; | ||
|
||
// dummy, we should never get here on Linux | ||
void esp_restart_noos_dig(void) | ||
{ | ||
abort(); | ||
} | ||
|
||
uint32_t esp_get_free_heap_size( void ) | ||
{ | ||
return MAGIC_HEAP_SIZE; | ||
} | ||
|
||
uint32_t esp_get_free_internal_heap_size( void ) | ||
{ | ||
return MAGIC_HEAP_SIZE; | ||
} | ||
|
||
uint32_t esp_get_minimum_free_heap_size( void ) | ||
{ | ||
return MAGIC_HEAP_SIZE; | ||
} | ||
|
||
const char *esp_get_idf_version(void) | ||
{ | ||
return IDF_VER; | ||
} | ||
|
||
void __attribute__((noreturn)) esp_system_abort(const char *details) | ||
{ | ||
exit(1); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# The CPU frequency is never really used, except in some xtensa timer headers, so it's empty for Linux. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Original Kconfig has settings related to brownout, rom and cache. All non-existent on Linux. |
Oops, something went wrong.