diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index be682f53..00000000 --- a/.gitmodules +++ /dev/null @@ -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 = . diff --git a/BUILD.gn b/BUILD.gn index b8304d45..18aee987 100644 --- a/BUILD.gn +++ b/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: diff --git a/README.md b/README.md index a3d1d4ca..72d7fc2c 100644 --- a/README.md +++ b/README.md @@ -15,11 +15,17 @@ The OpenHarmony LiteOS Cortex-M is the kernel designed for the lightweight opera ## Directory Structure +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 diff --git a/README_zh.md b/README_zh.md index 9e9e8489..255e9471 100644 --- a/README_zh.md +++ b/README_zh.md @@ -15,11 +15,17 @@ OpenHarmony LiteOS-M内核是面向IoT领域构建的轻量级物联网操作系 ## 目录 +目录结构如下,详细目录请参考[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领域构建的轻量级物联网操作系 ## 使用说明 -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 diff --git a/arch_spec.md b/arch_spec.md index 2ce739e4..b7ae40e1 100644 --- a/arch_spec.md +++ b/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 ``` + diff --git a/arch_spec_zh.md b/arch_spec_zh.md new file mode 100644 index 00000000..99a4e535 --- /dev/null +++ b/arch_spec_zh.md @@ -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 +``` + diff --git a/components/backtrace/BUILD.gn b/components/backtrace/BUILD.gn index 9d1dc2b1..22e3a48d 100644 --- a/components/backtrace/BUILD.gn +++ b/components/backtrace/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: diff --git a/components/backtrace/los_backtrace.c b/components/backtrace/los_backtrace.c index c9742a1e..1910be60 100644 --- a/components/backtrace/los_backtrace.c +++ b/components/backtrace/los_backtrace.c @@ -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(); diff --git a/components/backtrace/los_backtrace.h b/components/backtrace/los_backtrace.h index e62f93da..b9d1886e 100644 --- a/components/backtrace/los_backtrace.h +++ b/components/backtrace/los_backtrace.h @@ -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 diff --git a/components/bounds_checking_function b/components/bounds_checking_function deleted file mode 120000 index 795e1a77..00000000 --- a/components/bounds_checking_function +++ /dev/null @@ -1 +0,0 @@ -../../../third_party/bounds_checking_function/ \ No newline at end of file diff --git a/components/cppsupport/BUILD.gn b/components/cppsupport/BUILD.gn index 2cb08a28..497ec40c 100644 --- a/components/cppsupport/BUILD.gn +++ b/components/cppsupport/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: diff --git a/components/cpup/BUILD.gn b/components/cpup/BUILD.gn index bec51891..cd5693b0 100644 --- a/components/cpup/BUILD.gn +++ b/components/cpup/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: diff --git a/components/cpup/los_cpup.h b/components/cpup/los_cpup.h index dd8ca9a3..ab418846 100644 --- a/components/cpup/los_cpup.h +++ b/components/cpup/los_cpup.h @@ -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: * * @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: * * @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: * * @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: * * @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. diff --git a/components/exchook/BUILD.gn b/components/exchook/BUILD.gn index fc93d9de..bbd45a1b 100644 --- a/components/exchook/BUILD.gn +++ b/components/exchook/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: diff --git a/components/fs/BUILD.gn b/components/fs/BUILD.gn index 5114fdd3..1173aa9f 100644 --- a/components/fs/BUILD.gn +++ b/components/fs/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: @@ -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" ] } diff --git a/components/fs/fatfs/BUILD.gn b/components/fs/fatfs/BUILD.gn index ad2945c8..7be3db52 100644 --- a/components/fs/fatfs/BUILD.gn +++ b/components/fs/fatfs/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: @@ -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", diff --git a/components/fs/fatfs/fatfs.c b/components/fs/fatfs/fatfs.c index 58b683ca..4e413184 100644 --- a/components/fs/fatfs/fatfs.c +++ b/components/fs/fatfs/fatfs.c @@ -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, +}; diff --git a/components/fs/fatfs/fs.c b/components/fs/fs.c similarity index 56% rename from components/fs/fatfs/fs.c rename to components/fs/fs.c index 04fecb89..66ed8af6 100644 --- a/components/fs/fatfs/fs.c +++ b/components/fs/fs.c @@ -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); } diff --git a/components/fs/fs_operations.h b/components/fs/fs_operations.h new file mode 100644 index 00000000..e22be283 --- /dev/null +++ b/components/fs/fs_operations.h @@ -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_ */ diff --git a/components/fs/littlefs/BUILD.gn b/components/fs/littlefs/BUILD.gn index f3d8c9ea..fbd76cc6 100644 --- a/components/fs/littlefs/BUILD.gn +++ b/components/fs/littlefs/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: diff --git a/components/fs/littlefs/lfs_api.c b/components/fs/littlefs/lfs_api.c index e30b3946..f5e34c3f 100644 --- a/components/fs/littlefs/lfs_api.c +++ b/components/fs/littlefs/lfs_api.c @@ -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; } diff --git a/components/fs/littlefs/lfs_api.h b/components/fs/littlefs/lfs_api.h index 8f87d108..fdbf582c 100644 --- a/components/fs/littlefs/lfs_api.h +++ b/components/fs/littlefs/lfs_api.h @@ -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); diff --git a/kal/BUILD.gn b/kal/BUILD.gn index 97dc7381..da59f5a6 100644 --- a/kal/BUILD.gn +++ b/kal/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: diff --git a/kal/cmsis/BUILD.gn b/kal/cmsis/BUILD.gn index 861efb9f..4b6516f9 100644 --- a/kal/cmsis/BUILD.gn +++ b/kal/cmsis/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: diff --git a/kal/cmsis/cmsis_os2.h b/kal/cmsis/cmsis_os2.h deleted file mode 120000 index c98551bc..00000000 --- a/kal/cmsis/cmsis_os2.h +++ /dev/null @@ -1 +0,0 @@ -../../../../third_party/cmsis/CMSIS/RTOS2/Include/cmsis_os2.h \ No newline at end of file diff --git a/kal/cmsis/cmsis_os2.h b/kal/cmsis/cmsis_os2.h new file mode 100644 index 00000000..b149eba4 --- /dev/null +++ b/kal/cmsis/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" diff --git a/kal/posix/BUILD.gn b/kal/posix/BUILD.gn index cc8d577b..c3e8235c 100644 --- a/kal/posix/BUILD.gn +++ b/kal/posix/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: diff --git a/kal/posix/include/bits/alltypes.h b/kal/posix/include/bits/alltypes.h index 2ba9a82e..e4c5af78 100644 --- a/kal/posix/include/bits/alltypes.h +++ b/kal/posix/include/bits/alltypes.h @@ -4,7 +4,7 @@ #define _Int64 long long #define _Reg int -#if __ARMEB__ +#ifdef __ARMEB__ #define __BYTE_ORDER 4321 #else #define __BYTE_ORDER 1234 diff --git a/kal/posix/include/sys/resource.h b/kal/posix/include/sys/resource.h index 3068328d..dc5f52d9 100644 --- a/kal/posix/include/sys/resource.h +++ b/kal/posix/include/sys/resource.h @@ -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; diff --git a/kal/posix/musl_src/stdio/__fdopen.c b/kal/posix/musl_src/stdio/__fdopen.c index e89f930d..bc50be7d 100644 --- a/kal/posix/musl_src/stdio/__fdopen.c +++ b/kal/posix/musl_src/stdio/__fdopen.c @@ -6,6 +6,11 @@ #include #include +int ioctl(int fd, int req, ...) +{ + return 0; +} + FILE *__fdopen(int fd, const char *mode) { FILE *f; diff --git a/kal/posix/musl_src/stdio/fclose.c b/kal/posix/musl_src/stdio/fclose.c index bd6a890d..eeba0ffb 100644 --- a/kal/posix/musl_src/stdio/fclose.c +++ b/kal/posix/musl_src/stdio/fclose.c @@ -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); \ No newline at end of file diff --git a/kal/posix/musl_src/stdio/fflush.c b/kal/posix/musl_src/stdio/fflush.c index 71606ac9..d755f8f1 100644 --- a/kal/posix/musl_src/stdio/fflush.c +++ b/kal/posix/musl_src/stdio/fflush.c @@ -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); diff --git a/kal/posix/musl_src/stdio/fseek.c b/kal/posix/musl_src/stdio/fseek.c index 2fc16d84..4731d8a0 100644 --- a/kal/posix/musl_src/stdio/fseek.c +++ b/kal/posix/musl_src/stdio/fseek.c @@ -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; } diff --git a/kal/posix/src/fwrap.c b/kal/posix/src/fwrap.c new file mode 100644 index 00000000..c47b46bf --- /dev/null +++ b/kal/posix/src/fwrap.c @@ -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); +} \ No newline at end of file diff --git a/kal/posix/src/mqueue_impl.h b/kal/posix/src/mqueue_impl.h index d0131a38..daedc0ab 100644 --- a/kal/posix/src/mqueue_impl.h +++ b/kal/posix/src/mqueue_impl.h @@ -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 diff --git a/kal/posix/src/time.c b/kal/posix/src/time.c index 838be5a1..adf3ca76 100644 --- a/kal/posix/src/time.c +++ b/kal/posix/src/time.c @@ -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)) { diff --git a/kernel/BUILD.gn b/kernel/BUILD.gn index 742da8b1..0eb0b54c 100644 --- a/kernel/BUILD.gn +++ b/kernel/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: diff --git a/kernel/arch/arm/cortex-m3/keil/los_arch_interrupt.h b/kernel/arch/arm/cortex-m3/keil/los_arch_interrupt.h index 008b97d3..3c98b745 100644 --- a/kernel/arch/arm/cortex-m3/keil/los_arch_interrupt.h +++ b/kernel/arch/arm/cortex-m3/keil/los_arch_interrupt.h @@ -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; diff --git a/kernel/arch/arm/cortex-m33/gcc/BUILD.gn b/kernel/arch/arm/cortex-m33/gcc/BUILD.gn index ccda24e2..9e6f08d1 100644 --- a/kernel/arch/arm/cortex-m33/gcc/BUILD.gn +++ b/kernel/arch/arm/cortex-m33/gcc/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: diff --git a/kernel/arch/arm/cortex-m33/gcc/los_arch_interrupt.h b/kernel/arch/arm/cortex-m33/gcc/los_arch_interrupt.h index 008b97d3..3c98b745 100644 --- a/kernel/arch/arm/cortex-m33/gcc/los_arch_interrupt.h +++ b/kernel/arch/arm/cortex-m33/gcc/los_arch_interrupt.h @@ -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; diff --git a/kernel/arch/arm/cortex-m33/iar/NTZ/los_arch_atomic.h b/kernel/arch/arm/cortex-m33/iar/NTZ/los_arch_atomic.h new file mode 100644 index 00000000..e57c6a9b --- /dev/null +++ b/kernel/arch/arm/cortex-m33/iar/NTZ/los_arch_atomic.h @@ -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 + * + * + * @param v [IN] The variable pointer. + * @param val [IN] The exchange value. + * + * @retval #INT32 The previous value of the atomic variable + * @par Dependency: + * + * @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 + * + * + * @param v [IN] The addSelf variable pointer. + * + * @retval #INT32 The return value of variable auto-decrement. + * @par Dependency: + * + * @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 + * + * + * @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: + * + * @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 */ + diff --git a/kernel/arch/arm/cortex-m33/iar/NTZ/los_arch_context.h b/kernel/arch/arm/cortex-m33/iar/NTZ/los_arch_context.h new file mode 100644 index 00000000..9220a1e1 --- /dev/null +++ b/kernel/arch/arm/cortex-m33/iar/NTZ/los_arch_context.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: + * + * + * @param: None. + * + * @retval None. + * + * @par Dependency: + * + * @see None. + */ +extern VOID HalStartToRun(VOID); + +#ifdef __cplusplus +#if __cplusplus +} +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +#endif /* _LOS_ARCH_CONTEXT_H */ + diff --git a/kernel/arch/arm/cortex-m33/iar/NTZ/los_arch_interrupt.h b/kernel/arch/arm/cortex-m33/iar/NTZ/los_arch_interrupt.h new file mode 100644 index 00000000..e02d529c --- /dev/null +++ b/kernel/arch/arm/cortex-m33/iar/NTZ/los_arch_interrupt.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: + * + * + * @param:None. + * + * @retval:None. + * @par Dependency: + * + * @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: + * + * + * @param: None. + * + * @retval: Interrupt Indexes number. + * @par Dependency: + * + * @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: + * + * + * @param:None. + * + * @retval:None. + * @par Dependency: + * + * @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: + * + * + * @param:None. + * + * @retval:None. + * @par Dependency: + * + * @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: + * + * + * @param:None. + * + * @retval:None. + * @par Dependency: + * + * @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: + * + * + * @param uwArraySize [IN] Memory size of exception. + * + * @retval: None + * @par Dependency: + * + * @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 */ diff --git a/kernel/arch/arm/cortex-m33/iar/NTZ/los_arch_timer.h b/kernel/arch/arm/cortex-m33/iar/NTZ/los_arch_timer.h new file mode 100644 index 00000000..48e48d8d --- /dev/null +++ b/kernel/arch/arm/cortex-m33/iar/NTZ/los_arch_timer.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 */ + diff --git a/kernel/arch/arm/cortex-m33/iar/NTZ/los_context.c b/kernel/arch/arm/cortex-m33/iar/NTZ/los_context.c new file mode 100644 index 00000000..19df61ce --- /dev/null +++ b/kernel/arch/arm/cortex-m33/iar/NTZ/los_context.c @@ -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 */ +} diff --git a/kernel/arch/arm/cortex-m33/iar/NTZ/los_dispatch.S b/kernel/arch/arm/cortex-m33/iar/NTZ/los_dispatch.S new file mode 100644 index 00000000..14198f9f --- /dev/null +++ b/kernel/arch/arm/cortex-m33/iar/NTZ/los_dispatch.S @@ -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 diff --git a/kernel/arch/arm/cortex-m33/iar/NTZ/los_exc.S b/kernel/arch/arm/cortex-m33/iar/NTZ/los_exc.S new file mode 100644 index 00000000..15051af2 --- /dev/null +++ b/kernel/arch/arm/cortex-m33/iar/NTZ/los_exc.S @@ -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 diff --git a/kernel/arch/arm/cortex-m33/iar/NTZ/los_interrupt.c b/kernel/arch/arm/cortex-m33/iar/NTZ/los_interrupt.c new file mode 100644 index 00000000..cdd706f4 --- /dev/null +++ b/kernel/arch/arm/cortex-m33/iar/NTZ/los_interrupt.c @@ -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 +#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; +} + diff --git a/kernel/arch/arm/cortex-m33/iar/NTZ/los_timer.c b/kernel/arch/arm/cortex-m33/iar/NTZ/los_timer.c new file mode 100644 index 00000000..bebda6f8 --- /dev/null +++ b/kernel/arch/arm/cortex-m33/iar/NTZ/los_timer.c @@ -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(); +} diff --git a/kernel/arch/arm/cortex-m33/iar/TZ/non_secure/los_arch_atomic.h b/kernel/arch/arm/cortex-m33/iar/TZ/non_secure/los_arch_atomic.h new file mode 100644 index 00000000..e57c6a9b --- /dev/null +++ b/kernel/arch/arm/cortex-m33/iar/TZ/non_secure/los_arch_atomic.h @@ -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 + *
    The pointer v must not be NULL.
+ * + * @param v [IN] The variable pointer. + * @param val [IN] The exchange value. + * + * @retval #INT32 The previous value of the atomic variable + * @par Dependency: + *
  • los_atomic.h: the header file that contains the API declaration.
+ * @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 + *
    + *
  • The pointer v must not be NULL.
  • + *
  • The value which v point to must not be INT_MIN to avoid overflow after reducing 1.
  • + *
+ * + * @param v [IN] The addSelf variable pointer. + * + * @retval #INT32 The return value of variable auto-decrement. + * @par Dependency: + *
  • los_atomic.h: the header file that contains the API declaration.
+ * @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 + *
    The pointer v must not be NULL.
+ * + * @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: + *
  • los_atomic.h: the header file that contains the API declaration.
+ * @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 */ + diff --git a/kernel/arch/arm/cortex-m33/iar/TZ/non_secure/los_arch_context.h b/kernel/arch/arm/cortex-m33/iar/TZ/non_secure/los_arch_context.h new file mode 100644 index 00000000..14500183 --- /dev/null +++ b/kernel/arch/arm/cortex-m33/iar/TZ/non_secure/los_arch_context.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: + *
  • None.
+ * + * @param: None. + * + * @retval None. + * + * @par Dependency: + *
  • los_config.h: the header file that contains the API declaration.
+ * @see None. + */ +extern VOID HalStartToRun(VOID); + +#ifdef __cplusplus +#if __cplusplus +} +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +#endif /* _LOS_ARCH_CONTEXT_H */ + diff --git a/kernel/arch/arm/cortex-m33/iar/TZ/non_secure/los_arch_interrupt.h b/kernel/arch/arm/cortex-m33/iar/TZ/non_secure/los_arch_interrupt.h new file mode 100644 index 00000000..e02d529c --- /dev/null +++ b/kernel/arch/arm/cortex-m33/iar/TZ/non_secure/los_arch_interrupt.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: + *
  • None.
+ * + * @param:None. + * + * @retval:None. + * @par Dependency: + *
  • los_hwi.h: the header file that contains the API declaration.
+ * @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: + *
  • None.
+ * + * @param: None. + * + * @retval: Interrupt Indexes number. + * @par Dependency: + *
  • los_hwi.h: the header file that contains the API declaration.
+ * @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: + *
  • None.
+ * + * @param:None. + * + * @retval:None. + * @par Dependency: + *
  • los_hwi.h: the header file that contains the API declaration.
+ * @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: + *
  • None.
+ * + * @param:None. + * + * @retval:None. + * @par Dependency: + *
  • los_hwi.h: the header file that contains the API declaration.
+ * @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: + *
  • None.
+ * + * @param:None. + * + * @retval:None. + * @par Dependency: + *
  • los_hwi.h: the header file that contains the API declaration.
+ * @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: + *
  • None.
+ * + * @param uwArraySize [IN] Memory size of exception. + * + * @retval: None + * @par Dependency: + *
  • los_hwi.h: the header file that contains the API declaration.
+ * @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 */ diff --git a/kernel/arch/arm/cortex-m33/iar/TZ/non_secure/los_arch_timer.h b/kernel/arch/arm/cortex-m33/iar/TZ/non_secure/los_arch_timer.h new file mode 100644 index 00000000..48e48d8d --- /dev/null +++ b/kernel/arch/arm/cortex-m33/iar/TZ/non_secure/los_arch_timer.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 */ + diff --git a/kernel/arch/arm/cortex-m33/iar/TZ/non_secure/los_context.c b/kernel/arch/arm/cortex-m33/iar/TZ/non_secure/los_context.c new file mode 100644 index 00000000..45fecf89 --- /dev/null +++ b/kernel/arch/arm/cortex-m33/iar/TZ/non_secure/los_context.c @@ -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 */ +} diff --git a/kernel/arch/arm/cortex-m33/iar/TZ/non_secure/los_dispatch.S b/kernel/arch/arm/cortex-m33/iar/TZ/non_secure/los_dispatch.S new file mode 100644 index 00000000..f786e0b4 --- /dev/null +++ b/kernel/arch/arm/cortex-m33/iar/TZ/non_secure/los_dispatch.S @@ -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 diff --git a/kernel/arch/arm/cortex-m33/iar/TZ/non_secure/los_exc.S b/kernel/arch/arm/cortex-m33/iar/TZ/non_secure/los_exc.S new file mode 100644 index 00000000..d954304d --- /dev/null +++ b/kernel/arch/arm/cortex-m33/iar/TZ/non_secure/los_exc.S @@ -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 diff --git a/kernel/arch/arm/cortex-m33/iar/TZ/non_secure/los_interrupt.c b/kernel/arch/arm/cortex-m33/iar/TZ/non_secure/los_interrupt.c new file mode 100644 index 00000000..cdd706f4 --- /dev/null +++ b/kernel/arch/arm/cortex-m33/iar/TZ/non_secure/los_interrupt.c @@ -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 +#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; +} + diff --git a/kernel/arch/arm/cortex-m33/iar/TZ/non_secure/los_timer.c b/kernel/arch/arm/cortex-m33/iar/TZ/non_secure/los_timer.c new file mode 100644 index 00000000..bebda6f8 --- /dev/null +++ b/kernel/arch/arm/cortex-m33/iar/TZ/non_secure/los_timer.c @@ -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(); +} diff --git a/kernel/arch/arm/cortex-m33/iar/TZ/non_secure/los_trustzone.c b/kernel/arch/arm/cortex-m33/iar/TZ/non_secure/los_trustzone.c new file mode 100644 index 00000000..ce989d58 --- /dev/null +++ b/kernel/arch/arm/cortex-m33/iar/TZ/non_secure/los_trustzone.c @@ -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(); +} + diff --git a/kernel/arch/arm/cortex-m33/iar/TZ/non_secure/los_trustzone.h b/kernel/arch/arm/cortex-m33/iar/TZ/non_secure/los_trustzone.h new file mode 100644 index 00000000..fba0578f --- /dev/null +++ b/kernel/arch/arm/cortex-m33/iar/TZ/non_secure/los_trustzone.h @@ -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 + diff --git a/kernel/arch/arm/cortex-m33/iar/TZ/secure/los_secure_context.c b/kernel/arch/arm/cortex-m33/iar/TZ/secure/los_secure_context.c new file mode 100644 index 00000000..db9a4f9a --- /dev/null +++ b/kernel/arch/arm/cortex-m33/iar/TZ/secure/los_secure_context.c @@ -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); +} + diff --git a/kernel/arch/arm/cortex-m33/iar/TZ/secure/los_secure_context.h b/kernel/arch/arm/cortex-m33/iar/TZ/secure/los_secure_context.h new file mode 100644 index 00000000..c988598e --- /dev/null +++ b/kernel/arch/arm/cortex-m33/iar/TZ/secure/los_secure_context.h @@ -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 + + diff --git a/kernel/arch/arm/cortex-m33/iar/TZ/secure/los_secure_context_asm.S b/kernel/arch/arm/cortex-m33/iar/TZ/secure/los_secure_context_asm.S new file mode 100644 index 00000000..b6d1bb16 --- /dev/null +++ b/kernel/arch/arm/cortex-m33/iar/TZ/secure/los_secure_context_asm.S @@ -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 \ No newline at end of file diff --git a/kernel/arch/arm/cortex-m33/iar/TZ/secure/los_secure_heap.c b/kernel/arch/arm/cortex-m33/iar/TZ/secure/los_secure_heap.c new file mode 100644 index 00000000..c576ba69 --- /dev/null +++ b/kernel/arch/arm/cortex-m33/iar/TZ/secure/los_secure_heap.c @@ -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); +} + diff --git a/kernel/arch/arm/cortex-m33/iar/TZ/secure/los_secure_heap.h b/kernel/arch/arm/cortex-m33/iar/TZ/secure/los_secure_heap.h new file mode 100644 index 00000000..d3ee1aad --- /dev/null +++ b/kernel/arch/arm/cortex-m33/iar/TZ/secure/los_secure_heap.h @@ -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 + diff --git a/kernel/arch/arm/cortex-m33/iar/TZ/secure/los_secure_macros.h b/kernel/arch/arm/cortex-m33/iar/TZ/secure/los_secure_macros.h new file mode 100644 index 00000000..45c8ae50 --- /dev/null +++ b/kernel/arch/arm/cortex-m33/iar/TZ/secure/los_secure_macros.h @@ -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 + diff --git a/kernel/arch/arm/cortex-m4/gcc/BUILD.gn b/kernel/arch/arm/cortex-m4/gcc/BUILD.gn index 0f6717a0..01757ea5 100644 --- a/kernel/arch/arm/cortex-m4/gcc/BUILD.gn +++ b/kernel/arch/arm/cortex-m4/gcc/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: diff --git a/kernel/arch/arm/cortex-m4/gcc/los_arch_interrupt.h b/kernel/arch/arm/cortex-m4/gcc/los_arch_interrupt.h index 008b97d3..3c98b745 100644 --- a/kernel/arch/arm/cortex-m4/gcc/los_arch_interrupt.h +++ b/kernel/arch/arm/cortex-m4/gcc/los_arch_interrupt.h @@ -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; diff --git a/kernel/arch/arm/cortex-m4/gcc/los_exc.S b/kernel/arch/arm/cortex-m4/gcc/los_exc.S index cfdf0fac..b2106500 100644 --- a/kernel/arch/arm/cortex-m4/gcc/los_exc.S +++ b/kernel/arch/arm/cortex-m4/gcc/los_exc.S @@ -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, diff --git a/kernel/arch/arm/cortex-m4/iar/los_arch_interrupt.h b/kernel/arch/arm/cortex-m4/iar/los_arch_interrupt.h index 008b97d3..3c98b745 100644 --- a/kernel/arch/arm/cortex-m4/iar/los_arch_interrupt.h +++ b/kernel/arch/arm/cortex-m4/iar/los_arch_interrupt.h @@ -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; diff --git a/kernel/arch/arm/cortex-m7/gcc/BUILD.gn b/kernel/arch/arm/cortex-m7/gcc/BUILD.gn index ccda24e2..9e6f08d1 100644 --- a/kernel/arch/arm/cortex-m7/gcc/BUILD.gn +++ b/kernel/arch/arm/cortex-m7/gcc/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: diff --git a/kernel/arch/arm/cortex-m7/gcc/los_arch_interrupt.h b/kernel/arch/arm/cortex-m7/gcc/los_arch_interrupt.h index 008b97d3..3c98b745 100644 --- a/kernel/arch/arm/cortex-m7/gcc/los_arch_interrupt.h +++ b/kernel/arch/arm/cortex-m7/gcc/los_arch_interrupt.h @@ -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; diff --git a/kernel/arch/arm/cortex-m7/iar/los_arch_interrupt.h b/kernel/arch/arm/cortex-m7/iar/los_arch_interrupt.h index 008b97d3..3c98b745 100644 --- a/kernel/arch/arm/cortex-m7/iar/los_arch_interrupt.h +++ b/kernel/arch/arm/cortex-m7/iar/los_arch_interrupt.h @@ -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; diff --git a/kernel/arch/risc-v/nuclei/gcc/los_arch_timer.h b/kernel/arch/risc-v/nuclei/gcc/los_arch_timer.h index 384bdd5b..7edc6940 100644 --- a/kernel/arch/risc-v/nuclei/gcc/los_arch_timer.h +++ b/kernel/arch/risc-v/nuclei/gcc/los_arch_timer.h @@ -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 */ diff --git a/kernel/arch/risc-v/riscv32/gcc/BUILD.gn b/kernel/arch/risc-v/riscv32/gcc/BUILD.gn index 3bd1a1d2..709a08e6 100644 --- a/kernel/arch/risc-v/riscv32/gcc/BUILD.gn +++ b/kernel/arch/risc-v/riscv32/gcc/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: diff --git a/kernel/include/los_config.h b/kernel/include/los_config.h index 8340e65a..e3f200ef 100644 --- a/kernel/include/los_config.h +++ b/kernel/include/los_config.h @@ -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 } diff --git a/kernel/include/los_event.h b/kernel/include/los_event.h index 3f38ad33..4df94aa8 100644 --- a/kernel/include/los_event.h +++ b/kernel/include/los_event.h @@ -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 diff --git a/kernel/include/los_queue.h b/kernel/include/los_queue.h index ec934ae1..c3aebc0d 100644 --- a/kernel/include/los_queue.h +++ b/kernel/include/los_queue.h @@ -355,7 +355,7 @@ typedef struct tagQueueInfo { * This API is used to create a message queue. * @attention *
    - *
  • Threre are LOSCFG_BASE_IPC_QUEUE_LIMIT queues available, change it's value when necessory.
  • + *
  • There are LOSCFG_BASE_IPC_QUEUE_LIMIT queues available, change it's value when necessary.
  • *
* @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. diff --git a/kernel/include/los_sched.h b/kernel/include/los_sched.h index cf2528ed..b514edb3 100644 --- a/kernel/include/los_sched.h +++ b/kernel/include/los_sched.h @@ -49,7 +49,7 @@ VOID OsSchedUpdateSchedTimeBase(VOID); UINT64 OsGetCurrSchedTimeCycle(VOID); -VOID OsSchedSetIdleTaskSchedPartam(LosTaskCB *idleTask); +VOID OsSchedSetIdleTaskSchedParam(LosTaskCB *idleTask); UINT32 OsSchedSwtmrScanRegister(SchedScan func); diff --git a/kernel/include/los_swtmr.h b/kernel/include/los_swtmr.h index 1eea9c89..8d74ddd6 100644 --- a/kernel/include/los_swtmr.h +++ b/kernel/include/los_swtmr.h @@ -367,7 +367,7 @@ extern UINT32 LOS_SwtmrTimeGet(UINT32 swtmrID, UINT32 *tick); * @attention *
    *
  • Do not use the delay interface in the callback function that handles software timer timeout.
  • - *
  • Threre are LOSCFG_BASE_CORE_SWTMR_LIMIT timers available, change it's value when necessory.
  • + *
  • There are LOSCFG_BASE_CORE_SWTMR_LIMIT timers available, change it's value when necessary.
  • *
* * @param interval [IN] Timing duration of the software timer to be created (unit: ms). diff --git a/kernel/include/los_task.h b/kernel/include/los_task.h index 5c8590e2..de5072a4 100644 --- a/kernel/include/los_task.h +++ b/kernel/include/los_task.h @@ -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. * diff --git a/kernel/src/los_event.c b/kernel/src/los_event.c index 26cae5d5..d2e5520c 100644 --- a/kernel/src/los_event.c +++ b/kernel/src/los_event.c @@ -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) diff --git a/kernel/src/los_mux.c b/kernel/src/los_mux.c index c3bce4bd..4f3f5923 100644 --- a/kernel/src/los_mux.c +++ b/kernel/src/los_mux.c @@ -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) { diff --git a/kernel/src/los_queue.c b/kernel/src/los_queue.c index e0d873a3..863d0a22 100644 --- a/kernel/src/los_queue.c +++ b/kernel/src/los_queue.c @@ -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)) { diff --git a/kernel/src/los_sched.c b/kernel/src/los_sched.c index 3e27e99b..a7616fda 100644 --- a/kernel/src/los_sched.c +++ b/kernel/src/los_sched.c @@ -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 diff --git a/kernel/src/los_sem.c b/kernel/src/los_sem.c index fbecace5..fdf8f52d 100644 --- a/kernel/src/los_sem.c +++ b/kernel/src/los_sem.c @@ -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) */ - diff --git a/kernel/src/los_task.c b/kernel/src/los_task.c index b9bd1c8f..b1c2f76a 100644 --- a/kernel/src/los_task.c +++ b/kernel/src/los_task.c @@ -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; diff --git a/kernel/src/mm/los_memory.c b/kernel/src/mm/los_memory.c index 7520ffc5..911ac6ee 100644 --- a/kernel/src/mm/los_memory.c +++ b/kernel/src/mm/los_memory.c @@ -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; } diff --git a/targets/cortex-m3_stm32f103_simulator_keil/main.c b/targets/cortex-m3_stm32f103_simulator_keil/main.c deleted file mode 100644 index 2fa9f0a4..00000000 --- a/targets/cortex-m3_stm32f103_simulator_keil/main.c +++ /dev/null @@ -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"); - } -} - diff --git a/targets/cortex-m3_stm32f103_simulator_keil/target_config.h b/targets/cortex-m3_stm32f103_simulator_keil/target_config.h deleted file mode 100644 index 2bf78843..00000000 --- a/targets/cortex-m3_stm32f103_simulator_keil/target_config.h +++ /dev/null @@ -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 */ diff --git a/targets/cortex-m4_stm32f429ig_fire-challenger_iar/dprintf.c b/targets/cortex-m4_stm32f429ig_fire-challenger_iar/dprintf.c deleted file mode 100644 index 5f505fbd..00000000 --- a/targets/cortex-m4_stm32f429ig_fire-challenger_iar/dprintf.c +++ /dev/null @@ -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 -#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; -} diff --git a/targets/cortex-m4_stm32f429ig_fire-challenger_iar/main.c b/targets/cortex-m4_stm32f429ig_fire-challenger_iar/main.c deleted file mode 100644 index f5a9daff..00000000 --- a/targets/cortex-m4_stm32f429ig_fire-challenger_iar/main.c +++ /dev/null @@ -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"); - } -} - diff --git a/targets/cortex-m4_stm32f429ig_fire-challenger_iar/target_config.h b/targets/cortex-m4_stm32f429ig_fire-challenger_iar/target_config.h deleted file mode 100644 index 5302b43b..00000000 --- a/targets/cortex-m4_stm32f429ig_fire-challenger_iar/target_config.h +++ /dev/null @@ -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 */ diff --git a/targets/cortex-m7_nucleo_f767zi_gcc/Makefile b/targets/cortex-m7_nucleo_f767zi_gcc/Makefile deleted file mode 100644 index fd624e96..00000000 --- a/targets/cortex-m7_nucleo_f767zi_gcc/Makefile +++ /dev/null @@ -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 *** diff --git a/targets/cortex-m7_nucleo_f767zi_gcc/liteos_m.mk b/targets/cortex-m7_nucleo_f767zi_gcc/liteos_m.mk deleted file mode 100644 index c39aa8e4..00000000 --- a/targets/cortex-m7_nucleo_f767zi_gcc/liteos_m.mk +++ /dev/null @@ -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 $@ diff --git a/targets/cortex-m7_nucleo_f767zi_gcc/target_config.h b/targets/cortex-m7_nucleo_f767zi_gcc/target_config.h deleted file mode 100644 index f81cf09a..00000000 --- a/targets/cortex-m7_nucleo_f767zi_gcc/target_config.h +++ /dev/null @@ -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 */ diff --git a/targets/riscv_nuclei_demo_soc_gcc/Src/task_sample.c b/targets/riscv_nuclei_demo_soc_gcc/Src/task_sample.c index f098dfe2..5301c542 100644 --- a/targets/riscv_nuclei_demo_soc_gcc/Src/task_sample.c +++ b/targets/riscv_nuclei_demo_soc_gcc/Src/task_sample.c @@ -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 */ diff --git a/targets/riscv_nuclei_demo_soc_gcc/Src/task_sample.h b/targets/riscv_nuclei_demo_soc_gcc/Src/task_sample.h index adcb79b5..a42f8ea2 100644 --- a/targets/riscv_nuclei_demo_soc_gcc/Src/task_sample.h +++ b/targets/riscv_nuclei_demo_soc_gcc/Src/task_sample.h @@ -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 */ diff --git a/targets/riscv_nuclei_gd32vf103_soc_gcc/SoC/gd32vf103/Common/Include/Usb/drv_usb_dev.h b/targets/riscv_nuclei_gd32vf103_soc_gcc/SoC/gd32vf103/Common/Include/Usb/drv_usb_dev.h index 9750dbea..878e8f90 100644 --- a/targets/riscv_nuclei_gd32vf103_soc_gcc/SoC/gd32vf103/Common/Include/Usb/drv_usb_dev.h +++ b/targets/riscv_nuclei_gd32vf103_soc_gcc/SoC/gd32vf103/Common/Include/Usb/drv_usb_dev.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; diff --git a/targets/riscv_nuclei_gd32vf103_soc_gcc/SoC/gd32vf103/Common/Include/gd32vf103_timer.h b/targets/riscv_nuclei_gd32vf103_soc_gcc/SoC/gd32vf103/Common/Include/gd32vf103_timer.h index c76474ae..9f05123e 100644 --- a/targets/riscv_nuclei_gd32vf103_soc_gcc/SoC/gd32vf103/Common/Include/gd32vf103_timer.h +++ b/targets/riscv_nuclei_gd32vf103_soc_gcc/SoC/gd32vf103/Common/Include/gd32vf103_timer.h @@ -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); diff --git a/targets/riscv_nuclei_gd32vf103_soc_gcc/SoC/gd32vf103/Common/Source/Drivers/gd32vf103_timer.c b/targets/riscv_nuclei_gd32vf103_soc_gcc/SoC/gd32vf103/Common/Source/Drivers/gd32vf103_timer.c index dd53c24b..8259cb87 100644 --- a/targets/riscv_nuclei_gd32vf103_soc_gcc/SoC/gd32vf103/Common/Source/Drivers/gd32vf103_timer.c +++ b/targets/riscv_nuclei_gd32vf103_soc_gcc/SoC/gd32vf103/Common/Source/Drivers/gd32vf103_timer.c @@ -469,16 +469,16 @@ void timer_channel_dma_request_source_select(uint32_t timer_periph, uint32_t dma \arg TIMER_DMACFG_DMATA_CH3CV: DMA transfer address is TIMER_CH3CV, TIMERx(x=0..4) \arg TIMER_DMACFG_DMATA_CCHP: DMA transfer address is TIMER_CCHP, TIMERx(x=0) \arg TIMER_DMACFG_DMATA_DMACFG: DMA transfer address is TIMER_DMACFG, TIMERx(x=0..4) - \param[in] dma_lenth: + \param[in] dma_length: only one parameter can be selected which is shown as below: \arg TIMER_DMACFG_DMATC_xTRANSFER(x=1..6): DMA transfer x time \param[out] none \retval none */ -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) { TIMER_DMACFG(timer_periph) &= (~(uint32_t)(TIMER_DMACFG_DMATA | TIMER_DMACFG_DMATC)); - TIMER_DMACFG(timer_periph) |= (uint32_t)(dma_baseaddr | dma_lenth); + TIMER_DMACFG(timer_periph) |= (uint32_t)(dma_baseaddr | dma_length); } /*! diff --git a/targets/riscv_nuclei_gd32vf103_soc_gcc/Src/task_sample.c b/targets/riscv_nuclei_gd32vf103_soc_gcc/Src/task_sample.c index bb9fca31..f2164010 100644 --- a/targets/riscv_nuclei_gd32vf103_soc_gcc/Src/task_sample.c +++ b/targets/riscv_nuclei_gd32vf103_soc_gcc/Src/task_sample.c @@ -44,8 +44,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]; @@ -117,5 +117,5 @@ VOID RunTaskSample(VOID) #ifdef __cplusplus #if __cplusplus } -#endif /* __cpluscplus */ -#endif /* __cpluscplus */ +#endif /* __cplusplus */ +#endif /* __cplusplus */ diff --git a/targets/riscv_nuclei_gd32vf103_soc_gcc/Src/task_sample.h b/targets/riscv_nuclei_gd32vf103_soc_gcc/Src/task_sample.h index adcb79b5..a42f8ea2 100644 --- a/targets/riscv_nuclei_gd32vf103_soc_gcc/Src/task_sample.h +++ b/targets/riscv_nuclei_gd32vf103_soc_gcc/Src/task_sample.h @@ -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 */ diff --git a/testsuits/sample/kernel/queue/It_los_queue.h b/testsuits/sample/kernel/queue/It_los_queue.h index 48d3d5da..3e2d9fb0 100644 --- a/testsuits/sample/kernel/queue/It_los_queue.h +++ b/testsuits/sample/kernel/queue/It_los_queue.h @@ -38,8 +38,8 @@ extern "C" { #endif /* __cplusplus */ #endif /* __cplusplus */ -#define QUEUE_SHORT_BUFFER_LENTH 12 -#define QUEUE_STANDARD_BUFFER_LENTH 50 +#define QUEUE_SHORT_BUFFER_LENGTH 12 +#define QUEUE_STANDARD_BUFFER_LENGTH 50 #define QUEUE_BASE_NUM 3 #define QUEUE_BASE_MSGSIZE 8 diff --git a/testsuits/sample/kernel/queue/It_los_queue_001.c b/testsuits/sample/kernel/queue/It_los_queue_001.c index 7213f759..75a9d4bc 100644 --- a/testsuits/sample/kernel/queue/It_los_queue_001.c +++ b/testsuits/sample/kernel/queue/It_los_queue_001.c @@ -36,8 +36,8 @@ static UINT32 Testcase(VOID) { UINT32 ret; - CHAR buff1[QUEUE_SHORT_BUFFER_LENTH] = "UniDSP"; - CHAR buff2[QUEUE_SHORT_BUFFER_LENTH] = ""; + CHAR buff1[QUEUE_SHORT_BUFFER_LENGTH] = "UniDSP"; + CHAR buff2[QUEUE_SHORT_BUFFER_LENGTH] = ""; ret = LOS_QueueCreate("Q1", QUEUE_BASE_NUM, &g_testQueueID01, 0, QUEUE_BASE_MSGSIZE); ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT); diff --git a/testsuits/sample/kernel/queue/It_los_queue_002.c b/testsuits/sample/kernel/queue/It_los_queue_002.c index 9f1d1f24..77693075 100644 --- a/testsuits/sample/kernel/queue/It_los_queue_002.c +++ b/testsuits/sample/kernel/queue/It_los_queue_002.c @@ -35,8 +35,8 @@ static UINT32 Testcase(VOID) { UINT32 ret; - CHAR buff1[QUEUE_SHORT_BUFFER_LENTH] = "UniDSP"; - CHAR buff2[QUEUE_SHORT_BUFFER_LENTH] = ""; + CHAR buff1[QUEUE_SHORT_BUFFER_LENGTH] = "UniDSP"; + CHAR buff2[QUEUE_SHORT_BUFFER_LENGTH] = ""; g_testQueueID01 = 1025; // 1025, is a invalid value diff --git a/testsuits/sample/kernel/queue/It_los_queue_003.c b/testsuits/sample/kernel/queue/It_los_queue_003.c index f81bd0e9..3a3fe432 100644 --- a/testsuits/sample/kernel/queue/It_los_queue_003.c +++ b/testsuits/sample/kernel/queue/It_los_queue_003.c @@ -35,8 +35,8 @@ static UINT32 Testcase(VOID) { UINT32 ret; - CHAR buff1[QUEUE_SHORT_BUFFER_LENTH] = "UniDSP"; - CHAR buff2[QUEUE_SHORT_BUFFER_LENTH] = ""; + CHAR buff1[QUEUE_SHORT_BUFFER_LENGTH] = "UniDSP"; + CHAR buff2[QUEUE_SHORT_BUFFER_LENGTH] = ""; ret = LOS_QueueCreate("Q1", QUEUE_BASE_NUM, &g_testQueueID01, 0, 1); ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT); diff --git a/testsuits/sample/kernel/queue/It_los_queue_004.c b/testsuits/sample/kernel/queue/It_los_queue_004.c index 1fd8fce3..2e984e8d 100644 --- a/testsuits/sample/kernel/queue/It_los_queue_004.c +++ b/testsuits/sample/kernel/queue/It_los_queue_004.c @@ -35,8 +35,8 @@ static UINT32 Testcase(VOID) { UINT32 ret; - CHAR buff1[QUEUE_SHORT_BUFFER_LENTH] = "UniDSP"; - CHAR buff2[QUEUE_SHORT_BUFFER_LENTH] = ""; + CHAR buff1[QUEUE_SHORT_BUFFER_LENGTH] = "UniDSP"; + CHAR buff2[QUEUE_SHORT_BUFFER_LENGTH] = ""; g_testQueueID01 = LOSCFG_BASE_IPC_QUEUE_LIMIT - 1; diff --git a/testsuits/sample/kernel/queue/It_los_queue_005.c b/testsuits/sample/kernel/queue/It_los_queue_005.c index aa17537a..eef96ecb 100644 --- a/testsuits/sample/kernel/queue/It_los_queue_005.c +++ b/testsuits/sample/kernel/queue/It_los_queue_005.c @@ -36,8 +36,8 @@ static UINT32 Testcase(VOID) { UINT32 ret; - CHAR buff1[QUEUE_SHORT_BUFFER_LENTH] = "UniDSP"; - CHAR buff2[QUEUE_SHORT_BUFFER_LENTH] = ""; + CHAR buff1[QUEUE_SHORT_BUFFER_LENGTH] = "UniDSP"; + CHAR buff2[QUEUE_SHORT_BUFFER_LENGTH] = ""; g_testQueueID01 = LOSCFG_BASE_IPC_QUEUE_LIMIT - 1; diff --git a/testsuits/sample/kernel/queue/It_los_queue_006.c b/testsuits/sample/kernel/queue/It_los_queue_006.c index 2df9deb4..15497d84 100644 --- a/testsuits/sample/kernel/queue/It_los_queue_006.c +++ b/testsuits/sample/kernel/queue/It_los_queue_006.c @@ -36,8 +36,8 @@ static UINT32 Testcase(VOID) { UINT32 ret; - CHAR buff1[QUEUE_SHORT_BUFFER_LENTH] = "UniDSP"; - CHAR buff2[QUEUE_SHORT_BUFFER_LENTH] = ""; + CHAR buff1[QUEUE_SHORT_BUFFER_LENGTH] = "UniDSP"; + CHAR buff2[QUEUE_SHORT_BUFFER_LENGTH] = ""; g_testQueueID01 = 1025; // 1025, to set a invalid values diff --git a/testsuits/sample/kernel/queue/It_los_queue_007.c b/testsuits/sample/kernel/queue/It_los_queue_007.c index 8001d5a3..52ba03a9 100644 --- a/testsuits/sample/kernel/queue/It_los_queue_007.c +++ b/testsuits/sample/kernel/queue/It_los_queue_007.c @@ -36,8 +36,8 @@ static UINT32 Testcase(VOID) { UINT32 ret; - CHAR buff1[QUEUE_SHORT_BUFFER_LENTH] = "UniDSP"; - CHAR buff2[QUEUE_SHORT_BUFFER_LENTH] = ""; + CHAR buff1[QUEUE_SHORT_BUFFER_LENGTH] = "UniDSP"; + CHAR buff2[QUEUE_SHORT_BUFFER_LENGTH] = ""; g_testQueueID01 = 1025; // 1025, to set a invalid values diff --git a/testsuits/sample/kernel/queue/It_los_queue_008.c b/testsuits/sample/kernel/queue/It_los_queue_008.c index 347e13de..ff698483 100644 --- a/testsuits/sample/kernel/queue/It_los_queue_008.c +++ b/testsuits/sample/kernel/queue/It_los_queue_008.c @@ -36,8 +36,8 @@ static UINT32 Testcase(VOID) { UINT32 ret; - CHAR buff1[QUEUE_SHORT_BUFFER_LENTH] = "UniDSP"; - CHAR buff2[QUEUE_SHORT_BUFFER_LENTH] = ""; + CHAR buff1[QUEUE_SHORT_BUFFER_LENGTH] = "UniDSP"; + CHAR buff2[QUEUE_SHORT_BUFFER_LENGTH] = ""; ret = LOS_QueueCreate("Q1", 1, &g_testQueueID01, 0, QUEUE_BASE_MSGSIZE); ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT); diff --git a/testsuits/sample/kernel/queue/It_los_queue_009.c b/testsuits/sample/kernel/queue/It_los_queue_009.c index 34fe3f47..2b7e1026 100644 --- a/testsuits/sample/kernel/queue/It_los_queue_009.c +++ b/testsuits/sample/kernel/queue/It_los_queue_009.c @@ -36,8 +36,8 @@ static UINT32 Testcase(VOID) { UINT32 ret; - CHAR buff1[QUEUE_SHORT_BUFFER_LENTH] = "UniDSP"; - CHAR buff2[QUEUE_SHORT_BUFFER_LENTH] = ""; + CHAR buff1[QUEUE_SHORT_BUFFER_LENGTH] = "UniDSP"; + CHAR buff2[QUEUE_SHORT_BUFFER_LENGTH] = ""; g_testQueueID01 = 1025; // 1025, to set a invalid values diff --git a/testsuits/sample/kernel/queue/It_los_queue_010.c b/testsuits/sample/kernel/queue/It_los_queue_010.c index ff0b550d..ac3988a0 100644 --- a/testsuits/sample/kernel/queue/It_los_queue_010.c +++ b/testsuits/sample/kernel/queue/It_los_queue_010.c @@ -35,8 +35,8 @@ static UINT32 Testcase(VOID) { UINT32 ret; - CHAR buff1[QUEUE_SHORT_BUFFER_LENTH] = "UniDSP"; - CHAR buff2[QUEUE_SHORT_BUFFER_LENTH] = ""; + CHAR buff1[QUEUE_SHORT_BUFFER_LENGTH] = "UniDSP"; + CHAR buff2[QUEUE_SHORT_BUFFER_LENGTH] = ""; g_testQueueID01 = LOSCFG_BASE_IPC_QUEUE_LIMIT - 1; diff --git a/testsuits/sample/kernel/queue/It_los_queue_011.c b/testsuits/sample/kernel/queue/It_los_queue_011.c index b4f2d0fb..a677a908 100644 --- a/testsuits/sample/kernel/queue/It_los_queue_011.c +++ b/testsuits/sample/kernel/queue/It_los_queue_011.c @@ -36,8 +36,8 @@ static UINT32 Testcase(VOID) { UINT32 ret; - CHAR buff1[QUEUE_SHORT_BUFFER_LENTH] = "UniDSP"; - CHAR buff2[QUEUE_SHORT_BUFFER_LENTH] = ""; + CHAR buff1[QUEUE_SHORT_BUFFER_LENGTH] = "UniDSP"; + CHAR buff2[QUEUE_SHORT_BUFFER_LENGTH] = ""; ret = LOS_QueueCreate("Q1", QUEUE_BASE_NUM, &g_testQueueID01, 0, QUEUE_BASE_MSGSIZE); ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT); diff --git a/testsuits/sample/kernel/queue/It_los_queue_015.c b/testsuits/sample/kernel/queue/It_los_queue_015.c index 5ae518a1..c846dc3d 100644 --- a/testsuits/sample/kernel/queue/It_los_queue_015.c +++ b/testsuits/sample/kernel/queue/It_los_queue_015.c @@ -36,7 +36,7 @@ static UINT32 Testcase(VOID) { UINT32 ret; - CHAR buff1[QUEUE_SHORT_BUFFER_LENTH] = "UniDSP"; + CHAR buff1[QUEUE_SHORT_BUFFER_LENGTH] = "UniDSP"; CHAR buff2[9] = ""; // 9, QUEUE_BASE_MSGSIZE + 1 ret = LOS_QueueCreate("Q1", QUEUE_BASE_NUM, &g_testQueueID01, 0, QUEUE_BASE_MSGSIZE); diff --git a/testsuits/sample/kernel/queue/It_los_queue_017.c b/testsuits/sample/kernel/queue/It_los_queue_017.c index ec52fa88..7697885f 100644 --- a/testsuits/sample/kernel/queue/It_los_queue_017.c +++ b/testsuits/sample/kernel/queue/It_los_queue_017.c @@ -36,7 +36,7 @@ static UINT32 Testcase(VOID) { UINT32 ret; - CHAR buff1[QUEUE_SHORT_BUFFER_LENTH] = "UniDSP"; + CHAR buff1[QUEUE_SHORT_BUFFER_LENGTH] = "UniDSP"; ret = LOS_QueueCreate("Q1", QUEUE_BASE_NUM, &g_testQueueID01, 0, QUEUE_BASE_MSGSIZE); ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT); diff --git a/testsuits/sample/kernel/queue/It_los_queue_018.c b/testsuits/sample/kernel/queue/It_los_queue_018.c index d7749115..89873bfa 100644 --- a/testsuits/sample/kernel/queue/It_los_queue_018.c +++ b/testsuits/sample/kernel/queue/It_los_queue_018.c @@ -35,8 +35,8 @@ static UINT32 Testcase(VOID) { UINT32 ret; - CHAR buff1[QUEUE_SHORT_BUFFER_LENTH] = "UniDSP"; - CHAR buff2[QUEUE_SHORT_BUFFER_LENTH] = ""; + CHAR buff1[QUEUE_SHORT_BUFFER_LENGTH] = "UniDSP"; + CHAR buff2[QUEUE_SHORT_BUFFER_LENGTH] = ""; ret = LOS_QueueCreate("Q1", QUEUE_BASE_NUM, &g_testQueueID01, 0, QUEUE_BASE_MSGSIZE); ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT); diff --git a/testsuits/sample/kernel/queue/It_los_queue_019.c b/testsuits/sample/kernel/queue/It_los_queue_019.c index df774b6c..7e553275 100644 --- a/testsuits/sample/kernel/queue/It_los_queue_019.c +++ b/testsuits/sample/kernel/queue/It_los_queue_019.c @@ -35,8 +35,8 @@ static UINT32 Testcase(VOID) { UINT32 ret; - CHAR buff1[QUEUE_SHORT_BUFFER_LENTH] = "UniDSP"; - CHAR buff2[QUEUE_SHORT_BUFFER_LENTH] = ""; + CHAR buff1[QUEUE_SHORT_BUFFER_LENGTH] = "UniDSP"; + CHAR buff2[QUEUE_SHORT_BUFFER_LENGTH] = ""; ret = LOS_QueueCreate("Q1", QUEUE_BASE_NUM, &g_testQueueID01, 0, QUEUE_BASE_MSGSIZE); ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT); diff --git a/testsuits/sample/kernel/queue/It_los_queue_020.c b/testsuits/sample/kernel/queue/It_los_queue_020.c index 45b68171..178ed3df 100644 --- a/testsuits/sample/kernel/queue/It_los_queue_020.c +++ b/testsuits/sample/kernel/queue/It_los_queue_020.c @@ -35,8 +35,8 @@ static UINT32 Testcase(VOID) { UINT32 ret; - CHAR buff1[QUEUE_SHORT_BUFFER_LENTH] = "UniDSP"; - CHAR buff2[QUEUE_SHORT_BUFFER_LENTH] = ""; + CHAR buff1[QUEUE_SHORT_BUFFER_LENGTH] = "UniDSP"; + CHAR buff2[QUEUE_SHORT_BUFFER_LENGTH] = ""; ret = LOS_QueueCreate("Q1", QUEUE_BASE_NUM, &g_testQueueID01, 0, QUEUE_BASE_MSGSIZE); ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT); diff --git a/testsuits/sample/kernel/queue/It_los_queue_021.c b/testsuits/sample/kernel/queue/It_los_queue_021.c index c105aa40..b520bc2e 100644 --- a/testsuits/sample/kernel/queue/It_los_queue_021.c +++ b/testsuits/sample/kernel/queue/It_los_queue_021.c @@ -37,8 +37,8 @@ static UINT32 Testcase(VOID) UINT32 ret; UINT32 index; UINT32 queueID[LOSCFG_BASE_IPC_QUEUE_LIMIT + 1]; - CHAR buff1[QUEUE_SHORT_BUFFER_LENTH] = "UniDSP"; - CHAR buff2[QUEUE_SHORT_BUFFER_LENTH] = ""; + CHAR buff1[QUEUE_SHORT_BUFFER_LENGTH] = "UniDSP"; + CHAR buff2[QUEUE_SHORT_BUFFER_LENGTH] = ""; for (index = 0; index < LOSCFG_BASE_IPC_QUEUE_LIMIT - QUEUE_EXISTED_NUM; index++) { ret = LOS_QueueCreate(NULL, QUEUE_BASE_NUM, &queueID[index], 0, QUEUE_BASE_MSGSIZE); diff --git a/testsuits/sample/kernel/queue/It_los_queue_022.c b/testsuits/sample/kernel/queue/It_los_queue_022.c index d55f70f3..6c04cd17 100644 --- a/testsuits/sample/kernel/queue/It_los_queue_022.c +++ b/testsuits/sample/kernel/queue/It_los_queue_022.c @@ -37,8 +37,8 @@ static UINT32 Testcase(VOID) UINT32 ret; UINT32 index; UINT32 queueID[LOSCFG_BASE_IPC_QUEUE_LIMIT + 1]; - CHAR buff1[QUEUE_SHORT_BUFFER_LENTH] = "UniDSP"; - CHAR buff2[QUEUE_SHORT_BUFFER_LENTH] = ""; + CHAR buff1[QUEUE_SHORT_BUFFER_LENGTH] = "UniDSP"; + CHAR buff2[QUEUE_SHORT_BUFFER_LENGTH] = ""; for (index = 0; index < LOSCFG_BASE_IPC_QUEUE_LIMIT - QUEUE_EXISTED_NUM; index++) { ret = LOS_QueueCreate(NULL, QUEUE_BASE_NUM, &queueID[index], 0, QUEUE_BASE_MSGSIZE); diff --git a/testsuits/sample/kernel/queue/It_los_queue_026.c b/testsuits/sample/kernel/queue/It_los_queue_026.c index d61e7b7f..fd6b4f1f 100644 --- a/testsuits/sample/kernel/queue/It_los_queue_026.c +++ b/testsuits/sample/kernel/queue/It_los_queue_026.c @@ -35,7 +35,7 @@ static UINT32 Testcase(VOID) { UINT32 ret; - CHAR buff2[QUEUE_SHORT_BUFFER_LENTH] = ""; + CHAR buff2[QUEUE_SHORT_BUFFER_LENGTH] = ""; ret = LOS_QueueCreate("Q1", QUEUE_BASE_NUM, &g_testQueueID01, 0, QUEUE_BASE_MSGSIZE); ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT); diff --git a/testsuits/sample/kernel/queue/It_los_queue_027.c b/testsuits/sample/kernel/queue/It_los_queue_027.c index dac175ab..0275cb00 100644 --- a/testsuits/sample/kernel/queue/It_los_queue_027.c +++ b/testsuits/sample/kernel/queue/It_los_queue_027.c @@ -36,8 +36,8 @@ static UINT32 Testcase(VOID) { UINT32 ret; - CHAR buff1[QUEUE_SHORT_BUFFER_LENTH] = "UniDSP"; - CHAR buff2[QUEUE_SHORT_BUFFER_LENTH] = ""; + CHAR buff1[QUEUE_SHORT_BUFFER_LENGTH] = "UniDSP"; + CHAR buff2[QUEUE_SHORT_BUFFER_LENGTH] = ""; ret = LOS_QueueCreate("Q1", QUEUE_BASE_NUM, &g_testQueueID01, 0, QUEUE_BASE_MSGSIZE); ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT); diff --git a/testsuits/sample/kernel/queue/It_los_queue_028.c b/testsuits/sample/kernel/queue/It_los_queue_028.c index 64d61d44..a2284df5 100644 --- a/testsuits/sample/kernel/queue/It_los_queue_028.c +++ b/testsuits/sample/kernel/queue/It_los_queue_028.c @@ -35,8 +35,8 @@ static UINT32 Testcase(VOID) { UINT32 ret; - CHAR buff1[QUEUE_SHORT_BUFFER_LENTH] = "UniDSP"; - CHAR buff2[QUEUE_SHORT_BUFFER_LENTH] = ""; + CHAR buff1[QUEUE_SHORT_BUFFER_LENGTH] = "UniDSP"; + CHAR buff2[QUEUE_SHORT_BUFFER_LENGTH] = ""; // 2, is a Invalid queueID for test erro code LOS_ERRNO_QUEUE_NOT_CREATE ret = LOS_QueueWrite(2, &buff1, QUEUE_BASE_MSGSIZE, 0); diff --git a/testsuits/sample/kernel/queue/It_los_queue_029.c b/testsuits/sample/kernel/queue/It_los_queue_029.c index 010d75a3..d660c80f 100644 --- a/testsuits/sample/kernel/queue/It_los_queue_029.c +++ b/testsuits/sample/kernel/queue/It_los_queue_029.c @@ -35,8 +35,8 @@ static UINT32 Testcase(VOID) { UINT32 ret; - CHAR buff1[QUEUE_SHORT_BUFFER_LENTH] = "UniDSP"; - CHAR buff2[QUEUE_SHORT_BUFFER_LENTH] = ""; + CHAR buff1[QUEUE_SHORT_BUFFER_LENGTH] = "UniDSP"; + CHAR buff2[QUEUE_SHORT_BUFFER_LENGTH] = ""; ret = LOS_QueueCreate("Q1", QUEUE_BASE_NUM, &g_testQueueID01, 0, QUEUE_BASE_MSGSIZE); ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT); diff --git a/testsuits/sample/kernel/queue/It_los_queue_030.c b/testsuits/sample/kernel/queue/It_los_queue_030.c index f8a8a0d8..e0f7faa4 100644 --- a/testsuits/sample/kernel/queue/It_los_queue_030.c +++ b/testsuits/sample/kernel/queue/It_los_queue_030.c @@ -37,8 +37,8 @@ static UINT32 Testcase(VOID) UINT32 ret; UINT32 index; UINT32 queueID[LOSCFG_BASE_IPC_QUEUE_LIMIT + 1]; - CHAR buff1[QUEUE_SHORT_BUFFER_LENTH] = "UniDSP"; - CHAR buff2[QUEUE_SHORT_BUFFER_LENTH] = ""; + CHAR buff1[QUEUE_SHORT_BUFFER_LENGTH] = "UniDSP"; + CHAR buff2[QUEUE_SHORT_BUFFER_LENGTH] = ""; for (index = 0; index < LOSCFG_BASE_IPC_QUEUE_LIMIT - QUEUE_EXISTED_NUM; index++) { ret = LOS_QueueCreate(NULL, QUEUE_BASE_NUM, &queueID[index], 0, QUEUE_BASE_MSGSIZE); diff --git a/testsuits/sample/kernel/queue/It_los_queue_031.c b/testsuits/sample/kernel/queue/It_los_queue_031.c index 7f81065a..46ec8d0a 100644 --- a/testsuits/sample/kernel/queue/It_los_queue_031.c +++ b/testsuits/sample/kernel/queue/It_los_queue_031.c @@ -35,8 +35,8 @@ static UINT32 Testcase(VOID) { UINT32 ret; - CHAR buff1[QUEUE_SHORT_BUFFER_LENTH] = "UniDSP"; - CHAR buff2[QUEUE_SHORT_BUFFER_LENTH] = ""; + CHAR buff1[QUEUE_SHORT_BUFFER_LENGTH] = "UniDSP"; + CHAR buff2[QUEUE_SHORT_BUFFER_LENGTH] = ""; ret = LOS_QueueCreate("Q1", QUEUE_BASE_NUM, &g_testQueueID01, 0, QUEUE_BASE_MSGSIZE); ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT); diff --git a/testsuits/sample/kernel/queue/It_los_queue_032.c b/testsuits/sample/kernel/queue/It_los_queue_032.c index ad05eed5..e650ea55 100644 --- a/testsuits/sample/kernel/queue/It_los_queue_032.c +++ b/testsuits/sample/kernel/queue/It_los_queue_032.c @@ -35,8 +35,8 @@ static UINT32 Testcase(VOID) { UINT32 ret; - CHAR buff1[QUEUE_SHORT_BUFFER_LENTH] = "UniDSP"; - CHAR buff2[QUEUE_SHORT_BUFFER_LENTH] = "DOPRA"; + CHAR buff1[QUEUE_SHORT_BUFFER_LENGTH] = "UniDSP"; + CHAR buff2[QUEUE_SHORT_BUFFER_LENGTH] = "DOPRA"; ret = LOS_QueueCreate("Q1", QUEUE_BASE_NUM, &g_testQueueID01, 0, QUEUE_BASE_MSGSIZE); ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT); diff --git a/testsuits/sample/kernel/queue/It_los_queue_033.c b/testsuits/sample/kernel/queue/It_los_queue_033.c index 3cd14ef7..56f0b4a6 100644 --- a/testsuits/sample/kernel/queue/It_los_queue_033.c +++ b/testsuits/sample/kernel/queue/It_los_queue_033.c @@ -35,7 +35,7 @@ static UINT32 Testcase(VOID) { UINT32 ret; - CHAR buff1[QUEUE_SHORT_BUFFER_LENTH]; + CHAR buff1[QUEUE_SHORT_BUFFER_LENGTH]; ret = LOS_QueueCreate("Q1", QUEUE_BASE_NUM, &g_testQueueID01, 0, QUEUE_BASE_MSGSIZE); ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT); diff --git a/testsuits/sample/kernel/queue/It_los_queue_034.c b/testsuits/sample/kernel/queue/It_los_queue_034.c index f3a54f47..79f44437 100644 --- a/testsuits/sample/kernel/queue/It_los_queue_034.c +++ b/testsuits/sample/kernel/queue/It_los_queue_034.c @@ -37,7 +37,7 @@ static UINT32 Testcase(VOID) UINT32 ret; UINT32 index; UINT32 queueID[LOSCFG_BASE_IPC_QUEUE_LIMIT + 1]; - CHAR buff1[QUEUE_SHORT_BUFFER_LENTH] = "UniDSP"; + CHAR buff1[QUEUE_SHORT_BUFFER_LENGTH] = "UniDSP"; for (index = 0; index < LOSCFG_BASE_IPC_QUEUE_LIMIT - QUEUE_EXISTED_NUM; index++) { ret = LOS_QueueCreate(NULL, QUEUE_BASE_NUM, &queueID[index], 0, QUEUE_BASE_MSGSIZE); diff --git a/testsuits/sample/kernel/queue/It_los_queue_035.c b/testsuits/sample/kernel/queue/It_los_queue_035.c index 4e1573f3..9408b44d 100644 --- a/testsuits/sample/kernel/queue/It_los_queue_035.c +++ b/testsuits/sample/kernel/queue/It_los_queue_035.c @@ -36,8 +36,8 @@ static UINT32 Testcase(VOID) { UINT32 ret; UINT32 index; - CHAR buff1[QUEUE_SHORT_BUFFER_LENTH] = "UniDSP"; - CHAR buff2[QUEUE_SHORT_BUFFER_LENTH] = ""; + CHAR buff1[QUEUE_SHORT_BUFFER_LENGTH] = "UniDSP"; + CHAR buff2[QUEUE_SHORT_BUFFER_LENGTH] = ""; ret = LOS_QueueCreate("Q1", QUEUE_BASE_NUM, &g_testQueueID01, 0, QUEUE_BASE_MSGSIZE); ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT); diff --git a/testsuits/sample/kernel/queue/It_los_queue_036.c b/testsuits/sample/kernel/queue/It_los_queue_036.c index 08cdb8f5..ead4f181 100644 --- a/testsuits/sample/kernel/queue/It_los_queue_036.c +++ b/testsuits/sample/kernel/queue/It_los_queue_036.c @@ -36,7 +36,7 @@ static UINT32 Testcase(VOID) { UINT32 ret; UINT32 index; - CHAR buff1[QUEUE_SHORT_BUFFER_LENTH] = "UniDSP"; + CHAR buff1[QUEUE_SHORT_BUFFER_LENGTH] = "UniDSP"; ret = LOS_QueueCreate("Q1", QUEUE_BASE_NUM, &g_testQueueID01, 0, QUEUE_BASE_MSGSIZE); ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT); diff --git a/testsuits/sample/kernel/queue/It_los_queue_037.c b/testsuits/sample/kernel/queue/It_los_queue_037.c index d9768c0e..e9339424 100644 --- a/testsuits/sample/kernel/queue/It_los_queue_037.c +++ b/testsuits/sample/kernel/queue/It_los_queue_037.c @@ -36,8 +36,8 @@ static UINT32 Testcase(VOID) { UINT32 ret; UINT32 index; - CHAR buff1[QUEUE_SHORT_BUFFER_LENTH] = "UniDSP"; - CHAR buff2[QUEUE_SHORT_BUFFER_LENTH] = "DOPRA"; + CHAR buff1[QUEUE_SHORT_BUFFER_LENGTH] = "UniDSP"; + CHAR buff2[QUEUE_SHORT_BUFFER_LENGTH] = "DOPRA"; CHAR buff3[8] = "TEST"; INT32 buff4; INT32 buff5; diff --git a/testsuits/sample/kernel/queue/It_los_queue_038.c b/testsuits/sample/kernel/queue/It_los_queue_038.c index ab549ca0..a70dca69 100644 --- a/testsuits/sample/kernel/queue/It_los_queue_038.c +++ b/testsuits/sample/kernel/queue/It_los_queue_038.c @@ -36,8 +36,8 @@ static UINT32 Testcase(VOID) { UINT32 ret; UINT32 index; - CHAR buff1[QUEUE_SHORT_BUFFER_LENTH] = "UniDSP"; - CHAR buff2[QUEUE_SHORT_BUFFER_LENTH] = ""; + CHAR buff1[QUEUE_SHORT_BUFFER_LENGTH] = "UniDSP"; + CHAR buff2[QUEUE_SHORT_BUFFER_LENGTH] = ""; ret = LOS_QueueCreate("Q1", QUEUE_BASE_NUM, &g_testQueueID01, 0, QUEUE_BASE_MSGSIZE); ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT); diff --git a/testsuits/sample/kernel/queue/It_los_queue_039.c b/testsuits/sample/kernel/queue/It_los_queue_039.c index b18d0e9a..b21dc59c 100644 --- a/testsuits/sample/kernel/queue/It_los_queue_039.c +++ b/testsuits/sample/kernel/queue/It_los_queue_039.c @@ -36,7 +36,7 @@ static UINT32 Testcase(VOID) { UINT32 ret; UINT32 index; - CHAR buff1[QUEUE_SHORT_BUFFER_LENTH] = "UniDSP"; + CHAR buff1[QUEUE_SHORT_BUFFER_LENGTH] = "UniDSP"; ret = LOS_QueueCreate("Q1", QUEUE_BASE_NUM, &g_testQueueID01, 0, QUEUE_BASE_MSGSIZE); ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT); diff --git a/testsuits/sample/kernel/queue/It_los_queue_040.c b/testsuits/sample/kernel/queue/It_los_queue_040.c index 3b8945f9..6620c257 100644 --- a/testsuits/sample/kernel/queue/It_los_queue_040.c +++ b/testsuits/sample/kernel/queue/It_los_queue_040.c @@ -35,7 +35,7 @@ static VOID TaskF01(VOID) { UINT32 ret; - CHAR buff2[QUEUE_SHORT_BUFFER_LENTH] = ""; + CHAR buff2[QUEUE_SHORT_BUFFER_LENGTH] = ""; g_testCount++; diff --git a/testsuits/sample/kernel/queue/It_los_queue_041.c b/testsuits/sample/kernel/queue/It_los_queue_041.c index 7f6bfd4a..d212e441 100644 --- a/testsuits/sample/kernel/queue/It_los_queue_041.c +++ b/testsuits/sample/kernel/queue/It_los_queue_041.c @@ -35,7 +35,7 @@ static VOID TaskF01(VOID) { UINT32 ret; - CHAR buff2[QUEUE_SHORT_BUFFER_LENTH] = ""; + CHAR buff2[QUEUE_SHORT_BUFFER_LENGTH] = ""; g_testCount++; @@ -51,7 +51,7 @@ EXIT: static UINT32 Testcase(VOID) { UINT32 ret; - CHAR buff1[QUEUE_SHORT_BUFFER_LENTH] = "UniDSP"; + CHAR buff1[QUEUE_SHORT_BUFFER_LENGTH] = "UniDSP"; TSK_INIT_PARAM_S task1 = { 0 }; task1.pfnTaskEntry = (TSK_ENTRY_FUNC)TaskF01; diff --git a/testsuits/sample/kernel/queue/It_los_queue_042.c b/testsuits/sample/kernel/queue/It_los_queue_042.c index 8a7a3c76..98a08817 100644 --- a/testsuits/sample/kernel/queue/It_los_queue_042.c +++ b/testsuits/sample/kernel/queue/It_los_queue_042.c @@ -35,7 +35,7 @@ static VOID TaskF01(VOID) { UINT32 ret; - CHAR buff2[QUEUE_SHORT_BUFFER_LENTH] = ""; + CHAR buff2[QUEUE_SHORT_BUFFER_LENGTH] = ""; g_testCount++; @@ -51,7 +51,7 @@ EXIT: static VOID TaskF02(VOID) { UINT32 ret; - CHAR buff1[QUEUE_SHORT_BUFFER_LENTH] = "UniDSP"; + CHAR buff1[QUEUE_SHORT_BUFFER_LENGTH] = "UniDSP"; g_testCount++; diff --git a/testsuits/sample/kernel/queue/It_los_queue_043.c b/testsuits/sample/kernel/queue/It_los_queue_043.c index c64a5748..f40f0736 100644 --- a/testsuits/sample/kernel/queue/It_los_queue_043.c +++ b/testsuits/sample/kernel/queue/It_los_queue_043.c @@ -35,7 +35,7 @@ static VOID TaskF01(VOID) { UINT32 ret; - CHAR buff1[QUEUE_SHORT_BUFFER_LENTH] = "UniDSP"; + CHAR buff1[QUEUE_SHORT_BUFFER_LENGTH] = "UniDSP"; g_testCount++; ret = LOS_QueueWrite(g_testQueueID01, &buff1, QUEUE_BASE_MSGSIZE, 100); // 100, Set the timeout time @@ -50,7 +50,7 @@ EXIT: static VOID TaskF02(VOID) { UINT32 ret; - CHAR buff2[QUEUE_SHORT_BUFFER_LENTH] = ""; + CHAR buff2[QUEUE_SHORT_BUFFER_LENGTH] = ""; g_testCount++; diff --git a/testsuits/sample/kernel/queue/It_los_queue_044.c b/testsuits/sample/kernel/queue/It_los_queue_044.c index e1de841a..2d7703b5 100644 --- a/testsuits/sample/kernel/queue/It_los_queue_044.c +++ b/testsuits/sample/kernel/queue/It_los_queue_044.c @@ -35,7 +35,7 @@ static VOID HwiF01(VOID) { UINT32 ret; - CHAR buff2[QUEUE_SHORT_BUFFER_LENTH] = ""; + CHAR buff2[QUEUE_SHORT_BUFFER_LENGTH] = ""; TestHwiClear(HWI_NUM_TEST); @@ -52,7 +52,7 @@ EXIT: static UINT32 Testcase(VOID) { UINT32 ret; - CHAR buff1[QUEUE_SHORT_BUFFER_LENTH] = "UniDSP"; + CHAR buff1[QUEUE_SHORT_BUFFER_LENGTH] = "UniDSP"; g_testCount = 0; diff --git a/testsuits/sample/kernel/queue/It_los_queue_045.c b/testsuits/sample/kernel/queue/It_los_queue_045.c index 97cfcdff..23257c77 100644 --- a/testsuits/sample/kernel/queue/It_los_queue_045.c +++ b/testsuits/sample/kernel/queue/It_los_queue_045.c @@ -35,7 +35,7 @@ static VOID HwiF01(VOID) { UINT32 ret; - CHAR buff1[QUEUE_SHORT_BUFFER_LENTH] = "UniDSP"; + CHAR buff1[QUEUE_SHORT_BUFFER_LENGTH] = "UniDSP"; TestHwiClear(HWI_NUM_TEST); diff --git a/testsuits/sample/kernel/queue/It_los_queue_046.c b/testsuits/sample/kernel/queue/It_los_queue_046.c index 81378dfd..5663397d 100644 --- a/testsuits/sample/kernel/queue/It_los_queue_046.c +++ b/testsuits/sample/kernel/queue/It_los_queue_046.c @@ -35,7 +35,7 @@ static VOID HwiF01(VOID) { UINT32 ret; - CHAR buff1[QUEUE_SHORT_BUFFER_LENTH] = "UniDSP"; + CHAR buff1[QUEUE_SHORT_BUFFER_LENGTH] = "UniDSP"; TestHwiClear(HWI_NUM_TEST); @@ -53,7 +53,7 @@ static VOID HwiF01(VOID) static VOID HwiF02(VOID) { UINT32 ret; - CHAR buff2[QUEUE_SHORT_BUFFER_LENTH] = ""; + CHAR buff2[QUEUE_SHORT_BUFFER_LENGTH] = ""; TestHwiClear(HWI_NUM_TEST3); diff --git a/testsuits/sample/kernel/queue/It_los_queue_047.c b/testsuits/sample/kernel/queue/It_los_queue_047.c index 6af0ac4b..ef0aeaee 100644 --- a/testsuits/sample/kernel/queue/It_los_queue_047.c +++ b/testsuits/sample/kernel/queue/It_los_queue_047.c @@ -35,7 +35,7 @@ static VOID TaskF01(VOID) { UINT32 ret; - CHAR buff1[QUEUE_SHORT_BUFFER_LENTH] = "UniDSP"; + CHAR buff1[QUEUE_SHORT_BUFFER_LENGTH] = "UniDSP"; g_testCount++; @@ -54,7 +54,7 @@ EXIT: static VOID HwiF01(VOID) { UINT32 ret; - CHAR buff2[QUEUE_SHORT_BUFFER_LENTH] = ""; + CHAR buff2[QUEUE_SHORT_BUFFER_LENGTH] = ""; TestHwiClear(HWI_NUM_TEST); diff --git a/testsuits/sample/kernel/queue/It_los_queue_048.c b/testsuits/sample/kernel/queue/It_los_queue_048.c index 69915fa9..fe2ff96f 100644 --- a/testsuits/sample/kernel/queue/It_los_queue_048.c +++ b/testsuits/sample/kernel/queue/It_los_queue_048.c @@ -35,7 +35,7 @@ static VOID TaskF01(VOID) { UINT32 ret; - CHAR buff2[QUEUE_SHORT_BUFFER_LENTH] = ""; + CHAR buff2[QUEUE_SHORT_BUFFER_LENGTH] = ""; g_testCount++; @@ -52,7 +52,7 @@ EXIT: static VOID HwiF01(VOID) { UINT32 ret; - CHAR buff1[QUEUE_SHORT_BUFFER_LENTH] = "UniDSP"; + CHAR buff1[QUEUE_SHORT_BUFFER_LENGTH] = "UniDSP"; TestHwiClear(HWI_NUM_TEST); diff --git a/testsuits/sample/kernel/queue/It_los_queue_050.c b/testsuits/sample/kernel/queue/It_los_queue_050.c index c3aef542..e3a54e87 100644 --- a/testsuits/sample/kernel/queue/It_los_queue_050.c +++ b/testsuits/sample/kernel/queue/It_los_queue_050.c @@ -35,7 +35,7 @@ static VOID HwiF01(VOID) { UINT32 ret; - CHAR buff2[QUEUE_SHORT_BUFFER_LENTH]; + CHAR buff2[QUEUE_SHORT_BUFFER_LENGTH]; TestHwiClear(HWI_NUM_TEST); diff --git a/testsuits/sample/kernel/queue/It_los_queue_051.c b/testsuits/sample/kernel/queue/It_los_queue_051.c index e6a9ca68..df9fb6ba 100644 --- a/testsuits/sample/kernel/queue/It_los_queue_051.c +++ b/testsuits/sample/kernel/queue/It_los_queue_051.c @@ -35,7 +35,7 @@ static UINT32 Testcase(VOID) { UINT32 ret; - CHAR buff1[QUEUE_SHORT_BUFFER_LENTH] = "UniDSP"; + CHAR buff1[QUEUE_SHORT_BUFFER_LENGTH] = "UniDSP"; g_testCount = 0; diff --git a/testsuits/sample/kernel/queue/It_los_queue_052.c b/testsuits/sample/kernel/queue/It_los_queue_052.c index 20d61ef2..d3da5ad2 100644 --- a/testsuits/sample/kernel/queue/It_los_queue_052.c +++ b/testsuits/sample/kernel/queue/It_los_queue_052.c @@ -35,7 +35,7 @@ static UINT32 Testcase(VOID) { UINT32 ret; - CHAR buff1[QUEUE_SHORT_BUFFER_LENTH] = "UniDSP"; + CHAR buff1[QUEUE_SHORT_BUFFER_LENGTH] = "UniDSP"; g_testCount = 0; diff --git a/testsuits/sample/kernel/queue/It_los_queue_053.c b/testsuits/sample/kernel/queue/It_los_queue_053.c index c5567a35..fd95de3a 100644 --- a/testsuits/sample/kernel/queue/It_los_queue_053.c +++ b/testsuits/sample/kernel/queue/It_los_queue_053.c @@ -35,7 +35,7 @@ static VOID TaskF01(VOID) { UINT32 ret; - CHAR buff2[QUEUE_SHORT_BUFFER_LENTH]; + CHAR buff2[QUEUE_SHORT_BUFFER_LENGTH]; g_testCount++; @@ -56,7 +56,7 @@ EXIT: static UINT32 Testcase(VOID) { UINT32 ret; - CHAR buff1[QUEUE_SHORT_BUFFER_LENTH] = "UniDSP"; + CHAR buff1[QUEUE_SHORT_BUFFER_LENGTH] = "UniDSP"; TSK_INIT_PARAM_S task1 = { 0 }; task1.pfnTaskEntry = (TSK_ENTRY_FUNC)TaskF01; diff --git a/testsuits/sample/kernel/queue/It_los_queue_054.c b/testsuits/sample/kernel/queue/It_los_queue_054.c index 3ae88eb6..a5f4cc9b 100644 --- a/testsuits/sample/kernel/queue/It_los_queue_054.c +++ b/testsuits/sample/kernel/queue/It_los_queue_054.c @@ -35,8 +35,8 @@ static UINT32 Testcase(VOID) { UINT32 ret; - CHAR buff1[QUEUE_SHORT_BUFFER_LENTH] = "UniDSP"; - CHAR buff2[QUEUE_SHORT_BUFFER_LENTH]; + CHAR buff1[QUEUE_SHORT_BUFFER_LENGTH] = "UniDSP"; + CHAR buff2[QUEUE_SHORT_BUFFER_LENGTH]; g_testQueueID01 = 0; diff --git a/testsuits/sample/kernel/queue/It_los_queue_055.c b/testsuits/sample/kernel/queue/It_los_queue_055.c index 0cbf36c4..3d1f1b73 100644 --- a/testsuits/sample/kernel/queue/It_los_queue_055.c +++ b/testsuits/sample/kernel/queue/It_los_queue_055.c @@ -35,8 +35,8 @@ static UINT32 Testcase(VOID) { UINT32 ret; - CHAR buff1[QUEUE_SHORT_BUFFER_LENTH] = "UniDSP"; - CHAR buff2[QUEUE_SHORT_BUFFER_LENTH]; + CHAR buff1[QUEUE_SHORT_BUFFER_LENGTH] = "UniDSP"; + CHAR buff2[QUEUE_SHORT_BUFFER_LENGTH]; g_testQueueID01 = 0; diff --git a/testsuits/sample/kernel/queue/It_los_queue_056.c b/testsuits/sample/kernel/queue/It_los_queue_056.c index e8048b13..2d4caefa 100644 --- a/testsuits/sample/kernel/queue/It_los_queue_056.c +++ b/testsuits/sample/kernel/queue/It_los_queue_056.c @@ -35,8 +35,8 @@ static UINT32 Testcase(VOID) { UINT32 ret; - CHAR buff1[QUEUE_SHORT_BUFFER_LENTH] = "UniDSP"; - CHAR buff2[QUEUE_SHORT_BUFFER_LENTH]; + CHAR buff1[QUEUE_SHORT_BUFFER_LENGTH] = "UniDSP"; + CHAR buff2[QUEUE_SHORT_BUFFER_LENGTH]; g_testQueueID01 = 0; diff --git a/testsuits/sample/kernel/queue/It_los_queue_057.c b/testsuits/sample/kernel/queue/It_los_queue_057.c index 13630b16..7b92c0ca 100644 --- a/testsuits/sample/kernel/queue/It_los_queue_057.c +++ b/testsuits/sample/kernel/queue/It_los_queue_057.c @@ -36,8 +36,8 @@ static UINT32 Testcase(VOID) { UINT32 ret; UINT32 i = 0; - CHAR buff1[QUEUE_SHORT_BUFFER_LENTH] = "UniDSP"; - CHAR buff2[QUEUE_SHORT_BUFFER_LENTH]; + CHAR buff1[QUEUE_SHORT_BUFFER_LENGTH] = "UniDSP"; + CHAR buff2[QUEUE_SHORT_BUFFER_LENGTH]; char bufname[102] = {0}; // 102, max len. g_testQueueID01 = 0; diff --git a/testsuits/sample/kernel/queue/It_los_queue_058.c b/testsuits/sample/kernel/queue/It_los_queue_058.c index a0796c56..b024f61f 100644 --- a/testsuits/sample/kernel/queue/It_los_queue_058.c +++ b/testsuits/sample/kernel/queue/It_los_queue_058.c @@ -35,8 +35,8 @@ static UINT32 Testcase(VOID) { UINT32 ret; - CHAR buff1[QUEUE_SHORT_BUFFER_LENTH] = "UniDSP"; - CHAR buff2[QUEUE_SHORT_BUFFER_LENTH]; + CHAR buff1[QUEUE_SHORT_BUFFER_LENGTH] = "UniDSP"; + CHAR buff2[QUEUE_SHORT_BUFFER_LENGTH]; UINT32 maxMsgSize; g_testQueueID01 = LOSCFG_BASE_IPC_QUEUE_LIMIT - 1; diff --git a/testsuits/sample/kernel/queue/It_los_queue_059.c b/testsuits/sample/kernel/queue/It_los_queue_059.c index 7b983a7c..7762c112 100644 --- a/testsuits/sample/kernel/queue/It_los_queue_059.c +++ b/testsuits/sample/kernel/queue/It_los_queue_059.c @@ -35,8 +35,8 @@ static UINT32 Testcase(VOID) { UINT32 ret; - CHAR buff1[QUEUE_SHORT_BUFFER_LENTH] = "UniDSP"; - CHAR buff2[QUEUE_SHORT_BUFFER_LENTH]; + CHAR buff1[QUEUE_SHORT_BUFFER_LENGTH] = "UniDSP"; + CHAR buff2[QUEUE_SHORT_BUFFER_LENGTH]; g_testQueueID01 = 0; diff --git a/testsuits/sample/kernel/queue/It_los_queue_060.c b/testsuits/sample/kernel/queue/It_los_queue_060.c index 844ccf58..5251e524 100644 --- a/testsuits/sample/kernel/queue/It_los_queue_060.c +++ b/testsuits/sample/kernel/queue/It_los_queue_060.c @@ -37,8 +37,8 @@ static UINT32 Testcase(VOID) UINT32 ret; UINT32 index; - CHAR buff1[QUEUE_SHORT_BUFFER_LENTH] = "UniDSP"; - CHAR buff2[QUEUE_SHORT_BUFFER_LENTH] = "DOPRA"; + CHAR buff1[QUEUE_SHORT_BUFFER_LENGTH] = "UniDSP"; + CHAR buff2[QUEUE_SHORT_BUFFER_LENGTH] = "DOPRA"; CHAR buff3[8] = "TEST"; INT32 buff4; INT32 buff5; diff --git a/testsuits/sample/kernel/queue/It_los_queue_064.c b/testsuits/sample/kernel/queue/It_los_queue_064.c index 2fedb058..1b42b485 100644 --- a/testsuits/sample/kernel/queue/It_los_queue_064.c +++ b/testsuits/sample/kernel/queue/It_los_queue_064.c @@ -35,8 +35,8 @@ static UINT32 Testcase(VOID) { UINT32 ret, len1; - CHAR buff1[QUEUE_SHORT_BUFFER_LENTH] = "UniDSP"; - CHAR buff2[QUEUE_SHORT_BUFFER_LENTH]; + CHAR buff1[QUEUE_SHORT_BUFFER_LENGTH] = "UniDSP"; + CHAR buff2[QUEUE_SHORT_BUFFER_LENGTH]; g_testQueueID01 = 0xFF; len1 = 0xFFFF + 1; diff --git a/testsuits/sample/kernel/queue/It_los_queue_068.c b/testsuits/sample/kernel/queue/It_los_queue_068.c index f104f914..16cba6c1 100644 --- a/testsuits/sample/kernel/queue/It_los_queue_068.c +++ b/testsuits/sample/kernel/queue/It_los_queue_068.c @@ -35,7 +35,7 @@ static UINT32 Testcase(VOID) { UINT32 ret; - CHAR buff1[QUEUE_SHORT_BUFFER_LENTH] = "UniDSP"; + CHAR buff1[QUEUE_SHORT_BUFFER_LENGTH] = "UniDSP"; CHAR buff2[7]; g_testQueueID01 = 0xFF; diff --git a/testsuits/sample/kernel/queue/It_los_queue_069.c b/testsuits/sample/kernel/queue/It_los_queue_069.c index 0740344c..d23f4deb 100644 --- a/testsuits/sample/kernel/queue/It_los_queue_069.c +++ b/testsuits/sample/kernel/queue/It_los_queue_069.c @@ -35,7 +35,7 @@ static UINT32 Testcase(VOID) { UINT32 ret; - CHAR buff1[QUEUE_SHORT_BUFFER_LENTH] = "UniDSP"; + CHAR buff1[QUEUE_SHORT_BUFFER_LENGTH] = "UniDSP"; CHAR buff2[10]; g_testQueueID01 = 0xFF; diff --git a/testsuits/sample/kernel/queue/It_los_queue_070.c b/testsuits/sample/kernel/queue/It_los_queue_070.c index f9dec66a..eacc37ed 100644 --- a/testsuits/sample/kernel/queue/It_los_queue_070.c +++ b/testsuits/sample/kernel/queue/It_los_queue_070.c @@ -35,7 +35,7 @@ static UINT32 Testcase(VOID) { UINT32 ret; - CHAR buff1[QUEUE_SHORT_BUFFER_LENTH] = "UniDSP"; + CHAR buff1[QUEUE_SHORT_BUFFER_LENGTH] = "UniDSP"; CHAR buff2[10]; g_testQueueID01 = 0xFF; diff --git a/testsuits/sample/kernel/queue/It_los_queue_071.c b/testsuits/sample/kernel/queue/It_los_queue_071.c index e5935c11..0052e6b8 100644 --- a/testsuits/sample/kernel/queue/It_los_queue_071.c +++ b/testsuits/sample/kernel/queue/It_los_queue_071.c @@ -35,7 +35,7 @@ static UINT32 Testcase(VOID) { UINT32 ret; - CHAR buff1[QUEUE_SHORT_BUFFER_LENTH] = "UniDSP"; + CHAR buff1[QUEUE_SHORT_BUFFER_LENGTH] = "UniDSP"; CHAR buff2[10]; g_testQueueID01 = 0xFF; diff --git a/testsuits/sample/kernel/queue/It_los_queue_072.c b/testsuits/sample/kernel/queue/It_los_queue_072.c index 4973620f..9d36a2ea 100644 --- a/testsuits/sample/kernel/queue/It_los_queue_072.c +++ b/testsuits/sample/kernel/queue/It_los_queue_072.c @@ -35,7 +35,7 @@ static UINT32 Testcase(VOID) { UINT32 ret; - CHAR buff1[QUEUE_SHORT_BUFFER_LENTH] = "UniDSP"; + CHAR buff1[QUEUE_SHORT_BUFFER_LENGTH] = "UniDSP"; CHAR buff2[10]; g_testQueueID01 = 0xFF; diff --git a/testsuits/sample/kernel/queue/It_los_queue_074.c b/testsuits/sample/kernel/queue/It_los_queue_074.c index 69d8c80e..7968532a 100644 --- a/testsuits/sample/kernel/queue/It_los_queue_074.c +++ b/testsuits/sample/kernel/queue/It_los_queue_074.c @@ -35,7 +35,7 @@ static UINT32 Testcase(VOID) { UINT32 ret; - CHAR buff1[QUEUE_SHORT_BUFFER_LENTH] = "UniDSP"; + CHAR buff1[QUEUE_SHORT_BUFFER_LENGTH] = "UniDSP"; CHAR buff2[10]; g_testQueueID01 = 0xFF; diff --git a/testsuits/sample/kernel/queue/It_los_queue_088.c b/testsuits/sample/kernel/queue/It_los_queue_088.c index 7794084d..130d2f8d 100644 --- a/testsuits/sample/kernel/queue/It_los_queue_088.c +++ b/testsuits/sample/kernel/queue/It_los_queue_088.c @@ -36,11 +36,11 @@ static UINT32 Testcase(VOID) { UINT32 ret, i; const UINT32 len = 1000; - CHAR buff1[QUEUE_SHORT_BUFFER_LENTH] = "UniDSP"; - CHAR buff2[QUEUE_SHORT_BUFFER_LENTH]; + CHAR buff1[QUEUE_SHORT_BUFFER_LENGTH] = "UniDSP"; + CHAR buff2[QUEUE_SHORT_BUFFER_LENGTH]; QUEUE_INFO_S queueInfo; - ret = LOS_QueueCreate("Q1", 1000, &g_testQueueID01, 0, QUEUE_SHORT_BUFFER_LENTH); // 1000, queue len + ret = LOS_QueueCreate("Q1", 1000, &g_testQueueID01, 0, QUEUE_SHORT_BUFFER_LENGTH); // 1000, queue len ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT); ret = LOS_QueueInfoGet(g_testQueueID01, &queueInfo); @@ -49,23 +49,23 @@ static UINT32 Testcase(VOID) ICUNIT_GOTO_EQUAL(queueInfo.queueID, g_testQueueID01, queueInfo.queueID, EXIT); for (i = 0; i < 1000; i++) { // 1000, queue len - ret = LOS_QueueWrite(g_testQueueID01, buff1, QUEUE_SHORT_BUFFER_LENTH, 0); + ret = LOS_QueueWrite(g_testQueueID01, buff1, QUEUE_SHORT_BUFFER_LENGTH, 0); ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT); } - ret = LOS_QueueWrite(g_testQueueID01, buff1, QUEUE_SHORT_BUFFER_LENTH, 0); + ret = LOS_QueueWrite(g_testQueueID01, buff1, QUEUE_SHORT_BUFFER_LENGTH, 0); ICUNIT_GOTO_EQUAL(ret, LOS_ERRNO_QUEUE_ISFULL, ret, EXIT); for (i = 0; i < 1000; i++) { // 1000, queue len - ret = LOS_QueueRead(g_testQueueID01, buff2, QUEUE_SHORT_BUFFER_LENTH, 0); + ret = LOS_QueueRead(g_testQueueID01, buff2, QUEUE_SHORT_BUFFER_LENGTH, 0); ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT); } - ret = LOS_QueueRead(g_testQueueID01, buff2, QUEUE_SHORT_BUFFER_LENTH, 0); + ret = LOS_QueueRead(g_testQueueID01, buff2, QUEUE_SHORT_BUFFER_LENGTH, 0); ICUNIT_GOTO_EQUAL(ret, LOS_ERRNO_QUEUE_ISEMPTY, ret, EXIT); - ret = LOS_QueueWrite(g_testQueueID01, buff1, QUEUE_SHORT_BUFFER_LENTH, 0); + ret = LOS_QueueWrite(g_testQueueID01, buff1, QUEUE_SHORT_BUFFER_LENGTH, 0); ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT); - ret = LOS_QueueRead(g_testQueueID01, buff2, QUEUE_SHORT_BUFFER_LENTH, 0); + ret = LOS_QueueRead(g_testQueueID01, buff2, QUEUE_SHORT_BUFFER_LENGTH, 0); ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT); ret = LOS_QueueInfoGet(g_testQueueID01, &queueInfo); @@ -73,7 +73,7 @@ static UINT32 Testcase(VOID) ICUNIT_GOTO_EQUAL(queueInfo.queueLen, len, queueInfo.queueLen, EXIT); ICUNIT_GOTO_EQUAL(queueInfo.queueID, g_testQueueID01, queueInfo.queueID, EXIT); - ret = LOS_QueueRead(g_testQueueID01, buff2, QUEUE_SHORT_BUFFER_LENTH, 0); + ret = LOS_QueueRead(g_testQueueID01, buff2, QUEUE_SHORT_BUFFER_LENGTH, 0); ICUNIT_GOTO_EQUAL(ret, LOS_ERRNO_QUEUE_ISEMPTY, ret, EXIT); ret = LOS_QueueDelete(g_testQueueID01); diff --git a/testsuits/sample/kernel/queue/It_los_queue_097.c b/testsuits/sample/kernel/queue/It_los_queue_097.c index f9725843..f0828f78 100644 --- a/testsuits/sample/kernel/queue/It_los_queue_097.c +++ b/testsuits/sample/kernel/queue/It_los_queue_097.c @@ -38,7 +38,7 @@ static UINT32 Testcase(VOID) { UINT32 ret; UINT32 swTmrID; - CHAR buff1[QUEUE_SHORT_BUFFER_LENTH] = "UniDSP"; + CHAR buff1[QUEUE_SHORT_BUFFER_LENGTH] = "UniDSP"; QUEUE_INFO_S queueInfo; ret = LOS_QueueCreate("Q1", QUEUE_BASE_NUM, &swTmrID, 0, QUEUE_BASE_MSGSIZE); diff --git a/testsuits/sample/kernel/queue/It_los_queue_104.c b/testsuits/sample/kernel/queue/It_los_queue_104.c index 9e9016f3..f40a6c99 100644 --- a/testsuits/sample/kernel/queue/It_los_queue_104.c +++ b/testsuits/sample/kernel/queue/It_los_queue_104.c @@ -38,7 +38,7 @@ static UINT32 Testcase(VOID) { UINT32 ret; UINT32 swTmrID; - CHAR buff1[QUEUE_SHORT_BUFFER_LENTH] = "UniDSP"; + CHAR buff1[QUEUE_SHORT_BUFFER_LENGTH] = "UniDSP"; QUEUE_INFO_S queueInfo; ret = LOS_QueueCreate("Q1", QUEUE_BASE_NUM, &swTmrID, 0, QUEUE_BASE_MSGSIZE); diff --git a/testsuits/sample/kernel/queue/It_los_queue_106.c b/testsuits/sample/kernel/queue/It_los_queue_106.c index 7fadcb45..a4c90102 100644 --- a/testsuits/sample/kernel/queue/It_los_queue_106.c +++ b/testsuits/sample/kernel/queue/It_los_queue_106.c @@ -38,24 +38,24 @@ static UINT32 Testcase(VOID) { UINT32 ret; UINT32 swTmrID; - CHAR buff1[QUEUE_SHORT_BUFFER_LENTH] = "UniDSP"; - CHAR buff2[QUEUE_SHORT_BUFFER_LENTH]; + CHAR buff1[QUEUE_SHORT_BUFFER_LENGTH] = "UniDSP"; + CHAR buff2[QUEUE_SHORT_BUFFER_LENGTH]; - ret = LOS_QueueCreate("Q1", QUEUE_BASE_NUM, &swTmrID, 0, QUEUE_SHORT_BUFFER_LENTH); + ret = LOS_QueueCreate("Q1", QUEUE_BASE_NUM, &swTmrID, 0, QUEUE_SHORT_BUFFER_LENGTH); ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT); - ret = LOS_QueueWriteCopy(swTmrID, NULL, QUEUE_SHORT_BUFFER_LENTH, 0); + ret = LOS_QueueWriteCopy(swTmrID, NULL, QUEUE_SHORT_BUFFER_LENGTH, 0); ICUNIT_GOTO_EQUAL(ret, LOS_ERRNO_QUEUE_WRITE_PTR_NULL, ret, EXIT); - (void)memset_s(buff2, QUEUE_SHORT_BUFFER_LENTH, 0, QUEUE_SHORT_BUFFER_LENTH); - ret = LOS_QueueRead(swTmrID, &buff2, QUEUE_SHORT_BUFFER_LENTH, 0); + (void)memset_s(buff2, QUEUE_SHORT_BUFFER_LENGTH, 0, QUEUE_SHORT_BUFFER_LENGTH); + ret = LOS_QueueRead(swTmrID, &buff2, QUEUE_SHORT_BUFFER_LENGTH, 0); ICUNIT_GOTO_EQUAL(ret, LOS_ERRNO_QUEUE_ISEMPTY, ret, EXIT); - ret = LOS_QueueWriteCopy(swTmrID, &buff1, QUEUE_SHORT_BUFFER_LENTH, 0); + ret = LOS_QueueWriteCopy(swTmrID, &buff1, QUEUE_SHORT_BUFFER_LENGTH, 0); ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT); - (void)memset_s(buff2, QUEUE_SHORT_BUFFER_LENTH, 0, QUEUE_SHORT_BUFFER_LENTH); - ret = LOS_QueueRead(swTmrID, &buff2, QUEUE_SHORT_BUFFER_LENTH, 0); + (void)memset_s(buff2, QUEUE_SHORT_BUFFER_LENGTH, 0, QUEUE_SHORT_BUFFER_LENGTH); + ret = LOS_QueueRead(swTmrID, &buff2, QUEUE_SHORT_BUFFER_LENGTH, 0); ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT); ret = LOS_QueueDelete(swTmrID); diff --git a/testsuits/sample/kernel/queue/It_los_queue_107.c b/testsuits/sample/kernel/queue/It_los_queue_107.c index 2ffbf434..1f1a1546 100644 --- a/testsuits/sample/kernel/queue/It_los_queue_107.c +++ b/testsuits/sample/kernel/queue/It_los_queue_107.c @@ -37,31 +37,31 @@ static UINT32 Testcase(VOID) { UINT32 ret; UINT32 swTmrID; - CHAR buff1[QUEUE_SHORT_BUFFER_LENTH] = "UniDSP"; - CHAR buff2[QUEUE_SHORT_BUFFER_LENTH]; + CHAR buff1[QUEUE_SHORT_BUFFER_LENGTH] = "UniDSP"; + CHAR buff2[QUEUE_SHORT_BUFFER_LENGTH]; - ret = LOS_QueueCreate("Q1", QUEUE_BASE_NUM, &swTmrID, 0, QUEUE_SHORT_BUFFER_LENTH); + ret = LOS_QueueCreate("Q1", QUEUE_BASE_NUM, &swTmrID, 0, QUEUE_SHORT_BUFFER_LENGTH); ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT); - ret = LOS_QueueWriteCopy(swTmrID, &buff1, QUEUE_SHORT_BUFFER_LENTH, 0xffffffff); + ret = LOS_QueueWriteCopy(swTmrID, &buff1, QUEUE_SHORT_BUFFER_LENGTH, 0xffffffff); ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT); - (void)memset_s(buff2, QUEUE_SHORT_BUFFER_LENTH, 0, QUEUE_SHORT_BUFFER_LENTH); - ret = LOS_QueueRead(swTmrID, &buff2, QUEUE_SHORT_BUFFER_LENTH, 0); + (void)memset_s(buff2, QUEUE_SHORT_BUFFER_LENGTH, 0, QUEUE_SHORT_BUFFER_LENGTH); + ret = LOS_QueueRead(swTmrID, &buff2, QUEUE_SHORT_BUFFER_LENGTH, 0); ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT); - ret = LOS_QueueWriteCopy(swTmrID, &buff1, QUEUE_SHORT_BUFFER_LENTH, 0xffffffff + 1); + ret = LOS_QueueWriteCopy(swTmrID, &buff1, QUEUE_SHORT_BUFFER_LENGTH, 0xffffffff + 1); ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT); - (void)memset_s(buff2, QUEUE_SHORT_BUFFER_LENTH, 0, QUEUE_SHORT_BUFFER_LENTH); - ret = LOS_QueueRead(swTmrID, &buff2, QUEUE_SHORT_BUFFER_LENTH, 0); + (void)memset_s(buff2, QUEUE_SHORT_BUFFER_LENGTH, 0, QUEUE_SHORT_BUFFER_LENGTH); + ret = LOS_QueueRead(swTmrID, &buff2, QUEUE_SHORT_BUFFER_LENGTH, 0); ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT); - ret = LOS_QueueWriteCopy(swTmrID, &buff1, QUEUE_SHORT_BUFFER_LENTH, 0xffffffff - 1); + ret = LOS_QueueWriteCopy(swTmrID, &buff1, QUEUE_SHORT_BUFFER_LENGTH, 0xffffffff - 1); ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT); - (void)memset_s(buff2, QUEUE_SHORT_BUFFER_LENTH, 0, QUEUE_SHORT_BUFFER_LENTH); - ret = LOS_QueueRead(swTmrID, &buff2, QUEUE_SHORT_BUFFER_LENTH, 0); + (void)memset_s(buff2, QUEUE_SHORT_BUFFER_LENGTH, 0, QUEUE_SHORT_BUFFER_LENGTH); + ret = LOS_QueueRead(swTmrID, &buff2, QUEUE_SHORT_BUFFER_LENGTH, 0); ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT); ret = LOS_QueueDelete(swTmrID); diff --git a/testsuits/sample/kernel/queue/It_los_queue_108.c b/testsuits/sample/kernel/queue/It_los_queue_108.c index 2ecd5f6a..a54e6d16 100644 --- a/testsuits/sample/kernel/queue/It_los_queue_108.c +++ b/testsuits/sample/kernel/queue/It_los_queue_108.c @@ -57,15 +57,15 @@ EXIT: static UINT32 Testcase(VOID) { UINT32 ret; - CHAR buff1[QUEUE_SHORT_BUFFER_LENTH] = "UniDSP"; + CHAR buff1[QUEUE_SHORT_BUFFER_LENGTH] = "UniDSP"; QUEUE_INFO_S queueInfo; g_testCount = 0; - ret = LOS_QueueCreate("Q1", QUEUE_BASE_NUM, &g_testQueueID01, 0, QUEUE_SHORT_BUFFER_LENTH); + ret = LOS_QueueCreate("Q1", QUEUE_BASE_NUM, &g_testQueueID01, 0, QUEUE_SHORT_BUFFER_LENGTH); ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT); - ret = LOS_QueueWrite(g_testQueueID01, &buff1, QUEUE_SHORT_BUFFER_LENTH, 0); + ret = LOS_QueueWrite(g_testQueueID01, &buff1, QUEUE_SHORT_BUFFER_LENGTH, 0); ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT); ret = LOS_HwiCreate(HWI_NUM_TEST, 1, 0, HwiF01, 0); diff --git a/testsuits/sample/kernel/queue/It_los_queue_109.c b/testsuits/sample/kernel/queue/It_los_queue_109.c index 4cbdc571..7c26f483 100644 --- a/testsuits/sample/kernel/queue/It_los_queue_109.c +++ b/testsuits/sample/kernel/queue/It_los_queue_109.c @@ -60,7 +60,7 @@ EXIT: static UINT32 Testcase(VOID) { UINT32 ret; - CHAR buff1[QUEUE_SHORT_BUFFER_LENTH] = "UniDSP"; + CHAR buff1[QUEUE_SHORT_BUFFER_LENGTH] = "UniDSP"; QUEUE_INFO_S queueInfo; TSK_INIT_PARAM_S task1 = { 0 }; @@ -71,10 +71,10 @@ static UINT32 Testcase(VOID) g_testCount = 0; - ret = LOS_QueueCreate("Q1", QUEUE_BASE_NUM, &g_testQueueID01, 0, QUEUE_SHORT_BUFFER_LENTH); + ret = LOS_QueueCreate("Q1", QUEUE_BASE_NUM, &g_testQueueID01, 0, QUEUE_SHORT_BUFFER_LENGTH); ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT); - ret = LOS_QueueWrite(g_testQueueID01, &buff1, QUEUE_SHORT_BUFFER_LENTH, 0); + ret = LOS_QueueWrite(g_testQueueID01, &buff1, QUEUE_SHORT_BUFFER_LENGTH, 0); ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT); ret = LOS_TaskCreate(&g_testTaskID01, &task1); diff --git a/testsuits/sample/kernel/queue/It_los_queue_110.c b/testsuits/sample/kernel/queue/It_los_queue_110.c index 512ac2a0..3da7b37c 100644 --- a/testsuits/sample/kernel/queue/It_los_queue_110.c +++ b/testsuits/sample/kernel/queue/It_los_queue_110.c @@ -56,15 +56,15 @@ static UINT32 Testcase(VOID) { UINT32 ret; UINT32 swTmrID; - CHAR buff1[QUEUE_SHORT_BUFFER_LENTH] = "UniDSP"; + CHAR buff1[QUEUE_SHORT_BUFFER_LENGTH] = "UniDSP"; QUEUE_INFO_S queueInfo; g_testCount = 0; - ret = LOS_QueueCreate("Q1", QUEUE_BASE_NUM, &g_testQueueID01, 0, QUEUE_SHORT_BUFFER_LENTH); + ret = LOS_QueueCreate("Q1", QUEUE_BASE_NUM, &g_testQueueID01, 0, QUEUE_SHORT_BUFFER_LENGTH); ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT); - ret = LOS_QueueWrite(g_testQueueID01, &buff1, QUEUE_SHORT_BUFFER_LENTH, 0); + ret = LOS_QueueWrite(g_testQueueID01, &buff1, QUEUE_SHORT_BUFFER_LENGTH, 0); ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT); // 4, Timeout interval of a periodic software timer. diff --git a/testsuits/sample/kernel/queue/It_los_queue_114.c b/testsuits/sample/kernel/queue/It_los_queue_114.c index 07883322..9353715e 100644 --- a/testsuits/sample/kernel/queue/It_los_queue_114.c +++ b/testsuits/sample/kernel/queue/It_los_queue_114.c @@ -38,21 +38,21 @@ static UINT32 Testcase(VOID) { UINT32 ret, i; UINT32 swTmrID; - CHAR buff1[QUEUE_SHORT_BUFFER_LENTH] = "UniDSP"; + CHAR buff1[QUEUE_SHORT_BUFFER_LENGTH] = "UniDSP"; QUEUE_INFO_S queueInfo; - ret = LOS_QueueCreate("Q1", QUEUE_BASE_NUM, &swTmrID, 0, QUEUE_SHORT_BUFFER_LENTH); + ret = LOS_QueueCreate("Q1", QUEUE_BASE_NUM, &swTmrID, 0, QUEUE_SHORT_BUFFER_LENGTH); ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT); for (i = 0; i < QUEUE_BASE_NUM; i++) { - ret = LOS_QueueWriteCopy(swTmrID, &buff1, QUEUE_SHORT_BUFFER_LENTH, 0); + ret = LOS_QueueWriteCopy(swTmrID, &buff1, QUEUE_SHORT_BUFFER_LENGTH, 0); ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT); } - ret = LOS_QueueWrite(swTmrID, &buff1, QUEUE_SHORT_BUFFER_LENTH, 0); + ret = LOS_QueueWrite(swTmrID, &buff1, QUEUE_SHORT_BUFFER_LENGTH, 0); ICUNIT_GOTO_EQUAL(ret, LOS_ERRNO_QUEUE_ISFULL, ret, EXIT); - ret = LOS_QueueWriteCopy(swTmrID, &buff1, QUEUE_SHORT_BUFFER_LENTH, 0); + ret = LOS_QueueWriteCopy(swTmrID, &buff1, QUEUE_SHORT_BUFFER_LENGTH, 0); ICUNIT_GOTO_EQUAL(ret, LOS_ERRNO_QUEUE_ISFULL, ret, EXIT); ret = LOS_QueueInfoGet(swTmrID, &queueInfo); diff --git a/testsuits/sample/kernel/queue/Llt_los_queue_001.c b/testsuits/sample/kernel/queue/Llt_los_queue_001.c index a1de91a6..db75cf40 100644 --- a/testsuits/sample/kernel/queue/Llt_los_queue_001.c +++ b/testsuits/sample/kernel/queue/Llt_los_queue_001.c @@ -6,8 +6,8 @@ static VOID TaskF01(VOID) { UINT32 ret; - CHAR buff1[QUEUE_SHORT_BUFFER_LENTH] = "UniDSP"; - CHAR buff2[QUEUE_SHORT_BUFFER_LENTH] = " "; + CHAR buff1[QUEUE_SHORT_BUFFER_LENGTH] = "UniDSP"; + CHAR buff2[QUEUE_SHORT_BUFFER_LENGTH] = " "; ret = LOS_QueueRead(g_testQueueID01, &buff2, QUEUE_BASE_MSGSIZE, LOS_WAIT_FOREVER); ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT); @@ -34,8 +34,8 @@ static UINT32 Testcase(VOID) QUEUE_INFO_S queueInfo; UINT32 i; UINT32 queueID[LOSCFG_BASE_IPC_QUEUE_LIMIT + 1]; - CHAR buff1[QUEUE_SHORT_BUFFER_LENTH] = "UniDSP"; - CHAR buff2[QUEUE_SHORT_BUFFER_LENTH] = " "; + CHAR buff1[QUEUE_SHORT_BUFFER_LENGTH] = "UniDSP"; + CHAR buff2[QUEUE_SHORT_BUFFER_LENGTH] = " "; TSK_INIT_PARAM_S task1 = {0}; task1.pfnTaskEntry = (TSK_ENTRY_FUNC)TaskF01; diff --git a/testsuits/unittest/posix/src/fs/posix_fs_func_test.c b/testsuits/unittest/posix/src/fs/posix_fs_func_test.c index f4328e13..393d7efd 100644 --- a/testsuits/unittest/posix/src/fs/posix_fs_func_test.c +++ b/testsuits/unittest/posix/src/fs/posix_fs_func_test.c @@ -42,6 +42,9 @@ #include "kernel_test.h" #include "log.h" #include +#include +#include +#include "sys/stat.h" /* * * @tc.desc : register a test suite, this suite is used to test basic flow and interface dependency @@ -143,6 +146,1417 @@ LITE_TEST_CASE(PosixFsFuncTestSuite, testFsDirname004, Function | MediumTest | L TEST_ASSERT_EQUAL_STRING(".", workDir); } +#define TEST_FILE_PTAH_RIGHT "/temp" +/* * + * @tc.number SUB_KERNEL_FS_DIRNAME_005 + * @tc.name fopen and fclose + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(PosixFsFuncTestSuite, testFsFopenFclose001, Function | MediumTest | Level1) +{ + int ret = 0; + FILE *fp = NULL; + fp = fopen(TEST_FILE_PTAH_RIGHT, "w"); + TEST_ASSERT_NOT_NULL(fp); + + ret = fclose(fp); + TEST_ASSERT_EQUAL_INT(ret, 0); +} + +/* * + * @tc.number SUB_KERNEL_FS_DIRNAME_006 + * @tc.name fopen and fclose + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(PosixFsFuncTestSuite, testFsFopenFclose002, Function | MediumTest | Level1) +{ + int ret = 0; + FILE *fp = NULL; + fp = fopen(TEST_FILE_PTAH_RIGHT, "w+"); + TEST_ASSERT_NOT_NULL(fp); + + ret = fclose(fp); + TEST_ASSERT_EQUAL_INT(ret, 0); +} + +/* * + * @tc.number SUB_KERNEL_FS_DIRNAME_007 + * @tc.name fopen and fclose + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(PosixFsFuncTestSuite, testFsFopenFclose003, Function | MediumTest | Level1) +{ + int ret = 0; + FILE *fp = NULL; + fp = fopen(TEST_FILE_PTAH_RIGHT, "r"); + TEST_ASSERT_NOT_NULL(fp); + + ret = fclose(fp); + TEST_ASSERT_EQUAL_INT(ret, 0); +} + +/* * + * @tc.number SUB_KERNEL_FS_DIRNAME_008 + * @tc.name fopen and fclose + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(PosixFsFuncTestSuite, testFsFopenFclose004, Function | MediumTest | Level1) +{ + int ret = 0; + FILE *fp = NULL; + fp = fopen(TEST_FILE_PTAH_RIGHT, "a"); + TEST_ASSERT_NOT_NULL(fp); + + ret = fclose(fp); + TEST_ASSERT_EQUAL_INT(ret, 0); +} + +/* * + * @tc.number SUB_KERNEL_FS_DIRNAME_009 + * @tc.name fopen and fclose + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(PosixFsFuncTestSuite, testFsFopenFclose005, Function | MediumTest | Level1) +{ + int ret = 0; + FILE *fp = NULL; + fp = fopen(TEST_FILE_PTAH_RIGHT, "c"); + TEST_ASSERT_NULL(fp); +} + +/* * + * @tc.number SUB_KERNEL_FS_DIRNAME_010 + * @tc.name remove the path before fopen and fclose + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(PosixFsFuncTestSuite, testFsFopenFclose006, Function | MediumTest | Level1) +{ + int ret = 0; + FILE *fp = NULL; + + remove(TEST_FILE_PTAH_RIGHT); + fp = fopen(TEST_FILE_PTAH_RIGHT, "w"); + TEST_ASSERT_NOT_NULL(fp); + + ret = fclose(fp); + TEST_ASSERT_EQUAL_INT(ret, 0); +} + +/* * + * @tc.number SUB_KERNEL_FS_DIRNAME_011 + * @tc.name remove the path before fopen and fclose + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(PosixFsFuncTestSuite, testFsFopenFclose007, Function | MediumTest | Level1) +{ + int ret = 0; + FILE *fp = NULL; + + remove(TEST_FILE_PTAH_RIGHT); + fp = fopen(TEST_FILE_PTAH_RIGHT, "w+"); + TEST_ASSERT_NOT_NULL(fp); + + ret = fclose(fp); + TEST_ASSERT_EQUAL_INT(ret, 0); +} + +/* * + * @tc.number SUB_KERNEL_FS_DIRNAME_012 + * @tc.name remove the path before fopen and fclose + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(PosixFsFuncTestSuite, testFsFopenFclose008, Function | MediumTest | Level1) +{ + int ret = 0; + FILE *fp = NULL; + + remove(TEST_FILE_PTAH_RIGHT); + fp = fopen(TEST_FILE_PTAH_RIGHT, "r"); + TEST_ASSERT_NOT_NULL(fp); + + ret = fclose(fp); + TEST_ASSERT_EQUAL_INT(ret, 0); +} + +/* * + * @tc.number SUB_KERNEL_FS_DIRNAME_013 + * @tc.name remove the path before fopen and fclose + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(PosixFsFuncTestSuite, testFsFopenFclose009, Function | MediumTest | Level1) +{ + int ret = 0; + FILE *fp = NULL; + + remove(TEST_FILE_PTAH_RIGHT); + fp = fopen(TEST_FILE_PTAH_RIGHT, "a"); + TEST_ASSERT_NOT_NULL(fp); + + ret = fclose(fp); + TEST_ASSERT_EQUAL_INT(ret, 0); +} + +/* * + * @tc.number SUB_KERNEL_FS_DIRNAME_014 + * @tc.name remove the path before fopen and fclose + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(PosixFsFuncTestSuite, testFsFopenFclose010, Function | MediumTest | Level1) +{ + int ret = 0; + FILE *fp = NULL; + + remove(TEST_FILE_PTAH_RIGHT); + fp = fopen(TEST_FILE_PTAH_RIGHT, NULL); + TEST_ASSERT_NULL(fp); +} + +/* * + * @tc.number SUB_KERNEL_FS_DIRNAME_015 + * @tc.name remove the path before fopen and fclose + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(PosixFsFuncTestSuite, testFsFopenFclose011, Function | MediumTest | Level1) +{ + int ret = 0; + FILE *fp = NULL; + int err = 0; + + ret = fclose(NULL); + TEST_ASSERT_EQUAL_INT(ret, -1); + err = errno; + TEST_ASSERT_EQUAL_INT(err, EINVAL); +} + +/* * + * @tc.number SUB_KERNEL_FS_DIRNAME_016 + * @tc.name fdopen + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(PosixFsFuncTestSuite, testFsFdopen001, Function | MediumTest | Level1) +{ + int ret = 0; + FILE *fp = NULL; + int fd = 0; + + fd = open(TEST_FILE_PTAH_RIGHT, O_CREAT | O_RDWR, 0666); + TEST_ASSERT_TRUE(fd > 0); + + fp = fdopen(fd, "w"); + TEST_ASSERT_NOT_NULL(fp); + + ret = fclose(fp); + TEST_ASSERT_EQUAL_INT(ret, 0); +} + +/* * + * @tc.number SUB_KERNEL_FS_DIRNAME_017 + * @tc.name fdopen + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(PosixFsFuncTestSuite, testFsFdopen002, Function | MediumTest | Level1) +{ + int ret = 0; + FILE *fp = NULL; + int fd = 0; + + fd = open(TEST_FILE_PTAH_RIGHT, O_CREAT | O_RDWR, 0666); + TEST_ASSERT_TRUE(fd > 0); + + fp = fdopen(fd, "w+"); + TEST_ASSERT_NOT_NULL(fp); + + ret = fclose(fp); + TEST_ASSERT_EQUAL_INT(ret, 0); +} + +/* * + * @tc.number SUB_KERNEL_FS_DIRNAME_018 + * @tc.name fdopen + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(PosixFsFuncTestSuite, testFsFdopen003, Function | MediumTest | Level1) +{ + int ret = 0; + FILE *fp = NULL; + int fd = 0; + + fd = open(TEST_FILE_PTAH_RIGHT, O_CREAT | O_RDWR, 0666); + TEST_ASSERT_TRUE(fd > 0); + + fp = fdopen(fd, "a"); + TEST_ASSERT_NOT_NULL(fp); + + ret = fclose(fp); + TEST_ASSERT_EQUAL_INT(ret, 0); +} + +/* * + * @tc.number SUB_KERNEL_FS_DIRNAME_019 + * @tc.name fdopen + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(PosixFsFuncTestSuite, testFsFdopen004, Function | MediumTest | Level1) +{ + int ret = 0; + FILE *fp = NULL; + int fd = 0; + + fd = open(TEST_FILE_PTAH_RIGHT, O_CREAT | O_RDWR, 0666); + TEST_ASSERT_TRUE(fd > 0); + + fp = fdopen(500, "w"); + // in some fs, may return ok, so return null or not is pass. + if (NULL == fp) { + close (fd); + return; + } + + fp->fd = fd; + ret = fclose(fp); + TEST_ASSERT_EQUAL_INT(ret, 0); +} + +/* * + * @tc.number SUB_KERNEL_FS_DIRNAME_020 + * @tc.name ftell and fseek + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(PosixFsFuncTestSuite, testFsFtellFseek001, Function | MediumTest | Level1) +{ + int ret = 0; + FILE *fp = NULL; + long off = 0; + + fp = fopen(TEST_FILE_PTAH_RIGHT, "w"); + TEST_ASSERT_NOT_NULL(fp); + + off = ftell(fp); + TEST_ASSERT_EQUAL_INT64(off, 0); + + ret = fclose(fp); + TEST_ASSERT_EQUAL_INT(ret, 0); +} + +/* * + * @tc.number SUB_KERNEL_FS_DIRNAME_021 + * @tc.name ftell and fseek + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(PosixFsFuncTestSuite, testFsFtellFseek002, Function | MediumTest | Level1) +{ + int ret = 0; + FILE *fp = NULL; + long off = 0; + + fp = fopen(TEST_FILE_PTAH_RIGHT, "w"); + TEST_ASSERT_NOT_NULL(fp); + + ret = fseek(fp, 0L, SEEK_SET); + TEST_ASSERT_TRUE(ret != -1); + + off = ftell(fp); + TEST_ASSERT_EQUAL_INT64(off, 0); + + ret = fclose(fp); + TEST_ASSERT_EQUAL_INT(ret, 0); +} + +/* * + * @tc.number SUB_KERNEL_FS_DIRNAME_022 + * @tc.name ftell and fseek + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(PosixFsFuncTestSuite, testFsFtellFseek003, Function | MediumTest | Level1) +{ + int ret = 0; + FILE *fp = NULL; + long off = 0; + + fp = fopen(TEST_FILE_PTAH_RIGHT, "w"); + TEST_ASSERT_NOT_NULL(fp); + + ret = fseek(fp, 10L, SEEK_SET); + TEST_ASSERT_TRUE(ret != -1); + + off = ftell(fp); + TEST_ASSERT_EQUAL_INT64(off, 10); + + ret = fclose(fp); + TEST_ASSERT_EQUAL_INT(ret, 0); +} + +/* * + * @tc.number SUB_KERNEL_FS_DIRNAME_023 + * @tc.name ftell and fseek + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(PosixFsFuncTestSuite, testFsFtellFseek004, Function | MediumTest | Level1) +{ + int ret = 0; + FILE *fp = NULL; + long off = 0; + + fp = fopen(TEST_FILE_PTAH_RIGHT, "w"); + TEST_ASSERT_NOT_NULL(fp); + + ret = fseek(fp, 10L, SEEK_END); + TEST_ASSERT_TRUE(ret != -1); + + off = ftell(fp); + TEST_ASSERT_EQUAL_INT64(off, 10); + + ret = fclose(fp); + TEST_ASSERT_EQUAL_INT(ret, 0); +} + +/* * + * @tc.number SUB_KERNEL_FS_DIRNAME_024 + * @tc.name ftell and fseek + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(PosixFsFuncTestSuite, testFsFtellFseek005, Function | MediumTest | Level1) +{ + int ret = 0; + FILE *fp = NULL; + long off = 0; + + fp = fopen(TEST_FILE_PTAH_RIGHT, "w"); + TEST_ASSERT_NOT_NULL(fp); + + ret = fseek(fp, 10L, SEEK_CUR); + TEST_ASSERT_TRUE(ret != -1); + + off = ftell(fp); + TEST_ASSERT_EQUAL_INT64(off, 10); + + ret = fclose(fp); + TEST_ASSERT_EQUAL_INT(ret, 0); +} + +/* * + * @tc.number SUB_KERNEL_FS_DIRNAME_025 + * @tc.name ftell and fseek + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(PosixFsFuncTestSuite, testFsFtellFseek006, Function | MediumTest | Level1) +{ + int ret = 0; + FILE *fp = NULL; + long off = 0; + + fp = fopen(TEST_FILE_PTAH_RIGHT, "w"); + TEST_ASSERT_NOT_NULL(fp); + + ret = fseek(fp, -1L, SEEK_SET); + TEST_ASSERT_EQUAL_INT(ret, -1); + + off = ftell(fp); + TEST_ASSERT_EQUAL_INT64(off, 0); + + ret = fclose(fp); + TEST_ASSERT_EQUAL_INT(ret, 0); +} + +/* * + * @tc.number SUB_KERNEL_FS_DIRNAME_026 + * @tc.name ftell and fseek + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(PosixFsFuncTestSuite, testFsFtellFseek007, Function | MediumTest | Level1) +{ + int ret = 0; + FILE *fp = NULL; + long off = 0; + + fp = fopen(TEST_FILE_PTAH_RIGHT, "w"); + TEST_ASSERT_NOT_NULL(fp); + + ret = fseek(fp, -1L, SEEK_CUR); + TEST_ASSERT_EQUAL_INT(ret, -1); + + off = ftell(fp); + TEST_ASSERT_EQUAL_INT64(off, 0); + + ret = fclose(fp); + TEST_ASSERT_EQUAL_INT(ret, 0); +} + +/* * + * @tc.number SUB_KERNEL_FS_DIRNAME_027 + * @tc.name ftell and fseek + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(PosixFsFuncTestSuite, testFsFtellFseek008, Function | MediumTest | Level1) +{ + int ret = 0; + FILE *fp = NULL; + long off = 0; + + fp = fopen(TEST_FILE_PTAH_RIGHT, "w"); + TEST_ASSERT_NOT_NULL(fp); + + ret = fseek(fp, -1L, SEEK_END); + TEST_ASSERT_EQUAL_INT(ret, -1); + + off = ftell(fp); + TEST_ASSERT_EQUAL_INT64(off, 0); + + ret = fclose(fp); + TEST_ASSERT_EQUAL_INT(ret, 0); +} + +/* * + * @tc.number SUB_KERNEL_FS_DIRNAME_028 + * @tc.name ftell and fseek + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(PosixFsFuncTestSuite, testFsFtellFseek009, Function | MediumTest | Level1) +{ + int ret = 0; + FILE *fp = NULL; + long off = 0; + + fp = fopen(TEST_FILE_PTAH_RIGHT, "w"); + TEST_ASSERT_NOT_NULL(fp); + + ret = fseek(fp, 10L, 5); + TEST_ASSERT_TRUE(ret != 0); + + off = ftell(fp); + TEST_ASSERT_EQUAL_INT64(off, 0); + + ret = fclose(fp); + TEST_ASSERT_EQUAL_INT(ret, 0); +} + +/* * + * @tc.number SUB_KERNEL_FS_DIRNAME_029 + * @tc.name ftell and fseek + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(PosixFsFuncTestSuite, testFsFtellFseek010, Function | MediumTest | Level1) +{ + int ret = 0; + FILE *fp = NULL; + long off = 0; + int fd; + + fp = fopen(TEST_FILE_PTAH_RIGHT, "w"); + TEST_ASSERT_NOT_NULL(fp); + + fd = fp->fd; + + fp->fd = 500; + + ret = fseek(fp, 10L, SEEK_SET); + TEST_ASSERT_EQUAL_INT(ret, -1); + + fp->fd = fd; + + ret = fclose(fp); + TEST_ASSERT_EQUAL_INT(ret, 0); +} + +/* * + * @tc.number SUB_KERNEL_FS_DIRNAME_030 + * @tc.name ftell and fseek + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(PosixFsFuncTestSuite, testFsFtellFseek011, Function | MediumTest | Level1) +{ + int ret = 0; + FILE *fp = NULL; + long off = 0; + + fp = fopen(TEST_FILE_PTAH_RIGHT, "w"); + TEST_ASSERT_NOT_NULL(fp); + + ret = fseek(fp, 100L, SEEK_SET); + TEST_ASSERT_TRUE(ret != -1); + + ret = fseek(fp, 40L, SEEK_CUR); + TEST_ASSERT_TRUE(ret != -1); + + off = ftell(fp); + TEST_ASSERT_EQUAL_INT64(off, 140); + + ret = fclose(fp); + TEST_ASSERT_EQUAL_INT(ret, 0); +} + + +/* * + * @tc.number SUB_KERNEL_FS_DIRNAME_031 + * @tc.name ftell and fseek + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(PosixFsFuncTestSuite, testFsFtellFseek012, Function | MediumTest | Level1) +{ + int ret = 0; + FILE *fp = NULL; + long off = 0; + + fp = fopen(TEST_FILE_PTAH_RIGHT, "w"); + TEST_ASSERT_NOT_NULL(fp); + + ret = fseek(fp, 100L, SEEK_SET); + TEST_ASSERT_TRUE(ret != -1); + + ret = fseek(fp, 20L, SEEK_SET); + TEST_ASSERT_TRUE(ret != -1); + + off = ftell(fp); + TEST_ASSERT_EQUAL_INT64(off, 20); + + ret = fclose(fp); + TEST_ASSERT_EQUAL_INT(ret, 0); +} + +/* * + * @tc.number SUB_KERNEL_FS_DIRNAME_032 + * @tc.name ftell and fseek + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(PosixFsFuncTestSuite, testFsFtellFseek013, Function | MediumTest | Level1) +{ + int ret = 0; + FILE *fp = NULL; + long off = 0; + + fp = fopen(TEST_FILE_PTAH_RIGHT, "w"); + TEST_ASSERT_NOT_NULL(fp); + + ret = fseek(fp, 100L, SEEK_SET); + TEST_ASSERT_TRUE(ret != -1); + + ret = fseek(fp, 20L, SEEK_END); + TEST_ASSERT_TRUE(ret != -1); + + off = ftell(fp); + TEST_ASSERT_EQUAL_INT64(off, 20); + + ret = fclose(fp); + TEST_ASSERT_EQUAL_INT(ret, 0); +} + +/* * + * @tc.number SUB_KERNEL_FS_DIRNAME_033 + * @tc.name ftell and fseek + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(PosixFsFuncTestSuite, testFsFtellFseek014, Function | MediumTest | Level1) +{ + int ret = 0; + FILE *fp = NULL; + long off = 0; + + fp = fopen(TEST_FILE_PTAH_RIGHT, "w"); + TEST_ASSERT_NOT_NULL(fp); + + ret = fseek(fp, 100L, SEEK_SET); + TEST_ASSERT_TRUE(ret != -1); + + rewind(fp); + + off = ftell(fp); + TEST_ASSERT_EQUAL_INT64(off, 0); + + ret = fclose(fp); + TEST_ASSERT_EQUAL_INT(ret, 0); +} + +/* * + * @tc.number SUB_KERNEL_FS_DIRNAME_034 + * @tc.name ftell and fseek + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(PosixFsFuncTestSuite, testFsFtellFseek015, Function | MediumTest | Level1) +{ + int ret = 0; + FILE *fp = NULL; + long off = 0; + + fp = fopen(TEST_FILE_PTAH_RIGHT, "w"); + TEST_ASSERT_NOT_NULL(fp); + + ret = fseek(fp, 100L, SEEK_CUR); + TEST_ASSERT_TRUE(ret != -1); + + rewind(fp); + + off = ftell(fp); + TEST_ASSERT_EQUAL_INT64(off, 0); + + ret = fclose(fp); + TEST_ASSERT_EQUAL_INT(ret, 0); +} + +/* * + * @tc.number SUB_KERNEL_FS_DIRNAME_035 + * @tc.name ftell and fseek + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(PosixFsFuncTestSuite, testFsFtellFseek016, Function | MediumTest | Level1) +{ + int ret = 0; + FILE *fp = NULL; + long off = 0; + + fp = fopen(TEST_FILE_PTAH_RIGHT, "w"); + TEST_ASSERT_NOT_NULL(fp); + + ret = fseek(fp, 100L, SEEK_END); + TEST_ASSERT_TRUE(ret != -1); + + rewind(fp); + + off = ftell(fp); + TEST_ASSERT_EQUAL_INT64(off, 0); + + ret = fclose(fp); + TEST_ASSERT_EQUAL_INT(ret, 0); +} + +/* * + * @tc.number SUB_KERNEL_FS_DIRNAME_036 + * @tc.name fputs + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(PosixFsFuncTestSuite, testFsFputs001, Function | MediumTest | Level1) +{ + int ret = 0; + FILE *fp = NULL; + const char chr1[10] = "hello"; + char str[20] = {0}; + + fp = fopen(TEST_FILE_PTAH_RIGHT, "w"); + TEST_ASSERT_NOT_NULL(fp); + + ret = fputs(chr1, fp); + TEST_ASSERT_TRUE(ret != -1); + + ret = fclose(fp); + TEST_ASSERT_EQUAL_INT(ret, 0); +} + +/* * + * @tc.number SUB_KERNEL_FS_DIRNAME_037 + * @tc.name fputs + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(PosixFsFuncTestSuite, testFsFputs002, Function | MediumTest | Level1) +{ + int ret = 0; + FILE *fp = NULL; + const char chr1[10] = "hello"; + char str[20] = {0}; + + fp = fopen(TEST_FILE_PTAH_RIGHT, "a"); + TEST_ASSERT_NOT_NULL(fp); + + ret = fputs(chr1, fp); + TEST_ASSERT_TRUE(ret != -1); + + ret = fclose(fp); + TEST_ASSERT_EQUAL_INT(ret, 0); +} + +/* * + * @tc.number SUB_KERNEL_FS_DIRNAME_038 + * @tc.name fputs + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(PosixFsFuncTestSuite, testFsFputs003, Function | MediumTest | Level1) +{ + int ret = 0; + FILE *fp = NULL; + const char chr1[10] = "hello"; + char str[20] = {0}; + + fp = fopen(TEST_FILE_PTAH_RIGHT, "w+"); + TEST_ASSERT_NOT_NULL(fp); + + ret = fputs(chr1, fp); + TEST_ASSERT_TRUE(ret != -1); + + ret = fclose(fp); + TEST_ASSERT_EQUAL_INT(ret, 0); +} + +/* * + * @tc.number SUB_KERNEL_FS_DIRNAME_039 + * @tc.name fputs + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(PosixFsFuncTestSuite, testFsFputs004, Function | MediumTest | Level1) +{ + int ret = 0; + FILE *fp = NULL; + const char chr1[10] = "hello"; + char str[20] = {0}; + + fp = fopen(TEST_FILE_PTAH_RIGHT, "w+"); + TEST_ASSERT_NOT_NULL(fp); + + ret = fputs(chr1, fp); + TEST_ASSERT_TRUE(ret != -1); + + (void)fseek (fp, 0L, SEEK_SET); + ret = fread(str, strlen(chr1) + 1, 1, fp); + TEST_ASSERT_TRUE(ret != -1); + + ret = strcmp(str, "hello"); + TEST_ASSERT_EQUAL_INT(ret, 0); + + ret = fclose(fp); + TEST_ASSERT_EQUAL_INT(ret, 0); +} + +/* * + * @tc.number SUB_KERNEL_FS_DIRNAME_040 + * @tc.name fputs + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(PosixFsFuncTestSuite, testFsFputs005, Function | MediumTest | Level1) +{ + int ret = 0; + FILE *fp = NULL; + const char chr1[10] = "hello"; + char str[20] = {0}; + int i; + + fp = fopen(TEST_FILE_PTAH_RIGHT, "w+"); + TEST_ASSERT_NOT_NULL(fp); + + for (i = 0; i < 200; i++) { + ret = fputs(chr1, fp); + TEST_ASSERT_TRUE(ret != -1); + } + + ret = ftell(fp); + TEST_ASSERT_EQUAL_INT(ret, 1000); + + ret = fclose(fp); + TEST_ASSERT_EQUAL_INT(ret, 0); +} + +/* * + * @tc.number SUB_KERNEL_FS_DIRNAME_041 + * @tc.name fread and fwrite + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(PosixFsFuncTestSuite, testFsFreadFwrite001, Function | MediumTest | Level1) +{ + int ret = 0; + FILE *fp = NULL; + long off = 0; + + const char chr1[10] = "hello"; + const char chr2[10] = "world"; + + char str[20] = {0}; + + fp = fopen(TEST_FILE_PTAH_RIGHT, "w"); + TEST_ASSERT_NOT_NULL(fp); + + ret = fwrite(chr1, strlen(chr1) + 1, 1, fp); + TEST_ASSERT_TRUE(ret != -1); + + ret = fclose(fp); + TEST_ASSERT_EQUAL_INT(ret, 0); +} + +/* * + * @tc.number SUB_KERNEL_FS_DIRNAME_042 + * @tc.name fread and fwrite + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(PosixFsFuncTestSuite, testFsFreadFwrite002, Function | MediumTest | Level1) +{ + int ret = 0; + FILE *fp = NULL; + long off = 0; + + const char chr1[10] = "hello"; + const char chr2[10] = "world"; + + char str[20] = {0}; + + fp = fopen(TEST_FILE_PTAH_RIGHT, "w"); + TEST_ASSERT_NOT_NULL(fp); + + ret = fwrite(0, 0, 1, fp); + TEST_ASSERT_TRUE(ret != -1); + + ret = fclose(fp); + TEST_ASSERT_EQUAL_INT(ret, 0); +} + +/* * + * @tc.number SUB_KERNEL_FS_DIRNAME_043 + * @tc.name fread and fwrite + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(PosixFsFuncTestSuite, testFsFreadFwrite003, Function | MediumTest | Level1) +{ + int ret = 0; + FILE *fp = NULL; + long off = 0; + + const char chr1[10] = "hello"; + const char chr2[10] = "world"; + + char str[20] = {0}; + + fp = fopen(TEST_FILE_PTAH_RIGHT, "r"); + TEST_ASSERT_NOT_NULL(fp); + + ret = fread(chr1, strlen(chr1) + 1, 1, fp); + TEST_ASSERT_TRUE(ret != -1); + + ret = fclose(fp); + TEST_ASSERT_EQUAL_INT(ret, 0); +} + +/* * + * @tc.number SUB_KERNEL_FS_DIRNAME_044 + * @tc.name fread and fwrite + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(PosixFsFuncTestSuite, testFsFreadFwrite004, Function | MediumTest | Level1) +{ + int ret = 0; + FILE *fp = NULL; + long off = 0; + + const char chr1[10] = "hello"; + const char chr2[10] = "world"; + + char str[20] = {0}; + + fp = fopen(TEST_FILE_PTAH_RIGHT, "r"); + TEST_ASSERT_NOT_NULL(fp); + + ret = fread(0, 0, 1, fp); + TEST_ASSERT_TRUE(ret != -1); + + ret = fclose(fp); + TEST_ASSERT_EQUAL_INT(ret, 0); +} + +/* * + * @tc.number SUB_KERNEL_FS_DIRNAME_045 + * @tc.name fread and fwrite + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(PosixFsFuncTestSuite, testFsFreadFwrite005, Function | MediumTest | Level1) +{ + int ret = 0; + FILE *fp = NULL; + long off = 0; + + const char chr1[10] = "hello"; + const char chr2[10] = "world"; + + char str[20] = {0}; + + fp = fopen(TEST_FILE_PTAH_RIGHT, "a"); + TEST_ASSERT_NOT_NULL(fp); + + ret = fwrite(chr1, strlen(chr1) + 1, 1, fp); + TEST_ASSERT_TRUE(ret != -1); + + ret = fclose(fp); + TEST_ASSERT_EQUAL_INT(ret, 0); +} + +/* * + * @tc.number SUB_KERNEL_FS_DIRNAME_046 + * @tc.name fread and fwrite + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(PosixFsFuncTestSuite, testFsFreadFwrite006, Function | MediumTest | Level1) +{ + int ret = 0; + FILE *fp = NULL; + long off = 0; + + const char chr1[10] = "hello"; + const char chr2[10] = "world"; + + char str[20] = {0}; + + fp = fopen(TEST_FILE_PTAH_RIGHT, "w+"); + TEST_ASSERT_NOT_NULL(fp); + + ret = fwrite(chr1, strlen(chr1) + 1, 1, fp); + TEST_ASSERT_TRUE(ret != -1); + + (void)fseek(fp, 0L, SEEK_SET); + + ret = fread(str, 20, 1, fp); + TEST_ASSERT_TRUE(ret != -1); + + ret = fwrite(chr2, strlen(chr2) + 1, 1, fp); + TEST_ASSERT_TRUE(ret != -1); + + (void)fseek(fp, 0L, SEEK_SET); + ret = fread(str, 20, 1, fp); + TEST_ASSERT_TRUE(ret != -1); + + ret = strcmp(str, "helloworld"); + TEST_ASSERT_EQUAL_INT(ret, 0); + + ret = fclose(fp); + TEST_ASSERT_EQUAL_INT(ret, 0); + +} + +/* * + * @tc.number SUB_KERNEL_FS_DIRNAME_047 + * @tc.name fread and fwrite + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(PosixFsFuncTestSuite, testFsFreadFwrite007, Function | MediumTest | Level1) +{ + int ret = 0; + FILE *fp = NULL; + long off = 0; + + const char chr1[10] = "hello"; + const char chr2[10] = "world"; + + char str[20] = {0}; + + fp = fopen(TEST_FILE_PTAH_RIGHT, "w+"); + TEST_ASSERT_NOT_NULL(fp); + + ret = fwrite(chr1, strlen(chr1) + 1, 1, fp); + TEST_ASSERT_TRUE(ret != -1); + + ret = fwrite(chr2, strlen(chr2) + 1, 1, fp); + TEST_ASSERT_TRUE(ret != -1); + + (void)fseek(fp, 0L, SEEK_SET); + + ret = fread(str, 20, 1, fp); + TEST_ASSERT_TRUE(ret != -1); + + ret = strcmp(str, "helloworld"); + TEST_ASSERT_EQUAL_INT(ret, 0); + + ret = fclose(fp); + TEST_ASSERT_EQUAL_INT(ret, 0); +} + +/* * + * @tc.number SUB_KERNEL_FS_DIRNAME_048 + * @tc.name fread and fwrite + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(PosixFsFuncTestSuite, testFsFreadFwrite008, Function | MediumTest | Level1) +{ + int ret = 0; + FILE *fp = NULL; + long off = 0; + int i; + + const char chr1[10] = "hello"; + const char chr2[10] = "world"; + + char str[30] = {0}; + + fp = fopen(TEST_FILE_PTAH_RIGHT, "w+"); + TEST_ASSERT_NOT_NULL(fp); + + for (i = 0; i < 200; i++) { + ret = fwrite(chr1, strlen(chr1) + 1, 1, fp); + TEST_ASSERT_TRUE(ret != -1); + } + + (void)fseek(fp, 100L, SEEK_SET); + + ret = fread(str, 20, 1, fp); + TEST_ASSERT_TRUE(ret != -1); + + ret = strcmp(str, "hellohellohellohello"); + TEST_ASSERT_EQUAL_INT(ret, 0); + + ret = fclose(fp); + TEST_ASSERT_EQUAL_INT(ret, 0); +} + +/* * + * @tc.number SUB_KERNEL_FS_DIRNAME_049 + * @tc.name fread and fwrite + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(PosixFsFuncTestSuite, testFsFreadFwrite009, Function | MediumTest | Level1) +{ + int ret = 0; + FILE *fp = NULL; + long off = 0; + int i; + + const char chr1[10] = "123456789"; + char str[30] = {0}; + + fp = fopen(TEST_FILE_PTAH_RIGHT, "w+"); + TEST_ASSERT_NOT_NULL(fp); + + for (i = 0; i < 200; i++) { + ret = fwrite(chr1, 5, 1, fp); + TEST_ASSERT_TRUE(ret != -1); + } + + (void)fseek(fp, 100L, SEEK_SET); + + for (i = 0; i < 10; i++) { + + ret = fread(str, 20, 1, fp); + TEST_ASSERT_TRUE(ret != -1); + } + ret = strcmp(str, "1234512345123451234512345"); + TEST_ASSERT_EQUAL_INT(ret, 0); + + ret = fclose(fp); + TEST_ASSERT_EQUAL_INT(ret, 0); +} + +/* * + * @tc.number SUB_KERNEL_FS_DIRNAME_050 + * @tc.name readdir + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(PosixFsFuncTestSuite, testFsReaddir001, Function | MediumTest | Level1) +{ + DIR *dirp; + struct dirent *dResult; + + dirp = opendir(DIR1); + TEST_ASSERT_NOT_NULL(dirp); + + dResult = readdir(dirp); + TEST_ASSERT_NOT_NULL(dResult); +} + +/* * + * @tc.number SUB_KERNEL_FS_DIRNAME_051 + * @tc.name readdir + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(PosixFsFuncTestSuite, testFsReaddir002, Function | MediumTest | Level1) +{ + DIR *dirp; + struct dirent *dResult; + long tellDir0; + long tellDir1; + long tellDir2; + + dirp = opendir(DIR1); + TEST_ASSERT_NOT_NULL(dirp); + + dResult = readdir(dirp); + TEST_ASSERT_NOT_NULL(dirp); + tellDir0 = dResult->d_off; + TEST_ASSERT_TRUE(tellDir0 == tellDir1); + + dResult = readdir(dirp); + TEST_ASSERT_NOT_NULL(dirp); + tellDir1 = dResult->d_off; + + rewinddir(dirp); + dResult = readdir(dirp); + TEST_ASSERT_NOT_NULL(dirp); + tellDir2 = dResult->d_off; + + TEST_ASSERT_TRUE(tellDir0 == tellDir2); +} + +/* * + * @tc.number SUB_KERNEL_FS_DIRNAME_052 + * @tc.name remove + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(PosixFsFuncTestSuite, testFsRemove001, Function | MediumTest | Level1) +{ + FILE *fp = NULL; + int ret = 0; + + fp = fopen(TEST_FILE_PTAH_RIGHT, "w"); + fclose(fp); + ret = remove(TEST_FILE_PTAH_RIGHT); + TEST_ASSERT_EQUAL_INT(ret, 0); +} + +/* * + * @tc.number SUB_KERNEL_FS_DIRNAME_053 + * @tc.name remove + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(PosixFsFuncTestSuite, testFsRemove002, Function | MediumTest | Level1) +{ + int ret = 0; + + ret = mkdir("a", 0777); + TEST_ASSERT_EQUAL_INT(ret, 0); + ret = remove("a"); + TEST_ASSERT_EQUAL_INT(ret, 0); +} + +/* * + * @tc.number SUB_KERNEL_FS_DIRNAME_054 + * @tc.name rmdir + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(PosixFsFuncTestSuite, testFsRmdir001, Function | MediumTest | Level1) +{ + int ret = 0; + + ret = mkdir("a", 0777); + TEST_ASSERT_EQUAL_INT(ret, 0); + + ret = mkdir("a/b", 0777); + TEST_ASSERT_EQUAL_INT(ret, 0); + + ret = rmdir("a/b"); + TEST_ASSERT_EQUAL_INT(ret, 0); + + ret = rmdir("a"); + TEST_ASSERT_EQUAL_INT(ret, 0); +} + +/* * + * @tc.number SUB_KERNEL_FS_DIRNAME_055 + * @tc.name rmdir + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(PosixFsFuncTestSuite, testFsRmdir002, Function | MediumTest | Level1) +{ + int ret = 0; + + ret = mkdir("a", 0777); + TEST_ASSERT_EQUAL_INT(ret, 0); + + ret = mkdir("a/b", 0777); + TEST_ASSERT_EQUAL_INT(ret, 0); + + ret = mkdir("a/c", 0777); + TEST_ASSERT_EQUAL_INT(ret, 0); + + ret = rmdir("a/b"); + TEST_ASSERT_EQUAL_INT(ret, 0); + + ret = rmdir("a/c"); + TEST_ASSERT_EQUAL_INT(ret, 0); + + ret = rmdir("a"); + TEST_ASSERT_EQUAL_INT(ret, 0); +} + +/* * + * @tc.number SUB_KERNEL_FS_DIRNAME_056 + * @tc.name rmdir + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(PosixFsFuncTestSuite, testFsRmdir003, Function | MediumTest | Level1) +{ + int ret = 0; + + ret = mkdir("a", 0777); + TEST_ASSERT_EQUAL_INT(ret, 0); + + ret = mkdir("a/b", 0777); + TEST_ASSERT_EQUAL_INT(ret, 0); + + ret = mkdir("a/c", 0777); + TEST_ASSERT_EQUAL_INT(ret, 0); + + ret = rmdir("a/b"); + TEST_ASSERT_EQUAL_INT(ret, 0); + + ret = rmdir("a"); + TEST_ASSERT_EQUAL_INT(ret, 0); + + ret = rmdir("a/c"); + TEST_ASSERT_EQUAL_INT(ret, -1); +} + +/* * + * @tc.number SUB_KERNEL_FS_DIRNAME_057 + * @tc.name unlink + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(PosixFsFuncTestSuite, testFsUnlink001, Function | MediumTest | Level1) +{ + int ret = 0; + int fd = 0; + char tmpFileName[]= "test"; + + fd = open(tmpFileName, O_RDWR); + TEST_ASSERT_TRUE(ret != -1); + + (void)close(fd); + ret = unlink(tmpFileName); + TEST_ASSERT_TRUE(ret != -1); +} + +/* * + * @tc.number SUB_KERNEL_FS_DIRNAME_058 + * @tc.name unlink + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(PosixFsFuncTestSuite, testFsUnlink002, Function | MediumTest | Level1) +{ + int ret = 0; + int fd = 0; + char tmpFileName[5]= "test"; + + fd = creat(tmpFileName, 0777); + TEST_ASSERT_TRUE(ret != -1); + + ret = unlink(tmpFileName); + TEST_ASSERT_TRUE(ret != -1); +} + +/* * + * @tc.number SUB_KERNEL_FS_DIRNAME_059 + * @tc.name unlink + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(PosixFsFuncTestSuite, testFsStat001, Function | MediumTest | Level1) +{ + struct stat buf; + int fd = 0; + char tmpFileName[5]= "test"; + int ret = 0; + + fd = open(tmpFileName, O_CREAT | O_RDWR, 0777); + TEST_ASSERT_TRUE(ret != -1); + + (void)close(fd); + + ret = stat(tmpFileName, &buf); + TEST_ASSERT_TRUE(ret != -1); +} + +/* * + * @tc.number SUB_KERNEL_FS_DIRNAME_060 + * @tc.name unlink + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(PosixFsFuncTestSuite, testFsStat002, Function | MediumTest | Level1) +{ + struct stat buf; + int fd = 0; + char tmpFileName[5]= "test"; + int ret = 0; + ssize_t size = 0; + char writeBuf[] = "write test"; + + fd = open(tmpFileName, O_CREAT | O_RDWR, 0777); + TEST_ASSERT_TRUE(ret != -1); + + size = write(fd, writeBuf, sizeof(writeBuf)); + TEST_ASSERT_TRUE(ret != -1); + (void)close(fd); + + ret = stat(tmpFileName, &buf); + TEST_ASSERT_TRUE(ret != -1); + + TEST_ASSERT_TRUE(buf.st_size == sizeof(writeBuf)); +} + +/* * + * @tc.number SUB_KERNEL_FS_DIRNAME_061 + * @tc.name unlink + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(PosixFsFuncTestSuite, testFsStat003, Function | MediumTest | Level1) +{ + struct stat buf; + int fd; + char tmpFileName[5]= "test"; + int ret = 0; + ssize_t size; + char writeBuf[] = "write test"; + + fd = open(tmpFileName, O_CREAT | O_RDWR, 0777); + TEST_ASSERT_TRUE(ret != -1); + + size = write(fd, writeBuf, sizeof(writeBuf)); + TEST_ASSERT_TRUE(ret != -1); + (void)close(fd); + + ret = stat(tmpFileName, &buf); + TEST_ASSERT_TRUE(ret != -1); + + TEST_ASSERT_EQUAL_INT(buf.st_rdev, 0); +} + +/* * + * @tc.number SUB_KERNEL_FS_DIRNAME_062 + * @tc.name unlink + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(PosixFsFuncTestSuite, testFsWrite001, Function | MediumTest | Level1) +{ + int reLseek; + int fd = 0; + char writeBuf[100]; + int ret = 0; + char tmpFileName[5]= "test"; + + for (int i = 0; i < 100; i++) { + writeBuf[i] = '1'; + } + + fd = open(tmpFileName, O_CREAT | O_RDWR, 0777); + TEST_ASSERT_TRUE(ret != -1); + + ret = write(fd, writeBuf, 20); + TEST_ASSERT_TRUE(ret != -1); + + reLseek = lseek(fd, 0, SEEK_CUR); + + ret = write(fd, writeBuf, 20); + TEST_ASSERT_TRUE(ret != -1); + + reLseek = lseek(fd, 0, SEEK_CUR); + + TEST_ASSERT_TRUE(40 == reLseek); + + (void)close(fd); +} + +/* * + * @tc.number SUB_KERNEL_FS_DIRNAME_063 + * @tc.name unlink + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(PosixFsFuncTestSuite, testFsWrite002, Function | MediumTest | Level1) +{ + int fd = 0; + char writeBuf[] = "123456789"; + int ret = 0; + struct stat statbuf; + char tmpFileName[5]= "test"; + + fd = open(tmpFileName, O_CREAT | O_RDWR, 0777); + TEST_ASSERT_TRUE(ret != -1); + + ret = write(fd, writeBuf, 20); + TEST_ASSERT_TRUE(ret != -1); + + ret = stat(tmpFileName, &statbuf); + TEST_ASSERT_TRUE(ret != -1); + + TEST_ASSERT_TRUE(statbuf.st_size == sizeof(writeBuf)); + + (void)close(fd); +} + RUN_TEST_SUITE(PosixFsFuncTestSuite); @@ -154,5 +1568,76 @@ void PosixFsFuncTest() RUN_ONE_TESTCASE(testFsDirname003); RUN_ONE_TESTCASE(testFsDirname004); + RUN_ONE_TESTCASE(testFsFopenFclose001); + RUN_ONE_TESTCASE(testFsFopenFclose002); + RUN_ONE_TESTCASE(testFsFopenFclose003); + RUN_ONE_TESTCASE(testFsFopenFclose004); + RUN_ONE_TESTCASE(testFsFopenFclose005); + RUN_ONE_TESTCASE(testFsFopenFclose006); + RUN_ONE_TESTCASE(testFsFopenFclose007); + RUN_ONE_TESTCASE(testFsFopenFclose008); + RUN_ONE_TESTCASE(testFsFopenFclose009); + RUN_ONE_TESTCASE(testFsFopenFclose010); + RUN_ONE_TESTCASE(testFsFopenFclose011); + + RUN_ONE_TESTCASE(testFsFdopen001); + RUN_ONE_TESTCASE(testFsFdopen002); + RUN_ONE_TESTCASE(testFsFdopen003); + RUN_ONE_TESTCASE(testFsFdopen004); + + + RUN_ONE_TESTCASE(testFsFtellFseek001); + RUN_ONE_TESTCASE(testFsFtellFseek002); + RUN_ONE_TESTCASE(testFsFtellFseek003); + RUN_ONE_TESTCASE(testFsFtellFseek004); + RUN_ONE_TESTCASE(testFsFtellFseek005); + RUN_ONE_TESTCASE(testFsFtellFseek006); + RUN_ONE_TESTCASE(testFsFtellFseek007); + RUN_ONE_TESTCASE(testFsFtellFseek008); + RUN_ONE_TESTCASE(testFsFtellFseek009); + RUN_ONE_TESTCASE(testFsFtellFseek010); + RUN_ONE_TESTCASE(testFsFtellFseek011); + RUN_ONE_TESTCASE(testFsFtellFseek012); + RUN_ONE_TESTCASE(testFsFtellFseek013); + RUN_ONE_TESTCASE(testFsFtellFseek014); + RUN_ONE_TESTCASE(testFsFtellFseek015); + RUN_ONE_TESTCASE(testFsFtellFseek016); + + RUN_ONE_TESTCASE(testFsFputs001); + RUN_ONE_TESTCASE(testFsFputs002); + RUN_ONE_TESTCASE(testFsFputs003); + RUN_ONE_TESTCASE(testFsFputs004); + RUN_ONE_TESTCASE(testFsFputs005); + + RUN_ONE_TESTCASE(testFsFreadFwrite001); + RUN_ONE_TESTCASE(testFsFreadFwrite002); + RUN_ONE_TESTCASE(testFsFreadFwrite003); + RUN_ONE_TESTCASE(testFsFreadFwrite004); + RUN_ONE_TESTCASE(testFsFreadFwrite005); + RUN_ONE_TESTCASE(testFsFreadFwrite006); + RUN_ONE_TESTCASE(testFsFreadFwrite007); + RUN_ONE_TESTCASE(testFsFreadFwrite008); + RUN_ONE_TESTCASE(testFsFreadFwrite009); + + RUN_ONE_TESTCASE(testFsReaddir001); + RUN_ONE_TESTCASE(testFsReaddir002); + + RUN_ONE_TESTCASE(testFsRemove001); + RUN_ONE_TESTCASE(testFsRemove002); + + RUN_ONE_TESTCASE(testFsRmdir001); + RUN_ONE_TESTCASE(testFsRmdir002); + RUN_ONE_TESTCASE(testFsRmdir003); + + RUN_ONE_TESTCASE(testFsUnlink001); + RUN_ONE_TESTCASE(testFsUnlink002); + + RUN_ONE_TESTCASE(testFsStat001); + RUN_ONE_TESTCASE(testFsStat002); + RUN_ONE_TESTCASE(testFsStat003); + + RUN_ONE_TESTCASE(testFsWrite001); + RUN_ONE_TESTCASE(testFsWrite002); + return; -} \ No newline at end of file +} diff --git a/third_party/FatFs b/third_party/FatFs deleted file mode 160000 index c9c6b40b..00000000 --- a/third_party/FatFs +++ /dev/null @@ -1 +0,0 @@ -Subproject commit c9c6b40b5ce3cc87735229cd2b4b25eab98efb78 diff --git a/third_party/bounds_checking_function b/third_party/bounds_checking_function deleted file mode 160000 index 7052dd04..00000000 --- a/third_party/bounds_checking_function +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 7052dd04a101eaf6a8f5acba8b675cdda4778d0a diff --git a/third_party/cmsis b/third_party/cmsis deleted file mode 160000 index 2ab5422f..00000000 --- a/third_party/cmsis +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 2ab5422fccd0ac2583fb616ee52051f6a043506a diff --git a/utils/BUILD.gn b/utils/BUILD.gn index 202eab8a..f23ddc0c 100644 --- a/utils/BUILD.gn +++ b/utils/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: diff --git a/utils/internal/los_hook_types.h b/utils/internal/los_hook_types.h index ca4760d4..999c90cf 100644 --- a/utils/internal/los_hook_types.h +++ b/utils/internal/los_hook_types.h @@ -57,11 +57,11 @@ extern "C" { LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_MEM_REALLOC, (VOID *pool, VOID *ptr, UINT32 size)) \ LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_MEM_ALLOCALIGN, (VOID *pool, UINT32 size, UINT32 boundary)) \ /* Hook types supported by event modules */ \ - LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_EVENT_INIT, (VOID)) \ + LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_EVENT_INIT, (PEVENT_CB_S eventCB)) \ LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_EVENT_READ, (PEVENT_CB_S eventCB, UINT32 eventMask, UINT32 mode)) \ LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_EVENT_WRITE, (PEVENT_CB_S eventCB)) \ LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_EVENT_CLEAR, (PEVENT_CB_S eventCB)) \ - LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_EVENT_DESTROY, (VOID)) \ + LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_EVENT_DESTROY, (PEVENT_CB_S eventCB)) \ /* Hook types supported by queue modules */ \ LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_QUEUE_CREATE, (const LosQueueCB *queueCB)) \ LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_QUEUE_READ, (const LosQueueCB *queueCB)) \ diff --git a/utils/internal/los_hook_types_parse.h b/utils/internal/los_hook_types_parse.h index e8407a2e..287ad81a 100644 --- a/utils/internal/los_hook_types_parse.h +++ b/utils/internal/los_hook_types_parse.h @@ -61,8 +61,10 @@ #define PARAM_TO_ARGS6(a, b, c, d, e, f) ARG(a), PARAM_TO_ARGS5(b, c, d, e, f) #define PARAM_TO_ARGS7(a, b, c, d, e, f, g) ARG(a), PARAM_TO_ARGS6(b, c, d, e, f, g) -#define __NARGS(a, b, c, d, e, f, g, h, n, ...) n -#define _NARGS(...) __NARGS(x, ##__VA_ARGS__, 7, 6, 5, 4, 3, 2, 1, 0, ) +#define _ZERO_ARGS 7, 6, 5, 4, 3, 2, 1, 0 +#define ___NARGS(a, b, c, d, e, f, g, h, n, ...) n +#define __NARGS(...) ___NARGS(__VA_ARGS__) +#define _NARGS(...) __NARGS(x, __VA_ARGS__##_ZERO_ARGS, 7, 6, 5, 4, 3, 2, 1, 0) #define __CONCAT(a, b) a##b #define _CONCAT(a, b) __CONCAT(a, b) diff --git a/utils/los_compiler.h b/utils/los_compiler.h index faf58bb4..fc36cc9f 100644 --- a/utils/los_compiler.h +++ b/utils/los_compiler.h @@ -335,7 +335,7 @@ typedef signed int INTPTR; #ifdef __cplusplus #define NULL 0L #else -#define NULL ((VOID *)0) +#define NULL ((void*)0) #endif #endif @@ -411,10 +411,7 @@ static inline UINT32 LOS_Align(UINT32 addr, UINT32 boundary) } while (0) #ifndef UNUSED -#define UNUSED(var) \ - do { \ - (void)var; \ - } while (0) +#define UNUSED(X) (void)X #endif #ifdef __cplusplus