From 21a93911da00ca96f86c8b9841a05307f830e764 Mon Sep 17 00:00:00 2001 From: Silvano Seva Date: Wed, 26 Jul 2023 11:57:52 +0200 Subject: [PATCH] Added support for ESP32-S3 MCU using Zephyr RTOS --- .gitignore | 4 +- CMakeLists.txt | 113 ++++++++++++++++++++++++++ platform/mcu/ESP32S3/drivers/delays.c | 52 ++++++++++++ platform/mcu/ESP32S3/zephyr.conf | 21 +++++ 4 files changed, 188 insertions(+), 2 deletions(-) create mode 100644 CMakeLists.txt create mode 100644 platform/mcu/ESP32S3/drivers/delays.c create mode 100644 platform/mcu/ESP32S3/zephyr.conf diff --git a/.gitignore b/.gitignore index 176dd856..7bcd13fa 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ -# Meson build dirs -build_* +#Build dirs +build* # Prerequisites *.d diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 00000000..7e0e7274 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,113 @@ +# SPDX-License-Identifier: GPL-3.0-or-later + +cmake_minimum_required(VERSION 3.20.0) + +find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) +project(openrtx) + +execute_process(COMMAND git describe --tags --dirty + OUTPUT_VARIABLE GIT_VER_ID + ERROR_QUIET + OUTPUT_STRIP_TRAILING_WHITESPACE) + +target_compile_definitions(app + PRIVATE + FONT_UBUNTU_REGULAR + CODEC2_MODE_EN_DEFAULT=0 + FREEDV_MODE_EN_DEFAULT=0 + CODEC2_MODE_3200_EN=1 + M_PI=3.14159265358979323846f + GIT_VERSION="${GIT_VER_ID}" +) + +target_include_directories(app + PRIVATE + + openrtx/include + openrtx/include/rtx + openrtx/include/core + openrtx/include/calibration + openrtx/include/protocols + openrtx/include/fonts/adafruit + openrtx/include/fonts/symbols + platform/drivers/ADC + platform/drivers/NVM + platform/drivers/GPS + platform/drivers/USB + platform/drivers/tones + platform/drivers/baseband + platform/drivers/backlight + platform/drivers/chSelector + + subprojects/codec2 + subprojects/codec2/src + + lib/minmea/include + lib/qdec/include +) + +target_sources(app + PRIVATE + + openrtx/src/main.c + openrtx/src/core/state.c + openrtx/src/core/threads.c + openrtx/src/core/battery.c + openrtx/src/core/graphics.c + openrtx/src/core/input.c + openrtx/src/core/utils.c + openrtx/src/core/queue.c + openrtx/src/core/chan.c + openrtx/src/core/gps.c + openrtx/src/core/dsp.cpp + openrtx/src/core/cps.c + openrtx/src/core/crc.c + openrtx/src/core/datetime.c + openrtx/src/core/openrtx.c + openrtx/src/core/audio_codec.c + openrtx/src/core/audio_stream.c + openrtx/src/core/audio_path.cpp + openrtx/src/core/data_conversion.c + openrtx/src/core/memory_profiling.cpp + openrtx/src/core/voicePrompts.c + openrtx/src/core/voicePromptUtils.c + openrtx/src/core/voicePromptData.S + openrtx/src/rtx/rtx.cpp + openrtx/src/rtx/OpMode_FM.cpp + openrtx/src/rtx/OpMode_M17.cpp + openrtx/src/protocols/M17/M17DSP.cpp + openrtx/src/protocols/M17/M17Golay.cpp + openrtx/src/protocols/M17/M17Callsign.cpp + openrtx/src/protocols/M17/M17Modulator.cpp + openrtx/src/protocols/M17/M17Demodulator.cpp + openrtx/src/protocols/M17/M17FrameEncoder.cpp + openrtx/src/protocols/M17/M17FrameDecoder.cpp + openrtx/src/protocols/M17/M17LinkSetupFrame.cpp + + openrtx/src/ui/default/ui.c + openrtx/src/ui/default/ui_main.c + openrtx/src/ui/default/ui_menu.c + openrtx/src/ui/default/ui_strings.c + + subprojects/codec2/src/dump.c + subprojects/codec2/src/lpc.c + subprojects/codec2/src/nlp.c + subprojects/codec2/src/phase.c + subprojects/codec2/src/quantise.c + subprojects/codec2/src/postfilter.c + subprojects/codec2/src/codec2.c + subprojects/codec2/src/codec2_fft.c + subprojects/codec2/src/lsp.c + subprojects/codec2/src/sine.c + subprojects/codec2/src/interp.c + subprojects/codec2/src/kiss_fft.c + subprojects/codec2/src/kiss_fftr.c + subprojects/codec2/src/newamp1.c + subprojects/codec2/src/codebook.c + subprojects/codec2/src/codebookd.c + subprojects/codec2/src/pack.c + subprojects/codec2/src/codebooknewamp1.c + subprojects/codec2/src/codebooknewamp1_energy.c + + lib/minmea/minmea.c +) diff --git a/platform/mcu/ESP32S3/drivers/delays.c b/platform/mcu/ESP32S3/drivers/delays.c new file mode 100644 index 00000000..a31205f1 --- /dev/null +++ b/platform/mcu/ESP32S3/drivers/delays.c @@ -0,0 +1,52 @@ +/*************************************************************************** + * Copyright (C) 2023 by Silvano Seva IU2KWO * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 3 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, see * + ***************************************************************************/ + +#include +#include +#include + + +void delayUs(unsigned int useconds) +{ + k_usleep(useconds); +} + +void delayMs(unsigned int mseconds) +{ + k_msleep(mseconds); +} + +void sleepFor(unsigned int seconds, unsigned int mseconds) +{ + uint64_t duration = (seconds * 1000) + mseconds; + k_sleep(K_MSEC(duration)); +} + +void sleepUntil(long long timestamp) +{ + if(timestamp <= k_uptime_get()) + return; + + k_sleep(K_TIMEOUT_ABS_MS(timestamp)); +} + +long long getTick() +{ + // k_uptime_get() returns the elapsed time since the system booted, + // in milliseconds. + return k_uptime_get(); +} diff --git a/platform/mcu/ESP32S3/zephyr.conf b/platform/mcu/ESP32S3/zephyr.conf new file mode 100644 index 00000000..ef4c4719 --- /dev/null +++ b/platform/mcu/ESP32S3/zephyr.conf @@ -0,0 +1,21 @@ +CONFIG_POSIX_CLOCK=y +CONFIG_PTHREAD_IPC=y +CONFIG_CPP=y +CONFIG_REQUIRES_FULL_LIBCPP=y +CONFIG_STD_CPP14=y +CONFIG_PRINTK=y +CONFIG_LOG=y +CONFIG_LOG_PRINTK=y +CONFIG_LOG_MODE_IMMEDIATE=y +CONFIG_XTENSA_RESET_VECTOR=n +CONFIG_SOC_ESP32S3=y +CONFIG_MAIN_STACK_SIZE=2048 +CONFIG_XTENSA_USE_CORE_CRT1=n +CONFIG_CONSOLE=y +CONFIG_SERIAL=y +CONFIG_UART_CONSOLE=y +CONFIG_GPIO=y +CONFIG_GEN_ISR_TABLES=y +CONFIG_GEN_IRQ_VECTOR_TABLE=n +CONFIG_CLOCK_CONTROL=y +CONFIG_I2C=y