mirror of
https://github.com/openharmony/kernel_uniproton.git
synced 2026-07-01 04:19:55 -04:00
!32 Description: kernel_uniproton版本升级
Merge pull request !32 from hw_llm/master
This commit is contained in:
@@ -17,6 +17,8 @@ set(LIB_RUN_TYPE "$ENV{LIB_RUN_TYPE}" )
|
||||
set(HOME_PATH "$ENV{HOME_PATH}" )
|
||||
set(BUILD_MACHINE_PLATFORM "$ENV{BUILD_MACHINE_PLATFORM}" )
|
||||
set(RPROTON_BINARY_DIR "$ENV{RPROTON_BINARY_DIR}" )
|
||||
#用于保存所有的对象库
|
||||
set(ALL_OBJECT_LIBRARYS "" CACHE STRING INTERNAL)
|
||||
|
||||
if("${RPROTON_BINARY_DIR}" STREQUAL "")
|
||||
# this branch will be taken
|
||||
@@ -75,6 +77,18 @@ include_directories(
|
||||
./platform/libboundscheck/include
|
||||
)
|
||||
|
||||
if (${CONFIG_OS_OPTION_POSIX})
|
||||
include_directories(
|
||||
./src/osal/posix/include
|
||||
./src/include/posix
|
||||
)
|
||||
endif()
|
||||
|
||||
if (${CONFIG_OS_OPTION_OPENAMP})
|
||||
include_directories(
|
||||
./thirdpart/openamp
|
||||
)
|
||||
endif()
|
||||
|
||||
if (NOT ${COMPILE_OPTION} STREQUAL "UniProton")
|
||||
###添加安全库的cmakelists
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@
|
||||
"Name" : "uniproton",
|
||||
"License" : "MulanPSL-2.0",
|
||||
"License File" : "LICENSE",
|
||||
"Version Number" : "1.0.0",
|
||||
"Version Number" : "1.0.1",
|
||||
"Owner" : "zhushengle@huawei.com",
|
||||
"Upstream URL" : "https://gitee.com/openeuler/UniProton",
|
||||
"Description" : "Uniproton is a highly real-time kernel implementation of the MulanPSL-2.0 license"
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
# UniProton介绍
|
||||
|
||||
UniProton主要目的在于为上层业务软件提供一个统一的操作系统平台,屏蔽底层硬件差异,并提供强大的调试功能。使得业务软件可在不同的硬件平台之间快速移植,方便产品芯片选型,降低硬件采购成本和软件维护成本。
|
||||
UniProton是一款实时操作系统,具备极致的低时延和灵活的混合关键性部署特性,可以适用于工业控制场景,既支持微控制器MCU,也支持算力强的多核CPU。
|
||||
|
||||
## 功能介绍
|
||||
|
||||
- 任务
|
||||
- 中断
|
||||
- 事件
|
||||
- 队列
|
||||
- 信号量
|
||||
- 内存管理
|
||||
- 软件定时器
|
||||
- 异常
|
||||
- 错误处理
|
||||
- cpu占用率
|
||||
- [任务](./doc/design/task.md)
|
||||
- [中断](./doc/design/hwi.md)
|
||||
- [事件](./doc/design/event.md)
|
||||
- [队列](./doc/design/queue.md)
|
||||
- [信号量](./doc/design/sem.md)
|
||||
- [内存管理](./doc/design/mem.md)
|
||||
- [软件定时器](./doc/design/timer.md)
|
||||
- [异常](./doc/design/exc.md)
|
||||
- [错误处理](./doc/design/err.md)
|
||||
- [cpu占用率](./doc/design/cpup.md)
|
||||
|
||||
注: UniProton基础内核机制请参考[官方介绍](https://gitee.com/openeuler/UniProton)。
|
||||
|
||||
@@ -53,7 +53,7 @@ alientek
|
||||
|
||||
## 约束
|
||||
|
||||
- 当前开源版本仅支持cortex_m4芯片,默认编译脚本的安全编译选项仅支持栈保护,其他选项由用户根据需要自行添加。
|
||||
- 当前开源版本支持cortex_m4和armv8芯片,默认编译脚本的安全编译选项仅支持栈保护,其他选项由用户根据需要自行添加。
|
||||
|
||||
- 遵循MulanPSL2开源许可协议。
|
||||
|
||||
|
||||
@@ -25,10 +25,14 @@ home_path = os.path.dirname(build_dir)
|
||||
config_dir = os.path.join(home_path,'config.xml')
|
||||
kbuild_path = '%s/cmake/common/build_auxiliary_script' % home_path
|
||||
|
||||
cpus_ = {'all': ['clean', 'm4'],
|
||||
cpus_ = {'all': ['clean', 'm4', 'raspi4', 'hi3093'],
|
||||
'clean':['clean'],
|
||||
'm4': ['m4']
|
||||
'm4': ['m4'],
|
||||
'raspi4': ['raspi4'],
|
||||
'hi3093': ['hi3093'],
|
||||
}
|
||||
|
||||
cpu_plat = {'m4': ['cortex']
|
||||
cpu_plat = {'m4': ['cortex'],
|
||||
'raspi4': ['armv8'],
|
||||
'hi3093': ['armv8'],
|
||||
}
|
||||
|
||||
@@ -0,0 +1,133 @@
|
||||
#
|
||||
# Automatically generated file; DO NOT EDIT.
|
||||
# UniProton Configuration
|
||||
#
|
||||
|
||||
#
|
||||
# Arch Modules Configuration
|
||||
#
|
||||
CONFIG_OS_ARCH_ARMV8=y
|
||||
# CONFIG_OS_OPTION_GUARD_STACK is not set
|
||||
|
||||
#
|
||||
# ARMV8 Sepecfic Configuration
|
||||
#
|
||||
CONFIG_INTERNAL_OS_PLATFORM_ARMV8_AX=y
|
||||
CONFIG_INTERNAL_OS_HI3093=y
|
||||
|
||||
#
|
||||
# ARMV8 DRV Features Configuration
|
||||
#
|
||||
CONFIG_INTERNAL_OS_GIC_VER="gicv600"
|
||||
CONFIG_OS_GIC_VER=3
|
||||
|
||||
#
|
||||
# Generic Configuration
|
||||
#
|
||||
CONFIG_OS_HARDWARE_PLATFORM="OS_ARMV8"
|
||||
CONFIG_OS_CPU_TYPE="OS_HI3093"
|
||||
CONFIG_OS_MAX_CORE_NUM=4
|
||||
CONFIG_OS_THIS_CORE=3
|
||||
CONFIG_INTERNAL_OS_BYTE_ORDER_LE=y
|
||||
CONFIG_OS_BYTE_ORDER="OS_LITTLE_ENDIAN"
|
||||
# CONFIG_OS_OPTION_DCACHE is not set
|
||||
CONFIG_OS_CACHE_LINE_SIZE=64
|
||||
|
||||
#
|
||||
# Core Modules Configuration
|
||||
#
|
||||
|
||||
#
|
||||
# IPC Modules Configuration
|
||||
#
|
||||
|
||||
#
|
||||
# Event feature configuration
|
||||
#
|
||||
CONFIG_OS_OPTION_EVENT=y
|
||||
CONFIG_OS_OPTION_QUEUE=y
|
||||
|
||||
#
|
||||
# Semaphore feature configuration
|
||||
#
|
||||
|
||||
#
|
||||
# Kernel Modules Configuration
|
||||
#
|
||||
|
||||
#
|
||||
# IRQ Modules Configuration
|
||||
#
|
||||
# CONFIG_OS_OPTION_HWI_COMBINE is not set
|
||||
CONFIG_OS_OPTION_HWI_PRIORITY=y
|
||||
CONFIG_OS_OPTION_HWI_ATTRIBUTE=y
|
||||
# CONFIG_OS_OPTION_HWI_MAX_NUM_CONFIG is not set
|
||||
|
||||
#
|
||||
# Exc Modules Configuration
|
||||
CONFIG_INTERNAL_OS_SCHEDULE_SINGLE_CORE_BY_CCODE=y
|
||||
CONFIG_OS_OPTION_SYS_TIME_USR=y
|
||||
#
|
||||
|
||||
#
|
||||
# Task module Configuration
|
||||
#
|
||||
CONFIG_OS_OPTION_TASK=y
|
||||
|
||||
#
|
||||
# TASK features configuration
|
||||
#
|
||||
# CONFIG_OS_OPTION_TASK_MON is not set
|
||||
CONFIG_OS_OPTION_TASK_DELETE=y
|
||||
CONFIG_OS_OPTION_TASK_SUSPEND=y
|
||||
CONFIG_OS_OPTION_TASK_INFO=y
|
||||
CONFIG_OS_OPTION_TASK_YIELD=y
|
||||
CONFIG_OS_TSK_PRIORITY_HIGHEST=0
|
||||
CONFIG_OS_TSK_PRIORITY_LOWEST=63
|
||||
CONFIG_OS_TSK_NUM_OF_PRIORITIES=64
|
||||
CONFIG_OS_TSK_CORE_BYTES_IN_PID=2
|
||||
CONFIG_OS_OPTION_TICK=y
|
||||
|
||||
#
|
||||
# Timer Modules Configuration
|
||||
#
|
||||
CONFIG_INTERNAL_OS_SWTMR=y
|
||||
|
||||
#
|
||||
# MM Modules Configuration
|
||||
#
|
||||
|
||||
#
|
||||
# OM Modules Configuration
|
||||
#
|
||||
# CONFIG_OS_OPTION_CPUP is not set
|
||||
|
||||
#
|
||||
# CPUP features configuration
|
||||
#
|
||||
CONFIG_INTERNAL_OS_CPUP_THREAD=y
|
||||
CONFIG_OS_OPTION_CPUP_WARN=y
|
||||
|
||||
#
|
||||
# Error Report Module Configuration
|
||||
#
|
||||
|
||||
#
|
||||
# Hook feature configuration
|
||||
#
|
||||
|
||||
#
|
||||
# security Modules Configuration
|
||||
#
|
||||
CONFIG_OS_OPTION_RND=y
|
||||
|
||||
#
|
||||
# Utility Modules Configuration
|
||||
#
|
||||
CONFIG_OS_OPTION_POSIX=y
|
||||
CONFIG_OS_POSIX_TYPE_NEWLIB=y
|
||||
|
||||
#
|
||||
# Openamp Modules Configuration
|
||||
#
|
||||
CONFIG_OS_OPTION_OPENAMP=y
|
||||
@@ -0,0 +1,133 @@
|
||||
#
|
||||
# Automatically generated file; DO NOT EDIT.
|
||||
# UniProton Configuration
|
||||
#
|
||||
|
||||
#
|
||||
# Arch Modules Configuration
|
||||
#
|
||||
CONFIG_OS_ARCH_ARMV8=y
|
||||
# CONFIG_OS_OPTION_GUARD_STACK is not set
|
||||
|
||||
#
|
||||
# ARMV8 Sepecfic Configuration
|
||||
#
|
||||
CONFIG_INTERNAL_OS_PLATFORM_ARMV8_AX=y
|
||||
CONFIG_INTERNAL_OS_RASPI4=y
|
||||
|
||||
#
|
||||
# ARMV8 DRV Features Configuration
|
||||
#
|
||||
CONFIG_INTERNAL_OS_GIC_VER="gicv600"
|
||||
CONFIG_OS_GIC_VER=2
|
||||
|
||||
#
|
||||
# Generic Configuration
|
||||
#
|
||||
CONFIG_OS_HARDWARE_PLATFORM="OS_ARMV8"
|
||||
CONFIG_OS_CPU_TYPE="OS_RASPI4"
|
||||
CONFIG_OS_MAX_CORE_NUM=4
|
||||
CONFIG_OS_THIS_CORE=3
|
||||
CONFIG_INTERNAL_OS_BYTE_ORDER_LE=y
|
||||
CONFIG_OS_BYTE_ORDER="OS_LITTLE_ENDIAN"
|
||||
# CONFIG_OS_OPTION_DCACHE is not set
|
||||
CONFIG_OS_CACHE_LINE_SIZE=64
|
||||
|
||||
#
|
||||
# Core Modules Configuration
|
||||
#
|
||||
|
||||
#
|
||||
# IPC Modules Configuration
|
||||
#
|
||||
|
||||
#
|
||||
# Event feature configuration
|
||||
#
|
||||
CONFIG_OS_OPTION_EVENT=y
|
||||
CONFIG_OS_OPTION_QUEUE=y
|
||||
|
||||
#
|
||||
# Semaphore feature configuration
|
||||
#
|
||||
|
||||
#
|
||||
# Kernel Modules Configuration
|
||||
#
|
||||
|
||||
#
|
||||
# IRQ Modules Configuration
|
||||
#
|
||||
# CONFIG_OS_OPTION_HWI_COMBINE is not set
|
||||
CONFIG_OS_OPTION_HWI_PRIORITY=y
|
||||
CONFIG_OS_OPTION_HWI_ATTRIBUTE=y
|
||||
# CONFIG_OS_OPTION_HWI_MAX_NUM_CONFIG is not set
|
||||
|
||||
#
|
||||
# Exc Modules Configuration
|
||||
CONFIG_INTERNAL_OS_SCHEDULE_SINGLE_CORE_BY_CCODE=y
|
||||
CONFIG_OS_OPTION_SYS_TIME_USR=y
|
||||
#
|
||||
|
||||
#
|
||||
# Task module Configuration
|
||||
#
|
||||
CONFIG_OS_OPTION_TASK=y
|
||||
|
||||
#
|
||||
# TASK features configuration
|
||||
#
|
||||
# CONFIG_OS_OPTION_TASK_MON is not set
|
||||
CONFIG_OS_OPTION_TASK_DELETE=y
|
||||
CONFIG_OS_OPTION_TASK_SUSPEND=y
|
||||
CONFIG_OS_OPTION_TASK_INFO=y
|
||||
CONFIG_OS_OPTION_TASK_YIELD=y
|
||||
CONFIG_OS_TSK_PRIORITY_HIGHEST=0
|
||||
CONFIG_OS_TSK_PRIORITY_LOWEST=63
|
||||
CONFIG_OS_TSK_NUM_OF_PRIORITIES=64
|
||||
CONFIG_OS_TSK_CORE_BYTES_IN_PID=2
|
||||
CONFIG_OS_OPTION_TICK=y
|
||||
|
||||
#
|
||||
# Timer Modules Configuration
|
||||
#
|
||||
CONFIG_INTERNAL_OS_SWTMR=y
|
||||
|
||||
#
|
||||
# MM Modules Configuration
|
||||
#
|
||||
|
||||
#
|
||||
# OM Modules Configuration
|
||||
#
|
||||
# CONFIG_OS_OPTION_CPUP is not set
|
||||
|
||||
#
|
||||
# CPUP features configuration
|
||||
#
|
||||
CONFIG_INTERNAL_OS_CPUP_THREAD=y
|
||||
CONFIG_OS_OPTION_CPUP_WARN=y
|
||||
|
||||
#
|
||||
# Error Report Module Configuration
|
||||
#
|
||||
|
||||
#
|
||||
# Hook feature configuration
|
||||
#
|
||||
|
||||
#
|
||||
# security Modules Configuration
|
||||
#
|
||||
CONFIG_OS_OPTION_RND=y
|
||||
|
||||
#
|
||||
# Utility Modules Configuration
|
||||
#
|
||||
CONFIG_OS_OPTION_POSIX=y
|
||||
CONFIG_OS_POSIX_TYPE_NEWLIB=y
|
||||
|
||||
#
|
||||
# Openamp Modules Configuration
|
||||
#
|
||||
CONFIG_OS_OPTION_OPENAMP=y
|
||||
@@ -7,6 +7,7 @@
|
||||
# Arch Modules Configuration
|
||||
#
|
||||
CONFIG_OS_ARCH_ARMV7_M=y
|
||||
CONFIG_OS_OPTION_GUARD_STACK=y
|
||||
|
||||
#
|
||||
# ARM7-M Sepecfic Configuration
|
||||
@@ -44,6 +45,9 @@ CONFIG_OS_OPTION_QUEUE=y
|
||||
#
|
||||
# Semaphore feature configuration
|
||||
#
|
||||
CONFIG_OS_OPTION_BIN_SEM=y
|
||||
CONFIG_OS_OPTION_SEM_RECUR_PV=y
|
||||
CONFIG_OS_OPTION_SEM_PRIOR=y
|
||||
|
||||
#
|
||||
# Kernel Modules Configuration
|
||||
@@ -114,3 +118,5 @@ CONFIG_OS_OPTION_RND=y
|
||||
#
|
||||
# Utility Modules Configuration
|
||||
#
|
||||
CONFIG_OS_OPTION_POSIX=y
|
||||
CONFIG_OS_POSIX_TYPE_NEWLIB=y
|
||||
|
||||
@@ -162,6 +162,18 @@ def write_tail(out_file):
|
||||
|
||||
return 0
|
||||
|
||||
def wirte_buildef_header(out_file):
|
||||
"""
|
||||
wirte_buildef_header
|
||||
:param out_file:
|
||||
:return:
|
||||
"""
|
||||
with codecs.open(out_file, 'a+') as fd_out:
|
||||
text = "\n/* common macros's definitions */\n"
|
||||
text = '%s#include "prt_buildef_common.h"\n' % (text)
|
||||
fd_out.write(text)
|
||||
return 0
|
||||
|
||||
def kconfig2macro(in_file, out_file, flag):
|
||||
header_type = headerType(in_file)
|
||||
if header_type == HEADER_TYPE_INVALID:
|
||||
@@ -175,13 +187,14 @@ def kconfig2macro(in_file, out_file, flag):
|
||||
if ret != 0:
|
||||
return ret
|
||||
|
||||
ret = write_external_macro(out_file)
|
||||
if ret != 0:
|
||||
return ret
|
||||
|
||||
ret = write_c_external_tail(out_file)
|
||||
if ret != 0:
|
||||
return ret
|
||||
|
||||
if header_type == HEADER_TYPE_BUILD:
|
||||
ret_code = wirte_buildef_header(out_file)
|
||||
if ret_code != 0:
|
||||
return ret_code
|
||||
|
||||
ret = write_tail(out_file)
|
||||
if ret != 0:
|
||||
|
||||
@@ -16,6 +16,8 @@ file=lib"${CK_LIB_SUFFIX}"
|
||||
|
||||
if [ "${CPU_TYPE}" = "m4" ] ; then
|
||||
ARNAME=arm-none-eabi-ar ; OBJCOPYNAME=arm-none-eabi-objcopy;
|
||||
elif [ "${CPU_TYPE}" = "raspi4" ] || [ "${CPU_TYPE}" = "hi3093" ];
|
||||
then ARNAME=aarch64-none-elf-ar; OBJCOPYNAME=aarch64-none-elf-objcopy;
|
||||
else
|
||||
ARNAME=ar; OBJCOPYNAME=objcopy;
|
||||
fi
|
||||
@@ -23,7 +25,7 @@ fi
|
||||
sleep 2
|
||||
pushd "$CK_LIB_PATH"
|
||||
##为什么不加这一行要报错
|
||||
if [ "${CPU_TYPE}" = "m4" ] ; then
|
||||
if [ "${CPU_TYPE}" = "m4" ] || [ "${CPU_TYPE}" = "raspi4" ] || [ "${CPU_TYPE}" = "hi3093" ] ; then
|
||||
[ -n tmp_"${file}" ] && rm -rf tmp_"${file}"
|
||||
fi
|
||||
mkdir tmp_"${file}"
|
||||
@@ -34,13 +36,15 @@ pushd tmp_"${file}"
|
||||
# 删除某变量指定的目录下所有文件。
|
||||
# 通过对变量${FILE_PATH}进行判断,当${FILE_PATH}为空时,不会错误删除根目录下的文件。
|
||||
[ -n "${file}" ] && rm -rf "${file}"
|
||||
if [ "${CPU_TYPE}" = "m4" ] ; then
|
||||
if [ "${CPU_TYPE}" = "m4" ] || [ "${CPU_TYPE}" = "raspi4" ] || [ "${CPU_TYPE}" = "hi3093" ]; then
|
||||
find . -name '*.s.o'| awk -F "." '{print $2}'|xargs -I'{}' mv ./{}.s.o ./{}.o
|
||||
find . -name '*.S.o'| awk -F "." '{print $2}'|xargs -I'{}' mv ./{}.S.o ./{}.o
|
||||
find . -name '*.c.o'| awk -F "." '{print $2}'|xargs -I'{}' mv ./{}.c.o ./{}.o
|
||||
|
||||
for i in $(ls *.o);
|
||||
do
|
||||
fi
|
||||
|
||||
if [ "${CPU_TYPE}" = "m4" ] ; then
|
||||
for i in $(ls *.o);
|
||||
do
|
||||
if [ -f "${i}" ] ; then
|
||||
"${AR_TOOL_PATH}"/"${OBJCOPYNAME}" --remove-section=.comment -I elf32-littlearm -O elf32-littlearm "${i}" "${i}".oooo
|
||||
"${AR_TOOL_PATH}"/"${OBJCOPYNAME}" --strip-unneeded "${i}".oooo
|
||||
@@ -49,6 +53,17 @@ if [ "${CPU_TYPE}" = "m4" ] ; then
|
||||
done
|
||||
fi
|
||||
|
||||
if [ "${CPU_TYPE}" = "raspi4" ] || [ "${CPU_TYPE}" = "hi3093" ]; then
|
||||
for i in $(ls *.o);
|
||||
do
|
||||
if [ -f "${i}" ] ; then
|
||||
"${AR_TOOL_PATH}"/"${OBJCOPYNAME}" --remove-section=.comment -I elf64-littleaarch64 -O elf64-littleaarch64 "${i}" "${i}".oooo
|
||||
"${AR_TOOL_PATH}"/"${OBJCOPYNAME}" --strip-unneeded "${i}".oooo
|
||||
mv "${i}".oooo "${i}"
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
"$AR_TOOL_PATH"/"${ARNAME}" -r -D "$file" *.o
|
||||
mv "$file" ../
|
||||
popd
|
||||
@@ -59,4 +74,4 @@ popd
|
||||
popd
|
||||
|
||||
|
||||
exit 0
|
||||
exit 0
|
||||
|
||||
@@ -169,3 +169,30 @@ function(link_library target_name target_path link_flag object_name object_pat
|
||||
add_dependencies(${target_name} ${object_target})
|
||||
endforeach()
|
||||
endfunction()
|
||||
|
||||
function(add_library_ex file_name)
|
||||
#[[
|
||||
函数功能:传入要生成的对象库的文件名(不包含路径),生成对应的对象库并添加到全局变量中
|
||||
用于后续能自动生成打包文件,无需开发人员再次人工指定
|
||||
局限性:
|
||||
1、只能传入单个文件,确保每个对象库只包含单个文件
|
||||
2、生成对象库的文件,必然都是.c 或者.S文件
|
||||
]]
|
||||
#查询传递进来的文件名是否包含路径
|
||||
string(FIND ${file_name} "/" idx REVERSE)
|
||||
if(${idx} GREATER -1)
|
||||
string(SUBSTRING ${file_name} ${idx} -1 str2)
|
||||
string(REPLACE "/" "" object_name ${str2})
|
||||
string(REPLACE ".c" "" object_name ${object_name})
|
||||
else()
|
||||
#将.c .S文件去除后缀名,只保留文件名(文件名作为对象库的名字)
|
||||
string(REPLACE ".c" "" object_name ${file_name})
|
||||
endif()
|
||||
|
||||
string(REPLACE ".S" "" object_name ${object_name})
|
||||
add_library(${object_name} OBJECT ${file_name})
|
||||
#将对象库添加到全局变量中
|
||||
list(APPEND ALL_OBJECT_LIBRARYS ${object_name})
|
||||
set(ALL_OBJECT_LIBRARYS ${ALL_OBJECT_LIBRARYS} CACHE STRING INTERNAL FORCE)
|
||||
|
||||
endfunction()
|
||||
@@ -0,0 +1,144 @@
|
||||
set(OBJCOPY_PATH "$ENV{HCC_PATH}" )
|
||||
##最终的链接目标,会生成对应的.a库
|
||||
#################################################
|
||||
## guest代码
|
||||
#################################################
|
||||
#添加进列表
|
||||
foreach(FILE_NAME ${ALL_OBJECT_LIBRARYS})
|
||||
list(FIND exclude "${FILE_NAME}" is_inclide)
|
||||
if(${is_inclide} EQUAL -1)
|
||||
list(APPEND GUEST_SRCS
|
||||
$<TARGET_OBJECTS:${FILE_NAME}>
|
||||
)
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
#编译结果
|
||||
string(TOUPPER ${PLAM_TYPE} PLAM_TYPE_UP)
|
||||
string(TOUPPER ${CPU_TYPE} CPU_TYPE_UP)
|
||||
add_library(HI3093 STATIC "${GUEST_SRCS}")
|
||||
add_custom_target(cleanobj)
|
||||
add_custom_command(TARGET cleanobj POST_BUILD
|
||||
COMMAND echo finishing)
|
||||
|
||||
if (${COMPILE_MODE} MATCHES "^.*dbg.*$")
|
||||
message("=============== COMPILE_MODE is ${COMPILE_MODE} ===============")
|
||||
else()
|
||||
add_custom_command(
|
||||
TARGET HI3093
|
||||
POST_BUILD
|
||||
COMMAND sh ${PROJECT_SOURCE_DIR}/cmake/common/build_auxiliary_script/make_lib_rename_file_type.sh ${OBJCOPY_PATH} ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY} "HI3093.a"
|
||||
)
|
||||
endif()
|
||||
|
||||
####以下为make install打包脚本#####
|
||||
set(hi3093_armv8_export modules)
|
||||
|
||||
# 下面的变量分别定义了安装根目录、头文件安装目录、动态库安装目录、静态库安装目录、OBJECT文件安装目录、可执行程序安装目录、配置文件安装目录。
|
||||
# 注意:所有安装路径必须是相对CMAKE_INSTALL_PREFIX的相对路径,不可以使用绝对路径!!!
|
||||
# 否则安装目录下的配置文件(foo-config.cmake, foo-tragets.cmake等)拷贝到其它目录时无法工作。
|
||||
set(INSTALL_HI3093_ARMV8_BASE_DIR .)
|
||||
set(INSTALL_HI3093_ARMV8_INCLUDE_DIR UniProton/include)
|
||||
set(INSTALL_HI3093_ARMV8_ARCHIVE_DIR UniProton/lib/hi3093)
|
||||
set(INSTALL_HI3093_ARMV8_ARCHIVE_SEC_DIR libboundscheck/lib/hi3093)
|
||||
set(INSTALL_HI3093_ARMV8_ARCHIVE_CONFIG_DIR UniProton/config)
|
||||
set(INSTALL_HI3093_ARMV8_CONFIG_DIR cmake/hi3093)
|
||||
|
||||
|
||||
include(CMakePackageConfigHelpers)
|
||||
configure_package_config_file(${PROJECT_SOURCE_DIR}/cmake/tool_chain/hi3093_armv8_config.cmake.in
|
||||
${CMAKE_CURRENT_BINARY_DIR}/uniproton-hi3093-armv8-config.cmake
|
||||
INSTALL_DESTINATION ${INSTALL_HI3093_ARMV8_CONFIG_DIR}
|
||||
PATH_VARS
|
||||
INSTALL_HI3093_ARMV8_BASE_DIR
|
||||
INSTALL_HI3093_ARMV8_INCLUDE_DIR
|
||||
INSTALL_HI3093_ARMV8_ARCHIVE_DIR
|
||||
INSTALL_HI3093_ARMV8_ARCHIVE_SEC_DIR
|
||||
INSTALL_HI3093_ARMV8_ARCHIVE_CONFIG_DIR
|
||||
INSTALL_HI3093_ARMV8_CONFIG_DIR
|
||||
INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX}
|
||||
)
|
||||
install(EXPORT ${hi3093_armv8_export}
|
||||
NAMESPACE UniProton::
|
||||
FILE uniproton-hi3093-armv8-targets.cmake
|
||||
DESTINATION ${INSTALL_HI3093_ARMV8_CONFIG_DIR}
|
||||
)
|
||||
install(FILES
|
||||
${CMAKE_CURRENT_BINARY_DIR}/uniproton-hi3093-armv8-config.cmake
|
||||
DESTINATION ${INSTALL_HI3093_ARMV8_CONFIG_DIR}
|
||||
)
|
||||
|
||||
install(TARGETS
|
||||
CortexMXsec_c
|
||||
EXPORT ${hi3093_armv8_export}
|
||||
ARCHIVE DESTINATION ${INSTALL_HI3093_ARMV8_ARCHIVE_SEC_DIR}
|
||||
)
|
||||
|
||||
install(TARGETS
|
||||
HI3093
|
||||
EXPORT ${hi3093_armv8_export}
|
||||
ARCHIVE DESTINATION ${INSTALL_HI3093_ARMV8_ARCHIVE_DIR}/
|
||||
)
|
||||
|
||||
set(TOOLCHAIN_DIR "$ENV{HCC_PATH}") #该路径应该是外部传入,指向编译工具路径
|
||||
if (${COMPILE_MODE} MATCHES "^.*dbg.*$")
|
||||
message("=============== COMPILE_MODE is ${COMPILE_MODE} ===============")
|
||||
else()
|
||||
|
||||
endif()
|
||||
|
||||
install(FILES
|
||||
${PROJECT_SOURCE_DIR}/build/uniproton_config/config_armv8_hi3093/prt_buildef.h
|
||||
DESTINATION ${INSTALL_HI3093_ARMV8_ARCHIVE_CONFIG_DIR}/hi3093
|
||||
)
|
||||
|
||||
if (NOT "${LIBCK_INSTALL_FILE_OPTION}" STREQUAL "SUPER_BUILD")
|
||||
##{GLOB 所有文件 | GLOB_RECURSE 递归查找文件&文件夹}
|
||||
install(FILES
|
||||
${PROJECT_SOURCE_DIR}/src/config/prt_config.c
|
||||
${PROJECT_SOURCE_DIR}/src/config/prt_config_internal.h
|
||||
${PROJECT_SOURCE_DIR}/src/config/config/prt_config.h
|
||||
DESTINATION ${INSTALL_HI3093_ARMV8_ARCHIVE_CONFIG_DIR}
|
||||
)
|
||||
##{GLOB 所有文件 | GLOB_RECURSE 递归查找文件&文件夹}
|
||||
file(GLOB common_include_files ${PROJECT_SOURCE_DIR}/src/include/uapi/*.h)
|
||||
install(FILES
|
||||
${common_include_files}
|
||||
DESTINATION ${INSTALL_HI3093_ARMV8_INCLUDE_DIR}/common
|
||||
)
|
||||
|
||||
|
||||
##{GLOB 所有文件 | GLOB_RECURSE 递归查找文件&文件夹 =======}
|
||||
file(GLOB hw_board_include_files ${PROJECT_SOURCE_DIR}/src/include/uapi/hw/armv8/*)
|
||||
install(FILES
|
||||
${hw_board_include_files}
|
||||
DESTINATION ${INSTALL_HI3093_ARMV8_INCLUDE_DIR}/hw/board
|
||||
)
|
||||
|
||||
##{GLOB 所有文件 | GLOB_RECURSE 递归查找文件&文件夹}
|
||||
file(GLOB hw_cpu_include_files ${PROJECT_SOURCE_DIR}/src/include/posix/*)
|
||||
install(FILES
|
||||
${hw_cpu_include_files}
|
||||
DESTINATION ${INSTALL_HI3093_ARMV8_INCLUDE_DIR}/hw/cpu
|
||||
)
|
||||
|
||||
install(FILES
|
||||
${PROJECT_SOURCE_DIR}/src/include/uapi/prt_errno.h
|
||||
${PROJECT_SOURCE_DIR}/src/include/uapi/prt_event.h
|
||||
${PROJECT_SOURCE_DIR}/src/include/uapi/prt_exc.h
|
||||
${PROJECT_SOURCE_DIR}/src/include/uapi/prt_hook.h
|
||||
${PROJECT_SOURCE_DIR}/src/include/uapi/prt_hwi.h
|
||||
${PROJECT_SOURCE_DIR}/src/include/uapi/prt_mem.h
|
||||
${PROJECT_SOURCE_DIR}/src/include/uapi/prt_module.h
|
||||
${PROJECT_SOURCE_DIR}/src/include/uapi/prt_queue.h
|
||||
${PROJECT_SOURCE_DIR}/src/include/uapi/prt_sem.h
|
||||
${PROJECT_SOURCE_DIR}/src/include/uapi/prt_sys.h
|
||||
${PROJECT_SOURCE_DIR}/src/include/uapi/prt_task.h
|
||||
${PROJECT_SOURCE_DIR}/src/include/uapi/prt_tick.h
|
||||
${PROJECT_SOURCE_DIR}/src/include/uapi/prt_timer.h
|
||||
${PROJECT_SOURCE_DIR}/src/include/uapi/prt_typedef.h
|
||||
${PROJECT_SOURCE_DIR}/src/include/uapi/prt_cpup.h
|
||||
${PROJECT_SOURCE_DIR}/src/include/uapi/prt_err.h
|
||||
DESTINATION ${INSTALL_HI3093_ARMV8_INCLUDE_DIR}/
|
||||
)
|
||||
endif()
|
||||
@@ -0,0 +1,12 @@
|
||||
@PACKAGE_INIT@
|
||||
include(${CMAKE_CURRENT_LIST_DIR}/uniproton-hi3093-armv8-targets.cmake)
|
||||
|
||||
|
||||
|
||||
set_and_check(INSTALL_HI3093_ARMV8_BASE_DIR "@PACKAGE_INSTALL_HI3093_ARMV8_BASE_DIR@")
|
||||
set_and_check(INSTALL_HI3093_ARMV8_INCLUDE_DIR "@PACKAGE_INSTALL_HI3093_ARMV8_INCLUDE_DIR@")
|
||||
set_and_check(INSTALL_HI3093_ARMV8_ARCHIVE_DIR "@PACKAGE_INSTALL_HI3093_ARMV8_ARCHIVE_DIR@")
|
||||
set_and_check(INSTALL_HI3093_ARMV8_ARCHIVE_CONFIG_DIR "@PACKAGE_INSTALL_HI3093_ARMV8_ARCHIVE_CONFIG_DIR@")
|
||||
set_and_check(INSTALL_HI3093_ARMV8_CONFIG_DIR "@PACKAGE_INSTALL_HI3093_ARMV8_CONFIG_DIR@")
|
||||
|
||||
check_required_components(uniproton-hi3093-armv8)
|
||||
@@ -1,107 +1,21 @@
|
||||
set(BUILD_DIR "$ENV{BUILD_TMP_DIR}" ) #version id
|
||||
set(OBJCOPY_PATH "$ENV{OBJCOPY_PATH}" ) #OBJCOPY_PATH
|
||||
|
||||
|
||||
|
||||
##最终的链接目标,会生成对应的.a库
|
||||
#################################################
|
||||
## arch代码
|
||||
#################################################
|
||||
list(APPEND ARCH_SRCS
|
||||
$<TARGET_OBJECTS:prt_hw_boot>
|
||||
$<TARGET_OBJECTS:prt_port>
|
||||
$<TARGET_OBJECTS:prt_dispatch>
|
||||
$<TARGET_OBJECTS:prt_hwi>
|
||||
$<TARGET_OBJECTS:prt_exc>
|
||||
$<TARGET_OBJECTS:prt_hw_exc>
|
||||
$<TARGET_OBJECTS:prt_vector>
|
||||
$<TARGET_OBJECTS:prt_vi_dispatch>
|
||||
$<TARGET_OBJECTS:prt_hw_tick>
|
||||
$<TARGET_OBJECTS:prt_hw_tick_minor>
|
||||
$<TARGET_OBJECTS:prt_hw>
|
||||
$<TARGET_OBJECTS:prt_div64>
|
||||
)
|
||||
|
||||
#################################################
|
||||
## kernel代码
|
||||
#################################################
|
||||
list(APPEND KERNEL_SRCS
|
||||
$<TARGET_OBJECTS:prt_sem>
|
||||
$<TARGET_OBJECTS:prt_sem_init>
|
||||
$<TARGET_OBJECTS:prt_sem_minor>
|
||||
$<TARGET_OBJECTS:prt_irq>
|
||||
$<TARGET_OBJECTS:prt_sys>
|
||||
$<TARGET_OBJECTS:prt_sys_init>
|
||||
$<TARGET_OBJECTS:prt_sys_time>
|
||||
$<TARGET_OBJECTS:prt_amp_task>
|
||||
$<TARGET_OBJECTS:prt_amp_task_del>
|
||||
$<TARGET_OBJECTS:prt_amp_task_init>
|
||||
$<TARGET_OBJECTS:prt_amp_task_minor>
|
||||
$<TARGET_OBJECTS:prt_task>
|
||||
$<TARGET_OBJECTS:prt_taskself_id>
|
||||
$<TARGET_OBJECTS:prt_task_attrib>
|
||||
$<TARGET_OBJECTS:prt_task_del>
|
||||
$<TARGET_OBJECTS:prt_task_global>
|
||||
$<TARGET_OBJECTS:prt_task_info>
|
||||
$<TARGET_OBJECTS:prt_task_init>
|
||||
$<TARGET_OBJECTS:prt_task_minor>
|
||||
$<TARGET_OBJECTS:prt_task_priority>
|
||||
$<TARGET_OBJECTS:prt_task_sem>
|
||||
$<TARGET_OBJECTS:prt_tick>
|
||||
$<TARGET_OBJECTS:prt_tick_init>
|
||||
$<TARGET_OBJECTS:prt_timer>
|
||||
$<TARGET_OBJECTS:prt_swtmr>
|
||||
$<TARGET_OBJECTS:prt_swtmr_init>
|
||||
$<TARGET_OBJECTS:prt_swtmr_minor>
|
||||
$<TARGET_OBJECTS:prt_kexc>
|
||||
$<TARGET_OBJECTS:prt_exc>
|
||||
$<TARGET_OBJECTS:prt_timer_minor>
|
||||
)
|
||||
list(APPEND IPC_SRCS
|
||||
$<TARGET_OBJECTS:prt_event>
|
||||
$<TARGET_OBJECTS:prt_queue>
|
||||
$<TARGET_OBJECTS:prt_queue_del>
|
||||
$<TARGET_OBJECTS:prt_queue_minor>
|
||||
$<TARGET_OBJECTS:prt_queue_init>
|
||||
)
|
||||
list(APPEND MEM_SRCS
|
||||
$<TARGET_OBJECTS:prt_fscmem>
|
||||
$<TARGET_OBJECTS:prt_mem>
|
||||
)
|
||||
list(APPEND OM_SRCS
|
||||
$<TARGET_OBJECTS:prt_cpup>
|
||||
$<TARGET_OBJECTS:prt_cpup_minor>
|
||||
$<TARGET_OBJECTS:prt_cpup_thread>
|
||||
$<TARGET_OBJECTS:prt_cpup_thread_64>
|
||||
$<TARGET_OBJECTS:prt_cpup_thread_init>
|
||||
$<TARGET_OBJECTS:prt_cpup_warn>
|
||||
$<TARGET_OBJECTS:prt_err>
|
||||
$<TARGET_OBJECTS:prt_err_init>
|
||||
$<TARGET_OBJECTS:prt_hook_init>
|
||||
$<TARGET_OBJECTS:prt_rnd_set>
|
||||
)
|
||||
list(APPEND BASE_LIB_SRCS
|
||||
$<TARGET_OBJECTS:prt_lib_math64>
|
||||
$<TARGET_OBJECTS:prt_lib_version>
|
||||
)
|
||||
|
||||
#将所有对象库添加到列表中
|
||||
foreach(FILE_NAME ${ALL_OBJECT_LIBRARYS})
|
||||
list(APPEND CORTEX_M4_SRCS
|
||||
$<TARGET_OBJECTS:${FILE_NAME}>
|
||||
)
|
||||
endforeach()
|
||||
|
||||
|
||||
|
||||
#编译结果
|
||||
string(TOUPPER ${PLAM_TYPE} PLAM_TYPE_UP)
|
||||
string(TOUPPER ${CPU_TYPE} CPU_TYPE_UP)
|
||||
#编译通用的.a库
|
||||
add_library(CortexMXarch STATIC "${ARCH_SRCS}")
|
||||
add_library(CortexMXkernel STATIC "${KERNEL_SRCS}" "${BASE_LIB_SRCS}")
|
||||
add_library(CortexMXmem STATIC "${MEM_SRCS}")
|
||||
add_library(CortexMXom STATIC "${OM_SRCS}")
|
||||
add_library(CortexMXipc STATIC "${IPC_SRCS}")
|
||||
|
||||
set_target_properties(CortexMXarch PROPERTIES SUFFIX ".lib")
|
||||
set_target_properties(CortexMXkernel PROPERTIES SUFFIX ".lib")
|
||||
set_target_properties(CortexMXmem PROPERTIES SUFFIX ".lib")
|
||||
set_target_properties(CortexMXom PROPERTIES SUFFIX ".lib")
|
||||
set_target_properties(CortexMXipc PROPERTIES SUFFIX ".lib")
|
||||
#编译.a库
|
||||
add_library(CortexM4 STATIC "${CORTEX_M4_SRCS}")
|
||||
set_target_properties(CortexM4 PROPERTIES SUFFIX ".a")
|
||||
|
||||
add_custom_target(cleanobj)
|
||||
add_custom_command(TARGET cleanobj POST_BUILD
|
||||
@@ -112,33 +26,9 @@ if (${COMPILE_MODE} STREQUAL "debug")
|
||||
message("=============== COMPILE_MODE is ${COMPILE_MODE} ===============")
|
||||
else()
|
||||
add_custom_command(
|
||||
TARGET CortexMXarch
|
||||
TARGET CortexM4
|
||||
POST_BUILD
|
||||
COMMAND sh ${PROJECT_SOURCE_DIR}/cmake/common/build_auxiliary_script/make_lib_rename_file_type.sh ${OBJCOPY_PATH} ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY} "CortexMXarch.lib"
|
||||
)
|
||||
|
||||
add_custom_command(
|
||||
TARGET CortexMXkernel
|
||||
POST_BUILD
|
||||
COMMAND sh ${PROJECT_SOURCE_DIR}/cmake/common/build_auxiliary_script/make_lib_rename_file_type.sh ${OBJCOPY_PATH} ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY} "CortexMXkernel.lib"
|
||||
)
|
||||
|
||||
add_custom_command(
|
||||
TARGET CortexMXmem
|
||||
POST_BUILD
|
||||
COMMAND sh ${PROJECT_SOURCE_DIR}/cmake/common/build_auxiliary_script/make_lib_rename_file_type.sh ${OBJCOPY_PATH} ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY} "CortexMXmem.lib"
|
||||
)
|
||||
|
||||
add_custom_command(
|
||||
TARGET CortexMXom
|
||||
POST_BUILD
|
||||
COMMAND sh ${PROJECT_SOURCE_DIR}/cmake/common/build_auxiliary_script/make_lib_rename_file_type.sh ${OBJCOPY_PATH} ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY} "CortexMXom.lib"
|
||||
)
|
||||
|
||||
add_custom_command(
|
||||
TARGET CortexMXipc
|
||||
POST_BUILD
|
||||
COMMAND sh ${PROJECT_SOURCE_DIR}/cmake/common/build_auxiliary_script/make_lib_rename_file_type.sh ${OBJCOPY_PATH} ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY} "CortexMXipc.lib"
|
||||
COMMAND sh ${PROJECT_SOURCE_DIR}/cmake/common/build_auxiliary_script/make_lib_rename_file_type.sh ${OBJCOPY_PATH} ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY} "CortexM4.a"
|
||||
)
|
||||
endif()
|
||||
####以下为m4 make install打包脚本#####
|
||||
@@ -183,11 +73,7 @@ install(FILES
|
||||
)
|
||||
|
||||
install(TARGETS
|
||||
CortexMXarch
|
||||
CortexMXkernel
|
||||
CortexMXmem
|
||||
CortexMXom
|
||||
CortexMXipc
|
||||
CortexM4
|
||||
EXPORT ${m4_cortex_export}
|
||||
ARCHIVE DESTINATION ${INSTALL_M4_CORTEX_ARCHIVE_DIR}/
|
||||
)
|
||||
|
||||
@@ -0,0 +1,151 @@
|
||||
set(OBJCOPY_PATH "$ENV{HCC_PATH}" )
|
||||
##最终的链接目标,会生成对应的.a库
|
||||
#################################################
|
||||
## guest代码
|
||||
#################################################
|
||||
#添加进列表
|
||||
foreach(FILE_NAME ${ALL_OBJECT_LIBRARYS})
|
||||
list(FIND exclude "${FILE_NAME}" is_inclide)
|
||||
if(${is_inclide} EQUAL -1)
|
||||
list(APPEND GUEST_SRCS
|
||||
$<TARGET_OBJECTS:${FILE_NAME}>
|
||||
)
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
#编译结果
|
||||
string(TOUPPER ${PLAM_TYPE} PLAM_TYPE_UP)
|
||||
string(TOUPPER ${CPU_TYPE} CPU_TYPE_UP)
|
||||
add_library(RASPI4 STATIC "${GUEST_SRCS}")
|
||||
add_custom_target(cleanobj)
|
||||
add_custom_command(TARGET cleanobj POST_BUILD
|
||||
COMMAND echo finishing)
|
||||
|
||||
if (${COMPILE_MODE} MATCHES "^.*dbg.*$")
|
||||
message("=============== COMPILE_MODE is ${COMPILE_MODE} ===============")
|
||||
else()
|
||||
add_custom_command(
|
||||
TARGET RASPI4
|
||||
POST_BUILD
|
||||
COMMAND sh ${PROJECT_SOURCE_DIR}/cmake/common/build_auxiliary_script/make_lib_rename_file_type.sh ${OBJCOPY_PATH} ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY} "RASPI4.a"
|
||||
)
|
||||
endif()
|
||||
|
||||
####以下为make install打包脚本#####
|
||||
set(raspi4_armv8_export modules)
|
||||
|
||||
# 下面的变量分别定义了安装根目录、头文件安装目录、动态库安装目录、静态库安装目录、OBJECT文件安装目录、可执行程序安装目录、配置文件安装目录。
|
||||
# 注意:所有安装路径必须是相对CMAKE_INSTALL_PREFIX的相对路径,不可以使用绝对路径!!!
|
||||
# 否则安装目录下的配置文件(foo-config.cmake, foo-tragets.cmake等)拷贝到其它目录时无法工作。
|
||||
set(INSTALL_RASPI4_ARMV8_BASE_DIR .)
|
||||
set(INSTALL_RASPI4_ARMV8_INCLUDE_DIR UniProton/include)
|
||||
set(INSTALL_RASPI4_ARMV8_ARCHIVE_DIR UniProton/lib/raspi4)
|
||||
set(INSTALL_RASPI4_ARMV8_ARCHIVE_SEC_DIR libboundscheck/lib/raspi4)
|
||||
set(INSTALL_RASPI4_ARMV8_ARCHIVE_CONFIG_DIR UniProton/config)
|
||||
set(INSTALL_RASPI4_ARMV8_CONFIG_DIR cmake/raspi4)
|
||||
|
||||
|
||||
include(CMakePackageConfigHelpers)
|
||||
configure_package_config_file(${PROJECT_SOURCE_DIR}/cmake/tool_chain/raspi4_armv8_config.cmake.in
|
||||
${CMAKE_CURRENT_BINARY_DIR}/uniproton-raspi4-armv8-config.cmake
|
||||
INSTALL_DESTINATION ${INSTALL_RASPI4_ARMV8_CONFIG_DIR}
|
||||
PATH_VARS
|
||||
INSTALL_RASPI4_ARMV8_BASE_DIR
|
||||
INSTALL_RASPI4_ARMV8_INCLUDE_DIR
|
||||
INSTALL_RASPI4_ARMV8_ARCHIVE_DIR
|
||||
INSTALL_RASPI4_ARMV8_ARCHIVE_SEC_DIR
|
||||
INSTALL_RASPI4_ARMV8_ARCHIVE_CONFIG_DIR
|
||||
INSTALL_RASPI4_ARMV8_CONFIG_DIR
|
||||
INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX}
|
||||
)
|
||||
install(EXPORT ${raspi4_armv8_export}
|
||||
NAMESPACE UniProton::
|
||||
FILE uniproton-raspi4-armv8-targets.cmake
|
||||
DESTINATION ${INSTALL_RASPI4_ARMV8_CONFIG_DIR}
|
||||
)
|
||||
install(FILES
|
||||
${CMAKE_CURRENT_BINARY_DIR}/uniproton-raspi4-armv8-config.cmake
|
||||
DESTINATION ${INSTALL_RASPI4_ARMV8_CONFIG_DIR}
|
||||
)
|
||||
|
||||
install(TARGETS
|
||||
CortexMXsec_c
|
||||
EXPORT ${raspi4_armv8_export}
|
||||
ARCHIVE DESTINATION ${INSTALL_RASPI4_ARMV8_ARCHIVE_SEC_DIR}
|
||||
)
|
||||
|
||||
install(TARGETS
|
||||
RASPI4
|
||||
EXPORT ${raspi4_armv8_export}
|
||||
ARCHIVE DESTINATION ${INSTALL_RASPI4_ARMV8_ARCHIVE_DIR}/
|
||||
)
|
||||
|
||||
set(TOOLCHAIN_DIR "$ENV{HCC_PATH}") #该路径应该是外部传入,指向编译工具路径
|
||||
if (${COMPILE_MODE} MATCHES "^.*dbg.*$")
|
||||
message("=============== COMPILE_MODE is ${COMPILE_MODE} ===============")
|
||||
else()
|
||||
|
||||
endif()
|
||||
|
||||
install(FILES
|
||||
${PROJECT_SOURCE_DIR}/build/uniproton_config/config_armv8_raspi4/prt_buildef.h
|
||||
DESTINATION ${INSTALL_RASPI4_ARMV8_ARCHIVE_CONFIG_DIR}/raspi4
|
||||
)
|
||||
|
||||
if (NOT "${LIBCK_INSTALL_FILE_OPTION}" STREQUAL "SUPER_BUILD")
|
||||
##{GLOB 所有文件 | GLOB_RECURSE 递归查找文件&文件夹}
|
||||
install(FILES
|
||||
${PROJECT_SOURCE_DIR}/src/config/prt_config.c
|
||||
${PROJECT_SOURCE_DIR}/src/config/prt_config_internal.h
|
||||
${PROJECT_SOURCE_DIR}/src/config/config/prt_config.h
|
||||
DESTINATION ${INSTALL_RASPI4_ARMV8_ARCHIVE_CONFIG_DIR}
|
||||
)
|
||||
##{GLOB 所有文件 | GLOB_RECURSE 递归查找文件&文件夹}
|
||||
file(GLOB common_include_files ${PROJECT_SOURCE_DIR}/src/include/uapi/common/*.h)
|
||||
install(FILES
|
||||
${common_include_files}
|
||||
DESTINATION ${INSTALL_RASPI4_ARMV8_INCLUDE_DIR}/common
|
||||
)
|
||||
|
||||
|
||||
##{GLOB 所有文件 | GLOB_RECURSE 递归查找文件&文件夹 =======}
|
||||
file(GLOB hw_board_include_files ${PROJECT_SOURCE_DIR}/src/include/uapi/sre/hw/board/*)
|
||||
install(FILES
|
||||
${hw_board_include_files}
|
||||
DESTINATION ${INSTALL_RASPI4_ARMV8_INCLUDE_DIR}/hw/board
|
||||
)
|
||||
|
||||
##{GLOB 所有文件 | GLOB_RECURSE 递归查找文件&文件夹}
|
||||
file(GLOB hw_cpu_include_files ${PROJECT_SOURCE_DIR}/src/include/uapi/sre/hw/cpu/*)
|
||||
install(FILES
|
||||
${hw_cpu_include_files}
|
||||
DESTINATION ${INSTALL_RASPI4_ARMV8_INCLUDE_DIR}/hw/cpu
|
||||
)
|
||||
|
||||
##{GLOB 所有文件 | GLOB_RECURSE 递归查找文件&文件夹}
|
||||
file(GLOB hw_drv_include_files ${PROJECT_SOURCE_DIR}/src/include/uapi/sre/hw/drv/*)
|
||||
install(FILES
|
||||
${hw_drv_include_files}
|
||||
DESTINATION ${INSTALL_RASPI4_ARMV8_INCLUDE_DIR}/hw/drv
|
||||
)
|
||||
|
||||
install(FILES
|
||||
${PROJECT_SOURCE_DIR}/src/include/uapi/prt_errno.h
|
||||
${PROJECT_SOURCE_DIR}/src/include/uapi/prt_event.h
|
||||
${PROJECT_SOURCE_DIR}/src/include/uapi/prt_exc.h
|
||||
${PROJECT_SOURCE_DIR}/src/include/uapi/prt_hook.h
|
||||
${PROJECT_SOURCE_DIR}/src/include/uapi/prt_hwi.h
|
||||
${PROJECT_SOURCE_DIR}/src/include/uapi/prt_mem.h
|
||||
${PROJECT_SOURCE_DIR}/src/include/uapi/prt_module.h
|
||||
${PROJECT_SOURCE_DIR}/src/include/uapi/prt_queue.h
|
||||
${PROJECT_SOURCE_DIR}/src/include/uapi/prt_sem.h
|
||||
${PROJECT_SOURCE_DIR}/src/include/uapi/prt_sys.h
|
||||
${PROJECT_SOURCE_DIR}/src/include/uapi/prt_task.h
|
||||
${PROJECT_SOURCE_DIR}/src/include/uapi/prt_tick.h
|
||||
${PROJECT_SOURCE_DIR}/src/include/uapi/prt_timer.h
|
||||
${PROJECT_SOURCE_DIR}/src/include/uapi/prt_typedef.h
|
||||
${PROJECT_SOURCE_DIR}/src/include/uapi/prt_cpup.h
|
||||
${PROJECT_SOURCE_DIR}/src/include/uapi/prt_err.h
|
||||
DESTINATION ${INSTALL_RASPI4_ARMV8_INCLUDE_DIR}/
|
||||
)
|
||||
endif()
|
||||
@@ -0,0 +1,12 @@
|
||||
@PACKAGE_INIT@
|
||||
include(${CMAKE_CURRENT_LIST_DIR}/uniproton-raspi4-armv8-targets.cmake)
|
||||
|
||||
|
||||
|
||||
set_and_check(INSTALL_RASPI4_ARMV8_BASE_DIR "@PACKAGE_INSTALL_RASPI4_ARMV8_BASE_DIR@")
|
||||
set_and_check(INSTALL_RASPI4_ARMV8_INCLUDE_DIR "@PACKAGE_INSTALL_RASPI4_ARMV8_INCLUDE_DIR@")
|
||||
set_and_check(INSTALL_RASPI4_ARMV8_ARCHIVE_DIR "@PACKAGE_INSTALL_RASPI4_ARMV8_ARCHIVE_DIR@")
|
||||
set_and_check(INSTALL_RASPI4_ARMV8_ARCHIVE_CONFIG_DIR "@PACKAGE_INSTALL_RASPI4_ARMV8_ARCHIVE_CONFIG_DIR@")
|
||||
set_and_check(INSTALL_RASPI4_ARMV8_CONFIG_DIR "@PACKAGE_INSTALL_RASPI4_ARMV8_CONFIG_DIR@")
|
||||
|
||||
check_required_components(uniproton-raspi4-armv8)
|
||||
@@ -13,12 +13,18 @@ set(COMPILE_OPTION "$ENV{COMPILE_OPTION}" )
|
||||
set(RPROTON_INSTALL_FILE_OPTION "$ENV{RPROTON_INSTALL_FILE_OPTION}" )##RPROTON_INSTALL_FILE_OPTION="SUPER_BUILD";
|
||||
|
||||
|
||||
if (${CPU_TYPE} STREQUAL "m4")
|
||||
#### 统一告警选项,请审慎增删
|
||||
set(STRONG_COMPILE_WARING_FLAG "-Wunused -Wredundant-decls -Wfloat-conversion -Wwrite-strings -Wunused-macros -Wswitch-default -Wshift-overflow=2 -Wnested-externs -Wmissing-include-dirs -Wlogical-op -Wjump-misses-init -Wformat-security -Wvla -Wframe-larger-than=4096 -Wduplicated-cond -Wdisabled-optimization -Wduplicated-branches -Wignored-qualifiers -Wimplicit-fallthrough=3 -Wpointer-arith -Wshift-negative-value -Wsign-compare -Wtype-limits -Wcast-qual -Wundef -Wbad-function-cast -Wold-style-definition -Wpacked -Wstrict-prototypes -Wstack-usage=2048")
|
||||
set(COMPILE_WARING_FLAG " -Wall -Werror -Wextra -Wformat=2 -Wfloat-equal -Wshadow -Wtrampolines -Wdate-time ")## -Wall -Werror -Wextra -Wformat=2 -Wfloat-equal
|
||||
include(${HOME_PATH}/cmake/tool_chain/uniproton_tool_chain_gcc.cmake)
|
||||
endif()
|
||||
|
||||
if (${CPU_TYPE} STREQUAL "m4" )
|
||||
include(${HOME_PATH}/cmake/tool_chain/rtosk_tool_chain_gcc.cmake)
|
||||
if (${CPU_TYPE} STREQUAL "raspi4" OR ${CPU_TYPE} STREQUAL "hi3093")
|
||||
#### 统一告警选项,请审慎增删
|
||||
set(STRONG_COMPILE_WARING_FLAG "-Wunused -Wredundant-decls -Wfloat-conversion -Wwrite-strings -Wunused-macros -Wswitch-default -Wshift-overflow=2 -Wnested-externs -Wmissing-include-dirs -Wlogical-op -Wjump-misses-init -Wformat-security -Wvla -Wframe-larger-than=4096 -Wduplicated-cond -Wdisabled-optimization -Wduplicated-branches -Wignored-qualifiers -Wimplicit-fallthrough=3 -Wpointer-arith -Wshift-negative-value -Wsign-compare -Wtype-limits -Wcast-qual -Wundef -Wbad-function-cast -Wold-style-definition -Wpacked -Wstrict-prototypes -Wstack-usage=2048")
|
||||
set(COMPILE_WARING_FLAG " -Wall -Werror -Wextra -Wformat=2 -Wfloat-equal -Wshadow -Wtrampolines -Wdate-time ")## -Wall -Werror -Wextra -Wformat=2 -Wfloat-equal
|
||||
include(${HOME_PATH}/cmake/tool_chain/uniproton_tool_chain_gcc_arm64.cmake)
|
||||
endif()
|
||||
|
||||
|
||||
|
||||
+7
-1
@@ -29,7 +29,13 @@ if(${CPU_TYPE} STREQUAL "m4")
|
||||
set(CMAKE_ASM_FLAGS "--specs=nosys.specs")
|
||||
set(CMAKE_ASM_COMPILE_OBJECT "<CMAKE_ASM_COMPILER> -O2 -pipe ${STRONG_COMPILE_WARING_FLAG} ${COMPILE_WARING_FLAG} -std=gnu11 -fno-common -fomit-frame-pointer -mthumb -mcpu=cortex-m4 -mfloat-abi=softfp -mfpu=fpv4-sp-d16 -Wa,-mimplicit-it=thumb -fstack-protector-strong -funsigned-char <FLAGS> <INCLUDES> -c <SOURCE> -o <OBJECT>")
|
||||
set(CMAKE_C_FLAGS "--specs=nosys.specs") #原ID形式\"888888\"
|
||||
set(CMAKE_C_COMPILE_OBJECT "<CMAKE_C_COMPILER> -O2 -pipe ${STRONG_COMPILE_WARING_FLAG} ${COMPILE_WARING_FLAG} -std=gnu11 -fno-common -fomit-frame-pointer -mcpu=cortex-m4 -mthumb -mfloat-abi=softfp -mfpu=fpv4-sp-d16 -fstack-protector-strong -fdata-sections -ffunction-sections -fshort-enums -funsigned-char -DSECUREC_BUFFER_SIZE=32 <FLAGS> <INCLUDES> -c <SOURCE> -o <OBJECT>")
|
||||
set(CMAKE_C_COMPILE_OBJECT "<CMAKE_C_COMPILER> -O2 -pipe ")
|
||||
|
||||
file(STRINGS "$ENV{CONFIG_FILE_PATH}/defconfig" config_options REGEX "^CONFIG_OS_OPTION_POSIX" ENCODING "UTF-8")
|
||||
foreach(config_option ${config_options})
|
||||
set(CMAKE_C_COMPILE_OBJECT "${CMAKE_C_COMPILE_OBJECT} -D_GNU_SOURCE -D_POSIX_THREADS -D_POSIX_THREAD_PRIORITY_SCHEDULING -D_POSIX_PRIORITY_SCHEDULING -D_POSIX_TIMERS -D_POSIX_CPUTIME -D_POSIX_THREAD_CPUTIME -D_POSIX_MONOTONIC_CLOCK -D_POSIX_TIMEOUTS -D_POSIX_CLOCK_SELECTION -D_POSIX_THREAD_PRIO_PROTECT -D_UNIX98_THREAD_MUTEX_ATTRIBUTES -D_POSIX_READER_WRITER_LOCKS")
|
||||
endforeach()
|
||||
set(CMAKE_C_COMPILE_OBJECT "${CMAKE_C_COMPILE_OBJECT} ${STRONG_COMPILE_WARING_FLAG} ${COMPILE_WARING_FLAG} -std=gnu11 -fno-common -fomit-frame-pointer -mcpu=cortex-m4 -mthumb -mfloat-abi=softfp -mfpu=fpv4-sp-d16 -fstack-protector-strong -fdata-sections -ffunction-sections -fshort-enums -funsigned-char -DSECUREC_BUFFER_SIZE=32 <FLAGS> <INCLUDES> -c <SOURCE> -o <OBJECT>")
|
||||
endif()
|
||||
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
################交叉编译#####################
|
||||
#cross-compilation config
|
||||
set(CMAKE_SYSTEM_NAME Linux)
|
||||
set(CMAKE_SYSTEM_PROCESSOR arm)
|
||||
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
|
||||
|
||||
|
||||
set(CPU_TYPE "$ENV{CPU_TYPE}" )
|
||||
set(PLAM_TYPE "$ENV{PLAM_TYPE}" )
|
||||
set(LIB_TYPE "$ENV{LIB_TYPE}" )
|
||||
set(SYSTEM "$ENV{SYSTEM}" )
|
||||
set(CORE "$ENV{CORE}" )
|
||||
set(LIB_RUN_TYPE "$ENV{LIB_RUN_TYPE}" )
|
||||
set(BUILD_DIR "$ENV{BUILD_TMP_DIR}" ) #version id
|
||||
set(OBJCOPY_PATH "$ENV{OBJCOPY_PATH}" ) #OBJCOPY_PATH
|
||||
set(COMPILE_MODE "$ENV{COMPILE_MODE}" )
|
||||
set(CC_TYPE "$ENV{CC_TYPE}" )
|
||||
set(TOOLCHAIN_DIR "$ENV{HCC_PATH}") #该路径应该是外部传入,指向编译工具路径
|
||||
|
||||
|
||||
# 设置gcc_arm64编译器公共的编译选项
|
||||
set(CC_OPT_LEVEL "-Os")
|
||||
set(CC_WARN_FLAGS "-Wformat-signedness")
|
||||
set(CC_MD_DEPENDENT_FLAGS "-Wl,--build-id=none")
|
||||
# 初始化为空,不能删除这句
|
||||
set(CC_OPT_FLAGS "")
|
||||
set(CC_SEC_FLAGS "${CC_SEC_FLAGS} -fno-PIE")
|
||||
# 待确认的编译选项,暂时没进行分类,待处理
|
||||
set(CC_OTHER_FLAGS "--specs=nosys.specs -fno-builtin -fno-dwarf2-cfi-asm -mcmodel=large -fomit-frame-pointer -fzero-initialized-in-bss -fdollars-in-identifiers -ffunction-sections -fdata-sections -fno-aggressive-loop-optimizations -fno-optimize-strlen -fno-schedule-insns -fno-inline-small-functions -fno-inline-functions-called-once -fno-strict-aliasing -finline-limit=20 -mstrict-align -mlittle-endian -nostartfiles -funwind-tables")
|
||||
set(CC_DEFINE_FLAGS "")
|
||||
|
||||
##compiler specified in /etc/profile
|
||||
set(CMAKE_C_COMPILER "${TOOLCHAIN_DIR}/aarch64-none-elf-gcc" CACHE PATH "arm-gcc C compiler" FORCE)
|
||||
set(CMAKE_ASM_COMPILER "${TOOLCHAIN_DIR}/aarch64-none-elf-gcc" CACHE PATH "arm-gcc ASM compiler" FORCE)
|
||||
|
||||
# 设置C和ASM相关的所有使用的编译选项
|
||||
set(CMAKE_C_FLAGS "${CC_OPT_LEVEL} ${CC_OVERALL_FLAGS_COMMON} ${CC_WARN_FLAGS_COMMON} ${CC_WARN_FLAGS} ${CC_LANGUAGE_FLAGS_COMMON} ${CC_LANGUAGE_FLAGS} ${CC_CDG_FLAGS} ${CC_MD_DEPENDENT_FLAGS} ${CC_OPT_FLAGS} ${CC_SEC_FLAGS} ${CC_OTHER_FLAGS} ${CC_DEFINE_FLAGS_COMMON} ${CC_DEFINE_FLAGS}")
|
||||
set(CMAKE_ASM_FLAGS "${CMAKE_C_FLAGS} ${ASM_EXTRA_FLAGS}")
|
||||
set(CMAKE_C_COMPILE_OBJECT "<CMAKE_C_COMPILER> <FLAGS> <INCLUDES> -c <SOURCE> -o <OBJECT>")
|
||||
file(STRINGS "$ENV{CONFIG_FILE_PATH}/defconfig" config_options REGEX "^CONFIG_OS_OPTION_POSIX" ENCODING "UTF-8")
|
||||
foreach(config_option ${config_options})
|
||||
set(CMAKE_C_COMPILE_OBJECT "${CMAKE_C_COMPILE_OBJECT} -D_GNU_SOURCE -D_POSIX_THREADS -D_POSIX_THREAD_PRIORITY_SCHEDULING -D_POSIX_PRIORITY_SCHEDULING -D_POSIX_TIMERS -D_POSIX_CPUTIME -D_POSIX_THREAD_CPUTIME -D_POSIX_MONOTONIC_CLOCK -D_POSIX_TIMEOUTS -D_POSIX_CLOCK_SELECTION -D_POSIX_THREAD_PRIO_PROTECT -D_UNIX98_THREAD_MUTEX_ATTRIBUTES -D_POSIX_READER_WRITER_LOCKS")
|
||||
endforeach()
|
||||
set(CMAKE_ASM_COMPILE_OBJECT "<CMAKE_ASM_COMPILER> <FLAGS> <INCLUDES> -c <SOURCE> -o <OBJECT>")
|
||||
|
||||
set(CMAKE_LINKER "${TOOLCHAIN_DIR}/aarch64-none-elf-ld" CACHE STRING "" FORCE)
|
||||
set(CMAKE_AR "${TOOLCHAIN_DIR}/aarch64-none-elf-ar" CACHE STRING "" FORCE)
|
||||
set(CMAKE_C_LINK_FLAGS "-r ")
|
||||
set(CMAKE_C_ARCHIVE_CREATE "<CMAKE_AR> -r <TARGET> <OBJECTS>")
|
||||
+22
@@ -37,4 +37,26 @@
|
||||
</platform>
|
||||
</project>
|
||||
</projects>
|
||||
<projects>
|
||||
<project cpu_type="raspi4">
|
||||
<lib_type>SRE</lib_type>
|
||||
<platform plat_name="armv8">
|
||||
<name>armv8</name>
|
||||
<compile_path_x86>/opt/buildtools/gcc-arm-10.3-2021.07-x86_64-aarch64-none-elf/bin</compile_path_x86>
|
||||
<compile_path_arm64>/opt/buildtools/gcc-arm-10.3-2021.07-x86_64-aarch64-none-elf/bin</compile_path_arm64>
|
||||
<kconf_dir>armv8_raspi4</kconf_dir>
|
||||
</platform>
|
||||
</project>
|
||||
</projects>
|
||||
<projects>
|
||||
<project cpu_type="hi3093">
|
||||
<lib_type>SRE</lib_type>
|
||||
<platform plat_name="armv8">
|
||||
<name>armv8</name>
|
||||
<compile_path_x86>/opt/buildtools/gcc-arm-10.3-2021.07-x86_64-aarch64-none-elf/bin</compile_path_x86>
|
||||
<compile_path_arm64>/opt/buildtools/gcc-arm-10.3-2021.07-x86_64-aarch64-none-elf/bin</compile_path_arm64>
|
||||
<kconf_dir>armv8_hi3093</kconf_dir>
|
||||
</platform>
|
||||
</project>
|
||||
</projects>
|
||||
</config>
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
cmake_minimum_required(VERSION 3.12)
|
||||
project(exmaples LANGUAGES C ASM CXX)
|
||||
|
||||
set(CMAKE_C_COMPILER ${TOOLCHAIN_PATH}/bin/arm-none-eabi-gcc)
|
||||
set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PATH}/bin/arm-none-eabi-g++)
|
||||
set(CMAKE_C_FLAGS "-g -O2 -mthumb -mcpu=cortex-m4 -std=gnu11 -fno-common -fomit-frame-pointer -mthumb -mcpu=cortex-m4 -mfloat-abi=softfp -mfpu=fpv4-sp-d16 -Wa,-mimplicit-it=thumb -fstack-protector-strong -funsigned-char -fdata-sections -ffunction-sections -fshort-enums")
|
||||
set(CMAKE_CXX_FLAGS "-mthumb -mcpu=cortex-m4 -fno-threadsafe-statics -fno-builtin -DEIGEN_NO_IO=1")
|
||||
set(CMAKE_ASM_COMPILER ${CMAKE_C_COMPILER})
|
||||
set(CMAKE_ASM_FLAGS ${CMAKE_C_FLAGS})
|
||||
|
||||
set(CXX_LIB ${TOOLCHAIN_PATH}/lib/gcc/arm-none-eabi/10.2.1/crti.o
|
||||
${TOOLCHAIN_PATH}/lib/gcc/arm-none-eabi/10.2.1/crtbegin.o
|
||||
${TOOLCHAIN_PATH}/arm-none-eabi/lib/crt0.o
|
||||
${TOOLCHAIN_PATH}/lib/gcc/arm-none-eabi/10.2.1/crtend.o
|
||||
${TOOLCHAIN_PATH}/lib/gcc/arm-none-eabi/10.2.1/crtn.o)
|
||||
|
||||
set(CMAKE_EXE_LINKER_FLAGS "-Wl,-EL -Wl,-d -Wl,-no-enum-size-warning -u _printf_float -nostartfiles -static -T ../examples.ld")
|
||||
|
||||
include_directories(./include ./config ./bsp)
|
||||
link_directories(./libs)
|
||||
link_libraries("${CMAKE_CURRENT_SOURCE_DIR}/libs/libCortexM4.a" "${CMAKE_CURRENT_SOURCE_DIR}/libs/libCortexMXsec_c.lib" "${CMAKE_CURRENT_SOURCE_DIR}/libs/libCortexM4.a" "${CMAKE_CURRENT_SOURCE_DIR}/libs/libCortexMXsec_c.lib")
|
||||
link_libraries(-lm -lc_nano -lnosys -lgcc)
|
||||
|
||||
add_subdirectory(bsp)
|
||||
add_subdirectory(config)
|
||||
add_subdirectory(apps)
|
||||
|
||||
list(APPEND OBJS $<TARGET_OBJECTS:apps> $<TARGET_OBJECTS:bsp> $<TARGET_OBJECTS:config>)
|
||||
add_executable(${APP} ${CXX_LIB} ${OBJS})
|
||||
@@ -0,0 +1,3 @@
|
||||
if(APP STREQUAL "helloworld")
|
||||
add_subdirectory(helloworld)
|
||||
endif()
|
||||
@@ -0,0 +1,2 @@
|
||||
set(SRCS main.c)
|
||||
add_library(apps OBJECT ${SRCS})
|
||||
@@ -0,0 +1,121 @@
|
||||
/*
|
||||
* Copyright (c) 2009-2022 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
*
|
||||
* UniProton is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
* http://license.coscl.org.cn/MulanPSL2
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PSL v2 for more details.
|
||||
* Create: 2009-12-22
|
||||
* Description: the uniproton helloworld demo
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdarg.h>
|
||||
#include "securec.h"
|
||||
#include "rtt_viewer.h"
|
||||
#include "prt_config.h"
|
||||
#include "prt_config_internal.h"
|
||||
#include "prt_clk.h"
|
||||
#include "test.h"
|
||||
|
||||
void helloworld_task(U32 uwParam1, U32 uParam2, U32 uwParam3, U32 uwParam4)
|
||||
{
|
||||
printf("hello world!\n");
|
||||
while (1) {
|
||||
PRT_TaskDelay(10);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
U32 PRT_AppInit(void)
|
||||
{
|
||||
U32 ret;
|
||||
TskHandle taskPid;
|
||||
struct TskInitParam stInitParam = {helloworld_task, 10, 0, {0}, 0x800, "TaskA", 0};
|
||||
|
||||
ret = PRT_TaskCreate(&taskPid, &stInitParam);
|
||||
if (ret) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = PRT_TaskResume(taskPid);
|
||||
if (ret) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
return OS_OK;
|
||||
}
|
||||
|
||||
U32 PRT_HardDrvInit(void)
|
||||
{
|
||||
RttViewerInit();
|
||||
RttViewerModeSet(0, RTT_VIEWER_MODE_BLOCK_IF_FIFO_FULL);
|
||||
|
||||
return OS_OK;
|
||||
}
|
||||
|
||||
U32 g_testRandStackProtect;
|
||||
void OsRandomSeedInit(void)
|
||||
{
|
||||
#if defined(OS_OPTION_RND)
|
||||
U32 ret;
|
||||
U32 seed;
|
||||
seed = PRT_ClkGetCycleCount64();
|
||||
g_testRandStackProtect = rand_r(&seed);
|
||||
ret = PRT_SysSetRndNum(OS_SYS_RND_STACK_PROTECT,g_testRandStackProtect);
|
||||
#endif
|
||||
}
|
||||
|
||||
extern U32 __data_start__;
|
||||
extern U32 __data_end__;
|
||||
extern U32 __text_end__;
|
||||
void OsGlobalDataInit(void)
|
||||
{
|
||||
U32 size;
|
||||
U32 *dest = (U32 *)&__data_start__;
|
||||
U32 *src = (U32 *)&__text_end__;
|
||||
U32 i;
|
||||
|
||||
size = (U32)&__data_end__ - (U32)&__data_start__;
|
||||
for (i = 0; i < (size / 4); i++) {
|
||||
dest[i] = src[i];
|
||||
}
|
||||
}
|
||||
|
||||
void PRT_HardBootInit(void)
|
||||
{
|
||||
OsGlobalDataInit();
|
||||
OsRandomSeedInit();
|
||||
}
|
||||
|
||||
U32 PRT_Printf(const char *format, ...)
|
||||
{
|
||||
va_list vaList;
|
||||
char buff[0x200] = { 0 };
|
||||
S32 count;
|
||||
U32 ret;
|
||||
|
||||
va_start(vaList, format);
|
||||
count = vsprintf_s(buff, 0x200, format, vaList);
|
||||
va_end(vaList);
|
||||
|
||||
if (count == -1) {
|
||||
return OS_ERROR;
|
||||
}
|
||||
|
||||
RttViewerWrite(0, buff, count);
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
S32 main(void)
|
||||
{
|
||||
return OsConfigStart();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* Copyright (c) 2009-2022 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
*
|
||||
* UniProton is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
* http://license.coscl.org.cn/MulanPSL2
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PSL v2 for more details.
|
||||
* Create: 2009-12-22
|
||||
* Description: the uniproton helloworld demo
|
||||
*/
|
||||
#include "prt_config.h"
|
||||
#include "prt_task.h"
|
||||
#include "prt_hwi.h"
|
||||
#include "prt_hook.h"
|
||||
#include "prt_exc.h"
|
||||
#include "prt_mem.h"
|
||||
|
||||
extern U32 PRT_Printf(const char *format, ...);
|
||||
#define printf PRT_Printf
|
||||
@@ -0,0 +1 @@
|
||||
请您参考example目录添加您的源代码,制作您的工程。如有疑问请联系华为对接工程师。
|
||||
@@ -0,0 +1,2 @@
|
||||
set(SRCS rtt_viewer.c)
|
||||
add_library(bsp OBJECT ${SRCS})
|
||||
@@ -0,0 +1,409 @@
|
||||
/*
|
||||
* Copyright (c) 2009-2022 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
*
|
||||
* UniProton is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
* http://license.coscl.org.cn/MulanPSL2
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PSL v2 for more details.
|
||||
* Create: 2009-12-22
|
||||
* Description: Hardware interrupt implementation
|
||||
*/
|
||||
#include "rtt_viewer.h"
|
||||
#include "prt_typedef.h"
|
||||
#include "prt_mem.h"
|
||||
#include "securec.h"
|
||||
|
||||
TagRttViewerCb _SEGGER_RTT;
|
||||
|
||||
/*
|
||||
* 描述: rtt viewer加锁
|
||||
*/
|
||||
static unsigned int RttViewerLock()
|
||||
{
|
||||
unsigned int lockState;
|
||||
OS_EMBED_ASM("mrs %0, basepri \n\t"
|
||||
"mov r1, %1 \n\t"
|
||||
"msr basepri, r1 \n\t"
|
||||
: "=r" (lockState) \
|
||||
: "i"(RTT_VIEWER_MAX_INT_PRI)
|
||||
: "r1", "cc"
|
||||
);
|
||||
|
||||
return lockState;
|
||||
}
|
||||
|
||||
/*
|
||||
* 描述: rtt viewer释放锁
|
||||
*/
|
||||
static void RttViewerUnlock(unsigned int lockSave)
|
||||
{
|
||||
OS_EMBED_ASM("msr basepri, %0 \n\t"
|
||||
:
|
||||
: "r" (lockSave)
|
||||
:
|
||||
);
|
||||
}
|
||||
|
||||
/*
|
||||
* 描述: rtt viewer初始化
|
||||
*/
|
||||
void RttViewerInit(void)
|
||||
{
|
||||
unsigned int idx;
|
||||
unsigned int size;
|
||||
unsigned char *wbuffer;
|
||||
unsigned char *rbuffer;
|
||||
|
||||
g_rttViewerCb.wbMaxNum = RTT_VIEWER_WB_MAX_NUM;
|
||||
g_rttViewerCb.rbMaxNum = RTT_VIEWER_RB_MAX_NUM;
|
||||
|
||||
/* rtt viewer写缓冲区资源申请 */
|
||||
size = RTT_VIEWER_WB_MAX_NUM * RTT_VIEWER_WB_BUFFER_SIZE;
|
||||
wbuffer = (unsigned char *)PRT_MemAlloc(0, OS_MEM_DEFAULT_FSC_PT, size);
|
||||
if ((wbuffer == NULL) || (memset_s(wbuffer, size, 0, size) != EOK)) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* rtt viewer写缓冲区初始化 */
|
||||
for (idx = 0; idx < RTT_VIEWER_WB_MAX_NUM; idx++) {
|
||||
g_rttViewerCb.aUp[idx].sName = "Terminal";
|
||||
g_rttViewerCb.aUp[idx].pBuffer = &wbuffer[idx * RTT_VIEWER_WB_BUFFER_SIZE];
|
||||
g_rttViewerCb.aUp[idx].size = RTT_VIEWER_WB_BUFFER_SIZE;
|
||||
g_rttViewerCb.aUp[idx].rIdx = 0;
|
||||
g_rttViewerCb.aUp[idx].wIdx = 0;
|
||||
g_rttViewerCb.aUp[idx].flags = RTT_VIEWER_MODE_DEFAULT;
|
||||
}
|
||||
|
||||
/* rtt viewer读缓冲区资源申请 */
|
||||
size = RTT_VIEWER_RB_MAX_NUM * RTT_VIEWER_RB_BUFFER_SIZE;
|
||||
rbuffer = (unsigned char *)PRT_MemAlloc(0, OS_MEM_DEFAULT_FSC_PT, size);
|
||||
if ((rbuffer == NULL) || (memset_s(rbuffer, size, 0, size) != EOK)) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* rtt viewer读缓冲区初始化 */
|
||||
for (idx = 0; idx < RTT_VIEWER_RB_MAX_NUM; idx++) {
|
||||
g_rttViewerCb.aDown[idx].sName = "Terminal";
|
||||
g_rttViewerCb.aDown[idx].pBuffer = &rbuffer[idx * RTT_VIEWER_RB_BUFFER_SIZE];
|
||||
g_rttViewerCb.aDown[idx].size = RTT_VIEWER_RB_BUFFER_SIZE;
|
||||
g_rttViewerCb.aDown[idx].rIdx = 0;
|
||||
g_rttViewerCb.aDown[idx].wIdx = 0;
|
||||
g_rttViewerCb.aDown[idx].flags = RTT_VIEWER_MODE_DEFAULT;
|
||||
}
|
||||
|
||||
/* 设置rtt viewer的id */
|
||||
strcpy((char *)&g_rttViewerCb.acID[0], "SEGGER");
|
||||
RTT_DMB();
|
||||
g_rttViewerCb.acID[6] = ' ';
|
||||
RTT_DMB();
|
||||
strcpy((char *)&g_rttViewerCb.acID[7], "RTT");
|
||||
RTT_DMB();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* 描述: rtt viewer写模式配置
|
||||
*/
|
||||
unsigned int RttViewerModeSet(unsigned int chn, unsigned int mode)
|
||||
{
|
||||
if ((mode > RTT_VIEWER_MODE_MASK) || (chn >= RTT_VIEWER_WB_MAX_NUM)) {
|
||||
return OS_ERROR;
|
||||
}
|
||||
|
||||
/* 设置模式 */
|
||||
g_rttViewerCb.aUp[chn].flags = mode;
|
||||
}
|
||||
|
||||
/*
|
||||
* 描述: 参数校验
|
||||
*/
|
||||
static unsigned int RttViewerWriteParaCheck(unsigned int chn, const void *buffer, unsigned int numBytes)
|
||||
{
|
||||
if (chn >= RTT_VIEWER_WB_MAX_NUM) {
|
||||
return OS_ERROR;
|
||||
}
|
||||
|
||||
if (buffer == NULL) {
|
||||
return OS_ERROR;
|
||||
}
|
||||
|
||||
if ((numBytes == 0) || (numBytes > RTT_VIEWER_WB_BUFFER_SIZE)) {
|
||||
return OS_ERROR;
|
||||
}
|
||||
|
||||
return OS_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* 描述: 获取可以写入环形缓冲区而不阻塞的字节数
|
||||
*/
|
||||
static unsigned int GetAvailWriteSpace(RTT_VIEWER_RING_BUFFER *ringBuffer) {
|
||||
unsigned int freeSize;
|
||||
|
||||
if (ringBuffer->rIdx <= ringBuffer->wIdx) {
|
||||
freeSize = ringBuffer->size - 1 - ringBuffer->wIdx + ringBuffer->rIdx;
|
||||
} else {
|
||||
freeSize = ringBuffer->rIdx - ringBuffer->wIdx - 1;
|
||||
}
|
||||
|
||||
return freeSize;
|
||||
}
|
||||
|
||||
/*
|
||||
* 描述: 环缓冲区中存储指定数量的字符
|
||||
*/
|
||||
static void RingBufferPush(RTT_VIEWER_RING_BUFFER *ringBuffer, const char *data, unsigned int numBytes)
|
||||
{
|
||||
unsigned int numBytesAtOnce;
|
||||
unsigned int wIdx;
|
||||
unsigned int rem;
|
||||
volatile char *dst;
|
||||
|
||||
wIdx = ringBuffer->wIdx;
|
||||
rem = ringBuffer->size - wIdx;
|
||||
dst = ringBuffer->pBuffer + wIdx;
|
||||
if (rem > numBytes) {
|
||||
memcpy_s((void*)dst, numBytes, data, numBytes);
|
||||
RTT_DMB();
|
||||
ringBuffer->wIdx = wIdx + numBytes;
|
||||
} else {
|
||||
numBytesAtOnce = rem;
|
||||
memcpy_s((void*)dst, numBytesAtOnce, data, numBytesAtOnce);
|
||||
numBytesAtOnce = numBytes - rem;
|
||||
|
||||
if (numBytesAtOnce > 0) {
|
||||
dst = ringBuffer->pBuffer;
|
||||
memcpy_s((void*)dst, numBytesAtOnce, data + rem, numBytesAtOnce);
|
||||
RTT_DMB();
|
||||
}
|
||||
ringBuffer->wIdx = numBytesAtOnce;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* 描述: 环缓冲区中存储指定数量的字符,数据长度可以
|
||||
*/
|
||||
static unsigned int RingBufferBlockPush(RTT_VIEWER_RING_BUFFER *ringBuffer, const char *buffer, unsigned int numBytes) {
|
||||
unsigned int numBytesToWrite;
|
||||
unsigned int numBytesWritten;
|
||||
unsigned int rIdx;
|
||||
unsigned int wIdx;
|
||||
volatile char *dst;
|
||||
|
||||
numBytesWritten = 0;
|
||||
wIdx = ringBuffer->wIdx;
|
||||
do {
|
||||
rIdx = ringBuffer->rIdx;
|
||||
if (rIdx > wIdx) {
|
||||
numBytesToWrite = rIdx - wIdx - 1u;
|
||||
} else {
|
||||
numBytesToWrite = ringBuffer->size - (wIdx - rIdx + 1u);
|
||||
}
|
||||
|
||||
numBytesToWrite = MIN(numBytesToWrite, (ringBuffer->size - wIdx));
|
||||
numBytesToWrite = MIN(numBytesToWrite, numBytes);
|
||||
dst = ringBuffer->pBuffer + wIdx;
|
||||
memcpy_s((void*)dst, numBytesToWrite, buffer, numBytesToWrite);
|
||||
|
||||
numBytesWritten += numBytesToWrite;
|
||||
buffer += numBytesToWrite;
|
||||
numBytes -= numBytesToWrite;
|
||||
wIdx += numBytesToWrite;
|
||||
if (wIdx == ringBuffer->size) {
|
||||
wIdx = 0;
|
||||
}
|
||||
RTT_DMB();
|
||||
ringBuffer->wIdx = wIdx;
|
||||
} while (numBytes);
|
||||
|
||||
return numBytesWritten;
|
||||
}
|
||||
|
||||
/*
|
||||
* 描述: rtt viewer写数据
|
||||
*/
|
||||
unsigned int RttViewerWrite(unsigned int chn, const void *buffer, unsigned int numBytes)
|
||||
{
|
||||
unsigned int ret;
|
||||
unsigned int intSave;
|
||||
unsigned int freeSize;
|
||||
unsigned int writeBytes;
|
||||
RTT_VIEWER_RING_BUFFER *wRingBuffer;
|
||||
|
||||
if (memcmp(g_rttViewerCb.acID, "SEGGER RTT", sizeof("SEGGER RTT")) != 0) {
|
||||
return OS_ERROR;
|
||||
}
|
||||
|
||||
/* 校验入参 */
|
||||
ret = RttViewerWriteParaCheck(chn, buffer, numBytes);
|
||||
if (ret != OS_OK) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
intSave = RttViewerLock();
|
||||
|
||||
wRingBuffer = &g_rttViewerCb.aUp[chn];
|
||||
|
||||
switch (wRingBuffer->flags) {
|
||||
case RTT_VIEWER_MODE_NO_BLOCK_SKIP:
|
||||
freeSize = GetAvailWriteSpace(wRingBuffer);
|
||||
if (freeSize >= numBytes) {
|
||||
RingBufferPush(wRingBuffer, buffer, numBytes);
|
||||
}
|
||||
break;
|
||||
|
||||
case RTT_VIEWER_MODE_NO_BLOCK_TRIM:
|
||||
freeSize = GetAvailWriteSpace(wRingBuffer);
|
||||
RingBufferPush(wRingBuffer, buffer, MIN(freeSize, numBytes));
|
||||
break;
|
||||
|
||||
case RTT_VIEWER_MODE_BLOCK_IF_FIFO_FULL:
|
||||
writeBytes = RingBufferBlockPush(wRingBuffer, buffer, numBytes);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
RttViewerUnlock(intSave);
|
||||
|
||||
return OS_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* 描述: 参数校验
|
||||
*/
|
||||
unsigned int RttViewerReadParaCheck(unsigned int chn, const void *buffer, unsigned int numBytes)
|
||||
{
|
||||
if (chn >= RTT_VIEWER_RB_MAX_NUM) {
|
||||
return OS_ERROR;
|
||||
}
|
||||
|
||||
if (buffer == NULL) {
|
||||
return OS_ERROR;
|
||||
}
|
||||
|
||||
if ((numBytes == 0) || (numBytes > RTT_VIEWER_RB_BUFFER_SIZE)) {
|
||||
return OS_ERROR;
|
||||
}
|
||||
|
||||
return OS_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* 描述: rtt viewer读数据
|
||||
*/
|
||||
unsigned int RttViewerRead(unsigned int chn, void *buffer, unsigned int numBytes)
|
||||
{
|
||||
unsigned int ret;
|
||||
unsigned int intSave;
|
||||
unsigned int numBytesRem;
|
||||
unsigned int numBytesRead;
|
||||
unsigned int rIdx;
|
||||
unsigned int wIdx;
|
||||
volatile char *src;
|
||||
RTT_VIEWER_RING_BUFFER *rRingBuffer;
|
||||
|
||||
if (memcmp(g_rttViewerCb.acID, "SEGGER RTT", sizeof("SEGGER RTT")) != 0) {
|
||||
return OS_ERROR;
|
||||
}
|
||||
|
||||
/* 校验入参 */
|
||||
ret = RttViewerReadParaCheck(chn, buffer, numBytes);
|
||||
if (ret != OS_OK) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
intSave = RttViewerLock();
|
||||
|
||||
rRingBuffer = &g_rttViewerCb.aDown[chn];
|
||||
rIdx = rRingBuffer->rIdx;
|
||||
wIdx = rRingBuffer->wIdx;
|
||||
numBytesRead = 0u;
|
||||
|
||||
if (rIdx > wIdx) {
|
||||
numBytesRem = rRingBuffer->size - rIdx;
|
||||
numBytesRem = MIN(numBytesRem, numBytes);
|
||||
src = rRingBuffer->pBuffer + rIdx;
|
||||
memcpy_s(buffer, numBytesRem, (void*)src, numBytesRem);
|
||||
|
||||
numBytesRead += numBytesRem;
|
||||
buffer += numBytesRem;
|
||||
numBytes -= numBytesRem;
|
||||
rIdx += numBytesRem;
|
||||
if (rIdx == rRingBuffer->size) {
|
||||
rIdx = 0u;
|
||||
}
|
||||
}
|
||||
|
||||
numBytesRem = wIdx - rIdx;
|
||||
numBytesRem = MIN(numBytesRem, numBytes);
|
||||
if (numBytesRem > 0) {
|
||||
src = rRingBuffer->pBuffer + rIdx;
|
||||
memcpy_s(buffer, numBytesRem, (void*)src, numBytesRem);
|
||||
|
||||
numBytesRead += numBytesRem;
|
||||
buffer += numBytesRem;
|
||||
numBytes -= numBytesRem;
|
||||
rIdx += numBytesRem;
|
||||
}
|
||||
|
||||
if (numBytesRead) {
|
||||
rRingBuffer->rIdx = rIdx;
|
||||
}
|
||||
|
||||
RttViewerUnlock(intSave);
|
||||
|
||||
return numBytesRead;
|
||||
}
|
||||
|
||||
/*
|
||||
* 描述: rtt viewer输出单个字符
|
||||
*/
|
||||
unsigned int RttViewerPutChar(unsigned int chn, char c)
|
||||
{
|
||||
unsigned int ret;
|
||||
|
||||
if (chn >= RTT_VIEWER_WB_MAX_NUM) {
|
||||
return OS_ERROR;
|
||||
}
|
||||
|
||||
ret = RttViewerWrite(chn, &c, 1);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
char g_rttViewerShowBuffer[RTT_VIEWER_MAX_SHOW_LEN];
|
||||
|
||||
/*
|
||||
* 描述: rtt viewer打印函数
|
||||
*/
|
||||
unsigned int RttViewerPrintf(unsigned int chn, const char *format, ...)
|
||||
{
|
||||
unsigned int ret;
|
||||
int len;
|
||||
char *str = g_rttViewerShowBuffer;
|
||||
va_list vaList;
|
||||
|
||||
if (chn >= RTT_VIEWER_WB_MAX_NUM) {
|
||||
return OS_ERROR;
|
||||
}
|
||||
|
||||
va_start(vaList, format);
|
||||
len = vsnprintf_s(str, RTT_VIEWER_MAX_SHOW_LEN, RTT_VIEWER_MAX_SHOW_LEN, format, vaList);
|
||||
va_end(vaList);
|
||||
if (len == -1) {
|
||||
return len;
|
||||
}
|
||||
|
||||
ret = RttViewerWrite(chn, str, len);
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -0,0 +1,134 @@
|
||||
/*
|
||||
* Copyright (c) 2009-2022 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
*
|
||||
* UniProton is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
* http://license.coscl.org.cn/MulanPSL2
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PSL v2 for more details.
|
||||
* Create: 2009-12-22
|
||||
* Description: Hardware interrupt implementation
|
||||
*/
|
||||
#ifndef RTT_VIEWER_H
|
||||
#define RTT_VIEWER_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#define RTT_VIEWER_MODE_NO_BLOCK_SKIP 0
|
||||
#define RTT_VIEWER_MODE_NO_BLOCK_TRIM 1
|
||||
#define RTT_VIEWER_MODE_BLOCK_IF_FIFO_FULL 2
|
||||
#define RTT_VIEWER_MODE_MASK 3
|
||||
|
||||
#ifndef RTT_VIEWER_MODE_DEFAULT
|
||||
#define RTT_VIEWER_MODE_DEFAULT RTT_VIEWER_MODE_NO_BLOCK_SKIP
|
||||
#endif
|
||||
|
||||
#ifndef RTT_VIEWER_WB_MAX_NUM
|
||||
#define RTT_VIEWER_WB_MAX_NUM 1
|
||||
#endif
|
||||
|
||||
#ifndef RTT_VIEWER_RB_MAX_NUM
|
||||
#define RTT_VIEWER_RB_MAX_NUM 1
|
||||
#endif
|
||||
|
||||
#ifndef RTT_VIEWER_WB_BUFFER_SIZE
|
||||
#define RTT_VIEWER_WB_BUFFER_SIZE 1024
|
||||
#endif
|
||||
|
||||
#ifndef RTT_VIEWER_RB_BUFFER_SIZE
|
||||
#define RTT_VIEWER_RB_BUFFER_SIZE 16
|
||||
#endif
|
||||
|
||||
#ifndef RTT_VIEWER_MAX_INT_PRI
|
||||
#define RTT_VIEWER_MAX_INT_PRI 0x20
|
||||
#endif
|
||||
|
||||
#ifndef RTT_VIEWER_MAX_SHOW_LEN
|
||||
#define RTT_VIEWER_MAX_SHOW_LEN 0x200
|
||||
#endif
|
||||
|
||||
#define RTT_DMB() __asm volatile ("dmb\n" : : :);
|
||||
|
||||
#define RTT_VIEWER_CTRL_RESET "\x1B[0m"
|
||||
#define RTT_VIEWER_CTRL_CLEAR "\x1B[2J"
|
||||
|
||||
#define RTT_VIEWER_CTRL_TEXT_BLACK "\x1B[2;30m"
|
||||
#define RTT_VIEWER_CTRL_TEXT_RED "\x1B[2;31m"
|
||||
#define RTT_VIEWER_CTRL_TEXT_GREEN "\x1B[2;32m"
|
||||
#define RTT_VIEWER_CTRL_TEXT_YELLOW "\x1B[2;33m"
|
||||
#define RTT_VIEWER_CTRL_TEXT_BLUE "\x1B[2;34m"
|
||||
#define RTT_VIEWER_CTRL_TEXT_MAGENTA "\x1B[2;35m"
|
||||
#define RTT_VIEWER_CTRL_TEXT_CYAN "\x1B[2;36m"
|
||||
#define RTT_VIEWER_CTRL_TEXT_WHITE "\x1B[2;37m"
|
||||
|
||||
#define RTT_VIEWER_CTRL_TEXT_BRIGHT_BLACK "\x1B[1;30m"
|
||||
#define RTT_VIEWER_CTRL_TEXT_BRIGHT_RED "\x1B[1;31m"
|
||||
#define RTT_VIEWER_CTRL_TEXT_BRIGHT_GREEN "\x1B[1;32m"
|
||||
#define RTT_VIEWER_CTRL_TEXT_BRIGHT_YELLOW "\x1B[1;33m"
|
||||
#define RTT_VIEWER_CTRL_TEXT_BRIGHT_BLUE "\x1B[1;34m"
|
||||
#define RTT_VIEWER_CTRL_TEXT_BRIGHT_MAGENTA "\x1B[1;35m"
|
||||
#define RTT_VIEWER_CTRL_TEXT_BRIGHT_CYAN "\x1B[1;36m"
|
||||
#define RTT_VIEWER_CTRL_TEXT_BRIGHT_WHITE "\x1B[1;37m"
|
||||
|
||||
#define RTT_VIEWER_CTRL_BG_BLACK "\x1B[24;40m"
|
||||
#define RTT_VIEWER_CTRL_BG_RED "\x1B[24;41m"
|
||||
#define RTT_VIEWER_CTRL_BG_GREEN "\x1B[24;42m"
|
||||
#define RTT_VIEWER_CTRL_BG_YELLOW "\x1B[24;43m"
|
||||
#define RTT_VIEWER_CTRL_BG_BLUE "\x1B[24;44m"
|
||||
#define RTT_VIEWER_CTRL_BG_MAGENTA "\x1B[24;45m"
|
||||
#define RTT_VIEWER_CTRL_BG_CYAN "\x1B[24;46m"
|
||||
#define RTT_VIEWER_CTRL_BG_WHITE "\x1B[24;47m"
|
||||
|
||||
#define RTT_VIEWER_CTRL_BG_BRIGHT_BLACK "\x1B[4;40m"
|
||||
#define RTT_VIEWER_CTRL_BG_BRIGHT_RED "\x1B[4;41m"
|
||||
#define RTT_VIEWER_CTRL_BG_BRIGHT_GREEN "\x1B[4;42m"
|
||||
#define RTT_VIEWER_CTRL_BG_BRIGHT_YELLOW "\x1B[4;43m"
|
||||
#define RTT_VIEWER_CTRL_BG_BRIGHT_BLUE "\x1B[4;44m"
|
||||
#define RTT_VIEWER_CTRL_BG_BRIGHT_MAGENTA "\x1B[4;45m"
|
||||
#define RTT_VIEWER_CTRL_BG_BRIGHT_CYAN "\x1B[4;46m"
|
||||
#define RTT_VIEWER_CTRL_BG_BRIGHT_WHITE "\x1B[4;47m"
|
||||
|
||||
#define MIN(a, b) ((a) < (b) ? (a) : (b))
|
||||
#define MAX(a, b) ((a) > (b) ? (a) : (b))
|
||||
|
||||
/*
|
||||
* rtt viewer环形缓冲区
|
||||
*/
|
||||
typedef struct {
|
||||
const char *sName;
|
||||
char *pBuffer;
|
||||
unsigned int size;
|
||||
unsigned int wIdx;
|
||||
volatile unsigned int rIdx;
|
||||
unsigned int flags;
|
||||
} RTT_VIEWER_RING_BUFFER;
|
||||
|
||||
typedef struct {
|
||||
char acID[16];
|
||||
int wbMaxNum;
|
||||
int rbMaxNum;
|
||||
RTT_VIEWER_RING_BUFFER aUp[RTT_VIEWER_WB_MAX_NUM];
|
||||
RTT_VIEWER_RING_BUFFER aDown[RTT_VIEWER_RB_MAX_NUM];
|
||||
} TagRttViewerCb;
|
||||
|
||||
extern TagRttViewerCb _SEGGER_RTT;
|
||||
#define g_rttViewerCb _SEGGER_RTT
|
||||
|
||||
void RttViewerInit(void);
|
||||
unsigned int RttViewerModeSet(unsigned int chn, unsigned int mode);
|
||||
unsigned int RttViewerWrite(unsigned int chn, const void *buffer, unsigned int numBytes);
|
||||
unsigned int RttViewerRead(unsigned int chn, void *buffer, unsigned int numBytes);
|
||||
unsigned int RttViewerPutChar(unsigned int chn, char c);
|
||||
unsigned int RttViewerPrintf(unsigned int chn, const char *format, ...);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* RTT_VIEWER_H */
|
||||
@@ -0,0 +1,24 @@
|
||||
#!/bin/bash
|
||||
# Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
# UniProton is licensed under Mulan PSL v2.
|
||||
# You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
# You may obtain a copy of Mulan PSL v2 at:
|
||||
# http://license.coscl.org.cn/MulanPSL2
|
||||
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
# EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
# MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
# See the Mulan PSL v2 for more details.
|
||||
|
||||
export TOOLCHAIN_PATH=/opt/buildtools/gcc-arm-none-eabi-10-2020-q4-major
|
||||
export APP=helloworld
|
||||
export TMP_DIR=$APP
|
||||
|
||||
sh ./build_static.sh
|
||||
|
||||
cmake -S .. -B $TMP_DIR -DAPP:STRING=$APP -DTOOLCHAIN_PATH:STRING=$TOOLCHAIN_PATH
|
||||
pushd $TMP_DIR
|
||||
make $APP
|
||||
popd
|
||||
cp $TMP_DIR/$APP $APP.elf
|
||||
$TOOLCHAIN_PATH/bin/arm-none-eabi-objcopy -O binary $TMP_DIR/$APP $APP.bin
|
||||
rm -rf $TMP_DIR
|
||||
@@ -0,0 +1,24 @@
|
||||
#!/bin/bash
|
||||
# Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
# UniProton is licensed under Mulan PSL v2.
|
||||
# You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
# You may obtain a copy of Mulan PSL v2 at:
|
||||
# http://license.coscl.org.cn/MulanPSL2
|
||||
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
# EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
# MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
# See the Mulan PSL v2 for more details.
|
||||
|
||||
git clone https://gitee.com/openeuler/libboundscheck.git
|
||||
|
||||
cp libboundscheck/include/* ../../../platform/libboundscheck/include
|
||||
cp libboundscheck/include/* ../include
|
||||
cp libboundscheck/src/* ../../../platform/libboundscheck/src
|
||||
rm -rf libboundscheck
|
||||
|
||||
pushd ./../../../
|
||||
python build.py m4
|
||||
cp output/UniProton/lib/cortex_m4/* demos/helloworld/libs
|
||||
cp output/libboundscheck/lib/cortex_m4/* demos/helloworld/libs
|
||||
cp -r src/include/uapi/* demos/helloworld/include
|
||||
popd
|
||||
@@ -0,0 +1,76 @@
|
||||
/***********************************************************/
|
||||
/* Configure memory regions */
|
||||
MEMORY
|
||||
{
|
||||
IROM (rwx) : ORIGIN = 0x08000000, LENGTH = 0x00100000
|
||||
SRAM (rwx) : ORIGIN = 0x20000000, LENGTH = 0x0001A000
|
||||
SYSSTACK (rwx) : ORIGIN = 0x2001A000, LENGTH = 0x2000
|
||||
}
|
||||
|
||||
ENTRY(OsResetVector)
|
||||
|
||||
SECTIONS
|
||||
{
|
||||
.resetzone :
|
||||
{
|
||||
__text_section_start = .;
|
||||
KEEP(*(.reset))
|
||||
} > IROM
|
||||
|
||||
.text :
|
||||
{
|
||||
. = ALIGN(4);
|
||||
__text_start__ = .;
|
||||
*(.text*)
|
||||
*(.rodata*)
|
||||
*(.kernel*)
|
||||
*(.rel*)
|
||||
} > IROM
|
||||
|
||||
.ARM.exidx :
|
||||
{
|
||||
*(.ARM.exidx* .gnu.linkonce.armexidx.*)
|
||||
. = ALIGN(4);
|
||||
} > IROM
|
||||
|
||||
.data : AT(LOADADDR(.ARM.exidx) + SIZEOF(.ARM.exidx))
|
||||
{
|
||||
__text_end__ = LOADADDR(.data);
|
||||
__data_start__ = .;
|
||||
KEEP(*(VECTOR))
|
||||
*(vtable)
|
||||
*(.data*)
|
||||
. = ALIGN(4);
|
||||
__data_end__ = .;
|
||||
} > SRAM
|
||||
|
||||
.bss :
|
||||
{
|
||||
. = ALIGN(4);
|
||||
__bss_start__ = .;
|
||||
g_bssStart = .;
|
||||
*(.bss*)
|
||||
*(COMMON)
|
||||
. = ALIGN(4);
|
||||
__bss_end__ = .;
|
||||
g_bssEnd = .;
|
||||
} > SRAM
|
||||
|
||||
.osStack :
|
||||
{
|
||||
g_stackStart = .;
|
||||
. = . + 0x2000;
|
||||
g_stackEnd = .;
|
||||
} > SYSSTACK
|
||||
|
||||
.heap (COPY):
|
||||
{
|
||||
__end__ = .;
|
||||
end = __end__;
|
||||
*(.heap*)
|
||||
__HeapLimit = .;
|
||||
} > SYSSTACK
|
||||
}
|
||||
|
||||
/***********************************************************/
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
本目录中的build_app.sh可以构建出/../apps中的示例镜像:
|
||||
1、在sh中选择/更改EXAMPLE的工程目录名(helloworld),默认使用helloworld
|
||||
2、将编译工具的路径和编译工具的静态库路径配置正确,编译工具在compiler目录取出安装使用;
|
||||
@@ -0,0 +1,2 @@
|
||||
set(SRCS prt_config.c)
|
||||
add_library(config OBJECT ${SRCS})
|
||||
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
* Copyright (c) 2009-2022 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
*
|
||||
* UniProton is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
* http://license.coscl.org.cn/MulanPSL2
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PSL v2 for more details.
|
||||
* Create: 2009-12-22
|
||||
* Description: the common part buildef.h
|
||||
*/
|
||||
#ifndef PRT_BUILDEF_H
|
||||
#define PRT_BUILDEF_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define OS_ARCH_ARMV7_M
|
||||
|
||||
#ifndef OS_HARDWARE_PLATFORM
|
||||
#define OS_HARDWARE_PLATFORM OS_CORTEX_M4
|
||||
#endif
|
||||
|
||||
#ifndef OS_CPU_TYPE
|
||||
#define OS_CPU_TYPE OS_STM32F407
|
||||
#endif
|
||||
|
||||
#define OS_MAX_CORE_NUM 1
|
||||
|
||||
#ifndef OS_BYTE_ORDER
|
||||
#define OS_BYTE_ORDER OS_LITTLE_ENDIAN
|
||||
#endif
|
||||
|
||||
#define OS_OPTION_EVENT
|
||||
|
||||
#define OS_OPTION_QUEUE
|
||||
|
||||
#define OS_OPTION_HWI_COMBINE
|
||||
|
||||
#define OS_OPTION_HWI_PRIORITY
|
||||
|
||||
#define OS_OPTION_HWI_ATTRIBUTE
|
||||
|
||||
#define OS_OPTION_HWI_MAX_NUM_CONFIG
|
||||
|
||||
#define OS_OPTION_TASK
|
||||
|
||||
#define OS_OPTION_TASK_DELETE
|
||||
|
||||
#define OS_OPTION_TASK_SUSPEND
|
||||
|
||||
#define OS_OPTION_TASK_INFO
|
||||
|
||||
#define OS_OPTION_TASK_YIELD
|
||||
|
||||
#define OS_TSK_PRIORITY_HIGHEST 0
|
||||
|
||||
#define OS_TSK_PRIORITY_LOWEST 31
|
||||
|
||||
#define OS_TSK_NUM_OF_PRIORITIES 32
|
||||
|
||||
#define OS_TSK_CORE_BYTES_IN_PID 2
|
||||
|
||||
#define OS_OPTION_CPUP
|
||||
|
||||
#define OS_OPTION_CPUP_WARN
|
||||
|
||||
#define OS_OPTION_RND
|
||||
|
||||
#define OS_LITTLE_ENDIAN 0x1234
|
||||
|
||||
#define OS_BIG_ENDIAN 0x4321
|
||||
|
||||
#define OS_CORTEX_M4 0x1
|
||||
|
||||
#define OS_STM32F407 0x1
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,313 @@
|
||||
/*
|
||||
* Copyright (c) 2009-2022 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
*
|
||||
* UniProton is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
* http://license.coscl.org.cn/MulanPSL2
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PSL v2 for more details.
|
||||
* Create: 2009-12-22
|
||||
* Description: UniProton的初始化C文件。
|
||||
*/
|
||||
#include "prt_config_internal.h"
|
||||
|
||||
U8 m_aucMemRegion00[OS_MEM_FSC_PT_SIZE] ; /* 私有静态内存分区(缺省) */
|
||||
|
||||
OS_SEC_ALW_INLINE INLINE void OsConfigAddrSizeGet(uintptr_t addr, uintptr_t size,
|
||||
uintptr_t *destAddr, uintptr_t *destSize)
|
||||
{
|
||||
*destAddr = addr;
|
||||
*destSize = size;
|
||||
}
|
||||
|
||||
U32 OsMemConfigReg(void)
|
||||
{
|
||||
U32 ret;
|
||||
|
||||
ret = OsFscMemInit(OS_MEM_FSC_PT_ADDR, OS_MEM_FSC_PT_SIZE);
|
||||
if (ret != OS_OK) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
return OS_OK;
|
||||
}
|
||||
|
||||
U32 OsMemDefPtInit(void)
|
||||
{
|
||||
return OS_OK;
|
||||
}
|
||||
|
||||
U32 OsMemConfigInit(void)
|
||||
{
|
||||
/* 系统默认FSC内存分区初始化 */
|
||||
return OsMemDefPtInit();
|
||||
}
|
||||
|
||||
U32 OsSystemReg(void)
|
||||
{
|
||||
struct SysModInfo sysModInfo;
|
||||
|
||||
sysModInfo.systemClock = OS_SYS_CLOCK;
|
||||
sysModInfo.cpuType = OS_CPU_TYPE;
|
||||
#if defined(OS_OPTION_HWI_MAX_NUM_CONFIG)
|
||||
sysModInfo.hwiMaxNum = OS_HWI_MAX_NUM_CONFIG;
|
||||
#endif
|
||||
|
||||
return OsSysRegister(&sysModInfo);
|
||||
}
|
||||
|
||||
#if (OS_INCLUDE_SEM == YES)
|
||||
U32 OsSemConfigReg(void)
|
||||
{
|
||||
struct SemModInfo semModInfo;
|
||||
|
||||
semModInfo.maxNum = OS_SEM_MAX_SUPPORT_NUM;
|
||||
return OsSemRegister(&semModInfo);
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
#if (OS_INCLUDE_TASK == YES)
|
||||
void OsTaskInfoSet(struct TskModInfo *taskModInfo)
|
||||
{
|
||||
taskModInfo->maxNum = OS_TSK_MAX_SUPPORT_NUM;
|
||||
taskModInfo->defaultSize = OS_TSK_DEFAULT_STACK_SIZE;
|
||||
taskModInfo->idleStackSize = OS_TSK_IDLE_STACK_SIZE;
|
||||
taskModInfo->magicWord = WORD_PACK((U32)OS_TSK_STACK_MAGIC_WORD);
|
||||
}
|
||||
#else
|
||||
#error "OS_INCLUDE_TASK MUST BE YES! The SWI has been cut out,the task can not cut out."
|
||||
#endif
|
||||
|
||||
U32 OsHookConfigReg(void)
|
||||
{
|
||||
struct HookModInfo hookModInfo;
|
||||
|
||||
hookModInfo.maxNum[OS_HOOK_HWI_ENTRY] = OS_HOOK_HWI_ENTRY_NUM;
|
||||
hookModInfo.maxNum[OS_HOOK_HWI_EXIT] = OS_HOOK_HWI_EXIT_NUM;
|
||||
hookModInfo.maxNum[OS_HOOK_TSK_SWITCH] = OS_HOOK_TSK_SWITCH_NUM;
|
||||
hookModInfo.maxNum[OS_HOOK_IDLE_PERIOD] = OS_HOOK_IDLE_NUM;
|
||||
|
||||
return OsHookRegister(&hookModInfo);
|
||||
}
|
||||
|
||||
U32 OsSysConfigReg(void)
|
||||
{
|
||||
U32 ret;
|
||||
|
||||
ret = OsSystemReg();
|
||||
if (ret != OS_OK) {
|
||||
return ret;
|
||||
}
|
||||
return OS_OK;
|
||||
}
|
||||
|
||||
#if (OS_INCLUDE_TICK == YES)
|
||||
U32 OsTickConfigReg(void)
|
||||
{
|
||||
struct TickModInfo tickModInfo;
|
||||
|
||||
tickModInfo.tickPerSecond = OS_TICK_PER_SECOND;
|
||||
tickModInfo.tickPriority = 0;
|
||||
|
||||
return OsTickRegister(&tickModInfo);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if (OS_INCLUDE_TASK == YES)
|
||||
U32 OsTskConfigReg(void)
|
||||
{
|
||||
struct TskModInfo taskModInfo;
|
||||
OsTaskInfoSet(&taskModInfo);
|
||||
return OsTskRegister(&taskModInfo);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if (OS_INCLUDE_QUEUE == YES)
|
||||
U32 OsQueueConfigReg(void)
|
||||
{
|
||||
return OsQueueRegister(OS_QUEUE_MAX_SUPPORT_NUM);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if (OS_INCLUDE_CPUP == YES)
|
||||
U32 OsCpupConfigReg(void)
|
||||
{
|
||||
struct CpupModInfo cpupModInfo;
|
||||
|
||||
cpupModInfo.cpupWarnFlag = (bool)OS_CONFIG_CPUP_WARN;
|
||||
cpupModInfo.sampleTime = OS_CPUP_SAMPLE_INTERVAL;
|
||||
cpupModInfo.warn = OS_CPUP_SHORT_WARN;
|
||||
cpupModInfo.resume = OS_CPUP_SHORT_RESUME;
|
||||
|
||||
return OsCpupRegister(&cpupModInfo);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if (OS_INCLUDE_TICK_SWTMER == YES)
|
||||
U32 OsSwTmrConfigInit(void)
|
||||
{
|
||||
return OsSwTmrInit(OS_TICK_SWITIMER_MAX_NUM);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if (OS_INCLUDE_CPUP == YES)
|
||||
#if (OS_INCLUDE_TICK == NO)
|
||||
#error "OS_INCLUDE_CPUP depend on OS_INCLUDE_TICK!"
|
||||
#endif
|
||||
U32 OsCpupConfigInit(void)
|
||||
{
|
||||
U32 ret;
|
||||
|
||||
ret = OsCpupInit();
|
||||
if (ret != OS_OK) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (OS_CONFIG_CPUP_WARN == YES) {
|
||||
#if defined(OS_OPTION_CPUP_WARN)
|
||||
OsCpupWarnInit();
|
||||
#else
|
||||
return OS_ERRNO_SYS_NO_CPUP_WARN;
|
||||
#endif
|
||||
}
|
||||
return OS_OK;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if (OS_INCLUDE_SEM == YES)
|
||||
U32 OsSemConfigInit(void)
|
||||
{
|
||||
return OsSemInit();
|
||||
}
|
||||
#endif
|
||||
|
||||
#if (OS_INCLUDE_TASK == YES)
|
||||
U32 OsTskConfigInit(void)
|
||||
{
|
||||
return OsTskInit();
|
||||
}
|
||||
#endif
|
||||
|
||||
/* 系统初始化注册表 */
|
||||
struct OsModuleConfigInfo g_moduleConfigTab[] = {
|
||||
/* {模块号, 模块注册函数, 模块初始化函数} */
|
||||
{OS_MID_SYS, {OsSysConfigReg, NULL}},
|
||||
{OS_MID_MEM, {OsMemConfigReg, OsMemConfigInit}},
|
||||
{OS_MID_HWI, {NULL, OsHwiConfigInit}},
|
||||
{OS_MID_HARDDRV, {NULL, PRT_HardDrvInit}},
|
||||
{OS_MID_HOOK, {OsHookConfigReg, OsHookConfigInit}},
|
||||
{OS_MID_EXC, {NULL, OsExcConfigInit}},
|
||||
#if (OS_INCLUDE_TASK == YES)
|
||||
{OS_MID_TSK, {OsTskConfigReg, OsTskConfigInit}},
|
||||
#endif
|
||||
#if (OS_INCLUDE_TICK == YES)
|
||||
{OS_MID_TICK, {OsTickConfigReg, OsTickConfigInit}},
|
||||
#endif
|
||||
|
||||
#if (OS_INCLUDE_TICK_SWTMER == YES)
|
||||
{OS_MID_SWTMR, {NULL, OsSwTmrConfigInit}},
|
||||
#endif
|
||||
|
||||
#if (OS_INCLUDE_CPUP == YES)
|
||||
{OS_MID_CPUP, {OsCpupConfigReg, OsCpupConfigInit}},
|
||||
#endif
|
||||
#if (OS_INCLUDE_SEM == YES)
|
||||
{OS_MID_SEM, {OsSemConfigReg, OsSemConfigInit}},
|
||||
#endif
|
||||
#if (OS_INCLUDE_QUEUE == YES)
|
||||
{OS_MID_QUEUE, {OsQueueConfigReg, OsQueueConfigInit}},
|
||||
#endif
|
||||
{OS_MID_APP, {NULL, PRT_AppInit}},
|
||||
|
||||
{OS_MID_BUTT, {NULL, NULL}},
|
||||
};
|
||||
|
||||
/*
|
||||
* 描述:OS模块注册、初始化运行函数
|
||||
*/
|
||||
U32 OsModuleConfigRun(enum OsinitPhaseId initPhaseId, U32 initPhase)
|
||||
{
|
||||
U32 idx = 0;
|
||||
U32 ret = OS_OK;
|
||||
while (g_moduleConfigTab[idx].moudleId != OS_MID_BUTT) {
|
||||
if (g_moduleConfigTab[idx].moudleConfigFunc[initPhaseId] == NULL) {
|
||||
idx++;
|
||||
continue;
|
||||
}
|
||||
ret = g_moduleConfigTab[idx].moudleConfigFunc[initPhaseId]();
|
||||
if (ret != OS_OK) {
|
||||
break;
|
||||
}
|
||||
idx++;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
U32 OsRegister(void)
|
||||
{
|
||||
return OsModuleConfigRun(OS_REGISTER_ID, OS_REGISTER_PHASE);
|
||||
}
|
||||
|
||||
/*
|
||||
* 描述:OsInitialize阶段
|
||||
*/
|
||||
U32 OsInitialize(void)
|
||||
{
|
||||
return OsModuleConfigRun(OS_INIT_ID, OS_INITIALIZE_PHASE);
|
||||
}
|
||||
|
||||
/*
|
||||
* 描述:OsStart阶段
|
||||
*/
|
||||
U32 OsStart(void)
|
||||
{
|
||||
U32 ret;
|
||||
|
||||
#if (OS_INCLUDE_TICK == YES)
|
||||
/* 表示系统在进行启动阶段,匹配MOUDLE_ID之后,标记进入TICK模块的启动 */
|
||||
ret = OsTickStart();
|
||||
if (ret != OS_OK) {
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if (OS_INCLUDE_TASK == YES)
|
||||
/* 表示系统在进行启动阶段,匹配MOUDLE_ID之后,标记进入任务模块的启动 */
|
||||
ret = OsActivate();
|
||||
#else
|
||||
ret = OS_OK;
|
||||
#endif
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
S32 OsConfigStart(void)
|
||||
{
|
||||
U32 ret;
|
||||
|
||||
OsHwInit();
|
||||
|
||||
/* OS模块注册 */
|
||||
ret = OsRegister();
|
||||
if (ret != OS_OK) {
|
||||
return (S32)ret;
|
||||
}
|
||||
|
||||
/* OS模块初始化 */
|
||||
ret = OsInitialize();
|
||||
if (ret != OS_OK) {
|
||||
return (S32)ret;
|
||||
}
|
||||
|
||||
/* OS启动调度 */
|
||||
ret = OsStart();
|
||||
if (ret != OS_OK) {
|
||||
return (S32)ret;
|
||||
}
|
||||
|
||||
/* Execution should not reach this point */
|
||||
return (S32)OS_ERROR;
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
/*
|
||||
* Copyright (c) 2009-2022 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
*
|
||||
* UniProton is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
* http://license.coscl.org.cn/MulanPSL2
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PSL v2 for more details.
|
||||
* Create: 2009-12-22
|
||||
* Description: UniProton配置头文件,裁剪开关和配置项。
|
||||
*/
|
||||
#ifndef PRT_CONFIG_H
|
||||
#define PRT_CONFIG_H
|
||||
|
||||
#include "prt_buildef.h"
|
||||
#include "prt_typedef.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* ***************************** 配置系统基本信息 ******************************* */
|
||||
/* 芯片主频 */
|
||||
#define OS_SYS_CLOCK 168000000
|
||||
|
||||
/* ***************************** 中断模块配置 ************************** */
|
||||
/* 硬中断最大支持个数 */
|
||||
#define OS_HWI_MAX_NUM_CONFIG 87
|
||||
|
||||
/* ***************************** 配置Tick中断模块 *************************** */
|
||||
/* Tick中断模块裁剪开关 */
|
||||
#define OS_INCLUDE_TICK YES
|
||||
/* Tick中断时间间隔,tick处理时间不能超过1/OS_TICK_PER_SECOND(s) */
|
||||
#define OS_TICK_PER_SECOND 5000
|
||||
|
||||
/* ***************************** 配置定时器模块 ***************************** */
|
||||
/* 基于TICK的软件定时器裁剪开关 */
|
||||
#define OS_INCLUDE_TICK_SWTMER YES
|
||||
/* 基于TICK的软件定时器最大个数 */
|
||||
#define OS_TICK_SWITIMER_MAX_NUM 8
|
||||
|
||||
/* ***************************** 配置任务模块 ******************************* */
|
||||
/* 任务模块裁剪开关 */
|
||||
#define OS_INCLUDE_TASK YES
|
||||
/* 最大支持的任务数,最大共支持254个 */
|
||||
#define OS_TSK_MAX_SUPPORT_NUM 8
|
||||
/* 缺省的任务栈大小 */
|
||||
#define OS_TSK_DEFAULT_STACK_SIZE 0x800
|
||||
/* IDLE任务栈的大小 */
|
||||
#define OS_TSK_IDLE_STACK_SIZE 0x800
|
||||
/* 任务栈初始化魔术字,默认是0xCA,只支持配置一个字节 */
|
||||
#define OS_TSK_STACK_MAGIC_WORD 0xCA
|
||||
|
||||
/* ***************************** 配置CPU占用率及CPU告警模块 **************** */
|
||||
/* CPU占用率模块裁剪开关 */
|
||||
#define OS_INCLUDE_CPUP NO
|
||||
/* 采样时间间隔(单位tick),若其值大于0,则作为采样周期,否则两次调用PRT_CpupNow或PRT_CpupThread间隔作为周期 */
|
||||
#define OS_CPUP_SAMPLE_INTERVAL 0
|
||||
/* CPU占用率告警动态配置项 */
|
||||
#define OS_CONFIG_CPUP_WARN NO
|
||||
/* CPU占用率告警阈值(精度为万分比) */
|
||||
#define OS_CPUP_SHORT_WARN 0
|
||||
/* CPU占用率告警恢复阈值(精度为万分比) */
|
||||
#define OS_CPUP_SHORT_RESUME 0
|
||||
|
||||
/* ***************************** 配置内存管理模块 ************************** */
|
||||
/* 用户可以创建的最大分区数,取值范围[0,253] */
|
||||
#define OS_MEM_MAX_PT_NUM 10
|
||||
/* 私有FSC内存分区起始地址 */
|
||||
#define OS_MEM_FSC_PT_ADDR (U32)&m_aucMemRegion00[0]
|
||||
/* 私有FSC内存分区大小 */
|
||||
#define OS_MEM_FSC_PT_SIZE 0x00008000
|
||||
|
||||
/* ***************************** 配置信号量管理模块 ************************* */
|
||||
/* 信号量模块裁剪开关 */
|
||||
#define OS_INCLUDE_SEM YES
|
||||
|
||||
/* 最大支持的信号量数 */
|
||||
#define OS_SEM_MAX_SUPPORT_NUM 10
|
||||
|
||||
/* ***************************** 配置队列模块 ******************************* */
|
||||
/* 队列模块裁剪开关 */
|
||||
#define OS_INCLUDE_QUEUE YES
|
||||
/* 最大支持的队列数,范围(0,0xFFFF] */
|
||||
#define OS_QUEUE_MAX_SUPPORT_NUM 10
|
||||
|
||||
/* ************************* 钩子模块配置 *********************************** */
|
||||
/* 硬中断进入钩子最大支持个数, 范围[0, 255] */
|
||||
#define OS_HOOK_HWI_ENTRY_NUM 20
|
||||
/* 硬中断退出钩子最大支持个数, 范围[0, 255] */
|
||||
#define OS_HOOK_HWI_EXIT_NUM 19
|
||||
/* 任务切换钩子最大支持个数, 范围[0, 255] */
|
||||
#define OS_HOOK_TSK_SWITCH_NUM 14
|
||||
/* IDLE钩子最大支持个数, 范围[0, 255] */
|
||||
#define OS_HOOK_IDLE_NUM 13
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cpluscplus */
|
||||
#endif /* __cpluscplus */
|
||||
|
||||
#endif /* PRT_CONFIG_H */
|
||||
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
* Copyright (c) 2009-2022 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
*
|
||||
* UniProton is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
* http://license.coscl.org.cn/MulanPSL2
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PSL v2 for more details.
|
||||
* Create: 2009-12-22
|
||||
* Description: UniProton配置私有文件。
|
||||
*/
|
||||
#ifndef PRT_CONFIG_INTERNAL_H
|
||||
#define PRT_CONFIG_INTERNAL_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include "prt_config.h"
|
||||
#include "prt_sys.h"
|
||||
#include "prt_task.h"
|
||||
#include "prt_sem.h"
|
||||
#include "prt_tick.h"
|
||||
#include "prt_exc.h"
|
||||
#include "prt_cpup.h"
|
||||
#include "prt_mem.h"
|
||||
#include "prt_hook.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cpluscplus */
|
||||
#endif /* __cpluscplus */
|
||||
|
||||
#define WORD_PACK(val) (((val) << 24) | ((val) << 16) | ((val) << 8) | (val))
|
||||
|
||||
enum OsinitPhaseId {
|
||||
OS_REGISTER_ID = 0,
|
||||
OS_INIT_ID,
|
||||
OS_MOUDLE_CONFIG
|
||||
};
|
||||
|
||||
extern U8 m_aucMemRegion00[OS_MEM_FSC_PT_SIZE] ; /* 私有静态内存分区(缺省) */
|
||||
|
||||
/* UniProton模块注册函数的声明 */
|
||||
extern U32 OsFscMemInit(U32 addr, U32 size);
|
||||
extern U32 OsSysRegister(struct SysModInfo *modInfo);
|
||||
extern U32 OsTickRegister(struct TickModInfo *modInfo);
|
||||
extern U32 OsTskRegister(struct TskModInfo *modInfo);
|
||||
extern U32 OsCpupRegister(struct CpupModInfo *modInfo);
|
||||
extern U32 OsSemRegister(const struct SemModInfo *modInfo);
|
||||
extern U32 OsHookRegister(struct HookModInfo *modInfo);
|
||||
|
||||
extern U32 OsHwiConfigInit(void);
|
||||
extern U32 OsTickConfigInit(void);
|
||||
extern U32 OsTskInit(void);
|
||||
extern U32 OsCpupInit(void);
|
||||
extern void OsCpupWarnInit(void);
|
||||
extern U32 OsExcConfigInit(void);
|
||||
extern U32 OsSemInit(void);
|
||||
extern U32 OsHookConfigInit(void);
|
||||
|
||||
/* UniProton系统启动相关函数的声明 */
|
||||
extern void OsHwInit(void);
|
||||
extern U32 OsActivate(void);
|
||||
extern U32 OsTickStart(void);
|
||||
extern U32 PRT_HardDrvInit(void);
|
||||
/* Notes: PRT_HardBootInit接口在栈保护支持随机数设置场景下必须在bss初始化后调用 */
|
||||
extern void PRT_HardBootInit(void);
|
||||
extern U32 PRT_AppInit(void);
|
||||
|
||||
extern U32 OsQueueRegister(U16 maxQueue);
|
||||
extern U32 OsQueueConfigInit(void);
|
||||
|
||||
#if (OS_INCLUDE_TICK_SWTMER == YES)
|
||||
extern U32 OsSwTmrInit(U32 maxTimerNum);
|
||||
#endif
|
||||
|
||||
typedef U32 (*ConfigInitFunc)(void);
|
||||
struct OsModuleConfigInfo {
|
||||
enum MoudleId moudleId;
|
||||
ConfigInitFunc moudleConfigFunc[OS_MOUDLE_CONFIG];
|
||||
};
|
||||
|
||||
extern S32 OsConfigStart(void);
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cpluscplus */
|
||||
#endif /* __cpluscplus */
|
||||
|
||||
#endif /* PRT_CONFIG_INTERNAL_H */
|
||||
@@ -0,0 +1,10 @@
|
||||
# Copyright (c) 2022-2022 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
#
|
||||
# UniProton is licensed under Mulan PSL v2.
|
||||
# You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
# You may obtain a copy of Mulan PSL v2 at:
|
||||
# http://license.coscl.org.cn/MulanPSL2
|
||||
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
# EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
# MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
# See the Mulan PSL v2 for more details.
|
||||
@@ -0,0 +1,10 @@
|
||||
# Copyright (c) 2022-2022 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
#
|
||||
# UniProton is licensed under Mulan PSL v2.
|
||||
# You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
# You may obtain a copy of Mulan PSL v2 at:
|
||||
# http://license.coscl.org.cn/MulanPSL2
|
||||
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
# EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
# MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
# See the Mulan PSL v2 for more details.
|
||||
@@ -0,0 +1,9 @@
|
||||
本目录下放置的是UniProton实时部分版本。
|
||||
|
||||
├─apps # 基于UniProton实时OS编程的demo程序;
|
||||
│ └─hello_world # hello_world示例程序;
|
||||
├─bsp # 提供的板级驱动与OS对接;
|
||||
├─build # 提供编译脚本编译出最终镜像;
|
||||
├─config # 配置选项,供用户调整运行时参数;
|
||||
├─include # UniProton实时部分提供的编程接口API;
|
||||
└─libs # UniProton实时部分的静态库,build目录中的makefile示例已经将头文件和静态库的引用准备好,应用可直接使用;
|
||||
@@ -0,0 +1,44 @@
|
||||
cmake_minimum_required(VERSION 3.12)
|
||||
project(exmaples LANGUAGES C ASM)
|
||||
|
||||
set(CMAKE_C_COMPILER ${TOOLCHAIN_PATH}/bin/aarch64-none-elf-gcc)
|
||||
set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PATH}/bin/aarch64-none-elf-g++)
|
||||
set(CMAKE_ASM_COMPILER ${TOOLCHAIN_PATH}/bin/aarch64-none-elf-gcc)
|
||||
set(CMAKE_LINKER ${TOOLCHAIN_PATH}/bin/aarch64-none-elf-ld)
|
||||
|
||||
set(POSIX_OPTION "-D_POSIX_THREADS -D_POSIX_THREAD_PRIORITY_SCHEDULING -D_POSIX_PRIORITY_SCHEDULING -D_POSIX_TIMERS -D_POSIX_CPUTIME -D_POSIX_THREAD_CPUTIME -D_POSIX_MONOTONIC_CLOCK -D_POSIX_TIMEOUTS -D_POSIX_CLOCK_SELECTION -D_POSIX_THREAD_PRIO_PROTECT -D_UNIX98_THREAD_MUTEX_ATTRIBUTES -D_POSIX_READER_WRITER_LOCKS")
|
||||
set(CC_OPTION "-g -march=armv8.2-a+nofp+nosimd -Wl,--build-id=none -fno-builtin -fno-PIE -Wall -fno-dwarf2-cfi-asm -O0 -mcmodel=large -fomit-frame-pointer -fzero-initialized-in-bss -fdollars-in-identifiers -ffunction-sections -fdata-sections -fno-common -fno-aggressive-loop-optimizations -fno-optimize-strlen -fno-schedule-insns -fno-inline-small-functions -fno-inline-functions-called-once -fno-strict-aliasing -fno-builtin -finline-limit=20 -mstrict-align -mlittle-endian -specs=nosys.specs -nostartfiles -funwind-tables")
|
||||
set(AS_OPTION "-g -march=armv8.2-a+nofp+nosimd -Wl,--build-id=none -fno-builtin -fno-PIE -Wall -fno-dwarf2-cfi-asm -O0 -mcmodel=large -fomit-frame-pointer -fzero-initialized-in-bss -fdollars-in-identifiers -ffunction-sections -fdata-sections -fno-common -fno-aggressive-loop-optimizations -fno-optimize-strlen -fno-schedule-insns -fno-inline-small-functions -fno-inline-functions-called-once -fno-strict-aliasing -fno-builtin -finline-limit=20 -mstrict-align -mlittle-endian -nostartfiles -mgeneral-regs-only -DENV_EL1")
|
||||
set(LD_OPTION "-static -no-pie -Wl,--wrap=memset -Wl,--wrap=memcpy")
|
||||
set(CMAKE_C_FLAGS "${CC_OPTION} ${POSIX_OPTION}")
|
||||
set(CMAKE_ASM_FLAGS "${AS_OPTION} ${POSIX_OPTION}")
|
||||
set(CMAKE_LINK_FLAGS "${LD_OPTION} -T ../hi3093.ld")
|
||||
set(CMAKE_EXE_LINKER_FLAGS "${LD_OPTION} -T ../hi3093.ld")
|
||||
|
||||
include_directories(
|
||||
./include
|
||||
./config
|
||||
./bsp
|
||||
./bsp/hi3093
|
||||
./bsp/uart
|
||||
./apps/openamp
|
||||
./build/open-amp/output/usr/local/include
|
||||
./build/libmetal/output/usr/local/include
|
||||
)
|
||||
|
||||
link_directories(./libs)
|
||||
link_libraries(
|
||||
-Wl,--start-group
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/libs/libCortexMXsec_c.lib"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/libs/libHI3093.a"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/libs/libmetal.a"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/libs/libopen_amp.a"
|
||||
-Wl,--end-group
|
||||
)
|
||||
|
||||
add_subdirectory(bsp)
|
||||
add_subdirectory(config)
|
||||
add_subdirectory(apps)
|
||||
|
||||
list(APPEND OBJS $<TARGET_OBJECTS:rpmsg> $<TARGET_OBJECTS:bsp> $<TARGET_OBJECTS:config> $<TARGET_OBJECTS:uart>)
|
||||
add_executable(${APP} ${OBJS})
|
||||
@@ -0,0 +1 @@
|
||||
add_subdirectory(openamp)
|
||||
@@ -0,0 +1,2 @@
|
||||
set(SRC rpmsg_backend.c rpmsg_service.c main.c)
|
||||
add_library(rpmsg OBJECT ${SRC})
|
||||
@@ -0,0 +1,137 @@
|
||||
/*
|
||||
* Copyright (c) 2022-2022 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
*
|
||||
* UniProton is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
* http://license.coscl.org.cn/MulanPSL2
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* See the Mulan PSL v2 for more details.
|
||||
* Create: 2022-12-05
|
||||
* Description: openamp configuration
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdarg.h>
|
||||
#include "securec.h"
|
||||
#include "prt_config.h"
|
||||
#include "prt_config_internal.h"
|
||||
#include "prt_task.h"
|
||||
#include "test.h"
|
||||
|
||||
TskHandle g_testTskHandle;
|
||||
U8 g_memRegion00[OS_MEM_FSC_PT_SIZE];
|
||||
|
||||
extern U32 PRT_PrintfInit();
|
||||
|
||||
#if defined(OS_OPTION_OPENAMP)
|
||||
int TestOpenamp()
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = rpmsg_service_init();
|
||||
if (ret) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
return OS_OK;
|
||||
}
|
||||
#endif
|
||||
|
||||
void TestTaskEntry()
|
||||
{
|
||||
#if defined(OS_OPTION_OPENAMP)
|
||||
TestOpenamp();
|
||||
#endif
|
||||
}
|
||||
|
||||
U32 OsTestInit(void)
|
||||
{
|
||||
U32 ret;
|
||||
U8 ptNo = OS_MEM_DEFAULT_FSC_PT;
|
||||
struct TskInitParam param = {0};
|
||||
|
||||
param.stackAddr = (U32)PRT_MemAllocAlign(0, ptNo, 0x2000, MEM_ADDR_ALIGN_016);
|
||||
param.taskEntry = (TskEntryFunc)TestTaskEntry;
|
||||
param.taskPrio = 25;
|
||||
param.name = "TestTask";
|
||||
param.stackSize = 0x2000;
|
||||
|
||||
ret = PRT_TaskCreate(&g_testTskHandle, ¶m);
|
||||
if (ret) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = PRT_TaskResume(g_testTskHandle);
|
||||
if (ret) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
return OS_OK;
|
||||
}
|
||||
|
||||
U32 PRT_AppInit(void)
|
||||
{
|
||||
U32 ret;
|
||||
|
||||
ret = OsTestInit();
|
||||
if (ret) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = TestClkStart();
|
||||
if (ret) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
return OS_OK;
|
||||
}
|
||||
|
||||
U32 PRT_HardDrvInit(void)
|
||||
{
|
||||
U32 ret;
|
||||
|
||||
ret = OsHwiInit();
|
||||
if (ret) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = PRT_PrintfInit();
|
||||
if (ret) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
return OS_OK;
|
||||
}
|
||||
|
||||
void PRT_HardBootInit(void)
|
||||
{
|
||||
}
|
||||
|
||||
S32 main(void)
|
||||
{
|
||||
return OsConfigStart();
|
||||
}
|
||||
|
||||
extern void *__wrap_memset(void *dest, int set, U32 len)
|
||||
{
|
||||
if (dest == NULL || len == 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char *ret = (char *)dest;
|
||||
for (int i = 0; i < len; ++i) {
|
||||
ret[i] = set;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
extern void *__wrap_memcpy(void *dest, const void *src, size_t size)
|
||||
{
|
||||
for (size_t i = 0; i < size; ++i) {
|
||||
*(char *)(dest + i) = *(char *)(src + i);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* Copyright (c) 2022-2022 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
*
|
||||
* UniProton is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
* http://license.coscl.org.cn/MulanPSL2
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* See the Mulan PSL v2 for more details.
|
||||
* Create: 2022-12-05
|
||||
* Description: openamp configuration
|
||||
*/
|
||||
|
||||
#ifndef COMMON_H__
|
||||
#define COMMON_H__
|
||||
|
||||
#include "cpu_config.h"
|
||||
#include "test.h"
|
||||
|
||||
#define VDEV_START_ADDR MMU_OPENAMP_ADDR
|
||||
#define VDEV_SIZE 0x30000
|
||||
|
||||
#define VDEV_STATUS_ADDR VDEV_START_ADDR
|
||||
#define VDEV_STATUS_SIZE 0x4000
|
||||
|
||||
#define SHM_START_ADDR (VDEV_START_ADDR + VDEV_STATUS_SIZE)
|
||||
#define SHM_SIZE (VDEV_SIZE - VDEV_STATUS_SIZE)
|
||||
#define SHM_DEVICE_NAME "lonely_device"
|
||||
|
||||
#define VRING_COUNT 2
|
||||
#define VRING_RX_ADDRESS (VDEV_START_ADDR + SHM_SIZE - VDEV_STATUS_SIZE)
|
||||
#define VRING_TX_ADDRESS (VDEV_START_ADDR + SHM_SIZE)
|
||||
#define VRING_ALIGNMENT 4
|
||||
#define VRING_SIZE 16
|
||||
|
||||
#define CONFIG_RPMSG_SERVICE_NUM_ENDPOINTS 1
|
||||
|
||||
#define DEFAULT_PAGE_SHIFT 0xffffffffffffffffULL
|
||||
#define DEFAULT_PAGE_MASK 0xffffffffffffffffULL
|
||||
|
||||
#define VIRTQUEUE_ID 1
|
||||
#define RPMSG_ROLE RPMSG_REMOTE
|
||||
|
||||
#define OS_OPENAMP_NOTIFY_HWI_NUM OS_HWI_IPI_NO_07
|
||||
#define OS_OPENAMP_NOTIFY_HWI_PRIO 0
|
||||
|
||||
#define BIT(n) (1 << (n))
|
||||
|
||||
OS_SEC_ALW_INLINE INLINE void sys_write32(uint32_t data, uintptr_t addr)
|
||||
{
|
||||
__asm__ volatile ("dmb sy" : : : "memory");
|
||||
__asm__ volatile ("str %w0, [%1]" : : "r" (data), "r" (addr));
|
||||
}
|
||||
|
||||
OS_SEC_ALW_INLINE INLINE uint32_t sys_read32(uintptr_t addr)
|
||||
{
|
||||
uint32_t val;
|
||||
__asm__ volatile ("ldr %w0, [%1]" : "=r" (val) : "r" (addr));
|
||||
__asm__ volatile ("dmb sy" : : : "memory");
|
||||
return val;
|
||||
}
|
||||
|
||||
OS_SEC_ALW_INLINE INLINE void sys_write8(uint8_t data, uintptr_t addr)
|
||||
{
|
||||
__asm__ volatile ("dmb sy" : : : "memory");
|
||||
__asm__ volatile ("strb %w0, [%1]" : : "r" (data), "r" (addr));
|
||||
}
|
||||
|
||||
OS_SEC_ALW_INLINE INLINE uint8_t sys_read8(uintptr_t addr)
|
||||
{
|
||||
uint8_t val;
|
||||
__asm__ volatile ("ldrb %w0, [%1]" : "=r" (val) : "r" (addr));
|
||||
__asm__ volatile ("dmb sy" : : : "memory");
|
||||
return val;
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,174 @@
|
||||
/*
|
||||
* Copyright (c) 2022-2022 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
*
|
||||
* UniProton is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
* http://license.coscl.org.cn/MulanPSL2
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* See the Mulan PSL v2 for more details.
|
||||
* Create: 2022-12-05
|
||||
* Description: openamp backend
|
||||
*/
|
||||
|
||||
#include "rpmsg_backend.h"
|
||||
#include "metal/device.h"
|
||||
#include "prt_hwi.h"
|
||||
|
||||
static metal_phys_addr_t shm_physmap[] = { SHM_START_ADDR };
|
||||
static struct metal_device shm_device = {
|
||||
.name = SHM_DEVICE_NAME,
|
||||
.bus = NULL,
|
||||
.num_regions = 1,
|
||||
{
|
||||
{
|
||||
.virt = (void *) SHM_START_ADDR,
|
||||
.physmap = shm_physmap,
|
||||
.size = SHM_SIZE,
|
||||
.page_shift = DEFAULT_PAGE_SHIFT,
|
||||
.page_mask = DEFAULT_PAGE_MASK,
|
||||
.mem_flags = 0,
|
||||
.ops = { NULL },
|
||||
},
|
||||
},
|
||||
.node = { NULL },
|
||||
.irq_num = 0,
|
||||
.irq_info = NULL
|
||||
};
|
||||
|
||||
static struct virtio_vring_info rvrings[2] = {
|
||||
[0] = {
|
||||
.info.align = VRING_ALIGNMENT,
|
||||
},
|
||||
[1] = {
|
||||
.info.align = VRING_ALIGNMENT,
|
||||
},
|
||||
};
|
||||
|
||||
static struct virtqueue *vq[2];
|
||||
|
||||
static unsigned char virtio_get_status(struct virtio_device *vdev)
|
||||
{
|
||||
return sys_read8(VDEV_STATUS_ADDR);
|
||||
}
|
||||
|
||||
static void virtio_set_status(struct virtio_device *vdev, unsigned char status)
|
||||
{
|
||||
sys_write8(status, VDEV_STATUS_ADDR);
|
||||
}
|
||||
|
||||
static uint32_t virtio_get_features(struct virtio_device *vdev)
|
||||
{
|
||||
return BIT(VIRTIO_RPMSG_F_NS);
|
||||
}
|
||||
|
||||
static void virtio_set_features(struct virtio_device *vdev, uint32_t features)
|
||||
{
|
||||
}
|
||||
|
||||
static void virtio_notify(struct virtqueue *vq)
|
||||
{
|
||||
uint16_t coreMask = 1;
|
||||
OsHwiMcTrigger(coreMask, OS_HWI_IPI_NO_07);
|
||||
}
|
||||
|
||||
const struct virtio_dispatch dispatch = {
|
||||
.get_status = virtio_get_status,
|
||||
.set_status = virtio_set_status,
|
||||
.get_features = virtio_get_features,
|
||||
.set_features = virtio_set_features,
|
||||
.notify = virtio_notify,
|
||||
};
|
||||
|
||||
static void rpmsg_hwi_handler(void)
|
||||
{
|
||||
virtqueue_notification(vq[VIRTQUEUE_ID]);
|
||||
}
|
||||
|
||||
static U32 rpmsg_hwi_init(void)
|
||||
{
|
||||
U32 ret;
|
||||
|
||||
ret = PRT_HwiSetAttr(OS_OPENAMP_NOTIFY_HWI_NUM, OS_OPENAMP_NOTIFY_HWI_PRIO, OS_HWI_MODE_ENGROSS);
|
||||
if (ret != OS_OK) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = PRT_HwiCreate(OS_OPENAMP_NOTIFY_HWI_NUM, (HwiProcFunc)rpmsg_hwi_handler, 0);
|
||||
if (ret != OS_OK) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
#if (OS_GIC_VER == 3)
|
||||
ret = PRT_HwiEnable(OS_OPENAMP_NOTIFY_HWI_NUM);
|
||||
if (ret != OS_OK) {
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
return OS_OK;
|
||||
}
|
||||
|
||||
int rpmsg_backend_init(struct metal_io_region **io, struct virtio_device *vdev)
|
||||
{
|
||||
int32_t err;
|
||||
struct metal_init_params metal_params = METAL_INIT_DEFAULTS;
|
||||
struct metal_device *device;
|
||||
|
||||
err = rpmsg_hwi_init();
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
|
||||
/* Libmetal setup */
|
||||
err = metal_init(&metal_params);
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
|
||||
err = metal_register_generic_device(&shm_device);
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
|
||||
err = metal_device_open("generic", SHM_DEVICE_NAME, &device);
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
|
||||
*io = metal_device_io_region(device, 0);
|
||||
if (!*io) {
|
||||
return err;
|
||||
}
|
||||
|
||||
/* Virtqueue setup */
|
||||
vq[0] = virtqueue_allocate(VRING_SIZE);
|
||||
if (!vq[0]) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
vq[1] = virtqueue_allocate(VRING_SIZE);
|
||||
if (!vq[1]) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
rvrings[0].io = *io;
|
||||
rvrings[0].info.vaddr = (void *)VRING_TX_ADDRESS;
|
||||
rvrings[0].info.num_descs = VRING_SIZE;
|
||||
rvrings[0].info.align = VRING_ALIGNMENT;
|
||||
rvrings[0].vq = vq[0];
|
||||
|
||||
rvrings[1].io = *io;
|
||||
rvrings[1].info.vaddr = (void *)VRING_RX_ADDRESS;
|
||||
rvrings[1].info.num_descs = VRING_SIZE;
|
||||
rvrings[1].info.align = VRING_ALIGNMENT;
|
||||
rvrings[1].vq = vq[1];
|
||||
|
||||
vdev->role = RPMSG_ROLE;
|
||||
vdev->vrings_num = VRING_COUNT;
|
||||
vdev->func = &dispatch;
|
||||
vdev->vrings_info = &rvrings[0];
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright (c) 2022-2022 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
*
|
||||
* UniProton is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
* http://license.coscl.org.cn/MulanPSL2
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* See the Mulan PSL v2 for more details.
|
||||
* Create: 2022-12-05
|
||||
* Description: openamp backend
|
||||
*/
|
||||
|
||||
#include "openamp/open_amp.h"
|
||||
#include "openamp_common.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern int rpmsg_service_init(void);
|
||||
|
||||
/*
|
||||
* @brief Initialize RPMsg backend
|
||||
*
|
||||
* @param io Shared memory IO region. This is an output parameter providing
|
||||
* a pointer to an actual shared memory IO region structure.
|
||||
* Caller of this function shall pass an address at which the
|
||||
* pointer to the shared memory IO region structure is stored.
|
||||
* @param vdev Pointer to the virtio device initialized by this function.
|
||||
*
|
||||
* @retval 0 Initialization successful
|
||||
* @retval <0 Initialization error reported by OpenAMP
|
||||
*/
|
||||
extern int rpmsg_backend_init(struct metal_io_region **io, struct virtio_device *vdev);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
* Copyright (c) 2022-2022 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
*
|
||||
* UniProton is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
* http://license.coscl.org.cn/MulanPSL2
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* See the Mulan PSL v2 for more details.
|
||||
* Create: 2022-12-05
|
||||
* Description: openamp configuration
|
||||
*/
|
||||
|
||||
#include "rpmsg_backend.h"
|
||||
|
||||
static struct virtio_device vdev;
|
||||
static struct rpmsg_virtio_device rvdev;
|
||||
static struct metal_io_region *io;
|
||||
struct rpmsg_device *g_rdev;
|
||||
struct rpmsg_endpoint g_ept;
|
||||
U32 g_receivedMsg;
|
||||
bool g_openampFlag = false;
|
||||
#define RPMSG_ENDPOINT_NAME "console"
|
||||
|
||||
void rpmsg_service_unbind(struct rpmsg_endpoint *ep)
|
||||
{
|
||||
rpmsg_destroy_ept(ep);
|
||||
}
|
||||
|
||||
int send_message(unsigned char *message, int len)
|
||||
{
|
||||
return rpmsg_send(&g_ept, message, len);
|
||||
}
|
||||
|
||||
char *g_s1 = "Hello, UniProton! \r\n";
|
||||
int rpmsg_endpoint_cb(struct rpmsg_endpoint *ept, void *data, size_t len, uint32_t src, void *priv)
|
||||
{
|
||||
g_openampFlag = true;
|
||||
send_message((void *)g_s1, strlen(g_s1) * sizeof(char));
|
||||
|
||||
return OS_OK;
|
||||
}
|
||||
|
||||
int openamp_init(void)
|
||||
{
|
||||
int32_t err;
|
||||
|
||||
err = rpmsg_backend_init(&io, &vdev);
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
|
||||
err = rpmsg_init_vdev(&rvdev, &vdev, NULL, io, NULL);
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
|
||||
g_rdev = rpmsg_virtio_get_rpmsg_device(&rvdev);
|
||||
|
||||
|
||||
err = rpmsg_create_ept(&g_ept, g_rdev, RPMSG_ENDPOINT_NAME,
|
||||
0xF, RPMSG_ADDR_ANY,
|
||||
rpmsg_endpoint_cb, rpmsg_service_unbind);
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
|
||||
return OS_OK;
|
||||
}
|
||||
|
||||
void openamp_deinit(void)
|
||||
{
|
||||
rpmsg_deinit_vdev(&rvdev);
|
||||
if (io) {
|
||||
free(io);
|
||||
}
|
||||
}
|
||||
|
||||
int rpmsg_service_init(void)
|
||||
{
|
||||
int32_t err;
|
||||
err = openamp_init();
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
|
||||
send_message((void *)&g_receivedMsg, sizeof(U32));
|
||||
|
||||
while (!g_openampFlag);
|
||||
|
||||
return OS_OK;
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2022-2022 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
*
|
||||
* UniProton is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
* http://license.coscl.org.cn/MulanPSL2
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* See the Mulan PSL v2 for more details.
|
||||
* Create: 2022-12-05
|
||||
* Description: openamp test Printf
|
||||
*/
|
||||
#include "prt_config.h"
|
||||
#include "prt_task.h"
|
||||
#include "prt_hwi.h"
|
||||
#include "prt_hook.h"
|
||||
#include "prt_exc.h"
|
||||
#include "prt_mem.h"
|
||||
|
||||
extern U32 PRT_Printf(const char *format, ...);
|
||||
@@ -0,0 +1 @@
|
||||
请您参考example目录添加您的源代码,制作您的工程。如有疑问请联系华为对接工程师。
|
||||
@@ -0,0 +1,4 @@
|
||||
set(SRCS start.S cache_asm.S hwi_init.c mmu.c print.c timer.c)
|
||||
add_library(bsp OBJECT ${SRCS})
|
||||
|
||||
add_subdirectory(uart)
|
||||
@@ -0,0 +1,103 @@
|
||||
@/*
|
||||
@ * Copyright (c) 2009-2022 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
@ *
|
||||
@ * UniProton is licensed under Mulan PSL v2.
|
||||
@ * You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
@ * You may obtain a copy of Mulan PSL v2 at:
|
||||
@ * http://license.coscl.org.cn/MulanPSL2
|
||||
@ * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
@ * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
@ * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
@ * See the Mulan PSL v2 for more details.
|
||||
@ * Create: 2009-12-22
|
||||
@ * Description: thread scheduler
|
||||
@ */
|
||||
.global os_asm_invalidate_dcache_all
|
||||
.global os_asm_invalidate_icache_all
|
||||
.global os_asm_invalidate_tlb_all
|
||||
|
||||
.type os_asm_dcache_level, "function"
|
||||
os_asm_dcache_level:
|
||||
lsl x12, x0, #1
|
||||
msr csselr_el1, x12
|
||||
isb
|
||||
mrs x6, ccsidr_el1
|
||||
and x2, x6, #7
|
||||
add x2, x2, #4
|
||||
mov x3, #0x3ff
|
||||
and x3, x3, x6, lsr #3
|
||||
clz w5, w3
|
||||
mov x4, #0x7fff
|
||||
and x4, x4, x6, lsr #13
|
||||
|
||||
loop_set:
|
||||
mov x6, x3
|
||||
loop_way:
|
||||
lsl x7, x6, x5
|
||||
orr x9, x12, x7
|
||||
lsl x7, x4, x2
|
||||
orr x9, x9, x7
|
||||
tbz w1, #1, 3f
|
||||
dc csw, x9
|
||||
b 2f
|
||||
3: tbz w1, #0, 1f
|
||||
dc isw, x9
|
||||
b 2f
|
||||
1: dc cisw, x9
|
||||
2: subs x6, x6, #1
|
||||
b.ge loop_way
|
||||
subs x4, x4, #1
|
||||
b.ge loop_set
|
||||
|
||||
ret
|
||||
|
||||
.type os_asm_dcache_all, "function"
|
||||
os_asm_dcache_all:
|
||||
mov x1, x0
|
||||
dsb sy
|
||||
mrs x10, clidr_el1
|
||||
lsr x11, x10, #24
|
||||
and x11, x11, #0x7
|
||||
cbz x11, finished
|
||||
mov x15, x30
|
||||
mov x0, #0
|
||||
|
||||
loop_level:
|
||||
lsl x12, x0, #1
|
||||
add x12, x12, x0
|
||||
lsr x12, x10, x12
|
||||
and x12, x12, #7
|
||||
cmp x12, #2
|
||||
b.lt skip
|
||||
bl os_asm_dcache_level
|
||||
skip:
|
||||
add x0, x0, #1
|
||||
cmp x11, x0
|
||||
b.gt loop_level
|
||||
|
||||
mov x0, #0
|
||||
msr csselr_el1, x0
|
||||
dsb sy
|
||||
isb
|
||||
mov x30, x15
|
||||
|
||||
finished:
|
||||
ret
|
||||
|
||||
.type os_asm_invalidate_dcache_all, "function"
|
||||
os_asm_invalidate_dcache_all:
|
||||
mov x0, #0x1
|
||||
b os_asm_dcache_all
|
||||
|
||||
.type os_asm_invalidate_icache_all, "function"
|
||||
os_asm_invalidate_icache_all:
|
||||
ic ialluis
|
||||
isb sy
|
||||
ret
|
||||
|
||||
.type os_asm_invalidate_tlb_all, "function"
|
||||
os_asm_invalidate_tlb_all:
|
||||
tlbi vmalle1
|
||||
dsb sy
|
||||
isb
|
||||
ret
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright (c) 2009-2022 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
*
|
||||
* UniProton is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
* http://license.coscl.org.cn/MulanPSL2
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PSL v2 for more details.
|
||||
* Create: 2009-12-22
|
||||
* Description: UniProton hi3093 demo
|
||||
*/
|
||||
#ifndef __CACHE_H__
|
||||
#define __CACHE_H__
|
||||
|
||||
#include "prt_buildef.h"
|
||||
#include "prt_typedef.h"
|
||||
#include "prt_module.h"
|
||||
#include "prt_errno.h"
|
||||
|
||||
extern void os_asm_invalidate_dcache_all(void);
|
||||
extern void os_asm_invalidate_icache_all(void);
|
||||
extern void os_asm_invalidate_tlb_all(void);
|
||||
#endif
|
||||
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* Copyright (c) 2009-2022 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
*
|
||||
* UniProton is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
* http://license.coscl.org.cn/MulanPSL2
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PSL v2 for more details.
|
||||
* Create: 2009-12-22
|
||||
* Description: UniProton配置私有文件。
|
||||
*/
|
||||
#ifndef CPU_CONFIG_H
|
||||
#define CPU_CONFIG_H
|
||||
|
||||
#include "cache_asm.h"
|
||||
|
||||
#define MMU_IMAGE_ADDR 0x93000000ULL
|
||||
#define MMU_GIC_ADDR 0x24000000ULL
|
||||
#define MMU_UART_ADDR 0x08743000ULL
|
||||
#define MMU_OPENAMP_ADDR 0x90000000ULL
|
||||
|
||||
#define UART_BASE_ADDR MMU_UART_ADDR
|
||||
|
||||
#define TEST_CLK_INT 30
|
||||
|
||||
#define OS_GIC_VER 3
|
||||
#define SICR_ADDR_OFFSET_PER_CORE 0x20000U
|
||||
#define GIC_REG_BASE_ADDR 0x24000000ULL
|
||||
|
||||
#define GICD_CTLR_S_ADDR (GIC_REG_BASE_ADDR + 0x0000U)
|
||||
#define GICD_IGROUPN_ADDR (GIC_REG_BASE_ADDR + 0x0080U)
|
||||
#define GICD_ISENABLER0_ADDR (GIC_REG_BASE_ADDR + 0x0100U)
|
||||
#define GICD_ICENABLER0_ADDR (GIC_REG_BASE_ADDR + 0x0180U)
|
||||
#define GICD_IPRIORITYN_ADDR (GIC_REG_BASE_ADDR + 0x0400U)
|
||||
#define GICD_IGRPMODRN_ADDR (GIC_REG_BASE_ADDR + 0x0D00U)
|
||||
|
||||
#define GICR_BASE0 (GIC_REG_BASE_ADDR + 0x40000U)
|
||||
#define GICR_BASE1 (GIC_REG_BASE_ADDR + 0x50000U)
|
||||
|
||||
#define GICR_CTRL_ADDR (GICR_BASE0 + 0x0000U)
|
||||
#define GICR_WAKER_ADDR (GICR_BASE0 + 0x0014U)
|
||||
|
||||
#define GICR_IGROUPR0_ADDR (GICR_BASE1 + 0x0080U)
|
||||
#define GICR_ISENABLER0_ADDR (GICR_BASE1 + 0x0100U)
|
||||
#define GICR_ICENABLER0_ADDR (GICR_BASE1 + 0x0180U)
|
||||
#define GICR_IGRPMODR0_ADDR (GICR_BASE1 + 0x0D00U)
|
||||
|
||||
|
||||
#define MAX_INT_NUM 387
|
||||
#define MIN_GIC_SPI_NUM 32
|
||||
#define SICD_IGROUP_INT_NUM 32
|
||||
#define SICD_REG_SIZE 4
|
||||
|
||||
#define GROUP_MAX_BPR 0x7U
|
||||
#define GROUP0_BP 0
|
||||
#define GROUP1_BP 0
|
||||
|
||||
#define PRIO_MASK_LEVEL 0xFFU
|
||||
|
||||
#define ICC_SRE_EL1 S3_0_C12_C12_5
|
||||
#define ICC_BPR0_EL1 S3_0_C12_C8_3
|
||||
#define ICC_BPR1_EL1 S3_0_C12_C12_3
|
||||
#define ICC_IGRPEN1_EL1 S3_0_C12_C12_7
|
||||
#define ICC_PMR_EL1 S3_0_C4_C6_0
|
||||
|
||||
#define PARAS_TO_STRING(x...) #x
|
||||
#define REG_ALIAS(x...) PARAS_TO_STRING(x)
|
||||
|
||||
#define GIC_REG_READ(addr) (*(volatile U32 *)((uintptr_t)(addr)))
|
||||
#define GIC_REG_WRITE(addr, data) (*(volatile U32 *)((uintptr_t)(addr)) = (U32)(data))
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,355 @@
|
||||
/*
|
||||
* Copyright (c) 2009-2022 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
*
|
||||
* UniProton is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
* http://license.coscl.org.cn/MulanPSL2
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PSL v2 for more details.
|
||||
* Create: 2009-12-22
|
||||
* Description: UniProton hi3093 demo
|
||||
*/
|
||||
#include "securec.h"
|
||||
#include "prt_tick.h"
|
||||
#include "prt_hwi.h"
|
||||
#include "prt_sys.h"
|
||||
#include "prt_task.h"
|
||||
#include "cpu_config.h"
|
||||
|
||||
#if (OS_GIC_VER == 3)
|
||||
enum GicIntState {
|
||||
GIC_DISABLE = 0,
|
||||
GIC_ENABLE = 1
|
||||
};
|
||||
|
||||
enum SicGroupType {
|
||||
SIC_GROUP_G0S = 0,
|
||||
SIC_GROUP_G1NS = 1,
|
||||
SIC_GROUP_G1S = 2,
|
||||
SIC_GROUP_BUTT,
|
||||
};
|
||||
|
||||
union SicrWaker {
|
||||
struct {
|
||||
U32 res0 : 1;
|
||||
U32 sleepReq : 1;
|
||||
U32 isSleep : 1;
|
||||
U32 res1 : 29;
|
||||
} bits;
|
||||
U32 value;
|
||||
};
|
||||
|
||||
union SicrCtrl {
|
||||
struct {
|
||||
U32 enLpis : 1;
|
||||
U32 res2 : 2;
|
||||
U32 rwp : 1;
|
||||
U32 res1 : 20;
|
||||
U32 dpg0 : 1;
|
||||
U32 dpg1ns : 1;
|
||||
U32 dpg1s : 1;
|
||||
U32 res0 : 4;
|
||||
U32 uwp : 1;
|
||||
} bits;
|
||||
U32 value;
|
||||
};
|
||||
|
||||
union HwiIccSreElx {
|
||||
struct {
|
||||
U64 prt : 1;
|
||||
U64 dfb : 1;
|
||||
U64 dib : 1;
|
||||
U64 enable : 1;
|
||||
U64 res : 60;
|
||||
} bits;
|
||||
U64 value;
|
||||
};
|
||||
|
||||
union SicdCtrl {
|
||||
struct {
|
||||
U32 enG0S : 1;
|
||||
U32 enG1Ns : 1;
|
||||
U32 enG1S : 1;
|
||||
U32 res1 : 1;
|
||||
U32 areS : 1;
|
||||
U32 areNs : 1;
|
||||
U32 ds : 1;
|
||||
U32 res0 : 24;
|
||||
U32 rwp : 1;
|
||||
} bits;
|
||||
U32 value;
|
||||
};
|
||||
|
||||
extern void OsGicdWaitCfgWork();
|
||||
|
||||
void OsSicrInit(void)
|
||||
{
|
||||
union SicrWaker sicrWaker;
|
||||
uintptr_t regAddr;
|
||||
U32 intId;
|
||||
|
||||
regAddr = GICR_WAKER_ADDR + OsGetCoreID() * SICR_ADDR_OFFSET_PER_CORE;
|
||||
sicrWaker.value = GIC_REG_READ(regAddr);
|
||||
sicrWaker.bits.sleepReq = 0;
|
||||
GIC_REG_WRITE(regAddr, sicrWaker.value);
|
||||
sicrWaker.value = GIC_REG_READ(regAddr);
|
||||
while (sicrWaker.bits.isSleep == 1) {
|
||||
sicrWaker.value = GIC_REG_READ(regAddr);
|
||||
}
|
||||
}
|
||||
|
||||
void OsSicrSetIntGroup(U32 coreId, U64 intId, enum SicGroupType groupId)
|
||||
{
|
||||
uintptr_t group0RegAddr;
|
||||
uintptr_t modRegAddr;
|
||||
U32 group0RegTmp;
|
||||
U32 modRegTmp;
|
||||
|
||||
group0RegAddr = GICR_IGROUPR0_ADDR + OsGetCoreID() * SICR_ADDR_OFFSET_PER_CORE;
|
||||
group0RegTmp = GIC_REG_READ(group0RegAddr);
|
||||
|
||||
if ((groupId == SIC_GROUP_G0S) || (groupId == SIC_GROUP_G1S)) {
|
||||
group0RegTmp &= ~(0x1U << intId);
|
||||
} else {
|
||||
group0RegTmp |= (0x1U << intId);
|
||||
}
|
||||
GIC_REG_WRITE(group0RegAddr, group0RegTmp);
|
||||
|
||||
modRegAddr = GICR_IGRPMODR0_ADDR + OsGetCoreID() * SICR_ADDR_OFFSET_PER_CORE;
|
||||
modRegTmp = GIC_REG_READ(modRegAddr);
|
||||
|
||||
if (groupId == SIC_GROUP_G1S) {
|
||||
modRegTmp |= (0x1U << intId);
|
||||
} else {
|
||||
modRegTmp &= ~(0x1U << intId);
|
||||
}
|
||||
GIC_REG_WRITE(modRegAddr, modRegTmp);
|
||||
}
|
||||
|
||||
U32 OsSiccEnableSre(void)
|
||||
{
|
||||
volatile union HwiIccSreElx iccSre;
|
||||
|
||||
OS_EMBED_ASM("MRS %0, " REG_ALIAS(ICC_SRE_EL1) " \n" : "=&r"(iccSre));
|
||||
iccSre.bits.prt = 1;
|
||||
iccSre.bits.dfb = 1;
|
||||
iccSre.bits.dib = 1;
|
||||
OS_EMBED_ASM("MSR " REG_ALIAS(ICC_SRE_EL1) ", %0 \n" : : "r"(iccSre));
|
||||
OS_EMBED_ASM("DSB SY");
|
||||
OS_EMBED_ASM("ISB");
|
||||
|
||||
OS_EMBED_ASM("MRS %0, " REG_ALIAS(ICC_SRE_EL1) " \n" : "=&r"(iccSre.value));
|
||||
|
||||
if (iccSre.bits.prt != 1) {
|
||||
return OS_FAIL;
|
||||
}
|
||||
|
||||
return OS_OK;
|
||||
}
|
||||
|
||||
void OsSiccCfgIntPreempt(void)
|
||||
{
|
||||
U64 tmp = 0;
|
||||
|
||||
OS_EMBED_ASM("MRS %0, " REG_ALIAS(ICC_BPR1_EL1) " \n" : "=&r"(tmp) : : "memory");
|
||||
tmp &= ~(GROUP_MAX_BPR);
|
||||
tmp |= GROUP1_BP;
|
||||
OS_EMBED_ASM("MSR " REG_ALIAS(ICC_BPR1_EL1) ", %0 \n" : : "r"(tmp) : "memory");
|
||||
}
|
||||
|
||||
void OsSiccEnableGroup1(void)
|
||||
{
|
||||
U64 tmp = 0;
|
||||
|
||||
OS_EMBED_ASM("MRS %0, " REG_ALIAS(ICC_IGRPEN1_EL1) " \n" : "=&r"(tmp) : : "memory");
|
||||
tmp |= 0x01U;
|
||||
OS_EMBED_ASM("MSR " REG_ALIAS(ICC_IGRPEN1_EL1) ", %0 \n" : : "r"(tmp) : "memory");
|
||||
}
|
||||
|
||||
void OsSiccCfgPriorityMask(void)
|
||||
{
|
||||
U64 tmp = 0;
|
||||
|
||||
OS_EMBED_ASM("MRS %0, " REG_ALIAS(ICC_PMR_EL1) " \n" : "=&r"(tmp) : : "memory");
|
||||
tmp |= PRIO_MASK_LEVEL;
|
||||
OS_EMBED_ASM("MSR " REG_ALIAS(ICC_PMR_EL1) ", %0 \n" : : "r"(tmp) : "memory");
|
||||
}
|
||||
|
||||
U32 OsSiccInit(void)
|
||||
{
|
||||
U32 ret;
|
||||
|
||||
ret = OsSiccEnableSre();
|
||||
if (ret != OS_OK) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
OsSiccCfgIntPreempt();
|
||||
|
||||
OsSiccEnableGroup1();
|
||||
|
||||
OsSiccCfgPriorityMask();
|
||||
|
||||
return OS_OK;
|
||||
}
|
||||
|
||||
void OsSicdSetIntGroup(U32 intId, enum SicGroupType groupId)
|
||||
{
|
||||
U64 group0RegAddr;
|
||||
U64 modRegAddr;
|
||||
U32 group0RegTmp;
|
||||
U32 modRegTmp;
|
||||
U32 sicdM;
|
||||
U32 bitOffset;
|
||||
|
||||
sicdM = (intId - MIN_GIC_SPI_NUM) / SICD_IGROUP_INT_NUM;
|
||||
group0RegAddr = GICD_IGROUPN_ADDR + (SICD_REG_SIZE * sicdM);
|
||||
modRegAddr = GICD_IGRPMODRN_ADDR + (SICD_REG_SIZE * sicdM);
|
||||
bitOffset = (intId - MIN_GIC_SPI_NUM) % SICD_IGROUP_INT_NUM;
|
||||
|
||||
group0RegTmp = GIC_REG_READ(group0RegAddr);
|
||||
if ((groupId == SIC_GROUP_G0S) || (groupId == SIC_GROUP_G1S)) {
|
||||
group0RegTmp &= ~(0x1U << bitOffset);
|
||||
} else {
|
||||
group0RegTmp |= (0x1U << bitOffset);
|
||||
}
|
||||
GIC_REG_WRITE(group0RegAddr, group0RegTmp);
|
||||
|
||||
modRegTmp = GIC_REG_READ(modRegAddr);
|
||||
if (groupId == SIC_GROUP_G1S) {
|
||||
modRegTmp |= (0x1U << bitOffset);
|
||||
} else {
|
||||
modRegTmp &= ~(0x1U << bitOffset);
|
||||
}
|
||||
GIC_REG_WRITE(modRegAddr, modRegTmp);
|
||||
}
|
||||
|
||||
void OsSicSetGroup(U32 intId, enum SicGroupType groupId)
|
||||
{
|
||||
U32 coreId = OsGetCoreID();
|
||||
enum GicIntState state;
|
||||
|
||||
if (intId < MIN_GIC_SPI_NUM) {
|
||||
state = OsGicrGetIntState(coreId, intId);
|
||||
OsGicrDisableInt(coreId, intId);
|
||||
OsSicrSetIntGroup(coreId, intId, groupId);
|
||||
if (state == GIC_ENABLE) {
|
||||
OsGicrEnableInt(coreId, intId);
|
||||
}
|
||||
} else {
|
||||
state = OsGicdGetIntState(intId);
|
||||
OsGicdDisableInt(intId);
|
||||
OsSicdSetIntGroup(intId, groupId);
|
||||
if (state == GIC_ENABLE) {
|
||||
OsGicdEnableInt(intId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
U32 OsSicInitLocal(void)
|
||||
{
|
||||
U32 ret;
|
||||
U32 intId;
|
||||
|
||||
OsSicrInit();
|
||||
|
||||
ret = OsSiccInit();
|
||||
if (ret != OS_OK) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
for (intId = 0; intId < MIN_GIC_SPI_NUM; ++intId) {
|
||||
OsSicSetGroup(intId, SIC_GROUP_G1NS);
|
||||
}
|
||||
|
||||
return OS_OK;
|
||||
}
|
||||
|
||||
void OsSicdInit(void)
|
||||
{
|
||||
union SicdCtrl sicdCtrl;
|
||||
|
||||
sicdCtrl.value = GIC_REG_READ(GICD_CTLR_S_ADDR);
|
||||
|
||||
if ((sicdCtrl.bits.enG0S == 1) || (sicdCtrl.bits.enG1Ns == 1) || (sicdCtrl.bits.enG1S == 1)) {
|
||||
return;
|
||||
}
|
||||
|
||||
sicdCtrl.bits.ds = 0;
|
||||
sicdCtrl.bits.areNs = 1;
|
||||
sicdCtrl.bits.areS = 1;
|
||||
sicdCtrl.bits.enG1Ns = 1;
|
||||
GIC_REG_WRITE(GICD_CTLR_S_ADDR, sicdCtrl.value);
|
||||
|
||||
OsGicdWaitCfgWork();
|
||||
}
|
||||
|
||||
void OsSicInitGlobal(void)
|
||||
{
|
||||
U32 intId;
|
||||
|
||||
OsSicdInit();
|
||||
|
||||
for (intId = MIN_GIC_SPI_NUM; intId < MAX_INT_NUM; ++intId) {
|
||||
OsSicSetGroup(intId, SIC_GROUP_G1NS);
|
||||
}
|
||||
}
|
||||
#elif (OS_GIC_VER == 2)
|
||||
int IsrRegister(U32 intNo, U32 pri)
|
||||
{
|
||||
U32 bitn, reg, shift;
|
||||
U32 *addr;
|
||||
|
||||
bitn = intNo / 32U;
|
||||
addr = (U32 *)(GICD_ISENABLERn + 4U * bitn);
|
||||
reg = *addr;
|
||||
*addr = (reg | (0x1U << (intNo % 32U)));
|
||||
|
||||
bitn = intNo / 4U;
|
||||
addr = (U32 *)(GICD_IPRIORITYn + 4U * bitn);
|
||||
shift = (intNo % 4U) * 8U;
|
||||
reg = (*addr) & ~(0xFFU << shift);
|
||||
*addr = (reg | pri << shift);
|
||||
}
|
||||
|
||||
void OsGicInitCpuInterface(void)
|
||||
{
|
||||
int i;
|
||||
U32 val;
|
||||
|
||||
GIC_REG_WRITE(0xFFFFFFFF, GICD_ICACTIVERn);
|
||||
GIC_REG_WRITE(0xFFFF0000, GICD_ICENABLERn);
|
||||
GIC_REG_WRITE(0x0000FFFF, GICD_ISENABLERn);
|
||||
|
||||
for (i = 0; i < 32; i += 4) {
|
||||
GIC_REG_WRITE(0xA0A0A0A0, GICD_IPRIORITYn + i);
|
||||
}
|
||||
|
||||
GIC_REG_WRITE(0xF0, GICC_PMR);
|
||||
val = GIC_REG_READ(GICC_CTLR);
|
||||
val &= ~GICC_CTLR_BYPASS_MASK;
|
||||
val |= GICC_CTLR_ENABLE_MASK;
|
||||
GIC_REG_WRITE(val, GICC_CTLR);
|
||||
}
|
||||
#endif
|
||||
U32 OsHwiInit(void)
|
||||
{
|
||||
#if (OS_GIC_VER == 3)
|
||||
U32 ret;
|
||||
|
||||
ret = OsSicInitLocal();
|
||||
if (ret != OS_OK) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
if(PRT_GetCoreID() == 0) {
|
||||
OsSicInitGlobal();
|
||||
}
|
||||
#elif (OS_GIC_VER == 2)
|
||||
OsGicInitCpuInterface();
|
||||
#endif
|
||||
return OS_OK;
|
||||
}
|
||||
@@ -0,0 +1,346 @@
|
||||
/*
|
||||
* Copyright (c) 2009-2022 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
*
|
||||
* UniProton is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
* http://license.coscl.org.cn/MulanPSL2
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PSL v2 for more details.
|
||||
* Create: 2009-12-22
|
||||
* Description: UniProton hi3093 demo
|
||||
*/
|
||||
#include "prt_buildef.h"
|
||||
#include "prt_typedef.h"
|
||||
#include "prt_module.h"
|
||||
#include "prt_errno.h"
|
||||
#include "mmu.h"
|
||||
#include "cache_asm.h"
|
||||
#include "prt_sys.h"
|
||||
#include "prt_task.h"
|
||||
#include "cpu_config.h"
|
||||
|
||||
extern U64 g_mmu_page_begin;
|
||||
extern U64 g_mmu_page_end;
|
||||
|
||||
static mmu_mmap_region_s g_mem_map_info[] = {
|
||||
{
|
||||
.virt = MMU_OPENAMP_ADDR,
|
||||
.phys = MMU_OPENAMP_ADDR,
|
||||
.size = 0x30000,
|
||||
.max_level = 0x2,
|
||||
.attrs = MMU_ATTR_DEVICE_NGNRNE | MMU_ACCESS_RWX,
|
||||
}, {
|
||||
.virt = MMU_IMAGE_ADDR,
|
||||
.phys = MMU_IMAGE_ADDR,
|
||||
.size = 0x1000000,
|
||||
.max_level = 0x2,
|
||||
.attrs = MMU_ATTR_CACHE_SHARE | MMU_ACCESS_RWX,
|
||||
}, {
|
||||
.virt = MMU_GIC_ADDR,
|
||||
.phys = MMU_GIC_ADDR,
|
||||
.size = 0x1000000,
|
||||
.max_level = 0x2,
|
||||
.attrs = MMU_ATTR_DEVICE_NGNRNE | MMU_ACCESS_RWX,
|
||||
}, {
|
||||
.virt = MMU_UART_ADDR,
|
||||
.phys = MMU_UART_ADDR,
|
||||
.size = 0x2000,
|
||||
.max_level = 0x2,
|
||||
.attrs = MMU_ATTR_DEVICE_NGNRNE | MMU_ACCESS_RWX,
|
||||
}
|
||||
};
|
||||
|
||||
static mmu_ctrl_s g_mmu_ctrl = { 0 };
|
||||
|
||||
static U64 mmu_get_tcr(U32 *pips, U32 *pva_bits)
|
||||
{
|
||||
U64 max_addr = 0;
|
||||
U64 ips, va_bits;
|
||||
U64 tcr;
|
||||
U32 i;
|
||||
U32 mmu_table_num = sizeof(g_mem_map_info) / sizeof(mmu_mmap_region_s);
|
||||
|
||||
for (i = 0; i < mmu_table_num; ++i) {
|
||||
max_addr = MAX(max_addr, g_mem_map_info[i].virt + g_mem_map_info[i].size);
|
||||
}
|
||||
|
||||
if (max_addr > (1ULL << MMU_BITS_44)) {
|
||||
ips = MMU_PHY_ADDR_LEVEL_5;
|
||||
va_bits = MMU_BITS_48;
|
||||
} else if (max_addr > (1ULL << MMU_BITS_42)) {
|
||||
ips = MMU_PHY_ADDR_LEVEL_4;
|
||||
va_bits = MMU_BITS_44;
|
||||
} else if (max_addr > (1ULL << MMU_BITS_40)) {
|
||||
ips = MMU_PHY_ADDR_LEVEL_3;
|
||||
va_bits = MMU_BITS_42;
|
||||
} else if (max_addr > (1ULL << MMU_BITS_36)) {
|
||||
ips = MMU_PHY_ADDR_LEVEL_2;
|
||||
va_bits = MMU_BITS_40;
|
||||
} else if (max_addr > (1ULL << MMU_BITS_32)) {
|
||||
ips = MMU_PHY_ADDR_LEVEL_1;
|
||||
va_bits = MMU_BITS_36;
|
||||
} else {
|
||||
ips = MMU_PHY_ADDR_LEVEL_0;
|
||||
va_bits = MMU_BITS_32;
|
||||
}
|
||||
|
||||
tcr = TCR_EL1_RSVD | TCR_IPS(ips);
|
||||
|
||||
if (g_mmu_ctrl.granule == MMU_GRANULE_4K) {
|
||||
tcr |= TCR_TG0_4K | TCR_SHARED_INNER | TCR_ORGN_WBWA | TCR_IRGN_WBWA;
|
||||
} else {
|
||||
tcr |= TCR_TG0_64K | TCR_SHARED_INNER | TCR_ORGN_WBWA | TCR_IRGN_WBWA;
|
||||
}
|
||||
|
||||
tcr |= TCR_T0SZ(va_bits);
|
||||
|
||||
if (pips != NULL) {
|
||||
*pips = ips;
|
||||
}
|
||||
|
||||
if (pva_bits != NULL) {
|
||||
*pva_bits = va_bits;
|
||||
}
|
||||
|
||||
return tcr;
|
||||
}
|
||||
|
||||
static U32 mmu_get_pte_type(U64 const *pte)
|
||||
{
|
||||
return (U32)(*pte & PTE_TYPE_MASK);
|
||||
}
|
||||
|
||||
static U32 mmu_level2shift(U32 level)
|
||||
{
|
||||
if (g_mmu_ctrl.granule == MMU_GRANULE_4K) {
|
||||
return (U32)(MMU_BITS_12 + MMU_BITS_9 * (MMU_LEVEL_3 - level));
|
||||
} else {
|
||||
return (U32)(MMU_BITS_16 + MMU_BITS_13 * (MMU_LEVEL_3 - level));
|
||||
}
|
||||
}
|
||||
|
||||
static U64 *mmu_find_pte(U64 addr, U32 level)
|
||||
{
|
||||
U64 *pte = NULL;
|
||||
U64 idx;
|
||||
U32 i;
|
||||
|
||||
if (level < g_mmu_ctrl.start_level) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pte = (U64 *)g_mmu_ctrl.tlb_addr;
|
||||
|
||||
for (i = g_mmu_ctrl.start_level; i < MMU_LEVEL_MAX; ++i) {
|
||||
if (g_mmu_ctrl.granule == MMU_GRANULE_4K) {
|
||||
idx = (addr >> mmu_level2shift(i)) & 0x1FF;
|
||||
} else {
|
||||
idx = (addr >> mmu_level2shift(i)) & 0x1FFF;
|
||||
}
|
||||
|
||||
pte += idx;
|
||||
|
||||
if (i == level) {
|
||||
return pte;
|
||||
}
|
||||
|
||||
if (mmu_get_pte_type(pte) != PTE_TYPE_TABLE) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (g_mmu_ctrl.granule == MMU_GRANULE_4K) {
|
||||
pte = (U64 *)(*pte & PTE_TABLE_ADDR_MARK_4K);
|
||||
} else {
|
||||
pte = (U64 *)(*pte & PTE_TABLE_ADDR_MARK_64K);
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static U64 *mmu_create_table(void)
|
||||
{
|
||||
U32 pt_len;
|
||||
U64 *new_table = (U64 *)g_mmu_ctrl.tlb_fillptr;
|
||||
|
||||
if (g_mmu_ctrl.granule == MMU_GRANULE_4K) {
|
||||
pt_len = MAX_PTE_ENTRIES_4K * sizeof(U64);
|
||||
} else {
|
||||
pt_len = MAX_PTE_ENTRIES_64K * sizeof(U64);
|
||||
}
|
||||
|
||||
g_mmu_ctrl.tlb_fillptr += pt_len;
|
||||
|
||||
if (g_mmu_ctrl.tlb_fillptr - g_mmu_ctrl.tlb_addr > g_mmu_ctrl.tlb_size) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
(void)memset_s((void *)new_table, MAX_PTE_ENTRIES_64K * sizeof(U64), 0, pt_len);
|
||||
|
||||
return new_table;
|
||||
}
|
||||
|
||||
static void mmu_set_pte_table(U64 *pte, U64 *table)
|
||||
{
|
||||
*pte = PTE_TYPE_TABLE | (U64)table;
|
||||
}
|
||||
|
||||
static S32 mmu_add_map_pte_process(mmu_mmap_region_s const *map, U64 *pte, U64 phys, U32 level)
|
||||
{
|
||||
U64 *new_table = NULL;
|
||||
|
||||
if (level < map->max_level) {
|
||||
if (mmu_get_pte_type(pte) == PTE_TYPE_FAULT) {
|
||||
new_table = mmu_create_table();
|
||||
if (new_table == NULL) {
|
||||
return -1;
|
||||
}
|
||||
mmu_set_pte_table(pte, new_table);
|
||||
}
|
||||
} else if (level == MMU_LEVEL_3) {
|
||||
*pte = phys | map->attrs | PTE_TYPE_PAGE;
|
||||
} else {
|
||||
*pte = phys | map->attrs | PTE_TYPE_BLOCK;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static S32 mmu_add_map(mmu_mmap_region_s const *map)
|
||||
{
|
||||
U64 virt = map->virt;
|
||||
U64 phys = map->phys;
|
||||
U64 max_level = map->max_level;
|
||||
U64 start_level = g_mmu_ctrl.start_level;
|
||||
U64 block_size = 0;
|
||||
U64 map_size = 0;
|
||||
U32 level;
|
||||
U64 *pte = NULL;
|
||||
S32 ret;
|
||||
|
||||
if (map->max_level <= start_level) {
|
||||
return -2;
|
||||
}
|
||||
|
||||
while (map_size < map->size) {
|
||||
for (level = start_level; level <= max_level; ++level) {
|
||||
pte = mmu_find_pte(virt, level);
|
||||
if (pte == NULL) {
|
||||
return -3;
|
||||
}
|
||||
|
||||
ret = mmu_add_map_pte_process(map, pte, phys, level);
|
||||
if (ret) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (level != start_level) {
|
||||
block_size = 1ULL << mmu_level2shift(level);
|
||||
}
|
||||
}
|
||||
|
||||
virt += block_size;
|
||||
phys += block_size;
|
||||
map_size += block_size;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline void mmu_set_ttbr_tcr_mair(U64 table, U64 tcr, U64 attr)
|
||||
{
|
||||
OS_EMBED_ASM("dsb sy");
|
||||
|
||||
OS_EMBED_ASM("msr ttbr0_el1, %0" : : "r" (table) : "memory");
|
||||
OS_EMBED_ASM("msr ttbr1_el1, %0" : : "r" (table) : "memory");
|
||||
OS_EMBED_ASM("msr tcr_el1, %0" : : "r" (tcr) : "memory");
|
||||
OS_EMBED_ASM("msr mair_el1, %0" : : "r" (attr) : "memory");
|
||||
|
||||
OS_EMBED_ASM("isb");
|
||||
}
|
||||
|
||||
static U32 mmu_setup_pgtables(mmu_mmap_region_s *mem_map, U32 mem_region_num, U64 tlb_addr, U64 tlb_len, U32 granule)
|
||||
{
|
||||
U32 i;
|
||||
U32 ret;
|
||||
U64 tcr;
|
||||
U64 *new_table = NULL;
|
||||
|
||||
g_mmu_ctrl.tlb_addr = tlb_addr;
|
||||
g_mmu_ctrl.tlb_size = tlb_len;
|
||||
g_mmu_ctrl.tlb_fillptr = tlb_addr;
|
||||
g_mmu_ctrl.granule = granule;
|
||||
g_mmu_ctrl.start_level = 0;
|
||||
|
||||
tcr = mmu_get_tcr(NULL, &g_mmu_ctrl.va_bits);
|
||||
|
||||
if (g_mmu_ctrl.granule == MMU_GRANULE_4K) {
|
||||
if (g_mmu_ctrl.va_bits < MMU_BITS_39) {
|
||||
g_mmu_ctrl.start_level = MMU_LEVEL_1;
|
||||
} else {
|
||||
g_mmu_ctrl.start_level = MMU_LEVEL_0;
|
||||
}
|
||||
} else {
|
||||
if (g_mmu_ctrl.va_bits <= MMU_BITS_36) {
|
||||
g_mmu_ctrl.start_level = MMU_LEVEL_2;
|
||||
} else {
|
||||
g_mmu_ctrl.start_level = MMU_LEVEL_1;
|
||||
return 3;
|
||||
}
|
||||
}
|
||||
|
||||
new_table = mmu_create_table();
|
||||
if (new_table == NULL) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
for (i = 0; i < mem_region_num; ++i) {
|
||||
ret = mmu_add_map(&mem_map[i]);
|
||||
if (ret) {
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
mmu_set_ttbr_tcr_mair(g_mmu_ctrl.tlb_addr, tcr, MEMORY_ATTRIBUTES);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static S32 mmu_setup(void)
|
||||
{
|
||||
S32 ret;
|
||||
U64 page_addr;
|
||||
U64 page_len;
|
||||
|
||||
page_addr = (U64)&g_mmu_page_begin;
|
||||
page_len = (U64)&g_mmu_page_end - (U64)&g_mmu_page_begin;
|
||||
|
||||
ret = mmu_setup_pgtables(g_mem_map_info, (sizeof(g_mem_map_info) / sizeof(mmu_mmap_region_s)),
|
||||
page_addr, page_len, MMU_GRANULE_4K);
|
||||
if (ret) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
S32 mmu_init(void)
|
||||
{
|
||||
S32 ret;
|
||||
|
||||
ret = mmu_setup();
|
||||
if (ret) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
os_asm_invalidate_dcache_all();
|
||||
os_asm_invalidate_icache_all();
|
||||
os_asm_invalidate_tlb_all();
|
||||
|
||||
set_sctlr(get_sctlr() | CR_C | CR_M | CR_I);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,220 @@
|
||||
/*
|
||||
* Copyright (c) 2009-2022 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
*
|
||||
* UniProton is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
* http://license.coscl.org.cn/MulanPSL2
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PSL v2 for more details.
|
||||
* Create: 2009-12-22
|
||||
* Description: UniProton hi3093 demo
|
||||
*/
|
||||
#ifndef __MMU_H__
|
||||
#define __MMU_H__
|
||||
|
||||
#include "prt_typedef.h"
|
||||
|
||||
#define CACHE_POS 0x2
|
||||
#define CACHE_ENABLE 0x4
|
||||
#define CACHE_MASK 0x7
|
||||
|
||||
#define MT_DEVICE_NGNRNE 0
|
||||
#define MT_DEVICE_NGNRE 1
|
||||
#define MT_DEVICE_GRE 2
|
||||
#define MT_NORMAL_NC 3
|
||||
#define MT_NORMAL 4
|
||||
|
||||
#define MEMORY_ATTRIBUTES ((0x00 << (MT_DEVICE_NGNRNE * 8)) | \
|
||||
(0x04 << (MT_DEVICE_NGNRE * 8)) | \
|
||||
(0x0c << (MT_DEVICE_GRE * 8)) | \
|
||||
(0x44 << (MT_NORMAL_NC * 8)) | \
|
||||
(0xffUL << (MT_NORMAL * 8)))
|
||||
|
||||
#define PTE_TYPE_FAULT (0 << 0)
|
||||
#define PTE_TYPE_BLOCK (1 << 0)
|
||||
#define PTE_TYPE_VALID (1 << 0)
|
||||
#define PTE_TYPE_MASK (3 << 0)
|
||||
#define PTE_TYPE_PAGE (3 << 0)
|
||||
#define PTE_TYPE_TABLE (3 << 0)
|
||||
|
||||
#define PTE_TABLE_PXN (1UL << 59)
|
||||
#define PTE_TABLE_XN (1UL << 60)
|
||||
#define PTE_TABLE_AP (1UL << 61)
|
||||
#define PTE_TABLE_NS (1UL << 63)
|
||||
|
||||
#define PTE_BLOCK_MEMTYPE(x) ((x) << 2)
|
||||
#define PTE_BLOCK_NS (1 << 5)
|
||||
#define PTE_BLOCK_AP_R (2 << 6)
|
||||
#define PTE_BLOCK_AP_RW (0 << 6)
|
||||
#define PTE_BLOCK_NON_SHARE (0 << 8)
|
||||
#define PTE_BLOCK_OUTER_SHARE (2 << 8)
|
||||
#define PTE_BLOCK_INNER_SHARE (3 << 8)
|
||||
#define PTE_BLOCK_AF (1 << 10)
|
||||
#define PTE_BLOCK_NG (1 << 11)
|
||||
#define PTE_BLOCK_PXN (1UL << 53)
|
||||
#define PTE_BLOCK_UXN (1UL << 54)
|
||||
|
||||
#define PMD_ATTRINDX(t) ((t) << 2)
|
||||
#define PMD_ATTRINDX_MASK (7 << 2)
|
||||
#define PMD_ATTRMASK (PTE_BLOCK_PXN | \
|
||||
PTE_BLOCK_UXN | \
|
||||
PMD_ATTRINDX_MASK | \
|
||||
PTE_TYPE_VALID)
|
||||
|
||||
#define TCR_IPS(x) ((x) << 32)
|
||||
#define TCR_T0SZ(x) ((64 - (x)) << 0)
|
||||
#define TCR_IRGN_NC (0 << 8)
|
||||
#define TCR_IRGN_WBWA (1 << 8)
|
||||
#define TCR_IRGN_WT (2 << 8)
|
||||
#define TCR_IRGN_WBNWA (3 << 8)
|
||||
#define TCR_IRGN_MASK (3 << 8)
|
||||
#define TCR_ORGN_NC (0 << 10)
|
||||
#define TCR_ORGN_WBWA (1 << 10)
|
||||
#define TCR_ORGN_WT (2 << 10)
|
||||
#define TCR_ORGN_WBNWA (3 << 10)
|
||||
#define TCR_ORGN_MASK (3 << 10)
|
||||
#define TCR_SHARED_NON (0 << 12)
|
||||
#define TCR_SHARED_OUTER (2 << 12)
|
||||
#define TCR_SHARED_INNER (3 << 12)
|
||||
#define TCR_TG0_4K (0 << 14)
|
||||
#define TCR_TG0_64K (1 << 14)
|
||||
#define TCR_TG0_16K (2 << 14)
|
||||
#define TCR_EPD1_DISABLE (1 << 23)
|
||||
|
||||
#define TCR_EL1_RSVD (1UL << 31)
|
||||
#define TCR_EL2_RSVD (1UL << 31 | 1UL << 23)
|
||||
#define TCR_EL3_RSVD (1UL << 31 | 1UL << 23)
|
||||
|
||||
#define MAX_PTE_ENTRIES_4K 512
|
||||
#define MAX_PTE_ENTRIES_64K 8192
|
||||
|
||||
#define PTE_TABLE_ADDR_MARK_4K 0x0000FFFFFFFFF000ULL
|
||||
#define PTE_TABLE_ADDR_MARK_64K 0x0000FFFFFFFF0000ULL
|
||||
|
||||
|
||||
#define MMU_ATTR_DEVICE_NGNRNE (PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE))
|
||||
#define MMU_ATTR_DEVICE (PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRE))
|
||||
#define MMU_ATTR_UNCACHE_UNSHARE (PTE_BLOCK_MEMTYPE(MT_NORMAL_NC) | PTE_BLOCK_NON_SHARE)
|
||||
#define MMU_ATTR_UNCACHE_SHARE (PTE_BLOCK_MEMTYPE(MT_NORMAL_NC) | PTE_BLOCK_INNER_SHARE)
|
||||
#define MMU_ATTR_CACHE_UNSHARE (PTE_BLOCK_MEMTYPE(MT_NORMAL) | PTE_BLOCK_NON_SHARE)
|
||||
#define MMU_ATTR_CACHE_SHARE (PTE_BLOCK_MEMTYPE(MT_NORMAL) | PTE_BLOCK_INNER_SHARE)
|
||||
#define MMU_ATTR_MASK 0X31CULL
|
||||
|
||||
#define MMU_ACCESS_NONE (PTE_BLOCK_AP_RW)
|
||||
#define MMU_ACCESS_R (PTE_BLOCK_AF | PTE_BLOCK_UXN | PTE_BLOCK_PXN | PTE_BLOCK_AP_R)
|
||||
#define MMU_ACCESS_RW (PTE_BLOCK_AF | PTE_BLOCK_UXN | PTE_BLOCK_PXN | PTE_BLOCK_AP_RW)
|
||||
#define MMU_ACCESS_RWX (PTE_BLOCK_AF | PTE_BLOCK_AP_RW)
|
||||
#define MMU_ACCESS_RX (PTE_BLOCK_AF | PTE_BLOCK_AP_R)
|
||||
#define MMU_ACCESS_MASK 0X600000000004C0ULL
|
||||
|
||||
#define MMU_GRANULE_4K 0
|
||||
#define MMU_GRANULE_64K 1
|
||||
|
||||
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
|
||||
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
|
||||
|
||||
#define CR_M (1 << 0)
|
||||
#define CR_A (1 << 1)
|
||||
#define CR_C (1 << 2)
|
||||
#define CR_SA (1 << 3)
|
||||
#define CR_I (1 << 12)
|
||||
#define CR_WXN (1 << 19)
|
||||
#define CR_EE (1 << 25)
|
||||
|
||||
#define SPSR_EL_END_LE (0 << 9)
|
||||
#define SPSR_EL_DEBUG_MASK (1 << 9)
|
||||
#define SPSR_EL_ASYN_MASK (1 << 8)
|
||||
#define SPSR_EL_SERR_MASK (1 << 8)
|
||||
#define SPSR_EL_IRQ_MASK (1 << 7)
|
||||
#define SPSR_EL_FIQ_MASK (1 << 6)
|
||||
#define SPSR_EL_T_A32 (0 << 5)
|
||||
#define SPSR_EL_M_AARCH64 (0 << 4)
|
||||
#define SPSR_EL_M_AARCH32 (1 << 4)
|
||||
#define SPSR_EL_M_SVC (0x3)
|
||||
#define SPSR_EL_M_HYP (0xa)
|
||||
#define SPSR_EL_M_EL1H (5)
|
||||
#define SPSR_EL_M_EL2H (9)
|
||||
|
||||
#define CPUECTLR_EL1_L1PCTL_MASK (7 << 13)
|
||||
#define CPUECTLR_EL1_L3PCTL_MASK (7 << 10)
|
||||
|
||||
typedef enum {
|
||||
MMU_LEVEL_0 = 0,
|
||||
MMU_LEVEL_1,
|
||||
MMU_LEVEL_2,
|
||||
MMU_LEVEL_3,
|
||||
MMU_LEVEL_MAX
|
||||
} mmu_level_e;
|
||||
|
||||
typedef enum {
|
||||
MMU_PHY_ADDR_LEVEL_0 = 0,
|
||||
MMU_PHY_ADDR_LEVEL_1,
|
||||
MMU_PHY_ADDR_LEVEL_2,
|
||||
MMU_PHY_ADDR_LEVEL_3,
|
||||
MMU_PHY_ADDR_LEVEL_4,
|
||||
MMU_PHY_ADDR_LEVEL_5
|
||||
} mmu_physical_addr_size_e;
|
||||
|
||||
typedef enum {
|
||||
MMU_BITS_9 = 9,
|
||||
MMU_BITS_12 = 12,
|
||||
MMU_BITS_13 = 13,
|
||||
MMU_BITS_16 = 16,
|
||||
MMU_BITS_32 = 32,
|
||||
MMU_BITS_36 = 36,
|
||||
MMU_BITS_39 = 39,
|
||||
MMU_BITS_40 = 40,
|
||||
MMU_BITS_42 = 42,
|
||||
MMU_BITS_44 = 44,
|
||||
MMU_BITS_48 = 48,
|
||||
} mmu_bits_e;
|
||||
|
||||
typedef struct {
|
||||
U64 tlb_addr;
|
||||
U64 tlb_size;
|
||||
U64 tlb_fillptr;
|
||||
U32 granule;
|
||||
U32 start_level;
|
||||
U32 va_bits;
|
||||
} mmu_ctrl_s;
|
||||
|
||||
typedef struct {
|
||||
U64 virt;
|
||||
U64 phys;
|
||||
U64 size;
|
||||
U64 max_level;
|
||||
U64 attrs;
|
||||
} mmu_mmap_region_s;
|
||||
|
||||
static inline unsigned long get_sctlr(void)
|
||||
{
|
||||
unsigned long val;
|
||||
|
||||
__asm__ __volatile__("mrs %0, sctlr_el1" : "=r" (val) : : "cc");
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
static inline unsigned long get_cpuectr(void)
|
||||
{
|
||||
unsigned long val;
|
||||
|
||||
__asm__ __volatile__("mrs %0, S3_1_C15_C2_1" : "=r" (val) : : "cc");
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
static inline void set_sctlr(unsigned long val)
|
||||
{
|
||||
__asm__ __volatile__("dsb sy");
|
||||
__asm__ __volatile__("msr sctlr_el1, %0" : : "r" (val) : "cc");
|
||||
__asm__ __volatile__("dsb sy");
|
||||
__asm__ __volatile__("isb");
|
||||
}
|
||||
|
||||
extern S32 mmu_init(void);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,126 @@
|
||||
/*
|
||||
* Copyright (c) 2009-2022 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
*
|
||||
* UniProton is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
* http://license.coscl.org.cn/MulanPSL2
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PSL v2 for more details.
|
||||
* Create: 2009-12-22
|
||||
* Description: UniProton hi3093 demo
|
||||
*/
|
||||
#include <stdarg.h>
|
||||
#include "prt_typedef.h"
|
||||
#include "cpu_config.h"
|
||||
#include "securec.h"
|
||||
#include "serial.h"
|
||||
#include "prt_hwi.h"
|
||||
|
||||
typedef U32 (*PrintFunc)(const char *format, va_list vaList);
|
||||
#define OS_MAX_SHOW_LEN 0x200
|
||||
|
||||
U32 uart_recv(U8 *value)
|
||||
{
|
||||
S32 ret = 0;
|
||||
ret = serial_getc();
|
||||
if (ret == -EAGAIN) {
|
||||
return EAGAIN;
|
||||
}
|
||||
|
||||
*value = (U8)ret;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void uart_recv_hwi(void)
|
||||
{
|
||||
U8 data;
|
||||
while (uart_recv(&data) == 0) {
|
||||
/*Do not printf in this task*/
|
||||
}
|
||||
}
|
||||
|
||||
U32 PRT_UartInit(void)
|
||||
{
|
||||
|
||||
U32 ret;
|
||||
(void)PRT_HwiDelete(CCORE_SYS_UART4_INTID);
|
||||
|
||||
ret = PRT_HwiSetAttr(CCORE_SYS_UART4_INTID, 12, OS_HWI_MODE_ENGROSS);
|
||||
if (ret != OS_OK) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = PRT_HwiCreate(CCORE_SYS_UART4_INTID, (HwiProcFunc)uart_recv_hwi, CCORE_SYS_UART4_INTID);
|
||||
if (ret != OS_OK) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = PRT_HwiEnable(CCORE_SYS_UART4_INTID);
|
||||
if (ret != OS_OK) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
serial_init(&g_uart_cfg, &g_uart_ops);
|
||||
|
||||
return OS_OK;
|
||||
}
|
||||
|
||||
void uart_poll_send(unsigned char ch)
|
||||
{
|
||||
serial_putc((char)ch);
|
||||
}
|
||||
|
||||
void TestPutc(unsigned char ch)
|
||||
{
|
||||
uart_poll_send(ch);
|
||||
if (ch == '\n') {
|
||||
uart_poll_send('\r');
|
||||
}
|
||||
}
|
||||
|
||||
int TestPrintf(const char *format, va_list vaList)
|
||||
{
|
||||
int len;
|
||||
char buff[OS_MAX_SHOW_LEN] = {0};
|
||||
char *str = buff;
|
||||
|
||||
len = vsnprintf_s(buff, OS_MAX_SHOW_LEN, OS_MAX_SHOW_LEN, format, vaList);
|
||||
if (len == -1) {
|
||||
return len;
|
||||
}
|
||||
|
||||
while (*str != '\0') {
|
||||
TestPutc(*str);
|
||||
str++;
|
||||
}
|
||||
|
||||
return OS_OK;
|
||||
}
|
||||
|
||||
U32 PRT_Printf(const char *format, ...)
|
||||
{
|
||||
va_list vaList;
|
||||
S32 count;
|
||||
|
||||
va_start(vaList, format);
|
||||
count = TestPrintf(format, vaList);
|
||||
va_end(vaList);
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
U32 PRT_PrintfInit()
|
||||
{
|
||||
U32 ret;
|
||||
|
||||
ret = PRT_UartInit();
|
||||
if (ret != OS_OK) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
return OS_OK;
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
@/*
|
||||
@ * Copyright (c) 2009-2022 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
@ *
|
||||
@ * UniProton is licensed under Mulan PSL v2.
|
||||
@ * You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
@ * You may obtain a copy of Mulan PSL v2 at:
|
||||
@ * http://license.coscl.org.cn/MulanPSL2
|
||||
@ * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
@ * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
@ * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
@ * See the Mulan PSL v2 for more details.
|
||||
@ * Create: 2009-12-22
|
||||
@ * Description: thread scheduler
|
||||
@ */
|
||||
#include "prt_buildef.h"
|
||||
|
||||
.global OsResetVector
|
||||
.global mmu_init
|
||||
|
||||
.type mmu_init, function
|
||||
.type start, function
|
||||
.section .text.bspinit, "ax"
|
||||
.balign 4
|
||||
|
||||
#define HCR_EL2_FMO (1 << 3)
|
||||
#define HCR_EL2_IMO (1 << 4)
|
||||
#define HCR_EL2_AMO (1 << 5)
|
||||
#define HCR_EL2_TWI (1 << 13)
|
||||
#define HCR_EL2_TWE (1 << 14)
|
||||
#define HCR_EL2_TVM (1 << 26)
|
||||
#define HCR_EL2_TGE (1 << 27)
|
||||
#define HCR_EL2_TDZ (1 << 28)
|
||||
#define HCR_EL2_HCD (1 << 29)
|
||||
#define HCR_EL2_TRVM (1 << 30)
|
||||
#define HCR_EL2_RW (1 << 31)
|
||||
|
||||
#define SPSR_DBG_MASK (1 << 9)
|
||||
#define SPSR_SERR_MASK (1 << 8)
|
||||
#define SPSR_IRQ_MASK (1 << 7)
|
||||
#define SPSR_FIQ_MASK (1 << 6)
|
||||
#define SPSR_M_AARCH64 (0 << 4)
|
||||
#define SPSR_M_AARCH32 (1 << 4)
|
||||
#define SPSR_M_EL1H (5)
|
||||
#define SPSR_M_EL2H (9)
|
||||
|
||||
#define CNTHCTL_EL2_EL1PCEN_EN (1 << 1)
|
||||
#define CNTHCTL_EL2_EL1PCTEN_EN (1 << 0)
|
||||
#define CPACR_EL1_FPEN_EN (3 << 20)
|
||||
|
||||
.global OsElxState
|
||||
.type OsElxState, @function
|
||||
OsElxState:
|
||||
MRS x6, CurrentEL
|
||||
MOV x2, #0x4
|
||||
CMP w6, w2
|
||||
|
||||
BEQ Start
|
||||
|
||||
OsEl2Entry:
|
||||
MRS x10, CNTHCTL_EL2
|
||||
ORR x10, x10, #0x3
|
||||
MSR CNTHCTL_EL2, x10
|
||||
|
||||
MRS x10, CNTKCTL_EL1
|
||||
ORR x10, x10, #0x3
|
||||
MSR CNTKCTL_EL1, x10
|
||||
|
||||
MRS x10, MIDR_EL1
|
||||
MRS x1, MPIDR_EL1
|
||||
MSR VPIDR_EL2, x10
|
||||
MSR VMPIDR_EL2, x1
|
||||
|
||||
MOV x10, #0x33ff
|
||||
MSR CPTR_EL2, x10
|
||||
MSR HSTR_EL2, xzr
|
||||
|
||||
MRS x10, CPACR_EL1
|
||||
MOV x10, #3 << 20
|
||||
MSR CPACR_EL1, x10
|
||||
|
||||
MOV x10, #(HCR_EL2_RW)
|
||||
ORR x10, x10, #(HCR_EL2_HCD)
|
||||
BIC x10, x10, #(HCR_EL2_TVM)
|
||||
BIC x10, x10, #(HCR_EL2_TRVM)
|
||||
BIC x10, x10, #(HCR_EL2_TGE)
|
||||
BIC x10, x10, #(HCR_EL2_AMO)
|
||||
BIC x10, x10, #(HCR_EL2_IMO)
|
||||
BIC x10, x10, #(HCR_EL2_FMO)
|
||||
BIC x10, x10, #(HCR_EL2_TWI)
|
||||
BIC x10, x10, #(HCR_EL2_TWE)
|
||||
|
||||
MSR HCR_EL2, x10
|
||||
|
||||
OsEl2SwitchToEl1:
|
||||
ADR x0, Start
|
||||
MSR SP_EL1, XZR
|
||||
MSR ELR_EL2, x0
|
||||
MOV x0, XZR
|
||||
|
||||
LDR x20, =(SPSR_DBG_MASK | SPSR_SERR_MASK | \
|
||||
SPSR_IRQ_MASK | SPSR_FIQ_MASK | SPSR_M_EL1H)
|
||||
MSR SPSR_EL2, x20
|
||||
|
||||
TLBI ALLE1IS
|
||||
IC IALLU
|
||||
DSB SY
|
||||
ISB
|
||||
ERET
|
||||
|
||||
Start:
|
||||
LDR x1, =__os_sys_sp_end
|
||||
BIC sp, x1, #0xf
|
||||
|
||||
BL mmu_init
|
||||
B OsResetVector
|
||||
|
||||
OsEnterReset:
|
||||
B OsEnterReset
|
||||
|
||||
.section .text, "ax"
|
||||
.balign 4
|
||||
@@ -0,0 +1,102 @@
|
||||
/*
|
||||
* Copyright (c) 2009-2022 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
*
|
||||
* UniProton is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
* http://license.coscl.org.cn/MulanPSL2
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PSL v2 for more details.
|
||||
* Create: 2009-12-22
|
||||
* Description: UniProton hi3093 demo
|
||||
*/
|
||||
#include "prt_sys.h"
|
||||
#include "prt_tick.h"
|
||||
#include "prt_config.h"
|
||||
#include "prt_task.h"
|
||||
#include "prt_hwi.h"
|
||||
#include "cpu_config.h"
|
||||
#include "securec.h"
|
||||
|
||||
U64 g_timerFrequency;
|
||||
#define PMU_TIMER_FREQUENCY g_timerFrequency
|
||||
|
||||
U64 GetGenericTimerFreq(void)
|
||||
{
|
||||
U64 freq;
|
||||
|
||||
OS_EMBED_ASM("MRS %0, CNTFRQ_EL0" : "=r"(freq) : : "memory", "cc");
|
||||
|
||||
return freq;
|
||||
}
|
||||
|
||||
void TimerIsr(uintptr_t para)
|
||||
{
|
||||
(void)para;
|
||||
U32 cfgMask = 0x0;
|
||||
U64 cycle = PMU_TIMER_FREQUENCY / OS_TICK_PER_SECOND;
|
||||
|
||||
OS_EMBED_ASM("MSR CNTP_CTL_EL0, %0" : : "r"(cfgMask) : "memory");
|
||||
PRT_ISB();
|
||||
OS_EMBED_ASM("MSR CNTP_TVAL_EL0, %0" : : "r"(cycle) : "memory", "cc");
|
||||
|
||||
cfgMask = 0x1;
|
||||
OS_EMBED_ASM("MSR CNTP_CTL_EL0, %0" : : "r"(cfgMask) : "memory");
|
||||
|
||||
PRT_TickISR();
|
||||
PRT_ISB();
|
||||
}
|
||||
|
||||
void CoreTimerInit(void)
|
||||
{
|
||||
U32 cfgMask = 0x0;
|
||||
U64 cycle = PMU_TIMER_FREQUENCY / OS_TICK_PER_SECOND;
|
||||
|
||||
OS_EMBED_ASM("MSR CNTP_CTL_EL0, %0" : : "r"(cfgMask) : "memory");
|
||||
PRT_ISB();
|
||||
OS_EMBED_ASM("MSR CNTP_TVAL_EL0, %0" : : "r"(cycle) : "memory", "cc");
|
||||
|
||||
cfgMask = 0x1;
|
||||
OS_EMBED_ASM("MSR CNTP_CTL_EL0, %0" : : "r"(cfgMask) : "memory");
|
||||
}
|
||||
|
||||
U32 CoreTimerStart(void)
|
||||
{
|
||||
g_timerFrequency = GetGenericTimerFreq();
|
||||
CoreTimerInit();
|
||||
|
||||
return OS_OK;
|
||||
}
|
||||
|
||||
U32 TestClkStart(void)
|
||||
{
|
||||
U32 ret;
|
||||
|
||||
ret = PRT_HwiSetAttr(TEST_CLK_INT, 10, OS_HWI_MODE_ENGROSS);
|
||||
if (ret != OS_OK) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = PRT_HwiCreate(TEST_CLK_INT, (HwiProcFunc)TimerIsr, 0);
|
||||
if (ret != OS_OK) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
#if (OS_GIC_VER == 3)
|
||||
ret = PRT_HwiEnable(TEST_CLK_INT);
|
||||
if (ret != OS_OK) {
|
||||
return ret;
|
||||
}
|
||||
#elif (OS_GIC_VER == 2)
|
||||
IsrRegister(TEST_CLK_INT, 0xaU, (0x1U << 0x3U));
|
||||
#endif
|
||||
|
||||
ret = CoreTimerStart();
|
||||
if (ret != OS_OK) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
return OS_OK;
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
set(SRCS uart.c uart_core.c serial.c)
|
||||
add_library(uart OBJECT ${SRCS})
|
||||
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* Copyright (c) 2009-2022 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
*
|
||||
* UniProton is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
* http://license.coscl.org.cn/MulanPSL2
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PSL v2 for more details.
|
||||
* Create: 2009-12-22
|
||||
* Description: UniProton hi3093 demo
|
||||
*/
|
||||
#ifndef __COMMON_H__
|
||||
#define __COMMON_H__
|
||||
|
||||
#include "prt_config.h"
|
||||
|
||||
#define PERI_APB_FREQ 100000000
|
||||
#define UART_BUSY_TIMEOUT 1000000
|
||||
#define ETIME 62
|
||||
|
||||
#define DIV_ROUND_CLOSEST(x, divisor, result) \
|
||||
({ \
|
||||
typeof(x) __x = x; \
|
||||
typeof(divisor) __d = divisor; \
|
||||
result = (((typeof(x)) - 1) > 0 || \
|
||||
((typeof(divisor)) - 1) > 0 || \
|
||||
(((__x) > 0) == ((__d) > 0))) ? \
|
||||
(((__x) + ((__d) / 2)) / (__d)) : \
|
||||
(((__x) - ((__d) / 2)) / (__d)); \
|
||||
})
|
||||
|
||||
#define EPERM 1 /* Operation not permitted */
|
||||
#define ENOENT 2 /* No such file or directory */
|
||||
#define ESRCH 3 /* No such process */
|
||||
#define EINTR 4 /* Interrupted system call */
|
||||
#define EIO 5 /* I/O error */
|
||||
#define ENXIO 6 /* No such device or address */
|
||||
#define E2BIG 7 /* Argument list too long */
|
||||
#define ENOEXEC 8 /* Exec format error */
|
||||
#define EBADF 9 /* Bad file number */
|
||||
#define ECHILD 10 /* No child processes */
|
||||
#define EAGAIN 11 /* Try again */
|
||||
#define ENOMEM 12 /* Out of memory */
|
||||
#define EACCES 13 /* Permission denied */
|
||||
#define EFAULT 14 /* Bad address */
|
||||
#define ENOTBLK 15 /* Block device required */
|
||||
#define EBUSY 16 /* Device or resource busy */
|
||||
#define EEXIST 17 /* File exists */
|
||||
#define EXDEV 18 /* Cross-device link */
|
||||
#define ENODEV 19 /* No such device */
|
||||
#define ENOTDIR 20 /* Not a directory */
|
||||
#define EISDIR 21 /* Is a directory */
|
||||
#define EINVAL 22 /* Invalid argument */
|
||||
#define ENFILE 23 /* File table overflow */
|
||||
#define EMFILE 24 /* Too many open files */
|
||||
#define ENOTTY 25 /* Not a typewriter */
|
||||
#define ETXTBSY 26 /* Text file busy */
|
||||
#define EFBIG 27 /* File too large */
|
||||
#define ENOSPC 28 /* No space left on device */
|
||||
#define ESPIPE 29 /* Illegal seek */
|
||||
#define EROFS 30 /* Read-only file system */
|
||||
#define EMLINK 31 /* Too many links */
|
||||
#define EPIPE 32 /* Broken pipe */
|
||||
#define EDOM 33 /* Math argument out of domain of func */
|
||||
#define ERANGE 34 /* Math result not representable */
|
||||
|
||||
#endif /* __COMMON_H__ */
|
||||
@@ -0,0 +1,130 @@
|
||||
/*
|
||||
* Copyright (c) 2009-2022 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
*
|
||||
* UniProton is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
* http://license.coscl.org.cn/MulanPSL2
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PSL v2 for more details.
|
||||
* Create: 2009-12-22
|
||||
* Description: UniProton hi3093 demo
|
||||
*/
|
||||
#include "serial.h"
|
||||
#include "securec.h"
|
||||
#include "common.h"
|
||||
|
||||
serial_t g_sys_serial;
|
||||
#define HW_UART_NO (g_sys_serial.cfg.hw_uart_no)
|
||||
#define UART_CLK (PERI_APB_FREQ)
|
||||
#define EAGAIN 11
|
||||
|
||||
void serial_soft_init(serial_cfg *cfg, uart_ops *hw_ops)
|
||||
{
|
||||
if (!cfg || !hw_ops) {
|
||||
return;
|
||||
}
|
||||
|
||||
g_sys_serial.cfg.init_done = 0;
|
||||
g_sys_serial.cfg.hw_uart_no = SERIAL_SEL_UART_PORT;
|
||||
g_sys_serial.cfg.uart_src_clk = UART_CLK;
|
||||
strncpy_s(g_sys_serial.cfg.name, SERIAL_NAME_SIZE, cfg->name, SERIAL_NAME_SIZE - 1);
|
||||
g_sys_serial.cfg.data_bits = cfg->data_bits;
|
||||
g_sys_serial.cfg.stop = cfg->stop;
|
||||
g_sys_serial.cfg.pen = cfg->pen;
|
||||
g_sys_serial.cfg.eps = cfg->eps;
|
||||
g_sys_serial.cfg.baud_rate = cfg->baud_rate;
|
||||
g_sys_serial.hw_ops = hw_ops;
|
||||
|
||||
g_sys_serial.cfg.init_done = 1;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void serial_init(serial_cfg *cfg, uart_ops *hw_ops)
|
||||
{
|
||||
if (!cfg || !hw_ops) {
|
||||
return;
|
||||
}
|
||||
|
||||
serial_soft_init(cfg, hw_ops);
|
||||
|
||||
g_sys_serial.cfg.init_done = 0;
|
||||
|
||||
if (g_sys_serial.hw_ops->init(&g_sys_serial.cfg)) {
|
||||
return;
|
||||
}
|
||||
|
||||
g_sys_serial.cfg.init_done = 1;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void serial_putc(const char ch)
|
||||
{
|
||||
uart_ops *hw_ops = g_sys_serial.hw_ops;
|
||||
|
||||
if (g_sys_serial.cfg.init_done) {
|
||||
if (ch == '\n') {
|
||||
hw_ops->put_char(HW_UART_NO, '\r');
|
||||
}
|
||||
hw_ops->put_char(HW_UART_NO, ch);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
S32 serial_getc(void)
|
||||
{
|
||||
uart_ops *hw_ops = g_sys_serial.hw_ops;
|
||||
|
||||
if (g_sys_serial.cfg.init_done) {
|
||||
if (!hw_ops->rx_ready(HW_UART_NO)) {
|
||||
return -EAGAIN;
|
||||
}
|
||||
|
||||
return hw_ops->get_char(HW_UART_NO);
|
||||
}
|
||||
|
||||
return -EAGAIN;
|
||||
}
|
||||
|
||||
void serial_puts(const char *s)
|
||||
{
|
||||
if (!g_sys_serial.cfg.init_done) {
|
||||
return;
|
||||
}
|
||||
|
||||
while (*s) {
|
||||
serial_putc(*s++);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
S32 serial_tstc(void)
|
||||
{
|
||||
uart_ops *hw_ops = NULL;
|
||||
|
||||
if (!g_sys_serial.cfg.init_done) {
|
||||
return OS_OK;
|
||||
}
|
||||
|
||||
hw_ops = g_sys_serial.hw_ops;
|
||||
|
||||
return (S32)hw_ops->rx_ready(HW_UART_NO);
|
||||
}
|
||||
|
||||
void serial_flush(void)
|
||||
{
|
||||
uart_ops *hw_ops = g_sys_serial.hw_ops;
|
||||
|
||||
if (!g_sys_serial.cfg.init_done) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* just flush, don't care fail */
|
||||
(void)hw_ops->wait4idle(g_sys_serial.cfg.hw_uart_no, SERIAL_FLUSH_TMOUT);
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* Copyright (c) 2009-2022 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
*
|
||||
* UniProton is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
* http://license.coscl.org.cn/MulanPSL2
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PSL v2 for more details.
|
||||
* Create: 2009-12-22
|
||||
* Description: UniProton hi3093 demo
|
||||
*/
|
||||
#ifndef __SERIAL_H__
|
||||
#define __SERIAL_H__
|
||||
|
||||
#include "uart_regs.h"
|
||||
#include "prt_typedef.h"
|
||||
|
||||
#define SERIAL_SEL_UART_PORT 4
|
||||
|
||||
#define SERIAL_TIMEOUT_MS 10
|
||||
#define SERIAL_NAME_SIZE 32
|
||||
#define SERIAL_FLUSH_TMOUT 0x100000
|
||||
|
||||
typedef struct _serial_cfg {
|
||||
char name[SERIAL_NAME_SIZE];
|
||||
S32 init_done;
|
||||
S32 hw_uart_no;
|
||||
U32 uart_src_clk;
|
||||
U8 data_bits;
|
||||
U8 stop;
|
||||
U8 pen;
|
||||
U8 eps;
|
||||
S32 baud_rate;
|
||||
} serial_cfg;
|
||||
|
||||
typedef struct {
|
||||
S32 (*init)(serial_cfg *cfg);
|
||||
void (*setbrg)(serial_cfg *cfg);
|
||||
S32 (*put_char)(S32 hw_uart_no, const char ch);
|
||||
S32 (*get_char)(S32 hw_uart_no);
|
||||
S32 (*tx_ready)(S32 hw_uart_no);
|
||||
S32 (*rx_ready)(S32 hw_uart_no);
|
||||
S32 (*wait4idle)(S32 hw_uart_no, U32 time_out);
|
||||
} uart_ops;
|
||||
|
||||
typedef struct _serial {
|
||||
serial_cfg cfg;
|
||||
uart_ops *hw_ops;
|
||||
} serial_t;
|
||||
|
||||
extern uart_ops g_uart_ops;
|
||||
extern serial_cfg g_uart_cfg;
|
||||
|
||||
extern void serial_soft_init(serial_cfg *cfg, uart_ops *hw_ops);
|
||||
extern void serial_init(serial_cfg *cfg, uart_ops *hw_ops);
|
||||
extern serial_t *serial_get(void);
|
||||
extern void serial_putc(const char ch);
|
||||
extern S32 serial_getc(void);
|
||||
extern void serial_puts(const char *s);
|
||||
extern S32 serial_tstc(void);
|
||||
extern void serial_flush(void);
|
||||
extern void printf_resource_init(void);
|
||||
extern S32 uart_init(serial_cfg *cfg);
|
||||
extern void uart_raw_puts(S32 uart_no, const S8 *str);
|
||||
extern S32 uart_busy_poll(S32 hw_uart_no);
|
||||
|
||||
#endif /* __SERIAL_H__ */
|
||||
@@ -0,0 +1,187 @@
|
||||
/*
|
||||
* Copyright (c) 2009-2022 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
*
|
||||
* UniProton is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
* http://license.coscl.org.cn/MulanPSL2
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PSL v2 for more details.
|
||||
* Create: 2009-12-22
|
||||
* Description: UniProton hi3093 demo
|
||||
*/
|
||||
#include "serial.h"
|
||||
#include "uart_core.h"
|
||||
#include "uart_regs.h"
|
||||
#include "common.h"
|
||||
#include "prt_typedef.h"
|
||||
|
||||
static S32 uart_busy_timeout(void)
|
||||
{
|
||||
return UART_BUSY_TIMEOUT;
|
||||
}
|
||||
|
||||
/* Caculate UART Divisor Factor */
|
||||
void calc_uart_dll_dlh(U32 uartclk, U32 baudrate, U32 *dll, U32 *dlh)
|
||||
{
|
||||
U32 divisor;
|
||||
|
||||
/*
|
||||
* baudrate = bus_clock / (16 * divisor)
|
||||
* ==> divisor = bus_clock/(baudrate * 16) */
|
||||
DIV_ROUND_CLOSEST(uartclk, (16 * baudrate), divisor); /* 16 just for codestyle */
|
||||
*dll = divisor & 0xFF;
|
||||
*dlh = (divisor >> 8) & 0xFF; /* take high 8 bits */
|
||||
}
|
||||
|
||||
static U32 calc_lcr_reg_val(serial_cfg *cfg)
|
||||
{
|
||||
U32 lcr = 0;
|
||||
|
||||
switch (cfg->data_bits) {
|
||||
case 8: /* 8个数据位 */
|
||||
lcr |= DW_UART_8bit;
|
||||
break;
|
||||
case 7: /* 7个数据位 */
|
||||
lcr |= DW_UART_7bit;
|
||||
break;
|
||||
case 6: /* 6个数据位 */
|
||||
lcr |= DW_UART_6bit;
|
||||
break;
|
||||
case 5: /* 5个数据位 */
|
||||
lcr |= DW_UART_5bit;
|
||||
break;
|
||||
default:
|
||||
lcr |= DW_UART_8bit;
|
||||
break;
|
||||
}
|
||||
|
||||
/* 0 - 1 stop bit 1 - 2 stop bit */
|
||||
if (cfg->stop == 2) {
|
||||
lcr |= DW_UART_STOP;
|
||||
}
|
||||
|
||||
if (cfg->pen) {
|
||||
lcr |= DW_UART_PEN;
|
||||
if (cfg->eps) {
|
||||
lcr |= DW_UART_EPS;
|
||||
}
|
||||
}
|
||||
|
||||
return lcr;
|
||||
}
|
||||
|
||||
void uart_set_baudrate(serial_cfg *cfg)
|
||||
{
|
||||
U32 dll = 0;
|
||||
U32 dlh = 0;
|
||||
|
||||
/* Wait till uart is idle */
|
||||
(void)uart_wait4idle(cfg->hw_uart_no, uart_busy_timeout());
|
||||
calc_uart_dll_dlh(cfg->uart_src_clk, cfg->baud_rate, &dll, &dlh);
|
||||
uart_set_dll_dlh(cfg->hw_uart_no, dll, dlh);
|
||||
}
|
||||
|
||||
S32 uart_init(serial_cfg *cfg)
|
||||
{
|
||||
U32 fifo_ctrl;
|
||||
|
||||
/* max data_bits is 8 */
|
||||
if ((cfg == NULL) || (cfg->hw_uart_no >= MAX_UART_NUM) || (cfg->hw_uart_no < 0) || (cfg->data_bits > 8)) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
/* Config FIFO,DLL,DLH at first */
|
||||
uart_set_baudrate(cfg);
|
||||
fifo_ctrl = FIFOENA | UART_FCR_RXCLR | UART_FCR_TXCLR;
|
||||
uart_set_fifo_ctrl(cfg->hw_uart_no, fifo_ctrl);
|
||||
/* Set data bits, stop bit, parity check */
|
||||
uart_set_lcr(cfg->hw_uart_no, calc_lcr_reg_val(cfg));
|
||||
|
||||
/* enable rx irq */
|
||||
uart_set_irq_enable(cfg->hw_uart_no, 1);
|
||||
return OS_OK;
|
||||
}
|
||||
|
||||
S32 uart_tx(S32 hw_uart_no, const char c)
|
||||
{
|
||||
S32 timeout = 0;
|
||||
S32 max_timeout = uart_busy_timeout();
|
||||
|
||||
while (uart_is_txfifo_full(hw_uart_no)) {
|
||||
timeout++;
|
||||
if (timeout >= max_timeout) {
|
||||
return -ETIME;
|
||||
}
|
||||
}
|
||||
|
||||
uart_tx_char(hw_uart_no, c);
|
||||
return OS_OK;
|
||||
}
|
||||
|
||||
S32 uart_rx(S32 hw_uart_no)
|
||||
{
|
||||
S32 timeout = 0;
|
||||
S32 max_timeout = uart_busy_timeout();
|
||||
S32 c = 0;
|
||||
|
||||
while (!uart_is_rx_ready(hw_uart_no)) {
|
||||
timeout++;
|
||||
if (timeout >= max_timeout) {
|
||||
return -ETIME;
|
||||
}
|
||||
}
|
||||
|
||||
uart_rx_char(hw_uart_no, (S8 *)&c);
|
||||
return c;
|
||||
}
|
||||
|
||||
void uart_raw_puts(S32 hw_uart_no, const S8 *str)
|
||||
{
|
||||
while (*str != '\0') {
|
||||
uart_tx_char(hw_uart_no, *str++);
|
||||
}
|
||||
}
|
||||
|
||||
S32 uart_tx_ready(S32 hw_uart_no)
|
||||
{
|
||||
if (uart_is_txfifo_full(hw_uart_no)) {
|
||||
return OS_OK;
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
S32 uart_rx_ready(S32 hw_uart_no)
|
||||
{
|
||||
return uart_is_rx_ready(hw_uart_no);
|
||||
}
|
||||
|
||||
/*
|
||||
* Wait until uart is not busy
|
||||
* Return 0 if success,otherwise return -1
|
||||
*/
|
||||
S32 uart_busy_poll(S32 hw_uart_no)
|
||||
{
|
||||
return uart_wait4idle(hw_uart_no, uart_busy_timeout());
|
||||
}
|
||||
|
||||
serial_cfg g_uart_cfg = {
|
||||
.name = "uart",
|
||||
.data_bits = 8, /* default data_bits is 8 */
|
||||
.stop = 1,
|
||||
.pen = 0,
|
||||
.baud_rate = 115200 /* default baud_rate is 115200 */
|
||||
};
|
||||
|
||||
uart_ops g_uart_ops = {
|
||||
.init = uart_init,
|
||||
.setbrg = uart_set_baudrate,
|
||||
.put_char = uart_tx,
|
||||
.get_char = uart_rx,
|
||||
.tx_ready = uart_tx_ready,
|
||||
.rx_ready = uart_rx_ready,
|
||||
.wait4idle = uart_wait4idle,
|
||||
};
|
||||
@@ -0,0 +1,182 @@
|
||||
/*
|
||||
* Copyright (c) 2009-2022 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
*
|
||||
* UniProton is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
* http://license.coscl.org.cn/MulanPSL2
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PSL v2 for more details.
|
||||
* Create: 2009-12-22
|
||||
* Description: UniProton hi3093 demo
|
||||
*/
|
||||
#include "uart_core.h"
|
||||
#include "common.h"
|
||||
|
||||
#define UART_REG_READ(addr) (*(volatile U32 *)(((uintptr_t)addr)))
|
||||
#define UART_REG_WRITE(value, addr) (*(volatile U32 *)((uintptr_t)addr) = (U32)value)
|
||||
|
||||
/* Get UART register base address */
|
||||
static S32 uart_core_base_addr(S32 uartno, U32 *reg_base)
|
||||
{
|
||||
unsigned long reg_bases[] = {
|
||||
UART0_REG_BASE,
|
||||
UART1_REG_BASE,
|
||||
UART2_REG_BASE,
|
||||
UART3_REG_BASE,
|
||||
UART4_REG_BASE
|
||||
};
|
||||
|
||||
if (uartno >= MAX_UART_NUM || uartno < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
*reg_base = reg_bases[uartno];
|
||||
|
||||
return OS_OK;
|
||||
}
|
||||
|
||||
S32 uart_reg_read(S32 uartno, U32 offset, U32 *val)
|
||||
{
|
||||
S32 ret;
|
||||
U32 reg_base = 0x0;
|
||||
|
||||
ret = uart_core_base_addr(uartno, ®_base);
|
||||
if (ret) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
*val = UART_REG_READ((unsigned long)(reg_base + offset));
|
||||
return OS_OK;
|
||||
}
|
||||
|
||||
void uart_reg_write(S32 uartno, U32 offset, U32 val)
|
||||
{
|
||||
S32 ret;
|
||||
U32 reg_base = 0x0;
|
||||
|
||||
ret = uart_core_base_addr(uartno, ®_base);
|
||||
if (ret) {
|
||||
return;
|
||||
}
|
||||
|
||||
UART_REG_WRITE(val, (unsigned long)(reg_base + offset));
|
||||
return;
|
||||
}
|
||||
|
||||
void uart_set_lcr_dlab(S32 uartno, S32 dlab_sel)
|
||||
{
|
||||
S32 ret;
|
||||
U32 lcr = 0;
|
||||
|
||||
ret = uart_reg_read(uartno, DW_UART_LCR, &lcr);
|
||||
if (ret) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (dlab_sel) {
|
||||
lcr |= DW_UART_DLAB;
|
||||
} else {
|
||||
lcr &= ~DW_UART_DLAB;
|
||||
}
|
||||
|
||||
uart_reg_write(uartno, DW_UART_LCR, lcr);
|
||||
return;
|
||||
}
|
||||
|
||||
void uart_set_dll_dlh(S32 uartno, U32 dll, U32 dlh)
|
||||
{
|
||||
/* Enable DLL/DLH/FCR access */
|
||||
uart_set_lcr_dlab(uartno, 1);
|
||||
uart_reg_write(uartno, DW_UART_DLL, dll);
|
||||
uart_reg_write(uartno, DW_UART_DLH, dlh);
|
||||
uart_set_lcr_dlab(uartno, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
void uart_get_dll_dlh(S32 uartno, U32 *dll, U32 *dlh)
|
||||
{
|
||||
/* Enable DLL/DLH/FCR access */
|
||||
uart_set_lcr_dlab(uartno, 1);
|
||||
uart_reg_read(uartno, DW_UART_DLL, dll);
|
||||
uart_reg_read(uartno, DW_UART_DLH, dlh);
|
||||
uart_set_lcr_dlab(uartno, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
void uart_set_fifo_ctrl(S32 uartno, U32 fifo_ctrl)
|
||||
{
|
||||
/* Enable DLL/DLH/FCR access */
|
||||
uart_set_lcr_dlab(uartno, 1);
|
||||
uart_reg_write(uartno, DW_UART_FCR, fifo_ctrl);
|
||||
uart_set_lcr_dlab(uartno, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
void uart_set_lcr(S32 uartno, U32 lcr)
|
||||
{
|
||||
uart_reg_write(uartno, DW_UART_LCR, lcr);
|
||||
return;
|
||||
}
|
||||
|
||||
/* value: 0:禁止;1:使能 */
|
||||
void uart_set_irq_enable(S32 uartno, U32 value)
|
||||
{
|
||||
uart_reg_write(uartno, ELSI, value);
|
||||
return;
|
||||
}
|
||||
|
||||
S32 uart_is_txfifo_full(S32 uartno)
|
||||
{
|
||||
S32 ret;
|
||||
U32 usr = 0;
|
||||
|
||||
ret = uart_reg_read(uartno, DW_UART_USR, &usr);
|
||||
if (ret) {
|
||||
return OS_OK;
|
||||
}
|
||||
|
||||
return (usr & DW_XFIFO_NOT_FULL) ? 0 : 1;
|
||||
}
|
||||
|
||||
S32 uart_is_rx_ready(S32 uartno)
|
||||
{
|
||||
U32 lsr = 0;
|
||||
|
||||
(void)uart_reg_read(uartno, DW_UART_LSR, &lsr);
|
||||
return (lsr & DW_UART_LSR_DDR) ? 1 : 0;
|
||||
}
|
||||
|
||||
void uart_tx_char(S32 uartno, const S8 c)
|
||||
{
|
||||
uart_reg_write(uartno, DW_UART_THR, (U32)(U8)c);
|
||||
return;
|
||||
}
|
||||
|
||||
void uart_rx_char(S32 uartno, S8 *c)
|
||||
{
|
||||
U32 rbr = 0;
|
||||
|
||||
(void)uart_reg_read(uartno, DW_UART_RBR, &rbr);
|
||||
*c = (S8)(rbr & 0xFF);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
S32 uart_wait4idle(S32 uartno, U32 timeout)
|
||||
{
|
||||
U32 usr = 0;
|
||||
|
||||
while (timeout) {
|
||||
(void)uart_reg_read(uartno, DW_UART_USR, &usr);
|
||||
if ((usr & (DW_UART_BUSY)) == 0) {
|
||||
return OS_OK;
|
||||
}
|
||||
|
||||
timeout--;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright (c) 2009-2022 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
*
|
||||
* UniProton is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
* http://license.coscl.org.cn/MulanPSL2
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PSL v2 for more details.
|
||||
* Create: 2009-12-22
|
||||
* Description: UniProton hi3093 demo
|
||||
*/
|
||||
#ifndef __DW_UART_CORE_H__
|
||||
#define __DW_UART_CORE_H__
|
||||
|
||||
#include "uart_regs.h"
|
||||
#include "common.h"
|
||||
|
||||
#define MAX_UART_NUM 8
|
||||
|
||||
extern S32 uart_reg_read(S32 uart_num, U32 offset, U32 *val);
|
||||
extern void uart_reg_write(S32 uart_num, U32 offset, U32 val);
|
||||
extern void uart_set_dll_dlh(S32 uart_num, U32 dll, U32 dlh);
|
||||
extern void uart_get_dll_dlh(S32 uart_num, U32 *dll, U32 *dlh);
|
||||
extern void uart_set_fifo_ctrl(S32 uart_num, U32 fifo_ctrl);
|
||||
extern void uart_set_lcr(S32 uart_num, U32 lcr);
|
||||
extern void uart_set_irq_enable(S32 uartno, U32 value);
|
||||
extern S32 uart_is_txfifo_full(S32 uart_num);
|
||||
extern S32 uart_is_rx_ready(S32 uart_num);
|
||||
extern void uart_tx_char(S32 uart_num, const S8 c);
|
||||
extern void uart_rx_char(S32 uart_num, S8 *c);
|
||||
extern S32 uart_wait4idle(S32 uartno, U32 timeout);
|
||||
|
||||
#endif /* __DW_UART_CORE_H__ */
|
||||
@@ -0,0 +1,147 @@
|
||||
/*
|
||||
* Copyright (c) 2009-2022 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
*
|
||||
* UniProton is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
* http://license.coscl.org.cn/MulanPSL2
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PSL v2 for more details.
|
||||
* Create: 2009-12-22
|
||||
* Description: UniProton hi3093 demo
|
||||
*/
|
||||
#ifndef __DW_UART_REGS_H__
|
||||
#define __DW_UART_REGS_H__
|
||||
|
||||
#define UART0_REG_BASE 0x0872A000
|
||||
#define UART1_REG_BASE 0x0872B000
|
||||
#define UART2_REG_BASE 0x08710000
|
||||
#define UART3_REG_BASE 0x08711000
|
||||
#define UART4_REG_BASE 0x08743000
|
||||
#define UART5_REG_BASE 0x08744000
|
||||
#define UART6_REG_BASE 0x0875D000
|
||||
#define UART7_REG_BASE 0x0875E000
|
||||
|
||||
#define CCORE_SYS_UART2_INTID 90
|
||||
#define CCORE_SYS_UART3_INTID 91
|
||||
#define CCORE_SYS_UART4_INTID 92
|
||||
#define CCORE_SYS_UART5_INTID 93
|
||||
#define CCORE_SYS_UART6_INTID 94
|
||||
#define CCORE_SYS_UART7_INTID 95
|
||||
|
||||
/*
|
||||
* UART register offsets
|
||||
*/
|
||||
#define DW_UART_RBR 0x00
|
||||
#define DW_UART_THR 0x00
|
||||
#define DW_UART_DLL 0x00
|
||||
|
||||
#define DW_UART_DLH 0x04
|
||||
#define DW_UART_IER 0x04
|
||||
|
||||
#define DW_UART_IIR 0x08
|
||||
#define DW_UART_FCR 0x08
|
||||
|
||||
#define DW_UART_LCR 0x0C
|
||||
|
||||
#define DW_UART_MCR 0x10
|
||||
|
||||
#define DW_UART_LSR 0x14
|
||||
#define DW_UART_MSR 0x18
|
||||
|
||||
#define DW_UART_USR 0x7C
|
||||
#define DW_UART_TFL 0x80
|
||||
#define DW_UART_RFL 0x84
|
||||
|
||||
#define DW_UART_HTX 0xA4
|
||||
|
||||
/* LSR 线性状态寄存器区域 */
|
||||
#define DW_UART_LSR_TEMT 0x40
|
||||
#define DW_UART_LSR_THRE 0x20
|
||||
#define DW_UART_LSR_BI 0x10
|
||||
#define DW_UART_LSR_FE 0x08
|
||||
#define DW_UART_LSR_PE 0x04
|
||||
#define DW_UART_LSR_R 0x02
|
||||
#define DW_UART_LSR_DDR 0x01
|
||||
|
||||
#define BIT(n) (1 << (n))
|
||||
|
||||
/* LCR bit field */
|
||||
#define DW_UART_DLAB BIT(7)
|
||||
#define DW_UART_BREAK BIT(6)
|
||||
#define DW_UART_STICK BIT(5)
|
||||
#define DW_UART_EPS BIT(4)
|
||||
#define DW_UART_PEN BIT(3)
|
||||
#define DW_UART_STOP BIT(2)
|
||||
#define DW_UART_8bit 0x3
|
||||
#define DW_UART_7bit 0x2
|
||||
#define DW_UART_6bit 0x1
|
||||
#define DW_UART_5bit 0x0
|
||||
#define DW_UART_DATALEN_MASK 0x03
|
||||
|
||||
/* IER bit field */
|
||||
#define PTIME BIT(7)
|
||||
#define EDSSI BIT(3)
|
||||
#define ELSI BIT(2)
|
||||
#define ETBEI BIT(1)
|
||||
#define ERBFI BIT(0)
|
||||
|
||||
/* LSR bit field */
|
||||
#define DW_RFE BIT(7)
|
||||
#define DW_TEMT BIT(6)
|
||||
#define DW_THRE BIT(5)
|
||||
#define DW_BI BIT(4)
|
||||
#define DW_FE BIT(3)
|
||||
#define DW_PE BIT(2)
|
||||
#define DW_OE BIT(1)
|
||||
#define DW_DR BIT(0)
|
||||
|
||||
#define UART_DW_DR_PE DW_PE
|
||||
#define UART_DW_DR_FE DW_FE
|
||||
#define UART_DW_DR_OE DW_OE
|
||||
#define UART_DW_DR_BE DW_BI
|
||||
|
||||
#define DW_RSR_ANY (DW_OE | DW_PE | DW_FE | DW_BI)
|
||||
#define DW_DUMMY_RSR_RX
|
||||
|
||||
/* MCR bit field */
|
||||
#define DW_MC_AFCE BIT(5)
|
||||
#define DW_MC_LOOP BIT(4)
|
||||
#define DW_MC_OUT2 BIT(3)
|
||||
#define DW_MC_OUT1 BIT(2)
|
||||
#define DW_MC_RTS BIT(1)
|
||||
#define DW_MC_DTR BIT(0)
|
||||
|
||||
/* MSR bit field */
|
||||
#define DW_DCD BIT(7)
|
||||
#define DW_RI BIT(6)
|
||||
#define DW_DSR BIT(5)
|
||||
#define DW_CTS BIT(4)
|
||||
#define DW_MSR_ANY (DW_DCD | DW_DSR | DW_CTS)
|
||||
|
||||
/* IIR bit field */
|
||||
#define DW_RECEIVERR 0x06
|
||||
#define DW_RECEIVEAVA 0x04
|
||||
#define DW_RECTIMEOUT 0x0C
|
||||
#define DW_TRANSEMP 0x02
|
||||
#define DW_NOINTERRUPT 0x01
|
||||
#define DW_MODEMSTA 0x0
|
||||
#define DW_BUSY 0x7
|
||||
|
||||
/* FCR bit field */
|
||||
#define RECFIFO1_2 (0x02 << 6)
|
||||
#define TXFIFO1_2 (0x03 << 4)
|
||||
#define FIFOENA 1
|
||||
#define UART_FCR_RXCLR 0x02
|
||||
#define UART_FCR_TXCLR 0x04
|
||||
|
||||
/* USR bit field */
|
||||
#define DW_UART_BUSY 0x01
|
||||
#define DW_XFIFO_NOT_FULL 0x02
|
||||
#define DW_XFIFO_EMP 0x04
|
||||
#define DW_RFIFO_NOT_EMP 0x08
|
||||
#define DW_RFIFO_FULL 0x10
|
||||
|
||||
#endif /* __DW_UART_REGS_H__ */
|
||||
@@ -0,0 +1,26 @@
|
||||
#!/bin/bash
|
||||
# Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
# UniProton is licensed under Mulan PSL v2.
|
||||
# You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
# You may obtain a copy of Mulan PSL v2 at:
|
||||
# http://license.coscl.org.cn/MulanPSL2
|
||||
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
# EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
# MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
# See the Mulan PSL v2 for more details.
|
||||
|
||||
export TOOLCHAIN_PATH=/opt/buildtools/gcc-arm-10.3-2021.07-x86_64-aarch64-none-elf
|
||||
export APP=hi3093
|
||||
export TMP_DIR=$APP
|
||||
|
||||
sh ./build_static.sh $APP
|
||||
sh ./build_openamp.sh
|
||||
|
||||
cmake -S .. -B $TMP_DIR -DAPP:STRING=$APP -DTOOLCHAIN_PATH:STRING=$TOOLCHAIN_PATH
|
||||
pushd $TMP_DIR
|
||||
make $APP
|
||||
popd
|
||||
cp ./$TMP_DIR/$APP $APP.elf
|
||||
$TOOLCHAIN_PATH/bin/aarch64-none-elf-objcopy -O binary ./$APP.elf $APP.bin
|
||||
$TOOLCHAIN_PATH/bin/aarch64-none-elf-objdump -D ./$APP.elf > $APP.asm
|
||||
rm -rf $TMP_DIR
|
||||
@@ -0,0 +1,69 @@
|
||||
#!/bin/bash
|
||||
# Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
# UniProton is licensed under Mulan PSL v2.
|
||||
# You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
# You may obtain a copy of Mulan PSL v2 at:
|
||||
# http://license.coscl.org.cn/MulanPSL2
|
||||
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
# EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
# MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
# See the Mulan PSL v2 for more details.
|
||||
|
||||
echo "################# git clone libmetal #################"
|
||||
pushd ../component
|
||||
rm -rf ./libmetal*
|
||||
git clone https://gitee.com/src-openeuler/libmetal.git
|
||||
mv ./libmetal/libmetal-2022.10.0.tar.gz .
|
||||
rm -rf ./libmetal
|
||||
tar -zxvf libmetal-2022.10.0.tar.gz
|
||||
mv ./libmetal-2022.10.0 ./libmetal
|
||||
cp UniProton-patch-for-libmetal.patch ./libmetal
|
||||
cd libmetal
|
||||
patch -p1 -d . < UniProton-patch-for-libmetal.patch
|
||||
popd
|
||||
|
||||
echo "################# git clone openamp #################"
|
||||
pushd ../component
|
||||
rm -rf ./open-amp*
|
||||
git clone https://gitee.com/src-openeuler/OpenAMP.git
|
||||
mv ./OpenAMP/openamp-2022.10.1.tar.gz .
|
||||
rm -rf ./OpenAMP
|
||||
tar -zxvf openamp-2022.10.1.tar.gz
|
||||
mv ./openamp-2022.10.1 ./open-amp
|
||||
cp UniProton-patch-for-openamp.patch ./open-amp
|
||||
cd open-amp
|
||||
patch -p1 -d . < UniProton-patch-for-openamp.patch
|
||||
popd
|
||||
|
||||
echo "######################### build metal #########################"
|
||||
pushd .
|
||||
mkdir -p libmetal
|
||||
cd libmetal
|
||||
mkdir -p build
|
||||
cd build
|
||||
rm -rf *
|
||||
cmake ../../../component/libmetal -DCMAKE_TOOLCHAIN_FILE=../../../component/libmetal/cmake/platforms/uniproton_arm64_gcc.cmake -DWITH_DOC=OFF -DWITH_EXAMPLES=OFF -DWITH_TESTS=OFF -DWITH_DEFAULT_LOGGER=OFF -DWITH_SHARED_LIB=OFF
|
||||
make VERBOSE=1 DESTDIR=../output install
|
||||
if [ $? -ne 0 ];then
|
||||
echo "make metal failed!"
|
||||
exit 1
|
||||
fi
|
||||
popd
|
||||
|
||||
echo "######################### build openamp #########################"
|
||||
pushd .
|
||||
mkdir -p open-amp
|
||||
cd open-amp
|
||||
mkdir -p build
|
||||
cd build
|
||||
rm -rf *
|
||||
cmake ../../../component/open-amp -DCMAKE_TOOLCHAIN_FILE=../../../component/open-amp/cmake/platforms/uniproton_arm64_gcc.cmake
|
||||
make VERBOSE=1 DESTDIR=../output install
|
||||
if [ $? -ne 0 ];then
|
||||
echo "make openamp failed!"
|
||||
exit 1
|
||||
fi
|
||||
popd
|
||||
|
||||
cp ./libmetal/output/usr/local/lib/*.a ../libs
|
||||
cp ./open-amp/output/usr/local/lib/*.a ../libs
|
||||
@@ -0,0 +1,24 @@
|
||||
#!/bin/bash
|
||||
# Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
# UniProton is licensed under Mulan PSL v2.
|
||||
# You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
# You may obtain a copy of Mulan PSL v2 at:
|
||||
# http://license.coscl.org.cn/MulanPSL2
|
||||
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
# EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
# MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
# See the Mulan PSL v2 for more details.
|
||||
|
||||
git clone https://gitee.com/openeuler/libboundscheck.git
|
||||
|
||||
cp libboundscheck/include/* ../../../platform/libboundscheck/include
|
||||
cp libboundscheck/include/* ../include
|
||||
cp libboundscheck/src/* ../../../platform/libboundscheck/src
|
||||
rm -rf libboundscheck
|
||||
|
||||
pushd ./../../../
|
||||
python build.py $1
|
||||
cp output/UniProton/lib/$1/* demos/$1/libs
|
||||
cp output/libboundscheck/lib/$1/* demos/$1/libs
|
||||
cp -r src/include/uapi/* demos/$1/include
|
||||
popd
|
||||
@@ -0,0 +1,120 @@
|
||||
ENTRY(__text_start)
|
||||
|
||||
_stack_size = 0x10000;
|
||||
_heap_size = 0x10000;
|
||||
|
||||
MEMORY
|
||||
{
|
||||
IMU_SRAM (rwx) : ORIGIN = 0x93000000, LENGTH = 0x800000
|
||||
MMU_MEM (rwx) : ORIGIN = 0x93800000, LENGTH = 0x800000
|
||||
}
|
||||
|
||||
SECTIONS
|
||||
{
|
||||
text_start = .;
|
||||
.start_bspinit :
|
||||
{
|
||||
__text_start = .;
|
||||
KEEP(*(.text.bspinit))
|
||||
} > IMU_SRAM
|
||||
|
||||
.start_text :
|
||||
{
|
||||
KEEP(*(.text.startup))
|
||||
} > IMU_SRAM
|
||||
|
||||
.text :
|
||||
{
|
||||
*(.text)
|
||||
*(.text.*)
|
||||
*(*.text)
|
||||
. = ALIGN(8);
|
||||
__text_end = .;
|
||||
} > IMU_SRAM
|
||||
. = ALIGN(8);
|
||||
data_copy_start = .;
|
||||
|
||||
.rodata :
|
||||
{
|
||||
. = ALIGN(8);
|
||||
__rodata_start = .;
|
||||
*(.rodata)
|
||||
*(.rodata.*)
|
||||
. = ALIGN(8);
|
||||
__rodata_end = .;
|
||||
} > IMU_SRAM
|
||||
|
||||
.eh_frame :
|
||||
{
|
||||
. = ALIGN(8);
|
||||
__os_unwind_table_start = .;
|
||||
*(.eh_frame)
|
||||
__os_unwind_table_end = .;
|
||||
} > IMU_SRAM
|
||||
|
||||
.heap (NOLOAD) :
|
||||
{
|
||||
. = ALIGN(8);
|
||||
PROVIDE (__HEAP_INIT = .);
|
||||
. = . + _heap_size;
|
||||
. = ALIGN(8);
|
||||
PROVIDE (__HEAP_END = .);
|
||||
} > IMU_SRAM
|
||||
|
||||
.stack (NOLOAD) :
|
||||
{
|
||||
. = ALIGN(8);
|
||||
PROVIDE (__os_sys_sp_start = .);
|
||||
. = . + _stack_size;
|
||||
. = ALIGN(8);
|
||||
PROVIDE (__os_sys_sp_end = .);
|
||||
} > IMU_SRAM
|
||||
end = .;
|
||||
|
||||
.percpu.data :
|
||||
{
|
||||
__os_per_cpu_start = .;
|
||||
*(.os.percpu.data)
|
||||
__os_per_cpu_end = .;
|
||||
LONG (ALIGNOF(.percpu.data))
|
||||
} > IMU_SRAM
|
||||
|
||||
.data :
|
||||
{
|
||||
. = ALIGN(8);
|
||||
__data_start = .;
|
||||
*(.data)
|
||||
*(.data.*)
|
||||
. = ALIGN(8);
|
||||
__os_text_start = .;
|
||||
QUAD(__text_start)
|
||||
QUAD(__text_end)
|
||||
__os_text_end = .;
|
||||
__data_end = .;
|
||||
} > IMU_SRAM
|
||||
|
||||
.llt.bss :
|
||||
{
|
||||
_llt_bss_start = .;
|
||||
*__code_measure_stub*.o(.bss)
|
||||
*__code_measure_stub*.o(.bss.*)
|
||||
_llt_bss_end = .;
|
||||
} > IMU_SRAM
|
||||
|
||||
.bss (NOLOAD) :
|
||||
{
|
||||
. = ALIGN(8);
|
||||
__bss_start__ = .;
|
||||
*(.bss)
|
||||
*(.bss.*)
|
||||
*(COMMON)
|
||||
. = ALIGN(8);
|
||||
__bss_end__ = .;
|
||||
} > IMU_SRAM
|
||||
|
||||
.mmu.table.base :
|
||||
{
|
||||
PROVIDE (g_mmu_page_begin = .);
|
||||
PROVIDE (g_mmu_page_end = g_mmu_page_begin + 0x8000);
|
||||
} > MMU_MEM
|
||||
}
|
||||
@@ -0,0 +1,581 @@
|
||||
diff -uparN libmetal-2022.10.0/cmake/platforms/uniproton_arm64_gcc.cmake libmetal/cmake/platforms/uniproton_arm64_gcc.cmake
|
||||
--- libmetal-2022.10.0/cmake/platforms/uniproton_arm64_gcc.cmake 1970-01-01 08:00:00.000000000 +0800
|
||||
+++ libmetal/cmake/platforms/uniproton_arm64_gcc.cmake 2023-02-22 11:01:30.000000000 +0800
|
||||
@@ -0,0 +1,16 @@
|
||||
+#cross-compilation config
|
||||
+
|
||||
+set(CMAKE_SYSTEM_PROCESSOR arm)
|
||||
+set(PROJECT_SYSTEM uniproton)
|
||||
+
|
||||
+set(CMAKE_C_COMPILER_WORKS 1)
|
||||
+set(CMAKE_CXX_COMPILER_WORKS 1)
|
||||
+
|
||||
+set(CROSS_PREFIX "/opt/buildtools/gcc-arm-10.3-2021.07-x86_64-aarch64-none-elf/bin/aarch64-none-elf-" CACHE STRING "")
|
||||
+set(CMAKE_C_COMPILER "${CROSS_PREFIX}gcc" CACHE STRING "")
|
||||
+set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER CACHE STRING "")
|
||||
+set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY NEVER CACHE STRING "")
|
||||
+set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE NEVER CACHE STRING "")
|
||||
+set(CMAKE_C_FLAGS "-D_GNU_SOURCE -D_POSIX_THREADS -D_POSIX_THREAD_PRIORITY_SCHEDULING -D_POSIX_PRIORITY_SCHEDULING -D_POSIX_TIMERS -D_POSIX_CPUTIME -D_POSIX_THREAD_CPUTIME -D_POSIX_MONOTONIC_CLOCK -D_POSIX_TIMEOUTS -D_POSIX_CLOCK_SELECTION -D_POSIX_THREAD_PRIO_PROTECT -D_UNIX98_THREAD_MUTEX_ATTRIBUTES -D_POSIX_READER_WRITER_LOCKS" CACHE STRING "")
|
||||
+
|
||||
+# vim: expandtab:ts=2:sw=2:smartindent
|
||||
diff -uparN libmetal-2022.10.0/CMakeLists.txt libmetal/CMakeLists.txt
|
||||
--- libmetal-2022.10.0/CMakeLists.txt 2022-10-28 10:12:23.000000000 +0800
|
||||
+++ libmetal/CMakeLists.txt 2023-02-24 16:25:04.000000000 +0800
|
||||
@@ -6,7 +6,8 @@ endif()
|
||||
if (POLICY CMP0077)
|
||||
cmake_policy(SET CMP0077 NEW)
|
||||
endif()
|
||||
-
|
||||
+include_directories(../../include)
|
||||
+set (CMAKE_SYSTEM_NAME Uniproton)
|
||||
set (LIBMETAL_ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
|
||||
|
||||
list (APPEND CMAKE_MODULE_PATH
|
||||
diff -uparN libmetal-2022.10.0/lib/system/uniproton/alloc.h libmetal/lib/system/uniproton/alloc.h
|
||||
--- libmetal-2022.10.0/lib/system/uniproton/alloc.h 1970-01-01 08:00:00.000000000 +0800
|
||||
+++ libmetal/lib/system/uniproton/alloc.h 2023-02-20 14:53:22.000000000 +0800
|
||||
@@ -0,0 +1,39 @@
|
||||
+/*
|
||||
+ * Copyright (c) 2017, Linaro Limited. and Contributors. All rights reserved.
|
||||
+ *
|
||||
+ * SPDX-License-Identifier: BSD-3-Clause
|
||||
+ */
|
||||
+
|
||||
+/*
|
||||
+ * @file uniproton/alloc.h
|
||||
+ * @brief Uniproton libmetal memory allocattion definitions.
|
||||
+ */
|
||||
+
|
||||
+#ifndef __METAL_ALLOC__H__
|
||||
+#error "Include metal/alloc.h instead of metal/uniproton/alloc.h"
|
||||
+#endif
|
||||
+
|
||||
+#ifndef __METAL_UNIPROTON_ALLOC__H__
|
||||
+#define __METAL_UNIPROTON_ALLOC__H__
|
||||
+
|
||||
+#include "prt_mem.h"
|
||||
+
|
||||
+#ifdef __cplusplus
|
||||
+extern "C" {
|
||||
+#endif
|
||||
+
|
||||
+static inline void *metal_allocate_memory(unsigned int size)
|
||||
+{
|
||||
+ return PRT_MemAlloc(OS_MID_SYS, OS_MEM_DEFAULT_PT0, size);
|
||||
+}
|
||||
+
|
||||
+static inline void metal_free_memory(void *ptr)
|
||||
+{
|
||||
+ PRT_MemFree(OS_MID_SYS, ptr);
|
||||
+}
|
||||
+
|
||||
+#ifdef __cplusplus
|
||||
+}
|
||||
+#endif
|
||||
+
|
||||
+#endif /* __METAL_UNIPROTON_ALLOC__H__ */
|
||||
diff -uparN libmetal-2022.10.0/lib/system/uniproton/assert.h libmetal/lib/system/uniproton/assert.h
|
||||
--- libmetal-2022.10.0/lib/system/uniproton/assert.h 1970-01-01 08:00:00.000000000 +0800
|
||||
+++ libmetal/lib/system/uniproton/assert.h 2022-12-26 10:59:44.000000000 +0800
|
||||
@@ -0,0 +1,26 @@
|
||||
+/*
|
||||
+ * Copyright (c) 2018, Xilinx Inc. and Contributors. All rights reserved.
|
||||
+ *
|
||||
+ * SPDX-License-Identifier: BSD-3-Clause
|
||||
+ */
|
||||
+
|
||||
+/*
|
||||
+ * @file assert.h
|
||||
+ * @brief Uniproton assertion support.
|
||||
+ */
|
||||
+
|
||||
+#ifndef __METAL_ASSERT__H__
|
||||
+#error "Include metal/assert.h instead of metal/uniproton/assert.h"
|
||||
+#endif
|
||||
+
|
||||
+#ifndef __METAL_UNIPROTON_ASSERT__H__
|
||||
+#define __METAL_UNIPROTON_ASSERT__H__
|
||||
+
|
||||
+/**
|
||||
+ * @brief Assertion macro.
|
||||
+ * @param cond Condition to test.
|
||||
+ */
|
||||
+#define metal_sys_assert(cond)
|
||||
+
|
||||
+#endif /* __METAL_UNIPROTON_ASSERT__H__ */
|
||||
+
|
||||
diff -uparN libmetal-2022.10.0/lib/system/uniproton/cache.h libmetal/lib/system/uniproton/cache.h
|
||||
--- libmetal-2022.10.0/lib/system/uniproton/cache.h 1970-01-01 08:00:00.000000000 +0800
|
||||
+++ libmetal/lib/system/uniproton/cache.h 2022-12-26 11:02:08.000000000 +0800
|
||||
@@ -0,0 +1,39 @@
|
||||
+/*
|
||||
+ * Copyright (c) 2018, Linaro Limited. and Contributors. All rights reserved.
|
||||
+ *
|
||||
+ * SPDX-License-Identifier: BSD-3-Clause
|
||||
+ */
|
||||
+
|
||||
+/*
|
||||
+ * @file uniproton/cache.h
|
||||
+ * @brief Uniproton cache operation primitives for libmetal.
|
||||
+ */
|
||||
+
|
||||
+#ifndef __METAL_CACHE__H__
|
||||
+#error "Include metal/cache.h instead of metal/uniproton/cache.h"
|
||||
+#endif
|
||||
+
|
||||
+#ifndef __METAL_UNIPROTON_CACHE__H__
|
||||
+#define __METAL_UNIPROTON_CACHE__H__
|
||||
+
|
||||
+#ifdef __cplusplus
|
||||
+extern "C" {
|
||||
+#endif
|
||||
+
|
||||
+static inline void __metal_cache_flush(void *addr, unsigned int len)
|
||||
+{
|
||||
+ (void)addr;
|
||||
+ (void)len;
|
||||
+}
|
||||
+
|
||||
+static inline void __metal_cache_invalidate(void *addr, unsigned int len)
|
||||
+{
|
||||
+ (void)addr;
|
||||
+ (void)len;
|
||||
+}
|
||||
+
|
||||
+#ifdef __cplusplus
|
||||
+}
|
||||
+#endif
|
||||
+
|
||||
+#endif /* __METAL_UNIPROTON_CACHE__H__ */
|
||||
diff -uparN libmetal-2022.10.0/lib/system/uniproton/CMakeLists.txt libmetal/lib/system/uniproton/CMakeLists.txt
|
||||
--- libmetal-2022.10.0/lib/system/uniproton/CMakeLists.txt 1970-01-01 08:00:00.000000000 +0800
|
||||
+++ libmetal/lib/system/uniproton/CMakeLists.txt 2022-12-26 14:13:48.000000000 +0800
|
||||
@@ -0,0 +1,17 @@
|
||||
+collect (PROJECT_LIB_HEADERS alloc.h)
|
||||
+collect (PROJECT_LIB_HEADERS assert.h)
|
||||
+collect (PROJECT_LIB_HEADERS cache.h)
|
||||
+collect (PROJECT_LIB_HEADERS condition.h)
|
||||
+collect (PROJECT_LIB_HEADERS io.h)
|
||||
+collect (PROJECT_LIB_HEADERS irq.h)
|
||||
+collect (PROJECT_LIB_HEADERS log.h)
|
||||
+collect (PROJECT_LIB_HEADERS mutex.h)
|
||||
+collect (PROJECT_LIB_HEADERS sleep.h)
|
||||
+collect (PROJECT_LIB_HEADERS sys.h)
|
||||
+
|
||||
+collect (PROJECT_LIB_SOURCES condition.c)
|
||||
+collect (PROJECT_LIB_SOURCES device.c)
|
||||
+collect (PROJECT_LIB_SOURCES init.c)
|
||||
+collect (PROJECT_LIB_SOURCES shmem.c)
|
||||
+
|
||||
+# vim: expandtab:ts=2:sw=2:smartindent
|
||||
diff -uparN libmetal-2022.10.0/lib/system/uniproton/condition.c libmetal/lib/system/uniproton/condition.c
|
||||
--- libmetal-2022.10.0/lib/system/uniproton/condition.c 1970-01-01 08:00:00.000000000 +0800
|
||||
+++ libmetal/lib/system/uniproton/condition.c 2022-12-26 11:06:12.000000000 +0800
|
||||
@@ -0,0 +1,33 @@
|
||||
+/*
|
||||
+ * Copyright (c) 2017, Linaro Limited. and Contributors. All rights reserved.
|
||||
+ *
|
||||
+ * SPDX-License-Identifier: BSD-3-Clause
|
||||
+ */
|
||||
+
|
||||
+/*
|
||||
+ * @file uniproton/condition.c
|
||||
+ * @brief Uniproton libmetal condition variable handling.
|
||||
+ */
|
||||
+
|
||||
+#include <metal/condition.h>
|
||||
+#include <metal/irq.h>
|
||||
+#include <metal/errno.h>
|
||||
+
|
||||
+int metal_condition_wait(struct metal_condition *cv,
|
||||
+ metal_mutex_t *m)
|
||||
+{
|
||||
+ unsigned int flags;
|
||||
+
|
||||
+ /* Check if the mutex has been acquired */
|
||||
+ if (!cv || !m || !metal_mutex_is_acquired(m)) {
|
||||
+ return -EINVAL;
|
||||
+ }
|
||||
+
|
||||
+ flags = metal_irq_save_disable();
|
||||
+ /* Release the mutex first. */
|
||||
+ metal_mutex_release(m);
|
||||
+ metal_irq_restore_enable(flags);
|
||||
+ /* Acquire the mutex again. */
|
||||
+ metal_mutex_acquire(m);
|
||||
+ return 0;
|
||||
+}
|
||||
diff -uparN libmetal-2022.10.0/lib/system/uniproton/condition.h libmetal/lib/system/uniproton/condition.h
|
||||
--- libmetal-2022.10.0/lib/system/uniproton/condition.h 1970-01-01 08:00:00.000000000 +0800
|
||||
+++ libmetal/lib/system/uniproton/condition.h 2022-12-26 11:09:02.000000000 +0800
|
||||
@@ -0,0 +1,30 @@
|
||||
+/*
|
||||
+ * Copyright (c) 2017, Linaro Limited. and Contributors. All rights reserved.
|
||||
+ *
|
||||
+ * SPDX-License-Identifier: BSD-3-Clause
|
||||
+ */
|
||||
+
|
||||
+/*
|
||||
+ * @file uniproton/condition.h
|
||||
+ * @brief Uniproton condition variable primitives for libmetal.
|
||||
+ */
|
||||
+
|
||||
+#ifndef __METAL_CONDITION__H__
|
||||
+#error "Include metal/condition.h instead of metal/uniproton/condition.h"
|
||||
+#endif
|
||||
+
|
||||
+#ifndef __METAL_UNIPROTON_CONDITION__H__
|
||||
+#define __METAL_UNIPROTON_CONDITION__H__
|
||||
+
|
||||
+#include <metal/mutex.h>
|
||||
+#include <metal/utilities.h>
|
||||
+
|
||||
+#ifdef __cplusplus
|
||||
+extern "C" {
|
||||
+#endif
|
||||
+
|
||||
+#ifdef __cplusplus
|
||||
+}
|
||||
+#endif
|
||||
+
|
||||
+#endif /* __METAL_UNIPROTON_CONDITION__H__ */
|
||||
diff -uparN libmetal-2022.10.0/lib/system/uniproton/device.c libmetal/lib/system/uniproton/device.c
|
||||
--- libmetal-2022.10.0/lib/system/uniproton/device.c 1970-01-01 08:00:00.000000000 +0800
|
||||
+++ libmetal/lib/system/uniproton/device.c 2022-12-26 11:13:30.000000000 +0800
|
||||
@@ -0,0 +1,21 @@
|
||||
+/*
|
||||
+ * Copyright (c) 2017, Linaro Limited. and Contributors. All rights reserved.
|
||||
+ *
|
||||
+ * SPDX-License-Identifier: BSD-3-Clause
|
||||
+ */
|
||||
+
|
||||
+/*
|
||||
+ * @file uniproton/device.c
|
||||
+ * @brief Uniproton libmetal device definitions.
|
||||
+ */
|
||||
+
|
||||
+#include <metal/device.h>
|
||||
+#include <metal/io.h>
|
||||
+#include <metal/sys.h>
|
||||
+#include <metal/utilities.h>
|
||||
+
|
||||
+int metal_generic_dev_sys_open(struct metal_device *dev)
|
||||
+{
|
||||
+ return 0;
|
||||
+}
|
||||
+
|
||||
diff -uparN libmetal-2022.10.0/lib/system/uniproton/init.c libmetal/lib/system/uniproton/init.c
|
||||
--- libmetal-2022.10.0/lib/system/uniproton/init.c 1970-01-01 08:00:00.000000000 +0800
|
||||
+++ libmetal/lib/system/uniproton/init.c 2022-12-26 11:14:34.000000000 +0800
|
||||
@@ -0,0 +1,27 @@
|
||||
+/*
|
||||
+ * Copyright (c) 2017, Linaro Limited. and Contributors. All rights reserved.
|
||||
+ *
|
||||
+ * SPDX-License-Identifier: BSD-3-Clause
|
||||
+ */
|
||||
+
|
||||
+/*
|
||||
+ * @file uniproton/init.c
|
||||
+ * @brief Uniproton libmetal initialization.
|
||||
+ */
|
||||
+
|
||||
+#include <metal/device.h>
|
||||
+#include <metal/sys.h>
|
||||
+
|
||||
+struct metal_state _metal;
|
||||
+
|
||||
+int metal_sys_init(const struct metal_init_params *params)
|
||||
+{
|
||||
+ (void)params;
|
||||
+ metal_bus_register(&metal_generic_bus);
|
||||
+ return 0;
|
||||
+}
|
||||
+
|
||||
+void metal_sys_finish(void)
|
||||
+{
|
||||
+ metal_bus_unregister(&metal_generic_bus);
|
||||
+}
|
||||
diff -uparN libmetal-2022.10.0/lib/system/uniproton/io.h libmetal/lib/system/uniproton/io.h
|
||||
--- libmetal-2022.10.0/lib/system/uniproton/io.h 1970-01-01 08:00:00.000000000 +0800
|
||||
+++ libmetal/lib/system/uniproton/io.h 2022-12-26 11:16:50.000000000 +0800
|
||||
@@ -0,0 +1,37 @@
|
||||
+/*
|
||||
+ * Copyright (c) 2017, Linaro Limited. and Contributors. All rights reserved.
|
||||
+ *
|
||||
+ * SPDX-License-Identifier: BSD-3-Clause
|
||||
+ */
|
||||
+
|
||||
+/*
|
||||
+ * @file uniproton/io.h
|
||||
+ * @brief Uniproton specific io definitions.
|
||||
+ */
|
||||
+
|
||||
+#ifndef __METAL_IO__H__
|
||||
+#error "Include metal/io.h instead of metal/uniproton/io.h"
|
||||
+#endif
|
||||
+
|
||||
+#ifndef __METAL_UNIPROTON_IO__H__
|
||||
+#define __METAL_UNIPROTON_IO__H__
|
||||
+
|
||||
+#ifdef __cplusplus
|
||||
+extern "C" {
|
||||
+#endif
|
||||
+
|
||||
+#ifdef METAL_INTERNAL
|
||||
+/**
|
||||
+ * @brief memory mapping for an I/O region
|
||||
+ */
|
||||
+static inline void metal_sys_io_mem_map(struct metal_io_region *io)
|
||||
+{
|
||||
+ (void)io;
|
||||
+}
|
||||
+#endif
|
||||
+
|
||||
+#ifdef __cplusplus
|
||||
+}
|
||||
+#endif
|
||||
+
|
||||
+#endif /* __METAL_UNIPROTON_IO__H__ */
|
||||
diff -uparN libmetal-2022.10.0/lib/system/uniproton/irq.h libmetal/lib/system/uniproton/irq.h
|
||||
--- libmetal-2022.10.0/lib/system/uniproton/irq.h 1970-01-01 08:00:00.000000000 +0800
|
||||
+++ libmetal/lib/system/uniproton/irq.h 2022-12-26 11:17:54.000000000 +0800
|
||||
@@ -0,0 +1,27 @@
|
||||
+/*
|
||||
+ * Copyright (c) 2017, Linaro Limited. and Contributors. All rights reserved.
|
||||
+ *
|
||||
+ * SPDX-License-Identifier: BSD-3-Clause
|
||||
+ */
|
||||
+
|
||||
+/*
|
||||
+ * @file uniproton/irq.c
|
||||
+ * @brief Uniproton libmetal irq definitions.
|
||||
+ */
|
||||
+
|
||||
+#ifndef __METAL_IRQ__H__
|
||||
+#error "Include metal/irq.h instead of metal/uniproton/irq.h"
|
||||
+#endif
|
||||
+
|
||||
+#ifndef __METAL_UNIPROTON_IRQ__H__
|
||||
+#define __METAL_UNIPROTON_IRQ__H__
|
||||
+
|
||||
+#ifdef __cplusplus
|
||||
+extern "C" {
|
||||
+#endif
|
||||
+
|
||||
+#ifdef __cplusplus
|
||||
+}
|
||||
+#endif
|
||||
+
|
||||
+#endif /* __METAL_UNIPROTON_IRQ__H__ */
|
||||
diff -uparN libmetal-2022.10.0/lib/system/uniproton/log.h libmetal/lib/system/uniproton/log.h
|
||||
--- libmetal-2022.10.0/lib/system/uniproton/log.h 1970-01-01 08:00:00.000000000 +0800
|
||||
+++ libmetal/lib/system/uniproton/log.h 2022-12-26 11:19:38.000000000 +0800
|
||||
@@ -0,0 +1,27 @@
|
||||
+/*
|
||||
+ * Copyright (c) 2018, Xilinx Inc. and Contributors. All rights reserved.
|
||||
+ *
|
||||
+ * SPDX-License-Identifier: BSD-3-Clause
|
||||
+ */
|
||||
+
|
||||
+/*
|
||||
+ * @file uniproton/log.h
|
||||
+ * @brief Uniproton libmetal log handler definition.
|
||||
+ */
|
||||
+
|
||||
+#ifndef __METAL_METAL_LOG__H__
|
||||
+#error "Include metal/log.h instead of metal/uniproton/log.h"
|
||||
+#endif
|
||||
+
|
||||
+#ifndef __METAL_UNIPROTON_LOG__H__
|
||||
+#define __METAL_UNIPROTON_LOG__H__
|
||||
+
|
||||
+#ifdef __cplusplus
|
||||
+extern "C" {
|
||||
+#endif
|
||||
+
|
||||
+#ifdef __cplusplus
|
||||
+}
|
||||
+#endif
|
||||
+
|
||||
+#endif /* __METAL_UNIPROTON_LOG__H__ */
|
||||
diff -uparN libmetal-2022.10.0/lib/system/uniproton/mutex.h libmetal/lib/system/uniproton/mutex.h
|
||||
--- libmetal-2022.10.0/lib/system/uniproton/mutex.h 1970-01-01 08:00:00.000000000 +0800
|
||||
+++ libmetal/lib/system/uniproton/mutex.h 2023-02-23 14:22:12.000000000 +0800
|
||||
@@ -0,0 +1,73 @@
|
||||
+/*
|
||||
+ * Copyright (c) 2017, Linaro Limited. and Contributors. All rights reserved.
|
||||
+ *
|
||||
+ * SPDX-License-Identifier: BSD-3-Clause
|
||||
+ */
|
||||
+
|
||||
+/*
|
||||
+ * @file uniproton/mutex.h
|
||||
+ * @brief Uniproton mutex primitives for libmetal.
|
||||
+ */
|
||||
+
|
||||
+#ifndef __METAL_MUTEX__H__
|
||||
+#error "Include metal/mutex.h instead of metal/uniproton/mutex.h"
|
||||
+#endif
|
||||
+
|
||||
+#ifndef __METAL_UNIPROTON_MUTEX__H__
|
||||
+#define __METAL_UNIPROTON_MUTEX__H__
|
||||
+
|
||||
+#include "errno.h"
|
||||
+#include "pthread.h"
|
||||
+
|
||||
+#ifdef __cplusplus
|
||||
+extern "C" {
|
||||
+#endif
|
||||
+
|
||||
+typedef pthread_mutex_t metal_mutex_t;
|
||||
+
|
||||
+/*
|
||||
+ * METAL_MUTEX_INIT - used for initializing an mutex element in a static struct
|
||||
+ * or global
|
||||
+ */
|
||||
+#define METAL_MUTEX_INIT(m) MUTEX_INITIALIZER
|
||||
+/*
|
||||
+ * METAL_MUTEX_DEFINE - used for defining and initializing a global or
|
||||
+ * static singleton mutex
|
||||
+ */
|
||||
+#define METAL_MUTEX_DEFINE(m) metal_mutex_t m = MUTEX_INITIALIZER
|
||||
+
|
||||
+static inline void __metal_mutex_init(metal_mutex_t *mutex)
|
||||
+{
|
||||
+ pthread_mutex_init(mutex, NULL);
|
||||
+}
|
||||
+
|
||||
+static inline void __metal_mutex_deinit(metal_mutex_t *mutex)
|
||||
+{
|
||||
+ pthread_mutex_destroy(mutex);
|
||||
+}
|
||||
+
|
||||
+static inline int __metal_mutex_try_acquire(metal_mutex_t *mutex)
|
||||
+{
|
||||
+ return pthread_mutex_trylock(mutex);
|
||||
+}
|
||||
+
|
||||
+static inline int __metal_mutex_is_acquired(metal_mutex_t *mutex)
|
||||
+{
|
||||
+
|
||||
+}
|
||||
+
|
||||
+static inline void __metal_mutex_acquire(metal_mutex_t *mutex)
|
||||
+{
|
||||
+ pthread_mutex_lock(mutex);
|
||||
+}
|
||||
+
|
||||
+static inline void __metal_mutex_release(metal_mutex_t *mutex)
|
||||
+{
|
||||
+ pthread_mutex_unlock(mutex);
|
||||
+}
|
||||
+
|
||||
+#ifdef __cplusplus
|
||||
+}
|
||||
+#endif
|
||||
+
|
||||
+#endif /* __METAL_UNIPROTON_MUTEX__H__ */
|
||||
diff -uparN libmetal-2022.10.0/lib/system/uniproton/shmem.c libmetal/lib/system/uniproton/shmem.c
|
||||
--- libmetal-2022.10.0/lib/system/uniproton/shmem.c 1970-01-01 08:00:00.000000000 +0800
|
||||
+++ libmetal/lib/system/uniproton/shmem.c 2022-12-26 11:20:44.000000000 +0800
|
||||
@@ -0,0 +1,19 @@
|
||||
+/*
|
||||
+ * Copyright (c) 2017, Linaro Limited. and Contributors. All rights reserved.
|
||||
+ *
|
||||
+ * SPDX-License-Identifier: BSD-3-Clause
|
||||
+ */
|
||||
+
|
||||
+/*
|
||||
+ *
|
||||
+ * @file uniproton/shmem.c
|
||||
+ * @brief Uniproton libmetal shared memory handling.
|
||||
+ */
|
||||
+
|
||||
+#include <metal/shmem.h>
|
||||
+
|
||||
+int metal_shmem_open(const char *name, size_t size,
|
||||
+ struct metal_io_region **io)
|
||||
+{
|
||||
+ return metal_shmem_open_generic(name, size, io);
|
||||
+}
|
||||
diff -uparN libmetal-2022.10.0/lib/system/uniproton/sleep.h libmetal/lib/system/uniproton/sleep.h
|
||||
--- libmetal-2022.10.0/lib/system/uniproton/sleep.h 1970-01-01 08:00:00.000000000 +0800
|
||||
+++ libmetal/lib/system/uniproton/sleep.h 2023-02-22 16:55:06.000000000 +0800
|
||||
@@ -0,0 +1,34 @@
|
||||
+/*
|
||||
+ * Copyright (c) 2018, Linaro Limited. and Contributors. All rights reserved.
|
||||
+ *
|
||||
+ * SPDX-License-Identifier: BSD-3-Clause
|
||||
+ */
|
||||
+
|
||||
+/*
|
||||
+ * @file uniproton/sleep.h
|
||||
+ * @brief Uniproton sleep primitives for libmetal.
|
||||
+ */
|
||||
+
|
||||
+#ifndef __METAL_SLEEP__H__
|
||||
+#error "Include metal/sleep.h instead of metal/uniproton/sleep.h"
|
||||
+#endif
|
||||
+
|
||||
+#ifndef __METAL_UNIPROTON_SLEEP__H__
|
||||
+#define __METAL_UNIPROTON_SLEEP__H__
|
||||
+
|
||||
+#include "prt_task.h"
|
||||
+
|
||||
+#ifdef __cplusplus
|
||||
+extern "C" {
|
||||
+#endif
|
||||
+
|
||||
+static inline int __metal_sleep_usec(unsigned int usec)
|
||||
+{
|
||||
+ return PRT_TaskDelay((U32)(usec / 1000));
|
||||
+}
|
||||
+
|
||||
+#ifdef __cplusplus
|
||||
+}
|
||||
+#endif
|
||||
+
|
||||
+#endif /* __METAL_UNIPROTON_SLEEP__H__ */
|
||||
diff -uparN libmetal-2022.10.0/lib/system/uniproton/sys.h libmetal/lib/system/uniproton/sys.h
|
||||
--- libmetal-2022.10.0/lib/system/uniproton/sys.h 1970-01-01 08:00:00.000000000 +0800
|
||||
+++ libmetal/lib/system/uniproton/sys.h 2022-12-26 11:25:18.000000000 +0800
|
||||
@@ -0,0 +1,39 @@
|
||||
+/*
|
||||
+ * Copyright (c) 2017, Linaro Limited. and Contributors. All rights reserved.
|
||||
+ *
|
||||
+ * SPDX-License-Identifier: BSD-3-Clause
|
||||
+ */
|
||||
+
|
||||
+/*
|
||||
+ * @file uniproton/sys.h
|
||||
+ * @brief Uniproton system primitives for libmetal.
|
||||
+ */
|
||||
+
|
||||
+#ifndef __METAL_SYS__H__
|
||||
+#error "Include metal/sys.h instead of metal/uniproton/sys.h"
|
||||
+#endif
|
||||
+
|
||||
+#ifndef __METAL_UNIPROTON_SYS__H__
|
||||
+#define __METAL_UNIPROTON_SYS__H__
|
||||
+
|
||||
+#ifdef __cplusplus
|
||||
+extern "C" {
|
||||
+#endif
|
||||
+
|
||||
+#define METAL_INIT_DEFAULTS \
|
||||
+{ \
|
||||
+ .log_handler = metal_default_log_handler, \
|
||||
+ .log_level = METAL_LOG_INFO, \
|
||||
+}
|
||||
+
|
||||
+/** Structure of libmetal runtime state. */
|
||||
+struct metal_state {
|
||||
+ /** Common (system independent) data. */
|
||||
+ struct metal_common_state common;
|
||||
+};
|
||||
+
|
||||
+#ifdef __cplusplus
|
||||
+}
|
||||
+#endif
|
||||
+
|
||||
+#endif /* __METAL_UNIPROTON_SYS__H__ */
|
||||
@@ -0,0 +1,61 @@
|
||||
diff -uparN open-amp-2022.10.1/cmake/depends.cmake open-amp/cmake/depends.cmake
|
||||
--- open-amp-2022.10.1/cmake/depends.cmake 2022-12-13 11:21:05.000000000 +0800
|
||||
+++ open-amp/cmake/depends.cmake 2023-02-24 16:36:38.000000000 +0800
|
||||
@@ -1,5 +1,5 @@
|
||||
if (WITH_LIBMETAL_FIND)
|
||||
- find_package (Libmetal REQUIRED)
|
||||
+ #find_package (Libmetal REQUIRED)
|
||||
collect (PROJECT_INC_DIRS "${LIBMETAL_INCLUDE_DIR}")
|
||||
collect (PROJECT_LIB_DIRS "${LIBMETAL_LIB_DIR}")
|
||||
collect (PROJECT_LIB_DEPS "${LIBMETAL_LIB}")
|
||||
diff -uparN open-amp-2022.10.1/cmake/platforms/uniproton_arm64_gcc.cmake open-amp/cmake/platforms/uniproton_arm64_gcc.cmake
|
||||
--- open-amp-2022.10.1/cmake/platforms/uniproton_arm64_gcc.cmake 1970-01-01 08:00:00.000000000 +0800
|
||||
+++ open-amp/cmake/platforms/uniproton_arm64_gcc.cmake 2023-02-20 14:24:50.000000000 +0800
|
||||
@@ -0,0 +1,14 @@
|
||||
+#cross-compilation config
|
||||
+
|
||||
+set(CMAKE_SYSTEM_PROCESSOR arm)
|
||||
+set(PROJECT_SYSTEM uniproton)
|
||||
+
|
||||
+set(CMAKE_C_COMPILER_WORKS 1)
|
||||
+set(CMAKE_CXX_COMPILER_WORKS 1)
|
||||
+
|
||||
+set(CROSS_PREFIX "/opt/buildtools/gcc-arm-10.3-2021.07-x86_64-aarch64-none-elf/bin/aarch64-none-elf-" CACHE STRING "")
|
||||
+set(CMAKE_C_COMPILER "${CROSS_PREFIX}gcc" CACHE STRING "")
|
||||
+set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER CACHE STRING "")
|
||||
+set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY NEVER CACHE STRING "")
|
||||
+set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE NEVER CACHE STRING "")
|
||||
+# vim: expandtab:ts=2:sw=2:smartindent
|
||||
diff -uparN open-amp-2022.10.1/CMakeLists.txt open-amp/CMakeLists.txt
|
||||
--- open-amp-2022.10.1/CMakeLists.txt 2022-12-13 11:21:05.000000000 +0800
|
||||
+++ open-amp/CMakeLists.txt 2023-02-24 16:27:30.000000000 +0800
|
||||
@@ -6,7 +6,8 @@ endif()
|
||||
if (POLICY CMP0077)
|
||||
cmake_policy(SET CMP0077 NEW)
|
||||
endif()
|
||||
-
|
||||
+include_directories(../../build/libmetal/output/usr/local/include ../../component/open-amp/lib/include ../../include ../../config)
|
||||
+set (CMAKE_SYSTEM_NAME Uniproton)
|
||||
set (OPENAMP_ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
|
||||
set (OPENAMP_BIN_ROOT "${CMAKE_CURRENT_BINARY_DIR}")
|
||||
|
||||
diff -uparN open-amp-2022.10.1/lib/remoteproc/rsc_table_parser.c open-amp/lib/remoteproc/rsc_table_parser.c
|
||||
--- open-amp-2022.10.1/lib/remoteproc/rsc_table_parser.c 2022-12-13 11:21:05.000000000 +0800
|
||||
+++ open-amp/lib/remoteproc/rsc_table_parser.c 2023-02-24 16:16:20.000000000 +0800
|
||||
@@ -144,6 +144,8 @@ int handle_vdev_rsc(struct remoteproc *r
|
||||
|
||||
num_vrings = vdev_rsc->num_of_vrings;
|
||||
for (i = 0; i < num_vrings; i++) {
|
||||
+ struct fw_rsc_vdev_vring *vring_rsc;
|
||||
+
|
||||
vring_rsc = &vdev_rsc->vring[i];
|
||||
notifyid = vring_rsc->notifyid;
|
||||
notifyid = remoteproc_allocate_id(rproc,
|
||||
diff -uparN open-amp-2022.10.1/VERSION open-amp/VERSION
|
||||
--- open-amp-2022.10.1/VERSION 2022-12-13 11:21:05.000000000 +0800
|
||||
+++ open-amp/VERSION 2023-02-24 15:51:04.000000000 +0800
|
||||
@@ -1,3 +1,3 @@
|
||||
VERSION_MAJOR = 1
|
||||
VERSION_MINOR = 3
|
||||
-VERSION_PATCH = 1
|
||||
+VERSION_PATCH = 0
|
||||
@@ -0,0 +1,2 @@
|
||||
set(SRCS prt_config.c)
|
||||
add_library(config OBJECT ${SRCS})
|
||||
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
* Copyright (c) 2009-2022 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
*
|
||||
* UniProton is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
* http://license.coscl.org.cn/MulanPSL2
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PSL v2 for more details.
|
||||
* Create: 2009-12-22
|
||||
* Description: the common part buildef.h
|
||||
*/
|
||||
#ifndef PRT_BUILDEF_H
|
||||
#define PRT_BUILDEF_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define OS_ARCH_ARMV8
|
||||
|
||||
#define OS_GIC_VER 3
|
||||
|
||||
#ifndef OS_HARDWARE_PLATFORM
|
||||
#define OS_HARDWARE_PLATFORM OS_ARMV8
|
||||
#endif
|
||||
|
||||
#ifndef OS_CPU_TYPE
|
||||
#define OS_CPU_TYPE OS_HI3093
|
||||
#endif
|
||||
|
||||
#define OS_MAX_CORE_NUM 4
|
||||
|
||||
#define OS_THIS_CORE 3
|
||||
|
||||
#ifndef OS_BYTE_ORDER
|
||||
#define OS_BYTE_ORDER OS_LITTLE_ENDIAN
|
||||
#endif
|
||||
|
||||
#define OS_CACHE_LINE_SIZE 64
|
||||
|
||||
#define OS_OPTION_EVENT
|
||||
|
||||
#define OS_OPTION_QUEUE
|
||||
|
||||
#define OS_OPTION_HWI_PRIORITY
|
||||
|
||||
#define OS_OPTION_HWI_ATTRIBUTE
|
||||
|
||||
#define OS_OPTION_SYS_TIME_USR
|
||||
|
||||
#define OS_OPTION_TASK
|
||||
|
||||
#define OS_OPTION_TASK_DELETE
|
||||
|
||||
#define OS_OPTION_TASK_SUSPEND
|
||||
|
||||
#define OS_OPTION_TASK_INFO
|
||||
|
||||
#define OS_OPTION_TASK_YIELD
|
||||
|
||||
#define OS_TSK_PRIORITY_HIGHEST 0
|
||||
|
||||
#define OS_TSK_PRIORITY_LOWEST 63
|
||||
|
||||
#define OS_TSK_NUM_OF_PRIORITIES 64
|
||||
|
||||
#define OS_TSK_CORE_BYTES_IN_PID 2
|
||||
|
||||
#define OS_OPTION_TICK
|
||||
|
||||
#define OS_OPTION_CPUP_WARN
|
||||
|
||||
#define OS_OPTION_RND
|
||||
|
||||
#define OS_OPTION_POSIX
|
||||
|
||||
#define OS_POSIX_TYPE_NEWLIB
|
||||
|
||||
#define OS_OPTION_OPENAMP
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* common macros's definitions */
|
||||
#include "prt_buildef_common.h"
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,324 @@
|
||||
/*
|
||||
* Copyright (c) 2009-2022 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
*
|
||||
* UniProton is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
* http://license.coscl.org.cn/MulanPSL2
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PSL v2 for more details.
|
||||
* Create: 2009-12-22
|
||||
* Description: UniProton的初始化C文件。
|
||||
*/
|
||||
#include "prt_config_internal.h"
|
||||
|
||||
OS_SEC_ALW_INLINE INLINE void OsConfigAddrSizeGet(uintptr_t addr, uintptr_t size,
|
||||
uintptr_t *destAddr, uintptr_t *destSize)
|
||||
{
|
||||
*destAddr = addr;
|
||||
*destSize = size;
|
||||
}
|
||||
|
||||
U32 OsMemConfigReg(void)
|
||||
{
|
||||
U32 ret;
|
||||
|
||||
ret = OsFscMemInit(OS_MEM_FSC_PT_ADDR, OS_MEM_FSC_PT_SIZE);
|
||||
if (ret != OS_OK) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
return OS_OK;
|
||||
}
|
||||
|
||||
U32 OsMemDefPtInit(void)
|
||||
{
|
||||
return OS_OK;
|
||||
}
|
||||
|
||||
U32 OsMemConfigInit(void)
|
||||
{
|
||||
/* 系统默认FSC内存分区初始化 */
|
||||
return OsMemDefPtInit();
|
||||
}
|
||||
|
||||
U32 OsSystemReg(void)
|
||||
{
|
||||
struct SysModInfo sysModInfo;
|
||||
|
||||
sysModInfo.systemClock = OS_SYS_CLOCK;
|
||||
sysModInfo.cpuType = OS_CPU_TYPE;
|
||||
sysModInfo.sysTimeHook = OS_SYS_TIME_HOOK;
|
||||
#if defined(OS_OPTION_HWI_MAX_NUM_CONFIG)
|
||||
sysModInfo.hwiMaxNum = OS_HWI_MAX_NUM_CONFIG;
|
||||
#endif
|
||||
|
||||
return OsSysRegister(&sysModInfo);
|
||||
}
|
||||
|
||||
#if (OS_INCLUDE_SEM == YES)
|
||||
U32 OsSemConfigReg(void)
|
||||
{
|
||||
struct SemModInfo semModInfo;
|
||||
|
||||
semModInfo.maxNum = OS_SEM_MAX_SUPPORT_NUM;
|
||||
return OsSemRegister(&semModInfo);
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
#if (OS_INCLUDE_TASK == YES)
|
||||
void OsTaskInfoSet(struct TskModInfo *taskModInfo)
|
||||
{
|
||||
taskModInfo->maxNum = OS_TSK_MAX_SUPPORT_NUM;
|
||||
taskModInfo->defaultSize = OS_TSK_DEFAULT_STACK_SIZE;
|
||||
taskModInfo->idleStackSize = OS_TSK_IDLE_STACK_SIZE;
|
||||
taskModInfo->magicWord = WORD_PACK((U32)OS_TSK_STACK_MAGIC_WORD);
|
||||
}
|
||||
#else
|
||||
#error "OS_INCLUDE_TASK MUST BE YES! The SWI has been cut out,the task can not cut out."
|
||||
#endif
|
||||
|
||||
U32 OsHookConfigReg(void)
|
||||
{
|
||||
struct HookModInfo hookModInfo;
|
||||
|
||||
hookModInfo.maxNum[OS_HOOK_HWI_ENTRY] = OS_HOOK_HWI_ENTRY_NUM;
|
||||
hookModInfo.maxNum[OS_HOOK_HWI_EXIT] = OS_HOOK_HWI_EXIT_NUM;
|
||||
hookModInfo.maxNum[OS_HOOK_TSK_SWITCH] = OS_HOOK_TSK_SWITCH_NUM;
|
||||
hookModInfo.maxNum[OS_HOOK_IDLE_PERIOD] = OS_HOOK_IDLE_NUM;
|
||||
|
||||
return OsHookRegister(&hookModInfo);
|
||||
}
|
||||
|
||||
U32 OsSysConfigReg(void)
|
||||
{
|
||||
U32 ret;
|
||||
|
||||
ret = OsSystemReg();
|
||||
if (ret != OS_OK) {
|
||||
return ret;
|
||||
}
|
||||
return OS_OK;
|
||||
}
|
||||
|
||||
#if (OS_INCLUDE_TICK == YES)
|
||||
U32 OsTickConfigReg(void)
|
||||
{
|
||||
struct TickModInfo tickModInfo;
|
||||
|
||||
tickModInfo.tickPerSecond = OS_TICK_PER_SECOND;
|
||||
tickModInfo.tickPriority = 0;
|
||||
|
||||
return OsTickRegister(&tickModInfo);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if (OS_INCLUDE_TASK == YES)
|
||||
U32 OsTskConfigReg(void)
|
||||
{
|
||||
struct TskModInfo taskModInfo;
|
||||
OsTaskInfoSet(&taskModInfo);
|
||||
return OsTskRegister(&taskModInfo);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if (OS_INCLUDE_QUEUE == YES)
|
||||
U32 OsQueueConfigReg(void)
|
||||
{
|
||||
return OsQueueRegister(OS_QUEUE_MAX_SUPPORT_NUM);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if (OS_INCLUDE_CPUP == YES)
|
||||
U32 OsCpupConfigReg(void)
|
||||
{
|
||||
struct CpupModInfo cpupModInfo;
|
||||
|
||||
cpupModInfo.cpupWarnFlag = (bool)OS_CONFIG_CPUP_WARN;
|
||||
cpupModInfo.sampleTime = OS_CPUP_SAMPLE_INTERVAL;
|
||||
cpupModInfo.warn = OS_CPUP_SHORT_WARN;
|
||||
cpupModInfo.resume = OS_CPUP_SHORT_RESUME;
|
||||
|
||||
return OsCpupRegister(&cpupModInfo);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if (OS_INCLUDE_TICK_SWTMER == YES)
|
||||
U32 OsSwTmrConfigInit(void)
|
||||
{
|
||||
return OsSwTmrInit(OS_TICK_SWITIMER_MAX_NUM);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if (OS_INCLUDE_CPUP == YES)
|
||||
#if (OS_INCLUDE_TICK == NO)
|
||||
#error "OS_INCLUDE_CPUP depend on OS_INCLUDE_TICK!"
|
||||
#endif
|
||||
U32 OsCpupConfigInit(void)
|
||||
{
|
||||
U32 ret;
|
||||
|
||||
ret = OsCpupInit();
|
||||
if (ret != OS_OK) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (OS_CONFIG_CPUP_WARN == YES) {
|
||||
#if defined(OS_OPTION_CPUP_WARN)
|
||||
OsCpupWarnInit();
|
||||
#else
|
||||
return OS_ERRNO_SYS_NO_CPUP_WARN;
|
||||
#endif
|
||||
}
|
||||
return OS_OK;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if (OS_INCLUDE_SEM == YES)
|
||||
U32 OsSemConfigInit(void)
|
||||
{
|
||||
return OsSemInit();
|
||||
}
|
||||
#endif
|
||||
|
||||
#if (OS_INCLUDE_TASK == YES)
|
||||
U32 OsTskConfigInit(void)
|
||||
{
|
||||
return OsTskInit();
|
||||
}
|
||||
#endif
|
||||
|
||||
static U32 OsHwiConfigReg(void)
|
||||
{
|
||||
#if (OS_INCLUDE_GIC_BASE_ADDR_CONFIG == YES)
|
||||
U32 ret;
|
||||
ret = OsGicConfigRegister((uintptr_t)OS_GIC_BASE_ADDR, (uintptr_t)OS_GICR_OFFSET, (uintptr_t)OS_GICR_STRIDE);
|
||||
if (ret != OS_OK) {
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
return OS_OK;
|
||||
}
|
||||
|
||||
/* 系统初始化注册表 */
|
||||
struct OsModuleConfigInfo g_moduleConfigTab[] = {
|
||||
/* {模块号, 模块注册函数, 模块初始化函数} */
|
||||
{OS_MID_SYS, {OsSysConfigReg, NULL}},
|
||||
{OS_MID_MEM, {OsMemConfigReg, OsMemConfigInit}},
|
||||
{OS_MID_HWI, {OsHwiConfigReg, OsHwiConfigInit}},
|
||||
{OS_MID_HARDDRV, {NULL, PRT_HardDrvInit}},
|
||||
{OS_MID_HOOK, {OsHookConfigReg, OsHookConfigInit}},
|
||||
{OS_MID_EXC, {NULL, OsExcConfigInit}},
|
||||
#if (OS_INCLUDE_TASK == YES)
|
||||
{OS_MID_TSK, {OsTskConfigReg, OsTskConfigInit}},
|
||||
#endif
|
||||
#if (OS_INCLUDE_TICK == YES)
|
||||
{OS_MID_TICK, {OsTickConfigReg, OsTickConfigInit}},
|
||||
#endif
|
||||
|
||||
#if (OS_INCLUDE_TICK_SWTMER == YES)
|
||||
{OS_MID_SWTMR, {NULL, OsSwTmrConfigInit}},
|
||||
#endif
|
||||
|
||||
#if (OS_INCLUDE_CPUP == YES)
|
||||
{OS_MID_CPUP, {OsCpupConfigReg, OsCpupConfigInit}},
|
||||
#endif
|
||||
#if (OS_INCLUDE_SEM == YES)
|
||||
{OS_MID_SEM, {OsSemConfigReg, OsSemConfigInit}},
|
||||
#endif
|
||||
#if (OS_INCLUDE_QUEUE == YES)
|
||||
{OS_MID_QUEUE, {OsQueueConfigReg, OsQueueConfigInit}},
|
||||
#endif
|
||||
{OS_MID_APP, {NULL, PRT_AppInit}},
|
||||
|
||||
{OS_MID_BUTT, {NULL, NULL}},
|
||||
};
|
||||
|
||||
/*
|
||||
* 描述:OS模块注册、初始化运行函数
|
||||
*/
|
||||
U32 OsModuleConfigRun(enum OsinitPhaseId initPhaseId, U32 initPhase)
|
||||
{
|
||||
U32 idx = 0;
|
||||
U32 ret = OS_OK;
|
||||
while (g_moduleConfigTab[idx].moudleId != OS_MID_BUTT) {
|
||||
if (g_moduleConfigTab[idx].moudleConfigFunc[initPhaseId] == NULL) {
|
||||
idx++;
|
||||
continue;
|
||||
}
|
||||
ret = g_moduleConfigTab[idx].moudleConfigFunc[initPhaseId]();
|
||||
if (ret != OS_OK) {
|
||||
break;
|
||||
}
|
||||
idx++;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
U32 OsRegister(void)
|
||||
{
|
||||
return OsModuleConfigRun(OS_REGISTER_ID, OS_REGISTER_PHASE);
|
||||
}
|
||||
|
||||
/*
|
||||
* 描述:OsInitialize阶段
|
||||
*/
|
||||
U32 OsInitialize(void)
|
||||
{
|
||||
return OsModuleConfigRun(OS_INIT_ID, OS_INITIALIZE_PHASE);
|
||||
}
|
||||
|
||||
/*
|
||||
* 描述:OsStart阶段
|
||||
*/
|
||||
U32 OsStart(void)
|
||||
{
|
||||
U32 ret;
|
||||
|
||||
#if (OS_INCLUDE_TICK == YES)
|
||||
/* 表示系统在进行启动阶段,匹配MOUDLE_ID之后,标记进入TICK模块的启动 */
|
||||
ret = OsTickStart();
|
||||
if (ret != OS_OK) {
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if (OS_INCLUDE_TASK == YES)
|
||||
/* 表示系统在进行启动阶段,匹配MOUDLE_ID之后,标记进入任务模块的启动 */
|
||||
ret = OsActivate();
|
||||
#else
|
||||
ret = OS_OK;
|
||||
#endif
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
S32 OsConfigStart(void)
|
||||
{
|
||||
U32 ret;
|
||||
|
||||
OsHwInit();
|
||||
|
||||
/* OS模块注册 */
|
||||
ret = OsRegister();
|
||||
if (ret != OS_OK) {
|
||||
return (S32)ret;
|
||||
}
|
||||
|
||||
/* OS模块初始化 */
|
||||
ret = OsInitialize();
|
||||
if (ret != OS_OK) {
|
||||
return (S32)ret;
|
||||
}
|
||||
|
||||
/* OS启动调度 */
|
||||
ret = OsStart();
|
||||
if (ret != OS_OK) {
|
||||
return (S32)ret;
|
||||
}
|
||||
|
||||
/* Execution should not reach this point */
|
||||
return (S32)OS_ERROR;
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
/*
|
||||
* Copyright (c) 2009-2022 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
*
|
||||
* UniProton is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
* http://license.coscl.org.cn/MulanPSL2
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PSL v2 for more details.
|
||||
* Create: 2009-12-22
|
||||
* Description: UniProton配置头文件,裁剪开关和配置项。
|
||||
*/
|
||||
#ifndef PRT_CONFIG_H
|
||||
#define PRT_CONFIG_H
|
||||
|
||||
#include "prt_buildef.h"
|
||||
#include "prt_typedef.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* ***************************** 配置系统基本信息 ******************************* */
|
||||
/* 芯片主频 */
|
||||
#define OS_SYS_CLOCK 250000000
|
||||
/* 用户注册的获取系统时间的函数*/
|
||||
#define OS_SYS_TIME_HOOK NULL
|
||||
|
||||
/* ***************************** 中断模块配置 ************************** */
|
||||
/* 硬中断最大支持个数 */
|
||||
#define OS_HWI_MAX_NUM_CONFIG 150
|
||||
|
||||
/* ***************************** 配置Tick中断模块 *************************** */
|
||||
/* Tick中断模块裁剪开关 */
|
||||
#define OS_INCLUDE_TICK YES
|
||||
/* Tick中断时间间隔,tick处理时间不能超过1/OS_TICK_PER_SECOND(s) */
|
||||
#define OS_TICK_PER_SECOND 1000
|
||||
|
||||
/* ***************************** 配置定时器模块 ***************************** */
|
||||
/* 基于TICK的软件定时器裁剪开关 */
|
||||
#define OS_INCLUDE_TICK_SWTMER NO
|
||||
/* 基于TICK的软件定时器最大个数 */
|
||||
#define OS_TICK_SWITIMER_MAX_NUM 32
|
||||
|
||||
/* ***************************** 配置任务模块 ******************************* */
|
||||
/* 任务模块裁剪开关 */
|
||||
#define OS_INCLUDE_TASK YES
|
||||
/* 最大支持的任务数,最大共支持254个 */
|
||||
#define OS_TSK_MAX_SUPPORT_NUM 8
|
||||
/* 缺省的任务栈大小 */
|
||||
#define OS_TSK_DEFAULT_STACK_SIZE 0x1000
|
||||
/* IDLE任务栈的大小 */
|
||||
#define OS_TSK_IDLE_STACK_SIZE 0x1000
|
||||
/* 任务栈初始化魔术字,默认是0xCA,只支持配置一个字节 */
|
||||
#define OS_TSK_STACK_MAGIC_WORD 0xCA
|
||||
|
||||
/* ***************************** 配置CPU占用率及CPU告警模块 **************** */
|
||||
/* CPU占用率模块裁剪开关 */
|
||||
#define OS_INCLUDE_CPUP NO
|
||||
/* 采样时间间隔(单位tick),若其值大于0,则作为采样周期,否则两次调用PRT_CpupNow或PRT_CpupThread间隔作为周期 */
|
||||
#define OS_CPUP_SAMPLE_INTERVAL 10
|
||||
/* CPU占用率告警动态配置项 */
|
||||
#define OS_CONFIG_CPUP_WARN NO
|
||||
/* CPU占用率告警阈值(精度为万分比) */
|
||||
#define OS_CPUP_SHORT_WARN 8500
|
||||
/* CPU占用率告警恢复阈值(精度为万分比) */
|
||||
#define OS_CPUP_SHORT_RESUME 7500
|
||||
|
||||
/* ***************************** 配置内存管理模块 ************************** */
|
||||
/* 用户可以创建的最大分区数,取值范围[0,253] */
|
||||
#define OS_MEM_MAX_PT_NUM 200
|
||||
/* 私有FSC内存分区起始地址 */
|
||||
#define OS_MEM_FSC_PT_ADDR (uintptr_t)&g_memRegion00[0]
|
||||
/* 私有FSC内存分区大小 */
|
||||
#define OS_MEM_FSC_PT_SIZE 0x80000
|
||||
|
||||
/* ***************************** 配置信号量管理模块 ************************* */
|
||||
/* 信号量模块裁剪开关 */
|
||||
#define OS_INCLUDE_SEM YES
|
||||
|
||||
/* 最大支持的信号量数 */
|
||||
#define OS_SEM_MAX_SUPPORT_NUM 10
|
||||
|
||||
/* ***************************** 配置队列模块 ******************************* */
|
||||
/* 队列模块裁剪开关 */
|
||||
#define OS_INCLUDE_QUEUE YES
|
||||
/* 最大支持的队列数,范围(0,0xFFFF] */
|
||||
#define OS_QUEUE_MAX_SUPPORT_NUM 10
|
||||
|
||||
/* ************************* 钩子模块配置 *********************************** */
|
||||
/* 硬中断进入钩子最大支持个数, 范围[0, 255] */
|
||||
#define OS_HOOK_HWI_ENTRY_NUM 5
|
||||
/* 硬中断退出钩子最大支持个数, 范围[0, 255] */
|
||||
#define OS_HOOK_HWI_EXIT_NUM 5
|
||||
/* 任务切换钩子最大支持个数, 范围[0, 255] */
|
||||
#define OS_HOOK_TSK_SWITCH_NUM 8
|
||||
/* IDLE钩子最大支持个数, 范围[0, 255] */
|
||||
#define OS_HOOK_IDLE_NUM 4
|
||||
|
||||
/* ************************* GIC模块配置 *********************************** */
|
||||
/* GIC地址可配置开关 */
|
||||
#define OS_INCLUDE_GIC_BASE_ADDR_CONFIG YES
|
||||
/* GIC基地址配置 */
|
||||
#define OS_GIC_BASE_ADDR 0x24000000U
|
||||
/* GICR相对于GIC基地址偏移量配置 */
|
||||
#define OS_GICR_OFFSET 0x40000U
|
||||
/* GICR核间偏移量配置 */
|
||||
#define OS_GICR_STRIDE 0x20000U
|
||||
|
||||
extern U8 g_memRegion00[];
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cpluscplus */
|
||||
#endif /* __cpluscplus */
|
||||
|
||||
#endif /* PRT_CONFIG_H */
|
||||
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
* Copyright (c) 2009-2022 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
*
|
||||
* UniProton is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
* http://license.coscl.org.cn/MulanPSL2
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PSL v2 for more details.
|
||||
* Create: 2009-12-22
|
||||
* Description: UniProton配置私有文件。
|
||||
*/
|
||||
#ifndef PRT_CONFIG_INTERNAL_H
|
||||
#define PRT_CONFIG_INTERNAL_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include "prt_config.h"
|
||||
#include "prt_sys.h"
|
||||
#include "prt_task.h"
|
||||
#include "prt_sem.h"
|
||||
#include "prt_tick.h"
|
||||
#include "prt_exc.h"
|
||||
#include "prt_cpup.h"
|
||||
#include "prt_mem.h"
|
||||
#include "prt_hook.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cpluscplus */
|
||||
#endif /* __cpluscplus */
|
||||
|
||||
#define WORD_PACK(val) (((val) << 24) | ((val) << 16) | ((val) << 8) | (val))
|
||||
|
||||
/* UniProton模块注册函数的声明 */
|
||||
extern U32 OsFscMemInit(U32 addr, U32 size);
|
||||
extern U32 OsSysRegister(struct SysModInfo *modInfo);
|
||||
extern U32 OsTickRegister(struct TickModInfo *modInfo);
|
||||
extern U32 OsTskRegister(struct TskModInfo *modInfo);
|
||||
extern U32 OsCpupRegister(struct CpupModInfo *modInfo);
|
||||
extern U32 OsSemRegister(const struct SemModInfo *modInfo);
|
||||
extern U32 OsHookRegister(struct HookModInfo *modInfo);
|
||||
|
||||
extern U32 OsHwiConfigInit(void);
|
||||
extern U32 OsTickConfigInit(void);
|
||||
extern U32 OsTskInit(void);
|
||||
extern U32 OsCpupInit(void);
|
||||
extern void OsCpupWarnInit(void);
|
||||
extern U32 OsExcConfigInit(void);
|
||||
extern U32 OsSemInit(void);
|
||||
extern U32 OsHookConfigInit(void);
|
||||
|
||||
/* UniProton系统启动相关函数的声明 */
|
||||
extern void OsHwInit(void);
|
||||
extern U32 OsActivate(void);
|
||||
extern U32 OsTickStart(void);
|
||||
extern U32 PRT_HardDrvInit(void);
|
||||
extern void PRT_HardBootInit(void);
|
||||
extern U32 PRT_AppInit(void);
|
||||
|
||||
extern U32 OsQueueRegister(U16 maxQueue);
|
||||
extern U32 OsQueueConfigInit(void);
|
||||
|
||||
#if (OS_INCLUDE_TICK_SWTMER == YES)
|
||||
extern U32 OsSwTmrInit(U32 maxTimerNum);
|
||||
#endif
|
||||
|
||||
enum OsinitPhaseId {
|
||||
OS_REGISTER_ID = 0,
|
||||
OS_INIT_ID,
|
||||
OS_MOUDLE_CONFIG
|
||||
};
|
||||
typedef U32 (*ConfigInitFunc)(void);
|
||||
struct OsModuleConfigInfo {
|
||||
enum MoudleId moudleId;
|
||||
ConfigInitFunc moudleConfigFunc[OS_MOUDLE_CONFIG];
|
||||
};
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cpluscplus */
|
||||
#endif /* __cpluscplus */
|
||||
|
||||
#endif /* PRT_CONFIG_INTERNAL_H */
|
||||
@@ -0,0 +1,10 @@
|
||||
# Copyright (c) 2022-2022 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
#
|
||||
# UniProton is licensed under Mulan PSL v2.
|
||||
# You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
# You may obtain a copy of Mulan PSL v2 at:
|
||||
# http://license.coscl.org.cn/MulanPSL2
|
||||
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
# EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
# MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
# See the Mulan PSL v2 for more details.
|
||||
@@ -0,0 +1,10 @@
|
||||
# Copyright (c) 2022-2022 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
#
|
||||
# UniProton is licensed under Mulan PSL v2.
|
||||
# You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
# You may obtain a copy of Mulan PSL v2 at:
|
||||
# http://license.coscl.org.cn/MulanPSL2
|
||||
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
# EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
# MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
# See the Mulan PSL v2 for more details.
|
||||
@@ -0,0 +1,10 @@
|
||||
本目录下放置的是UniProton实时部分版本。
|
||||
|
||||
├─apps # 基于UniProton实时OS编程的demo程序;
|
||||
│ └─openamp # openamp示例程序;
|
||||
├─bsp # 提供的板级驱动与OS对接;
|
||||
├─build # 提供编译脚本编译出最终镜像;
|
||||
├─component # 适配openamp框架patch文件,openamp源码下载存放路径;
|
||||
├─config # 配置选项,供用户调整运行时参数;
|
||||
├─include # UniProton实时部分提供的编程接口API;
|
||||
└─libs # UniProton实时部分的静态库,build目录中的makefile示例已经将头文件和静态库的引用准备好,应用可直接使用;
|
||||
@@ -0,0 +1,43 @@
|
||||
cmake_minimum_required(VERSION 3.12)
|
||||
project(exmaples LANGUAGES C ASM)
|
||||
|
||||
set(CMAKE_C_COMPILER ${TOOLCHAIN_PATH}/bin/aarch64-none-elf-gcc)
|
||||
set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PATH}/bin/aarch64-none-elf-g++)
|
||||
set(CMAKE_ASM_COMPILER ${TOOLCHAIN_PATH}/bin/aarch64-none-elf-gcc)
|
||||
set(CMAKE_LINKER ${TOOLCHAIN_PATH}/bin/aarch64-none-elf-ld)
|
||||
|
||||
set(POSIX_OPTION "-D_POSIX_THREADS -D_POSIX_THREAD_PRIORITY_SCHEDULING -D_POSIX_PRIORITY_SCHEDULING -D_POSIX_TIMERS -D_POSIX_CPUTIME -D_POSIX_THREAD_CPUTIME -D_POSIX_MONOTONIC_CLOCK -D_POSIX_TIMEOUTS -D_POSIX_CLOCK_SELECTION -D_POSIX_THREAD_PRIO_PROTECT -D_UNIX98_THREAD_MUTEX_ATTRIBUTES -D_POSIX_READER_WRITER_LOCKS")
|
||||
set(CC_OPTION "-g -march=armv8.2-a+nofp+nosimd -Wl,--build-id=none -fno-builtin -fno-PIE -Wall -fno-dwarf2-cfi-asm -O0 -mcmodel=large -fomit-frame-pointer -fzero-initialized-in-bss -fdollars-in-identifiers -ffunction-sections -fdata-sections -fno-common -fno-aggressive-loop-optimizations -fno-optimize-strlen -fno-schedule-insns -fno-inline-small-functions -fno-inline-functions-called-once -fno-strict-aliasing -fno-builtin -finline-limit=20 -mstrict-align -mlittle-endian -specs=nosys.specs -nostartfiles -funwind-tables")
|
||||
set(AS_OPTION "-g -march=armv8.2-a+nofp+nosimd -Wl,--build-id=none -fno-builtin -fno-PIE -Wall -fno-dwarf2-cfi-asm -O0 -mcmodel=large -fomit-frame-pointer -fzero-initialized-in-bss -fdollars-in-identifiers -ffunction-sections -fdata-sections -fno-common -fno-aggressive-loop-optimizations -fno-optimize-strlen -fno-schedule-insns -fno-inline-small-functions -fno-inline-functions-called-once -fno-strict-aliasing -fno-builtin -finline-limit=20 -mstrict-align -mlittle-endian -nostartfiles -mgeneral-regs-only -DENV_EL1")
|
||||
set(LD_OPTION "-static -no-pie -Wl,--wrap=memset -Wl,--wrap=memcpy")
|
||||
set(CMAKE_C_FLAGS "${CC_OPTION} ${POSIX_OPTION}")
|
||||
set(CMAKE_ASM_FLAGS "${AS_OPTION} ${POSIX_OPTION}")
|
||||
set(CMAKE_LINK_FLAGS "${LD_OPTION} -T ../raspi4.ld")
|
||||
set(CMAKE_EXE_LINKER_FLAGS "${LD_OPTION} -T ../raspi4.ld")
|
||||
|
||||
include_directories(
|
||||
./include
|
||||
./config
|
||||
./bsp
|
||||
./bsp/raspi4
|
||||
./apps/openamp
|
||||
./build/open-amp/output/usr/local/include
|
||||
./build/libmetal/output/usr/local/include
|
||||
)
|
||||
|
||||
link_directories(./libs)
|
||||
link_libraries(
|
||||
-Wl,--start-group
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/libs/libCortexMXsec_c.lib"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/libs/libRASPI4.a"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/libs/libmetal.a"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/libs/libopen_amp.a"
|
||||
-Wl,--end-group
|
||||
)
|
||||
|
||||
add_subdirectory(bsp)
|
||||
add_subdirectory(config)
|
||||
add_subdirectory(apps)
|
||||
|
||||
list(APPEND OBJS $<TARGET_OBJECTS:rpmsg> $<TARGET_OBJECTS:bsp> $<TARGET_OBJECTS:config>)
|
||||
add_executable(${APP} ${OBJS})
|
||||
@@ -0,0 +1 @@
|
||||
add_subdirectory(openamp)
|
||||
@@ -0,0 +1,2 @@
|
||||
set(SRC rpmsg_backend.c rpmsg_service.c main.c)
|
||||
add_library(rpmsg OBJECT ${SRC})
|
||||
@@ -0,0 +1,131 @@
|
||||
/*
|
||||
* Copyright (c) 2009-2022 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
*
|
||||
* UniProton is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
* http://license.coscl.org.cn/MulanPSL2
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PSL v2 for more details.
|
||||
* Create: 2009-12-22
|
||||
* Description: UniProton raspi4 demo
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdarg.h>
|
||||
#include "securec.h"
|
||||
#include "prt_config.h"
|
||||
#include "prt_config_internal.h"
|
||||
#include "prt_task.h"
|
||||
#include "test.h"
|
||||
|
||||
TskHandle g_testTskHandle;
|
||||
U8 g_memRegion00[OS_MEM_FSC_PT_SIZE];
|
||||
|
||||
#if defined(OS_OPTION_OPENAMP)
|
||||
int TestOpenamp()
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = rpmsg_service_init();
|
||||
if (ret) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
return OS_OK;
|
||||
}
|
||||
#endif
|
||||
|
||||
void TestTaskEntry()
|
||||
{
|
||||
#if defined(OS_OPTION_OPENAMP)
|
||||
TestOpenamp();
|
||||
#endif
|
||||
}
|
||||
|
||||
U32 OsTestInit(void)
|
||||
{
|
||||
U32 ret;
|
||||
U8 ptNo = OS_MEM_DEFAULT_FSC_PT;
|
||||
struct TskInitParam param = {0};
|
||||
|
||||
param.stackAddr = (U32)PRT_MemAllocAlign(0, ptNo, 0x2000, MEM_ADDR_ALIGN_016);
|
||||
param.taskEntry = (TskEntryFunc)TestTaskEntry;
|
||||
param.taskPrio = 25;
|
||||
param.name = "TestTask";
|
||||
param.stackSize = 0x2000;
|
||||
|
||||
ret = PRT_TaskCreate(&g_testTskHandle, ¶m);
|
||||
if (ret) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = PRT_TaskResume(g_testTskHandle);
|
||||
if (ret) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
return OS_OK;
|
||||
}
|
||||
|
||||
U32 PRT_AppInit(void)
|
||||
{
|
||||
U32 ret;
|
||||
|
||||
ret = OsTestInit();
|
||||
if (ret) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = TestClkStart();
|
||||
if (ret) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
return OS_OK;
|
||||
}
|
||||
|
||||
U32 PRT_HardDrvInit(void)
|
||||
{
|
||||
U32 ret;
|
||||
|
||||
ret = OsHwiInit();
|
||||
if (ret) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
return OS_OK;
|
||||
}
|
||||
|
||||
void PRT_HardBootInit(void)
|
||||
{
|
||||
}
|
||||
|
||||
S32 main(void)
|
||||
{
|
||||
return OsConfigStart();
|
||||
}
|
||||
|
||||
extern void *__wrap_memset(void *dest, int set, U32 len)
|
||||
{
|
||||
if (dest == NULL || len == 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char *ret = (char *)dest;
|
||||
for (int i = 0; i < len; ++i) {
|
||||
ret[i] = set;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
extern void *__wrap_memcpy(void *dest, const void *src, size_t size)
|
||||
{
|
||||
for (size_t i = 0; i < size; ++i) {
|
||||
*(char *)(dest + i) = *(char *)(src + i);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* Copyright (c) 2022-2022 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
*
|
||||
* UniProton is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
* http://license.coscl.org.cn/MulanPSL2
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* See the Mulan PSL v2 for more details.
|
||||
* Create: 2022-12-05
|
||||
* Description: openamp configuration
|
||||
*/
|
||||
|
||||
#ifndef COMMON_H__
|
||||
#define COMMON_H__
|
||||
|
||||
#include "cpu_config.h"
|
||||
#include "test.h"
|
||||
|
||||
#define VDEV_START_ADDR MMU_OPENAMP_ADDR
|
||||
#define VDEV_SIZE 0x30000
|
||||
|
||||
#define VDEV_STATUS_ADDR VDEV_START_ADDR
|
||||
#define VDEV_STATUS_SIZE 0x4000
|
||||
|
||||
#define SHM_START_ADDR (VDEV_START_ADDR + VDEV_STATUS_SIZE)
|
||||
#define SHM_SIZE (VDEV_SIZE - VDEV_STATUS_SIZE)
|
||||
#define SHM_DEVICE_NAME "lonely_device"
|
||||
|
||||
#define VRING_COUNT 2
|
||||
#define VRING_RX_ADDRESS (VDEV_START_ADDR + SHM_SIZE - VDEV_STATUS_SIZE)
|
||||
#define VRING_TX_ADDRESS (VDEV_START_ADDR + SHM_SIZE)
|
||||
#define VRING_ALIGNMENT 4
|
||||
#define VRING_SIZE 16
|
||||
|
||||
#define CONFIG_RPMSG_SERVICE_NUM_ENDPOINTS 1
|
||||
|
||||
#define DEFAULT_PAGE_SHIFT 0xffffffffffffffffULL
|
||||
#define DEFAULT_PAGE_MASK 0xffffffffffffffffULL
|
||||
|
||||
#define VIRTQUEUE_ID 1
|
||||
#define RPMSG_ROLE RPMSG_REMOTE
|
||||
|
||||
#define OS_OPENAMP_NOTIFY_HWI_NUM OS_HWI_IPI_NO_07
|
||||
#define OS_OPENAMP_NOTIFY_HWI_PRIO 0
|
||||
|
||||
#define BIT(n) (1 << (n))
|
||||
|
||||
OS_SEC_ALW_INLINE INLINE void sys_write32(uint32_t data, uintptr_t addr)
|
||||
{
|
||||
__asm__ volatile ("dmb sy" : : : "memory");
|
||||
__asm__ volatile ("str %w0, [%1]" : : "r" (data), "r" (addr));
|
||||
}
|
||||
|
||||
OS_SEC_ALW_INLINE INLINE uint32_t sys_read32(uintptr_t addr)
|
||||
{
|
||||
uint32_t val;
|
||||
__asm__ volatile ("ldr %w0, [%1]" : "=r" (val) : "r" (addr));
|
||||
__asm__ volatile ("dmb sy" : : : "memory");
|
||||
return val;
|
||||
}
|
||||
|
||||
OS_SEC_ALW_INLINE INLINE void sys_write8(uint8_t data, uintptr_t addr)
|
||||
{
|
||||
__asm__ volatile ("dmb sy" : : : "memory");
|
||||
__asm__ volatile ("strb %w0, [%1]" : : "r" (data), "r" (addr));
|
||||
}
|
||||
|
||||
OS_SEC_ALW_INLINE INLINE uint8_t sys_read8(uintptr_t addr)
|
||||
{
|
||||
uint8_t val;
|
||||
__asm__ volatile ("ldrb %w0, [%1]" : "=r" (val) : "r" (addr));
|
||||
__asm__ volatile ("dmb sy" : : : "memory");
|
||||
return val;
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,174 @@
|
||||
/*
|
||||
* Copyright (c) 2022-2022 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
*
|
||||
* UniProton is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
* http://license.coscl.org.cn/MulanPSL2
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* See the Mulan PSL v2 for more details.
|
||||
* Create: 2022-12-05
|
||||
* Description: openamp backend
|
||||
*/
|
||||
|
||||
#include "rpmsg_backend.h"
|
||||
#include "metal/device.h"
|
||||
#include "prt_hwi.h"
|
||||
|
||||
static metal_phys_addr_t shm_physmap[] = { SHM_START_ADDR };
|
||||
static struct metal_device shm_device = {
|
||||
.name = SHM_DEVICE_NAME,
|
||||
.bus = NULL,
|
||||
.num_regions = 1,
|
||||
{
|
||||
{
|
||||
.virt = (void *) SHM_START_ADDR,
|
||||
.physmap = shm_physmap,
|
||||
.size = SHM_SIZE,
|
||||
.page_shift = DEFAULT_PAGE_SHIFT,
|
||||
.page_mask = DEFAULT_PAGE_MASK,
|
||||
.mem_flags = 0,
|
||||
.ops = { NULL },
|
||||
},
|
||||
},
|
||||
.node = { NULL },
|
||||
.irq_num = 0,
|
||||
.irq_info = NULL
|
||||
};
|
||||
|
||||
static struct virtio_vring_info rvrings[2] = {
|
||||
[0] = {
|
||||
.info.align = VRING_ALIGNMENT,
|
||||
},
|
||||
[1] = {
|
||||
.info.align = VRING_ALIGNMENT,
|
||||
},
|
||||
};
|
||||
|
||||
static struct virtqueue *vq[2];
|
||||
|
||||
static unsigned char virtio_get_status(struct virtio_device *vdev)
|
||||
{
|
||||
return sys_read8(VDEV_STATUS_ADDR);
|
||||
}
|
||||
|
||||
static void virtio_set_status(struct virtio_device *vdev, unsigned char status)
|
||||
{
|
||||
sys_write8(status, VDEV_STATUS_ADDR);
|
||||
}
|
||||
|
||||
static uint32_t virtio_get_features(struct virtio_device *vdev)
|
||||
{
|
||||
return BIT(VIRTIO_RPMSG_F_NS);
|
||||
}
|
||||
|
||||
static void virtio_set_features(struct virtio_device *vdev, uint32_t features)
|
||||
{
|
||||
}
|
||||
|
||||
static void virtio_notify(struct virtqueue *vq)
|
||||
{
|
||||
uint16_t coreMask = 1;
|
||||
OsHwiMcTrigger(coreMask, OS_HWI_IPI_NO_07);
|
||||
}
|
||||
|
||||
const struct virtio_dispatch dispatch = {
|
||||
.get_status = virtio_get_status,
|
||||
.set_status = virtio_set_status,
|
||||
.get_features = virtio_get_features,
|
||||
.set_features = virtio_set_features,
|
||||
.notify = virtio_notify,
|
||||
};
|
||||
|
||||
static void rpmsg_hwi_handler(void)
|
||||
{
|
||||
virtqueue_notification(vq[VIRTQUEUE_ID]);
|
||||
}
|
||||
|
||||
static U32 rpmsg_hwi_init(void)
|
||||
{
|
||||
U32 ret;
|
||||
|
||||
ret = PRT_HwiSetAttr(OS_OPENAMP_NOTIFY_HWI_NUM, OS_OPENAMP_NOTIFY_HWI_PRIO, OS_HWI_MODE_ENGROSS);
|
||||
if (ret != OS_OK) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = PRT_HwiCreate(OS_OPENAMP_NOTIFY_HWI_NUM, (HwiProcFunc)rpmsg_hwi_handler, 0);
|
||||
if (ret != OS_OK) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
#if (OS_GIC_VER == 3)
|
||||
ret = PRT_HwiEnable(OS_OPENAMP_NOTIFY_HWI_NUM);
|
||||
if (ret != OS_OK) {
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
return OS_OK;
|
||||
}
|
||||
|
||||
int rpmsg_backend_init(struct metal_io_region **io, struct virtio_device *vdev)
|
||||
{
|
||||
int32_t err;
|
||||
struct metal_init_params metal_params = METAL_INIT_DEFAULTS;
|
||||
struct metal_device *device;
|
||||
|
||||
err = rpmsg_hwi_init();
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
|
||||
/* Libmetal setup */
|
||||
err = metal_init(&metal_params);
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
|
||||
err = metal_register_generic_device(&shm_device);
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
|
||||
err = metal_device_open("generic", SHM_DEVICE_NAME, &device);
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
|
||||
*io = metal_device_io_region(device, 0);
|
||||
if (!*io) {
|
||||
return err;
|
||||
}
|
||||
|
||||
/* Virtqueue setup */
|
||||
vq[0] = virtqueue_allocate(VRING_SIZE);
|
||||
if (!vq[0]) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
vq[1] = virtqueue_allocate(VRING_SIZE);
|
||||
if (!vq[1]) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
rvrings[0].io = *io;
|
||||
rvrings[0].info.vaddr = (void *)VRING_TX_ADDRESS;
|
||||
rvrings[0].info.num_descs = VRING_SIZE;
|
||||
rvrings[0].info.align = VRING_ALIGNMENT;
|
||||
rvrings[0].vq = vq[0];
|
||||
|
||||
rvrings[1].io = *io;
|
||||
rvrings[1].info.vaddr = (void *)VRING_RX_ADDRESS;
|
||||
rvrings[1].info.num_descs = VRING_SIZE;
|
||||
rvrings[1].info.align = VRING_ALIGNMENT;
|
||||
rvrings[1].vq = vq[1];
|
||||
|
||||
vdev->role = RPMSG_ROLE;
|
||||
vdev->vrings_num = VRING_COUNT;
|
||||
vdev->func = &dispatch;
|
||||
vdev->vrings_info = &rvrings[0];
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright (c) 2022-2022 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
*
|
||||
* UniProton is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
* http://license.coscl.org.cn/MulanPSL2
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* See the Mulan PSL v2 for more details.
|
||||
* Create: 2022-12-05
|
||||
* Description: openamp backend
|
||||
*/
|
||||
|
||||
#include "openamp/open_amp.h"
|
||||
#include "openamp_common.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern int rpmsg_service_init(void);
|
||||
|
||||
/*
|
||||
* @brief Initialize RPMsg backend
|
||||
*
|
||||
* @param io Shared memory IO region. This is an output parameter providing
|
||||
* a pointer to an actual shared memory IO region structure.
|
||||
* Caller of this function shall pass an address at which the
|
||||
* pointer to the shared memory IO region structure is stored.
|
||||
* @param vdev Pointer to the virtio device initialized by this function.
|
||||
*
|
||||
* @retval 0 Initialization successful
|
||||
* @retval <0 Initialization error reported by OpenAMP
|
||||
*/
|
||||
extern int rpmsg_backend_init(struct metal_io_region **io, struct virtio_device *vdev);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
* Copyright (c) 2022-2022 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
*
|
||||
* UniProton is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
* http://license.coscl.org.cn/MulanPSL2
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* See the Mulan PSL v2 for more details.
|
||||
* Create: 2022-12-05
|
||||
* Description: openamp configuration
|
||||
*/
|
||||
|
||||
#include "rpmsg_backend.h"
|
||||
|
||||
static struct virtio_device vdev;
|
||||
static struct rpmsg_virtio_device rvdev;
|
||||
static struct metal_io_region *io;
|
||||
struct rpmsg_device *g_rdev;
|
||||
struct rpmsg_endpoint g_ept;
|
||||
U32 g_receivedMsg;
|
||||
bool g_openampFlag = false;
|
||||
#define RPMSG_ENDPOINT_NAME "console"
|
||||
|
||||
void rpmsg_service_unbind(struct rpmsg_endpoint *ep)
|
||||
{
|
||||
rpmsg_destroy_ept(ep);
|
||||
}
|
||||
|
||||
int send_message(unsigned char *message, int len)
|
||||
{
|
||||
return rpmsg_send(&g_ept, message, len);
|
||||
}
|
||||
|
||||
char *g_s1 = "Hello, UniProton! \r\n";
|
||||
int rpmsg_endpoint_cb(struct rpmsg_endpoint *ept, void *data, size_t len, uint32_t src, void *priv)
|
||||
{
|
||||
g_openampFlag = true;
|
||||
send_message((void *)g_s1, strlen(g_s1) * sizeof(char));
|
||||
|
||||
return OS_OK;
|
||||
}
|
||||
|
||||
int openamp_init(void)
|
||||
{
|
||||
int32_t err;
|
||||
|
||||
err = rpmsg_backend_init(&io, &vdev);
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
|
||||
err = rpmsg_init_vdev(&rvdev, &vdev, NULL, io, NULL);
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
|
||||
g_rdev = rpmsg_virtio_get_rpmsg_device(&rvdev);
|
||||
|
||||
|
||||
err = rpmsg_create_ept(&g_ept, g_rdev, RPMSG_ENDPOINT_NAME,
|
||||
0xF, RPMSG_ADDR_ANY,
|
||||
rpmsg_endpoint_cb, rpmsg_service_unbind);
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
|
||||
return OS_OK;
|
||||
}
|
||||
|
||||
void openamp_deinit(void)
|
||||
{
|
||||
rpmsg_deinit_vdev(&rvdev);
|
||||
if (io) {
|
||||
free(io);
|
||||
}
|
||||
}
|
||||
|
||||
int rpmsg_service_init(void)
|
||||
{
|
||||
int32_t err;
|
||||
err = openamp_init();
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
|
||||
send_message((void *)&g_receivedMsg, sizeof(U32));
|
||||
|
||||
while (!g_openampFlag);
|
||||
|
||||
return OS_OK;
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Copyright (c) 2009-2022 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
*
|
||||
* UniProton is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
* http://license.coscl.org.cn/MulanPSL2
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PSL v2 for more details.
|
||||
* Create: 2009-12-22
|
||||
* Description: UniProton raspi4 demo
|
||||
*/
|
||||
#include "prt_config.h"
|
||||
#include "prt_task.h"
|
||||
#include "prt_hwi.h"
|
||||
#include "prt_hook.h"
|
||||
#include "prt_exc.h"
|
||||
#include "prt_mem.h"
|
||||
|
||||
extern U32 PRT_Printf(const char *format, ...);
|
||||
@@ -0,0 +1 @@
|
||||
请您参考example目录添加您的源代码,制作您的工程。如有疑问请联系华为对接工程师。
|
||||
@@ -0,0 +1,2 @@
|
||||
set(SRCS start.S cache_asm.S hwi_init.c mmu.c print.c timer.c)
|
||||
add_library(bsp OBJECT ${SRCS})
|
||||
@@ -0,0 +1,103 @@
|
||||
@/*
|
||||
@ * Copyright (c) 2009-2022 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
@ *
|
||||
@ * UniProton is licensed under Mulan PSL v2.
|
||||
@ * You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
@ * You may obtain a copy of Mulan PSL v2 at:
|
||||
@ * http://license.coscl.org.cn/MulanPSL2
|
||||
@ * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
@ * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
@ * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
@ * See the Mulan PSL v2 for more details.
|
||||
@ * Create: 2009-12-22
|
||||
@ * Description: thread scheduler
|
||||
@ */
|
||||
.global os_asm_invalidate_dcache_all
|
||||
.global os_asm_invalidate_icache_all
|
||||
.global os_asm_invalidate_tlb_all
|
||||
|
||||
.type os_asm_dcache_level, "function"
|
||||
os_asm_dcache_level:
|
||||
lsl x12, x0, #1
|
||||
msr csselr_el1, x12
|
||||
isb
|
||||
mrs x6, ccsidr_el1
|
||||
and x2, x6, #7
|
||||
add x2, x2, #4
|
||||
mov x3, #0x3ff
|
||||
and x3, x3, x6, lsr #3
|
||||
clz w5, w3
|
||||
mov x4, #0x7fff
|
||||
and x4, x4, x6, lsr #13
|
||||
|
||||
loop_set:
|
||||
mov x6, x3
|
||||
loop_way:
|
||||
lsl x7, x6, x5
|
||||
orr x9, x12, x7
|
||||
lsl x7, x4, x2
|
||||
orr x9, x9, x7
|
||||
tbz w1, #1, 3f
|
||||
dc csw, x9
|
||||
b 2f
|
||||
3: tbz w1, #0, 1f
|
||||
dc isw, x9
|
||||
b 2f
|
||||
1: dc cisw, x9
|
||||
2: subs x6, x6, #1
|
||||
b.ge loop_way
|
||||
subs x4, x4, #1
|
||||
b.ge loop_set
|
||||
|
||||
ret
|
||||
|
||||
.type os_asm_dcache_all, "function"
|
||||
os_asm_dcache_all:
|
||||
mov x1, x0
|
||||
dsb sy
|
||||
mrs x10, clidr_el1
|
||||
lsr x11, x10, #24
|
||||
and x11, x11, #0x7
|
||||
cbz x11, finished
|
||||
mov x15, x30
|
||||
mov x0, #0
|
||||
|
||||
loop_level:
|
||||
lsl x12, x0, #1
|
||||
add x12, x12, x0
|
||||
lsr x12, x10, x12
|
||||
and x12, x12, #7
|
||||
cmp x12, #2
|
||||
b.lt skip
|
||||
bl os_asm_dcache_level
|
||||
skip:
|
||||
add x0, x0, #1
|
||||
cmp x11, x0
|
||||
b.gt loop_level
|
||||
|
||||
mov x0, #0
|
||||
msr csselr_el1, x0
|
||||
dsb sy
|
||||
isb
|
||||
mov x30, x15
|
||||
|
||||
finished:
|
||||
ret
|
||||
|
||||
.type os_asm_invalidate_dcache_all, "function"
|
||||
os_asm_invalidate_dcache_all:
|
||||
mov x0, #0x1
|
||||
b os_asm_dcache_all
|
||||
|
||||
.type os_asm_invalidate_icache_all, "function"
|
||||
os_asm_invalidate_icache_all:
|
||||
ic ialluis
|
||||
isb sy
|
||||
ret
|
||||
|
||||
.type os_asm_invalidate_tlb_all, "function"
|
||||
os_asm_invalidate_tlb_all:
|
||||
tlbi vmalle1
|
||||
dsb sy
|
||||
isb
|
||||
ret
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright (c) 2009-2022 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
*
|
||||
* UniProton is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
* http://license.coscl.org.cn/MulanPSL2
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PSL v2 for more details.
|
||||
* Create: 2009-12-22
|
||||
* Description: UniProton raspi4 demo
|
||||
*/
|
||||
#ifndef __CACHE_H__
|
||||
#define __CACHE_H__
|
||||
|
||||
#include "prt_buildef.h"
|
||||
#include "prt_typedef.h"
|
||||
#include "prt_module.h"
|
||||
#include "prt_errno.h"
|
||||
|
||||
extern void os_asm_invalidate_dcache_all(void);
|
||||
extern void os_asm_invalidate_icache_all(void);
|
||||
extern void os_asm_invalidate_tlb_all(void);
|
||||
#endif
|
||||
@@ -0,0 +1,356 @@
|
||||
/*
|
||||
* Copyright (c) 2009-2022 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
*
|
||||
* UniProton is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
* http://license.coscl.org.cn/MulanPSL2
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PSL v2 for more details.
|
||||
* Create: 2009-12-22
|
||||
* Description: UniProton raspi4 demo
|
||||
*/
|
||||
#include "securec.h"
|
||||
#include "prt_tick.h"
|
||||
#include "prt_hwi.h"
|
||||
#include "prt_sys.h"
|
||||
#include "prt_task.h"
|
||||
#include "cpu_config.h"
|
||||
|
||||
#if (OS_GIC_VER == 3)
|
||||
enum GicIntState {
|
||||
GIC_DISABLE = 0,
|
||||
GIC_ENABLE = 1
|
||||
};
|
||||
|
||||
enum SicGroupType {
|
||||
SIC_GROUP_G0S = 0,
|
||||
SIC_GROUP_G1NS = 1,
|
||||
SIC_GROUP_G1S = 2,
|
||||
SIC_GROUP_BUTT,
|
||||
};
|
||||
|
||||
union SicrWaker {
|
||||
struct {
|
||||
U32 res0 : 1;
|
||||
U32 sleepReq : 1;
|
||||
U32 isSleep : 1;
|
||||
U32 res1 : 29;
|
||||
} bits;
|
||||
U32 value;
|
||||
};
|
||||
|
||||
union SicrCtrl {
|
||||
struct {
|
||||
U32 enLpis : 1;
|
||||
U32 res2 : 2;
|
||||
U32 rwp : 1;
|
||||
U32 res1 : 20;
|
||||
U32 dpg0 : 1;
|
||||
U32 dpg1ns : 1;
|
||||
U32 dpg1s : 1;
|
||||
U32 res0 : 4;
|
||||
U32 uwp : 1;
|
||||
} bits;
|
||||
U32 value;
|
||||
};
|
||||
|
||||
union HwiIccSreElx {
|
||||
struct {
|
||||
U64 prt : 1;
|
||||
U64 dfb : 1;
|
||||
U64 dib : 1;
|
||||
U64 enable : 1;
|
||||
U64 res : 60;
|
||||
} bits;
|
||||
U64 value;
|
||||
};
|
||||
|
||||
union SicdCtrl {
|
||||
struct {
|
||||
U32 enG0S : 1;
|
||||
U32 enG1Ns : 1;
|
||||
U32 enG1S : 1;
|
||||
U32 res1 : 1;
|
||||
U32 areS : 1;
|
||||
U32 areNs : 1;
|
||||
U32 ds : 1;
|
||||
U32 res0 : 24;
|
||||
U32 rwp : 1;
|
||||
} bits;
|
||||
U32 value;
|
||||
};
|
||||
|
||||
extern void OsGicdWaitCfgWork();
|
||||
|
||||
void OsSicrInit(void)
|
||||
{
|
||||
union SicrWaker sicrWaker;
|
||||
uintptr_t regAddr;
|
||||
U32 intId;
|
||||
|
||||
regAddr = GICR_WAKER_ADDR + OsGetCoreID() * SICR_ADDR_OFFSET_PER_CORE;
|
||||
sicrWaker.value = GIC_REG_READ(regAddr);
|
||||
sicrWaker.bits.sleepReq = 0;
|
||||
GIC_REG_WRITE(regAddr, sicrWaker.value);
|
||||
|
||||
sicrWaker.value = GIC_REG_READ(regAddr);
|
||||
while (sicrWaker.bits.isSleep == 1) {
|
||||
sicrWaker.value = GIC_REG_READ(regAddr);
|
||||
}
|
||||
}
|
||||
|
||||
void OsSicrSetIntGroup(U32 coreId, U64 intId, enum SicGroupType groupId)
|
||||
{
|
||||
uintptr_t group0RegAddr;
|
||||
uintptr_t modRegAddr;
|
||||
U32 group0RegTmp;
|
||||
U32 modRegTmp;
|
||||
|
||||
group0RegAddr = GICR_IGROUPR0_ADDR + OsGetCoreID() * SICR_ADDR_OFFSET_PER_CORE;
|
||||
group0RegTmp = GIC_REG_READ(group0RegAddr);
|
||||
|
||||
if ((groupId == SIC_GROUP_G0S) || (groupId == SIC_GROUP_G1S)) {
|
||||
group0RegTmp &= ~(0x1U << intId);
|
||||
} else {
|
||||
group0RegTmp |= (0x1U << intId);
|
||||
}
|
||||
GIC_REG_WRITE(group0RegAddr, group0RegTmp);
|
||||
|
||||
modRegAddr = GICR_IGRPMODR0_ADDR + OsGetCoreID() * SICR_ADDR_OFFSET_PER_CORE;
|
||||
modRegTmp = GIC_REG_READ(modRegAddr);
|
||||
|
||||
if (groupId == SIC_GROUP_G1S) {
|
||||
modRegTmp |= (0x1U << intId);
|
||||
} else {
|
||||
modRegTmp &= ~(0x1U << intId);
|
||||
}
|
||||
GIC_REG_WRITE(modRegAddr, modRegTmp);
|
||||
}
|
||||
|
||||
U32 OsSiccEnableSre(void)
|
||||
{
|
||||
volatile union HwiIccSreElx iccSre;
|
||||
|
||||
OS_EMBED_ASM("MRS %0, " REG_ALIAS(ICC_SRE_EL1) " \n" : "=&r"(iccSre));
|
||||
iccSre.bits.prt = 1;
|
||||
iccSre.bits.dfb = 1;
|
||||
iccSre.bits.dib = 1;
|
||||
OS_EMBED_ASM("MSR " REG_ALIAS(ICC_SRE_EL1) ", %0 \n" : : "r"(iccSre));
|
||||
OS_EMBED_ASM("DSB SY");
|
||||
OS_EMBED_ASM("ISB");
|
||||
|
||||
OS_EMBED_ASM("MRS %0, " REG_ALIAS(ICC_SRE_EL1) " \n" : "=&r"(iccSre.value));
|
||||
|
||||
if (iccSre.bits.prt != 1) {
|
||||
return OS_FAIL;
|
||||
}
|
||||
|
||||
return OS_OK;
|
||||
}
|
||||
|
||||
void OsSiccCfgIntPreempt(void)
|
||||
{
|
||||
U64 tmp = 0;
|
||||
|
||||
OS_EMBED_ASM("MRS %0, " REG_ALIAS(ICC_BPR1_EL1) " \n" : "=&r"(tmp) : : "memory");
|
||||
tmp &= ~(GROUP_MAX_BPR);
|
||||
tmp |= GROUP1_BP;
|
||||
OS_EMBED_ASM("MSR " REG_ALIAS(ICC_BPR1_EL1) ", %0 \n" : : "r"(tmp) : "memory");
|
||||
}
|
||||
|
||||
void OsSiccEnableGroup1(void)
|
||||
{
|
||||
U64 tmp = 0;
|
||||
|
||||
OS_EMBED_ASM("MRS %0, " REG_ALIAS(ICC_IGRPEN1_EL1) " \n" : "=&r"(tmp) : : "memory");
|
||||
tmp |= 0x01U;
|
||||
OS_EMBED_ASM("MSR " REG_ALIAS(ICC_IGRPEN1_EL1) ", %0 \n" : : "r"(tmp) : "memory");
|
||||
}
|
||||
|
||||
void OsSiccCfgPriorityMask(void)
|
||||
{
|
||||
U64 tmp = 0;
|
||||
|
||||
OS_EMBED_ASM("MRS %0, " REG_ALIAS(ICC_PMR_EL1) " \n" : "=&r"(tmp) : : "memory");
|
||||
tmp |= PRIO_MASK_LEVEL;
|
||||
OS_EMBED_ASM("MSR " REG_ALIAS(ICC_PMR_EL1) ", %0 \n" : : "r"(tmp) : "memory");
|
||||
}
|
||||
|
||||
U32 OsSiccInit(void)
|
||||
{
|
||||
U32 ret;
|
||||
|
||||
ret = OsSiccEnableSre();
|
||||
if (ret != OS_OK) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
OsSiccCfgIntPreempt();
|
||||
|
||||
OsSiccEnableGroup1();
|
||||
|
||||
OsSiccCfgPriorityMask();
|
||||
|
||||
return OS_OK;
|
||||
}
|
||||
|
||||
void OsSicdSetIntGroup(U32 intId, enum SicGroupType groupId)
|
||||
{
|
||||
U64 group0RegAddr;
|
||||
U64 modRegAddr;
|
||||
U32 group0RegTmp;
|
||||
U32 modRegTmp;
|
||||
U32 sicdM;
|
||||
U32 bitOffset;
|
||||
|
||||
sicdM = (intId - MIN_GIC_SPI_NUM) / SICD_IGROUP_INT_NUM;
|
||||
group0RegAddr = GICD_IGROUPN_ADDR + (SICD_REG_SIZE * sicdM);
|
||||
modRegAddr = GICD_IGRPMODRN_ADDR + (SICD_REG_SIZE * sicdM);
|
||||
bitOffset = (intId - MIN_GIC_SPI_NUM) % SICD_IGROUP_INT_NUM;
|
||||
|
||||
group0RegTmp = GIC_REG_READ(group0RegAddr);
|
||||
if ((groupId == SIC_GROUP_G0S) || (groupId == SIC_GROUP_G1S)) {
|
||||
group0RegTmp &= ~(0x1U << bitOffset);
|
||||
} else {
|
||||
group0RegTmp |= (0x1U << bitOffset);
|
||||
}
|
||||
GIC_REG_WRITE(group0RegAddr, group0RegTmp);
|
||||
|
||||
modRegTmp = GIC_REG_READ(modRegAddr);
|
||||
if (groupId == SIC_GROUP_G1S) {
|
||||
modRegTmp |= (0x1U << bitOffset);
|
||||
} else {
|
||||
modRegTmp &= ~(0x1U << bitOffset);
|
||||
}
|
||||
GIC_REG_WRITE(modRegAddr, modRegTmp);
|
||||
}
|
||||
|
||||
void OsSicSetGroup(U32 intId, enum SicGroupType groupId)
|
||||
{
|
||||
U32 coreId = OsGetCoreID();
|
||||
enum GicIntState state;
|
||||
|
||||
if (intId < MIN_GIC_SPI_NUM) {
|
||||
state = OsGicrGetIntState(coreId, intId);
|
||||
OsGicrDisableInt(coreId, intId);
|
||||
OsSicrSetIntGroup(coreId, intId, groupId);
|
||||
if (state == GIC_ENABLE) {
|
||||
OsGicrEnableInt(coreId, intId);
|
||||
}
|
||||
} else {
|
||||
state = OsGicdGetIntState(intId);
|
||||
OsGicdDisableInt(intId);
|
||||
OsSicdSetIntGroup(intId, groupId);
|
||||
if (state == GIC_ENABLE) {
|
||||
OsGicdEnableInt(intId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
U32 OsSicInitLocal(void)
|
||||
{
|
||||
U32 ret;
|
||||
U32 intId;
|
||||
|
||||
OsSicrInit();
|
||||
|
||||
ret = OsSiccInit();
|
||||
if (ret != OS_OK) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
for (intId = 0; intId < MIN_GIC_SPI_NUM; ++intId) {
|
||||
OsSicSetGroup(intId, SIC_GROUP_G1NS);
|
||||
}
|
||||
|
||||
return OS_OK;
|
||||
}
|
||||
|
||||
void OsSicdInit(void)
|
||||
{
|
||||
union SicdCtrl sicdCtrl;
|
||||
|
||||
sicdCtrl.value = GIC_REG_READ(GICD_CTLR_S_ADDR);
|
||||
|
||||
if ((sicdCtrl.bits.enG0S == 1) || (sicdCtrl.bits.enG1Ns == 1) || (sicdCtrl.bits.enG1S == 1)) {
|
||||
return;
|
||||
}
|
||||
|
||||
sicdCtrl.bits.ds = 0;
|
||||
sicdCtrl.bits.areNs = 1;
|
||||
sicdCtrl.bits.areS = 1;
|
||||
sicdCtrl.bits.enG1Ns = 1;
|
||||
GIC_REG_WRITE(GICD_CTLR_S_ADDR, sicdCtrl.value);
|
||||
|
||||
OsGicdWaitCfgWork();
|
||||
}
|
||||
|
||||
void OsSicInitGlobal(void)
|
||||
{
|
||||
U32 intId;
|
||||
|
||||
OsSicdInit();
|
||||
|
||||
for (intId = MIN_GIC_SPI_NUM; intId < MAX_INT_NUM; ++intId) {
|
||||
OsSicSetGroup(intId, SIC_GROUP_G1NS);
|
||||
}
|
||||
}
|
||||
#elif (OS_GIC_VER == 2)
|
||||
int IsrRegister(U32 intNo, U32 pri)
|
||||
{
|
||||
U32 bitn, reg, shift;
|
||||
U32 *addr;
|
||||
|
||||
bitn = intNo / 32U;
|
||||
addr = (U32 *)(GICD_ISENABLERn + 4U * bitn);
|
||||
reg = *addr;
|
||||
*addr = (reg | (0x1U << (intNo % 32U)));
|
||||
|
||||
bitn = intNo / 4U;
|
||||
addr = (U32 *)(GICD_IPRIORITYn + 4U * bitn);
|
||||
shift = (intNo % 4U) * 8U;
|
||||
reg = (*addr) & ~(0xFFU << shift);
|
||||
*addr = (reg | pri << shift);
|
||||
}
|
||||
|
||||
void OsGicInitCpuInterface(void)
|
||||
{
|
||||
int i;
|
||||
U32 val;
|
||||
|
||||
GIC_REG_WRITE(0xFFFFFFFF, GICD_ICACTIVERn);
|
||||
GIC_REG_WRITE(0xFFFF0000, GICD_ICENABLERn);
|
||||
GIC_REG_WRITE(0x0000FFFF, GICD_ISENABLERn);
|
||||
|
||||
for (i = 0; i < 32; i += 4) {
|
||||
GIC_REG_WRITE(0xA0A0A0A0, GICD_IPRIORITYn + i);
|
||||
}
|
||||
|
||||
GIC_REG_WRITE(0xF0, GICC_PMR);
|
||||
val = GIC_REG_READ(GICC_CTLR);
|
||||
val &= ~GICC_CTLR_BYPASS_MASK;
|
||||
val |= GICC_CTLR_ENABLE_MASK;
|
||||
GIC_REG_WRITE(val, GICC_CTLR);
|
||||
}
|
||||
#endif
|
||||
U32 OsHwiInit(void)
|
||||
{
|
||||
#if (OS_GIC_VER == 3)
|
||||
U32 ret;
|
||||
|
||||
ret = OsSicInitLocal();
|
||||
if (ret != OS_OK) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
if(OsGetCoreID() == 0) {
|
||||
OsSicInitGlobal();
|
||||
}
|
||||
#elif (OS_GIC_VER == 2)
|
||||
OsGicInitCpuInterface();
|
||||
#endif
|
||||
return OS_OK;
|
||||
}
|
||||
@@ -0,0 +1,346 @@
|
||||
/*
|
||||
* Copyright (c) 2009-2022 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
*
|
||||
* UniProton is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
* http://license.coscl.org.cn/MulanPSL2
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PSL v2 for more details.
|
||||
* Create: 2009-12-22
|
||||
* Description: UniProton raspi4 demo
|
||||
*/
|
||||
#include "prt_buildef.h"
|
||||
#include "prt_typedef.h"
|
||||
#include "prt_module.h"
|
||||
#include "prt_errno.h"
|
||||
#include "mmu.h"
|
||||
#include "cache_asm.h"
|
||||
#include "prt_sys.h"
|
||||
#include "prt_task.h"
|
||||
#include "cpu_config.h"
|
||||
|
||||
extern U64 g_mmu_page_begin;
|
||||
extern U64 g_mmu_page_end;
|
||||
|
||||
static mmu_mmap_region_s g_mem_map_info[] = {
|
||||
{
|
||||
.virt = MMU_OPENAMP_ADDR,
|
||||
.phys = MMU_OPENAMP_ADDR,
|
||||
.size = 0x30000,
|
||||
.max_level = 0x2,
|
||||
.attrs = MMU_ATTR_DEVICE_NGNRNE | MMU_ACCESS_RWX,
|
||||
}, {
|
||||
.virt = MMU_IMAGE_ADDR,
|
||||
.phys = MMU_IMAGE_ADDR,
|
||||
.size = 0x1000000,
|
||||
.max_level = 0x2,
|
||||
.attrs = MMU_ATTR_CACHE_SHARE | MMU_ACCESS_RWX,
|
||||
}, {
|
||||
.virt = MMU_GIC_ADDR,
|
||||
.phys = MMU_GIC_ADDR,
|
||||
.size = 0x1000000,
|
||||
.max_level = 0x2,
|
||||
.attrs = MMU_ATTR_DEVICE_NGNRNE | MMU_ACCESS_RWX,
|
||||
}, {
|
||||
.virt = MMU_UART_ADDR,
|
||||
.phys = MMU_UART_ADDR,
|
||||
.size = 0x2000,
|
||||
.max_level = 0x2,
|
||||
.attrs = MMU_ATTR_DEVICE_NGNRNE | MMU_ACCESS_RWX,
|
||||
}
|
||||
};
|
||||
|
||||
static mmu_ctrl_s g_mmu_ctrl = { 0 };
|
||||
|
||||
static U64 mmu_get_tcr(U32 *pips, U32 *pva_bits)
|
||||
{
|
||||
U64 max_addr = 0;
|
||||
U64 ips, va_bits;
|
||||
U64 tcr;
|
||||
U32 i;
|
||||
U32 mmu_table_num = sizeof(g_mem_map_info) / sizeof(mmu_mmap_region_s);
|
||||
|
||||
for (i = 0; i < mmu_table_num; ++i) {
|
||||
max_addr = MAX(max_addr, g_mem_map_info[i].virt + g_mem_map_info[i].size);
|
||||
}
|
||||
|
||||
if (max_addr > (1ULL << MMU_BITS_44)) {
|
||||
ips = MMU_PHY_ADDR_LEVEL_5;
|
||||
va_bits = MMU_BITS_48;
|
||||
} else if (max_addr > (1ULL << MMU_BITS_42)) {
|
||||
ips = MMU_PHY_ADDR_LEVEL_4;
|
||||
va_bits = MMU_BITS_44;
|
||||
} else if (max_addr > (1ULL << MMU_BITS_40)) {
|
||||
ips = MMU_PHY_ADDR_LEVEL_3;
|
||||
va_bits = MMU_BITS_42;
|
||||
} else if (max_addr > (1ULL << MMU_BITS_36)) {
|
||||
ips = MMU_PHY_ADDR_LEVEL_2;
|
||||
va_bits = MMU_BITS_40;
|
||||
} else if (max_addr > (1ULL << MMU_BITS_32)) {
|
||||
ips = MMU_PHY_ADDR_LEVEL_1;
|
||||
va_bits = MMU_BITS_36;
|
||||
} else {
|
||||
ips = MMU_PHY_ADDR_LEVEL_0;
|
||||
va_bits = MMU_BITS_32;
|
||||
}
|
||||
|
||||
tcr = TCR_EL1_RSVD | TCR_IPS(ips);
|
||||
|
||||
if (g_mmu_ctrl.granule == MMU_GRANULE_4K) {
|
||||
tcr |= TCR_TG0_4K | TCR_SHARED_INNER | TCR_ORGN_WBWA | TCR_IRGN_WBWA;
|
||||
} else {
|
||||
tcr |= TCR_TG0_64K | TCR_SHARED_INNER | TCR_ORGN_WBWA | TCR_IRGN_WBWA;
|
||||
}
|
||||
|
||||
tcr |= TCR_T0SZ(va_bits);
|
||||
|
||||
if (pips != NULL) {
|
||||
*pips = ips;
|
||||
}
|
||||
|
||||
if (pva_bits != NULL) {
|
||||
*pva_bits = va_bits;
|
||||
}
|
||||
|
||||
return tcr;
|
||||
}
|
||||
|
||||
static U32 mmu_get_pte_type(U64 const *pte)
|
||||
{
|
||||
return (U32)(*pte & PTE_TYPE_MASK);
|
||||
}
|
||||
|
||||
static U32 mmu_level2shift(U32 level)
|
||||
{
|
||||
if (g_mmu_ctrl.granule == MMU_GRANULE_4K) {
|
||||
return (U32)(MMU_BITS_12 + MMU_BITS_9 * (MMU_LEVEL_3 - level));
|
||||
} else {
|
||||
return (U32)(MMU_BITS_16 + MMU_BITS_13 * (MMU_LEVEL_3 - level));
|
||||
}
|
||||
}
|
||||
|
||||
static U64 *mmu_find_pte(U64 addr, U32 level)
|
||||
{
|
||||
U64 *pte = NULL;
|
||||
U64 idx;
|
||||
U32 i;
|
||||
|
||||
if (level < g_mmu_ctrl.start_level) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pte = (U64 *)g_mmu_ctrl.tlb_addr;
|
||||
|
||||
for (i = g_mmu_ctrl.start_level; i < MMU_LEVEL_MAX; ++i) {
|
||||
if (g_mmu_ctrl.granule == MMU_GRANULE_4K) {
|
||||
idx = (addr >> mmu_level2shift(i)) & 0x1FF;
|
||||
} else {
|
||||
idx = (addr >> mmu_level2shift(i)) & 0x1FFF;
|
||||
}
|
||||
|
||||
pte += idx;
|
||||
|
||||
if (i == level) {
|
||||
return pte;
|
||||
}
|
||||
|
||||
if (mmu_get_pte_type(pte) != PTE_TYPE_TABLE) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (g_mmu_ctrl.granule == MMU_GRANULE_4K) {
|
||||
pte = (U64 *)(*pte & PTE_TABLE_ADDR_MARK_4K);
|
||||
} else {
|
||||
pte = (U64 *)(*pte & PTE_TABLE_ADDR_MARK_64K);
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static U64 *mmu_create_table(void)
|
||||
{
|
||||
U32 pt_len;
|
||||
U64 *new_table = (U64 *)g_mmu_ctrl.tlb_fillptr;
|
||||
|
||||
if (g_mmu_ctrl.granule == MMU_GRANULE_4K) {
|
||||
pt_len = MAX_PTE_ENTRIES_4K * sizeof(U64);
|
||||
} else {
|
||||
pt_len = MAX_PTE_ENTRIES_64K * sizeof(U64);
|
||||
}
|
||||
|
||||
g_mmu_ctrl.tlb_fillptr += pt_len;
|
||||
|
||||
if (g_mmu_ctrl.tlb_fillptr - g_mmu_ctrl.tlb_addr > g_mmu_ctrl.tlb_size) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
(void)memset_s((void *)new_table, MAX_PTE_ENTRIES_64K * sizeof(U64), 0, pt_len);
|
||||
|
||||
return new_table;
|
||||
}
|
||||
|
||||
static void mmu_set_pte_table(U64 *pte, U64 *table)
|
||||
{
|
||||
*pte = PTE_TYPE_TABLE | (U64)table;
|
||||
}
|
||||
|
||||
static S32 mmu_add_map_pte_process(mmu_mmap_region_s const *map, U64 *pte, U64 phys, U32 level)
|
||||
{
|
||||
U64 *new_table = NULL;
|
||||
|
||||
if (level < map->max_level) {
|
||||
if (mmu_get_pte_type(pte) == PTE_TYPE_FAULT) {
|
||||
new_table = mmu_create_table();
|
||||
if (new_table == NULL) {
|
||||
return -1;
|
||||
}
|
||||
mmu_set_pte_table(pte, new_table);
|
||||
}
|
||||
} else if (level == MMU_LEVEL_3) {
|
||||
*pte = phys | map->attrs | PTE_TYPE_PAGE;
|
||||
} else {
|
||||
*pte = phys | map->attrs | PTE_TYPE_BLOCK;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static S32 mmu_add_map(mmu_mmap_region_s const *map)
|
||||
{
|
||||
U64 virt = map->virt;
|
||||
U64 phys = map->phys;
|
||||
U64 max_level = map->max_level;
|
||||
U64 start_level = g_mmu_ctrl.start_level;
|
||||
U64 block_size = 0;
|
||||
U64 map_size = 0;
|
||||
U32 level;
|
||||
U64 *pte = NULL;
|
||||
S32 ret;
|
||||
|
||||
if (map->max_level <= start_level) {
|
||||
return -2;
|
||||
}
|
||||
|
||||
while (map_size < map->size) {
|
||||
for (level = start_level; level <= max_level; ++level) {
|
||||
pte = mmu_find_pte(virt, level);
|
||||
if (pte == NULL) {
|
||||
return -3;
|
||||
}
|
||||
|
||||
ret = mmu_add_map_pte_process(map, pte, phys, level);
|
||||
if (ret) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (level != start_level) {
|
||||
block_size = 1ULL << mmu_level2shift(level);
|
||||
}
|
||||
}
|
||||
|
||||
virt += block_size;
|
||||
phys += block_size;
|
||||
map_size += block_size;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline void mmu_set_ttbr_tcr_mair(U64 table, U64 tcr, U64 attr)
|
||||
{
|
||||
OS_EMBED_ASM("dsb sy");
|
||||
|
||||
OS_EMBED_ASM("msr ttbr0_el1, %0" : : "r" (table) : "memory");
|
||||
OS_EMBED_ASM("msr ttbr1_el1, %0" : : "r" (table) : "memory");
|
||||
OS_EMBED_ASM("msr tcr_el1, %0" : : "r" (tcr) : "memory");
|
||||
OS_EMBED_ASM("msr mair_el1, %0" : : "r" (attr) : "memory");
|
||||
|
||||
OS_EMBED_ASM("isb");
|
||||
}
|
||||
|
||||
static U32 mmu_setup_pgtables(mmu_mmap_region_s *mem_map, U32 mem_region_num, U64 tlb_addr, U64 tlb_len, U32 granule)
|
||||
{
|
||||
U32 i;
|
||||
U32 ret;
|
||||
U64 tcr;
|
||||
U64 *new_table = NULL;
|
||||
|
||||
g_mmu_ctrl.tlb_addr = tlb_addr;
|
||||
g_mmu_ctrl.tlb_size = tlb_len;
|
||||
g_mmu_ctrl.tlb_fillptr = tlb_addr;
|
||||
g_mmu_ctrl.granule = granule;
|
||||
g_mmu_ctrl.start_level = 0;
|
||||
|
||||
tcr = mmu_get_tcr(NULL, &g_mmu_ctrl.va_bits);
|
||||
|
||||
if (g_mmu_ctrl.granule == MMU_GRANULE_4K) {
|
||||
if (g_mmu_ctrl.va_bits < MMU_BITS_39) {
|
||||
g_mmu_ctrl.start_level = MMU_LEVEL_1;
|
||||
} else {
|
||||
g_mmu_ctrl.start_level = MMU_LEVEL_0;
|
||||
}
|
||||
} else {
|
||||
if (g_mmu_ctrl.va_bits <= MMU_BITS_36) {
|
||||
g_mmu_ctrl.start_level = MMU_LEVEL_2;
|
||||
} else {
|
||||
g_mmu_ctrl.start_level = MMU_LEVEL_1;
|
||||
return 3;
|
||||
}
|
||||
}
|
||||
|
||||
new_table = mmu_create_table();
|
||||
if (new_table == NULL) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
for (i = 0; i < mem_region_num; ++i) {
|
||||
ret = mmu_add_map(&mem_map[i]);
|
||||
if (ret) {
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
mmu_set_ttbr_tcr_mair(g_mmu_ctrl.tlb_addr, tcr, MEMORY_ATTRIBUTES);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static S32 mmu_setup(void)
|
||||
{
|
||||
S32 ret;
|
||||
U64 page_addr;
|
||||
U64 page_len;
|
||||
|
||||
page_addr = (U64)&g_mmu_page_begin;
|
||||
page_len = (U64)&g_mmu_page_end - (U64)&g_mmu_page_begin;
|
||||
|
||||
ret = mmu_setup_pgtables(g_mem_map_info, (sizeof(g_mem_map_info) / sizeof(mmu_mmap_region_s)),
|
||||
page_addr, page_len, MMU_GRANULE_4K);
|
||||
if (ret) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
S32 mmu_init(void)
|
||||
{
|
||||
S32 ret;
|
||||
|
||||
ret = mmu_setup();
|
||||
if (ret) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
os_asm_invalidate_dcache_all();
|
||||
os_asm_invalidate_icache_all();
|
||||
os_asm_invalidate_tlb_all();
|
||||
|
||||
set_sctlr(get_sctlr() | CR_C | CR_M | CR_I);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,220 @@
|
||||
/*
|
||||
* Copyright (c) 2009-2022 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
*
|
||||
* UniProton is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
* http://license.coscl.org.cn/MulanPSL2
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PSL v2 for more details.
|
||||
* Create: 2009-12-22
|
||||
* Description: UniProton raspi4 demo
|
||||
*/
|
||||
#ifndef __MMU_H__
|
||||
#define __MMU_H__
|
||||
|
||||
#include "prt_typedef.h"
|
||||
|
||||
#define CACHE_POS 0x2
|
||||
#define CACHE_ENABLE 0x4
|
||||
#define CACHE_MASK 0x7
|
||||
|
||||
#define MT_DEVICE_NGNRNE 0
|
||||
#define MT_DEVICE_NGNRE 1
|
||||
#define MT_DEVICE_GRE 2
|
||||
#define MT_NORMAL_NC 3
|
||||
#define MT_NORMAL 4
|
||||
|
||||
#define MEMORY_ATTRIBUTES ((0x00 << (MT_DEVICE_NGNRNE * 8)) | \
|
||||
(0x04 << (MT_DEVICE_NGNRE * 8)) | \
|
||||
(0x0c << (MT_DEVICE_GRE * 8)) | \
|
||||
(0x44 << (MT_NORMAL_NC * 8)) | \
|
||||
(0xffUL << (MT_NORMAL * 8)))
|
||||
|
||||
#define PTE_TYPE_FAULT (0 << 0)
|
||||
#define PTE_TYPE_BLOCK (1 << 0)
|
||||
#define PTE_TYPE_VALID (1 << 0)
|
||||
#define PTE_TYPE_MASK (3 << 0)
|
||||
#define PTE_TYPE_PAGE (3 << 0)
|
||||
#define PTE_TYPE_TABLE (3 << 0)
|
||||
|
||||
#define PTE_TABLE_PXN (1UL << 59)
|
||||
#define PTE_TABLE_XN (1UL << 60)
|
||||
#define PTE_TABLE_AP (1UL << 61)
|
||||
#define PTE_TABLE_NS (1UL << 63)
|
||||
|
||||
#define PTE_BLOCK_MEMTYPE(x) ((x) << 2)
|
||||
#define PTE_BLOCK_NS (1 << 5)
|
||||
#define PTE_BLOCK_AP_R (2 << 6)
|
||||
#define PTE_BLOCK_AP_RW (0 << 6)
|
||||
#define PTE_BLOCK_NON_SHARE (0 << 8)
|
||||
#define PTE_BLOCK_OUTER_SHARE (2 << 8)
|
||||
#define PTE_BLOCK_INNER_SHARE (3 << 8)
|
||||
#define PTE_BLOCK_AF (1 << 10)
|
||||
#define PTE_BLOCK_NG (1 << 11)
|
||||
#define PTE_BLOCK_PXN (1UL << 53)
|
||||
#define PTE_BLOCK_UXN (1UL << 54)
|
||||
|
||||
#define PMD_ATTRINDX(t) ((t) << 2)
|
||||
#define PMD_ATTRINDX_MASK (7 << 2)
|
||||
#define PMD_ATTRMASK (PTE_BLOCK_PXN | \
|
||||
PTE_BLOCK_UXN | \
|
||||
PMD_ATTRINDX_MASK | \
|
||||
PTE_TYPE_VALID)
|
||||
|
||||
#define TCR_IPS(x) ((x) << 32)
|
||||
#define TCR_T0SZ(x) ((64 - (x)) << 0)
|
||||
#define TCR_IRGN_NC (0 << 8)
|
||||
#define TCR_IRGN_WBWA (1 << 8)
|
||||
#define TCR_IRGN_WT (2 << 8)
|
||||
#define TCR_IRGN_WBNWA (3 << 8)
|
||||
#define TCR_IRGN_MASK (3 << 8)
|
||||
#define TCR_ORGN_NC (0 << 10)
|
||||
#define TCR_ORGN_WBWA (1 << 10)
|
||||
#define TCR_ORGN_WT (2 << 10)
|
||||
#define TCR_ORGN_WBNWA (3 << 10)
|
||||
#define TCR_ORGN_MASK (3 << 10)
|
||||
#define TCR_SHARED_NON (0 << 12)
|
||||
#define TCR_SHARED_OUTER (2 << 12)
|
||||
#define TCR_SHARED_INNER (3 << 12)
|
||||
#define TCR_TG0_4K (0 << 14)
|
||||
#define TCR_TG0_64K (1 << 14)
|
||||
#define TCR_TG0_16K (2 << 14)
|
||||
#define TCR_EPD1_DISABLE (1 << 23)
|
||||
|
||||
#define TCR_EL1_RSVD (1UL << 31)
|
||||
#define TCR_EL2_RSVD (1UL << 31 | 1UL << 23)
|
||||
#define TCR_EL3_RSVD (1UL << 31 | 1UL << 23)
|
||||
|
||||
#define MAX_PTE_ENTRIES_4K 512
|
||||
#define MAX_PTE_ENTRIES_64K 8192
|
||||
|
||||
#define PTE_TABLE_ADDR_MARK_4K 0x0000FFFFFFFFF000ULL
|
||||
#define PTE_TABLE_ADDR_MARK_64K 0x0000FFFFFFFF0000ULL
|
||||
|
||||
|
||||
#define MMU_ATTR_DEVICE_NGNRNE (PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE))
|
||||
#define MMU_ATTR_DEVICE (PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRE))
|
||||
#define MMU_ATTR_UNCACHE_UNSHARE (PTE_BLOCK_MEMTYPE(MT_NORMAL_NC) | PTE_BLOCK_NON_SHARE)
|
||||
#define MMU_ATTR_UNCACHE_SHARE (PTE_BLOCK_MEMTYPE(MT_NORMAL_NC) | PTE_BLOCK_INNER_SHARE)
|
||||
#define MMU_ATTR_CACHE_UNSHARE (PTE_BLOCK_MEMTYPE(MT_NORMAL) | PTE_BLOCK_NON_SHARE)
|
||||
#define MMU_ATTR_CACHE_SHARE (PTE_BLOCK_MEMTYPE(MT_NORMAL) | PTE_BLOCK_INNER_SHARE)
|
||||
#define MMU_ATTR_MASK 0X31CULL
|
||||
|
||||
#define MMU_ACCESS_NONE (PTE_BLOCK_AP_RW)
|
||||
#define MMU_ACCESS_R (PTE_BLOCK_AF | PTE_BLOCK_UXN | PTE_BLOCK_PXN | PTE_BLOCK_AP_R)
|
||||
#define MMU_ACCESS_RW (PTE_BLOCK_AF | PTE_BLOCK_UXN | PTE_BLOCK_PXN | PTE_BLOCK_AP_RW)
|
||||
#define MMU_ACCESS_RWX (PTE_BLOCK_AF | PTE_BLOCK_AP_RW)
|
||||
#define MMU_ACCESS_RX (PTE_BLOCK_AF | PTE_BLOCK_AP_R)
|
||||
#define MMU_ACCESS_MASK 0X600000000004C0ULL
|
||||
|
||||
#define MMU_GRANULE_4K 0
|
||||
#define MMU_GRANULE_64K 1
|
||||
|
||||
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
|
||||
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
|
||||
|
||||
#define CR_M (1 << 0)
|
||||
#define CR_A (1 << 1)
|
||||
#define CR_C (1 << 2)
|
||||
#define CR_SA (1 << 3)
|
||||
#define CR_I (1 << 12)
|
||||
#define CR_WXN (1 << 19)
|
||||
#define CR_EE (1 << 25)
|
||||
|
||||
#define SPSR_EL_END_LE (0 << 9)
|
||||
#define SPSR_EL_DEBUG_MASK (1 << 9)
|
||||
#define SPSR_EL_ASYN_MASK (1 << 8)
|
||||
#define SPSR_EL_SERR_MASK (1 << 8)
|
||||
#define SPSR_EL_IRQ_MASK (1 << 7)
|
||||
#define SPSR_EL_FIQ_MASK (1 << 6)
|
||||
#define SPSR_EL_T_A32 (0 << 5)
|
||||
#define SPSR_EL_M_AARCH64 (0 << 4)
|
||||
#define SPSR_EL_M_AARCH32 (1 << 4)
|
||||
#define SPSR_EL_M_SVC (0x3)
|
||||
#define SPSR_EL_M_HYP (0xa)
|
||||
#define SPSR_EL_M_EL1H (5)
|
||||
#define SPSR_EL_M_EL2H (9)
|
||||
|
||||
#define CPUECTLR_EL1_L1PCTL_MASK (7 << 13)
|
||||
#define CPUECTLR_EL1_L3PCTL_MASK (7 << 10)
|
||||
|
||||
typedef enum {
|
||||
MMU_LEVEL_0 = 0,
|
||||
MMU_LEVEL_1,
|
||||
MMU_LEVEL_2,
|
||||
MMU_LEVEL_3,
|
||||
MMU_LEVEL_MAX
|
||||
} mmu_level_e;
|
||||
|
||||
typedef enum {
|
||||
MMU_PHY_ADDR_LEVEL_0 = 0,
|
||||
MMU_PHY_ADDR_LEVEL_1,
|
||||
MMU_PHY_ADDR_LEVEL_2,
|
||||
MMU_PHY_ADDR_LEVEL_3,
|
||||
MMU_PHY_ADDR_LEVEL_4,
|
||||
MMU_PHY_ADDR_LEVEL_5
|
||||
} mmu_physical_addr_size_e;
|
||||
|
||||
typedef enum {
|
||||
MMU_BITS_9 = 9,
|
||||
MMU_BITS_12 = 12,
|
||||
MMU_BITS_13 = 13,
|
||||
MMU_BITS_16 = 16,
|
||||
MMU_BITS_32 = 32,
|
||||
MMU_BITS_36 = 36,
|
||||
MMU_BITS_39 = 39,
|
||||
MMU_BITS_40 = 40,
|
||||
MMU_BITS_42 = 42,
|
||||
MMU_BITS_44 = 44,
|
||||
MMU_BITS_48 = 48,
|
||||
} mmu_bits_e;
|
||||
|
||||
typedef struct {
|
||||
U64 tlb_addr;
|
||||
U64 tlb_size;
|
||||
U64 tlb_fillptr;
|
||||
U32 granule;
|
||||
U32 start_level;
|
||||
U32 va_bits;
|
||||
} mmu_ctrl_s;
|
||||
|
||||
typedef struct {
|
||||
U64 virt;
|
||||
U64 phys;
|
||||
U64 size;
|
||||
U64 max_level;
|
||||
U64 attrs;
|
||||
} mmu_mmap_region_s;
|
||||
|
||||
static inline unsigned long get_sctlr(void)
|
||||
{
|
||||
unsigned long val;
|
||||
|
||||
__asm__ __volatile__("mrs %0, sctlr_el1" : "=r" (val) : : "cc");
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
static inline unsigned long get_cpuectr(void)
|
||||
{
|
||||
unsigned long val;
|
||||
|
||||
__asm__ __volatile__("mrs %0, S3_1_C15_C2_1" : "=r" (val) : : "cc");
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
static inline void set_sctlr(unsigned long val)
|
||||
{
|
||||
__asm__ __volatile__("dsb sy");
|
||||
__asm__ __volatile__("msr sctlr_el1, %0" : : "r" (val) : "cc");
|
||||
__asm__ __volatile__("dsb sy");
|
||||
__asm__ __volatile__("isb");
|
||||
}
|
||||
|
||||
extern S32 mmu_init(void);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Copyright (c) 2009-2022 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
*
|
||||
* UniProton is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
* http://license.coscl.org.cn/MulanPSL2
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PSL v2 for more details.
|
||||
* Create: 2009-12-22
|
||||
* Description: UniProton raspi4 demo
|
||||
*/
|
||||
#include <stdarg.h>
|
||||
#include "prt_typedef.h"
|
||||
#include "cpu_config.h"
|
||||
#include "securec.h"
|
||||
|
||||
typedef U32 (*PrintFunc)(const char *format, va_list vaList);
|
||||
#define OS_MAX_SHOW_LEN 0x200
|
||||
|
||||
void uart_poll_send(unsigned char ch)
|
||||
{
|
||||
volatile int time = 100000;
|
||||
*(unsigned int *)UART_BASE_ADDR = ch;
|
||||
while (time--);
|
||||
}
|
||||
|
||||
void TestPutc(unsigned char ch)
|
||||
{
|
||||
uart_poll_send(ch);
|
||||
if (ch == '\n') {
|
||||
uart_poll_send('\r');
|
||||
}
|
||||
}
|
||||
|
||||
int TestPrintf(const char *format, va_list vaList)
|
||||
{
|
||||
int len;
|
||||
char buff[OS_MAX_SHOW_LEN] = {0};
|
||||
char *str = buff;
|
||||
|
||||
len = vsnprintf_s(buff, OS_MAX_SHOW_LEN, OS_MAX_SHOW_LEN, format, vaList);
|
||||
if (len == -1) {
|
||||
return len;
|
||||
}
|
||||
|
||||
while (*str != '\0') {
|
||||
TestPutc(*str);
|
||||
str++;
|
||||
}
|
||||
|
||||
return OS_OK;
|
||||
}
|
||||
|
||||
U32 PRT_Printf(const char *format, ...)
|
||||
{
|
||||
va_list vaList;
|
||||
S32 count;
|
||||
|
||||
va_start(vaList, format);
|
||||
count = TestPrintf(format, vaList);
|
||||
va_end(vaList);
|
||||
|
||||
return count;
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* Copyright (c) 2009-2022 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
*
|
||||
* UniProton is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
* http://license.coscl.org.cn/MulanPSL2
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PSL v2 for more details.
|
||||
* Create: 2009-12-22
|
||||
* Description: UniProton raspi4 demo
|
||||
*/
|
||||
#ifndef CPU_CONFIG_H
|
||||
#define CPU_CONFIG_H
|
||||
|
||||
#include "cache_asm.h"
|
||||
|
||||
#define MMU_IMAGE_ADDR 0x7A000000ULL
|
||||
#define MMU_GIC_ADDR 0xFF800000ULL
|
||||
#define MMU_UART_ADDR 0xFE200000ULL
|
||||
#define MMU_OPENAMP_ADDR 0x70000000ULL
|
||||
|
||||
#define UART_BASE_ADDR 0xFE201000ULL
|
||||
|
||||
#define TEST_CLK_INT 30
|
||||
|
||||
#define OS_GIC_VER 2
|
||||
#define SICR_ADDR_OFFSET_PER_CORE 0x200U
|
||||
#define GIC_REG_BASE_ADDR 0xFF841000ULL
|
||||
|
||||
#define GIC_DIST_BASE GIC_REG_BASE_ADDR
|
||||
#define GIC_CPU_BASE (GIC_DIST_BASE + 0x1000U)
|
||||
|
||||
#define GICD_CTLR (GIC_DIST_BASE + 0x0000U)
|
||||
#define GICD_TYPER (GIC_DIST_BASE + 0x0004U)
|
||||
#define GICD_IIDR (GIC_DIST_BASE + 0x0008U)
|
||||
#define GICD_IGROUPRn (GIC_DIST_BASE + 0x0080U)
|
||||
#define GICD_ISENABLERn (GIC_DIST_BASE + 0x0100U)
|
||||
#define GICD_ICENABLERn (GIC_DIST_BASE + 0x0180U)
|
||||
#define GICD_ISPENDRn (GIC_DIST_BASE + 0x0200U)
|
||||
#define GICD_ICPENDRn (GIC_DIST_BASE + 0x0280U)
|
||||
#define GICD_ISACTIVERn (GIC_DIST_BASE + 0x0300U)
|
||||
#define GICD_ICACTIVERn (GIC_DIST_BASE + 0x0380U)
|
||||
#define GICD_IPRIORITYn (GIC_DIST_BASE + 0x0400U)
|
||||
|
||||
#define GICC_CTLR (GIC_CPU_BASE + 0x0000U)
|
||||
#define GICC_PMR (GIC_CPU_BASE + 0x0004U)
|
||||
|
||||
#define BIT(n) (1 << (n))
|
||||
|
||||
#define GICC_CTLR_ENABLEGRP0 BIT(0)
|
||||
#define GICC_CTLR_ENABLEGRP1 BIT(1)
|
||||
#define GICC_CTLR_FIQBYPDISGRP0 BIT(5)
|
||||
#define GICC_CTLR_IRQBYPDISGRP0 BIT(6)
|
||||
#define GICC_CTLR_FIQBYPDISGRP1 BIT(7)
|
||||
#define GICC_CTLR_IRQBYPDISGRP1 BIT(8)
|
||||
|
||||
#define GICC_CTLR_ENABLE_MASK (GICC_CTLR_ENABLEGRP0 | \
|
||||
GICC_CTLR_ENABLEGRP1)
|
||||
|
||||
#define GICC_CTLR_BYPASS_MASK (GICC_CTLR_FIQBYPDISGRP0 | \
|
||||
GICC_CTLR_IRQBYPDISGRP0 | \
|
||||
GICC_CTLR_FIQBYPDISGRP1 | \
|
||||
GICC_CTLR_IRQBYPDISGRP1)
|
||||
|
||||
#define GIC_REG_READ(addr) (*(volatile U32 *)((uintptr_t)(addr)))
|
||||
#define GIC_REG_WRITE(data, addr) (*(volatile U32 *)((uintptr_t)(addr)) = (U32)(data))
|
||||
|
||||
#endif
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user