-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add libmcu and unit test framework (#12)
- Loading branch information
Showing
20 changed files
with
336 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +0,0 @@ | ||
1c8a0938a69c1253735ac9878d0e0c5b | ||
36764e646064a94b9467eb13219bf56d | ||
afc0316ee5034294725332859b5e5a8d | ||
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 |
---|---|---|
@@ -1,2 +1,2 @@ | ||
text data bss dec hex filename | ||
159173 46760 367669 573602 8c0a2 build/template.elf | ||
177729 50704 371141 599574 92616 build/template.elf |
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,3 @@ | ||
[submodule "external/libmcu"] | ||
path = external/libmcu | ||
url = https://github.com/libmcu/libmcu.git |
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,13 @@ | ||
METRICS_DEFINE(HeartbeatInterval) | ||
METRICS_DEFINE(UnixTime) | ||
METRICS_DEFINE(MonotonicTime) | ||
METRICS_DEFINE(ResetCount) | ||
METRICS_DEFINE(ResetReason) | ||
METRICS_DEFINE(Assertions) | ||
METRICS_DEFINE(FaultExceptions) | ||
METRICS_DEFINE(OOM) | ||
METRICS_DEFINE(CPULoad) | ||
METRICS_DEFINE(HeapLowWatermark) | ||
METRICS_DEFINE(MainStackHighWatermark) | ||
METRICS_DEFINE(HeapAllocFailure) | ||
METRICS_DEFINE(BootingTime) |
This file was deleted.
Oops, something went wrong.
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
File renamed without changes.
4 changes: 2 additions & 2 deletions
4
ports/esp_idf/sdkconfig.defaults → ports/esp-idf/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
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,27 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2023 Kyunghwan Kwon <k@mononn.com> | ||
* | ||
* SPDX-License-Identifier: MIT | ||
*/ | ||
|
||
#include "freertos/FreeRTOS.h" | ||
#include "freertos/task.h" | ||
#include "nvs.h" | ||
#include "nvs_flash.h" | ||
#include "esp_event.h" | ||
#include "esp_system.h" | ||
|
||
extern int main(void); | ||
extern void app_main(void); | ||
|
||
static void esp_init(void) | ||
{ | ||
ESP_ERROR_CHECK(nvs_flash_init()); | ||
ESP_ERROR_CHECK(esp_event_loop_create_default()); | ||
} | ||
|
||
void app_main(void) | ||
{ | ||
esp_init(); | ||
main(); | ||
} |
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,8 @@ | ||
add_subdirectory(external/libmcu) | ||
|
||
target_compile_definitions(libmcu PUBLIC | ||
_POSIX_THREADS | ||
_POSIX_C_SOURCE=200809L | ||
LIBMCU_NOINIT=__attribute__\(\(section\(\".rtc.data.libmcu\"\)\)\) | ||
METRICS_USER_DEFINES=\"${PROJECT_SOURCE_DIR}/include/metrics.def\" | ||
) |
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,24 @@ | ||
set(fpl-src-dirs src) | ||
foreach(dir ${fpl-src-dirs}) | ||
file(GLOB_RECURSE fpl_${dir}_SRCS RELATIVE ${CMAKE_SOURCE_DIR} ${dir}/*.c) | ||
file(GLOB_RECURSE fpl_${dir}_CPP_SRCS RELATIVE ${CMAKE_SOURCE_DIR} ${dir}/*.cpp) | ||
list(APPEND FPL_SRCS ${fpl_${dir}_SRCS} ${fpl_${dir}_CPP_SRCS}) | ||
endforeach() | ||
|
||
set(APP_SRCS | ||
${CMAKE_SOURCE_DIR}/src/main.c | ||
) | ||
set(APP_INCS | ||
${CMAKE_SOURCE_DIR}/include | ||
) | ||
set(APP_DEFS | ||
BUILD_DATE=${BUILD_DATE} | ||
VERSION_MAJOR=${VERSION_MAJOR} | ||
VERSION_MINOR=${VERSION_MINOR} | ||
VERSION_PATCH=${VERSION_PATCH} | ||
VERSION_TAG=${VERSION_TAG} | ||
VERSION=${VERSION} | ||
|
||
_POSIX_THREADS | ||
_POSIX_C_SOURCE=200809L | ||
) |
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,30 @@ | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
execute_process( | ||
COMMAND git describe --long --tags --dirty --always | ||
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} | ||
OUTPUT_VARIABLE VERSION | ||
OUTPUT_STRIP_TRAILING_WHITESPACE | ||
) | ||
|
||
string(REPLACE "-" ";" VERSION_STR ${VERSION}) | ||
list(GET VERSION_STR 0 VERSION_NUMBER) | ||
string(REPLACE "v" "" VERSION_NUMBER_LIST ${VERSION_NUMBER}) | ||
string(REPLACE "." ";" VERSION_NUMBER_LIST ${VERSION_NUMBER_LIST}) | ||
list(GET VERSION_NUMBER_LIST 0 VERSION_MAJOR) | ||
|
||
list(LENGTH VERSION_NUMBER_LIST VERSION_NUMBER_LIST_COUNT) | ||
|
||
if (${VERSION_NUMBER_LIST_COUNT} GREATER_EQUAL 2) | ||
list(GET VERSION_NUMBER_LIST 1 VERSION_MINOR) | ||
list(GET VERSION_STR 1 VERSION_PATCH) | ||
endif() | ||
|
||
if (${VERSION_NUMBER_LIST_COUNT} GREATER_EQUAL 3) | ||
list(GET VERSION_NUMBER_LIST 2 BUILD_NUMBER_ORG) | ||
MATH(EXPR VERSION_PATCH "${BUILD_NUMBER_ORG} + ${VERSION_PATCH}") | ||
endif() | ||
|
||
set(VERSION_TAG "v${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}") | ||
|
||
string(TIMESTAMP BUILD_DATE "\"%Y-%m-%dT%H:%M:%SZ\"" UTC) |
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 |
---|---|---|
@@ -1,49 +1,51 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2010-2022 Espressif Systems (Shanghai) CO LTD | ||
* SPDX-FileCopyrightText: 2023 Kyunghwan Kwon <k@mononn.com> | ||
* | ||
* SPDX-License-Identifier: CC0-1.0 | ||
* SPDX-License-Identifier: MIT | ||
*/ | ||
|
||
#include <stdio.h> | ||
#include <inttypes.h> | ||
#include "sdkconfig.h" | ||
#include "freertos/FreeRTOS.h" | ||
#include "freertos/task.h" | ||
#include "esp_chip_info.h" | ||
#include "esp_flash.h" | ||
|
||
void app_main(void) | ||
|
||
#include "libmcu/board.h" | ||
#include "libmcu/logging.h" | ||
|
||
static size_t logging_stdout_writer(const void *data, size_t size) | ||
{ | ||
unused(size); | ||
static char buf[LOGGING_MESSAGE_MAXLEN]; | ||
size_t len = logging_stringify(buf, sizeof(buf)-1, data); | ||
|
||
buf[len++] = '\n'; | ||
buf[len] = '\0'; | ||
|
||
const size_t rc = fwrite(buf, len, 1, stdout); | ||
|
||
return rc == 0? len : 0; | ||
} | ||
|
||
static void logging_stdout_backend_init(void) | ||
{ | ||
printf("Hello world!\n"); | ||
|
||
/* Print chip information */ | ||
esp_chip_info_t chip_info; | ||
uint32_t flash_size; | ||
esp_chip_info(&chip_info); | ||
printf("This is %s chip with %d CPU core(s), WiFi%s%s, ", | ||
CONFIG_IDF_TARGET, | ||
chip_info.cores, | ||
(chip_info.features & CHIP_FEATURE_BT) ? "/BT" : "", | ||
(chip_info.features & CHIP_FEATURE_BLE) ? "/BLE" : ""); | ||
|
||
unsigned major_rev = chip_info.revision / 100; | ||
unsigned minor_rev = chip_info.revision % 100; | ||
printf("silicon revision v%d.%d, ", major_rev, minor_rev); | ||
if(esp_flash_get_size(NULL, &flash_size) != ESP_OK) { | ||
printf("Get flash size failed"); | ||
return; | ||
} | ||
|
||
printf("%" PRIu32 "MB %s flash\n", flash_size / (uint32_t)(1024 * 1024), | ||
(chip_info.features & CHIP_FEATURE_EMB_FLASH) ? "embedded" : "external"); | ||
|
||
printf("Minimum free heap size: %" PRIu32 " bytes\n", esp_get_minimum_free_heap_size()); | ||
|
||
for (int i = 10; i >= 0; i--) { | ||
printf("Restarting in %d seconds...\n", i); | ||
vTaskDelay(1000 / portTICK_PERIOD_MS); | ||
} | ||
printf("Restarting now.\n"); | ||
fflush(stdout); | ||
esp_restart(); | ||
static struct logging_backend log_console = { | ||
.write = logging_stdout_writer, | ||
}; | ||
|
||
logging_add_backend(&log_console); | ||
} | ||
|
||
int main(void) | ||
{ | ||
board_init(); /* should be called very first. */ | ||
logging_init(board_get_time_since_boot_ms); | ||
|
||
logging_stdout_backend_init(); | ||
|
||
const board_reboot_reason_t reboot_reason = board_get_reboot_reason(); | ||
|
||
info("[%s] %s %s", board_get_reboot_reason_string(reboot_reason), | ||
board_get_serial_number_string(), | ||
board_get_version_string()); | ||
|
||
while (1) { | ||
/* hang */ | ||
} | ||
} |
Oops, something went wrong.