Compare commits
127 Commits
weekly_202
...
weekly_202
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
831d089652 | ||
|
|
f5fa92feff | ||
|
|
bed1d28df8 | ||
|
|
efebc00f87 | ||
|
|
28c1529e2f | ||
|
|
159d304275 | ||
|
|
18f65ae0b3 | ||
|
|
5363e4b472 | ||
|
|
c65d908905 | ||
|
|
1b9d59aa9a | ||
|
|
c6958aa181 | ||
|
|
315a448142 | ||
|
|
32a2e193f4 | ||
|
|
b35792fa6c | ||
|
|
a5e651cb01 | ||
|
|
f12dd8bbe6 | ||
|
|
3f41c36926 | ||
|
|
a3daa77e53 | ||
|
|
fb740f9b23 | ||
|
|
a45bf8797c | ||
|
|
84f89b9660 | ||
|
|
03b4650a16 | ||
|
|
728aca27f5 | ||
|
|
91743d3ea4 | ||
|
|
fcd677feba | ||
|
|
c4fd9be138 | ||
|
|
81249a0384 | ||
|
|
8746f5abe5 | ||
|
|
56565beeb6 | ||
|
|
a77aa7de98 | ||
|
|
db8c284cd1 | ||
|
|
b1daca7f82 | ||
|
|
46546688c9 | ||
|
|
d017af7459 | ||
|
|
4e9f8c71f9 | ||
|
|
e34c4050f9 | ||
|
|
67b579161d | ||
|
|
d5b90399b7 | ||
|
|
1ab2ffcd4a | ||
|
|
ec9f0e47e9 | ||
|
|
8550117b01 | ||
|
|
f29973e995 | ||
|
|
9e0e39f277 | ||
|
|
2f19ba3653 | ||
|
|
fe7191183e | ||
|
|
d84471ff29 | ||
|
|
45654cee93 | ||
|
|
110ee01118 | ||
|
|
b51e7f93d4 | ||
|
|
2d9e476c0b | ||
|
|
9ee49f1bb8 | ||
|
|
befe8ecf9d | ||
|
|
637de91170 | ||
|
|
390a488a97 | ||
|
|
9d3d983376 | ||
|
|
0e2dded346 | ||
|
|
b0393151a6 | ||
|
|
38f8472ddb | ||
|
|
7167ba7578 | ||
|
|
d28c8a0423 | ||
|
|
17daa50fa2 | ||
|
|
57a0002252 | ||
|
|
4f12ab9a2a | ||
|
|
e703376d68 | ||
|
|
8f1dc3a1ff | ||
|
|
9bf8ff9ce5 | ||
|
|
a09d4882c4 | ||
|
|
98a82ba357 | ||
|
|
e7e850a6a6 | ||
|
|
3ad47afec4 | ||
|
|
6f04b5345c | ||
|
|
83b6331aad | ||
|
|
67a5b580f6 | ||
|
|
f5ee192962 | ||
|
|
a42ba7aed6 | ||
|
|
1fc024a158 | ||
|
|
21ee0b2c1d | ||
|
|
b0cfa5e52c | ||
|
|
543732f522 | ||
|
|
dab1a0d62f | ||
|
|
6a8f24ba01 | ||
|
|
40bbb4d6c4 | ||
|
|
90a027090a | ||
|
|
bcd177bbd3 | ||
|
|
cde2b3bd31 | ||
|
|
e3e9b2f5a5 | ||
|
|
536e9b4584 | ||
|
|
632ea10418 | ||
|
|
73b77d11a1 | ||
|
|
9aa32ae743 | ||
|
|
133e87b1b1 | ||
|
|
09034de68a | ||
|
|
867a6edcdc | ||
|
|
3dceae52aa | ||
|
|
43baa4fdc4 | ||
|
|
bedef30658 | ||
|
|
7e284239b3 | ||
|
|
f34b94e98d | ||
|
|
bc33bcd319 | ||
|
|
ae7a374ebb | ||
|
|
fb76350771 | ||
|
|
ea5b2e8ae4 | ||
|
|
c5a3ed4fb1 | ||
|
|
7688a3f52d | ||
|
|
590ab9182d | ||
|
|
ed863e90dd | ||
|
|
491cefae76 | ||
|
|
36887d467d | ||
|
|
9f393bcc6d | ||
|
|
fe4db41b7c | ||
|
|
5c982f1087 | ||
|
|
9a3745384a | ||
|
|
0245b1a7b2 | ||
|
|
d4d59cf08f | ||
|
|
692651fe40 | ||
|
|
e4d08ba896 | ||
|
|
021e5299ab | ||
|
|
16e87d78d8 | ||
|
|
96cc92d035 | ||
|
|
4983542b46 | ||
|
|
6c68adad4d | ||
|
|
6efd469a4f | ||
|
|
cc57f81ab8 | ||
|
|
5dbac3ab4c | ||
|
|
60805e1a7c | ||
|
|
7cf08722a0 | ||
|
|
21b46e82f3 |
24
Kconfig
24
Kconfig
@@ -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) 2020-2022 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:
|
||||
@@ -317,7 +317,7 @@ config CPUP_INCLUDE_IRQ
|
||||
help
|
||||
If you wish to include irq usage for cpup.
|
||||
|
||||
config DYNLINK
|
||||
config KERNEL_DYNLINK
|
||||
bool "Enable Dynamic Link Feature"
|
||||
default n
|
||||
depends on KERNEL_EXTKERNEL && ARCH_ARM
|
||||
@@ -369,7 +369,7 @@ config KERNEL_LMK
|
||||
default n
|
||||
depends on KERNEL_EXTKERNEL
|
||||
help
|
||||
Configuration item for low momery killer tailoring.
|
||||
Configuration item for low memory killer tailoring.
|
||||
If you wish to build LiteOS with support for low memory killer.
|
||||
|
||||
config KERNEL_LMK_DEBUG
|
||||
@@ -554,6 +554,13 @@ config SHELL_CMD_DEBUG
|
||||
default n
|
||||
depends on DEBUG_VERSION && SHELL
|
||||
|
||||
config DEBUG_TOOLS
|
||||
bool "Enable DEBUG TOOLS"
|
||||
default n
|
||||
depends on DEBUG_VERSION
|
||||
help
|
||||
Answer Y to enable LiteOS debug tools, include stackdump, hwidump, tasktrack.
|
||||
|
||||
config USB_DEBUG
|
||||
bool "Enable USB Debug"
|
||||
default n
|
||||
@@ -574,7 +581,7 @@ config MEM_LEAKCHECK
|
||||
depends on DEBUG_VERSION && MEM_DEBUG
|
||||
select KERNEL_BACKTRACE
|
||||
help
|
||||
Answer Y to enable record the LR of Function call stack of Mem operation, it can check the mem leak through the infomations of mem node.
|
||||
Answer Y to enable record the LR of Function call stack of Mem operation, it can check the mem leak through the informations of mem node.
|
||||
config BASE_MEM_NODE_INTEGRITY_CHECK
|
||||
bool "Enable integrity check or not"
|
||||
default n
|
||||
@@ -600,11 +607,11 @@ endmenu
|
||||
|
||||
######################## config options os security #######################
|
||||
menu "Security"
|
||||
osource "security/Kconfig"
|
||||
config SECURE_TRUSTZONE
|
||||
bool "Enable ARM TrustZone"
|
||||
default n
|
||||
depends on ARCH_ARM
|
||||
depends on ARCH_ARM_V8M
|
||||
config SECURE_HEAP_SIZE
|
||||
int "TrustZone Heap Size (bytes)"
|
||||
default 2048
|
||||
@@ -615,6 +622,13 @@ config SECURE_STACK_DEFAULT_SIZE
|
||||
depends on SECURE_TRUSTZONE
|
||||
help
|
||||
The secure stack must be allocated before the task calls non-secure functions.
|
||||
config SECURE
|
||||
bool "Enable Security"
|
||||
default n
|
||||
select MPU_ENABLE
|
||||
config MPU_ENABLE
|
||||
bool "Enable MPU"
|
||||
default n
|
||||
endmenu
|
||||
|
||||
menu "Test"
|
||||
|
||||
@@ -85,11 +85,11 @@ Before setting up the environment for a development board, you must set up the b
|
||||
|
||||
For details about how to obtain the source code, see [Source Code Acquisition](https://gitee.com/openharmony/docs/blob/HEAD/en/device-dev/get-code/sourcecode-acquire.md). This document assumes that the clone directory is `~/openHarmony` after the complete OpenHarmony repository code is obtained.
|
||||
|
||||
### Example projects that are already supported
|
||||
### Example projects
|
||||
|
||||
Qemu simulator: `arm_mps2_an386、esp32、riscv32_virt、SmartL_E802`, For details about how to compile and run, see [qemu guide](https://gitee.com/openharmony/device_qemu)
|
||||
Qemu simulator: `arm_mps2_an386、esp32、riscv32_virt、SmartL_E802`. For details about how to compile and run, see [qemu guide](https://gitee.com/openharmony/device_qemu).
|
||||
|
||||
Bestechnic: `bes2600`, For details about how to compile and run, see [Bestechnic developer guide](https://gitee.com/openharmony/device_soc_bestechnic)
|
||||
Bestechnic: `bes2600`. For details about how to compile and run, see [Bestechnic developer guide](https://gitee.com/openharmony/device_soc_bestechnic).
|
||||
|
||||
### Community Porting Project Links
|
||||
|
||||
@@ -131,4 +131,4 @@ How to contribute a chip based on Liteos-M kernel:
|
||||
|
||||
[Kernel Subsystem](https://gitee.com/openharmony/docs/blob/HEAD/en/readme/kernel-subsystem.md)
|
||||
|
||||
**kernel\_liteos\_m**
|
||||
[kernel\_liteos\_m](https://gitee.com/openharmony/kernel_liteos_m/blob/master/README.md)
|
||||
|
||||
@@ -131,5 +131,5 @@ LiteOS-M内核移植的具体开发板的工程由社区开发者提供,可以
|
||||
|
||||
[内核子系统](https://gitee.com/openharmony/docs/blob/HEAD/zh-cn/readme/%E5%86%85%E6%A0%B8%E5%AD%90%E7%B3%BB%E7%BB%9F.md)
|
||||
|
||||
**kernel\_liteos\_m**
|
||||
[kernel\_liteos\_m](https://gitee.com/openharmony/kernel_liteos_m/blob/master/README_zh.md)
|
||||
|
||||
|
||||
@@ -39,7 +39,8 @@ module_group("arch") {
|
||||
"$board_cpu" == "cortex-m4" || "$board_cpu" == "cortex-m7" ||
|
||||
"$board_cpu" == "cortex-m33" || "$board_cpu" == "cortex-m55") {
|
||||
modules += [ "arm" ]
|
||||
} else if ("$board_cpu" == "ck802" || "$board_cpu" == "e802") {
|
||||
} else if ("$board_cpu" == "ck802" || "$board_cpu" == "e802" ||
|
||||
"$board_cpu" == "ck804ef") {
|
||||
modules += [ "csky" ]
|
||||
} else if ("$board_cpu" == "") {
|
||||
if ("$board_arch" == "rv32imac" || "$board_arch" == "rv32imafdc") {
|
||||
|
||||
@@ -16,12 +16,16 @@ config ARCH_ARM_AARCH32
|
||||
config ARCH_ARM_V7M
|
||||
bool
|
||||
|
||||
config ARCH_ARM_V8M
|
||||
bool
|
||||
|
||||
config ARCH_ARM_V5TE
|
||||
bool
|
||||
|
||||
config ARCH_ARM_VER
|
||||
string
|
||||
default "armv7-m" if ARCH_ARM_V7M
|
||||
default "armv8-m" if ARCH_ARM_V8M
|
||||
default "armv5te" if ARCH_ARM_V5TE
|
||||
|
||||
#
|
||||
@@ -84,23 +88,20 @@ config ARCH_CORTEX_M7
|
||||
select ARCH_ARM_AARCH32
|
||||
select ARCH_FPU_VFP_V4
|
||||
select ARCH_FPU_VFP_D32
|
||||
select ARCH_FPU_VFP_NEON
|
||||
|
||||
config ARCH_CORTEX_M33
|
||||
bool
|
||||
select ARCH_ARM_V7M
|
||||
select ARCH_ARM_V8M
|
||||
select ARCH_ARM_AARCH32
|
||||
select ARCH_FPU_VFP_V4
|
||||
select ARCH_FPU_VFP_D32
|
||||
select ARCH_FPU_VFP_NEON
|
||||
|
||||
config ARCH_CORTEX_M55
|
||||
bool
|
||||
select ARCH_ARM_V7M
|
||||
select ARCH_ARM_V8M
|
||||
select ARCH_ARM_AARCH32
|
||||
select ARCH_FPU_VFP_V4
|
||||
select ARCH_FPU_VFP_D32
|
||||
select ARCH_FPU_VFP_NEON
|
||||
|
||||
config ARCH_ARM9
|
||||
bool
|
||||
|
||||
@@ -76,6 +76,7 @@ LITE_OS_SEC_TEXT_MINOR VOID ArchSysExit(VOID)
|
||||
LITE_OS_SEC_TEXT_INIT VOID *ArchTskStackInit(UINT32 taskID, UINT32 stackSize, VOID *topStack)
|
||||
{
|
||||
TaskContext *context = (TaskContext *)((UINTPTR)topStack + stackSize - sizeof(TaskContext));
|
||||
LosTaskCB *taskCB = OS_TCB_FROM_TID(taskID);
|
||||
|
||||
context->r0 = taskID;
|
||||
context->r1 = 0x01010101L;
|
||||
|
||||
@@ -39,6 +39,9 @@
|
||||
#include "los_sched.h"
|
||||
#include "los_memory.h"
|
||||
#include "los_membox.h"
|
||||
#if (LOSCFG_CPUP_INCLUDE_IRQ == 1)
|
||||
#include "los_cpup.h"
|
||||
#endif
|
||||
#include "los_reg.h"
|
||||
|
||||
#define OS_INT_IRQ_ENABLE (1U << 0)
|
||||
@@ -61,6 +64,30 @@ ExcInfo g_excInfo = {0};
|
||||
*/
|
||||
STATIC HWI_PROC_FUNC g_hwiForm[OS_VECTOR_CNT] = {0};
|
||||
|
||||
#if (LOSCFG_DEBUG_TOOLS == 1)
|
||||
STATIC UINT32 g_hwiFormCnt[OS_HWI_MAX_NUM] = {0};
|
||||
STATIC CHAR *g_hwiFormName[OS_HWI_MAX_NUM] = {0};
|
||||
|
||||
UINT32 OsGetHwiFormCnt(UINT32 index)
|
||||
{
|
||||
return g_hwiFormCnt[index];
|
||||
}
|
||||
|
||||
CHAR *OsGetHwiFormName(UINT32 index)
|
||||
{
|
||||
return g_hwiFormName[index];
|
||||
}
|
||||
|
||||
BOOL OsGetHwiCreated(UINT32 index)
|
||||
{
|
||||
if (g_hwiForm[index] != (HWI_PROC_FUNC)HalHwiDefaultHandler) {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if (LOSCFG_PLATFORM_HWI_WITH_ARG == 1)
|
||||
|
||||
typedef struct {
|
||||
@@ -163,11 +190,9 @@ inline UINT32 ArchIsIntActive(VOID)
|
||||
Output : None
|
||||
Return : None
|
||||
**************************************************************************** */
|
||||
/*lint -e529*/
|
||||
LITE_OS_SEC_TEXT_MINOR VOID HalHwiDefaultHandler(VOID)
|
||||
{
|
||||
UINT32 irqNum = HwiNumGet();
|
||||
PRINT_ERR("%s irqnum:%u\n", __FUNCTION__, irqNum);
|
||||
PRINT_ERR("%s irqnum:%u\n", __FUNCTION__, HwiNumGet());
|
||||
while (1) {}
|
||||
}
|
||||
|
||||
@@ -206,6 +231,9 @@ LITE_OS_SEC_TEXT VOID HalInterrupt(VOID)
|
||||
hwiIndex = HwiNumGet();
|
||||
|
||||
OsHookCall(LOS_HOOK_TYPE_ISR_ENTER, hwiIndex);
|
||||
#if (LOSCFG_CPUP_INCLUDE_IRQ == 1)
|
||||
OsCpupIrqStart(hwiIndex);
|
||||
#endif
|
||||
|
||||
HalPreInterruptHandler(hwiIndex);
|
||||
|
||||
@@ -219,8 +247,16 @@ LITE_OS_SEC_TEXT VOID HalInterrupt(VOID)
|
||||
}
|
||||
#endif
|
||||
|
||||
#if (LOSCFG_DEBUG_TOOLS == 1)
|
||||
++g_hwiFormCnt[hwiIndex];
|
||||
#endif
|
||||
|
||||
HalAftInterruptHandler(hwiIndex);
|
||||
|
||||
#if (LOSCFG_CPUP_INCLUDE_IRQ == 1)
|
||||
OsCpupIrqEnd(hwiIndex);
|
||||
#endif
|
||||
|
||||
OsHookCall(LOS_HOOK_TYPE_ISR_EXIT, hwiIndex);
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
@@ -233,22 +269,22 @@ LITE_OS_SEC_TEXT VOID HalInterrupt(VOID)
|
||||
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
|
||||
hwiMode --- unused
|
||||
hwiHandler --- hwi handler
|
||||
irqParam --- param of the hwi handler
|
||||
Output : None
|
||||
Return : LOS_OK on success or error code on failure
|
||||
**************************************************************************** */
|
||||
LITE_OS_SEC_TEXT_INIT UINT32 ArchHwiCreate(HWI_HANDLE_T hwiNum,
|
||||
HWI_PRIOR_T hwiPrio,
|
||||
HWI_MODE_T mode,
|
||||
HWI_PROC_FUNC handler,
|
||||
HWI_ARG_T arg)
|
||||
HWI_MODE_T hwiMode,
|
||||
HWI_PROC_FUNC hwiHandler,
|
||||
HwiIrqParam *irqParam)
|
||||
{
|
||||
(VOID)mode;
|
||||
(VOID)hwiMode;
|
||||
UINT32 intSave;
|
||||
|
||||
if (handler == NULL) {
|
||||
if (hwiHandler == NULL) {
|
||||
return OS_ERRNO_HWI_PROC_FUNC_NULL;
|
||||
}
|
||||
|
||||
@@ -262,10 +298,20 @@ LITE_OS_SEC_TEXT_INIT UINT32 ArchHwiCreate(HWI_HANDLE_T hwiNum,
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
#if (LOSCFG_PLATFORM_HWI_WITH_ARG == 1)
|
||||
OsSetVector(hwiNum, handler, arg);
|
||||
if (irqParam != NULL) {
|
||||
OsSetVector(hwiNum, hwiHandler, irqParam->pDevId);
|
||||
} else {
|
||||
OsSetVector(hwiNum, hwiHandler, NULL);
|
||||
}
|
||||
#else
|
||||
(VOID)arg;
|
||||
OsSetVector(hwiNum, handler);
|
||||
(VOID)irqParam;
|
||||
OsSetVector(hwiNum, hwiHandler);
|
||||
#endif
|
||||
#if (LOSCFG_DEBUG_TOOLS == 1)
|
||||
if ((irqParam != NULL) && (irqParam->pName != NULL)) {
|
||||
g_hwiFormName[hwiNum + OS_SYS_VECTOR_CNT] = (CHAR *)irqParam->pName;
|
||||
}
|
||||
g_hwiFormCnt[hwiNum + OS_SYS_VECTOR_CNT] = 0;
|
||||
#endif
|
||||
HwiUnmask(hwiNum);
|
||||
LOS_IntRestore(intSave);
|
||||
@@ -277,11 +323,13 @@ LITE_OS_SEC_TEXT_INIT UINT32 ArchHwiCreate(HWI_HANDLE_T hwiNum,
|
||||
Function : ArchHwiDelete
|
||||
Description : Delete hardware interrupt
|
||||
Input : hwiNum --- hwi num to delete
|
||||
irqParam --- param of the hwi handler
|
||||
Output : None
|
||||
Return : LOS_OK on success or error code on failure
|
||||
**************************************************************************** */
|
||||
LITE_OS_SEC_TEXT_INIT UINT32 ArchHwiDelete(HWI_HANDLE_T hwiNum)
|
||||
LITE_OS_SEC_TEXT_INIT UINT32 ArchHwiDelete(HWI_HANDLE_T hwiNum, HwiIrqParam *irqParam)
|
||||
{
|
||||
(VOID)irqParam;
|
||||
UINT32 intSave;
|
||||
|
||||
if (hwiNum >= OS_HWI_MAX_NUM) {
|
||||
|
||||
0
arch/arm/cortex-m3/keil/los_atomic.S
Executable file → Normal file
0
arch/arm/cortex-m3/keil/los_atomic.S
Executable file → Normal file
@@ -190,7 +190,7 @@ _hwiActiveCheck
|
||||
CMP R3, #0
|
||||
BEQ _hwiActiveCheckNext
|
||||
|
||||
; exc occured in IRQ
|
||||
; exc occurred in IRQ
|
||||
ORR R0, R0, #FLAG_HWI_ACTIVE
|
||||
RBIT R2, R3
|
||||
CLZ R2, R2
|
||||
@@ -228,19 +228,19 @@ _hwiActiveCheckNext
|
||||
AND R2, R2,R3
|
||||
CMP R2,#0
|
||||
BNE _ExcInMSP
|
||||
; exc occured in Task or Init or exc
|
||||
; exc occurred 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
|
||||
BEQ _ExcInMSP ; if exc occurred in Init then branch
|
||||
|
||||
|
||||
CMP LR, #0xFFFFFFED ;auto push floating registers
|
||||
BNE _NoFloatInPsp
|
||||
|
||||
; exc occured in Task
|
||||
; exc occurred in Task
|
||||
MOV R2, R13
|
||||
SUB R13, #96 ; add 8 Bytes reg(for STMFD)
|
||||
|
||||
|
||||
@@ -39,15 +39,16 @@
|
||||
#include "los_sched.h"
|
||||
#include "los_memory.h"
|
||||
#include "los_membox.h"
|
||||
#if (LOSCFG_CPUP_INCLUDE_IRQ == 1)
|
||||
#include "los_cpup.h"
|
||||
#endif
|
||||
|
||||
/*lint -save -e40 -e522 -e533*/
|
||||
UINT32 g_intCount = 0;
|
||||
|
||||
/*lint -restore*/
|
||||
#ifdef __ICCARM__
|
||||
#pragma location = ".data.vector"
|
||||
#elif defined(__CC_ARM) || defined(__GNUC__)
|
||||
#pragma data_alignment=LOSCFG_ARCH_HWI_VECTOR_ALIGN
|
||||
#pragma data_alignment = LOSCFG_ARCH_HWI_VECTOR_ALIGN
|
||||
LITE_OS_SEC_VEC
|
||||
#endif
|
||||
/* *
|
||||
@@ -56,6 +57,30 @@ LITE_OS_SEC_VEC
|
||||
*/
|
||||
STATIC HWI_PROC_FUNC g_hwiForm[OS_VECTOR_CNT] = {0};
|
||||
|
||||
#if (LOSCFG_DEBUG_TOOLS == 1)
|
||||
STATIC UINT32 g_hwiFormCnt[OS_HWI_MAX_NUM] = {0};
|
||||
STATIC CHAR *g_hwiFormName[OS_HWI_MAX_NUM] = {0};
|
||||
|
||||
UINT32 OsGetHwiFormCnt(UINT32 index)
|
||||
{
|
||||
return g_hwiFormCnt[index];
|
||||
}
|
||||
|
||||
CHAR *OsGetHwiFormName(UINT32 index)
|
||||
{
|
||||
return g_hwiFormName[index];
|
||||
}
|
||||
|
||||
BOOL OsGetHwiCreated(UINT32 index)
|
||||
{
|
||||
if (g_hwiForm[index] != (HWI_PROC_FUNC)HalHwiDefaultHandler) {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if (LOSCFG_PLATFORM_HWI_WITH_ARG == 1)
|
||||
|
||||
typedef struct {
|
||||
@@ -198,11 +223,9 @@ inline UINT32 ArchIsIntActive(VOID)
|
||||
Output : None
|
||||
Return : None
|
||||
**************************************************************************** */
|
||||
/*lint -e529*/
|
||||
LITE_OS_SEC_TEXT_MINOR VOID HalHwiDefaultHandler(VOID)
|
||||
{
|
||||
UINT32 irqNum = HwiNumGet();
|
||||
PRINT_ERR("%s irqnum:%u\n", __FUNCTION__, irqNum);
|
||||
PRINT_ERR("%s irqnum:%u\n", __FUNCTION__, HwiNumGet());
|
||||
while (1) {}
|
||||
}
|
||||
|
||||
@@ -241,6 +264,9 @@ LITE_OS_SEC_TEXT VOID HalInterrupt(VOID)
|
||||
hwiIndex = HwiNumGet();
|
||||
|
||||
OsHookCall(LOS_HOOK_TYPE_ISR_ENTER, hwiIndex);
|
||||
#if (LOSCFG_CPUP_INCLUDE_IRQ == 1)
|
||||
OsCpupIrqStart(hwiIndex);
|
||||
#endif
|
||||
|
||||
HalPreInterruptHandler(hwiIndex);
|
||||
|
||||
@@ -254,8 +280,16 @@ LITE_OS_SEC_TEXT VOID HalInterrupt(VOID)
|
||||
}
|
||||
#endif
|
||||
|
||||
#if (LOSCFG_DEBUG_TOOLS == 1)
|
||||
++g_hwiFormCnt[hwiIndex];
|
||||
#endif
|
||||
|
||||
HalAftInterruptHandler(hwiIndex);
|
||||
|
||||
#if (LOSCFG_CPUP_INCLUDE_IRQ == 1)
|
||||
OsCpupIrqEnd(hwiIndex);
|
||||
#endif
|
||||
|
||||
OsHookCall(LOS_HOOK_TYPE_ISR_EXIT, hwiIndex);
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
@@ -268,22 +302,22 @@ LITE_OS_SEC_TEXT VOID HalInterrupt(VOID)
|
||||
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
|
||||
hwiMode --- unused
|
||||
hwiHandler --- hwi handler
|
||||
irqParam --- param of the hwi handler
|
||||
Output : None
|
||||
Return : LOS_OK on success or error code on failure
|
||||
**************************************************************************** */
|
||||
LITE_OS_SEC_TEXT_INIT UINT32 ArchHwiCreate(HWI_HANDLE_T hwiNum,
|
||||
HWI_PRIOR_T hwiPrio,
|
||||
HWI_MODE_T mode,
|
||||
HWI_PROC_FUNC handler,
|
||||
HWI_ARG_T arg)
|
||||
HWI_MODE_T hwiMode,
|
||||
HWI_PROC_FUNC hwiHandler,
|
||||
HwiIrqParam *irqParam)
|
||||
{
|
||||
(VOID)mode;
|
||||
(VOID)hwiMode;
|
||||
UINT32 intSave;
|
||||
|
||||
if (handler == NULL) {
|
||||
if (hwiHandler == NULL) {
|
||||
return OS_ERRNO_HWI_PROC_FUNC_NULL;
|
||||
}
|
||||
|
||||
@@ -301,11 +335,23 @@ LITE_OS_SEC_TEXT_INIT UINT32 ArchHwiCreate(HWI_HANDLE_T hwiNum,
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
#if (LOSCFG_PLATFORM_HWI_WITH_ARG == 1)
|
||||
OsSetVector(hwiNum, handler, arg);
|
||||
if (irqParam != NULL) {
|
||||
OsSetVector(hwiNum, hwiHandler, irqParam->pDevId);
|
||||
} else {
|
||||
OsSetVector(hwiNum, hwiHandler, NULL);
|
||||
}
|
||||
#else
|
||||
(VOID)arg;
|
||||
OsSetVector(hwiNum, handler);
|
||||
(VOID)irqParam;
|
||||
OsSetVector(hwiNum, hwiHandler);
|
||||
#endif
|
||||
|
||||
#if (LOSCFG_DEBUG_TOOLS == 1)
|
||||
if ((irqParam != NULL) && (irqParam->pName != NULL)) {
|
||||
g_hwiFormName[hwiNum + OS_SYS_VECTOR_CNT] = (CHAR *)irqParam->pName;
|
||||
}
|
||||
g_hwiFormCnt[hwiNum + OS_SYS_VECTOR_CNT] = 0;
|
||||
#endif
|
||||
|
||||
HwiUnmask((IRQn_Type)hwiNum);
|
||||
HwiSetPriority((IRQn_Type)hwiNum, hwiPrio);
|
||||
|
||||
@@ -318,11 +364,13 @@ LITE_OS_SEC_TEXT_INIT UINT32 ArchHwiCreate(HWI_HANDLE_T hwiNum,
|
||||
Function : ArchHwiDelete
|
||||
Description : Delete hardware interrupt
|
||||
Input : hwiNum --- hwi num to delete
|
||||
irqParam --- param of the hwi handler
|
||||
Output : None
|
||||
Return : LOS_OK on success or error code on failure
|
||||
**************************************************************************** */
|
||||
LITE_OS_SEC_TEXT_INIT UINT32 ArchHwiDelete(HWI_HANDLE_T hwiNum)
|
||||
LITE_OS_SEC_TEXT_INIT UINT32 ArchHwiDelete(HWI_HANDLE_T hwiNum, HwiIrqParam *irqParam)
|
||||
{
|
||||
(VOID)irqParam;
|
||||
UINT32 intSave;
|
||||
|
||||
if (hwiNum >= OS_HWI_MAX_NUM) {
|
||||
@@ -597,7 +645,7 @@ LITE_OS_SEC_TEXT_INIT VOID HalHwiInit(VOID)
|
||||
|
||||
/* Enable USGFAULT, BUSFAULT, MEMFAULT */
|
||||
*(volatile UINT32 *)OS_NVIC_SHCSR |= (USGFAULT | BUSFAULT | MEMFAULT);
|
||||
|
||||
|
||||
/* Enable DIV 0 and unaligned exception */
|
||||
#ifdef LOSCFG_ARCH_UNALIGNED_EXC
|
||||
*(volatile UINT32 *)OS_NVIC_CCR |= (DIV0FAULT | UNALIGNFAULT);
|
||||
|
||||
0
arch/arm/cortex-m33/gcc/NTZ/los_arch_atomic.h
Executable file → Normal file
0
arch/arm/cortex-m33/gcc/NTZ/los_arch_atomic.h
Executable file → Normal file
0
arch/arm/cortex-m33/gcc/NTZ/los_arch_context.h
Executable file → Normal file
0
arch/arm/cortex-m33/gcc/NTZ/los_arch_context.h
Executable file → Normal file
0
arch/arm/cortex-m33/gcc/NTZ/los_arch_interrupt.h
Executable file → Normal file
0
arch/arm/cortex-m33/gcc/NTZ/los_arch_interrupt.h
Executable file → Normal file
8
arch/arm/cortex-m33/gcc/NTZ/los_exc.S
Executable file → Normal file
8
arch/arm/cortex-m33/gcc/NTZ/los_exc.S
Executable file → Normal file
@@ -263,7 +263,7 @@ _hwiActiveCheck:
|
||||
CMP R3, #0
|
||||
BEQ _hwiActiveCheckNext
|
||||
|
||||
// exc occured in IRQ
|
||||
// exc occurred in IRQ
|
||||
ORR R0, R0, #FLAG_HWI_ACTIVE
|
||||
RBIT R2, R3
|
||||
CLZ R2, R2
|
||||
@@ -316,19 +316,19 @@ _hwiActiveCheckNext:
|
||||
AND R2, R2,R3
|
||||
CMP R2,#0
|
||||
BNE _ExcInMSP
|
||||
// exc occured in Task or Init or exc
|
||||
// exc occurred 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
|
||||
BEQ _ExcInMSP // if exc occurred in Init then branch
|
||||
|
||||
|
||||
CMP LR, #0xFFFFFFED //auto push floating registers
|
||||
BNE _NoFloatInPsp
|
||||
|
||||
// exc occured in Task
|
||||
// exc occurred in Task
|
||||
MOV R2, R13
|
||||
SUB R13, #96 // add 8 Bytes reg(for STMFD)
|
||||
|
||||
|
||||
84
arch/arm/cortex-m33/gcc/NTZ/los_interrupt.c
Executable file → Normal file
84
arch/arm/cortex-m33/gcc/NTZ/los_interrupt.c
Executable file → Normal file
@@ -39,12 +39,13 @@
|
||||
#include "los_sched.h"
|
||||
#include "los_memory.h"
|
||||
#include "los_membox.h"
|
||||
#if (LOSCFG_CPUP_INCLUDE_IRQ == 1)
|
||||
#include "los_cpup.h"
|
||||
#endif
|
||||
|
||||
#define DEF_HANDLER_START_INDEX 2
|
||||
/*lint -save -e40 -e522 -e533*/
|
||||
UINT32 g_intCount = 0;
|
||||
|
||||
/*lint -restore*/
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
@@ -52,6 +53,30 @@ UINT32 g_intCount = 0;
|
||||
*/
|
||||
STATIC HWI_PROC_FUNC __attribute__((aligned(LOSCFG_ARCH_HWI_VECTOR_ALIGN))) g_hwiForm[OS_VECTOR_CNT] = {0};
|
||||
|
||||
#if (LOSCFG_DEBUG_TOOLS == 1)
|
||||
STATIC UINT32 g_hwiFormCnt[OS_HWI_MAX_NUM] = {0};
|
||||
STATIC CHAR *g_hwiFormName[OS_HWI_MAX_NUM] = {0};
|
||||
|
||||
UINT32 OsGetHwiFormCnt(UINT32 index)
|
||||
{
|
||||
return g_hwiFormCnt[index];
|
||||
}
|
||||
|
||||
CHAR *OsGetHwiFormName(UINT32 index)
|
||||
{
|
||||
return g_hwiFormName[index];
|
||||
}
|
||||
|
||||
BOOL OsGetHwiCreated(UINT32 index)
|
||||
{
|
||||
if (g_hwiForm[index] != (HWI_PROC_FUNC)HalHwiDefaultHandler) {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if (LOSCFG_PLATFORM_HWI_WITH_ARG == 1)
|
||||
|
||||
typedef struct {
|
||||
@@ -189,11 +214,9 @@ inline UINT32 ArchIsIntActive(VOID)
|
||||
Output : None
|
||||
Return : None
|
||||
**************************************************************************** */
|
||||
/*lint -e529*/
|
||||
LITE_OS_SEC_TEXT_MINOR VOID HalHwiDefaultHandler(VOID)
|
||||
{
|
||||
UINT32 irqNum = HwiNumGet();
|
||||
PRINT_ERR("%s irqnum:%u\n", __FUNCTION__, irqNum);
|
||||
PRINT_ERR("%s irqnum:%u\n", __FUNCTION__, HwiNumGet());
|
||||
while (1) {}
|
||||
}
|
||||
|
||||
@@ -232,6 +255,9 @@ LITE_OS_SEC_TEXT VOID HalInterrupt(VOID)
|
||||
hwiIndex = HwiNumGet();
|
||||
|
||||
OsHookCall(LOS_HOOK_TYPE_ISR_ENTER, hwiIndex);
|
||||
#if (LOSCFG_CPUP_INCLUDE_IRQ == 1)
|
||||
OsCpupIrqStart(hwiIndex);
|
||||
#endif
|
||||
|
||||
HalPreInterruptHandler(hwiIndex);
|
||||
|
||||
@@ -245,8 +271,16 @@ LITE_OS_SEC_TEXT VOID HalInterrupt(VOID)
|
||||
}
|
||||
#endif
|
||||
|
||||
#if (LOSCFG_DEBUG_TOOLS == 1)
|
||||
++g_hwiFormCnt[hwiIndex];
|
||||
#endif
|
||||
|
||||
HalAftInterruptHandler(hwiIndex);
|
||||
|
||||
#if (LOSCFG_CPUP_INCLUDE_IRQ == 1)
|
||||
OsCpupIrqEnd(hwiIndex);
|
||||
#endif
|
||||
|
||||
OsHookCall(LOS_HOOK_TYPE_ISR_EXIT, hwiIndex);
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
@@ -259,22 +293,22 @@ LITE_OS_SEC_TEXT VOID HalInterrupt(VOID)
|
||||
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
|
||||
hwiMode --- unused
|
||||
hwiHandler --- hwi handler
|
||||
irqParam --- param of the hwi handler
|
||||
Output : None
|
||||
Return : LOS_OK on success or error code on failure
|
||||
**************************************************************************** */
|
||||
LITE_OS_SEC_TEXT_INIT UINT32 ArchHwiCreate(HWI_HANDLE_T hwiNum,
|
||||
HWI_PRIOR_T hwiPrio,
|
||||
HWI_MODE_T mode,
|
||||
HWI_PROC_FUNC handler,
|
||||
HWI_ARG_T arg)
|
||||
HWI_MODE_T hwiMode,
|
||||
HWI_PROC_FUNC hwiHandler,
|
||||
HwiIrqParam *irqParam)
|
||||
{
|
||||
(VOID)mode;
|
||||
(VOID)hwiMode;
|
||||
UINT32 intSave;
|
||||
|
||||
if (handler == NULL) {
|
||||
if (hwiHandler == NULL) {
|
||||
return OS_ERRNO_HWI_PROC_FUNC_NULL;
|
||||
}
|
||||
|
||||
@@ -292,11 +326,23 @@ LITE_OS_SEC_TEXT_INIT UINT32 ArchHwiCreate(HWI_HANDLE_T hwiNum,
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
#if (LOSCFG_PLATFORM_HWI_WITH_ARG == 1)
|
||||
OsSetVector(hwiNum, handler, arg);
|
||||
if (irqParam != NULL) {
|
||||
OsSetVector(hwiNum, hwiHandler, irqParam->pDevId);
|
||||
} else {
|
||||
OsSetVector(hwiNum, hwiHandler, NULL);
|
||||
}
|
||||
#else
|
||||
(VOID)arg;
|
||||
OsSetVector(hwiNum, handler);
|
||||
(VOID)irqParam;
|
||||
OsSetVector(hwiNum, hwiHandler);
|
||||
#endif
|
||||
|
||||
#if (LOSCFG_DEBUG_TOOLS == 1)
|
||||
if ((irqParam != NULL) && (irqParam->pName != NULL)) {
|
||||
g_hwiFormName[hwiNum + OS_SYS_VECTOR_CNT] = (CHAR *)irqParam->pName;
|
||||
}
|
||||
g_hwiFormCnt[hwiNum + OS_SYS_VECTOR_CNT] = 0;
|
||||
#endif
|
||||
|
||||
HwiUnmask((IRQn_Type)hwiNum);
|
||||
HwiSetPriority((IRQn_Type)hwiNum, hwiPrio);
|
||||
|
||||
@@ -309,11 +355,13 @@ LITE_OS_SEC_TEXT_INIT UINT32 ArchHwiCreate(HWI_HANDLE_T hwiNum,
|
||||
Function : ArchHwiDelete
|
||||
Description : Delete hardware interrupt
|
||||
Input : hwiNum --- hwi num to delete
|
||||
irqParam --- param of the hwi handler
|
||||
Output : None
|
||||
Return : LOS_OK on success or error code on failure
|
||||
**************************************************************************** */
|
||||
LITE_OS_SEC_TEXT_INIT UINT32 ArchHwiDelete(HWI_HANDLE_T hwiNum)
|
||||
LITE_OS_SEC_TEXT_INIT UINT32 ArchHwiDelete(HWI_HANDLE_T hwiNum, HwiIrqParam *irqParam)
|
||||
{
|
||||
(VOID)irqParam;
|
||||
UINT32 intSave;
|
||||
|
||||
if (hwiNum >= OS_HWI_MAX_NUM) {
|
||||
@@ -588,7 +636,7 @@ LITE_OS_SEC_TEXT_INIT VOID HalHwiInit(VOID)
|
||||
|
||||
/* Enable USGFAULT, BUSFAULT, MEMFAULT */
|
||||
*(volatile UINT32 *)OS_NVIC_SHCSR |= (USGFAULT | BUSFAULT | MEMFAULT);
|
||||
|
||||
|
||||
/* Enable DIV 0 and unaligned exception */
|
||||
#ifdef LOSCFG_ARCH_UNALIGNED_EXC
|
||||
*(volatile UINT32 *)OS_NVIC_CCR |= (DIV0FAULT | UNALIGNFAULT);
|
||||
|
||||
0
arch/arm/cortex-m33/gcc/NTZ/los_timer.c
Executable file → Normal file
0
arch/arm/cortex-m33/gcc/NTZ/los_timer.c
Executable file → Normal file
0
arch/arm/cortex-m33/gcc/TZ/non_secure/los_arch_atomic.h
Executable file → Normal file
0
arch/arm/cortex-m33/gcc/TZ/non_secure/los_arch_atomic.h
Executable file → Normal file
0
arch/arm/cortex-m33/gcc/TZ/non_secure/los_arch_context.h
Executable file → Normal file
0
arch/arm/cortex-m33/gcc/TZ/non_secure/los_arch_context.h
Executable file → Normal file
0
arch/arm/cortex-m33/gcc/TZ/non_secure/los_arch_interrupt.h
Executable file → Normal file
0
arch/arm/cortex-m33/gcc/TZ/non_secure/los_arch_interrupt.h
Executable file → Normal file
8
arch/arm/cortex-m33/gcc/TZ/non_secure/los_exc.S
Executable file → Normal file
8
arch/arm/cortex-m33/gcc/TZ/non_secure/los_exc.S
Executable file → Normal file
@@ -247,7 +247,7 @@ _hwiActiveCheck:
|
||||
CMP R3, #0
|
||||
BEQ _hwiActiveCheckNext
|
||||
|
||||
// exc occured in IRQ
|
||||
// exc occurred in IRQ
|
||||
ORR R0, R0, #FLAG_HWI_ACTIVE
|
||||
RBIT R2, R3
|
||||
CLZ R2, R2
|
||||
@@ -300,19 +300,19 @@ _hwiActiveCheckNext:
|
||||
AND R2, R2,R3
|
||||
CMP R2,#0
|
||||
BNE _ExcInMSP
|
||||
// exc occured in Task or Init or exc
|
||||
// exc occurred 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
|
||||
BEQ _ExcInMSP // if exc occurred in Init then branch
|
||||
|
||||
|
||||
CMP LR, #0xFFFFFFED //auto push floating registers
|
||||
BNE _NoFloatInPsp
|
||||
|
||||
// exc occured in Task
|
||||
// exc occurred in Task
|
||||
MOV R2, R13
|
||||
SUB R13, #96 // add 8 Bytes reg(for STMFD)
|
||||
|
||||
|
||||
84
arch/arm/cortex-m33/gcc/TZ/non_secure/los_interrupt.c
Executable file → Normal file
84
arch/arm/cortex-m33/gcc/TZ/non_secure/los_interrupt.c
Executable file → Normal file
@@ -39,19 +39,43 @@
|
||||
#include "los_sched.h"
|
||||
#include "los_memory.h"
|
||||
#include "los_membox.h"
|
||||
#if (LOSCFG_CPUP_INCLUDE_IRQ == 1)
|
||||
#include "los_cpup.h"
|
||||
#endif
|
||||
|
||||
#define DEF_HANDLER_START_INDEX 2
|
||||
/*lint -save -e40 -e522 -e533*/
|
||||
UINT32 g_intCount = 0;
|
||||
|
||||
/*lint -restore*/
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Hardware interrupt form mapping handling function array.
|
||||
*/
|
||||
STATIC HWI_PROC_FUNC __attribute__((aligned(LOSCFG_ARCH_HWI_VECTOR_ALIGN))) g_hwiForm[OS_VECTOR_CNT] = {0};
|
||||
|
||||
#if (LOSCFG_DEBUG_TOOLS == 1)
|
||||
STATIC UINT32 g_hwiFormCnt[OS_HWI_MAX_NUM] = {0};
|
||||
STATIC CHAR *g_hwiFormName[OS_HWI_MAX_NUM] = {0};
|
||||
|
||||
UINT32 OsGetHwiFormCnt(UINT32 index)
|
||||
{
|
||||
return g_hwiFormCnt[index];
|
||||
}
|
||||
|
||||
CHAR *OsGetHwiFormName(UINT32 index)
|
||||
{
|
||||
return g_hwiFormName[index];
|
||||
}
|
||||
|
||||
BOOL OsGetHwiCreated(UINT32 index)
|
||||
{
|
||||
if (g_hwiForm[index] != (HWI_PROC_FUNC)HalHwiDefaultHandler) {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if (LOSCFG_PLATFORM_HWI_WITH_ARG == 1)
|
||||
|
||||
typedef struct {
|
||||
@@ -192,8 +216,7 @@ inline UINT32 ArchIsIntActive(VOID)
|
||||
/*lint -e529*/
|
||||
LITE_OS_SEC_TEXT_MINOR VOID HalHwiDefaultHandler(VOID)
|
||||
{
|
||||
UINT32 irqNum = HwiNumGet();
|
||||
PRINT_ERR("%s irqnum:%u\n", __FUNCTION__, irqNum);
|
||||
PRINT_ERR("%s irqnum:%u\n", __FUNCTION__, HwiNumGet());
|
||||
while (1) {}
|
||||
}
|
||||
|
||||
@@ -232,6 +255,9 @@ LITE_OS_SEC_TEXT VOID HalInterrupt(VOID)
|
||||
hwiIndex = HwiNumGet();
|
||||
|
||||
OsHookCall(LOS_HOOK_TYPE_ISR_ENTER, hwiIndex);
|
||||
#if (LOSCFG_CPUP_INCLUDE_IRQ == 1)
|
||||
OsCpupIrqStart(hwiIndex);
|
||||
#endif
|
||||
|
||||
HalPreInterruptHandler(hwiIndex);
|
||||
|
||||
@@ -245,8 +271,16 @@ LITE_OS_SEC_TEXT VOID HalInterrupt(VOID)
|
||||
}
|
||||
#endif
|
||||
|
||||
#if (LOSCFG_DEBUG_TOOLS == 1)
|
||||
++g_hwiFormCnt[hwiIndex];
|
||||
#endif
|
||||
|
||||
HalAftInterruptHandler(hwiIndex);
|
||||
|
||||
#if (LOSCFG_CPUP_INCLUDE_IRQ == 1)
|
||||
OsCpupIrqEnd(hwiIndex);
|
||||
#endif
|
||||
|
||||
OsHookCall(LOS_HOOK_TYPE_ISR_EXIT, hwiIndex);
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
@@ -259,22 +293,22 @@ LITE_OS_SEC_TEXT VOID HalInterrupt(VOID)
|
||||
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
|
||||
hwiMode --- unused
|
||||
hwiHandler --- hwi handler
|
||||
irqParam --- param of the hwi handler
|
||||
Output : None
|
||||
Return : LOS_OK on success or error code on failure
|
||||
**************************************************************************** */
|
||||
LITE_OS_SEC_TEXT_INIT UINT32 ArchHwiCreate(HWI_HANDLE_T hwiNum,
|
||||
HWI_PRIOR_T hwiPrio,
|
||||
HWI_MODE_T mode,
|
||||
HWI_PROC_FUNC handler,
|
||||
HWI_ARG_T arg)
|
||||
HWI_MODE_T hwiMode,
|
||||
HWI_PROC_FUNC hwiHandler,
|
||||
HwiIrqParam *irqParam)
|
||||
{
|
||||
(VOID)mode;
|
||||
(VOID)hwiMode;
|
||||
UINT32 intSave;
|
||||
|
||||
if (handler == NULL) {
|
||||
if (hwiHandler == NULL) {
|
||||
return OS_ERRNO_HWI_PROC_FUNC_NULL;
|
||||
}
|
||||
|
||||
@@ -292,11 +326,23 @@ LITE_OS_SEC_TEXT_INIT UINT32 ArchHwiCreate(HWI_HANDLE_T hwiNum,
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
#if (LOSCFG_PLATFORM_HWI_WITH_ARG == 1)
|
||||
OsSetVector(hwiNum, handler, arg);
|
||||
if (irqParam != NULL) {
|
||||
OsSetVector(hwiNum, hwiHandler, irqParam->pDevId);
|
||||
} else {
|
||||
OsSetVector(hwiNum, hwiHandler, NULL);
|
||||
}
|
||||
#else
|
||||
(VOID)arg;
|
||||
OsSetVector(hwiNum, handler);
|
||||
(VOID)irqParam;
|
||||
OsSetVector(hwiNum, hwiHandler);
|
||||
#endif
|
||||
|
||||
#if (LOSCFG_DEBUG_TOOLS == 1)
|
||||
if ((irqParam != NULL) && (irqParam->pName != NULL)) {
|
||||
g_hwiFormName[hwiNum + OS_SYS_VECTOR_CNT] = (CHAR *)irqParam->pName;
|
||||
}
|
||||
g_hwiFormCnt[hwiNum + OS_SYS_VECTOR_CNT] = 0;
|
||||
#endif
|
||||
|
||||
HwiUnmask((IRQn_Type)hwiNum);
|
||||
HwiSetPriority((IRQn_Type)hwiNum, hwiPrio);
|
||||
|
||||
@@ -309,11 +355,13 @@ LITE_OS_SEC_TEXT_INIT UINT32 ArchHwiCreate(HWI_HANDLE_T hwiNum,
|
||||
Function : ArchHwiDelete
|
||||
Description : Delete hardware interrupt
|
||||
Input : hwiNum --- hwi num to delete
|
||||
irqParam --- param of the hwi handler
|
||||
Output : None
|
||||
Return : LOS_OK on success or error code on failure
|
||||
**************************************************************************** */
|
||||
LITE_OS_SEC_TEXT_INIT UINT32 ArchHwiDelete(HWI_HANDLE_T hwiNum)
|
||||
LITE_OS_SEC_TEXT_INIT UINT32 ArchHwiDelete(HWI_HANDLE_T hwiNum, HwiIrqParam *irqParam)
|
||||
{
|
||||
(VOID)irqParam;
|
||||
UINT32 intSave;
|
||||
|
||||
if (hwiNum >= OS_HWI_MAX_NUM) {
|
||||
@@ -588,7 +636,7 @@ LITE_OS_SEC_TEXT_INIT VOID HalHwiInit(VOID)
|
||||
|
||||
/* Enable USGFAULT, BUSFAULT, MEMFAULT */
|
||||
*(volatile UINT32 *)OS_NVIC_SHCSR |= (USGFAULT | BUSFAULT | MEMFAULT);
|
||||
|
||||
|
||||
/* Enable DIV 0 and unaligned exception */
|
||||
#ifdef LOSCFG_ARCH_UNALIGNED_EXC
|
||||
*(volatile UINT32 *)OS_NVIC_CCR |= (DIV0FAULT | UNALIGNFAULT);
|
||||
|
||||
0
arch/arm/cortex-m33/gcc/TZ/non_secure/los_timer.c
Executable file → Normal file
0
arch/arm/cortex-m33/gcc/TZ/non_secure/los_timer.c
Executable file → Normal file
0
arch/arm/cortex-m33/gcc/TZ/non_secure/los_trustzone.c
Executable file → Normal file
0
arch/arm/cortex-m33/gcc/TZ/non_secure/los_trustzone.c
Executable file → Normal file
0
arch/arm/cortex-m33/gcc/TZ/non_secure/los_trustzone.h
Executable file → Normal file
0
arch/arm/cortex-m33/gcc/TZ/non_secure/los_trustzone.h
Executable file → Normal file
0
arch/arm/cortex-m33/gcc/TZ/secure/los_secure_context.c
Executable file → Normal file
0
arch/arm/cortex-m33/gcc/TZ/secure/los_secure_context.c
Executable file → Normal file
0
arch/arm/cortex-m33/gcc/TZ/secure/los_secure_context.h
Executable file → Normal file
0
arch/arm/cortex-m33/gcc/TZ/secure/los_secure_context.h
Executable file → Normal file
0
arch/arm/cortex-m33/gcc/TZ/secure/los_secure_context_asm.S
Executable file → Normal file
0
arch/arm/cortex-m33/gcc/TZ/secure/los_secure_context_asm.S
Executable file → Normal file
0
arch/arm/cortex-m33/gcc/TZ/secure/los_secure_heap.c
Executable file → Normal file
0
arch/arm/cortex-m33/gcc/TZ/secure/los_secure_heap.c
Executable file → Normal file
0
arch/arm/cortex-m33/gcc/TZ/secure/los_secure_heap.h
Executable file → Normal file
0
arch/arm/cortex-m33/gcc/TZ/secure/los_secure_heap.h
Executable file → Normal file
0
arch/arm/cortex-m33/gcc/TZ/secure/los_secure_macros.h
Executable file → Normal file
0
arch/arm/cortex-m33/gcc/TZ/secure/los_secure_macros.h
Executable file → Normal file
@@ -56,8 +56,8 @@ 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_FSR EQU 0xE000ED28 ;include BusFault/MemFault/UsageFault State Register
|
||||
OS_NVIC_HFSR EQU 0xE000ED2C ;HardFault State Register
|
||||
OS_NVIC_BFAR EQU 0xE000ED38
|
||||
OS_NVIC_MMAR EQU 0xE000ED34
|
||||
OS_NVIC_ACT_BASE EQU 0xE000E300
|
||||
@@ -190,7 +190,7 @@ _hwiActiveCheck
|
||||
CMP R3, #0
|
||||
BEQ _hwiActiveCheckNext
|
||||
|
||||
; exc occured in IRQ
|
||||
; exc occurred in IRQ
|
||||
ORR R0, R0, #FLAG_HWI_ACTIVE
|
||||
RBIT R2, R3
|
||||
CLZ R2, R2
|
||||
@@ -228,19 +228,19 @@ _hwiActiveCheckNext
|
||||
AND R2, R2,R3
|
||||
CMP R2,#0
|
||||
BNE _ExcInMSP
|
||||
; exc occured in Task or Init or exc
|
||||
; exc occurred 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
|
||||
BEQ _ExcInMSP ; if exc occurred in Init then branch
|
||||
|
||||
|
||||
CMP LR, #0xFFFFFFED ;auto push floating registers
|
||||
BNE _NoFloatInPsp
|
||||
|
||||
; exc occured in Task
|
||||
; exc occurred in Task
|
||||
MOV R2, R13
|
||||
SUB R13, #96 ; add 8 Bytes reg(for STMFD)
|
||||
|
||||
|
||||
@@ -40,19 +40,46 @@
|
||||
#include "los_sched.h"
|
||||
#include "los_memory.h"
|
||||
#include "los_membox.h"
|
||||
#if (LOSCFG_CPUP_INCLUDE_IRQ == 1)
|
||||
#include "los_cpup.h"
|
||||
#endif
|
||||
|
||||
/*lint -save -e40 -e522 -e533*/
|
||||
UINT32 g_intCount = 0;
|
||||
|
||||
/*lint -restore*/
|
||||
#pragma location = ".data.vector"
|
||||
#pragma data_alignment=LOSCFG_ARCH_HWI_VECTOR_ALIGN
|
||||
#pragma data_alignment = LOSCFG_ARCH_HWI_VECTOR_ALIGN
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* hardware interrupt form mapping handling function array.
|
||||
*/
|
||||
STATIC HWI_PROC_FUNC g_hwiForm[OS_VECTOR_CNT] = {0};
|
||||
|
||||
#if (LOSCFG_DEBUG_TOOLS == 1)
|
||||
STATIC UINT32 g_hwiFormCnt[OS_HWI_MAX_NUM] = {0};
|
||||
STATIC CHAR *g_hwiFormName[OS_HWI_MAX_NUM] = {0};
|
||||
|
||||
UINT32 OsGetHwiFormCnt(UINT32 index)
|
||||
{
|
||||
return g_hwiFormCnt[index];
|
||||
}
|
||||
|
||||
CHAR *OsGetHwiFormName(UINT32 index)
|
||||
{
|
||||
return g_hwiFormName[index];
|
||||
}
|
||||
|
||||
BOOL OsGetHwiCreated(UINT32 index)
|
||||
{
|
||||
if (g_hwiForm[index] != (HWI_PROC_FUNC)HalHwiDefaultHandler) {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if (LOSCFG_PLATFORM_HWI_WITH_ARG == 1)
|
||||
|
||||
typedef struct {
|
||||
@@ -198,8 +225,7 @@ inline UINT32 ArchIsIntActive(VOID)
|
||||
/*lint -e529*/
|
||||
LITE_OS_SEC_TEXT_MINOR VOID HalHwiDefaultHandler(VOID)
|
||||
{
|
||||
UINT32 irqNum = HwiNumGet();
|
||||
PRINT_ERR("%s irqnum:%u\n", __FUNCTION__, irqNum);
|
||||
PRINT_ERR("%s irqnum:%u\n", __FUNCTION__, HwiNumGet());
|
||||
while (1) {}
|
||||
}
|
||||
|
||||
@@ -240,6 +266,9 @@ LITE_OS_SEC_TEXT VOID HalInterrupt(VOID)
|
||||
hwiIndex = HwiNumGet();
|
||||
|
||||
OsHookCall(LOS_HOOK_TYPE_ISR_ENTER, hwiIndex);
|
||||
#if (LOSCFG_CPUP_INCLUDE_IRQ == 1)
|
||||
OsCpupIrqStart(hwiIndex);
|
||||
#endif
|
||||
|
||||
HalPreInterruptHandler(hwiIndex);
|
||||
|
||||
@@ -253,8 +282,16 @@ LITE_OS_SEC_TEXT VOID HalInterrupt(VOID)
|
||||
}
|
||||
#endif
|
||||
|
||||
#if (LOSCFG_DEBUG_TOOLS == 1)
|
||||
++g_hwiFormCnt[hwiIndex];
|
||||
#endif
|
||||
|
||||
HalAftInterruptHandler(hwiIndex);
|
||||
|
||||
#if (LOSCFG_CPUP_INCLUDE_IRQ == 1)
|
||||
OsCpupIrqEnd(hwiIndex);
|
||||
#endif
|
||||
|
||||
OsHookCall(LOS_HOOK_TYPE_ISR_EXIT, hwiIndex);
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
@@ -267,22 +304,22 @@ LITE_OS_SEC_TEXT VOID HalInterrupt(VOID)
|
||||
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
|
||||
hwiMode --- unused
|
||||
hwiHandler --- hwi handler
|
||||
irqParam --- param of the hwi handler
|
||||
Output : None
|
||||
Return : LOS_OK on success or error code on failure
|
||||
**************************************************************************** */
|
||||
LITE_OS_SEC_TEXT_INIT UINT32 ArchHwiCreate(HWI_HANDLE_T hwiNum,
|
||||
HWI_PRIOR_T hwiPrio,
|
||||
HWI_MODE_T mode,
|
||||
HWI_PROC_FUNC handler,
|
||||
HWI_ARG_T arg)
|
||||
HWI_MODE_T hwiMode,
|
||||
HWI_PROC_FUNC hwiHandler,
|
||||
HwiIrqParam *irqParam)
|
||||
{
|
||||
(VOID)mode;
|
||||
(VOID)hwiMode;
|
||||
UINTPTR intSave;
|
||||
|
||||
if (handler == NULL) {
|
||||
if (hwiHandler == NULL) {
|
||||
return OS_ERRNO_HWI_PROC_FUNC_NULL;
|
||||
}
|
||||
|
||||
@@ -300,11 +337,23 @@ LITE_OS_SEC_TEXT_INIT UINT32 ArchHwiCreate(HWI_HANDLE_T hwiNum,
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
#if (LOSCFG_PLATFORM_HWI_WITH_ARG == 1)
|
||||
OsSetVector(hwiNum, handler, arg);
|
||||
if (irqParam != NULL) {
|
||||
OsSetVector(hwiNum, hwiHandler, irqParam->pDevId);
|
||||
} else {
|
||||
OsSetVector(hwiNum, hwiHandler, NULL);
|
||||
}
|
||||
#else
|
||||
(VOID)arg;
|
||||
OsSetVector(hwiNum, handler);
|
||||
(VOID)irqParam;
|
||||
OsSetVector(hwiNum, hwiHandler);
|
||||
#endif
|
||||
|
||||
#if (LOSCFG_DEBUG_TOOLS == 1)
|
||||
if ((irqParam != NULL) && (irqParam->pName != NULL)) {
|
||||
g_hwiFormName[hwiNum + OS_SYS_VECTOR_CNT] = (CHAR *)irqParam->pName;
|
||||
}
|
||||
g_hwiFormCnt[hwiNum + OS_SYS_VECTOR_CNT] = 0;
|
||||
#endif
|
||||
|
||||
HwiUnmask((IRQn_Type)hwiNum);
|
||||
HwiSetPriority((IRQn_Type)hwiNum, hwiPrio);
|
||||
|
||||
@@ -317,11 +366,13 @@ LITE_OS_SEC_TEXT_INIT UINT32 ArchHwiCreate(HWI_HANDLE_T hwiNum,
|
||||
Function : ArchHwiDelete
|
||||
Description : Delete hardware interrupt
|
||||
Input : hwiNum --- hwi num to delete
|
||||
irqParam --- param of the hwi handler
|
||||
Output : None
|
||||
Return : LOS_OK on success or error code on failure
|
||||
**************************************************************************** */
|
||||
LITE_OS_SEC_TEXT_INIT UINT32 ArchHwiDelete(HWI_HANDLE_T hwiNum)
|
||||
LITE_OS_SEC_TEXT_INIT UINT32 ArchHwiDelete(HWI_HANDLE_T hwiNum, HwiIrqParam *irqParam)
|
||||
{
|
||||
(VOID)irqParam;
|
||||
UINT32 intSave;
|
||||
|
||||
if (hwiNum >= OS_HWI_MAX_NUM) {
|
||||
|
||||
@@ -55,8 +55,8 @@ 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_FSR EQU 0xE000ED28 ;include BusFault/MemFault/UsageFault State Register
|
||||
OS_NVIC_HFSR EQU 0xE000ED2C ;HardFault State Register
|
||||
OS_NVIC_BFAR EQU 0xE000ED38
|
||||
OS_NVIC_MMAR EQU 0xE000ED34
|
||||
OS_NVIC_ACT_BASE EQU 0xE000E300
|
||||
@@ -179,7 +179,7 @@ _hwiActiveCheck
|
||||
CMP R3, #0
|
||||
BEQ _hwiActiveCheckNext
|
||||
|
||||
; exc occured in IRQ
|
||||
; exc occurred in IRQ
|
||||
ORR R0, R0, #FLAG_HWI_ACTIVE
|
||||
RBIT R2, R3
|
||||
CLZ R2, R2
|
||||
@@ -217,19 +217,19 @@ _hwiActiveCheckNext
|
||||
AND R2, R2,R3
|
||||
CMP R2,#0
|
||||
BNE _ExcInMSP
|
||||
; exc occured in Task or Init or exc
|
||||
; exc occurred 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
|
||||
BEQ _ExcInMSP ; if exc occurred in Init then branch
|
||||
|
||||
|
||||
CMP LR, #0xFFFFFFED ;auto push floating registers
|
||||
BNE _NoFloatInPsp
|
||||
|
||||
; exc occured in Task
|
||||
; exc occurred in Task
|
||||
MOV R2, R13
|
||||
SUB R13, #96 ; add 8 Bytes reg(for STMFD)
|
||||
|
||||
|
||||
@@ -40,19 +40,46 @@
|
||||
#include "los_sched.h"
|
||||
#include "los_memory.h"
|
||||
#include "los_membox.h"
|
||||
#if (LOSCFG_CPUP_INCLUDE_IRQ == 1)
|
||||
#include "los_cpup.h"
|
||||
#endif
|
||||
|
||||
/*lint -save -e40 -e522 -e533*/
|
||||
UINT32 g_intCount = 0;
|
||||
|
||||
/*lint -restore*/
|
||||
#pragma location = ".data.vector"
|
||||
#pragma data_alignment=LOSCFG_ARCH_HWI_VECTOR_ALIGN
|
||||
#pragma data_alignment = LOSCFG_ARCH_HWI_VECTOR_ALIGN
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* hardware interrupt form mapping handling function array.
|
||||
*/
|
||||
STATIC HWI_PROC_FUNC g_hwiForm[OS_VECTOR_CNT] = {0};
|
||||
|
||||
#if (LOSCFG_DEBUG_TOOLS == 1)
|
||||
STATIC UINT32 g_hwiFormCnt[OS_HWI_MAX_NUM] = {0};
|
||||
STATIC CHAR *g_hwiFormName[OS_HWI_MAX_NUM] = {0};
|
||||
|
||||
UINT32 OsGetHwiFormCnt(UINT32 index)
|
||||
{
|
||||
return g_hwiFormCnt[index];
|
||||
}
|
||||
|
||||
CHAR *OsGetHwiFormName(UINT32 index)
|
||||
{
|
||||
return g_hwiFormName[index];
|
||||
}
|
||||
|
||||
BOOL OsGetHwiCreated(UINT32 index)
|
||||
{
|
||||
if (g_hwiForm[index] != (HWI_PROC_FUNC)HalHwiDefaultHandler) {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if (LOSCFG_PLATFORM_HWI_WITH_ARG == 1)
|
||||
|
||||
typedef struct {
|
||||
@@ -198,8 +225,7 @@ inline UINT32 ArchIsIntActive(VOID)
|
||||
/*lint -e529*/
|
||||
LITE_OS_SEC_TEXT_MINOR VOID HalHwiDefaultHandler(VOID)
|
||||
{
|
||||
UINT32 irqNum = HwiNumGet();
|
||||
PRINT_ERR("%s irqnum:%u\n", __FUNCTION__, irqNum);
|
||||
PRINT_ERR("%s irqnum:%u\n", __FUNCTION__, HwiNumGet());
|
||||
while (1) {}
|
||||
}
|
||||
|
||||
@@ -240,6 +266,9 @@ LITE_OS_SEC_TEXT VOID HalInterrupt(VOID)
|
||||
hwiIndex = HwiNumGet();
|
||||
|
||||
OsHookCall(LOS_HOOK_TYPE_ISR_ENTER, hwiIndex);
|
||||
#if (LOSCFG_CPUP_INCLUDE_IRQ == 1)
|
||||
OsCpupIrqStart(hwiIndex);
|
||||
#endif
|
||||
|
||||
HalPreInterruptHandler(hwiIndex);
|
||||
|
||||
@@ -253,8 +282,16 @@ LITE_OS_SEC_TEXT VOID HalInterrupt(VOID)
|
||||
}
|
||||
#endif
|
||||
|
||||
#if (LOSCFG_DEBUG_TOOLS == 1)
|
||||
++g_hwiFormCnt[hwiIndex];
|
||||
#endif
|
||||
|
||||
HalAftInterruptHandler(hwiIndex);
|
||||
|
||||
#if (LOSCFG_CPUP_INCLUDE_IRQ == 1)
|
||||
OsCpupIrqEnd(hwiIndex);
|
||||
#endif
|
||||
|
||||
OsHookCall(LOS_HOOK_TYPE_ISR_EXIT, hwiIndex);
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
@@ -267,22 +304,22 @@ LITE_OS_SEC_TEXT VOID HalInterrupt(VOID)
|
||||
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
|
||||
hwiMode --- unused
|
||||
hwiHandler --- hwi handler
|
||||
irqParam --- param of the hwi handler
|
||||
Output : None
|
||||
Return : LOS_OK on success or error code on failure
|
||||
**************************************************************************** */
|
||||
LITE_OS_SEC_TEXT_INIT UINT32 ArchHwiCreate(HWI_HANDLE_T hwiNum,
|
||||
HWI_PRIOR_T hwiPrio,
|
||||
HWI_MODE_T mode,
|
||||
HWI_PROC_FUNC handler,
|
||||
HWI_ARG_T arg)
|
||||
HWI_MODE_T hwiMode,
|
||||
HWI_PROC_FUNC hwiHandler,
|
||||
HwiIrqParam *irqParam)
|
||||
{
|
||||
(VOID)mode;
|
||||
(VOID)hwiMode;
|
||||
UINTPTR intSave;
|
||||
|
||||
if (handler == NULL) {
|
||||
if (hwiHandler == NULL) {
|
||||
return OS_ERRNO_HWI_PROC_FUNC_NULL;
|
||||
}
|
||||
|
||||
@@ -300,11 +337,23 @@ LITE_OS_SEC_TEXT_INIT UINT32 ArchHwiCreate(HWI_HANDLE_T hwiNum,
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
#if (LOSCFG_PLATFORM_HWI_WITH_ARG == 1)
|
||||
OsSetVector(hwiNum, handler, arg);
|
||||
if (irqParam != NULL) {
|
||||
OsSetVector(hwiNum, hwiHandler, irqParam->pDevId);
|
||||
} else {
|
||||
OsSetVector(hwiNum, hwiHandler, NULL);
|
||||
}
|
||||
#else
|
||||
(VOID)arg;
|
||||
OsSetVector(hwiNum, handler);
|
||||
(VOID)irqParam;
|
||||
OsSetVector(hwiNum, hwiHandler);
|
||||
#endif
|
||||
|
||||
#if (LOSCFG_DEBUG_TOOLS == 1)
|
||||
if ((irqParam != NULL) && (irqParam->pName != NULL)) {
|
||||
g_hwiFormName[hwiNum + OS_SYS_VECTOR_CNT] = (CHAR *)irqParam->pName;
|
||||
}
|
||||
g_hwiFormCnt[hwiNum + OS_SYS_VECTOR_CNT] = 0;
|
||||
#endif
|
||||
|
||||
HwiUnmask((IRQn_Type)hwiNum);
|
||||
HwiSetPriority((IRQn_Type)hwiNum, hwiPrio);
|
||||
|
||||
@@ -317,11 +366,13 @@ LITE_OS_SEC_TEXT_INIT UINT32 ArchHwiCreate(HWI_HANDLE_T hwiNum,
|
||||
Function : ArchHwiDelete
|
||||
Description : Delete hardware interrupt
|
||||
Input : hwiNum --- hwi num to delete
|
||||
irqParam --- param of the hwi handler
|
||||
Output : None
|
||||
Return : LOS_OK on success or error code on failure
|
||||
**************************************************************************** */
|
||||
LITE_OS_SEC_TEXT_INIT UINT32 ArchHwiDelete(HWI_HANDLE_T hwiNum)
|
||||
LITE_OS_SEC_TEXT_INIT UINT32 ArchHwiDelete(HWI_HANDLE_T hwiNum, HwiIrqParam *irqParam)
|
||||
{
|
||||
(VOID)irqParam;
|
||||
UINT32 intSave;
|
||||
|
||||
if (hwiNum >= OS_HWI_MAX_NUM) {
|
||||
|
||||
@@ -34,7 +34,7 @@
|
||||
#include "los_config.h"
|
||||
#include "los_list.h"
|
||||
|
||||
#pragma data_alignment=0x4
|
||||
#pragma data_alignment = 0x4
|
||||
STATIC UINT8 g_secureHeap[LOSCFG_SECURE_HEAP_SIZE] = {0};
|
||||
STATIC LOS_DL_LIST g_secureHeapFreeList = {NULL, NULL};
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2022 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:
|
||||
@@ -121,6 +121,29 @@ typedef struct TagTskContext {
|
||||
*/
|
||||
extern VOID HalStartToRun(VOID);
|
||||
|
||||
#if (LOSCFG_SECURE == 1)
|
||||
/**
|
||||
* @ingroup los_config
|
||||
* @brief: User Task Stack Initialize.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to init a user task stack.
|
||||
*
|
||||
* @attention:
|
||||
* <ul><li>None.</li></ul>
|
||||
*
|
||||
* @param: context [IN] Task context.
|
||||
* @param: taskEntry [IN] Task entry function address.
|
||||
* @param: stack [IN] Task stack address.
|
||||
*
|
||||
* @retval None.
|
||||
*
|
||||
* @par Dependency: <ul><li>los_config.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see None.
|
||||
*/
|
||||
extern VOID HalUserTaskStackInit(TaskContext *context, UINTPTR taskEntry, UINTPTR stack);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
|
||||
@@ -148,6 +148,15 @@ VOID *ArchSignalContextInit(VOID *stackPointer, VOID *stackTop, UINTPTR sigHandl
|
||||
return (VOID *)context;
|
||||
}
|
||||
|
||||
#if (LOSCFG_SECURE == 1)
|
||||
VOID HalUserTaskStackInit(TaskContext *context, UINTPTR taskEntry, UINTPTR stack)
|
||||
{
|
||||
context->uwR0 = stack;
|
||||
context->uwPC = (UINT32)taskEntry;
|
||||
context->uwxPSR = 0x01000000L; /* Thumb flag, always set 1 */
|
||||
}
|
||||
#endif
|
||||
|
||||
LITE_OS_SEC_TEXT_INIT UINT32 ArchStartSchedule(VOID)
|
||||
{
|
||||
(VOID)LOS_IntLock();
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2022 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:
|
||||
@@ -40,6 +40,12 @@
|
||||
.equ OS_NVIC_PENDSV_PRI, 0xF0F00000
|
||||
.equ OS_NVIC_PENDSVSET, 0x10000000
|
||||
.equ OS_TASK_STATUS_RUNNING, 0x0010
|
||||
.equ OS_CONTROL_FPCA_ENABLE, 0x4
|
||||
.equ OS_CONTROL_KERNEL_MODE, 0x2
|
||||
#if (LOSCFG_SECURE == 1)
|
||||
.equ OS_CONTROL_USER_MODE, 0x3
|
||||
.equ OS_TASK_FLAG_USER_TASK, 0x0200
|
||||
#endif
|
||||
|
||||
.section .text
|
||||
.thumb
|
||||
@@ -63,7 +69,7 @@ HalStartToRun:
|
||||
ldr r5, =OS_NVIC_PENDSV_PRI
|
||||
str r5, [r4]
|
||||
|
||||
mov r0, #2
|
||||
mov r0, #OS_CONTROL_KERNEL_MODE
|
||||
msr CONTROL, r0
|
||||
|
||||
ldr r1, =g_losTask
|
||||
@@ -141,7 +147,7 @@ ArchTaskSchedule:
|
||||
bx lr
|
||||
dsb
|
||||
isb
|
||||
.fnend
|
||||
.fnend
|
||||
|
||||
.type HalPendSV, %function
|
||||
.global HalPendSV
|
||||
@@ -194,6 +200,14 @@ SignalContextRestore:
|
||||
vldmia r1!, {d8-d15}
|
||||
|
||||
__DisabledFPU2:
|
||||
#if (LOSCFG_SECURE == 1)
|
||||
ldrh r7, [r0, #4]
|
||||
tst r7, #OS_TASK_FLAG_USER_TASK
|
||||
ite eq
|
||||
moveq r3, #OS_CONTROL_KERNEL_MODE
|
||||
movne r3, #OS_CONTROL_USER_MODE
|
||||
msr CONTROL, r3
|
||||
#endif
|
||||
ldmfd r1!, {r4-r12}
|
||||
msr psp, r1
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2022 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:
|
||||
@@ -57,15 +57,15 @@
|
||||
|
||||
.equ FLAG_ADDR_VALID, 0x10000
|
||||
.equ FLAG_HWI_ACTIVE, 0x20000
|
||||
.equ FLAG_NO_FLOAT, 0x10000000
|
||||
.equ FLAG_NO_FLOAT, 0x10000000
|
||||
|
||||
.equ OS_NVIC_FSR , 0xE000ED28 //include BusFault/MemFault/UsageFault State Register
|
||||
.equ OS_NVIC_HFSR , 0xE000ED2C //HardFault State Register
|
||||
.equ OS_NVIC_BFAR , 0xE000ED38
|
||||
.equ OS_NVIC_MMAR , 0xE000ED34
|
||||
.equ OS_NVIC_ACT_BASE , 0xE000E300
|
||||
.equ OS_NVIC_SHCSRS , 0xE000ED24
|
||||
.equ OS_NVIC_SHCSR_MASK , 0xC00
|
||||
.equ OS_NVIC_FSR, 0xE000ED28 //include BusFault/MemFault/UsageFault State Register
|
||||
.equ OS_NVIC_HFSR, 0xE000ED2C //HardFault State Register
|
||||
.equ OS_NVIC_BFAR, 0xE000ED38
|
||||
.equ OS_NVIC_MMAR, 0xE000ED34
|
||||
.equ OS_NVIC_ACT_BASE, 0xE000E300
|
||||
.equ OS_NVIC_SHCSRS, 0xE000ED24
|
||||
.equ OS_NVIC_SHCSR_MASK, 0xC00
|
||||
|
||||
.type HalExcNMI, %function
|
||||
.global HalExcNMI
|
||||
@@ -155,10 +155,25 @@ HalExcSvcCall:
|
||||
.cantunwind
|
||||
TST LR, #0x4
|
||||
ITE EQ
|
||||
MRSEQ R0, MSP
|
||||
MRSNE R0, PSP
|
||||
LDR R1, [R0,#24]
|
||||
LDRB R0, [R1,#-2]
|
||||
MRSEQ R1, MSP
|
||||
BNE _svcCallFromPsp
|
||||
B _svcCall
|
||||
_svcCallFromPsp:
|
||||
#ifdef LOSCFG_SECURE
|
||||
PUSH {R0-R12, LR}
|
||||
MOV R0, SP
|
||||
CPSIE I
|
||||
BL OsSyscallHandle
|
||||
CPSID I
|
||||
MRS R12, PSP
|
||||
STM R12, {R0-R1}
|
||||
POP {R0-R12, LR}
|
||||
BX LR
|
||||
#endif
|
||||
MRS R1, PSP
|
||||
_svcCall:
|
||||
LDR R0, [R1,#24]
|
||||
LDRB R0, [R0,#-2]
|
||||
MOV R1, #0
|
||||
B osExcDispatch
|
||||
.fnend
|
||||
@@ -263,7 +278,7 @@ _hwiActiveCheck:
|
||||
CMP R3, #0
|
||||
BEQ _hwiActiveCheckNext
|
||||
|
||||
// exc occured in IRQ
|
||||
// exc occurred in IRQ
|
||||
ORR R0, R0, #FLAG_HWI_ACTIVE
|
||||
RBIT R2, R3
|
||||
CLZ R2, R2
|
||||
@@ -284,7 +299,7 @@ _ExcInMSP:
|
||||
PUSH {R4-R12} // store message-->exc: {R4-R12}
|
||||
VPUSH {D8-D15} // FPU
|
||||
B _handleEntry
|
||||
.fnend
|
||||
.fnend
|
||||
|
||||
.type _NoFloatInMsp, %function
|
||||
.global _NoFloatInMsp
|
||||
@@ -298,7 +313,7 @@ _NoFloatInMsp:
|
||||
PUSH {R4-R12} // store message-->exc: {R4-R12}
|
||||
ORR R0, R0, #FLAG_NO_FLOAT
|
||||
B _handleEntry
|
||||
.fnend
|
||||
.fnend
|
||||
|
||||
.type _hwiActiveCheckNext, %function
|
||||
.global _hwiActiveCheckNext
|
||||
@@ -316,19 +331,19 @@ _hwiActiveCheckNext:
|
||||
AND R2, R2,R3
|
||||
CMP R2,#0
|
||||
BNE _ExcInMSP
|
||||
// exc occured in Task or Init or exc
|
||||
// exc occurred 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
|
||||
BEQ _ExcInMSP // if exc occurred in Init then branch
|
||||
|
||||
|
||||
CMP LR, #0xFFFFFFED //auto push floating registers
|
||||
BNE _NoFloatInPsp
|
||||
|
||||
// exc occured in Task
|
||||
// exc occurred in Task
|
||||
MOV R2, R13
|
||||
SUB R13, #96 // add 8 Bytes reg(for STMFD)
|
||||
|
||||
@@ -347,7 +362,7 @@ _hwiActiveCheckNext:
|
||||
VSTMDB R2!, {D8-D15} // FPU
|
||||
STMFD R2!, {R4-R11}
|
||||
B _handleEntry
|
||||
.fnend
|
||||
.fnend
|
||||
|
||||
.type _NoFloatInPsp, %function
|
||||
.global _NoFloatInPsp
|
||||
@@ -367,7 +382,7 @@ _NoFloatInPsp:
|
||||
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
|
||||
.fnend
|
||||
.fnend
|
||||
|
||||
.type _handleEntry, %function
|
||||
.global _handleEntry
|
||||
@@ -380,4 +395,4 @@ _handleEntry:
|
||||
B HalExcHandleEntry
|
||||
|
||||
NOP
|
||||
.fnend
|
||||
.fnend
|
||||
|
||||
@@ -39,18 +39,42 @@
|
||||
#include "los_sched.h"
|
||||
#include "los_memory.h"
|
||||
#include "los_membox.h"
|
||||
#if (LOSCFG_CPUP_INCLUDE_IRQ == 1)
|
||||
#include "los_cpup.h"
|
||||
#endif
|
||||
|
||||
/*lint -save -e40 -e522 -e533*/
|
||||
UINT32 g_intCount = 0;
|
||||
|
||||
/*lint -restore*/
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Hardware interrupt form mapping handling function array.
|
||||
*/
|
||||
STATIC HWI_PROC_FUNC __attribute__((aligned(LOSCFG_ARCH_HWI_VECTOR_ALIGN))) g_hwiForm[OS_VECTOR_CNT] = {0};
|
||||
|
||||
#if (LOSCFG_DEBUG_TOOLS == 1)
|
||||
STATIC UINT32 g_hwiFormCnt[OS_HWI_MAX_NUM] = {0};
|
||||
STATIC CHAR *g_hwiFormName[OS_HWI_MAX_NUM] = {0};
|
||||
|
||||
UINT32 OsGetHwiFormCnt(UINT32 index)
|
||||
{
|
||||
return g_hwiFormCnt[index];
|
||||
}
|
||||
|
||||
CHAR *OsGetHwiFormName(UINT32 index)
|
||||
{
|
||||
return g_hwiFormName[index];
|
||||
}
|
||||
|
||||
BOOL OsGetHwiCreated(UINT32 index)
|
||||
{
|
||||
if (g_hwiForm[index] != (HWI_PROC_FUNC)HalHwiDefaultHandler) {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if (LOSCFG_PLATFORM_HWI_WITH_ARG == 1)
|
||||
|
||||
typedef struct {
|
||||
@@ -193,11 +217,9 @@ inline UINT32 ArchIsIntActive(VOID)
|
||||
Output : None
|
||||
Return : None
|
||||
**************************************************************************** */
|
||||
/*lint -e529*/
|
||||
LITE_OS_SEC_TEXT_MINOR VOID HalHwiDefaultHandler(VOID)
|
||||
{
|
||||
UINT32 irqNum = HwiNumGet();
|
||||
PRINT_ERR("%s irqnum:%u\n", __FUNCTION__, irqNum);
|
||||
PRINT_ERR("%s irqnum:%u\n", __FUNCTION__, HwiNumGet());
|
||||
while (1) {}
|
||||
}
|
||||
|
||||
@@ -236,6 +258,9 @@ LITE_OS_SEC_TEXT VOID HalInterrupt(VOID)
|
||||
hwiIndex = HwiNumGet();
|
||||
|
||||
OsHookCall(LOS_HOOK_TYPE_ISR_ENTER, hwiIndex);
|
||||
#if (LOSCFG_CPUP_INCLUDE_IRQ == 1)
|
||||
OsCpupIrqStart(hwiIndex);
|
||||
#endif
|
||||
|
||||
HalPreInterruptHandler(hwiIndex);
|
||||
|
||||
@@ -249,8 +274,16 @@ LITE_OS_SEC_TEXT VOID HalInterrupt(VOID)
|
||||
}
|
||||
#endif
|
||||
|
||||
#if (LOSCFG_DEBUG_TOOLS == 1)
|
||||
++g_hwiFormCnt[hwiIndex];
|
||||
#endif
|
||||
|
||||
HalAftInterruptHandler(hwiIndex);
|
||||
|
||||
#if (LOSCFG_CPUP_INCLUDE_IRQ == 1)
|
||||
OsCpupIrqEnd(hwiIndex);
|
||||
#endif
|
||||
|
||||
OsHookCall(LOS_HOOK_TYPE_ISR_EXIT, hwiIndex);
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
@@ -263,22 +296,22 @@ LITE_OS_SEC_TEXT VOID HalInterrupt(VOID)
|
||||
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
|
||||
hwiMode --- unused
|
||||
hwiHandler --- hwi handler
|
||||
irqParam --- param of the hwi handler
|
||||
Output : None
|
||||
Return : LOS_OK on success or error code on failure
|
||||
**************************************************************************** */
|
||||
LITE_OS_SEC_TEXT_INIT UINT32 ArchHwiCreate(HWI_HANDLE_T hwiNum,
|
||||
HWI_PRIOR_T hwiPrio,
|
||||
HWI_MODE_T mode,
|
||||
HWI_PROC_FUNC handler,
|
||||
HWI_ARG_T arg)
|
||||
HWI_MODE_T hwiMode,
|
||||
HWI_PROC_FUNC hwiHandler,
|
||||
HwiIrqParam *irqParam)
|
||||
{
|
||||
(VOID)mode;
|
||||
(VOID)hwiMode;
|
||||
UINT32 intSave;
|
||||
|
||||
if (handler == NULL) {
|
||||
if (hwiHandler == NULL) {
|
||||
return OS_ERRNO_HWI_PROC_FUNC_NULL;
|
||||
}
|
||||
|
||||
@@ -296,11 +329,23 @@ LITE_OS_SEC_TEXT_INIT UINT32 ArchHwiCreate(HWI_HANDLE_T hwiNum,
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
#if (LOSCFG_PLATFORM_HWI_WITH_ARG == 1)
|
||||
OsSetVector(hwiNum, handler, arg);
|
||||
if (irqParam != NULL) {
|
||||
OsSetVector(hwiNum, hwiHandler, irqParam->pDevId);
|
||||
} else {
|
||||
OsSetVector(hwiNum, hwiHandler, NULL);
|
||||
}
|
||||
#else
|
||||
(VOID)arg;
|
||||
OsSetVector(hwiNum, handler);
|
||||
(VOID)irqParam;
|
||||
OsSetVector(hwiNum, hwiHandler);
|
||||
#endif
|
||||
|
||||
#if (LOSCFG_DEBUG_TOOLS == 1)
|
||||
if ((irqParam != NULL) && (irqParam->pName != NULL)) {
|
||||
g_hwiFormName[hwiNum + OS_SYS_VECTOR_CNT] = (CHAR *)irqParam->pName;
|
||||
}
|
||||
g_hwiFormCnt[hwiNum + OS_SYS_VECTOR_CNT] = 0;
|
||||
#endif
|
||||
|
||||
HwiUnmask((IRQn_Type)hwiNum);
|
||||
HwiSetPriority((IRQn_Type)hwiNum, hwiPrio);
|
||||
|
||||
@@ -313,11 +358,13 @@ LITE_OS_SEC_TEXT_INIT UINT32 ArchHwiCreate(HWI_HANDLE_T hwiNum,
|
||||
Function : ArchHwiDelete
|
||||
Description : Delete hardware interrupt
|
||||
Input : hwiNum --- hwi num to delete
|
||||
irqParam --- param of the hwi handler
|
||||
Output : None
|
||||
Return : LOS_OK on success or error code on failure
|
||||
**************************************************************************** */
|
||||
LITE_OS_SEC_TEXT_INIT UINT32 ArchHwiDelete(HWI_HANDLE_T hwiNum)
|
||||
LITE_OS_SEC_TEXT_INIT UINT32 ArchHwiDelete(HWI_HANDLE_T hwiNum, HwiIrqParam *irqParam)
|
||||
{
|
||||
(VOID)irqParam;
|
||||
UINT32 intSave;
|
||||
|
||||
if (hwiNum >= OS_HWI_MAX_NUM) {
|
||||
@@ -602,7 +649,7 @@ LITE_OS_SEC_TEXT_INIT VOID HalHwiInit(VOID)
|
||||
|
||||
/* Enable USGFAULT, BUSFAULT, MEMFAULT */
|
||||
*(volatile UINT32 *)OS_NVIC_SHCSR |= (USGFAULT | BUSFAULT | MEMFAULT);
|
||||
|
||||
|
||||
/* Enable DIV 0 and unaligned exception */
|
||||
#ifdef LOSCFG_ARCH_UNALIGNED_EXC
|
||||
*(volatile UINT32 *)OS_NVIC_CCR |= (DIV0FAULT | UNALIGNFAULT);
|
||||
|
||||
@@ -190,7 +190,7 @@ _hwiActiveCheck
|
||||
CMP R3, #0
|
||||
BEQ _hwiActiveCheckNext
|
||||
|
||||
; exc occured in IRQ
|
||||
; exc occurred in IRQ
|
||||
ORR R0, R0, #FLAG_HWI_ACTIVE
|
||||
RBIT R2, R3
|
||||
CLZ R2, R2
|
||||
@@ -228,19 +228,19 @@ _hwiActiveCheckNext
|
||||
AND R2, R2,R3
|
||||
CMP R2,#0
|
||||
BNE _ExcInMSP
|
||||
; exc occured in Task or Init or exc
|
||||
; exc occurred 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
|
||||
BEQ _ExcInMSP ; if exc occurred in Init then branch
|
||||
|
||||
|
||||
CMP LR, #0xFFFFFFED ;auto push floating registers
|
||||
BNE _NoFloatInPsp
|
||||
|
||||
; exc occured in Task
|
||||
; exc occurred in Task
|
||||
MOV R2, R13
|
||||
SUB R13, #96 ; add 8 Bytes reg(for STMFD)
|
||||
|
||||
|
||||
@@ -40,14 +40,15 @@
|
||||
#include "los_sched.h"
|
||||
#include "los_memory.h"
|
||||
#include "los_membox.h"
|
||||
#if (LOSCFG_CPUP_INCLUDE_IRQ == 1)
|
||||
#include "los_cpup.h"
|
||||
#endif
|
||||
|
||||
/*lint -save -e40 -e522 -e533*/
|
||||
UINT32 g_intCount = 0;
|
||||
|
||||
/*lint -restore*/
|
||||
#ifdef __ICCARM__
|
||||
#pragma location = ".data.vector"
|
||||
#pragma data_alignment=LOSCFG_ARCH_HWI_VECTOR_ALIGN
|
||||
#pragma data_alignment = LOSCFG_ARCH_HWI_VECTOR_ALIGN
|
||||
#elif defined(__CC_ARM) || defined(__GNUC__)
|
||||
LITE_OS_SEC_VEC
|
||||
#endif
|
||||
@@ -57,6 +58,30 @@ LITE_OS_SEC_VEC
|
||||
*/
|
||||
STATIC HWI_PROC_FUNC g_hwiForm[OS_VECTOR_CNT] = {0};
|
||||
|
||||
#if (LOSCFG_DEBUG_TOOLS == 1)
|
||||
STATIC UINT32 g_hwiFormCnt[OS_HWI_MAX_NUM] = {0};
|
||||
STATIC CHAR *g_hwiFormName[OS_HWI_MAX_NUM] = {0};
|
||||
|
||||
UINT32 OsGetHwiFormCnt(UINT32 index)
|
||||
{
|
||||
return g_hwiFormCnt[index];
|
||||
}
|
||||
|
||||
CHAR *OsGetHwiFormName(UINT32 index)
|
||||
{
|
||||
return g_hwiFormName[index];
|
||||
}
|
||||
|
||||
BOOL OsGetHwiCreated(UINT32 index)
|
||||
{
|
||||
if (g_hwiForm[index] != (HWI_PROC_FUNC)HalHwiDefaultHandler) {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if (LOSCFG_PLATFORM_HWI_WITH_ARG == 1)
|
||||
|
||||
typedef struct {
|
||||
@@ -202,8 +227,7 @@ inline UINT32 ArchIsIntActive(VOID)
|
||||
/*lint -e529*/
|
||||
LITE_OS_SEC_TEXT_MINOR VOID HalHwiDefaultHandler(VOID)
|
||||
{
|
||||
UINT32 irqNum = HwiNumGet();
|
||||
PRINT_ERR("%s irqnum:%u\n", __FUNCTION__, irqNum);
|
||||
PRINT_ERR("%s irqnum:%u\n", __FUNCTION__, HwiNumGet());
|
||||
while (1) {}
|
||||
}
|
||||
|
||||
@@ -242,6 +266,9 @@ LITE_OS_SEC_TEXT VOID HalInterrupt(VOID)
|
||||
hwiIndex = HwiNumGet();
|
||||
|
||||
OsHookCall(LOS_HOOK_TYPE_ISR_ENTER, hwiIndex);
|
||||
#if (LOSCFG_CPUP_INCLUDE_IRQ == 1)
|
||||
OsCpupIrqStart(hwiIndex);
|
||||
#endif
|
||||
|
||||
HalPreInterruptHandler(hwiIndex);
|
||||
|
||||
@@ -255,8 +282,16 @@ LITE_OS_SEC_TEXT VOID HalInterrupt(VOID)
|
||||
}
|
||||
#endif
|
||||
|
||||
#if (LOSCFG_DEBUG_TOOLS == 1)
|
||||
++g_hwiFormCnt[hwiIndex];
|
||||
#endif
|
||||
|
||||
HalAftInterruptHandler(hwiIndex);
|
||||
|
||||
#if (LOSCFG_CPUP_INCLUDE_IRQ == 1)
|
||||
OsCpupIrqEnd(hwiIndex);
|
||||
#endif
|
||||
|
||||
OsHookCall(LOS_HOOK_TYPE_ISR_EXIT, hwiIndex);
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
@@ -269,22 +304,22 @@ LITE_OS_SEC_TEXT VOID HalInterrupt(VOID)
|
||||
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
|
||||
hwiMode --- unused
|
||||
hwiHandler --- hwi handler
|
||||
irqParam --- param of the hwi handler
|
||||
Output : None
|
||||
Return : LOS_OK on success or error code on failure
|
||||
**************************************************************************** */
|
||||
LITE_OS_SEC_TEXT_INIT UINT32 ArchHwiCreate(HWI_HANDLE_T hwiNum,
|
||||
HWI_PRIOR_T hwiPrio,
|
||||
HWI_MODE_T mode,
|
||||
HWI_PROC_FUNC handler,
|
||||
HWI_ARG_T arg)
|
||||
HWI_MODE_T hwiMode,
|
||||
HWI_PROC_FUNC hwiHandler,
|
||||
HwiIrqParam *irqParam)
|
||||
{
|
||||
(VOID)mode;
|
||||
(VOID)hwiMode;
|
||||
UINT32 intSave;
|
||||
|
||||
if (handler == NULL) {
|
||||
if (hwiHandler == NULL) {
|
||||
return OS_ERRNO_HWI_PROC_FUNC_NULL;
|
||||
}
|
||||
|
||||
@@ -302,11 +337,23 @@ LITE_OS_SEC_TEXT_INIT UINT32 ArchHwiCreate(HWI_HANDLE_T hwiNum,
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
#if (LOSCFG_PLATFORM_HWI_WITH_ARG == 1)
|
||||
OsSetVector(hwiNum, handler, arg);
|
||||
if (irqParam != NULL) {
|
||||
OsSetVector(hwiNum, hwiHandler, irqParam->pDevId);
|
||||
} else {
|
||||
OsSetVector(hwiNum, hwiHandler, NULL);
|
||||
}
|
||||
#else
|
||||
(VOID)arg;
|
||||
OsSetVector(hwiNum, handler);
|
||||
(VOID)irqParam;
|
||||
OsSetVector(hwiNum, hwiHandler);
|
||||
#endif
|
||||
|
||||
#if (LOSCFG_DEBUG_TOOLS == 1)
|
||||
if ((irqParam != NULL) && (irqParam->pName != NULL)) {
|
||||
g_hwiFormName[hwiNum + OS_SYS_VECTOR_CNT] = (CHAR *)irqParam->pName;
|
||||
}
|
||||
g_hwiFormCnt[hwiNum + OS_SYS_VECTOR_CNT] = 0;
|
||||
#endif
|
||||
|
||||
HwiUnmask((IRQn_Type)hwiNum);
|
||||
HwiSetPriority((IRQn_Type)hwiNum, hwiPrio);
|
||||
|
||||
@@ -319,11 +366,13 @@ LITE_OS_SEC_TEXT_INIT UINT32 ArchHwiCreate(HWI_HANDLE_T hwiNum,
|
||||
Function : ArchHwiDelete
|
||||
Description : Delete hardware interrupt
|
||||
Input : hwiNum --- hwi num to delete
|
||||
irqParam --- param of the hwi handler
|
||||
Output : None
|
||||
Return : LOS_OK on success or error code on failure
|
||||
**************************************************************************** */
|
||||
LITE_OS_SEC_TEXT_INIT UINT32 ArchHwiDelete(HWI_HANDLE_T hwiNum)
|
||||
LITE_OS_SEC_TEXT_INIT UINT32 ArchHwiDelete(HWI_HANDLE_T hwiNum, HwiIrqParam *irqParam)
|
||||
{
|
||||
(VOID)irqParam;
|
||||
UINT32 intSave;
|
||||
|
||||
if (hwiNum >= OS_HWI_MAX_NUM) {
|
||||
@@ -598,7 +647,7 @@ LITE_OS_SEC_TEXT_INIT VOID HalHwiInit(VOID)
|
||||
|
||||
/* Enable USGFAULT, BUSFAULT, MEMFAULT */
|
||||
*(volatile UINT32 *)OS_NVIC_SHCSR |= (USGFAULT | BUSFAULT | MEMFAULT);
|
||||
|
||||
|
||||
/* Enable DIV 0 and unaligned exception */
|
||||
#ifdef LOSCFG_ARCH_UNALIGNED_EXC
|
||||
*(volatile UINT32 *)OS_NVIC_CCR |= (DIV0FAULT | UNALIGNFAULT);
|
||||
|
||||
0
arch/arm/cortex-m55/gcc/BUILD.gn
Executable file → Normal file
0
arch/arm/cortex-m55/gcc/BUILD.gn
Executable file → Normal file
0
arch/arm/cortex-m55/gcc/NTZ/BUILD.gn
Executable file → Normal file
0
arch/arm/cortex-m55/gcc/NTZ/BUILD.gn
Executable file → Normal file
0
arch/arm/cortex-m55/gcc/NTZ/los_arch_atomic.h
Executable file → Normal file
0
arch/arm/cortex-m55/gcc/NTZ/los_arch_atomic.h
Executable file → Normal file
0
arch/arm/cortex-m55/gcc/NTZ/los_arch_context.h
Executable file → Normal file
0
arch/arm/cortex-m55/gcc/NTZ/los_arch_context.h
Executable file → Normal file
0
arch/arm/cortex-m55/gcc/NTZ/los_arch_interrupt.h
Executable file → Normal file
0
arch/arm/cortex-m55/gcc/NTZ/los_arch_interrupt.h
Executable file → Normal file
0
arch/arm/cortex-m55/gcc/NTZ/los_arch_timer.h
Executable file → Normal file
0
arch/arm/cortex-m55/gcc/NTZ/los_arch_timer.h
Executable file → Normal file
0
arch/arm/cortex-m55/gcc/NTZ/los_context.c
Executable file → Normal file
0
arch/arm/cortex-m55/gcc/NTZ/los_context.c
Executable file → Normal file
0
arch/arm/cortex-m55/gcc/NTZ/los_dispatch.S
Executable file → Normal file
0
arch/arm/cortex-m55/gcc/NTZ/los_dispatch.S
Executable file → Normal file
8
arch/arm/cortex-m55/gcc/NTZ/los_exc.S
Executable file → Normal file
8
arch/arm/cortex-m55/gcc/NTZ/los_exc.S
Executable file → Normal file
@@ -260,7 +260,7 @@ _hwiActiveCheck:
|
||||
CMP R3, #0
|
||||
BEQ _hwiActiveCheckNext
|
||||
|
||||
// exc occured in IRQ
|
||||
// exc occurred in IRQ
|
||||
ORR R0, R0, #FLAG_HWI_ACTIVE
|
||||
RBIT R2, R3
|
||||
CLZ R2, R2
|
||||
@@ -313,19 +313,19 @@ _hwiActiveCheckNext:
|
||||
AND R2, R2, R3
|
||||
CMP R2, #0
|
||||
BNE _ExcInMSP
|
||||
// exc occured in Task or Init or exc
|
||||
// exc occurred 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
|
||||
BEQ _ExcInMSP // if exc occurred in Init then branch
|
||||
|
||||
|
||||
CMP LR, #0xFFFFFFED //auto push floating registers
|
||||
BNE _NoFloatInPsp
|
||||
|
||||
// exc occured in Task
|
||||
// exc occurred in Task
|
||||
MOV R2, R13
|
||||
SUB R13, #96 // add 8 Bytes reg(for STMFD)
|
||||
|
||||
|
||||
82
arch/arm/cortex-m55/gcc/NTZ/los_interrupt.c
Executable file → Normal file
82
arch/arm/cortex-m55/gcc/NTZ/los_interrupt.c
Executable file → Normal file
@@ -38,12 +38,13 @@
|
||||
#include "los_sched.h"
|
||||
#include "los_memory.h"
|
||||
#include "los_membox.h"
|
||||
#if (LOSCFG_CPUP_INCLUDE_IRQ == 1)
|
||||
#include "los_cpup.h"
|
||||
#endif
|
||||
|
||||
#define DEF_HANDLER_START_INDEX 2
|
||||
/*lint -save -e40 -e522 -e533*/
|
||||
UINT32 g_intCount = 0;
|
||||
|
||||
/*lint -restore*/
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
@@ -51,6 +52,30 @@ UINT32 g_intCount = 0;
|
||||
*/
|
||||
STATIC HWI_PROC_FUNC __attribute__((aligned(LOSCFG_ARCH_HWI_VECTOR_ALIGN))) g_hwiForm[OS_VECTOR_CNT] = {0};
|
||||
|
||||
#if (LOSCFG_DEBUG_TOOLS == 1)
|
||||
STATIC UINT32 g_hwiFormCnt[OS_HWI_MAX_NUM] = {0};
|
||||
STATIC CHAR *g_hwiFormName[OS_HWI_MAX_NUM] = {0};
|
||||
|
||||
UINT32 OsGetHwiFormCnt(UINT32 index)
|
||||
{
|
||||
return g_hwiFormCnt[index];
|
||||
}
|
||||
|
||||
CHAR *OsGetHwiFormName(UINT32 index)
|
||||
{
|
||||
return g_hwiFormName[index];
|
||||
}
|
||||
|
||||
BOOL OsGetHwiCreated(UINT32 index)
|
||||
{
|
||||
if (g_hwiForm[index] != (HWI_PROC_FUNC)HalHwiDefaultHandler) {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if (LOSCFG_PLATFORM_HWI_WITH_ARG == 1)
|
||||
|
||||
typedef struct {
|
||||
@@ -193,11 +218,9 @@ inline UINT32 ArchIsIntActive(VOID)
|
||||
Output : None
|
||||
Return : None
|
||||
**************************************************************************** */
|
||||
/*lint -e529*/
|
||||
LITE_OS_SEC_TEXT_MINOR VOID HalHwiDefaultHandler(VOID)
|
||||
{
|
||||
UINT32 irqNum = HwiNumGet();
|
||||
PRINT_ERR("%s irqnum:%u\n", __FUNCTION__, irqNum);
|
||||
PRINT_ERR("%s irqnum:%u\n", __FUNCTION__, HwiNumGet());
|
||||
while (1) {}
|
||||
}
|
||||
|
||||
@@ -236,6 +259,9 @@ LITE_OS_SEC_TEXT VOID HalInterrupt(VOID)
|
||||
hwiIndex = HwiNumGet();
|
||||
|
||||
OsHookCall(LOS_HOOK_TYPE_ISR_ENTER, hwiIndex);
|
||||
#if (LOSCFG_CPUP_INCLUDE_IRQ == 1)
|
||||
OsCpupIrqStart(hwiIndex);
|
||||
#endif
|
||||
|
||||
HalPreInterruptHandler(hwiIndex);
|
||||
|
||||
@@ -249,8 +275,16 @@ LITE_OS_SEC_TEXT VOID HalInterrupt(VOID)
|
||||
}
|
||||
#endif
|
||||
|
||||
#if (LOSCFG_DEBUG_TOOLS == 1)
|
||||
++g_hwiFormCnt[hwiIndex];
|
||||
#endif
|
||||
|
||||
HalAftInterruptHandler(hwiIndex);
|
||||
|
||||
#if (LOSCFG_CPUP_INCLUDE_IRQ == 1)
|
||||
OsCpupIrqEnd(hwiIndex);
|
||||
#endif
|
||||
|
||||
OsHookCall(LOS_HOOK_TYPE_ISR_EXIT, hwiIndex);
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
@@ -263,22 +297,22 @@ LITE_OS_SEC_TEXT VOID HalInterrupt(VOID)
|
||||
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
|
||||
hwiMode --- unused
|
||||
hwiHandler --- hwi handler
|
||||
irqParam --- param of the hwi handler
|
||||
Output : None
|
||||
Return : LOS_OK on success or error code on failure
|
||||
**************************************************************************** */
|
||||
LITE_OS_SEC_TEXT_INIT UINT32 ArchHwiCreate(HWI_HANDLE_T hwiNum,
|
||||
HWI_PRIOR_T hwiPrio,
|
||||
HWI_MODE_T mode,
|
||||
HWI_PROC_FUNC handler,
|
||||
HWI_ARG_T arg)
|
||||
HWI_MODE_T hwiMode,
|
||||
HWI_PROC_FUNC hwiHandler,
|
||||
HwiIrqParam *irqParam)
|
||||
{
|
||||
(VOID)mode;
|
||||
(VOID)hwiMode;
|
||||
UINT32 intSave;
|
||||
|
||||
if (handler == NULL) {
|
||||
if (hwiHandler == NULL) {
|
||||
return OS_ERRNO_HWI_PROC_FUNC_NULL;
|
||||
}
|
||||
|
||||
@@ -296,11 +330,23 @@ LITE_OS_SEC_TEXT_INIT UINT32 ArchHwiCreate(HWI_HANDLE_T hwiNum,
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
#if (LOSCFG_PLATFORM_HWI_WITH_ARG == 1)
|
||||
OsSetVector(hwiNum, handler, arg);
|
||||
if (irqParam != NULL) {
|
||||
OsSetVector(hwiNum, hwiHandler, irqParam->pDevId);
|
||||
} else {
|
||||
OsSetVector(hwiNum, hwiHandler, NULL);
|
||||
}
|
||||
#else
|
||||
(VOID)arg;
|
||||
OsSetVector(hwiNum, handler);
|
||||
(VOID)irqParam;
|
||||
OsSetVector(hwiNum, hwiHandler);
|
||||
#endif
|
||||
|
||||
#if (LOSCFG_DEBUG_TOOLS == 1)
|
||||
if ((irqParam != NULL) && (irqParam->pName != NULL)) {
|
||||
g_hwiFormName[hwiNum + OS_SYS_VECTOR_CNT] = (CHAR *)irqParam->pName;
|
||||
}
|
||||
g_hwiFormCnt[hwiNum + OS_SYS_VECTOR_CNT] = 0;
|
||||
#endif
|
||||
|
||||
HwiUnmask((IRQn_Type)hwiNum);
|
||||
HwiSetPriority((IRQn_Type)hwiNum, hwiPrio);
|
||||
|
||||
@@ -313,11 +359,13 @@ LITE_OS_SEC_TEXT_INIT UINT32 ArchHwiCreate(HWI_HANDLE_T hwiNum,
|
||||
Function : ArchHwiDelete
|
||||
Description : Delete hardware interrupt
|
||||
Input : hwiNum --- hwi num to delete
|
||||
irqParam --- param of the hwi handler
|
||||
Output : None
|
||||
Return : LOS_OK on success or error code on failure
|
||||
**************************************************************************** */
|
||||
LITE_OS_SEC_TEXT_INIT UINT32 ArchHwiDelete(HWI_HANDLE_T hwiNum)
|
||||
LITE_OS_SEC_TEXT_INIT UINT32 ArchHwiDelete(HWI_HANDLE_T hwiNum, HwiIrqParam *irqParam)
|
||||
{
|
||||
(VOID)irqParam;
|
||||
UINT32 intSave;
|
||||
|
||||
if (hwiNum >= OS_HWI_MAX_NUM) {
|
||||
|
||||
0
arch/arm/cortex-m55/gcc/NTZ/los_timer.c
Executable file → Normal file
0
arch/arm/cortex-m55/gcc/NTZ/los_timer.c
Executable file → Normal file
@@ -137,7 +137,7 @@ ArchTaskSchedule:
|
||||
dsb
|
||||
isb
|
||||
bx lr
|
||||
.fnend
|
||||
.fnend
|
||||
|
||||
.type HalPendSV, %function
|
||||
.global HalPendSV
|
||||
@@ -178,7 +178,7 @@ TaskContextSwitch:
|
||||
str r0, [r5]
|
||||
ldr r1, [r0]
|
||||
|
||||
SignalContextRestore:
|
||||
SignalContextRestore:
|
||||
#if ((defined(__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \
|
||||
(defined(__FPU_USED) && (__FPU_USED == 1U)))
|
||||
vldmia r1!, {d8-d15}
|
||||
|
||||
@@ -29,9 +29,9 @@
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
.syntax unified
|
||||
.arch armv7e-m
|
||||
.thumb
|
||||
.syntax unified
|
||||
.arch armv7e-m
|
||||
.thumb
|
||||
.fpu fpv5-d16
|
||||
.section .text
|
||||
|
||||
@@ -263,7 +263,7 @@ _hwiActiveCheck:
|
||||
CMP R3, #0
|
||||
BEQ _hwiActiveCheckNext
|
||||
|
||||
// exc occured in IRQ
|
||||
// exc occurred in IRQ
|
||||
ORR R0, R0, #FLAG_HWI_ACTIVE
|
||||
RBIT R2, R3
|
||||
CLZ R2, R2
|
||||
@@ -284,7 +284,7 @@ _ExcInMSP:
|
||||
PUSH {R4-R12} // store message-->exc: {R4-R12}
|
||||
VPUSH {D8-D15}
|
||||
B _handleEntry
|
||||
.fnend
|
||||
.fnend
|
||||
|
||||
.type _NoFloatInMsp, %function
|
||||
.global _NoFloatInMsp
|
||||
@@ -298,7 +298,7 @@ _NoFloatInMsp:
|
||||
PUSH {R4-R12} // store message-->exc: {R4-R12}
|
||||
ORR R0, R0, #FLAG_NO_FLOAT
|
||||
B _handleEntry
|
||||
.fnend
|
||||
.fnend
|
||||
|
||||
.type _hwiActiveCheckNext, %function
|
||||
.global _hwiActiveCheckNext
|
||||
@@ -316,19 +316,19 @@ _hwiActiveCheckNext:
|
||||
AND R2, R2,R3
|
||||
CMP R2,#0
|
||||
BNE _ExcInMSP
|
||||
// exc occured in Task or Init or exc
|
||||
// exc occurred 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
|
||||
BEQ _ExcInMSP // if exc occurred in Init then branch
|
||||
|
||||
|
||||
CMP LR, #0xFFFFFFED //auto push floating registers
|
||||
BNE _NoFloatInPsp
|
||||
|
||||
// exc occured in Task
|
||||
// exc occurred in Task
|
||||
MOV R2, R13
|
||||
SUB R13, #96 // add 8 Bytes reg(for STMFD)
|
||||
|
||||
@@ -347,7 +347,7 @@ _hwiActiveCheckNext:
|
||||
VSTMDB R2!, {D8-D15}
|
||||
STMFD R2!, {R4-R11}
|
||||
B _handleEntry
|
||||
.fnend
|
||||
.fnend
|
||||
|
||||
.type _NoFloatInPsp, %function
|
||||
.global _NoFloatInPsp
|
||||
@@ -367,7 +367,7 @@ _NoFloatInPsp:
|
||||
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
|
||||
.fnend
|
||||
.fnend
|
||||
|
||||
.type _handleEntry, %function
|
||||
.global _handleEntry
|
||||
@@ -380,5 +380,5 @@ _handleEntry:
|
||||
B HalExcHandleEntry
|
||||
|
||||
NOP
|
||||
.fnend
|
||||
.fnend
|
||||
|
||||
|
||||
@@ -39,18 +39,42 @@
|
||||
#include "los_sched.h"
|
||||
#include "los_memory.h"
|
||||
#include "los_membox.h"
|
||||
#if (LOSCFG_CPUP_INCLUDE_IRQ == 1)
|
||||
#include "los_cpup.h"
|
||||
#endif
|
||||
|
||||
/*lint -save -e40 -e522 -e533*/
|
||||
UINT32 g_intCount = 0;
|
||||
|
||||
/*lint -restore*/
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Hardware interrupt form mapping handling function array.
|
||||
*/
|
||||
STATIC HWI_PROC_FUNC __attribute__((aligned(LOSCFG_ARCH_HWI_VECTOR_ALIGN))) g_hwiForm[OS_VECTOR_CNT] = {0};
|
||||
|
||||
#if (LOSCFG_DEBUG_TOOLS == 1)
|
||||
STATIC UINT32 g_hwiFormCnt[OS_HWI_MAX_NUM] = {0};
|
||||
STATIC CHAR *g_hwiFormName[OS_HWI_MAX_NUM] = {0};
|
||||
|
||||
UINT32 OsGetHwiFormCnt(UINT32 index)
|
||||
{
|
||||
return g_hwiFormCnt[index];
|
||||
}
|
||||
|
||||
CHAR *OsGetHwiFormName(UINT32 index)
|
||||
{
|
||||
return g_hwiFormName[index];
|
||||
}
|
||||
|
||||
BOOL OsGetHwiCreated(UINT32 index)
|
||||
{
|
||||
if (g_hwiForm[index] != (HWI_PROC_FUNC)HalHwiDefaultHandler) {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if (LOSCFG_PLATFORM_HWI_WITH_ARG == 1)
|
||||
|
||||
typedef struct {
|
||||
@@ -188,11 +212,9 @@ inline UINT32 ArchIsIntActive(VOID)
|
||||
Output : None
|
||||
Return : None
|
||||
**************************************************************************** */
|
||||
/*lint -e529*/
|
||||
LITE_OS_SEC_TEXT_MINOR VOID HalHwiDefaultHandler(VOID)
|
||||
{
|
||||
UINT32 irqNum = HwiNumGet();
|
||||
PRINT_ERR("%s irqnum:%u\n", __FUNCTION__, irqNum);
|
||||
PRINT_ERR("%s irqnum:%u\n", __FUNCTION__, HwiNumGet());
|
||||
while (1) {}
|
||||
}
|
||||
|
||||
@@ -231,6 +253,9 @@ LITE_OS_SEC_TEXT VOID HalInterrupt(VOID)
|
||||
hwiIndex = HwiNumGet();
|
||||
|
||||
OsHookCall(LOS_HOOK_TYPE_ISR_ENTER, hwiIndex);
|
||||
#if (LOSCFG_CPUP_INCLUDE_IRQ == 1)
|
||||
OsCpupIrqStart(hwiIndex);
|
||||
#endif
|
||||
|
||||
HalPreInterruptHandler(hwiIndex);
|
||||
|
||||
@@ -244,8 +269,16 @@ LITE_OS_SEC_TEXT VOID HalInterrupt(VOID)
|
||||
}
|
||||
#endif
|
||||
|
||||
#if (LOSCFG_DEBUG_TOOLS == 1)
|
||||
++g_hwiFormCnt[hwiIndex];
|
||||
#endif
|
||||
|
||||
HalAftInterruptHandler(hwiIndex);
|
||||
|
||||
#if (LOSCFG_CPUP_INCLUDE_IRQ == 1)
|
||||
OsCpupIrqEnd(hwiIndex);
|
||||
#endif
|
||||
|
||||
OsHookCall(LOS_HOOK_TYPE_ISR_EXIT, hwiIndex);
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
@@ -258,22 +291,22 @@ LITE_OS_SEC_TEXT VOID HalInterrupt(VOID)
|
||||
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
|
||||
hwiMode --- unused
|
||||
hwiHandler --- hwi handler
|
||||
irqParam --- param of the hwi handler
|
||||
Output : None
|
||||
Return : LOS_OK on success or error code on failure
|
||||
**************************************************************************** */
|
||||
LITE_OS_SEC_TEXT_INIT UINT32 ArchHwiCreate(HWI_HANDLE_T hwiNum,
|
||||
HWI_PRIOR_T hwiPrio,
|
||||
HWI_MODE_T mode,
|
||||
HWI_PROC_FUNC handler,
|
||||
HWI_ARG_T arg)
|
||||
HWI_MODE_T hwiMode,
|
||||
HWI_PROC_FUNC hwiHandler,
|
||||
HwiIrqParam *irqParam)
|
||||
{
|
||||
(VOID)mode;
|
||||
(VOID)hwiMode;
|
||||
UINT32 intSave;
|
||||
|
||||
if (handler == NULL) {
|
||||
if (hwiHandler == NULL) {
|
||||
return OS_ERRNO_HWI_PROC_FUNC_NULL;
|
||||
}
|
||||
|
||||
@@ -291,11 +324,23 @@ LITE_OS_SEC_TEXT_INIT UINT32 ArchHwiCreate(HWI_HANDLE_T hwiNum,
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
#if (LOSCFG_PLATFORM_HWI_WITH_ARG == 1)
|
||||
OsSetVector(hwiNum, handler, arg);
|
||||
if (irqParam != NULL) {
|
||||
OsSetVector(hwiNum, hwiHandler, irqParam->pDevId);
|
||||
} else {
|
||||
OsSetVector(hwiNum, hwiHandler, NULL);
|
||||
}
|
||||
#else
|
||||
(VOID)arg;
|
||||
OsSetVector(hwiNum, handler);
|
||||
(VOID)irqParam;
|
||||
OsSetVector(hwiNum, hwiHandler);
|
||||
#endif
|
||||
|
||||
#if (LOSCFG_DEBUG_TOOLS == 1)
|
||||
if ((irqParam != NULL) && (irqParam->pName != NULL)) {
|
||||
g_hwiFormName[hwiNum + OS_SYS_VECTOR_CNT] = (CHAR *)irqParam->pName;
|
||||
}
|
||||
g_hwiFormCnt[hwiNum + OS_SYS_VECTOR_CNT] = 0;
|
||||
#endif
|
||||
|
||||
HwiUnmask((IRQn_Type)hwiNum);
|
||||
HwiSetPriority((IRQn_Type)hwiNum, hwiPrio);
|
||||
|
||||
@@ -308,11 +353,13 @@ LITE_OS_SEC_TEXT_INIT UINT32 ArchHwiCreate(HWI_HANDLE_T hwiNum,
|
||||
Function : ArchHwiDelete
|
||||
Description : Delete hardware interrupt
|
||||
Input : hwiNum --- hwi num to delete
|
||||
irqParam --- param of the hwi handler
|
||||
Output : None
|
||||
Return : LOS_OK on success or error code on failure
|
||||
**************************************************************************** */
|
||||
LITE_OS_SEC_TEXT_INIT UINT32 ArchHwiDelete(HWI_HANDLE_T hwiNum)
|
||||
LITE_OS_SEC_TEXT_INIT UINT32 ArchHwiDelete(HWI_HANDLE_T hwiNum, HwiIrqParam *irqParam)
|
||||
{
|
||||
(VOID)irqParam;
|
||||
UINT32 intSave;
|
||||
|
||||
if (hwiNum >= OS_HWI_MAX_NUM) {
|
||||
@@ -587,7 +634,7 @@ LITE_OS_SEC_TEXT_INIT VOID HalHwiInit(VOID)
|
||||
|
||||
/* Enable USGFAULT, BUSFAULT, MEMFAULT */
|
||||
*(volatile UINT32 *)OS_NVIC_SHCSR |= (USGFAULT | BUSFAULT | MEMFAULT);
|
||||
|
||||
|
||||
/* Enable DIV 0 and unaligned exception */
|
||||
#ifdef LOSCFG_ARCH_UNALIGNED_EXC
|
||||
*(volatile UINT32 *)OS_NVIC_CCR |= (DIV0FAULT | UNALIGNFAULT);
|
||||
|
||||
@@ -190,7 +190,7 @@ _hwiActiveCheck
|
||||
CMP R3, #0
|
||||
BEQ _hwiActiveCheckNext
|
||||
|
||||
; exc occured in IRQ
|
||||
; exc occurred in IRQ
|
||||
ORR R0, R0, #FLAG_HWI_ACTIVE
|
||||
RBIT R2, R3
|
||||
CLZ R2, R2
|
||||
@@ -228,19 +228,19 @@ _hwiActiveCheckNext
|
||||
AND R2, R2,R3
|
||||
CMP R2,#0
|
||||
BNE _ExcInMSP
|
||||
; exc occured in Task or Init or exc
|
||||
; exc occurred 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
|
||||
BEQ _ExcInMSP ; if exc occurred in Init then branch
|
||||
|
||||
|
||||
CMP LR, #0xFFFFFFED ;auto push floating registers
|
||||
BNE _NoFloatInPsp
|
||||
|
||||
; exc occured in Task
|
||||
; exc occurred in Task
|
||||
MOV R2, R13
|
||||
SUB R13, #96 ; add 8 Bytes reg(for STMFD)
|
||||
|
||||
|
||||
@@ -40,19 +40,44 @@
|
||||
#include "los_sched.h"
|
||||
#include "los_memory.h"
|
||||
#include "los_membox.h"
|
||||
#if (LOSCFG_CPUP_INCLUDE_IRQ == 1)
|
||||
#include "los_cpup.h"
|
||||
#endif
|
||||
|
||||
/*lint -save -e40 -e522 -e533*/
|
||||
UINT32 g_intCount = 0;
|
||||
|
||||
/*lint -restore*/
|
||||
#pragma location = ".data.vector"
|
||||
#pragma data_alignment=LOSCFG_ARCH_HWI_VECTOR_ALIGN
|
||||
#pragma data_alignment = LOSCFG_ARCH_HWI_VECTOR_ALIGN
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Hardware interrupt form mapping handling function array.
|
||||
*/
|
||||
STATIC HWI_PROC_FUNC g_hwiForm[OS_VECTOR_CNT] = {0};
|
||||
|
||||
#if (LOSCFG_DEBUG_TOOLS == 1)
|
||||
STATIC UINT32 g_hwiFormCnt[OS_HWI_MAX_NUM] = {0};
|
||||
STATIC CHAR *g_hwiFormName[OS_HWI_MAX_NUM] = {0};
|
||||
|
||||
UINT32 OsGetHwiFormCnt(UINT32 index)
|
||||
{
|
||||
return g_hwiFormCnt[index];
|
||||
}
|
||||
|
||||
CHAR *OsGetHwiFormName(UINT32 index)
|
||||
{
|
||||
return g_hwiFormName[index];
|
||||
}
|
||||
|
||||
BOOL OsGetHwiCreated(UINT32 index)
|
||||
{
|
||||
if (g_hwiForm[index] != (HWI_PROC_FUNC)HalHwiDefaultHandler) {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if (LOSCFG_PLATFORM_HWI_WITH_ARG == 1)
|
||||
|
||||
typedef struct {
|
||||
@@ -198,8 +223,7 @@ inline UINT32 ArchIsIntActive(VOID)
|
||||
/*lint -e529*/
|
||||
LITE_OS_SEC_TEXT_MINOR VOID HalHwiDefaultHandler(VOID)
|
||||
{
|
||||
UINT32 irqNum = HwiNumGet();
|
||||
PRINT_ERR("%s irqnum:%u\n", __FUNCTION__, irqNum);
|
||||
PRINT_ERR("%s irqnum:%u\n", __FUNCTION__, HwiNumGet());
|
||||
while (1) {}
|
||||
}
|
||||
|
||||
@@ -238,6 +262,9 @@ LITE_OS_SEC_TEXT VOID HalInterrupt(VOID)
|
||||
hwiIndex = HwiNumGet();
|
||||
|
||||
OsHookCall(LOS_HOOK_TYPE_ISR_ENTER, hwiIndex);
|
||||
#if (LOSCFG_CPUP_INCLUDE_IRQ == 1)
|
||||
OsCpupIrqStart(hwiIndex);
|
||||
#endif
|
||||
|
||||
HalPreInterruptHandler(hwiIndex);
|
||||
|
||||
@@ -251,8 +278,16 @@ LITE_OS_SEC_TEXT VOID HalInterrupt(VOID)
|
||||
}
|
||||
#endif
|
||||
|
||||
#if (LOSCFG_DEBUG_TOOLS == 1)
|
||||
++g_hwiFormCnt[hwiIndex];
|
||||
#endif
|
||||
|
||||
HalAftInterruptHandler(hwiIndex);
|
||||
|
||||
#if (LOSCFG_CPUP_INCLUDE_IRQ == 1)
|
||||
OsCpupIrqEnd(hwiIndex);
|
||||
#endif
|
||||
|
||||
OsHookCall(LOS_HOOK_TYPE_ISR_EXIT, hwiIndex);
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
@@ -265,22 +300,22 @@ LITE_OS_SEC_TEXT VOID HalInterrupt(VOID)
|
||||
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
|
||||
hwiMode --- unused
|
||||
hwiHandler --- hwi handler
|
||||
irqParam --- param of the hwi handler
|
||||
Output : None
|
||||
Return : LOS_OK on success or error code on failure
|
||||
**************************************************************************** */
|
||||
LITE_OS_SEC_TEXT_INIT UINT32 ArchHwiCreate(HWI_HANDLE_T hwiNum,
|
||||
HWI_PRIOR_T hwiPrio,
|
||||
HWI_MODE_T mode,
|
||||
HWI_PROC_FUNC handler,
|
||||
HWI_ARG_T arg)
|
||||
HWI_MODE_T hwiMode,
|
||||
HWI_PROC_FUNC hwiHandler,
|
||||
HwiIrqParam *irqParam)
|
||||
{
|
||||
(VOID)mode;
|
||||
(VOID)hwiMode;
|
||||
UINT32 intSave;
|
||||
|
||||
if (handler == NULL) {
|
||||
if (hwiHandler == NULL) {
|
||||
return OS_ERRNO_HWI_PROC_FUNC_NULL;
|
||||
}
|
||||
|
||||
@@ -298,11 +333,23 @@ LITE_OS_SEC_TEXT_INIT UINT32 ArchHwiCreate(HWI_HANDLE_T hwiNum,
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
#if (LOSCFG_PLATFORM_HWI_WITH_ARG == 1)
|
||||
OsSetVector(hwiNum, handler, arg);
|
||||
if (irqParam != NULL) {
|
||||
OsSetVector(hwiNum, hwiHandler, irqParam->pDevId);
|
||||
} else {
|
||||
OsSetVector(hwiNum, hwiHandler, NULL);
|
||||
}
|
||||
#else
|
||||
(VOID)arg;
|
||||
OsSetVector(hwiNum, handler);
|
||||
(VOID)irqParam;
|
||||
OsSetVector(hwiNum, hwiHandler);
|
||||
#endif
|
||||
|
||||
#if (LOSCFG_DEBUG_TOOLS == 1)
|
||||
if ((irqParam != NULL) && (irqParam->pName != NULL)) {
|
||||
g_hwiFormName[hwiNum + OS_SYS_VECTOR_CNT] = (CHAR *)irqParam->pName;
|
||||
}
|
||||
g_hwiFormCnt[hwiNum + OS_SYS_VECTOR_CNT] = 0;
|
||||
#endif
|
||||
|
||||
HwiUnmask((IRQn_Type)hwiNum);
|
||||
HwiSetPriority((IRQn_Type)hwiNum, hwiPrio);
|
||||
|
||||
@@ -315,11 +362,13 @@ LITE_OS_SEC_TEXT_INIT UINT32 ArchHwiCreate(HWI_HANDLE_T hwiNum,
|
||||
Function : ArchHwiDelete
|
||||
Description : Delete hardware interrupt
|
||||
Input : hwiNum --- hwi num to delete
|
||||
irqParam --- param of the hwi handler
|
||||
Output : None
|
||||
Return : LOS_OK on success or error code on failure
|
||||
**************************************************************************** */
|
||||
LITE_OS_SEC_TEXT_INIT UINT32 ArchHwiDelete(HWI_HANDLE_T hwiNum)
|
||||
LITE_OS_SEC_TEXT_INIT UINT32 ArchHwiDelete(HWI_HANDLE_T hwiNum, HwiIrqParam *irqParam)
|
||||
{
|
||||
(VOID)irqParam;
|
||||
UINT32 intSave;
|
||||
|
||||
if (hwiNum >= OS_HWI_MAX_NUM) {
|
||||
@@ -594,7 +643,7 @@ LITE_OS_SEC_TEXT_INIT VOID HalHwiInit(VOID)
|
||||
|
||||
/* Enable USGFAULT, BUSFAULT, MEMFAULT */
|
||||
*(volatile UINT32 *)OS_NVIC_SHCSR |= (USGFAULT | BUSFAULT | MEMFAULT);
|
||||
|
||||
|
||||
/* Enable DIV 0 and unaligned exception */
|
||||
*(volatile UINT32 *)OS_NVIC_CCR |= (DIV0FAULT | UNALIGNFAULT);
|
||||
|
||||
|
||||
0
arch/csky/v2/gcc/BUILD.gn
Executable file → Normal file
0
arch/csky/v2/gcc/BUILD.gn
Executable file → Normal file
@@ -59,13 +59,33 @@ typedef struct TagTskContext {
|
||||
UINT32 R12;
|
||||
UINT32 R13;
|
||||
UINT32 R15;
|
||||
#ifdef CPU_CK804
|
||||
UINT32 R16;
|
||||
UINT32 R17;
|
||||
UINT32 R18;
|
||||
UINT32 R19;
|
||||
UINT32 R20;
|
||||
UINT32 R21;
|
||||
UINT32 R22;
|
||||
UINT32 R23;
|
||||
UINT32 R24;
|
||||
UINT32 R25;
|
||||
UINT32 R26;
|
||||
UINT32 R27;
|
||||
UINT32 R28;
|
||||
UINT32 R29;
|
||||
UINT32 R30;
|
||||
UINT32 R31;
|
||||
#endif
|
||||
UINT32 EPSR;
|
||||
UINT32 EPC;
|
||||
} TaskContext;
|
||||
|
||||
VOID HalStartToRun(VOID);
|
||||
VOID HalTaskContextSwitch(VOID);
|
||||
#ifndef CPU_CK804
|
||||
VOID HalIrqEndCheckNeedSched(VOID);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
|
||||
@@ -82,7 +82,7 @@ typedef VOID (**HWI_VECTOR_FUNC)(VOID);
|
||||
* @ingroup los_arch_interrupt
|
||||
* Count of interrupts.
|
||||
*/
|
||||
extern UINT32 g_intCount;
|
||||
extern volatile UINT32 g_intCount;
|
||||
|
||||
/* *
|
||||
* @ingroup los_arch_interrupt
|
||||
|
||||
@@ -38,7 +38,9 @@
|
||||
#include "los_interrupt.h"
|
||||
#include "los_debug.h"
|
||||
|
||||
#ifndef CPU_CK804
|
||||
STATIC UINT32 g_sysNeedSched = FALSE;
|
||||
#endif
|
||||
|
||||
/* ****************************************************************************
|
||||
Function : ArchInit
|
||||
@@ -93,8 +95,29 @@ LITE_OS_SEC_TEXT_INIT VOID *ArchTskStackInit(UINT32 taskID, UINT32 stackSize, VO
|
||||
context->R11 = 0x11111111L;
|
||||
context->R12 = 0x12121212L;
|
||||
context->R13 = 0x13131313L;
|
||||
#ifdef CPU_CK804
|
||||
context->R15 = (UINT32)ArchSysExit;
|
||||
context->R16 = 0x16161616L;
|
||||
context->R17 = 0x17171717L;
|
||||
context->R18 = 0x18181818L;
|
||||
context->R19 = 0x19191919L;
|
||||
context->R20 = 0x20202020L;
|
||||
context->R21 = 0x21212121L;
|
||||
context->R22 = 0x22222222L;
|
||||
context->R23 = 0x23232323L;
|
||||
context->R24 = 0x24242424L;
|
||||
context->R25 = 0x25252525L;
|
||||
context->R26 = 0x26262626L;
|
||||
context->R27 = 0x27272727L;
|
||||
context->R28 = 0x28282828L;
|
||||
context->R29 = 0x29292929L;
|
||||
context->R30 = 0x30303030L;
|
||||
context->R31 = 0x31313131L;
|
||||
context->EPSR = 0x80000340L;
|
||||
#else
|
||||
context->R15 = (UINT32)ArchSysExit;
|
||||
context->EPSR = 0xe0000144L;
|
||||
#endif
|
||||
context->EPC = (UINT32)OsTaskEntry;
|
||||
return (VOID *)context;
|
||||
}
|
||||
@@ -107,6 +130,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 ArchStartSchedule(VOID)
|
||||
return LOS_OK; /* never return */
|
||||
}
|
||||
|
||||
#ifndef CPU_CK804
|
||||
VOID HalIrqEndCheckNeedSched(VOID)
|
||||
{
|
||||
if (g_sysNeedSched && g_taskScheduled && LOS_CHECK_SCHEDULE) {
|
||||
@@ -132,3 +156,10 @@ VOID ArchTaskSchedule(VOID)
|
||||
LOS_IntRestore(intSave);
|
||||
return;
|
||||
}
|
||||
#else
|
||||
VOID ArchTaskSchedule(VOID)
|
||||
{
|
||||
HalTaskContextSwitch();
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@@ -32,6 +32,89 @@
|
||||
#define OS_TASK_STATUS_RUNNING 0x0010
|
||||
#define VIC_TSPDR 0XE000EC08
|
||||
|
||||
#ifdef CPU_CK804
|
||||
.section .text
|
||||
.align 2
|
||||
.type HalStartToRun, %function
|
||||
.global HalStartToRun
|
||||
HalStartToRun:
|
||||
lrw r1, g_losTask
|
||||
lrw r2, g_losTask + 4
|
||||
|
||||
ldw r0, (r2)
|
||||
|
||||
st.w r0, (r1)
|
||||
st.w r0, (r2)
|
||||
|
||||
ldw sp, (r0)
|
||||
|
||||
ldw r0, (sp, 128)
|
||||
mtcr r0, epc
|
||||
ldw r0, (sp, 124)
|
||||
mtcr r0, epsr
|
||||
ldw r15, (sp, 56)
|
||||
ldm r0-r13, (sp)
|
||||
addi sp, 60
|
||||
ldm r16-r31, (sp)
|
||||
addi sp, 72
|
||||
|
||||
rte
|
||||
|
||||
.align 2
|
||||
.type HalTaskContextSwitch, %function
|
||||
.global HalTaskContextSwitch
|
||||
HalTaskContextSwitch:
|
||||
lrw r0, VIC_TSPDR
|
||||
bgeni r1, 0
|
||||
stw r1, (r0)
|
||||
nop
|
||||
nop
|
||||
nop
|
||||
rts
|
||||
|
||||
.align 2
|
||||
.type tspend_handler, %function
|
||||
.global tspend_handler
|
||||
tspend_handler:
|
||||
|
||||
subi sp, 132
|
||||
stm r0-r13, (sp)
|
||||
stw r15, (sp, 56)
|
||||
addi r0, sp, 60
|
||||
stm r16-r31, (r0)
|
||||
mfcr r1, epsr
|
||||
stw r1, (sp, 124)
|
||||
mfcr r1, epc
|
||||
stw r1, (sp, 128)
|
||||
|
||||
jbsr OsSchedTaskSwitch
|
||||
bez r0, ret_con
|
||||
|
||||
lrw r2, g_losTask
|
||||
ldw r0, (r2)
|
||||
stw sp, (r0)
|
||||
|
||||
lrw r3, g_losTask + 4
|
||||
ldw r0, (r3)
|
||||
stw r0, (r2)
|
||||
|
||||
ldw sp, (r0)
|
||||
|
||||
ret_con:
|
||||
ldw r0, (sp, 128)
|
||||
mtcr r0, epc
|
||||
ldw r0, (sp, 124)
|
||||
mtcr r0, epsr
|
||||
ldw r15, (sp, 56)
|
||||
ldm r0-r13, (sp)
|
||||
addi sp, 60
|
||||
ldm r16-r31, (sp)
|
||||
|
||||
addi sp, 72
|
||||
|
||||
rte
|
||||
|
||||
#else
|
||||
.section .text
|
||||
.align 2
|
||||
.type HalStartToRun, %function
|
||||
@@ -87,3 +170,4 @@ HalTaskContextSwitch:
|
||||
|
||||
rte
|
||||
|
||||
#endif
|
||||
|
||||
@@ -32,6 +32,57 @@
|
||||
.import HalExcHandleEntry
|
||||
.extern g_trapStackBase
|
||||
|
||||
#ifdef CPU_CK804
|
||||
.section .text
|
||||
.align 2
|
||||
.global HandleEntry
|
||||
HandleEntry:
|
||||
mov r10, sp
|
||||
lrw r14, g_trapStackBase
|
||||
|
||||
stm r0-r15, (sp)
|
||||
stw r10, (sp, 56)
|
||||
addi r0, sp, 64
|
||||
stm r16-r31, (r0)
|
||||
mfcr r0, epsr
|
||||
stw r0, (sp, 128)
|
||||
mfcr r0, epc
|
||||
stw r0, (sp, 132)
|
||||
mov r0, sp
|
||||
|
||||
mfcr r1, epc
|
||||
|
||||
mov sp, r10
|
||||
lrw r2, HalExcHandleEntry
|
||||
jmp r2
|
||||
|
||||
.section .text
|
||||
.align 2
|
||||
.global IrqEntry
|
||||
IrqEntry:
|
||||
psrset ee
|
||||
subi sp, 136
|
||||
stm r0-r15, (sp)
|
||||
addi r0, sp, 64
|
||||
stm r16-r31, (r0)
|
||||
mfcr r0, epsr
|
||||
stw r0, (sp, 128)
|
||||
mfcr r0, epc
|
||||
stw r0, (sp, 132)
|
||||
|
||||
jbsr HalInterrupt
|
||||
|
||||
ldw r0, (sp, 132)
|
||||
mtcr r0, epc
|
||||
ldw r0, (sp, 128)
|
||||
bseti r0, r0, 6
|
||||
mtcr r0, epsr
|
||||
ldm r0-r15, (sp)
|
||||
addi sp, 64
|
||||
ldm r16-r31, (sp)
|
||||
addi sp, 72
|
||||
rte
|
||||
#else
|
||||
.section .text
|
||||
.align 2
|
||||
.global HandleEntry
|
||||
@@ -75,3 +126,4 @@ IrqEntry:
|
||||
ldm r0-r15, (sp)
|
||||
addi sp, 72
|
||||
rte
|
||||
#endif
|
||||
@@ -52,13 +52,12 @@
|
||||
#define MASK_8_BITS 0xFF
|
||||
#define MASK_32_BITS 0xFFFFFFFF
|
||||
#define BYTES_OF_128_INT 4
|
||||
#define TIM_INT_NUM 1
|
||||
|
||||
#define OS_USER_HWI_MIN 0
|
||||
#define OS_USER_HWI_MAX (LOSCFG_PLATFORM_HWI_LIMIT - 1)
|
||||
#define HWI_ALIGNSIZE 0x400
|
||||
|
||||
UINT32 g_intCount = 0;
|
||||
UINT32 volatile g_intCount = 0;
|
||||
CHAR g_trapStackBase[OS_TRAP_STACK_SIZE];
|
||||
|
||||
VIC_TYPE *VIC_REG = (VIC_TYPE *)VIC_REG_BASE;
|
||||
@@ -282,8 +281,7 @@ inline UINT32 ArchIsIntActive(VOID)
|
||||
**************************************************************************** */
|
||||
LITE_OS_SEC_TEXT_MINOR VOID HalHwiDefaultHandler(VOID)
|
||||
{
|
||||
UINT32 irqNum = HwiNumGet();
|
||||
PRINT_ERR("%s irqnum:%x\n", __FUNCTION__, irqNum);
|
||||
PRINT_ERR("%s irqnum:%x\n", __FUNCTION__, HwiNumGet());
|
||||
while (1) {}
|
||||
}
|
||||
|
||||
@@ -335,7 +333,9 @@ LITE_OS_SEC_TEXT VOID HalInterrupt(VOID)
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
g_intCount--;
|
||||
#ifndef CPU_CK804
|
||||
HalIrqEndCheckNeedSched();
|
||||
#endif
|
||||
LOS_IntRestore(intSave);
|
||||
}
|
||||
|
||||
@@ -344,22 +344,22 @@ LITE_OS_SEC_TEXT VOID HalInterrupt(VOID)
|
||||
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
|
||||
hwiMode --- unused
|
||||
hwiHandler --- hwi handler
|
||||
irqParam --- param of the hwi handler
|
||||
Output : None
|
||||
Return : LOS_OK on success or error code on failure
|
||||
**************************************************************************** */
|
||||
LITE_OS_SEC_TEXT_INIT UINT32 ArchHwiCreate(HWI_HANDLE_T hwiNum,
|
||||
HWI_PRIOR_T hwiPrio,
|
||||
HWI_MODE_T mode,
|
||||
HWI_PROC_FUNC handler,
|
||||
HWI_ARG_T arg)
|
||||
HWI_MODE_T hwiMode,
|
||||
HWI_PROC_FUNC hwiHandler,
|
||||
HwiIrqParam *irqParam)
|
||||
{
|
||||
(VOID)mode;
|
||||
(VOID)hwiMode;
|
||||
UINT32 intSave;
|
||||
|
||||
if (handler == NULL) {
|
||||
if (hwiHandler == NULL) {
|
||||
return OS_ERRNO_HWI_PROC_FUNC_NULL;
|
||||
}
|
||||
if (hwiNum >= OS_HWI_MAX_NUM) {
|
||||
@@ -376,10 +376,14 @@ LITE_OS_SEC_TEXT_INIT UINT32 ArchHwiCreate(HWI_HANDLE_T hwiNum,
|
||||
}
|
||||
intSave = LOS_IntLock();
|
||||
#if (LOSCFG_PLATFORM_HWI_WITH_ARG == 1)
|
||||
OsSetVector(hwiNum, handler, arg);
|
||||
if (irqParam != NULL) {
|
||||
OsSetVector(hwiNum, hwiHandler, irqParam->pDevId);
|
||||
} else {
|
||||
OsSetVector(hwiNum, hwiHandler, NULL);
|
||||
}
|
||||
#else
|
||||
(VOID)arg;
|
||||
OsSetVector(hwiNum, handler);
|
||||
(VOID)irqParam;
|
||||
OsSetVector(hwiNum, hwiHandler);
|
||||
#endif
|
||||
HwiUnmask(hwiNum);
|
||||
(VOID)HwiSetPriority(hwiNum, (UINT8)hwiPrio);
|
||||
@@ -392,11 +396,13 @@ LITE_OS_SEC_TEXT_INIT UINT32 ArchHwiCreate(HWI_HANDLE_T hwiNum,
|
||||
Function : ArchHwiDelete
|
||||
Description : Delete hardware interrupt
|
||||
Input : hwiNum --- hwi num to delete
|
||||
irqParam --- param of the hwi handler
|
||||
Output : None
|
||||
Return : LOS_OK on success or error code on failure
|
||||
**************************************************************************** */
|
||||
LITE_OS_SEC_TEXT_INIT UINT32 ArchHwiDelete(HWI_HANDLE_T hwiNum)
|
||||
LITE_OS_SEC_TEXT_INIT UINT32 ArchHwiDelete(HWI_HANDLE_T hwiNum, HwiIrqParam *irqParam)
|
||||
{
|
||||
(VOID)irqParam;
|
||||
UINT32 intSave;
|
||||
|
||||
if (hwiNum >= OS_HWI_MAX_NUM) {
|
||||
@@ -581,6 +587,10 @@ WEAK VOID __stack_chk_fail(VOID)
|
||||
__builtin_return_address(0));
|
||||
}
|
||||
|
||||
WEAK void HalHwiHandleReInit(UINT32 hwiFormAddr)
|
||||
{
|
||||
}
|
||||
|
||||
/* ****************************************************************************
|
||||
Function : HalHwiInit
|
||||
Description : initialization of the hardware interrupt
|
||||
@@ -599,6 +609,7 @@ LITE_OS_SEC_TEXT_INIT VOID HalHwiInit(VOID)
|
||||
for (i = OS_SYS_VECTOR_CNT; i < (LOSCFG_PLATFORM_HWI_LIMIT + OS_SYS_VECTOR_CNT); i++) {
|
||||
g_hwiForm[i] = (HWI_PROC_FUNC)IrqEntry;
|
||||
}
|
||||
HalHwiHandleReInit((UINT32)&g_hwiForm);
|
||||
|
||||
HalSetVbr((UINT32)&g_hwiForm);
|
||||
for (int i = 0; i < BYTES_OF_128_INT; i++) {
|
||||
|
||||
@@ -50,7 +50,11 @@ typedef struct {
|
||||
#define CORETIM_SOURCE (1UL << 2)
|
||||
#define CORETIM_MODE (1UL << 16)
|
||||
|
||||
#ifdef CPU_CK804
|
||||
#define TIM_INT_NUM 25
|
||||
#else
|
||||
#define TIM_INT_NUM 1
|
||||
#endif
|
||||
|
||||
STATIC UINT32 SysTickStart(HWI_PROC_FUNC handler);
|
||||
STATIC UINT64 SysTickReload(UINT64 nextResponseTime);
|
||||
|
||||
@@ -41,6 +41,52 @@ extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#if defined(__ICCARM__) || defined(__CC_ARM)
|
||||
STATIC INLINE UINTPTR ArchSpGet(VOID)
|
||||
{
|
||||
UINTPTR sp;
|
||||
__asm("mov %0, sp" : "=r" (sp));
|
||||
return sp;
|
||||
}
|
||||
|
||||
STATIC INLINE UINTPTR ArchPspGet(VOID)
|
||||
{
|
||||
UINTPTR psp;
|
||||
__asm("mrs %0, psp" : "=r" (psp));
|
||||
return psp;
|
||||
}
|
||||
|
||||
STATIC INLINE UINTPTR ArchMspGet(VOID)
|
||||
{
|
||||
UINTPTR msp;
|
||||
__asm("mrs %0, msp" : "=r" (msp));
|
||||
return msp;
|
||||
}
|
||||
#elif defined(__CLANG_ARM) || defined(__GNUC__)
|
||||
STATIC INLINE UINTPTR ArchSpGet(VOID)
|
||||
{
|
||||
UINTPTR sp;
|
||||
__asm volatile("mov %0, sp" : "=r" (sp));
|
||||
return sp;
|
||||
}
|
||||
|
||||
STATIC INLINE UINTPTR ArchPspGet(VOID)
|
||||
{
|
||||
UINTPTR psp;
|
||||
__asm volatile("mrs %0, psp" : "=r" (psp));
|
||||
return psp;
|
||||
}
|
||||
|
||||
STATIC INLINE UINTPTR ArchMspGet(VOID)
|
||||
{
|
||||
UINTPTR msp;
|
||||
__asm volatile("mrs %0, msp" : "=r" (msp));
|
||||
return msp;
|
||||
}
|
||||
#else
|
||||
/* Other platforms to be improved */
|
||||
#endif
|
||||
|
||||
VOID ArchInit(VOID);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
0
arch/include/los_atomic.h
Executable file → Normal file
0
arch/include/los_atomic.h
Executable file → Normal file
@@ -53,6 +53,11 @@ typedef VOID (*HWI_PROC_FUNC)(VOID *parm);
|
||||
#else
|
||||
typedef VOID (*HWI_PROC_FUNC)(void);
|
||||
#endif
|
||||
typedef struct tagIrqParam {
|
||||
int swIrq; /**< The interrupt number */
|
||||
VOID *pDevId; /**< The pointer to the device ID that launches the interrupt */
|
||||
const CHAR *pName; /**< The interrupt name */
|
||||
} HwiIrqParam;
|
||||
|
||||
typedef struct {
|
||||
UINT32 (*triggerIrq)(HWI_HANDLE_T hwiNum);
|
||||
@@ -109,14 +114,15 @@ UINT32 ArchIntUnLock(VOID);
|
||||
* </ul>
|
||||
*
|
||||
* @param hwiNum [IN] Type#HWI_HANDLE_T: hardware interrupt number. The value range applicable for a Cortex-A7 platform is [32,95].
|
||||
*
|
||||
* @param irqParam [IN] Type #HwiIrqParam *. ID of hardware interrupt which will base on
|
||||
* when delete the hardware interrupt.
|
||||
* @retval #OS_ERRNO_HWI_NUM_INVALID 0x02000900: Invalid interrupt number.
|
||||
* @retval #LOS_OK 0 : The interrupt is successfully delete.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_interrupt.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see None.
|
||||
*/
|
||||
UINT32 ArchHwiDelete(HWI_HANDLE_T hwiNum);
|
||||
UINT32 ArchHwiDelete(HWI_HANDLE_T hwiNum, HwiIrqParam *irqParam);
|
||||
|
||||
/**
|
||||
* @ingroup los_interrupt
|
||||
@@ -137,7 +143,8 @@ UINT32 ArchHwiDelete(HWI_HANDLE_T hwiNum);
|
||||
* @param hwiPrio [IN] Type#HWI_PRIOR_T: hardware interrupt priority. Ignore this parameter temporarily.
|
||||
* @param mode [IN] Type#HWI_MODE_T: hardware interrupt mode. Ignore this parameter temporarily.
|
||||
* @param handler [IN] Type#HWI_PROC_FUNC: interrupt handler used when a hardware interrupt is triggered.
|
||||
* @param arg [IN] Type#HWI_ARG_T: input parameter of the interrupt handler used when a hardware interrupt is triggered.
|
||||
* @param irqParam [IN] Type#HwiIrqParam: input parameter of the interrupt
|
||||
* handler used when a hardware interrupt is triggered.
|
||||
*
|
||||
* @retval #OS_ERRNO_HWI_PROC_FUNC_NULL 0x02000901: Null hardware interrupt handling function.
|
||||
* @retval #OS_ERRNO_HWI_NUM_INVALID 0x02000900: Invalid interrupt number.
|
||||
@@ -152,7 +159,7 @@ UINT32 ArchHwiCreate(HWI_HANDLE_T hwiNum,
|
||||
HWI_PRIOR_T hwiPrio,
|
||||
HWI_MODE_T mode,
|
||||
HWI_PROC_FUNC handler,
|
||||
HWI_ARG_T arg);
|
||||
HwiIrqParam *irqParam);
|
||||
|
||||
STATIC INLINE UINT32 ArchIntTrigger(HWI_HANDLE_T hwiNum)
|
||||
{
|
||||
@@ -207,6 +214,12 @@ STATIC INLINE HwiControllerOps *ArchIntOpsGet(VOID)
|
||||
return &g_archHwiOps;
|
||||
}
|
||||
|
||||
#if (LOSCFG_DEBUG_TOOLS == 1)
|
||||
extern UINT32 OsGetHwiFormCnt(UINT32 index);
|
||||
extern CHAR *OsGetHwiFormName(UINT32 index);
|
||||
extern BOOL OsGetHwiCreated(UINT32 index);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
|
||||
@@ -179,7 +179,6 @@ exc_entry:
|
||||
csrr a0, mcause
|
||||
mv a1, sp
|
||||
/*
|
||||
* TODO: Call the exception handler function
|
||||
* By default, the function template is provided in
|
||||
* system_Device.c, you can adjust it as you want
|
||||
*/
|
||||
|
||||
@@ -86,9 +86,9 @@ LITE_OS_SEC_TEXT_INIT VOID HalHwiInit(VOID)
|
||||
Description : create hardware interrupt
|
||||
Input : hwiNum --- hwi num to create
|
||||
hwiPrio --- priority of the hwi
|
||||
mode --- hwi interrupt mode, between vector or non-vector
|
||||
handler --- hwi handler
|
||||
arg --- set trig mode of the hwi handler
|
||||
hwiMode --- hwi interrupt hwiMode, between vector or non-vector
|
||||
hwiHandler --- hwi handler
|
||||
irqParam --- set trig hwiMode of the hwi handler
|
||||
Level Triggerred = 0
|
||||
Postive/Rising Edge Triggered = 1
|
||||
Negtive/Falling Edge Triggered = 3
|
||||
@@ -97,24 +97,24 @@ LITE_OS_SEC_TEXT_INIT VOID HalHwiInit(VOID)
|
||||
*****************************************************************************/
|
||||
UINT32 ArchHwiCreate(HWI_HANDLE_T hwiNum,
|
||||
HWI_PRIOR_T hwiPrio,
|
||||
HWI_MODE_T mode,
|
||||
HWI_PROC_FUNC handler,
|
||||
HWI_ARG_T arg)
|
||||
HWI_MODE_T hwiMode,
|
||||
HWI_PROC_FUNC hwiHandler,
|
||||
HwiIrqParam *irqParam)
|
||||
{
|
||||
if (hwiNum > SOC_INT_MAX) {
|
||||
return OS_ERRNO_HWI_NUM_INVALID;
|
||||
}
|
||||
if (mode > ECLIC_VECTOR_INTERRUPT) {
|
||||
if (hwiMode > ECLIC_VECTOR_INTERRUPT) {
|
||||
return OS_ERRNO_HWI_MODE_INVALID;
|
||||
}
|
||||
if (arg > ECLIC_NEGTIVE_EDGE_TRIGGER) {
|
||||
if ((irqParam == NULL) || (irqParam->pDevId > ECLIC_NEGTIVE_EDGE_TRIGGER)) {
|
||||
return OS_ERRNO_HWI_ARG_INVALID;
|
||||
}
|
||||
|
||||
/* set interrupt vector mode */
|
||||
ECLIC_SetShvIRQ(hwiNum, mode);
|
||||
/* set interrupt trigger mode and polarity */
|
||||
ECLIC_SetTrigIRQ(hwiNum, arg);
|
||||
/* set interrupt vector hwiMode */
|
||||
ECLIC_SetShvIRQ(hwiNum, hwiMode);
|
||||
/* set interrupt trigger hwiMode and polarity */
|
||||
ECLIC_SetTrigIRQ(hwiNum, irqParam->pDevId);
|
||||
/* set interrupt level */
|
||||
// default to 0
|
||||
ECLIC_SetLevelIRQ(hwiNum, 0);
|
||||
@@ -124,9 +124,9 @@ UINT32 ArchHwiCreate(HWI_HANDLE_T hwiNum,
|
||||
/* set interrupt priority */
|
||||
// low 16 bit for priority
|
||||
ECLIC_SetPriorityIRQ(hwiNum, (hwiPrio & 0xffff));
|
||||
if (handler != NULL) {
|
||||
if (hwiHandler != NULL) {
|
||||
/* set interrupt handler entry to vector table */
|
||||
ECLIC_SetVector(hwiNum, (rv_csr_t)handler);
|
||||
ECLIC_SetVector(hwiNum, (rv_csr_t)hwiHandler);
|
||||
}
|
||||
/* enable interrupt */
|
||||
HwiUnmask(hwiNum);
|
||||
@@ -137,10 +137,12 @@ UINT32 ArchHwiCreate(HWI_HANDLE_T hwiNum,
|
||||
Function : ArchHwiDelete
|
||||
Description : Delete hardware interrupt
|
||||
Input : hwiNum --- hwi num to delete
|
||||
irqParam --- param of the hwi handler
|
||||
Return : LOS_OK on success or error code on failure
|
||||
*****************************************************************************/
|
||||
LITE_OS_SEC_TEXT UINT32 ArchHwiDelete(HWI_HANDLE_T hwiNum)
|
||||
LITE_OS_SEC_TEXT UINT32 ArchHwiDelete(HWI_HANDLE_T hwiNum, HwiIrqParam *irqParam)
|
||||
{
|
||||
(VOID)irqParam;
|
||||
// change func to default func
|
||||
ECLIC_SetVector(hwiNum, (rv_csr_t)HalHwiDefaultHandler);
|
||||
// disable interrupt
|
||||
|
||||
@@ -105,7 +105,7 @@
|
||||
* Based on the types of the four 8-bit arithmetic operations, the SIMD 8-bit add/subtract instructions
|
||||
* can be classified into 2 main categories: Addition (four 8-bit addition), and Subtraction (four 8-bit
|
||||
* subtraction).
|
||||
* Based on the way of how an overflow condition is handled for singed or unsigned operation, the
|
||||
* Based on the way of how an overflow condition is handled for signed or unsigned operation, the
|
||||
* SIMD 8-bit add/subtract instructions can be classified into 5 groups: Wrap-around (dropping
|
||||
* overflow), Signed Halving (keeping overflow by dropping 1 LSB bit), Unsigned Halving, Signed
|
||||
* Saturation (clipping overflow), and Unsigned Saturation.
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
#define _LOS_ARCH_ATOMIC_H
|
||||
|
||||
#include "los_compiler.h"
|
||||
#include "los_interrupt.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
|
||||
@@ -165,7 +165,7 @@ LITE_OS_SEC_TEXT UINT32 ArchHwiCreate(HWI_HANDLE_T hwiNum,
|
||||
HWI_PRIOR_T hwiPrio,
|
||||
HWI_MODE_T hwiMode,
|
||||
HWI_PROC_FUNC hwiHandler,
|
||||
HWI_ARG_T irqParam)
|
||||
HwiIrqParam *irqParam)
|
||||
{
|
||||
UINT32 intSave;
|
||||
|
||||
@@ -186,8 +186,11 @@ LITE_OS_SEC_TEXT UINT32 ArchHwiCreate(HWI_HANDLE_T hwiNum,
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
g_hwiForm[hwiNum].pfnHook = hwiHandler;
|
||||
g_hwiForm[hwiNum].uwParam = (VOID *)irqParam;
|
||||
|
||||
if (irqParam != NULL) {
|
||||
g_hwiForm[hwiNum].uwParam = (VOID *)irqParam->pDevId;
|
||||
} else {
|
||||
g_hwiForm[hwiNum].uwParam = NULL;
|
||||
}
|
||||
if (hwiNum >= OS_RISCV_SYS_VECTOR_CNT) {
|
||||
HalSetLocalInterPri(hwiNum, hwiPrio);
|
||||
}
|
||||
@@ -201,10 +204,12 @@ LITE_OS_SEC_TEXT UINT32 ArchHwiCreate(HWI_HANDLE_T hwiNum,
|
||||
Function : ArchHwiDelete
|
||||
Description : Delete hardware interrupt
|
||||
Input : hwiNum --- hwi num to delete
|
||||
irqParam --- param of the hwi handler
|
||||
Return : LOS_OK on success or error code on failure
|
||||
*****************************************************************************/
|
||||
LITE_OS_SEC_TEXT UINT32 ArchHwiDelete(HWI_HANDLE_T hwiNum)
|
||||
LITE_OS_SEC_TEXT UINT32 ArchHwiDelete(HWI_HANDLE_T hwiNum, HwiIrqParam *irqParam)
|
||||
{
|
||||
(VOID)irqParam;
|
||||
UINT32 intSave;
|
||||
|
||||
if (hwiNum >= OS_HWI_MAX_NUM) {
|
||||
@@ -327,7 +332,7 @@ VOID HalExcEntry(const LosExcContext *excBufAddr)
|
||||
ExcInfoDisplay(excBufAddr);
|
||||
|
||||
if (LOS_TaskIsRunning()) {
|
||||
PRINTK("----------------All Task infomation ------------\n");
|
||||
PRINTK("----------------All Task information ------------\n");
|
||||
OsGetAllTskInfo();
|
||||
}
|
||||
|
||||
|
||||
@@ -61,7 +61,10 @@ STATIC UINT32 SysTickStart(HWI_PROC_FUNC handler)
|
||||
ArchTickTimer *tick = &g_archTickTimer;
|
||||
|
||||
UINT32 period = (UINT32)LOSCFG_BASE_CORE_TICK_RESPONSE_MAX;
|
||||
UINT32 ret = LOS_HwiCreate(RISCV_MACH_TIMER_IRQ, 0x1, 0, handler, period);
|
||||
HwiIrqParam irqParam;
|
||||
irqParam.pDevId = (VOID *)period;
|
||||
|
||||
UINT32 ret = LOS_HwiCreate(RISCV_MACH_TIMER_IRQ, 0x1, 0, handler, &irqParam);
|
||||
if (ret != LOS_OK) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -249,8 +249,7 @@ INLINE UINT32 ArchIsIntActive(VOID)
|
||||
**************************************************************************** */
|
||||
VOID HalHwiDefaultHandler(VOID)
|
||||
{
|
||||
UINT32 irqNum = HwiNumGet();
|
||||
PRINT_ERR("%s irqnum:%u\n", __FUNCTION__, irqNum);
|
||||
PRINT_ERR("%s irqnum:%u\n", __FUNCTION__, HwiNumGet());
|
||||
while (1) {}
|
||||
}
|
||||
|
||||
@@ -314,22 +313,22 @@ VOID HalInterrupt(VOID)
|
||||
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
|
||||
hwiMode --- unused
|
||||
hwiHandler --- hwi handler
|
||||
irqParam --- param of the hwi handler
|
||||
Output : None
|
||||
Return : LOS_OK on success or error code on failure
|
||||
**************************************************************************** */
|
||||
UINT32 ArchHwiCreate(HWI_HANDLE_T hwiNum,
|
||||
HWI_PRIOR_T hwiPrio,
|
||||
HWI_MODE_T mode,
|
||||
HWI_PROC_FUNC handler,
|
||||
HWI_ARG_T arg)
|
||||
HWI_MODE_T hwiMode,
|
||||
HWI_PROC_FUNC hwiHandler,
|
||||
HwiIrqParam *irqParam)
|
||||
{
|
||||
(VOID)mode;
|
||||
(VOID)hwiMode;
|
||||
UINT32 intSave;
|
||||
|
||||
if (handler == NULL) {
|
||||
if (hwiHandler == NULL) {
|
||||
return OS_ERRNO_HWI_PROC_FUNC_NULL;
|
||||
}
|
||||
|
||||
@@ -347,10 +346,14 @@ UINT32 ArchHwiCreate(HWI_HANDLE_T hwiNum,
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
#if (LOSCFG_PLATFORM_HWI_WITH_ARG == 1)
|
||||
OsSetVector(hwiNum, handler, arg);
|
||||
if (irqParam != NULL) {
|
||||
OsSetVector(hwiNum, hwiHandler, irqParam->pDevId);
|
||||
} else {
|
||||
OsSetVector(hwiNum, hwiHandler, NULL);
|
||||
}
|
||||
#else
|
||||
(VOID)arg;
|
||||
OsSetVector(hwiNum, handler);
|
||||
(VOID)irqParam;
|
||||
OsSetVector(hwiNum, hwiHandler);
|
||||
#endif
|
||||
HwiUnmask(hwiNum);
|
||||
|
||||
@@ -363,11 +366,13 @@ UINT32 ArchHwiCreate(HWI_HANDLE_T hwiNum,
|
||||
Function : ArchHwiDelete
|
||||
Description : Delete hardware interrupt
|
||||
Input : hwiNum --- hwi num to delete
|
||||
irqParam --- param of the hwi handler
|
||||
Output : None
|
||||
Return : LOS_OK on success or error code on failure
|
||||
**************************************************************************** */
|
||||
LITE_OS_SEC_TEXT_INIT UINT32 ArchHwiDelete(HWI_HANDLE_T hwiNum)
|
||||
LITE_OS_SEC_TEXT_INIT UINT32 ArchHwiDelete(HWI_HANDLE_T hwiNum, HwiIrqParam *irqParam)
|
||||
{
|
||||
(VOID)irqParam;
|
||||
UINT32 intSave;
|
||||
|
||||
if (hwiNum >= OS_HWI_MAX_NUM) {
|
||||
|
||||
18
arch_spec.md
18
arch_spec.md
@@ -48,7 +48,9 @@
|
||||
│ ├── lms --- Lite memory sanitizer functions
|
||||
│ ├── net --- Networking functions
|
||||
│ ├── power --- Power management
|
||||
│ ├── security --- Security isolation
|
||||
│ ├── shell --- Shell function
|
||||
│ ├── signal --- Signal support
|
||||
│ ├── fs --- File systems
|
||||
│ └── trace --- Trace tool
|
||||
├── drivers --- driver Kconfig
|
||||
@@ -71,14 +73,13 @@
|
||||
│ │ └── los_tick.h --- Tick
|
||||
│ └── src
|
||||
├── targets
|
||||
│ └── targets
|
||||
│ └── 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
|
||||
│ └── 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
|
||||
├── testsuites --- Kernel testsuites
|
||||
├── tools --- Kernel tools
|
||||
└── utils
|
||||
@@ -93,6 +94,5 @@
|
||||
├── los_hook.h
|
||||
├── los_list.h --- Doubly linked list
|
||||
└── los_reg.h --- Register macros
|
||||
└── src
|
||||
```
|
||||
|
||||
|
||||
@@ -48,7 +48,9 @@
|
||||
│ ├── lms --- Lite memory sanitizer 机制
|
||||
│ ├── net --- Network功能
|
||||
│ ├── power --- 低功耗管理
|
||||
│ ├── security --- 安全隔离
|
||||
│ ├── shell --- shell功能
|
||||
│ ├── signal --- signal支持
|
||||
│ └── trace --- trace 工具
|
||||
├── drivers --- 驱动框架Kconfig
|
||||
├── kal --- 内核抽象层,提供内核对外接口,当前支持CMSIS接口和部分POSIX接口
|
||||
@@ -70,14 +72,13 @@
|
||||
│ │ └── 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
|
||||
│ └── riscv_nuclei_demo_soc_gcc
|
||||
│ │ ├── GCC --- 编译相关
|
||||
│ │ ├── OS_CONFIG --- 开发板配置功能开关和配置参数
|
||||
│ │ ├── SoC --- SOC相关代码
|
||||
│ │ └── Src --- Application相关代码
|
||||
│ └── riscv_nuclei_gd32vf103_soc_gcc
|
||||
│ └── riscv_sifive_fe310_gcc
|
||||
├── testsuites --- 内核测试用例
|
||||
├── tools --- 内核工具
|
||||
└── utils
|
||||
@@ -92,6 +93,5 @@
|
||||
├── los_hook.h
|
||||
├── los_list.h --- 双向链表
|
||||
└── los_reg.h --- 寄存器读写宏定义
|
||||
└── src
|
||||
```
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
# Copyright (c) 2020-2022 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,6 +34,7 @@ group("components") {
|
||||
"backtrace",
|
||||
"cppsupport",
|
||||
"cpup",
|
||||
"debugtools",
|
||||
"dynlink",
|
||||
"exchook",
|
||||
"fs",
|
||||
@@ -41,6 +42,7 @@ group("components") {
|
||||
"lms",
|
||||
"net",
|
||||
"power",
|
||||
"security",
|
||||
"shell",
|
||||
"signal",
|
||||
"trace",
|
||||
@@ -57,10 +59,12 @@ config("public") {
|
||||
"fs:public",
|
||||
"net:public",
|
||||
"power:public",
|
||||
"security:public",
|
||||
"shell:public",
|
||||
"trace:public",
|
||||
"lmk:public",
|
||||
"lms:public",
|
||||
"signal:public",
|
||||
"debugtools:public",
|
||||
]
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
#include "los_backtrace.h"
|
||||
#include "los_task.h"
|
||||
#include "los_debug.h"
|
||||
#include "los_arch.h"
|
||||
#if (LOSCFG_BACKTRACE_TYPE == 4)
|
||||
#include "los_arch_regs.h"
|
||||
#endif
|
||||
@@ -60,52 +61,6 @@ WEAK BOOL OsStackDataIsCodeAddr(UINTPTR value)
|
||||
#define OS_BLX_INX_MASK 0xFF00
|
||||
#define OS_BLX_INX 0x4700
|
||||
|
||||
#if defined(__ICCARM__) || defined(__CC_ARM)
|
||||
STATIC INLINE UINTPTR HalSpGet(VOID)
|
||||
{
|
||||
UINTPTR sp;
|
||||
__asm("mov %0, sp" : "=r" (sp));
|
||||
return sp;
|
||||
}
|
||||
|
||||
STATIC INLINE UINTPTR HalPspGet(VOID)
|
||||
{
|
||||
UINTPTR psp;
|
||||
__asm("mrs %0, psp" : "=r" (psp));
|
||||
return psp;
|
||||
}
|
||||
|
||||
STATIC INLINE UINTPTR HalMspGet(VOID)
|
||||
{
|
||||
UINTPTR msp;
|
||||
__asm("mrs %0, msp" : "=r" (msp));
|
||||
return msp;
|
||||
}
|
||||
#elif defined(__CLANG_ARM) || defined(__GNUC__)
|
||||
STATIC INLINE UINTPTR HalSpGet(VOID)
|
||||
{
|
||||
UINTPTR sp;
|
||||
__asm volatile("mov %0, sp" : "=r" (sp));
|
||||
return sp;
|
||||
}
|
||||
|
||||
STATIC INLINE UINTPTR HalPspGet(VOID)
|
||||
{
|
||||
UINTPTR psp;
|
||||
__asm volatile("mrs %0, psp" : "=r" (psp));
|
||||
return psp;
|
||||
}
|
||||
|
||||
STATIC INLINE UINTPTR HalMspGet(VOID)
|
||||
{
|
||||
UINTPTR msp;
|
||||
__asm volatile("mrs %0, msp" : "=r" (msp));
|
||||
return msp;
|
||||
}
|
||||
#else
|
||||
#error Unknown compiler.
|
||||
#endif
|
||||
|
||||
STATIC INLINE BOOL OsInsIsBlOrBlx(UINTPTR addr)
|
||||
{
|
||||
UINT16 ins1 = *((UINT16 *)addr);
|
||||
@@ -138,8 +93,8 @@ STATIC INLINE UINT32 OsStackAddrGet(UINTPTR *stackStart, UINTPTR *stackEnd, UINT
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (HalSpGet() != HalPspGet()) {
|
||||
*stackStart = HalMspGet();
|
||||
if (ArchSpGet() != ArchPspGet()) {
|
||||
*stackStart = ArchMspGet();
|
||||
*stackEnd = CSTACK_END_ADDR;
|
||||
if ((*stackStart < CSTACK_START_ADDR) || (*stackStart >= CSTACK_END_ADDR)) {
|
||||
PRINT_ERR("msp stack [0x%x, 0x%x], cur sp(0x%x) is overflow!\n",
|
||||
@@ -148,7 +103,7 @@ STATIC INLINE UINT32 OsStackAddrGet(UINTPTR *stackStart, UINTPTR *stackEnd, UINT
|
||||
}
|
||||
PRINTK("msp, start = %x, end = %x\n", *stackStart, *stackEnd);
|
||||
} else {
|
||||
*stackStart = HalPspGet();
|
||||
*stackStart = ArchPspGet();
|
||||
UINT32 taskID = LOS_CurTaskIDGet();
|
||||
LosTaskCB *taskCB = OS_TCB_FROM_TID(taskID);
|
||||
*stackEnd = (UINTPTR)taskCB->topOfStack + taskCB->stackSize;
|
||||
|
||||
@@ -52,8 +52,8 @@ extern "C" {
|
||||
#define CODE_SECTION_NAME ".text"
|
||||
/* The default C stack section name is CSTACK */
|
||||
#define CSTACK_SECTION_NAME "CSTACK"
|
||||
#pragma section=CODE_SECTION_NAME
|
||||
#pragma section=CSTACK_SECTION_NAME
|
||||
#pragma section = CODE_SECTION_NAME
|
||||
#pragma section = CSTACK_SECTION_NAME
|
||||
|
||||
/* Default only one code section. In fact, there may be more than one.
|
||||
You can define more than one and redefine the OsStackDataIsCodeAddr function
|
||||
|
||||
@@ -35,8 +35,15 @@
|
||||
#include "los_debug.h"
|
||||
#include "los_tick.h"
|
||||
|
||||
#if (LOSCFG_BASE_CORE_CPUP == 1)
|
||||
#if (LOSCFG_BASE_CORE_SWTMR == 1)
|
||||
#include "los_swtmr.h"
|
||||
#endif
|
||||
|
||||
#if (LOSCFG_CPUP_INCLUDE_IRQ == 1)
|
||||
#include "los_arch_interrupt.h"
|
||||
#endif
|
||||
|
||||
#if (LOSCFG_BASE_CORE_CPUP == 1)
|
||||
/**
|
||||
* @ingroup los_cpup
|
||||
* CPU usage-type macro: used for tasks.
|
||||
@@ -54,7 +61,79 @@
|
||||
LITE_OS_SEC_BSS UINT16 g_cpupInitFlg = 0;
|
||||
LITE_OS_SEC_BSS OsCpupCB *g_cpup = NULL;
|
||||
LITE_OS_SEC_BSS UINT64 g_lastRecordTime;
|
||||
LITE_OS_SEC_BSS UINT16 g_hisPos; /* <current Sampling point of historyTime */
|
||||
LITE_OS_SEC_BSS UINT16 g_hisPos; /* current Sampling point of historyTime */
|
||||
|
||||
#if (LOSCFG_CPUP_INCLUDE_IRQ == 1)
|
||||
LITE_OS_SEC_BSS UINT16 g_irqCpupInitFlg = 0;
|
||||
LITE_OS_SEC_BSS UINT16 g_irqHisPos = 0; /* current Sampling point of historyTime */
|
||||
LITE_OS_SEC_BSS UINT64 g_irqLastRecordTime;
|
||||
LITE_OS_SEC_BSS OsIrqCpupCB *g_irqCpup = NULL;
|
||||
LITE_OS_SEC_BSS STATIC UINT64 g_cpuHistoryTime[OS_CPUP_HISTORY_RECORD_NUM];
|
||||
#define OS_CPUP_USED 0x1U
|
||||
|
||||
#if (LOSCFG_BASE_CORE_SWTMR == 1)
|
||||
LITE_OS_SEC_TEXT_INIT VOID OsCpupGuard(VOID)
|
||||
{
|
||||
UINT16 prevPos;
|
||||
UINT32 loop;
|
||||
UINT32 intSave;
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
prevPos = g_irqHisPos;
|
||||
|
||||
if (g_irqHisPos == OS_CPUP_HISTORY_RECORD_NUM - 1) {
|
||||
g_irqHisPos = 0;
|
||||
} else {
|
||||
g_irqHisPos++;
|
||||
}
|
||||
|
||||
g_cpuHistoryTime[prevPos] = 0;
|
||||
for (loop = 0; loop < LOSCFG_PLATFORM_HWI_LIMIT; loop++) {
|
||||
if (g_irqCpup[loop].status != OS_CPUP_USED) {
|
||||
continue;
|
||||
}
|
||||
g_irqCpup[loop].historyTime[prevPos] = g_irqCpup[loop].allTime;
|
||||
g_cpuHistoryTime[prevPos] += g_irqCpup[loop].allTime;
|
||||
}
|
||||
LOS_IntRestore(intSave);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
LITE_OS_SEC_TEXT_INIT UINT32 OsCpupGuardCreator(VOID)
|
||||
{
|
||||
UINT32 cpupSwtmrID;
|
||||
#if (LOSCFG_BASE_CORE_SWTMR_ALIGN == 1)
|
||||
(VOID)LOS_SwtmrCreate(LOSCFG_BASE_CORE_TICK_PER_SECOND, LOS_SWTMR_MODE_PERIOD,
|
||||
(SWTMR_PROC_FUNC)OsCpupGuard, &cpupSwtmrID, 0,
|
||||
OS_SWTMR_ROUSES_ALLOW, OS_SWTMR_ALIGN_INSENSITIVE);
|
||||
#else
|
||||
(VOID)LOS_SwtmrCreate(LOSCFG_BASE_CORE_TICK_PER_SECOND, LOS_SWTMR_MODE_PERIOD,
|
||||
(SWTMR_PROC_FUNC)OsCpupGuard, &cpupSwtmrID, 0);
|
||||
#endif
|
||||
|
||||
(VOID)LOS_SwtmrStart(cpupSwtmrID);
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*****************************************************************************
|
||||
Function : OsCpupDaemonInit
|
||||
Description: initialization of CPUP Daemon
|
||||
Input : None
|
||||
Return : LOS_OK or Error Information
|
||||
*****************************************************************************/
|
||||
LITE_OS_SEC_TEXT_INIT UINT32 OsCpupDaemonInit()
|
||||
{
|
||||
#if (LOSCFG_BASE_CORE_SWTMR == 1)
|
||||
(VOID)OsCpupGuardCreator();
|
||||
g_irqCpupInitFlg = 1;
|
||||
#endif
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*****************************************************************************
|
||||
Function : OsCpupInit
|
||||
@@ -65,16 +144,24 @@ Return : LOS_OK or Error Information
|
||||
LITE_OS_SEC_TEXT_INIT UINT32 OsCpupInit()
|
||||
{
|
||||
UINT32 size;
|
||||
CHAR *cpupMem = NULL;
|
||||
|
||||
size = g_taskMaxNum * sizeof(OsCpupCB);
|
||||
g_cpup = (OsCpupCB *)LOS_MemAlloc(m_aucSysMem0, size);
|
||||
#if (LOSCFG_CPUP_INCLUDE_IRQ == 1)
|
||||
size += LOSCFG_PLATFORM_HWI_LIMIT * sizeof(OsIrqCpupCB);
|
||||
#endif
|
||||
|
||||
if (g_cpup == NULL) {
|
||||
cpupMem = LOS_MemAlloc(m_aucSysMem0, size);
|
||||
if (cpupMem == NULL) {
|
||||
return LOS_ERRNO_CPUP_NO_MEMORY;
|
||||
}
|
||||
(VOID)memset_s(cpupMem, size, 0, size);
|
||||
|
||||
g_cpup = (OsCpupCB *)cpupMem;
|
||||
#if (LOSCFG_CPUP_INCLUDE_IRQ == 1)
|
||||
g_irqCpup = (OsIrqCpupCB *)(cpupMem + g_taskMaxNum * sizeof(OsCpupCB));
|
||||
#endif
|
||||
|
||||
// Ignore the return code when matching CSEC rule 6.6(3).
|
||||
(VOID)memset_s(g_cpup, size, 0, size);
|
||||
g_cpupInitFlg = 1;
|
||||
|
||||
return LOS_OK;
|
||||
@@ -82,7 +169,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 OsCpupInit()
|
||||
|
||||
/*****************************************************************************
|
||||
Function : OsTskCycleStart
|
||||
Description: start task to get cycles count in current task begining
|
||||
Description: start task to get cycles count in current task beginning
|
||||
Input : None
|
||||
Return : None
|
||||
*****************************************************************************/
|
||||
@@ -513,4 +600,146 @@ LITE_OS_SEC_TEXT_MINOR UINT32 LOS_CpupUsageMonitor(CPUP_TYPE_E type, CPUP_MODE_E
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
#if (LOSCFG_CPUP_INCLUDE_IRQ == 1)
|
||||
LITE_OS_SEC_TEXT_MINOR VOID OsCpupIrqStart(UINT32 intNum)
|
||||
{
|
||||
if (g_irqCpupInitFlg == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
g_irqCpup[intNum].startTime = LOS_SysCycleGet();
|
||||
return;
|
||||
}
|
||||
|
||||
LITE_OS_SEC_TEXT_MINOR VOID OsCpupIrqEnd(UINT32 intNum)
|
||||
{
|
||||
UINT64 cpuCycle;
|
||||
UINT64 usedTime;
|
||||
|
||||
if (g_irqCpupInitFlg == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (g_irqCpup[intNum].startTime == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
cpuCycle = LOS_SysCycleGet();
|
||||
|
||||
if (cpuCycle < g_irqCpup[intNum].startTime) {
|
||||
cpuCycle += g_cyclesPerTick;
|
||||
}
|
||||
|
||||
g_irqCpup[intNum].cpupID = intNum;
|
||||
g_irqCpup[intNum].status = OS_CPUP_USED;
|
||||
usedTime = cpuCycle - g_irqCpup[intNum].startTime;
|
||||
|
||||
if (g_irqCpup[intNum].count <= 1000) { /* 1000, Take 1000 samples */
|
||||
g_irqCpup[intNum].allTime += usedTime;
|
||||
g_irqCpup[intNum].count++;
|
||||
} else {
|
||||
g_irqCpup[intNum].allTime = 0;
|
||||
g_irqCpup[intNum].count = 0;
|
||||
}
|
||||
g_irqCpup[intNum].startTime = 0;
|
||||
if (usedTime > g_irqCpup[intNum].timeMax) {
|
||||
g_irqCpup[intNum].timeMax = usedTime;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
LITE_OS_SEC_TEXT_MINOR OsIrqCpupCB *OsGetIrqCpupArrayBase(VOID)
|
||||
{
|
||||
return g_irqCpup;
|
||||
}
|
||||
|
||||
LITE_OS_SEC_TEXT_MINOR STATIC VOID OsGetIrqPositions(UINT16 mode, UINT16* curPosAddr, UINT16* prePosAddr)
|
||||
{
|
||||
UINT16 curPos;
|
||||
UINT16 prePos = 0;
|
||||
|
||||
curPos = g_irqHisPos;
|
||||
|
||||
if (mode == CPUP_IN_1S) {
|
||||
curPos = OsGetPrePos(curPos);
|
||||
prePos = OsGetPrePos(curPos);
|
||||
} else if (mode == CPUP_LESS_THAN_1S) {
|
||||
curPos = OsGetPrePos(curPos);
|
||||
}
|
||||
|
||||
*curPosAddr = curPos;
|
||||
*prePosAddr = prePos;
|
||||
}
|
||||
|
||||
LITE_OS_SEC_TEXT_MINOR STATIC UINT64 OsGetIrqAllTime(VOID)
|
||||
{
|
||||
INT32 i;
|
||||
UINT64 cpuCycleAll = 0;
|
||||
for (i = 0; i < OS_CPUP_HISTORY_RECORD_NUM; i++) {
|
||||
cpuCycleAll += g_cpuHistoryTime[i];
|
||||
}
|
||||
|
||||
return cpuCycleAll;
|
||||
}
|
||||
|
||||
LITE_OS_SEC_TEXT_MINOR STATIC UINT64 OsGetIrqAllHisTime(UINT32 num)
|
||||
{
|
||||
INT32 i;
|
||||
UINT64 historyTime = 0;
|
||||
for (i = 0; i < OS_CPUP_HISTORY_RECORD_NUM; i++) {
|
||||
historyTime += g_irqCpup[num].historyTime[i];
|
||||
}
|
||||
|
||||
return historyTime;
|
||||
}
|
||||
|
||||
LITE_OS_SEC_TEXT_MINOR UINT32 LOS_GetAllIrqCpuUsage(UINT16 mode, CPUP_INFO_S *cpupInfo)
|
||||
{
|
||||
UINT16 loopNum;
|
||||
UINT16 curPos;
|
||||
UINT16 prePos = 0;
|
||||
UINT32 intSave;
|
||||
UINT64 cpuCycleAll;
|
||||
UINT64 cpuCycleCurIrq;
|
||||
|
||||
if (g_irqCpupInitFlg == 0) {
|
||||
return LOS_ERRNO_CPUP_NO_INIT;
|
||||
}
|
||||
|
||||
if (cpupInfo == NULL) {
|
||||
return LOS_ERRNO_CPUP_TASK_PTR_NULL;
|
||||
}
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
|
||||
OsGetIrqPositions(mode, &curPos, &prePos);
|
||||
if (mode == CPUP_IN_10S) {
|
||||
cpuCycleAll = OsGetIrqAllTime();
|
||||
} else {
|
||||
cpuCycleAll = g_cpuHistoryTime[curPos] - g_cpuHistoryTime[prePos];
|
||||
}
|
||||
|
||||
for (loopNum = 0; loopNum < LOSCFG_PLATFORM_HWI_LIMIT; loopNum++) {
|
||||
if (g_irqCpup[loopNum].status != OS_CPUP_USED) {
|
||||
continue;
|
||||
}
|
||||
|
||||
cpupInfo[loopNum].usStatus = g_irqCpup[loopNum].status;
|
||||
|
||||
if (mode == CPUP_IN_10S) {
|
||||
cpuCycleCurIrq = OsGetIrqAllHisTime(loopNum);
|
||||
} else {
|
||||
cpuCycleCurIrq = g_irqCpup[loopNum].historyTime[curPos] - g_irqCpup[loopNum].historyTime[prePos];
|
||||
}
|
||||
|
||||
if (cpuCycleAll != 0) {
|
||||
cpupInfo[loopNum].uwUsage = (UINT32)((LOS_CPUP_PRECISION * cpuCycleCurIrq) / cpuCycleAll);
|
||||
}
|
||||
}
|
||||
|
||||
LOS_IntRestore(intSave);
|
||||
return LOS_OK;
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* LOSCFG_BASE_CORE_CPUP */
|
||||
|
||||
@@ -139,6 +139,18 @@ typedef struct {
|
||||
|
||||
extern OsCpupCB *g_cpup;
|
||||
|
||||
#if (LOSCFG_CPUP_INCLUDE_IRQ == 1)
|
||||
typedef struct {
|
||||
UINT32 cpupID; /**< Irq ID */
|
||||
UINT16 status; /**< Irq status */
|
||||
UINT64 allTime; /**< Total running time */
|
||||
UINT64 startTime; /**< Time before a task is invoked */
|
||||
UINT64 timeMax; /**< Irq samples count */
|
||||
UINT64 count; /**< Irq samples count */
|
||||
UINT64 historyTime[OS_CPUP_HISTORY_RECORD_NUM]; /**< Historical running time */
|
||||
} OsIrqCpupCB;
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @ingroup los_cpup
|
||||
* @brief Initialization cpup.
|
||||
@@ -159,6 +171,7 @@ extern OsCpupCB *g_cpup;
|
||||
*/
|
||||
extern UINT32 OsCpupInit(VOID);
|
||||
|
||||
extern UINT32 OsCpupDaemonInit(VOID);
|
||||
/**
|
||||
* @ingroup los_cpup
|
||||
* @brief Start task to get cycles count in current task ending.
|
||||
@@ -357,6 +370,13 @@ extern UINT32 LOS_AllTaskCpuUsage(CPUP_INFO_S *cpupInfo, UINT16 mode);
|
||||
*/
|
||||
extern UINT32 LOS_CpupUsageMonitor(CPUP_TYPE_E type, CPUP_MODE_E mode, UINT32 taskID);
|
||||
|
||||
#if (LOSCFG_CPUP_INCLUDE_IRQ == 1)
|
||||
extern VOID OsCpupIrqStart(UINT32 intNum);
|
||||
extern VOID OsCpupIrqEnd(UINT32 intNum);
|
||||
extern OsIrqCpupCB *OsGetIrqCpupArrayBase(VOID);
|
||||
extern UINT32 LOS_GetAllIrqCpuUsage(UINT16 mode, CPUP_INFO_S *cpupInfo);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
|
||||
44
components/debugtools/BUILD.gn
Normal file
44
components/debugtools/BUILD.gn
Normal file
@@ -0,0 +1,44 @@
|
||||
# Copyright (c) 2022-2022 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.
|
||||
|
||||
import("//kernel/liteos_m/liteos.gni")
|
||||
|
||||
module_switch = defined(LOSCFG_DEBUG_TOOLS)
|
||||
module_name = get_path_info(rebase_path("."), "name")
|
||||
kernel_module(module_name) {
|
||||
sources = [
|
||||
"los_hwidump.c",
|
||||
"los_schedtrace.c",
|
||||
"los_stackdump.c",
|
||||
]
|
||||
configs += [ "$LITEOSTOPDIR:warn_config" ]
|
||||
}
|
||||
|
||||
config("public") {
|
||||
include_dirs = [ "." ]
|
||||
}
|
||||
89
components/debugtools/los_debugtools.h
Normal file
89
components/debugtools/los_debugtools.h
Normal file
@@ -0,0 +1,89 @@
|
||||
/*
|
||||
* Copyright (c) 2022-2022 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_DEBUGTOOLS_H
|
||||
#define _LOS_DEBUGTOOLS_H
|
||||
|
||||
#include "los_config.h"
|
||||
#include "los_task.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
|
||||
/* StackDump print format */
|
||||
#define PRINT_PER_ROW 4
|
||||
|
||||
/* SchedTrace records number */
|
||||
#define TRACE_NUM 200
|
||||
|
||||
/* sched trace info, users can add their own */
|
||||
typedef struct {
|
||||
UINT32 newTaskID;
|
||||
CHAR newTaskName[LOS_TASK_NAMELEN];
|
||||
UINT32 runTaskID;
|
||||
CHAR runTaskName[LOS_TASK_NAMELEN];
|
||||
} SchedTraceInfo;
|
||||
|
||||
/* SchedTrace record callback */
|
||||
typedef void (*SchedTraceRecordCB)(LosTaskCB *newTask, LosTaskCB *runTask);
|
||||
|
||||
/* SchedTrace show callback, buf is overwrite ringbuf, max amount of storage is TRACE_NUM */
|
||||
typedef void (*SchedTraceShowCB)(SchedTraceInfo *ringBuf, UINT32 count);
|
||||
|
||||
/* Shell callback */
|
||||
extern UINT32 OsShellCmdStackDump(INT32 argc, const CHAR **argv);
|
||||
extern UINT32 OsShellCmdHwiDump(INT32 argc, const CHAR **argv);
|
||||
extern UINT32 OsShellCmdSchedTrace(INT32 argc, const CHAR **argv);
|
||||
|
||||
/* Other module callback */
|
||||
extern VOID OsSchedTraceRecord(LosTaskCB *newTask, LosTaskCB *runTask);
|
||||
|
||||
/* External interface */
|
||||
/* dump stack by task id, can be called at any time */
|
||||
extern VOID LOS_TaskStackDump(UINT32 taskID);
|
||||
|
||||
/* register sched trace handle, If not registered, the default fun will be used */
|
||||
extern VOID LOS_SchedTraceHandleRegister(SchedTraceRecordCB recordCB, SchedTraceShowCB showCB);
|
||||
/* start sched trace, will alloc buf, and start write to buf when sched */
|
||||
extern VOID LOS_SchedTraceStart(VOID);
|
||||
/* stop sched trace, will stop record and free buf */
|
||||
extern VOID LOS_SchedTraceStop(VOID);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif
|
||||
149
components/debugtools/los_hwidump.c
Normal file
149
components/debugtools/los_hwidump.c
Normal file
@@ -0,0 +1,149 @@
|
||||
/*
|
||||
* Copyright (c) 2022-2022 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_debugtools.h"
|
||||
#include "securec.h"
|
||||
#include "los_debug.h"
|
||||
#include "los_memory.h"
|
||||
#include "los_arch.h"
|
||||
#include "los_interrupt.h"
|
||||
#include "los_arch_interrupt.h"
|
||||
|
||||
#if (LOSCFG_DEBUG_TOOLS == 1)
|
||||
|
||||
#if (LOSCFG_CPUP_INCLUDE_IRQ == 1) && (LOSCFG_BASE_CORE_SWTMR == 1)
|
||||
#include "los_cpup.h"
|
||||
|
||||
#define IRQ_CPUP_INFO_SIZE (sizeof(CPUP_INFO_S) * LOSCFG_PLATFORM_HWI_LIMIT)
|
||||
#define IRQ_CPUP_ALL_INFO_SIZE (IRQ_CPUP_INFO_SIZE + IRQ_CPUP_INFO_SIZE)
|
||||
#define IRQ_DATA_SIZE sizeof(OsIrqCpupCB)
|
||||
#define CPUP_PRECISION_MULT LOS_CPUP_PRECISION_MULT
|
||||
|
||||
STATIC VOID ShellCmdHwiInfoShow(OsIrqCpupCB *irqData, CPUP_INFO_S *hwiCpup1s,
|
||||
CPUP_INFO_S *hwiCpup10s)
|
||||
{
|
||||
UINT32 i;
|
||||
UINT32 intSave;
|
||||
UINT32 count;
|
||||
UINT64 cycles = 0;
|
||||
UINT64 timeMax = 0;
|
||||
CHAR *irqName = NULL;
|
||||
|
||||
OsIrqCpupCB *irqDataBase = OsGetIrqCpupArrayBase();
|
||||
if (irqDataBase == NULL) {
|
||||
PRINT_ERR("get hwi info error\n");
|
||||
return;
|
||||
}
|
||||
|
||||
for (i = 0; i < LOSCFG_PLATFORM_HWI_LIMIT; i++) {
|
||||
if ((OsGetHwiCreated(i) != TRUE) || (OsGetHwiFormCnt(i) == 0)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
(VOID)memcpy_s(irqData, IRQ_DATA_SIZE, &irqDataBase[i], IRQ_DATA_SIZE);
|
||||
LOS_IntRestore(intSave);
|
||||
|
||||
if (irqData->status == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
count = OsGetHwiFormCnt(i);
|
||||
if (count != 0) {
|
||||
if (irqData->count != 0) {
|
||||
cycles = (irqData->allTime * OS_NS_PER_CYCLE) / (irqData->count * OS_SYS_NS_PER_US);
|
||||
}
|
||||
timeMax = (irqData->timeMax * OS_NS_PER_CYCLE) / OS_SYS_NS_PER_US;
|
||||
}
|
||||
irqName = OsGetHwiFormName(i);
|
||||
|
||||
PRINTK(" %10u:%11u%11llu%10llu%9u.%-2u%9u.%-2u %-12s\n", i - OS_SYS_VECTOR_CNT, count, cycles, timeMax,
|
||||
hwiCpup1s[i].uwUsage / CPUP_PRECISION_MULT, hwiCpup1s[i].uwUsage % CPUP_PRECISION_MULT,
|
||||
hwiCpup10s[i].uwUsage / CPUP_PRECISION_MULT, hwiCpup10s[i].uwUsage % CPUP_PRECISION_MULT,
|
||||
(irqName != NULL) ? irqName : NULL);
|
||||
}
|
||||
}
|
||||
|
||||
STATIC VOID HwiInfoDump(VOID)
|
||||
{
|
||||
UINT32 size;
|
||||
|
||||
size = IRQ_CPUP_ALL_INFO_SIZE + IRQ_DATA_SIZE;
|
||||
CHAR *irqCpup = LOS_MemAlloc(m_aucSysMem0, size);
|
||||
if (irqCpup == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
CPUP_INFO_S *hwiCpup10s = (CPUP_INFO_S *)(irqCpup);
|
||||
CPUP_INFO_S *hwiCpup1s = (CPUP_INFO_S *)(hwiCpup10s + IRQ_CPUP_INFO_SIZE);
|
||||
OsIrqCpupCB *irqData = (OsIrqCpupCB *)(irqCpup + IRQ_CPUP_ALL_INFO_SIZE);
|
||||
|
||||
(VOID)LOS_GetAllIrqCpuUsage(CPUP_IN_1S, hwiCpup1s);
|
||||
(VOID)LOS_GetAllIrqCpuUsage(CPUP_IN_10S, hwiCpup10s);
|
||||
|
||||
PRINTK(" InterruptNo Count ATime(us) MTime(us) CPUUSE1s CPUUSE10s Name\n");
|
||||
ShellCmdHwiInfoShow(irqData, hwiCpup1s, hwiCpup10s);
|
||||
(VOID)LOS_MemFree(m_aucSysMem0, irqCpup);
|
||||
return;
|
||||
}
|
||||
#else
|
||||
STATIC VOID HwiInfoDump(VOID)
|
||||
{
|
||||
INT32 i;
|
||||
|
||||
PRINTK(" InterruptNo Count Name\n");
|
||||
for (i = 0; i < LOSCFG_PLATFORM_HWI_LIMIT; i++) {
|
||||
if ((OsGetHwiCreated(i) != TRUE) || (OsGetHwiFormCnt(i) == 0)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (OsGetHwiFormName(i) != NULL) {
|
||||
PRINTK(" %8d:%10d %-s\n", i - OS_SYS_VECTOR_CNT, OsGetHwiFormCnt(i), OsGetHwiFormName(i));
|
||||
} else {
|
||||
PRINTK(" %8d:%10d\n", i - OS_SYS_VECTOR_CNT, OsGetHwiFormCnt(i));
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
UINT32 OsShellCmdHwiDump(INT32 argc, const CHAR **argv)
|
||||
{
|
||||
(VOID)argv;
|
||||
|
||||
if (argc > 1) {
|
||||
PRINT_ERR("\nUsage:hwi\n");
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
HwiInfoDump();
|
||||
return LOS_OK;
|
||||
}
|
||||
#endif /* LOSCFG_STACK_DUMP == 1 */
|
||||
162
components/debugtools/los_schedtrace.c
Normal file
162
components/debugtools/los_schedtrace.c
Normal file
@@ -0,0 +1,162 @@
|
||||
/*
|
||||
* Copyright (c) 2022-2022 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_debugtools.h"
|
||||
#include "securec.h"
|
||||
#include "los_debug.h"
|
||||
#include "los_memory.h"
|
||||
#include "los_arch.h"
|
||||
|
||||
#if (LOSCFG_DEBUG_TOOLS == 1)
|
||||
STATIC BOOL g_startTrace = FALSE;
|
||||
STATIC SchedTraceInfo *g_traceRingBuf = NULL;
|
||||
STATIC UINT32 g_schedCount = 0;
|
||||
STATIC SchedTraceRecordCB g_recordCB = NULL;
|
||||
STATIC SchedTraceShowCB g_showCB = NULL;
|
||||
|
||||
STATIC VOID DefaultShowFormat(SchedTraceInfo *buf, UINT32 count)
|
||||
{
|
||||
INT32 i;
|
||||
UINT32 cycle = count / TRACE_NUM;
|
||||
UINT32 point = count % TRACE_NUM;
|
||||
|
||||
PRINTK ("sched %u time, last %u is:\r\n", count, TRACE_NUM);
|
||||
PRINTK("RunTaskID RunTaskName NewTaskID NewTaskName \r\n");
|
||||
if (cycle > 0) {
|
||||
for (i = point; i < TRACE_NUM; i++) {
|
||||
PRINTK("%4u %20s, %4u %20s\n",
|
||||
g_traceRingBuf[i].runTaskID, g_traceRingBuf[i].runTaskName,
|
||||
g_traceRingBuf[i].newTaskID, g_traceRingBuf[i].newTaskName);
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < point; i++) {
|
||||
PRINTK("%4u %20s, %4u %20s\n",
|
||||
g_traceRingBuf[i].runTaskID, g_traceRingBuf[i].runTaskName,
|
||||
g_traceRingBuf[i].newTaskID, g_traceRingBuf[i].newTaskName);
|
||||
}
|
||||
|
||||
PRINTK("\r\n");
|
||||
}
|
||||
|
||||
STATIC VOID DefaultRecordHandle(LosTaskCB *newTask, LosTaskCB *runTask)
|
||||
{
|
||||
UINT32 point = g_schedCount % TRACE_NUM;
|
||||
|
||||
g_traceRingBuf[point].newTaskID = newTask->taskID;
|
||||
(VOID)memcpy_s(g_traceRingBuf[point].newTaskName, LOS_TASK_NAMELEN, newTask->taskName, LOS_TASK_NAMELEN);
|
||||
g_traceRingBuf[point].runTaskID = runTask->taskID;
|
||||
(VOID)memcpy_s(g_traceRingBuf[point].runTaskName, LOS_TASK_NAMELEN, runTask->taskName, LOS_TASK_NAMELEN);
|
||||
|
||||
g_schedCount++;
|
||||
}
|
||||
|
||||
STATIC VOID ShowFormat(SchedTraceInfo *buf, UINT32 count)
|
||||
{
|
||||
if (count == 0) {
|
||||
PRINT_ERR("none shed happend\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if (g_showCB != NULL) {
|
||||
g_showCB(buf, count);
|
||||
}
|
||||
}
|
||||
|
||||
VOID OsSchedTraceRecord(LosTaskCB *newTask, LosTaskCB *runTask)
|
||||
{
|
||||
if (g_startTrace == FALSE) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (g_recordCB != NULL) {
|
||||
g_recordCB(newTask, runTask);
|
||||
}
|
||||
}
|
||||
|
||||
VOID LOS_SchedTraceStart(VOID)
|
||||
{
|
||||
if (g_recordCB == NULL) {
|
||||
g_recordCB = DefaultRecordHandle;
|
||||
}
|
||||
|
||||
g_traceRingBuf = (SchedTraceInfo *)LOS_MemAlloc(OS_SYS_MEM_ADDR, TRACE_NUM * sizeof(SchedTraceInfo));
|
||||
if (g_traceRingBuf == NULL) {
|
||||
PRINT_ERR("alloc failed for dump\n");
|
||||
return;
|
||||
}
|
||||
(VOID)memset_s(g_traceRingBuf, TRACE_NUM * sizeof(SchedTraceInfo), 0, TRACE_NUM * sizeof(SchedTraceInfo));
|
||||
|
||||
g_startTrace = TRUE;
|
||||
}
|
||||
|
||||
VOID LOS_SchedTraceStop(VOID)
|
||||
{
|
||||
if (g_showCB == NULL) {
|
||||
g_showCB = DefaultShowFormat;
|
||||
}
|
||||
g_startTrace = FALSE;
|
||||
ShowFormat(g_traceRingBuf, g_schedCount);
|
||||
g_schedCount = 0;
|
||||
|
||||
(VOID)LOS_MemFree(OS_SYS_MEM_ADDR, g_traceRingBuf);
|
||||
g_traceRingBuf = NULL;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
VOID LOS_SchedTraceHandleRegister(SchedTraceRecordCB recordCB, SchedTraceShowCB showCB)
|
||||
{
|
||||
g_recordCB = recordCB;
|
||||
g_showCB = showCB;
|
||||
}
|
||||
|
||||
UINT32 OsShellCmdSchedTrace(INT32 argc, const CHAR **argv)
|
||||
{
|
||||
if (argc != 1) {
|
||||
PRINT_ERR("\nUsage: st -h\n");
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
if (strcmp(argv[0], "-s") == 0) {
|
||||
LOS_SchedTraceStart();
|
||||
} else if (strcmp(argv[0], "-e") == 0) {
|
||||
LOS_SchedTraceStop();
|
||||
} else if (strcmp(argv[0], "-h") == 0) {
|
||||
PRINTK("\nUsage: \nst -s , SchedTrace start\n");
|
||||
PRINTK("st -e , SchedTrace end and show\n");
|
||||
} else {
|
||||
PRINTK("\nUsage: st -h\n");
|
||||
return OS_ERROR;
|
||||
}
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
#endif /* LOSCFG_STACK_DUMP == 1 */
|
||||
155
components/debugtools/los_stackdump.c
Normal file
155
components/debugtools/los_stackdump.c
Normal file
@@ -0,0 +1,155 @@
|
||||
/*
|
||||
* Copyright (c) 2022-2022 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_debugtools.h"
|
||||
#include "securec.h"
|
||||
#include "los_debug.h"
|
||||
#include "los_memory.h"
|
||||
#include "los_arch.h"
|
||||
|
||||
#if (LOSCFG_DEBUG_TOOLS == 1)
|
||||
typedef struct {
|
||||
UINT32 waterLine;
|
||||
UINT32 taskSPTop;
|
||||
UINT32 taskSPLimit;
|
||||
UINTPTR taskSP;
|
||||
} DumpInfo;
|
||||
|
||||
STATIC VOID ShowFormat(UINTPTR *buf, DumpInfo *info)
|
||||
{
|
||||
INT32 i;
|
||||
|
||||
UINT32 len = info->waterLine / sizeof(UINTPTR);
|
||||
UINTPTR addr = (info->taskSPLimit - info->waterLine);
|
||||
|
||||
for (i = 0; i < len; i++) {
|
||||
if ((i % PRINT_PER_ROW) == 0) {
|
||||
PRINTK("\r\n 0x%08x: ", addr);
|
||||
}
|
||||
if (addr == info->taskSP) {
|
||||
PRINTK(" *%08x", buf[i]);
|
||||
} else {
|
||||
PRINTK(" %08x", buf[i]);
|
||||
}
|
||||
addr += sizeof(UINTPTR);
|
||||
}
|
||||
|
||||
PRINTK("\r\n");
|
||||
}
|
||||
|
||||
STATIC INT32 DumpTaskInfo(UINT32 taskID, UINTPTR *buf, DumpInfo *info)
|
||||
{
|
||||
errno_t ret;
|
||||
LosTaskCB *taskCB = OS_TCB_FROM_TID(taskID);
|
||||
|
||||
if (taskID == LOS_CurTaskIDGet()) {
|
||||
info->taskSP = ArchSpGet();
|
||||
} else {
|
||||
info->taskSP = (UINTPTR)taskCB->stackPointer;
|
||||
}
|
||||
|
||||
info->taskSPTop = taskCB->topOfStack;
|
||||
info->taskSPLimit = taskCB->topOfStack + taskCB->stackSize;
|
||||
if ((info->taskSP > info->taskSPLimit) || (info->taskSP < info->taskSPTop)) {
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
ret = memcpy_s(buf, info->waterLine, (const VOID *)(info->taskSPLimit - info->waterLine), info->waterLine);
|
||||
if (ret != EOK) {
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
VOID LOS_TaskStackDump(UINT32 taskID)
|
||||
{
|
||||
UINTPTR *buf = NULL;
|
||||
DumpInfo info;
|
||||
UINT32 intSave;
|
||||
INT32 ret;
|
||||
|
||||
if (taskID > g_taskMaxNum) {
|
||||
PRINT_ERR("error taskID %u\r\n", taskID);
|
||||
return;
|
||||
}
|
||||
|
||||
if (OS_INT_ACTIVE) {
|
||||
PRINT_ERR("called during an interrupt.\r\n");
|
||||
return;
|
||||
}
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
info.waterLine = OsGetTaskWaterLine(taskID);
|
||||
if (info.waterLine == OS_NULL_INT) {
|
||||
LOS_IntRestore(intSave);
|
||||
return;
|
||||
}
|
||||
|
||||
buf = (UINTPTR *)LOS_MemAlloc(OS_SYS_MEM_ADDR, info.waterLine);
|
||||
if (buf == NULL) {
|
||||
LOS_IntRestore(intSave);
|
||||
PRINT_ERR("alloc failed for dump\n");
|
||||
return;
|
||||
}
|
||||
(VOID)memset_s(buf, info.waterLine, 0, info.waterLine);
|
||||
|
||||
ret = DumpTaskInfo(taskID, buf, &info);
|
||||
if (ret != LOS_OK) {
|
||||
LOS_IntRestore(intSave);
|
||||
(VOID)LOS_MemFree(OS_SYS_MEM_ADDR, buf);
|
||||
PRINT_ERR("SP 0x%x may error or memcpy_s failed, stack space from 0x%x to 0x%x\r\n", \
|
||||
info.taskSP, info.taskSPTop, info.taskSPLimit);
|
||||
return;
|
||||
}
|
||||
|
||||
LOS_IntRestore(intSave);
|
||||
PRINTK("Task %u, SP 0x%x, WaterLine 0x%x", taskID, info.taskSP, info.waterLine);
|
||||
ShowFormat(buf, &info);
|
||||
(VOID)LOS_MemFree(OS_SYS_MEM_ADDR, buf);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
UINT32 OsShellCmdStackDump(INT32 argc, const CHAR **argv)
|
||||
{
|
||||
UINT32 taskID;
|
||||
|
||||
if (argc != 1) {
|
||||
PRINT_ERR("\nUsage: stack taskID\n");
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
taskID = (UINT32)atoi(argv[0]);
|
||||
|
||||
LOS_TaskStackDump(taskID);
|
||||
return LOS_OK;
|
||||
}
|
||||
#endif /* LOSCFG_STACK_DUMP == 1 */
|
||||
21
components/dynlink/los_dynlink.c
Executable file → Normal file
21
components/dynlink/los_dynlink.c
Executable file → Normal file
@@ -73,8 +73,8 @@ const SymInfo symTableEnd __attribute__((section(".table.end"))) = {
|
||||
.name = "end",
|
||||
.addr = 0
|
||||
};
|
||||
#pragma section=".TABLE.START"
|
||||
#pragma section=".table.end"
|
||||
#pragma section = ".TABLE.START"
|
||||
#pragma section = ".table.end"
|
||||
#elif defined(__CLANG_ARM) || defined(__GNUC__)
|
||||
/**
|
||||
* Place instructions below in rodata segment of .ld linker file:
|
||||
@@ -796,13 +796,13 @@ VOID *LOS_SoLoad(const CHAR *fileName, VOID *pool)
|
||||
return dso;
|
||||
|
||||
ERR2:
|
||||
LOS_MemFree(dso->pool, (VOID *)dso->loadBase);
|
||||
(VOID)LOS_MemFree(dso->pool, (VOID *)dso->loadBase);
|
||||
ERR1:
|
||||
close(dso->fd);
|
||||
(VOID)LOS_MuxPost(g_dynlinkMux);
|
||||
LOS_MemFree(OS_SYS_MEM_ADDR, dso->dlInfo->elfPhdr);
|
||||
LOS_MemFree(OS_SYS_MEM_ADDR, dso->dlInfo);
|
||||
LOS_MemFree(OS_SYS_MEM_ADDR, dso);
|
||||
(VOID)LOS_MemFree(OS_SYS_MEM_ADDR, dso->dlInfo->elfPhdr);
|
||||
(VOID)LOS_MemFree(OS_SYS_MEM_ADDR, dso->dlInfo);
|
||||
(VOID)LOS_MemFree(OS_SYS_MEM_ADDR, dso);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -902,9 +902,12 @@ INT32 LOS_SoUnload(VOID *handle)
|
||||
LOS_ListDelete(&dso->dsoNode);
|
||||
(VOID)LOS_MuxPost(g_dynlinkMux);
|
||||
|
||||
LOS_MemFree(dso->pool, (VOID *)dso->loadBase);
|
||||
LOS_MemFree(OS_SYS_MEM_ADDR, dso->dlInfo);
|
||||
LOS_MemFree(OS_SYS_MEM_ADDR, dso);
|
||||
(VOID)LOS_MemFree(dso->pool, (VOID *)dso->loadBase);
|
||||
if (dso->dlInfo != NULL) {
|
||||
(VOID)LOS_MemFree(OS_SYS_MEM_ADDR, dso->dlInfo->elfPhdr);
|
||||
}
|
||||
(VOID)LOS_MemFree(OS_SYS_MEM_ADDR, dso->dlInfo);
|
||||
(VOID)LOS_MemFree(OS_SYS_MEM_ADDR, dso);
|
||||
|
||||
return LOS_OK;
|
||||
ERR:
|
||||
|
||||
2
components/dynlink/los_dynlink.h
Executable file → Normal file
2
components/dynlink/los_dynlink.h
Executable file → Normal file
@@ -169,7 +169,7 @@ VOID *LOS_SoLoad(const CHAR *fileName, VOID *pool);
|
||||
VOID *LOS_FindSym(VOID *handle, const CHAR *name);
|
||||
|
||||
/*
|
||||
* @brief Decrement the reference count on the loaded shared library refered to by handle.
|
||||
* @brief Decrement the reference count on the loaded shared library referred to by handle.
|
||||
* If the reference count drops to zero, then the library is unloaded.
|
||||
*
|
||||
* This function validates that the handle is valid.
|
||||
|
||||
@@ -55,7 +55,7 @@ STATIC ExcInfoArray g_excArray[OS_EXC_TYPE_MAX];
|
||||
|
||||
STATIC UINT32 OsExcSaveIntStatus(UINT32 type, VOID *arg)
|
||||
{
|
||||
UINT32 ret;
|
||||
errno_t ret;
|
||||
UINTPTR excContentEnd = (UINTPTR)MAX_INT_INFO_SIZE + (UINTPTR)g_excContent;
|
||||
|
||||
(VOID)arg;
|
||||
@@ -92,6 +92,9 @@ STATIC UINT32 OsExcSaveIntStatus(UINT32 type, VOID *arg)
|
||||
/* save IRQ Priority reg group */
|
||||
ret = memcpy_s(g_excContent, excContentEnd - (UINTPTR)g_excContent,
|
||||
(const VOID *)OS_NVIC_PRI_BASE, OS_NVIC_INT_PRI_SIZE);
|
||||
if (ret != EOK) {
|
||||
return LOS_NOK;
|
||||
}
|
||||
g_excContent = (UINT8 *)g_excContent + OS_NVIC_INT_PRI_SIZE;
|
||||
|
||||
/* save Exception Priority reg group */
|
||||
@@ -294,5 +297,3 @@ VOID OsExcMsgDumpInit(VOID)
|
||||
(VOID)LOS_RegExcHook(EXC_INTERRUPT, (ExcHookFn)OsExcMsgDump);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
@@ -36,39 +36,3 @@ config FS_FAT
|
||||
help
|
||||
Answer Y to enable LiteOS support fat filesystem.
|
||||
|
||||
config FS_FAT_CACHE
|
||||
bool "Enable FAT Cache"
|
||||
default y
|
||||
depends on FS_FAT
|
||||
help
|
||||
Answer Y to enable LiteOS fat filesystem support cache.
|
||||
|
||||
config FS_FAT_CACHE_SYNC_THREAD
|
||||
bool "Enable FAT Cache Sync Thread"
|
||||
default n
|
||||
depends on FS_FAT_CACHE
|
||||
help
|
||||
Answer Y to enable LiteOS fat filesystem support cache sync thread.
|
||||
|
||||
config FS_FAT_CHINESE
|
||||
bool "Enable Chinese"
|
||||
default y
|
||||
depends on FS_FAT
|
||||
help
|
||||
Answer Y to enable LiteOS fat filesystem support Chinese.
|
||||
|
||||
config FS_FAT_VIRTUAL_PARTITION
|
||||
bool "Enabel Virtual Partition"
|
||||
default n
|
||||
depends on FS_FAT
|
||||
|
||||
config FS_FAT_VOLUMES
|
||||
int
|
||||
depends on FS_FAT
|
||||
default 32 if PLATFORM_HI3731
|
||||
default 16
|
||||
|
||||
config FS_FAT_DISK
|
||||
bool "Enable partinfo for storage device"
|
||||
depends on FS_FAT
|
||||
default y
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -32,14 +32,7 @@
|
||||
#ifndef _FATFS_H
|
||||
#define _FATFS_H
|
||||
|
||||
#include "dirent.h"
|
||||
#include "fatfs_conf.h"
|
||||
#include "fcntl.h"
|
||||
#include "fs_config.h"
|
||||
#include "sys/mount.h"
|
||||
#include "sys/stat.h"
|
||||
#include "sys/statfs.h"
|
||||
#include "unistd.h"
|
||||
#include "ff.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
@@ -47,56 +40,7 @@ extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
int fatfs_mount(const char *source, const char *target,
|
||||
const char *filesystemtype, unsigned long mountflags,
|
||||
const void *data);
|
||||
int fatfs_umount(const char *target);
|
||||
int fatfs_umount2(const char *target, int flag);
|
||||
int fatfs_open(const char *path, int oflag, ...);
|
||||
int fatfs_close(int fd);
|
||||
ssize_t fatfs_read(int fd, void *buf, size_t nbyte);
|
||||
ssize_t fatfs_write(int fd, const void *buf, size_t nbyte);
|
||||
off_t fatfs_lseek(int fd, off_t offset, int whence);
|
||||
int fatfs_unlink(const char *path);
|
||||
int fatfs_fstat(int fd, struct stat *buf);
|
||||
int fatfs_stat(const char *path, struct stat *buf);
|
||||
int fatfs_fsync(int fd);
|
||||
int fatfs_mkdir(const char *path, mode_t mode);
|
||||
DIR *fatfs_opendir(const char *dirName);
|
||||
struct dirent *fatfs_readdir(DIR *dir);
|
||||
int fatfs_closedir(DIR *dir);
|
||||
int fatfs_rmdir(const char *path);
|
||||
int fatfs_rename(const char *oldName, const char *newName);
|
||||
int fatfs_statfs(const char *path, struct statfs *buf);
|
||||
int fatfs_ftruncate(int fd, off_t length);
|
||||
|
||||
/**
|
||||
* @brief divide a physical drive (SD card, U disk, and MMC card), this function is OHOS-specific
|
||||
* @param pdrv physical drive number.
|
||||
* @param partTbl list of partition size to create on the drive.
|
||||
* -- item is <= 100: specifies the partition size in percentage of the entire drive space.
|
||||
* -- item is > 100: specifies number of sectors.
|
||||
* @return fdisk result
|
||||
* @retval -1 fdisk error
|
||||
* @retval 0 fdisk successful
|
||||
*/
|
||||
int fatfs_fdisk(int pdrv, const unsigned int *partTbl);
|
||||
|
||||
/**
|
||||
* @brief format FAT device (SD card, U disk, and MMC card), this function is OHOS-specific
|
||||
* @param dev device name.
|
||||
* @param sectors sectors per cluster, can be 0 OR power of 2. The sector size for standard FAT volumes is 512 bytes.
|
||||
* -- sector number is 0 OR >128: automatically choose the appropriate cluster size.
|
||||
* -- sector number is 1 ~ 128: cluster size = sectors per cluster * 512B.
|
||||
* @param option file system type.
|
||||
* -- FMT_FAT
|
||||
* -- FMT_FAT32
|
||||
* -- FMT_ANY
|
||||
* @return format result
|
||||
* @retval -1 format error
|
||||
* @retval 0 format successful
|
||||
*/
|
||||
int fatfs_format(const char *dev, int sectors, int option);
|
||||
void FatFsInit(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
|
||||
@@ -34,7 +34,7 @@ module_switch = defined(LOSCFG_FS_LITTLEFS)
|
||||
module_name = get_path_info(rebase_path("."), "name")
|
||||
kernel_module(module_name) {
|
||||
configs += [ "$LITEOSTOPDIR:warn_config" ]
|
||||
sources = LITTLEFS_SRC_FILES_FOR_KERNEL_MODULE + [ "lfs_api.c" ]
|
||||
sources = LITTLEFS_SRC_FILES_FOR_KERNEL_MODULE + [ "lfs_adapter.c" ]
|
||||
}
|
||||
|
||||
config("public") {
|
||||
|
||||
596
components/fs/littlefs/lfs_adapter.c
Normal file
596
components/fs/littlefs/lfs_adapter.c
Normal file
@@ -0,0 +1,596 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#define _GNU_SOURCE 1
|
||||
#include "lfs_adapter.h"
|
||||
#include "los_config.h"
|
||||
#include "vfs_files.h"
|
||||
#include "vfs_operations.h"
|
||||
#include "vfs_partition.h"
|
||||
#include "vfs_maps.h"
|
||||
#include "vfs_mount.h"
|
||||
#include "securec.h"
|
||||
|
||||
struct dirent g_nameValue;
|
||||
static pthread_mutex_t g_FslocalMutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
static int ConvertFlagToLfsOpenFlag (int oflags)
|
||||
{
|
||||
int lfsOpenFlag = 0;
|
||||
|
||||
if (oflags & O_CREAT) {
|
||||
lfsOpenFlag |= LFS_O_CREAT;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
static int LittlefsErrno(int result)
|
||||
{
|
||||
return (result < 0) ? -result : result;
|
||||
}
|
||||
|
||||
int LfsMount(struct MountPoint *mp, unsigned long mountflags, const void *data)
|
||||
{
|
||||
int ret;
|
||||
lfs_t *mountHdl = NULL;
|
||||
|
||||
if ((mp == NULL) || (mp->mPath == NULL) || (data == NULL)) {
|
||||
errno = EFAULT;
|
||||
ret = LOS_NOK;
|
||||
goto errout;
|
||||
}
|
||||
|
||||
mountHdl = (lfs_t *)malloc(sizeof(lfs_t));
|
||||
if (mountHdl == NULL) {
|
||||
errno = ENODEV;
|
||||
ret = LOS_NOK;
|
||||
goto errout;
|
||||
}
|
||||
(void)memset_s(mountHdl, sizeof(lfs_t), 0, sizeof(lfs_t));
|
||||
mp->mData = (void *)mountHdl;
|
||||
|
||||
ret = lfs_mount((lfs_t *)mp->mData, (struct lfs_config *)data);
|
||||
if (ret != 0) {
|
||||
ret = lfs_format((lfs_t *)mp->mData, (struct lfs_config*)data);
|
||||
if (ret == 0) {
|
||||
ret = lfs_mount((lfs_t *)mp->mData, (struct lfs_config*)data);
|
||||
}
|
||||
}
|
||||
|
||||
if (ret != 0) {
|
||||
free(mountHdl);
|
||||
errno = LittlefsErrno(ret);
|
||||
ret = LOS_NOK;
|
||||
}
|
||||
|
||||
errout:
|
||||
return ret;
|
||||
}
|
||||
|
||||
int LfsUmount(struct MountPoint *mp)
|
||||
{
|
||||
int ret;
|
||||
|
||||
if (mp == NULL) {
|
||||
errno = EFAULT;
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
if (mp->mData == NULL) {
|
||||
errno = ENOENT;
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
ret = lfs_unmount((lfs_t *)mp->mData);
|
||||
if (ret != 0) {
|
||||
errno = LittlefsErrno(ret);
|
||||
ret = LOS_NOK;
|
||||
}
|
||||
|
||||
free(mp->mData);
|
||||
mp->mData = NULL;
|
||||
return ret;
|
||||
}
|
||||
|
||||
int LfsUnlink(struct MountPoint *mp, const char *fileName)
|
||||
{
|
||||
int ret;
|
||||
|
||||
if ((mp == NULL) || (fileName == NULL)) {
|
||||
errno = EFAULT;
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
if (mp->mData == NULL) {
|
||||
errno = ENOENT;
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
ret = lfs_remove((lfs_t *)mp->mData, fileName);
|
||||
if (ret != 0) {
|
||||
errno = LittlefsErrno(ret);
|
||||
ret = LOS_NOK;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int LfsMkdir(struct MountPoint *mp, const char *dirName)
|
||||
{
|
||||
int ret;
|
||||
|
||||
if ((dirName == NULL) || (mp == NULL)) {
|
||||
errno = EFAULT;
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
if (mp->mData == NULL) {
|
||||
errno = ENOENT;
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
lfs_t *lfs = (lfs_t *)mp->mData;
|
||||
|
||||
ret = lfs_mkdir(lfs, dirName);
|
||||
if (ret != 0) {
|
||||
errno = LittlefsErrno(ret);
|
||||
ret = LOS_NOK;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int LfsRmdir(struct MountPoint *mp, const char *dirName)
|
||||
{
|
||||
int ret;
|
||||
lfs_t *lfs = NULL;
|
||||
|
||||
if (mp == NULL) {
|
||||
errno = EFAULT;
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
if (mp->mData == NULL) {
|
||||
errno = ENOENT;
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
lfs = (lfs_t *)mp->mData;
|
||||
|
||||
if (dirName == NULL) {
|
||||
errno = EFAULT;
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
ret = lfs_remove(lfs, dirName);
|
||||
if (ret != 0) {
|
||||
errno = LittlefsErrno(ret);
|
||||
ret = LOS_NOK;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int LfsOpendir(struct Dir *dir, const char *dirName)
|
||||
{
|
||||
int ret;
|
||||
|
||||
if ((dir == NULL) || (dir->dMp == NULL) || (dir->dMp->mData == NULL)) {
|
||||
errno = EFAULT;
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
lfs_t *lfs = (lfs_t *)dir->dMp->mData;
|
||||
lfs_dir_t *dirInfo = (lfs_dir_t *)malloc(sizeof(lfs_dir_t));
|
||||
if (dirInfo == NULL) {
|
||||
errno = ENOMEM;
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
(void)memset_s(dirInfo, sizeof(lfs_dir_t), 0, sizeof(lfs_dir_t));
|
||||
ret = lfs_dir_open(lfs, dirInfo, dirName);
|
||||
if (ret != 0) {
|
||||
free(dirInfo);
|
||||
errno = LittlefsErrno(ret);
|
||||
goto errout;
|
||||
}
|
||||
|
||||
dir->dData = dirInfo;
|
||||
dir->dOffset = 0;
|
||||
|
||||
return LOS_OK;
|
||||
|
||||
errout:
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
int LfsReaddir(struct Dir *dir, struct dirent *dent)
|
||||
{
|
||||
int ret;
|
||||
struct lfs_info lfsInfo;
|
||||
|
||||
if ((dir == NULL) || (dir->dMp == NULL) || (dir->dMp->mData == NULL) ||
|
||||
(dent == NULL)) {
|
||||
errno = EFAULT;
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
if (dir->dData == NULL) {
|
||||
errno = EBADF;
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
lfs_t *lfs = (lfs_t *)dir->dMp->mData;
|
||||
lfs_dir_t *dirInfo = (lfs_dir_t *)dir->dData;
|
||||
|
||||
ret = lfs_dir_read(lfs, dirInfo, &lfsInfo);
|
||||
if (ret == TRUE) {
|
||||
pthread_mutex_lock(&g_FslocalMutex);
|
||||
(void)strncpy_s(dent->d_name, sizeof(dent->d_name), lfsInfo.name, strlen(lfsInfo.name) + 1);
|
||||
if (lfsInfo.type == LFS_TYPE_DIR) {
|
||||
dent->d_type = DT_DIR;
|
||||
} else if (lfsInfo.type == LFS_TYPE_REG) {
|
||||
dent->d_type = DT_REG;
|
||||
}
|
||||
|
||||
dent->d_reclen = lfsInfo.size;
|
||||
pthread_mutex_unlock(&g_FslocalMutex);
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
if (ret != 0) {
|
||||
errno = LittlefsErrno(ret);
|
||||
}
|
||||
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
int LfsClosedir(struct Dir *dir)
|
||||
{
|
||||
int ret;
|
||||
|
||||
if ((dir == NULL) || (dir->dMp == NULL) || (dir->dMp->mData == NULL)) {
|
||||
errno = EFAULT;
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
if (dir->dData == NULL) {
|
||||
errno = EBADF;
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
lfs_t *lfs = (lfs_t *)dir->dMp->mData;
|
||||
lfs_dir_t *dirInfo = (lfs_dir_t *)dir->dData;
|
||||
|
||||
ret = lfs_dir_close(lfs, dirInfo);
|
||||
if (ret != 0) {
|
||||
errno = LittlefsErrno(ret);
|
||||
ret = LOS_NOK;
|
||||
}
|
||||
|
||||
free(dirInfo);
|
||||
dir->dData = NULL;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int LfsOpen(struct File *file, const char *pathName, int openFlag)
|
||||
{
|
||||
int ret;
|
||||
lfs_file_t *lfsHandle = NULL;
|
||||
|
||||
if ((pathName == NULL) || (file == NULL) || (file->fMp == NULL) ||
|
||||
(file->fMp->mData == NULL)) {
|
||||
errno = EFAULT;
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
lfsHandle = (lfs_file_t *)malloc(sizeof(lfs_file_t));
|
||||
if (lfsHandle == NULL) {
|
||||
errno = ENOMEM;
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
int lfsOpenFlag = ConvertFlagToLfsOpenFlag(openFlag);
|
||||
ret = lfs_file_open((lfs_t *)file->fMp->mData, lfsHandle, pathName, lfsOpenFlag);
|
||||
if (ret != 0) {
|
||||
free(lfsHandle);
|
||||
errno = LittlefsErrno(ret);
|
||||
goto errout;
|
||||
}
|
||||
|
||||
file->fData = (void *)lfsHandle;
|
||||
return ret;
|
||||
|
||||
errout:
|
||||
return INVALID_FD;
|
||||
}
|
||||
|
||||
int LfsRead(struct File *file, char *buf, size_t len)
|
||||
{
|
||||
int ret;
|
||||
struct MountPoint *mp = NULL;
|
||||
lfs_file_t *lfsHandle = NULL;
|
||||
|
||||
if (buf == NULL) {
|
||||
errno = EFAULT;
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
if ((file == NULL) || (file->fData == NULL)) {
|
||||
errno = EBADF;
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
lfsHandle = (lfs_file_t *)file->fData;
|
||||
mp = file->fMp;
|
||||
if ((mp == NULL) || (mp->mData == NULL)) {
|
||||
errno = EFAULT;
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
ret = lfs_file_read((lfs_t *)mp->mData, lfsHandle, buf, len);
|
||||
if (ret < 0) {
|
||||
errno = LittlefsErrno(ret);
|
||||
ret = LOS_NOK;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int LfsWrite(struct File *file, const char *buf, size_t len)
|
||||
{
|
||||
int ret;
|
||||
struct MountPoint *mp = NULL;
|
||||
lfs_file_t *lfsHandle = NULL;
|
||||
|
||||
if (buf == NULL) {
|
||||
errno = EFAULT;
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
if ((file == NULL) || (file->fData == NULL)) {
|
||||
errno = EBADF;
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
lfsHandle = (lfs_file_t *)file->fData;
|
||||
mp = file->fMp;
|
||||
if ((mp == NULL) || (mp->mData == NULL)) {
|
||||
errno = EFAULT;
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
ret = lfs_file_write((lfs_t *)mp->mData, lfsHandle, buf, len);
|
||||
if (ret < 0) {
|
||||
errno = LittlefsErrno(ret);
|
||||
ret = LOS_NOK;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
off_t LfsSeek(struct File *file, off_t offset, int whence)
|
||||
{
|
||||
off_t ret;
|
||||
struct MountPoint *mp = NULL;
|
||||
lfs_file_t *lfsHandle = NULL;
|
||||
|
||||
if ((file == NULL) || (file->fData == NULL)) {
|
||||
errno = EBADF;
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
lfsHandle = (lfs_file_t *)file->fData;
|
||||
mp = file->fMp;
|
||||
if ((mp == NULL) || (mp->mData == NULL)) {
|
||||
errno = EFAULT;
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
ret = (off_t)lfs_file_seek((lfs_t *)mp->mData, lfsHandle, offset, whence);
|
||||
if (ret < 0) {
|
||||
errno = LittlefsErrno(ret);
|
||||
ret = LOS_NOK;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int LfsClose(struct File *file)
|
||||
{
|
||||
INT32 ret;
|
||||
struct MountPoint *mp = NULL;
|
||||
lfs_file_t *lfsHandle = NULL;
|
||||
|
||||
if ((file == NULL) || (file->fData == NULL)) {
|
||||
errno = EBADF;
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
lfsHandle = (lfs_file_t *)file->fData;
|
||||
mp = file->fMp;
|
||||
if ((mp == NULL) || (mp->mData == NULL)) {
|
||||
errno = EFAULT;
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
pthread_mutex_lock(&g_FslocalMutex);
|
||||
ret = lfs_file_close((lfs_t *)mp->mData, lfsHandle);
|
||||
pthread_mutex_unlock(&g_FslocalMutex);
|
||||
|
||||
if (ret != 0) {
|
||||
errno = LittlefsErrno(ret);
|
||||
ret = LOS_NOK;
|
||||
}
|
||||
|
||||
free(file->fData);
|
||||
file->fData = NULL;
|
||||
return ret;
|
||||
}
|
||||
|
||||
int LfsRename(struct MountPoint *mp, const char *oldName, const char *newName)
|
||||
{
|
||||
int ret;
|
||||
|
||||
if ((mp == NULL) || (oldName == NULL) || (newName == NULL)) {
|
||||
errno = EFAULT;
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
if (mp->mData == NULL) {
|
||||
errno = ENOENT;
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
ret = lfs_rename((lfs_t *)mp->mData, oldName, newName);
|
||||
if (ret != 0) {
|
||||
errno = LittlefsErrno(ret);
|
||||
ret = LOS_NOK;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int LfsStat(struct MountPoint *mp, const char *path, struct stat *buf)
|
||||
{
|
||||
int ret;
|
||||
struct lfs_info info;
|
||||
|
||||
if ((mp == NULL) || (path == NULL) || (buf == NULL)) {
|
||||
errno = EFAULT;
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
if (mp->mData == NULL) {
|
||||
errno = ENOENT;
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
ret = lfs_stat((lfs_t *)mp->mData, path, &info);
|
||||
if (ret == 0) {
|
||||
buf->st_size = info.size;
|
||||
if (info.type == LFS_TYPE_REG) {
|
||||
buf->st_mode = S_IFREG;
|
||||
} else {
|
||||
buf->st_mode = S_IFDIR;
|
||||
}
|
||||
} else {
|
||||
errno = LittlefsErrno(ret);
|
||||
ret = LOS_NOK;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int LfsSync(struct File *file)
|
||||
{
|
||||
int ret;
|
||||
struct MountPoint *mp = NULL;
|
||||
|
||||
if ((file == NULL) || (file->fData == NULL)) {
|
||||
errno = EBADF;
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
if ((file->fMp == NULL) || (file->fMp->mData == NULL)) {
|
||||
errno = EFAULT;
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
mp = file->fMp;
|
||||
ret = lfs_file_sync((lfs_t *)mp->mData, (lfs_file_t *)file->fData);
|
||||
if (ret != 0) {
|
||||
errno = LittlefsErrno(ret);
|
||||
ret = LOS_NOK;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static struct MountOps g_lfsMnt = {
|
||||
.mount = LfsMount,
|
||||
.umount = LfsUmount,
|
||||
.umount2 = NULL,
|
||||
.statfs = NULL,
|
||||
};
|
||||
|
||||
static struct FileOps g_lfsFops = {
|
||||
.open = LfsOpen,
|
||||
.close = LfsClose,
|
||||
.read = LfsRead,
|
||||
.write = LfsWrite,
|
||||
.lseek = LfsSeek,
|
||||
.stat = LfsStat,
|
||||
.truncate = NULL,
|
||||
.unlink = LfsUnlink,
|
||||
.rename = LfsRename,
|
||||
.ioctl = NULL, /* not support */
|
||||
.sync = LfsSync,
|
||||
.rmdir = LfsRmdir,
|
||||
.opendir = LfsOpendir,
|
||||
.readdir = LfsReaddir,
|
||||
.closedir = LfsClosedir,
|
||||
.mkdir = LfsMkdir,
|
||||
};
|
||||
|
||||
static struct FsManagement g_lfsMgt = {
|
||||
.fdisk = NULL,
|
||||
.format = NULL,
|
||||
};
|
||||
|
||||
void LfsInit(void)
|
||||
{
|
||||
(void)OsFsRegister("littlefs", &g_lfsMnt, &g_lfsFops, &g_lfsMgt);
|
||||
}
|
||||
@@ -29,15 +29,15 @@
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef _LFS_API_H_
|
||||
#define _LFS_API_H_
|
||||
#ifndef _LFS_ADAPTER_H_
|
||||
#define _LFS_ADAPTER_H_
|
||||
|
||||
#include "fcntl.h"
|
||||
#include "sys/stat.h"
|
||||
|
||||
#include "dirent.h"
|
||||
#include "errno.h"
|
||||
#include "fs_operations.h"
|
||||
#include "vfs_operations.h"
|
||||
#include "lfs.h"
|
||||
#include "lfs_conf.h"
|
||||
#include "lfs_util.h"
|
||||
@@ -46,57 +46,5 @@
|
||||
|
||||
#define INVALID_FD (-1)
|
||||
|
||||
#ifndef VFS_ERROR
|
||||
#define VFS_ERROR (-1)
|
||||
#endif
|
||||
|
||||
#ifndef VFS_OK
|
||||
#define VFS_OK 0
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
uint8_t useFlag;
|
||||
const char *pathName;
|
||||
lfs_t *lfsHandle;
|
||||
lfs_file_t file;
|
||||
} LittleFsHandleStruct;
|
||||
|
||||
struct FileOpInfo {
|
||||
uint8_t useFlag;
|
||||
const struct FileOps *fsVops;
|
||||
char *dirName;
|
||||
lfs_t lfsInfo;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
uint8_t useFlag;
|
||||
char *dirName;
|
||||
lfs_t *lfsHandle;
|
||||
lfs_dir_t dir;
|
||||
} FileDirInfo;
|
||||
|
||||
LittleFsHandleStruct *GetFreeFd(int *fd);
|
||||
|
||||
int LfsMount(const char *source, const char *target, const char *fileSystemType, unsigned long mountflags,
|
||||
const void *data);
|
||||
|
||||
int LfsUmount(const char *target);
|
||||
int LfsUnlink(const char *fileName);
|
||||
int LfsMkdir(const char *dirName, mode_t mode);
|
||||
int LfsRmdir(const char *dirName);
|
||||
DIR *LfsOpendir(const char *dirName);
|
||||
struct dirent *LfsReaddir(DIR *dir);
|
||||
int LfsClosedir(DIR *dir);
|
||||
int LfsOpen(const char *pathName, int openFlag, ...);
|
||||
int LfsRead(int fd, void *buf, unsigned int len);
|
||||
int LfsWrite(int fd, const void *buf, unsigned int len);
|
||||
off_t LfsSeek(int fd, off_t offset, int whence);
|
||||
int LfsClose(int fd);
|
||||
int LfsRename(const char *oldName, const char *newName);
|
||||
int LfsStat(const char *path, struct stat *buf);
|
||||
int LfsFsync(int fd);
|
||||
int LfsFstat(int fd, struct stat *buf);
|
||||
int SetDefaultMountPath(int pathNameIndex, const char* target);
|
||||
|
||||
#endif /* _LFS_API_H_ */
|
||||
|
||||
void LfsInit(void);
|
||||
#endif /* _LFS_ADAPTER_H_ */
|
||||
@@ -1,805 +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.
|
||||
*/
|
||||
|
||||
#define _GNU_SOURCE 1
|
||||
#include "lfs_api.h"
|
||||
#include "los_config.h"
|
||||
#include "securec.h"
|
||||
|
||||
lfs_t g_lfs;
|
||||
FileDirInfo g_lfsDir[LFS_MAX_OPEN_DIRS] = {0};
|
||||
|
||||
struct FileOpInfo g_fsOp[LOSCFG_LFS_MAX_MOUNT_SIZE] = {0};
|
||||
static LittleFsHandleStruct g_handle[LOSCFG_LFS_MAX_OPEN_FILES] = {0};
|
||||
struct dirent g_nameValue;
|
||||
static pthread_mutex_t g_FslocalMutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
static const char *g_littlefsMntName[LOSCFG_LFS_MAX_MOUNT_SIZE] = {"/a"};
|
||||
|
||||
LittleFsHandleStruct *LfsAllocFd(const char *fileName, int *fd)
|
||||
{
|
||||
pthread_mutex_lock(&g_FslocalMutex);
|
||||
for (int i = 0; i < LOSCFG_LFS_MAX_OPEN_FILES; i++) {
|
||||
if (g_handle[i].useFlag == 0) {
|
||||
*fd = i;
|
||||
g_handle[i].useFlag = 1;
|
||||
g_handle[i].pathName = strdup(fileName);
|
||||
pthread_mutex_unlock(&g_FslocalMutex);
|
||||
return &(g_handle[i]);
|
||||
}
|
||||
}
|
||||
pthread_mutex_unlock(&g_FslocalMutex);
|
||||
*fd = INVALID_FD;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void LfsFreeFd(int fd)
|
||||
{
|
||||
pthread_mutex_lock(&g_FslocalMutex);
|
||||
g_handle[fd].useFlag = 0;
|
||||
if (g_handle[fd].pathName != NULL) {
|
||||
free((void *)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);
|
||||
}
|
||||
|
||||
BOOL CheckFileIsOpen(const char *fileName)
|
||||
{
|
||||
pthread_mutex_lock(&g_FslocalMutex);
|
||||
for (int i = 0; i < LOSCFG_LFS_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;
|
||||
}
|
||||
|
||||
static BOOL LfsFdIsValid(int fd)
|
||||
{
|
||||
if (fd >= LOSCFG_LFS_MAX_OPEN_FILES || fd < 0) {
|
||||
return FALSE;
|
||||
}
|
||||
if (g_handle[fd].lfsHandle == NULL) {
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
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]);
|
||||
}
|
||||
}
|
||||
pthread_mutex_unlock(&g_FslocalMutex);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void FreeDirInfo(const char *dirName)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
int GetFirstLevelPathLen(const char *pathName)
|
||||
{
|
||||
int len = 1;
|
||||
for (int i = 1; i < strlen(pathName) + 1; i++) {
|
||||
if (pathName[i] == '/') {
|
||||
break;
|
||||
}
|
||||
len++;
|
||||
}
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
BOOL CheckPathIsMounted(const char *pathName, struct FileOpInfo **fileOpInfo)
|
||||
{
|
||||
char tmpName[LITTLEFS_MAX_LFN_LEN] = {0};
|
||||
int len = GetFirstLevelPathLen(pathName);
|
||||
|
||||
pthread_mutex_lock(&g_FslocalMutex);
|
||||
for (int i = 0; i < LOSCFG_LFS_MAX_MOUNT_SIZE; i++) {
|
||||
if (g_fsOp[i].useFlag == 1) {
|
||||
(void)strncpy_s(tmpName, LITTLEFS_MAX_LFN_LEN, pathName, len);
|
||||
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, const struct FileOps *fileOps)
|
||||
{
|
||||
pthread_mutex_lock(&g_FslocalMutex);
|
||||
for (int i = 0; i < LOSCFG_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;
|
||||
}
|
||||
|
||||
int SetDefaultMountPath(int pathNameIndex, const char* target)
|
||||
{
|
||||
if (pathNameIndex >= LOSCFG_LFS_MAX_MOUNT_SIZE) {
|
||||
return VFS_ERROR;
|
||||
}
|
||||
|
||||
pthread_mutex_lock(&g_FslocalMutex);
|
||||
g_littlefsMntName[pathNameIndex] = strdup(target);
|
||||
pthread_mutex_unlock(&g_FslocalMutex);
|
||||
return VFS_OK;
|
||||
}
|
||||
|
||||
struct FileOpInfo *GetMountRes(const char *target, int *mountIndex)
|
||||
{
|
||||
pthread_mutex_lock(&g_FslocalMutex);
|
||||
for (int i = 0; i < LOSCFG_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 >= LOSCFG_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 < LOSCFG_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;
|
||||
}
|
||||
|
||||
static int ConvertFlagToLfsOpenFlag (int oflags)
|
||||
{
|
||||
int lfsOpenFlag = 0;
|
||||
|
||||
if (oflags & O_CREAT) {
|
||||
lfsOpenFlag |= LFS_O_CREAT;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
static int LittlefsErrno(int result)
|
||||
{
|
||||
return (result < 0) ? -result : result;
|
||||
}
|
||||
|
||||
const struct MountOps g_lfsMnt = {
|
||||
.Mount = LfsMount,
|
||||
.Umount = LfsUmount,
|
||||
};
|
||||
|
||||
const struct FileOps g_lfsFops = {
|
||||
.Mkdir = LfsMkdir,
|
||||
.Unlink = LfsUnlink,
|
||||
.Rmdir = LfsRmdir,
|
||||
.Opendir = LfsOpendir,
|
||||
.Readdir = LfsReaddir,
|
||||
.Closedir = LfsClosedir,
|
||||
.Open = LfsOpen,
|
||||
.Close = LfsClose,
|
||||
.Write = LfsWrite,
|
||||
.Read = LfsRead,
|
||||
.Seek = LfsSeek,
|
||||
.Rename = LfsRename,
|
||||
.Getattr = LfsStat,
|
||||
.Fsync = LfsFsync,
|
||||
.Fstat = LfsFstat,
|
||||
};
|
||||
|
||||
int LfsMount(const char *source, const char *target, const char *fileSystemType, unsigned long mountflags,
|
||||
const void *data)
|
||||
{
|
||||
int ret;
|
||||
struct FileOpInfo *fileOpInfo = NULL;
|
||||
|
||||
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_ERROR;
|
||||
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);
|
||||
ret = VFS_ERROR;
|
||||
}
|
||||
|
||||
errout:
|
||||
return ret;
|
||||
}
|
||||
|
||||
int LfsUmount(const char *target)
|
||||
{
|
||||
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);
|
||||
ret = VFS_ERROR;
|
||||
}
|
||||
|
||||
(void)FreeMountResByIndex(mountIndex);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int LfsUnlink(const char *fileName)
|
||||
{
|
||||
int ret;
|
||||
struct FileOpInfo *fileOpInfo = NULL;
|
||||
|
||||
if (fileName == NULL) {
|
||||
errno = EFAULT;
|
||||
return VFS_ERROR;
|
||||
}
|
||||
|
||||
if (CheckPathIsMounted(fileName, &fileOpInfo) == FALSE || fileOpInfo == NULL) {
|
||||
errno = ENOENT;
|
||||
return VFS_ERROR;
|
||||
}
|
||||
|
||||
ret = lfs_remove(&(fileOpInfo->lfsInfo), fileName);
|
||||
if (ret != 0) {
|
||||
errno = LittlefsErrno(ret);
|
||||
ret = VFS_ERROR;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int LfsMkdir(const char *dirName, mode_t mode)
|
||||
{
|
||||
int ret;
|
||||
struct FileOpInfo *fileOpInfo = NULL;
|
||||
|
||||
if (dirName == NULL) {
|
||||
errno = EFAULT;
|
||||
return VFS_ERROR;
|
||||
}
|
||||
|
||||
if (CheckPathIsMounted(dirName, &fileOpInfo) == FALSE || fileOpInfo == NULL) {
|
||||
errno = ENOENT;
|
||||
return VFS_ERROR;
|
||||
}
|
||||
|
||||
ret = lfs_mkdir(&(fileOpInfo->lfsInfo), dirName);
|
||||
if (ret != 0) {
|
||||
errno = LittlefsErrno(ret);
|
||||
ret = VFS_ERROR;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int LfsRmdir(const char *dirName)
|
||||
{
|
||||
int ret;
|
||||
|
||||
struct FileOpInfo *fileOpInfo = NULL;
|
||||
|
||||
if (dirName == NULL) {
|
||||
errno = EFAULT;
|
||||
return VFS_ERROR;
|
||||
}
|
||||
|
||||
if (CheckPathIsMounted(dirName, &fileOpInfo) == FALSE || fileOpInfo == NULL) {
|
||||
errno = ENOENT;
|
||||
return VFS_ERROR;
|
||||
}
|
||||
|
||||
ret = lfs_remove(&(fileOpInfo->lfsInfo), dirName);
|
||||
if (ret != 0) {
|
||||
errno = LittlefsErrno(ret);
|
||||
ret = VFS_ERROR;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
DIR *LfsOpendir(const char *dirName)
|
||||
{
|
||||
int ret;
|
||||
struct FileOpInfo *fileOpInfo = NULL;
|
||||
|
||||
if (dirName == NULL) {
|
||||
errno = EFAULT;
|
||||
goto errout;
|
||||
}
|
||||
|
||||
if (CheckPathIsMounted(dirName, &fileOpInfo) == FALSE || fileOpInfo == NULL) {
|
||||
errno = ENOENT;
|
||||
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) {
|
||||
FreeDirInfo(dirName);
|
||||
errno = LittlefsErrno(ret);
|
||||
goto errout;
|
||||
}
|
||||
|
||||
dirInfo->lfsHandle = &(fileOpInfo->lfsInfo);
|
||||
|
||||
return (DIR *)dirInfo;
|
||||
|
||||
errout:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct dirent *LfsReaddir(DIR *dir)
|
||||
{
|
||||
int ret;
|
||||
struct lfs_info lfsInfo;
|
||||
|
||||
FileDirInfo *dirInfo = (FileDirInfo *)dir;
|
||||
|
||||
if (dirInfo == NULL || dirInfo->lfsHandle == NULL) {
|
||||
errno = EBADF;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ret = lfs_dir_read(dirInfo->lfsHandle, (lfs_dir_t *)(&(dirInfo->dir)), &lfsInfo);
|
||||
if (ret == TRUE) {
|
||||
pthread_mutex_lock(&g_FslocalMutex);
|
||||
(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) {
|
||||
g_nameValue.d_type = DT_REG;
|
||||
}
|
||||
|
||||
g_nameValue.d_reclen = lfsInfo.size;
|
||||
pthread_mutex_unlock(&g_FslocalMutex);
|
||||
|
||||
return &g_nameValue;
|
||||
}
|
||||
|
||||
if (ret != 0) {
|
||||
errno = LittlefsErrno(ret);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int LfsClosedir(DIR *dir)
|
||||
{
|
||||
int ret;
|
||||
FileDirInfo *dirInfo = (FileDirInfo *)dir;
|
||||
|
||||
if (dirInfo == NULL || dirInfo->lfsHandle == NULL) {
|
||||
errno = EBADF;
|
||||
return VFS_ERROR;
|
||||
}
|
||||
|
||||
ret = lfs_dir_close(dirInfo->lfsHandle, (lfs_dir_t *)(&(dirInfo->dir)));
|
||||
|
||||
FreeDirInfo(dirInfo->dirName);
|
||||
|
||||
if (ret != 0) {
|
||||
errno = LittlefsErrno(ret);
|
||||
ret = VFS_ERROR;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int LfsOpen(const char *pathName, int openFlag, ...)
|
||||
{
|
||||
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 = ENOENT;
|
||||
goto errout;
|
||||
}
|
||||
// if file is already open, return invalid fd
|
||||
if (CheckFileIsOpen(pathName)) {
|
||||
errno = EBUSY;
|
||||
goto errout;
|
||||
}
|
||||
|
||||
LittleFsHandleStruct *fsHandle = LfsAllocFd(pathName, &fd);
|
||||
if (fd == INVALID_FD) {
|
||||
errno = ENFILE;
|
||||
goto errout;
|
||||
}
|
||||
|
||||
int lfsOpenFlag = ConvertFlagToLfsOpenFlag(openFlag);
|
||||
err = lfs_file_open(&(fileOpInfo->lfsInfo), &(fsHandle->file), pathName, lfsOpenFlag);
|
||||
if (err != 0) {
|
||||
LfsFreeFd(fd);
|
||||
errno = LittlefsErrno(err);
|
||||
goto errout;
|
||||
}
|
||||
|
||||
g_handle[fd].lfsHandle = &(fileOpInfo->lfsInfo);
|
||||
return fd;
|
||||
|
||||
errout:
|
||||
return INVALID_FD;
|
||||
}
|
||||
|
||||
int LfsRead(int fd, void *buf, unsigned int len)
|
||||
{
|
||||
int ret;
|
||||
|
||||
if (buf == NULL) {
|
||||
errno = EFAULT;
|
||||
return VFS_ERROR;
|
||||
}
|
||||
|
||||
if (LfsFdIsValid(fd) == FALSE) {
|
||||
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);
|
||||
ret = VFS_ERROR;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int LfsWrite(int fd, const void *buf, unsigned int len)
|
||||
{
|
||||
int ret;
|
||||
|
||||
if (buf == NULL) {
|
||||
errno = EFAULT;
|
||||
return VFS_ERROR;
|
||||
}
|
||||
|
||||
if (LfsFdIsValid(fd) == FALSE) {
|
||||
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);
|
||||
ret = VFS_ERROR;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
off_t LfsSeek(int fd, off_t offset, int whence)
|
||||
{
|
||||
off_t ret;
|
||||
|
||||
if (LfsFdIsValid(fd) == FALSE) {
|
||||
errno = EBADF;
|
||||
return VFS_ERROR;
|
||||
}
|
||||
|
||||
ret = (off_t)lfs_file_seek(g_handle[fd].lfsHandle, &(g_handle[fd].file), offset, whence);
|
||||
if (ret < 0) {
|
||||
errno = LittlefsErrno(ret);
|
||||
ret = VFS_ERROR;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int LfsClose(int fd)
|
||||
{
|
||||
int ret;
|
||||
|
||||
if (LfsFdIsValid(fd) == FALSE) {
|
||||
errno = EBADF;
|
||||
return VFS_ERROR;
|
||||
}
|
||||
|
||||
pthread_mutex_lock(&g_FslocalMutex);
|
||||
ret = lfs_file_close(g_handle[fd].lfsHandle, &(g_handle[fd].file));
|
||||
pthread_mutex_unlock(&g_FslocalMutex);
|
||||
|
||||
LfsFreeFd(fd);
|
||||
|
||||
if (ret != 0) {
|
||||
errno = LittlefsErrno(ret);
|
||||
ret = VFS_ERROR;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int LfsRename(const char *oldName, const char *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 = ENOENT;
|
||||
return VFS_ERROR;
|
||||
}
|
||||
|
||||
ret = lfs_rename(&(fileOpInfo->lfsInfo), oldName, newName);
|
||||
if (ret != 0) {
|
||||
errno = LittlefsErrno(ret);
|
||||
ret = VFS_ERROR;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int LfsStat(const char *path, struct stat *buf)
|
||||
{
|
||||
int ret;
|
||||
struct lfs_info info;
|
||||
struct FileOpInfo *fileOpInfo = NULL;
|
||||
|
||||
if (path == NULL || buf == NULL) {
|
||||
errno = EFAULT;
|
||||
return VFS_ERROR;
|
||||
}
|
||||
|
||||
if (CheckPathIsMounted(path, &fileOpInfo) == FALSE || fileOpInfo == NULL) {
|
||||
errno = ENOENT;
|
||||
return VFS_ERROR;
|
||||
}
|
||||
|
||||
ret = lfs_stat(&(fileOpInfo->lfsInfo), path, &info);
|
||||
if (ret == 0) {
|
||||
buf->st_size = info.size;
|
||||
if (info.type == LFS_TYPE_REG) {
|
||||
buf->st_mode = S_IFREG;
|
||||
} else {
|
||||
buf->st_mode = S_IFDIR;
|
||||
}
|
||||
} else {
|
||||
errno = LittlefsErrno(ret);
|
||||
ret = VFS_ERROR;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int LfsFsync(int fd)
|
||||
{
|
||||
int ret;
|
||||
|
||||
if (LfsFdIsValid(fd) == FALSE) {
|
||||
errno = EBADF;
|
||||
return VFS_ERROR;
|
||||
}
|
||||
|
||||
ret = lfs_file_sync(g_handle[fd].lfsHandle, &(g_handle[fd].file));
|
||||
if (ret != 0) {
|
||||
errno = LittlefsErrno(ret);
|
||||
ret = VFS_ERROR;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int LfsFstat(int fd, struct stat *buf)
|
||||
{
|
||||
int ret;
|
||||
struct lfs_info info;
|
||||
|
||||
if (buf == NULL) {
|
||||
errno = EFAULT;
|
||||
return FS_FAILURE;
|
||||
}
|
||||
|
||||
if (LfsFdIsValid(fd) == FALSE) {
|
||||
errno = EBADF;
|
||||
return VFS_ERROR;
|
||||
}
|
||||
|
||||
ret = lfs_stat(g_handle[fd].lfsHandle, g_handle[fd].pathName, &info);
|
||||
if (ret == 0) {
|
||||
buf->st_size = info.size;
|
||||
if (info.type == LFS_TYPE_REG) {
|
||||
buf->st_mode = S_IFREG;
|
||||
} else {
|
||||
buf->st_mode = S_IFDIR;
|
||||
}
|
||||
} else {
|
||||
errno = LittlefsErrno(ret);
|
||||
ret = VFS_ERROR;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
# Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
# Copyright (c) 2022-2022 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:
|
||||
@@ -32,7 +31,26 @@ import("//kernel/liteos_m/liteos.gni")
|
||||
module_switch = defined(LOSCFG_FS_VFS)
|
||||
module_name = get_path_info(rebase_path("."), "name")
|
||||
kernel_module(module_name) {
|
||||
sources = [ "los_fs.c" ]
|
||||
sources = [
|
||||
"vfs_files.c",
|
||||
"vfs_fs.c",
|
||||
"vfs_init.c",
|
||||
"vfs_maps.c",
|
||||
"vfs_mount.c",
|
||||
"vfs_partition.c",
|
||||
]
|
||||
|
||||
include_dirs = [
|
||||
"//kernel/liteos_m/kernel/arch/include",
|
||||
"//kernel/liteos_m/kernel/include",
|
||||
"//kernel/liteos_m/utils",
|
||||
"../",
|
||||
".",
|
||||
]
|
||||
|
||||
deps = [ "//kernel/liteos_m/kal" ]
|
||||
configs += [ "$LITEOSTOPDIR:warn_config" ]
|
||||
cflags = [ "-Wno-parentheses" ]
|
||||
}
|
||||
|
||||
config("public") {
|
||||
|
||||
@@ -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) 2020-2022 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:
|
||||
@@ -30,5 +30,6 @@
|
||||
config FS_VFS
|
||||
bool "Enable FS VFS"
|
||||
default y
|
||||
|
||||
help
|
||||
Answer Y to enable LiteOS support VFS.
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user