未验证 提交 0a6aaf12 编写于 作者: W WCX 提交者: GitHub

[bsp][esp32-c3] Realization of scons compilation of ESP32-C3 | 实现ESP32-C3的scons编译 (#7821)

Co-authored-by: Thomas_Fly's avatarSupper Thomas <78900636@qq.com>
上级 7e5620ed
......@@ -303,7 +303,10 @@ jobs:
RTT_TOOL_CHAIN: "gcc"
SUB_RTT_BSP:
- "simulator"
- RTT_BSP: "ESP32C3"
RTT_TOOL_CHAIN: "sourcery-riscv32-esp32"
SUB_RTT_BSP:
- "ESP32_C3"
steps:
- uses: actions/checkout@v3
- name: Set up Python
......@@ -376,6 +379,15 @@ jobs:
/opt/xpack-riscv-none-embed-gcc-8.3.0-2.3/bin/riscv-none-embed-gcc --version
echo "RTT_EXEC_PATH=/opt/xpack-riscv-none-embed-gcc-8.3.0-2.3/bin" >> $GITHUB_ENV
- name: Install riscv32-esp-elf ToolChains
if: ${{ matrix.legs.RTT_TOOL_CHAIN == 'sourcery-riscv32-esp32' && success() }}
run: |
wget -q https://github.com/espressif/crosstool-NG/releases/download/esp-2022r1-RC1/riscv32-esp-elf-gcc11_2_0-esp-2022r1-RC1-linux-amd64.tar.xz
sudo tar xf riscv32-esp-elf-gcc11_2_0-esp-2022r1-RC1-linux-amd64.tar.xz -C /opt
/opt/riscv32-esp-elf/bin/riscv32-esp-elf-gcc --version
/usr/bin/pip install esptool
echo "RTT_EXEC_PATH=/opt/riscv32-esp-elf/bin" >> $GITHUB_ENV
- name: Install Simulator Tools
if: ${{ matrix.legs.RTT_TOOL_CHAIN == 'gcc' && success() }}
run: |
......
......@@ -8,6 +8,7 @@
#
CONFIG_RT_NAME_MAX=8
# CONFIG_RT_USING_ARCH_DATA_TYPE is not set
# CONFIG_RT_USING_AMP is not set
# CONFIG_RT_USING_SMP is not set
CONFIG_RT_ALIGN_SIZE=8
# CONFIG_RT_THREAD_PRIORITY_8 is not set
......@@ -40,12 +41,12 @@ CONFIG_RT_USING_MUTEX=y
CONFIG_RT_USING_EVENT=y
CONFIG_RT_USING_MAILBOX=y
CONFIG_RT_USING_MESSAGEQUEUE=y
# CONFIG_RT_USING_MESSAGEQUEUE_PRIORITY is not set
# CONFIG_RT_USING_SIGNALS is not set
#
# Memory Management
#
CONFIG_RT_PAGE_MAX_ORDER=11
CONFIG_RT_USING_MEMPOOL=y
CONFIG_RT_USING_SMALL_MEM=y
# CONFIG_RT_USING_SLAB is not set
......@@ -69,7 +70,7 @@ CONFIG_RT_USING_DEVICE=y
CONFIG_RT_USING_CONSOLE=y
CONFIG_RT_CONSOLEBUF_SIZE=256
CONFIG_RT_CONSOLE_DEVICE_NAME="uart"
CONFIG_RT_VER_NUM=0x50000
CONFIG_RT_VER_NUM=0x50001
# CONFIG_RT_USING_STDC_ATOMIC is not set
# CONFIG_RT_USING_CACHE is not set
# CONFIG_RT_USING_HW_ATOMIC is not set
......@@ -100,6 +101,10 @@ CONFIG_FINSH_USING_DESCRIPTION=y
# CONFIG_FINSH_ECHO_DISABLE_DEFAULT is not set
# CONFIG_FINSH_USING_AUTH is not set
CONFIG_FINSH_ARG_MAX=10
#
# DFS: device virtual file system
#
# CONFIG_RT_USING_DFS is not set
# CONFIG_RT_USING_FAL is not set
......@@ -194,6 +199,7 @@ CONFIG_RT_LIBC_DEFAULT_TIMEZONE=8
# CONFIG_RT_USING_ULOG is not set
# CONFIG_RT_USING_UTEST is not set
# CONFIG_RT_USING_VAR_EXPORT is not set
# CONFIG_RT_USING_RESOURCE_ID is not set
# CONFIG_RT_USING_ADT is not set
# CONFIG_RT_USING_RT_LINK is not set
# CONFIG_RT_USING_VBUS is not set
......@@ -221,7 +227,6 @@ CONFIG_RT_LIBC_DEFAULT_TIMEZONE=8
# CONFIG_PKG_USING_KAWAII_MQTT is not set
# CONFIG_PKG_USING_BC28_MQTT is not set
# CONFIG_PKG_USING_WEBTERMINAL is not set
# CONFIG_PKG_USING_LIBMODBUS is not set
# CONFIG_PKG_USING_FREEMODBUS is not set
# CONFIG_PKG_USING_NANOPB is not set
......@@ -458,6 +463,8 @@ CONFIG_RT_LIBC_DEFAULT_TIMEZONE=8
# CONFIG_PKG_USING_UC_MODBUS is not set
CONFIG_PKG_USING_FREERTOS_WRAPPER=y
CONFIG_PKG_FREERTOS_WRAPPER_PATH="/packages/system/FreeRTOS_Wrapper"
CONFIG_PKG_FREERTOS_USING_CONFIG_H=y
# CONFIG_PKG_FREERTOS_USING_MEMMANG is not set
CONFIG_PKG_USING_FREERTOS_WRAPPER_LATEST_VERSION=y
CONFIG_PKG_FREERTOS_WRAPPER_VER="latest"
# CONFIG_PKG_USING_CAIRO is not set
......@@ -495,6 +502,7 @@ CONFIG_PKG_FREERTOS_WRAPPER_VER="latest"
# CONFIG_PKG_USING_QPC is not set
# CONFIG_PKG_USING_AGILE_UPGRADE is not set
# CONFIG_PKG_USING_FLASH_BLOB is not set
# CONFIG_PKG_USING_MLIBC is not set
#
# peripheral libraries and drivers
......@@ -559,6 +567,7 @@ CONFIG_PKG_FREERTOS_WRAPPER_VER="latest"
# CONFIG_PKG_USING_BALANCE is not set
# CONFIG_PKG_USING_SHT2X is not set
# CONFIG_PKG_USING_SHT3X is not set
# CONFIG_PKG_USING_SHT4X is not set
# CONFIG_PKG_USING_AD7746 is not set
# CONFIG_PKG_USING_ADT74XX is not set
# CONFIG_PKG_USING_MAX17048 is not set
......@@ -579,6 +588,7 @@ CONFIG_PKG_FREERTOS_WRAPPER_VER="latest"
# CONFIG_PKG_USING_FT5426 is not set
# CONFIG_PKG_USING_FT6236 is not set
# CONFIG_PKG_USING_XPT2046_TOUCH is not set
# CONFIG_PKG_USING_CST816X is not set
# CONFIG_PKG_USING_REALTEK_AMEBA is not set
# CONFIG_PKG_USING_STM32_SDIO is not set
CONFIG_PKG_USING_ESP_IDF=y
......@@ -594,7 +604,6 @@ CONFIG_PKG_ESP_IDF_VER="latest"
# CONFIG_PKG_USING_LKDGUI is not set
# CONFIG_PKG_USING_NRF5X_SDK is not set
# CONFIG_PKG_USING_NRFX is not set
# CONFIG_PKG_USING_WM_LIBRARIES is not set
#
# Kendryte SDK
......@@ -652,14 +661,18 @@ CONFIG_PKG_ESP_IDF_VER="latest"
# CONFIG_PKG_USING_MISAKA_AT24CXX is not set
# CONFIG_PKG_USING_MISAKA_RGB_BLING is not set
# CONFIG_PKG_USING_LORA_MODEM_DRIVER is not set
# CONFIG_PKG_USING_BL_MCU_SDK is not set
# CONFIG_PKG_USING_SOFT_SERIAL is not set
# CONFIG_PKG_USING_MB85RS16 is not set
# CONFIG_PKG_USING_RFM300 is not set
# CONFIG_PKG_USING_IO_INPUT_FILTER is not set
# CONFIG_PKG_USING_RASPBERRYPI_PICO_SDK is not set
# CONFIG_PKG_USING_LRF_NV7LIDAR is not set
# CONFIG_PKG_USING_AIP650 is not set
# CONFIG_PKG_USING_FINGERPRINT is not set
# CONFIG_PKG_USING_BT_ECB02C is not set
# CONFIG_PKG_USING_UAT is not set
# CONFIG_PKG_USING_ST7789 is not set
# CONFIG_PKG_USING_SPI_TOOLS is not set
#
# AI packages
......@@ -678,7 +691,10 @@ CONFIG_PKG_ESP_IDF_VER="latest"
# Signal Processing and Control Algorithm Packages
#
# CONFIG_PKG_USING_FIRE_PID_CURVE is not set
# CONFIG_PKG_USING_QPID is not set
# CONFIG_PKG_USING_UKAL is not set
# CONFIG_PKG_USING_DIGITALCTRL is not set
# CONFIG_PKG_USING_KISSFFT is not set
#
# miscellaneous packages
......@@ -725,7 +741,6 @@ CONFIG_PKG_ESP_IDF_VER="latest"
# CONFIG_PKG_USING_DSTR is not set
# CONFIG_PKG_USING_TINYFRAME is not set
# CONFIG_PKG_USING_KENDRYTE_DEMO is not set
# CONFIG_PKG_USING_DIGITALCTRL is not set
# CONFIG_PKG_USING_UPACKER is not set
# CONFIG_PKG_USING_UPARAM is not set
# CONFIG_PKG_USING_HELLO is not set
......@@ -750,8 +765,9 @@ CONFIG_PKG_ESP_IDF_VER="latest"
# CONFIG_PKG_USING_RTDUINO is not set
#
# Projects
# Projects and Demos
#
# CONFIG_PKG_USING_ARDUINO_MSGQ_C_CPP_DEMO is not set
# CONFIG_PKG_USING_ARDUINO_ULTRASOUND_RADAR is not set
# CONFIG_PKG_USING_ARDUINO_SENSOR_KIT is not set
# CONFIG_PKG_USING_ARDUINO_MATLAB_SUPPORT is not set
......@@ -898,14 +914,20 @@ CONFIG_PKG_ESP_IDF_VER="latest"
#
# Display
#
# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_GFX_LIBRARY is not set
# CONFIG_PKG_USING_ARDUINO_U8G2 is not set
# CONFIG_PKG_USING_ARDUINO_U8GLIB_ARDUINO is not set
# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_ST7735 is not set
# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_SSD1306 is not set
# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_ILI9341 is not set
# CONFIG_PKG_USING_SEEED_TM1637 is not set
#
# Timing
#
# CONFIG_PKG_USING_ARDUINO_RTCLIB is not set
# CONFIG_PKG_USING_ARDUINO_MSTIMER2 is not set
# CONFIG_PKG_USING_ARDUINO_TICKER is not set
# CONFIG_PKG_USING_ARDUINO_TASKSCHEDULER is not set
#
# Data Processing
......@@ -939,7 +961,6 @@ CONFIG_PKG_ESP_IDF_VER="latest"
#
# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_MFRC630 is not set
# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_SI5351 is not set
# CONFIG_PKG_USING_ARDUINO_RTCLIB is not set
#
# Signal IO
......@@ -962,7 +983,6 @@ CONFIG_SOC_ESP32_C3=y
#
# Hardware Drivers Config
#
# CONFIG_BSP_USING_LOCAL_ESP_IDF is not set
CONFIG_BSP_BOARD_LUATOS_ESP32C3=y
# CONFIG_BSP_BOARD_HX_EXP32C3 is not set
......
......@@ -43,69 +43,73 @@ Each peripheral supporting condition for this BSP is as follows:
| UART | Support | Using LUATOS_ESP32C3 development board requires connecting serial port to USB chip UART0_TX and UART0_RX (such as CP2102) |
| JTAG debug | Support | ESP32C3 usb-linked development boards can be debugged |
## Install ESP-IDF
ESP-IDF can be installed in two ways
1. Use Env tool
- Download the package
```
pkgs --update
```
- Install IDF tools. If you are using Linux or MacOS, go to ESP-IDF package directory and install IDF tools by running
```
cd packages/ESP-IDF-latest
./install.sh
```
If you are using Windows, open Command Prompt. Note that you cannot use any other terminals, such as the Env command line or PowerShell. Enter the BSP directory and run
```
install.bat
```
No matter what operating system you are using, this step only needs to be done once after the package is downloaded for the first time.
- Under the ESP-IDF package directory, export IDF environment variables. This commands need to be run every time when the BSP is built in a new terminal.
If you are using Linux or MacOS, run
```
. export.sh
```
If you are using Windows, run
```
export.bat
```
Same as the previous step, you can only use Command Prompt.
2. Apply patch to a local installation of ESP-IDF
- Select the below option with `SCons --menuconfig`
```
Hardware Drivers Config
[*] Use local ESP-IDF installation
```
And deselect ESP-IDF package
```
RT-Thread online packages
peripheral libraries and drivers
[ ] ESP-IDF: Espressif IoT Development Framework
```
- Install FreeRTOS wrapper
```
pkgs --update
```
- Any convenient method to install ESP-IDF can be used, such as [VSCode plugin](https://github.com/espressif/vscode-esp-idf-extension/blob/master/docs/tutorial/install.md). Make sure to install the master version of ESP-IDF.
- Enter the local ESP-IDF directory and run the following commands
```
git checkout 5c1044d84d625219eafa18c24758d9f0e4006b2c
# Replace rtt.patch with the actual directory of rtt.patch under the BSP directory
git am rtt.patch
```
- After applying the patch, ESP-IDF FreeRTOS projects can be compiled as usual
## Compile and Upload
- Configure RT-Thread under the BSP directory
```
scons --menuconfig
```
- Whenever RT-Thread configuration is changed with `scons --menuconfig`, a new `CMakeLists.txt` needs to be generated with the command below
```
scons --target=esp-idf
```
- If ESP-IDf is installed using Env, use `idf.py` to compile and upload the program. Refer to [Espressif official documents](https://docs.espressif.com/projects/esp-idf/en/latest/esp32c3/get-started/index.html#build-your-first-project) for reference. Note if you are using Windows, you can only use `idf.py` commands in Windows Command Prompt. Otherwise follow the appropriate steps depending on how ESP-IDF was installed, such as using [VSCode plugin](https://github.com/espressif/vscode-esp-idf-extension/blob/master/docs/tutorial/install.md).
- Once the project is successfully downloaded, the system runs automatically, the red LED will blink in 1s on cycles.
## Environment construction and compilation
1. Download the RISC-V toolchain:
```sh
wget https://github.com/espressif/crosstool-NG/releases/download/esp-2022r1-RC1/riscv32-esp-elf-gcc11_2_0-esp-2022r1-RC1-linux-amd64.tar.xz
tar xf riscv32-esp-elf-gcc11_2_0-esp-2022r1-RC1-linux-amd64.tar.xz
```
2. Configure the path of the toolchain:
Add the local path of the `RISC-V` toolchain to the `EXEC_PATH` variable in the `rtconfig.py` file, or specify the path by setting the `RTT_EXEC_PATH` environment variable, for example:
```sh
export RTT_EXEC_PATH=/opt/riscv32-esp-elf/bin
```
3. Compile
Install esptool to convert ELF files to binary flash files:
```sh
pip install esptool
```
Execute the following command on the Linux platform to configure:
```
scons --menuconfig
```
It will automatically download env-related scripts to the `~/.env` directory, and then execute:
```sh
source ~/.env/env.sh
cd bsp/ESP32_C3/
pkgs --update
```
It will automatically download `RT-Thread-packages/esp-idf` and `RT-Thread-packages/FreeRTOS-Wrapper`, after updating the software packages, execute `scons` to compile the board support package.
If the compilation is successful, `rtthread.elf`, `rtthread.bin` files will be generated.
## Download and program
1. Programming tool download
The current bsp test uses the `flash_download_tool_3.9.4` tool to program without errors.
Programming tool download address: [https://www.espressif.com.cn/sites/default/files/tools/flash_download_tool_3.9.4_0.zip](https://www.espressif.com.cn/sites/default/files/tools/flash_download_tool_3.9.4_0.zip)
2. Programming tool configuration
Chip model selection `ESP32-C3`
Configure the binary file and offset address as follows:
| binary file | offset address |
| ------------------- | -------- |
| bootloader.bin | 0x0 |
| partition-table.bin | 0x8000 |
| rtthread.bin | 0x10000 |
Among them, `bootloader.bin` and `partition-table.bin` can be found in the `bsp/ESP32_C3/builtin_imgs` folder. After the configuration is completed, the screenshot is as follows, and then click `START` to download.
![flash_download_tools](images/flash_download_tools.png)
## Notes
......
......@@ -50,70 +50,73 @@
| UART | 支持 | 使用LUATOS_ESP32C3开发板需要在UART0_TX和UART0_RX连接串口转USB芯片(如CP2102)|
| JTAG调试 | 支持 | ESP32C3采用USB方式和PC链接的开发板可以调试 |
## 安装ESP-IDF
可以使用两种方法安装ESP-IDF
1. 使用Env工具安装
- 下载软件包
```
pkgs --update
```
- 安装IDF工具链。如果使用Linux或MacOS系统,在命令行内进入到ESP-IDF软件包路径,安装IDf工具链。
```
cd packages/ESP-IDF-latest
./install.sh
```
如果使用Windows系统,打开Command Prompt,注意不能使用其他任何命令行,如Env命令行和PowerShell。进入BSP目录并执行
```
install.bat
```
无论使用任何系统,这一步只需要在下载完软件包后执行一次。
- 在软件包路径下设置IDF路径。每当在新的命令行编译BSP时需要执行此命令。
如果使用Linux或MacOS系统,执行
```
. export.sh
```
如果使用Windows系统,执行
```
export.bat
```
这一步仍然只能使用Command Prompt。
2. 在本地ESP-IDF加载patch
- 通过`SCons --menuconfig`选择
```
Hardware Drivers Config
[*] Use local ESP-IDF installation
```
并取消勾选ESP-IDF软件包
```
RT-Thread online packages
peripheral libraries and drivers
[ ] ESP-IDF: Espressif IoT Development Framework
```
- 使用Env工具下载FreeRTOS兼容层
```
pkgs --update
```
- 可以选择其他方式在本地安装ESP-IDF,如[VSCode插件](https://github.com/espressif/vscode-esp-idf-extension/blob/master/docs/tutorial/install.md)。确保安装的ESP-IDF是master版本。
- 进入本地ESP-IDF目录执行以下命令
```
git checkout 5c1044d84d625219eafa18c24758d9f0e4006b2c
# 把rtt.patch换成BSP目录下rtt.patch的正确路径
git am rtt.patch
```
- 加载patch后不会影响使用ESP-IDF编译基于FreeRTOS的工程
## 编译和烧录
1. 在BSP路径下配置RT-Thread
```
scons --menuconfig
```
2. 每当使用`scons --menuconfig`更改RT-Thread配置后需要重新生成`CMakeLists.txt`
```
scons --target=esp-idf
```
3. 如果使用Env安装了ESP-IDF,使用`idf.py`命令编译,烧录。具体参考[乐鑫官网](https://docs.espressif.com/projects/esp-idf/en/latest/esp32c3/get-started/index.html#build-your-first-project)。注意如果使用Windows系统,`idf.py`只能在Command Prompt里执行。如果使用了在本地ESP-IDF加载patch的方式,可使用其他相应的编译和烧录方法,如[VSCode插件](https://github.com/espressif/vscode-esp-idf-extension/blob/master/docs/tutorial/install.md)
4. 下载程序成功之后,系统会运行,红色的 LED灯以 1S 周期闪烁。
## 环境搭建及编译
1. 下载 RISC-V 工具链:
```sh
wget https://github.com/espressif/crosstool-NG/releases/download/esp-2022r1-RC1/riscv32-esp-elf-gcc11_2_0-esp-2022r1-RC1-linux-amd64.tar.xz
tar xf riscv32-esp-elf-gcc11_2_0-esp-2022r1-RC1-linux-amd64.tar.xz
```
2. 配置工具链的路径:
在`rtconfig.py`文件中将`RISC-V`工具链的本地路径添加到`EXEC_PATH`变量中,或者通过设置 `RTT_EXEC_PATH`环境变量指定路径,例如:
```sh
export RTT_EXEC_PATH=/opt/riscv32-esp-elf/bin
```
3. 编译
安装 esptool 用于转换 ELF 文件为二进制烧录文件:
```sh
pip install esptool
```
在 Linux 平台下执行以下命令进行配置:
```
scons --menuconfig
```
它会自动下载env相关脚本到`~/.env`目录,然后执行:
```sh
source ~/.env/env.sh
cd bsp/ESP32_C3/
pkgs --update
```
它会自动下载`RT-Thread-packages/esp-idf`和`RT-Thread-packages/FreeRTOS-Wrapper`,更新完软件包后,执行 `scons` 来编译这个板级支持包。
如果编译成功,将生成`rtthread.elf`、`rtthread.bin`文件。
## 下载烧录
1. 烧录工具下载
当前bsp测试使用`flash_download_tool_3.9.4`工具进行烧录无误。
烧录工具下载地址:[https://www.espressif.com.cn/sites/default/files/tools/flash_download_tool_3.9.4_0.zip](https://www.espressif.com.cn/sites/default/files/tools/flash_download_tool_3.9.4_0.zip)
2. 烧录工具配置
芯片型号选择`ESP32-C3`
将二进制文件与偏移地址配置如下:
| 二进制文件 | 偏移地址 |
| ------------------- | -------- |
| bootloader.bin | 0x0 |
| partition-table.bin | 0x8000 |
| rtthread.bin | 0x10000 |
其中`bootloader.bin`和`partition-table.bin`可在`bsp/ESP32_C3/builtin_imgs`文件夹下找到,配置完成后截图如下,之后点击`START`即可下载。
![flash_download_tools](images/flash_download_tools.png)
## 注意事项
......
import os
import sys
import rtconfig
from esptool.bin_image import ELFFile, ImageSegment, LoadFirmwareImage
from esptool.targets import CHIP_DEFS, CHIP_LIST, ROM_LIST
def elf2image(target, source, env):
e = ELFFile("rtthread.elf")
print("Creating esp32c3 image...")
image = CHIP_DEFS["esp32c3"].BOOTLOADER_IMAGE()
image.min_rev = 3
image.entrypoint = e.entrypoint
image.flash_mode = 2 # flash_mode: dio
# ELFSection is a subclass of ImageSegment, so can use interchangeably
image.segments = e.sections
image.flash_size_freq = image.ROM_LOADER.parse_flash_size_arg("4MB")
image.flash_size_freq += image.ROM_LOADER.parse_flash_freq_arg("80m")
image.elf_sha256 = e.sha256()
image.elf_sha256_offset = 0xb0
before = len(image.segments)
image.merge_adjacent_segments()
if len(image.segments) != before:
delta = before - len(image.segments)
print("Merged %d ELF section%s" % (delta, "s" if delta > 1 else ""))
image.verify()
image.save("rtthread.bin")
print("Successfully created esp32c3 image.")
if os.getenv('RTT_ROOT'):
RTT_ROOT = os.getenv('RTT_ROOT')
......@@ -30,3 +62,6 @@ objs = PrepareBuilding(env, RTT_ROOT, remove_components = ['libc'])
# make a building
DoBuilding(TARGET, objs)
# 添加构建后的钩子函数
env.AddPostAction(TARGET, elf2image)
!bootloader.bin
!partition-table.bin
......@@ -7,15 +7,13 @@ config SOC_ESP32_C3
select SOC_ESPRESSIF
select RT_USING_COMPONENTS_INIT
select RT_USING_USER_MAIN
select PKG_USING_ESP_IDF if BSP_USING_LOCAL_ESP_IDF = n
select PKG_USING_ESP_IDF
select PKG_USING_FREERTOS_WRAPPER
select PKG_FREERTOS_USING_CONFIG_H
default y
menu "Hardware Drivers Config"
config BSP_USING_LOCAL_ESP_IDF
bool "Use local ESP-IDF installation"
default n
choice
prompt "Select BSP board "
default BSP_BOARD_LUATOS_ESP32C3
......
此差异已折叠。
import os
from building import *
src = Split("""
src/rt-thread_balance_stub.c
src/x509_crt_bundle.S
src/port.c
src/port_common.c
""")
CPPPATH = Split(
"""
include
include/freertos
""")
group = DefineGroup('idf_port', src, depend = [''], CPPPATH = CPPPATH)
Return('group')
/*
* SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef FREERTOS_CONFIG_H
#define FREERTOS_CONFIG_H
#include "sdkconfig.h"
/*
This file get's pulled into assembly sources. Therefore, some includes need to be wrapped in #ifndef __ASSEMBLER__
*/
#ifndef __ASSEMBLER__
#include <assert.h> //For configASSERT()
#endif /* def __ASSEMBLER__ */
#ifdef CONFIG_FREERTOS_SMP
// Pull in the SMP configuration
#include "freertos/FreeRTOSConfig_smp.h"
#else // CONFIG_FREERTOS_SMP
// The arch-specific FreeRTOSConfig_arch.h in port/<arch>/include.
#include "freertos/FreeRTOSConfig_arch.h"
#if !(defined(FREERTOS_CONFIG_XTENSA_H) || defined(FREERTOS_CONFIG_RISCV_H) || defined(FREERTOS_CONFIG_LINUX_H))
#error "Needs architecture-speific FreeRTOSConfig.h!"
#endif
/* ----------------------------------------------------- Helpers -------------------------------------------------------
* - Macros that the FreeRTOS configuration macros depend on
* ------------------------------------------------------------------------------------------------------------------ */
/* Higher stack checker modes cause overhead on each function call */
#if CONFIG_STACK_CHECK_ALL || CONFIG_STACK_CHECK_STRONG
#define STACK_OVERHEAD_CHECKER 256
#else
#define STACK_OVERHEAD_CHECKER 0
#endif
/* with optimizations disabled, scheduler uses additional stack */
#if CONFIG_COMPILER_OPTIMIZATION_NONE
#define STACK_OVERHEAD_OPTIMIZATION 320
#else
#define STACK_OVERHEAD_OPTIMIZATION 0
#endif
/* apptrace mdule increases minimum stack usage */
#if CONFIG_APPTRACE_ENABLE
#define STACK_OVERHEAD_APPTRACE 1280
#else
#define STACK_OVERHEAD_APPTRACE 0
#endif
/* Stack watchpoint decreases minimum usable stack size by up to 60 bytes.
See FreeRTOS FREERTOS_WATCHPOINT_END_OF_STACK option in Kconfig. */
#if CONFIG_FREERTOS_WATCHPOINT_END_OF_STACK
#define STACK_OVERHEAD_WATCHPOINT 60
#else
#define STACK_OVERHEAD_WATCHPOINT 0
#endif
#define configSTACK_OVERHEAD_TOTAL ( \
STACK_OVERHEAD_CHECKER + \
STACK_OVERHEAD_OPTIMIZATION + \
STACK_OVERHEAD_APPTRACE + \
STACK_OVERHEAD_WATCHPOINT)
/* ------------------------------------------------- FreeRTOS Config ---------------------------------------------------
* - All Vanilla FreeRTOS configuration goes into this section
* - Keep this section in-sync with the corresponding version of single-core upstream version of FreeRTOS
* - Don't put any SMP or ESP-IDF exclusive FreeRTOS configurations here. Those go into the next section
* - Not all FreeRTOS configuration are listed. Some configurations have default values set in FreeRTOS.h thus don't
* need to be explicitly defined.
* ------------------------------------------------------------------------------------------------------------------ */
/*-----------------------------------------------------------
* Application specific definitions.
*
* These definitions should be adjusted for your particular hardware and
* application requirements.
*
* THESE PARAMETERS ARE DESCRIBED WITHIN THE 'CONFIGURATION' SECTION OF THE
* FreeRTOS API DOCUMENTATION AVAILABLE ON THE FreeRTOS.org WEB SITE.
*
* See http://www.freertos.org/a00110.html
*----------------------------------------------------------*/
// ------------------ Scheduler Related --------------------
// #define configUSE_PREEMPTION 1
// #define configUSE_TICKLESS_IDLE CONFIG_FREERTOS_USE_TICKLESS_IDLE
#if configUSE_TICKLESS_IDLE
#define configEXPECTED_IDLE_TIME_BEFORE_SLEEP CONFIG_FREERTOS_IDLE_TIME_BEFORE_SLEEP
#endif // configUSE_TICKLESS_IDLE
#define configCPU_CLOCK_HZ (CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ * 1000000)
// #define configTICK_RATE_HZ CONFIG_FREERTOS_HZ
// #define configMAX_PRIORITIES ( 25 ) //This has impact on speed of search for highest priority
// #define configMINIMAL_STACK_SIZE ( 768 + configSTACK_OVERHEAD_TOTAL )
// #define configUSE_TIME_SLICING 1
// #define configUSE_16_BIT_TICKS 0
#define configIDLE_SHOULD_YIELD 0
#define configKERNEL_INTERRUPT_PRIORITY 1 // Todo: This currently isn't used anywhere
// ------------- Synchronization Primitives ----------------
// #define configUSE_MUTEXES 1
// #define configUSE_RECURSIVE_MUTEXES 1
#define configUSE_COUNTING_SEMAPHORES 1
// #define configUSE_QUEUE_SETS 1
// #define configQUEUE_REGISTRY_SIZE CONFIG_FREERTOS_QUEUE_REGISTRY_SIZE
#define configUSE_TASK_NOTIFICATIONS 1
// #define configTASK_NOTIFICATION_ARRAY_ENTRIES 1
// ----------------------- System --------------------------
// #define configMAX_TASK_NAME_LEN CONFIG_FREERTOS_MAX_TASK_NAME_LEN
#define configNUM_THREAD_LOCAL_STORAGE_POINTERS CONFIG_FREERTOS_THREAD_LOCAL_STORAGE_POINTERS
#ifndef CONFIG_IDF_TARGET_LINUX
#define configSTACK_DEPTH_TYPE uint32_t
#define configUSE_NEWLIB_REENTRANT 1
#endif
#if CONFIG_FREERTOS_ENABLE_BACKWARD_COMPATIBILITY
#define configENABLE_BACKWARD_COMPATIBILITY 1
#else
#define configENABLE_BACKWARD_COMPATIBILITY 0
#endif
// #define configASSERT(a) assert(a)
#define configINCLUDE_FREERTOS_TASK_C_ADDITIONS_H 1
// ----------------------- Memory -------------------------
#define configSUPPORT_STATIC_ALLOCATION 1
#define configSUPPORT_DYNAMIC_ALLOCATION 1
// We define the heap to span all of the non-statically-allocated shared RAM. ToDo: Make sure there
// is some space left for the app and main cpu when running outside of a thread.
// #define configTOTAL_HEAP_SIZE (&_heap_end - &_heap_start)//( ( size_t ) (64 * 1024) )
// #define configAPPLICATION_ALLOCATED_HEAP 1
#define configSTACK_ALLOCATION_FROM_SEPARATE_HEAP 0
// ------------------------ Hooks --------------------------
// #define configUSE_IDLE_HOOK CONFIG_FREERTOS_USE_IDLE_HOOK
// #define configUSE_TICK_HOOK CONFIG_FREERTOS_USE_TICK_HOOK
#if CONFIG_FREERTOS_CHECK_STACKOVERFLOW_NONE
#define configCHECK_FOR_STACK_OVERFLOW 0
#elif CONFIG_FREERTOS_CHECK_STACKOVERFLOW_PTRVAL
#define configCHECK_FOR_STACK_OVERFLOW 1
#elif CONFIG_FREERTOS_CHECK_STACKOVERFLOW_CANARY
#define configCHECK_FOR_STACK_OVERFLOW 2
#endif
#define configRECORD_STACK_HIGH_ADDRESS 1
// ------------------- Run-time Stats ----------------------
#ifdef CONFIG_FREERTOS_GENERATE_RUN_TIME_STATS
#define configGENERATE_RUN_TIME_STATS 1 /* Used by vTaskGetRunTimeStats() */
#endif
#ifdef CONFIG_FREERTOS_USE_TRACE_FACILITY
#define configUSE_TRACE_FACILITY 1 /* Used by uxTaskGetSystemState(), and other trace facility functions */
#endif
#ifdef CONFIG_FREERTOS_USE_STATS_FORMATTING_FUNCTIONS
#define configUSE_STATS_FORMATTING_FUNCTIONS 1 /* Used by vTaskList() */
#endif
// -------------------- Co-routines -----------------------
#define configUSE_CO_ROUTINES 0
#define configMAX_CO_ROUTINE_PRIORITIES 2
// ------------------- Software Timer ----------------------
// #define configUSE_TIMERS 1
// #define configTIMER_TASK_PRIORITY CONFIG_FREERTOS_TIMER_TASK_PRIORITY
// #define configTIMER_QUEUE_LENGTH CONFIG_FREERTOS_TIMER_QUEUE_LENGTH
// #define configTIMER_TASK_STACK_DEPTH CONFIG_FREERTOS_TIMER_TASK_STACK_DEPTH
// -------------------- API Includes -----------------------
#if CONFIG_FREERTOS_ENABLE_BACKWARD_COMPATIBILITY
#define configENABLE_BACKWARD_COMPATIBILITY 1
#else
#define configENABLE_BACKWARD_COMPATIBILITY 0
#endif
#define INCLUDE_vTaskPrioritySet 1
#define INCLUDE_uxTaskPriorityGet 1
#define INCLUDE_vTaskDelete 1
#define INCLUDE_vTaskSuspend 1
#define INCLUDE_xTaskDelayUntil 1
#define INCLUDE_vTaskDelay 1
#define INCLUDE_xTaskGetIdleTaskHandle 1
#define INCLUDE_xTaskAbortDelay 1
#define INCLUDE_xSemaphoreGetMutexHolder 1
#define INCLUDE_xTaskGetHandle 1
#define INCLUDE_uxTaskGetStackHighWaterMark 1
#define INCLUDE_uxTaskGetStackHighWaterMark2 1
#define INCLUDE_eTaskGetState 1
#define INCLUDE_xTaskResumeFromISR 1
// #define INCLUDE_xTimerPendFunctionCall 1
#define INCLUDE_xTaskGetSchedulerState 1
#define INCLUDE_xTaskGetCurrentTaskHandle 1
// Unlisted
#define INCLUDE_pxTaskGetStackStart 1
// -------------------- Trace Macros -----------------------
/*
For trace macros.
Note: Include trace macros here and not above as trace macros are dependent on some of the FreeRTOS configs
*/
#ifndef __ASSEMBLER__
#if CONFIG_SYSVIEW_ENABLE
#include "SEGGER_SYSVIEW_FreeRTOS.h"
#undef INLINE // to avoid redefinition
#endif // CONFIG_SYSVIEW_ENABLE
#endif /* def __ASSEMBLER__ */
/* ------------------------------------------------ ESP-IDF Additions --------------------------------------------------
* - All FreeRTOS related configurations no part of Vanilla FreeRTOS goes into this section
* - FreeRTOS configurations related to SMP and ESP-IDF additions go into this section
* ------------------------------------------------------------------------------------------------------------------ */
// ------------------------- SMP ---------------------------
#ifndef CONFIG_FREERTOS_UNICORE
#define portNUM_PROCESSORS 2
#else
#define portNUM_PROCESSORS 1
#endif
#define configNUM_CORES portNUM_PROCESSORS
#ifdef CONFIG_FREERTOS_VTASKLIST_INCLUDE_COREID
#define configTASKLIST_INCLUDE_COREID 1
#endif
// ---------------------- Features -------------------------
#define configTHREAD_LOCAL_STORAGE_DELETE_CALLBACKS 1
#ifndef configIDLE_TASK_STACK_SIZE
#define configIDLE_TASK_STACK_SIZE CONFIG_FREERTOS_IDLE_TASK_STACKSIZE
#endif
#if CONFIG_FREERTOS_CHECK_MUTEX_GIVEN_BY_OWNER
#define configCHECK_MUTEX_GIVEN_BY_OWNER 1
#else
#define configCHECK_MUTEX_GIVEN_BY_OWNER 0
#endif
#ifndef __ASSEMBLER__
#if CONFIG_FREERTOS_ENABLE_STATIC_TASK_CLEAN_UP
extern void vPortCleanUpTCB(void *pxTCB);
#define portCLEAN_UP_TCB(pxTCB) vPortCleanUpTCB(pxTCB)
#endif
#endif
// -------------------- Compatibility ----------------------
// backward compatibility for 4.4
#define xTaskRemoveFromUnorderedEventList vTaskRemoveFromUnorderedEventList
#endif // CONFIG_FREERTOS_SMP
#endif /* FREERTOS_CONFIG_H */
/*
* SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef FREERTOS_CONFIG_RISCV_H
#define FREERTOS_CONFIG_RISCV_H
//RISC-V Archiecture specific configuration. This file is included in the common FreeRTOSConfig.h.
#include "sdkconfig.h"
/* ------------------------------------------------- FreeRTOS Config ---------------------------------------------------
* - All Vanilla FreeRTOS configuration goes into this section
* ------------------------------------------------------------------------------------------------------------------ */
// ------------------ Scheduler Related --------------------
// #define configUSE_PORT_OPTIMISED_TASK_SELECTION 0
#define configMAX_API_CALL_INTERRUPT_PRIORITY 0
/* ------------------------------------------------ ESP-IDF Additions --------------------------------------------------
*
* ------------------------------------------------------------------------------------------------------------------ */
#ifndef configISR_STACK_SIZE
#define configISR_STACK_SIZE (CONFIG_FREERTOS_ISR_STACKSIZE)
#endif
#endif // FREERTOS_CONFIG_RISCV_H
/*
* SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
#include "sdkconfig.h"
/**
* This file will be included in `tasks.c` file, thus, it must NOT be included
* by any (other) file.
* The functions below only consist in getters for the static variables in
* `tasks.c` file.
* The only source files that should call these functions are the ones in
* `/additions` directory.
*/
/* ----------------------------------------------------- Newlib --------------------------------------------------------
*
* ------------------------------------------------------------------------------------------------------------------ */
#if ( configUSE_NEWLIB_REENTRANT == 1 )
/**
* @brief Get reentrancy structure of the current task
*
* - This funciton is required by newlib (when __DYNAMIC_REENT__ is enabled)
* - It will return a pointer to the current task's reent struct
* - If FreeRTOS is not running, it will return the global reent struct
*
* @return Pointer to a the (current taks's)/(globa) reent struct
*/
struct _reent *__getreent(void)
{
// No lock needed because if this changes, we won't be running anymore.
struct _reent *ret;
#if !defined CONFIG_IDF_RTOS_RTTHREAD
TCB_t *pxCurTask = xTaskGetCurrentTaskHandle();
if (pxCurTask == NULL) {
// No task running. Return global struct.
ret = _GLOBAL_REENT;
} else {
// We have a task; return its reentrant struct.
ret = &pxCurTask->xNewLib_reent;
}
#else
ret = _GLOBAL_REENT;
#endif
return ret;
}
#endif // configUSE_NEWLIB_REENTRANT == 1
/* -------------------------------------------------- Task Snapshot ----------------------------------------------------
*
* ------------------------------------------------------------------------------------------------------------------ */
#if CONFIG_FREERTOS_ENABLE_TASK_SNAPSHOT
#include "task_snapshot.h"
/**
* @brief List of all task lists in FreeRTOS
*
* @note There are currently differing number of task list between SMP FreeRTOS and ESP-IDF FreeRTOS
*/
static List_t *non_ready_task_lists[] = {
#ifdef CONFIG_FREERTOS_SMP
&xPendingReadyList,
#else
&xPendingReadyList[0],
#ifndef CONFIG_FREERTOS_UNICORE
&xPendingReadyList[1],
#endif // CONFIG_FREERTOS_UNICORE
#endif //CONFIG_FREERTOS_SMP
&xDelayedTaskList1,
&xDelayedTaskList2,
#if( INCLUDE_vTaskDelete == 1 )
&xTasksWaitingTermination,
#endif
#if( INCLUDE_vTaskSuspend == 1 )
&xSuspendedTaskList,
#endif
};
/**
* @brief Get the next task list to traverse
*
* - Given a particular task list, this function returns the next task to traverse.
* - The task lists are returned in the following precedence
* - Ready lists (highest to lowers priority)
* - Pending ready list(s)
* - Delayed list 1
* - Delayed list 2
* - Waiting termination list
* - Suspended list
*
* @param pxCurTaskList Previously traversed task list (or NULL if obtaining the first task list)
* @return List_t* The next task list to traverse (or NULL of all task lists have been traversed)
*/
static List_t *pxGetNextTaskList(List_t *pxCurTaskList)
{
List_t *pxNextTaskList = NULL;
// No Current List. Start from the highest priority ready task list
if (pxCurTaskList == NULL)
{
pxNextTaskList = &pxReadyTasksLists[configMAX_PRIORITIES - 1];
}
// Current list is one of the ready task lists. Find the current priority, and return the next lower priority ready task list
else if (pxCurTaskList >= &pxReadyTasksLists[0] && pxCurTaskList <= &pxReadyTasksLists[configMAX_PRIORITIES - 1] )
{
// Find the current priority
int cur_priority;
for (cur_priority = configMAX_PRIORITIES - 1; cur_priority >= 0; cur_priority--) {
if (pxCurTaskList == &pxReadyTasksLists[cur_priority]) {
break;
}
}
// Return the ready task list at (cur_priority - 1), or the pending ready task list
if (cur_priority > 0)
{
pxNextTaskList = &pxReadyTasksLists[cur_priority - 1];
}
// We've reached the end of the Ready Task Lists. We get the next list from the non-ready task lists
else if (cur_priority == 0)
{
pxNextTaskList = non_ready_task_lists[0];
}
else
{
abort(); // This should never occur
}
}
// Current list is one of the non-ready task lists. Fetch the next non-ready task list
if (pxNextTaskList == NULL) {
int cur_list_idx;
const int num_non_ready_task_lists = (sizeof(non_ready_task_lists) / sizeof(List_t *));
// Note: - 1 so that if the current list is the last on non_ready_task_lists[], the next list will return NULL
for (cur_list_idx = 0; cur_list_idx < num_non_ready_task_lists - 1; cur_list_idx++) {
if (pxCurTaskList == non_ready_task_lists[cur_list_idx]) {
pxNextTaskList = non_ready_task_lists[cur_list_idx + 1];
break;
}
}
}
return pxNextTaskList;
}
TaskHandle_t pxTaskGetNext( TaskHandle_t pxTask )
{
TCB_t *pxTCB = (TCB_t *)pxTask;
// Check current task is valid
if (pxTCB != NULL && !portVALID_TCB_MEM(pxTCB)) {
return NULL;
}
List_t *pxCurTaskList;
const ListItem_t *pxCurListItem;
if (pxTCB == NULL) {
// Starting traversal for the first time
pxCurTaskList = pxGetNextTaskList(NULL);
pxCurListItem = listGET_END_MARKER(pxCurTaskList);
} else {
// Continuing traversal
pxCurTaskList = listLIST_ITEM_CONTAINER(&pxTCB->xStateListItem);
pxCurListItem = &pxTCB->xStateListItem;
}
ListItem_t *pxNextListItem = NULL;
if (pxCurListItem->pxNext == listGET_END_MARKER(pxCurTaskList)) {
List_t *pxNextTaskList = pxGetNextTaskList(pxCurTaskList);
while (pxNextTaskList != NULL) {
if (!listLIST_IS_EMPTY(pxNextTaskList)) {
// Get the first item in the next task list
pxNextListItem = listGET_HEAD_ENTRY(pxNextTaskList);
break;
}
// Task list is empty. Get the next task list
pxNextTaskList = pxGetNextTaskList(pxNextTaskList);
}
} else {
//There are still more items in the current task list. Get the next item
pxNextListItem = listGET_NEXT(pxCurListItem);
}
TCB_t *pxNextTCB;
if (pxNextListItem == NULL) {
pxNextTCB = NULL;
} else {
pxNextTCB = (TCB_t *)listGET_LIST_ITEM_OWNER(pxNextListItem);
}
return pxNextTCB;
}
BaseType_t vTaskGetSnapshot( TaskHandle_t pxTask, TaskSnapshot_t *pxTaskSnapshot )
{
if (portVALID_TCB_MEM(pxTask) == false || pxTaskSnapshot == NULL) {
return pdFALSE;
}
TCB_t *pxTCB = (TCB_t *)pxTask;
pxTaskSnapshot->pxTCB = pxTCB;
pxTaskSnapshot->pxTopOfStack = (StackType_t *)pxTCB->pxTopOfStack;
pxTaskSnapshot->pxEndOfStack = (StackType_t *)pxTCB->pxEndOfStack;
return pdTRUE;
}
UBaseType_t uxTaskGetSnapshotAll( TaskSnapshot_t * const pxTaskSnapshotArray, const UBaseType_t uxArrayLength, UBaseType_t * const pxTCBSize )
{
UBaseType_t uxArrayNumFilled = 0;
//Traverse all of the tasks lists
List_t *pxCurTaskList = pxGetNextTaskList(NULL); //Get the first task list
while (pxCurTaskList != NULL && uxArrayNumFilled < uxArrayLength) {
if (!listLIST_IS_EMPTY(pxCurTaskList)) {
const ListItem_t *pxCurListItem;
//Walk each task on the current task list
pxCurListItem = listGET_HEAD_ENTRY(pxCurTaskList);
while (pxCurListItem != listGET_END_MARKER(pxCurTaskList)) {
TCB_t *pxTCB = (TCB_t *)listGET_LIST_ITEM_OWNER(pxCurListItem);
vTaskGetSnapshot((TaskHandle_t)pxTCB, &pxTaskSnapshotArray[uxArrayNumFilled]);
uxArrayNumFilled++;
if (!(uxArrayNumFilled < uxArrayLength)) {
break;
}
pxCurListItem = listGET_NEXT(pxCurListItem);
}
}
//Get the next task list
pxCurTaskList = pxGetNextTaskList(pxCurTaskList);
}
*pxTCBSize = sizeof(TCB_t);
return uxArrayNumFilled;
}
#endif // CONFIG_FREERTOS_ENABLE_TASK_SNAPSHOT
/* ----------------------------------------------------- OpenOCD -------------------------------------------------------
*
* ------------------------------------------------------------------------------------------------------------------ */
#if ( configENABLE_FREERTOS_DEBUG_OCDAWARE == 1 )
/**
* Debug param indexes. DO NOT change the order. OpenOCD uses the same indexes
* Entries in FreeRTOS_openocd_params must match the order of these indexes
*/
enum {
ESP_FREERTOS_DEBUG_TABLE_SIZE = 0,
ESP_FREERTOS_DEBUG_TABLE_VERSION,
ESP_FREERTOS_DEBUG_KERNEL_VER_MAJOR,
ESP_FREERTOS_DEBUG_KERNEL_VER_MINOR,
ESP_FREERTOS_DEBUG_KERNEL_VER_BUILD,
ESP_FREERTOS_DEBUG_UX_TOP_USED_PIORITY,
ESP_FREERTOS_DEBUG_PX_TOP_OF_STACK,
ESP_FREERTOS_DEBUG_PC_TASK_NAME,
/* New entries must be inserted here */
ESP_FREERTOS_DEBUG_TABLE_END,
};
const DRAM_ATTR uint8_t FreeRTOS_openocd_params[ESP_FREERTOS_DEBUG_TABLE_END] = {
ESP_FREERTOS_DEBUG_TABLE_END, /* table size */
1, /* table version */
tskKERNEL_VERSION_MAJOR,
tskKERNEL_VERSION_MINOR,
tskKERNEL_VERSION_BUILD,
configMAX_PRIORITIES - 1, /* uxTopUsedPriority */
offsetof(TCB_t, pxTopOfStack), /* thread_stack_offset; */
offsetof(TCB_t, pcTaskName), /* thread_name_offset; */
};
#endif // configENABLE_FREERTOS_DEBUG_OCDAWARE == 1
/* -------------------------------------------- FreeRTOS IDF API Additions ---------------------------------------------
* FreeRTOS related API that were added by IDF
* ------------------------------------------------------------------------------------------------------------------ */
#if CONFIG_FREERTOS_SMP
_Static_assert(tskNO_AFFINITY == CONFIG_FREERTOS_NO_AFFINITY, "CONFIG_FREERTOS_NO_AFFINITY must be the same as tskNO_AFFINITY");
BaseType_t xTaskCreatePinnedToCore( TaskFunction_t pxTaskCode,
const char * const pcName,
const uint32_t usStackDepth,
void * const pvParameters,
UBaseType_t uxPriority,
TaskHandle_t * const pxCreatedTask,
const BaseType_t xCoreID)
{
BaseType_t ret;
#if ( ( configUSE_CORE_AFFINITY == 1 ) && ( configNUM_CORES > 1 ) )
{
// Convert xCoreID into an affinity mask
UBaseType_t uxCoreAffinityMask;
if (xCoreID == tskNO_AFFINITY) {
uxCoreAffinityMask = tskNO_AFFINITY;
} else {
uxCoreAffinityMask = (1 << xCoreID);
}
ret = xTaskCreateAffinitySet(pxTaskCode, pcName, usStackDepth, pvParameters, uxPriority, uxCoreAffinityMask, pxCreatedTask);
}
#else /* ( ( configUSE_CORE_AFFINITY == 1 ) && ( configNUM_CORES > 1 ) ) */
{
ret = xTaskCreate(pxTaskCode, pcName, usStackDepth, pvParameters, uxPriority, pxCreatedTask);
}
#endif /* ( ( configUSE_CORE_AFFINITY == 1 ) && ( configNUM_CORES > 1 ) ) */
return ret;
}
#if ( configSUPPORT_STATIC_ALLOCATION == 1 )
TaskHandle_t xTaskCreateStaticPinnedToCore( TaskFunction_t pxTaskCode,
const char * const pcName,
const uint32_t ulStackDepth,
void * const pvParameters,
UBaseType_t uxPriority,
StackType_t * const puxStackBuffer,
StaticTask_t * const pxTaskBuffer,
const BaseType_t xCoreID)
{
TaskHandle_t ret;
#if ( ( configUSE_CORE_AFFINITY == 1 ) && ( configNUM_CORES > 1 ) )
{
// Convert xCoreID into an affinity mask
UBaseType_t uxCoreAffinityMask;
if (xCoreID == tskNO_AFFINITY) {
uxCoreAffinityMask = tskNO_AFFINITY;
} else {
uxCoreAffinityMask = (1 << xCoreID);
}
ret = xTaskCreateStaticAffinitySet(pxTaskCode, pcName, ulStackDepth, pvParameters, uxPriority, puxStackBuffer, pxTaskBuffer, uxCoreAffinityMask);
}
#else /* ( ( configUSE_CORE_AFFINITY == 1 ) && ( configNUM_CORES > 1 ) ) */
{
ret = xTaskCreateStatic(pxTaskCode, pcName, ulStackDepth, pvParameters, uxPriority, puxStackBuffer, pxTaskBuffer);
}
#endif /* ( ( configUSE_CORE_AFFINITY == 1 ) && ( configNUM_CORES > 1 ) ) */
return ret;
}
#endif /* configSUPPORT_STATIC_ALLOCATION */
TaskHandle_t xTaskGetCurrentTaskHandleForCPU( BaseType_t xCoreID )
{
TaskHandle_t xTaskHandleTemp;
assert(xCoreID >= 0 && xCoreID < configNUM_CORES);
taskENTER_CRITICAL();
xTaskHandleTemp = (TaskHandle_t) pxCurrentTCBs[xCoreID];
taskEXIT_CRITICAL();
return xTaskHandleTemp;
}
TaskHandle_t xTaskGetIdleTaskHandleForCPU( BaseType_t xCoreID )
{
assert(xCoreID >= 0 && xCoreID < configNUM_CORES);
return (TaskHandle_t) xIdleTaskHandle[xCoreID];
}
BaseType_t xTaskGetAffinity( TaskHandle_t xTask )
{
taskENTER_CRITICAL();
UBaseType_t uxCoreAffinityMask;
#if ( configUSE_CORE_AFFINITY == 1 && configNUM_CORES > 1 )
TCB_t *pxTCB = prvGetTCBFromHandle( xTask );
uxCoreAffinityMask = pxTCB->uxCoreAffinityMask;
#else
uxCoreAffinityMask = tskNO_AFFINITY;
#endif
taskEXIT_CRITICAL();
BaseType_t ret;
// If the task is not pinned to a particular core, treat it as tskNO_AFFINITY
if (uxCoreAffinityMask & (uxCoreAffinityMask - 1)) { // If more than one bit set
ret = tskNO_AFFINITY;
} else {
int index_plus_one = __builtin_ffs(uxCoreAffinityMask);
assert(index_plus_one >= 1);
ret = index_plus_one - 1;
}
return ret;
}
#if ( CONFIG_FREERTOS_TLSP_DELETION_CALLBACKS )
void vTaskSetThreadLocalStoragePointerAndDelCallback( TaskHandle_t xTaskToSet, BaseType_t xIndex, void *pvValue, TlsDeleteCallbackFunction_t pvDelCallback)
{
// Verify that the offsets of pvThreadLocalStoragePointers and pvDummy15 match.
// pvDummy15 is part of the StaticTask_t struct and is used to access the TLSPs
// while deletion.
_Static_assert(offsetof( StaticTask_t, pvDummy15 ) == offsetof( TCB_t, pvThreadLocalStoragePointers ), "Offset of pvDummy15 must match the offset of pvThreadLocalStoragePointers");
//Set the local storage pointer first
vTaskSetThreadLocalStoragePointer( xTaskToSet, xIndex, pvValue );
//Set the deletion callback at an offset of configNUM_THREAD_LOCAL_STORAGE_POINTERS/2
vTaskSetThreadLocalStoragePointer( xTaskToSet, ( xIndex + ( configNUM_THREAD_LOCAL_STORAGE_POINTERS / 2 ) ), pvDelCallback );
}
#endif // CONFIG_FREERTOS_TLSP_DELETION_CALLBACKS
#endif // CONFIG_FREERTOS_SMP
/*
* SPDX-FileCopyrightText: 2020 Amazon.com, Inc. or its affiliates
*
* SPDX-License-Identifier: MIT
*
* SPDX-FileContributor: 2016-2022 Espressif Systems (Shanghai) CO LTD
*/
/*
* FreeRTOS Kernel V10.4.3
* Copyright (C) 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* http://www.FreeRTOS.org
* http://aws.amazon.com/freertos
*
* 1 tab == 4 spaces!
*/
#ifndef PORTMACRO_H
#define PORTMACRO_H
#ifndef __ASSEMBLER__
#include "sdkconfig.h"
#include <stdint.h>
#include <stdlib.h>
#include <stdbool.h>
#include <stdio.h>
#include "spinlock.h"
#include "soc/interrupt_core0_reg.h"
#include "esp_macros.h"
#include "esp_attr.h"
#include "esp_cpu.h"
#include "esp_rom_sys.h"
#include "esp_heap_caps.h"
#include "esp_system.h" /* required by esp_get_...() functions in portable.h. [refactor-todo] Update portable.h */
#include "esp_newlib.h"
/* [refactor-todo] These includes are not directly used in this file. They are kept into to prevent a breaking change. Remove these. */
#include <limits.h>
/* [refactor-todo] introduce a port wrapper function to avoid including esp_timer.h into the public header */
#if CONFIG_FREERTOS_RUN_TIME_STATS_USING_ESP_TIMER
#include "esp_timer.h"
#endif
#ifdef __cplusplus
extern "C" {
#endif
/* --------------------------------------------------- Port Types ------------------------------------------------------
* - Port specific types.
* - The settings in this file configure FreeRTOS correctly for the given hardware and compiler.
* - These settings should not be altered.
* - The port types must come first as they are used further down in this file
* ------------------------------------------------------------------------------------------------------------------ */
#define portCHAR char
#define portFLOAT float
#define portDOUBLE double
#define portLONG long
#define portSHORT short
#define portSTACK_TYPE rt_ubase_t
#define portBASE_TYPE rt_base_t
typedef portSTACK_TYPE StackType_t;
typedef rt_base_t BaseType_t;
typedef rt_ubase_t UBaseType_t;
typedef rt_tick_t TickType_t;
#define portMAX_DELAY (TickType_t) RT_TICK_MAX
struct rt_semaphore_wrapper
{
struct rt_semaphore sem;
rt_uint16_t max_value;
};
/* ----------------------------------------------- Port Configurations -------------------------------------------------
* - Configurations values supplied by each port
* - Required by FreeRTOS
* ------------------------------------------------------------------------------------------------------------------ */
#define portTICK_PERIOD_MS ((TickType_t) (1000 / configTICK_RATE_HZ))
#define portBYTE_ALIGNMENT RT_ALIGN_SIZE
#define portNOP() __asm volatile (" nop ")
/* ---------------------------------------------- Forward Declarations -------------------------------------------------
* - Forward declarations of all the port functions and macros need to implement the FreeRTOS porting interface
* - These must come before definition/declaration of the FreeRTOS porting interface
* ------------------------------------------------------------------------------------------------------------------ */
// --------------------- Interrupts ------------------------
/**
* @brief Checks if the current core is in an ISR context
*
* - ISR context consist of Low/Mid priority ISR, or time tick ISR
* - High priority ISRs aren't detected here, but they normally cannot call C code, so that should not be an issue anyway.
*
* @note [refactor-todo] Check if this should be inlined
* @return
* - pdTRUE if in ISR
* - pdFALSE otherwise
*/
BaseType_t xPortInIsrContext(void);
/**
* @brief Check if in ISR context from High priority ISRs
*
* - Called from High priority ISR
* - Checks if the previous context (before high priority interrupt) was in ISR context (meaning low/med priority)
*
* @note [refactor-todo] Check if this should be inlined
* @return
* - pdTRUE if in previous in ISR context
* - pdFALSE otherwise
*/
BaseType_t xPortInterruptedFromISRContext(void);
/* ---------------------- Spinlocks ------------------------
- Spinlocks added to match API with SMP FreeRTOS. Single core RISC-V does not need spin locks
- Because single core does not have a primitive spinlock data type, we have to implement one here
* @note [refactor-todo] Refactor critical section API so that this is no longer required
* ------------------------------------------------------ */
/**
* @brief Spinlock object
* Owner:
* - Set to 0 if uninitialized
* - Set to portMUX_FREE_VAL when free
* - Set to CORE_ID_REGVAL_PRO or CORE_ID_REGVAL_AP when locked
* - Any other value indicates corruption
* Count:
* - 0 if unlocked
* - Recursive count if locked
*
* @note Not a true spinlock as single core RISC-V does not have atomic compare and set instruction
* @note Keep portMUX_INITIALIZER_UNLOCKED in sync with this struct
*/
typedef struct {
uint32_t owner;
uint32_t count;
} portMUX_TYPE;
/**< Spinlock initializer */
#define portMUX_INITIALIZER_UNLOCKED { \
.owner = portMUX_FREE_VAL, \
.count = 0, \
}
#define portMUX_FREE_VAL SPINLOCK_FREE /**< Spinlock is free. [refactor-todo] check if this is still required */
#define portMUX_NO_TIMEOUT SPINLOCK_WAIT_FOREVER /**< When passed for 'timeout_cycles', spin forever if necessary. [refactor-todo] check if this is still required */
#define portMUX_TRY_LOCK SPINLOCK_NO_WAIT /**< Try to acquire the spinlock a single time only. [refactor-todo] check if this is still required */
#define portMUX_INITIALIZE(mux) ({ \
(mux)->owner = portMUX_FREE_VAL; \
(mux)->count = 0; \
})
// ------------------ Critical Sections --------------------
/**
* @brief Enter a critical section
*
* - Simply disable interrupts
* - Can be nested
*/
void vPortEnterCritical(void);
/**
* @brief Exit a critical section
*
* - Reenables interrupts
* - Can be nested
*/
void vPortExitCritical(void);
// ---------------------- Yielding -------------------------
/**
* @brief Perform a context switch from a task
*
* @note [refactor-todo] The rest of ESP-IDF should call taskYield() instead
*/
#define vPortYield(void) rt_thread_yield()
/**
* @brief Checks if the current core can yield
*
* - A core cannot yield if its in an ISR or in a critical section
*
* @note [refactor-todo] See if this can be separated from port macro
* @note [refactor-todo] Check if this function should be renamed (due to bool return type)
* @return true Core can yield
* @return false Core cannot yield
*/
FORCE_INLINE_ATTR bool xPortCanYield(void);
// ----------------------- System --------------------------
/**
* @brief Get the tick rate per second
*
* @note [refactor-todo] make this inline
* @note [refactor-todo] Check if this function should be renamed (due to uint return type)
* @return uint32_t Tick rate in Hz
*/
uint32_t xPortGetTickRateHz(void);
/**
* @brief Set a watchpoint to watch the last 32 bytes of the stack
*
* Callback to set a watchpoint on the end of the stack. Called every context switch to change the stack watchpoint
* around.
*
* @param pxStackStart Pointer to the start of the stack
*/
void vPortSetStackWatchpoint(void *pxStackStart);
/**
* @brief Get the current core's ID
*
* @note Added to be compatible with SMP API
* @note [refactor-todo] IDF should call a FreeRTOS like macro instead of port function directly
* @return BaseType_t Core ID
*/
FORCE_INLINE_ATTR BaseType_t xPortGetCoreID(void)
{
return (BaseType_t) esp_cpu_get_core_id();
}
/* ------------------------------------------- FreeRTOS Porting Interface ----------------------------------------------
* - Contains all the mappings of the macros required by FreeRTOS
* - Most come after forward declare as porting macros map to declared functions
* - Maps to forward declared functions
* ------------------------------------------------------------------------------------------------------------------ */
// --------------------- Interrupts ------------------------
#define portDISABLE_INTERRUPTS() vPortEnterCritical()
#define portENABLE_INTERRUPTS() vPortExitCritical()
#define portSET_INTERRUPT_MASK_FROM_ISR() rt_hw_interrupt_disable()
#define portCLEAR_INTERRUPT_MASK_FROM_ISR(uxSavedStatusValue) rt_hw_interrupt_enable(uxSavedStatusValue)
// ------------------ Critical Sections --------------------
#define portENTER_CRITICAL(mux) {(void)mux; vPortEnterCritical();}
#define portEXIT_CRITICAL(mux) {(void)mux; vPortExitCritical();}
#define portTRY_ENTER_CRITICAL(mux, timeout) ({ \
(void)mux; (void)timeout; \
vPortEnterCritical(); \
BaseType_t ret = pdPASS; \
ret; \
})
//In single-core RISC-V, we can use the same critical section API
#define portENTER_CRITICAL_ISR(mux) portENTER_CRITICAL(mux)
#define portEXIT_CRITICAL_ISR(mux) portEXIT_CRITICAL(mux)
#define portTRY_ENTER_CRITICAL_ISR(mux, timeout) portTRY_ENTER_CRITICAL(mux, timeout)
/* [refactor-todo] on RISC-V, both ISR and non-ISR cases result in the same call. We can redefine this macro */
#define portENTER_CRITICAL_SAFE(mux) ({ \
if (xPortInIsrContext()) { \
portENTER_CRITICAL_ISR(mux); \
} else { \
portENTER_CRITICAL(mux); \
} \
})
#define portEXIT_CRITICAL_SAFE(mux) ({ \
if (xPortInIsrContext()) { \
portEXIT_CRITICAL_ISR(mux); \
} else { \
portEXIT_CRITICAL(mux); \
} \
})
#define portTRY_ENTER_CRITICAL_SAFE(mux, timeout) portENTER_CRITICAL_SAFE(mux, timeout)
// ---------------------- Yielding -------------------------
#define portYIELD() rt_thread_yield()
#define portYIELD_FROM_ISR_NO_ARG() rt_thread_yield()
#define portYIELD_FROM_ISR_ARG(xHigherPriorityTaskWoken) ({ \
if (xHigherPriorityTaskWoken == pdTRUE) { \
rt_thread_yield(); \
} \
})
/**
* @note The macro below could be used when passing a single argument, or without any argument,
* it was developed to support both usages of portYIELD inside of an ISR. Any other usage form
* might result in undesired behavior
*/
#if defined(__cplusplus) && (__cplusplus > 201703L)
#define portYIELD_FROM_ISR(...) CHOOSE_MACRO_VA_ARG(portYIELD_FROM_ISR_ARG, portYIELD_FROM_ISR_NO_ARG __VA_OPT__(,) __VA_ARGS__)(__VA_ARGS__)
#else
#define portYIELD_FROM_ISR(...) CHOOSE_MACRO_VA_ARG(portYIELD_FROM_ISR_ARG, portYIELD_FROM_ISR_NO_ARG, ##__VA_ARGS__)(__VA_ARGS__)
#endif
/* --------------------------------------------- Inline Implementations ------------------------------------------------
* - Implementation of inline functions of the forward declares
* - Should come after forward declare and FreeRTOS Porting interface, as implementation may use both.
* - For implementation of non-inlined functions, see port.c, port_common.c, or other assembly files
* ------------------------------------------------------------------------------------------------------------------ */
// --------------------- Interrupts ------------------------
// ---------------------- Yielding -------------------------
FORCE_INLINE_ATTR bool xPortCanYield(void)
{
uint32_t threshold = REG_READ(INTERRUPT_CORE0_CPU_INT_THRESH_REG);
/* when enter critical code, FreeRTOS will mask threshold to RVHAL_EXCM_LEVEL
* and exit critical code, will recover threshold value (1). so threshold <= 1
* means not in critical code
*/
return (threshold <= 1);
}
#define FREERTOS_PRIORITY_TO_RTTHREAD(priority) ( configMAX_PRIORITIES - 1 - ( priority ) )
#define RTTHREAD_PRIORITY_TO_FREERTOS(priority) ( RT_THREAD_PRIORITY_MAX - 1 - ( priority ) )
/* Use this macro to calculate the buffer size when allocating a queue statically
* To ensure the buffer can fit the desired number of messages
*/
#define QUEUE_BUFFER_SIZE( uxQueueLength, uxItemSize ) ( ( RT_ALIGN( uxItemSize, RT_ALIGN_SIZE ) + sizeof( void * ) ) * uxQueueLength )
BaseType_t rt_err_to_freertos(rt_err_t rt_err);
#if CONFIG_APPTRACE_SV_ENABLE
extern int xPortSwitchFlag;
#define os_task_switch_is_pended(_cpu_) (xPortSwitchFlag)
#else
#define os_task_switch_is_pended(_cpu_) (false)
#endif
#ifdef __cplusplus
}
#endif
#endif //__ASSEMBLER__
#endif /* PORTMACRO_H */
/*
* SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
#include "sdkconfig.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#ifdef __cplusplus
extern "C" {
#endif
#if CONFIG_FREERTOS_ENABLE_TASK_SNAPSHOT || defined __DOXYGEN__
/**
* @brief Task Snapshot structure
*
* - Used with the uxTaskGetSnapshotAll() function to save memory snapshot of each task in the system.
* - We need this structure because TCB_t is defined (hidden) in tasks.c.
*/
typedef struct xTASK_SNAPSHOT
{
void *pxTCB; /*!< Address of the task control block. */
StackType_t *pxTopOfStack; /*!< Points to the location of the last item placed on the tasks stack. */
StackType_t *pxEndOfStack; /*!< Points to the end of the stack. pxTopOfStack < pxEndOfStack, stack grows hi2lo
pxTopOfStack > pxEndOfStack, stack grows lo2hi*/
} TaskSnapshot_t;
/**
* @brief Iterate over all tasks in the system
*
* - This function can be used to iterate over every task in the system
* - The first call to this function must set pxTask to NULL
* - When all functions have been iterated, this function will return NULL.
* - This function is only available when CONFIG_FREERTOS_ENABLE_TASK_SNAPSHOT is set to 1.
*
* @note This function should only be called when FreeRTOS is no longer running (e.g., during a panic) as this function
* does not acquire any locks.
* @param pxTask Handle of the previous task (or NULL on the first call of this function)
* @return TaskHandle_t Handle of the next task (or NULL when all tasks have been iterated over)
*/
TaskHandle_t pxTaskGetNext( TaskHandle_t pxTask );
/**
* @brief Fill a TaskSnapshot_t structure for specified task.
*
* - This function is used by the panic handler to get the snapshot of a particular task.
* - This function is only available when CONFIG_FREERTOS_ENABLE_TASK_SNAPSHOT is set to 1.
*
* @note This function should only be called when FreeRTOS is no longer running (e.g., during a panic) as this function
* does not acquire any locks.
* @param[in] pxTask Task's handle
* @param[out] pxTaskSnapshot Snapshot of the task
* @return pdTRUE if operation was successful else pdFALSE
*/
BaseType_t vTaskGetSnapshot( TaskHandle_t pxTask, TaskSnapshot_t *pxTaskSnapshot );
/**
* @brief Fill an array of TaskSnapshot_t structures for every task in the system
*
* - This function is used by the panic handler to get a snapshot of all tasks in the system
* - This function is only available when CONFIG_FREERTOS_ENABLE_TASK_SNAPSHOT is set to 1.
*
* @note This function should only be called when FreeRTOS is no longer running (e.g., during a panic) as this function
* does not acquire any locks.
* @param[out] pxTaskSnapshotArray Array of TaskSnapshot_t structures filled by this function
* @param[in] uxArrayLength Length of the provided array
* @param[out] pxTCBSize Size of the a task's TCB structure
* @return UBaseType_t
*/
UBaseType_t uxTaskGetSnapshotAll( TaskSnapshot_t * const pxTaskSnapshotArray, const UBaseType_t uxArrayLength, UBaseType_t * const pxTCBSize );
#endif // CONFIG_FREERTOS_ENABLE_TASK_SNAPSHOT || defined __DOXYGEN__
#ifdef __cplusplus
}
#endif
/*
* SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
/**
* ESP32-C3 Linker Script Memory Layout
* This file describes the memory layout (memory blocks) by virtual memory addresses.
* This linker script is passed through the C preprocessor to include configuration options.
* Please use preprocessor features sparingly!
* Restrict to simple macros with numeric values, and/or #if/#endif blocks.
*/
/*
* Automatically generated file. DO NOT EDIT.
* Espressif IoT Development Framework (ESP-IDF) Configuration Header
*/
/* List of deprecated options */
/*
* SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
/* CPU instruction prefetch padding size for flash mmap scenario */
_esp_flash_mmap_prefetch_pad_size = 16;
/* CPU instruction prefetch padding size for memory protection scenario */
_esp_memprot_prefetch_pad_size = 16;
/* Memory alignment size for PMS */
_esp_memprot_align_size = 512;
_esp_mmu_block_size = (0x10000);
/**
* physical memory is mapped twice to the vritual address (IRAM and DRAM).
* `I_D_SRAM_OFFSET` is the offset between the two locations of the same physical memory
*/
MEMORY
{
/**
* All these values assume the flash cache is on, and have the blocks this uses subtracted from the length
* of the various regions. The 'data access port' dram/drom regions map to the same iram/irom regions but
* are connected to the data port of the CPU and eg allow byte-wise access.
*/
/* IRAM for PRO CPU. */
iram0_0_seg (RX) : org = (0x4037C000 + 0x4000), len = 0x403CF600 - (0x4037C000 - 0x3FC7C000) - (0x3FC7C000 + 0x4000)
/* Flash mapped instruction data */
iram0_2_seg (RX) : org = 0x42000020, len = 0x800000-0x20
/**
* (0x20 offset above is a convenience for the app binary image generation.
* Flash cache has 64KB pages. The .bin file which is flashed to the chip
* has a 0x18 byte file header, and each segment has a 0x08 byte segment
* header. Setting this offset makes it simple to meet the flash cache MMU's
* constraint that (paddr % 64KB == vaddr % 64KB).)
*/
/**
* Shared data RAM, excluding memory reserved for ROM bss/data/stack.
* Enabling Bluetooth & Trace Memory features in menuconfig will decrease the amount of RAM available.
*/
dram0_0_seg (RW) : org = (0x3FC7C000 + 0x4000), len = 0x403CF600 - (0x4037C000 - 0x3FC7C000) - (0x3FC7C000 + 0x4000)
/* Flash mapped constant data */
drom0_0_seg (R) : org = 0x3C000020, len = 0x800000-0x20
/* (See iram0_2_seg for meaning of 0x20 offset in the above.) */
/**
* RTC fast memory (executable). Persists over deep sleep.
*/
rtc_iram_seg(RWX) : org = 0x50000000, len = 0x2000 - 0
}
_static_data_end = _bss_end;
/* Heap ends at top of dram0_0_seg */
_heap_end = 0x40000000;
_data_seg_org = ORIGIN(rtc_data_seg);
/**
* The lines below define location alias for .rtc.data section
* As C3 only has RTC fast memory, this is not configurable like on other targets
*/
REGION_ALIAS("rtc_data_seg", rtc_iram_seg );
REGION_ALIAS("rtc_slow_seg", rtc_iram_seg );
REGION_ALIAS("rtc_data_location", rtc_iram_seg );
REGION_ALIAS("default_code_seg", iram0_2_seg);
REGION_ALIAS("default_rodata_seg", drom0_0_seg);
/**
* If rodata default segment is placed in `drom0_0_seg`, then flash's first rodata section must
* also be first in the segment.
*/
ASSERT(_flash_rodata_dummy_start == ORIGIN(default_rodata_seg),
".flash_rodata_dummy section must be placed at the beginning of the rodata segment.")
此差异已折叠。
/*
* SPDX-FileCopyrightText: 2020 Amazon.com, Inc. or its affiliates
*
* SPDX-License-Identifier: MIT
*
* SPDX-FileContributor: 2016-2022 Espressif Systems (Shanghai) CO LTD
*/
/*
* FreeRTOS Kernel V10.4.3
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* https://www.FreeRTOS.org
* https://github.com/FreeRTOS
*
* 1 tab == 4 spaces!
*/
/*-----------------------------------------------------------------------
* Implementation of functions defined in portable.h for the RISC-V port.
*----------------------------------------------------------------------*/
#include "sdkconfig.h"
#include <string.h>
#include "soc/soc_caps.h"
#include "soc/periph_defs.h"
#include "soc/system_reg.h"
#include "hal/systimer_hal.h"
#include "hal/systimer_ll.h"
#include "riscv/rvruntime-frames.h"
#include "riscv/riscv_interrupts.h"
#include "riscv/interrupt.h"
#include "esp_private/crosscore_int.h"
#include "esp_attr.h"
#include "esp_system.h"
#include "esp_intr_alloc.h"
#include "esp_log.h"
#include "FreeRTOS.h" /* This pulls in portmacro.h */
#include "task.h"
#include "portmacro.h"
#include "esp_memory_utils.h"
/* ---------------------------------------------------- Variables ------------------------------------------------------
*
* ------------------------------------------------------------------------------------------------------------------ */
static const char *TAG = "cpu_start";
/* ---------------------------------------------- Port Implementations -------------------------------------------------
*
* ------------------------------------------------------------------------------------------------------------------ */
// --------------------- Interrupts ------------------------
BaseType_t xPortInIsrContext(void)
{
return (BaseType_t)rt_interrupt_get_nest();
}
BaseType_t IRAM_ATTR xPortInterruptedFromISRContext(void)
{
/* For single core, this can be the same as xPortInIsrContext() because reading it is atomic */
return (BaseType_t)rt_interrupt_get_nest();
}
// ----------------------- System --------------------------
uint32_t xPortGetTickRateHz(void)
{
return (uint32_t)configTICK_RATE_HZ;
}
#define STACK_WATCH_AREA_SIZE 32
#define STACK_WATCH_POINT_NUMBER (SOC_CPU_WATCHPOINTS_NUM - 1)
void vPortSetStackWatchpoint(void *pxStackStart)
{
uint32_t addr = (uint32_t)pxStackStart;
addr = (addr + (STACK_WATCH_AREA_SIZE - 1)) & (~(STACK_WATCH_AREA_SIZE - 1));
esp_cpu_set_watchpoint(STACK_WATCH_POINT_NUMBER, (char *)addr, STACK_WATCH_AREA_SIZE, ESP_CPU_WATCHPOINT_STORE);
}
/* ---------------------------------------------- Misc Implementations -------------------------------------------------
*
* ------------------------------------------------------------------------------------------------------------------ */
// --------------------- App Start-up ----------------------
/* [refactor-todo]: See if we can include this through a header */
extern void esp_startup_start_app_common(void);
void esp_startup_start_app(void)
{
esp_startup_start_app_common();
ESP_LOGI(TAG, "Starting scheduler.");
vTaskStartScheduler();
}
/*
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <string.h>
#include "FreeRTOS.h"
#include "task.h"
#include "portmacro.h"
#include "esp_private/esp_int_wdt.h"
#include "esp_system.h"
#include "esp_heap_caps_init.h"
#include "esp_task_wdt.h"
#include "esp_task.h"
#include "esp_private/crosscore_int.h"
#include "esp_log.h"
#include "esp_memory_utils.h"
#include "esp_freertos_hooks.h"
#include "sdkconfig.h"
#include "esp_freertos_hooks.h"
#if CONFIG_SPIRAM
#include "esp_psram.h"
#include "esp_private/esp_psram_extram.h"
#endif
#if CONFIG_SPIRAM_MALLOC_RESERVE_INTERNAL
static const char* TAG = "cpu_start";
#endif
/* Architecture-agnostic parts of the FreeRTOS ESP-IDF port layer can go here.
*
* The actual call flow will be to call esp_startup_start_app() in <ARCH>/port.c,
* which will then call esp_startup_start_app_common()
*/
// Duplicate of inaccessible xSchedulerRunning; needed at startup to avoid counting nesting
volatile unsigned port_xSchedulerRunning[portNUM_PROCESSORS] = {0};
// For now, running FreeRTOS on one core and a bare metal on the other (or other OSes)
// is not supported. For now CONFIG_FREERTOS_UNICORE and CONFIG_ESP_SYSTEM_SINGLE_CORE_MODE
// should mirror each other's values.
//
// And since this should be true, we can just check for CONFIG_FREERTOS_UNICORE.
#if CONFIG_FREERTOS_UNICORE != CONFIG_ESP_SYSTEM_SINGLE_CORE_MODE
#error "FreeRTOS and system configuration mismatch regarding the use of multiple cores."
#endif
#if !defined CONFIG_IDF_RTOS_RTTHREAD
static void main_task(void* args);
#endif
#ifdef CONFIG_ESP_SYSTEM_GDBSTUB_RUNTIME
void esp_gdbstub_init(void);
#endif // CONFIG_ESP_SYSTEM_GDBSTUB_RUNTIME
extern void app_main(void);
void esp_startup_start_app_common(void)
{
#if CONFIG_ESP_INT_WDT
esp_int_wdt_init();
//Initialize the interrupt watch dog for CPU0.
esp_int_wdt_cpu_init();
#endif
esp_crosscore_int_init();
#if CONFIG_ESP_SYSTEM_GDBSTUB_RUNTIME && !CONFIG_IDF_TARGET_ESP32C2
esp_gdbstub_init();
#endif // CONFIG_ESP_SYSTEM_GDBSTUB_RUNTIME
#if !defined CONFIG_IDF_RTOS_RTTHREAD
portBASE_TYPE res = xTaskCreatePinnedToCore(&main_task, "main",
ESP_TASK_MAIN_STACK, NULL,
ESP_TASK_MAIN_PRIO, NULL, ESP_TASK_MAIN_CORE);
assert(res == pdTRUE);
(void)res;
#endif
}
#if !CONFIG_FREERTOS_UNICORE
static volatile bool s_other_cpu_startup_done = false;
static bool other_cpu_startup_idle_hook_cb(void)
{
s_other_cpu_startup_done = true;
return true;
}
#endif
#if !defined CONFIG_IDF_RTOS_RTTHREAD
static void main_task(void* args)
{
#if !CONFIG_FREERTOS_UNICORE
// Wait for FreeRTOS initialization to finish on other core, before replacing its startup stack
esp_register_freertos_idle_hook_for_cpu(other_cpu_startup_idle_hook_cb, !xPortGetCoreID());
while (!s_other_cpu_startup_done) {
;
}
esp_deregister_freertos_idle_hook_for_cpu(other_cpu_startup_idle_hook_cb, !xPortGetCoreID());
#endif
// [refactor-todo] check if there is a way to move the following block to esp_system startup
heap_caps_enable_nonos_stack_heaps();
// Now we have startup stack RAM available for heap, enable any DMA pool memory
#if CONFIG_SPIRAM_MALLOC_RESERVE_INTERNAL
if (esp_psram_is_initialized()) {
esp_err_t r = esp_psram_extram_reserve_dma_pool(CONFIG_SPIRAM_MALLOC_RESERVE_INTERNAL);
if (r != ESP_OK) {
ESP_EARLY_LOGE(TAG, "Could not reserve internal/DMA pool (error 0x%x)", r);
abort();
}
}
#endif
//Initialize TWDT if configured to do so
#if CONFIG_ESP_TASK_WDT
esp_task_wdt_config_t twdt_config = {
.timeout_ms = CONFIG_ESP_TASK_WDT_TIMEOUT_S * 1000,
.idle_core_mask = 0,
#if CONFIG_ESP_TASK_WDT_PANIC
.trigger_panic = true,
#endif
};
#if CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU0
twdt_config.idle_core_mask |= (1 << 0);
#endif
#if CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU1
twdt_config.idle_core_mask |= (1 << 1);
#endif
ESP_ERROR_CHECK(esp_task_wdt_init(&twdt_config));
#endif // CONFIG_ESP_TASK_WDT
app_main();
vTaskDelete(NULL);
}
#endif
#include <math.h>
double ceil(double i)
{
i=i;
return i;
}
double floor (double i)
{
i = i;
return i;
}
void _end(void)
{
return;
}
void _edata(void)
{
return;
}
void opendir(void)
{
return;
}
void readdir(void)
{
return;
}
void closedir(void)
{
return;
}
void select(void)
{
return;
}
此差异已折叠。
......@@ -29,7 +29,6 @@
/* Memory Management */
#define RT_PAGE_MAX_ORDER 11
#define RT_USING_MEMPOOL
#define RT_USING_SMALL_MEM
#define RT_USING_SMALL_MEM_AS_HEAP
......@@ -41,7 +40,7 @@
#define RT_USING_CONSOLE
#define RT_CONSOLEBUF_SIZE 256
#define RT_CONSOLE_DEVICE_NAME "uart"
#define RT_VER_NUM 0x50000
#define RT_VER_NUM 0x50001
/* RT-Thread Components */
......@@ -63,6 +62,9 @@
#define FINSH_USING_DESCRIPTION
#define FINSH_ARG_MAX 10
/* DFS: device virtual file system */
/* Device Drivers */
#define RT_USING_DEVICE_IPC
......@@ -149,6 +151,7 @@
/* Micrium: Micrium software products porting for RT-Thread */
#define PKG_USING_FREERTOS_WRAPPER
#define PKG_FREERTOS_USING_CONFIG_H
#define PKG_USING_FREERTOS_WRAPPER_LATEST_VERSION
/* peripheral libraries and drivers */
......@@ -183,7 +186,7 @@
/* Arduino libraries */
/* Projects */
/* Projects and Demos */
/* Sensors */
......
......@@ -27,16 +27,17 @@ if PLATFORM == 'gcc':
CXX = PREFIX + 'g++'
AS = PREFIX + 'gcc'
AR = PREFIX + 'ar'
LINK = PREFIX + 'gcc'
LINK = PREFIX + 'g++'
TARGET_EXT = 'elf'
SIZE = PREFIX + 'size'
OBJDUMP = PREFIX + 'objdump'
OBJCPY = PREFIX + 'objcopy'
STRIP = PREFIX + 'strip'
CFLAGS = ''
AFLAGS = ''
LFLAGS = ''
CXXFLAGS = ''
DEVICE = ' -nostartfiles -march=rv32imc --specs=nosys.specs '
CFLAGS = DEVICE + '-gdwarf-4 -ggdb -Os '
AFLAGS = ' -c' + DEVICE + ' -x assembler-with-cpp'
LFLAGS = DEVICE + ' -Wl,--cref -Wl,--defsym=IDF_TARGET_ESP32C3=0 -Wl,--gc-sections,-Map=rtthread.map,-cref,-u,_start -T idf_port/ld/memory.ld -T idf_port/ld/sections.ld -T packages/ESP-IDF-latest/components/esp_rom/esp32c3/ld/esp32c3.rom.ld -T packages/ESP-IDF-latest/components/esp_rom/esp32c3/ld/esp32c3.rom.api.ld -T packages/ESP-IDF-latest/components/esp_rom/esp32c3/ld/esp32c3.rom.libgcc.ld -T packages/ESP-IDF-latest/components/esp_rom/esp32c3/ld/esp32c3.rom.newlib.ld -T packages/ESP-IDF-latest/components/esp_rom/esp32c3/ld/esp32c3.rom.version.ld -T packages/ESP-IDF-latest/components/esp_rom/esp32c3/ld/esp32c3.rom.eco3.ld -T packages/ESP-IDF-latest/components/soc/esp32c3/ld/esp32c3.peripherals.ld -Wl,--wrap=_Unwind_SetEnableExceptionFdeSorting -Wl,--wrap=__register_frame_info_bases -Wl,--wrap=__register_frame_info -Wl,--wrap=__register_frame -Wl,--wrap=__register_frame_info_table_bases -Wl,--wrap=__register_frame_info_table -Wl,--wrap=__register_frame_table -Wl,--wrap=__deregister_frame_info_bases -Wl,--wrap=__deregister_frame_info -Wl,--wrap=_Unwind_Find_FDE -Wl,--wrap=_Unwind_GetGR -Wl,--wrap=_Unwind_GetCFA -Wl,--wrap=_Unwind_GetIP -Wl,--wrap=_Unwind_GetIPInfo -Wl,--wrap=_Unwind_GetRegionStart -Wl,--wrap=_Unwind_GetDataRelBase -Wl,--wrap=_Unwind_GetTextRelBase -Wl,--wrap=_Unwind_SetIP -Wl,--wrap=_Unwind_SetGR -Wl,--wrap=_Unwind_GetLanguageSpecificData -Wl,--wrap=_Unwind_FindEnclosingFunction -Wl,--wrap=_Unwind_Resume -Wl,--wrap=_Unwind_RaiseException -Wl,--wrap=_Unwind_DeleteException -Wl,--wrap=_Unwind_ForcedUnwind -Wl,--wrap=_Unwind_Resume_or_Rethrow -Wl,--wrap=_Unwind_Backtrace -Wl,--wrap=__cxa_call_unexpected -Wl,--wrap=__gxx_personality_v0 -Wl,--cref -Wl,--defsym=IDF_TARGET_ESP32C3=0'
CXXFLAGS = CFLAGS
POST_ACTION = ''
POST_ACTION = OBJCPY + ' -Oihex $TARGET rtthread.hex\n' + SIZE + ' $TARGET \n'
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册