Merge branch 'master' of gitee.com:openharmony/kernel_liteos_m into backtrace
This commit is contained in:
commit
97a5b6d8dc
|
@ -1,12 +0,0 @@
|
|||
[submodule "third_party/cmsis"]
|
||||
path = third_party/cmsis
|
||||
url = ../third_party_cmsis.git
|
||||
branch = .
|
||||
[submodule "third_party/bounds_checking_function"]
|
||||
path = third_party/bounds_checking_function
|
||||
url = ../third_party_bounds_checking_function.git
|
||||
branch = .
|
||||
[submodule "third_party/FatFs"]
|
||||
path = third_party/FatFs
|
||||
url = ../third_party_FatFs.git
|
||||
branch = .
|
4
BUILD.gn
4
BUILD.gn
|
@ -1,5 +1,5 @@
|
|||
# Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
# Copyright (c) 2020-2021, Huawei Device Co., Ltd. All rights reserved.
|
||||
# Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without modification,
|
||||
# are permitted provided that the following conditions are met:
|
||||
|
|
|
@ -15,11 +15,17 @@ The OpenHarmony LiteOS Cortex-M is the kernel designed for the lightweight opera
|
|||
|
||||
## Directory Structure<a name="section161941989596"></a>
|
||||
|
||||
The directory structure is listed as below, for the detailed directories, please refer to [arch_spec.md](arch_spec.md).
|
||||
|
||||
```
|
||||
/kernel/liteos_m
|
||||
├── components # Optional components
|
||||
│ ├── backtrace # Backtrace support
|
||||
│ ├── cppsupport # C++ support
|
||||
│ └── cpup # CPU possession (CPUP)
|
||||
│ ├── cpup # CPU possession (CPUP)
|
||||
│ ├── exchook # Exception hook
|
||||
│ ├── fs # File system
|
||||
│ └── net # Network support
|
||||
├── kal # Kernel abstraction layer
|
||||
│ ├── cmsis # CMSIS-compliant API support
|
||||
│ └── posix # POSIX API support
|
||||
|
|
14
README_zh.md
14
README_zh.md
|
@ -15,11 +15,17 @@ OpenHarmony LiteOS-M内核是面向IoT领域构建的轻量级物联网操作系
|
|||
|
||||
## 目录<a name="section161941989596"></a>
|
||||
|
||||
目录结构如下,详细目录请参考[arch_spec_zh.md](arch_spec_zh.md)。
|
||||
|
||||
```
|
||||
/kernel/liteos_m
|
||||
├── components # 可选组件
|
||||
│ ├── backtrace # 回溯栈支持
|
||||
│ ├── cppsupport # C++支持
|
||||
│ └── cpup # CPUP功能
|
||||
│ ├── cpup # CPUP功能
|
||||
│ ├── exchook # 异常钩子
|
||||
│ ├── fs # 文件系统
|
||||
│ └── net # Network功能
|
||||
├── kal # 内核抽象层
|
||||
│ ├── cmsis # cmsis标准接口支持
|
||||
│ └── posix # posix标准接口支持
|
||||
|
@ -41,11 +47,11 @@ OpenHarmony LiteOS-M内核是面向IoT领域构建的轻量级物联网操作系
|
|||
|
||||
## 使用说明<a name="section3732185231214"></a>
|
||||
|
||||
OpenHarmony LiteOS-M内核的编译构建系统是一个基于gn和ninja的组件化构建系统,支持按组件配置、裁剪和拼装,按需构建出定制化的产品。编译构建系统的详细信息可以参考[官方开源站点编译系统介绍](https://gitee.com/openharmony/docs/blob/master/zh-cn/device-dev/porting/%E7%BC%96%E8%AF%91%E7%B3%BB%E7%BB%9F%E4%BB%8B%E7%BB%8D.md)。本文主要介绍如何基于gn和ninja编译LiteOS-M工程,GCC+Makefile、IAR、Keil MDK等编译方式可以参考社区爱好者贡献的站点。
|
||||
OpenHarmony LiteOS-M内核的编译构建系统是一个基于gn和ninja的组件化构建系统,支持按组件配置、裁剪和拼装,按需构建出定制化的产品。编译构建系统的详细信息可以参考[轻量和小型系统编译构建指导](https://gitee.com/openharmony/docs/blob/master/zh-cn/device-dev/subsystems/%E8%BD%BB%E9%87%8F%E5%92%8C%E5%B0%8F%E5%9E%8B%E7%B3%BB%E7%BB%9F%E7%BC%96%E8%AF%91%E6%9E%84%E5%BB%BA%E6%8C%87%E5%AF%BC.md)。本文主要介绍如何基于gn和ninja编译LiteOS-M工程,GCC+Makefile、IAR、Keil MDK等编译方式可以参考社区爱好者贡献的站点。
|
||||
|
||||
### 搭建系统基础环境
|
||||
|
||||
在搭建各个开发板环境前,需要完成OpenHarmony系统基础环境搭建。系统基础环境主要是指OpenHarmony的编译环境和开发环境,详细介绍请参考官方站点[搭建系统基础环境](https://gitee.com/openharmony/docs/blob/master/zh-cn/device-dev/quick-start/%E6%90%AD%E5%BB%BA%E7%B3%BB%E7%BB%9F%E5%9F%BA%E7%A1%80%E7%8E%AF%E5%A2%83.md)。开发者需要根据环境搭建文档,完成下述软件的安装:Python3.7+、gn、ninja、hb。对于LiteOS-M内核,还需要安装Make构建工具和[ARM GCC编译工具链](https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain/gnu-rm/downloads)。
|
||||
在搭建各个开发板环境前,需要完成OpenHarmony系统基础环境搭建。系统基础环境主要是指OpenHarmony的编译环境和开发环境,详细介绍请参考官方站点[Ubuntu编译环境准备](https://gitee.com/openharmony/docs/blob/master/zh-cn/device-dev/quick-start/Ubuntu%E7%BC%96%E8%AF%91%E7%8E%AF%E5%A2%83%E5%87%86%E5%A4%87.md)。开发者需要根据环境搭建文档,完成下述软件的安装:Python3.7+、gn、ninja、hb。对于LiteOS-M内核,还需要安装Make构建工具和[ARM GCC编译工具链](https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain/gnu-rm/downloads)。
|
||||
|
||||
### 获取OpenHarmony源码
|
||||
|
||||
|
@ -62,6 +68,8 @@ git clone https://gitee.com/harylee/nucleo_f767zi.git
|
|||
假设克隆到的代码目录为`~/nucleo_f767zi`。 执行如下命令把代码目录的`device`、`vendor`目录复制到`openHarmony`工程的相应目录。
|
||||
|
||||
```
|
||||
mkdir ~/openHarmony/device/st
|
||||
|
||||
cp -r ~/nucleo_f767zi/device/st/nucleo_f767zi ~/openHarmony/device/st/nucleo_f767zi
|
||||
|
||||
chmod +x ~/openHarmony/device/st/nucleo_f767zi/build.sh
|
||||
|
|
94
arch_spec.md
94
arch_spec.md
|
@ -1,52 +1,76 @@
|
|||
```
|
||||
.
|
||||
├── components --- Optional components
|
||||
├── components --- Components available for porting and header files exposed externally
|
||||
│ ├── backtrace --- Backtrace
|
||||
│ ├── cppsupport --- C++
|
||||
│ └── cpup --- CPUP
|
||||
├── kal --- Kernel Abstraction Layer
|
||||
│ ├── cmsis --- cmsis
|
||||
│ └── posix --- posix
|
||||
├── kernel --- Minimalistic kernel funtionalities
|
||||
│ ├── arch --- Support for hardware architectures
|
||||
│ │ ├── arm --- arm32
|
||||
│ │ │ └── cortex-m4 --- cortex-m4
|
||||
│ │ │ └── iar
|
||||
│ │ │ ├── los_atomic.h
|
||||
│ │ │ ├── los_context.h
|
||||
│ │ │ ├── los_interrupt.h
|
||||
│ │ │ └── los_mpu.h
|
||||
│ ├── cpup --- CPUP
|
||||
│ ├── exchook --- Exception hook
|
||||
│ ├── fs --- File System
|
||||
│ └── net --- Network
|
||||
├── kal --- Kernel Abstraction Layer, APIs exposed externally, including CMSIS APIs and part of POSIX APIs
|
||||
│ ├── cmsis --- CMSIS
|
||||
│ └── posix --- POSIX
|
||||
├── kernel --- Code for defining the minimum kernel function set
|
||||
│ ├── arch --- Code of the kernel instruction architecture layer
|
||||
│ │ ├── arm --- ARM32 architecture
|
||||
│ │ │ ├── cortex-m3 --- Cortex-m3 architecture
|
||||
│ │ │ │ └── keil --- Implementation of the Keil toolchain
|
||||
│ │ │ ├── cortex-m33 --- Cortex-m33 architecture
|
||||
│ │ │ │ │── gcc --- Implementation of the GCC toolchain
|
||||
│ │ │ │ └── iar --- Implementation of the IAR toolchain
|
||||
│ │ │ └── cortex-m4 --- Cortex-m4 architecture
|
||||
│ │ │ │ │── gcc --- Implementation of the GCC toolchain
|
||||
│ │ │ │ └── iar --- Implementation of the IAR toolchain
|
||||
│ │ │ └── cortex-m7 --- Cortex-m7 architecture
|
||||
│ │ │ │ │── gcc --- Implementation of the GCC toolchain
|
||||
│ │ │ │ └── iar --- Implementation of the IAR toolchain
|
||||
│ │ ├── risc-v --- Risc-v architecture
|
||||
│ │ │ ├── nuclei --- Nuclei architecture
|
||||
│ │ │ │ └── gcc --- Implementation of the GCC toolchain
|
||||
│ │ │ └── riscv32 --- Riscv32 architecture
|
||||
│ │ │ │ └── gcc --- Implementation of the GCC toolchain
|
||||
│ │ └── include
|
||||
│ │ ├── los_arch_atomic.h --- Atomic operations
|
||||
│ │ ├── los_arch_context.h --- Context switch
|
||||
│ │ ├── los_arch.h --- Initialization
|
||||
│ │ └── los_arch_interrupt.h --- Interrupts
|
||||
│ │ ├── los_arch.h --- Arch initialization
|
||||
│ │ ├── los_atomic.h --- Atomic operations
|
||||
│ │ ├── los_context.h --- Context switch
|
||||
│ │ ├── los_interrupt.h --- Interrupts
|
||||
│ │ ├── los_mpu.h --- Memory protection unit operations
|
||||
│ │ └── los_timer.h --- Timer operations
|
||||
│ ├── include
|
||||
│ │ ├── los_config.h --- Configuration parameters
|
||||
│ │ ├── los_event.h --- Events management
|
||||
│ │ ├── los_liteos.h --- Kernel types and functions
|
||||
│ │ ├── los_membox.h --- Membox management
|
||||
│ │ ├── los_memory.h --- Heap memory management
|
||||
│ │ ├── los_mutex.h --- Mutex
|
||||
│ │ ├── los_mux.h --- Mutex
|
||||
│ │ ├── los_queue.h --- Queue
|
||||
│ │ ├── los_scheduler.h --- Scheduler
|
||||
│ │ ├── los_sched.h --- Scheduler
|
||||
│ │ ├── los_sem.h --- Semaphores
|
||||
│ │ ├── los_sortlink.h --- Sort link
|
||||
│ │ ├── los_swtmr.h --- Timer
|
||||
│ │ ├── los_task.h --- Tasks
|
||||
│ │ └── los_timer.h --- Timer
|
||||
│ │ └── los_tick.h --- Tick
|
||||
│ └── src
|
||||
├── targets
|
||||
│ └── targets
|
||||
│ └── cortex-m4_stm32f429ig_fire-challenger_iar
|
||||
│ ├── board
|
||||
│ ├── dprintf.c
|
||||
│ ├── Libraries
|
||||
│ ├── main.c
|
||||
│ ├── project
|
||||
│ ├── target_config.h --- Hardware target configuration
|
||||
│ └── Utilities
|
||||
│ └── riscv_nuclei_demo_soc_gcc
|
||||
│ │ ├── GCC --- Compilation config
|
||||
│ │ ├── OS_CONFIG --- Board config
|
||||
│ │ ├── SoC --- SOC codes
|
||||
│ │ └── Src --- Application codes
|
||||
│ └── riscv_nuclei_gd32vf103_soc_gcc
|
||||
│ └── riscv_sifive_fe310_gcc
|
||||
└── utils
|
||||
├── include
|
||||
│ ├── los_compiler.h --- Compiler configuration
|
||||
│ ├── los_debug.h --- Debugging facilities
|
||||
│ ├── los_error.h --- Errors codes and definitions
|
||||
│ └── los_list.h
|
||||
├── internal
|
||||
├── BUILD.gn --- Gn build config file
|
||||
├── los_compiler.h --- Compiler configuration
|
||||
├── los_debug.c --- Debugging facilities
|
||||
├── los_debug.h
|
||||
├── los_error.c --- Errors codes and definitions
|
||||
├── los_error.h
|
||||
├── los_hook.c --- Hook function facilities
|
||||
├── los_hook.h
|
||||
├── los_list.h --- Doubly linked list
|
||||
└── los_reg.h --- Register macros
|
||||
└── src
|
||||
```
|
||||
|
||||
|
|
|
@ -0,0 +1,76 @@
|
|||
```
|
||||
.
|
||||
├── components --- 移植可选组件,依赖内核,单独对外提供头文件
|
||||
│ ├── backtrace --- 回溯栈支持
|
||||
│ ├── cppsupport --- C++支持
|
||||
│ ├── cpup --- CPUP功能
|
||||
│ ├── exchook --- 异常钩子
|
||||
│ ├── fs --- 文件系统
|
||||
│ └── net --- 网络功能
|
||||
├── kal --- 内核抽象层,提供内核对外接口,当前支持CMSIS接口和部分POSIX接口
|
||||
│ ├── cmsis --- CMSIS标准支持
|
||||
│ └── posix --- POSIX标准支持
|
||||
├── kernel --- 内核最小功能集代码
|
||||
│ ├── arch --- 内核指令架构层代码
|
||||
│ │ ├── arm --- ARM32架构
|
||||
│ │ │ ├── cortex-m3 --- Cortex-m3架构
|
||||
│ │ │ │ └── keil --- Keil编译工具链实现
|
||||
│ │ │ ├── cortex-m33 --- Cortex-m33架构
|
||||
│ │ │ │ │── gcc --- GCC编译工具链实现
|
||||
│ │ │ │ └── iar --- IAR编译工具链实现
|
||||
│ │ │ └── cortex-m4 --- Cortex-m4架构
|
||||
│ │ │ │ │── gcc --- GCC编译工具链实现
|
||||
│ │ │ │ └── iar --- IAR编译工具链实现
|
||||
│ │ │ └── cortex-m7 --- Cortex-m7架构
|
||||
│ │ │ │ │── gcc --- GCC编译工具链实现
|
||||
│ │ │ │ └── iar --- IAR编译工具链实现
|
||||
│ │ ├── risc-v --- Risc-v架构
|
||||
│ │ │ ├── nuclei --- Nuclei架构
|
||||
│ │ │ │ └── gcc --- GCC编译工具链实现
|
||||
│ │ │ └── riscv32 --- Riscv32架构
|
||||
│ │ │ │ └── gcc --- GCC编译工具链实现
|
||||
│ │ └── include
|
||||
│ │ ├── los_arch.h --- 定义arch初始化
|
||||
│ │ ├── los_atomic.h --- 定义通用arch原子操作
|
||||
│ │ ├── los_context.h --- 定义通用arch上下文切换
|
||||
│ │ ├── los_interrupt.h --- 定义通用arch中断
|
||||
│ │ ├── los_mpu.h --- 定义通用arch内存保护
|
||||
│ │ └── los_timer.h --- 定义通用arch定时器
|
||||
│ ├── include
|
||||
│ │ ├── los_config.h --- 功能开关和配置参数
|
||||
│ │ ├── los_event.h --- 事件
|
||||
│ │ ├── los_membox.h --- 静态内存管理
|
||||
│ │ ├── los_memory.h --- 动态内存管理
|
||||
│ │ ├── los_mux.h --- 互斥锁
|
||||
│ │ ├── los_queue.h --- 队列
|
||||
│ │ ├── los_sched.h --- 调度算法
|
||||
│ │ ├── los_sem.h --- 信号量
|
||||
│ │ ├── los_sortlink.h --- 排序链表
|
||||
│ │ ├── los_swtmr.h --- 定时器
|
||||
│ │ ├── los_task.h --- 任务
|
||||
│ │ └── los_tick.h --- Tick时钟
|
||||
└── src
|
||||
├── targets
|
||||
│ └── targets
|
||||
│ └── riscv_nuclei_demo_soc_gcc
|
||||
│ │ ├── GCC --- 编译相关
|
||||
│ │ ├── OS_CONFIG --- 开发板配置功能开关和配置参数
|
||||
│ │ ├── SoC --- SOC相关代码
|
||||
│ │ └── Src --- Application相关代码
|
||||
│ └── riscv_nuclei_gd32vf103_soc_gcc
|
||||
│ └── riscv_sifive_fe310_gcc
|
||||
└── utils
|
||||
├── internal
|
||||
├── BUILD.gn --- Gn构建文件
|
||||
├── los_compiler.h --- 编译工具配置,类型定义
|
||||
├── los_debug.c --- Debug,printf相关
|
||||
├── los_debug.h
|
||||
├── los_error.c --- 错误处理
|
||||
├── los_error.h
|
||||
├── los_hook.c --- 钩子函数注册和调用
|
||||
├── los_hook.h
|
||||
├── los_list.h --- 双向链表
|
||||
└── los_reg.h --- 寄存器读写宏定义
|
||||
└── src
|
||||
```
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
# Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
# Copyright (c) 2020-2021, Huawei Device Co., Ltd. All rights reserved.
|
||||
# Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without modification,
|
||||
# are permitted provided that the following conditions are met:
|
||||
|
|
|
@ -188,7 +188,7 @@ STATIC INLINE BOOL OsBackTraceFpCheck(UINT32 value);
|
|||
#define OS_FP_CHECK(value) (((UINT32)(value) != FP_INIT_VALUE) && OS_FP_ALIGN(value))
|
||||
|
||||
STATIC INLINE UINTPTR OsFpGet(VOID)
|
||||
{
|
||||
{
|
||||
UINTPTR fp = 0;
|
||||
__asm volatile("mv %0, s0" : "=r"(fp));
|
||||
dsb();
|
||||
|
@ -199,8 +199,8 @@ VOID LOS_RecordLR(UINTPTR *LR, UINT32 LRSize, UINT32 jumpCount, UINTPTR SP)
|
|||
{
|
||||
UNUSED(SP);
|
||||
UINT32 backFp = OsFpGet();
|
||||
UINT32 tmpFp;
|
||||
UINT32 backRa;
|
||||
UINT32 tmpFp;
|
||||
UINT32 backRa;
|
||||
UINT32 count = 0;
|
||||
UINT32 index = 0;
|
||||
|
||||
|
@ -209,7 +209,7 @@ VOID LOS_RecordLR(UINTPTR *LR, UINT32 LRSize, UINT32 jumpCount, UINTPTR SP)
|
|||
}
|
||||
|
||||
while (OS_FP_CHECK(backFp)) {
|
||||
tmpFp = backFp;
|
||||
tmpFp = backFp;
|
||||
backRa = *((UINT32 *)(UINTPTR)(tmpFp - OS_RA_OFFSET));
|
||||
backFp = *((UINT32 *)(UINTPTR)(tmpFp - OS_FP_OFFSET));
|
||||
if (index++ < jumpCount) {
|
||||
|
@ -220,8 +220,8 @@ VOID LOS_RecordLR(UINTPTR *LR, UINT32 LRSize, UINT32 jumpCount, UINTPTR SP)
|
|||
count++;
|
||||
if ((count == LRSize) || (backFp == tmpFp) ||
|
||||
(!OsStackDataIsCodeAddr(backRa))) {
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (count < LRSize) {
|
||||
|
@ -273,7 +273,7 @@ STATIC INLINE BOOL OsInsIsJump(UINTPTR addr)
|
|||
}
|
||||
|
||||
STATIC INLINE UINTPTR OsSpGet(VOID)
|
||||
{
|
||||
{
|
||||
UINTPTR sp = 0;
|
||||
__asm volatile("mv %0, sp" : "=r"(sp));
|
||||
dsb();
|
||||
|
|
|
@ -46,7 +46,7 @@ extern "C" {
|
|||
#if (LOSCFG_BACKTRACE_TYPE != 0)
|
||||
#if (LOSCFG_BACKTRACE_TYPE == 1)
|
||||
/* The default name of the code section and CSTACK section are given below,
|
||||
and the user can be adjust it according to the linker script file. */
|
||||
and the user can adjust it according to the linker script file. */
|
||||
#if defined(__ICCARM__)
|
||||
/* The default code section name is .text */
|
||||
#define CODE_SECTION_NAME ".text"
|
||||
|
@ -91,9 +91,9 @@ extern CHAR *CODE_SECTION_END(CODE_SECTION_NAME);
|
|||
#define CSTACK_START_ADDR ((UINTPTR)&CSTACK_SECTION_START(CSTACK_SECTION_NAME))
|
||||
#define CSTACK_END_ADDR ((UINTPTR)&CSTACK_SECTION_END(CSTACK_SECTION_NAME))
|
||||
#elif defined(__GNUC__)
|
||||
/* The defalut code section start address */
|
||||
/* The default code section start address */
|
||||
#define CODE_SECTION_START _stext
|
||||
/* The defalut code section end address */
|
||||
/* The default code section end address */
|
||||
#define CODE_SECTION_END _etext
|
||||
/* The default C stack section start address */
|
||||
#define CSTACK_SECTION_START _sstack
|
||||
|
@ -117,9 +117,9 @@ extern CHAR *CSTACK_SECTION_END;
|
|||
#endif
|
||||
#elif (LOSCFG_BACKTRACE_TYPE == 2) || (LOSCFG_BACKTRACE_TYPE == 3)
|
||||
#if defined(__GNUC__)
|
||||
/* The defalut code section start address */
|
||||
/* The default code section start address */
|
||||
#define CODE_SECTION_START __text_start
|
||||
/* The defalut code section end address */
|
||||
/* The default code section end address */
|
||||
#define CODE_SECTION_END __text_end
|
||||
/* The default C stack section start address */
|
||||
#define CSTACK_SECTION_START __except_stack_top
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
../../../third_party/bounds_checking_function/
|
|
@ -1,5 +1,5 @@
|
|||
# Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
# Copyright (c) 2020-2021, Huawei Device Co., Ltd. All rights reserved.
|
||||
# Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without modification,
|
||||
# are permitted provided that the following conditions are met:
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
# Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
# Copyright (c) 2020-2021, Huawei Device Co., Ltd. All rights reserved.
|
||||
# Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without modification,
|
||||
# are permitted provided that the following conditions are met:
|
||||
|
|
|
@ -222,7 +222,7 @@ typedef enum {
|
|||
* @param None.
|
||||
*
|
||||
* @retval #OS_ERRNO_CPUP_NO_INIT 0x02001e02: The CPU usage is not initialized.
|
||||
* @retval #cpup [0,100], current CPU usage, of which the precision is adjustable.
|
||||
* @retval #cpup [0,1000], current CPU usage, of which the precision is adjustable.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_cpup.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see LOS_SysCpuUsage
|
||||
|
@ -245,7 +245,7 @@ extern UINT32 LOS_SysCpuUsage(VOID);
|
|||
* indicate that the CPU usage in the period that is less than 1s will be obtained.
|
||||
*
|
||||
* @retval #OS_ERRNO_CPUP_NO_INIT 0x02001e02: The CPU usage is not initialized.
|
||||
* @retval #cpup [0,100], historical CPU usage, of which the precision is adjustable.
|
||||
* @retval #cpup [0,1000], historical CPU usage, of which the precision is adjustable.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_cpup.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see LOS_HistoryTaskCpuUsage
|
||||
|
@ -270,7 +270,7 @@ extern UINT32 LOS_HistorySysCpuUsage(UINT16 mode);
|
|||
* @retval #OS_ERRNO_CPUP_NO_INIT 0x02001e02: The CPU usage is not initialized.
|
||||
* @retval #OS_ERRNO_CPUP_TSK_ID_INVALID 0x02001e05: The target task ID is invalid.
|
||||
* @retval #OS_ERRNO_CPUP_THREAD_NO_CREATED 0x02001e04: The target thread is not created.
|
||||
* @retval #cpup [0,100], CPU usage of the specified task.
|
||||
* @retval #cpup [0,1000], CPU usage of the specified task.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_cpup.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see LOS_HistoryTaskCpuUsage
|
||||
|
@ -299,7 +299,7 @@ extern UINT32 LOS_TaskCpuUsage(UINT32 taskID);
|
|||
* @retval #OS_ERRNO_CPUP_NO_INIT 0x02001e02: The CPU usage is not initialized.
|
||||
* @retval #OS_ERRNO_CPUP_TSK_ID_INVALID 0x02001e05: The target task ID is invalid.
|
||||
* @retval #OS_ERRNO_CPUP_THREAD_NO_CREATED 0x02001e04: The target thread is not created.
|
||||
* @retval #cpup [0,100], CPU usage of the specified task.
|
||||
* @retval #cpup [0,1000], CPU usage of the specified task.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_cpup.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see LOS_HistorySysCpuUsage
|
||||
|
@ -346,7 +346,7 @@ extern UINT32 LOS_AllTaskCpuUsage(CPUP_INFO_S *cpupInfo, UINT16 mode);
|
|||
*
|
||||
* @param type [IN] cpup type, SYS_CPU_USAGE and TASK_CPU_USAGE
|
||||
* @param mode [IN] mode,CPUP_IN_10S = usage in 10s,CPUP_IN_1S = usage in last 1s,
|
||||
* CPUP_LESS_THAN_1S = less than 1s, if the inpuit mode is none of them, it will be as CPUP_LESS_THAN_1S.
|
||||
* CPUP_LESS_THAN_1S = less than 1s, if the input mode is none of them, it will be as CPUP_LESS_THAN_1S.
|
||||
* @param taskID [IN] task ID, Only in SYS_CPU_USAGE type, taskID is invalid
|
||||
*
|
||||
* @retval #OS_ERROR -1:CPU usage info obtain failed.
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
# Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
# Copyright (c) 2020-2021, Huawei Device Co., Ltd. All rights reserved.
|
||||
# Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without modification,
|
||||
# are permitted provided that the following conditions are met:
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
# Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
# Copyright (c) 2020-2021, Huawei Device Co., Ltd. All rights reserved.
|
||||
# Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without modification,
|
||||
# are permitted provided that the following conditions are met:
|
||||
|
@ -27,6 +27,12 @@
|
|||
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
static_library("fs_operations") {
|
||||
sources = [
|
||||
"./fs.c",
|
||||
]
|
||||
}
|
||||
|
||||
declare_args() {
|
||||
enable_ohos_kernel_liteos_m_fatfs = true
|
||||
enable_ohos_kernel_liteos_m_littlefs = false
|
||||
|
@ -34,6 +40,7 @@ declare_args() {
|
|||
|
||||
group("fs") {
|
||||
deps = []
|
||||
deps += [ ".:fs_operations" ]
|
||||
if (enable_ohos_kernel_liteos_m_fatfs == true) {
|
||||
deps += [ "fatfs:fatfs" ]
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
# Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
# Copyright (c) 2020-2021, Huawei Device Co., Ltd. All rights reserved.
|
||||
# Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without modification,
|
||||
# are permitted provided that the following conditions are met:
|
||||
|
@ -34,10 +34,10 @@ static_library("fatfs") {
|
|||
"//third_party/FatFs/source/ffsystem.c",
|
||||
"//third_party/FatFs/source/ffunicode.c",
|
||||
"fatfs.c",
|
||||
"fs.c",
|
||||
]
|
||||
|
||||
include_dirs = [
|
||||
"../",
|
||||
"../../../kernel/arch/include",
|
||||
"../../../kernel/include",
|
||||
"../../../utils",
|
||||
|
|
|
@ -41,9 +41,8 @@
|
|||
#include "los_compiler.h"
|
||||
#include "los_debug.h"
|
||||
#include "cmsis_os2.h"
|
||||
#include "fs_operations.h"
|
||||
|
||||
#define FS_SUCCESS 0
|
||||
#define FS_FAILURE (-1)
|
||||
/* the max name length of different parts should not bigger than 32 */
|
||||
#define FS_DRIVE_NAME_MAX_LEN 32
|
||||
|
||||
|
@ -51,9 +50,9 @@
|
|||
#define FAT_MAX_OPEN_DIRS 8
|
||||
#endif /* FAT_MAX_OPEN_DIRS */
|
||||
|
||||
#ifndef FS_LOCK_TIMEMOUT_SEC
|
||||
#define FS_LOCK_TIMEMOUT_SEC 15
|
||||
#endif /* FS_LOCK_TIMEMOUT_SEC */
|
||||
#ifndef FS_LOCK_TIMEOUT_SEC
|
||||
#define FS_LOCK_TIMEOUT_SEC 15
|
||||
#endif /* FS_LOCK_TIMEOUT_SEC */
|
||||
|
||||
#define PART_NAME 0x0
|
||||
#define VOLUME_NAME 0x1
|
||||
|
@ -89,7 +88,7 @@ static int FsLock(void)
|
|||
PRINTK("clock gettime err 0x%x!\r\n", errno);
|
||||
return errno;
|
||||
}
|
||||
absTimeout.tv_sec += FS_LOCK_TIMEMOUT_SEC;
|
||||
absTimeout.tv_sec += FS_LOCK_TIMEOUT_SEC;
|
||||
ret = pthread_mutex_timedlock(&g_fsMutex, &absTimeout);
|
||||
return ret;
|
||||
}
|
||||
|
@ -1258,8 +1257,8 @@ OUT:
|
|||
|
||||
static int do_truncate(int fd, off_t length, UINT count)
|
||||
{
|
||||
FRESULT res;
|
||||
INT32 ret = FR_OK;
|
||||
FRESULT res = FR_OK;
|
||||
INT32 ret = FS_SUCCESS;
|
||||
DWORD csz;
|
||||
|
||||
csz = (DWORD)(g_handle[fd].fil.obj.fs)->csize * SS(g_handle[fd].fil.obj.fs); /* Cluster size */
|
||||
|
@ -1420,3 +1419,27 @@ OUT:
|
|||
FsUnlock();
|
||||
return ret;
|
||||
}
|
||||
|
||||
struct MountOps g_fatfsMnt = {
|
||||
.Mount = fatfs_mount,
|
||||
.Umount = fatfs_umount,
|
||||
.Umount2 = fatfs_umount2,
|
||||
.Statfs = fatfs_statfs,
|
||||
};
|
||||
|
||||
struct FileOps g_fatfsFops = {
|
||||
.Mkdir = fatfs_mkdir,
|
||||
.Unlink = fatfs_unlink,
|
||||
.Rmdir = fatfs_rmdir,
|
||||
.Opendir = fatfs_opendir,
|
||||
.Readdir = fatfs_readdir,
|
||||
.Closedir = fatfs_closedir,
|
||||
.Open = fatfs_open,
|
||||
.Close = fatfs_close,
|
||||
.Write = fatfs_write,
|
||||
.Read = fatfs_read,
|
||||
.Seek = fatfs_lseek,
|
||||
.Rename = fatfs_rename,
|
||||
.Getattr = fatfs_stat,
|
||||
.Fsync = fatfs_fsync,
|
||||
};
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "fs_operations.h"
|
||||
#include "fatfs.h"
|
||||
#include "dirent.h"
|
||||
#include "errno.h"
|
||||
|
@ -42,6 +42,9 @@
|
|||
#include "sys/stat.h"
|
||||
#include "unistd.h"
|
||||
|
||||
struct FsMap g_fsmap[MAX_FILESYSTEM_LEN] = {0};
|
||||
struct FsMap *g_fs = NULL;
|
||||
|
||||
#ifdef LOSCFG_NET_LWIP_SACK
|
||||
#include "lwip/lwipopts.h"
|
||||
#include "lwip/sockets.h"
|
||||
|
@ -92,12 +95,12 @@ static size_t GetCanonicalPath(const char *cwd, const char *path, char *buf, siz
|
|||
size_t tmpLen = strlen(cwd) + strlen(path) + offset;
|
||||
char *tmpBuf = (char *)malloc(tmpLen);
|
||||
if (tmpBuf == NULL) {
|
||||
return 0;
|
||||
return FS_SUCCESS;
|
||||
}
|
||||
|
||||
if (-1 == sprintf_s(tmpBuf, tmpLen, "/%s/%s/", cwd, path)) {
|
||||
free(tmpBuf);
|
||||
return 0;
|
||||
return FS_SUCCESS;
|
||||
}
|
||||
|
||||
char *p;
|
||||
|
@ -106,7 +109,7 @@ static size_t GetCanonicalPath(const char *cwd, const char *path, char *buf, siz
|
|||
while ((p = strstr(tmpBuf, "/./")) != NULL) {
|
||||
if (EOK != memmove_s(p, tmpLen - (p - tmpBuf), p + offset, tmpLen - (p - tmpBuf) - offset)) {
|
||||
free(tmpBuf);
|
||||
return 0;
|
||||
return FS_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -114,7 +117,7 @@ static size_t GetCanonicalPath(const char *cwd, const char *path, char *buf, siz
|
|||
while ((p = strstr(tmpBuf, "//")) != NULL) {
|
||||
if (EOK != memmove_s(p, tmpLen - (p - tmpBuf), p + 1, tmpLen - (p - tmpBuf) - 1)) {
|
||||
free(tmpBuf);
|
||||
return 0;
|
||||
return FS_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -127,7 +130,7 @@ static size_t GetCanonicalPath(const char *cwd, const char *path, char *buf, siz
|
|||
}
|
||||
if (EOK != memmove_s(start, tmpLen - (start - tmpBuf), p + offset, tmpLen - (p - tmpBuf) - offset)) {
|
||||
free(tmpBuf);
|
||||
return 0;
|
||||
return FS_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -144,7 +147,7 @@ static size_t GetCanonicalPath(const char *cwd, const char *path, char *buf, siz
|
|||
|
||||
if (EOK != memcpy_s(buf, bufSize, tmpBuf, (((totalLen + 1) > bufSize) ? bufSize : (totalLen + 1)))) {
|
||||
free(tmpBuf);
|
||||
return 0;
|
||||
return FS_SUCCESS;
|
||||
}
|
||||
|
||||
buf[bufSize - 1] = 0;
|
||||
|
@ -153,21 +156,83 @@ static size_t GetCanonicalPath(const char *cwd, const char *path, char *buf, siz
|
|||
}
|
||||
#endif
|
||||
|
||||
static void InitMountInfo(void)
|
||||
{
|
||||
extern struct MountOps g_fatfsMnt;
|
||||
extern struct FileOps g_fatfsFops;
|
||||
g_fsmap[0].fileSystemtype = strdup("fat");
|
||||
g_fsmap[0].fsMops = &g_fatfsMnt;
|
||||
g_fsmap[0].fsFops = &g_fatfsFops;
|
||||
extern struct MountOps g_lfsMnt;
|
||||
extern struct FileOps g_lfsFops;
|
||||
g_fsmap[1].fileSystemtype = strdup("littlefs");
|
||||
g_fsmap[1].fsMops = &g_lfsMnt;
|
||||
g_fsmap[1].fsFops = &g_lfsFops;
|
||||
}
|
||||
|
||||
static struct FsMap *MountFindfs(const char *fileSystemtype)
|
||||
{
|
||||
struct FsMap *m = NULL;
|
||||
|
||||
for (int i = 0; i < MAX_FILESYSTEM_LEN; i++) {
|
||||
m = &(g_fsmap[i]);
|
||||
if (m->fileSystemtype && strcmp(fileSystemtype, m->fileSystemtype) == 0) {
|
||||
return m;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int mount(const char *source, const char *target,
|
||||
const char *filesystemtype, unsigned long mountflags,
|
||||
const void *data)
|
||||
{
|
||||
return fatfs_mount(source, target, filesystemtype, mountflags, data);
|
||||
static int initFlag = 0;
|
||||
|
||||
if (initFlag == 0) {
|
||||
InitMountInfo();
|
||||
initFlag = 1;
|
||||
}
|
||||
|
||||
g_fs = MountFindfs(filesystemtype);
|
||||
if (g_fs == NULL) {
|
||||
errno = ENODEV;
|
||||
return FS_FAILURE;
|
||||
}
|
||||
|
||||
if (g_fs->fsMops == NULL || g_fs->fsMops->Mount == NULL) {
|
||||
errno = ENOSYS;
|
||||
return FS_FAILURE;
|
||||
}
|
||||
|
||||
return g_fs->fsMops->Mount(source, target, filesystemtype, mountflags, data);
|
||||
}
|
||||
|
||||
int umount(const char *target)
|
||||
{
|
||||
return fatfs_umount(target);
|
||||
if (g_fs == NULL) {
|
||||
errno = ENODEV;
|
||||
return FS_FAILURE;
|
||||
}
|
||||
if (g_fs->fsMops == NULL || g_fs->fsMops->Umount == NULL) {
|
||||
errno = ENOSYS;
|
||||
return FS_FAILURE;
|
||||
}
|
||||
return g_fs->fsMops->Umount(target);
|
||||
}
|
||||
|
||||
int umount2(const char *target, int flag)
|
||||
{
|
||||
return fatfs_umount2(target, flag);
|
||||
if (g_fs == NULL) {
|
||||
errno = ENODEV;
|
||||
return FS_FAILURE;
|
||||
}
|
||||
if (g_fs->fsMops == NULL || g_fs->fsMops->Umount2 == NULL) {
|
||||
errno = ENOSYS;
|
||||
return FS_FAILURE;
|
||||
}
|
||||
return g_fs->fsMops->Umount2(target, flag);
|
||||
}
|
||||
|
||||
int open(const char *path, int oflag, ...)
|
||||
|
@ -176,30 +241,30 @@ int open(const char *path, int oflag, ...)
|
|||
unsigned flags = O_RDONLY | O_WRONLY | O_RDWR | O_APPEND | O_CREAT | O_LARGEFILE | O_TRUNC | O_EXCL | O_DIRECTORY;
|
||||
if ((unsigned)oflag & ~flags) {
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
return FS_FAILURE;
|
||||
}
|
||||
|
||||
size_t pathLen = strlen(path) + 1;
|
||||
char *canonicalPath = (char *)malloc(pathLen);
|
||||
if (!canonicalPath) {
|
||||
errno = ENOMEM;
|
||||
return -1;
|
||||
return FS_FAILURE;
|
||||
}
|
||||
if (GetCanonicalPath(NULL, path, canonicalPath, pathLen) == 0) {
|
||||
FREE_AND_SET_NULL(canonicalPath);
|
||||
errno = ENOMEM;
|
||||
return -1;
|
||||
return FS_FAILURE;
|
||||
}
|
||||
|
||||
if (strcmp(canonicalPath, RANDOM_DEV_PATH) == 0) {
|
||||
FREE_AND_SET_NULL(canonicalPath);
|
||||
if ((O_ACCMODE & (unsigned)oflag) != O_RDONLY) {
|
||||
errno = EPERM;
|
||||
return -1;
|
||||
return FS_FAILURE;
|
||||
}
|
||||
if ((unsigned)oflag & O_DIRECTORY) {
|
||||
errno = ENOTDIR;
|
||||
return -1;
|
||||
return FS_FAILURE;
|
||||
}
|
||||
return RANDOM_DEV_FD;
|
||||
}
|
||||
|
@ -207,21 +272,29 @@ int open(const char *path, int oflag, ...)
|
|||
FREE_AND_SET_NULL(canonicalPath);
|
||||
if ((unsigned)oflag & O_DIRECTORY) {
|
||||
errno = EPERM;
|
||||
return -1;
|
||||
return FS_FAILURE;
|
||||
}
|
||||
errno = EISDIR;
|
||||
return -1;
|
||||
return FS_FAILURE;
|
||||
}
|
||||
FREE_AND_SET_NULL(canonicalPath);
|
||||
#endif
|
||||
return fatfs_open(path, oflag);
|
||||
if (g_fs == NULL) {
|
||||
errno = ENODEV;
|
||||
return FS_FAILURE;
|
||||
}
|
||||
if (g_fs->fsFops == NULL || g_fs->fsFops->Open == NULL) {
|
||||
errno = ENOSYS;
|
||||
return FS_FAILURE;
|
||||
}
|
||||
return g_fs->fsFops->Open(path, oflag);
|
||||
}
|
||||
|
||||
int close(int fd)
|
||||
{
|
||||
#ifdef LOSCFG_RANDOM_DEV
|
||||
if (fd == RANDOM_DEV_FD) {
|
||||
return 0;
|
||||
return FS_SUCCESS;
|
||||
}
|
||||
#endif
|
||||
#ifdef LOSCFG_NET_LWIP_SACK
|
||||
|
@ -229,7 +302,15 @@ int close(int fd)
|
|||
return closesocket(fd);
|
||||
}
|
||||
#endif
|
||||
return fatfs_close(fd);
|
||||
if (g_fs == NULL) {
|
||||
errno = ENODEV;
|
||||
return FS_FAILURE;
|
||||
}
|
||||
if (g_fs->fsFops == NULL || g_fs->fsFops->Close == NULL) {
|
||||
errno = ENOSYS;
|
||||
return FS_FAILURE;
|
||||
}
|
||||
return g_fs->fsFops->Close(fd);
|
||||
}
|
||||
|
||||
ssize_t read(int fd, void *buf, size_t nbyte)
|
||||
|
@ -237,11 +318,11 @@ ssize_t read(int fd, void *buf, size_t nbyte)
|
|||
#ifdef LOSCFG_RANDOM_DEV
|
||||
if (fd == RANDOM_DEV_FD) {
|
||||
if (nbyte == 0) {
|
||||
return 0;
|
||||
return FS_SUCCESS;
|
||||
}
|
||||
if (buf == NULL) {
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
return FS_FAILURE;
|
||||
}
|
||||
if (nbyte > 1024) {
|
||||
nbyte = 1024; /* hks_generate_random: random_size must <= 1024 */
|
||||
|
@ -249,7 +330,7 @@ ssize_t read(int fd, void *buf, size_t nbyte)
|
|||
struct hks_blob key = {HKS_BLOB_TYPE_RAW, (uint8_t *)buf, nbyte};
|
||||
if (hks_generate_random(&key) != 0) {
|
||||
errno = EIO;
|
||||
return -1;
|
||||
return FS_FAILURE;
|
||||
}
|
||||
return (ssize_t)nbyte;
|
||||
}
|
||||
|
@ -259,7 +340,15 @@ ssize_t read(int fd, void *buf, size_t nbyte)
|
|||
return recv(fd, buf, nbyte, 0);
|
||||
}
|
||||
#endif
|
||||
return fatfs_read(fd, buf, nbyte);
|
||||
if (g_fs->fsFops == NULL || g_fs->fsFops->Read == NULL) {
|
||||
errno = ENOSYS;
|
||||
return FS_FAILURE;
|
||||
}
|
||||
if (g_fs == NULL) {
|
||||
errno = ENODEV;
|
||||
return FS_FAILURE;
|
||||
}
|
||||
return g_fs->fsFops->Read(fd, buf, nbyte);
|
||||
}
|
||||
|
||||
ssize_t write(int fd, const void *buf, size_t nbyte)
|
||||
|
@ -267,7 +356,7 @@ ssize_t write(int fd, const void *buf, size_t nbyte)
|
|||
#ifdef LOSCFG_RANDOM_DEV
|
||||
if (fd == RANDOM_DEV_FD) {
|
||||
errno = EBADF; /* "/dev/random" is readonly */
|
||||
return -1;
|
||||
return FS_FAILURE;
|
||||
}
|
||||
#endif
|
||||
#ifdef LOSCFG_NET_LWIP_SACK
|
||||
|
@ -275,70 +364,182 @@ ssize_t write(int fd, const void *buf, size_t nbyte)
|
|||
return send(fd, buf, nbyte, 0);
|
||||
}
|
||||
#endif
|
||||
return fatfs_write(fd, buf, nbyte);
|
||||
if (g_fs == NULL) {
|
||||
errno = ENODEV;
|
||||
return FS_FAILURE;
|
||||
}
|
||||
if (g_fs->fsFops == NULL || g_fs->fsFops->Write == NULL) {
|
||||
errno = ENOSYS;
|
||||
return FS_FAILURE;
|
||||
}
|
||||
return g_fs->fsFops->Write(fd, buf, nbyte);
|
||||
}
|
||||
|
||||
off_t lseek(int fd, off_t offset, int whence)
|
||||
{
|
||||
return fatfs_lseek(fd, offset, whence);
|
||||
if (g_fs == NULL) {
|
||||
errno = ENODEV;
|
||||
return FS_FAILURE;
|
||||
}
|
||||
if (g_fs->fsFops == NULL || g_fs->fsFops->Seek == NULL) {
|
||||
errno = ENOSYS;
|
||||
return FS_FAILURE;
|
||||
}
|
||||
return g_fs->fsFops->Seek(fd, offset, whence);
|
||||
}
|
||||
|
||||
int unlink(const char *path)
|
||||
{
|
||||
return fatfs_unlink(path);
|
||||
if (g_fs == NULL) {
|
||||
errno = ENODEV;
|
||||
return FS_FAILURE;
|
||||
}
|
||||
if (g_fs->fsFops == NULL || g_fs->fsFops->Unlink == NULL) {
|
||||
errno = ENOSYS;
|
||||
return FS_FAILURE;
|
||||
}
|
||||
return g_fs->fsFops->Unlink(path);
|
||||
}
|
||||
|
||||
int fstat(int fd, struct stat *buf)
|
||||
{
|
||||
return fatfs_fstat(fd, buf);
|
||||
if (g_fs == NULL) {
|
||||
errno = ENODEV;
|
||||
return FS_FAILURE;
|
||||
}
|
||||
if (g_fs->fsFops == NULL || g_fs->fsFops->Fstat == NULL) {
|
||||
errno = ENOSYS;
|
||||
return FS_FAILURE;
|
||||
}
|
||||
return g_fs->fsFops->Fstat(fd, buf);
|
||||
}
|
||||
|
||||
int stat(const char *path, struct stat *buf)
|
||||
{
|
||||
return fatfs_stat(path, buf);
|
||||
if (g_fs == NULL) {
|
||||
errno = ENODEV;
|
||||
return FS_FAILURE;
|
||||
}
|
||||
if (g_fs->fsFops == NULL || g_fs->fsFops->Stat == NULL) {
|
||||
errno = ENOSYS;
|
||||
return FS_FAILURE;
|
||||
}
|
||||
return g_fs->fsFops->Stat(path, buf);
|
||||
}
|
||||
|
||||
int fsync(int fd)
|
||||
{
|
||||
return fatfs_fsync(fd);
|
||||
if (g_fs == NULL) {
|
||||
errno = ENODEV;
|
||||
return FS_FAILURE;
|
||||
}
|
||||
if (g_fs->fsFops == NULL || g_fs->fsFops->Fsync == NULL) {
|
||||
errno = ENOSYS;
|
||||
return FS_FAILURE;
|
||||
}
|
||||
return g_fs->fsFops->Fsync(fd);
|
||||
}
|
||||
|
||||
int mkdir(const char *path, mode_t mode)
|
||||
{
|
||||
return fatfs_mkdir(path, mode);
|
||||
if (g_fs == NULL) {
|
||||
errno = ENODEV;
|
||||
return FS_FAILURE;
|
||||
}
|
||||
if (g_fs->fsFops == NULL || g_fs->fsFops->Mkdir == NULL) {
|
||||
errno = ENOSYS;
|
||||
return FS_FAILURE;
|
||||
}
|
||||
return g_fs->fsFops->Mkdir(path, mode);
|
||||
}
|
||||
|
||||
DIR *opendir(const char *dirName)
|
||||
{
|
||||
return fatfs_opendir(dirName);
|
||||
if (g_fs == NULL) {
|
||||
errno = ENODEV;
|
||||
return NULL;
|
||||
}
|
||||
if (g_fs->fsFops == NULL || g_fs->fsFops->Opendir == NULL) {
|
||||
errno = ENOSYS;
|
||||
return NULL;
|
||||
}
|
||||
return g_fs->fsFops->Opendir(dirName);
|
||||
}
|
||||
|
||||
struct dirent *readdir(DIR *dir)
|
||||
{
|
||||
return fatfs_readdir(dir);
|
||||
if (g_fs == NULL) {
|
||||
errno = ENODEV;
|
||||
return NULL;
|
||||
}
|
||||
if (g_fs->fsFops == NULL || g_fs->fsFops->Readdir == NULL) {
|
||||
errno = ENOSYS;
|
||||
return NULL;
|
||||
}
|
||||
return g_fs->fsFops->Readdir(dir);
|
||||
}
|
||||
|
||||
int closedir(DIR *dir)
|
||||
{
|
||||
return fatfs_closedir(dir);
|
||||
if (g_fs == NULL) {
|
||||
errno = ENODEV;
|
||||
return FS_FAILURE;
|
||||
}
|
||||
if (g_fs->fsFops == NULL || g_fs->fsFops->Closedir == NULL) {
|
||||
errno = ENOSYS;
|
||||
return FS_FAILURE;
|
||||
}
|
||||
return g_fs->fsFops->Closedir(dir);
|
||||
}
|
||||
|
||||
int rmdir(const char *path)
|
||||
{
|
||||
return fatfs_rmdir(path);
|
||||
if (g_fs == NULL) {
|
||||
errno = ENODEV;
|
||||
return FS_FAILURE;
|
||||
}
|
||||
if (g_fs->fsFops == NULL || g_fs->fsFops->Rmdir == NULL) {
|
||||
errno = ENOSYS;
|
||||
return FS_FAILURE;
|
||||
}
|
||||
return g_fs->fsFops->Rmdir(path);
|
||||
}
|
||||
|
||||
int rename(const char *oldName, const char *newName)
|
||||
{
|
||||
return fatfs_rename(oldName, newName);
|
||||
if (g_fs == NULL) {
|
||||
errno = ENODEV;
|
||||
return FS_FAILURE;
|
||||
}
|
||||
if (g_fs->fsFops == NULL || g_fs->fsFops->Rename == NULL) {
|
||||
errno = ENOSYS;
|
||||
return FS_FAILURE;
|
||||
}
|
||||
return g_fs->fsFops->Rename(oldName, newName);
|
||||
}
|
||||
|
||||
int statfs(const char *path, struct statfs *buf)
|
||||
{
|
||||
return fatfs_statfs(path, buf);
|
||||
if (g_fs == NULL) {
|
||||
errno = ENODEV;
|
||||
return FS_FAILURE;
|
||||
}
|
||||
if (g_fs->fsMops == NULL || g_fs->fsMops->Statfs == NULL) {
|
||||
errno = ENOSYS;
|
||||
return FS_FAILURE;
|
||||
}
|
||||
return g_fs->fsMops->Statfs(path, buf);
|
||||
}
|
||||
|
||||
int ftruncate(int fd, off_t length)
|
||||
{
|
||||
return fatfs_ftruncate(fd, length);
|
||||
if (g_fs == NULL) {
|
||||
errno = ENODEV;
|
||||
return FS_FAILURE;
|
||||
}
|
||||
if (g_fs->fsFops == NULL || g_fs->fsFops->Ftruncate == NULL) {
|
||||
errno = ENOSYS;
|
||||
return FS_FAILURE;
|
||||
}
|
||||
return g_fs->fsFops->Ftruncate(fd, length);
|
||||
}
|
|
@ -0,0 +1,80 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef _FS_OPERATIONS_H_
|
||||
#define _FS_OPERATIONS_H_
|
||||
|
||||
#include "fcntl.h"
|
||||
#include "dirent.h"
|
||||
#include "unistd.h"
|
||||
#include "sys/mount.h"
|
||||
#include "sys/stat.h"
|
||||
#include "sys/statfs.h"
|
||||
|
||||
#define FS_SUCCESS 0
|
||||
#define FS_FAILURE (-1)
|
||||
#define MAX_FILESYSTEM_LEN 2
|
||||
|
||||
struct MountOps {
|
||||
int (*Mount)(const char *source, const char *target, const char *filesystemtype, unsigned long mountflags,
|
||||
const void *data);
|
||||
int (*Umount)(const char* target);
|
||||
int (*Umount2)(const char* target, int flag);
|
||||
int (*Statfs)(const char *path, struct statfs *buf);
|
||||
};
|
||||
|
||||
struct FsMap {
|
||||
const char *fileSystemtype;
|
||||
const struct MountOps *fsMops;
|
||||
const struct FileOps *fsFops;
|
||||
};
|
||||
|
||||
struct FileOps {
|
||||
int (*Open)(const char *path, int openFlag, ...);
|
||||
int (*Close)(int fd);
|
||||
int (*Unlink)(const char *fileName);
|
||||
int (*Rmdir)(const char *dirName);
|
||||
int (*Mkdir)(const char *dirName, mode_t mode);
|
||||
struct dirent *(*Readdir)(DIR *dir);
|
||||
DIR *(*Opendir)(const char *dirName);
|
||||
int (*Closedir)(DIR *dir);
|
||||
int (*Read)(int fd, void *buf, size_t len);
|
||||
int (*Write)(int fd, const void *buf, size_t len);
|
||||
off_t (*Seek)(int fd, off_t offset, int whence);
|
||||
int (*Getattr)(const char *path, struct stat *buf);
|
||||
int (*Rename)(const char *oldName, const char *newName);
|
||||
int (*Fsync)(int fd);
|
||||
int (*Fstat)(int fd, struct stat *buf);
|
||||
int (*Stat)(const char *path, struct stat *buf);
|
||||
int (*Ftruncate)(int fd, off_t length);
|
||||
};
|
||||
|
||||
#endif /* _FS_OPERATIONS_H_ */
|
|
@ -1,5 +1,5 @@
|
|||
# Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
# Copyright (c) 2020-2021, Huawei Device Co., Ltd. All rights reserved.
|
||||
# Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without modification,
|
||||
# are permitted provided that the following conditions are met:
|
||||
|
|
|
@ -34,11 +34,11 @@
|
|||
lfs_t g_lfs;
|
||||
FileDirInfo g_lfsDir[LFS_MAX_OPEN_DIRS] = {0};
|
||||
|
||||
FileOpInfo g_fsOp;
|
||||
struct FileOpInfo g_fsOp[LFS_MAX_MOUNT_SIZE] = {0};
|
||||
static LittleFsHandleStruct g_handle[LITTLE_FS_MAX_OPEN_FILES] = {0};
|
||||
struct dirent g_nameValue;
|
||||
struct FsMap g_fsmap[MAX_FILE_SYSTEM_LEN] = {0};
|
||||
static pthread_mutex_t g_FslocalMutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
static const char *const g_littlefsMntName[LFS_MAX_MOUNT_SIZE] = {"/a","/b","/c"};
|
||||
|
||||
FileOpInfo GetFsOpInfo(void)
|
||||
{
|
||||
|
@ -47,17 +47,12 @@ FileOpInfo GetFsOpInfo(void)
|
|||
|
||||
LittleFsHandleStruct *LfsAllocFd(const char *fileName, int *fd)
|
||||
{
|
||||
int len = strlen(fileName) + 1;
|
||||
|
||||
pthread_mutex_lock(&g_FslocalMutex);
|
||||
for (int i = 0; i < LITTLE_FS_MAX_OPEN_FILES; i++) {
|
||||
if (g_handle[i].useFlag == 0) {
|
||||
*fd = i;
|
||||
g_handle[i].useFlag = 1;
|
||||
g_handle[i].pathName = (char *)malloc(len);
|
||||
if (g_handle[i].pathName) {
|
||||
memcpy_s(g_handle[i].pathName, LITTLE_FS_MAX_NAME_LEN, fileName, len);
|
||||
}
|
||||
g_handle[i].pathName = strdup(fileName);
|
||||
pthread_mutex_unlock(&g_FslocalMutex);
|
||||
return &(g_handle[i]);
|
||||
}
|
||||
|
@ -69,66 +64,248 @@ LittleFsHandleStruct *LfsAllocFd(const char *fileName, int *fd)
|
|||
|
||||
BOOL CheckFileIsOpen(const char *fileName)
|
||||
{
|
||||
pthread_mutex_lock(&g_FslocalMutex);
|
||||
for (int i = 0; i < LITTLE_FS_MAX_OPEN_FILES; i++) {
|
||||
if (g_handle[i].useFlag == 1) {
|
||||
if (strcmp(g_handle[i].pathName, fileName) == 0) {
|
||||
pthread_mutex_unlock(&g_FslocalMutex);
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&g_FslocalMutex);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
lfs_dir_t *GetFreeDir()
|
||||
FileDirInfo *GetFreeDir(const char *dirName)
|
||||
{
|
||||
pthread_mutex_lock(&g_FslocalMutex);
|
||||
for (int i = 0; i < LFS_MAX_OPEN_DIRS; i++) {
|
||||
if (g_lfsDir[i].useFlag == 0) {
|
||||
g_lfsDir[i].useFlag = 1;
|
||||
g_lfsDir[i].dirName = strdup(dirName);
|
||||
pthread_mutex_unlock(&g_FslocalMutex);
|
||||
return &(g_lfsDir[i].dir);
|
||||
return &(g_lfsDir[i]);
|
||||
}
|
||||
}
|
||||
pthread_mutex_unlock(&g_FslocalMutex);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int InitMountInfo(const char *fileSystemType, const struct MountOps *fsMops)
|
||||
void FreeDirInfo(const char *dirName)
|
||||
{
|
||||
int len = strlen(fileSystemType) + 1;
|
||||
for (int i = 0; i < MAX_FILE_SYSTEM_LEN; i++) {
|
||||
if (g_fsmap[i].fileSystemtype == NULL) {
|
||||
g_fsmap[i].fileSystemtype = (char*)malloc(len);
|
||||
memcpy_s(g_fsmap[i].fileSystemtype, LITTLE_FS_MAX_NAME_LEN, fileSystemType, len);
|
||||
g_fsmap[i].fsMops = fsMops;
|
||||
return VFS_OK;
|
||||
pthread_mutex_lock(&g_FslocalMutex);
|
||||
for (int i = 0; i < LFS_MAX_OPEN_DIRS; i++) {
|
||||
if (g_lfsDir[i].useFlag == 1 && strcmp(g_lfsDir[i].dirName, dirName) == 0) {
|
||||
g_lfsDir[i].useFlag = 0;
|
||||
if (g_lfsDir[i].dirName) {
|
||||
free(g_lfsDir[i].dirName);
|
||||
g_lfsDir[i].dirName = NULL;
|
||||
}
|
||||
pthread_mutex_unlock(&g_FslocalMutex);
|
||||
}
|
||||
}
|
||||
pthread_mutex_unlock(&g_FslocalMutex);
|
||||
}
|
||||
|
||||
BOOL CheckDirIsOpen(const char *dirName)
|
||||
{
|
||||
pthread_mutex_lock(&g_FslocalMutex);
|
||||
for (int i = 0; i < LFS_MAX_OPEN_DIRS; i++) {
|
||||
if (g_lfsDir[i].useFlag == 1) {
|
||||
if (strcmp(g_lfsDir[i].dirName, dirName) == 0) {
|
||||
pthread_mutex_unlock(&g_FslocalMutex);
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
pthread_mutex_unlock(&g_FslocalMutex);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
BOOL CheckPathIsMounted(const char *pathName, struct FileOpInfo **fileOpInfo)
|
||||
{
|
||||
char tmpName[LITTLEFS_MAX_LFN_LEN] = {0};
|
||||
int mountPathNameLen;
|
||||
int len = strlen(pathName) + 1;
|
||||
|
||||
pthread_mutex_lock(&g_FslocalMutex);
|
||||
for (int i = 0; i < LFS_MAX_MOUNT_SIZE; i++) {
|
||||
if (g_fsOp[i].useFlag == 1) {
|
||||
mountPathNameLen = strlen(g_fsOp[i].dirName);
|
||||
if (len < mountPathNameLen + 1) {
|
||||
pthread_mutex_unlock(&g_FslocalMutex);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
(void)strncpy_s(tmpName, LITTLEFS_MAX_LFN_LEN, pathName, mountPathNameLen);
|
||||
tmpName[mountPathNameLen] = '\0';
|
||||
|
||||
if (strcmp(tmpName, g_fsOp[i].dirName) == 0) {
|
||||
*fileOpInfo = &(g_fsOp[i]);
|
||||
pthread_mutex_unlock(&g_FslocalMutex);
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
pthread_mutex_unlock(&g_FslocalMutex);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
struct FileOpInfo *AllocMountRes(const char* target, struct FileOps *fileOps)
|
||||
{
|
||||
pthread_mutex_lock(&g_FslocalMutex);
|
||||
for (int i = 0; i < LFS_MAX_MOUNT_SIZE; i++) {
|
||||
if (g_fsOp[i].useFlag == 0 && strcmp(target, g_littlefsMntName[i]) == 0) {
|
||||
g_fsOp[i].useFlag = 1;
|
||||
g_fsOp[i].fsVops = fileOps;
|
||||
g_fsOp[i].dirName == strdup(target);
|
||||
pthread_mutex_unlock(&g_FslocalMutex);
|
||||
return &(g_fsOp[i]);
|
||||
}
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&g_FslocalMutex);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct FileOpInfo *GetMountRes(const char *target, int *mountIndex)
|
||||
{
|
||||
pthread_mutex_lock(&g_FslocalMutex);
|
||||
for (int i = 0; i < LFS_MAX_MOUNT_SIZE; i++) {
|
||||
if (g_fsOp[i].useFlag == 1) {
|
||||
if (g_fsOp[i].dirName && strcmp(target, g_fsOp[i].dirName) == 0) {
|
||||
*mountIndex = i;
|
||||
pthread_mutex_unlock(&g_FslocalMutex);
|
||||
return &(g_fsOp[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&g_FslocalMutex);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int FreeMountResByIndex(int mountIndex)
|
||||
{
|
||||
if (mountIndex < 0 || mountIndex >= LFS_MAX_MOUNT_SIZE) {
|
||||
return VFS_ERROR;
|
||||
}
|
||||
|
||||
pthread_mutex_lock(&g_FslocalMutex);
|
||||
if (g_fsOp[mountIndex].useFlag == 1 && g_fsOp[mountIndex].dirName != NULL) {
|
||||
g_fsOp[mountIndex].useFlag = 0;
|
||||
free(g_fsOp[mountIndex].dirName);
|
||||
g_fsOp[mountIndex].dirName = NULL;
|
||||
}
|
||||
pthread_mutex_unlock(&g_FslocalMutex);
|
||||
|
||||
return VFS_OK;
|
||||
}
|
||||
|
||||
int FreeMountRes(const char *target)
|
||||
{
|
||||
pthread_mutex_lock(&g_FslocalMutex);
|
||||
for (int i = 0; i < LFS_MAX_MOUNT_SIZE; i++) {
|
||||
if (g_fsOp[i].useFlag == 1) {
|
||||
if (g_fsOp[i].dirName && strcmp(target, g_fsOp[i].dirName) == 0) {
|
||||
g_fsOp[i].useFlag = 0;
|
||||
free(g_fsOp[i].dirName);
|
||||
g_fsOp[i].dirName = NULL;
|
||||
pthread_mutex_unlock(&g_FslocalMutex);
|
||||
return VFS_OK;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&g_FslocalMutex);
|
||||
return VFS_ERROR;
|
||||
}
|
||||
|
||||
const struct FsMap *MountFindfs(const char *fileSystemtype)
|
||||
{
|
||||
struct FsMap *m = NULL;
|
||||
|
||||
for (int i = 0; i < MAX_FILE_SYSTEM_LEN; i++) {
|
||||
m = &(g_fsmap[i]);
|
||||
if (m->fileSystemtype && strcmp(fileSystemtype, m->fileSystemtype) == 0) {
|
||||
return m;
|
||||
}
|
||||
static int ConvertFlagToLfsOpenFlag (int oflags)
|
||||
{
|
||||
int lfsOpenFlag = 0;
|
||||
|
||||
if (oflags & O_CREAT) {
|
||||
lfsOpenFlag |= LFS_O_CREAT;
|
||||
}
|
||||
|
||||
return (const struct FsMap *)NULL;
|
||||
if (oflags & O_EXCL) {
|
||||
lfsOpenFlag |= LFS_O_EXCL;
|
||||
}
|
||||
|
||||
if (oflags & O_TRUNC) {
|
||||
lfsOpenFlag |= LFS_O_TRUNC;
|
||||
}
|
||||
|
||||
if (oflags & O_APPEND) {
|
||||
lfsOpenFlag |= LFS_O_APPEND;
|
||||
}
|
||||
|
||||
if (oflags & O_RDWR) {
|
||||
lfsOpenFlag |= LFS_O_RDWR;
|
||||
}
|
||||
|
||||
if (oflags & O_WRONLY) {
|
||||
lfsOpenFlag |= LFS_O_WRONLY;
|
||||
}
|
||||
|
||||
if (oflags & O_RDONLY) {
|
||||
lfsOpenFlag |= LFS_O_RDONLY;
|
||||
}
|
||||
|
||||
return lfsOpenFlag;
|
||||
}
|
||||
|
||||
const struct MountOps g_fsMnt = {
|
||||
static int LittlefsErrno(int result)
|
||||
{
|
||||
int status = 0;
|
||||
|
||||
if (result < 0) {
|
||||
return result;
|
||||
}
|
||||
|
||||
switch (result) {
|
||||
case LFS_ERR_OK:
|
||||
break;
|
||||
case LFS_ERR_NOTDIR:
|
||||
status = ENOTDIR;
|
||||
break;
|
||||
case LFS_ERR_NOENT:
|
||||
status = ENFILE;
|
||||
break;
|
||||
case LFS_ERR_EXIST:
|
||||
status = EEXIST;
|
||||
break;
|
||||
case LFS_ERR_ISDIR:
|
||||
status = EISDIR;
|
||||
break;
|
||||
case LFS_ERR_NOTEMPTY:
|
||||
status = ENOTEMPTY;
|
||||
break;
|
||||
case LFS_ERR_INVAL:
|
||||
status = EINVAL;
|
||||
break;
|
||||
case LFS_ERR_NOSPC:
|
||||
status = ENOSPC;
|
||||
break;
|
||||
case LFS_ERR_IO:
|
||||
status = EIO;
|
||||
break;
|
||||
default:
|
||||
status = result;
|
||||
break;
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
const struct MountOps g_lfsMnt = {
|
||||
.Mount = LfsMount,
|
||||
.Umount = LfsUmount,
|
||||
};
|
||||
|
||||
const struct FileOps g_lfsVops = {
|
||||
const struct FileOps g_lfsFops = {
|
||||
.Mkdir = LfsMkdir,
|
||||
.Unlink = LfsUnlink,
|
||||
.Rmdir = LfsRmdir,
|
||||
|
@ -149,49 +326,186 @@ int LfsMount(const char *source, const char *target, const char *fileSystemType,
|
|||
const void *data)
|
||||
{
|
||||
int ret;
|
||||
struct FileOpInfo *fileOpInfo = NULL;
|
||||
|
||||
g_fsOp.fsVops = &g_lfsVops;
|
||||
ret = lfs_mount(&g_lfs, (struct lfs_config*)data);
|
||||
if (target == NULL || fileSystemType == NULL || data == NULL) {
|
||||
errno = EFAULT;
|
||||
ret = VFS_ERROR;
|
||||
goto errout;
|
||||
}
|
||||
|
||||
if (strcmp(fileSystemType, "littlefs") != 0) {
|
||||
errno = ENODEV;
|
||||
ret = VFS_ERROR;
|
||||
goto errout;
|
||||
}
|
||||
|
||||
if (CheckPathIsMounted(target, &fileOpInfo)) {
|
||||
errno = EBUSY;
|
||||
ret = VFS_OK;
|
||||
goto errout;
|
||||
}
|
||||
|
||||
// select free mount resource
|
||||
fileOpInfo = AllocMountRes(target, &g_lfsFops);
|
||||
if (fileOpInfo == NULL) {
|
||||
errno = ENODEV;
|
||||
ret = VFS_ERROR;
|
||||
goto errout;
|
||||
}
|
||||
|
||||
ret = lfs_mount(&(fileOpInfo->lfsInfo), (struct lfs_config*)data);
|
||||
if (ret != 0) {
|
||||
ret = lfs_format(&(fileOpInfo->lfsInfo), (struct lfs_config*)data);
|
||||
if (ret == 0) {
|
||||
ret = lfs_mount(&(fileOpInfo->lfsInfo), (struct lfs_config*)data);
|
||||
}
|
||||
}
|
||||
|
||||
if (ret != 0) {
|
||||
errno = LittlefsErrno(ret);
|
||||
}
|
||||
|
||||
return ret;
|
||||
errout:
|
||||
return ret;
|
||||
}
|
||||
|
||||
int LfsUmount(const char *target)
|
||||
{
|
||||
return lfs_unmount(&g_lfs);
|
||||
int ret;
|
||||
int mountIndex = -1;
|
||||
struct FileOpInfo *fileOpInfo = NULL;
|
||||
|
||||
if (target == NULL) {
|
||||
errno = EFAULT;
|
||||
return VFS_ERROR;
|
||||
}
|
||||
|
||||
fileOpInfo = GetMountRes(target, &mountIndex);
|
||||
if (fileOpInfo == NULL) {
|
||||
errno = ENOENT;
|
||||
return VFS_ERROR;
|
||||
}
|
||||
|
||||
ret = lfs_unmount(&(fileOpInfo->lfsInfo));
|
||||
if (ret != 0) {
|
||||
errno = LittlefsErrno(ret);
|
||||
}
|
||||
|
||||
(void)FreeMountResByIndex(mountIndex);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int LfsUnlink(const char *fileName)
|
||||
{
|
||||
return lfs_remove(&g_lfs, fileName);
|
||||
int ret;
|
||||
struct FileOpInfo *fileOpInfo = NULL;
|
||||
|
||||
if (fileName == NULL) {
|
||||
errno = EFAULT;
|
||||
return VFS_ERROR;
|
||||
}
|
||||
|
||||
if (CheckPathIsMounted(fileName, &fileOpInfo) == FALSE || fileOpInfo == NULL) {
|
||||
errno = EACCES;
|
||||
return VFS_ERROR;
|
||||
}
|
||||
|
||||
ret = lfs_remove(&(fileOpInfo->lfsInfo), fileName);
|
||||
if (ret != 0) {
|
||||
errno = LittlefsErrno(ret);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int LfsMkdir(const char *dirName, mode_t mode)
|
||||
{
|
||||
return lfs_mkdir(&g_lfs, dirName);
|
||||
int ret;
|
||||
struct FileOpInfo *fileOpInfo = NULL;
|
||||
|
||||
if (dirName == NULL) {
|
||||
errno = EFAULT;
|
||||
return VFS_ERROR;
|
||||
}
|
||||
|
||||
if (CheckPathIsMounted(dirName, &fileOpInfo) == FALSE || fileOpInfo == NULL) {
|
||||
errno = EACCES;
|
||||
return VFS_ERROR;
|
||||
}
|
||||
|
||||
ret = lfs_mkdir(&(fileOpInfo->lfsInfo), dirName);
|
||||
if (ret != 0) {
|
||||
errno = LittlefsErrno(ret);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int LfsRmdir(const char *dirName)
|
||||
{
|
||||
return lfs_remove(&g_lfs, dirName);
|
||||
int ret;
|
||||
|
||||
struct FileOpInfo *fileOpInfo = NULL;
|
||||
|
||||
if (dirName == NULL) {
|
||||
errno = EFAULT;
|
||||
return VFS_ERROR;
|
||||
}
|
||||
|
||||
if (CheckPathIsMounted(dirName, &fileOpInfo) == FALSE || fileOpInfo == NULL) {
|
||||
errno = EACCES;
|
||||
return VFS_ERROR;
|
||||
}
|
||||
|
||||
ret = lfs_remove(&(fileOpInfo->lfsInfo), dirName);
|
||||
if (ret != 0) {
|
||||
errno = LittlefsErrno(ret);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
DIR *LfsOpendir(const char *dirName)
|
||||
{
|
||||
int ret;
|
||||
struct FileOpInfo *fileOpInfo = NULL;
|
||||
|
||||
lfs_dir_t *dir = GetFreeDir();
|
||||
if (dir == NULL) {
|
||||
return NULL;
|
||||
if (dirName == NULL) {
|
||||
errno = EFAULT;
|
||||
goto errout;
|
||||
}
|
||||
|
||||
ret = lfs_dir_open(&g_lfs, dir, dirName);
|
||||
|
||||
if (ret == 0) {
|
||||
return (DIR *)dir;
|
||||
} else {
|
||||
return NULL;
|
||||
if (CheckPathIsMounted(dirName, &fileOpInfo) == FALSE || fileOpInfo == NULL) {
|
||||
errno = EACCES;
|
||||
goto errout;
|
||||
}
|
||||
|
||||
if (CheckDirIsOpen(dirName)) {
|
||||
errno = EBUSY;
|
||||
goto errout;
|
||||
}
|
||||
|
||||
FileDirInfo *dirInfo = GetFreeDir(dirName);
|
||||
if (dirInfo == NULL) {
|
||||
errno = ENFILE;
|
||||
goto errout;
|
||||
}
|
||||
|
||||
ret = lfs_dir_open(&(fileOpInfo->lfsInfo), (lfs_dir_t *)(&(dirInfo->dir)), dirName);
|
||||
|
||||
if (ret != 0) {
|
||||
errno = LittlefsErrno(ret);
|
||||
goto errout;
|
||||
}
|
||||
|
||||
dirInfo->lfsHandle = &(fileOpInfo->lfsInfo);
|
||||
|
||||
return (DIR *)dirInfo;
|
||||
|
||||
errout:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct dirent *LfsReaddir(DIR *dir)
|
||||
|
@ -199,10 +513,17 @@ struct dirent *LfsReaddir(DIR *dir)
|
|||
int ret;
|
||||
struct lfs_info lfsInfo;
|
||||
|
||||
ret = lfs_dir_read(&g_lfs, (lfs_dir_t *)dir, &lfsInfo);
|
||||
FileDirInfo *dirInfo = (FileDirInfo *)dir;
|
||||
|
||||
if (dirInfo == NULL || dirInfo->lfsHandle == NULL) {
|
||||
errno = EFAULT;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ret = lfs_dir_read(dirInfo->lfsHandle, (lfs_dir_t *)(&(dirInfo->dir)), &lfsInfo);
|
||||
if (ret == 0) {
|
||||
pthread_mutex_lock(&g_FslocalMutex);
|
||||
(void)memcpy_s(g_nameValue.d_name, sizeof(g_nameValue.d_name), lfsInfo.name, strlen(lfsInfo.name) + 1);
|
||||
(void)strncpy_s(g_nameValue.d_name, sizeof(g_nameValue.d_name), lfsInfo.name, strlen(lfsInfo.name) + 1);
|
||||
if (lfsInfo.type == LFS_TYPE_DIR) {
|
||||
g_nameValue.d_type = DT_DIR;
|
||||
} else if (lfsInfo.type == LFS_TYPE_REG) {
|
||||
|
@ -215,98 +536,214 @@ struct dirent *LfsReaddir(DIR *dir)
|
|||
return &g_nameValue;
|
||||
}
|
||||
|
||||
if (ret != 0) {
|
||||
errno = LittlefsErrno(ret);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int LfsClosedir(const DIR *dir)
|
||||
{
|
||||
return lfs_dir_close(&g_lfs, (lfs_dir_t *)dir);
|
||||
int ret;
|
||||
FileDirInfo *dirInfo = (FileDirInfo *)dir;
|
||||
|
||||
if (dirInfo == NULL || dirInfo->lfsHandle == NULL) {
|
||||
errno = EFAULT;
|
||||
return VFS_ERROR;
|
||||
}
|
||||
|
||||
ret = lfs_dir_close(dirInfo->lfsHandle, (lfs_dir_t *)(&(dirInfo->dir)));
|
||||
|
||||
FreeDirInfo(dirInfo->dirName);
|
||||
|
||||
if (ret != 0) {
|
||||
errno = LittlefsErrno(ret);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int LfsOpen(const char *pathName, int openFlag, int mode)
|
||||
{
|
||||
int fd = INVALID_FD;
|
||||
int err = INVALID_FD;
|
||||
|
||||
struct FileOpInfo *fileOpInfo = NULL;
|
||||
|
||||
if (pathName == NULL) {
|
||||
errno = EFAULT;
|
||||
goto errout;
|
||||
}
|
||||
|
||||
if (CheckPathIsMounted(pathName, &fileOpInfo) == FALSE || fileOpInfo == NULL) {
|
||||
errno = EACCES;
|
||||
goto errout;
|
||||
}
|
||||
// if file is already open, return invalid fd
|
||||
if (pathName == NULL || CheckFileIsOpen(pathName)) {
|
||||
if (CheckFileIsOpen(pathName)) {
|
||||
errno = EBUSY;
|
||||
goto errout;
|
||||
}
|
||||
|
||||
LittleFsHandleStruct *fsHandle = LfsAllocFd(pathName, &fd);
|
||||
if (fd == INVALID_FD) {
|
||||
errno = ENFILE;
|
||||
goto errout;
|
||||
}
|
||||
|
||||
int err = lfs_file_open(&g_lfs, &(fsHandle->file), pathName, openFlag);
|
||||
int lfsOpenFlag = ConvertFlagToLfsOpenFlag(openFlag);
|
||||
err = lfs_file_open(&(fileOpInfo->lfsInfo), &(fsHandle->file), pathName, lfsOpenFlag);
|
||||
if (err != 0) {
|
||||
errno = LittlefsErrno(err);
|
||||
goto errout;
|
||||
}
|
||||
|
||||
g_handle[fd].lfsHandle = &(fileOpInfo->lfsInfo);
|
||||
return fd;
|
||||
errout:
|
||||
return INVALID_FD;
|
||||
return err;
|
||||
}
|
||||
|
||||
int LfsRead(int fd, void *buf, unsigned int len)
|
||||
{
|
||||
if (fd >= LITTLE_FS_MAX_OPEN_FILES && fd < 0) {
|
||||
int ret;
|
||||
if (fd >= LITTLE_FS_MAX_OPEN_FILES || fd < 0 || buf == NULL) {
|
||||
errno = EFAULT;
|
||||
return VFS_ERROR;
|
||||
}
|
||||
|
||||
return lfs_file_read(&g_lfs, &(g_handle[fd].file), buf, len);
|
||||
if (g_handle[fd].lfsHandle == NULL) {
|
||||
errno = EBADF;
|
||||
return VFS_ERROR;
|
||||
}
|
||||
|
||||
ret = lfs_file_read(g_handle[fd].lfsHandle, &(g_handle[fd].file), buf, len);
|
||||
if (ret != 0) {
|
||||
errno = LittlefsErrno(ret);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int LfsWrite(int fd, const void *buf, unsigned int len)
|
||||
{
|
||||
if (fd >= LITTLE_FS_MAX_OPEN_FILES && fd < 0) {
|
||||
int ret;
|
||||
if (fd >= LITTLE_FS_MAX_OPEN_FILES || fd < 0 || buf == NULL) {
|
||||
errno = EFAULT;
|
||||
return VFS_ERROR;
|
||||
}
|
||||
|
||||
return lfs_file_write(&g_lfs, &(g_handle[fd].file), buf, len);
|
||||
if (g_handle[fd].lfsHandle == NULL) {
|
||||
errno = EBADF;
|
||||
return VFS_ERROR;
|
||||
}
|
||||
|
||||
ret = lfs_file_write(g_handle[fd].lfsHandle, &(g_handle[fd].file), buf, len);
|
||||
if (ret != 0) {
|
||||
errno = LittlefsErrno(ret);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int LfsSeek(int fd, off_t offset, int whence)
|
||||
{
|
||||
if (fd >= LITTLE_FS_MAX_OPEN_FILES && fd < 0) {
|
||||
int ret;
|
||||
if (fd >= LITTLE_FS_MAX_OPEN_FILES || fd < 0) {
|
||||
errno = EFAULT;
|
||||
return VFS_ERROR;
|
||||
}
|
||||
|
||||
return lfs_file_seek(&g_lfs, &(g_handle[fd].file), offset, whence);
|
||||
if (g_handle[fd].lfsHandle == NULL) {
|
||||
errno = EBADF;
|
||||
return VFS_ERROR;
|
||||
}
|
||||
|
||||
ret = lfs_file_seek(g_handle[fd].lfsHandle, &(g_handle[fd].file), offset, whence);
|
||||
if (ret != 0) {
|
||||
errno = LittlefsErrno(ret);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int LfsClose(int fd)
|
||||
{
|
||||
int ret = VFS_ERROR;
|
||||
|
||||
if (fd >= LITTLE_FS_MAX_OPEN_FILES && fd < 0) {
|
||||
if (fd >= LITTLE_FS_MAX_OPEN_FILES || fd < 0) {
|
||||
errno = EFAULT;
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (g_handle[fd].lfsHandle == NULL) {
|
||||
errno = EBADF;
|
||||
return VFS_ERROR;
|
||||
}
|
||||
|
||||
pthread_mutex_lock(&g_FslocalMutex);
|
||||
ret = lfs_file_close(&g_lfs, &(g_handle[fd].file));
|
||||
ret = lfs_file_close(g_handle[fd].lfsHandle, &(g_handle[fd].file));
|
||||
g_handle[fd].useFlag = 0;
|
||||
if (g_handle[fd].pathName != NULL) {
|
||||
if (g_handle[fd].pathName != NULL) {
|
||||
free(g_handle[fd].pathName);
|
||||
g_handle[fd].pathName = NULL;
|
||||
}
|
||||
|
||||
if (g_handle[fd].lfsHandle != NULL) {
|
||||
g_handle[fd].lfsHandle = NULL;
|
||||
}
|
||||
pthread_mutex_unlock(&g_FslocalMutex);
|
||||
|
||||
if (ret != 0) {
|
||||
errno = LittlefsErrno(ret);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int LfsRename(const char *oldName, const char *newName)
|
||||
{
|
||||
return lfs_rename(&g_lfs, oldName, newName);
|
||||
int ret;
|
||||
struct FileOpInfo *fileOpInfo = NULL;
|
||||
|
||||
if (oldName == NULL || newName == NULL) {
|
||||
errno = EFAULT;
|
||||
return VFS_ERROR;
|
||||
}
|
||||
|
||||
if (CheckPathIsMounted(oldName, &fileOpInfo) == FALSE || fileOpInfo == NULL) {
|
||||
errno = EACCES;
|
||||
return VFS_ERROR;
|
||||
}
|
||||
|
||||
ret = lfs_rename(&(fileOpInfo->lfsInfo), oldName, newName);
|
||||
if (ret != 0) {
|
||||
errno = LittlefsErrno(ret);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int LfsStat(const char *path, struct stat *buf)
|
||||
{
|
||||
int ret;
|
||||
struct lfs_info info;
|
||||
struct FileOpInfo *fileOpInfo = NULL;
|
||||
|
||||
ret = lfs_stat(&g_lfs, path, &info);
|
||||
if (path == NULL || buf == NULL) {
|
||||
errno = EFAULT;
|
||||
return VFS_ERROR;
|
||||
}
|
||||
|
||||
if (CheckPathIsMounted(path, &fileOpInfo) == FALSE || fileOpInfo == NULL) {
|
||||
errno = EACCES;
|
||||
return VFS_ERROR;
|
||||
}
|
||||
|
||||
ret = lfs_stat(&(fileOpInfo->lfsInfo), path, &info);
|
||||
if (ret == 0) {
|
||||
buf->st_size = info.size;
|
||||
} else {
|
||||
errno = LittlefsErrno(ret);
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
@ -314,6 +751,22 @@ int LfsStat(const char *path, struct stat *buf)
|
|||
|
||||
int LfsFsync(int fd)
|
||||
{
|
||||
return lfs_file_sync(&g_lfs, &(g_handle[fd].file));
|
||||
int ret;
|
||||
|
||||
if (fd >= LITTLE_FS_MAX_OPEN_FILES || fd < 0) {
|
||||
errno = EFAULT;
|
||||
return VFS_ERROR;
|
||||
}
|
||||
|
||||
if (g_handle[fd].lfsHandle == NULL) {
|
||||
errno = EACCES;
|
||||
return VFS_ERROR;
|
||||
}
|
||||
|
||||
ret = lfs_file_sync(g_handle[fd].lfsHandle, &(g_handle[fd].file));
|
||||
if (ret != 0) {
|
||||
errno = LittlefsErrno(ret);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
|
@ -33,9 +33,11 @@
|
|||
#define _LFS_API_H_
|
||||
|
||||
#include "bits/alltypes.h"
|
||||
#include "fcntl.h"
|
||||
#include "sys/stat.h"
|
||||
|
||||
#include "dirent.h"
|
||||
#include "errno.h"
|
||||
#include "lfs.h"
|
||||
#include "lfs_util.h"
|
||||
#include "memory.h"
|
||||
|
@ -56,43 +58,21 @@ typedef unsigned mode_t;
|
|||
typedef struct {
|
||||
uint8_t useFlag;
|
||||
const char *pathName;
|
||||
lfs_t *lfsHandle;
|
||||
lfs_file_t file;
|
||||
} LittleFsHandleStruct;
|
||||
|
||||
struct MountOps {
|
||||
int (*Mount)(const char *source, const char *target, const char *filesystemtype, unsigned long mountflags,
|
||||
const void *data);
|
||||
int (*Umount)(const char* target);
|
||||
};
|
||||
|
||||
struct FsMap {
|
||||
const char *fileSystemtype;
|
||||
const struct MountOps *fsMops;
|
||||
};
|
||||
|
||||
struct FileOps {
|
||||
int (*Open)(const char *path, int openFlag, int mode);
|
||||
int (*Close)(int fd);
|
||||
int (*Unlink)(const char *fileName);
|
||||
int (*Rmdir)(const char *dirName);
|
||||
int (*Mkdir)(const char *dirName, mode_t mode);
|
||||
struct dirent *(*Readdir)(DIR *dir);
|
||||
DIR *(*Opendir)(const char *dirName);
|
||||
int (*Closedir)(const DIR *dir);
|
||||
int (*Read)(int fd, void *buf, size_t len);
|
||||
int (*Write)(int fd, const void *buf, size_t len);
|
||||
int (*Seek)(int fd, off_t offset, int whence);
|
||||
int (*Getattr)(const char *path, struct stat *buf);
|
||||
int (*Rename)(const char *oldName, const char *newName);
|
||||
int (*Fsync)(int fd);
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
struct FileOpInfo {
|
||||
uint8_t useFlag;
|
||||
struct FileOps *fsVops;
|
||||
} FileOpInfo;
|
||||
char *dirName;
|
||||
lfs_t lfsInfo;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
uint8_t useFlag;
|
||||
char *dirName;
|
||||
lfs_t *lfsHandle;
|
||||
lfs_dir_t dir;
|
||||
} FileDirInfo;
|
||||
|
||||
|
@ -104,12 +84,17 @@ typedef struct {
|
|||
#define MAX_BUFFER_LEN 100
|
||||
#define MAX_WRITE_FILE_LEN 500
|
||||
#define MAX_READ_FILE_LEN 500
|
||||
#define MAX_FILE_SYSTEM_LEN 2
|
||||
#define LITTLEFS_MAX_LFN_LEN 255
|
||||
|
||||
#ifndef LFS_MAX_OPEN_DIRS
|
||||
#define LFS_MAX_OPEN_DIRS 10
|
||||
#endif
|
||||
|
||||
#ifndef LFS_MAX_MOUNT_SIZE
|
||||
#define LFS_MAX_MOUNT_SIZE 3
|
||||
#endif
|
||||
|
||||
|
||||
LittleFsHandleStruct *GetFreeFd(int *fd);
|
||||
|
||||
int InitMountInfo(const char *fileSystemType, const struct MountOps *fsMops);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
# Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
# Copyright (c) 2020-2021, Huawei Device Co., Ltd. All rights reserved.
|
||||
# Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without modification,
|
||||
# are permitted provided that the following conditions are met:
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
# Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
# Copyright (c) 2020-2021, Huawei Device Co., Ltd. All rights reserved.
|
||||
# Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without modification,
|
||||
# are permitted provided that the following conditions are met:
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
../../../../third_party/cmsis/CMSIS/RTOS2/Include/cmsis_os2.h
|
|
@ -0,0 +1,32 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "../../../../third_party/cmsis/CMSIS/RTOS2/Include/cmsis_os2.h"
|
|
@ -1,5 +1,5 @@
|
|||
# Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
# Copyright (c) 2020-2021, Huawei Device Co., Ltd. All rights reserved.
|
||||
# Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without modification,
|
||||
# are permitted provided that the following conditions are met:
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#define _Int64 long long
|
||||
#define _Reg int
|
||||
|
||||
#if __ARMEB__
|
||||
#ifdef __ARMEB__
|
||||
#define __BYTE_ORDER 4321
|
||||
#else
|
||||
#define __BYTE_ORDER 1234
|
||||
|
|
|
@ -27,7 +27,7 @@ struct rlimit {
|
|||
struct rusage {
|
||||
struct timeval ru_utime;
|
||||
struct timeval ru_stime;
|
||||
/* linux extentions, but useful */
|
||||
/* linux extensions, but useful */
|
||||
long ru_maxrss;
|
||||
long ru_ixrss;
|
||||
long ru_idrss;
|
||||
|
|
|
@ -6,6 +6,11 @@
|
|||
#include <string.h>
|
||||
#include <pthread.h>
|
||||
|
||||
int ioctl(int fd, int req, ...)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
FILE *__fdopen(int fd, const char *mode)
|
||||
{
|
||||
FILE *f;
|
||||
|
|
|
@ -4,10 +4,10 @@
|
|||
static void dummy(FILE *f) { }
|
||||
weak_alias(dummy, __unlist_locked_file);
|
||||
|
||||
int fclose(FILE *f)
|
||||
int __fclose(FILE *f)
|
||||
{
|
||||
int r;
|
||||
|
||||
|
||||
FLOCK(f);
|
||||
r = fflush(f);
|
||||
r |= f->close(f);
|
||||
|
@ -34,3 +34,4 @@ int fclose(FILE *f)
|
|||
|
||||
return r;
|
||||
}
|
||||
weak_alias(__fclose, fclose);
|
|
@ -5,16 +5,16 @@ static FILE *volatile dummy = 0;
|
|||
weak_alias(dummy, __stdout_used);
|
||||
weak_alias(dummy, __stderr_used);
|
||||
|
||||
int fflush(FILE *f)
|
||||
int __fflush(FILE *f)
|
||||
{
|
||||
if (!f) {
|
||||
int r = 0;
|
||||
if (__stdout_used) r |= fflush(__stdout_used);
|
||||
if (__stderr_used) r |= fflush(__stderr_used);
|
||||
if (__stdout_used) r |= __fflush(__stdout_used);
|
||||
if (__stderr_used) r |= __fflush(__stderr_used);
|
||||
|
||||
for (f=*__ofl_lock(); f; f=f->next) {
|
||||
FLOCK(f);
|
||||
if (f->wpos != f->wbase) r |= fflush(f);
|
||||
if (f->wpos != f->wbase) r |= __fflush(f);
|
||||
FUNLOCK(f);
|
||||
}
|
||||
__ofl_unlock();
|
||||
|
@ -45,3 +45,4 @@ int fflush(FILE *f)
|
|||
}
|
||||
|
||||
weak_alias(fflush, fflush_unlocked);
|
||||
weak_alias(__fflush, fflush);
|
||||
|
|
|
@ -15,12 +15,12 @@ int __fseeko_unlocked(FILE *f, off_t off, int whence)
|
|||
f->wpos = f->wbase = f->wend = 0;
|
||||
|
||||
/* Perform the underlying seek. */
|
||||
if (lseek(f->fd, (unsigned int)off, whence) < 0) return -1;
|
||||
if (lseek(f->fd, off, whence) < 0) return -1;
|
||||
|
||||
/* If seek succeeded, file is seekable and we discard read buffer. */
|
||||
f->rpos = f->rend = 0;
|
||||
f->flags &= ~F_EOF;
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "stdio_impl.h"
|
||||
|
||||
int __wrap_fclose(FILE *f)
|
||||
{
|
||||
return __fclose(f);
|
||||
}
|
||||
|
||||
int __wrap_fflush(FILE *f)
|
||||
{
|
||||
return __fflush(f);
|
||||
}
|
|
@ -137,9 +137,5 @@ struct mqpersonal {
|
|||
UINT32 mq_status;
|
||||
UINT32 mq_refcount;
|
||||
};
|
||||
#ifdef LOSCFG_BASE_IPC_QUEUE_LIMIT
|
||||
#undef LOSCFG_BASE_IPC_QUEUE_LIMIT
|
||||
#define LOSCFG_BASE_IPC_QUEUE_LIMIT 20
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
|
@ -188,7 +188,8 @@ int timer_settime(timer_t timerID, int flags,
|
|||
intSave = LOS_IntLock();
|
||||
swtmr = OS_SWT_FROM_SID(swtmrID);
|
||||
swtmr->ucMode = (interval ? LOS_SWTMR_MODE_PERIOD : LOS_SWTMR_MODE_NO_SELFDELETE);
|
||||
swtmr->uwInterval = interval;
|
||||
swtmr->uwInterval = (interval ? interval : expiry);
|
||||
|
||||
LOS_IntRestore(intSave);
|
||||
|
||||
if ((value->it_value.tv_sec == 0) && (value->it_value.tv_nsec == 0)) {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
# Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
# Copyright (c) 2020-2021, Huawei Device Co., Ltd. All rights reserved.
|
||||
# Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without modification,
|
||||
# are permitted provided that the following conditions are met:
|
||||
|
|
|
@ -687,7 +687,7 @@ VOID HalHwiInit();
|
|||
typedef struct TagExcInfo {
|
||||
/**< Exception occurrence phase: 0 means that an exception occurs in initialization, 1 means that an exception occurs in a task, and 2 means that an exception occurs in an interrupt */
|
||||
UINT16 phase;
|
||||
/**< Exception type. When exceptions occur, check the numbers 1 - 19 listed above */
|
||||
/**< Exception type. When exceptions occur, check the numbers 1 - 21 listed above */
|
||||
UINT16 type;
|
||||
/**< If the exact address access error indicates the wrong access address when the exception occurred */
|
||||
UINT32 faultAddr;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
# Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
# Copyright (c) 2020-2021, Huawei Device Co., Ltd. All rights reserved.
|
||||
# Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without modification,
|
||||
# are permitted provided that the following conditions are met:
|
||||
|
|
|
@ -687,7 +687,7 @@ VOID HalHwiInit();
|
|||
typedef struct TagExcInfo {
|
||||
/**< Exception occurrence phase: 0 means that an exception occurs in initialization, 1 means that an exception occurs in a task, and 2 means that an exception occurs in an interrupt */
|
||||
UINT16 phase;
|
||||
/**< Exception type. When exceptions occur, check the numbers 1 - 19 listed above */
|
||||
/**< Exception type. When exceptions occur, check the numbers 1 - 21 listed above */
|
||||
UINT16 type;
|
||||
/**< If the exact address access error indicates the wrong access address when the exception occurred */
|
||||
UINT32 faultAddr;
|
||||
|
|
|
@ -0,0 +1,158 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef LOS_ATOMIC_H
|
||||
#define LOS_ATOMIC_H
|
||||
|
||||
#include "los_compiler.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/**
|
||||
* @ingroup los_atomic
|
||||
* @brief Atomic exchange for 32-bit variable.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to implement the atomic exchange for 32-bit variable and return the previous value of the atomic variable.
|
||||
* @attention
|
||||
* <ul>The pointer v must not be NULL.</ul>
|
||||
*
|
||||
* @param v [IN] The variable pointer.
|
||||
* @param val [IN] The exchange value.
|
||||
*
|
||||
* @retval #INT32 The previous value of the atomic variable
|
||||
* @par Dependency:
|
||||
* <ul><li>los_atomic.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see
|
||||
*/
|
||||
STATIC INLINE INT32 HalAtomicXchg32bits(volatile INT32 *v, INT32 val)
|
||||
{
|
||||
INT32 prevVal = 0;
|
||||
UINT32 status = 0;
|
||||
|
||||
do {
|
||||
__asm__ __volatile__("ldrex %0, [%3]\n"
|
||||
"strex %1, %4, [%3]"
|
||||
: "=&r"(prevVal), "=&r"(status), "+m"(*v)
|
||||
: "r"(v), "r"(val)
|
||||
: "cc");
|
||||
} while (__builtin_expect(status != 0, 0));
|
||||
|
||||
return prevVal;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ingroup los_atomic
|
||||
* @brief Atomic auto-decrement.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to implementating the atomic auto-decrement and return the result of auto-decrement.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>The pointer v must not be NULL.</li>
|
||||
* <li>The value which v point to must not be INT_MIN to avoid overflow after reducing 1.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param v [IN] The addSelf variable pointer.
|
||||
*
|
||||
* @retval #INT32 The return value of variable auto-decrement.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_atomic.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see
|
||||
*/
|
||||
STATIC INLINE INT32 HalAtomicDecRet(volatile INT32 *v)
|
||||
{
|
||||
INT32 val = 0;
|
||||
UINT32 status = 0;
|
||||
|
||||
do {
|
||||
__asm__ __volatile__("ldrex %0, [%3]\n"
|
||||
"sub %0, %0, #1\n"
|
||||
"strex %1, %0, [%3]"
|
||||
: "=&r"(val), "=&r"(status), "+m"(*v)
|
||||
: "r"(v)
|
||||
: "cc");
|
||||
} while (__builtin_expect(status != 0, 0));
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ingroup los_atomic
|
||||
* @brief Atomic exchange for 32-bit variable with compare.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to implement the atomic exchange for 32-bit variable, if the value of variable is equal to oldVal.
|
||||
* @attention
|
||||
* <ul>The pointer v must not be NULL.</ul>
|
||||
*
|
||||
* @param v [IN] The variable pointer.
|
||||
* @param val [IN] The new value.
|
||||
* @param oldVal [IN] The old value.
|
||||
*
|
||||
* @retval TRUE The previous value of the atomic variable is not equal to oldVal.
|
||||
* @retval FALSE The previous value of the atomic variable is equal to oldVal.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_atomic.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see
|
||||
*/
|
||||
STATIC INLINE BOOL HalAtomicCmpXchg32bits(volatile INT32 *v, INT32 val, INT32 oldVal)
|
||||
{
|
||||
INT32 prevVal = 0;
|
||||
UINT32 status = 0;
|
||||
|
||||
do {
|
||||
__asm__ __volatile__("1: ldrex %0, %2\n"
|
||||
" mov %1, #0\n"
|
||||
" cmp %0, %3\n"
|
||||
" bne 2f\n"
|
||||
" strex %1, %4, %2\n"
|
||||
"2:"
|
||||
: "=&r"(prevVal), "=&r"(status), "+Q"(*v)
|
||||
: "r"(oldVal), "r"(val)
|
||||
: "cc");
|
||||
} while (__builtin_expect(status != 0, 0));
|
||||
|
||||
return prevVal != oldVal;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* LOS_ATOMIC_H */
|
||||
|
|
@ -0,0 +1,131 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef _LOS_ARCH_CONTEXT_H
|
||||
#define _LOS_ARCH_CONTEXT_H
|
||||
|
||||
#include "los_config.h"
|
||||
#include "los_compiler.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
typedef struct TagTskContext {
|
||||
#if ((defined(__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \
|
||||
(defined(__FPU_USED) && (__FPU_USED == 1U)))
|
||||
UINT32 S16;
|
||||
UINT32 S17;
|
||||
UINT32 S18;
|
||||
UINT32 S19;
|
||||
UINT32 S20;
|
||||
UINT32 S21;
|
||||
UINT32 S22;
|
||||
UINT32 S23;
|
||||
UINT32 S24;
|
||||
UINT32 S25;
|
||||
UINT32 S26;
|
||||
UINT32 S27;
|
||||
UINT32 S28;
|
||||
UINT32 S29;
|
||||
UINT32 S30;
|
||||
UINT32 S31;
|
||||
#endif
|
||||
UINT32 uwR4;
|
||||
UINT32 uwR5;
|
||||
UINT32 uwR6;
|
||||
UINT32 uwR7;
|
||||
UINT32 uwR8;
|
||||
UINT32 uwR9;
|
||||
UINT32 uwR10;
|
||||
UINT32 uwR11;
|
||||
UINT32 uwPriMask;
|
||||
UINT32 uwR0;
|
||||
UINT32 uwR1;
|
||||
UINT32 uwR2;
|
||||
UINT32 uwR3;
|
||||
UINT32 uwR12;
|
||||
UINT32 uwLR;
|
||||
UINT32 uwPC;
|
||||
UINT32 uwxPSR;
|
||||
#if ((defined(__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \
|
||||
(defined(__FPU_USED) && (__FPU_USED == 1U)))
|
||||
UINT32 S0;
|
||||
UINT32 S1;
|
||||
UINT32 S2;
|
||||
UINT32 S3;
|
||||
UINT32 S4;
|
||||
UINT32 S5;
|
||||
UINT32 S6;
|
||||
UINT32 S7;
|
||||
UINT32 S8;
|
||||
UINT32 S9;
|
||||
UINT32 S10;
|
||||
UINT32 S11;
|
||||
UINT32 S12;
|
||||
UINT32 S13;
|
||||
UINT32 S14;
|
||||
UINT32 S15;
|
||||
UINT32 FPSCR;
|
||||
UINT32 NO_NAME;
|
||||
#endif
|
||||
} TaskContext;
|
||||
|
||||
/**
|
||||
* @ingroup los_config
|
||||
* @brief: Task start running function.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to start a task.
|
||||
*
|
||||
* @attention:
|
||||
* <ul><li>None.</li></ul>
|
||||
*
|
||||
* @param: None.
|
||||
*
|
||||
* @retval None.
|
||||
*
|
||||
* @par Dependency:
|
||||
* <ul><li>los_config.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see None.
|
||||
*/
|
||||
extern VOID HalStartToRun(VOID);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _LOS_ARCH_CONTEXT_H */
|
||||
|
|
@ -0,0 +1,717 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef _LOS_EXC_H
|
||||
#define _LOS_EXC_H
|
||||
|
||||
#include "los_config.h"
|
||||
#include "los_compiler.h"
|
||||
#include "los_interrupt.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Maximum number of used hardware interrupts.
|
||||
*/
|
||||
#ifndef OS_HWI_MAX_NUM
|
||||
#define OS_HWI_MAX_NUM LOSCFG_PLATFORM_HWI_LIMIT
|
||||
#endif
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Highest priority of a hardware interrupt.
|
||||
*/
|
||||
#ifndef OS_HWI_PRIO_HIGHEST
|
||||
#define OS_HWI_PRIO_HIGHEST 0
|
||||
#endif
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Lowest priority of a hardware interrupt.
|
||||
*/
|
||||
#ifndef OS_HWI_PRIO_LOWEST
|
||||
#define OS_HWI_PRIO_LOWEST 7
|
||||
#endif
|
||||
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Define the type of a hardware interrupt vector table function.
|
||||
*/
|
||||
typedef VOID (**HWI_VECTOR_FUNC)(void);
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Count of interrupts.
|
||||
*/
|
||||
extern UINT32 g_intCount;
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Count of M-Core system interrupt vector.
|
||||
*/
|
||||
#define OS_SYS_VECTOR_CNT 16
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Count of M-Core interrupt vector.
|
||||
*/
|
||||
#define OS_VECTOR_CNT (OS_SYS_VECTOR_CNT + OS_HWI_MAX_NUM)
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* AIRCR register priority group parameter .
|
||||
*/
|
||||
#define OS_NVIC_AIRCR_PRIGROUP 7
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Boot interrupt vector table.
|
||||
*/
|
||||
extern UINT32 _BootVectors[];
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Hardware interrupt error code: Invalid interrupt number.
|
||||
*
|
||||
* Value: 0x02000900
|
||||
*
|
||||
* Solution: Ensure that the interrupt number is valid. The value range of the interrupt number applicable for a Cortex-A7 platform is [OS_USER_HWI_MIN,OS_USER_HWI_MAX].
|
||||
*/
|
||||
#define OS_ERRNO_HWI_NUM_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x00)
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Hardware interrupt error code: Null hardware interrupt handling function.
|
||||
*
|
||||
* Value: 0x02000901
|
||||
*
|
||||
* Solution: Pass in a valid non-null hardware interrupt handling function.
|
||||
*/
|
||||
#define OS_ERRNO_HWI_PROC_FUNC_NULL LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x01)
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Hardware interrupt error code: Insufficient interrupt resources for hardware interrupt creation.
|
||||
*
|
||||
* Value: 0x02000902
|
||||
*
|
||||
* Solution: Increase the configured maximum number of supported hardware interrupts.
|
||||
*/
|
||||
#define OS_ERRNO_HWI_CB_UNAVAILABLE LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x02)
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Hardware interrupt error code: Insufficient memory for hardware interrupt initialization.
|
||||
*
|
||||
* Value: 0x02000903
|
||||
*
|
||||
* Solution: Expand the configured memory.
|
||||
*/
|
||||
#define OS_ERRNO_HWI_NO_MEMORY LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x03)
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Hardware interrupt error code: The interrupt has already been created.
|
||||
*
|
||||
* Value: 0x02000904
|
||||
*
|
||||
* Solution: Check whether the interrupt specified by the passed-in interrupt number has already been created.
|
||||
*/
|
||||
#define OS_ERRNO_HWI_ALREADY_CREATED LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x04)
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Hardware interrupt error code: Invalid interrupt priority.
|
||||
*
|
||||
* Value: 0x02000905
|
||||
*
|
||||
* Solution: Ensure that the interrupt priority is valid. The value range of the interrupt priority applicable for a Cortex-A7 platform is [0,15].
|
||||
*/
|
||||
#define OS_ERRNO_HWI_PRIO_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x05)
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Hardware interrupt error code: Incorrect interrupt creation mode.
|
||||
*
|
||||
* Value: 0x02000906
|
||||
*
|
||||
* Solution: The interrupt creation mode can be only set to OS_HWI_MODE_COMM or OS_HWI_MODE_FAST of which the value can be 0 or 1.
|
||||
*/
|
||||
#define OS_ERRNO_HWI_MODE_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x06)
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Hardware interrupt error code: The interrupt has already been created as a fast interrupt.
|
||||
*
|
||||
* Value: 0x02000907
|
||||
*
|
||||
* Solution: Check whether the interrupt specified by the passed-in interrupt number has already been created.
|
||||
*/
|
||||
#define OS_ERRNO_HWI_FASTMODE_ALREADY_CREATED LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x07)
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* SysTick control and status register.
|
||||
*/
|
||||
#define OS_SYSTICK_CONTROL_REG 0xE000E010
|
||||
|
||||
/* *
|
||||
* @ingroup los_hw
|
||||
* SysTick current value register.
|
||||
*/
|
||||
#define OS_SYSTICK_CURRENT_REG 0xE000E018
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Interrupt Priority-Level Registers.
|
||||
*/
|
||||
#define OS_NVIC_PRI_BASE 0xE000E400
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Interrupt enable register for 0-31.
|
||||
*/
|
||||
#define OS_NVIC_SETENA_BASE 0xE000E100
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* interrupt pending register.
|
||||
*/
|
||||
#define OS_NVIC_SETPEND_BASE 0xE000E200
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Interrupt active register.
|
||||
*/
|
||||
#define OS_NVIC_INT_ACT_BASE 0xE000E300
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Interrupt disable register for 0-31.
|
||||
*/
|
||||
#define OS_NVIC_CLRENA_BASE 0xE000E180
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Interrupt control and status register.
|
||||
*/
|
||||
#define OS_NVIC_INT_CTRL 0xE000ED04
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Vector table offset register.
|
||||
*/
|
||||
#define OS_NVIC_VTOR 0xE000ED08
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Application interrupt and reset control register
|
||||
*/
|
||||
#define OS_NVIC_AIRCR 0xE000ED0C
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* System exception priority register.
|
||||
*/
|
||||
#define OS_NVIC_EXCPRI_BASE 0xE000ED18
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Interrupt No. 1 :reset.
|
||||
*/
|
||||
#define OS_EXC_RESET 1
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Interrupt No. 2 :Non-Maskable Interrupt.
|
||||
*/
|
||||
#define OS_EXC_NMI 2
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Interrupt No. 3 :(hard)fault.
|
||||
*/
|
||||
#define OS_EXC_HARD_FAULT 3
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Interrupt No. 4 :MemManage fault.
|
||||
*/
|
||||
#define OS_EXC_MPU_FAULT 4
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Interrupt No. 5 :Bus fault.
|
||||
*/
|
||||
#define OS_EXC_BUS_FAULT 5
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Interrupt No. 6 :Usage fault.
|
||||
*/
|
||||
#define OS_EXC_USAGE_FAULT 6
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Interrupt No. 11 :SVCall.
|
||||
*/
|
||||
#define OS_EXC_SVC_CALL 11
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Interrupt No. 12 :Debug monitor.
|
||||
*/
|
||||
#define OS_EXC_DBG_MONITOR 12
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Interrupt No. 14 :PendSV.
|
||||
*/
|
||||
#define OS_EXC_PEND_SV 14
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Interrupt No. 15 :SysTick.
|
||||
*/
|
||||
#define OS_EXC_SYS_TICK 15
|
||||
|
||||
#if (OS_HWI_WITH_ARG == 1)
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Set interrupt vector table.
|
||||
*/
|
||||
extern VOID OsSetVector(UINT32 num, HWI_PROC_FUNC vector, VOID *arg);
|
||||
#else
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Set interrupt vector table.
|
||||
*/
|
||||
extern VOID OsSetVector(UINT32 num, HWI_PROC_FUNC vector);
|
||||
#endif
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* @brief: Hardware interrupt entry function.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used as all hardware interrupt handling function entry.
|
||||
*
|
||||
* @attention:
|
||||
* <ul><li>None.</li></ul>
|
||||
*
|
||||
* @param:None.
|
||||
*
|
||||
* @retval:None.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_hwi.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see None.
|
||||
*/
|
||||
extern VOID HalInterrupt(VOID);
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* @brief: Get an interrupt number.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to get the current interrupt number.
|
||||
*
|
||||
* @attention:
|
||||
* <ul><li>None.</li></ul>
|
||||
*
|
||||
* @param: None.
|
||||
*
|
||||
* @retval: Interrupt Indexes number.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_hwi.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see None.
|
||||
*/
|
||||
extern UINT32 HalIntNumGet(VOID);
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* @brief: Default vector handling function.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to configure interrupt for null function.
|
||||
*
|
||||
* @attention:
|
||||
* <ul><li>None.</li></ul>
|
||||
*
|
||||
* @param:None.
|
||||
*
|
||||
* @retval:None.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_hwi.h: the header file that contains the API declaration.</li
|
||||
></ul>
|
||||
* @see None.
|
||||
*/
|
||||
extern VOID HalHwiDefaultHandler(VOID);
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* @brief: Reset the vector table.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to reset the vector table.
|
||||
*
|
||||
* @attention:
|
||||
* <ul><li>None.</li></ul>
|
||||
*
|
||||
* @param:None.
|
||||
*
|
||||
* @retval:None.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_hwi.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see None.
|
||||
*/
|
||||
extern VOID Reset_Handler(VOID);
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* @brief: Pended System Call.
|
||||
*
|
||||
* @par Description:
|
||||
* PendSV can be pended and is useful for an OS to pend an exception
|
||||
* so that an action can be performed after other important tasks are completed.
|
||||
*
|
||||
* @attention:
|
||||
* <ul><li>None.</li></ul>
|
||||
*
|
||||
* @param:None.
|
||||
*
|
||||
* @retval:None.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_hwi.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see None.
|
||||
*/
|
||||
extern VOID HalPendSV(VOID);
|
||||
|
||||
|
||||
#define OS_EXC_IN_INIT 0
|
||||
#define OS_EXC_IN_TASK 1
|
||||
#define OS_EXC_IN_HWI 2
|
||||
|
||||
#define OS_EXC_MAX_BUF_LEN 25
|
||||
#define OS_EXC_MAX_NEST_DEPTH 1
|
||||
|
||||
#define OS_NVIC_SHCSR 0xE000ED24
|
||||
#define OS_NVIC_CCR 0xE000ED14
|
||||
|
||||
#define OS_NVIC_INT_ENABLE_SIZE 0x20
|
||||
#define OS_NVIC_INT_PRI_SIZE 0xF0
|
||||
#define OS_NVIC_EXCPRI_SIZE 0xC
|
||||
#define OS_NVIC_INT_CTRL_SIZE 4
|
||||
#define OS_NVIC_SHCSR_SIZE 4
|
||||
|
||||
#define OS_NVIC_INT_PEND_SIZE OS_NVIC_INT_ACT_SIZE
|
||||
#define OS_NVIC_INT_ACT_SIZE OS_NVIC_INT_ENABLE_SIZE
|
||||
|
||||
#define OS_EXC_FLAG_NO_FLOAT 0x10000000
|
||||
#define OS_EXC_FLAG_FAULTADDR_VALID 0x01
|
||||
#define OS_EXC_FLAG_IN_HWI 0x02
|
||||
|
||||
#define OS_EXC_IMPRECISE_ACCESS_ADDR 0xABABABAB
|
||||
|
||||
#define OS_EXC_EVENT 0x00000001
|
||||
|
||||
/**
|
||||
* @ingroup los_exc
|
||||
* the struct of register files
|
||||
*
|
||||
* description: the register files that saved when exception triggered
|
||||
*
|
||||
* notes:the following register with prefix 'uw' correspond to the registers in the cpu data sheet.
|
||||
*/
|
||||
typedef struct TagExcContext {
|
||||
#if ((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \
|
||||
(defined (__FPU_USED ) && (__FPU_USED == 1U)) )
|
||||
UINT32 S16;
|
||||
UINT32 S17;
|
||||
UINT32 S18;
|
||||
UINT32 S19;
|
||||
UINT32 S20;
|
||||
UINT32 S21;
|
||||
UINT32 S22;
|
||||
UINT32 S23;
|
||||
UINT32 S24;
|
||||
UINT32 S25;
|
||||
UINT32 S26;
|
||||
UINT32 S27;
|
||||
UINT32 S28;
|
||||
UINT32 S29;
|
||||
UINT32 S30;
|
||||
UINT32 S31;
|
||||
#endif
|
||||
UINT32 uwR4;
|
||||
UINT32 uwR5;
|
||||
UINT32 uwR6;
|
||||
UINT32 uwR7;
|
||||
UINT32 uwR8;
|
||||
UINT32 uwR9;
|
||||
UINT32 uwR10;
|
||||
UINT32 uwR11;
|
||||
UINT32 uwPriMask;
|
||||
/* auto save */
|
||||
UINT32 uwSP;
|
||||
UINT32 uwR0;
|
||||
UINT32 uwR1;
|
||||
UINT32 uwR2;
|
||||
UINT32 uwR3;
|
||||
UINT32 uwR12;
|
||||
UINT32 uwLR;
|
||||
UINT32 uwPC;
|
||||
UINT32 uwxPSR;
|
||||
#if ((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \
|
||||
(defined (__FPU_USED) && (__FPU_USED== 1U)))
|
||||
UINT32 S0;
|
||||
UINT32 S1;
|
||||
UINT32 S2;
|
||||
UINT32 S3;
|
||||
UINT32 S4;
|
||||
UINT32 S5;
|
||||
UINT32 S6;
|
||||
UINT32 S7;
|
||||
UINT32 S8;
|
||||
UINT32 S9;
|
||||
UINT32 S10;
|
||||
UINT32 S11;
|
||||
UINT32 S12;
|
||||
UINT32 S13;
|
||||
UINT32 S14;
|
||||
UINT32 S15;
|
||||
UINT32 FPSCR;
|
||||
UINT32 NO_NAME;
|
||||
#endif
|
||||
}EXC_CONTEXT_S;
|
||||
|
||||
typedef VOID (*EXC_PROC_FUNC)(UINT32, EXC_CONTEXT_S *);
|
||||
VOID HalExcHandleEntry(UINT32 excType, UINT32 faultAddr, UINT32 pid, EXC_CONTEXT_S *excBufAddr);
|
||||
|
||||
/**
|
||||
* @ingroup los_hwi
|
||||
* @brief: Exception initialization.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to configure the exception function vector table.
|
||||
*
|
||||
* @attention:
|
||||
* <ul><li>None.</li></ul>
|
||||
*
|
||||
* @param uwArraySize [IN] Memory size of exception.
|
||||
*
|
||||
* @retval: None
|
||||
* @par Dependency:
|
||||
* <ul><li>los_hwi.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see None.
|
||||
*/
|
||||
VOID OsExcInit(VOID);
|
||||
|
||||
VOID HalExcNMI(VOID);
|
||||
VOID HalExcHardFault(VOID);
|
||||
VOID HalExcMemFault(VOID);
|
||||
VOID HalExcBusFault(VOID);
|
||||
VOID HalExcUsageFault(VOID);
|
||||
VOID HalSVCHandler(VOID);
|
||||
VOID HalHwiInit();
|
||||
|
||||
|
||||
/**
|
||||
* @ingroup los_exc
|
||||
* Cortex-M exception types: An error occurred while the bus status register was being pushed.
|
||||
*/
|
||||
#define OS_EXC_BF_STKERR 1
|
||||
|
||||
/**
|
||||
* @ingroup los_exc
|
||||
* Cortex-M exception types: An error occurred while the bus status register was out of the stack.
|
||||
*/
|
||||
#define OS_EXC_BF_UNSTKERR 2
|
||||
|
||||
/**
|
||||
* @ingroup los_exc
|
||||
* Cortex-M exception types: Bus status register imprecise data access violation.
|
||||
*/
|
||||
#define OS_EXC_BF_IMPRECISERR 3
|
||||
|
||||
/**
|
||||
* @ingroup los_exc
|
||||
* Cortex-M exception types: Bus status register exact data access violation.
|
||||
*/
|
||||
#define OS_EXC_BF_PRECISERR 4
|
||||
|
||||
/**
|
||||
* @ingroup los_exc
|
||||
* Cortex-M exception types: Bus status register access violation while pointing.
|
||||
*/
|
||||
#define OS_EXC_BF_IBUSERR 5
|
||||
|
||||
/**
|
||||
* @ingroup los_exc
|
||||
* Cortex-M exception types: An error occurred while the memory management status register was being pushed.
|
||||
*/
|
||||
#define OS_EXC_MF_MSTKERR 6
|
||||
|
||||
/**
|
||||
* @ingroup los_exc
|
||||
* Cortex-M exception types: An error occurred while the memory management status register was out of the stack.
|
||||
*/
|
||||
#define OS_EXC_MF_MUNSTKERR 7
|
||||
|
||||
/**
|
||||
* @ingroup los_exc
|
||||
* Cortex-M exception types: Memory management status register data access violation.
|
||||
*/
|
||||
#define OS_EXC_MF_DACCVIOL 8
|
||||
|
||||
/**
|
||||
* @ingroup los_exc
|
||||
* Cortex-M exception types: Memory management status register access violation.
|
||||
*/
|
||||
#define OS_EXC_MF_IACCVIOL 9
|
||||
|
||||
|
||||
/**
|
||||
* @ingroup los_exc
|
||||
* Cortex-M exception types: Incorrect usage indicating that the divisor is zero during the division operation.
|
||||
*/
|
||||
#define OS_EXC_UF_DIVBYZERO 10
|
||||
|
||||
/**
|
||||
* @ingroup los_exc
|
||||
* Cortex-M exception types: Usage error, error caused by unaligned access.
|
||||
*/
|
||||
#define OS_EXC_UF_UNALIGNED 11
|
||||
|
||||
/**
|
||||
* @ingroup los_exc
|
||||
* Cortex-M exception types: Incorrect usage attempting to execute coprocessor related instruction.
|
||||
*/
|
||||
#define OS_EXC_UF_NOCP 12
|
||||
|
||||
/**
|
||||
* @ingroup los_exc
|
||||
* Cortex-M exception types: Usage error attempting to load EXC_RETURN to PC illegally on exception return.
|
||||
*/
|
||||
#define OS_EXC_UF_INVPC 13
|
||||
|
||||
/**
|
||||
* @ingroup los_exc
|
||||
* Cortex-M exception types: Incorrect usage, attempting to cut to ARM state.
|
||||
*/
|
||||
#define OS_EXC_UF_INVSTATE 14
|
||||
|
||||
/**
|
||||
* @ingroup los_exc
|
||||
* Cortex-M exception types: Incorrect usage. Executed instruction whose code is undefined.
|
||||
*/
|
||||
#define OS_EXC_UF_UNDEFINSTR 15
|
||||
|
||||
/**
|
||||
* @ingroup los_exc
|
||||
* Cortex-M exception types: NMI
|
||||
*/
|
||||
|
||||
#define OS_EXC_CAUSE_NMI 16
|
||||
|
||||
/**
|
||||
* @ingroup los_exc
|
||||
* Cortex-M exception types: hard fault
|
||||
*/
|
||||
#define OS_EXC_CAUSE_HARDFAULT 17
|
||||
|
||||
/**
|
||||
* @ingroup los_exc
|
||||
* Cortex-M exception types: The task handler exits.
|
||||
*/
|
||||
#define OS_EXC_CAUSE_TASK_EXIT 18
|
||||
|
||||
/**
|
||||
* @ingroup los_exc
|
||||
* Cortex-M exception types: A fatal error.
|
||||
*/
|
||||
#define OS_EXC_CAUSE_FATAL_ERR 19
|
||||
|
||||
/**
|
||||
* @ingroup los_exc
|
||||
* Cortex-M exception types: Hard Fault caused by a debug event.
|
||||
*/
|
||||
#define OS_EXC_CAUSE_DEBUGEVT 20
|
||||
|
||||
/**
|
||||
* @ingroup los_exc
|
||||
* Cortex-M exception types: A hard fault that occurs when a quantity is oriented.
|
||||
*/
|
||||
#define OS_EXC_CAUSE_VECTBL 21
|
||||
|
||||
/**
|
||||
* @ingroup los_exc
|
||||
* Exception information structure
|
||||
*
|
||||
* Description: Exception information saved when an exception is triggered on the Cortex-M4 platform.
|
||||
*
|
||||
*/
|
||||
typedef struct TagExcInfo {
|
||||
/**< Exception occurrence phase: 0 means that an exception occurs in initialization, 1 means that an exception occurs in a task, and 2 means that an exception occurs in an interrupt */
|
||||
UINT16 phase;
|
||||
/**< Exception type. When exceptions occur, check the numbers 1 - 21 listed above */
|
||||
UINT16 type;
|
||||
/**< If the exact address access error indicates the wrong access address when the exception occurred */
|
||||
UINT32 faultAddr;
|
||||
/**< An exception occurs in an interrupt, indicating the interrupt number. An exception occurs in the task, indicating the task ID, or 0xFFFFFFFF if it occurs during initialization */
|
||||
UINT32 thrdPid;
|
||||
/**< Number of nested exceptions. Currently only registered hook functions are supported when an exception is entered for the first time */
|
||||
UINT16 nestCnt;
|
||||
/**< reserve */
|
||||
UINT16 reserved;
|
||||
/**< Hardware context at the time an exception to the automatic stack floating-point register occurs */
|
||||
EXC_CONTEXT_S *context;
|
||||
} ExcInfo;
|
||||
|
||||
extern UINT32 g_curNestCount;
|
||||
extern UINT32 g_intCount;
|
||||
extern UINT8 g_uwExcTbl[32];
|
||||
extern ExcInfo g_excInfo;
|
||||
|
||||
#define MAX_INT_INFO_SIZE (8 + 0x164)
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _LOS_EXC_H */
|
|
@ -0,0 +1,54 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef _LOS_ARCH_TIMER_H
|
||||
#define _LOS_ARCH_TIMER_H
|
||||
|
||||
#include "los_config.h"
|
||||
#include "los_compiler.h"
|
||||
#include "los_context.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
UINT32 HalTickStart(OS_TICK_HANDLER handler);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _LOS_ARCH_TIMER_H */
|
||||
|
|
@ -0,0 +1,159 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "los_context.h"
|
||||
#include "securec.h"
|
||||
#include "los_arch_context.h"
|
||||
#include "los_arch_interrupt.h"
|
||||
#include "los_task.h"
|
||||
#include "los_sched.h"
|
||||
#include "los_interrupt.h"
|
||||
#include "los_arch_timer.h"
|
||||
|
||||
/* ****************************************************************************
|
||||
Function : HalArchInit
|
||||
Description : arch init function
|
||||
Input : None
|
||||
Output : None
|
||||
Return : None
|
||||
**************************************************************************** */
|
||||
LITE_OS_SEC_TEXT_INIT VOID HalArchInit()
|
||||
{
|
||||
HalHwiInit();
|
||||
}
|
||||
|
||||
/* ****************************************************************************
|
||||
Function : HalSysExit
|
||||
Description : Task exit function
|
||||
Input : None
|
||||
Output : None
|
||||
Return : None
|
||||
**************************************************************************** */
|
||||
LITE_OS_SEC_TEXT_MINOR VOID HalSysExit(VOID)
|
||||
{
|
||||
LOS_IntLock();
|
||||
while (1) {
|
||||
}
|
||||
}
|
||||
|
||||
/* ****************************************************************************
|
||||
Function : HalTskStackInit
|
||||
Description : Task stack initialization function
|
||||
Input : taskID --- TaskID
|
||||
stackSize --- Total size of the stack
|
||||
topStack --- Top of task's stack
|
||||
Output : None
|
||||
Return : Context pointer
|
||||
**************************************************************************** */
|
||||
LITE_OS_SEC_TEXT_INIT VOID *HalTskStackInit(UINT32 taskID, UINT32 stackSize, VOID *topStack)
|
||||
{
|
||||
TaskContext *context = NULL;
|
||||
errno_t result;
|
||||
|
||||
/* initialize the task stack, write magic num to stack top */
|
||||
result = memset_s(topStack, stackSize, (INT32)(OS_TASK_STACK_INIT & 0xFF), stackSize);
|
||||
if (result != EOK) {
|
||||
printf("memset_s is failed:%s[%d]\r\n", __FUNCTION__, __LINE__);
|
||||
}
|
||||
*((UINT32 *)(topStack)) = OS_TASK_MAGIC_WORD;
|
||||
|
||||
context = (TaskContext *)(((UINTPTR)topStack + stackSize) - sizeof(TaskContext));
|
||||
|
||||
#if ((defined(__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \
|
||||
(defined(__FPU_USED) && (__FPU_USED == 1U)))
|
||||
context->S16 = 0xAA000010;
|
||||
context->S17 = 0xAA000011;
|
||||
context->S18 = 0xAA000012;
|
||||
context->S19 = 0xAA000013;
|
||||
context->S20 = 0xAA000014;
|
||||
context->S21 = 0xAA000015;
|
||||
context->S22 = 0xAA000016;
|
||||
context->S23 = 0xAA000017;
|
||||
context->S24 = 0xAA000018;
|
||||
context->S25 = 0xAA000019;
|
||||
context->S26 = 0xAA00001A;
|
||||
context->S27 = 0xAA00001B;
|
||||
context->S28 = 0xAA00001C;
|
||||
context->S29 = 0xAA00001D;
|
||||
context->S30 = 0xAA00001E;
|
||||
context->S31 = 0xAA00001F;
|
||||
context->S0 = 0xAA000000;
|
||||
context->S1 = 0xAA000001;
|
||||
context->S2 = 0xAA000002;
|
||||
context->S3 = 0xAA000003;
|
||||
context->S4 = 0xAA000004;
|
||||
context->S5 = 0xAA000005;
|
||||
context->S6 = 0xAA000006;
|
||||
context->S7 = 0xAA000007;
|
||||
context->S8 = 0xAA000008;
|
||||
context->S9 = 0xAA000009;
|
||||
context->S10 = 0xAA00000A;
|
||||
context->S11 = 0xAA00000B;
|
||||
context->S12 = 0xAA00000C;
|
||||
context->S13 = 0xAA00000D;
|
||||
context->S14 = 0xAA00000E;
|
||||
context->S15 = 0xAA00000F;
|
||||
context->FPSCR = 0x00000000;
|
||||
context->NO_NAME = 0xAA000011;
|
||||
#endif
|
||||
|
||||
context->uwR4 = 0x04040404L;
|
||||
context->uwR5 = 0x05050505L;
|
||||
context->uwR6 = 0x06060606L;
|
||||
context->uwR7 = 0x07070707L;
|
||||
context->uwR8 = 0x08080808L;
|
||||
context->uwR9 = 0x09090909L;
|
||||
context->uwR10 = 0x10101010L;
|
||||
context->uwR11 = 0x11111111L;
|
||||
context->uwPriMask = 0;
|
||||
context->uwR0 = taskID;
|
||||
context->uwR1 = 0x01010101L;
|
||||
context->uwR2 = 0x02020202L;
|
||||
context->uwR3 = 0x03030303L;
|
||||
context->uwR12 = 0x12121212L;
|
||||
context->uwLR = (UINT32)(UINTPTR)HalSysExit;
|
||||
context->uwPC = (UINT32)(UINTPTR)OsTaskEntry;
|
||||
context->uwxPSR = 0x01000000L;
|
||||
|
||||
return (VOID *)context;
|
||||
}
|
||||
|
||||
LITE_OS_SEC_TEXT_INIT UINT32 HalStartSchedule(OS_TICK_HANDLER handler)
|
||||
{
|
||||
(VOID)LOS_IntLock();
|
||||
UINT32 ret = HalTickStart(handler);
|
||||
if (ret != LOS_OK) {
|
||||
return ret;
|
||||
}
|
||||
OsSchedStart();
|
||||
HalStartToRun();
|
||||
return LOS_OK; /* never return */
|
||||
}
|
|
@ -0,0 +1,162 @@
|
|||
;
|
||||
; Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
; Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
;
|
||||
; Redistribution and use in source and binary forms, with or without modification,
|
||||
; are permitted provided that the following conditions are met:
|
||||
;
|
||||
; 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
; conditions and the following disclaimer.
|
||||
;
|
||||
; 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
; of conditions and the following disclaimer in the documentation and/or other materials
|
||||
; provided with the distribution.
|
||||
;
|
||||
; 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
; to endorse or promote products derived from this software without specific prior written
|
||||
; permission.
|
||||
;
|
||||
; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
; THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
; PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
; CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
; EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
; WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
; OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
; ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
;
|
||||
|
||||
PRESERVE8
|
||||
|
||||
EXPORT HalIntLock
|
||||
EXPORT HalIntUnLock
|
||||
EXPORT HalIntRestore
|
||||
EXPORT HalStartToRun
|
||||
EXPORT HalTaskSchedule
|
||||
EXPORT HalPendSV
|
||||
IMPORT OsSchedTaskSwitch
|
||||
IMPORT g_losTask
|
||||
|
||||
OS_FPU_CPACR EQU 0xE000ED88
|
||||
OS_FPU_CPACR_ENABLE EQU 0x00F00000
|
||||
OS_NVIC_INT_CTRL EQU 0xE000ED04
|
||||
OS_NVIC_SYSPRI2 EQU 0xE000ED20
|
||||
OS_NVIC_PENDSV_PRI EQU 0xF0F00000
|
||||
OS_NVIC_PENDSVSET EQU 0x10000000
|
||||
OS_TASK_STATUS_RUNNING EQU 0x0010
|
||||
|
||||
SECTION .text:CODE(2)
|
||||
THUMB
|
||||
REQUIRE8
|
||||
|
||||
HalStartToRun
|
||||
LDR R4, =OS_NVIC_SYSPRI2
|
||||
LDR R5, =OS_NVIC_PENDSV_PRI
|
||||
STR R5, [R4]
|
||||
|
||||
MOV R0, #2
|
||||
MSR CONTROL, R0
|
||||
|
||||
LDR R1, =g_losTask
|
||||
LDR R0, [R1, #4]
|
||||
LDR R12, [R0]
|
||||
|
||||
LDR.W R1, =OS_FPU_CPACR
|
||||
LDR R1, [R1]
|
||||
AND R1, R1, #OS_FPU_CPACR_ENABLE
|
||||
CMP R1, #OS_FPU_CPACR_ENABLE
|
||||
BNE __DisabledFPU
|
||||
ADD R12, R12, #100
|
||||
|
||||
LDMFD R12!, {R0-R7}
|
||||
ADD R12, R12, #72
|
||||
MSR PSP, R12
|
||||
VPUSH S0;
|
||||
VPOP S0;
|
||||
MOV LR, R5
|
||||
CPSIE I
|
||||
BX R6
|
||||
|
||||
__DisabledFPU
|
||||
ADD R12, R12, #36
|
||||
|
||||
LDMFD R12!, {R0-R7}
|
||||
MSR PSP, R12
|
||||
MOV LR, R5
|
||||
CPSIE I
|
||||
BX R6
|
||||
|
||||
|
||||
HalIntLock
|
||||
MRS R0, PRIMASK
|
||||
CPSID I
|
||||
BX LR
|
||||
|
||||
HalIntUnLock
|
||||
MRS R0, PRIMASK
|
||||
CPSIE I
|
||||
BX LR
|
||||
|
||||
HalIntRestore
|
||||
MSR PRIMASK, R0
|
||||
BX LR
|
||||
|
||||
HalTaskSchedule
|
||||
LDR R0, =OS_NVIC_INT_CTRL
|
||||
LDR R1, =OS_NVIC_PENDSVSET
|
||||
STR R1, [R0]
|
||||
DSB
|
||||
ISB
|
||||
BX LR
|
||||
|
||||
HalPendSV
|
||||
MRS R12, PRIMASK
|
||||
CPSID I
|
||||
|
||||
HalTaskSwitch
|
||||
PUSH {R12, LR}
|
||||
BLX OsSchedTaskSwitch
|
||||
POP {R12, LR}
|
||||
CMP R0, #0
|
||||
MOV R0, LR
|
||||
BNE TaskContextSwitch
|
||||
MSR PRIMASK, R12
|
||||
BX LR
|
||||
|
||||
TaskContextSwitch
|
||||
MOV LR, R0
|
||||
MRS R0, PSP
|
||||
|
||||
STMFD R0!, {R4-R12}
|
||||
LDR.W R3, =OS_FPU_CPACR
|
||||
LDR R3, [R3]
|
||||
AND R3, R3, #OS_FPU_CPACR_ENABLE
|
||||
CMP R3, #OS_FPU_CPACR_ENABLE
|
||||
BNE __DisabledFPU1
|
||||
VSTMDB R0!, {D8-D15}
|
||||
|
||||
__DisabledFPU1
|
||||
LDR R5, =g_losTask
|
||||
LDR R6, [R5]
|
||||
STR R0, [R6]
|
||||
|
||||
LDR R0, [R5, #4]
|
||||
STR R0, [R5]
|
||||
|
||||
LDR R1, [R0]
|
||||
AND R3, R3, #OS_FPU_CPACR_ENABLE
|
||||
CMP R3, #OS_FPU_CPACR_ENABLE
|
||||
BNE __DisabledFPU2
|
||||
VLDMIA R1!, {D8-D15}
|
||||
|
||||
__DisabledFPU2
|
||||
LDMFD R1!, {R4-R12}
|
||||
MSR PSP, R1
|
||||
|
||||
MSR PRIMASK, R12
|
||||
BX LR
|
||||
|
||||
END
|
|
@ -0,0 +1,285 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
PRESERVE8
|
||||
SECTION .text:CODE(2)
|
||||
THUMB
|
||||
|
||||
EXPORT HalExcNMI
|
||||
EXPORT HalExcHardFault
|
||||
EXPORT HalExcMemFault
|
||||
EXPORT HalExcBusFault
|
||||
EXPORT HalExcUsageFault
|
||||
EXPORT HalSVCHandler
|
||||
|
||||
IMPORT HalExcHandleEntry
|
||||
IMPORT g_uwExcTbl
|
||||
IMPORT g_taskScheduled
|
||||
|
||||
OS_FLG_BGD_ACTIVE EQU 0x0002
|
||||
|
||||
OS_EXC_CAUSE_NMI EQU 16
|
||||
OS_EXC_CAUSE_HARDFAULT EQU 17
|
||||
|
||||
HF_DEBUGEVT EQU 20
|
||||
HF_VECTBL EQU 21
|
||||
|
||||
FLAG_ADDR_VALID EQU 0x10000
|
||||
FLAG_HWI_ACTIVE EQU 0x20000
|
||||
FLAG_NO_FLOAT EQU 0x10000000
|
||||
|
||||
OS_NVIC_FSR EQU 0xE000ED28 ;include BusFault/MemFault/UsageFault State Regeister
|
||||
OS_NVIC_HFSR EQU 0xE000ED2C ;HardFault State Regeister
|
||||
OS_NVIC_BFAR EQU 0xE000ED38
|
||||
OS_NVIC_MMAR EQU 0xE000ED34
|
||||
OS_NVIC_ACT_BASE EQU 0xE000E300
|
||||
OS_NVIC_SHCSRS EQU 0xE000ED24
|
||||
OS_NVIC_SHCSR_MASK EQU 0xC00
|
||||
|
||||
HalExcNMI
|
||||
MOV R0, #OS_EXC_CAUSE_NMI
|
||||
MOV R1, #0
|
||||
B osExcDispatch
|
||||
|
||||
HalExcHardFault
|
||||
MOV R0, #OS_EXC_CAUSE_HARDFAULT
|
||||
LDR R2, =OS_NVIC_HFSR
|
||||
LDR R2, [R2]
|
||||
|
||||
MOV R1, #HF_DEBUGEVT
|
||||
ORR R0, R0, R1, LSL #0x8
|
||||
TST R2, #0x80000000
|
||||
BNE osExcDispatch ; DEBUGEVT
|
||||
|
||||
AND R0, R0 , #0x000000FF
|
||||
MOV R1, #HF_VECTBL
|
||||
ORR R0, R0, R1, LSL #0x8
|
||||
TST R2, #0x00000002
|
||||
BNE osExcDispatch ; VECTBL
|
||||
|
||||
;if not DEBUGEVT and VECTBL then is FORCED
|
||||
AND R0, R0, #0x000000FF
|
||||
|
||||
LDR R2, =OS_NVIC_FSR
|
||||
LDR R2, [R2]
|
||||
|
||||
TST R2, #0x8000 ; BFARVALID
|
||||
BNE _HFBusFault ; BusFault
|
||||
|
||||
TST R2, #0x80 ; MMARVALID
|
||||
BNE _HFMemFault ; MemFault
|
||||
|
||||
MOV R12,#0
|
||||
B osHFExcCommonBMU
|
||||
|
||||
_HFBusFault
|
||||
LDR R1, =OS_NVIC_BFAR
|
||||
LDR R1, [R1]
|
||||
MOV R12, #FLAG_ADDR_VALID
|
||||
B osHFExcCommonBMU
|
||||
|
||||
_HFMemFault
|
||||
LDR R1, =OS_NVIC_MMAR
|
||||
LDR R1, [R1]
|
||||
MOV R12, #FLAG_ADDR_VALID
|
||||
|
||||
osHFExcCommonBMU
|
||||
CLZ R2, R2
|
||||
LDR R3, =g_uwExcTbl
|
||||
ADD R3, R3, R2
|
||||
LDRB R2, [R3]
|
||||
ORR R0, R0, R2, LSL #0x8
|
||||
ORR R0, R0 ,R12
|
||||
B osExcDispatch
|
||||
|
||||
HalSVCHandler
|
||||
TST LR, #0x4
|
||||
ITE EQ
|
||||
MRSEQ R0, MSP
|
||||
MRSNE R0, PSP
|
||||
LDR R1, [R0,#24]
|
||||
LDRB R0, [R1,#-2]
|
||||
MOV R1, #0
|
||||
B osExcDispatch
|
||||
|
||||
HalExcBusFault
|
||||
LDR R0, =OS_NVIC_FSR
|
||||
LDR R0, [R0]
|
||||
|
||||
TST R0, #0x8000 ; BFARVALID
|
||||
BEQ _ExcBusNoADDR
|
||||
LDR R1, =OS_NVIC_BFAR
|
||||
LDR R1, [R1]
|
||||
MOV R12, #FLAG_ADDR_VALID
|
||||
AND R0, R0, #0x1F00
|
||||
|
||||
B osExcCommonBMU
|
||||
|
||||
_ExcBusNoADDR
|
||||
MOV R12,#0
|
||||
B osExcCommonBMU
|
||||
|
||||
HalExcMemFault
|
||||
LDR R0, =OS_NVIC_FSR
|
||||
LDR R0, [R0]
|
||||
|
||||
TST R0, #0x80 ; MMARVALID
|
||||
BEQ _ExcMemNoADDR
|
||||
LDR R1, =OS_NVIC_MMAR
|
||||
LDR R1, [R1]
|
||||
MOV R12, #FLAG_ADDR_VALID
|
||||
AND R0, R0, #0x1B
|
||||
|
||||
B osExcCommonBMU
|
||||
|
||||
_ExcMemNoADDR
|
||||
MOV R12,#0
|
||||
B osExcCommonBMU
|
||||
|
||||
HalExcUsageFault
|
||||
LDR R0, =OS_NVIC_FSR
|
||||
LDR R0, [R0]
|
||||
|
||||
MOV R1, #0x030F
|
||||
LSL R1, R1, #16
|
||||
AND R0, R0, R1
|
||||
MOV R12, #0
|
||||
|
||||
osExcCommonBMU
|
||||
CLZ R0, R0
|
||||
LDR R3, =g_uwExcTbl
|
||||
ADD R3, R3, R0
|
||||
LDRB R0, [R3]
|
||||
ORR R0, R0, R12
|
||||
|
||||
; R0 -- EXCCAUSE(bit 16 is 1 if EXCADDR valid), R1 -- EXCADDR
|
||||
osExcDispatch
|
||||
LDR R2, =OS_NVIC_ACT_BASE
|
||||
MOV R12, #8 ; R12 is hwi check loop counter
|
||||
|
||||
_hwiActiveCheck
|
||||
LDR R3, [R2] ; R3 store active hwi register when exc
|
||||
CMP R3, #0
|
||||
BEQ _hwiActiveCheckNext
|
||||
|
||||
; exc occured in IRQ
|
||||
ORR R0, R0, #FLAG_HWI_ACTIVE
|
||||
RBIT R2, R3
|
||||
CLZ R2, R2
|
||||
AND R12, R12, #1
|
||||
ADD R2, R2, R12, LSL #5 ; calculate R2 (hwi number) as uwPid
|
||||
|
||||
_ExcInMSP
|
||||
CMP LR, #0XFFFFFFED
|
||||
BNE _NoFloatInMsp
|
||||
ADD R3, R13, #104
|
||||
PUSH {R3}
|
||||
MRS R12, PRIMASK ; store message-->exc: disable int?
|
||||
PUSH {R4-R12} ; store message-->exc: {R4-R12}
|
||||
VPUSH {D8-D15}
|
||||
B _handleEntry
|
||||
|
||||
_NoFloatInMsp
|
||||
ADD R3, R13, #32
|
||||
PUSH {R3} ; save IRQ SP ; store message-->exc: MSP(R13)
|
||||
|
||||
MRS R12, PRIMASK ; store message-->exc: disable int?
|
||||
PUSH {R4-R12} ; store message-->exc: {R4-R12}
|
||||
ORR R0, R0, #FLAG_NO_FLOAT
|
||||
B _handleEntry
|
||||
|
||||
_hwiActiveCheckNext
|
||||
ADD R2, R2, #4 ; next NVIC ACT ADDR
|
||||
SUBS R12, R12, #1
|
||||
BNE _hwiActiveCheck
|
||||
|
||||
;/*NMI interrupt excption*/
|
||||
LDR R2, =OS_NVIC_SHCSRS
|
||||
LDRH R2,[R2]
|
||||
LDR R3,=OS_NVIC_SHCSR_MASK
|
||||
AND R2, R2,R3
|
||||
CMP R2,#0
|
||||
BNE _ExcInMSP
|
||||
; exc occured in Task or Init or exc
|
||||
; reserved for register info from task stack
|
||||
|
||||
LDR R2, =g_taskScheduled
|
||||
LDR R2, [R2]
|
||||
TST R2, #1 ; OS_FLG_BGD_ACTIVE
|
||||
BEQ _ExcInMSP ; if exc occured in Init then branch
|
||||
|
||||
|
||||
CMP LR, #0xFFFFFFED ;auto push floating registers
|
||||
BNE _NoFloatInPsp
|
||||
|
||||
; exc occured in Task
|
||||
MOV R2, R13
|
||||
SUB R13, #96 ; add 8 Bytes reg(for STMFD)
|
||||
|
||||
MRS R3, PSP
|
||||
ADD R12, R3, #104
|
||||
PUSH {R12} ; save task SP
|
||||
|
||||
MRS R12, PRIMASK
|
||||
PUSH {R4-R12}
|
||||
VPUSH {D8-D15}
|
||||
|
||||
; copy auto saved task register
|
||||
|
||||
LDMFD R3!, {R4-R11} ; R4-R11 store PSP reg(auto push when exc in task)
|
||||
VLDMIA R3!, {D8-D15}
|
||||
VSTMDB R2!, {D8-D15}
|
||||
STMFD R2!, {R4-R11}
|
||||
B _handleEntry
|
||||
|
||||
_NoFloatInPsp
|
||||
MOV R2, R13 ;no auto push floating registers
|
||||
SUB R13, #32 ; add 8 Bytes reg(for STMFD)
|
||||
|
||||
MRS R3, PSP
|
||||
ADD R12, R3, #32
|
||||
PUSH {R12} ; save task SP
|
||||
|
||||
MRS R12, PRIMASK
|
||||
PUSH {R4-R12}
|
||||
|
||||
LDMFD R3, {R4-R11} ; R4-R11 store PSP reg(auto push when exc in task)
|
||||
STMFD R2!, {R4-R11}
|
||||
ORR R0, R0, #FLAG_NO_FLOAT
|
||||
|
||||
_handleEntry
|
||||
MOV R3, R13 ; R13:the 4th param
|
||||
CPSID I
|
||||
CPSID F
|
||||
B HalExcHandleEntry
|
||||
|
||||
NOP
|
||||
END
|
|
@ -0,0 +1,532 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "los_interrupt.h"
|
||||
#include "securec.h"
|
||||
#include <stdarg.h>
|
||||
#include "los_arch_interrupt.h"
|
||||
#include "los_context.h"
|
||||
#include "los_debug.h"
|
||||
#include "los_hook.h"
|
||||
#include "los_task.h"
|
||||
#include "los_sched.h"
|
||||
#include "los_memory.h"
|
||||
#include "los_membox.h"
|
||||
|
||||
|
||||
/*lint -save -e40 -e522 -e533*/
|
||||
UINT32 g_intCount = 0;
|
||||
|
||||
/*lint -restore*/
|
||||
#pragma location = ".data.vector"
|
||||
#pragma data_alignment=0x100
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* hardware interrupt form mapping handling function array.
|
||||
*/
|
||||
STATIC HWI_PROC_FUNC g_hwiForm[OS_VECTOR_CNT] = {0};
|
||||
|
||||
#if (OS_HWI_WITH_ARG == 1)
|
||||
|
||||
typedef struct {
|
||||
HWI_PROC_FUNC pfnHandler;
|
||||
VOID *pParm;
|
||||
} HWI_HANDLER_FUNC;
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* hardware interrupt handler form mapping handling function array.
|
||||
*/
|
||||
STATIC HWI_HANDLER_FUNC g_hwiHandlerForm[OS_VECTOR_CNT] = {{ (HWI_PROC_FUNC)0, (HWI_ARG_T)0 }};
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Set interrupt vector table.
|
||||
*/
|
||||
VOID OsSetVector(UINT32 num, HWI_PROC_FUNC vector, VOID *arg)
|
||||
{
|
||||
if ((num + OS_SYS_VECTOR_CNT) < OS_VECTOR_CNT) {
|
||||
g_hwiForm[num + OS_SYS_VECTOR_CNT] = (HWI_PROC_FUNC)HalInterrupt;
|
||||
g_hwiHandlerForm[num + OS_SYS_VECTOR_CNT].pfnHandler = vector;
|
||||
g_hwiHandlerForm[num + OS_SYS_VECTOR_CNT].pParm = arg;
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* hardware interrupt handler form mapping handling function array.
|
||||
*/
|
||||
STATIC HWI_PROC_FUNC g_hwiHandlerForm[OS_VECTOR_CNT] = {0};
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Set interrupt vector table.
|
||||
*/
|
||||
VOID OsSetVector(UINT32 num, HWI_PROC_FUNC vector)
|
||||
{
|
||||
if ((num + OS_SYS_VECTOR_CNT) < OS_VECTOR_CNT) {
|
||||
g_hwiForm[num + OS_SYS_VECTOR_CNT] = HalInterrupt;
|
||||
g_hwiHandlerForm[num + OS_SYS_VECTOR_CNT] = vector;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
WEAK VOID SysTick_Handler(VOID)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
/* ****************************************************************************
|
||||
Function : HalIntNumGet
|
||||
Description : Get an interrupt number
|
||||
Input : None
|
||||
Output : None
|
||||
Return : Interrupt Indexes number
|
||||
**************************************************************************** */
|
||||
LITE_OS_SEC_TEXT_MINOR UINT32 HalIntNumGet(VOID)
|
||||
{
|
||||
return __get_IPSR();
|
||||
}
|
||||
|
||||
inline UINT32 HalIsIntActive(VOID)
|
||||
{
|
||||
return (g_intCount > 0);
|
||||
}
|
||||
/* ****************************************************************************
|
||||
Function : HalHwiDefaultHandler
|
||||
Description : default handler of the hardware interrupt
|
||||
Input : None
|
||||
Output : None
|
||||
Return : None
|
||||
**************************************************************************** */
|
||||
/*lint -e529*/
|
||||
LITE_OS_SEC_TEXT_MINOR VOID HalHwiDefaultHandler(VOID)
|
||||
{
|
||||
UINT32 irqNum = HalIntNumGet();
|
||||
PRINT_ERR("%s irqnum:%d\n", __FUNCTION__, irqNum);
|
||||
while (1) {}
|
||||
}
|
||||
|
||||
WEAK VOID HalPreInterruptHandler(UINT32 arg)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
WEAK VOID HalAftInterruptHandler(UINT32 arg)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
/* ****************************************************************************
|
||||
Function : HalInterrupt
|
||||
Description : Hardware interrupt entry function
|
||||
Input : None
|
||||
Output : None
|
||||
Return : None
|
||||
**************************************************************************** */
|
||||
LITE_OS_SEC_TEXT VOID HalInterrupt(VOID)
|
||||
{
|
||||
UINT32 hwiIndex;
|
||||
UINT32 intSave;
|
||||
|
||||
#if (LOSCFG_KERNEL_RUNSTOP == 1)
|
||||
SCB->SCR &= (UINT32) ~((UINT32)SCB_SCR_SLEEPDEEP_Msk);
|
||||
#endif
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
|
||||
g_intCount++;
|
||||
|
||||
LOS_IntRestore(intSave);
|
||||
|
||||
#if (LOSCFG_BASE_CORE_SCHED_SLEEP == 1)
|
||||
OsSchedUpdateSleepTime();
|
||||
#endif
|
||||
|
||||
hwiIndex = HalIntNumGet();
|
||||
|
||||
OsHookCall(LOS_HOOK_TYPE_ISR_ENTER, hwiIndex);
|
||||
|
||||
HalPreInterruptHandler(hwiIndex);
|
||||
|
||||
#if (OS_HWI_WITH_ARG == 1)
|
||||
if (g_hwiHandlerForm[hwiIndex].pfnHandler != 0) {
|
||||
g_hwiHandlerForm[hwiIndex].pfnHandler((VOID *)g_hwiHandlerForm[hwiIndex].pParm);
|
||||
}
|
||||
#else
|
||||
if (g_hwiHandlerForm[hwiIndex] != 0) {
|
||||
g_hwiHandlerForm[hwiIndex]();
|
||||
}
|
||||
#endif
|
||||
|
||||
HalAftInterruptHandler(hwiIndex);
|
||||
|
||||
OsHookCall(LOS_HOOK_TYPE_ISR_EXIT, hwiIndex);
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
g_intCount--;
|
||||
LOS_IntRestore(intSave);
|
||||
}
|
||||
|
||||
/* ****************************************************************************
|
||||
Function : HalHwiCreate
|
||||
Description : create hardware interrupt
|
||||
Input : hwiNum --- hwi num to create
|
||||
hwiPrio --- priority of the hwi
|
||||
mode --- unused
|
||||
handler --- hwi handler
|
||||
arg --- param of the hwi handler
|
||||
Output : None
|
||||
Return : LOS_OK on success or error code on failure
|
||||
**************************************************************************** */
|
||||
LITE_OS_SEC_TEXT_INIT UINT32 HalHwiCreate(HWI_HANDLE_T hwiNum,
|
||||
HWI_PRIOR_T hwiPrio,
|
||||
HWI_MODE_T mode,
|
||||
HWI_PROC_FUNC handler,
|
||||
HWI_ARG_T arg)
|
||||
{
|
||||
UINTPTR intSave;
|
||||
|
||||
if (handler == NULL) {
|
||||
return OS_ERRNO_HWI_PROC_FUNC_NULL;
|
||||
}
|
||||
|
||||
if (hwiNum >= OS_HWI_MAX_NUM) {
|
||||
return OS_ERRNO_HWI_NUM_INVALID;
|
||||
}
|
||||
|
||||
if (g_hwiForm[hwiNum + OS_SYS_VECTOR_CNT] != (HWI_PROC_FUNC)HalHwiDefaultHandler) {
|
||||
return OS_ERRNO_HWI_ALREADY_CREATED;
|
||||
}
|
||||
|
||||
if (hwiPrio > OS_HWI_PRIO_LOWEST) {
|
||||
return OS_ERRNO_HWI_PRIO_INVALID;
|
||||
}
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
#if (OS_HWI_WITH_ARG == 1)
|
||||
OsSetVector(hwiNum, handler, arg);
|
||||
#else
|
||||
OsSetVector(hwiNum, handler);
|
||||
#endif
|
||||
NVIC_EnableIRQ((IRQn_Type)hwiNum);
|
||||
NVIC_SetPriority((IRQn_Type)hwiNum, hwiPrio);
|
||||
|
||||
LOS_IntRestore(intSave);
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
/* ****************************************************************************
|
||||
Function : HalHwiDelete
|
||||
Description : Delete hardware interrupt
|
||||
Input : hwiNum --- hwi num to delete
|
||||
Output : None
|
||||
Return : LOS_OK on success or error code on failure
|
||||
**************************************************************************** */
|
||||
LITE_OS_SEC_TEXT_INIT UINT32 HalHwiDelete(HWI_HANDLE_T hwiNum)
|
||||
{
|
||||
UINT32 intSave;
|
||||
|
||||
if (hwiNum >= OS_HWI_MAX_NUM) {
|
||||
return OS_ERRNO_HWI_NUM_INVALID;
|
||||
}
|
||||
|
||||
NVIC_DisableIRQ((IRQn_Type)hwiNum);
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
|
||||
g_hwiForm[hwiNum + OS_SYS_VECTOR_CNT] = (HWI_PROC_FUNC)HalHwiDefaultHandler;
|
||||
|
||||
LOS_IntRestore(intSave);
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
#define FAULT_STATUS_REG_BIT 32
|
||||
#define USGFAULT (1 << 18)
|
||||
#define BUSFAULT (1 << 17)
|
||||
#define MEMFAULT (1 << 16)
|
||||
#define DIV0FAULT (1 << 4)
|
||||
#define HARDFAULT_IRQN (-13)
|
||||
|
||||
ExcInfo g_excInfo = {0};
|
||||
|
||||
UINT8 g_uwExcTbl[FAULT_STATUS_REG_BIT] = {
|
||||
0, 0, 0, 0, 0, 0, OS_EXC_UF_DIVBYZERO, OS_EXC_UF_UNALIGNED,
|
||||
0, 0, 0, 0, OS_EXC_UF_NOCP, OS_EXC_UF_INVPC, OS_EXC_UF_INVSTATE, OS_EXC_UF_UNDEFINSTR,
|
||||
0, 0, 0, OS_EXC_BF_STKERR, OS_EXC_BF_UNSTKERR, OS_EXC_BF_IMPRECISERR, OS_EXC_BF_PRECISERR, OS_EXC_BF_IBUSERR,
|
||||
0, 0, 0, OS_EXC_MF_MSTKERR, OS_EXC_MF_MUNSTKERR, 0, OS_EXC_MF_DACCVIOL, OS_EXC_MF_IACCVIOL
|
||||
};
|
||||
|
||||
#if (LOSCFG_KERNEL_PRINTF != 0)
|
||||
STATIC VOID OsExcNvicDump(VOID)
|
||||
{
|
||||
#define OS_NR_NVIC_EXC_DUMP_TYPES 7
|
||||
UINT32 *base = NULL;
|
||||
UINT32 len, i, j;
|
||||
UINT32 rgNvicBases[OS_NR_NVIC_EXC_DUMP_TYPES] = {
|
||||
OS_NVIC_SETENA_BASE, OS_NVIC_SETPEND_BASE, OS_NVIC_INT_ACT_BASE,
|
||||
OS_NVIC_PRI_BASE, OS_NVIC_EXCPRI_BASE, OS_NVIC_SHCSR, OS_NVIC_INT_CTRL
|
||||
};
|
||||
UINT32 rgNvicLens[OS_NR_NVIC_EXC_DUMP_TYPES] = {
|
||||
OS_NVIC_INT_ENABLE_SIZE, OS_NVIC_INT_PEND_SIZE, OS_NVIC_INT_ACT_SIZE,
|
||||
OS_NVIC_INT_PRI_SIZE, OS_NVIC_EXCPRI_SIZE, OS_NVIC_SHCSR_SIZE,
|
||||
OS_NVIC_INT_CTRL_SIZE
|
||||
};
|
||||
CHAR strRgEnable[] = "enable";
|
||||
CHAR strRgPending[] = "pending";
|
||||
CHAR strRgActive[] = "active";
|
||||
CHAR strRgPriority[] = "priority";
|
||||
CHAR strRgException[] = "exception";
|
||||
CHAR strRgShcsr[] = "shcsr";
|
||||
CHAR strRgIntCtrl[] = "control";
|
||||
CHAR *strRgs[] = {
|
||||
strRgEnable, strRgPending, strRgActive, strRgPriority,
|
||||
strRgException, strRgShcsr, strRgIntCtrl
|
||||
};
|
||||
|
||||
PRINTK("\r\nOS exception NVIC dump:\n");
|
||||
for (i = 0; i < OS_NR_NVIC_EXC_DUMP_TYPES; i++) {
|
||||
base = (UINT32 *)rgNvicBases[i];
|
||||
len = rgNvicLens[i];
|
||||
PRINTK("interrupt %s register, base address: 0x%x, size: 0x%x\n", strRgs[i], base, len);
|
||||
len = (len >> 2); /* 2: Gets the next register offset */
|
||||
for (j = 0; j < len; j++) {
|
||||
PRINTK("0x%x ", *(base + j));
|
||||
if ((j != 0) && ((j % 16) == 0)) { /* 16: print wrap line */
|
||||
PRINTK("\n");
|
||||
}
|
||||
}
|
||||
PRINTK("\n");
|
||||
}
|
||||
}
|
||||
|
||||
STATIC VOID OsExcTypeInfo(const ExcInfo *excInfo)
|
||||
{
|
||||
CHAR *phaseStr[] = {"exc in init", "exc in task", "exc in hwi"};
|
||||
|
||||
PRINTK("Type = %d\n", excInfo->type);
|
||||
PRINTK("ThrdPid = %d\n", excInfo->thrdPid);
|
||||
PRINTK("Phase = %s\n", phaseStr[excInfo->phase]);
|
||||
PRINTK("FaultAddr = 0x%x\n", excInfo->faultAddr);
|
||||
}
|
||||
|
||||
STATIC VOID OsExcCurTaskInfo(const ExcInfo *excInfo)
|
||||
{
|
||||
PRINTK("Current task info:\n");
|
||||
if (excInfo->phase == OS_EXC_IN_TASK) {
|
||||
LosTaskCB *taskCB = OS_TCB_FROM_TID(LOS_CurTaskIDGet());
|
||||
PRINTK("Task name = %s\n", taskCB->taskName);
|
||||
PRINTK("Task ID = %d\n", taskCB->taskID);
|
||||
PRINTK("Task SP = 0x%x\n", taskCB->stackPointer);
|
||||
PRINTK("Task ST = 0x%x\n", taskCB->topOfStack);
|
||||
PRINTK("Task SS = 0x%x\n", taskCB->stackSize);
|
||||
} else if (excInfo->phase == OS_EXC_IN_HWI) {
|
||||
PRINTK("Exception occur in interrupt phase!\n");
|
||||
} else {
|
||||
PRINTK("Exception occur in system init phase!\n");
|
||||
}
|
||||
}
|
||||
|
||||
STATIC VOID OsExcRegInfo(const ExcInfo *excInfo)
|
||||
{
|
||||
PRINTK("Exception reg dump:\n");
|
||||
PRINTK("PC = 0x%x\n", excInfo->context->uwPC);
|
||||
PRINTK("LR = 0x%x\n", excInfo->context->uwLR);
|
||||
PRINTK("SP = 0x%x\n", excInfo->context->uwSP);
|
||||
PRINTK("R0 = 0x%x\n", excInfo->context->uwR0);
|
||||
PRINTK("R1 = 0x%x\n", excInfo->context->uwR1);
|
||||
PRINTK("R2 = 0x%x\n", excInfo->context->uwR2);
|
||||
PRINTK("R3 = 0x%x\n", excInfo->context->uwR3);
|
||||
PRINTK("R4 = 0x%x\n", excInfo->context->uwR4);
|
||||
PRINTK("R5 = 0x%x\n", excInfo->context->uwR5);
|
||||
PRINTK("R6 = 0x%x\n", excInfo->context->uwR6);
|
||||
PRINTK("R7 = 0x%x\n", excInfo->context->uwR7);
|
||||
PRINTK("R8 = 0x%x\n", excInfo->context->uwR8);
|
||||
PRINTK("R9 = 0x%x\n", excInfo->context->uwR9);
|
||||
PRINTK("R10 = 0x%x\n", excInfo->context->uwR10);
|
||||
PRINTK("R11 = 0x%x\n", excInfo->context->uwR11);
|
||||
PRINTK("R12 = 0x%x\n", excInfo->context->uwR12);
|
||||
PRINTK("PriMask = 0x%x\n", excInfo->context->uwPriMask);
|
||||
PRINTK("xPSR = 0x%x\n", excInfo->context->uwxPSR);
|
||||
}
|
||||
|
||||
STATIC VOID OsExcBackTraceInfo(const ExcInfo *excInfo)
|
||||
{
|
||||
UINTPTR LR[LOSCFG_BACKTRACE_DEPTH] = {0};
|
||||
UINT32 index;
|
||||
|
||||
OsBackTraceHookCall(LR, LOSCFG_BACKTRACE_DEPTH, 0, excInfo->context->uwSP);
|
||||
|
||||
PRINTK("----- backtrace start -----\n");
|
||||
for (index = 0; index < LOSCFG_BACKTRACE_DEPTH; index++) {
|
||||
if (LR[index] == 0) {
|
||||
break;
|
||||
}
|
||||
PRINTK("backtrace %d -- lr = 0x%x\n", index, LR[index]);
|
||||
}
|
||||
PRINTK("----- backtrace end -----\n");
|
||||
}
|
||||
|
||||
STATIC VOID OsExcMemPoolCheckInfo(VOID)
|
||||
{
|
||||
PRINTK("\r\nmemory pools check:\n");
|
||||
#if (LOSCFG_PLATFORM_EXC == 1)
|
||||
MemInfoCB memExcInfo[OS_SYS_MEM_NUM];
|
||||
UINT32 errCnt;
|
||||
UINT32 i;
|
||||
|
||||
(VOID)memset_s(memExcInfo, sizeof(memExcInfo), 0, sizeof(memExcInfo));
|
||||
|
||||
errCnt = OsMemExcInfoGet(OS_SYS_MEM_NUM, memExcInfo);
|
||||
if (errCnt < OS_SYS_MEM_NUM) {
|
||||
errCnt += OsMemboxExcInfoGet(OS_SYS_MEM_NUM - errCnt, memExcInfo + errCnt);
|
||||
}
|
||||
|
||||
if (errCnt == 0) {
|
||||
PRINTK("all memory pool check passed!\n");
|
||||
return;
|
||||
}
|
||||
|
||||
for (i = 0; i < errCnt; i++) {
|
||||
PRINTK("pool num = %d\n", i);
|
||||
PRINTK("pool type = %d\n", memExcInfo[i].type);
|
||||
PRINTK("pool addr = 0x%x\n", memExcInfo[i].startAddr);
|
||||
PRINTK("pool size = 0x%x\n", memExcInfo[i].size);
|
||||
PRINTK("pool free = 0x%x\n", memExcInfo[i].free);
|
||||
PRINTK("pool blkNum = %d\n", memExcInfo[i].blockSize);
|
||||
PRINTK("pool error node addr = 0x%x\n", memExcInfo[i].errorAddr);
|
||||
PRINTK("pool error node len = 0x%x\n", memExcInfo[i].errorLen);
|
||||
PRINTK("pool error node owner = %d\n", memExcInfo[i].errorOwner);
|
||||
}
|
||||
#endif
|
||||
UINT32 ret = LOS_MemIntegrityCheck(LOSCFG_SYS_HEAP_ADDR);
|
||||
if (ret == LOS_OK) {
|
||||
PRINTK("system heap memcheck over, all passed!\n");
|
||||
}
|
||||
|
||||
PRINTK("memory pool check end!\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
STATIC VOID OsExcInfoDisplay(const ExcInfo *excInfo)
|
||||
{
|
||||
#if (LOSCFG_KERNEL_PRINTF != 0)
|
||||
PRINTK("*************Exception Information**************\n");
|
||||
OsExcTypeInfo(excInfo);
|
||||
OsExcCurTaskInfo(excInfo);
|
||||
OsExcRegInfo(excInfo);
|
||||
OsExcBackTraceInfo(excInfo);
|
||||
OsGetAllTskInfo();
|
||||
OsExcNvicDump();
|
||||
OsExcMemPoolCheckInfo();
|
||||
#endif
|
||||
}
|
||||
|
||||
LITE_OS_SEC_TEXT_INIT VOID HalExcHandleEntry(UINT32 excType, UINT32 faultAddr, UINT32 pid, EXC_CONTEXT_S *excBufAddr)
|
||||
{
|
||||
UINT16 tmpFlag = (excType >> 16) & OS_NULL_SHORT; /* 16: Get Exception Type */
|
||||
g_intCount++;
|
||||
g_excInfo.nestCnt++;
|
||||
|
||||
g_excInfo.type = excType & OS_NULL_SHORT;
|
||||
|
||||
if (tmpFlag & OS_EXC_FLAG_FAULTADDR_VALID) {
|
||||
g_excInfo.faultAddr = faultAddr;
|
||||
} else {
|
||||
g_excInfo.faultAddr = OS_EXC_IMPRECISE_ACCESS_ADDR;
|
||||
}
|
||||
if (g_losTask.runTask != NULL) {
|
||||
if (tmpFlag & OS_EXC_FLAG_IN_HWI) {
|
||||
g_excInfo.phase = OS_EXC_IN_HWI;
|
||||
g_excInfo.thrdPid = pid;
|
||||
} else {
|
||||
g_excInfo.phase = OS_EXC_IN_TASK;
|
||||
g_excInfo.thrdPid = g_losTask.runTask->taskID;
|
||||
}
|
||||
} else {
|
||||
g_excInfo.phase = OS_EXC_IN_INIT;
|
||||
g_excInfo.thrdPid = OS_NULL_INT;
|
||||
}
|
||||
if (excType & OS_EXC_FLAG_NO_FLOAT) {
|
||||
g_excInfo.context = (EXC_CONTEXT_S *)((CHAR *)excBufAddr - LOS_OFF_SET_OF(EXC_CONTEXT_S, uwR4));
|
||||
} else {
|
||||
g_excInfo.context = excBufAddr;
|
||||
}
|
||||
|
||||
OsDoExcHook(EXC_INTERRUPT);
|
||||
OsExcInfoDisplay(&g_excInfo);
|
||||
HalSysExit();
|
||||
}
|
||||
|
||||
/* ****************************************************************************
|
||||
Function : HalHwiInit
|
||||
Description : initialization of the hardware interrupt
|
||||
Input : None
|
||||
Output : None
|
||||
Return : None
|
||||
**************************************************************************** */
|
||||
LITE_OS_SEC_TEXT_INIT VOID HalHwiInit()
|
||||
{
|
||||
#if (LOSCFG_USE_SYSTEM_DEFINED_INTERRUPT == 1)
|
||||
UINT32 index;
|
||||
g_hwiForm[0] = 0; /* [0] Top of Stack */
|
||||
g_hwiForm[1] = Reset_Handler; /* [1] reset */
|
||||
for (index = 2; index < OS_VECTOR_CNT; index++) { /* 2: The starting position of the interrupt */
|
||||
g_hwiForm[index] = (HWI_PROC_FUNC)HalHwiDefaultHandler;
|
||||
}
|
||||
/* Exception handler register */
|
||||
g_hwiForm[NonMaskableInt_IRQn + OS_SYS_VECTOR_CNT] = HalExcNMI;
|
||||
g_hwiForm[HARDFAULT_IRQN + OS_SYS_VECTOR_CNT] = HalExcHardFault;
|
||||
g_hwiForm[MemoryManagement_IRQn + OS_SYS_VECTOR_CNT] = HalExcMemFault;
|
||||
g_hwiForm[BusFault_IRQn + OS_SYS_VECTOR_CNT] = HalExcBusFault;
|
||||
g_hwiForm[UsageFault_IRQn + OS_SYS_VECTOR_CNT] = HalExcUsageFault;
|
||||
g_hwiForm[SVCall_IRQn + OS_SYS_VECTOR_CNT] = HalSVCHandler;
|
||||
g_hwiForm[PendSV_IRQn + OS_SYS_VECTOR_CNT] = HalPendSV;
|
||||
g_hwiForm[SysTick_IRQn + OS_SYS_VECTOR_CNT] = SysTick_Handler;
|
||||
|
||||
/* Interrupt vector table location */
|
||||
SCB->VTOR = (UINT32)(UINTPTR)g_hwiForm;
|
||||
#endif
|
||||
#if (__CORTEX_M >= 0x03U) /* only for Cortex-M3 and above */
|
||||
NVIC_SetPriorityGrouping(OS_NVIC_AIRCR_PRIGROUP);
|
||||
#endif
|
||||
|
||||
/* Enable USGFAULT, BUSFAULT, MEMFAULT */
|
||||
*(volatile UINT32 *)OS_NVIC_SHCSR |= (USGFAULT | BUSFAULT | MEMFAULT);
|
||||
/* Enable DIV 0 and unaligned exception */
|
||||
*(volatile UINT32 *)OS_NVIC_CCR |= DIV0FAULT;
|
||||
|
||||
return;
|
||||
}
|
||||
|
|
@ -0,0 +1,116 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "los_timer.h"
|
||||
#include "los_config.h"
|
||||
#include "los_tick.h"
|
||||
#include "los_arch_interrupt.h"
|
||||
#include "los_context.h"
|
||||
#include "los_sched.h"
|
||||
#include "los_debug.h"
|
||||
|
||||
/* ****************************************************************************
|
||||
Function : HalTickStart
|
||||
Description : Configure Tick Interrupt Start
|
||||
Input : none
|
||||
output : none
|
||||
return : LOS_OK - Success , or LOS_ERRNO_TICK_CFG_INVALID - failed
|
||||
**************************************************************************** */
|
||||
WEAK UINT32 HalTickStart(OS_TICK_HANDLER *handler)
|
||||
{
|
||||
UINT32 ret;
|
||||
|
||||
if ((OS_SYS_CLOCK == 0) ||
|
||||
(LOSCFG_BASE_CORE_TICK_PER_SECOND == 0) ||
|
||||
(LOSCFG_BASE_CORE_TICK_PER_SECOND > OS_SYS_CLOCK)) {
|
||||
return LOS_ERRNO_TICK_CFG_INVALID;
|
||||
}
|
||||
|
||||
#if (LOSCFG_USE_SYSTEM_DEFINED_INTERRUPT == 1)
|
||||
#if (OS_HWI_WITH_ARG == 1)
|
||||
OsSetVector(SysTick_IRQn, (HWI_PROC_FUNC)handler, NULL);
|
||||
#else
|
||||
OsSetVector(SysTick_IRQn, (HWI_PROC_FUNC)handler);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
g_sysClock = OS_SYS_CLOCK;
|
||||
g_cyclesPerTick = OS_SYS_CLOCK / LOSCFG_BASE_CORE_TICK_PER_SECOND;
|
||||
|
||||
ret = SysTick_Config(g_cyclesPerTick);
|
||||
if (ret == 1) {
|
||||
return LOS_ERRNO_TICK_PER_SEC_TOO_SMALL;
|
||||
}
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
WEAK VOID HalSysTickReload(UINT64 nextResponseTime)
|
||||
{
|
||||
SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk;
|
||||
SysTick->LOAD = (UINT32)(nextResponseTime - 1UL); /* set reload register */
|
||||
SysTick->VAL = 0UL; /* Load the SysTick Counter Value */
|
||||
NVIC_ClearPendingIRQ(SysTick_IRQn);
|
||||
SysTick->CTRL |= SysTick_CTRL_ENABLE_Msk;
|
||||
}
|
||||
|
||||
WEAK UINT64 HalGetTickCycle(UINT32 *period)
|
||||
{
|
||||
UINT32 hwCycle;
|
||||
UINTPTR intSave = LOS_IntLock();
|
||||
*period = SysTick->LOAD;
|
||||
hwCycle = *period - SysTick->VAL;
|
||||
LOS_IntRestore(intSave);
|
||||
return (UINT64)hwCycle;
|
||||
}
|
||||
|
||||
WEAK VOID HalTickLock(VOID)
|
||||
{
|
||||
SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk;
|
||||
}
|
||||
|
||||
WEAK VOID HalTickUnlock(VOID)
|
||||
{
|
||||
SysTick->CTRL |= SysTick_CTRL_ENABLE_Msk;
|
||||
}
|
||||
|
||||
VOID HalEnterSleep(LOS_SysSleepEnum sleep)
|
||||
{
|
||||
#if (LOSCFG_BASE_CORE_SCHED_SLEEP == 1)
|
||||
if (sleep == OS_SYS_DEEP_SLEEP) {
|
||||
OsSchedToSleep();
|
||||
}
|
||||
#endif
|
||||
|
||||
__DSB();
|
||||
__WFI();
|
||||
__ISB();
|
||||
}
|
|
@ -0,0 +1,158 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef LOS_ATOMIC_H
|
||||
#define LOS_ATOMIC_H
|
||||
|
||||
#include "los_compiler.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/**
|
||||
* @ingroup los_atomic
|
||||
* @brief Atomic exchange for 32-bit variable.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to implement the atomic exchange for 32-bit variable and return the previous value of the atomic variable.
|
||||
* @attention
|
||||
* <ul>The pointer v must not be NULL.</ul>
|
||||
*
|
||||
* @param v [IN] The variable pointer.
|
||||
* @param val [IN] The exchange value.
|
||||
*
|
||||
* @retval #INT32 The previous value of the atomic variable
|
||||
* @par Dependency:
|
||||
* <ul><li>los_atomic.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see
|
||||
*/
|
||||
STATIC INLINE INT32 HalAtomicXchg32bits(volatile INT32 *v, INT32 val)
|
||||
{
|
||||
INT32 prevVal = 0;
|
||||
UINT32 status = 0;
|
||||
|
||||
do {
|
||||
__asm__ __volatile__("ldrex %0, [%3]\n"
|
||||
"strex %1, %4, [%3]"
|
||||
: "=&r"(prevVal), "=&r"(status), "+m"(*v)
|
||||
: "r"(v), "r"(val)
|
||||
: "cc");
|
||||
} while (__builtin_expect(status != 0, 0));
|
||||
|
||||
return prevVal;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ingroup los_atomic
|
||||
* @brief Atomic auto-decrement.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to implementating the atomic auto-decrement and return the result of auto-decrement.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>The pointer v must not be NULL.</li>
|
||||
* <li>The value which v point to must not be INT_MIN to avoid overflow after reducing 1.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param v [IN] The addSelf variable pointer.
|
||||
*
|
||||
* @retval #INT32 The return value of variable auto-decrement.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_atomic.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see
|
||||
*/
|
||||
STATIC INLINE INT32 HalAtomicDecRet(volatile INT32 *v)
|
||||
{
|
||||
INT32 val = 0;
|
||||
UINT32 status = 0;
|
||||
|
||||
do {
|
||||
__asm__ __volatile__("ldrex %0, [%3]\n"
|
||||
"sub %0, %0, #1\n"
|
||||
"strex %1, %0, [%3]"
|
||||
: "=&r"(val), "=&r"(status), "+m"(*v)
|
||||
: "r"(v)
|
||||
: "cc");
|
||||
} while (__builtin_expect(status != 0, 0));
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ingroup los_atomic
|
||||
* @brief Atomic exchange for 32-bit variable with compare.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to implement the atomic exchange for 32-bit variable, if the value of variable is equal to oldVal.
|
||||
* @attention
|
||||
* <ul>The pointer v must not be NULL.</ul>
|
||||
*
|
||||
* @param v [IN] The variable pointer.
|
||||
* @param val [IN] The new value.
|
||||
* @param oldVal [IN] The old value.
|
||||
*
|
||||
* @retval TRUE The previous value of the atomic variable is not equal to oldVal.
|
||||
* @retval FALSE The previous value of the atomic variable is equal to oldVal.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_atomic.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see
|
||||
*/
|
||||
STATIC INLINE BOOL HalAtomicCmpXchg32bits(volatile INT32 *v, INT32 val, INT32 oldVal)
|
||||
{
|
||||
INT32 prevVal = 0;
|
||||
UINT32 status = 0;
|
||||
|
||||
do {
|
||||
__asm__ __volatile__("1: ldrex %0, %2\n"
|
||||
" mov %1, #0\n"
|
||||
" cmp %0, %3\n"
|
||||
" bne 2f\n"
|
||||
" strex %1, %4, %2\n"
|
||||
"2:"
|
||||
: "=&r"(prevVal), "=&r"(status), "+Q"(*v)
|
||||
: "r"(oldVal), "r"(val)
|
||||
: "cc");
|
||||
} while (__builtin_expect(status != 0, 0));
|
||||
|
||||
return prevVal != oldVal;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* LOS_ATOMIC_H */
|
||||
|
|
@ -0,0 +1,134 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef _LOS_ARCH_CONTEXT_H
|
||||
#define _LOS_ARCH_CONTEXT_H
|
||||
|
||||
#include "los_config.h"
|
||||
#include "los_compiler.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
typedef struct TagTskContext {
|
||||
UINT32 secureContext;
|
||||
UINT32 stackLmit;
|
||||
UINT32 excReturn;
|
||||
#if ((defined(__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \
|
||||
(defined(__FPU_USED) && (__FPU_USED == 1U)))
|
||||
UINT32 S16;
|
||||
UINT32 S17;
|
||||
UINT32 S18;
|
||||
UINT32 S19;
|
||||
UINT32 S20;
|
||||
UINT32 S21;
|
||||
UINT32 S22;
|
||||
UINT32 S23;
|
||||
UINT32 S24;
|
||||
UINT32 S25;
|
||||
UINT32 S26;
|
||||
UINT32 S27;
|
||||
UINT32 S28;
|
||||
UINT32 S29;
|
||||
UINT32 S30;
|
||||
UINT32 S31;
|
||||
#endif
|
||||
UINT32 uwR4;
|
||||
UINT32 uwR5;
|
||||
UINT32 uwR6;
|
||||
UINT32 uwR7;
|
||||
UINT32 uwR8;
|
||||
UINT32 uwR9;
|
||||
UINT32 uwR10;
|
||||
UINT32 uwR11;
|
||||
UINT32 uwPriMask;
|
||||
UINT32 uwR0;
|
||||
UINT32 uwR1;
|
||||
UINT32 uwR2;
|
||||
UINT32 uwR3;
|
||||
UINT32 uwR12;
|
||||
UINT32 uwLR;
|
||||
UINT32 uwPC;
|
||||
UINT32 uwxPSR;
|
||||
#if ((defined(__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \
|
||||
(defined(__FPU_USED) && (__FPU_USED == 1U)))
|
||||
UINT32 S0;
|
||||
UINT32 S1;
|
||||
UINT32 S2;
|
||||
UINT32 S3;
|
||||
UINT32 S4;
|
||||
UINT32 S5;
|
||||
UINT32 S6;
|
||||
UINT32 S7;
|
||||
UINT32 S8;
|
||||
UINT32 S9;
|
||||
UINT32 S10;
|
||||
UINT32 S11;
|
||||
UINT32 S12;
|
||||
UINT32 S13;
|
||||
UINT32 S14;
|
||||
UINT32 S15;
|
||||
UINT32 FPSCR;
|
||||
UINT32 NO_NAME;
|
||||
#endif
|
||||
} TaskContext;
|
||||
|
||||
/**
|
||||
* @ingroup los_config
|
||||
* @brief: Task start running function.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to start a task.
|
||||
*
|
||||
* @attention:
|
||||
* <ul><li>None.</li></ul>
|
||||
*
|
||||
* @param: None.
|
||||
*
|
||||
* @retval None.
|
||||
*
|
||||
* @par Dependency:
|
||||
* <ul><li>los_config.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see None.
|
||||
*/
|
||||
extern VOID HalStartToRun(VOID);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _LOS_ARCH_CONTEXT_H */
|
||||
|
|
@ -0,0 +1,717 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef _LOS_EXC_H
|
||||
#define _LOS_EXC_H
|
||||
|
||||
#include "los_config.h"
|
||||
#include "los_compiler.h"
|
||||
#include "los_interrupt.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Maximum number of used hardware interrupts.
|
||||
*/
|
||||
#ifndef OS_HWI_MAX_NUM
|
||||
#define OS_HWI_MAX_NUM LOSCFG_PLATFORM_HWI_LIMIT
|
||||
#endif
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Highest priority of a hardware interrupt.
|
||||
*/
|
||||
#ifndef OS_HWI_PRIO_HIGHEST
|
||||
#define OS_HWI_PRIO_HIGHEST 0
|
||||
#endif
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Lowest priority of a hardware interrupt.
|
||||
*/
|
||||
#ifndef OS_HWI_PRIO_LOWEST
|
||||
#define OS_HWI_PRIO_LOWEST 7
|
||||
#endif
|
||||
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Define the type of a hardware interrupt vector table function.
|
||||
*/
|
||||
typedef VOID (**HWI_VECTOR_FUNC)(void);
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Count of interrupts.
|
||||
*/
|
||||
extern UINT32 g_intCount;
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Count of M-Core system interrupt vector.
|
||||
*/
|
||||
#define OS_SYS_VECTOR_CNT 16
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Count of M-Core interrupt vector.
|
||||
*/
|
||||
#define OS_VECTOR_CNT (OS_SYS_VECTOR_CNT + OS_HWI_MAX_NUM)
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* AIRCR register priority group parameter .
|
||||
*/
|
||||
#define OS_NVIC_AIRCR_PRIGROUP 7
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Boot interrupt vector table.
|
||||
*/
|
||||
extern UINT32 _BootVectors[];
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Hardware interrupt error code: Invalid interrupt number.
|
||||
*
|
||||
* Value: 0x02000900
|
||||
*
|
||||
* Solution: Ensure that the interrupt number is valid. The value range of the interrupt number applicable for a Cortex-A7 platform is [OS_USER_HWI_MIN,OS_USER_HWI_MAX].
|
||||
*/
|
||||
#define OS_ERRNO_HWI_NUM_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x00)
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Hardware interrupt error code: Null hardware interrupt handling function.
|
||||
*
|
||||
* Value: 0x02000901
|
||||
*
|
||||
* Solution: Pass in a valid non-null hardware interrupt handling function.
|
||||
*/
|
||||
#define OS_ERRNO_HWI_PROC_FUNC_NULL LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x01)
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Hardware interrupt error code: Insufficient interrupt resources for hardware interrupt creation.
|
||||
*
|
||||
* Value: 0x02000902
|
||||
*
|
||||
* Solution: Increase the configured maximum number of supported hardware interrupts.
|
||||
*/
|
||||
#define OS_ERRNO_HWI_CB_UNAVAILABLE LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x02)
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Hardware interrupt error code: Insufficient memory for hardware interrupt initialization.
|
||||
*
|
||||
* Value: 0x02000903
|
||||
*
|
||||
* Solution: Expand the configured memory.
|
||||
*/
|
||||
#define OS_ERRNO_HWI_NO_MEMORY LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x03)
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Hardware interrupt error code: The interrupt has already been created.
|
||||
*
|
||||
* Value: 0x02000904
|
||||
*
|
||||
* Solution: Check whether the interrupt specified by the passed-in interrupt number has already been created.
|
||||
*/
|
||||
#define OS_ERRNO_HWI_ALREADY_CREATED LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x04)
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Hardware interrupt error code: Invalid interrupt priority.
|
||||
*
|
||||
* Value: 0x02000905
|
||||
*
|
||||
* Solution: Ensure that the interrupt priority is valid. The value range of the interrupt priority applicable for a Cortex-A7 platform is [0,15].
|
||||
*/
|
||||
#define OS_ERRNO_HWI_PRIO_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x05)
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Hardware interrupt error code: Incorrect interrupt creation mode.
|
||||
*
|
||||
* Value: 0x02000906
|
||||
*
|
||||
* Solution: The interrupt creation mode can be only set to OS_HWI_MODE_COMM or OS_HWI_MODE_FAST of which the value can be 0 or 1.
|
||||
*/
|
||||
#define OS_ERRNO_HWI_MODE_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x06)
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Hardware interrupt error code: The interrupt has already been created as a fast interrupt.
|
||||
*
|
||||
* Value: 0x02000907
|
||||
*
|
||||
* Solution: Check whether the interrupt specified by the passed-in interrupt number has already been created.
|
||||
*/
|
||||
#define OS_ERRNO_HWI_FASTMODE_ALREADY_CREATED LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x07)
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* SysTick control and status register.
|
||||
*/
|
||||
#define OS_SYSTICK_CONTROL_REG 0xE000E010
|
||||
|
||||
/* *
|
||||
* @ingroup los_hw
|
||||
* SysTick current value register.
|
||||
*/
|
||||
#define OS_SYSTICK_CURRENT_REG 0xE000E018
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Interrupt Priority-Level Registers.
|
||||
*/
|
||||
#define OS_NVIC_PRI_BASE 0xE000E400
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Interrupt enable register for 0-31.
|
||||
*/
|
||||
#define OS_NVIC_SETENA_BASE 0xE000E100
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* interrupt pending register.
|
||||
*/
|
||||
#define OS_NVIC_SETPEND_BASE 0xE000E200
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Interrupt active register.
|
||||
*/
|
||||
#define OS_NVIC_INT_ACT_BASE 0xE000E300
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Interrupt disable register for 0-31.
|
||||
*/
|
||||
#define OS_NVIC_CLRENA_BASE 0xE000E180
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Interrupt control and status register.
|
||||
*/
|
||||
#define OS_NVIC_INT_CTRL 0xE000ED04
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Vector table offset register.
|
||||
*/
|
||||
#define OS_NVIC_VTOR 0xE000ED08
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Application interrupt and reset control register
|
||||
*/
|
||||
#define OS_NVIC_AIRCR 0xE000ED0C
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* System exception priority register.
|
||||
*/
|
||||
#define OS_NVIC_EXCPRI_BASE 0xE000ED18
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Interrupt No. 1 :reset.
|
||||
*/
|
||||
#define OS_EXC_RESET 1
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Interrupt No. 2 :Non-Maskable Interrupt.
|
||||
*/
|
||||
#define OS_EXC_NMI 2
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Interrupt No. 3 :(hard)fault.
|
||||
*/
|
||||
#define OS_EXC_HARD_FAULT 3
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Interrupt No. 4 :MemManage fault.
|
||||
*/
|
||||
#define OS_EXC_MPU_FAULT 4
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Interrupt No. 5 :Bus fault.
|
||||
*/
|
||||
#define OS_EXC_BUS_FAULT 5
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Interrupt No. 6 :Usage fault.
|
||||
*/
|
||||
#define OS_EXC_USAGE_FAULT 6
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Interrupt No. 11 :SVCall.
|
||||
*/
|
||||
#define OS_EXC_SVC_CALL 11
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Interrupt No. 12 :Debug monitor.
|
||||
*/
|
||||
#define OS_EXC_DBG_MONITOR 12
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Interrupt No. 14 :PendSV.
|
||||
*/
|
||||
#define OS_EXC_PEND_SV 14
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Interrupt No. 15 :SysTick.
|
||||
*/
|
||||
#define OS_EXC_SYS_TICK 15
|
||||
|
||||
#if (OS_HWI_WITH_ARG == 1)
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Set interrupt vector table.
|
||||
*/
|
||||
extern VOID OsSetVector(UINT32 num, HWI_PROC_FUNC vector, VOID *arg);
|
||||
#else
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Set interrupt vector table.
|
||||
*/
|
||||
extern VOID OsSetVector(UINT32 num, HWI_PROC_FUNC vector);
|
||||
#endif
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* @brief: Hardware interrupt entry function.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used as all hardware interrupt handling function entry.
|
||||
*
|
||||
* @attention:
|
||||
* <ul><li>None.</li></ul>
|
||||
*
|
||||
* @param:None.
|
||||
*
|
||||
* @retval:None.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_hwi.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see None.
|
||||
*/
|
||||
extern VOID HalInterrupt(VOID);
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* @brief: Get an interrupt number.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to get the current interrupt number.
|
||||
*
|
||||
* @attention:
|
||||
* <ul><li>None.</li></ul>
|
||||
*
|
||||
* @param: None.
|
||||
*
|
||||
* @retval: Interrupt Indexes number.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_hwi.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see None.
|
||||
*/
|
||||
extern UINT32 HalIntNumGet(VOID);
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* @brief: Default vector handling function.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to configure interrupt for null function.
|
||||
*
|
||||
* @attention:
|
||||
* <ul><li>None.</li></ul>
|
||||
*
|
||||
* @param:None.
|
||||
*
|
||||
* @retval:None.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_hwi.h: the header file that contains the API declaration.</li
|
||||
></ul>
|
||||
* @see None.
|
||||
*/
|
||||
extern VOID HalHwiDefaultHandler(VOID);
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* @brief: Reset the vector table.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to reset the vector table.
|
||||
*
|
||||
* @attention:
|
||||
* <ul><li>None.</li></ul>
|
||||
*
|
||||
* @param:None.
|
||||
*
|
||||
* @retval:None.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_hwi.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see None.
|
||||
*/
|
||||
extern VOID Reset_Handler(VOID);
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* @brief: Pended System Call.
|
||||
*
|
||||
* @par Description:
|
||||
* PendSV can be pended and is useful for an OS to pend an exception
|
||||
* so that an action can be performed after other important tasks are completed.
|
||||
*
|
||||
* @attention:
|
||||
* <ul><li>None.</li></ul>
|
||||
*
|
||||
* @param:None.
|
||||
*
|
||||
* @retval:None.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_hwi.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see None.
|
||||
*/
|
||||
extern VOID HalPendSV(VOID);
|
||||
|
||||
|
||||
#define OS_EXC_IN_INIT 0
|
||||
#define OS_EXC_IN_TASK 1
|
||||
#define OS_EXC_IN_HWI 2
|
||||
|
||||
#define OS_EXC_MAX_BUF_LEN 25
|
||||
#define OS_EXC_MAX_NEST_DEPTH 1
|
||||
|
||||
#define OS_NVIC_SHCSR 0xE000ED24
|
||||
#define OS_NVIC_CCR 0xE000ED14
|
||||
|
||||
#define OS_NVIC_INT_ENABLE_SIZE 0x20
|
||||
#define OS_NVIC_INT_PRI_SIZE 0xF0
|
||||
#define OS_NVIC_EXCPRI_SIZE 0xC
|
||||
#define OS_NVIC_INT_CTRL_SIZE 4
|
||||
#define OS_NVIC_SHCSR_SIZE 4
|
||||
|
||||
#define OS_NVIC_INT_PEND_SIZE OS_NVIC_INT_ACT_SIZE
|
||||
#define OS_NVIC_INT_ACT_SIZE OS_NVIC_INT_ENABLE_SIZE
|
||||
|
||||
#define OS_EXC_FLAG_NO_FLOAT 0x10000000
|
||||
#define OS_EXC_FLAG_FAULTADDR_VALID 0x01
|
||||
#define OS_EXC_FLAG_IN_HWI 0x02
|
||||
|
||||
#define OS_EXC_IMPRECISE_ACCESS_ADDR 0xABABABAB
|
||||
|
||||
#define OS_EXC_EVENT 0x00000001
|
||||
|
||||
/**
|
||||
* @ingroup los_exc
|
||||
* the struct of register files
|
||||
*
|
||||
* description: the register files that saved when exception triggered
|
||||
*
|
||||
* notes:the following register with prefix 'uw' correspond to the registers in the cpu data sheet.
|
||||
*/
|
||||
typedef struct TagExcContext {
|
||||
#if ((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \
|
||||
(defined (__FPU_USED ) && (__FPU_USED == 1U)) )
|
||||
UINT32 S16;
|
||||
UINT32 S17;
|
||||
UINT32 S18;
|
||||
UINT32 S19;
|
||||
UINT32 S20;
|
||||
UINT32 S21;
|
||||
UINT32 S22;
|
||||
UINT32 S23;
|
||||
UINT32 S24;
|
||||
UINT32 S25;
|
||||
UINT32 S26;
|
||||
UINT32 S27;
|
||||
UINT32 S28;
|
||||
UINT32 S29;
|
||||
UINT32 S30;
|
||||
UINT32 S31;
|
||||
#endif
|
||||
UINT32 uwR4;
|
||||
UINT32 uwR5;
|
||||
UINT32 uwR6;
|
||||
UINT32 uwR7;
|
||||
UINT32 uwR8;
|
||||
UINT32 uwR9;
|
||||
UINT32 uwR10;
|
||||
UINT32 uwR11;
|
||||
UINT32 uwPriMask;
|
||||
/* auto save */
|
||||
UINT32 uwSP;
|
||||
UINT32 uwR0;
|
||||
UINT32 uwR1;
|
||||
UINT32 uwR2;
|
||||
UINT32 uwR3;
|
||||
UINT32 uwR12;
|
||||
UINT32 uwLR;
|
||||
UINT32 uwPC;
|
||||
UINT32 uwxPSR;
|
||||
#if ((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \
|
||||
(defined (__FPU_USED) && (__FPU_USED== 1U)))
|
||||
UINT32 S0;
|
||||
UINT32 S1;
|
||||
UINT32 S2;
|
||||
UINT32 S3;
|
||||
UINT32 S4;
|
||||
UINT32 S5;
|
||||
UINT32 S6;
|
||||
UINT32 S7;
|
||||
UINT32 S8;
|
||||
UINT32 S9;
|
||||
UINT32 S10;
|
||||
UINT32 S11;
|
||||
UINT32 S12;
|
||||
UINT32 S13;
|
||||
UINT32 S14;
|
||||
UINT32 S15;
|
||||
UINT32 FPSCR;
|
||||
UINT32 NO_NAME;
|
||||
#endif
|
||||
}EXC_CONTEXT_S;
|
||||
|
||||
typedef VOID (*EXC_PROC_FUNC)(UINT32, EXC_CONTEXT_S *);
|
||||
VOID HalExcHandleEntry(UINT32 excType, UINT32 faultAddr, UINT32 pid, EXC_CONTEXT_S *excBufAddr);
|
||||
|
||||
/**
|
||||
* @ingroup los_hwi
|
||||
* @brief: Exception initialization.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to configure the exception function vector table.
|
||||
*
|
||||
* @attention:
|
||||
* <ul><li>None.</li></ul>
|
||||
*
|
||||
* @param uwArraySize [IN] Memory size of exception.
|
||||
*
|
||||
* @retval: None
|
||||
* @par Dependency:
|
||||
* <ul><li>los_hwi.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see None.
|
||||
*/
|
||||
VOID OsExcInit(VOID);
|
||||
|
||||
VOID HalExcNMI(VOID);
|
||||
VOID HalExcHardFault(VOID);
|
||||
VOID HalExcMemFault(VOID);
|
||||
VOID HalExcBusFault(VOID);
|
||||
VOID HalExcUsageFault(VOID);
|
||||
VOID HalSVCHandler(VOID);
|
||||
VOID HalHwiInit();
|
||||
|
||||
|
||||
/**
|
||||
* @ingroup los_exc
|
||||
* Cortex-M exception types: An error occurred while the bus status register was being pushed.
|
||||
*/
|
||||
#define OS_EXC_BF_STKERR 1
|
||||
|
||||
/**
|
||||
* @ingroup los_exc
|
||||
* Cortex-M exception types: An error occurred while the bus status register was out of the stack.
|
||||
*/
|
||||
#define OS_EXC_BF_UNSTKERR 2
|
||||
|
||||
/**
|
||||
* @ingroup los_exc
|
||||
* Cortex-M exception types: Bus status register imprecise data access violation.
|
||||
*/
|
||||
#define OS_EXC_BF_IMPRECISERR 3
|
||||
|
||||
/**
|
||||
* @ingroup los_exc
|
||||
* Cortex-M exception types: Bus status register exact data access violation.
|
||||
*/
|
||||
#define OS_EXC_BF_PRECISERR 4
|
||||
|
||||
/**
|
||||
* @ingroup los_exc
|
||||
* Cortex-M exception types: Bus status register access violation while pointing.
|
||||
*/
|
||||
#define OS_EXC_BF_IBUSERR 5
|
||||
|
||||
/**
|
||||
* @ingroup los_exc
|
||||
* Cortex-M exception types: An error occurred while the memory management status register was being pushed.
|
||||
*/
|
||||
#define OS_EXC_MF_MSTKERR 6
|
||||
|
||||
/**
|
||||
* @ingroup los_exc
|
||||
* Cortex-M exception types: An error occurred while the memory management status register was out of the stack.
|
||||
*/
|
||||
#define OS_EXC_MF_MUNSTKERR 7
|
||||
|
||||
/**
|
||||
* @ingroup los_exc
|
||||
* Cortex-M exception types: Memory management status register data access violation.
|
||||
*/
|
||||
#define OS_EXC_MF_DACCVIOL 8
|
||||
|
||||
/**
|
||||
* @ingroup los_exc
|
||||
* Cortex-M exception types: Memory management status register access violation.
|
||||
*/
|
||||
#define OS_EXC_MF_IACCVIOL 9
|
||||
|
||||
|
||||
/**
|
||||
* @ingroup los_exc
|
||||
* Cortex-M exception types: Incorrect usage indicating that the divisor is zero during the division operation.
|
||||
*/
|
||||
#define OS_EXC_UF_DIVBYZERO 10
|
||||
|
||||
/**
|
||||
* @ingroup los_exc
|
||||
* Cortex-M exception types: Usage error, error caused by unaligned access.
|
||||
*/
|
||||
#define OS_EXC_UF_UNALIGNED 11
|
||||
|
||||
/**
|
||||
* @ingroup los_exc
|
||||
* Cortex-M exception types: Incorrect usage attempting to execute coprocessor related instruction.
|
||||
*/
|
||||
#define OS_EXC_UF_NOCP 12
|
||||
|
||||
/**
|
||||
* @ingroup los_exc
|
||||
* Cortex-M exception types: Usage error attempting to load EXC_RETURN to PC illegally on exception return.
|
||||
*/
|
||||
#define OS_EXC_UF_INVPC 13
|
||||
|
||||
/**
|
||||
* @ingroup los_exc
|
||||
* Cortex-M exception types: Incorrect usage, attempting to cut to ARM state.
|
||||
*/
|
||||
#define OS_EXC_UF_INVSTATE 14
|
||||
|
||||
/**
|
||||
* @ingroup los_exc
|
||||
* Cortex-M exception types: Incorrect usage. Executed instruction whose code is undefined.
|
||||
*/
|
||||
#define OS_EXC_UF_UNDEFINSTR 15
|
||||
|
||||
/**
|
||||
* @ingroup los_exc
|
||||
* Cortex-M exception types: NMI
|
||||
*/
|
||||
|
||||
#define OS_EXC_CAUSE_NMI 16
|
||||
|
||||
/**
|
||||
* @ingroup los_exc
|
||||
* Cortex-M exception types: hard fault
|
||||
*/
|
||||
#define OS_EXC_CAUSE_HARDFAULT 17
|
||||
|
||||
/**
|
||||
* @ingroup los_exc
|
||||
* Cortex-M exception types: The task handler exits.
|
||||
*/
|
||||
#define OS_EXC_CAUSE_TASK_EXIT 18
|
||||
|
||||
/**
|
||||
* @ingroup los_exc
|
||||
* Cortex-M exception types: A fatal error.
|
||||
*/
|
||||
#define OS_EXC_CAUSE_FATAL_ERR 19
|
||||
|
||||
/**
|
||||
* @ingroup los_exc
|
||||
* Cortex-M exception types: Hard Fault caused by a debug event.
|
||||
*/
|
||||
#define OS_EXC_CAUSE_DEBUGEVT 20
|
||||
|
||||
/**
|
||||
* @ingroup los_exc
|
||||
* Cortex-M exception types: A hard fault that occurs when a quantity is oriented.
|
||||
*/
|
||||
#define OS_EXC_CAUSE_VECTBL 21
|
||||
|
||||
/**
|
||||
* @ingroup los_exc
|
||||
* Exception information structure
|
||||
*
|
||||
* Description: Exception information saved when an exception is triggered on the Cortex-M4 platform.
|
||||
*
|
||||
*/
|
||||
typedef struct TagExcInfo {
|
||||
/**< Exception occurrence phase: 0 means that an exception occurs in initialization, 1 means that an exception occurs in a task, and 2 means that an exception occurs in an interrupt */
|
||||
UINT16 phase;
|
||||
/**< Exception type. When exceptions occur, check the numbers 1 - 21 listed above */
|
||||
UINT16 type;
|
||||
/**< If the exact address access error indicates the wrong access address when the exception occurred */
|
||||
UINT32 faultAddr;
|
||||
/**< An exception occurs in an interrupt, indicating the interrupt number. An exception occurs in the task, indicating the task ID, or 0xFFFFFFFF if it occurs during initialization */
|
||||
UINT32 thrdPid;
|
||||
/**< Number of nested exceptions. Currently only registered hook functions are supported when an exception is entered for the first time */
|
||||
UINT16 nestCnt;
|
||||
/**< reserve */
|
||||
UINT16 reserved;
|
||||
/**< Hardware context at the time an exception to the automatic stack floating-point register occurs */
|
||||
EXC_CONTEXT_S *context;
|
||||
} ExcInfo;
|
||||
|
||||
extern UINT32 g_curNestCount;
|
||||
extern UINT32 g_intCount;
|
||||
extern UINT8 g_uwExcTbl[32];
|
||||
extern ExcInfo g_excInfo;
|
||||
|
||||
#define MAX_INT_INFO_SIZE (8 + 0x164)
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _LOS_EXC_H */
|
|
@ -0,0 +1,54 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef _LOS_ARCH_TIMER_H
|
||||
#define _LOS_ARCH_TIMER_H
|
||||
|
||||
#include "los_config.h"
|
||||
#include "los_compiler.h"
|
||||
#include "los_context.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
UINT32 HalTickStart(OS_TICK_HANDLER handler);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _LOS_ARCH_TIMER_H */
|
||||
|
|
@ -0,0 +1,163 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "los_context.h"
|
||||
#include "securec.h"
|
||||
#include "los_arch_context.h"
|
||||
#include "los_arch_interrupt.h"
|
||||
#include "los_task.h"
|
||||
#include "los_sched.h"
|
||||
#include "los_interrupt.h"
|
||||
#include "los_arch_timer.h"
|
||||
|
||||
/* ****************************************************************************
|
||||
Function : HalArchInit
|
||||
Description : arch init function
|
||||
Input : None
|
||||
Output : None
|
||||
Return : None
|
||||
**************************************************************************** */
|
||||
LITE_OS_SEC_TEXT_INIT VOID HalArchInit()
|
||||
{
|
||||
HalHwiInit();
|
||||
}
|
||||
|
||||
/* ****************************************************************************
|
||||
Function : HalSysExit
|
||||
Description : Task exit function
|
||||
Input : None
|
||||
Output : None
|
||||
Return : None
|
||||
**************************************************************************** */
|
||||
LITE_OS_SEC_TEXT_MINOR VOID HalSysExit(VOID)
|
||||
{
|
||||
LOS_IntLock();
|
||||
while (1) {
|
||||
}
|
||||
}
|
||||
|
||||
/* ****************************************************************************
|
||||
Function : HalTskStackInit
|
||||
Description : Task stack initialization function
|
||||
Input : taskID --- TaskID
|
||||
stackSize --- Total size of the stack
|
||||
topStack --- Top of task's stack
|
||||
Output : None
|
||||
Return : Context pointer
|
||||
**************************************************************************** */
|
||||
LITE_OS_SEC_TEXT_INIT VOID *HalTskStackInit(UINT32 taskID, UINT32 stackSize, VOID *topStack)
|
||||
{
|
||||
TaskContext *context = NULL;
|
||||
errno_t result;
|
||||
|
||||
/* initialize the task stack, write magic num to stack top */
|
||||
result = memset_s(topStack, stackSize, (INT32)(OS_TASK_STACK_INIT & 0xFF), stackSize);
|
||||
if (result != EOK) {
|
||||
printf("memset_s is failed:%s[%d]\r\n", __FUNCTION__, __LINE__);
|
||||
}
|
||||
*((UINT32 *)(topStack)) = OS_TASK_MAGIC_WORD;
|
||||
|
||||
context = (TaskContext *)(((UINTPTR)topStack + stackSize) - sizeof(TaskContext));
|
||||
|
||||
#if ((defined(__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \
|
||||
(defined(__FPU_USED) && (__FPU_USED == 1U)))
|
||||
context->S16 = 0xAA000010;
|
||||
context->S17 = 0xAA000011;
|
||||
context->S18 = 0xAA000012;
|
||||
context->S19 = 0xAA000013;
|
||||
context->S20 = 0xAA000014;
|
||||
context->S21 = 0xAA000015;
|
||||
context->S22 = 0xAA000016;
|
||||
context->S23 = 0xAA000017;
|
||||
context->S24 = 0xAA000018;
|
||||
context->S25 = 0xAA000019;
|
||||
context->S26 = 0xAA00001A;
|
||||
context->S27 = 0xAA00001B;
|
||||
context->S28 = 0xAA00001C;
|
||||
context->S29 = 0xAA00001D;
|
||||
context->S30 = 0xAA00001E;
|
||||
context->S31 = 0xAA00001F;
|
||||
context->S0 = 0xAA000000;
|
||||
context->S1 = 0xAA000001;
|
||||
context->S2 = 0xAA000002;
|
||||
context->S3 = 0xAA000003;
|
||||
context->S4 = 0xAA000004;
|
||||
context->S5 = 0xAA000005;
|
||||
context->S6 = 0xAA000006;
|
||||
context->S7 = 0xAA000007;
|
||||
context->S8 = 0xAA000008;
|
||||
context->S9 = 0xAA000009;
|
||||
context->S10 = 0xAA00000A;
|
||||
context->S11 = 0xAA00000B;
|
||||
context->S12 = 0xAA00000C;
|
||||
context->S13 = 0xAA00000D;
|
||||
context->S14 = 0xAA00000E;
|
||||
context->S15 = 0xAA00000F;
|
||||
context->FPSCR = 0x00000000;
|
||||
context->NO_NAME = 0xAA000011;
|
||||
#endif
|
||||
|
||||
context->secureContext = 0UL;
|
||||
context->stackLmit = (UINT32)topStack;
|
||||
context->excReturn = 0xFFFFFFBC;
|
||||
|
||||
context->uwR4 = 0x04040404L;
|
||||
context->uwR5 = 0x05050505L;
|
||||
context->uwR6 = 0x06060606L;
|
||||
context->uwR7 = 0x07070707L;
|
||||
context->uwR8 = 0x08080808L;
|
||||
context->uwR9 = 0x09090909L;
|
||||
context->uwR10 = 0x10101010L;
|
||||
context->uwR11 = 0x11111111L;
|
||||
context->uwPriMask = 0;
|
||||
context->uwR0 = taskID;
|
||||
context->uwR1 = 0x01010101L;
|
||||
context->uwR2 = 0x02020202L;
|
||||
context->uwR3 = 0x03030303L;
|
||||
context->uwR12 = 0x12121212L;
|
||||
context->uwLR = (UINT32)(UINTPTR)HalSysExit;
|
||||
context->uwPC = (UINT32)(UINTPTR)OsTaskEntry;
|
||||
context->uwxPSR = 0x01000000L;
|
||||
|
||||
return (VOID *)context;
|
||||
}
|
||||
|
||||
LITE_OS_SEC_TEXT_INIT UINT32 HalStartSchedule(OS_TICK_HANDLER handler)
|
||||
{
|
||||
(VOID)LOS_IntLock();
|
||||
UINT32 ret = HalTickStart(handler);
|
||||
if (ret != LOS_OK) {
|
||||
return ret;
|
||||
}
|
||||
OsSchedStart();
|
||||
HalStartToRun();
|
||||
return LOS_OK; /* never return */
|
||||
}
|
|
@ -0,0 +1,225 @@
|
|||
;
|
||||
; Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
; Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
;
|
||||
; Redistribution and use in source and binary forms, with or without modification,
|
||||
; are permitted provided that the following conditions are met:
|
||||
;
|
||||
; 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
; conditions and the following disclaimer.
|
||||
;
|
||||
; 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
; of conditions and the following disclaimer in the documentation and/or other materials
|
||||
; provided with the distribution.
|
||||
;
|
||||
; 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
; to endorse or promote products derived from this software without specific prior written
|
||||
; permission.
|
||||
;
|
||||
; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
; THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
; PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
; CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
; EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
; WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
; OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
; ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
;
|
||||
|
||||
PRESERVE8
|
||||
|
||||
EXPORT HalIntLock
|
||||
EXPORT HalIntUnLock
|
||||
EXPORT HalIntRestore
|
||||
EXPORT HalTaskSchedule
|
||||
EXPORT HalPendSV
|
||||
EXPORT HalSVCHandler
|
||||
EXPORT HalStartFirstTask
|
||||
EXPORT HalSVCStartSchedule
|
||||
EXPORT HalSVCSecureContextAlloc
|
||||
EXPORT HalSVCSecureContextFree
|
||||
|
||||
IMPORT OsSchedTaskSwitch
|
||||
IMPORT g_losTask
|
||||
|
||||
EXTERN HalSecureSVCHandler
|
||||
EXTERN HalSecureContextSave
|
||||
EXTERN HalSecureContextLoad
|
||||
EXTERN g_secureContext
|
||||
|
||||
OS_FPU_CPACR EQU 0xE000ED88
|
||||
OS_FPU_CPACR_ENABLE EQU 0x00F00000
|
||||
OS_NVIC_INT_CTRL EQU 0xE000ED04
|
||||
OS_NVIC_SYSPRI2 EQU 0xE000ED20
|
||||
OS_NVIC_PENDSV_PRI EQU 0xF0F00000
|
||||
OS_NVIC_PENDSVSET EQU 0x10000000
|
||||
OS_TASK_STATUS_RUNNING EQU 0x0010
|
||||
|
||||
SECTION .text:CODE(2)
|
||||
THUMB
|
||||
REQUIRE8
|
||||
|
||||
HalStartFirstTask
|
||||
MOV R0, #2
|
||||
MSR CONTROL, R0
|
||||
|
||||
LDR R1, =g_losTask
|
||||
LDR R0, [R1, #4]
|
||||
|
||||
LDR R12, [R0] /* Get the stack pointer of the current task. */
|
||||
LDMFD R12!, {R1-R3} /* Read from stack: R1 = secureContext, R2 = stackLmit and R3 = excReturn.*/
|
||||
LDR R4, =g_secureContext
|
||||
STR R1, [R4] /* Set the secureContext to g_secureContext handler. */
|
||||
MSR PSPLIM, R2 /* Set the stackLmit for the PSPLIM about current task. */
|
||||
ISB
|
||||
|
||||
LDR.W R1, =OS_FPU_CPACR
|
||||
LDR R1, [R1]
|
||||
AND R1, R1, #OS_FPU_CPACR_ENABLE
|
||||
CMP R1, #OS_FPU_CPACR_ENABLE
|
||||
BNE __DisabledFPU1
|
||||
ADD R12, R12, #64
|
||||
VPUSH S0;
|
||||
VPOP S0;
|
||||
|
||||
__DisabledFPU1
|
||||
ADD R12, R12, #36
|
||||
MSR PSP, R12
|
||||
CPSIE I
|
||||
BX R3
|
||||
|
||||
HalIntLock
|
||||
MRS R0, PRIMASK
|
||||
CPSID I
|
||||
BX LR
|
||||
|
||||
HalIntUnLock
|
||||
MRS R0, PRIMASK
|
||||
CPSIE I
|
||||
BX LR
|
||||
|
||||
HalIntRestore
|
||||
MSR PRIMASK, R0
|
||||
BX LR
|
||||
|
||||
HalTaskSchedule
|
||||
LDR R0, =OS_NVIC_INT_CTRL
|
||||
LDR R1, =OS_NVIC_PENDSVSET
|
||||
STR R1, [R0]
|
||||
DSB
|
||||
ISB
|
||||
BX LR
|
||||
|
||||
HalPendSV
|
||||
MRS R12, PRIMASK
|
||||
CPSID I
|
||||
|
||||
HalTaskSwitch
|
||||
PUSH {R12, LR}
|
||||
BLX OsSchedTaskSwitch
|
||||
POP {R12, LR}
|
||||
CMP R0, #0
|
||||
MOV R0, LR
|
||||
BNE TaskContextSwitch
|
||||
MSR PRIMASK, R12
|
||||
BX LR
|
||||
|
||||
TaskContextSwitch
|
||||
MOV LR, R0
|
||||
MRS R0, PSP
|
||||
|
||||
LDR R2, =g_secureContext
|
||||
LDR R1, [R2]
|
||||
CBZ R1, __SaveNSContext /* If the g_secureContext is NULL, so no secure context to save. */
|
||||
|
||||
PUSH {R0-R1, R12, R14} /* Store registers, include LR, PRIMASK. */
|
||||
BL HalSecureContextSave /* Store the secure context to g_secureContext->curStackPointer. */
|
||||
POP {R0-R3}
|
||||
MOV LR, R3
|
||||
MOV R12, R2 /* R2 = PRIMASK. */
|
||||
|
||||
__SaveNSContext
|
||||
STMFD R0!, {R4-R12}
|
||||
LDR.W R3, =OS_FPU_CPACR
|
||||
LDR R3, [R3]
|
||||
AND R3, R3, #OS_FPU_CPACR_ENABLE
|
||||
CMP R3, #OS_FPU_CPACR_ENABLE
|
||||
BNE __DisabledFPU2
|
||||
VSTMDB R0!, {D8-D15}
|
||||
|
||||
__DisabledFPU2
|
||||
LDR R5, =g_losTask
|
||||
LDR R6, [R5] /* Get the stackPointer handler of the current task. */
|
||||
SUBS R0, R0, #12
|
||||
STR R0, [R6] /* Save the new top of stack in TCB. */
|
||||
MRS R2, PSPLIM
|
||||
MOV R3, LR
|
||||
STMIA R0!, {R1, R2-R3} /* Store g_secureContext, PSPLIM and LR on the stack of current task. */
|
||||
|
||||
LDR R0, [R5, #4]
|
||||
STR R0, [R5]
|
||||
|
||||
LDR R1, [R0]
|
||||
LDMIA R1!, {R0, R2-R3} /* Restore secureContext, PSPLIM and LR from the current task stack. */
|
||||
MSR PSPLIM, R2
|
||||
MOV LR, R3
|
||||
LDR R2, =g_secureContext
|
||||
STR R0, [R2] /* Set the secureContext of the new task to g_secureContext. */
|
||||
CBZ R0, __RestoreNSContext /* If there is no secure context for the new task, so restore from the non-secure context. */
|
||||
PUSH {R1, R3}
|
||||
BL HalSecureContextLoad /* Restore the secure context. */
|
||||
POP {R1, R3}
|
||||
MOV LR, R3
|
||||
|
||||
__RestoreNSContext
|
||||
LDR.W R3, =OS_FPU_CPACR
|
||||
LDR R3, [R3]
|
||||
AND R3, R3, #OS_FPU_CPACR_ENABLE
|
||||
CMP R3, #OS_FPU_CPACR_ENABLE
|
||||
BNE __DisabledFPU3
|
||||
VLDMIA R1!, {D8-D15}
|
||||
|
||||
__DisabledFPU3
|
||||
LDMFD R1!, {R4-R12}
|
||||
MSR PSP, R1
|
||||
|
||||
MSR PRIMASK, R12
|
||||
BX LR
|
||||
|
||||
HalSVCStartSchedule
|
||||
LDR R4, =OS_NVIC_SYSPRI2
|
||||
LDR R5, =OS_NVIC_PENDSV_PRI
|
||||
STR R5, [R4]
|
||||
CPSIE I
|
||||
DSB
|
||||
ISB
|
||||
SVC 2
|
||||
|
||||
HalSVCSecureContextAlloc
|
||||
SVC 0
|
||||
BX LR
|
||||
|
||||
HalSVCSecureContextFree
|
||||
SVC 1
|
||||
BX LR
|
||||
|
||||
HalSVCHandler
|
||||
TST LR, #0x04
|
||||
ITE EQ
|
||||
MRSEQ R1, MSP
|
||||
MRSNE R1, PSP
|
||||
LDR R0, [R1, #24]
|
||||
LDRB R0, [R0, #-2] /* Get the SVC number. */
|
||||
|
||||
PUSH {LR}
|
||||
MOV R2, R1 /* Get the stack for R2. */
|
||||
LDMFD R2!, {R1} /* Get the input arg for HalSecureSVCHandler. */
|
||||
STMFD R2!, {R1}
|
||||
BL HalSecureSVCHandler
|
||||
POP {LR}
|
||||
BX LR
|
||||
|
||||
END
|
|
@ -0,0 +1,274 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
PRESERVE8
|
||||
SECTION .text:CODE(2)
|
||||
THUMB
|
||||
|
||||
EXPORT HalExcNMI
|
||||
EXPORT HalExcHardFault
|
||||
EXPORT HalExcMemFault
|
||||
EXPORT HalExcBusFault
|
||||
EXPORT HalExcUsageFault
|
||||
|
||||
IMPORT HalExcHandleEntry
|
||||
IMPORT g_uwExcTbl
|
||||
IMPORT g_taskScheduled
|
||||
|
||||
OS_FLG_BGD_ACTIVE EQU 0x0002
|
||||
|
||||
OS_EXC_CAUSE_NMI EQU 16
|
||||
OS_EXC_CAUSE_HARDFAULT EQU 17
|
||||
|
||||
HF_DEBUGEVT EQU 20
|
||||
HF_VECTBL EQU 21
|
||||
|
||||
FLAG_ADDR_VALID EQU 0x10000
|
||||
FLAG_HWI_ACTIVE EQU 0x20000
|
||||
FLAG_NO_FLOAT EQU 0x10000000
|
||||
|
||||
OS_NVIC_FSR EQU 0xE000ED28 ;include BusFault/MemFault/UsageFault State Regeister
|
||||
OS_NVIC_HFSR EQU 0xE000ED2C ;HardFault State Regeister
|
||||
OS_NVIC_BFAR EQU 0xE000ED38
|
||||
OS_NVIC_MMAR EQU 0xE000ED34
|
||||
OS_NVIC_ACT_BASE EQU 0xE000E300
|
||||
OS_NVIC_SHCSRS EQU 0xE000ED24
|
||||
OS_NVIC_SHCSR_MASK EQU 0xC00
|
||||
|
||||
HalExcNMI
|
||||
MOV R0, #OS_EXC_CAUSE_NMI
|
||||
MOV R1, #0
|
||||
B osExcDispatch
|
||||
|
||||
HalExcHardFault
|
||||
MOV R0, #OS_EXC_CAUSE_HARDFAULT
|
||||
LDR R2, =OS_NVIC_HFSR
|
||||
LDR R2, [R2]
|
||||
|
||||
MOV R1, #HF_DEBUGEVT
|
||||
ORR R0, R0, R1, LSL #0x8
|
||||
TST R2, #0x80000000
|
||||
BNE osExcDispatch ; DEBUGEVT
|
||||
|
||||
AND R0, R0 , #0x000000FF
|
||||
MOV R1, #HF_VECTBL
|
||||
ORR R0, R0, R1, LSL #0x8
|
||||
TST R2, #0x00000002
|
||||
BNE osExcDispatch ; VECTBL
|
||||
|
||||
;if not DEBUGEVT and VECTBL then is FORCED
|
||||
AND R0, R0, #0x000000FF
|
||||
|
||||
LDR R2, =OS_NVIC_FSR
|
||||
LDR R2, [R2]
|
||||
|
||||
TST R2, #0x8000 ; BFARVALID
|
||||
BNE _HFBusFault ; BusFault
|
||||
|
||||
TST R2, #0x80 ; MMARVALID
|
||||
BNE _HFMemFault ; MemFault
|
||||
|
||||
MOV R12,#0
|
||||
B osHFExcCommonBMU
|
||||
|
||||
_HFBusFault
|
||||
LDR R1, =OS_NVIC_BFAR
|
||||
LDR R1, [R1]
|
||||
MOV R12, #FLAG_ADDR_VALID
|
||||
B osHFExcCommonBMU
|
||||
|
||||
_HFMemFault
|
||||
LDR R1, =OS_NVIC_MMAR
|
||||
LDR R1, [R1]
|
||||
MOV R12, #FLAG_ADDR_VALID
|
||||
|
||||
osHFExcCommonBMU
|
||||
CLZ R2, R2
|
||||
LDR R3, =g_uwExcTbl
|
||||
ADD R3, R3, R2
|
||||
LDRB R2, [R3]
|
||||
ORR R0, R0, R2, LSL #0x8
|
||||
ORR R0, R0 ,R12
|
||||
B osExcDispatch
|
||||
|
||||
HalExcBusFault
|
||||
LDR R0, =OS_NVIC_FSR
|
||||
LDR R0, [R0]
|
||||
|
||||
TST R0, #0x8000 ; BFARVALID
|
||||
BEQ _ExcBusNoADDR
|
||||
LDR R1, =OS_NVIC_BFAR
|
||||
LDR R1, [R1]
|
||||
MOV R12, #FLAG_ADDR_VALID
|
||||
AND R0, R0, #0x1F00
|
||||
|
||||
B osExcCommonBMU
|
||||
|
||||
_ExcBusNoADDR
|
||||
MOV R12,#0
|
||||
B osExcCommonBMU
|
||||
|
||||
HalExcMemFault
|
||||
LDR R0, =OS_NVIC_FSR
|
||||
LDR R0, [R0]
|
||||
|
||||
TST R0, #0x80 ; MMARVALID
|
||||
BEQ _ExcMemNoADDR
|
||||
LDR R1, =OS_NVIC_MMAR
|
||||
LDR R1, [R1]
|
||||
MOV R12, #FLAG_ADDR_VALID
|
||||
AND R0, R0, #0x1B
|
||||
|
||||
B osExcCommonBMU
|
||||
|
||||
_ExcMemNoADDR
|
||||
MOV R12,#0
|
||||
B osExcCommonBMU
|
||||
|
||||
HalExcUsageFault
|
||||
LDR R0, =OS_NVIC_FSR
|
||||
LDR R0, [R0]
|
||||
|
||||
MOV R1, #0x030F
|
||||
LSL R1, R1, #16
|
||||
AND R0, R0, R1
|
||||
MOV R12, #0
|
||||
|
||||
osExcCommonBMU
|
||||
CLZ R0, R0
|
||||
LDR R3, =g_uwExcTbl
|
||||
ADD R3, R3, R0
|
||||
LDRB R0, [R3]
|
||||
ORR R0, R0, R12
|
||||
|
||||
; R0 -- EXCCAUSE(bit 16 is 1 if EXCADDR valid), R1 -- EXCADDR
|
||||
osExcDispatch
|
||||
LDR R2, =OS_NVIC_ACT_BASE
|
||||
MOV R12, #8 ; R12 is hwi check loop counter
|
||||
|
||||
_hwiActiveCheck
|
||||
LDR R3, [R2] ; R3 store active hwi register when exc
|
||||
CMP R3, #0
|
||||
BEQ _hwiActiveCheckNext
|
||||
|
||||
; exc occured in IRQ
|
||||
ORR R0, R0, #FLAG_HWI_ACTIVE
|
||||
RBIT R2, R3
|
||||
CLZ R2, R2
|
||||
AND R12, R12, #1
|
||||
ADD R2, R2, R12, LSL #5 ; calculate R2 (hwi number) as uwPid
|
||||
|
||||
_ExcInMSP
|
||||
CMP LR, #0XFFFFFFED
|
||||
BNE _NoFloatInMsp
|
||||
ADD R3, R13, #104
|
||||
PUSH {R3}
|
||||
MRS R12, PRIMASK ; store message-->exc: disable int?
|
||||
PUSH {R4-R12} ; store message-->exc: {R4-R12}
|
||||
VPUSH {D8-D15}
|
||||
B _handleEntry
|
||||
|
||||
_NoFloatInMsp
|
||||
ADD R3, R13, #32
|
||||
PUSH {R3} ; save IRQ SP ; store message-->exc: MSP(R13)
|
||||
|
||||
MRS R12, PRIMASK ; store message-->exc: disable int?
|
||||
PUSH {R4-R12} ; store message-->exc: {R4-R12}
|
||||
ORR R0, R0, #FLAG_NO_FLOAT
|
||||
B _handleEntry
|
||||
|
||||
_hwiActiveCheckNext
|
||||
ADD R2, R2, #4 ; next NVIC ACT ADDR
|
||||
SUBS R12, R12, #1
|
||||
BNE _hwiActiveCheck
|
||||
|
||||
;/*NMI interrupt excption*/
|
||||
LDR R2, =OS_NVIC_SHCSRS
|
||||
LDRH R2,[R2]
|
||||
LDR R3,=OS_NVIC_SHCSR_MASK
|
||||
AND R2, R2,R3
|
||||
CMP R2,#0
|
||||
BNE _ExcInMSP
|
||||
; exc occured in Task or Init or exc
|
||||
; reserved for register info from task stack
|
||||
|
||||
LDR R2, =g_taskScheduled
|
||||
LDR R2, [R2]
|
||||
TST R2, #1 ; OS_FLG_BGD_ACTIVE
|
||||
BEQ _ExcInMSP ; if exc occured in Init then branch
|
||||
|
||||
|
||||
CMP LR, #0xFFFFFFED ;auto push floating registers
|
||||
BNE _NoFloatInPsp
|
||||
|
||||
; exc occured in Task
|
||||
MOV R2, R13
|
||||
SUB R13, #96 ; add 8 Bytes reg(for STMFD)
|
||||
|
||||
MRS R3, PSP
|
||||
ADD R12, R3, #104
|
||||
PUSH {R12} ; save task SP
|
||||
|
||||
MRS R12, PRIMASK
|
||||
PUSH {R4-R12}
|
||||
VPUSH {D8-D15}
|
||||
|
||||
; copy auto saved task register
|
||||
|
||||
LDMFD R3!, {R4-R11} ; R4-R11 store PSP reg(auto push when exc in task)
|
||||
VLDMIA R3!, {D8-D15}
|
||||
VSTMDB R2!, {D8-D15}
|
||||
STMFD R2!, {R4-R11}
|
||||
B _handleEntry
|
||||
|
||||
_NoFloatInPsp
|
||||
MOV R2, R13 ;no auto push floating registers
|
||||
SUB R13, #32 ; add 8 Bytes reg(for STMFD)
|
||||
|
||||
MRS R3, PSP
|
||||
ADD R12, R3, #32
|
||||
PUSH {R12} ; save task SP
|
||||
|
||||
MRS R12, PRIMASK
|
||||
PUSH {R4-R12}
|
||||
|
||||
LDMFD R3, {R4-R11} ; R4-R11 store PSP reg(auto push when exc in task)
|
||||
STMFD R2!, {R4-R11}
|
||||
ORR R0, R0, #FLAG_NO_FLOAT
|
||||
|
||||
_handleEntry
|
||||
MOV R3, R13 ; R13:the 4th param
|
||||
CPSID I
|
||||
CPSID F
|
||||
B HalExcHandleEntry
|
||||
|
||||
NOP
|
||||
END
|
|
@ -0,0 +1,532 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "los_interrupt.h"
|
||||
#include "securec.h"
|
||||
#include <stdarg.h>
|
||||
#include "los_arch_interrupt.h"
|
||||
#include "los_context.h"
|
||||
#include "los_debug.h"
|
||||
#include "los_hook.h"
|
||||
#include "los_task.h"
|
||||
#include "los_sched.h"
|
||||
#include "los_memory.h"
|
||||
#include "los_membox.h"
|
||||
|
||||
|
||||
/*lint -save -e40 -e522 -e533*/
|
||||
UINT32 g_intCount = 0;
|
||||
|
||||
/*lint -restore*/
|
||||
#pragma location = ".data.vector"
|
||||
#pragma data_alignment=0x100
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* hardware interrupt form mapping handling function array.
|
||||
*/
|
||||
STATIC HWI_PROC_FUNC g_hwiForm[OS_VECTOR_CNT] = {0};
|
||||
|
||||
#if (OS_HWI_WITH_ARG == 1)
|
||||
|
||||
typedef struct {
|
||||
HWI_PROC_FUNC pfnHandler;
|
||||
VOID *pParm;
|
||||
} HWI_HANDLER_FUNC;
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* hardware interrupt handler form mapping handling function array.
|
||||
*/
|
||||
STATIC HWI_HANDLER_FUNC g_hwiHandlerForm[OS_VECTOR_CNT] = {{ (HWI_PROC_FUNC)0, (HWI_ARG_T)0 }};
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Set interrupt vector table.
|
||||
*/
|
||||
VOID OsSetVector(UINT32 num, HWI_PROC_FUNC vector, VOID *arg)
|
||||
{
|
||||
if ((num + OS_SYS_VECTOR_CNT) < OS_VECTOR_CNT) {
|
||||
g_hwiForm[num + OS_SYS_VECTOR_CNT] = (HWI_PROC_FUNC)HalInterrupt;
|
||||
g_hwiHandlerForm[num + OS_SYS_VECTOR_CNT].pfnHandler = vector;
|
||||
g_hwiHandlerForm[num + OS_SYS_VECTOR_CNT].pParm = arg;
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* hardware interrupt handler form mapping handling function array.
|
||||
*/
|
||||
STATIC HWI_PROC_FUNC g_hwiHandlerForm[OS_VECTOR_CNT] = {0};
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Set interrupt vector table.
|
||||
*/
|
||||
VOID OsSetVector(UINT32 num, HWI_PROC_FUNC vector)
|
||||
{
|
||||
if ((num + OS_SYS_VECTOR_CNT) < OS_VECTOR_CNT) {
|
||||
g_hwiForm[num + OS_SYS_VECTOR_CNT] = HalInterrupt;
|
||||
g_hwiHandlerForm[num + OS_SYS_VECTOR_CNT] = vector;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
WEAK VOID SysTick_Handler(VOID)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
/* ****************************************************************************
|
||||
Function : HalIntNumGet
|
||||
Description : Get an interrupt number
|
||||
Input : None
|
||||
Output : None
|
||||
Return : Interrupt Indexes number
|
||||
**************************************************************************** */
|
||||
LITE_OS_SEC_TEXT_MINOR UINT32 HalIntNumGet(VOID)
|
||||
{
|
||||
return __get_IPSR();
|
||||
}
|
||||
|
||||
inline UINT32 HalIsIntActive(VOID)
|
||||
{
|
||||
return (g_intCount > 0);
|
||||
}
|
||||
/* ****************************************************************************
|
||||
Function : HalHwiDefaultHandler
|
||||
Description : default handler of the hardware interrupt
|
||||
Input : None
|
||||
Output : None
|
||||
Return : None
|
||||
**************************************************************************** */
|
||||
/*lint -e529*/
|
||||
LITE_OS_SEC_TEXT_MINOR VOID HalHwiDefaultHandler(VOID)
|
||||
{
|
||||
UINT32 irqNum = HalIntNumGet();
|
||||
PRINT_ERR("%s irqnum:%d\n", __FUNCTION__, irqNum);
|
||||
while (1) {}
|
||||
}
|
||||
|
||||
WEAK VOID HalPreInterruptHandler(UINT32 arg)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
WEAK VOID HalAftInterruptHandler(UINT32 arg)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
/* ****************************************************************************
|
||||
Function : HalInterrupt
|
||||
Description : Hardware interrupt entry function
|
||||
Input : None
|
||||
Output : None
|
||||
Return : None
|
||||
**************************************************************************** */
|
||||
LITE_OS_SEC_TEXT VOID HalInterrupt(VOID)
|
||||
{
|
||||
UINT32 hwiIndex;
|
||||
UINT32 intSave;
|
||||
|
||||
#if (LOSCFG_KERNEL_RUNSTOP == 1)
|
||||
SCB->SCR &= (UINT32) ~((UINT32)SCB_SCR_SLEEPDEEP_Msk);
|
||||
#endif
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
|
||||
g_intCount++;
|
||||
|
||||
LOS_IntRestore(intSave);
|
||||
|
||||
#if (LOSCFG_BASE_CORE_SCHED_SLEEP == 1)
|
||||
OsSchedUpdateSleepTime();
|
||||
#endif
|
||||
|
||||
hwiIndex = HalIntNumGet();
|
||||
|
||||
OsHookCall(LOS_HOOK_TYPE_ISR_ENTER, hwiIndex);
|
||||
|
||||
HalPreInterruptHandler(hwiIndex);
|
||||
|
||||
#if (OS_HWI_WITH_ARG == 1)
|
||||
if (g_hwiHandlerForm[hwiIndex].pfnHandler != 0) {
|
||||
g_hwiHandlerForm[hwiIndex].pfnHandler((VOID *)g_hwiHandlerForm[hwiIndex].pParm);
|
||||
}
|
||||
#else
|
||||
if (g_hwiHandlerForm[hwiIndex] != 0) {
|
||||
g_hwiHandlerForm[hwiIndex]();
|
||||
}
|
||||
#endif
|
||||
|
||||
HalAftInterruptHandler(hwiIndex);
|
||||
|
||||
OsHookCall(LOS_HOOK_TYPE_ISR_EXIT, hwiIndex);
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
g_intCount--;
|
||||
LOS_IntRestore(intSave);
|
||||
}
|
||||
|
||||
/* ****************************************************************************
|
||||
Function : HalHwiCreate
|
||||
Description : create hardware interrupt
|
||||
Input : hwiNum --- hwi num to create
|
||||
hwiPrio --- priority of the hwi
|
||||
mode --- unused
|
||||
handler --- hwi handler
|
||||
arg --- param of the hwi handler
|
||||
Output : None
|
||||
Return : LOS_OK on success or error code on failure
|
||||
**************************************************************************** */
|
||||
LITE_OS_SEC_TEXT_INIT UINT32 HalHwiCreate(HWI_HANDLE_T hwiNum,
|
||||
HWI_PRIOR_T hwiPrio,
|
||||
HWI_MODE_T mode,
|
||||
HWI_PROC_FUNC handler,
|
||||
HWI_ARG_T arg)
|
||||
{
|
||||
UINTPTR intSave;
|
||||
|
||||
if (handler == NULL) {
|
||||
return OS_ERRNO_HWI_PROC_FUNC_NULL;
|
||||
}
|
||||
|
||||
if (hwiNum >= OS_HWI_MAX_NUM) {
|
||||
return OS_ERRNO_HWI_NUM_INVALID;
|
||||
}
|
||||
|
||||
if (g_hwiForm[hwiNum + OS_SYS_VECTOR_CNT] != (HWI_PROC_FUNC)HalHwiDefaultHandler) {
|
||||
return OS_ERRNO_HWI_ALREADY_CREATED;
|
||||
}
|
||||
|
||||
if (hwiPrio > OS_HWI_PRIO_LOWEST) {
|
||||
return OS_ERRNO_HWI_PRIO_INVALID;
|
||||
}
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
#if (OS_HWI_WITH_ARG == 1)
|
||||
OsSetVector(hwiNum, handler, arg);
|
||||
#else
|
||||
OsSetVector(hwiNum, handler);
|
||||
#endif
|
||||
NVIC_EnableIRQ((IRQn_Type)hwiNum);
|
||||
NVIC_SetPriority((IRQn_Type)hwiNum, hwiPrio);
|
||||
|
||||
LOS_IntRestore(intSave);
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
/* ****************************************************************************
|
||||
Function : HalHwiDelete
|
||||
Description : Delete hardware interrupt
|
||||
Input : hwiNum --- hwi num to delete
|
||||
Output : None
|
||||
Return : LOS_OK on success or error code on failure
|
||||
**************************************************************************** */
|
||||
LITE_OS_SEC_TEXT_INIT UINT32 HalHwiDelete(HWI_HANDLE_T hwiNum)
|
||||
{
|
||||
UINT32 intSave;
|
||||
|
||||
if (hwiNum >= OS_HWI_MAX_NUM) {
|
||||
return OS_ERRNO_HWI_NUM_INVALID;
|
||||
}
|
||||
|
||||
NVIC_DisableIRQ((IRQn_Type)hwiNum);
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
|
||||
g_hwiForm[hwiNum + OS_SYS_VECTOR_CNT] = (HWI_PROC_FUNC)HalHwiDefaultHandler;
|
||||
|
||||
LOS_IntRestore(intSave);
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
#define FAULT_STATUS_REG_BIT 32
|
||||
#define USGFAULT (1 << 18)
|
||||
#define BUSFAULT (1 << 17)
|
||||
#define MEMFAULT (1 << 16)
|
||||
#define DIV0FAULT (1 << 4)
|
||||
#define HARDFAULT_IRQN (-13)
|
||||
|
||||
ExcInfo g_excInfo = {0};
|
||||
|
||||
UINT8 g_uwExcTbl[FAULT_STATUS_REG_BIT] = {
|
||||
0, 0, 0, 0, 0, 0, OS_EXC_UF_DIVBYZERO, OS_EXC_UF_UNALIGNED,
|
||||
0, 0, 0, 0, OS_EXC_UF_NOCP, OS_EXC_UF_INVPC, OS_EXC_UF_INVSTATE, OS_EXC_UF_UNDEFINSTR,
|
||||
0, 0, 0, OS_EXC_BF_STKERR, OS_EXC_BF_UNSTKERR, OS_EXC_BF_IMPRECISERR, OS_EXC_BF_PRECISERR, OS_EXC_BF_IBUSERR,
|
||||
0, 0, 0, OS_EXC_MF_MSTKERR, OS_EXC_MF_MUNSTKERR, 0, OS_EXC_MF_DACCVIOL, OS_EXC_MF_IACCVIOL
|
||||
};
|
||||
|
||||
#if (LOSCFG_KERNEL_PRINTF != 0)
|
||||
STATIC VOID OsExcNvicDump(VOID)
|
||||
{
|
||||
#define OS_NR_NVIC_EXC_DUMP_TYPES 7
|
||||
UINT32 *base = NULL;
|
||||
UINT32 len, i, j;
|
||||
UINT32 rgNvicBases[OS_NR_NVIC_EXC_DUMP_TYPES] = {
|
||||
OS_NVIC_SETENA_BASE, OS_NVIC_SETPEND_BASE, OS_NVIC_INT_ACT_BASE,
|
||||
OS_NVIC_PRI_BASE, OS_NVIC_EXCPRI_BASE, OS_NVIC_SHCSR, OS_NVIC_INT_CTRL
|
||||
};
|
||||
UINT32 rgNvicLens[OS_NR_NVIC_EXC_DUMP_TYPES] = {
|
||||
OS_NVIC_INT_ENABLE_SIZE, OS_NVIC_INT_PEND_SIZE, OS_NVIC_INT_ACT_SIZE,
|
||||
OS_NVIC_INT_PRI_SIZE, OS_NVIC_EXCPRI_SIZE, OS_NVIC_SHCSR_SIZE,
|
||||
OS_NVIC_INT_CTRL_SIZE
|
||||
};
|
||||
CHAR strRgEnable[] = "enable";
|
||||
CHAR strRgPending[] = "pending";
|
||||
CHAR strRgActive[] = "active";
|
||||
CHAR strRgPriority[] = "priority";
|
||||
CHAR strRgException[] = "exception";
|
||||
CHAR strRgShcsr[] = "shcsr";
|
||||
CHAR strRgIntCtrl[] = "control";
|
||||
CHAR *strRgs[] = {
|
||||
strRgEnable, strRgPending, strRgActive, strRgPriority,
|
||||
strRgException, strRgShcsr, strRgIntCtrl
|
||||
};
|
||||
|
||||
PRINTK("\r\nOS exception NVIC dump:\n");
|
||||
for (i = 0; i < OS_NR_NVIC_EXC_DUMP_TYPES; i++) {
|
||||
base = (UINT32 *)rgNvicBases[i];
|
||||
len = rgNvicLens[i];
|
||||
PRINTK("interrupt %s register, base address: 0x%x, size: 0x%x\n", strRgs[i], base, len);
|
||||
len = (len >> 2); /* 2: Gets the next register offset */
|
||||
for (j = 0; j < len; j++) {
|
||||
PRINTK("0x%x ", *(base + j));
|
||||
if ((j != 0) && ((j % 16) == 0)) { /* 16: print wrap line */
|
||||
PRINTK("\n");
|
||||
}
|
||||
}
|
||||
PRINTK("\n");
|
||||
}
|
||||
}
|
||||
|
||||
STATIC VOID OsExcTypeInfo(const ExcInfo *excInfo)
|
||||
{
|
||||
CHAR *phaseStr[] = {"exc in init", "exc in task", "exc in hwi"};
|
||||
|
||||
PRINTK("Type = %d\n", excInfo->type);
|
||||
PRINTK("ThrdPid = %d\n", excInfo->thrdPid);
|
||||
PRINTK("Phase = %s\n", phaseStr[excInfo->phase]);
|
||||
PRINTK("FaultAddr = 0x%x\n", excInfo->faultAddr);
|
||||
}
|
||||
|
||||
STATIC VOID OsExcCurTaskInfo(const ExcInfo *excInfo)
|
||||
{
|
||||
PRINTK("Current task info:\n");
|
||||
if (excInfo->phase == OS_EXC_IN_TASK) {
|
||||
LosTaskCB *taskCB = OS_TCB_FROM_TID(LOS_CurTaskIDGet());
|
||||
PRINTK("Task name = %s\n", taskCB->taskName);
|
||||
PRINTK("Task ID = %d\n", taskCB->taskID);
|
||||
PRINTK("Task SP = 0x%x\n", taskCB->stackPointer);
|
||||
PRINTK("Task ST = 0x%x\n", taskCB->topOfStack);
|
||||
PRINTK("Task SS = 0x%x\n", taskCB->stackSize);
|
||||
} else if (excInfo->phase == OS_EXC_IN_HWI) {
|
||||
PRINTK("Exception occur in interrupt phase!\n");
|
||||
} else {
|
||||
PRINTK("Exception occur in system init phase!\n");
|
||||
}
|
||||
}
|
||||
|
||||
STATIC VOID OsExcRegInfo(const ExcInfo *excInfo)
|
||||
{
|
||||
PRINTK("Exception reg dump:\n");
|
||||
PRINTK("PC = 0x%x\n", excInfo->context->uwPC);
|
||||
PRINTK("LR = 0x%x\n", excInfo->context->uwLR);
|
||||
PRINTK("SP = 0x%x\n", excInfo->context->uwSP);
|
||||
PRINTK("R0 = 0x%x\n", excInfo->context->uwR0);
|
||||
PRINTK("R1 = 0x%x\n", excInfo->context->uwR1);
|
||||
PRINTK("R2 = 0x%x\n", excInfo->context->uwR2);
|
||||
PRINTK("R3 = 0x%x\n", excInfo->context->uwR3);
|
||||
PRINTK("R4 = 0x%x\n", excInfo->context->uwR4);
|
||||
PRINTK("R5 = 0x%x\n", excInfo->context->uwR5);
|
||||
PRINTK("R6 = 0x%x\n", excInfo->context->uwR6);
|
||||
PRINTK("R7 = 0x%x\n", excInfo->context->uwR7);
|
||||
PRINTK("R8 = 0x%x\n", excInfo->context->uwR8);
|
||||
PRINTK("R9 = 0x%x\n", excInfo->context->uwR9);
|
||||
PRINTK("R10 = 0x%x\n", excInfo->context->uwR10);
|
||||
PRINTK("R11 = 0x%x\n", excInfo->context->uwR11);
|
||||
PRINTK("R12 = 0x%x\n", excInfo->context->uwR12);
|
||||
PRINTK("PriMask = 0x%x\n", excInfo->context->uwPriMask);
|
||||
PRINTK("xPSR = 0x%x\n", excInfo->context->uwxPSR);
|
||||
}
|
||||
|
||||
STATIC VOID OsExcBackTraceInfo(const ExcInfo *excInfo)
|
||||
{
|
||||
UINTPTR LR[LOSCFG_BACKTRACE_DEPTH] = {0};
|
||||
UINT32 index;
|
||||
|
||||
OsBackTraceHookCall(LR, LOSCFG_BACKTRACE_DEPTH, 0, excInfo->context->uwSP);
|
||||
|
||||
PRINTK("----- backtrace start -----\n");
|
||||
for (index = 0; index < LOSCFG_BACKTRACE_DEPTH; index++) {
|
||||
if (LR[index] == 0) {
|
||||
break;
|
||||
}
|
||||
PRINTK("backtrace %d -- lr = 0x%x\n", index, LR[index]);
|
||||
}
|
||||
PRINTK("----- backtrace end -----\n");
|
||||
}
|
||||
|
||||
STATIC VOID OsExcMemPoolCheckInfo(VOID)
|
||||
{
|
||||
PRINTK("\r\nmemory pools check:\n");
|
||||
#if (LOSCFG_PLATFORM_EXC == 1)
|
||||
MemInfoCB memExcInfo[OS_SYS_MEM_NUM];
|
||||
UINT32 errCnt;
|
||||
UINT32 i;
|
||||
|
||||
(VOID)memset_s(memExcInfo, sizeof(memExcInfo), 0, sizeof(memExcInfo));
|
||||
|
||||
errCnt = OsMemExcInfoGet(OS_SYS_MEM_NUM, memExcInfo);
|
||||
if (errCnt < OS_SYS_MEM_NUM) {
|
||||
errCnt += OsMemboxExcInfoGet(OS_SYS_MEM_NUM - errCnt, memExcInfo + errCnt);
|
||||
}
|
||||
|
||||
if (errCnt == 0) {
|
||||
PRINTK("all memory pool check passed!\n");
|
||||
return;
|
||||
}
|
||||
|
||||
for (i = 0; i < errCnt; i++) {
|
||||
PRINTK("pool num = %d\n", i);
|
||||
PRINTK("pool type = %d\n", memExcInfo[i].type);
|
||||
PRINTK("pool addr = 0x%x\n", memExcInfo[i].startAddr);
|
||||
PRINTK("pool size = 0x%x\n", memExcInfo[i].size);
|
||||
PRINTK("pool free = 0x%x\n", memExcInfo[i].free);
|
||||
PRINTK("pool blkNum = %d\n", memExcInfo[i].blockSize);
|
||||
PRINTK("pool error node addr = 0x%x\n", memExcInfo[i].errorAddr);
|
||||
PRINTK("pool error node len = 0x%x\n", memExcInfo[i].errorLen);
|
||||
PRINTK("pool error node owner = %d\n", memExcInfo[i].errorOwner);
|
||||
}
|
||||
#endif
|
||||
UINT32 ret = LOS_MemIntegrityCheck(LOSCFG_SYS_HEAP_ADDR);
|
||||
if (ret == LOS_OK) {
|
||||
PRINTK("system heap memcheck over, all passed!\n");
|
||||
}
|
||||
|
||||
PRINTK("memory pool check end!\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
STATIC VOID OsExcInfoDisplay(const ExcInfo *excInfo)
|
||||
{
|
||||
#if (LOSCFG_KERNEL_PRINTF != 0)
|
||||
PRINTK("*************Exception Information**************\n");
|
||||
OsExcTypeInfo(excInfo);
|
||||
OsExcCurTaskInfo(excInfo);
|
||||
OsExcRegInfo(excInfo);
|
||||
OsExcBackTraceInfo(excInfo);
|
||||
OsGetAllTskInfo();
|
||||
OsExcNvicDump();
|
||||
OsExcMemPoolCheckInfo();
|
||||
#endif
|
||||
}
|
||||
|
||||
LITE_OS_SEC_TEXT_INIT VOID HalExcHandleEntry(UINT32 excType, UINT32 faultAddr, UINT32 pid, EXC_CONTEXT_S *excBufAddr)
|
||||
{
|
||||
UINT16 tmpFlag = (excType >> 16) & OS_NULL_SHORT; /* 16: Get Exception Type */
|
||||
g_intCount++;
|
||||
g_excInfo.nestCnt++;
|
||||
|
||||
g_excInfo.type = excType & OS_NULL_SHORT;
|
||||
|
||||
if (tmpFlag & OS_EXC_FLAG_FAULTADDR_VALID) {
|
||||
g_excInfo.faultAddr = faultAddr;
|
||||
} else {
|
||||
g_excInfo.faultAddr = OS_EXC_IMPRECISE_ACCESS_ADDR;
|
||||
}
|
||||
if (g_losTask.runTask != NULL) {
|
||||
if (tmpFlag & OS_EXC_FLAG_IN_HWI) {
|
||||
g_excInfo.phase = OS_EXC_IN_HWI;
|
||||
g_excInfo.thrdPid = pid;
|
||||
} else {
|
||||
g_excInfo.phase = OS_EXC_IN_TASK;
|
||||
g_excInfo.thrdPid = g_losTask.runTask->taskID;
|
||||
}
|
||||
} else {
|
||||
g_excInfo.phase = OS_EXC_IN_INIT;
|
||||
g_excInfo.thrdPid = OS_NULL_INT;
|
||||
}
|
||||
if (excType & OS_EXC_FLAG_NO_FLOAT) {
|
||||
g_excInfo.context = (EXC_CONTEXT_S *)((CHAR *)excBufAddr - LOS_OFF_SET_OF(EXC_CONTEXT_S, uwR4));
|
||||
} else {
|
||||
g_excInfo.context = excBufAddr;
|
||||
}
|
||||
|
||||
OsDoExcHook(EXC_INTERRUPT);
|
||||
OsExcInfoDisplay(&g_excInfo);
|
||||
HalSysExit();
|
||||
}
|
||||
|
||||
/* ****************************************************************************
|
||||
Function : HalHwiInit
|
||||
Description : initialization of the hardware interrupt
|
||||
Input : None
|
||||
Output : None
|
||||
Return : None
|
||||
**************************************************************************** */
|
||||
LITE_OS_SEC_TEXT_INIT VOID HalHwiInit()
|
||||
{
|
||||
#if (LOSCFG_USE_SYSTEM_DEFINED_INTERRUPT == 1)
|
||||
UINT32 index;
|
||||
g_hwiForm[0] = 0; /* [0] Top of Stack */
|
||||
g_hwiForm[1] = Reset_Handler; /* [1] reset */
|
||||
for (index = 2; index < OS_VECTOR_CNT; index++) { /* 2: The starting position of the interrupt */
|
||||
g_hwiForm[index] = (HWI_PROC_FUNC)HalHwiDefaultHandler;
|
||||
}
|
||||
/* Exception handler register */
|
||||
g_hwiForm[NonMaskableInt_IRQn + OS_SYS_VECTOR_CNT] = HalExcNMI;
|
||||
g_hwiForm[HARDFAULT_IRQN + OS_SYS_VECTOR_CNT] = HalExcHardFault;
|
||||
g_hwiForm[MemoryManagement_IRQn + OS_SYS_VECTOR_CNT] = HalExcMemFault;
|
||||
g_hwiForm[BusFault_IRQn + OS_SYS_VECTOR_CNT] = HalExcBusFault;
|
||||
g_hwiForm[UsageFault_IRQn + OS_SYS_VECTOR_CNT] = HalExcUsageFault;
|
||||
g_hwiForm[SVCall_IRQn + OS_SYS_VECTOR_CNT] = HalSVCHandler;
|
||||
g_hwiForm[PendSV_IRQn + OS_SYS_VECTOR_CNT] = HalPendSV;
|
||||
g_hwiForm[SysTick_IRQn + OS_SYS_VECTOR_CNT] = SysTick_Handler;
|
||||
|
||||
/* Interrupt vector table location */
|
||||
SCB->VTOR = (UINT32)(UINTPTR)g_hwiForm;
|
||||
#endif
|
||||
#if (__CORTEX_M >= 0x03U) /* only for Cortex-M3 and above */
|
||||
NVIC_SetPriorityGrouping(OS_NVIC_AIRCR_PRIGROUP);
|
||||
#endif
|
||||
|
||||
/* Enable USGFAULT, BUSFAULT, MEMFAULT */
|
||||
*(volatile UINT32 *)OS_NVIC_SHCSR |= (USGFAULT | BUSFAULT | MEMFAULT);
|
||||
/* Enable DIV 0 and unaligned exception */
|
||||
*(volatile UINT32 *)OS_NVIC_CCR |= DIV0FAULT;
|
||||
|
||||
return;
|
||||
}
|
||||
|
|
@ -0,0 +1,116 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "los_timer.h"
|
||||
#include "los_config.h"
|
||||
#include "los_tick.h"
|
||||
#include "los_arch_interrupt.h"
|
||||
#include "los_context.h"
|
||||
#include "los_sched.h"
|
||||
#include "los_debug.h"
|
||||
|
||||
/* ****************************************************************************
|
||||
Function : HalTickStart
|
||||
Description : Configure Tick Interrupt Start
|
||||
Input : none
|
||||
output : none
|
||||
return : LOS_OK - Success , or LOS_ERRNO_TICK_CFG_INVALID - failed
|
||||
**************************************************************************** */
|
||||
WEAK UINT32 HalTickStart(OS_TICK_HANDLER *handler)
|
||||
{
|
||||
UINT32 ret;
|
||||
|
||||
if ((OS_SYS_CLOCK == 0) ||
|
||||
(LOSCFG_BASE_CORE_TICK_PER_SECOND == 0) ||
|
||||
(LOSCFG_BASE_CORE_TICK_PER_SECOND > OS_SYS_CLOCK)) {
|
||||
return LOS_ERRNO_TICK_CFG_INVALID;
|
||||
}
|
||||
|
||||
#if (LOSCFG_USE_SYSTEM_DEFINED_INTERRUPT == 1)
|
||||
#if (OS_HWI_WITH_ARG == 1)
|
||||
OsSetVector(SysTick_IRQn, (HWI_PROC_FUNC)handler, NULL);
|
||||
#else
|
||||
OsSetVector(SysTick_IRQn, (HWI_PROC_FUNC)handler);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
g_sysClock = OS_SYS_CLOCK;
|
||||
g_cyclesPerTick = OS_SYS_CLOCK / LOSCFG_BASE_CORE_TICK_PER_SECOND;
|
||||
|
||||
ret = SysTick_Config(g_cyclesPerTick);
|
||||
if (ret == 1) {
|
||||
return LOS_ERRNO_TICK_PER_SEC_TOO_SMALL;
|
||||
}
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
WEAK VOID HalSysTickReload(UINT64 nextResponseTime)
|
||||
{
|
||||
SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk;
|
||||
SysTick->LOAD = (UINT32)(nextResponseTime - 1UL); /* set reload register */
|
||||
SysTick->VAL = 0UL; /* Load the SysTick Counter Value */
|
||||
NVIC_ClearPendingIRQ(SysTick_IRQn);
|
||||
SysTick->CTRL |= SysTick_CTRL_ENABLE_Msk;
|
||||
}
|
||||
|
||||
WEAK UINT64 HalGetTickCycle(UINT32 *period)
|
||||
{
|
||||
UINT32 hwCycle;
|
||||
UINTPTR intSave = LOS_IntLock();
|
||||
*period = SysTick->LOAD;
|
||||
hwCycle = *period - SysTick->VAL;
|
||||
LOS_IntRestore(intSave);
|
||||
return (UINT64)hwCycle;
|
||||
}
|
||||
|
||||
WEAK VOID HalTickLock(VOID)
|
||||
{
|
||||
SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk;
|
||||
}
|
||||
|
||||
WEAK VOID HalTickUnlock(VOID)
|
||||
{
|
||||
SysTick->CTRL |= SysTick_CTRL_ENABLE_Msk;
|
||||
}
|
||||
|
||||
VOID HalEnterSleep(LOS_SysSleepEnum sleep)
|
||||
{
|
||||
#if (LOSCFG_BASE_CORE_SCHED_SLEEP == 1)
|
||||
if (sleep == OS_SYS_DEEP_SLEEP) {
|
||||
OsSchedToSleep();
|
||||
}
|
||||
#endif
|
||||
|
||||
__DSB();
|
||||
__WFI();
|
||||
__ISB();
|
||||
}
|
|
@ -0,0 +1,80 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "los_trustzone.h"
|
||||
#include "los_secure_macros.h"
|
||||
#include "los_secure_context.h"
|
||||
#include "los_debug.h"
|
||||
#include "los_arch_context.h"
|
||||
|
||||
OsSecureContext *g_secureContext = NULL;
|
||||
|
||||
VOID HalSecureSVCHandler(UINT32 svcID, UINTPTR arg)
|
||||
{
|
||||
switch (svcID) {
|
||||
case OS_SVC_START_SCHEDULE:
|
||||
HalSecureContextInit();
|
||||
HalStartFirstTask();
|
||||
break;
|
||||
case OS_SVC_ALLOCATE_SECURE_CONTEXT:
|
||||
g_secureContext = HalSecureContextAlloc(arg);
|
||||
LOS_ASSERT(g_secureContext != NULL);
|
||||
HalSecureContextLoad(g_secureContext);
|
||||
break;
|
||||
case OS_SVC_FREE_SECURE_CONTEXT:
|
||||
HalSecureContextFree(g_secureContext);
|
||||
break;
|
||||
default:
|
||||
PRINT_ERR("Incorrect svc id = %u\n", svcID);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
VOID HalStartToRun(VOID)
|
||||
{
|
||||
HalSVCStartSchedule();
|
||||
}
|
||||
|
||||
VOID LOS_SecureContextAlloc(UINT32 secureStackSize)
|
||||
{
|
||||
if (secureStackSize == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
secureStackSize = LOS_Align(secureStackSize, sizeof(UINTPTR));
|
||||
HalSVCSecureContextAlloc(secureStackSize);
|
||||
}
|
||||
|
||||
VOID LOS_SecureContextFree(VOID)
|
||||
{
|
||||
HalSVCSecureContextFree();
|
||||
}
|
||||
|
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef _LOS_TRUSTZONE_H
|
||||
#define _LOS_TRUSTZONE_H
|
||||
|
||||
#include "los_config.h"
|
||||
#include "los_task.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
extern VOID LOS_SecureContextAlloc(UINT32 secureStackSize);
|
||||
extern VOID LOS_SecureContextFree(VOID);
|
||||
|
||||
extern VOID HalStartFirstTask(VOID);
|
||||
extern VOID HalSVCStartSchedule(VOID);
|
||||
extern VOID HalSVCSecureContextAlloc(UINT32 secureStackSize);
|
||||
extern VOID HalSVCSecureContextFree(VOID);
|
||||
extern VOID HalSVCHandler(VOID);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif
|
||||
|
|
@ -0,0 +1,98 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "los_secure_context.h"
|
||||
#include "los_secure_macros.h"
|
||||
#include "los_secure_heap.h"
|
||||
|
||||
OS_CMSE_NS_ENTRY VOID HalSecureContextInit(VOID)
|
||||
{
|
||||
UINT32 ipsr;
|
||||
|
||||
OS_IPSR_READ(ipsr);
|
||||
if (!ipsr) {
|
||||
return;
|
||||
}
|
||||
|
||||
HalSecureContextInitAsm();
|
||||
}
|
||||
|
||||
OS_CMSE_NS_ENTRY OsSecureContext *HalSecureContextAlloc(UINT32 size)
|
||||
{
|
||||
OsSecureContext *secureContext = NULL;
|
||||
UINT32 ipsr;
|
||||
|
||||
OS_IPSR_READ(ipsr);
|
||||
if (!ipsr) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
secureContext = HalSecureMalloc(sizeof(OsSecureContext));
|
||||
if (secureContext == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
secureContext->stackLimit = HalSecureMalloc(size);
|
||||
if (secureContext->stackLimit == NULL) {
|
||||
HalSecureFree(secureContext);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
secureContext->stackStart = secureContext->stackLimit + size;
|
||||
secureContext->curStackPointer = secureContext->stackStart;
|
||||
|
||||
return secureContext;
|
||||
}
|
||||
|
||||
OS_CMSE_NS_ENTRY VOID HalSecureContextFree(OsSecureContext *secureContext)
|
||||
{
|
||||
UINT32 ipsr;
|
||||
|
||||
OS_IPSR_READ(ipsr);
|
||||
if (!ipsr) {
|
||||
return;
|
||||
}
|
||||
|
||||
HalSecureFree(secureContext->stackLimit);
|
||||
secureContext->stackLimit = NULL;
|
||||
HalSecureFree(secureContext);
|
||||
}
|
||||
|
||||
OS_CMSE_NS_ENTRY VOID HalSecureContextLoad(OsSecureContext *secureContext)
|
||||
{
|
||||
HalSecureContextLoadAsm(secureContext);
|
||||
}
|
||||
|
||||
OS_CMSE_NS_ENTRY VOID HalSecureContextSave(OsSecureContext *secureContext)
|
||||
{
|
||||
HalSecureContextSaveAsm(secureContext);
|
||||
}
|
||||
|
|
@ -0,0 +1,67 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef _LOS_SECURE_CONTEXT_H
|
||||
#define _LOS_SECURE_CONTEXT_H
|
||||
|
||||
#include "los_config.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
typedef struct {
|
||||
UINT8 *curStackPointer;
|
||||
UINT8 *stackLimit;
|
||||
UINT8 *stackStart;
|
||||
} OsSecureContext;
|
||||
|
||||
extern VOID HalSecureContextInit(VOID);
|
||||
extern OsSecureContext *HalSecureContextAlloc(UINT32 size);
|
||||
extern VOID HalSecureContextFree(OsSecureContext *secureContext);
|
||||
extern VOID HalSecureContextLoad(OsSecureContext *secureContext);
|
||||
extern VOID HalSecureContextSave(OsSecureContext *secureContext);
|
||||
|
||||
extern VOID HalSecureContextInitAsm(VOID);
|
||||
extern VOID HalSecureContextLoadAsm(OsSecureContext *secureContext);
|
||||
extern VOID HalSecureContextSaveAsm(OsSecureContext *secureContext);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif
|
||||
|
||||
|
|
@ -0,0 +1,89 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
PRESERVE8
|
||||
|
||||
EXPORT HalSecureContextInitAsm
|
||||
EXPORT HalSecureContextLoadAsm
|
||||
EXPORT HalSecureContextSaveAsm
|
||||
|
||||
OS_SECURE_SCB_AIRCR EQU 0xE000ED0C
|
||||
|
||||
SECTION .text:CODE(2)
|
||||
THUMB
|
||||
REQUIRE8
|
||||
|
||||
HalSecureContextInitAsm
|
||||
LDR R0, =OS_SECURE_SCB_AIRCR
|
||||
LDR R1, [R0]
|
||||
|
||||
MOV R2, #0xFFFF
|
||||
LSL R2, R2, #16
|
||||
BIC R1, R1, R2
|
||||
MOV R2, #0x05FA
|
||||
LSL R2, R2, #16
|
||||
ORR R1, R1, R2
|
||||
|
||||
BIC R1, R1, #0x4000
|
||||
MOV R2, #0x4000
|
||||
ORR R1, R1, R2
|
||||
STR R1, [R0]
|
||||
|
||||
MOV R0, #0
|
||||
MSR PSPLIM, R0
|
||||
MSR PSP, R0
|
||||
MOV R0, #2
|
||||
MSR CONTROL, R0
|
||||
BX LR
|
||||
|
||||
HalSecureContextLoadAsm
|
||||
MRS R1, IPSR
|
||||
CBZ R1, __ThreadMode
|
||||
|
||||
LDMIA R0!, {R1, R2} /* R1 = g_secureContext->curStackPointer, R2 = g_secureContext->stackLimit. */
|
||||
MSR PSPLIM, R2 /* Restore PSPLIM. */
|
||||
MSR PSP, R1 /* Restore PSP. */
|
||||
BX LR
|
||||
|
||||
HalSecureContextSaveAsm
|
||||
MRS R0, IPSR
|
||||
CBZ R0, __ThreadMode
|
||||
|
||||
MRS R0, PSP
|
||||
STR R0, [R1] /* g_secureContext->curStackPointer = R0. */
|
||||
MOV R0, #0
|
||||
MSR PSPLIM, R0 /* No PSPLIM for the current task. */
|
||||
MSR PSP, R0 /* No secure stack for the current task. */
|
||||
|
||||
__ThreadMode
|
||||
BX LR
|
||||
|
||||
END
|
|
@ -0,0 +1,229 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "los_secure_heap.h"
|
||||
#include "los_secure_macros.h"
|
||||
#include "los_config.h"
|
||||
#include "los_list.h"
|
||||
|
||||
STATIC UINT8 g_secureHeap[LOSCFG_SECURE_HEAP_SIZE] = {0};
|
||||
STATIC LOS_DL_LIST g_secureHeapFreeList = {NULL, NULL};
|
||||
|
||||
struct OsSecureHeapNode {
|
||||
LOS_DL_LIST freeNode;
|
||||
struct OsSecureHeapNode *preNode;
|
||||
UINT32 size : 24;
|
||||
UINT32 used : 8;
|
||||
};
|
||||
|
||||
#define OS_SECURE_HEAP_NODE_HEAD_SIZE sizeof(struct OsSecureHeapNode)
|
||||
#define OS_SECURE_HEAP_ALIGN_SIZE sizeof(UINTPTR)
|
||||
|
||||
#define OS_SECURE_HEAP_NODE_USED 1
|
||||
#define OS_SECURE_HEAP_NODE_FREE 0
|
||||
|
||||
#define OS_SECURE_HEAP_FIRST_NODE ((struct OsSecureHeapNode *)g_secureHeap)
|
||||
#define OS_SECURE_HEAP_NEXT_NODE(node) \
|
||||
((struct OsSecureHeapNode *)((UINT8 *)(node) + (node)->size))
|
||||
#define OS_SECURE_HEAP_END_NODE \
|
||||
((struct OsSecureHeapNode *)((UINT8 *)g_secureHeap + LOSCFG_SECURE_HEAP_SIZE - OS_SECURE_HEAP_NODE_HEAD_SIZE))
|
||||
|
||||
STATIC INLINE VOID OsSecureHeapListInit(LOS_DL_LIST *head)
|
||||
{
|
||||
head->pstPrev = head;
|
||||
head->pstNext = head;
|
||||
}
|
||||
|
||||
STATIC INLINE VOID OsSecureHeapListDelete(LOS_DL_LIST *node)
|
||||
{
|
||||
node->pstNext->pstPrev = node->pstPrev;
|
||||
node->pstPrev->pstNext = node->pstNext;
|
||||
node->pstNext = NULL;
|
||||
node->pstPrev = NULL;
|
||||
}
|
||||
|
||||
STATIC INLINE VOID OsSecureHeapListAdd(LOS_DL_LIST *listNode, LOS_DL_LIST *node)
|
||||
{
|
||||
node->pstNext = listNode->pstNext;
|
||||
node->pstPrev = listNode;
|
||||
listNode->pstNext->pstPrev = node;
|
||||
listNode->pstNext = node;
|
||||
}
|
||||
|
||||
STATIC struct OsSecureHeapNode *OsSecureHeapFindSuitableFreeBlock(UINT32 allocSize)
|
||||
{
|
||||
LOS_DL_LIST *listNodeHead = &g_secureHeapFreeList;
|
||||
struct OsSecureHeapNode *tmpNode = NULL;
|
||||
|
||||
LOS_DL_LIST_FOR_EACH_ENTRY(tmpNode, listNodeHead, struct OsSecureHeapNode, freeNode) {
|
||||
if (tmpNode->size >= allocSize) {
|
||||
return tmpNode;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
STATIC INLINE VOID OsSecureHeapClearNode(struct OsSecureHeapNode *node)
|
||||
{
|
||||
node->preNode = NULL;
|
||||
node->size = 0;
|
||||
node->used = 0;
|
||||
node->freeNode.pstPrev = NULL;
|
||||
node->freeNode.pstNext = NULL;
|
||||
}
|
||||
|
||||
STATIC INLINE VOID OsSecureHeapMergeNode(struct OsSecureHeapNode *node)
|
||||
{
|
||||
struct OsSecureHeapNode *nextNode = NULL;
|
||||
|
||||
node->preNode->size += node->size;
|
||||
nextNode = (struct OsSecureHeapNode *)((UINTPTR)node + node->size);
|
||||
nextNode->preNode = node->preNode;
|
||||
OsSecureHeapClearNode(node);
|
||||
}
|
||||
|
||||
STATIC INLINE VOID OsSecureHeapSplitNode(struct OsSecureHeapNode *allocNode, UINT32 allocSize)
|
||||
{
|
||||
struct OsSecureHeapNode *newFreeNode = NULL;
|
||||
struct OsSecureHeapNode *nextNode = NULL;
|
||||
|
||||
newFreeNode = (struct OsSecureHeapNode *)((UINT8 *)allocNode + allocSize);
|
||||
newFreeNode->preNode = allocNode;
|
||||
newFreeNode->size = allocNode->size - allocSize;
|
||||
newFreeNode->used = OS_SECURE_HEAP_NODE_FREE;
|
||||
allocNode->size = allocSize;
|
||||
nextNode = OS_SECURE_HEAP_NEXT_NODE(newFreeNode);
|
||||
nextNode->preNode = newFreeNode;
|
||||
if (nextNode->used == OS_SECURE_HEAP_NODE_FREE) {
|
||||
OsSecureHeapListDelete(&nextNode->freeNode);
|
||||
OsSecureHeapMergeNode(nextNode);
|
||||
}
|
||||
|
||||
OsSecureHeapListAdd(&g_secureHeapFreeList, &newFreeNode->freeNode);
|
||||
}
|
||||
|
||||
STATIC INLINE VOID OsSecureHeapFreeNode(struct OsSecureHeapNode *node)
|
||||
{
|
||||
struct OsSecureHeapNode *nextNode = NULL;
|
||||
|
||||
if ((node->preNode != NULL) && (node->preNode->used == OS_SECURE_HEAP_NODE_FREE)) {
|
||||
struct OsSecureHeapNode *preNode = node->preNode;
|
||||
OsSecureHeapMergeNode(node);
|
||||
nextNode = OS_SECURE_HEAP_NEXT_NODE(preNode);
|
||||
if (nextNode->used == OS_SECURE_HEAP_NODE_FREE) {
|
||||
OsSecureHeapListDelete(&nextNode->freeNode);
|
||||
OsSecureHeapMergeNode(nextNode);
|
||||
}
|
||||
|
||||
OsSecureHeapListDelete(&preNode->freeNode);
|
||||
preNode->used = OS_SECURE_HEAP_NODE_FREE;
|
||||
OsSecureHeapListAdd(&g_secureHeapFreeList, &preNode->freeNode);
|
||||
} else {
|
||||
nextNode = OS_SECURE_HEAP_NEXT_NODE(node);
|
||||
if (nextNode->used == OS_SECURE_HEAP_NODE_FREE) {
|
||||
OsSecureHeapListDelete(&nextNode->freeNode);
|
||||
OsSecureHeapMergeNode(nextNode);
|
||||
}
|
||||
|
||||
node->used = OS_SECURE_HEAP_NODE_FREE;
|
||||
OsSecureHeapListAdd(&g_secureHeapFreeList, &node->freeNode);
|
||||
}
|
||||
}
|
||||
|
||||
STATIC INLINE VOID *OsSecureHeapAllocNode(UINT32 size)
|
||||
{
|
||||
struct OsSecureHeapNode *allocNode = NULL;
|
||||
UINT32 allocSize;
|
||||
|
||||
allocSize = LOS_Align(size + OS_SECURE_HEAP_NODE_HEAD_SIZE, OS_SECURE_HEAP_ALIGN_SIZE);
|
||||
allocNode = OsSecureHeapFindSuitableFreeBlock(allocSize);
|
||||
if (allocNode == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
if ((allocSize + OS_SECURE_HEAP_NODE_HEAD_SIZE + OS_SECURE_HEAP_ALIGN_SIZE) <= allocNode->size) {
|
||||
OsSecureHeapSplitNode(allocNode, allocSize);
|
||||
}
|
||||
OsSecureHeapListDelete(&allocNode->freeNode);
|
||||
allocNode->used = OS_SECURE_HEAP_NODE_USED;
|
||||
|
||||
return (allocNode + 1);
|
||||
}
|
||||
|
||||
STATIC INLINE VOID OsSecureHeapInit(VOID)
|
||||
{
|
||||
struct OsSecureHeapNode *newNode = NULL;
|
||||
struct OsSecureHeapNode *endNode = NULL;
|
||||
|
||||
newNode = OS_SECURE_HEAP_FIRST_NODE;
|
||||
newNode->size = LOSCFG_SECURE_HEAP_SIZE - OS_SECURE_HEAP_NODE_HEAD_SIZE;
|
||||
newNode->preNode = OS_SECURE_HEAP_END_NODE;
|
||||
newNode->used = OS_SECURE_HEAP_NODE_FREE;
|
||||
|
||||
OsSecureHeapListInit(&g_secureHeapFreeList);
|
||||
OsSecureHeapListAdd(&g_secureHeapFreeList, &newNode->freeNode);
|
||||
|
||||
endNode = OS_SECURE_HEAP_END_NODE;
|
||||
endNode->preNode = newNode;
|
||||
endNode->size = OS_SECURE_HEAP_NODE_HEAD_SIZE;
|
||||
endNode->used = OS_SECURE_HEAP_NODE_USED;
|
||||
}
|
||||
|
||||
OS_CMSE_NS_ENTRY VOID *HalSecureMalloc(UINT32 size)
|
||||
{
|
||||
if (size == 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if ((g_secureHeapFreeList.pstPrev == NULL) &&
|
||||
(g_secureHeapFreeList.pstNext == NULL)) {
|
||||
OsSecureHeapInit();
|
||||
}
|
||||
|
||||
return OsSecureHeapAllocNode(size);
|
||||
}
|
||||
|
||||
OS_CMSE_NS_ENTRY VOID HalSecureFree(VOID *ptr)
|
||||
{
|
||||
struct OsSecureHeapNode *node = NULL;
|
||||
|
||||
if (ptr == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
node = (struct OsSecureHeapNode *)((UINTPTR)ptr - OS_SECURE_HEAP_NODE_HEAD_SIZE);
|
||||
if (node->used != OS_SECURE_HEAP_NODE_USED) {
|
||||
return;
|
||||
}
|
||||
|
||||
OsSecureHeapFreeNode(node);
|
||||
}
|
||||
|
|
@ -0,0 +1,53 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef _LOS_SECURE_HEAP_H
|
||||
#define _LOS_SECURE_HEAP_H
|
||||
|
||||
#include "los_config.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
VOID *HalSecureMalloc(UINT32 size);
|
||||
VOID HalSecureFree(VOID *ptr);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif
|
||||
|
|
@ -0,0 +1,58 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef _LOS_SECURE_MACROS_H
|
||||
#define _LOS_SECURE_MACROS_H
|
||||
|
||||
#include "los_config.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#define OS_CMSE_NS_ENTRY __attribute__((cmse_nonsecure_entry))
|
||||
#define OS_CMSE_NS_CALL __attribute__((cmse_nonsecure_call))
|
||||
#define OS_IPSR_READ(ipsr) __asm volatile("MRS %0, IPSR" : "=r" (ipsr))
|
||||
|
||||
#define OS_SVC_ALLOCATE_SECURE_CONTEXT 0
|
||||
#define OS_SVC_FREE_SECURE_CONTEXT 1
|
||||
#define OS_SVC_START_SCHEDULE 2
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
# Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
# Copyright (c) 2020-2021, Huawei Device Co., Ltd. All rights reserved.
|
||||
# Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without modification,
|
||||
# are permitted provided that the following conditions are met:
|
||||
|
|
|
@ -687,7 +687,7 @@ VOID HalHwiInit();
|
|||
typedef struct TagExcInfo {
|
||||
/**< Exception occurrence phase: 0 means that an exception occurs in initialization, 1 means that an exception occurs in a task, and 2 means that an exception occurs in an interrupt */
|
||||
UINT16 phase;
|
||||
/**< Exception type. When exceptions occur, check the numbers 1 - 19 listed above */
|
||||
/**< Exception type. When exceptions occur, check the numbers 1 - 21 listed above */
|
||||
UINT16 type;
|
||||
/**< If the exact address access error indicates the wrong access address when the exception occurred */
|
||||
UINT32 faultAddr;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
|
|
|
@ -687,7 +687,7 @@ VOID HalHwiInit();
|
|||
typedef struct TagExcInfo {
|
||||
/**< Exception occurrence phase: 0 means that an exception occurs in initialization, 1 means that an exception occurs in a task, and 2 means that an exception occurs in an interrupt */
|
||||
UINT16 phase;
|
||||
/**< Exception type. When exceptions occur, check the numbers 1 - 19 listed above */
|
||||
/**< Exception type. When exceptions occur, check the numbers 1 - 21 listed above */
|
||||
UINT16 type;
|
||||
/**< If the exact address access error indicates the wrong access address when the exception occurred */
|
||||
UINT32 faultAddr;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
# Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
# Copyright (c) 2020-2021, Huawei Device Co., Ltd. All rights reserved.
|
||||
# Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without modification,
|
||||
# are permitted provided that the following conditions are met:
|
||||
|
|
|
@ -687,7 +687,7 @@ VOID HalHwiInit();
|
|||
typedef struct TagExcInfo {
|
||||
/**< Exception occurrence phase: 0 means that an exception occurs in initialization, 1 means that an exception occurs in a task, and 2 means that an exception occurs in an interrupt */
|
||||
UINT16 phase;
|
||||
/**< Exception type. When exceptions occur, check the numbers 1 - 19 listed above */
|
||||
/**< Exception type. When exceptions occur, check the numbers 1 - 21 listed above */
|
||||
UINT16 type;
|
||||
/**< If the exact address access error indicates the wrong access address when the exception occurred */
|
||||
UINT32 faultAddr;
|
||||
|
|
|
@ -687,7 +687,7 @@ VOID HalHwiInit();
|
|||
typedef struct TagExcInfo {
|
||||
/**< Exception occurrence phase: 0 means that an exception occurs in initialization, 1 means that an exception occurs in a task, and 2 means that an exception occurs in an interrupt */
|
||||
UINT16 phase;
|
||||
/**< Exception type. When exceptions occur, check the numbers 1 - 19 listed above */
|
||||
/**< Exception type. When exceptions occur, check the numbers 1 - 21 listed above */
|
||||
UINT16 type;
|
||||
/**< If the exact address access error indicates the wrong access address when the exception occurred */
|
||||
UINT32 faultAddr;
|
||||
|
|
|
@ -40,16 +40,16 @@
|
|||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cpluscplus */
|
||||
#endif /* __cpluscplus */
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
UINT32 HalTickStart(OS_TICK_HANDLER handler);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cpluscplus */
|
||||
#endif /* __cpluscplus */
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _LOS_ARCH_TIMER_H */
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
# Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
# Copyright (c) 2020-2021, Huawei Device Co., Ltd. All rights reserved.
|
||||
# Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without modification,
|
||||
# are permitted provided that the following conditions are met:
|
||||
|
|
|
@ -541,8 +541,8 @@ extern UINT8 *m_aucSysMem0;
|
|||
* @ingroup los_config
|
||||
* Configuration of hardware stack protection
|
||||
*/
|
||||
#ifndef LOSCFG_EXC_HRADWARE_STACK_PROTECTION
|
||||
#define LOSCFG_EXC_HRADWARE_STACK_PROTECTION 0
|
||||
#ifndef LOSCFG_EXC_HARDWARE_STACK_PROTECTION
|
||||
#define LOSCFG_EXC_HARDWARE_STACK_PROTECTION 0
|
||||
#endif
|
||||
|
||||
/* =============================================================================
|
||||
|
@ -634,6 +634,23 @@ extern UINT8 *m_aucSysMem0;
|
|||
#define LOSCFG_BASE_CORE_SCHED_SLEEP 0
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @ingroup los_config
|
||||
* Configuration trustzone secure heap size.
|
||||
*/
|
||||
#ifndef LOSCFG_SECURE_HEAP_SIZE
|
||||
#define LOSCFG_SECURE_HEAP_SIZE 2048
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @ingroup los_config
|
||||
* Configuration trustzone secure stack default size.
|
||||
* The secure stack must be allocated before the task calls non-secure callble functions.
|
||||
*/
|
||||
#ifndef LOSCFG_SECURE_STACK_DEFAULT_SIZE
|
||||
#define LOSCFG_SECURE_STACK_DEFAULT_SIZE 512
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
|
|
|
@ -147,13 +147,13 @@ extern "C" {
|
|||
|
||||
/**
|
||||
* @ingroup los_event
|
||||
* Event reading error code: should not be distory.
|
||||
* Event reading error code: should not be destroyed.
|
||||
*
|
||||
* Value: 0x02001c08
|
||||
*
|
||||
* Solution: Check whether the event list is not empty.
|
||||
*/
|
||||
#define LOS_ERRNO_EVENT_SHOULD_NOT_DESTORY LOS_ERRNO_OS_ERROR(LOS_MOD_EVENT, 0x08)
|
||||
#define LOS_ERRNO_EVENT_SHOULD_NOT_DESTROYED LOS_ERRNO_OS_ERROR(LOS_MOD_EVENT, 0x08)
|
||||
|
||||
/**
|
||||
* @ingroup los_event
|
||||
|
|
|
@ -355,7 +355,7 @@ typedef struct tagQueueInfo {
|
|||
* This API is used to create a message queue.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>Threre are LOSCFG_BASE_IPC_QUEUE_LIMIT queues available, change it's value when necessory.</li>
|
||||
* <li>There are LOSCFG_BASE_IPC_QUEUE_LIMIT queues available, change it's value when necessary.</li>
|
||||
* </ul>
|
||||
* @param queueName [IN] Message queue name. Reserved parameter, not used for now.
|
||||
* @param len [IN] Queue length. The value range is [1,0xffff].
|
||||
|
@ -402,7 +402,7 @@ extern UINT32 LOS_QueueCreate(CHAR *queueName,
|
|||
* [1,LOSCFG_BASE_IPC_QUEUE_LIMIT].
|
||||
* @param bufferAddr [OUT] Starting address that stores the obtained data. The starting address must not be
|
||||
* null.
|
||||
* @param bufferSize [IN/OUT] Where to maintain the buffer wantted-size before read, and the real-size after read.
|
||||
* @param bufferSize [IN/OUT] Where to maintain the buffer expected-size before read, and the real-size after read.
|
||||
* @param timeOut [IN] Expiry time. The value range is [0,LOS_WAIT_FOREVER](unit: Tick).
|
||||
*
|
||||
* @retval #LOS_OK The queue is successfully read.
|
||||
|
|
|
@ -49,7 +49,7 @@ VOID OsSchedUpdateSchedTimeBase(VOID);
|
|||
|
||||
UINT64 OsGetCurrSchedTimeCycle(VOID);
|
||||
|
||||
VOID OsSchedSetIdleTaskSchedPartam(LosTaskCB *idleTask);
|
||||
VOID OsSchedSetIdleTaskSchedParam(LosTaskCB *idleTask);
|
||||
|
||||
UINT32 OsSchedSwtmrScanRegister(SchedScan func);
|
||||
|
||||
|
|
|
@ -367,7 +367,7 @@ extern UINT32 LOS_SwtmrTimeGet(UINT32 swtmrID, UINT32 *tick);
|
|||
* @attention
|
||||
* <ul>
|
||||
* <li>Do not use the delay interface in the callback function that handles software timer timeout.</li>
|
||||
* <li>Threre are LOSCFG_BASE_CORE_SWTMR_LIMIT timers available, change it's value when necessory.</li>
|
||||
* <li>There are LOSCFG_BASE_CORE_SWTMR_LIMIT timers available, change it's value when necessary.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param interval [IN] Timing duration of the software timer to be created (unit: ms).
|
||||
|
|
|
@ -1052,7 +1052,7 @@ extern BOOL LOS_TaskIsRunning(VOID);
|
|||
* @brief Obtain current new task ID.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to obtain the ID of new task.
|
||||
* This API is used to obtain the ID of new task.
|
||||
*
|
||||
* @attention None.
|
||||
*
|
||||
|
@ -1066,10 +1066,10 @@ extern BOOL LOS_TaskIsRunning(VOID);
|
|||
extern UINT32 LOS_NewTaskIDGet(VOID);
|
||||
/**
|
||||
* @ingroup los_task
|
||||
* @brief Obtain current new task name.
|
||||
* @brief Obtain the task name.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to obtain the name of new task.
|
||||
* This API is used to obtain the task name.
|
||||
*
|
||||
* @attention None.
|
||||
*
|
||||
|
|
|
@ -43,7 +43,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 LOS_EventInit(PEVENT_CB_S eventCB)
|
|||
}
|
||||
eventCB->uwEventID = 0;
|
||||
LOS_ListInit(&eventCB->stEventList);
|
||||
OsHookCall(LOS_HOOK_TYPE_EVENT_INIT);
|
||||
OsHookCall(LOS_HOOK_TYPE_EVENT_INIT, eventCB);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
|
@ -196,12 +196,12 @@ LITE_OS_SEC_TEXT_INIT UINT32 LOS_EventDestroy(PEVENT_CB_S eventCB)
|
|||
|
||||
if (!LOS_ListEmpty(&eventCB->stEventList)) {
|
||||
LOS_IntRestore(intSave);
|
||||
return LOS_ERRNO_EVENT_SHOULD_NOT_DESTORY;
|
||||
return LOS_ERRNO_EVENT_SHOULD_NOT_DESTROYED;
|
||||
}
|
||||
eventCB->stEventList.pstNext = (LOS_DL_LIST *)NULL;
|
||||
eventCB->stEventList.pstPrev = (LOS_DL_LIST *)NULL;
|
||||
LOS_IntRestore(intSave);
|
||||
OsHookCall(LOS_HOOK_TYPE_EVENT_DESTROY);
|
||||
OsHookCall(LOS_HOOK_TYPE_EVENT_DESTROY, eventCB);
|
||||
return LOS_OK;
|
||||
}
|
||||
LITE_OS_SEC_TEXT_MINOR UINT32 LOS_EventClear(PEVENT_CB_S eventCB, UINT32 eventMask)
|
||||
|
|
|
@ -44,11 +44,11 @@ LITE_OS_SEC_BSS LosMuxCB* g_allMux = NULL;
|
|||
LITE_OS_SEC_DATA_INIT LOS_DL_LIST g_unusedMuxList;
|
||||
|
||||
/*****************************************************************************
|
||||
Funtion : OsMuxInit
|
||||
Function : OsMuxInit
|
||||
Description : Initializes the mutex
|
||||
Input : None
|
||||
Output : None
|
||||
Return : LOS_OK on success ,or error code on failure
|
||||
Return : LOS_OK on success, or error code on failure
|
||||
*****************************************************************************/
|
||||
LITE_OS_SEC_TEXT_INIT UINT32 OsMuxInit(VOID)
|
||||
{
|
||||
|
@ -80,7 +80,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 OsMuxInit(VOID)
|
|||
Description : Create a mutex
|
||||
Input : None
|
||||
Output : muxHandle ------ Mutex operation handle
|
||||
Return : LOS_OK on success ,or error code on failure
|
||||
Return : LOS_OK on success, or error code on failure
|
||||
*****************************************************************************/
|
||||
LITE_OS_SEC_TEXT_INIT UINT32 LOS_MuxCreate(UINT32 *muxHandle)
|
||||
{
|
||||
|
@ -121,7 +121,7 @@ ERR_HANDLER:
|
|||
Description : Delete a mutex
|
||||
Input : muxHandle ------Mutex operation handle
|
||||
Output : None
|
||||
Return : LOS_OK on success ,or error code on failure
|
||||
Return : LOS_OK on success, or error code on failure
|
||||
*****************************************************************************/
|
||||
LITE_OS_SEC_TEXT_INIT UINT32 LOS_MuxDelete(UINT32 muxHandle)
|
||||
{
|
||||
|
@ -181,7 +181,7 @@ STATIC_INLINE UINT32 OsMuxValidCheck(LosMuxCB *muxPended)
|
|||
Input : muxHandle ------ Mutex operation handleone
|
||||
: timeOut ------- waiting time
|
||||
Output : None
|
||||
Return : LOS_OK on success ,or error code on failure
|
||||
Return : LOS_OK on success, or error code on failure
|
||||
*****************************************************************************/
|
||||
LITE_OS_SEC_TEXT UINT32 LOS_MuxPend(UINT32 muxHandle, UINT32 timeout)
|
||||
{
|
||||
|
@ -257,7 +257,7 @@ ERROR_MUX_PEND:
|
|||
Description : Specify the mutex V operation,
|
||||
Input : muxHandle ------ Mutex operation handle
|
||||
Output : None
|
||||
Return : LOS_OK on success ,or error code on failure
|
||||
Return : LOS_OK on success, or error code on failure
|
||||
*****************************************************************************/
|
||||
LITE_OS_SEC_TEXT UINT32 LOS_MuxPost(UINT32 muxHandle)
|
||||
{
|
||||
|
|
|
@ -84,7 +84,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 OsQueueInit(VOID)
|
|||
Function : LOS_QueueCreate
|
||||
Description : Create a queue
|
||||
Input : queueName --- Queue name, less than 4 characters
|
||||
: len --- Queue lenth
|
||||
: len --- Queue length
|
||||
: flags --- Queue type, FIFO or PRIO
|
||||
: maxMsgSize --- Maximum message size in byte
|
||||
Output : queueID --- Queue ID
|
||||
|
@ -205,23 +205,23 @@ static INLINE VOID OsQueueBufferOperate(LosQueueCB *queueCB, UINT32 operateType,
|
|||
{
|
||||
UINT8 *queueNode = NULL;
|
||||
UINT32 msgDataSize;
|
||||
UINT16 queuePosion;
|
||||
UINT16 queuePosition;
|
||||
errno_t rc;
|
||||
|
||||
/* get the queue position */
|
||||
switch (OS_QUEUE_OPERATE_GET(operateType)) {
|
||||
case OS_QUEUE_READ_HEAD:
|
||||
queuePosion = queueCB->queueHead;
|
||||
queuePosition = queueCB->queueHead;
|
||||
((queueCB->queueHead + 1) == queueCB->queueLen) ? (queueCB->queueHead = 0) : (queueCB->queueHead++);
|
||||
break;
|
||||
|
||||
case OS_QUEUE_WRITE_HEAD:
|
||||
(queueCB->queueHead == 0) ? (queueCB->queueHead = (queueCB->queueLen - 1)) : (--queueCB->queueHead);
|
||||
queuePosion = queueCB->queueHead;
|
||||
queuePosition = queueCB->queueHead;
|
||||
break;
|
||||
|
||||
case OS_QUEUE_WRITE_TAIL:
|
||||
queuePosion = queueCB->queueTail;
|
||||
queuePosition = queueCB->queueTail;
|
||||
((queueCB->queueTail + 1) == queueCB->queueLen) ? (queueCB->queueTail = 0) : (queueCB->queueTail++);
|
||||
break;
|
||||
|
||||
|
@ -230,7 +230,7 @@ static INLINE VOID OsQueueBufferOperate(LosQueueCB *queueCB, UINT32 operateType,
|
|||
return;
|
||||
}
|
||||
|
||||
queueNode = &(queueCB->queue[(queuePosion * (queueCB->queueSize))]);
|
||||
queueNode = &(queueCB->queue[(queuePosition * (queueCB->queueSize))]);
|
||||
|
||||
if (OS_QUEUE_IS_POINT(operateType)) {
|
||||
if (OS_QUEUE_IS_READ(operateType)) {
|
||||
|
|
|
@ -65,7 +65,6 @@ typedef struct {
|
|||
SchedSleepStart start;
|
||||
SchedSleepStop stop;
|
||||
SchedSleepGetSleepTimeNs getTimeNs;
|
||||
BOOL ready;
|
||||
} SchedSleep;
|
||||
|
||||
STATIC BOOL g_schedSleepFlags = FALSE;
|
||||
|
@ -249,7 +248,7 @@ STATIC INLINE BOOL OsSchedScanTimerList(VOID)
|
|||
* (per cpu) and ipc(mutex,sem and etc.)'s block at the same time, it can be waken
|
||||
* up by either timeout or corresponding ipc it's waiting.
|
||||
*
|
||||
* Now synchronize sortlink preocedure is used, therefore the whole task scan needs
|
||||
* Now synchronize sortlink procedure is used, therefore the whole task scan needs
|
||||
* to be protected, preventing another core from doing sortlink deletion at same time.
|
||||
*/
|
||||
|
||||
|
@ -380,7 +379,7 @@ BOOL OsSchedModifyTaskSchedParam(LosTaskCB *taskCB, UINT16 priority)
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
VOID OsSchedSetIdleTaskSchedPartam(LosTaskCB *idleTask)
|
||||
VOID OsSchedSetIdleTaskSchedParam(LosTaskCB *idleTask)
|
||||
{
|
||||
OsSchedTaskEnQueue(idleTask);
|
||||
}
|
||||
|
@ -539,37 +538,39 @@ VOID OsSchedUpdateSleepTime(VOID)
|
|||
UINT64 currTime, realSleepTime;
|
||||
UINT32 intSave;
|
||||
|
||||
if (g_schedSleepFlags == FALSE) {
|
||||
if ((g_schedSleepFlags == FALSE) || (g_schedSleepCB.stop == NULL)) {
|
||||
return;
|
||||
}
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
realSleepTime = g_schedSleepCB.getTimeNs();
|
||||
realSleepTime = (realSleepTime / OS_SYS_NS_PER_SECOND) * OS_SYS_CLOCK +
|
||||
(realSleepTime % OS_SYS_NS_PER_SECOND) * OS_SYS_CLOCK / OS_SYS_NS_PER_SECOND;
|
||||
if (realSleepTime < g_schedSleepTime) {
|
||||
nextResponseTime = g_schedSleepTime - realSleepTime;
|
||||
} else {
|
||||
nextResponseTime = 0;
|
||||
}
|
||||
if (g_schedSleepCB.getTimeNs != NULL) {
|
||||
realSleepTime = g_schedSleepCB.getTimeNs();
|
||||
realSleepTime = (realSleepTime / OS_SYS_NS_PER_SECOND) * OS_SYS_CLOCK +
|
||||
(realSleepTime % OS_SYS_NS_PER_SECOND) * OS_SYS_CLOCK / OS_SYS_NS_PER_SECOND;
|
||||
if (realSleepTime < g_schedSleepTime) {
|
||||
nextResponseTime = g_schedSleepTime - realSleepTime;
|
||||
} else {
|
||||
nextResponseTime = 0;
|
||||
}
|
||||
|
||||
#if (LOSCFG_BASE_CORE_TICK_WTIMER == 1)
|
||||
currTime = HalGetTickCycle(NULL);
|
||||
currTime = HalGetTickCycle(NULL);
|
||||
#else
|
||||
g_schedTimerBase = g_schedEntrySleepTime + realSleepTime;
|
||||
currTime = g_schedTimerBase;
|
||||
g_schedTimerBase = g_schedEntrySleepTime + realSleepTime;
|
||||
currTime = g_schedTimerBase;
|
||||
#endif
|
||||
if (nextResponseTime > OS_TICK_RESPONSE_TIME_MAX) {
|
||||
nextResponseTime = OS_TICK_RESPONSE_TIME_MAX;
|
||||
} else if (nextResponseTime < OS_CYCLE_PER_TICK) {
|
||||
nextResponseTime = OS_CYCLE_PER_TICK;
|
||||
}
|
||||
if (nextResponseTime > OS_TICK_RESPONSE_TIME_MAX) {
|
||||
nextResponseTime = OS_TICK_RESPONSE_TIME_MAX;
|
||||
} else if (nextResponseTime < OS_CYCLE_PER_TICK) {
|
||||
nextResponseTime = OS_CYCLE_PER_TICK;
|
||||
}
|
||||
|
||||
g_schedResponseID = OS_INVALID;
|
||||
g_schedResponseTime = currTime + nextResponseTime;
|
||||
HalSysTickReload(nextResponseTime);
|
||||
g_schedResponseID = OS_INVALID;
|
||||
g_schedResponseTime = currTime + nextResponseTime;
|
||||
HalSysTickReload(nextResponseTime);
|
||||
g_schedSleepTime = 0;
|
||||
}
|
||||
g_schedSleepFlags = FALSE;
|
||||
g_schedSleepTime = 0;
|
||||
g_schedSleepCB.stop();
|
||||
LOS_IntRestore(intSave);
|
||||
}
|
||||
|
@ -579,19 +580,23 @@ VOID OsSchedToSleep(VOID)
|
|||
UINT32 intSave;
|
||||
UINT64 sleepTime;
|
||||
|
||||
if (!g_schedSleepCB.ready) {
|
||||
if (g_schedSleepCB.start == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
sleepTime = (g_schedSleepTime / OS_SYS_CLOCK) * OS_SYS_NS_PER_SECOND +
|
||||
(g_schedSleepTime % OS_SYS_CLOCK) * OS_SYS_NS_PER_SECOND / OS_SYS_CLOCK;
|
||||
if (sleepTime == 0) {
|
||||
return;
|
||||
}
|
||||
if (g_schedSleepCB.getTimeNs != NULL) {
|
||||
sleepTime = (g_schedSleepTime / OS_SYS_CLOCK) * OS_SYS_NS_PER_SECOND +
|
||||
(g_schedSleepTime % OS_SYS_CLOCK) * OS_SYS_NS_PER_SECOND / OS_SYS_CLOCK;
|
||||
if (sleepTime == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
HalTickLock();
|
||||
g_schedEntrySleepTime = OsGetCurrSchedTimeCycle();
|
||||
intSave = LOS_IntLock();
|
||||
HalTickLock();
|
||||
g_schedEntrySleepTime = OsGetCurrSchedTimeCycle();
|
||||
} else {
|
||||
intSave = LOS_IntLock();
|
||||
}
|
||||
|
||||
g_schedSleepCB.start(sleepTime);
|
||||
g_schedSleepFlags = TRUE;
|
||||
|
@ -603,7 +608,7 @@ UINT32 LOS_SchedSleepInit(SchedSleepInit init, SchedSleepStart start,
|
|||
{
|
||||
UINT32 ret;
|
||||
|
||||
if ((init == NULL) || (start == NULL) || (stop == NULL) || (getTime == NULL)) {
|
||||
if ((init == NULL) && (start == NULL) && (stop == NULL)) {
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
|
@ -612,12 +617,13 @@ UINT32 LOS_SchedSleepInit(SchedSleepInit init, SchedSleepStart start,
|
|||
g_schedSleepCB.stop = stop;
|
||||
g_schedSleepCB.getTimeNs = getTime;
|
||||
|
||||
ret = g_schedSleepCB.init();
|
||||
if (ret != LOS_OK) {
|
||||
return ret;
|
||||
if (g_schedSleepCB.init != NULL) {
|
||||
ret = g_schedSleepCB.init();
|
||||
if (ret != LOS_OK) {
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
g_schedSleepCB.ready = TRUE;
|
||||
return LOS_OK;
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -46,7 +46,7 @@ LITE_OS_SEC_BSS LosSemCB *g_allSem = NULL;
|
|||
|
||||
/*****************************************************************************
|
||||
Function : OsSemInit
|
||||
Description : Initialize the Semaphore doubly linked list
|
||||
Description : Initialize the Semaphore doubly linked list
|
||||
Input : None
|
||||
Output : None
|
||||
Return : LOS_OK on success, or error code on failure
|
||||
|
@ -67,7 +67,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 OsSemInit(VOID)
|
|||
return LOS_ERRNO_SEM_NO_MEMORY;
|
||||
}
|
||||
|
||||
/* Connect all the ECBs in a doubly linked list. */
|
||||
/* Connect all the semaphore CBs in a doubly linked list. */
|
||||
for (index = 0; index < LOSCFG_BASE_IPC_SEM_LIMIT; index++) {
|
||||
semNode = ((LosSemCB *)g_allSem) + index;
|
||||
semNode->semID = index;
|
||||
|
@ -79,7 +79,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 OsSemInit(VOID)
|
|||
|
||||
/*****************************************************************************
|
||||
Function : OsSemCreate
|
||||
Description : create the Semaphore
|
||||
Description : create the Semaphore
|
||||
Input : count --- Semaphore count
|
||||
: maxCount --- Max semaphore count for check
|
||||
Output : semHandle --- Index of semaphore
|
||||
|
@ -313,4 +313,3 @@ LITE_OS_SEC_TEXT UINT32 LOS_SemPost(UINT32 semHandle)
|
|||
}
|
||||
|
||||
#endif /* (LOSCFG_BASE_IPC_SEM == 1) */
|
||||
|
||||
|
|
|
@ -134,7 +134,7 @@ STATIC VOID OsRecyleFinishedTask(VOID)
|
|||
taskCB = OS_TCB_FROM_PENDLIST(LOS_DL_LIST_FIRST(&g_taskRecyleList));
|
||||
LOS_ListDelete(LOS_DL_LIST_FIRST(&g_taskRecyleList));
|
||||
LOS_ListAdd(&g_losFreeTask, &taskCB->pendList);
|
||||
#if (LOSCFG_EXC_HRADWARE_STACK_PROTECTION == 1)
|
||||
#if (LOSCFG_EXC_HARDWARE_STACK_PROTECTION == 1)
|
||||
stackPtr = taskCB->topOfStack - OS_TASK_STACK_PROTECT_SIZE;
|
||||
#else
|
||||
stackPtr = taskCB->topOfStack;
|
||||
|
@ -396,7 +396,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 OsIdleTaskCreate(VOID)
|
|||
return retVal;
|
||||
}
|
||||
|
||||
OsSchedSetIdleTaskSchedPartam(OS_TCB_FROM_TID(g_idleTaskID));
|
||||
OsSchedSetIdleTaskSchedParam(OS_TCB_FROM_TID(g_idleTaskID));
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
|
@ -450,7 +450,7 @@ LITE_OS_SEC_TEXT CHAR *LOS_CurTaskNameGet(VOID)
|
|||
}
|
||||
|
||||
#if (LOSCFG_BASE_CORE_TSK_MONITOR == 1)
|
||||
#if (LOSCFG_EXC_HRADWARE_STACK_PROTECTION == 0)
|
||||
#if (LOSCFG_EXC_HARDWARE_STACK_PROTECTION == 0)
|
||||
/*****************************************************************************
|
||||
Function : OsHandleRunTaskStackOverflow
|
||||
Description : handle stack overflow exception of the run task.
|
||||
|
@ -530,7 +530,7 @@ LITE_OS_SEC_TEXT STATIC VOID OsTaskStackProtect(VOID)
|
|||
LITE_OS_SEC_TEXT VOID OsTaskSwitchCheck(VOID)
|
||||
{
|
||||
UINT32 intSave = LOS_IntLock();
|
||||
#if (LOSCFG_EXC_HRADWARE_STACK_PROTECTION == 0)
|
||||
#if (LOSCFG_EXC_HARDWARE_STACK_PROTECTION == 0)
|
||||
UINT32 endOfStack = g_losTask.newTask->topOfStack + g_losTask.newTask->stackSize;
|
||||
|
||||
if ((*(UINT32 *)(UINTPTR)(g_losTask.runTask->topOfStack)) != OS_TASK_MAGIC_WORD) {
|
||||
|
@ -702,7 +702,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 LOS_TaskCreateOnly(UINT32 *taskID, TSK_INIT_PARAM_S
|
|||
|
||||
LOS_IntRestore(intSave);
|
||||
|
||||
#if (LOSCFG_EXC_HRADWARE_STACK_PROTECTION == 1)
|
||||
#if (LOSCFG_EXC_HARDWARE_STACK_PROTECTION == 1)
|
||||
UINTPTR stackPtr = (UINTPTR)LOS_MemAllocAlign(OS_TASK_STACK_ADDR, taskInitParam->uwStackSize +
|
||||
OS_TASK_STACK_PROTECT_SIZE, OS_TASK_STACK_PROTECT_SIZE);
|
||||
topOfStack = (VOID *)(stackPtr + OS_TASK_STACK_PROTECT_SIZE);
|
||||
|
@ -929,7 +929,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 LOS_TaskDelete(UINT32 taskID)
|
|||
} else {
|
||||
taskCB->taskStatus = OS_TASK_STATUS_UNUSED;
|
||||
LOS_ListAdd(&g_losFreeTask, &taskCB->pendList);
|
||||
#if (LOSCFG_EXC_HRADWARE_STACK_PROTECTION == 1)
|
||||
#if (LOSCFG_EXC_HARDWARE_STACK_PROTECTION == 1)
|
||||
stackPtr = taskCB->topOfStack - OS_TASK_STACK_PROTECT_SIZE;
|
||||
#else
|
||||
stackPtr = taskCB->topOfStack;
|
||||
|
|
|
@ -1286,6 +1286,8 @@ UINT32 LOS_MemFree(VOID *pool, VOID *ptr)
|
|||
return LOS_NOK;
|
||||
}
|
||||
|
||||
OsHookCall(LOS_HOOK_TYPE_MEM_FREE, pool, ptr);
|
||||
|
||||
UINT32 ret = LOS_NOK;
|
||||
struct OsMemPoolHead *poolHead = (struct OsMemPoolHead *)pool;
|
||||
struct OsMemNodeHead *node = NULL;
|
||||
|
@ -1308,8 +1310,6 @@ UINT32 LOS_MemFree(VOID *pool, VOID *ptr)
|
|||
LOS_Trace(LOS_TRACE_MEM_TIME, (UINTPTR)pool & MEM_POOL_ADDR_MASK, MEM_TRACE_FREE, timeUsed);
|
||||
#endif
|
||||
|
||||
OsHookCall(LOS_HOOK_TYPE_MEM_FREE, pool, ptr);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,126 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "los_tick.h"
|
||||
#include "los_task.h"
|
||||
#include "los_config.h"
|
||||
#include "los_interrupt.h"
|
||||
#include "los_debug.h"
|
||||
#include "los_compiler.h"
|
||||
|
||||
|
||||
#pragma data_alignment=8
|
||||
UINT8 g_memStart[LOSCFG_SYS_HEAP_SIZE];
|
||||
|
||||
VOID taskSampleEntry2(VOID)
|
||||
{
|
||||
while(1) {
|
||||
LOS_TaskDelay(10000);
|
||||
printf("taskSampleEntry2 running...\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
VOID taskSampleEntry1(VOID)
|
||||
{
|
||||
while(1) {
|
||||
LOS_TaskDelay(2000);
|
||||
printf("taskSampleEntry1 running...\n");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
UINT32 taskSample(VOID)
|
||||
{
|
||||
UINT32 uwRet;
|
||||
UINT32 taskID1,taskID2;
|
||||
TSK_INIT_PARAM_S stTask1={0};
|
||||
stTask1.pfnTaskEntry = (TSK_ENTRY_FUNC)taskSampleEntry1;
|
||||
stTask1.uwStackSize = 0X1000;
|
||||
stTask1.pcName = "taskSampleEntry1";
|
||||
stTask1.usTaskPrio = 6;
|
||||
uwRet = LOS_TaskCreate(&taskID1, &stTask1);
|
||||
if (uwRet != LOS_OK) {
|
||||
printf("create task1 failed\n");
|
||||
}
|
||||
|
||||
stTask1.pfnTaskEntry = (TSK_ENTRY_FUNC)taskSampleEntry2;
|
||||
stTask1.uwStackSize = 0X1000;
|
||||
stTask1.pcName = "taskSampleEntry2";
|
||||
stTask1.usTaskPrio = 7;
|
||||
uwRet = LOS_TaskCreate(&taskID2, &stTask1);
|
||||
if (uwRet != LOS_OK) {
|
||||
printf("create task2 failed\n");
|
||||
}
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
|
||||
void LOS_HardBootInit()
|
||||
{
|
||||
UINT32 uwRet = LOS_OK;
|
||||
|
||||
uwRet = LOS_UartBaseInit();
|
||||
if (uwRet != LOS_OK)
|
||||
{
|
||||
return ;
|
||||
}
|
||||
|
||||
return ;
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************************************
|
||||
Function : main
|
||||
Description : Main function entry
|
||||
Input : None
|
||||
Output : None
|
||||
Return : None
|
||||
*****************************************************************************/
|
||||
LITE_OS_SEC_TEXT_INIT int main(void)
|
||||
{
|
||||
unsigned int ret;
|
||||
|
||||
//USART_Config();
|
||||
|
||||
printf("\n\rhello world!!\n\r");
|
||||
|
||||
ret = LOS_KernelInit();
|
||||
taskSample();
|
||||
if (ret == LOS_OK) {
|
||||
LOS_Start();
|
||||
}
|
||||
|
||||
while (1) {
|
||||
__asm volatile("wfi");
|
||||
}
|
||||
}
|
||||
|
|
@ -1,116 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/**@defgroup los_config System configuration items
|
||||
* @ingroup kernel
|
||||
*/
|
||||
|
||||
#ifndef _TARGET_CONFIG_H
|
||||
#define _TARGET_CONFIG_H
|
||||
|
||||
#include "ARMCM3.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/*=============================================================================
|
||||
System clock module configuration
|
||||
=============================================================================*/
|
||||
#define OS_SYS_CLOCK 24000000
|
||||
#define LOSCFG_BASE_CORE_TICK_PER_SECOND (1000UL)
|
||||
#define LOSCFG_BASE_CORE_TICK_HW_TIME 0
|
||||
#define LOSCFG_BASE_CORE_TICK_WTIMER 0
|
||||
#define LOSCFG_BASE_CORE_TICK_RESPONSE_MAX 0xFFFFFF
|
||||
|
||||
/*=============================================================================
|
||||
Hardware interrupt module configuration
|
||||
=============================================================================*/
|
||||
#define LOSCFG_PLATFORM_HWI 1
|
||||
#define LOSCFG_PLATFORM_HWI_LIMIT 128
|
||||
/*=============================================================================
|
||||
Task module configuration
|
||||
=============================================================================*/
|
||||
#define LOSCFG_BASE_CORE_TSK_LIMIT 24
|
||||
#define LOSCFG_BASE_CORE_TSK_IDLE_STACK_SIZE (0x500U)
|
||||
#define LOSCFG_BASE_CORE_TSK_DEFAULT_STACK_SIZE (0x2D0U)
|
||||
#define LOSCFG_BASE_CORE_TSK_MIN_STACK_SIZE (0x130U)
|
||||
#define LOSCFG_BASE_CORE_TIMESLICE 1
|
||||
#define LOSCFG_BASE_CORE_TIMESLICE_TIMEOUT 20000
|
||||
/*=============================================================================
|
||||
Semaphore module configuration
|
||||
=============================================================================*/
|
||||
#define LOSCFG_BASE_IPC_SEM 1
|
||||
#define LOSCFG_BASE_IPC_SEM_LIMIT 48
|
||||
/*=============================================================================
|
||||
Mutex module configuration
|
||||
=============================================================================*/
|
||||
#define LOSCFG_BASE_IPC_MUX 1
|
||||
#define LOSCFG_BASE_IPC_MUX_LIMIT 24
|
||||
/*=============================================================================
|
||||
Queue module configuration
|
||||
=============================================================================*/
|
||||
#define LOSCFG_BASE_IPC_QUEUE 1
|
||||
#define LOSCFG_BASE_IPC_QUEUE_LIMIT 24
|
||||
/*=============================================================================
|
||||
Software timer module configuration
|
||||
=============================================================================*/
|
||||
#define LOSCFG_BASE_CORE_SWTMR 1
|
||||
#define LOSCFG_BASE_CORE_SWTMR_ALIGN 1
|
||||
#define LOSCFG_BASE_CORE_SWTMR_LIMIT 48
|
||||
/*=============================================================================
|
||||
Memory module configuration
|
||||
=============================================================================*/
|
||||
extern unsigned char g_memStart[];
|
||||
#define LOSCFG_SYS_EXTERNAL_HEAP 1
|
||||
#define LOSCFG_SYS_HEAP_ADDR (&g_memStart[0])
|
||||
#define LOSCFG_SYS_HEAP_SIZE 0x00013000
|
||||
#define LOSCFG_MEM_MUL_POOL 1
|
||||
#define OS_SYS_MEM_NUM 20
|
||||
/*=============================================================================
|
||||
Exception module configuration
|
||||
=============================================================================*/
|
||||
#define LOSCFG_PLATFORM_EXC 1
|
||||
/* =============================================================================
|
||||
printf module configuration
|
||||
============================================================================= */
|
||||
#define LOSCFG_KERNEL_PRINTF 1
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
|
||||
#endif /* _TARGET_CONFIG_H */
|
|
@ -1,184 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "stdarg.h"
|
||||
#include <stdio.h>
|
||||
#include "los_debug.h"
|
||||
#include "stm32f4xx_usart.h"
|
||||
#include "stm324x9i_eval.h"
|
||||
|
||||
#define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
|
||||
|
||||
/**
|
||||
* @brief Retargets the C library printf function to the USART.
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
PUTCHAR_PROTOTYPE
|
||||
{
|
||||
/* Place your implementation of fputc here */
|
||||
/* e.g. write a character to the USART */
|
||||
USART_SendData(EVAL_COM1, (uint8_t) ch);
|
||||
|
||||
/* Loop until the end of transmission */
|
||||
while (USART_GetFlagStatus(EVAL_COM1, USART_FLAG_TC) == RESET)
|
||||
{}
|
||||
|
||||
return ch;
|
||||
}
|
||||
|
||||
static int hex2asc(int n)
|
||||
{
|
||||
n &= 15;
|
||||
if(n > 9){
|
||||
return ('a' - 10) + n;
|
||||
} else {
|
||||
return '0' + n;
|
||||
}
|
||||
}
|
||||
|
||||
static void dputs(char const *s, int (*pFputc)(int n, FILE *cookie), void *cookie)
|
||||
{
|
||||
while (*s) {
|
||||
pFputc(*s++, cookie);
|
||||
}
|
||||
}
|
||||
|
||||
void __dprintf(char const *fmt, va_list ap,
|
||||
int (*pFputc)(int n, FILE *cookie),
|
||||
void *cookie)
|
||||
{
|
||||
char scratch[256];
|
||||
|
||||
for(;;){
|
||||
switch(*fmt){
|
||||
case 0:
|
||||
va_end(ap);
|
||||
return;
|
||||
case '%':
|
||||
switch(fmt[1]) {
|
||||
case 'c': {
|
||||
unsigned n = va_arg(ap, unsigned);
|
||||
pFputc(n, cookie);
|
||||
fmt += 2;
|
||||
continue;
|
||||
}
|
||||
case 'h': {
|
||||
unsigned n = va_arg(ap, unsigned);
|
||||
pFputc(hex2asc(n >> 12), cookie);
|
||||
pFputc(hex2asc(n >> 8), cookie);
|
||||
pFputc(hex2asc(n >> 4), cookie);
|
||||
pFputc(hex2asc(n >> 0), cookie);
|
||||
fmt += 2;
|
||||
continue;
|
||||
}
|
||||
case 'b': {
|
||||
unsigned n = va_arg(ap, unsigned);
|
||||
pFputc(hex2asc(n >> 4), cookie);
|
||||
pFputc(hex2asc(n >> 0), cookie);
|
||||
fmt += 2;
|
||||
continue;
|
||||
}
|
||||
case 'p':
|
||||
case 'X':
|
||||
case 'x': {
|
||||
unsigned n = va_arg(ap, unsigned);
|
||||
char *p = scratch + 15;
|
||||
*p = 0;
|
||||
do {
|
||||
*--p = hex2asc(n);
|
||||
n = n >> 4;
|
||||
} while(n != 0);
|
||||
while(p > (scratch + 7)) *--p = '0';
|
||||
dputs(p, pFputc, cookie);
|
||||
fmt += 2;
|
||||
continue;
|
||||
}
|
||||
case 'd': {
|
||||
int n = va_arg(ap, int);
|
||||
char *p = scratch + 15;
|
||||
*p = 0;
|
||||
if(n < 0) {
|
||||
pFputc('-', cookie);
|
||||
n = -n;
|
||||
}
|
||||
do {
|
||||
*--p = (n % 10) + '0';
|
||||
n /= 10;
|
||||
} while(n != 0);
|
||||
dputs(p, pFputc, cookie);
|
||||
fmt += 2;
|
||||
continue;
|
||||
}
|
||||
case 'u': {
|
||||
unsigned int n = va_arg(ap, unsigned int);
|
||||
char *p = scratch + 15;
|
||||
*p = 0;
|
||||
do {
|
||||
*--p = (n % 10) + '0';
|
||||
n /= 10;
|
||||
} while(n != 0);
|
||||
dputs(p, pFputc, cookie);
|
||||
fmt += 2;
|
||||
continue;
|
||||
}
|
||||
case 's': {
|
||||
char *s = va_arg(ap, char*); /*lint !e64*/
|
||||
if(s == 0) s = "(null)";
|
||||
dputs(s, pFputc, cookie);
|
||||
fmt += 2;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
pFputc(*fmt++, cookie);
|
||||
break;
|
||||
case '\n':
|
||||
pFputc('\r', cookie);
|
||||
default: /*lint !e616*/
|
||||
pFputc(*fmt++, cookie);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void HalConsoleOutput(LogModuleType type, const char *fmt, va_list ap)
|
||||
{
|
||||
(void)type;
|
||||
__dprintf(fmt, ap, fputc, 0);
|
||||
}
|
||||
|
||||
int printf(char const *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
va_start(ap, fmt); /*lint !e1055 !e534 !e530*/
|
||||
__dprintf(fmt, ap, fputc, 0); /*lint !e611 !e64*/
|
||||
va_end(ap);
|
||||
return 0;
|
||||
}
|
|
@ -1,194 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "los_tick.h"
|
||||
#include "los_task.h"
|
||||
#include "los_config.h"
|
||||
#include "los_interrupt.h"
|
||||
#include "los_debug.h"
|
||||
#include "los_compiler.h"
|
||||
#include "los_sched.h"
|
||||
#include "iar_stm32f429ig_fire-challenger.h"
|
||||
|
||||
|
||||
STATIC VOID TaskSampleEntry2(VOID)
|
||||
{
|
||||
while (1) {
|
||||
printf("TaskSampleEntry2 running...\n");
|
||||
LOS_TaskDelay(10000); /* 10 Seconds */
|
||||
}
|
||||
}
|
||||
|
||||
STATIC VOID TaskSampleEntry1(VOID)
|
||||
{
|
||||
while (1) {
|
||||
printf("TaskSampleEntry1 running...\n");
|
||||
LOS_TaskDelay(2000); /* 2 Seconds */
|
||||
}
|
||||
}
|
||||
|
||||
WEAK VOID TaskSample(VOID)
|
||||
{
|
||||
UINT32 uwRet;
|
||||
UINT32 taskID1;
|
||||
UINT32 taskID2;
|
||||
TSK_INIT_PARAM_S stTask = {0};
|
||||
|
||||
stTask.pfnTaskEntry = (TSK_ENTRY_FUNC)TaskSampleEntry1;
|
||||
stTask.uwStackSize = 0x1000;
|
||||
stTask.pcName = "TaskSampleEntry1";
|
||||
stTask.usTaskPrio = 6; /* Os task priority is 6 */
|
||||
uwRet = LOS_TaskCreate(&taskID1, &stTask);
|
||||
if (uwRet != LOS_OK) {
|
||||
printf("Task1 create failed\n");
|
||||
}
|
||||
|
||||
stTask.pfnTaskEntry = (TSK_ENTRY_FUNC)TaskSampleEntry2;
|
||||
stTask.uwStackSize = 0x1000;
|
||||
stTask.pcName = "TaskSampleEntry2";
|
||||
stTask.usTaskPrio = 7; /* Os task priority is 7 */
|
||||
uwRet = LOS_TaskCreate(&taskID2, &stTask);
|
||||
if (uwRet != LOS_OK) {
|
||||
printf("Task2 create failed\n");
|
||||
}
|
||||
}
|
||||
|
||||
#if (LOSCFG_BASE_CORE_SCHED_SLEEP == 1)
|
||||
#define SLEEP_TIME_CYCLE 90000000UL
|
||||
#define SLEEP_TIME_MAX_RESPONSE_TIME ((UINT32)-1)
|
||||
#define TIM2_INI_PRIORITY 3
|
||||
unsigned int g_sleepTimePeriod;
|
||||
TIM_TimeBaseInitTypeDef g_timerInit = { 0 };
|
||||
unsigned long long GetSleepTimeNs(VOID)
|
||||
{
|
||||
unsigned long long currTime = g_sleepTimePeriod + TIM_GetCounter(TIM2);
|
||||
currTime = (currTime * OS_SYS_NS_PER_SECOND) / SLEEP_TIME_CYCLE;
|
||||
return currTime;
|
||||
}
|
||||
|
||||
void SleepTimerStop(void)
|
||||
{
|
||||
TIM_ClearITPendingBit(TIM2, TIM_FLAG_Update);
|
||||
TIM_DeInit(TIM2);
|
||||
TIM_Cmd(TIM2, DISABLE);
|
||||
}
|
||||
|
||||
void SleepTimerStart(unsigned long long sleepTimeNs)
|
||||
{
|
||||
unsigned long long period = (sleepTimeNs * SLEEP_TIME_CYCLE) / OS_SYS_NS_PER_SECOND;
|
||||
if (period > SLEEP_TIME_MAX_RESPONSE_TIME) {
|
||||
period = SLEEP_TIME_MAX_RESPONSE_TIME;
|
||||
}
|
||||
|
||||
g_timerInit.TIM_Period = period;
|
||||
g_sleepTimePeriod = period;
|
||||
TIM_TimeBaseInit(TIM2, &g_timerInit);
|
||||
|
||||
TIM_ClearFlag(TIM2, TIM_FLAG_Update);
|
||||
TIM_ClearITPendingBit(TIM2, TIM_FLAG_Update);
|
||||
|
||||
TIM_ITConfig(TIM2, TIM_IT_Update, ENABLE);
|
||||
TIM_Cmd(TIM2, ENABLE);
|
||||
}
|
||||
|
||||
void TIM2_IRQHandler(void)
|
||||
{
|
||||
TIM_ClearFlag(TIM2, TIM_FLAG_Update);
|
||||
TIM_ClearITPendingBit(TIM2, TIM_FLAG_Update);
|
||||
|
||||
SleepTimerStop();
|
||||
}
|
||||
|
||||
unsigned int SleepTimerInit(void)
|
||||
{
|
||||
NVIC_InitTypeDef nvic = { 0 };
|
||||
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
|
||||
TIM_TimeBaseStructInit(&g_timerInit);
|
||||
g_timerInit.TIM_Period = SLEEP_TIME_MAX_RESPONSE_TIME;
|
||||
g_timerInit.TIM_Prescaler = 0;
|
||||
TIM_TimeBaseInit(TIM2, &g_timerInit);
|
||||
|
||||
nvic.NVIC_IRQChannel = TIM2_IRQn;
|
||||
nvic.NVIC_IRQChannelPreemptionPriority = TIM2_INI_PRIORITY;
|
||||
nvic.NVIC_IRQChannelSubPriority = 0;
|
||||
nvic.NVIC_IRQChannelCmd = ENABLE;
|
||||
NVIC_Init(&nvic);
|
||||
|
||||
TIM_ClearFlag(TIM2, TIM_FLAG_Update);
|
||||
TIM_ClearITPendingBit(TIM2, TIM_FLAG_Update);
|
||||
#if (LOSCFG_USE_SYSTEM_DEFINED_INTERRUPT == 1)
|
||||
UINT32 ret = HalHwiCreate(TIM2_IRQn, TIM2_INI_PRIORITY, 0, TIM2_IRQHandler, 0);
|
||||
if (ret != LOS_OK) {
|
||||
printf("SleepTimerInit create time2 irq failed! ERROR: 0x%x\n", ret);
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*****************************************************************************
|
||||
Function : main
|
||||
Description : Main function entry
|
||||
Input : None
|
||||
Output : None
|
||||
Return : None
|
||||
*****************************************************************************/
|
||||
LITE_OS_SEC_TEXT_INIT int main(void)
|
||||
{
|
||||
unsigned int ret;
|
||||
|
||||
USART_Config();
|
||||
|
||||
printf("\n\rhello world!!\n\r");
|
||||
|
||||
ret = LOS_KernelInit();
|
||||
if (ret == LOS_OK) {
|
||||
#if (LOSCFG_BASE_CORE_SCHED_SLEEP == 1)
|
||||
ret = LOS_SchedSleepInit(SleepTimerInit, SleepTimerStart, SleepTimerStop, GetSleepTimeNs);
|
||||
if (ret != LOS_OK) {
|
||||
goto EXIT;
|
||||
}
|
||||
#endif
|
||||
TaskSample();
|
||||
LOS_Start();
|
||||
}
|
||||
|
||||
#if (LOSCFG_BASE_CORE_SCHED_SLEEP == 1)
|
||||
EXIT:
|
||||
#endif
|
||||
while (1) {
|
||||
__asm volatile("wfi");
|
||||
}
|
||||
}
|
||||
|
|
@ -1,115 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/**@defgroup los_config System configuration items
|
||||
* @ingroup kernel
|
||||
*/
|
||||
|
||||
#ifndef _TARGET_CONFIG_H
|
||||
#define _TARGET_CONFIG_H
|
||||
|
||||
#include "stm32f4xx.h"
|
||||
#include "stm32f4xx_it.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/*=============================================================================
|
||||
System clock module configuration
|
||||
=============================================================================*/
|
||||
#define OS_SYS_CLOCK SystemCoreClock
|
||||
#define LOSCFG_BASE_CORE_TICK_PER_SECOND (1000UL)
|
||||
#define LOSCFG_BASE_CORE_TICK_HW_TIME 0
|
||||
#define LOSCFG_BASE_CORE_TICK_WTIMER 0
|
||||
#define LOSCFG_BASE_CORE_TICK_RESPONSE_MAX SysTick_LOAD_RELOAD_Msk
|
||||
|
||||
/*=============================================================================
|
||||
Hardware interrupt module configuration
|
||||
=============================================================================*/
|
||||
#define LOSCFG_PLATFORM_HWI 1
|
||||
#define LOSCFG_USE_SYSTEM_DEFINED_INTERRUPT 1
|
||||
#define LOSCFG_PLATFORM_HWI_LIMIT 128
|
||||
/*=============================================================================
|
||||
Task module configuration
|
||||
=============================================================================*/
|
||||
#define LOSCFG_BASE_CORE_TSK_LIMIT 24
|
||||
#define LOSCFG_BASE_CORE_TSK_IDLE_STACK_SIZE (0x500U)
|
||||
#define LOSCFG_BASE_CORE_TSK_DEFAULT_STACK_SIZE (0x2D0U)
|
||||
#define LOSCFG_BASE_CORE_TSK_MIN_STACK_SIZE (0x130U)
|
||||
#define LOSCFG_BASE_CORE_TIMESLICE 1
|
||||
#define LOSCFG_BASE_CORE_TIMESLICE_TIMEOUT 20000
|
||||
/*=============================================================================
|
||||
Semaphore module configuration
|
||||
=============================================================================*/
|
||||
#define LOSCFG_BASE_IPC_SEM 1
|
||||
#define LOSCFG_BASE_IPC_SEM_LIMIT 48
|
||||
/*=============================================================================
|
||||
Mutex module configuration
|
||||
=============================================================================*/
|
||||
#define LOSCFG_BASE_IPC_MUX 1
|
||||
#define LOSCFG_BASE_IPC_MUX_LIMIT 24
|
||||
/*=============================================================================
|
||||
Queue module configuration
|
||||
=============================================================================*/
|
||||
#define LOSCFG_BASE_IPC_QUEUE 1
|
||||
#define LOSCFG_BASE_IPC_QUEUE_LIMIT 24
|
||||
/*=============================================================================
|
||||
Software timer module configuration
|
||||
=============================================================================*/
|
||||
#define LOSCFG_BASE_CORE_SWTMR 1
|
||||
#define LOSCFG_BASE_CORE_SWTMR_ALIGN 1
|
||||
#define LOSCFG_BASE_CORE_SWTMR_LIMIT 48
|
||||
/*=============================================================================
|
||||
Memory module configuration
|
||||
=============================================================================*/
|
||||
#define LOSCFG_MEM_MUL_POOL 1
|
||||
#define OS_SYS_MEM_NUM 20
|
||||
/*=============================================================================
|
||||
Exception module configuration
|
||||
=============================================================================*/
|
||||
#define LOSCFG_PLATFORM_EXC 1
|
||||
/* =============================================================================
|
||||
printf module configuration
|
||||
============================================================================= */
|
||||
#define LOSCFG_KERNEL_PRINTF 1
|
||||
|
||||
#define LOSCFG_BASE_CORE_SCHED_SLEEP 1
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _TARGET_CONFIG_H */
|
|
@ -1,196 +0,0 @@
|
|||
##########################################################################################################################
|
||||
# File automatically-generated by tool: [projectgenerator] version: [3.11.0-B13] date: [Wed Dec 16 15:17:16 CST 2020]
|
||||
##########################################################################################################################
|
||||
|
||||
# ------------------------------------------------
|
||||
# Generic Makefile (based on gcc)
|
||||
#
|
||||
# ChangeLog :
|
||||
# 2017-02-10 - Several enhancements + project update mode
|
||||
# 2015-07-22 - first version
|
||||
# ------------------------------------------------
|
||||
|
||||
######################################
|
||||
# target
|
||||
######################################
|
||||
TARGET = NUCLEO-F767
|
||||
|
||||
|
||||
######################################
|
||||
# building variables
|
||||
######################################
|
||||
# debug build?
|
||||
DEBUG = 1
|
||||
# optimization
|
||||
OPT = -Og
|
||||
|
||||
|
||||
#######################################
|
||||
# paths
|
||||
#######################################
|
||||
# Build path
|
||||
BUILD_DIR = build
|
||||
|
||||
######################################
|
||||
# source
|
||||
######################################
|
||||
# C sources
|
||||
C_SOURCES = \
|
||||
Core/Src/main.c \
|
||||
Core/Src/stm32f7xx_it.c \
|
||||
Core/Src/stm32f7xx_hal_msp.c \
|
||||
Drivers/STM32F7xx_HAL_Driver/Src/stm32f7xx_hal_cortex.c \
|
||||
Drivers/STM32F7xx_HAL_Driver/Src/stm32f7xx_hal_tim.c \
|
||||
Drivers/STM32F7xx_HAL_Driver/Src/stm32f7xx_hal_tim_ex.c \
|
||||
Drivers/STM32F7xx_HAL_Driver/Src/stm32f7xx_hal_uart.c \
|
||||
Drivers/STM32F7xx_HAL_Driver/Src/stm32f7xx_hal_uart_ex.c \
|
||||
Drivers/STM32F7xx_HAL_Driver/Src/stm32f7xx_hal_rcc.c \
|
||||
Drivers/STM32F7xx_HAL_Driver/Src/stm32f7xx_hal_rcc_ex.c \
|
||||
Drivers/STM32F7xx_HAL_Driver/Src/stm32f7xx_hal_flash.c \
|
||||
Drivers/STM32F7xx_HAL_Driver/Src/stm32f7xx_hal_flash_ex.c \
|
||||
Drivers/STM32F7xx_HAL_Driver/Src/stm32f7xx_hal_gpio.c \
|
||||
Drivers/STM32F7xx_HAL_Driver/Src/stm32f7xx_hal_dma.c \
|
||||
Drivers/STM32F7xx_HAL_Driver/Src/stm32f7xx_hal_dma_ex.c \
|
||||
Drivers/STM32F7xx_HAL_Driver/Src/stm32f7xx_hal_pwr.c \
|
||||
Drivers/STM32F7xx_HAL_Driver/Src/stm32f7xx_hal_pwr_ex.c \
|
||||
Drivers/STM32F7xx_HAL_Driver/Src/stm32f7xx_hal.c \
|
||||
Drivers/STM32F7xx_HAL_Driver/Src/stm32f7xx_hal_i2c.c \
|
||||
Drivers/STM32F7xx_HAL_Driver/Src/stm32f7xx_hal_i2c_ex.c \
|
||||
Drivers/STM32F7xx_HAL_Driver/Src/stm32f7xx_hal_exti.c \
|
||||
Core/Src/system_stm32f7xx.c
|
||||
|
||||
# ASM sources
|
||||
ASM_SOURCES = \
|
||||
startup_stm32f767xx.s
|
||||
|
||||
|
||||
#######################################
|
||||
# binaries
|
||||
#######################################
|
||||
PREFIX = arm-none-eabi-
|
||||
# The gcc compiler bin path can be either defined in make command via GCC_PATH variable (> make GCC_PATH=xxx)
|
||||
# either it can be added to the PATH environment variable.
|
||||
ifdef GCC_PATH
|
||||
CC = $(GCC_PATH)/$(PREFIX)gcc
|
||||
AS = $(GCC_PATH)/$(PREFIX)gcc -x assembler-with-cpp
|
||||
CP = $(GCC_PATH)/$(PREFIX)objcopy
|
||||
SZ = $(GCC_PATH)/$(PREFIX)size
|
||||
else
|
||||
CC = $(PREFIX)gcc
|
||||
AS = $(PREFIX)gcc -x assembler-with-cpp
|
||||
CP = $(PREFIX)objcopy
|
||||
SZ = $(PREFIX)size
|
||||
endif
|
||||
HEX = $(CP) -O ihex
|
||||
BIN = $(CP) -O binary -S
|
||||
|
||||
#######################################
|
||||
# CFLAGS
|
||||
#######################################
|
||||
# cpu
|
||||
CPU = -mcpu=cortex-m7
|
||||
|
||||
# fpu
|
||||
FPU = -mfpu=fpv5-d16
|
||||
|
||||
# float-abi
|
||||
#FLOAT-ABI = -mfloat-abi=hard
|
||||
FLOAT-ABI = -mfloat-abi=soft
|
||||
|
||||
# mcu
|
||||
MCU = $(CPU) -mthumb $(FPU) $(FLOAT-ABI)
|
||||
|
||||
# macros for gcc
|
||||
# AS defines
|
||||
AS_DEFS =
|
||||
|
||||
# C defines
|
||||
C_DEFS = \
|
||||
-DUSE_HAL_DRIVER \
|
||||
-DSTM32F767xx
|
||||
|
||||
|
||||
# AS includes
|
||||
AS_INCLUDES =
|
||||
|
||||
# C includes
|
||||
C_INCLUDES = \
|
||||
-ICore/Inc \
|
||||
-IDrivers/STM32F7xx_HAL_Driver/Inc \
|
||||
-IDrivers/STM32F7xx_HAL_Driver/Inc/Legacy \
|
||||
-IDrivers/CMSIS/Device/ST/STM32F7xx/Include \
|
||||
-IDrivers/CMSIS/Include \
|
||||
-IDrivers/CMSIS/Include
|
||||
|
||||
|
||||
# compile gcc flags
|
||||
ASFLAGS = $(MCU) $(AS_DEFS) $(AS_INCLUDES) $(OPT) -Wall -fdata-sections -ffunction-sections
|
||||
|
||||
CFLAGS = $(MCU) $(C_DEFS) $(C_INCLUDES) $(OPT) -Wall -fdata-sections -ffunction-sections
|
||||
|
||||
ifeq ($(DEBUG), 1)
|
||||
CFLAGS += -g -gdwarf-2
|
||||
endif
|
||||
|
||||
|
||||
# Generate dependency information
|
||||
CFLAGS += -MMD -MP -MF"$(@:%.o=%.d)"
|
||||
|
||||
|
||||
#######################################
|
||||
# LDFLAGS
|
||||
#######################################
|
||||
# link script
|
||||
LDSCRIPT = STM32F767ZITx_FLASH.ld
|
||||
|
||||
# libraries
|
||||
LIBS = -lc -lm -lnosys
|
||||
LIBDIR =
|
||||
LDFLAGS = $(MCU) -specs=nano.specs -T$(LDSCRIPT) $(LIBDIR) $(LIBS) -Wl,-Map=$(BUILD_DIR)/$(TARGET).map,--cref -Wl,--gc-sections
|
||||
|
||||
# default action: build all
|
||||
all: $(BUILD_DIR)/$(TARGET).elf $(BUILD_DIR)/$(TARGET).hex $(BUILD_DIR)/$(TARGET).bin
|
||||
|
||||
include liteos_m.mk
|
||||
|
||||
#######################################
|
||||
# build the application
|
||||
#######################################
|
||||
# list of objects
|
||||
OBJECTS += $(addprefix $(BUILD_DIR)/,$(notdir $(C_SOURCES:.c=.o)))
|
||||
vpath %.c $(sort $(dir $(C_SOURCES)))
|
||||
# list of ASM program objects
|
||||
OBJECTS += $(addprefix $(BUILD_DIR)/,$(notdir $(ASM_SOURCES:.s=.o)))
|
||||
vpath %.s $(sort $(dir $(ASM_SOURCES)))
|
||||
|
||||
$(BUILD_DIR)/%.o: %.c Makefile | $(BUILD_DIR)
|
||||
$(CC) -c $(CFLAGS) -Wa,-a,-ad,-alms=$(BUILD_DIR)/$(notdir $(<:.c=.lst)) $< -o $@
|
||||
|
||||
$(BUILD_DIR)/%.o: %.s Makefile | $(BUILD_DIR)
|
||||
$(AS) -c $(CFLAGS) $< -o $@
|
||||
|
||||
$(BUILD_DIR)/$(TARGET).elf: $(OBJECTS) Makefile
|
||||
$(CC) $(OBJECTS) $(LDFLAGS) -o $@
|
||||
$(SZ) $@
|
||||
|
||||
$(BUILD_DIR)/%.hex: $(BUILD_DIR)/%.elf | $(BUILD_DIR)
|
||||
$(HEX) $< $@
|
||||
|
||||
$(BUILD_DIR)/%.bin: $(BUILD_DIR)/%.elf | $(BUILD_DIR)
|
||||
$(BIN) $< $@
|
||||
|
||||
$(BUILD_DIR):
|
||||
mkdir $@
|
||||
|
||||
#######################################
|
||||
# clean up
|
||||
#######################################
|
||||
clean:
|
||||
-rm -fR $(BUILD_DIR)
|
||||
|
||||
#######################################
|
||||
# dependencies
|
||||
#######################################
|
||||
-include $(wildcard $(BUILD_DIR)/*.d)
|
||||
|
||||
# *** EOF ***
|
|
@ -1,38 +0,0 @@
|
|||
LITEOSTOPDIR := ../../
|
||||
LITEOSTOPDIR := $(realpath $(LITEOSTOPDIR))
|
||||
|
||||
# Common
|
||||
C_SOURCES += $(wildcard $(LITEOSTOPDIR)/kernel/src/*.c) \
|
||||
$(wildcard $(LITEOSTOPDIR)/kernel/src/mm/*.c) \
|
||||
$(wildcard $(LITEOSTOPDIR)/components/cpup/*.c) \
|
||||
$(wildcard $(LITEOSTOPDIR)/third_party/bounds_checking_function/src/*.c) \
|
||||
$(wildcard $(LITEOSTOPDIR)/utils/*.c) \
|
||||
$(wildcard $(LITEOSTOPDIR)/kal/posix/src/*.c) \
|
||||
Core/Src/task_sample.c
|
||||
|
||||
C_INCLUDES += -I$(LITEOSTOPDIR)/utils \
|
||||
-I$(LITEOSTOPDIR)/kal/posix/include \
|
||||
-I$(LITEOSTOPDIR)/kernel/include \
|
||||
-I$(LITEOSTOPDIR)/components/cpup \
|
||||
-I$(LITEOSTOPDIR)/third_party/cmsis/CMSIS/RTOS2/Include \
|
||||
-I$(LITEOSTOPDIR)/third_party/bounds_checking_function/include
|
||||
|
||||
# Related to arch
|
||||
ASM_SOURCES += $(wildcard $(LITEOSTOPDIR)/kernel/arch/arm/cortex-m7/gcc/*.s)
|
||||
|
||||
ASMS_SOURCES += $(wildcard $(LITEOSTOPDIR)/kernel/arch/arm/cortex-m7/gcc/*.S)
|
||||
|
||||
C_SOURCES += $(wildcard $(LITEOSTOPDIR)/kernel/arch/arm/cortex-m7/gcc/*.c)
|
||||
|
||||
C_INCLUDES += -I. \
|
||||
-I$(LITEOSTOPDIR)/kernel/arch/include \
|
||||
-I$(LITEOSTOPDIR)/kernel/arch/arm/cortex-m7/gcc
|
||||
|
||||
CFLAGS += -nostdinc -nostdlib
|
||||
|
||||
# list of ASM .S program objects
|
||||
OBJECTS += $(addprefix $(BUILD_DIR)/,$(notdir $(ASMS_SOURCES:.S=.o)))
|
||||
vpath %.S $(sort $(dir $(ASMS_SOURCES)))
|
||||
|
||||
$(BUILD_DIR)/%.o: %.S Makefile | $(BUILD_DIR)
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
|
@ -1,113 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/**@defgroup los_config System configuration items
|
||||
* @ingroup kernel
|
||||
*/
|
||||
|
||||
#ifndef _TARGET_CONFIG_H
|
||||
#define _TARGET_CONFIG_H
|
||||
|
||||
#include "stm32f7xx.h"
|
||||
#include "stm32f7xx_it.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/*=============================================================================
|
||||
System clock module configuration
|
||||
=============================================================================*/
|
||||
#define OS_SYS_CLOCK 96000000
|
||||
#define LOSCFG_BASE_CORE_TICK_PER_SECOND (1000UL)
|
||||
#define LOSCFG_BASE_CORE_TICK_HW_TIME 0
|
||||
#define LOSCFG_BASE_CORE_TICK_WTIMER 0
|
||||
#define LOSCFG_BASE_CORE_TICK_RESPONSE_MAX SysTick_LOAD_RELOAD_Msk
|
||||
|
||||
/*=============================================================================
|
||||
Hardware interrupt module configuration
|
||||
=============================================================================*/
|
||||
#define LOSCFG_PLATFORM_HWI 1
|
||||
#define LOSCFG_PLATFORM_HWI_LIMIT 128
|
||||
/*=============================================================================
|
||||
Task module configuration
|
||||
=============================================================================*/
|
||||
#define LOSCFG_BASE_CORE_TSK_LIMIT 24
|
||||
#define LOSCFG_BASE_CORE_TSK_IDLE_STACK_SIZE (0x500U)
|
||||
#define LOSCFG_BASE_CORE_TSK_DEFAULT_STACK_SIZE (0x2D0U)
|
||||
#define LOSCFG_BASE_CORE_TSK_MIN_STACK_SIZE (0x130U)
|
||||
#define LOSCFG_BASE_CORE_TIMESLICE 1
|
||||
#define LOSCFG_BASE_CORE_TIMESLICE_TIMEOUT 20000
|
||||
/*=============================================================================
|
||||
Semaphore module configuration
|
||||
=============================================================================*/
|
||||
#define LOSCFG_BASE_IPC_SEM 1
|
||||
#define LOSCFG_BASE_IPC_SEM_LIMIT 48
|
||||
/*=============================================================================
|
||||
Mutex module configuration
|
||||
=============================================================================*/
|
||||
#define LOSCFG_BASE_IPC_MUX 1
|
||||
#define LOSCFG_BASE_IPC_MUX_LIMIT 24
|
||||
/*=============================================================================
|
||||
Queue module configuration
|
||||
=============================================================================*/
|
||||
#define LOSCFG_BASE_IPC_QUEUE 1
|
||||
#define LOSCFG_BASE_IPC_QUEUE_LIMIT 24
|
||||
/*=============================================================================
|
||||
Software timer module configuration
|
||||
=============================================================================*/
|
||||
#define LOSCFG_BASE_CORE_SWTMR 1
|
||||
#define LOSCFG_BASE_CORE_SWTMR_ALIGN 1
|
||||
#define LOSCFG_BASE_CORE_SWTMR_LIMIT 48
|
||||
/*=============================================================================
|
||||
Memory module configuration
|
||||
=============================================================================*/
|
||||
#define OS_SYS_MEM_SIZE 0x00013000
|
||||
#define LOSCFG_BASE_MEM_NODE_INTEGRITY_CHECK 0
|
||||
#define LOSCFG_BASE_MEM_NODE_SIZE_CHECK 1
|
||||
#define LOSCFG_MEM_MUL_POOL 1
|
||||
#define OS_SYS_MEM_NUM 20
|
||||
#define LOSCFG_KERNEL_MEM_SLAB 0
|
||||
/*=============================================================================
|
||||
Exception module configuration
|
||||
=============================================================================*/
|
||||
#define LOSCFG_PLATFORM_EXC 0
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
|
||||
#endif /* _TARGET_CONFIG_H */
|
|
@ -42,8 +42,8 @@
|
|||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cpluscplus */
|
||||
#endif /* __cpluscplus */
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
UINT8 __attribute__ ((aligned (8))) g_memStart[OS_SYS_MEM_SIZE];
|
||||
|
||||
|
@ -102,5 +102,5 @@ VOID RunTaskSample(VOID)
|
|||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cpluscplus */
|
||||
#endif /* __cpluscplus */
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
|
|
@ -40,15 +40,15 @@
|
|||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cpluscplus */
|
||||
#endif /* __cpluscplus */
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
VOID RunTaskSample(VOID);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cpluscplus */
|
||||
#endif /* __cpluscplus */
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _TASKSAMPLE_H */
|
||||
|
|
|
@ -72,7 +72,7 @@ typedef struct _usb_control {
|
|||
usb_req req; /*!< USB standard device request */
|
||||
|
||||
uint8_t ctl_state; /*!< USB control transfer state */
|
||||
uint8_t ctl_zlp; /*!< zero lenth package */
|
||||
uint8_t ctl_zlp; /*!< zero length package */
|
||||
} usb_control;
|
||||
|
||||
typedef struct
|
||||
|
@ -87,14 +87,14 @@ typedef struct
|
|||
uint8_t ep_stall; /*!< USB endpoint stall status */
|
||||
|
||||
uint8_t frame_num; /*!< number of frame */
|
||||
uint16_t max_len; /*!< Maximum packet lenth */
|
||||
uint16_t max_len; /*!< Maximum packet length */
|
||||
|
||||
/* transaction level variables */
|
||||
uint8_t *xfer_buf; /*!< transmit buffer */
|
||||
uint32_t xfer_len; /*!< transmit buffer length */
|
||||
uint32_t xfer_count; /*!< transmit buffer count */
|
||||
|
||||
uint32_t remain_len; /*!< remain packet lenth */
|
||||
uint32_t remain_len; /*!< remain packet length */
|
||||
|
||||
uint32_t dma_addr; /*!< DMA address */
|
||||
} usb_transc;
|
||||
|
|
|
@ -619,7 +619,7 @@ void timer_dma_disable(uint32_t timer_periph, uint16_t dma);
|
|||
/* channel DMA request source selection */
|
||||
void timer_channel_dma_request_source_select(uint32_t timer_periph, uint32_t dma_request);
|
||||
/* configure the TIMER DMA transfer */
|
||||
void timer_dma_transfer_config(uint32_t timer_periph, uint32_t dma_baseaddr, uint32_t dma_lenth);
|
||||
void timer_dma_transfer_config(uint32_t timer_periph, uint32_t dma_baseaddr, uint32_t dma_length);
|
||||
/* software generate events */
|
||||
void timer_event_software_generate(uint32_t timer_periph, uint16_t event);
|
||||
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue