Commit c7d6df08 authored by Neucrack's avatar Neucrack

add new framwork

parents
# Prerequisites
*.d
# Object files
*.o
*.ko
*.obj
*.elf
# Linker output
*.ilk
*.map
*.exp
# Precompiled Headers
*.gch
*.pch
# Libraries
*.lib
*.a
*.la
*.lo
# Shared objects (inc. Windows DLLs)
*.dll
*.so
*.so.*
*.dylib
# Executables
*.exe
*.out
*.app
*.i*86
*.x86_64
*.hex
# Debug files
*.dSYM/
*.su
*.idb
*.pdb
# Kernel Module Compile Results
*.mod*
*.cmd
.tmp_versions/
modules.order
Module.symvers
Mkfile.old
dkms.conf
build
.vscode
.config
.config.old
# python
*.pyc
__pycache__
[submodule "tools/kconfig/Kconfiglib"]
path = tools/kconfig/Kconfiglib
url = https://github.com/ulfalizer/Kconfiglib.git
[submodule "components/kendryte_sdk/kendryte-standalone-sdk"]
path = components/kendryte_sdk/kendryte-standalone-sdk
url = https://github.com/sipeed/kendryte-standalone-sdk
mainmenu "C/CPP CMake project framework Kconfig configuration"
menu "Toolchain configuration"
config TOOLCHAIN_PATH
string "toolchain path"
default ""
config TOOLCHAIN_PREFIX
string "toolchain prefix"
default ""
endmenu
menu "Components configuration"
source "$(COMPONENT_KCONFIGS)"
endmenu
License
======
All the source code in this repository is released under MIT or Apache v2.0 license.
All the sources related to MicroPython and openomv are under MIT license.
All the sources created/modified by the repository owner are released under Apache v2.0 license and contains the following copyright notice:
Copyright 2019 Sipeed Co.,Ltd.
Most of the source files contains license and copyright notice, please check the individual files for more information.
Also check the license information in individual components directories.
```
The MIT License (MIT)
Copyright (c) 2013, 2014 Damien P. George
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.
```
```
Copyright 2019 Sipeed Co.,Ltd.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
```
```
The MIT License (MIT)
Copyright (c) 2014 Ibrahim Abdelkader <i.abdalkader@gmail.com>
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
```
<img width=205 src="assets/image/maixpy.png">
<br />
<br />
<div class="title_pic">
<img src="assets/image/micropython.png"><img src="assets/image/icon_sipeed2.png" height="60">
</div>
<br />
<a href="https://travis-ci.org/sipeed/MaixPy">
<img src="https://travis-ci.org/sipeed/MaixPy.svg?branch=master" alt="Master branch build status" />
</a>
<a href="http://dl.sipeed.com/MAIX/MaixPy/release/master/">
<img src="https://img.shields.io/badge/build-master-ff69b4.svg" alt="master build firmware" />
</a>
<a href="https://github.com/sipeed/MaixPy/releases">
<img src="https://img.shields.io/github/release/sipeed/maixpy.svg" alt="Latest release version" />
</a>
<a href="https://github.com/sipeed/MaixPy/blob/master/LICENSE.md">
<img src="https://img.shields.io/badge/license-Apache%20v2.0-orange.svg" alt="License" />
</a>
<br />
<a href="https://github.com/sipeed/MaixPy/issues?utf8=%E2%9C%93&q=is%3Aissue+label%3A%22good+first+issue%22">
<img src="https://img.shields.io/github/issues/sipeed/maixpy/good%20first%20issue.svg" alt="Good first issues" />
</a>
<a href="https://github.com/sipeed/MaixPy/issues?q=is%3Aopen+is%3Aissue+label%3Abug">
<img src="https://img.shields.io/github/issues/sipeed/maixpy/bug.svg" alt="Bug issues" />
</a>
<a href="https://github.com/sipeed/MaixPy/issues?q=is%3Aissue+is%3Aopen+label%3Aenhancement">
<img src="https://img.shields.io/github/issues/sipeed/maixpy/enhancement.svg" alt="Enhancement issues" />
</a>
<br />
[中文](README_ZH.md)
<br />
<br />
**Let's Sipeed up, Maximize AI's power!**
**MaixPy, makes AIOT easier!**
Maixpy is designed to make AIOT programming easier, based on the [Micropython](http://www.micropython.org) syntax, running on a very powerful embedded AIOT chip [K210](https://kendryte.com).
> K210 brief:
> * Image Recognition with hardware acceleration
> * Dual core with FPU
> * 8MB(6MB+2MB) RAM
> * 16MB external Flash
> * Max 800MHz CPU freq (see the dev board in detail)
> * Microphone array(8 mics)
> * Hardware AES SHA256
> * FPIOA (Periphrals can map to any pins)
> * Peripherals: I2C, SPI, I2S, WDT, TIMER, RTC, UART, GPIO etc.
![](assets/image/maix_bit.png)
## Simple code
Find I2C devices:
```python
from machine import I2C
i2c = I2C(I2C.I2C0, freq=100000, scl=28, sda=29)
devices = i2c.scan()
print(devices)
```
Take picture:
```python
import sensor
import image
import lcd
lcd.init()
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.run(1)
while True:
img=sensor.snapshot()
lcd.display(img)
```
## Release
See [Releases page](https://github.com/sipeed/MaixPy/releases)
Get latest commit firmware: [master firmware](http://dl.sipeed.com/MAIX/MaixPy/release/master/)
## Documentation
Doc refer to [maixpy.sipeed.com](https://maixpy.sipeed.com)
## Examples
[MaixPy_scripts](https://github.com/sipeed/MaixPy_scripts)
## Build From Source
See [build doc](ports/k210-freertos/README.md)
## License
See [LICENSE](LICENSE.md) file
<img width=205 src="assets/image/maixpy.png">
<br />
<br />
<div class="title_pic">
<img src="assets/image/micropython.png"><img src="assets/image/icon_sipeed2.png" height="60">
</div>
<br />
<a href="https://travis-ci.org/sipeed/MaixPy">
<img src="https://travis-ci.org/sipeed/MaixPy.svg?branch=master" alt="Master branch build status" />
</a>
<a href="http://dl.sipeed.com/MAIX/MaixPy/release/master/">
<img src="https://img.shields.io/badge/build-master-ff69b4.svg" alt="master build firmware" />
</a>
<a href="https://github.com/sipeed/MaixPy/releases">
<img src="https://img.shields.io/github/release/sipeed/maixpy.svg" alt="Latest release version" />
</a>
<a href="https://github.com/sipeed/MaixPy/blob/master/LICENSE.md">
<img src="https://img.shields.io/badge/license-Apache%20v2.0-orange.svg" alt="License" />
</a>
<br />
<a href="https://github.com/sipeed/MaixPy/issues?utf8=%E2%9C%93&q=is%3Aissue+label%3A%22good+first+issue%22">
<img src="https://img.shields.io/github/issues/sipeed/maixpy/good%20first%20issue.svg" alt="Good first issues" />
</a>
<a href="https://github.com/sipeed/MaixPy/issues?q=is%3Aopen+is%3Aissue+label%3Abug">
<img src="https://img.shields.io/github/issues/sipeed/maixpy/bug.svg" alt="Bug issues" />
</a>
<a href="https://github.com/sipeed/MaixPy/issues?q=is%3Aissue+is%3Aopen+label%3Aenhancement">
<img src="https://img.shields.io/github/issues/sipeed/maixpy/enhancement.svg" alt="Enhancement issues" />
</a>
<br />
[English](README.md)
<br />
<br />
**MaixPy, 让 AIOT 更简单~**
Maixpy 的目的是让 AIOT 编程更简单, 基于 [Micropython](http://www.micropython.org) 语法, 运行在一款有着便宜价格的高性能芯片 [K210](https://kendryte.com) 上.
> K210 简介 :
> * 拥有硬件加速的图像识别
> * 带硬件浮点运算的双核处理器
> * 8MB(6MB+2MB) 内存
> * 16MB 外置 Flash
> * 芯片 CPU 最高可达 800MHz 主频 (开发板支持最高主频具体看开发板介绍)
> * 麦克风阵列支持(8个麦克风)
> * 硬件 AES SHA256 支持
> * FPIOA (每个外设可以映射到任意引脚)
> * 外设: I2C, SPI, I2S, WDT, TIMER, RTC, UART, GPIO 等等
![](assets/image/maix_bit.png)
## 简单易懂的代码
寻找 I2C 设备:
```python
from machine import I2C
i2c = I2C(I2C.I2C0, freq=100000, scl=28, sda=29)
devices = i2c.scan()
print(devices)
```
拍照:
```python
import sensor
import image
import lcd
lcd.init()
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.run(1)
while True:
img=sensor.snapshot()
lcd.display(img)
```
## 固件发布
发布版本固件: [固件发布页面](https://github.com/sipeed/MaixPy/releases)
最新提交(开发中)的固件: [master 分支的固件](http://dl.sipeed.com/MAIX/MaixPy/release/master/)
## 文档
查看 [maixpy.sipeed.com](https://maixpy.sipeed.com)
## 例示代码
[MaixPy_scripts](https://github.com/sipeed/MaixPy_scripts)
## 从源码构建自己的固件
参考 [build doc](ports/k210-freertos/README.md)
## 开源协议
查看 [LICENSE](LICENSE.md) 文件
################# Add include #################
list(APPEND ADD_INCLUDE "include"
"kendryte-standalone-sdk/lib/bsp/include"
"kendryte-standalone-sdk/lib/drivers/include"
"kendryte-standalone-sdk/lib/freertos/include"
"kendryte-standalone-sdk/lib/freertos/conf"
"kendryte-standalone-sdk/lib/freertos/portable"
"kendryte-standalone-sdk/lib/utils/include"
)
list(APPEND ADD_PRIVATE_INCLUDE "include_private")
###############################################
############## Add source files ###############
aux_source_directory("kendryte-standalone-sdk/lib/bsp" ADD_SRCS_BSP)
aux_source_directory("kendryte-standalone-sdk/lib/drivers" ADD_SRCS_DRIVER)
aux_source_directory("kendryte-standalone-sdk/lib/freertos" ADD_SRCS_FREERTOS)
aux_source_directory("kendryte-standalone-sdk/lib/freertos/portable" ADD_SRCS_FREERTOS2)
list(APPEND ADD_SRCS ${ADD_SRCS_BSP}
${ADD_SRCS_DRIVER}
${ADD_SRCS_FREERTOS}
${ADD_SRCS_FREERTOS2}
)
# list(REMOVE_ITEM COMPONENT_SRCS "src/test.c")
###############################################
###### Add required/dependent components ######
# list(APPEND ADD_REQUIREMENTS )
###############################################
############ Add static libs ##################
# list(APPEND ADD_STATIC_LIB "lib/libtest.a")
###############################################
add_definitions(-DLOG_LEVEL=${CONFIG_SDK_LOG_LEVEL})
register_component()
menu "Toolchain configuration"
config SDK_LOG_LEVEL
int "log level, 5:LOG_VERBOSE, 4:LOG_DEBUG, 3:LOG_INFO, 2:LOG_WARN, 1:LOG_ERROR, 0:LOG_NONE"
default 5
endmenu
Make sure you read and understand this document.
Use one of the two templates below and delete the rest.
- [ ] BUG REPORT
- [ ] FEATURE REQUEST
-------------------------------------------------------------------------------
> BUG REPORT
### Expected behavior
### Actual behavior
### Test code
Provide a [Minimal, Complete, and Verifiable example](http://stackoverflow.com/help/mcve) which will reproduce the problem.
```bash
# Add code here
```
### Document version
Which branch are you on? If you know the Git revision then add it here as well.
### Hardware
Which hardware do you use?
### System
What system do you use?
-------------------------------------------------------------------------------
> FEATURE REQUEST
### Missing feature
### Justification
Tell us why you would like to see this feature added.
### Workarounds
Are there any workarounds you currently have in place because the feature is missing?
Fixes #\<GitHub-issue-number\>.
Make sure all boxes are checked (add x inside the brackets) when you submit your contribution, remove this sentence before doing so.
- [ ] I have thoroughly tested my contribution.
- [ ] The code I submitted has no copyright issues.
\<Description of and rational behind this PR\>
\ No newline at end of file
This diff is collapsed.
sudo: false
language: cpp
git:
submodules: false
addons:
apt:
packages:
- python
- python-pip
- git
- wget
- make
- cmake
- libncurses-dev
- flex
- bison
- gperf
- aria2
cache:
- pip
- directories:
- cache
before_install:
- export TOOLCHAIN_URL=https://github.com/kendryte/kendryte-gnu-toolchain/releases/download/v8.2.0-20190213/kendryte-toolchain-ubuntu-amd64-8.2.0-20190213.tar.gz
- export TOOLCHAIN=${TOOLCHAIN_URL##*/}
- |
if [ ! -f $TRAVIS_BUILD_DIR/cache/$TOOLCHAIN ]; then
echo "Download toolchain ..."
aria2c $TOOLCHAIN_URL -d $TRAVIS_BUILD_DIR/cache -o $TOOLCHAIN
else
echo "Toolchain is ready download in cache"
fi
- |
if [ ! -d $TRAVIS_BUILD_DIR/cache/kendryte-toolchain ]; then
echo "Extract toolchain ..."
tar -C $TRAVIS_BUILD_DIR/cache -zxvf $TRAVIS_BUILD_DIR/cache/$TOOLCHAIN
else
echo "Toolchain is ready extract in cache"
fi
install:
- export PATH=$TRAVIS_BUILD_DIR/cache/kendryte-toolchain/bin:$PATH
- export LD_LIBRARY_PATH=$TRAVIS_BUILD_DIR/cache/kendryte-toolchain/bin:$LD_LIBRARY_PATH
- |
cd $TRAVIS_BUILD_DIR
export BRANCH=$(if [ "$TRAVIS_BRANCH" == "master" ]; then echo $TRAVIS_BRANCH; else echo "develop"; fi)
git clone --single-branch --branch $BRANCH https://github.com/kendryte/kendryte-standalone-demo.git
echo "Build branch $BRANCH"
script:
- export BUILD_DATE=$(date +%Y%m%d)
## Copy all example code
- |
cd $TRAVIS_BUILD_DIR/src
cp -rf $TRAVIS_BUILD_DIR/kendryte-standalone-demo/* .
mv $TRAVIS_BUILD_DIR/kendryte-standalone-demo ~/demo
## Check example code
- |
for DIR in $(ls $TRAVIS_BUILD_DIR/src)
do
echo "[MAKE]" $TRAVIS_BUILD_DIR/src/$DIR
cd $TRAVIS_BUILD_DIR/src/$DIR
if [ ! -f "Makefile" ]; then
COUNT=$(expr $(ls -1 *.c 2>/dev/null | wc -l) + $(ls -1 *.cpp 2>/dev/null | wc -l) + $(ls -1 *.S 2>/dev/null | wc -l))
if [ $COUNT -gt 0 ]; then
mkdir build && cd build
cmake -DPROJ=$DIR -DTOOLCHAIN=$TRAVIS_BUILD_DIR/cache/kendryte-toolchain/bin ../../../ || exit -1
make || exit -1
else
echo "[IGNORE]" $TRAVIS_BUILD_DIR/src/$DIR
fi
else
make || exit -1
fi
done
Changelog for Kendryte K210
======
## 0.1.0
Kendryte K210 first SDK with FreeRTOS, have fun.
## 0.2.0
- Major changes
- Rework trap handling
- New functions to enable spi0 and dvp pin
- New functions to select IO power mode
- Breaking changes
- Modify struct enum union format
- Non-breaking bug fixes
- Fix spi lcd unwork issues
- Fix dual core startup issues
- Use "__global_pointer$" instead of "_gp"
## 0.3.0
- Major change
- Modify AES、FFT、SHA、I2C、SPI、WDT、SPI driver
- Breaking changes
- Modify struct enum union format
- Non-breaking bug fixes
- Fix out of memory issues
- Fix lcd unused issues
## 0.4.1
- Major change
- Add dma support for aes driver
- Add uarths driver
- Add dma interrupt handler
- Non-breaking bug fixes
- Fix the procedure of setting pll
- Fix wdt interrupt bug
- Fix serveral bugs in i2s drivers
## 0.5.0
- Major change
- Add KPU driver
- Find toolchain automatically
- Non-breaking bug fixes
- Fix aes gcm bug
- Fix dmac interrupt bug
- Fix i2s transfer bug
## 0.5.1
- Major changes
- Add i2c slave driver
- Non-breaking bug fixes
- Fix pll init issues
- Fix spi receive mode issues
- Fix redefine function does not report error issues
- Reduce stack size
## 0.5.2
- Major change
- Add KPU driver for latest model compiler
- Automatic set PROJ if user not set it
- Update timer driver to support better interrupt
- Add uart dma and interrupt function
- Non-breaking bug fixes
- Fix rtc issues
- Fix sccb issues
- Breaking change
- Fix timer interrupt lost problem
- Add new timer interrupt API
## 0.5.3
- Major change
- Modify KPU driver for latest model compiler
- Add freertos
- Add new gpiohs and wdt interrupt function
- Add dvp xclk setting
- Add sysctl reset status
- Non-breaking bug fixes
- Fix i2c issues
- Fix spi issues
- Breaking change
- Fix uarths stopbit problem
- Fix core1 stack problem
- Fix core1 interrupt problem
## 0.5.4
- Major change
- Modify KPU driver for NNCASE
- Add APU driver
- Add support for new toolchain
- UART use shadow regs
- Add spi slave driver
- Add travis CI script
- Non-breaking bug fixes
- Fix float issues
- Breaking change
- Fix bus reset problem
## 0.5.5
- Major change
- Add SPI I2C I2S UART DMA callback
- Add malloc lock
- Update WIN32 cmake program auto-set
- Upadte KPU driver for lastest NNCASE
- Non-breaking bug fixes
- Fix double issues
- Fix GPIO issues
- Breaking change
- Fix device reset problem
### This file is used for build example projects.
# set this will supress some warnings
set(BUILDING_SDK "yes" CACHE INTERNAL "")
# basic config
if (NOT PROJ)
get_filename_component(PROJ ${CMAKE_CURRENT_BINARY_DIR} DIRECTORY)
get_filename_component(PROJ ${PROJ} NAME)
string(REPLACE " " "_" PROJ ${PROJ})
message(STATUS "PROJ not set, use ${PROJ} as PROJ. Also, you can set it manually. e.g. -DPROJ=hello_world")
else()
message("PROJ = ${PROJ}")
endif ()
cmake_minimum_required(VERSION 3.0)
include(./cmake/common.cmake)
project(${PROJ} C CXX ASM)
# config self use headers
include(./cmake/macros.internal.cmake)
header_directories(${SDK_ROOT}/lib)
header_directories(src/${PROJ})
header_directories(kendryte-standalone-demo/${PROJ})
# build library first
add_subdirectory(lib)
# compile project
add_source_files(src/${PROJ}/*.c src/${PROJ}/*.s src/${PROJ}/*.S src/${PROJ}/*.cpp)
add_source_files(kendryte-standalone-demo/${PROJ}/*.c kendryte-standalone-demo/${PROJ}/*.s kendryte-standalone-demo/${PROJ}/*.S kendryte-standalone-demo/${PROJ}/*.cpp)
include(./cmake/executable.cmake)
This diff is collapsed.
# Kendryte K210 standalone SDK
[![Build Status](https://travis-ci.org/kendryte/kendryte-standalone-sdk.svg)](https://travis-ci.org/kendryte/kendryte-standalone-sdk)
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
This SDK is for Kendryte K210 without OS support.
If you have any questions, please be free to contact us.
## Usage
If you want to start a new project, for instance, `hello_world`, you only need to:
- Linux and OSX
`mkdir` your project in `src/`, `cd src && mkdir hello_world`, then put your codes in it, enter SDK root directory and build it.
```bash
mkdir build && cd build
cmake .. -DPROJ=<ProjectName> -DTOOLCHAIN=/opt/riscv-toolchain/bin && make
```
- Windows
Download and install latest CMake.
[Download cmake-3.14.1-win64-x64.msi](https://github.com/Kitware/CMake/releases/download/v3.14.1/cmake-3.14.1-win64-x64.msi)
Download and install latest toolchain.
[Download kendryte-toolchain-win-i386-8.2.0-20190409.tar.xz](https://github.com/kendryte/kendryte-gnu-toolchain/releases/download/v8.2.0-20190409/kendryte-toolchain-win-i386-8.2.0-20190409.tar.xz)
Open a Windows Powershell, cd to Project directory.
`mkdir` your project in `src/`, `cd src && mkdir hello_world`, then put your codes in it, and build it.
```powershell
$env:Path="E:\kendryte-toolchain\bin;C:\Program Files\CMak
e\bin" + $env:Path
mkdir build && cd build
cmake -G "MinGW Makefiles" ../../../..
make
```
You will get 2 key files, `hello_world` and `hello_world.bin`.
1. If you are using JLink to run or debug your program, use `hello_world`
2. If you want to flash it in UOG, using `hello_world.bin`, then using flash-tool(s) burn <ProjectName>.bin to your flash.
This is very important, don't make a mistake in files.
### This file is used for build library standalone.
# set this will supress some warnings
set(BUILDING_SDK "yes" CACHE INTERNAL "")
# basic config
cmake_minimum_required(VERSION 3.0)
include(./common.cmake)
project(kendryte)
# config self use headers
include(./macros.internal.cmake)
header_directories(${SDK_ROOT}/lib)
# include lib make file
include(../lib/CMakeLists.txt)
# find headers files to INSTALL
file(GLOB_RECURSE LIB_HEADERS
"../lib/*.h"
"../lib/*.hpp"
)
set_target_properties(kendryte PROPERTIES PUBLIC_HEADER "${LIB_HEADERS}")
# copy .a file and headers
install(TARGETS kendryte
EXPORT kendryte
ARCHIVE
DESTINATION ${CMAKE_BINARY_DIR}/archive
PUBLIC_HEADER DESTINATION ${CMAKE_BINARY_DIR}/archive/include
)
# copy utils files
install(DIRECTORY
../lds
../utils
../cmake
DESTINATION ${CMAKE_BINARY_DIR}/archive
PATTERN "*internal*" EXCLUDE
PATTERN "CMakeLists.txt" EXCLUDE
)
# show information
include(./dump-config.cmake)
prepend `common.cmake` before
append `executable.cmake` after
cmake_minimum_required(VERSION 3.0)
include(${CMAKE_CURRENT_LIST_DIR}/macros.cmake)
global_set(CMAKE_C_COMPILER_WORKS 1)
global_set(CMAKE_CXX_COMPILER_WORKS 1)
global_set(CMAKE_SYSTEM_NAME "Generic")
if (NOT CMAKE_BUILD_TYPE)
global_set(CMAKE_BUILD_TYPE Debug)
else ()
if ((NOT CMAKE_BUILD_TYPE STREQUAL "Debug") AND (NOT CMAKE_BUILD_TYPE STREQUAL "Release"))
message(FATAL_ERROR "CMAKE_BUILD_TYPE must either be Debug or Release instead of ${CMAKE_BUILD_TYPE}")
endif ()
endif ()
# - Debug & Release
IF (CMAKE_BUILD_TYPE STREQUAL Debug)
add_definitions(-DDEBUG=1)
ENDIF ()
# definitions in macros
add_definitions(-DCONFIG_LOG_LEVEL=LOG_VERBOSE -DCONFIG_LOG_ENABLE -DCONFIG_LOG_COLORS -DLOG_KERNEL -D__riscv64 -DLV_CONF_INCLUDE_SIMPLE)
if (NOT SDK_ROOT)
get_filename_component(_SDK_ROOT ${CMAKE_CURRENT_LIST_DIR} DIRECTORY)
global_set(SDK_ROOT ${_SDK_ROOT})
endif ()
include(${CMAKE_CURRENT_LIST_DIR}/toolchain.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/compile-flags.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/fix-9985.cmake)
add_compile_flags(LD
-nostartfiles
-static
-Wl,--gc-sections
-Wl,-static
-Wl,--start-group
-Wl,--whole-archive
-Wl,--no-whole-archive
-Wl,--end-group
-Wl,-EL
-Wl,--no-relax
-T ${SDK_ROOT}/lds/kendryte.ld
)
# C Flags Settings
add_compile_flags(BOTH
-mcmodel=medany
-mabi=lp64f
-march=rv64imafc
-fno-common
-ffunction-sections
-fdata-sections
-fstrict-volatile-bitfields
-fno-zero-initialized-in-bss
-ffast-math
-fno-math-errno
-fsingle-precision-constant
-Os
-ggdb
)
add_compile_flags(C -std=gnu11 -Wno-pointer-to-int-cast)
add_compile_flags(CXX -std=gnu++17)
if (BUILDING_SDK)
add_compile_flags(BOTH
-Wall
-Werror=all
-Wno-error=unused-function
-Wno-error=unused-but-set-variable
-Wno-error=unused-variable
-Wno-error=deprecated-declarations
-Wextra
-Werror=frame-larger-than=32768
-Wno-unused-parameter
-Wno-sign-compare
-Wno-error=missing-braces
-Wno-error=return-type
-Wno-error=pointer-sign
-Wno-missing-braces
-Wno-strict-aliasing
-Wno-implicit-fallthrough
-Wno-missing-field-initializers
-Wno-int-to-pointer-cast
-Wno-error=comment
-Wno-error=logical-not-parentheses
-Wno-error=duplicate-decl-specifier
-Wno-error=parentheses
)
add_compile_flags(C -Wno-old-style-declaration)
else ()
add_compile_flags(BOTH -L${SDK_ROOT}/include/)
endif ()
message("")
message("Project: ${PROJECT_NAME}")
message(" LIST_FILE=${CMAKE_PARENT_LIST_FILE}")
message(" TOOLCHAIN=${TOOLCHAIN}")
message(" KENDRYTE_IDE=${KENDRYTE_IDE}")
message(" BUILDING_SDK=${BUILDING_SDK}")
message("")
message(" CMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}")
message(" CMAKE_C_COMPILER=${CMAKE_C_COMPILER}")
message(" CMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}")
message(" CMAKE_LINKER=${CMAKE_LINKER}")
message(" CMAKE_OBJCOPY=${CMAKE_OBJCOPY}")
message(" CMAKE_OBJDUMP=${CMAKE_OBJDUMP}")
message(" CMAKE_MAKE_PROGRAM=${CMAKE_MAKE_PROGRAM}")
message("")
message(" CMAKE_C_FLAGS=${CMAKE_C_FLAGS}")
message(" CMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}")
message(" LDFLAGS=${LDFLAGS}")
message(" CMAKE_BINARY_DIR=${CMAKE_BINARY_DIR}")
message("Makefile created.")
message("")
message("")
if (NOT BUILDING_SDK)
if(EXISTS ${SDK_ROOT}/libkendryte.a)
add_library(kendryte STATIC IMPORTED)
set_property(TARGET kendryte PROPERTY IMPORTED_LOCATION ${SDK_ROOT}/libkendryte.a)
include_directories(${SDK_ROOT}/include/)
else()
header_directories(${SDK_ROOT}/lib)
add_subdirectory(${SDK_ROOT}/lib)
endif()
endif ()
removeDuplicateSubstring(${CMAKE_C_FLAGS} CMAKE_C_FLAGS)
removeDuplicateSubstring(${CMAKE_CXX_FLAGS} CMAKE_CXX_FLAGS)
message("SOURCE_FILES=${SOURCE_FILES}")
add_executable(${PROJECT_NAME} ${SOURCE_FILES})
set_target_properties(${PROJECT_NAME} PROPERTIES LINKER_LANGUAGE C)
target_link_libraries(${PROJECT_NAME}
-Wl,--start-group
gcc m c
-Wl,--whole-archive
kendryte
-Wl,--no-whole-archive
-Wl,--end-group
)
if (EXISTS ${SDK_ROOT}/src/${PROJ}/project.cmake)
include(${SDK_ROOT}/src/${PROJ}/project.cmake)
endif ()
IF(SUFFIX)
SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES SUFFIX ${SUFFIX})
ENDIF()
# Build target
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_OBJCOPY} --output-format=binary ${CMAKE_BINARY_DIR}/${PROJECT_NAME}${SUFFIX} ${CMAKE_BINARY_DIR}/${PROJECT_NAME}.bin
DEPENDS ${PROJECT_NAME}
COMMENT "Generating .bin file ...")
# show information
include(${CMAKE_CURRENT_LIST_DIR}/dump-config.cmake)
### http://www.cmake.org/Bug/view.php?id=9985
string(REPLACE "-rdynamic" "" CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "${CMAKE_SHARED_LIBRARY_LINK_C_FLAGS}")
string(REPLACE "-rdynamic" "" CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "${CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS}")
macro(global_set Name Value)
# message("set ${Name} to " ${ARGN})
set(${Name} "${Value}" CACHE STRING "NoDesc" FORCE)
endmacro()
macro(condition_set Name Value)
if (NOT ${Name})
global_set(${Name} ${Value})
else ()
# message("exists ${Name} is " ${ARGN})
endif ()
endmacro()
set(SOURCE_FILES "" CACHE STRING "Source Files" FORCE)
macro(add_source_files)
# message(" + add_source_files ${ARGN}")
file(GLOB_RECURSE newlist ${ARGN})
foreach (filepath ${newlist})
string(FIND ${filepath} ${CMAKE_BINARY_DIR} found)
if (NOT found EQUAL 0)
set(SOURCE_FILES ${SOURCE_FILES} ${filepath} CACHE STRING "Source Files" FORCE)
endif ()
endforeach ()
endmacro()
function(JOIN VALUES GLUE OUTPUT)
string(REGEX REPLACE "([^\\]|^);" "\\1${GLUE}" _TMP_STR "${VALUES}")
string(REGEX REPLACE "[\\](.)" "\\1" _TMP_STR "${_TMP_STR}") #fixes escaping
set(${OUTPUT} "${_TMP_STR}" PARENT_SCOPE)
endfunction()
global_set(LDFLAGS "")
global_set(CMAKE_EXE_LINKER_FLAGS "")
global_set(CMAKE_SHARED_LINKER_FLAGS "")
global_set(CMAKE_MODULE_LINKER_FLAGS "")
function(removeDuplicateSubstring stringIn stringOut)
separate_arguments(stringIn)
list(REMOVE_DUPLICATES stringIn)
string(REPLACE ";" " " stringIn "${stringIn}")
set(${stringOut} "${stringIn}" PARENT_SCOPE)
endfunction()
macro(add_compile_flags WHERE)
JOIN("${ARGN}" " " STRING_ARGS)
if (${WHERE} STREQUAL C)
global_set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${STRING_ARGS}")
elseif (${WHERE} STREQUAL CXX)
global_set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${STRING_ARGS}")
elseif (${WHERE} STREQUAL LD)
global_set(LDFLAGS "${LDFLAGS} ${STRING_ARGS}")
global_set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${STRING_ARGS}")
global_set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${STRING_ARGS}")
global_set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} ${STRING_ARGS}")
elseif (${WHERE} STREQUAL BOTH)
add_compile_flags(C ${ARGN})
add_compile_flags(CXX ${ARGN})
elseif (${WHERE} STREQUAL ALL)
add_compile_flags(C ${ARGN})
add_compile_flags(CXX ${ARGN})
add_compile_flags(LD ${ARGN})
else ()
message(FATAL_ERROR "add_compile_flags - only support: C, CXX, BOTH, LD, ALL")
endif ()
endmacro()
# Add lib headers
macro(header_directories parent)
file(GLOB_RECURSE newList ${parent}/*.h)
set(dir_list "")
foreach (file_path ${newList})
get_filename_component(dir_path ${file_path} DIRECTORY)
set(dir_list ${dir_list} ${dir_path})
endforeach ()
list(REMOVE_DUPLICATES dir_list)
include_directories(${dir_list})
endmacro()
\ No newline at end of file
if (WIN32)
set(EXT ".exe")
else ()
set(EXT "")
endif ()
message(STATUS "Check for RISCV toolchain ...")
if(NOT TOOLCHAIN)
find_path(_TOOLCHAIN riscv64-unknown-elf-gcc${EXT})
global_set(TOOLCHAIN "${_TOOLCHAIN}")
elseif(NOT "${TOOLCHAIN}" MATCHES "/$")
global_set(TOOLCHAIN "${TOOLCHAIN}")
endif()
if (NOT TOOLCHAIN)
message(FATAL_ERROR "TOOLCHAIN must be set, to absolute path of kendryte-toolchain dist/bin folder.")
endif ()
message(STATUS "Using ${TOOLCHAIN} RISCV toolchain")
global_set(CMAKE_C_COMPILER "${TOOLCHAIN}/riscv64-unknown-elf-gcc${EXT}")
global_set(CMAKE_CXX_COMPILER "${TOOLCHAIN}/riscv64-unknown-elf-g++${EXT}")
global_set(CMAKE_LINKER "${TOOLCHAIN}/riscv64-unknown-elf-ld${EXT}")
global_set(CMAKE_AR "${TOOLCHAIN}/riscv64-unknown-elf-ar${EXT}")
global_set(CMAKE_OBJCOPY "${TOOLCHAIN}/riscv64-unknown-elf-objcopy${EXT}")
global_set(CMAKE_SIZE "${TOOLCHAIN}/riscv64-unknown-elf-size${EXT}")
global_set(CMAKE_OBJDUMP "${TOOLCHAIN}/riscv64-unknown-elf-objdump${EXT}")
if (WIN32)
if(EXISTS "${TOOLCHAIN}/make${EXT}")
global_set(CMAKE_MAKE_PROGRAM "${TOOLCHAIN}/make${EXT}")
else()
global_set(CMAKE_MAKE_PROGRAM "${TOOLCHAIN}/mingw32-make${EXT}")
endif()
endif ()
execute_process(COMMAND ${CMAKE_C_COMPILER} -print-file-name=crt0.o OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE CRT0_OBJ)
execute_process(COMMAND ${CMAKE_C_COMPILER} -print-file-name=crtbegin.o OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE CRTBEGIN_OBJ)
execute_process(COMMAND ${CMAKE_C_COMPILER} -print-file-name=crtend.o OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE CRTEND_OBJ)
execute_process(COMMAND ${CMAKE_C_COMPILER} -print-file-name=crti.o OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE CRTI_OBJ)
execute_process(COMMAND ${CMAKE_C_COMPILER} -print-file-name=crtn.o OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE CRTN_OBJ)
global_set(CMAKE_C_LINK_EXECUTABLE
"<CMAKE_C_COMPILER> <FLAGS> <CMAKE_C_LINK_FLAGS> <LINK_FLAGS> \"${CRTI_OBJ}\" \"${CRTBEGIN_OBJ}\" <OBJECTS> \"${CRTEND_OBJ}\" \"${CRTN_OBJ}\" -o <TARGET> <LINK_LIBRARIES>")
global_set(CMAKE_CXX_LINK_EXECUTABLE
"<CMAKE_CXX_COMPILER> <FLAGS> <CMAKE_CXX_LINK_FLAGS> <LINK_FLAGS> \"${CRTI_OBJ}\" \"${CRTBEGIN_OBJ}\" <OBJECTS> \"${CRTEND_OBJ}\" \"${CRTN_OBJ}\" -o <TARGET> <LINK_LIBRARIES>")
get_filename_component(_BIN_DIR "${CMAKE_C_COMPILER}" DIRECTORY)
if (NOT "${TOOLCHAIN}" STREQUAL "${_BIN_DIR}")
message(FATAL_ERROR "CMAKE_C_COMPILER is not in kendryte-toolchain dist/bin folder.")
endif ()
{
"name": "framework-kendryte210-standalone-sdk",
"description": "This SDK is for Kendryte K210 without OS support.",
"version": "0.5.4",
"url": "https://github.com/kendryte/kendryte-standalone-sdk"
}
/*
* The MEMORY command describes the location and size of blocks of memory
* in the target. You can use it to describe which memory regions may be
* used by the linker, and which memory regions it must avoid.
*/
MEMORY
{
/*
* Memory with CPU cache.
*6M CPU SRAM
*/
ram (wxa!ri) : ORIGIN = 0x80000000, LENGTH = (6 * 1024 * 1024)
/*
* Memory without CPU cache
* 6M CPU SRAM
*/
ram_nocache (wxa!ri) : ORIGIN = 0x40000000, LENGTH = (6 * 1024 * 1024)
}
PROVIDE( _rom_start = ORIGIN(rom) );
PROVIDE( _rom_end = ORIGIN(rom) + LENGTH(rom) );
PROVIDE( _ram_start = ORIGIN(ram) );
PROVIDE( _ram_end = ORIGIN(ram) + LENGTH(ram) );
PROVIDE( _io_start = 0x40000000 );
PROVIDE( _io_end = _io_start + LENGTH(ram) );
PROVIDE( _stack_size = 1 << 15 );
/*
* The OUTPUT_ARCH command specifies the machine architecture where the
* argument is one of the names used in the Kendryte library.
*/
OUTPUT_ARCH( "riscv" )
/*
* The ENTRY command specifies the entry point (ie. first instruction to
* execute). The symbol _start is defined in crt0.S
*/
ENTRY(_start)
/*
* The GROUP command is special since the listed archives will be
* searched repeatedly until there are no new undefined references. We
* need this since -lc depends on -lgloss and -lgloss depends on -lc. I
* thought gcc would automatically include -lgcc when needed, but
* in this file includes it explicitly here and I was seeing link errors
* without it.
*/
/* GROUP( -lc -lgloss -lgcc ) */
/*
* The linker only pays attention to the PHDRS command when generating
* an ELF output file. In other cases, the linker will simply ignore PHDRS.
*/
PHDRS
{
ram_ro PT_LOAD;
ram_init PT_LOAD;
ram PT_NULL;
}
/*
* This is where we specify how the input sections map to output
* sections.
*/
SECTIONS
{
/* Program code segment, also known as a text segment */
.text :
{
PROVIDE( _text = ABSOLUTE(.) );
/* Initialization code segment */
KEEP( *(.text.start) )
KEEP( *(.text.systick) )
*(.text.unlikely .text.unlikely.*)
*(.text.startup .text.startup.*)
/* Normal code segment */
*(.text .text.*)
*(.gnu.linkonce.t.*)
. = ALIGN(8);
PROVIDE( _etext = ABSOLUTE(.) );
} >ram AT>ram :ram_ro
/* Read-only data segment */
.rodata :
{
*(.rdata)
*(.rodata .rodata.*)
*(.gnu.linkonce.r.*)
} >ram AT>ram :ram_ro
. = ALIGN(8);
/* Init array and fini array */
.preinit_array :
{
PROVIDE_HIDDEN (__preinit_array_start = .);
KEEP (*(.preinit_array))
PROVIDE_HIDDEN (__preinit_array_end = .);
} >ram AT>ram :ram_ro
.init_array :
{
PROVIDE_HIDDEN (__init_array_start = .);
KEEP (*(SORT_BY_INIT_PRIORITY(.init_array.*) SORT_BY_INIT_PRIORITY(.ctors.*)))
KEEP (*(.init_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .ctors))
PROVIDE_HIDDEN (__init_array_end = .);
} >ram AT>ram :ram_ro
.fini_array :
{
PROVIDE_HIDDEN (__fini_array_start = .);
KEEP (*(SORT_BY_INIT_PRIORITY(.fini_array.*) SORT_BY_INIT_PRIORITY(.dtors.*)))
KEEP (*(.fini_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .dtors))
PROVIDE_HIDDEN (__fini_array_end = .);
} >ram AT>ram :ram_ro
.ctors :
{
/* gcc uses crtbegin.o to find the start of
the constructors, so we make sure it is
first. Because this is a wildcard, it
doesn't matter if the user does not
actually link against crtbegin.o; the
linker won't look for a file to match a
wildcard. The wildcard also means that it
doesn't matter which directory crtbegin.o
is in. */
KEEP (*crtbegin.o(.ctors))
KEEP (*crtbegin?.o(.ctors))
/* We don't want to include the .ctor section from
the crtend.o file until after the sorted ctors.
The .ctor section from the crtend file contains the
end of ctors marker and it must be last */
KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .ctors))
KEEP (*(SORT(.ctors.*)))
KEEP (*(.ctors))
} >ram AT>ram :ram_ro
.dtors :
{
KEEP (*crtbegin.o(.dtors))
KEEP (*crtbegin?.o(.dtors))
KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .dtors))
KEEP (*(SORT(.dtors.*)))
KEEP (*(.dtors))
} >ram AT>ram :ram_ro
. = ALIGN(8);
.lalign :
{
. = ALIGN(8);
PROVIDE( _data_lma = . );
} >ram AT>ram :ram_ro
.dalign :
{
. = ALIGN(8);
PROVIDE( _data = . );
} >ram AT>ram :ram_init
. = ALIGN(8);
/* .data, .sdata and .srodata segment */
.data :
{
/* Writable data segment (.data segment) */
*(.data .data.*)
*(.gnu.linkonce.d.*)
/* Have _gp point to middle of sdata/sbss to maximize displacement range */
. = ALIGN(8);
PROVIDE( __global_pointer$ = ABSOLUTE(.) + 0x800);
/* Writable small data segment (.sdata segment) */
*(.sdata .sdata.*)
*(.gnu.linkonce.s.*)
/* Read-only small data segment (.srodata segment) */
. = ALIGN(8);
*(.srodata.cst16)
*(.srodata.cst8)
*(.srodata.cst4)
*(.srodata.cst2)
*(.srodata .srodata.*)
/* Align _edata to cache line size */
. = ALIGN(64);
PROVIDE( _edata = ABSOLUTE(.) );
} >ram AT>ram :ram_init
/* .bss and .sbss segment */
.bss :
{
PROVIDE( _bss = ABSOLUTE(.) );
/* Writable uninitialized small data segment (.sbss segment)*/
*(.sbss .sbss.*)
*(.gnu.linkonce.sb.*)
*(.scommon)
/* Uninitialized writeable data section (.bss segment)*/
*(.bss .bss.*)
*(.gnu.linkonce.b.*)
*(COMMON)
. = ALIGN(8);
PROVIDE( _ebss = ABSOLUTE(.) );
} >ram AT>ram :ram
PROVIDE( _tls_data = ABSOLUTE(.) );
/*
* Thread Local Storage (TLS) are per-thread global variables.
* Compilers such as GCC provide a __thread keyword to mark global
* variables as per-thread. Support is required in the program loader
* and thread creator.
*/
/* Thread-local data segment, .tdata (initialized tls). */
.tdata :
{
KEEP( *(.tdata.begin) )
*(.tdata .tdata.*)
*(.gnu.linkonce.td.*)
KEEP( *(.tdata.end) )
} >ram AT>ram :ram
/* Thread-local bss segment, .tbss (zero-initialized tls). */
.tbss :
{
*(.tbss .tbss.*)
*(.gnu.linkonce.tb.*)
KEEP( *(.tbss.end) )
} >ram AT>ram :ram
/*
* End of uninitalized data segement
*
* Actually the stack needs 16B alignment, and it won't hurt to also slightly
* increase the alignment to 32 or even 64 (cache line size).
*
* Align _heap_start to cache line size
*/
. = ALIGN(64);
PROVIDE( _end = ABSOLUTE(.) );
/* Leave 2 holes for stack & TLS, the size can set in kconfig */
PROVIDE( _heap_start = ABSOLUTE(.) + _stack_size * 2 );
PROVIDE( _tp0 = (_end + 63) & (-64) );
PROVIDE( _tp1 = _tp0 + _stack_size );
PROVIDE( _sp0 = _tp0 + _stack_size );
PROVIDE( _sp1 = _tp1 + _stack_size );
/* Heap end is at the end of memory, the memory size can set in kconfig */
PROVIDE( _heap_end = _ram_end );
}
#project(maix_drivers)
# create driver library
FILE(GLOB_RECURSE LIB_SRC
"${CMAKE_CURRENT_LIST_DIR}/*.h"
"${CMAKE_CURRENT_LIST_DIR}/*.hpp"
"${CMAKE_CURRENT_LIST_DIR}/*.cpp"
"${CMAKE_CURRENT_LIST_DIR}/*.c"
"${CMAKE_CURRENT_LIST_DIR}/*.s"
"${CMAKE_CURRENT_LIST_DIR}/*.S"
)
FILE(GLOB_RECURSE ASSEMBLY_FILES
"${CMAKE_CURRENT_LIST_DIR}/*.s"
"${CMAKE_CURRENT_LIST_DIR}/*.S"
)
include_directories(${CMAKE_CURRENT_LIST_DIR}/drivers/include ${CMAKE_CURRENT_LIST_DIR}/bsp/include)
SET_PROPERTY(SOURCE ${ASSEMBLY_FILES} PROPERTY LANGUAGE C)
SET_SOURCE_FILES_PROPERTIES(${ASSEMBLY_FILES} PROPERTIES COMPILE_FLAGS "-x assembler-with-cpp -D __riscv64")
ADD_LIBRARY(kendryte
${LIB_SRC}
)
SET_TARGET_PROPERTIES(kendryte PROPERTIES LINKER_LANGUAGE C)
# Copyright 2018 Canaan Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#include "encoding.h"
# define LREG ld
# define SREG sd
# define LFREG flw
# define SFREG fsw
# define REGBYTES 8
# define STKSHIFT 15
.section .text.start, "ax", @progbits
.globl _start
_start:
j 1f
.word 0xdeadbeef
.align 3
.global g_wake_up
g_wake_up:
.dword 1
.dword 0
1:
csrw mideleg, 0
csrw medeleg, 0
csrw mie, 0
csrw mip, 0
la t0, trap_entry
csrw mtvec, t0
li x1, 0
li x2, 0
li x3, 0
li x4, 0
li x5, 0
li x6, 0
li x7, 0
li x8, 0
li x9, 0
li x10,0
li x11,0
li x12,0
li x13,0
li x14,0
li x15,0
li x16,0
li x17,0
li x18,0
li x19,0
li x20,0
li x21,0
li x22,0
li x23,0
li x24,0
li x25,0
li x26,0
li x27,0
li x28,0
li x29,0
li x30,0
li x31,0
li t0, MSTATUS_FS
csrs mstatus, t0
fssr x0
fmv.w.x f0, x0
fmv.w.x f1, x0
fmv.w.x f2, x0
fmv.w.x f3, x0
fmv.w.x f4, x0
fmv.w.x f5, x0
fmv.w.x f6, x0
fmv.w.x f7, x0
fmv.w.x f8, x0
fmv.w.x f9, x0
fmv.w.x f10,x0
fmv.w.x f11,x0
fmv.w.x f12,x0
fmv.w.x f13,x0
fmv.w.x f14,x0
fmv.w.x f15,x0
fmv.w.x f16,x0
fmv.w.x f17,x0
fmv.w.x f18,x0
fmv.w.x f19,x0
fmv.w.x f20,x0
fmv.w.x f21,x0
fmv.w.x f22,x0
fmv.w.x f23,x0
fmv.w.x f24,x0
fmv.w.x f25,x0
fmv.w.x f26,x0
fmv.w.x f27,x0
fmv.w.x f28,x0
fmv.w.x f29,x0
fmv.w.x f30,x0
fmv.w.x f31,x0
.option push
.option norelax
la gp, __global_pointer$
.option pop
la tp, _end + 63
and tp, tp, -64
csrr a0, mhartid
add sp, a0, 1
sll sp, sp, STKSHIFT
add sp, sp, tp
j _init_bsp
.globl trap_entry
.type trap_entry, @function
.align 2
trap_entry:
addi sp, sp, -REGBYTES
sd t0, 0x0(sp)
csrr t0, mcause
bgez t0, .handle_other
# Test soft interrupt
slli t0, t0, 1
addi t0, t0, -(IRQ_M_SOFT << 1)
bnez t0, .handle_other
# Interupt is soft interrupt
# Get event
addi sp, sp, -REGBYTES
sd t1, 0x0(sp)
la t0, g_core_pending_switch
csrr t1, mhartid
slli t1, t1, 3
add t0, t0, t1
ld t1, 0x0(sp)
addi sp, sp, REGBYTES
# Test ContextSwitch event
ld t0, 0x0(t0)
beqz t0, .handle_other
ld t0, 0x0(sp)
addi sp, sp, REGBYTES
# Do not use jal here
j xPortSysTickInt
mret
.handle_other:
ld t0, 0x0(sp)
addi sp, sp, REGBYTES
addi sp, sp, -64*REGBYTES
SREG x1, 1*REGBYTES(sp)
SREG x2, 2*REGBYTES(sp)
SREG x3, 3*REGBYTES(sp)
SREG x4, 4*REGBYTES(sp)
SREG x5, 5*REGBYTES(sp)
SREG x6, 6*REGBYTES(sp)
SREG x7, 7*REGBYTES(sp)
SREG x8, 8*REGBYTES(sp)
SREG x9, 9*REGBYTES(sp)
SREG x10, 10*REGBYTES(sp)
SREG x11, 11*REGBYTES(sp)
SREG x12, 12*REGBYTES(sp)
SREG x13, 13*REGBYTES(sp)
SREG x14, 14*REGBYTES(sp)
SREG x15, 15*REGBYTES(sp)
SREG x16, 16*REGBYTES(sp)
SREG x17, 17*REGBYTES(sp)
SREG x18, 18*REGBYTES(sp)
SREG x19, 19*REGBYTES(sp)
SREG x20, 20*REGBYTES(sp)
SREG x21, 21*REGBYTES(sp)
SREG x22, 22*REGBYTES(sp)
SREG x23, 23*REGBYTES(sp)
SREG x24, 24*REGBYTES(sp)
SREG x25, 25*REGBYTES(sp)
SREG x26, 26*REGBYTES(sp)
SREG x27, 27*REGBYTES(sp)
SREG x28, 28*REGBYTES(sp)
SREG x29, 29*REGBYTES(sp)
SREG x30, 30*REGBYTES(sp)
SREG x31, 31*REGBYTES(sp)
SFREG f0, ( 0 + 32)*REGBYTES(sp)
SFREG f1, ( 1 + 32)*REGBYTES(sp)
SFREG f2, ( 2 + 32)*REGBYTES(sp)
SFREG f3, ( 3 + 32)*REGBYTES(sp)
SFREG f4, ( 4 + 32)*REGBYTES(sp)
SFREG f5, ( 5 + 32)*REGBYTES(sp)
SFREG f6, ( 6 + 32)*REGBYTES(sp)
SFREG f7, ( 7 + 32)*REGBYTES(sp)
SFREG f8, ( 8 + 32)*REGBYTES(sp)
SFREG f9, ( 9 + 32)*REGBYTES(sp)
SFREG f10,( 10 + 32)*REGBYTES(sp)
SFREG f11,( 11 + 32)*REGBYTES(sp)
SFREG f12,( 12 + 32)*REGBYTES(sp)
SFREG f13,( 13 + 32)*REGBYTES(sp)
SFREG f14,( 14 + 32)*REGBYTES(sp)
SFREG f15,( 15 + 32)*REGBYTES(sp)
SFREG f16,( 16 + 32)*REGBYTES(sp)
SFREG f17,( 17 + 32)*REGBYTES(sp)
SFREG f18,( 18 + 32)*REGBYTES(sp)
SFREG f19,( 19 + 32)*REGBYTES(sp)
SFREG f20,( 20 + 32)*REGBYTES(sp)
SFREG f21,( 21 + 32)*REGBYTES(sp)
SFREG f22,( 22 + 32)*REGBYTES(sp)
SFREG f23,( 23 + 32)*REGBYTES(sp)
SFREG f24,( 24 + 32)*REGBYTES(sp)
SFREG f25,( 25 + 32)*REGBYTES(sp)
SFREG f26,( 26 + 32)*REGBYTES(sp)
SFREG f27,( 27 + 32)*REGBYTES(sp)
SFREG f28,( 28 + 32)*REGBYTES(sp)
SFREG f29,( 29 + 32)*REGBYTES(sp)
SFREG f30,( 30 + 32)*REGBYTES(sp)
SFREG f31,( 31 + 32)*REGBYTES(sp)
csrr a0, mcause
csrr a1, mepc
mv a2, sp
add a3, sp, 32*REGBYTES
bgez a0, .handle_syscall
.handle_irq:
jal handle_irq
j .restore
.handle_syscall:
jal handle_syscall
.restore:
csrw mepc, a0
LREG x1, 1*REGBYTES(sp)
LREG x2, 2*REGBYTES(sp)
LREG x3, 3*REGBYTES(sp)
LREG x4, 4*REGBYTES(sp)
LREG x5, 5*REGBYTES(sp)
LREG x6, 6*REGBYTES(sp)
LREG x7, 7*REGBYTES(sp)
LREG x8, 8*REGBYTES(sp)
LREG x9, 9*REGBYTES(sp)
LREG x10, 10*REGBYTES(sp)
LREG x11, 11*REGBYTES(sp)
LREG x12, 12*REGBYTES(sp)
LREG x13, 13*REGBYTES(sp)
LREG x14, 14*REGBYTES(sp)
LREG x15, 15*REGBYTES(sp)
LREG x16, 16*REGBYTES(sp)
LREG x17, 17*REGBYTES(sp)
LREG x18, 18*REGBYTES(sp)
LREG x19, 19*REGBYTES(sp)
LREG x20, 20*REGBYTES(sp)
LREG x21, 21*REGBYTES(sp)
LREG x22, 22*REGBYTES(sp)
LREG x23, 23*REGBYTES(sp)
LREG x24, 24*REGBYTES(sp)
LREG x25, 25*REGBYTES(sp)
LREG x26, 26*REGBYTES(sp)
LREG x27, 27*REGBYTES(sp)
LREG x28, 28*REGBYTES(sp)
LREG x29, 29*REGBYTES(sp)
LREG x30, 30*REGBYTES(sp)
LREG x31, 31*REGBYTES(sp)
LFREG f0, ( 0 + 32)*REGBYTES(sp)
LFREG f1, ( 1 + 32)*REGBYTES(sp)
LFREG f2, ( 2 + 32)*REGBYTES(sp)
LFREG f3, ( 3 + 32)*REGBYTES(sp)
LFREG f4, ( 4 + 32)*REGBYTES(sp)
LFREG f5, ( 5 + 32)*REGBYTES(sp)
LFREG f6, ( 6 + 32)*REGBYTES(sp)
LFREG f7, ( 7 + 32)*REGBYTES(sp)
LFREG f8, ( 8 + 32)*REGBYTES(sp)
LFREG f9, ( 9 + 32)*REGBYTES(sp)
LFREG f10,( 10 + 32)*REGBYTES(sp)
LFREG f11,( 11 + 32)*REGBYTES(sp)
LFREG f12,( 12 + 32)*REGBYTES(sp)
LFREG f13,( 13 + 32)*REGBYTES(sp)
LFREG f14,( 14 + 32)*REGBYTES(sp)
LFREG f15,( 15 + 32)*REGBYTES(sp)
LFREG f16,( 16 + 32)*REGBYTES(sp)
LFREG f17,( 17 + 32)*REGBYTES(sp)
LFREG f18,( 18 + 32)*REGBYTES(sp)
LFREG f19,( 19 + 32)*REGBYTES(sp)
LFREG f20,( 20 + 32)*REGBYTES(sp)
LFREG f21,( 21 + 32)*REGBYTES(sp)
LFREG f22,( 22 + 32)*REGBYTES(sp)
LFREG f23,( 23 + 32)*REGBYTES(sp)
LFREG f24,( 24 + 32)*REGBYTES(sp)
LFREG f25,( 25 + 32)*REGBYTES(sp)
LFREG f26,( 26 + 32)*REGBYTES(sp)
LFREG f27,( 27 + 32)*REGBYTES(sp)
LFREG f28,( 28 + 32)*REGBYTES(sp)
LFREG f29,( 29 + 32)*REGBYTES(sp)
LFREG f30,( 30 + 32)*REGBYTES(sp)
LFREG f31,( 31 + 32)*REGBYTES(sp)
addi sp, sp, 64*REGBYTES
mret
.section ".tdata.begin"
.globl _tdata_begin
_tdata_begin:
.section ".tdata.end"
.globl _tdata_end
_tdata_end:
.section ".tbss.end"
.globl _tbss_end
_tbss_end:
/* Copyright 2018 Canaan Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "entry.h"
/**
* @brief Dummy function for __libc_init_array called
*/
void __attribute__((weak)) _init(void)
{
/**
* These don't have to do anything since we use init_array/fini_array.
*/
}
/**
* @brief Dummy function for __libc_fini_array called
*/
void __attribute__((weak)) _fini(void)
{
/**
* These don't have to do anything since we use init_array/fini_array.
*/
}
/* Copyright 2018 Canaan Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <stdlib.h>
#include "atomic.h"
#include "clint.h"
#include "dmac.h"
#include "entry.h"
#include "fpioa.h"
#include "platform.h"
#include "plic.h"
#include "sysctl.h"
#include "syslog.h"
#include "uart.h"
#include "syscalls.h"
extern volatile uint64_t g_wake_up[2];
core_instance_t core1_instance;
volatile char * const ram = (volatile char*)RAM_BASE_ADDR;
extern char _heap_start[];
extern char _heap_end[];
void thread_entry(int core_id)
{
while (!atomic_read(&g_wake_up[core_id]));
}
void core_enable(int core_id)
{
clint_ipi_send(core_id);
atomic_set(&g_wake_up[core_id], 1);
}
int register_core1(core_function func, void *ctx)
{
if(func == NULL)
return -1;
core1_instance.callback = func;
core1_instance.ctx = ctx;
core_enable(1);
return 0;
}
int __attribute__((weak)) os_entry(int core_id, int number_of_cores, int (*user_main)(int, char**))
{
/* Call main if there is no OS */
return user_main(0, 0);
}
void _init_bsp(int core_id, int number_of_cores)
{
extern int main(int argc, char* argv[]);
extern void __libc_init_array(void);
extern void __libc_fini_array(void);
if (core_id == 0)
{
/* Initialize bss data to 0 */
init_bss();
/* Init UART */
uart_init(UART_DEVICE_3);
uart_configure(UART_DEVICE_3, 115200, 8, UART_STOP_1, UART_PARITY_NONE);
fpioa_set_function(4, FUNC_UART3_RX);
fpioa_set_function(5, FUNC_UART3_TX);
sys_register_getchar(uart3_getchar);
sys_register_putchar(uart3_putchar);
/* Init FPIOA */
fpioa_init();
/* Register finalization function */
atexit(__libc_fini_array);
/* Init libc array for C++ */
__libc_init_array();
/* Get reset status */
sysctl_get_reset_status();
/* Init plic */
plic_init();
/* Enable global interrupt */
sysctl_enable_irq();
}
int ret = 0;
if (core_id == 0)
{
core1_instance.callback = NULL;
core1_instance.ctx = NULL;
ret = os_entry(core_id, number_of_cores, main);
}
else
{
plic_init();
sysctl_enable_irq();
thread_entry(core_id);
if(core1_instance.callback == NULL)
asm volatile ("wfi");
else
ret = core1_instance.callback(core1_instance.ctx);
}
exit(ret);
}
/* Copyright 2018 Canaan Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef _BSP_ATOMIC_H
#define _BSP_ATOMIC_H
#ifdef __cplusplus
extern "C" {
#endif
#define SPINLOCK_INIT \
{ \
0 \
}
#define CORELOCK_INIT \
{ \
.lock = SPINLOCK_INIT, \
.count = 0, \
.core = -1 \
}
/* Defination of memory barrier macro */
#define mb() \
{ \
asm volatile("fence" :: \
: "memory"); \
}
#define atomic_set(ptr, val) (*(volatile typeof(*(ptr))*)(ptr) = val)
#define atomic_read(ptr) (*(volatile typeof(*(ptr))*)(ptr))
#ifndef __riscv_atomic
#error "atomic extension is required."
#endif
#define atomic_add(ptr, inc) __sync_fetch_and_add(ptr, inc)
#define atomic_or(ptr, inc) __sync_fetch_and_or(ptr, inc)
#define atomic_swap(ptr, swp) __sync_lock_test_and_set(ptr, swp)
#define atomic_cas(ptr, cmp, swp) __sync_val_compare_and_swap(ptr, cmp, swp)
typedef struct _spinlock
{
int lock;
} spinlock_t;
typedef struct _semaphore
{
spinlock_t lock;
int count;
int waiting;
} semaphore_t;
typedef struct _corelock
{
spinlock_t lock;
int count;
int core;
} corelock_t;
static inline int spinlock_trylock(spinlock_t *lock)
{
int res = atomic_swap(&lock->lock, -1);
/* Use memory barrier to keep coherency */
mb();
return res;
}
static inline void spinlock_lock(spinlock_t *lock)
{
while (spinlock_trylock(lock));
}
static inline void spinlock_unlock(spinlock_t *lock)
{
/* Use memory barrier to keep coherency */
mb();
atomic_set(&lock->lock, 0);
asm volatile ("nop");
}
static inline void semaphore_signal(semaphore_t *semaphore, int i)
{
spinlock_lock(&(semaphore->lock));
semaphore->count += i;
spinlock_unlock(&(semaphore->lock));
}
static inline void semaphore_wait(semaphore_t *semaphore, int i)
{
atomic_add(&(semaphore->waiting), 1);
while (1)
{
spinlock_lock(&(semaphore->lock));
if (semaphore->count >= i)
{
semaphore->count -= i;
atomic_add(&(semaphore->waiting), -1);
spinlock_unlock(&(semaphore->lock));
break;
}
spinlock_unlock(&(semaphore->lock));
}
}
static inline int semaphore_count(semaphore_t *semaphore)
{
int res = 0;
spinlock_lock(&(semaphore->lock));
res = semaphore->count;
spinlock_unlock(&(semaphore->lock));
return res;
}
static inline int semaphore_waiting(semaphore_t *semaphore)
{
return atomic_read(&(semaphore->waiting));
}
static inline int corelock_trylock(corelock_t *lock)
{
int res = 0;
unsigned long core;
asm volatile("csrr %0, mhartid;"
: "=r"(core));
if(spinlock_trylock(&lock->lock))
{
return -1;
}
if (lock->count == 0)
{
/* First time get lock */
lock->count++;
lock->core = core;
res = 0;
}
else if (lock->core == core)
{
/* Same core get lock */
lock->count++;
res = 0;
}
else
{
/* Different core get lock */
res = -1;
}
spinlock_unlock(&lock->lock);
return res;
}
static inline void corelock_lock(corelock_t *lock)
{
unsigned long core;
asm volatile("csrr %0, mhartid;"
: "=r"(core));
spinlock_lock(&lock->lock);
if (lock->count == 0)
{
/* First time get lock */
lock->count++;
lock->core = core;
}
else if (lock->core == core)
{
/* Same core get lock */
lock->count++;
}
else
{
/* Different core get lock */
spinlock_unlock(&lock->lock);
do
{
while (atomic_read(&lock->count))
;
} while (corelock_trylock(lock));
return;
}
spinlock_unlock(&lock->lock);
}
static inline void corelock_unlock(corelock_t *lock)
{
unsigned long core;
asm volatile("csrr %0, mhartid;"
: "=r"(core));
spinlock_lock(&lock->lock);
if (lock->core == core)
{
/* Same core release lock */
lock->count--;
if (lock->count <= 0)
{
lock->core = -1;
lock->count = 0;
}
}
else
{
/* Different core release lock */
spinlock_unlock(&lock->lock);
register unsigned long a7 asm("a7") = 93;
register unsigned long a0 asm("a0") = 0;
register unsigned long a1 asm("a1") = 0;
register unsigned long a2 asm("a2") = 0;
asm volatile("scall"
: "+r"(a0)
: "r"(a1), "r"(a2), "r"(a7));
}
spinlock_unlock(&lock->lock);
}
#ifdef __cplusplus
}
#endif
#endif /* _BSP_ATOMIC_H */
#ifndef _KENDRYTE_BSP_H
#define _KENDRYTE_BSP_H
#include "atomic.h"
#include "entry.h"
#include "sleep.h"
#include "encoding.h"
#endif
\ No newline at end of file
/* Copyright 2018 Canaan Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef _BSP_DUMP_H
#define _BSP_DUMP_H
#include <stdlib.h>
#include <string.h>
#include "syslog.h"
#include "uarths.h"
#ifdef __cplusplus
extern "C" {
#endif
#define DUMP_PRINTF printk
static inline void
dump_core(const char *reason, uintptr_t cause, uintptr_t epc, uintptr_t regs[32], uintptr_t fregs[32])
{
static const char *const reg_usage[][2] =
{
{"zero ", "Hard-wired zero"},
{"ra ", "Return address"},
{"sp ", "Stack pointer"},
{"gp ", "Global pointer"},
{"tp ", "Thread pointer"},
{"t0 ", "Temporaries Caller"},
{"t1 ", "Temporaries Caller"},
{"t2 ", "Temporaries Caller"},
{"s0/fp", "Saved register/frame pointer"},
{"s1 ", "Saved register"},
{"a0 ", "Function arguments/return values"},
{"a1 ", "Function arguments/return values"},
{"a2 ", "Function arguments values"},
{"a3 ", "Function arguments values"},
{"a4 ", "Function arguments values"},
{"a5 ", "Function arguments values"},
{"a6 ", "Function arguments values"},
{"a7 ", "Function arguments values"},
{"s2 ", "Saved registers"},
{"s3 ", "Saved registers"},
{"s4 ", "Saved registers"},
{"s5 ", "Saved registers"},
{"s6 ", "Saved registers"},
{"s7 ", "Saved registers"},
{"s8 ", "Saved registers"},
{"s9 ", "Saved registers"},
{"s10 ", "Saved registers"},
{"s11 ", "Saved registers"},
{"t3 ", "Temporaries Caller"},
{"t4 ", "Temporaries Caller"},
{"t5 ", "Temporaries Caller"},
{"t6 ", "Temporaries Caller"},
};
static const char *const regf_usage[][2] =
{
{"ft0 ", "FP temporaries"},
{"ft1 ", "FP temporaries"},
{"ft2 ", "FP temporaries"},
{"ft3 ", "FP temporaries"},
{"ft4 ", "FP temporaries"},
{"ft5 ", "FP temporaries"},
{"ft6 ", "FP temporaries"},
{"ft7 ", "FP temporaries"},
{"fs0 ", "FP saved registers"},
{"fs1 ", "FP saved registers"},
{"fa0 ", "FP arguments/return values"},
{"fa1 ", "FP arguments/return values"},
{"fa2 ", "FP arguments values"},
{"fa3 ", "FP arguments values"},
{"fa4 ", "FP arguments values"},
{"fa5 ", "FP arguments values"},
{"fa6 ", "FP arguments values"},
{"fa7 ", "FP arguments values"},
{"fs2 ", "FP Saved registers"},
{"fs3 ", "FP Saved registers"},
{"fs4 ", "FP Saved registers"},
{"fs5 ", "FP Saved registers"},
{"fs6 ", "FP Saved registers"},
{"fs7 ", "FP Saved registers"},
{"fs8 ", "FP Saved registers"},
{"fs9 ", "FP Saved registers"},
{"fs10", "FP Saved registers"},
{"fs11", "FP Saved registers"},
{"ft8 ", "FP Temporaries Caller"},
{"ft9 ", "FP Temporaries Caller"},
{"ft10", "FP Temporaries Caller"},
{"ft11", "FP Temporaries Caller"},
};
if (CONFIG_LOG_LEVEL >= LOG_ERROR)
{
const char unknown_reason[] = "unknown";
if (!reason)
reason = unknown_reason;
DUMP_PRINTF("core dump: %s\r\n", reason);
DUMP_PRINTF("Cause 0x%016lx, EPC 0x%016lx\r\n", cause, epc);
int i = 0;
for (i = 0; i < 32 / 2; i++)
{
DUMP_PRINTF(
"reg[%02d](%s) = 0x%016lx, reg[%02d](%s) = 0x%016lx\r\n",
i * 2, reg_usage[i * 2][0], regs[i * 2],
i * 2 + 1, reg_usage[i * 2 + 1][0], regs[i * 2 + 1]);
}
for (i = 0; i < 32 / 2; i++)
{
DUMP_PRINTF(
"freg[%02d](%s) = 0x%016lx(%f), freg[%02d](%s) = 0x%016lx(%f)\r\n",
i * 2, regf_usage[i * 2][0], fregs[i * 2], (float)fregs[i * 2],
i * 2 + 1, regf_usage[i * 2 + 1][0], fregs[i * 2 + 1], (float)fregs[i * 2 + 1]);
}
}
}
#undef DUMP_PRINTF
#ifdef __cplusplus
}
#endif
#endif /* _BSP_DUMP_H */
/* Copyright 2018 Canaan Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef _BSP_ENTRY_H
#define _BSP_ENTRY_H
#include <stdlib.h>
#include <string.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef int (*core_function)(void *ctx);
typedef struct _core_instance_t
{
core_function callback;
void *ctx;
} core_instance_t;
int register_core1(core_function func, void *ctx);
static inline void init_lma(void)
{
extern unsigned int _data_lma;
extern unsigned int _data;
extern unsigned int _edata;
unsigned int *src, *dst;
src = &_data_lma;
dst = &_data;
while (dst < &_edata)
*dst++ = *src++;
}
static inline void init_bss(void)
{
extern unsigned int _bss;
extern unsigned int _ebss;
unsigned int *dst;
dst = &_bss;
while (dst < &_ebss)
*dst++ = 0;
}
static inline void init_tls(void)
{
register void *thread_pointer asm("tp");
extern char _tls_data;
extern __thread char _tdata_begin, _tdata_end, _tbss_end;
size_t tdata_size = &_tdata_end - &_tdata_begin;
memcpy(thread_pointer, &_tls_data, tdata_size);
size_t tbss_size = &_tbss_end - &_tdata_end;
memset(thread_pointer + tdata_size, 0, tbss_size);
}
#ifdef __cplusplus
}
#endif
#endif /* _BSP_ENTRY_H */
/* Copyright 2018 Canaan Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef _BSP_INTERRUPT_H
#define _BSP_INTERRUPT_H
#ifdef __cplusplus
extern "C" {
#endif
/* clang-format off */
/* Machine interrupt mask for 64 bit system, 0x8000 0000 0000 0000 */
#define CAUSE_MACHINE_IRQ_MASK (0x1ULL << 63)
/* Machine interrupt reason mask for 64 bit system, 0x7FFF FFFF FFFF FFFF */
#define CAUSE_MACHINE_IRQ_REASON_MASK (CAUSE_MACHINE_IRQ_MASK - 1)
/* Hypervisor interrupt mask for 64 bit system, 0x8000 0000 0000 0000 */
#define CAUSE_HYPERVISOR_IRQ_MASK (0x1ULL << 63)
/* Hypervisor interrupt reason mask for 64 bit system, 0x7FFF FFFF FFFF FFFF */
#define CAUSE_HYPERVISOR_IRQ_REASON_MASK (CAUSE_HYPERVISOR_IRQ_MASK - 1)
/* Supervisor interrupt mask for 64 bit system, 0x8000 0000 0000 0000 */
#define CAUSE_SUPERVISOR_IRQ_MASK (0x1ULL << 63)
/* Supervisor interrupt reason mask for 64 bit system, 0x7FFF FFFF FFFF FFFF */
#define CAUSE_SUPERVISOR_IRQ_REASON_MASK (CAUSE_SUPERVISOR_IRQ_MASK - 1)
/* clang-format on */
#ifdef __cplusplus
}
#endif
#endif /* _BSP_INTERRUPT_H */
/* Copyright 2018 Canaan Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef _BSP_PLATFORM_H
#define _BSP_PLATFORM_H
#ifdef __cplusplus
extern "C" {
#endif
/* clang-format off */
/* Register base address */
/* Under Coreplex */
#define CLINT_BASE_ADDR (0x02000000U)
#define PLIC_BASE_ADDR (0x0C000000U)
/* Under TileLink */
#define UARTHS_BASE_ADDR (0x38000000U)
#define GPIOHS_BASE_ADDR (0x38001000U)
/* Under AXI 64 bit */
#define RAM_BASE_ADDR (0x80000000U)
#define RAM_SIZE (6 * 1024 * 1024U)
#define IO_BASE_ADDR (0x40000000U)
#define IO_SIZE (6 * 1024 * 1024U)
#define AI_RAM_BASE_ADDR (0x80600000U)
#define AI_RAM_SIZE (2 * 1024 * 1024U)
#define AI_IO_BASE_ADDR (0x40600000U)
#define AI_IO_SIZE (2 * 1024 * 1024U)
#define AI_BASE_ADDR (0x40800000U)
#define AI_SIZE (12 * 1024 * 1024U)
#define FFT_BASE_ADDR (0x42000000U)
#define FFT_SIZE (4 * 1024 * 1024U)
#define ROM_BASE_ADDR (0x88000000U)
#define ROM_SIZE (128 * 1024U)
/* Under AHB 32 bit */
#define DMAC_BASE_ADDR (0x50000000U)
/* Under APB1 32 bit */
#define GPIO_BASE_ADDR (0x50200000U)
#define UART1_BASE_ADDR (0x50210000U)
#define UART2_BASE_ADDR (0x50220000U)
#define UART3_BASE_ADDR (0x50230000U)
#define SPI_SLAVE_BASE_ADDR (0x50240000U)
#define I2S0_BASE_ADDR (0x50250000U)
#define I2S1_BASE_ADDR (0x50260000U)
#define I2S2_BASE_ADDR (0x50270000U)
#define I2C0_BASE_ADDR (0x50280000U)
#define I2C1_BASE_ADDR (0x50290000U)
#define I2C2_BASE_ADDR (0x502A0000U)
#define FPIOA_BASE_ADDR (0x502B0000U)
#define SHA256_BASE_ADDR (0x502C0000U)
#define TIMER0_BASE_ADDR (0x502D0000U)
#define TIMER1_BASE_ADDR (0x502E0000U)
#define TIMER2_BASE_ADDR (0x502F0000U)
/* Under APB2 32 bit */
#define WDT0_BASE_ADDR (0x50400000U)
#define WDT1_BASE_ADDR (0x50410000U)
#define OTP_BASE_ADDR (0x50420000U)
#define DVP_BASE_ADDR (0x50430000U)
#define SYSCTL_BASE_ADDR (0x50440000U)
#define AES_BASE_ADDR (0x50450000U)
#define RTC_BASE_ADDR (0x50460000U)
/* Under APB3 32 bit */
#define SPI0_BASE_ADDR (0x52000000U)
#define SPI1_BASE_ADDR (0x53000000U)
#define SPI3_BASE_ADDR (0x54000000U)
/* clang-format on */
#ifdef __cplusplus
}
#endif
#endif /* _BSP_PLATFORM_H */
/* Copyright 2018 Canaan Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef _BSP_SLEEP_H
#define _BSP_SLEEP_H
#include "encoding.h"
#include "clint.h"
#include "syscalls.h"
#ifdef __cplusplus
extern "C" {
#endif
int usleep(uint64_t usec);
int msleep(uint64_t msec);
unsigned int sleep(unsigned int seconds);
#ifdef __cplusplus
}
#endif
#endif /* _BSP_SLEEP_H */
/* Copyright 2018 Canaan Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef _BSP_SYSCALLS_H
#define _BSP_SYSCALLS_H
#include <machine/syscall.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Definitions for syscall putchar function
*
* @param[in] c The char to put
*
* @return result
* - Byte On success, returns the written character.
* - EOF On failure, returns EOF and sets the error indicator (see ferror()) on stdout.
*/
typedef int (*sys_putchar_t)(char c);
/**
* @brief Definitions for syscall getchar function
*
* @return byte as int type to get
* - Byte The character read as an unsigned char cast to an int
* - EOF EOF on end of file or error, no enough byte to read
*/
typedef int (*sys_getchar_t)(void);
/**
* @brief Register putchar function when perform write syscall
*
* @param[in] putchar The user-defined putchar function
*
* @return None
*/
void sys_register_putchar(sys_putchar_t putchar);
/**
* @brief Register getchar function when perform read syscall
*
* @param[in] getchar The user-defined getchar function
*
* @return None
*/
void sys_register_getchar(sys_getchar_t getchar);
void __attribute__((noreturn)) sys_exit(int code);
void setStats(int enable);
#undef putchar
int putchar(int ch);
void printstr(const char *s);
void printhex(uint64_t x);
size_t get_free_heap_size(void);
#ifdef __cplusplus
}
#endif
#endif /* _BSP_SYSCALLS_H */
/* Copyright 2018 Canaan Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "stdio.h"
#include "sysctl.h"
#include "uarths.h"
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment