Compare commits

..

32 Commits

Author SHA1 Message Date
openharmony_ci
76366bc358 !600 fix: posix线程和LOS_TaskCreate任务不兼容,补齐接口防护,防止访问野指针
Merge pull request !600 from zhushengle/cherry-pick-1645010283
2022-02-16 12:20:42 +00:00
zhushengle
11e7f0f5e2 fixed 60805e1 from https://gitee.com/zhushengle/kernel_liteos_m/pulls/599
fix: posix线程和LOS_TaskCreate任务不兼容,补齐接口防护,防止访问野指针

Signed-off-by: zhushengle <zhushengle@huawei.com>
Change-Id: I03040e86a5ac618d3ede671c497a0ae88a3717ae
2022-02-16 11:18:03 +00:00
openharmony_ci
35971d660e !591 littlefs最大打开文件个数修改为可通过menuconfig配置
Merge pull request !591 from 方烨/master
2022-02-15 06:55:09 +00:00
openharmony_ci
289ad2c57d !591 littlefs最大打开文件个数修改为可通过menuconfig配置
Merge pull request !591 from 方烨/master
2022-02-15 06:55:09 +00:00
openharmony_ci
e20444cda6 !591 littlefs最大打开文件个数修改为可通过menuconfig配置
Merge pull request !591 from 方烨/master
2022-02-15 06:55:08 +00:00
openharmony_ci
b9830c61f5 !592 【liteos_m】kernel接口融合修改
Merge pull request !592 from LiteOS/master
2022-02-15 06:30:43 +00:00
LiteOS2021
cee9714a90 fix: kernel接口融合,添加/修改kernel函数
kernel接口融合,添加/修改kernel函数

BREAKING CHANGE:
新增接口:
LOS_TaskResRecycle
LOS_CurrNanosec
LOS_MDelay
接口修改:
LOS_QueueCreate:第一个入参添加const修饰并增加一种异常情况处理
los_memory.c中 OS_ERROR 修改为LOS_NOK,重定义LOS_NOK为(UINT32)-1。
接口位置转移:
LOS_UDelay 由los_task.h/.c 转移到los_tick.h/.c 
宏修改:
LOS_ERRNO_MUX_PEND_INTERR 改名为 LOS_ERRNO_MUX_IN_INTERR
增加宏:

Signed-off-by: LiteOS2021 <dinglu@huawei.com>
2022-02-15 09:47:58 +08:00
openharmony_ci
ffd228cd8d !595 fix: los_interrupt.c存在未使用的参数编译出错
Merge pull request !595 from kenneth/compile_error
2022-02-14 13:16:38 +00:00
kenneth
5af4c2e213 fix: los_interrupt.c存在未使用的参数编译出错
修复los_interrupt.c存在未使用的参数编译出错

close #I4SJPZ

Signed-off-by: kenneth <zhushangyuan@huawei.com>
2022-02-14 20:14:40 +08:00
openharmony_ci
b423d9f7bb !589 feat: 同步调度部分优化至liteos_m
Merge pull request !589 from zhushengle/sched_timer
2022-02-13 04:17:46 +00:00
zhushengle
fb11ab181e feat: 同步调度部分优化至liteos_m
1.tick timer与调度进一步剥离
2.性能敏感函数内敛化

Signed-off-by: zhushengle <zhushengle@huawei.com>
Change-Id: I00c27216e286dd7ca9c02db3e2377707d628a786
2022-02-12 14:52:36 +08:00
openharmony_ci
c811efbf37 !590 feat: cortex-m55支持psplimit
Merge pull request !590 from Harylee/m55
2022-02-11 07:26:26 +00:00
fangye
9bc9f3aa53 feat: littlefs最大打开文件个数修改为可通过menuconfig配置
Signed-off-by: fangye <fangye@talkweb.com.cn>
Change-Id: Iba141821200b6044d89ec50b7ddb1047490f5229
2022-02-11 14:52:42 +08:00
Haryslee
db7d641c22 feat: cortex-m55支持psplimit
cortex-m55增加栈溢出检测特性

close #I4T7R3

Signed-off-by: Haryslee <lihao189@huawei.com>
Change-Id: Ie24adbb672c47404b56aa5bfc9f22e0f7f947540
2022-02-11 11:35:38 +08:00
openharmony_ci
a68323683d !587 fix: cortex-m55栈优化
Merge pull request !587 from Harylee/m55
2022-02-10 13:37:30 +00:00
Haryslee
59e9c6ed73 fix: cortex-m55栈优化
利用EXC_RETURN可判断出上下文是否使用FPU寄存器,进而确定是否对FPU寄存器进行压栈操作

close #I4SQIQ

Signed-off-by: Haryslee <lihao189@huawei.com>
Change-Id: Ib8b3a8b359486b3b7851278365860be1bfed65f2
2022-02-10 21:17:27 +08:00
openharmony_ci
d1d412255c !570 fix:shell 命令 ctrl +c 打印使用多余的参数
Merge pull request !570 from 拓维信息候鹏飞/master
2022-02-10 12:16:07 +00:00
openharmony_ci
b534083056 !569 shell命令行输入增加回退支持
Merge pull request !569 from 方烨/master
2022-02-10 11:56:34 +00:00
openharmony_ci
968c00f049 !588 【liteos_m】posix接口融合,接口规范兼容性修改
Merge pull request !588 from LiteOS/master
2022-02-10 11:43:16 +00:00
openharmony_ci
df0ed8d219 !588 【liteos_m】posix接口融合,接口规范兼容性修改
Merge pull request !588 from LiteOS/master
2022-02-10 11:43:15 +00:00
LiteOS2021
4b607fd074 fix(posix接口融合): posix接口融合,接口规范兼容性修改
posix接口融合,接口规范兼容性修改

BREAKING CHANGE:
接口修改:
calloc
pthread_mutex_init
mq_unlink
pthread_join
pthread_exit
pthread_attr_init
pthread_attr_destroy
pthread_condattr_destroy
pthread_cond_timedwait
pthread_mutexattr_init
pthread_mutexattr_settype
pthread_mutex_destroy
pthread_mutex_timedlock
pthread_mutex_trylockk
pthread_mutex_unlock
sem_getvalue
sem_timedwait
pthread_cond_timedwait
nanosleep
timer_create
timer_settime
timer_gettime
testStdlibStrtoull005
testStdlibStrtol011
testStdlibStrtoul007
testPthread004

新增接口:
CheckForCancel
pthread_setcancelstate
pthread_setcanceltype
pthread_once
pthread_setschedprio
pthread_attr_setstack
pthread_attr_getstack
pthread_condattr_getpshared
pthread_condattr_setpshared
pthread_condattr_getclock
pthread_mutexattr_gettype
CheckMutexAttr
OsMuxPreCheck
sem_trywait
MuxPendForPosix
MuxPostForPosix
增加overrun功能

接口变化:
mq_getsetattr 改为内部接口MqGetSetAttr
GetTickTimeFromNow->OsGetTickTimeFromNow

接口位置转移:
pthread_equal接口由newlib下转移到kal/posix/src/pthread.c中

Signed-off-by: LiteOS2021 <dinglu@huawei.com>
2022-02-10 16:41:12 +08:00
openharmony_ci
1013f24209 !583 posix兼容回退
Merge pull request !583 from LiteOS/master
2022-01-30 23:49:31 +00:00
LiteOS2021
207efc15b8 fix(posix): posix兼容回退
posix兼容回退

Signed-off-by: LiteOS2021 <dinglu@huawei.com>
2022-01-30 23:09:20 +08:00
openharmony_ci
f2e55bd6a3 !576 支持cortex-m55
Merge pull request !576 from Harylee/m55
2022-01-30 13:21:28 +00:00
openharmony_ci
607152c434 !566 【liteos_m】posix接口融合,接口规范兼容性修改
Merge pull request !566 from LiteOS/master
2022-01-30 02:27:56 +00:00
LiteOS
39558ae1a3 Merge branch 'master' of gitee.com:openharmony/kernel_liteos_m into master
Signed-off-by: LiteOS2021 <dinglu@huawei.com>
2022-01-29 19:30:28 +08:00
openharmony_ci
eae638be6c !575 【liteos_m】posix单元测试融合
Merge pull request !575 from LiteOS/master
2022-01-29 11:11:00 +00:00
LiteOS2021
e0b12758da fix(posix): posix接口融合,接口规范兼容性修改
posix接口融合,接口规范兼容性修改

BREAKING CHANGE:
接口修改:
calloc
pthread_mutex_init
mq_unlink
pthread_join
pthread_exit
pthread_attr_init
pthread_attr_destroy
pthread_condattr_destroy
pthread_cond_timedwait
pthread_mutexattr_init
pthread_mutexattr_settype
pthread_mutex_destroy
pthread_mutex_timedlock
pthread_mutex_trylockk
pthread_mutex_unlock
sem_getvalue

新增接口:
CheckForCancel
pthread_setcancelstate
pthread_setcanceltype
pthread_once
pthread_setschedprio
pthread_attr_setstack
pthread_attr_getstack
pthread_condattr_getpshared
pthread_condattr_setpshared
pthread_condattr_getclock
pthread_mutexattr_gettype
CheckMutexAttr
OsMuxPreCheck
sem_trywait

接口变化:
mq_getsetattr 改为内部接口OsMqGetSetAttr

接口位置转移:
pthread_equal接口由newlib下转移到kal/posix/src/pthread.c中

Signed-off-by: LiteOS2021 <dinglu@huawei.com>
2022-01-29 16:57:49 +08:00
Haryslee
6e1780546c feat: 支持cortex-m55
基于qemu支持cortex-m55处理器,包括MVE功能使能。

close #I4Q9OQ

Signed-off-by: Haryslee <lihao189@huawei.com>
Change-Id: I571702ac8e8f52769afdf600b48451f1f1806a88
2022-01-28 15:40:37 +08:00
LiteOS2021
ad6f249d1e fix(posix unittest): posix unittest 融合
posix unittest 融合

Signed-off-by: LiteOS2021 <dinglu@huawei.com>
2022-01-26 14:50:44 +08:00
houpengfei
8b586fb2bf 删除不必要的参数
Signed-off-by: houpengfei <houpengfei@talkweb.com.cn>
2022-01-24 09:07:36 +08:00
fangye
d986648e9c shell命令行增加回退支持
Signed-off-by: fangye <fangye@talkweb.com.cn>
2022-01-23 21:11:43 +08:00
120 changed files with 5468 additions and 450 deletions

14
Kconfig
View File

@@ -91,19 +91,20 @@ menu "Platform"
######################### config options of bsp #####################
config PLATFORM
string
default "virt" if PLATFORM_QEMU_ARM_VIRT_CM7 || PLATFORM_QEMU_ARM_VIRT_CM4 || PRODUCT_QEMU_RISCV32_VIRT || PLATFORM_QEMU_CSKY_SMARTL || PLATFORM_QEMU_XTENSA_ESP32
default "virt" if PLATFORM_QEMU_ARM_VIRT_CM7 || PLATFORM_QEMU_ARM_VIRT_CM4 || PLATFORM_QEMU_ARM_VIRT_CM55 || PRODUCT_QEMU_RISCV32_VIRT || PLATFORM_QEMU_CSKY_SMARTL || PLATFORM_QEMU_XTENSA_ESP32
config PRODUCT_NAME
string
default "arm_virt" if PRODUCT_QEMU_ARM
default "arm_mps2_an386" if PRODUCT_QEMU_ARM_MPS2_AN386
default "arm_mps3_an547" if PRODUCT_QEMU_ARM_MPS3_AN547
default "riscv32_virt" if PRODUCT_QEMU_RISCV32_VIRT
default "csky_smartl_e802" if PRODUCT_QEMU_CSKY_SMARTL_E802
default "xtensa_esp32" if PRODUCT_QEMU_XTENSA_ESP32
config DEVICE_COMPANY
string
default "qemu" if PLATFORM_QEMU_ARM_VIRT_CM7 || PLATFORM_QEMU_ARM_VIRT_CM4 || PRODUCT_QEMU_RISCV32_VIRT || PLATFORM_QEMU_CSKY_SMARTL || PLATFORM_QEMU_XTENSA_ESP32
default "qemu" if PLATFORM_QEMU_ARM_VIRT_CM7 || PLATFORM_QEMU_ARM_VIRT_CM4 || PLATFORM_QEMU_ARM_VIRT_CM55 || PRODUCT_QEMU_RISCV32_VIRT || PLATFORM_QEMU_CSKY_SMARTL || PLATFORM_QEMU_XTENSA_ESP32
choice
prompt "Chip"
@@ -128,6 +129,12 @@ config PLATFORM_QEMU_ARM_VIRT_CM4
help
QEMU ARM Virtual Platform using Cortex-M4 CPU.
config PLATFORM_QEMU_ARM_VIRT_CM55
bool "qemu_arm_virt_cm55"
select ARCH_CORTEX_M55
help
QEMU ARM Virtual Platform using Cortex-M55 CPU.
config PLATFORM_QEMU_RISCV32_VIRT
bool "qemu_riscv32_virt"
select ARCH_RISCV32
@@ -159,6 +166,9 @@ config PRODUCT_QEMU_ARM
config PRODUCT_QEMU_ARM_MPS2_AN386
bool "arm_mps2_an386" if PLATFORM_QEMU_ARM_VIRT_CM4
config PRODUCT_QEMU_ARM_MPS3_AN547
bool "arm_mps3_an547" if PLATFORM_QEMU_ARM_VIRT_CM55
config PRODUCT_QEMU_RISCV32_VIRT
bool "riscv32_virt" if PLATFORM_QEMU_RISCV32_VIRT

View File

@@ -37,7 +37,7 @@ module_group("arch") {
modules = []
if ("$board_cpu" == "arm9" || "$board_cpu" == "cortex-m3" ||
"$board_cpu" == "cortex-m4" || "$board_cpu" == "cortex-m7" ||
"$board_cpu" == "cortex-m33") {
"$board_cpu" == "cortex-m33" || "$board_cpu" == "cortex-m55") {
modules += [ "arm" ]
} else if ("$board_cpu" == "ck802" || "$board_cpu" == "e802") {
modules += [ "csky" ]

View File

@@ -94,6 +94,14 @@ config ARCH_CORTEX_M33
select ARCH_FPU_VFP_D32
select ARCH_FPU_VFP_NEON
config ARCH_CORTEX_M55
bool
select ARCH_ARM_V7M
select ARCH_ARM_AARCH32
select ARCH_FPU_VFP_V4
select ARCH_FPU_VFP_D32
select ARCH_FPU_VFP_NEON
config ARCH_ARM9
bool
select ARCH_ARM_V5TE
@@ -105,4 +113,5 @@ config ARCH_CPU
default "cortex-m4" if ARCH_CORTEX_M4
default "cortex-m7" if ARCH_CORTEX_M7
default "cortex-m33" if ARCH_CORTEX_M33
default "cortex-m55" if ARCH_CORTEX_M55
default "arm9" if ARCH_ARM9

View File

@@ -173,11 +173,13 @@ LITE_OS_SEC_TEXT_MINOR VOID HalHwiDefaultHandler(VOID)
WEAK VOID HalPreInterruptHandler(UINT32 arg)
{
(VOID)arg;
return;
}
WEAK VOID HalAftInterruptHandler(UINT32 arg)
{
(VOID)arg;
return;
}
@@ -243,6 +245,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 ArchHwiCreate(HWI_HANDLE_T hwiNum,
HWI_PROC_FUNC handler,
HWI_ARG_T arg)
{
(VOID)mode;
UINT32 intSave;
if (handler == NULL) {
@@ -261,6 +264,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 ArchHwiCreate(HWI_HANDLE_T hwiNum,
#if (LOSCFG_PLATFORM_HWI_WITH_ARG == 1)
OsSetVector(hwiNum, handler, arg);
#else
(VOID)arg;
OsSetVector(hwiNum, handler);
#endif
HwiUnmask(hwiNum);

View File

@@ -52,7 +52,7 @@
#define OS_TIMER_READ_VAL_ADDR (OS_TIMER_REG_BASE + 20)
STATIC UINT32 SysTickStart(HWI_PROC_FUNC handler);
STATIC VOID SysTickReload(UINT64 nextResponseTime);
STATIC UINT64 SysTickReload(UINT64 nextResponseTime);
STATIC UINT64 SysTickCycleGet(UINT32 *period);
STATIC VOID SysTickLock(VOID);
STATIC VOID SysTickUnlock(VOID);
@@ -60,6 +60,7 @@ STATIC VOID SysTickUnlock(VOID);
STATIC ArchTickTimer g_archTickTimer = {
.freq = 0,
.irqNum = OS_TIMER_IRQ_NUM,
.periodMax = LOSCFG_BASE_CORE_TICK_RESPONSE_MAX,
.init = SysTickStart,
.getCycle = SysTickCycleGet,
.reload = SysTickReload,
@@ -107,12 +108,17 @@ STATIC VOID SysTickClockIrqClear(VOID)
} while (status & mask);
}
STATIC VOID SysTickReload(UINT64 nextResponseTime)
STATIC UINT64 SysTickReload(UINT64 nextResponseTime)
{
if (nextResponseTime > g_archTickTimer.periodMax) {
nextResponseTime = g_archTickTimer.periodMax;
}
SysTickLock();
WRITE_UINT32(nextResponseTime, OS_TIMER_PERIOD_REG_ADDR);
WRITE_UINT32((UINT32)nextResponseTime, OS_TIMER_PERIOD_REG_ADDR);
SysTickClockIrqClear();
SysTickUnlock();
return nextResponseTime;
}
STATIC UINT64 SysTickCycleGet(UINT32 *period)

View File

@@ -208,11 +208,13 @@ LITE_OS_SEC_TEXT_MINOR VOID HalHwiDefaultHandler(VOID)
WEAK VOID HalPreInterruptHandler(UINT32 arg)
{
(VOID)arg;
return;
}
WEAK VOID HalAftInterruptHandler(UINT32 arg)
{
(VOID)arg;
return;
}
@@ -278,6 +280,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 ArchHwiCreate(HWI_HANDLE_T hwiNum,
HWI_PROC_FUNC handler,
HWI_ARG_T arg)
{
(VOID)mode;
UINT32 intSave;
if (handler == NULL) {
@@ -300,6 +303,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 ArchHwiCreate(HWI_HANDLE_T hwiNum,
#if (LOSCFG_PLATFORM_HWI_WITH_ARG == 1)
OsSetVector(hwiNum, handler, arg);
#else
(VOID)arg;
OsSetVector(hwiNum, handler);
#endif
HwiUnmask((IRQn_Type)hwiNum);

View File

@@ -37,7 +37,7 @@
#include "los_debug.h"
STATIC UINT32 SysTickStart(HWI_PROC_FUNC handler);
STATIC VOID SysTickReload(UINT64 nextResponseTime);
STATIC UINT64 SysTickReload(UINT64 nextResponseTime);
STATIC UINT64 SysTickCycleGet(UINT32 *period);
STATIC VOID SysTickLock(VOID);
STATIC VOID SysTickUnlock(VOID);
@@ -45,6 +45,7 @@ STATIC VOID SysTickUnlock(VOID);
STATIC ArchTickTimer g_archTickTimer = {
.freq = 0,
.irqNum = SysTick_IRQn,
.periodMax = LOSCFG_BASE_CORE_TICK_RESPONSE_MAX,
.init = SysTickStart,
.getCycle = SysTickCycleGet,
.reload = SysTickReload,
@@ -76,13 +77,19 @@ STATIC UINT32 SysTickStart(HWI_PROC_FUNC handler)
return LOS_OK;
}
STATIC VOID SysTickReload(UINT64 nextResponseTime)
STATIC UINT64 SysTickReload(UINT64 nextResponseTime)
{
if (nextResponseTime > g_archTickTimer.periodMax) {
nextResponseTime = g_archTickTimer.periodMax;
}
SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk;
SysTick->LOAD = (UINT32)(nextResponseTime - 1UL); /* set reload register */
SysTick->VAL = 0UL; /* Load the SysTick Counter Value */
NVIC_ClearPendingIRQ(SysTick_IRQn);
SysTick->CTRL |= SysTick_CTRL_ENABLE_Msk;
return nextResponseTime;
}
STATIC UINT64 SysTickCycleGet(UINT32 *period)

View File

@@ -199,11 +199,13 @@ LITE_OS_SEC_TEXT_MINOR VOID HalHwiDefaultHandler(VOID)
WEAK VOID HalPreInterruptHandler(UINT32 arg)
{
(VOID)arg;
return;
}
WEAK VOID HalAftInterruptHandler(UINT32 arg)
{
(VOID)arg;
return;
}
@@ -269,6 +271,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 ArchHwiCreate(HWI_HANDLE_T hwiNum,
HWI_PROC_FUNC handler,
HWI_ARG_T arg)
{
(VOID)mode;
UINT32 intSave;
if (handler == NULL) {
@@ -291,6 +294,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 ArchHwiCreate(HWI_HANDLE_T hwiNum,
#if (LOSCFG_PLATFORM_HWI_WITH_ARG == 1)
OsSetVector(hwiNum, handler, arg);
#else
(VOID)arg;
OsSetVector(hwiNum, handler);
#endif
HwiUnmask((IRQn_Type)hwiNum);

View File

@@ -36,7 +36,7 @@
#include "los_debug.h"
STATIC UINT32 SysTickStart(HWI_PROC_FUNC handler);
STATIC VOID SysTickReload(UINT64 nextResponseTime);
STATIC UINT64 SysTickReload(UINT64 nextResponseTime);
STATIC UINT64 SysTickCycleGet(UINT32 *period);
STATIC VOID SysTickLock(VOID);
STATIC VOID SysTickUnlock(VOID);
@@ -44,6 +44,7 @@ STATIC VOID SysTickUnlock(VOID);
STATIC ArchTickTimer g_archTickTimer = {
.freq = 0,
.irqNum = SysTick_IRQn,
.periodMax = LOSCFG_BASE_CORE_TICK_RESPONSE_MAX,
.init = SysTickStart,
.getCycle = SysTickCycleGet,
.reload = SysTickReload,
@@ -75,13 +76,18 @@ STATIC UINT32 SysTickStart(HWI_PROC_FUNC handler)
return LOS_OK;
}
STATIC VOID SysTickReload(UINT64 nextResponseTime)
STATIC UINT64 SysTickReload(UINT64 nextResponseTime)
{
if (nextResponseTime > g_archTickTimer.periodMax) {
nextResponseTime = g_archTickTimer.periodMax;
}
SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk;
SysTick->LOAD = (UINT32)(nextResponseTime - 1UL); /* set reload register */
SysTick->VAL = 0UL; /* Load the SysTick Counter Value */
NVIC_ClearPendingIRQ(SysTick_IRQn);
SysTick->CTRL |= SysTick_CTRL_ENABLE_Msk;
return nextResponseTime;
}
STATIC UINT64 SysTickCycleGet(UINT32 *period)

View File

@@ -199,11 +199,13 @@ LITE_OS_SEC_TEXT_MINOR VOID HalHwiDefaultHandler(VOID)
WEAK VOID HalPreInterruptHandler(UINT32 arg)
{
(VOID)arg;
return;
}
WEAK VOID HalAftInterruptHandler(UINT32 arg)
{
(VOID)arg;
return;
}
@@ -269,6 +271,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 ArchHwiCreate(HWI_HANDLE_T hwiNum,
HWI_PROC_FUNC handler,
HWI_ARG_T arg)
{
(VOID)mode;
UINT32 intSave;
if (handler == NULL) {
@@ -291,6 +294,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 ArchHwiCreate(HWI_HANDLE_T hwiNum,
#if (LOSCFG_PLATFORM_HWI_WITH_ARG == 1)
OsSetVector(hwiNum, handler, arg);
#else
(VOID)arg;
OsSetVector(hwiNum, handler);
#endif
HwiUnmask((IRQn_Type)hwiNum);

View File

@@ -35,7 +35,7 @@
#include "los_arch_interrupt.h"
STATIC UINT32 SysTickStart(HWI_PROC_FUNC handler);
STATIC VOID SysTickReload(UINT64 nextResponseTime);
STATIC UINT64 SysTickReload(UINT64 nextResponseTime);
STATIC UINT64 SysTickCycleGet(UINT32 *period);
STATIC VOID SysTickLock(VOID);
STATIC VOID SysTickUnlock(VOID);
@@ -43,6 +43,7 @@ STATIC VOID SysTickUnlock(VOID);
STATIC ArchTickTimer g_archTickTimer = {
.freq = 0,
.irqNum = SysTick_IRQn,
.periodMax = LOSCFG_BASE_CORE_TICK_RESPONSE_MAX,
.init = SysTickStart,
.getCycle = SysTickCycleGet,
.reload = SysTickReload,
@@ -74,13 +75,18 @@ STATIC UINT32 SysTickStart(HWI_PROC_FUNC handler)
return LOS_OK;
}
STATIC VOID SysTickReload(UINT64 nextResponseTime)
STATIC UINT64 SysTickReload(UINT64 nextResponseTime)
{
if (nextResponseTime > g_archTickTimer.periodMax) {
nextResponseTime = g_archTickTimer.periodMax;
}
SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk;
SysTick->LOAD = (UINT32)(nextResponseTime - 1UL); /* set reload register */
SysTick->VAL = 0UL; /* Load the SysTick Counter Value */
NVIC_ClearPendingIRQ(SysTick_IRQn);
SysTick->CTRL |= SysTick_CTRL_ENABLE_Msk;
return nextResponseTime;
}
STATIC UINT64 SysTickCycleGet(UINT32 *period)

View File

@@ -205,11 +205,13 @@ LITE_OS_SEC_TEXT_MINOR VOID HalHwiDefaultHandler(VOID)
WEAK VOID HalPreInterruptHandler(UINT32 arg)
{
(VOID)arg;
return;
}
WEAK VOID HalAftInterruptHandler(UINT32 arg)
{
(VOID)arg;
return;
}
@@ -277,6 +279,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 ArchHwiCreate(HWI_HANDLE_T hwiNum,
HWI_PROC_FUNC handler,
HWI_ARG_T arg)
{
(VOID)mode;
UINTPTR intSave;
if (handler == NULL) {
@@ -299,6 +302,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 ArchHwiCreate(HWI_HANDLE_T hwiNum,
#if (LOSCFG_PLATFORM_HWI_WITH_ARG == 1)
OsSetVector(hwiNum, handler, arg);
#else
(VOID)arg;
OsSetVector(hwiNum, handler);
#endif
HwiUnmask((IRQn_Type)hwiNum);

View File

@@ -36,7 +36,7 @@
#include "los_debug.h"
STATIC UINT32 SysTickStart(HWI_PROC_FUNC handler);
STATIC VOID SysTickReload(UINT64 nextResponseTime);
STATIC UINT64 SysTickReload(UINT64 nextResponseTime);
STATIC UINT64 SysTickCycleGet(UINT32 *period);
STATIC VOID SysTickLock(VOID);
STATIC VOID SysTickUnlock(VOID);
@@ -44,6 +44,7 @@ STATIC VOID SysTickUnlock(VOID);
STATIC ArchTickTimer g_archTickTimer = {
.freq = 0,
.irqNum = SysTick_IRQn,
.periodMax = LOSCFG_BASE_CORE_TICK_RESPONSE_MAX,
.init = SysTickStart,
.getCycle = SysTickCycleGet,
.reload = SysTickReload,
@@ -75,13 +76,17 @@ STATIC UINT32 SysTickStart(HWI_PROC_FUNC handler)
return LOS_OK;
}
STATIC VOID SysTickReload(UINT64 nextResponseTime)
STATIC UINT64 SysTickReload(UINT64 nextResponseTime)
{
if (nextResponseTime > g_archTickTimer.periodMax) {
nextResponseTime = g_archTickTimer.periodMax;
}
SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk;
SysTick->LOAD = (UINT32)(nextResponseTime - 1UL); /* set reload register */
SysTick->VAL = 0UL; /* Load the SysTick Counter Value */
NVIC_ClearPendingIRQ(SysTick_IRQn);
SysTick->CTRL |= SysTick_CTRL_ENABLE_Msk;
return nextResponseTime;
}
STATIC UINT64 SysTickCycleGet(UINT32 *period)

View File

@@ -205,11 +205,13 @@ LITE_OS_SEC_TEXT_MINOR VOID HalHwiDefaultHandler(VOID)
WEAK VOID HalPreInterruptHandler(UINT32 arg)
{
(VOID)arg;
return;
}
WEAK VOID HalAftInterruptHandler(UINT32 arg)
{
(VOID)arg;
return;
}
@@ -277,6 +279,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 ArchHwiCreate(HWI_HANDLE_T hwiNum,
HWI_PROC_FUNC handler,
HWI_ARG_T arg)
{
(VOID)mode;
UINTPTR intSave;
if (handler == NULL) {
@@ -299,6 +302,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 ArchHwiCreate(HWI_HANDLE_T hwiNum,
#if (LOSCFG_PLATFORM_HWI_WITH_ARG == 1)
OsSetVector(hwiNum, handler, arg);
#else
(VOID)arg;
OsSetVector(hwiNum, handler);
#endif
HwiUnmask((IRQn_Type)hwiNum);

View File

@@ -36,7 +36,7 @@
#include "los_debug.h"
STATIC UINT32 SysTickStart(HWI_PROC_FUNC handler);
STATIC VOID SysTickReload(UINT64 nextResponseTime);
STATIC UINT64 SysTickReload(UINT64 nextResponseTime);
STATIC UINT64 SysTickCycleGet(UINT32 *period);
STATIC VOID SysTickLock(VOID);
STATIC VOID SysTickUnlock(VOID);
@@ -44,6 +44,7 @@ STATIC VOID SysTickUnlock(VOID);
STATIC ArchTickTimer g_archTickTimer = {
.freq = 0,
.irqNum = SysTick_IRQn,
.periodMax = LOSCFG_BASE_CORE_TICK_RESPONSE_MAX,
.init = SysTickStart,
.getCycle = SysTickCycleGet,
.reload = SysTickReload,
@@ -75,13 +76,18 @@ STATIC UINT32 SysTickStart(HWI_PROC_FUNC handler)
return LOS_OK;
}
STATIC VOID SysTickReload(UINT64 nextResponseTime)
STATIC UINT64 SysTickReload(UINT64 nextResponseTime)
{
if (nextResponseTime > g_archTickTimer.periodMax) {
nextResponseTime = g_archTickTimer.periodMax;
}
SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk;
SysTick->LOAD = (UINT32)(nextResponseTime - 1UL); /* set reload register */
SysTick->VAL = 0UL; /* Load the SysTick Counter Value */
NVIC_ClearPendingIRQ(SysTick_IRQn);
SysTick->CTRL |= SysTick_CTRL_ENABLE_Msk;
return nextResponseTime;
}
STATIC UINT64 SysTickCycleGet(UINT32 *period)

View File

@@ -203,11 +203,13 @@ LITE_OS_SEC_TEXT_MINOR VOID HalHwiDefaultHandler(VOID)
WEAK VOID HalPreInterruptHandler(UINT32 arg)
{
(VOID)arg;
return;
}
WEAK VOID HalAftInterruptHandler(UINT32 arg)
{
(VOID)arg;
return;
}
@@ -273,6 +275,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 ArchHwiCreate(HWI_HANDLE_T hwiNum,
HWI_PROC_FUNC handler,
HWI_ARG_T arg)
{
(VOID)mode;
UINT32 intSave;
if (handler == NULL) {
@@ -295,6 +298,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 ArchHwiCreate(HWI_HANDLE_T hwiNum,
#if (LOSCFG_PLATFORM_HWI_WITH_ARG == 1)
OsSetVector(hwiNum, handler, arg);
#else
(VOID)arg;
OsSetVector(hwiNum, handler);
#endif
HwiUnmask((IRQn_Type)hwiNum);

View File

@@ -36,7 +36,7 @@
#include "los_debug.h"
STATIC UINT32 SysTickStart(HWI_PROC_FUNC handler);
STATIC VOID SysTickReload(UINT64 nextResponseTime);
STATIC UINT64 SysTickReload(UINT64 nextResponseTime);
STATIC UINT64 SysTickCycleGet(UINT32 *period);
STATIC VOID SysTickLock(VOID);
STATIC VOID SysTickUnlock(VOID);
@@ -44,6 +44,7 @@ STATIC VOID SysTickUnlock(VOID);
STATIC ArchTickTimer g_archTickTimer = {
.freq = 0,
.irqNum = SysTick_IRQn,
.periodMax = LOSCFG_BASE_CORE_TICK_RESPONSE_MAX,
.init = SysTickStart,
.getCycle = SysTickCycleGet,
.reload = SysTickReload,
@@ -75,13 +76,17 @@ STATIC UINT32 SysTickStart(HWI_PROC_FUNC handler)
return LOS_OK;
}
STATIC VOID SysTickReload(UINT64 nextResponseTime)
STATIC UINT64 SysTickReload(UINT64 nextResponseTime)
{
if (nextResponseTime > g_archTickTimer.periodMax) {
nextResponseTime = g_archTickTimer.periodMax;
}
SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk;
SysTick->LOAD = (UINT32)(nextResponseTime - 1UL); /* set reload register */
SysTick->VAL = 0UL; /* Load the SysTick Counter Value */
NVIC_ClearPendingIRQ(SysTick_IRQn);
SysTick->CTRL |= SysTick_CTRL_ENABLE_Msk;
return nextResponseTime;
}
STATIC UINT64 SysTickCycleGet(UINT32 *period)

View File

@@ -209,11 +209,13 @@ LITE_OS_SEC_TEXT_MINOR VOID HalHwiDefaultHandler(VOID)
WEAK VOID HalPreInterruptHandler(UINT32 arg)
{
(VOID)arg;
return;
}
WEAK VOID HalAftInterruptHandler(UINT32 arg)
{
(VOID)arg;
return;
}
@@ -279,6 +281,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 ArchHwiCreate(HWI_HANDLE_T hwiNum,
HWI_PROC_FUNC handler,
HWI_ARG_T arg)
{
(VOID)mode;
UINT32 intSave;
if (handler == NULL) {
@@ -301,6 +304,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 ArchHwiCreate(HWI_HANDLE_T hwiNum,
#if (LOSCFG_PLATFORM_HWI_WITH_ARG == 1)
OsSetVector(hwiNum, handler, arg);
#else
(VOID)arg;
OsSetVector(hwiNum, handler);
#endif
HwiUnmask((IRQn_Type)hwiNum);

View File

@@ -36,7 +36,7 @@
#include "los_debug.h"
STATIC UINT32 SysTickStart(HWI_PROC_FUNC handler);
STATIC VOID SysTickReload(UINT64 nextResponseTime);
STATIC UINT64 SysTickReload(UINT64 nextResponseTime);
STATIC UINT64 SysTickCycleGet(UINT32 *period);
STATIC VOID SysTickLock(VOID);
STATIC VOID SysTickUnlock(VOID);
@@ -44,6 +44,7 @@ STATIC VOID SysTickUnlock(VOID);
STATIC ArchTickTimer g_archTickTimer = {
.freq = 0,
.irqNum = SysTick_IRQn,
.periodMax = LOSCFG_BASE_CORE_TICK_RESPONSE_MAX,
.init = SysTickStart,
.getCycle = SysTickCycleGet,
.reload = SysTickReload,
@@ -75,13 +76,17 @@ STATIC UINT32 SysTickStart(HWI_PROC_FUNC handler)
return LOS_OK;
}
STATIC VOID SysTickReload(UINT64 nextResponseTime)
STATIC UINT64 SysTickReload(UINT64 nextResponseTime)
{
if (nextResponseTime > g_archTickTimer.periodMax) {
nextResponseTime = g_archTickTimer.periodMax;
}
SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk;
SysTick->LOAD = (UINT32)(nextResponseTime - 1UL); /* set reload register */
SysTick->VAL = 0UL; /* Load the SysTick Counter Value */
NVIC_ClearPendingIRQ(SysTick_IRQn);
SysTick->CTRL |= SysTick_CTRL_ENABLE_Msk;
return nextResponseTime;
}
STATIC UINT64 SysTickCycleGet(UINT32 *period)

View File

@@ -0,0 +1,37 @@
# 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_group("gcc") {
if (defined(LOSCFG_SECURE_TRUSTZONE)) {
modules = [ "TZ" ]
} else {
modules = [ "NTZ" ]
}
}

View File

@@ -0,0 +1,45 @@
# 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_name = "arch"
kernel_module(module_name) {
sources = [
"los_context.c",
"los_dispatch.S",
"los_exc.S",
"los_interrupt.c",
"los_timer.c",
]
configs += [ "$LITEOSTOPDIR:warn_config" ]
}
config("public") {
include_dirs = [ "." ]
}

View File

@@ -0,0 +1,295 @@
/*
* 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_ARCH_ATOMIC_H
#define _LOS_ARCH_ATOMIC_H
#include "los_compiler.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
STATIC INLINE INT32 ArchAtomicRead(const Atomic *v)
{
INT32 val;
__asm__ __volatile__("ldrex %0, [%1]\n"
: "=&r"(val)
: "r"(v)
: "cc");
return val;
}
STATIC INLINE VOID ArchAtomicSet(Atomic *v, INT32 setVal)
{
UINT32 status;
do {
__asm__ __volatile__("ldrex %0, [%1]\n"
"strex %0, %2, [%1]\n"
: "=&r"(status)
: "r"(v), "r"(setVal)
: "cc");
} while (__builtin_expect(status != 0, 0));
}
STATIC INLINE INT32 ArchAtomicAdd(Atomic *v, INT32 addVal)
{
INT32 val;
UINT32 status;
do {
__asm__ __volatile__("ldrex %1, [%2]\n"
"add %1, %1, %3\n"
"strex %0, %1, [%2]"
: "=&r"(status), "=&r"(val)
: "r"(v), "r"(addVal)
: "cc");
} while (__builtin_expect(status != 0, 0));
return val;
}
STATIC INLINE INT32 ArchAtomicSub(Atomic *v, INT32 subVal)
{
INT32 val;
UINT32 status;
do {
__asm__ __volatile__("ldrex %1, [%2]\n"
"sub %1, %1, %3\n"
"strex %0, %1, [%2]"
: "=&r"(status), "=&r"(val)
: "r"(v), "r"(subVal)
: "cc");
} while (__builtin_expect(status != 0, 0));
return val;
}
STATIC INLINE VOID ArchAtomicInc(Atomic *v)
{
(VOID)ArchAtomicAdd(v, 1);
}
STATIC INLINE VOID ArchAtomicDec(Atomic *v)
{
(VOID)ArchAtomicSub(v, 1);
}
STATIC INLINE INT32 ArchAtomicIncRet(Atomic *v)
{
return ArchAtomicAdd(v, 1);
}
STATIC INLINE INT32 ArchAtomicDecRet(Atomic *v)
{
return ArchAtomicSub(v, 1);
}
/**
* @ingroup los_arch_atomic
* @brief Atomic exchange for 32-bit variable.
*
* @par Description:
* This API is used to implement the atomic exchange for 32-bit variable
* and return the previous value of the atomic variable.
* @attention
* <ul>The pointer v must not be NULL.</ul>
*
* @param v [IN] The variable pointer.
* @param val [IN] The exchange value.
*
* @retval #INT32 The previous value of the atomic variable
* @par Dependency:
* <ul><li>los_arch_atomic.h: the header file that contains the API declaration.</li></ul>
* @see
*/
STATIC INLINE INT32 ArchAtomicXchg32bits(volatile INT32 *v, INT32 val)
{
INT32 prevVal = 0;
UINT32 status = 0;
do {
__asm__ __volatile__("ldrex %0, [%3]\n"
"strex %1, %4, [%3]"
: "=&r"(prevVal), "=&r"(status), "+m"(*v)
: "r"(v), "r"(val)
: "cc");
} while (__builtin_expect(status != 0, 0));
return prevVal;
}
/**
* @ingroup los_arch_atomic
* @brief Atomic exchange for 32-bit variable with compare.
*
* @par Description:
* This API is used to implement the atomic exchange for 32-bit variable, if the value of variable is equal to oldVal.
* @attention
* <ul>The pointer v must not be NULL.</ul>
*
* @param v [IN] The variable pointer.
* @param val [IN] The new value.
* @param oldVal [IN] The old value.
*
* @retval TRUE The previous value of the atomic variable is not equal to oldVal.
* @retval FALSE The previous value of the atomic variable is equal to oldVal.
* @par Dependency:
* <ul><li>los_arch_atomic.h: the header file that contains the API declaration.</li></ul>
* @see
*/
STATIC INLINE BOOL ArchAtomicCmpXchg32bits(volatile INT32 *v, INT32 val, INT32 oldVal)
{
INT32 prevVal = 0;
UINT32 status = 0;
do {
__asm__ __volatile__("ldrex %0, %2\n"
"mov %1, #0\n"
"cmp %0, %3\n"
"bne 1f\n"
"strex %1, %4, %2\n"
"1:"
: "=&r"(prevVal), "=&r"(status), "+Q"(*v)
: "r"(oldVal), "r"(val)
: "cc");
} while (__builtin_expect(status != 0, 0));
return prevVal != oldVal;
}
STATIC INLINE INT64 ArchAtomic64Read(const Atomic64 *v)
{
INT64 val;
UINT32 intSave;
intSave = LOS_IntLock();
val = *v;
LOS_IntRestore(intSave);
return val;
}
STATIC INLINE VOID ArchAtomic64Set(Atomic64 *v, INT64 setVal)
{
UINT32 intSave;
intSave = LOS_IntLock();
*v = setVal;
LOS_IntRestore(intSave);
}
STATIC INLINE INT64 ArchAtomic64Add(Atomic64 *v, INT64 addVal)
{
INT64 val;
UINT32 intSave;
intSave = LOS_IntLock();
*v += addVal;
val = *v;
LOS_IntRestore(intSave);
return val;
}
STATIC INLINE INT64 ArchAtomic64Sub(Atomic64 *v, INT64 subVal)
{
INT64 val;
UINT32 intSave;
intSave = LOS_IntLock();
*v -= subVal;
val = *v;
LOS_IntRestore(intSave);
return val;
}
STATIC INLINE VOID ArchAtomic64Inc(Atomic64 *v)
{
(VOID)ArchAtomic64Add(v, 1);
}
STATIC INLINE INT64 ArchAtomic64IncRet(Atomic64 *v)
{
return ArchAtomic64Add(v, 1);
}
STATIC INLINE VOID ArchAtomic64Dec(Atomic64 *v)
{
(VOID)ArchAtomic64Sub(v, 1);
}
STATIC INLINE INT64 ArchAtomic64DecRet(Atomic64 *v)
{
return ArchAtomic64Sub(v, 1);
}
STATIC INLINE INT64 ArchAtomicXchg64bits(Atomic64 *v, INT64 val)
{
INT64 prevVal;
UINT32 intSave;
intSave = LOS_IntLock();
prevVal = *v;
*v = val;
LOS_IntRestore(intSave);
return prevVal;
}
STATIC INLINE BOOL ArchAtomicCmpXchg64bits(Atomic64 *v, INT64 val, INT64 oldVal)
{
INT64 prevVal;
UINT32 intSave;
intSave = LOS_IntLock();
prevVal = *v;
if (prevVal == oldVal) {
*v = val;
}
LOS_IntRestore(intSave);
return prevVal != oldVal;
}
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif /* _LOS_ARCH_ATOMIC_H */

View File

@@ -0,0 +1,131 @@
/*
* 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_ARCH_CONTEXT_H
#define _LOS_ARCH_CONTEXT_H
#include "los_config.h"
#include "los_compiler.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
typedef struct TagTskContext {
UINT32 uwPspLim;
UINT32 uwExcLR;
UINT32 uwR4;
UINT32 uwR5;
UINT32 uwR6;
UINT32 uwR7;
UINT32 uwR8;
UINT32 uwR9;
UINT32 uwR10;
UINT32 uwR11;
UINT32 uwPriMask;
#if ((defined(__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \
(defined(__FPU_USED) && (__FPU_USED == 1U)))
UINT32 S16;
UINT32 S17;
UINT32 S18;
UINT32 S19;
UINT32 S20;
UINT32 S21;
UINT32 S22;
UINT32 S23;
UINT32 S24;
UINT32 S25;
UINT32 S26;
UINT32 S27;
UINT32 S28;
UINT32 S29;
UINT32 S30;
UINT32 S31;
#endif
UINT32 uwR0;
UINT32 uwR1;
UINT32 uwR2;
UINT32 uwR3;
UINT32 uwR12;
UINT32 uwLR;
UINT32 uwPC;
UINT32 uwxPSR;
#if ((defined(__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \
(defined(__FPU_USED) && (__FPU_USED == 1U)))
UINT32 S0;
UINT32 S1;
UINT32 S2;
UINT32 S3;
UINT32 S4;
UINT32 S5;
UINT32 S6;
UINT32 S7;
UINT32 S8;
UINT32 S9;
UINT32 S10;
UINT32 S11;
UINT32 S12;
UINT32 S13;
UINT32 S14;
UINT32 S15;
UINT32 FPSCR;
UINT32 NO_NAME;
#endif
} TaskContext;
/**
* @ingroup los_config
* @brief: Task start running function.
*
* @par Description:
* This API is used to start a task.
*
* @attention:
* <ul><li>None.</li></ul>
*
* @param: None.
*
* @retval None.
*
* @par Dependency:
* <ul><li>los_config.h: the header file that contains the API declaration.</li></ul>
* @see None.
*/
extern VOID HalStartToRun(VOID);
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif /* _LOS_ARCH_CONTEXT_H */

View File

@@ -0,0 +1,693 @@
/*
* 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_ARCH_INTERRUPT_H
#define _LOS_ARCH_INTERRUPT_H
#include "los_config.h"
#include "los_compiler.h"
#include "los_interrupt.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
/* *
* @ingroup los_arch_interrupt
* Maximum number of used hardware interrupts.
*/
#ifndef OS_HWI_MAX_NUM
#define OS_HWI_MAX_NUM LOSCFG_PLATFORM_HWI_LIMIT
#endif
/* *
* @ingroup los_arch_interrupt
* Highest priority of a hardware interrupt.
*/
#ifndef OS_HWI_PRIO_HIGHEST
#define OS_HWI_PRIO_HIGHEST 0
#endif
/* *
* @ingroup los_arch_interrupt
* Lowest priority of a hardware interrupt.
*/
#ifndef OS_HWI_PRIO_LOWEST
#define OS_HWI_PRIO_LOWEST 7
#endif
/* *
* @ingroup los_arch_interrupt
* Define the type of a hardware interrupt vector table function.
*/
typedef VOID (**HWI_VECTOR_FUNC)(void);
/* *
* @ingroup los_arch_interrupt
* Count of interrupts.
*/
extern UINT32 g_intCount;
/* *
* @ingroup los_arch_interrupt
* Count of M-Core system interrupt vector.
*/
#define OS_SYS_VECTOR_CNT 16
/* *
* @ingroup los_arch_interrupt
* Count of M-Core interrupt vector.
*/
#define OS_VECTOR_CNT (OS_SYS_VECTOR_CNT + OS_HWI_MAX_NUM)
/* *
* @ingroup los_arch_interrupt
* AIRCR register priority group parameter .
*/
#define OS_NVIC_AIRCR_PRIGROUP 7
/* *
* @ingroup los_arch_interrupt
* Hardware interrupt error code: Invalid interrupt number.
*
* Value: 0x02000900
*
* Solution: Ensure that the interrupt number is valid.
* The value range of the interrupt number applicable for a Cortex-M33 platform is [OS_USER_HWI_MIN,OS_USER_HWI_MAX].
*/
#define OS_ERRNO_HWI_NUM_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x00)
/* *
* @ingroup los_arch_interrupt
* Hardware interrupt error code: Null hardware interrupt handling function.
*
* Value: 0x02000901
*
* Solution: Pass in a valid non-null hardware interrupt handling function.
*/
#define OS_ERRNO_HWI_PROC_FUNC_NULL LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x01)
/* *
* @ingroup los_arch_interrupt
* Hardware interrupt error code: Insufficient interrupt resources for hardware interrupt creation.
*
* Value: 0x02000902
*
* Solution: Increase the configured maximum number of supported hardware interrupts.
*/
#define OS_ERRNO_HWI_CB_UNAVAILABLE LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x02)
/* *
* @ingroup los_arch_interrupt
* Hardware interrupt error code: Insufficient memory for hardware interrupt initialization.
*
* Value: 0x02000903
*
* Solution: Expand the configured memory.
*/
#define OS_ERRNO_HWI_NO_MEMORY LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x03)
/* *
* @ingroup los_arch_interrupt
* Hardware interrupt error code: The interrupt has already been created.
*
* Value: 0x02000904
*
* Solution: Check whether the interrupt specified by the passed-in interrupt number has already been created.
*/
#define OS_ERRNO_HWI_ALREADY_CREATED LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x04)
/* *
* @ingroup los_arch_interrupt
* Hardware interrupt error code: Invalid interrupt priority.
*
* Value: 0x02000905
*
* Solution: Ensure that the interrupt priority is valid.
* The value range of the interrupt priority applicable for a Cortex-M33 platform is [0,15].
*/
#define OS_ERRNO_HWI_PRIO_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x05)
/* *
* @ingroup los_arch_interrupt
* Hardware interrupt error code: Incorrect interrupt creation mode.
*
* Value: 0x02000906
*
* Solution: The interrupt creation mode can be only set to OS_HWI_MODE_COMM or
* OS_HWI_MODE_FAST of which the value can be 0 or 1.
*/
#define OS_ERRNO_HWI_MODE_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x06)
/* *
* @ingroup los_arch_interrupt
* Hardware interrupt error code: The interrupt has already been created as a fast interrupt.
*
* Value: 0x02000907
*
* Solution: Check whether the interrupt specified by the passed-in interrupt number has already been created.
*/
#define OS_ERRNO_HWI_FASTMODE_ALREADY_CREATED LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x07)
/* *
* @ingroup los_arch_interrupt
* SysTick control and status register.
*/
#define OS_SYSTICK_CONTROL_REG 0xE000E010
/* *
* @ingroup los_hw
* SysTick current value register.
*/
#define OS_SYSTICK_CURRENT_REG 0xE000E018
/* *
* @ingroup los_arch_interrupt
* Interrupt Priority-Level Registers.
*/
#define OS_NVIC_PRI_BASE 0xE000E400
/* *
* @ingroup los_arch_interrupt
* Interrupt enable register for 0-31.
*/
#define OS_NVIC_SETENA_BASE 0xE000E100
/* *
* @ingroup los_arch_interrupt
* interrupt pending register.
*/
#define OS_NVIC_SETPEND_BASE 0xE000E200
/* *
* @ingroup los_arch_interrupt
* Interrupt active register.
*/
#define OS_NVIC_INT_ACT_BASE 0xE000E300
/* *
* @ingroup los_arch_interrupt
* Interrupt disable register for 0-31.
*/
#define OS_NVIC_CLRENA_BASE 0xE000E180
/* *
* @ingroup los_arch_interrupt
* Interrupt control and status register.
*/
#define OS_NVIC_INT_CTRL 0xE000ED04
/* *
* @ingroup los_arch_interrupt
* Vector table offset register.
*/
#define OS_NVIC_VTOR 0xE000ED08
/* *
* @ingroup los_arch_interrupt
* Application interrupt and reset control register
*/
#define OS_NVIC_AIRCR 0xE000ED0C
/* *
* @ingroup los_arch_interrupt
* System exception priority register.
*/
#define OS_NVIC_EXCPRI_BASE 0xE000ED18
/* *
* @ingroup los_arch_interrupt
* Interrupt No. 1 :reset.
*/
#define OS_EXC_RESET 1
/* *
* @ingroup los_arch_interrupt
* Interrupt No. 2 :Non-Maskable Interrupt.
*/
#define OS_EXC_NMI 2
/* *
* @ingroup los_arch_interrupt
* Interrupt No. 3 :(hard)fault.
*/
#define OS_EXC_HARD_FAULT 3
/* *
* @ingroup los_arch_interrupt
* Interrupt No. 4 :MemManage fault.
*/
#define OS_EXC_MPU_FAULT 4
/* *
* @ingroup los_arch_interrupt
* Interrupt No. 5 :Bus fault.
*/
#define OS_EXC_BUS_FAULT 5
/* *
* @ingroup los_arch_interrupt
* Interrupt No. 6 :Usage fault.
*/
#define OS_EXC_USAGE_FAULT 6
/* *
* @ingroup los_arch_interrupt
* Interrupt No. 11 :SVCall.
*/
#define OS_EXC_SVC_CALL 11
/* *
* @ingroup los_arch_interrupt
* Interrupt No. 12 :Debug monitor.
*/
#define OS_EXC_DBG_MONITOR 12
/* *
* @ingroup los_arch_interrupt
* Interrupt No. 14 :PendSV.
*/
#define OS_EXC_PEND_SV 14
/* *
* @ingroup los_arch_interrupt
* Interrupt No. 15 :SysTick.
*/
#define OS_EXC_SYS_TICK 15
#if (LOSCFG_PLATFORM_HWI_WITH_ARG == 1)
/* *
* @ingroup los_arch_interrupt
* Set interrupt vector table.
*/
extern VOID OsSetVector(UINT32 num, HWI_PROC_FUNC vector, VOID *arg);
#else
/* *
* @ingroup los_arch_interrupt
* Set interrupt vector table.
*/
extern VOID OsSetVector(UINT32 num, HWI_PROC_FUNC vector);
#endif
/* *
* @ingroup los_arch_interrupt
* @brief: Hardware interrupt entry function.
*
* @par Description:
* This API is used as all hardware interrupt handling function entry.
*
* @attention:
* <ul><li>None.</li></ul>
*
* @param:None.
*
* @retval:None.
* @par Dependency:
* <ul><li>los_arch_interrupt.h: the header file that contains the API declaration.</li></ul>
* @see None.
*/
extern VOID HalInterrupt(VOID);
/* *
* @ingroup los_arch_interrupt
* @brief: Default vector handling function.
*
* @par Description:
* This API is used to configure interrupt for null function.
*
* @attention:
* <ul><li>None.</li></ul>
*
* @param:None.
*
* @retval:None.
* @par Dependency:
* <ul><li>los_arch_interrupt.h: the header file that contains the API declaration.</li></ul>
* @see None.
*/
extern VOID HalHwiDefaultHandler(VOID);
/* *
* @ingroup los_arch_interrupt
* @brief: Reset the vector table.
*
* @par Description:
* This API is used to reset the vector table.
*
* @attention:
* <ul><li>None.</li></ul>
*
* @param:None.
*
* @retval:None.
* @par Dependency:
* <ul><li>los_arch_interrupt.h: the header file that contains the API declaration.</li></ul>
* @see None.
*/
extern VOID Reset_Handler(VOID);
/* *
* @ingroup los_arch_interrupt
* @brief: Pended System Call.
*
* @par Description:
* PendSV can be pended and is useful for an OS to pend an exception
* so that an action can be performed after other important tasks are completed.
*
* @attention:
* <ul><li>None.</li></ul>
*
* @param:None.
*
* @retval:None.
* @par Dependency:
* <ul><li>los_arch_interrupt.h: the header file that contains the API declaration.</li></ul>
* @see None.
*/
extern VOID HalPendSV(VOID);
#define OS_EXC_IN_INIT 0
#define OS_EXC_IN_TASK 1
#define OS_EXC_IN_HWI 2
#define OS_EXC_MAX_BUF_LEN 25
#define OS_EXC_MAX_NEST_DEPTH 1
#define OS_NVIC_SHCSR 0xE000ED24
#define OS_NVIC_CCR 0xE000ED14
#define OS_NVIC_INT_ENABLE_SIZE 0x20
#define OS_NVIC_INT_PRI_SIZE 0xF0
#define OS_NVIC_EXCPRI_SIZE 0xC
#define OS_NVIC_INT_CTRL_SIZE 4
#define OS_NVIC_SHCSR_SIZE 4
#define OS_NVIC_INT_PEND_SIZE OS_NVIC_INT_ACT_SIZE
#define OS_NVIC_INT_ACT_SIZE OS_NVIC_INT_ENABLE_SIZE
#define OS_EXC_FLAG_NO_FLOAT 0x10000000
#define OS_EXC_FLAG_FAULTADDR_VALID 0x01
#define OS_EXC_FLAG_IN_HWI 0x02
#define OS_EXC_IMPRECISE_ACCESS_ADDR 0xABABABAB
#define OS_EXC_EVENT 0x00000001
/**
* @ingroup los_exc
* the struct of register files
*
* description: the register files that saved when exception triggered
*
* notes:the following register with prefix 'uw' correspond to the registers in the cpu data sheet.
*/
typedef struct TagExcContext {
#if ((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \
(defined (__FPU_USED ) && (__FPU_USED == 1U)) )
UINT32 S16;
UINT32 S17;
UINT32 S18;
UINT32 S19;
UINT32 S20;
UINT32 S21;
UINT32 S22;
UINT32 S23;
UINT32 S24;
UINT32 S25;
UINT32 S26;
UINT32 S27;
UINT32 S28;
UINT32 S29;
UINT32 S30;
UINT32 S31;
#endif
UINT32 uwR4;
UINT32 uwR5;
UINT32 uwR6;
UINT32 uwR7;
UINT32 uwR8;
UINT32 uwR9;
UINT32 uwR10;
UINT32 uwR11;
UINT32 uwPriMask;
/* auto save */
UINT32 uwSP;
UINT32 uwR0;
UINT32 uwR1;
UINT32 uwR2;
UINT32 uwR3;
UINT32 uwR12;
UINT32 uwLR;
UINT32 uwPC;
UINT32 uwxPSR;
#if ((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \
(defined (__FPU_USED) && (__FPU_USED== 1U)))
UINT32 S0;
UINT32 S1;
UINT32 S2;
UINT32 S3;
UINT32 S4;
UINT32 S5;
UINT32 S6;
UINT32 S7;
UINT32 S8;
UINT32 S9;
UINT32 S10;
UINT32 S11;
UINT32 S12;
UINT32 S13;
UINT32 S14;
UINT32 S15;
UINT32 FPSCR;
UINT32 NO_NAME;
#endif
} EXC_CONTEXT_S;
typedef VOID (*EXC_PROC_FUNC)(UINT32, EXC_CONTEXT_S *);
VOID HalExcHandleEntry(UINT32 excType, UINT32 faultAddr, UINT32 pid, EXC_CONTEXT_S *excBufAddr);
VOID HalExcNMI(VOID);
VOID HalExcHardFault(VOID);
VOID HalExcMemFault(VOID);
VOID HalExcBusFault(VOID);
VOID HalExcUsageFault(VOID);
VOID HalSVCHandler(VOID);
VOID HalHwiInit(VOID);
/**
* @ingroup los_exc
* Cortex-M exception types: Record whether a precise BusFault occurred during floating-point lazy state preservation.
*/
#define OS_EXC_BF_LSPERR 1
/**
* @ingroup los_exc
* Cortex-M exception types: An error occurred while the bus status register was being pushed.
*/
#define OS_EXC_BF_STKERR 2
/**
* @ingroup los_exc
* Cortex-M exception types: An error occurred while the bus status register was out of the stack.
*/
#define OS_EXC_BF_UNSTKERR 3
/**
* @ingroup los_exc
* Cortex-M exception types: Bus status register imprecise data access violation.
*/
#define OS_EXC_BF_IMPRECISERR 4
/**
* @ingroup los_exc
* Cortex-M exception types: Bus status register exact data access violation.
*/
#define OS_EXC_BF_PRECISERR 5
/**
* @ingroup los_exc
* Cortex-M exception types: Bus status register access violation while pointing.
*/
#define OS_EXC_BF_IBUSERR 6
/**
* @ingroup los_exc
* Cortex-M exception types: Record whether a MemManage fault occurred during floating-point lazy state preservation.
*/
#define OS_EXC_MF_MLSPERR 7
/**
* @ingroup los_exc
* Cortex-M exception types: An error occurred while the memory management status register was being pushed.
*/
#define OS_EXC_MF_MSTKERR 8
/**
* @ingroup los_exc
* Cortex-M exception types: An error occurred while the memory management status register was out of the stack.
*/
#define OS_EXC_MF_MUNSTKERR 9
/**
* @ingroup los_exc
* Cortex-M exception types: Memory management status register data access violation.
*/
#define OS_EXC_MF_DACCVIOL 10
/**
* @ingroup los_exc
* Cortex-M exception types: Memory management status register access violation.
*/
#define OS_EXC_MF_IACCVIOL 11
/**
* @ingroup los_exc
* Cortex-M exception types: Incorrect usage indicating that the divisor is zero during the division operation.
*/
#define OS_EXC_UF_DIVBYZERO 12
/**
* @ingroup los_exc
* Cortex-M exception types: Usage error, error caused by unaligned access.
*/
#define OS_EXC_UF_UNALIGNED 13
/**
* @ingroup los_exc
* Cortex-M exception types: Sticky flag indicating whether a stack overflow error has occurred.
*/
#define OS_EXC_UF_STKOF 14
/**
* @ingroup los_exc
* Cortex-M exception types: Incorrect usage attempting to execute coprocessor related instruction.
*/
#define OS_EXC_UF_NOCP 15
/**
* @ingroup los_exc
* Cortex-M exception types: Usage error attempting to load EXC_RETURN to PC illegally on exception return.
*/
#define OS_EXC_UF_INVPC 16
/**
* @ingroup los_exc
* Cortex-M exception types: Incorrect usage, attempting to cut to ARM state.
*/
#define OS_EXC_UF_INVSTATE 17
/**
* @ingroup los_exc
* Cortex-M exception types: Incorrect usage. Executed instruction whose code is undefined.
*/
#define OS_EXC_UF_UNDEFINSTR 18
/**
* @ingroup los_exc
* Cortex-M exception types: NMI
*/
#define OS_EXC_CAUSE_NMI 19
/**
* @ingroup los_exc
* Cortex-M exception types: hard fault
*/
#define OS_EXC_CAUSE_HARDFAULT 20
/**
* @ingroup los_exc
* Cortex-M exception types: The task handler exits.
*/
#define OS_EXC_CAUSE_TASK_EXIT 21
/**
* @ingroup los_exc
* Cortex-M exception types: A fatal error.
*/
#define OS_EXC_CAUSE_FATAL_ERR 22
/**
* @ingroup los_exc
* Cortex-M exception types: Hard Fault caused by a debug event.
*/
#define OS_EXC_CAUSE_DEBUGEVT 23
/**
* @ingroup los_exc
* Cortex-M exception types: A hard fault that occurs when a quantity is oriented.
*/
#define OS_EXC_CAUSE_VECTBL 24
/**
* @ingroup los_exc
* Exception information structure
*
* Description: Exception information saved when an exception is triggered on the Cortex-M33 platform.
*
*/
typedef struct TagExcInfo {
/**< Exception occurrence phase: 0 means that an exception occurs in initialization,
* 1 means that an exception occurs in a task, and 2 means that an exception occurs in an interrupt */
UINT16 phase;
/**< Exception type. When exceptions occur, check the numbers 1 - 21 listed above */
UINT16 type;
/**< If the exact address access error indicates the wrong access address when the exception occurred */
UINT32 faultAddr;
/**< An exception occurs in an interrupt, indicating the interrupt number.
* An exception occurs in the task, indicating the task ID, or 0xFFFFFFFF if it occurs during initialization */
UINT32 thrdPid;
/**< Number of nested exceptions. Currently only registered hook functions are supported
* when an exception is entered for the first time */
UINT16 nestCnt;
/**< reserve */
UINT16 reserved;
/**< Hardware context at the time an exception to the automatic stack floating-point register occurs */
EXC_CONTEXT_S *context;
} ExcInfo;
extern UINT32 g_curNestCount;
extern UINT32 g_intCount;
extern UINT8 g_uwExcTbl[32];
extern ExcInfo g_excInfo;
#define MAX_INT_INFO_SIZE (8 + 0x164)
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif /* _LOS_ARCH_INTERRUPT_H */

View File

@@ -28,9 +28,23 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <pthread.h>
#ifndef _LOS_ARCH_TIMER_H
#define _LOS_ARCH_TIMER_H
int pthread_equal(pthread_t __t1, pthread_t __t2)
{
return (int)(__t1 == __t2);
#include "los_config.h"
#include "los_compiler.h"
#include "los_timer.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif /* _LOS_ARCH_TIMER_H */

View 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_context.h"
#include "securec.h"
#include "los_arch_context.h"
#include "los_arch_interrupt.h"
#include "los_task.h"
#include "los_sched.h"
#include "los_interrupt.h"
#include "los_debug.h"
/* ****************************************************************************
Function : ArchInit
Description : arch init function
Input : None
Output : None
Return : None
**************************************************************************** */
LITE_OS_SEC_TEXT_INIT VOID ArchInit(VOID)
{
HalHwiInit();
}
/* ****************************************************************************
Function : ArchSysExit
Description : Task exit function
Input : None
Output : None
Return : None
**************************************************************************** */
LITE_OS_SEC_TEXT_MINOR VOID ArchSysExit(VOID)
{
LOS_IntLock();
while (1) {
}
}
/* ****************************************************************************
Function : ArchTskStackInit
Description : Task stack initialization function
Input : taskID --- TaskID
stackSize --- Total size of the stack
topStack --- Top of task's stack
Output : None
Return : Context pointer
**************************************************************************** */
LITE_OS_SEC_TEXT_INIT VOID *ArchTskStackInit(UINT32 taskID, UINT32 stackSize, VOID *topStack)
{
TaskContext *context = (TaskContext *)((UINTPTR)topStack + stackSize - sizeof(TaskContext));
#if ((defined(__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \
(defined(__FPU_USED) && (__FPU_USED == 1U)))
context->S16 = 0xAA000010;
context->S17 = 0xAA000011;
context->S18 = 0xAA000012;
context->S19 = 0xAA000013;
context->S20 = 0xAA000014;
context->S21 = 0xAA000015;
context->S22 = 0xAA000016;
context->S23 = 0xAA000017;
context->S24 = 0xAA000018;
context->S25 = 0xAA000019;
context->S26 = 0xAA00001A;
context->S27 = 0xAA00001B;
context->S28 = 0xAA00001C;
context->S29 = 0xAA00001D;
context->S30 = 0xAA00001E;
context->S31 = 0xAA00001F;
context->S0 = 0xAA000000;
context->S1 = 0xAA000001;
context->S2 = 0xAA000002;
context->S3 = 0xAA000003;
context->S4 = 0xAA000004;
context->S5 = 0xAA000005;
context->S6 = 0xAA000006;
context->S7 = 0xAA000007;
context->S8 = 0xAA000008;
context->S9 = 0xAA000009;
context->S10 = 0xAA00000A;
context->S11 = 0xAA00000B;
context->S12 = 0xAA00000C;
context->S13 = 0xAA00000D;
context->S14 = 0xAA00000E;
context->S15 = 0xAA00000F;
context->FPSCR = 0x00000000;
context->NO_NAME = 0xAA000011;
context->uwExcLR = 0xFFFFFFEDL;
#else
context->uwExcLR = 0xFFFFFFFDL;
#endif
context->uwPspLim = (UINT32)topStack;
context->uwR4 = 0x04040404L;
context->uwR5 = 0x05050505L;
context->uwR6 = 0x06060606L;
context->uwR7 = 0x07070707L;
context->uwR8 = 0x08080808L;
context->uwR9 = 0x09090909L;
context->uwR10 = 0x10101010L;
context->uwR11 = 0x11111111L;
context->uwPriMask = 0;
context->uwR0 = taskID;
context->uwR1 = 0x01010101L;
context->uwR2 = 0x02020202L;
context->uwR3 = 0x03030303L;
context->uwR12 = 0x12121212L;
context->uwLR = (UINT32)(UINTPTR)ArchSysExit;
context->uwPC = (UINT32)(UINTPTR)OsTaskEntry;
context->uwxPSR = 0x01000000L;
return (VOID *)context;
}
#if (LOSCFG_KERNEL_SIGNAL == 1)
VOID *ArchSignalContextInit(VOID *stackPointer, VOID *stackTop, UINTPTR sigHandler, UINT32 param)
{
UNUSED(stackTop);
TaskContext *context = (TaskContext *)((UINTPTR)stackPointer - sizeof(TaskContext));
(VOID)memset_s((VOID *)context, sizeof(TaskContext), 0, sizeof(TaskContext));
context->uwR0 = param;
context->uwPC = sigHandler;
context->uwxPSR = 0x01000000L; /* Thumb flag, always set 1 */
return (VOID *)context;
}
#endif
LITE_OS_SEC_TEXT_INIT UINT32 ArchStartSchedule(VOID)
{
(VOID)LOS_IntLock();
OsSchedStart();
HalStartToRun();
return LOS_OK; /* never return */
}

View File

@@ -0,0 +1,191 @@
/*
* 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.
*/
.syntax unified
.arch armv8.1-m.main
.fpu vfpv3-d16-fp16
.thumb
.equ OS_NVIC_INT_CTRL, 0xE000ED04
.equ OS_NVIC_SYSPRI3, 0xE000ED20
.equ OS_NVIC_PENDSV_PRI, 0xF0F00000
.equ OS_NVIC_PENDSVSET, 0x10000000
.section .text
.thumb
.macro SIGNAL_CONTEXT_RESTORE
push {r12, lr}
blx OsSignalTaskContextRestore
pop {r12, lr}
cmp r0, #0
mov r1, r0
bne SignalContextRestore
.endm
.type HalStartToRun, %function
.global HalStartToRun
HalStartToRun:
.fnstart
.cantunwind
ldr r4, =OS_NVIC_SYSPRI3
ldr r5, =OS_NVIC_PENDSV_PRI
str r5, [r4]
mov r0, #2
msr CONTROL, r0
ldr r1, =g_losTask
ldr r0, [r1, #4]
ldr r12, [r0]
ldr r2, [r12, #4]
tst r2, #0x10
it ne
bne __DisabledFPU
add r12, r12, #108
ldmfd r12!, {r0-r7}
add r12, r12, #72
msr psp, r12
vpush {s0}
vpop {s0}
mov lr, r5
cpsie I
bx r6
__DisabledFPU:
add r12, r12, #44
ldmfd r12!, {r0-r7}
msr psp, r12
mov lr, r5
cpsie I
bx r6
.fnend
.type ArchIntLock, %function
.global ArchIntLock
ArchIntLock:
.fnstart
.cantunwind
mrs r0, PRIMASK
cpsid I
bx lr
.fnend
.type ArchIntUnLock, %function
.global ArchIntUnLock
ArchIntUnLock:
.fnstart
.cantunwind
mrs r0, PRIMASK
cpsie I
bx lr
.fnend
.type ArchIntRestore, %function
.global ArchIntRestore
ArchIntRestore:
.fnstart
.cantunwind
msr PRIMASK, r0
bx lr
.fnend
.type ArchTaskSchedule, %function
.global ArchTaskSchedule
ArchTaskSchedule:
.fnstart
.cantunwind
ldr r0, =OS_NVIC_INT_CTRL
ldr r1, =OS_NVIC_PENDSVSET
str r1, [r0]
dsb
isb
bx lr
.fnend
.type HalPendSV, %function
.global HalPendSV
HalPendSV:
.fnstart
.cantunwind
mrs r12, PRIMASK
cpsid I
HalTaskSwitch:
SIGNAL_CONTEXT_RESTORE
push {r12, lr}
blx OsSchedTaskSwitch
pop {r12, lr}
cmp r0, #0
mov r0, lr
bne TaskContextSwitch
msr PRIMASK, r12
bx lr
TaskContextSwitch:
mov lr, r0
mrs r0, psp
tst lr, #0x10
it eq
vstmdbeq r0!, {d8-d15}
mrs r2, psplim
mov r3, lr
stmfd r0!, {r2-r12}
ldr r5, =g_losTask
ldr r6, [r5]
str r0, [r6]
ldr r0, [r5, #4]
str r0, [r5]
ldr r1, [r0]
SignalContextRestore:
ldmfd r1!, {r2-r12}
msr psplim, r2
tst r3, #0x10
it eq
vldmiaeq r1!, {d8-d15}
msr psp, r1
msr PRIMASK, r12
bx lr
.fnend

View File

@@ -0,0 +1,381 @@
/*
* 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.
*/
.syntax unified
.arch armv8.1-m.main
.fpu vfpv3-d16-fp16
.thumb
.section .text
.global HalExcNMI
.global HalExcHardFault
.global HalExcMemFault
.global HalExcBusFault
.global HalExcUsageFault
.global HalSVCHandler
.extern HalExcHandleEntry
.extern g_uwExcTbl
.extern g_taskScheduled
.equ OS_FLG_BGD_ACTIVE, 0x0002
.equ OS_EXC_CAUSE_NMI, 19
.equ OS_EXC_CAUSE_HARDFAULT, 20
.equ HF_DEBUGEVT, 23
.equ HF_VECTBL, 24
.equ FLAG_ADDR_VALID, 0x10000
.equ FLAG_HWI_ACTIVE, 0x20000
.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
.type HalExcNMI, %function
.global HalExcNMI
HalExcNMI:
.fnstart
.cantunwind
MOV R0, #OS_EXC_CAUSE_NMI
MOV R1, #0
B osExcDispatch
.fnend
.type HalExcHardFault, %function
.global HalExcHardFault
HalExcHardFault:
.fnstart
.cantunwind
MOV R0, #OS_EXC_CAUSE_HARDFAULT
LDR R2, =OS_NVIC_HFSR
LDR R2, [R2]
MOV R1, #HF_DEBUGEVT
ORR R0, R0, R1, LSL #0x8
TST R2, #0x80000000
BNE osExcDispatch // DEBUGEVT
AND R0, R0, #0x000000FF
MOV R1, #HF_VECTBL
ORR R0, R0, R1, LSL #0x8
TST R2, #0x00000002
BNE osExcDispatch // VECTBL
//if not DEBUGEVT and VECTBL then is FORCED
AND R0, R0, #0x000000FF
LDR R2, =OS_NVIC_FSR
LDR R2, [R2]
TST R2, #0x8000 // BFARVALID
BNE _HFBusFault // BusFault
TST R2, #0x80 // MMARVALID
BNE _HFMemFault // MemFault
MOV R12, #0
B osHFExcCommonBMU
.fnend
.type _HFBusFault, %function
_HFBusFault:
.fnstart
.cantunwind
LDR R1, =OS_NVIC_BFAR
LDR R1, [R1]
MOV R12, #FLAG_ADDR_VALID
B osHFExcCommonBMU
.fnend
.type _HFMemFault, %function
_HFMemFault:
.fnstart
.cantunwind
LDR R1, =OS_NVIC_MMAR
LDR R1, [R1]
MOV R12, #FLAG_ADDR_VALID
.fnend
.type osHFExcCommonBMU, %function
.global osHFExcCommonBMU
osHFExcCommonBMU:
.fnstart
.cantunwind
CLZ R2, R2
LDR R3, =g_uwExcTbl
ADD R3, R3, R2
LDRB R2, [R3]
ORR R0, R0, R2, LSL #0x8
ORR R0, R0, R12
B osExcDispatch
.fnend
.type HalSVCHandler, %function
.global HalSVCHandler
HalSVCHandler:
.fnstart
.cantunwind
TST LR, #0x4
ITE EQ
MRSEQ R0, MSP
MRSNE R0, PSP
LDR R1, [R0,#24]
LDRB R0, [R1,#-2]
MOV R1, #0
B osExcDispatch
.fnend
.type HalExcBusFault, %function
.global HalExcBusFault
HalExcBusFault:
.fnstart
.cantunwind
LDR R0, =OS_NVIC_FSR
LDR R0, [R0]
TST R0, #0x8000 // BFARVALID
BEQ _ExcBusNoADDR
LDR R1, =OS_NVIC_BFAR
LDR R1, [R1]
MOV R12, #FLAG_ADDR_VALID
AND R0, R0, #0x1F00
B osExcCommonBMU
.fnend
.type _ExcBusNoADDR, %function
.global _ExcBusNoADDR
_ExcBusNoADDR:
.fnstart
.cantunwind
MOV R12, #0
B osExcCommonBMU
.fnend
.type HalExcMemFault, %function
.global HalExcMemFault
HalExcMemFault:
.fnstart
.cantunwind
LDR R0, =OS_NVIC_FSR
LDR R0, [R0]
TST R0, #0x80 // MMARVALID
BEQ _ExcMemNoADDR
LDR R1, =OS_NVIC_MMAR
LDR R1, [R1]
MOV R12, #FLAG_ADDR_VALID
AND R0, R0, #0x1B
B osExcCommonBMU
.fnend
.type _ExcMemNoADDR, %function
.global _ExcMemNoADDR
_ExcMemNoADDR:
.fnstart
.cantunwind
MOV R12, #0
B osExcCommonBMU
.fnend
.type HalExcUsageFault, %function
.global HalExcUsageFault
HalExcUsageFault:
.fnstart
.cantunwind
LDR R0, =OS_NVIC_FSR
LDR R0, [R0]
MOVW R1, #0x031F
LSL R1, R1, #16
AND R0, R0, R1
MOV R12, #0
.fnend
.type osExcCommonBMU, %function
.global osExcCommonBMU
osExcCommonBMU:
.fnstart
.cantunwind
CLZ R0, R0
LDR R3, =g_uwExcTbl
ADD R3, R3, R0
LDRB R0, [R3]
ORR R0, R0, R12
.fnend
// R0 -- EXCCAUSE(bit 16 is 1 if EXCADDR valid), R1 -- EXCADDR
.type osExcDispatch, %function
.global osExcDispatch
osExcDispatch:
.fnstart
.cantunwind
LDR R2, =OS_NVIC_ACT_BASE
MOV R12, #16 // R12 is hwi check loop counter
.fnend
.type _hwiActiveCheck, %function
.global _hwiActiveCheck
_hwiActiveCheck:
.fnstart
.cantunwind
LDR R3, [R2] // R3 store active hwi register when exc
CMP R3, #0
BEQ _hwiActiveCheckNext
// exc occured in IRQ
ORR R0, R0, #FLAG_HWI_ACTIVE
RBIT R2, R3
CLZ R2, R2
AND R12, R12, #1
ADD R2, R2, R12, LSL #5 // calculate R2 (hwi number) as pid
.fnend
.type _ExcInMSP, %function
.global _ExcInMSP
_ExcInMSP:
.fnstart
.cantunwind
CMP LR, #0xFFFFFFE9
BNE _NoFloatInMsp
ADD R3, R13, #104
PUSH {R3}
MRS R12, PRIMASK // store message-->exc: disable int?
PUSH {R4-R12} // store message-->exc: {R4-R12}
VPUSH {D8-D15}
B _handleEntry
.fnend
.type _NoFloatInMsp, %function
.global _NoFloatInMsp
_NoFloatInMsp:
.fnstart
.cantunwind
ADD R3, R13, #32
PUSH {R3} // save IRQ SP // store message-->exc: MSP(R13)
MRS R12, PRIMASK // store message-->exc: disable int?
PUSH {R4-R12} // store message-->exc: {R4-R12}
ORR R0, R0, #FLAG_NO_FLOAT
B _handleEntry
.fnend
.type _hwiActiveCheckNext, %function
.global _hwiActiveCheckNext
_hwiActiveCheckNext:
.fnstart
.cantunwind
ADD R2, R2, #4 // next NVIC ACT ADDR
SUBS R12, R12, #1
BNE _hwiActiveCheck
/*NMI interrupt excption*/
LDR R2, =OS_NVIC_SHCSRS
LDRH R2, [R2]
LDR R3, =OS_NVIC_SHCSR_MASK
AND R2, R2, R3
CMP R2, #0
BNE _ExcInMSP
// exc occured in Task or Init or exc
// reserved for register info from task stack
LDR R2, =g_taskScheduled
LDR R2, [R2]
TST R2, #1 // OS_FLG_BGD_ACTIVE
BEQ _ExcInMSP // if exc occured in Init then branch
CMP LR, #0xFFFFFFED //auto push floating registers
BNE _NoFloatInPsp
// exc occured in Task
MOV R2, R13
SUB R13, #96 // add 8 Bytes reg(for STMFD)
MRS R3, PSP
ADD R12, R3, #104
PUSH {R12} // save task SP
MRS R12, PRIMASK
PUSH {R4-R12}
VPUSH {D8-D15}
// copy auto saved task register
LDMFD R3!, {R4-R11} // R4-R11 store PSP reg(auto push when exc in task)
VLDMIA R3!, {D8-D15}
VSTMDB R2!, {D8-D15}
STMFD R2!, {R4-R11}
B _handleEntry
.fnend
.type _NoFloatInPsp, %function
.global _NoFloatInPsp
_NoFloatInPsp:
.fnstart
.cantunwind
MOV R2, R13 // no auto push floating registers
SUB R13, #32 // add 8 Bytes reg(for STMFD)
MRS R3, PSP
ADD R12, R3, #32
PUSH {R12} // save task SP
MRS R12, PRIMASK
PUSH {R4-R12}
LDMFD R3, {R4-R11} // R4-R11 store PSP reg(auto push when exc in task)
STMFD R2!, {R4-R11}
ORR R0, R0, #FLAG_NO_FLOAT
.fnend
.type _handleEntry, %function
.global _handleEntry
_handleEntry:
.fnstart
.cantunwind
MOV R3, R13 // R13:the 4th param
CPSID I
CPSID F
B HalExcHandleEntry
NOP
.fnend

View File

@@ -0,0 +1,609 @@
/*
* 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_interrupt.h"
#include <stdarg.h>
#include "securec.h"
#include "los_context.h"
#include "los_arch_interrupt.h"
#include "los_debug.h"
#include "los_hook.h"
#include "los_task.h"
#include "los_sched.h"
#include "los_memory.h"
#include "los_membox.h"
#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_PLATFORM_HWI_WITH_ARG == 1)
typedef struct {
HWI_PROC_FUNC pfnHandler;
VOID *pParm;
} HWI_HANDLER_FUNC;
/* *
* @ingroup los_hwi
* Hardware interrupt handler form mapping handling function array.
*/
STATIC HWI_HANDLER_FUNC g_hwiHandlerForm[OS_VECTOR_CNT] = {{ (HWI_PROC_FUNC)0, (HWI_ARG_T)0 }};
/* *
* @ingroup los_hwi
* Set interrupt vector table.
*/
VOID OsSetVector(UINT32 num, HWI_PROC_FUNC vector, VOID *arg)
{
if ((num + OS_SYS_VECTOR_CNT) < OS_VECTOR_CNT) {
g_hwiForm[num + OS_SYS_VECTOR_CNT] = (HWI_PROC_FUNC)HalInterrupt;
g_hwiHandlerForm[num + OS_SYS_VECTOR_CNT].pfnHandler = vector;
g_hwiHandlerForm[num + OS_SYS_VECTOR_CNT].pParm = arg;
}
}
#else
/* *
* @ingroup los_hwi
* hardware interrupt handler form mapping handling function array.
*/
STATIC HWI_PROC_FUNC g_hwiHandlerForm[OS_VECTOR_CNT] = {0};
/* *
* @ingroup los_hwi
* Set interrupt vector table.
*/
VOID OsSetVector(UINT32 num, HWI_PROC_FUNC vector)
{
if ((num + OS_SYS_VECTOR_CNT) < OS_VECTOR_CNT) {
g_hwiForm[num + OS_SYS_VECTOR_CNT] = HalInterrupt;
g_hwiHandlerForm[num + OS_SYS_VECTOR_CNT] = vector;
}
}
#endif
WEAK VOID SysTick_Handler(VOID)
{
return;
}
/* ****************************************************************************
Function : HwiNumGet
Description : Get an interrupt number
Input : None
Output : None
Return : Interrupt Indexes number
**************************************************************************** */
STATIC UINT32 HwiNumGet(VOID)
{
return __get_IPSR();
}
STATIC UINT32 HwiUnmask(HWI_HANDLE_T hwiNum)
{
if (hwiNum >= OS_HWI_MAX_NUM) {
return OS_ERRNO_HWI_NUM_INVALID;
}
NVIC_EnableIRQ((IRQn_Type)hwiNum);
return LOS_OK;
}
STATIC UINT32 HwiMask(HWI_HANDLE_T hwiNum)
{
if (hwiNum >= OS_HWI_MAX_NUM) {
return OS_ERRNO_HWI_NUM_INVALID;
}
NVIC_DisableIRQ((IRQn_Type)hwiNum);
return LOS_OK;
}
STATIC UINT32 HwiSetPriority(HWI_HANDLE_T hwiNum, UINT8 priority)
{
if (hwiNum >= OS_HWI_MAX_NUM) {
return OS_ERRNO_HWI_NUM_INVALID;
}
if (priority > OS_HWI_PRIO_LOWEST) {
return OS_ERRNO_HWI_PRIO_INVALID;
}
NVIC_SetPriority((IRQn_Type)hwiNum, priority);
return LOS_OK;
}
STATIC UINT32 HwiPending(HWI_HANDLE_T hwiNum)
{
if (hwiNum >= OS_HWI_MAX_NUM) {
return OS_ERRNO_HWI_NUM_INVALID;
}
NVIC_SetPendingIRQ((IRQn_Type)hwiNum);
return LOS_OK;
}
STATIC UINT32 HwiClear(HWI_HANDLE_T hwiNum)
{
if (hwiNum >= OS_HWI_MAX_NUM) {
return OS_ERRNO_HWI_NUM_INVALID;
}
NVIC_ClearPendingIRQ((IRQn_Type)hwiNum);
return LOS_OK;
}
HwiControllerOps g_archHwiOps = {
.enableIrq = HwiUnmask,
.disableIrq = HwiMask,
.setIrqPriority = HwiSetPriority,
.getCurIrqNum = HwiNumGet,
.triggerIrq = HwiPending,
.clearIrq = HwiClear,
};
inline UINT32 ArchIsIntActive(VOID)
{
return (g_intCount > 0);
}
/* ****************************************************************************
Function : HalHwiDefaultHandler
Description : default handler of the hardware interrupt
Input : None
Output : None
Return : None
**************************************************************************** */
/*lint -e529*/
LITE_OS_SEC_TEXT_MINOR VOID HalHwiDefaultHandler(VOID)
{
UINT32 irqNum = HwiNumGet();
PRINT_ERR("%s irqnum:%u\n", __FUNCTION__, irqNum);
while (1) {}
}
WEAK VOID HalPreInterruptHandler(UINT32 arg)
{
(VOID)arg;
return;
}
WEAK VOID HalAftInterruptHandler(UINT32 arg)
{
(VOID)arg;
return;
}
/* ****************************************************************************
Function : HalInterrupt
Description : Hardware interrupt entry function
Input : None
Output : None
Return : None
**************************************************************************** */
LITE_OS_SEC_TEXT VOID HalInterrupt(VOID)
{
UINT32 hwiIndex;
UINT32 intSave;
#if (LOSCFG_KERNEL_RUNSTOP == 1)
SCB->SCR &= (UINT32) ~((UINT32)SCB_SCR_SLEEPDEEP_Msk);
#endif
intSave = LOS_IntLock();
g_intCount++;
LOS_IntRestore(intSave);
hwiIndex = HwiNumGet();
OsHookCall(LOS_HOOK_TYPE_ISR_ENTER, hwiIndex);
HalPreInterruptHandler(hwiIndex);
#if (LOSCFG_PLATFORM_HWI_WITH_ARG == 1)
if (g_hwiHandlerForm[hwiIndex].pfnHandler != 0) {
g_hwiHandlerForm[hwiIndex].pfnHandler((VOID *)g_hwiHandlerForm[hwiIndex].pParm);
}
#else
if (g_hwiHandlerForm[hwiIndex] != 0) {
g_hwiHandlerForm[hwiIndex]();
}
#endif
HalAftInterruptHandler(hwiIndex);
OsHookCall(LOS_HOOK_TYPE_ISR_EXIT, hwiIndex);
intSave = LOS_IntLock();
g_intCount--;
LOS_IntRestore(intSave);
}
/* ****************************************************************************
Function : ArchHwiCreate
Description : create hardware interrupt
Input : hwiNum --- hwi num to create
hwiPrio --- priority of the hwi
mode --- unused
handler --- hwi handler
arg --- param of the hwi handler
Output : None
Return : LOS_OK on success or error code on failure
**************************************************************************** */
LITE_OS_SEC_TEXT_INIT UINT32 ArchHwiCreate(HWI_HANDLE_T hwiNum,
HWI_PRIOR_T hwiPrio,
HWI_MODE_T mode,
HWI_PROC_FUNC handler,
HWI_ARG_T arg)
{
(VOID)mode;
UINT32 intSave;
if (handler == NULL) {
return OS_ERRNO_HWI_PROC_FUNC_NULL;
}
if (hwiNum >= OS_HWI_MAX_NUM) {
return OS_ERRNO_HWI_NUM_INVALID;
}
if (g_hwiForm[hwiNum + OS_SYS_VECTOR_CNT] != (HWI_PROC_FUNC)HalHwiDefaultHandler) {
return OS_ERRNO_HWI_ALREADY_CREATED;
}
if (hwiPrio > OS_HWI_PRIO_LOWEST) {
return OS_ERRNO_HWI_PRIO_INVALID;
}
intSave = LOS_IntLock();
#if (LOSCFG_PLATFORM_HWI_WITH_ARG == 1)
OsSetVector(hwiNum, handler, arg);
#else
(VOID)arg;
OsSetVector(hwiNum, handler);
#endif
HwiUnmask((IRQn_Type)hwiNum);
HwiSetPriority((IRQn_Type)hwiNum, hwiPrio);
LOS_IntRestore(intSave);
return LOS_OK;
}
/* ****************************************************************************
Function : ArchHwiDelete
Description : Delete hardware interrupt
Input : hwiNum --- hwi num to delete
Output : None
Return : LOS_OK on success or error code on failure
**************************************************************************** */
LITE_OS_SEC_TEXT_INIT UINT32 ArchHwiDelete(HWI_HANDLE_T hwiNum)
{
UINT32 intSave;
if (hwiNum >= OS_HWI_MAX_NUM) {
return OS_ERRNO_HWI_NUM_INVALID;
}
HwiMask((IRQn_Type)hwiNum);
intSave = LOS_IntLock();
g_hwiForm[hwiNum + OS_SYS_VECTOR_CNT] = (HWI_PROC_FUNC)HalHwiDefaultHandler;
LOS_IntRestore(intSave);
return LOS_OK;
}
#define FAULT_STATUS_REG_BIT 32
#define USGFAULT (1 << 18)
#define BUSFAULT (1 << 17)
#define MEMFAULT (1 << 16)
#define DIV0FAULT (1 << 4)
#define UNALIGNFAULT (1 << 3)
#define HARDFAULT_IRQN (-13)
ExcInfo g_excInfo = {0};
UINT8 g_uwExcTbl[FAULT_STATUS_REG_BIT] = {
0, 0, 0, 0,
0, 0, OS_EXC_UF_DIVBYZERO, OS_EXC_UF_UNALIGNED,
0, 0, 0, OS_EXC_UF_STKOF,
OS_EXC_UF_NOCP, OS_EXC_UF_INVPC, OS_EXC_UF_INVSTATE, OS_EXC_UF_UNDEFINSTR,
0, 0, OS_EXC_BF_LSPERR, OS_EXC_BF_STKERR,
OS_EXC_BF_UNSTKERR, OS_EXC_BF_IMPRECISERR, OS_EXC_BF_PRECISERR, OS_EXC_BF_IBUSERR,
0, 0, OS_EXC_MF_MLSPERR, OS_EXC_MF_MSTKERR,
OS_EXC_MF_MUNSTKERR, 0, OS_EXC_MF_DACCVIOL, OS_EXC_MF_IACCVIOL
};
#if (LOSCFG_KERNEL_PRINTF != 0)
STATIC VOID OsExcNvicDump(VOID)
{
#define OS_NR_NVIC_EXC_DUMP_TYPES 7
UINT32 *base = NULL;
UINT32 len, i, j;
UINT32 rgNvicBases[OS_NR_NVIC_EXC_DUMP_TYPES] = {
OS_NVIC_SETENA_BASE, OS_NVIC_SETPEND_BASE, OS_NVIC_INT_ACT_BASE,
OS_NVIC_PRI_BASE, OS_NVIC_EXCPRI_BASE, OS_NVIC_SHCSR, OS_NVIC_INT_CTRL
};
UINT32 rgNvicLens[OS_NR_NVIC_EXC_DUMP_TYPES] = {
OS_NVIC_INT_ENABLE_SIZE, OS_NVIC_INT_PEND_SIZE, OS_NVIC_INT_ACT_SIZE,
OS_NVIC_INT_PRI_SIZE, OS_NVIC_EXCPRI_SIZE, OS_NVIC_SHCSR_SIZE,
OS_NVIC_INT_CTRL_SIZE
};
CHAR strRgEnable[] = "enable";
CHAR strRgPending[] = "pending";
CHAR strRgActive[] = "active";
CHAR strRgPriority[] = "priority";
CHAR strRgException[] = "exception";
CHAR strRgShcsr[] = "shcsr";
CHAR strRgIntCtrl[] = "control";
CHAR *strRgs[] = {
strRgEnable, strRgPending, strRgActive, strRgPriority,
strRgException, strRgShcsr, strRgIntCtrl
};
PRINTK("\r\nOS exception NVIC dump:\n");
for (i = 0; i < OS_NR_NVIC_EXC_DUMP_TYPES; i++) {
base = (UINT32 *)rgNvicBases[i];
len = rgNvicLens[i];
PRINTK("interrupt %s register, base address: %p, size: 0x%x\n", strRgs[i], base, len);
len = (len >> 2); /* 2: Gets the next register offset */
for (j = 0; j < len; j++) {
PRINTK("0x%x ", *(base + j));
if ((j != 0) && ((j % 16) == 0)) { /* 16: print wrap line */
PRINTK("\n");
}
}
PRINTK("\n");
}
}
STATIC VOID OsExcTypeInfo(const ExcInfo *excInfo)
{
CHAR *phaseStr[] = {"exc in init", "exc in task", "exc in hwi"};
PRINTK("Type = %d\n", excInfo->type);
PRINTK("ThrdPid = %d\n", excInfo->thrdPid);
PRINTK("Phase = %s\n", phaseStr[excInfo->phase]);
PRINTK("FaultAddr = 0x%x\n", excInfo->faultAddr);
}
STATIC VOID OsExcCurTaskInfo(const ExcInfo *excInfo)
{
PRINTK("Current task info:\n");
if (excInfo->phase == OS_EXC_IN_TASK) {
LosTaskCB *taskCB = OS_TCB_FROM_TID(LOS_CurTaskIDGet());
PRINTK("Task name = %s\n", taskCB->taskName);
PRINTK("Task ID = %d\n", taskCB->taskID);
PRINTK("Task SP = %p\n", taskCB->stackPointer);
PRINTK("Task ST = 0x%x\n", taskCB->topOfStack);
PRINTK("Task SS = 0x%x\n", taskCB->stackSize);
} else if (excInfo->phase == OS_EXC_IN_HWI) {
PRINTK("Exception occur in interrupt phase!\n");
} else {
PRINTK("Exception occur in system init phase!\n");
}
}
STATIC VOID OsExcRegInfo(const ExcInfo *excInfo)
{
PRINTK("Exception reg dump:\n");
PRINTK("PC = 0x%x\n", excInfo->context->uwPC);
PRINTK("LR = 0x%x\n", excInfo->context->uwLR);
PRINTK("SP = 0x%x\n", excInfo->context->uwSP);
PRINTK("R0 = 0x%x\n", excInfo->context->uwR0);
PRINTK("R1 = 0x%x\n", excInfo->context->uwR1);
PRINTK("R2 = 0x%x\n", excInfo->context->uwR2);
PRINTK("R3 = 0x%x\n", excInfo->context->uwR3);
PRINTK("R4 = 0x%x\n", excInfo->context->uwR4);
PRINTK("R5 = 0x%x\n", excInfo->context->uwR5);
PRINTK("R6 = 0x%x\n", excInfo->context->uwR6);
PRINTK("R7 = 0x%x\n", excInfo->context->uwR7);
PRINTK("R8 = 0x%x\n", excInfo->context->uwR8);
PRINTK("R9 = 0x%x\n", excInfo->context->uwR9);
PRINTK("R10 = 0x%x\n", excInfo->context->uwR10);
PRINTK("R11 = 0x%x\n", excInfo->context->uwR11);
PRINTK("R12 = 0x%x\n", excInfo->context->uwR12);
PRINTK("PriMask = 0x%x\n", excInfo->context->uwPriMask);
PRINTK("xPSR = 0x%x\n", excInfo->context->uwxPSR);
}
#if (LOSCFG_KERNEL_BACKTRACE == 1)
STATIC VOID OsExcBackTraceInfo(const ExcInfo *excInfo)
{
UINTPTR LR[LOSCFG_BACKTRACE_DEPTH] = {0};
UINT32 index;
OsBackTraceHookCall(LR, LOSCFG_BACKTRACE_DEPTH, 0, excInfo->context->uwSP);
PRINTK("----- backtrace start -----\n");
for (index = 0; index < LOSCFG_BACKTRACE_DEPTH; index++) {
if (LR[index] == 0) {
break;
}
PRINTK("backtrace %d -- lr = 0x%x\n", index, LR[index]);
}
PRINTK("----- backtrace end -----\n");
}
#endif
STATIC VOID OsExcMemPoolCheckInfo(VOID)
{
PRINTK("\r\nmemory pools check:\n");
#if (LOSCFG_PLATFORM_EXC == 1)
MemInfoCB memExcInfo[OS_SYS_MEM_NUM];
UINT32 errCnt;
UINT32 i;
(VOID)memset_s(memExcInfo, sizeof(memExcInfo), 0, sizeof(memExcInfo));
errCnt = OsMemExcInfoGet(OS_SYS_MEM_NUM, memExcInfo);
if (errCnt < OS_SYS_MEM_NUM) {
errCnt += OsMemboxExcInfoGet(OS_SYS_MEM_NUM - errCnt, memExcInfo + errCnt);
}
if (errCnt == 0) {
PRINTK("all memory pool check passed!\n");
return;
}
for (i = 0; i < errCnt; i++) {
PRINTK("pool num = %d\n", i);
PRINTK("pool type = %d\n", memExcInfo[i].type);
PRINTK("pool addr = 0x%x\n", memExcInfo[i].startAddr);
PRINTK("pool size = 0x%x\n", memExcInfo[i].size);
PRINTK("pool free = 0x%x\n", memExcInfo[i].free);
PRINTK("pool blkNum = %d\n", memExcInfo[i].blockSize);
PRINTK("pool error node addr = 0x%x\n", memExcInfo[i].errorAddr);
PRINTK("pool error node len = 0x%x\n", memExcInfo[i].errorLen);
PRINTK("pool error node owner = %d\n", memExcInfo[i].errorOwner);
}
#endif
UINT32 ret = LOS_MemIntegrityCheck(LOSCFG_SYS_HEAP_ADDR);
if (ret == LOS_OK) {
PRINTK("system heap memcheck over, all passed!\n");
}
PRINTK("memory pool check end!\n");
}
#endif
STATIC VOID OsExcInfoDisplay(const ExcInfo *excInfo)
{
#if (LOSCFG_KERNEL_PRINTF != 0)
PRINTK("*************Exception Information**************\n");
OsExcTypeInfo(excInfo);
OsExcCurTaskInfo(excInfo);
OsExcRegInfo(excInfo);
#if (LOSCFG_KERNEL_BACKTRACE == 1)
OsExcBackTraceInfo(excInfo);
#endif
OsGetAllTskInfo();
OsExcNvicDump();
OsExcMemPoolCheckInfo();
#endif
}
LITE_OS_SEC_TEXT_INIT VOID HalExcHandleEntry(UINT32 excType, UINT32 faultAddr, UINT32 pid, EXC_CONTEXT_S *excBufAddr)
{
UINT16 tmpFlag = (excType >> 16) & OS_NULL_SHORT; /* 16: Get Exception Type */
g_intCount++;
g_excInfo.nestCnt++;
g_excInfo.type = excType & OS_NULL_SHORT;
if (tmpFlag & OS_EXC_FLAG_FAULTADDR_VALID) {
g_excInfo.faultAddr = faultAddr;
} else {
g_excInfo.faultAddr = OS_EXC_IMPRECISE_ACCESS_ADDR;
}
if (g_losTask.runTask != NULL) {
if (tmpFlag & OS_EXC_FLAG_IN_HWI) {
g_excInfo.phase = OS_EXC_IN_HWI;
g_excInfo.thrdPid = pid;
} else {
g_excInfo.phase = OS_EXC_IN_TASK;
g_excInfo.thrdPid = g_losTask.runTask->taskID;
}
} else {
g_excInfo.phase = OS_EXC_IN_INIT;
g_excInfo.thrdPid = OS_NULL_INT;
}
if (excType & OS_EXC_FLAG_NO_FLOAT) {
g_excInfo.context = (EXC_CONTEXT_S *)((CHAR *)excBufAddr - LOS_OFF_SET_OF(EXC_CONTEXT_S, uwR4));
} else {
g_excInfo.context = excBufAddr;
}
OsDoExcHook(EXC_INTERRUPT);
OsExcInfoDisplay(&g_excInfo);
ArchSysExit();
}
/* ****************************************************************************
Function : HalHwiInit
Description : initialization of the hardware interrupt
Input : None
Output : None
Return : None
**************************************************************************** */
LITE_OS_SEC_TEXT_INIT VOID HalHwiInit(VOID)
{
#if (LOSCFG_USE_SYSTEM_DEFINED_INTERRUPT == 1)
UINT32 index;
g_hwiForm[0] = 0; /* [0] Top of Stack */
g_hwiForm[1] = 0; /* [1] reset */
for (index = DEF_HANDLER_START_INDEX; index < OS_VECTOR_CNT; index++) {
g_hwiForm[index] = (HWI_PROC_FUNC)HalHwiDefaultHandler;
}
/* Exception handler register */
g_hwiForm[NonMaskableInt_IRQn + OS_SYS_VECTOR_CNT] = HalExcNMI;
g_hwiForm[HARDFAULT_IRQN + OS_SYS_VECTOR_CNT] = HalExcHardFault;
g_hwiForm[MemoryManagement_IRQn + OS_SYS_VECTOR_CNT] = HalExcMemFault;
g_hwiForm[BusFault_IRQn + OS_SYS_VECTOR_CNT] = HalExcBusFault;
g_hwiForm[UsageFault_IRQn + OS_SYS_VECTOR_CNT] = HalExcUsageFault;
g_hwiForm[SVCall_IRQn + OS_SYS_VECTOR_CNT] = HalSVCHandler;
g_hwiForm[PendSV_IRQn + OS_SYS_VECTOR_CNT] = HalPendSV;
g_hwiForm[SysTick_IRQn + OS_SYS_VECTOR_CNT] = OsTickHandler;
/* Interrupt vector table location */
SCB->VTOR = (UINT32)(UINTPTR)g_hwiForm;
#endif
#if (__CORTEX_M >= 0x03U) /* only for Cortex-M3 and above */
NVIC_SetPriorityGrouping(OS_NVIC_AIRCR_PRIGROUP);
#endif
/* Enable USGFAULT, BUSFAULT, MEMFAULT */
*(volatile UINT32 *)OS_NVIC_SHCSR |= (USGFAULT | BUSFAULT | MEMFAULT);
/* Enable DIV 0 and unaligned exception */
#ifdef LOSCFG_ARCH_UNALIGNED_EXC
*(volatile UINT32 *)OS_NVIC_CCR |= (DIV0FAULT | UNALIGNFAULT);
#else
*(volatile UINT32 *)OS_NVIC_CCR |= (DIV0FAULT);
#endif
return;
}

View File

@@ -0,0 +1,127 @@
/*
* 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_timer.h"
#include "los_config.h"
#include "los_tick.h"
#include "los_arch_interrupt.h"
#include "los_debug.h"
STATIC UINT32 SysTickStart(HWI_PROC_FUNC handler);
STATIC UINT64 SysTickReload(UINT64 nextResponseTime);
STATIC UINT64 SysTickCycleGet(UINT32 *period);
STATIC VOID SysTickLock(VOID);
STATIC VOID SysTickUnlock(VOID);
STATIC ArchTickTimer g_archTickTimer = {
.freq = 0,
.irqNum = SysTick_IRQn,
.periodMax = LOSCFG_BASE_CORE_TICK_RESPONSE_MAX,
.init = SysTickStart,
.getCycle = SysTickCycleGet,
.reload = SysTickReload,
.lock = SysTickLock,
.unlock = SysTickUnlock,
.tickHandler = NULL,
};
STATIC UINT32 SysTickStart(HWI_PROC_FUNC handler)
{
UINT32 ret;
ArchTickTimer *tick = &g_archTickTimer;
tick->freq = OS_SYS_CLOCK;
#if (LOSCFG_USE_SYSTEM_DEFINED_INTERRUPT == 1)
#if (LOSCFG_PLATFORM_HWI_WITH_ARG == 1)
OsSetVector(tick->irqNum, handler, NULL);
#else
OsSetVector(tick->irqNum, handler);
#endif
#endif
ret = SysTick_Config(LOSCFG_BASE_CORE_TICK_RESPONSE_MAX);
if (ret == 1) {
return LOS_ERRNO_TICK_PER_SEC_TOO_SMALL;
}
return LOS_OK;
}
STATIC UINT64 SysTickReload(UINT64 nextResponseTime)
{
if (nextResponseTime > g_archTickTimer.periodMax) {
nextResponseTime = g_archTickTimer.periodMax;
}
SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk;
SysTick->LOAD = (UINT32)(nextResponseTime - 1UL); /* set reload register */
SysTick->VAL = 0UL; /* Load the SysTick Counter Value */
NVIC_ClearPendingIRQ(SysTick_IRQn);
SysTick->CTRL |= SysTick_CTRL_ENABLE_Msk;
return nextResponseTime;
}
STATIC UINT64 SysTickCycleGet(UINT32 *period)
{
UINT32 hwCycle = 0;
UINT32 intSave = LOS_IntLock();
UINT32 val = SysTick->VAL;
*period = SysTick->LOAD;
if (val != 0) {
hwCycle = *period - val;
}
LOS_IntRestore(intSave);
return (UINT64)hwCycle;
}
STATIC VOID SysTickLock(VOID)
{
SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk;
}
STATIC VOID SysTickUnlock(VOID)
{
SysTick->CTRL |= SysTick_CTRL_ENABLE_Msk;
}
ArchTickTimer *ArchSysTickTimerGet(VOID)
{
return &g_archTickTimer;
}
UINT32 ArchEnterSleep(VOID)
{
__DSB();
__WFI();
__ISB();
return LOS_OK;
}

View File

@@ -198,11 +198,13 @@ LITE_OS_SEC_TEXT_MINOR VOID HalHwiDefaultHandler(VOID)
WEAK VOID HalPreInterruptHandler(UINT32 arg)
{
(VOID)arg;
return;
}
WEAK VOID HalAftInterruptHandler(UINT32 arg)
{
(VOID)arg;
return;
}
@@ -268,6 +270,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 ArchHwiCreate(HWI_HANDLE_T hwiNum,
HWI_PROC_FUNC handler,
HWI_ARG_T arg)
{
(VOID)mode;
UINT32 intSave;
if (handler == NULL) {
@@ -290,6 +293,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 ArchHwiCreate(HWI_HANDLE_T hwiNum,
#if (LOSCFG_PLATFORM_HWI_WITH_ARG == 1)
OsSetVector(hwiNum, handler, arg);
#else
(VOID)arg;
OsSetVector(hwiNum, handler);
#endif
HwiUnmask((IRQn_Type)hwiNum);

View File

@@ -36,7 +36,7 @@
#include "los_debug.h"
STATIC UINT32 SysTickStart(HWI_PROC_FUNC handler);
STATIC VOID SysTickReload(UINT64 nextResponseTime);
STATIC UINT64 SysTickReload(UINT64 nextResponseTime);
STATIC UINT64 SysTickCycleGet(UINT32 *period);
STATIC VOID SysTickLock(VOID);
STATIC VOID SysTickUnlock(VOID);
@@ -44,6 +44,7 @@ STATIC VOID SysTickUnlock(VOID);
STATIC ArchTickTimer g_archTickTimer = {
.freq = 0,
.irqNum = SysTick_IRQn,
.periodMax = LOSCFG_BASE_CORE_TICK_RESPONSE_MAX,
.init = SysTickStart,
.getCycle = SysTickCycleGet,
.reload = SysTickReload,
@@ -75,13 +76,17 @@ STATIC UINT32 SysTickStart(HWI_PROC_FUNC handler)
return LOS_OK;
}
STATIC VOID SysTickReload(UINT64 nextResponseTime)
STATIC UINT64 SysTickReload(UINT64 nextResponseTime)
{
if (nextResponseTime > g_archTickTimer.periodMax) {
nextResponseTime = g_archTickTimer.periodMax;
}
SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk;
SysTick->LOAD = (UINT32)(nextResponseTime - 1UL); /* set reload register */
SysTick->VAL = 0UL; /* Load the SysTick Counter Value */
NVIC_ClearPendingIRQ(SysTick_IRQn);
SysTick->CTRL |= SysTick_CTRL_ENABLE_Msk;
return nextResponseTime;
}
STATIC UINT64 SysTickCycleGet(UINT32 *period)

View File

@@ -205,11 +205,13 @@ LITE_OS_SEC_TEXT_MINOR VOID HalHwiDefaultHandler(VOID)
WEAK VOID HalPreInterruptHandler(UINT32 arg)
{
(VOID)arg;
return;
}
WEAK VOID HalAftInterruptHandler(UINT32 arg)
{
(VOID)arg;
return;
}
@@ -275,6 +277,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 ArchHwiCreate(HWI_HANDLE_T hwiNum,
HWI_PROC_FUNC handler,
HWI_ARG_T arg)
{
(VOID)mode;
UINT32 intSave;
if (handler == NULL) {
@@ -297,6 +300,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 ArchHwiCreate(HWI_HANDLE_T hwiNum,
#if (LOSCFG_PLATFORM_HWI_WITH_ARG == 1)
OsSetVector(hwiNum, handler, arg);
#else
(VOID)arg;
OsSetVector(hwiNum, handler);
#endif
HwiUnmask((IRQn_Type)hwiNum);

View File

@@ -36,7 +36,7 @@
#include "los_debug.h"
STATIC UINT32 SysTickStart(HWI_PROC_FUNC handler);
STATIC VOID SysTickReload(UINT64 nextResponseTime);
STATIC UINT64 SysTickReload(UINT64 nextResponseTime);
STATIC UINT64 SysTickCycleGet(UINT32 *period);
STATIC VOID SysTickLock(VOID);
STATIC VOID SysTickUnlock(VOID);
@@ -44,6 +44,7 @@ STATIC VOID SysTickUnlock(VOID);
STATIC ArchTickTimer g_archTickTimer = {
.freq = 0,
.irqNum = SysTick_IRQn,
.periodMax = LOSCFG_BASE_CORE_TICK_RESPONSE_MAX,
.init = SysTickStart,
.getCycle = SysTickCycleGet,
.reload = SysTickReload,
@@ -75,13 +76,17 @@ STATIC UINT32 SysTickStart(HWI_PROC_FUNC handler)
return LOS_OK;
}
STATIC VOID SysTickReload(UINT64 nextResponseTime)
STATIC UINT64 SysTickReload(UINT64 nextResponseTime)
{
if (nextResponseTime > g_archTickTimer.periodMax) {
nextResponseTime = g_archTickTimer.periodMax;
}
SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk;
SysTick->LOAD = (UINT32)(nextResponseTime - 1UL); /* set reload register */
SysTick->VAL = 0UL; /* Load the SysTick Counter Value */
NVIC_ClearPendingIRQ(SysTick_IRQn);
SysTick->CTRL |= SysTick_CTRL_ENABLE_Msk;
return nextResponseTime;
}
STATIC UINT64 SysTickCycleGet(UINT32 *period)

View File

@@ -256,7 +256,7 @@ VOID OsSetVector(UINT32 num, HWI_PROC_FUNC vector)
**************************************************************************** */
STATIC UINT32 HwiNumGet(VOID)
{
return HalGetPsr();
return (HalGetPsr() >> PSR_VEC_OFFSET) & MASK_8_BITS;
}
HwiControllerOps g_archHwiOps = {
@@ -283,18 +283,19 @@ inline UINT32 ArchIsIntActive(VOID)
LITE_OS_SEC_TEXT_MINOR VOID HalHwiDefaultHandler(VOID)
{
UINT32 irqNum = HwiNumGet();
irqNum = (irqNum >> PSR_VEC_OFFSET) & MASK_8_BITS;
PRINT_ERR("%s irqnum:%x\n", __FUNCTION__, irqNum);
while (1) {}
}
WEAK VOID HalPreInterruptHandler(UINT32 arg)
{
(VOID)arg;
return;
}
WEAK VOID HalAftInterruptHandler(UINT32 arg)
{
(VOID)arg;
return;
}
@@ -315,7 +316,6 @@ LITE_OS_SEC_TEXT VOID HalInterrupt(VOID)
LOS_IntRestore(intSave);
hwiIndex = HwiNumGet();
hwiIndex = (hwiIndex >> PSR_VEC_OFFSET) & MASK_8_BITS;
OsHookCall(LOS_HOOK_TYPE_ISR_ENTER, hwiIndex);
HalPreInterruptHandler(hwiIndex);
@@ -356,6 +356,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 ArchHwiCreate(HWI_HANDLE_T hwiNum,
HWI_PROC_FUNC handler,
HWI_ARG_T arg)
{
(VOID)mode;
UINT32 intSave;
if (handler == NULL) {
@@ -377,6 +378,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 ArchHwiCreate(HWI_HANDLE_T hwiNum,
#if (LOSCFG_PLATFORM_HWI_WITH_ARG == 1)
OsSetVector(hwiNum, handler, arg);
#else
(VOID)arg;
OsSetVector(hwiNum, handler);
#endif
HwiUnmask(hwiNum);

View File

@@ -53,7 +53,7 @@ typedef struct {
#define TIM_INT_NUM 1
STATIC UINT32 SysTickStart(HWI_PROC_FUNC handler);
STATIC VOID SysTickReload(UINT64 nextResponseTime);
STATIC UINT64 SysTickReload(UINT64 nextResponseTime);
STATIC UINT64 SysTickCycleGet(UINT32 *period);
STATIC VOID SysTickLock(VOID);
STATIC VOID SysTickUnlock(VOID);
@@ -61,6 +61,7 @@ STATIC VOID SysTickUnlock(VOID);
STATIC ArchTickTimer g_archTickTimer = {
.freq = 0,
.irqNum = TIM_INT_NUM,
.periodMax = LOSCFG_BASE_CORE_TICK_RESPONSE_MAX,
.init = SysTickStart,
.getCycle = SysTickCycleGet,
.reload = SysTickReload,
@@ -98,12 +99,16 @@ STATIC UINT32 SysTickStart(HWI_PROC_FUNC handler)
return LOS_OK;
}
STATIC VOID SysTickReload(UINT64 nextResponseTime)
STATIC UINT64 SysTickReload(UINT64 nextResponseTime)
{
if (nextResponseTime > g_archTickTimer.periodMax) {
nextResponseTime = g_archTickTimer.periodMax;
}
SysTick->CTRL &= ~CORETIM_ENABLE;
SysTick->LOAD = (UINT32)(nextResponseTime - 1UL); /* set reload register */
SysTick->VAL = 0UL; /* Load the SysTick Counter Value */
SysTick->CTRL |= CORETIM_ENABLE;
return nextResponseTime;
}
STATIC UINT64 SysTickCycleGet(UINT32 *period)

View File

@@ -80,6 +80,7 @@ UINT32 ArchIsIntActive(VOID);
#define LOS_HwiDisable ArchIntDisable
#define LOS_HwiClear ArchIntClear
#define LOS_HwiSetPriority ArchIntSetPriority
#define LOS_HwiCurIrqNum ArchIntCurIrqNum
UINT32 ArchIntLock(VOID);
#define LOS_IntLock ArchIntLock
@@ -193,6 +194,14 @@ STATIC INLINE UINT32 ArchIntSetPriority(HWI_HANDLE_T hwiNum, HWI_PRIOR_T priorit
return g_archHwiOps.setIrqPriority(hwiNum, priority);
}
STATIC INLINE UINT32 ArchIntCurIrqNum(VOID)
{
if (g_archHwiOps.getCurIrqNum == NULL) {
return LOS_NOK;
}
return g_archHwiOps.getCurIrqNum();
}
STATIC INLINE HwiControllerOps *ArchIntOpsGet(VOID)
{
return &g_archHwiOps;

View File

@@ -56,9 +56,10 @@ extern "C" {
typedef struct {
UINT32 freq;
INT32 irqNum;
UINT64 periodMax;
UINT32 (*init)(HWI_PROC_FUNC tickHandler);
UINT64 (*getCycle)(UINT32 *period);
VOID (*reload)(UINT64 time);
UINT64 (*reload)(UINT64 time);
VOID (*lock)(VOID);
VOID (*unlock)(VOID);
HWI_PROC_FUNC tickHandler;

View File

@@ -47,7 +47,7 @@ STATIC HWI_PROC_FUNC g_sysTickHandler = (HWI_PROC_FUNC)NULL;
extern UINT32 g_intCount;
STATIC UINT32 SysTickStart(HWI_PROC_FUNC handler);
STATIC VOID SysTickReload(UINT64 nextResponseTime);
STATIC UINT64 SysTickReload(UINT64 nextResponseTime);
STATIC UINT64 SysTickCycleGet(UINT32 *period);
STATIC VOID SysTickLock(VOID);
STATIC VOID SysTickUnlock(VOID);
@@ -55,6 +55,7 @@ STATIC VOID SysTickUnlock(VOID);
STATIC ArchTickTimer g_archTickTimer = {
.freq = 0,
.irqNum = SysTimer_IRQn,
.periodMax = LOSCFG_BASE_CORE_TICK_RESPONSE_MAX,
.init = SysTickStart,
.getCycle = SysTickCycleGet,
.reload = SysTickReload,
@@ -95,9 +96,10 @@ void ArchTickSysTickHandler(void)
}
}
STATIC VOID SysTickReload(UINT64 nextResponseTime)
STATIC UINT64 SysTickReload(UINT64 nextResponseTime)
{
SysTick_Reload(nextResponseTime);
return nextResponseTime;
}
STATIC UINT64 SysTickCycleGet(UINT32 *period)

View File

@@ -39,7 +39,7 @@
#include "los_debug.h"
STATIC UINT32 SysTickStart(HWI_PROC_FUNC handler);
STATIC VOID SysTickReload(UINT64 nextResponseTime);
STATIC UINT64 SysTickReload(UINT64 nextResponseTime);
STATIC UINT64 SysTickCycleGet(UINT32 *period);
STATIC VOID SysTickLock(VOID);
STATIC VOID SysTickUnlock(VOID);
@@ -47,6 +47,7 @@ STATIC VOID SysTickUnlock(VOID);
STATIC ArchTickTimer g_archTickTimer = {
.freq = 0,
.irqNum = RISCV_MACH_TIMER_IRQ,
.periodMax = LOSCFG_BASE_CORE_TICK_RESPONSE_MAX,
.init = SysTickStart,
.getCycle = SysTickCycleGet,
.reload = SysTickReload,
@@ -75,7 +76,7 @@ STATIC UINT32 SysTickStart(HWI_PROC_FUNC handler)
return LOS_OK;
}
STATIC VOID SysTickReload(UINT64 nextResponseTime)
STATIC UINT64 SysTickReload(UINT64 nextResponseTime)
{
UINT64 timeMax = (UINT64)LOSCFG_BASE_CORE_TICK_RESPONSE_MAX - 1;
UINT64 timer;
@@ -94,6 +95,7 @@ STATIC VOID SysTickReload(UINT64 nextResponseTime)
WRITE_UINT32((UINT32)timer, MTIMERCMP);
WRITE_UINT32((UINT32)(timer >> SHIFT_32_BIT), MTIMERCMP + MTIMER_HI_OFFSET);
HalIrqEnable(RISCV_MACH_TIMER_IRQ);
return nextResponseTime;
}
STATIC UINT64 SysTickCycleGet(UINT32 *period)

View File

@@ -256,11 +256,13 @@ VOID HalHwiDefaultHandler(VOID)
WEAK VOID HalPreInterruptHandler(UINT32 arg)
{
(VOID)arg;
return;
}
WEAK VOID HalAftInterruptHandler(UINT32 arg)
{
(VOID)arg;
return;
}
@@ -324,6 +326,7 @@ UINT32 ArchHwiCreate(HWI_HANDLE_T hwiNum,
HWI_PROC_FUNC handler,
HWI_ARG_T arg)
{
(VOID)mode;
UINT32 intSave;
if (handler == NULL) {
@@ -346,6 +349,7 @@ UINT32 ArchHwiCreate(HWI_HANDLE_T hwiNum,
#if (LOSCFG_PLATFORM_HWI_WITH_ARG == 1)
OsSetVector(hwiNum, handler, arg);
#else
(VOID)arg;
OsSetVector(hwiNum, handler);
#endif
HwiUnmask(hwiNum);

View File

@@ -37,7 +37,7 @@
#include "los_debug.h"
STATIC UINT32 SysTickStart(HWI_PROC_FUNC handler);
STATIC VOID SysTickReload(UINT64 nextResponseTime);
STATIC UINT64 SysTickReload(UINT64 nextResponseTime);
STATIC UINT64 SysTickCycleGet(UINT32 *period);
STATIC VOID SysTickLock(VOID);
STATIC VOID SysTickUnlock(VOID);
@@ -45,6 +45,7 @@ STATIC VOID SysTickUnlock(VOID);
STATIC ArchTickTimer g_archTickTimer = {
.freq = 0,
.irqNum = OS_TICK_INT_NUM,
.periodMax = LOSCFG_BASE_CORE_TICK_RESPONSE_MAX,
.init = SysTickStart,
.getCycle = SysTickCycleGet,
.reload = SysTickReload,
@@ -77,12 +78,17 @@ STATIC UINT32 SysTickStart(HWI_PROC_FUNC handler)
return LOS_OK;
}
STATIC VOID SysTickReload(UINT64 nextResponseTime)
STATIC UINT64 SysTickReload(UINT64 nextResponseTime)
{
UINT32 timerL;
if (nextResponseTime > g_archTickTimer.periodMax) {
nextResponseTime = g_archTickTimer.periodMax;
}
timerL = GetCcount();
timerL += nextResponseTime;
SetCcompare(timerL);
return nextResponseTime;
}
STATIC UINT64 SysTickCycleGet(UINT32 *period)

View File

@@ -42,4 +42,9 @@ config LFS_MAX_MOUNT_SIZE
help
This is a global maximum number of mount points.
config LFS_MAX_OPEN_FILES
int "Maximum number of open files"
default 100
help
This is a global maximum number of open files.
endif # FS_LITTLEFS

View File

@@ -38,7 +38,7 @@ 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[LITTLE_FS_MAX_OPEN_FILES] = {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"};
@@ -46,7 +46,7 @@ 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 < LITTLE_FS_MAX_OPEN_FILES; i++) {
for (int i = 0; i < LOSCFG_LFS_MAX_OPEN_FILES; i++) {
if (g_handle[i].useFlag == 0) {
*fd = i;
g_handle[i].useFlag = 1;
@@ -78,7 +78,7 @@ static void LfsFreeFd(int fd)
BOOL CheckFileIsOpen(const char *fileName)
{
pthread_mutex_lock(&g_FslocalMutex);
for (int i = 0; i < LITTLE_FS_MAX_OPEN_FILES; i++) {
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);
@@ -92,7 +92,7 @@ BOOL CheckFileIsOpen(const char *fileName)
static BOOL LfsFdIsValid(int fd)
{
if (fd >= LITTLE_FS_MAX_OPEN_FILES || fd < 0) {
if (fd >= LOSCFG_LFS_MAX_OPEN_FILES || fd < 0) {
return FALSE;
}
if (g_handle[fd].lfsHandle == NULL) {

View File

@@ -31,7 +31,6 @@
#ifndef _LFS_CONF_H
#define _LFS_CONF_H
#define LITTLE_FS_MAX_OPEN_FILES 100
#define LITTLE_FS_STANDARD_NAME_LENGTH 50
#define LITTLE_FS_MAX_NAME_LEN 255

View File

@@ -106,7 +106,7 @@
#ifdef LOSCFG_FS_LITTLEFS
#include "lfs_conf.h"
#define __LFS_NFILE LITTLE_FS_MAX_OPEN_FILES
#define __LFS_NFILE LOSCFG_LFS_MAX_OPEN_FILES
#else
#define __LFS_NFILE 0
#endif

View File

@@ -31,8 +31,11 @@
#include "los_pm.h"
#include "securec.h"
#include "los_sched.h"
#include "los_timer.h"
#include "los_task.h"
#include "los_tick.h"
#include "los_event.h"
#include "los_sched.h"
#include "los_memory.h"
#include "los_swtmr.h"
@@ -70,7 +73,6 @@ typedef struct {
STATIC EVENT_CB_S g_pmEvent;
STATIC LosPmCB g_pmCB;
STATIC LosPmSysctrl g_sysctrl;
STATIC UINT64 g_pmSleepTime;
STATIC VOID OsPmSysctrlInit(VOID)
{
@@ -122,7 +124,7 @@ STATIC BOOL OsPmTickTimerStop(LosPmCB *pm)
{
#if (LOSCFG_BASE_CORE_TICK_WTIMER == 0)
UINT64 sleepCycle;
UINT64 realSleepTime = g_pmSleepTime;
UINT64 realSleepTime = OsSchedGetNextExpireTime(OsGetCurrSchedTimeCycle());
#endif
LosPmTickTimer *tickTimer = pm->tickTimer;
@@ -239,7 +241,6 @@ STATIC UINT32 OsPmSuspendSleep(LosPmCB *pm)
LOS_SysSleepEnum mode;
UINT32 prepare = 0;
BOOL tickTimerStop = FALSE;
UINT64 currTime;
ret = OsPmSuspendCheck(pm, &sysSuspendEarly, &deviceSuspend, &mode);
if (ret != LOS_OK) {
@@ -261,9 +262,8 @@ STATIC UINT32 OsPmSuspendSleep(LosPmCB *pm)
tickTimerStop = OsPmTickTimerStop(pm);
if (!tickTimerStop) {
currTime = OsGetCurrSchedTimeCycle();
OsSchedResetSchedResponseTime(0);
OsSchedUpdateExpireTime(currTime);
OsSchedUpdateExpireTime();
}
OsPmCpuSuspend(pm);
@@ -723,11 +723,6 @@ UINT32 LOS_PmSuspend(UINT32 wakeCount)
return OsPmSuspendSleep(&g_pmCB);
}
STATIC VOID OsPmSleepTimeSet(UINT64 sleepTime)
{
g_pmSleepTime = sleepTime;
}
BOOL OsIsPmMode(VOID)
{
LosPmCB *pm = &g_pmCB;
@@ -752,11 +747,6 @@ UINT32 OsPmInit(VOID)
LOS_ListInit(&pm->lockList);
(VOID)LOS_EventInit(&g_pmEvent);
ret = OsSchedRealSleepTimeSet(OsPmSleepTimeSet);
if (ret != LOS_OK) {
return ret;
}
ret = OsPmEnterHandlerSet(OsPmNormalSleep);
if (ret != LOS_OK) {
return ret;

7
components/shell/src/base/shmsg.c Executable file → Normal file
View File

@@ -212,10 +212,15 @@ VOID ShellTaskEntry(VOID)
(VOID)LOS_EventRead(&g_shellInputEvent, 0x1, LOS_WAITMODE_AND | LOS_WAITMODE_CLR, LOS_WAIT_FOREVER);
while ((*ptr = (UINT8)UartGetc()) != 0 && *ptr != 13) {
if (*ptr == '\x03') { /* ctrl + c */
PRINTK("^C\n\rOHOS # ", *ptr);
PRINTK("^C\n\rOHOS # ");
ptr = buf;
break;
}
if (*ptr == '\b' && ptr != buf) { /* support backspace */
PRINTK("\b \b");
ptr--;
break;
}
if (!VISIABLE_CHAR(*ptr)) {
break;
}

View File

@@ -29,6 +29,7 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdint.h>
#include "securec.h"
#include "los_config.h"
#include "los_memory.h"
@@ -39,7 +40,7 @@ void *calloc(size_t nitems, size_t size)
size_t real_size;
void *ptr = NULL;
if (nitems == 0 || size == 0) {
if ((nitems == 0) || (size == 0) || (nitems > (UINT32_MAX / size))) {
return NULL;
}

View File

@@ -40,7 +40,6 @@ kernel_module(module_name) {
"porting/src/network/ntohl.c",
"porting/src/network/ntohs.c",
"porting/src/other_adapt.c",
"porting/src/pthread.c",
"porting/src/time.c",
]
configs += [ "$LITEOSTOPDIR:warn_config" ]

View File

@@ -57,6 +57,7 @@
#undef _PTHREAD_ONCE_INIT
#undef PTHREAD_STACK_MIN
#undef PTHREAD_MUTEX_DEFAULT
#include "los_config.h"
#define PTHREAD_STACK_MIN LOSCFG_BASE_CORE_TSK_MIN_STACK_SIZE
@@ -76,17 +77,18 @@ typedef struct {
} pthread_attr_t;
#include "los_list.h"
typedef struct { unsigned int magic; unsigned int handle; } pthread_mutex_t;
typedef struct { unsigned type; } pthread_mutexattr_t;
typedef struct { unsigned int magic; unsigned int handle; pthread_mutexattr_t stAttr;} pthread_mutex_t;
#define _MUX_MAGIC 0xEBCFDEA0
#define _MUX_INVALID_HANDLE 0xEEEEEEEF
#define PTHREAD_MUTEX_DEFAULT 0
#define _PTHREAD_MUTEX_INITIALIZER { _MUX_MAGIC, _MUX_INVALID_HANDLE }
#define PTHREAD_MUTEXATTR_INITIALIZER { PTHREAD_MUTEX_RECURSIVE }
#define _PTHREAD_MUTEX_INITIALIZER { _MUX_MAGIC, _MUX_INVALID_HANDLE, PTHREAD_MUTEXATTR_INITIALIZER }
#ifdef _GNU_SOURCE
#define PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP { _MUX_MAGIC, _MUX_INVALID_HANDLE }
#define PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP { _MUX_MAGIC, _MUX_INVALID_HANDLE, PTHREAD_MUTEXATTR_INITIALIZER }
#endif
#include "los_event.h"

View File

@@ -49,6 +49,7 @@
#define _POSIX_TIMEOUTS
#define _POSIX_THREAD_PRIORITY_SCHEDULING
#define _UNIX98_THREAD_MUTEX_ATTRIBUTES
#define _POSIX_THREAD_PROCESS_SHARED
#include_next <sys/features.h>

View File

@@ -312,7 +312,7 @@ OUT:
int mq_close(mqd_t personal)
{
INT32 ret = 0;
INT32 ret = -1;
struct mqarray *mqueueCB = NULL;
struct mqpersonal *privateMqPersonal = NULL;
struct mqpersonal *tmp = NULL;
@@ -425,7 +425,7 @@ int OsMqSetAttr(mqd_t personal, const struct mq_attr *mqSetAttr, struct mq_attr
return 0;
}
int mq_getsetattr(mqd_t mqd, const struct mq_attr *new, struct mq_attr *old)
static int MqGetSetAttr(mqd_t mqd, const struct mq_attr *new, struct mq_attr *old)
{
if (new == NULL) {
return OsMqGetAttr(mqd, old);
@@ -439,7 +439,7 @@ int mq_getattr(mqd_t mqd, struct mq_attr *attr)
errno = EBADF;
return -1;
}
return mq_getsetattr(mqd, 0, attr);
return MqGetSetAttr(mqd, NULL, attr);
}
int mq_setattr(mqd_t mqd, const struct mq_attr *new, struct mq_attr *old)
@@ -452,7 +452,7 @@ int mq_setattr(mqd_t mqd, const struct mq_attr *new, struct mq_attr *old)
errno = EINVAL;
return -1;
}
return mq_getsetattr(mqd, new, old);
return MqGetSetAttr(mqd, new, old);
}
int mq_unlink(const char *mqName)
@@ -472,7 +472,9 @@ int mq_unlink(const char *mqName)
}
if (mqueueCB->mq_personal != NULL) {
errno = EINTR;
mqueueCB->unlinkflag = TRUE;
goto ERROUT_UNLOCK;
} else {
ret = DoMqueueDelete(mqueueCB);
}

View File

@@ -35,14 +35,17 @@
#include <unistd.h>
#include <securec.h>
#include <limits.h>
#include <stdbool.h>
#include "los_config.h"
#include "los_task.h"
#include "los_debug.h"
#define PTHREAD_DEFAULT_NAME "pthread"
#define PTHREAD_DEFAULT_NAME_LEN 8
#define PTHREAD_NAMELEN 16
#define PTHREAD_KEY_UNUSED 0
#define PTHREAD_KEY_USED 1
#define PTHREAD_TASK_INVAILD 0
typedef void (*PthreadKeyDtor)(void *);
typedef struct {
@@ -59,6 +62,9 @@ typedef struct {
char name[PTHREAD_NAMELEN];
uintptr_t *key;
LOS_DL_LIST threadList;
unsigned char cancelState;
unsigned char cancelType;
unsigned char canceled;
} PthreadData;
static void PthreadExitKeyDtor(PthreadData *pthreadData);
@@ -69,12 +75,21 @@ static void *PthreadEntry(UINT32 param)
void *(*startRoutine)(void *) = pthreadData->startRoutine;
void *ret = startRoutine(pthreadData->param);
pthread_exit(ret);
return ret;
}
static inline int IsPthread(pthread_t thread)
static inline bool IsPthread(pthread_t thread)
{
return ((UINT32)thread <= LOSCFG_BASE_CORE_TSK_LIMIT);
LosTaskCB *tcb = NULL;
if ((UINT32)thread >= LOSCFG_BASE_CORE_TSK_LIMIT) {
return false;
}
tcb = OS_TCB_FROM_TID((UINT32)thread);
if ((UINTPTR)tcb->taskEntry != (UINTPTR)PthreadEntry) {
return false;
}
return true;
}
static int PthreadCreateAttrInit(const pthread_attr_t *attr, void *(*startRoutine)(void *), void *arg,
@@ -121,6 +136,9 @@ static int PthreadCreateAttrInit(const pthread_attr_t *attr, void *(*startRoutin
return error;
}
pthreadData->cancelState = PTHREAD_CANCEL_ENABLE;
pthreadData->cancelType = PTHREAD_CANCEL_DEFERRED;
pthreadData->canceled = 0;
pthreadData->startRoutine = startRoutine;
pthreadData->param = arg;
pthreadData->key = NULL;
@@ -130,6 +148,29 @@ static int PthreadCreateAttrInit(const pthread_attr_t *attr, void *(*startRoutin
if (threadAttr->detachstate != PTHREAD_CREATE_DETACHED) {
taskInitParam->uwResved = LOS_TASK_ATTR_JOINABLE;
}
return 0;
}
static int CheckForCancel(void)
{
UINT32 intSave;
LosTaskCB *tcb = NULL;
pthread_t thread = pthread_self();
if (!IsPthread(thread)) {
PRINT_ERR("[%s:%d] This task %d is not a posix thread!!!\n", __FUNCTION__, __LINE__, thread);
return 0;
}
tcb = OS_TCB_FROM_TID((UINT32)thread);
intSave = LOS_IntLock();
PthreadData *pthreadData = (PthreadData *)(UINTPTR)tcb->arg;
if ((pthreadData->canceled) && (pthreadData->cancelState == PTHREAD_CANCEL_ENABLE)) {
LOS_IntRestore(intSave);
return 1;
}
LOS_IntRestore(intSave);
return 0;
}
@@ -167,13 +208,19 @@ int pthread_create(pthread_t *thread, const pthread_attr_t *attr,
(void)LOS_TaskResume(taskID);
*thread = (pthread_t)taskID;
return 0;
}
int pthread_setschedparam(pthread_t thread, int policy, const struct sched_param *param)
{
if (!IsPthread(thread)) {
PRINT_ERR("[%s:%d] This task %d is not a posix thread!!!\n", __FUNCTION__, __LINE__, thread);
return EINVAL;
}
if ((param == NULL) || (param->sched_priority < OS_TASK_PRIORITY_HIGHEST) ||
(param->sched_priority >= OS_TASK_PRIORITY_LOWEST) || !IsPthread(thread)) {
(param->sched_priority >= OS_TASK_PRIORITY_LOWEST)) {
return EINVAL;
}
@@ -189,11 +236,127 @@ int pthread_setschedparam(pthread_t thread, int policy, const struct sched_param
return 0;
}
int pthread_setschedprio(pthread_t thread, int prio)
{
if (!IsPthread(thread)) {
PRINT_ERR("[%s:%d] This task %d is not a posix thread!!!\n", __FUNCTION__, __LINE__, thread);
return EINVAL;
}
if (LOS_TaskPriSet((UINT32)thread, (UINT16)prio) != LOS_OK) {
return EINVAL;
}
return 0;
}
int pthread_once(pthread_once_t *onceControl, void (*initRoutine)(void))
{
UINT32 intSave;
pthread_once_t old;
pthread_t thread = pthread_self();
if (!IsPthread(thread)) {
PRINT_ERR("[%s:%d] This task %d is not a posix thread!!!\n", __FUNCTION__, __LINE__, thread);
return EINVAL;
}
if ((onceControl == NULL) || (initRoutine == NULL)) {
return EINVAL;
}
intSave = LOS_IntLock();
old = *onceControl;
*onceControl = 1;
LOS_IntRestore(intSave);
if (!old) {
initRoutine();
}
return 0;
}
int pthread_equal(pthread_t thread1, pthread_t thread2)
{
return (int)(thread1 == thread2);
}
int pthread_setcancelstate(int state, int *oldState)
{
UINT32 intSave;
LosTaskCB *tcb = NULL;
PthreadData *pthreadData = NULL;
pthread_t thread = pthread_self();
if (!IsPthread(thread)) {
PRINT_ERR("[%s:%d] This task %d is not a posix thread!!!\n", __FUNCTION__, __LINE__, thread);
return EINVAL;
}
if ((state != PTHREAD_CANCEL_ENABLE) && (state != PTHREAD_CANCEL_DISABLE)) {
return EINVAL;
}
tcb = OS_TCB_FROM_TID((UINT32)thread);
intSave = LOS_IntLock();
pthreadData = (PthreadData *)(UINTPTR)tcb->arg;
if (pthreadData == NULL) {
LOS_IntRestore(intSave);
return EINVAL;
}
if (oldState != NULL) {
*oldState = pthreadData->cancelState;
}
pthreadData->cancelState = (UINT8)state;
LOS_IntRestore(intSave);
return 0;
}
int pthread_setcanceltype(int type, int *oldType)
{
UINT32 intSave;
LosTaskCB *tcb = NULL;
PthreadData *pthreadData = NULL;
pthread_t thread = pthread_self();
if (!IsPthread(thread)) {
PRINT_ERR("[%s:%d] This task %d is not a posix thread!!!\n", __FUNCTION__, __LINE__, thread);
return EINVAL;
}
if ((type != PTHREAD_CANCEL_ASYNCHRONOUS) && (type != PTHREAD_CANCEL_DEFERRED)) {
return EINVAL;
}
tcb = OS_TCB_FROM_TID((UINT32)thread);
intSave = LOS_IntLock();
pthreadData = (PthreadData *)(UINTPTR)tcb->arg;
if (pthreadData == NULL) {
LOS_IntRestore(intSave);
return EINVAL;
}
if (oldType != NULL) {
*oldType = pthreadData->cancelType;
}
pthreadData->cancelType = (UINT8)type;
LOS_IntRestore(intSave);
return 0;
}
int pthread_getschedparam(pthread_t thread, int *policy, struct sched_param *param)
{
UINT32 prio;
if ((policy == NULL) || (param == NULL) || !IsPthread(thread)) {
if (!IsPthread(thread)) {
PRINT_ERR("[%s:%d] This task %d is not a posix thread!!!\n", __FUNCTION__, __LINE__, thread);
return EINVAL;
}
if ((policy == NULL) || (param == NULL)) {
return EINVAL;
}
@@ -204,6 +367,7 @@ int pthread_getschedparam(pthread_t thread, int *policy, struct sched_param *par
*policy = SCHED_RR;
param->sched_priority = prio;
return 0;
}
@@ -212,21 +376,87 @@ pthread_t pthread_self(void)
return (pthread_t)LOS_CurTaskIDGet();
}
STATIC UINT32 DoPthreadCancel(LosTaskCB *task)
{
UINT32 ret = LOS_OK;
PthreadData *pthreadData = NULL;
LOS_TaskLock();
pthreadData = (PthreadData *)(UINTPTR)task->arg;
pthreadData->canceled = 0;
if ((task->taskStatus == PTHREAD_TASK_INVAILD) || (LOS_TaskSuspend(task->taskID) != LOS_OK)) {
ret = LOS_NOK;
goto OUT;
}
free((VOID *)(UINTPTR)task->arg);
task->arg = (UINT32)(UINTPTR)NULL;
(void)LOS_TaskDelete(task->taskID);
OUT:
LOS_TaskUnlock();
return ret;
}
int pthread_cancel(pthread_t thread)
{
UINT32 intSave;
LosTaskCB *tcb = NULL;
PthreadData *pthreadData = NULL;
if (!IsPthread(thread)) {
PRINT_ERR("[%s:%d] This task %d is not a posix thread!!!\n", __FUNCTION__, __LINE__, thread);
return EINVAL;
}
intSave = LOS_IntLock();
tcb = OS_TCB_FROM_TID((UINT32)thread);
pthreadData = (PthreadData *)(UINTPTR)tcb->arg;
pthreadData->canceled = 1;
if ((pthreadData->cancelState == PTHREAD_CANCEL_ENABLE) &&
(pthreadData->cancelType == PTHREAD_CANCEL_ASYNCHRONOUS)) {
/*
* If the thread has cancellation enabled, and it is in
* asynchronous mode, suspend it and set corresponding thread's status.
* We also release the thread out of any current wait to make it wake up.
*/
if (DoPthreadCancel(tcb) == LOS_NOK) {
LOS_IntRestore(intSave);
return ESRCH;
}
}
LOS_IntRestore(intSave);
return ENOSYS;
return 0;
}
void pthread_testcancel(void)
{
if (CheckForCancel()) {
/*
* If we have cancellation enabled, and there is a cancellation
* pending, then go ahead and do the deed.
* Exit now with special retVal. pthread_exit() calls the
* cancellation handlers implicitly.
*/
pthread_exit((void *)PTHREAD_CANCELED);
}
}
int pthread_join(pthread_t thread, void **retval)
{
UINTPTR result;
UINT32 ret = LOS_TaskJoin((UINT32)thread, &result);
UINT32 ret;
if (!IsPthread(thread)) {
PRINT_ERR("[%s:%d] This task %d is not a posix thread!!!\n", __FUNCTION__, __LINE__, thread);
return EINVAL;
}
ret = LOS_TaskJoin((UINT32)thread, &result);
if (ret == LOS_ERRNO_TSK_NOT_JOIN_SELF) {
return EDEADLK;
} else if ((ret == LOS_ERRNO_TSK_NOT_CREATED) ||
(ret == LOS_ERRNO_TSK_OPERATE_IDLE) ||
(ret == LOS_ERRNO_TSK_ID_INVALID) ||
(ret == LOS_ERRNO_TSK_SUSPEND_SWTMR_NOT_ALLOWED)) {
return ESRCH;
} else if (ret != LOS_OK) {
return EINVAL;
}
@@ -234,12 +464,19 @@ int pthread_join(pthread_t thread, void **retval)
if (retval != NULL) {
*retval = (VOID *)result;
}
return 0;
}
int pthread_detach(pthread_t thread)
{
UINT32 ret = LOS_TaskDetach((UINT32)thread);
UINT32 ret;
if (!IsPthread(thread)) {
PRINT_ERR("[%s:%d] This task %d is not a posix thread!!!\n", __FUNCTION__, __LINE__, thread);
return EINVAL;
}
ret = LOS_TaskDetach((UINT32)thread);
if (ret == LOS_ERRNO_TSK_NOT_JOIN) {
return ESRCH;
} else if (ret != LOS_OK) {
@@ -253,9 +490,18 @@ void pthread_exit(void *retVal)
{
UINT32 intSave;
LosTaskCB *tcb = OS_TCB_FROM_TID(LOS_CurTaskIDGet());
pthread_t thread = pthread_self();
if (!IsPthread(thread)) {
PRINT_ERR("[%s:%d] This task %d is not a posix thread!!!\n", __FUNCTION__, __LINE__, thread);
goto EXIT;
}
LosTaskCB *tcb = OS_TCB_FROM_TID((UINT32)thread);
tcb->joinRetval = (UINTPTR)retVal;
PthreadData *pthreadData = (PthreadData *)(UINTPTR)tcb->arg;
if (pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL) != 0) {
PRINT_ERR("%s: %d failed\n", __FUNCTION__, __LINE__);
}
if (pthreadData->key != NULL) {
PthreadExitKeyDtor(pthreadData);
@@ -267,6 +513,7 @@ void pthread_exit(void *retVal)
LOS_IntRestore(intSave);
free(pthreadData);
(void)LOS_TaskDelete(tcb->taskID);
EXIT:
while (1) {
}
}
@@ -275,8 +522,15 @@ int pthread_setname_np(pthread_t thread, const char *name)
{
UINT32 intSave;
LosTaskCB *taskCB = NULL;
char *taskName = LOS_TaskNameGet((UINT32)thread);
if (taskName == NULL || !IsPthread(thread)) {
char *taskName = NULL;
if (!IsPthread(thread)) {
PRINT_ERR("[%s:%d] This task %d is not a posix thread!!!\n", __FUNCTION__, __LINE__, thread);
return EINVAL;
}
taskName = LOS_TaskNameGet((UINT32)thread);
if (taskName == NULL) {
return EINVAL;
}
@@ -298,15 +552,22 @@ int pthread_setname_np(pthread_t thread, const char *name)
return EINVAL;
}
LOS_IntRestore(intSave);
return 0;
}
int pthread_getname_np(pthread_t thread, char *buf, size_t buflen)
{
int ret;
const char *name = NULL;
const char *name = LOS_TaskNameGet((UINT32)thread);
if (name == NULL || !IsPthread(thread)) {
if (!IsPthread(thread)) {
PRINT_ERR("[%s:%d] This task %d is not a posix thread!!!\n", __FUNCTION__, __LINE__, thread);
return EINVAL;
}
name = LOS_TaskNameGet((UINT32)thread);
if (name == NULL) {
return EINVAL;
}
if (buflen > strlen(name)) {
@@ -315,6 +576,7 @@ int pthread_getname_np(pthread_t thread, char *buf, size_t buflen)
return 0;
}
}
return ERANGE;
}
@@ -349,6 +611,12 @@ int pthread_key_create(pthread_key_t *k, void (*dtor)(void *))
unsigned int count = 0;
PthreadKey *keys = NULL;
pthread_t thread = pthread_self();
if (!IsPthread(thread)) {
PRINT_ERR("[%s:%d] This task %d is not a posix thread!!!\n", __FUNCTION__, __LINE__, thread);
return EINVAL;
}
if (k == NULL) {
return EINVAL;
}
@@ -373,6 +641,7 @@ int pthread_key_create(pthread_key_t *k, void (*dtor)(void *))
LOS_IntRestore(intSave);
*k = count;
return 0;
}
@@ -380,6 +649,12 @@ int pthread_key_delete(pthread_key_t k)
{
unsigned int intSave;
pthread_t thread = pthread_self();
if (!IsPthread(thread)) {
PRINT_ERR("[%s:%d] This task %d is not a posix thread!!!\n", __FUNCTION__, __LINE__, thread);
return EINVAL;
}
if (k >= PTHREAD_KEYS_MAX) {
return EINVAL;
}
@@ -406,20 +681,22 @@ int pthread_key_delete(pthread_key_t k)
g_pthreadKeyData[k].flag = PTHREAD_KEY_UNUSED;
g_pthreadkeyCount--;
LOS_IntRestore(intSave);
return 0;
}
int pthread_setspecific(pthread_key_t k, const void *x)
{
pthread_t self = pthread_self();
unsigned int intSave;
uintptr_t *key = NULL;
if (k >= PTHREAD_KEYS_MAX) {
pthread_t self = pthread_self();
if (!IsPthread(self)) {
PRINT_ERR("[%s:%d] This task %d is not a posix thread!!!\n", __FUNCTION__, __LINE__, self);
return EINVAL;
}
if (!IsPthread(self)) {
if (k >= PTHREAD_KEYS_MAX) {
return EINVAL;
}
@@ -446,6 +723,7 @@ int pthread_setspecific(pthread_key_t k, const void *x)
pthreadData->key[k] = (uintptr_t)x;
LOS_IntRestore(intSave);
return 0;
}
@@ -454,12 +732,12 @@ void *pthread_getspecific(pthread_key_t k)
unsigned int intSave;
void *key = NULL;
pthread_t self = pthread_self();
if (k >= PTHREAD_KEYS_MAX) {
if (!IsPthread(self)) {
PRINT_ERR("[%s:%d] This task %d is not a posix thread!!!\n", __FUNCTION__, __LINE__, self);
return NULL;
}
if (!IsPthread(self)) {
if (k >= PTHREAD_KEYS_MAX) {
return NULL;
}
@@ -473,6 +751,7 @@ void *pthread_getspecific(pthread_key_t k)
key = (void *)pthreadData->key[k];
LOS_IntRestore(intSave);
return key;
}

View File

@@ -29,10 +29,12 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "pthread.h"
#include <errno.h>
#include <securec.h>
#include <limits.h>
#include "pthread.h"
#include "los_config.h"
#include "los_debug.h"
int pthread_attr_init(pthread_attr_t *attr)
{
@@ -44,7 +46,7 @@ int pthread_attr_init(pthread_attr_t *attr)
attr->schedpolicy = SCHED_RR;
attr->schedparam.sched_priority = LOSCFG_BASE_CORE_TSK_DEFAULT_PRIO;
attr->inheritsched = PTHREAD_INHERIT_SCHED;
attr->scope = PTHREAD_SCOPE_PROCESS;
attr->scope = PTHREAD_SCOPE_SYSTEM;
attr->stackaddr_set = 0;
attr->stackaddr = NULL;
attr->stacksize_set = 1;
@@ -59,7 +61,8 @@ int pthread_attr_destroy(pthread_attr_t *attr)
return EINVAL;
}
/* Nothing to do here... */
(void)memset_s(attr, sizeof(pthread_attr_t), 0, sizeof(pthread_attr_t));
return 0;
}
@@ -90,12 +93,12 @@ int pthread_attr_setscope(pthread_attr_t *attr, int scope)
return EINVAL;
}
if (scope == PTHREAD_SCOPE_PROCESS) {
if (scope == PTHREAD_SCOPE_SYSTEM) {
attr->scope = (unsigned int)scope;
return 0;
}
if (scope == PTHREAD_SCOPE_SYSTEM) {
if (scope == PTHREAD_SCOPE_PROCESS) {
return ENOTSUP;
}
@@ -220,6 +223,28 @@ int pthread_attr_setstacksize(pthread_attr_t *attr, size_t stackSize)
return 0;
}
int pthread_attr_setstack(pthread_attr_t *attr, void *stackAddr, size_t stackSize)
{
(void)attr;
(void)stackAddr;
(void)stackSize;
PRINT_ERR("%s: Don't support the pthread stack func currently!\n", __FUNCTION__);
errno = ENOSYS;
return -1;
}
int pthread_attr_getstack(const pthread_attr_t *attr, void **stackAddr, size_t *stackSize)
{
(void)attr;
(void)stackAddr;
(void)stackSize;
PRINT_ERR("%s: Don't support the pthread stack func currently!\n", __FUNCTION__);
errno = ENOSYS;
return -1;
}
int pthread_attr_getstacksize(const pthread_attr_t *attr, size_t *stackSize)
{
/* Reject attempts to get a stack size when one has not been set. */

View File

@@ -29,7 +29,6 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "time_internal.h"
#include <errno.h>
#include <pthread.h>
#include <stdlib.h>
@@ -37,9 +36,11 @@
#include <securec.h>
#include "los_config.h"
#include "los_task.h"
#include <los_swtmr.h>
#include "los_swtmr.h"
#include "time_internal.h"
#include "los_atomic.h"
#include "los_event.h"
#include "los_mux.h"
typedef struct {
volatile INT32 *realValue;
@@ -54,6 +55,31 @@ typedef struct {
#define COND_FLAGS_MASK 0x0003U
#define COND_COUNTER_MASK (~COND_FLAGS_MASK)
int pthread_condattr_getpshared(const pthread_condattr_t *attr, int *shared)
{
if ((attr == NULL) || (shared == NULL)) {
return EINVAL;
}
*shared = PTHREAD_PROCESS_PRIVATE;
return 0;
}
int pthread_condattr_setpshared(pthread_condattr_t *attr, int shared)
{
(VOID)attr;
if ((shared != PTHREAD_PROCESS_PRIVATE) && (shared != PTHREAD_PROCESS_SHARED)) {
return EINVAL;
}
if (shared != PTHREAD_PROCESS_PRIVATE) {
return ENOSYS;
}
return 0;
}
int pthread_condattr_destroy(pthread_condattr_t *attr)
{
if (attr == NULL) {
@@ -61,6 +87,19 @@ int pthread_condattr_destroy(pthread_condattr_t *attr)
}
(VOID)memset_s(attr, sizeof(pthread_condattr_t), 0, sizeof(pthread_condattr_t));
attr->clock = INT32_MAX;
return 0;
}
int pthread_condattr_getclock(const pthread_condattr_t *attr, clockid_t *clock)
{
if ((attr == NULL) || (clock == NULL)) {
return -1;
}
*clock = attr->clock;
return 0;
}
@@ -71,6 +110,7 @@ int pthread_condattr_init(pthread_condattr_t *attr)
}
attr->clock = CLOCK_REALTIME;
return 0;
}
@@ -86,6 +126,7 @@ int pthread_condattr_setclock(pthread_condattr_t *attr, clockid_t clk)
}
attr->clock = clk;
return 0;
}
@@ -95,6 +136,7 @@ STATIC INLINE INT32 CondInitCheck(const pthread_cond_t *cond)
(cond->event.stEventList.pstNext == NULL)) {
return 1;
}
return 0;
}
@@ -149,6 +191,7 @@ int pthread_cond_destroy(pthread_cond_t *cond)
}
free(cond->mutex);
cond->mutex = NULL;
return 0;
}
@@ -222,6 +265,7 @@ STATIC INT32 ProcessReturnVal(pthread_cond_t *cond, INT32 val)
ret = EINVAL;
break;
}
return ret;
}
@@ -230,15 +274,17 @@ int pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex,
{
INT32 ret;
UINT64 absTicks;
const UINT32 nsPerTick = OS_SYS_NS_PER_SECOND / LOSCFG_BASE_CORE_TICK_PER_SECOND;
struct timespec tp;
UINT64 nseconds;
UINT64 currTime;
if ((cond == NULL) || (mutex == NULL) || (ts == NULL)) {
LosMuxCB *muxPosted = NULL;
pthread_testcancel();
if ((cond == NULL) || (mutex == NULL) || (ts == NULL) || (mutex->magic != _MUX_MAGIC)) {
return EINVAL;
}
muxPosted = GET_MUX(mutex->handle);
if ((mutex->stAttr.type == PTHREAD_MUTEX_ERRORCHECK) && (g_losTask.runTask != muxPosted->owner)) {
return EPERM;
}
if (CondInitCheck(cond)) {
ret = pthread_cond_init(cond, NULL);
if (ret != 0) {
@@ -250,17 +296,11 @@ int pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex,
cond->count++;
(VOID)pthread_mutex_unlock(cond->mutex);
if (!ValidTimeSpec(ts)) {
return EINVAL;
ret = OsGetTickTimeFromNow(ts, cond->clock, &absTicks);
if (ret != 0) {
return ret;
}
clock_gettime(cond->clock, &tp);
currTime = (UINT64)tp.tv_sec * OS_SYS_NS_PER_SECOND + tp.tv_nsec;
nseconds = (UINT64)ts->tv_sec * OS_SYS_NS_PER_SECOND + ts->tv_nsec;
if (currTime >= nseconds) {
return ETIMEDOUT;
}
absTicks = ((nseconds - currTime) + nsPerTick - 1) / nsPerTick + 1;
if (absTicks >= UINT32_MAX) {
return EINVAL;
}
@@ -277,6 +317,8 @@ int pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex,
}
ret = ProcessReturnVal(cond, ret);
pthread_testcancel();
return ret;
}

View File

@@ -35,8 +35,12 @@
#include "los_compiler.h"
#include "los_mux.h"
#include "errno.h"
#include "los_mux.h"
#include "los_debug.h"
#include "los_hook.h"
#include "los_sched.h"
#define MUTEXATTR_TYPE_MASK 0x0FU
#define OS_SYS_NS_PER_MSECOND 1000000
#define OS_SYS_NS_PER_SECOND 1000000000
@@ -45,7 +49,7 @@ static inline int MapError(UINT32 err)
switch (err) {
case LOS_OK:
return 0;
case LOS_ERRNO_MUX_PEND_INTERR:
case LOS_ERRNO_MUX_IN_INTERR:
return EPERM;
case LOS_ERRNO_MUX_PEND_IN_LOCK:
return EDEADLK;
@@ -68,7 +72,28 @@ int pthread_mutexattr_init(pthread_mutexattr_t *mutexAttr)
return EINVAL;
}
mutexAttr->type = PTHREAD_MUTEX_RECURSIVE;
mutexAttr->type = PTHREAD_MUTEX_DEFAULT;
return 0;
}
int pthread_mutexattr_gettype(const pthread_mutexattr_t *attr, int *outType)
{
INT32 type;
if ((attr == NULL) || (outType == NULL)) {
return EINVAL;
}
type = (INT32)(attr->type & MUTEXATTR_TYPE_MASK);
if ((type != PTHREAD_MUTEX_NORMAL) &&
(type != PTHREAD_MUTEX_RECURSIVE) &&
(type != PTHREAD_MUTEX_ERRORCHECK)) {
return EINVAL;
}
*outType = type;
return 0;
}
@@ -83,12 +108,8 @@ int pthread_mutexattr_settype(pthread_mutexattr_t *mutexAttr, int type)
((unsigned)type != PTHREAD_MUTEX_ERRORCHECK)) {
return EINVAL;
}
mutexAttr->type = (UINT8)((mutexAttr->type & ~MUTEXATTR_TYPE_MASK) | (UINT32)type);
if ((unsigned)type != PTHREAD_MUTEX_RECURSIVE) {
return EOPNOTSUPP;
}
mutexAttr->type = PTHREAD_MUTEX_RECURSIVE;
return 0;
}
@@ -99,17 +120,25 @@ int pthread_mutexattr_destroy(pthread_mutexattr_t *mutexAttr)
}
(VOID)memset_s(mutexAttr, sizeof(pthread_mutexattr_t), 0, sizeof(pthread_mutexattr_t));
return 0;
}
/* Initialize mutex. If mutexAttr is NULL, use default attributes. */
int pthread_mutex_init(pthread_mutex_t *mutex, const pthread_mutexattr_t *mutexAttr)
{
pthread_mutexattr_t useAttr;
UINT32 muxHandle;
UINT32 ret;
if ((mutexAttr != NULL) && (mutexAttr->type != PTHREAD_MUTEX_RECURSIVE)) {
return EOPNOTSUPP;
if (mutex == NULL) {
return EINVAL;
}
if (mutexAttr == NULL) {
(VOID)pthread_mutexattr_init(&useAttr);
} else {
useAttr = *mutexAttr;
}
ret = LOS_MuxCreate(&muxHandle);
@@ -117,6 +146,7 @@ int pthread_mutex_init(pthread_mutex_t *mutex, const pthread_mutexattr_t *mutexA
return MapError(ret);
}
mutex->stAttr = useAttr;
mutex->magic = _MUX_MAGIC;
mutex->handle = muxHandle;
@@ -126,7 +156,7 @@ int pthread_mutex_init(pthread_mutex_t *mutex, const pthread_mutexattr_t *mutexA
int pthread_mutex_destroy(pthread_mutex_t *mutex)
{
UINT32 ret;
if (mutex->magic != _MUX_MAGIC) {
if ((mutex == NULL) || (mutex->magic != _MUX_MAGIC)) {
return EINVAL;
}
ret = LOS_MuxDelete(mutex->handle);
@@ -135,16 +165,172 @@ int pthread_mutex_destroy(pthread_mutex_t *mutex)
}
mutex->handle = _MUX_INVALID_HANDLE;
mutex->magic = 0;
return 0;
}
STATIC UINT32 CheckMutexAttr(const pthread_mutexattr_t *attr)
{
if ((attr->type != PTHREAD_MUTEX_NORMAL) &&
(attr->type != PTHREAD_MUTEX_RECURSIVE) &&
(attr->type != PTHREAD_MUTEX_ERRORCHECK)) {
return LOS_NOK;
}
return LOS_OK;
}
STATIC UINT32 MuxPreCheck(const pthread_mutex_t *mutex, const LosTaskCB *runTask)
{
if ((mutex == NULL) || (mutex->magic != _MUX_MAGIC) ||
((mutex->handle != _MUX_INVALID_HANDLE) && (mutex->handle >= (UINT32)LOSCFG_BASE_IPC_MUX_LIMIT))) {
return EINVAL;
}
if (OS_INT_ACTIVE) {
return EPERM;
}
/* DO NOT recommend to use blocking API in system tasks */
if ((runTask != NULL) && (runTask->taskStatus & OS_TASK_FLAG_SYSTEM_TASK)) {
PRINT_DEBUG("Warning: DO NOT recommend to use %s in system tasks.\n", __FUNCTION__);
}
if (CheckMutexAttr(&mutex->stAttr) != LOS_OK) {
return EINVAL;
}
return 0;
}
STATIC UINT32 MuxPendForPosix(pthread_mutex_t *mutex, UINT32 timeout)
{
UINT32 intSave;
LosMuxCB *muxPended = NULL;
UINT32 retErr;
LosTaskCB *runningTask = NULL;
UINT32 muxHandle = mutex->handle;
muxPended = GET_MUX(muxHandle);
intSave = LOS_IntLock();
if (muxPended->muxStat == OS_MUX_UNUSED) {
LOS_IntRestore(intSave);
OS_RETURN_ERROR(LOS_ERRNO_MUX_INVALID);
}
runningTask = (LosTaskCB *)g_losTask.runTask;
if (muxPended->muxCount == 0) {
muxPended->muxCount++;
muxPended->owner = runningTask;
muxPended->priority = runningTask->priority;
LOS_IntRestore(intSave);
OsHookCall(LOS_HOOK_TYPE_MUX_PEND, muxPended, timeout);
return LOS_OK;
}
if ((muxPended->owner == runningTask) && (mutex->stAttr.type == PTHREAD_MUTEX_RECURSIVE)) {
muxPended->muxCount++;
LOS_IntRestore(intSave);
OsHookCall(LOS_HOOK_TYPE_MUX_PEND, muxPended, timeout);
return LOS_OK;
}
if (!timeout) {
LOS_IntRestore(intSave);
OS_RETURN_ERROR(LOS_ERRNO_MUX_UNAVAILABLE);
}
runningTask->taskMux = (VOID *)muxPended;
if (muxPended->owner->priority > runningTask->priority) {
(VOID)OsSchedModifyTaskSchedParam(muxPended->owner, runningTask->priority);
}
OsSchedTaskWait(&muxPended->muxList, timeout);
LOS_IntRestore(intSave);
OsHookCall(LOS_HOOK_TYPE_MUX_PEND, muxPended, timeout);
LOS_Schedule();
intSave = LOS_IntLock();
if (runningTask->taskStatus & OS_TASK_STATUS_TIMEOUT) {
runningTask->taskStatus &= (~OS_TASK_STATUS_TIMEOUT);
retErr = LOS_ERRNO_MUX_TIMEOUT;
LOS_IntRestore(intSave);
OS_RETURN_ERROR(retErr);
}
LOS_IntRestore(intSave);
return LOS_OK;
}
STATIC UINT32 MuxPostForPosix(pthread_mutex_t *mutex)
{
UINT32 intSave;
LosMuxCB *muxPosted = NULL;
LosTaskCB *resumedTask = NULL;
LosTaskCB *runningTask = NULL;
UINT32 muxHandle = mutex->handle;
muxPosted = GET_MUX(muxHandle);
intSave = LOS_IntLock();
if (muxPosted->muxStat == OS_MUX_UNUSED) {
LOS_IntRestore(intSave);
OS_RETURN_ERROR(LOS_ERRNO_MUX_INVALID);
}
runningTask = (LosTaskCB *)g_losTask.runTask;
if ((muxPosted->muxCount == 0) || (muxPosted->owner != runningTask)) {
LOS_IntRestore(intSave);
OS_RETURN_ERROR(LOS_ERRNO_MUX_INVALID);
}
if ((--(muxPosted->muxCount) != 0) && (mutex->stAttr.type == PTHREAD_MUTEX_RECURSIVE)) {
LOS_IntRestore(intSave);
OsHookCall(LOS_HOOK_TYPE_MUX_POST, muxPosted);
return LOS_OK;
}
if ((muxPosted->owner->priority) != muxPosted->priority) {
(VOID)OsSchedModifyTaskSchedParam(muxPosted->owner, muxPosted->priority);
}
if (!LOS_ListEmpty(&muxPosted->muxList)) {
resumedTask = OS_TCB_FROM_PENDLIST(LOS_DL_LIST_FIRST(&(muxPosted->muxList)));
muxPosted->muxCount = 1;
muxPosted->owner = resumedTask;
muxPosted->priority = resumedTask->priority;
resumedTask->taskMux = NULL;
OsSchedTaskWake(resumedTask);
LOS_IntRestore(intSave);
OsHookCall(LOS_HOOK_TYPE_MUX_POST, muxPosted);
LOS_Schedule();
} else {
muxPosted->owner = NULL;
LOS_IntRestore(intSave);
}
return LOS_OK;
}
int pthread_mutex_timedlock(pthread_mutex_t *mutex, const struct timespec *absTimeout)
{
UINT32 ret;
UINT32 timeout;
UINT64 timeoutNs;
struct timespec curTime = {0};
if ((mutex->magic != _MUX_MAGIC) || (absTimeout->tv_nsec < 0) || (absTimeout->tv_nsec >= OS_SYS_NS_PER_SECOND)) {
LosMuxCB *muxPended = NULL;
ret = MuxPreCheck(mutex, OS_TCB_FROM_TID(LOS_CurTaskIDGet()));
if (ret != 0) {
return (INT32)ret;
}
if ((absTimeout == NULL) || (absTimeout->tv_nsec < 0) || (absTimeout->tv_nsec >= OS_SYS_NS_PER_SECOND)) {
return EINVAL;
}
if (mutex->handle == _MUX_INVALID_HANDLE) {
@@ -152,6 +338,13 @@ int pthread_mutex_timedlock(pthread_mutex_t *mutex, const struct timespec *absTi
if (ret != LOS_OK) {
return MapError(ret);
}
} else {
muxPended = GET_MUX(mutex->handle);
if ((mutex->stAttr.type == PTHREAD_MUTEX_ERRORCHECK) &&
(muxPended->muxCount != 0) &&
(muxPended->owner == OS_TCB_FROM_TID(LOS_CurTaskIDGet()))) {
return EDEADLK;
}
}
ret = clock_gettime(CLOCK_REALTIME, &curTime);
if (ret != LOS_OK) {
@@ -162,7 +355,8 @@ int pthread_mutex_timedlock(pthread_mutex_t *mutex, const struct timespec *absTi
return ETIMEDOUT;
}
timeout = (timeoutNs + (OS_SYS_NS_PER_MSECOND - 1)) / OS_SYS_NS_PER_MSECOND;
ret = LOS_MuxPend(mutex->handle, timeout);
ret = MuxPendForPosix(mutex, timeout);
return MapError(ret);
}
@@ -170,42 +364,72 @@ int pthread_mutex_timedlock(pthread_mutex_t *mutex, const struct timespec *absTi
int pthread_mutex_lock(pthread_mutex_t *mutex)
{
UINT32 ret;
if (mutex->magic != _MUX_MAGIC) {
return EINVAL;
LosMuxCB *muxPended = NULL;
LosTaskCB *runTask = OS_TCB_FROM_TID(LOS_CurTaskIDGet());
ret = MuxPreCheck(mutex, runTask);
if (ret != 0) {
return (INT32)ret;
}
if (mutex->handle == _MUX_INVALID_HANDLE) {
ret = LOS_MuxCreate(&mutex->handle);
if (ret != LOS_OK) {
return MapError(ret);
}
} else {
muxPended = GET_MUX(mutex->handle);
if ((mutex->stAttr.type == PTHREAD_MUTEX_ERRORCHECK) &&
(muxPended->muxCount != 0) &&
(muxPended->owner == runTask)) {
return EDEADLK;
}
}
ret = LOS_MuxPend(mutex->handle, LOS_WAIT_FOREVER);
ret = MuxPendForPosix(mutex, LOS_WAIT_FOREVER);
return MapError(ret);
}
int pthread_mutex_trylock(pthread_mutex_t *mutex)
{
UINT32 ret;
if (mutex->magic != _MUX_MAGIC) {
return EINVAL;
LosMuxCB *muxPended = NULL;
ret = MuxPreCheck(mutex, OS_TCB_FROM_TID(LOS_CurTaskIDGet()));
if (ret != 0) {
return (INT32)ret;
}
if (mutex->handle == _MUX_INVALID_HANDLE) {
ret = LOS_MuxCreate(&mutex->handle);
if (ret != LOS_OK) {
return MapError(ret);
}
} else {
muxPended = GET_MUX(mutex->handle);
if ((mutex->stAttr.type != PTHREAD_MUTEX_RECURSIVE) && (muxPended->muxCount != 0)) {
return EBUSY;
}
}
ret = LOS_MuxPend(mutex->handle, 0);
ret = MuxPendForPosix(mutex, 0);
return MapError(ret);
}
int pthread_mutex_unlock(pthread_mutex_t *mutex)
{
UINT32 ret;
if (mutex->magic != _MUX_MAGIC) {
ret = MuxPreCheck(mutex, OS_TCB_FROM_TID(LOS_CurTaskIDGet()));
if (ret != 0) {
return (INT32)ret;
}
if (mutex->handle == _MUX_INVALID_HANDLE) {
return EINVAL;
}
ret = LOS_MuxPost(mutex->handle);
ret = MuxPostForPosix(mutex);
return MapError(ret);
}

View File

@@ -102,6 +102,7 @@ int sem_destroy(sem_t *sem)
errno = MapError(ret);
return -1;
}
return 0;
}
@@ -119,6 +120,7 @@ int sem_wait(sem_t *sem)
errno = MapError(ret);
return -1;
}
return 0;
}
@@ -140,38 +142,37 @@ int sem_post(sem_t *sem)
return 0;
}
static long long GetTickTimeFromNow(const struct timespec *absTimeSpec)
int sem_trywait(sem_t *sem)
{
struct timespec tsNow = { 0 };
long long ns;
long long tick;
UINT32 ret;
clock_gettime(CLOCK_REALTIME, &tsNow);
ns = (absTimeSpec->tv_sec - tsNow.tv_sec) * OS_SYS_NS_PER_SECOND + (absTimeSpec->tv_nsec - tsNow.tv_nsec);
if ((sem == NULL) || (sem->s_magic != _SEM_MAGIC)) {
errno = EINVAL;
return -1;
}
/* Round up for ticks */
tick = (ns * LOSCFG_BASE_CORE_TICK_PER_SECOND + (OS_SYS_NS_PER_SECOND - 1)) / OS_SYS_NS_PER_SECOND;
return tick;
ret = LOS_SemPend((UINT32)sem->s_handle, LOS_NO_WAIT);
if (ret != LOS_OK) {
errno = MapError(ret);
return -1;
}
return 0;
}
int sem_timedwait(sem_t *sem, const struct timespec *timeout)
{
UINT32 ret;
long long tickCnt;
UINT64 tickCnt;
if ((sem == NULL) || (sem->s_magic != (int)_SEM_MAGIC)) {
errno = EINVAL;
return -1;
}
if (!ValidTimeSpec(timeout)) {
errno = EINVAL;
return -1;
}
tickCnt = GetTickTimeFromNow(timeout);
if (tickCnt < 0) {
errno = ETIMEDOUT;
ret = OsGetTickTimeFromNow(timeout, CLOCK_REALTIME, &tickCnt);
if (ret != 0) {
errno = (INT32)ret;
return -1;
}
@@ -192,7 +193,7 @@ int sem_getvalue(sem_t *sem, int *currVal)
{
UINT32 ret;
if ((sem == NULL) || (currVal == NULL)) {
if ((sem == NULL) || (sem->s_magic != _SEM_MAGIC)|| (currVal == NULL)) {
errno = EINVAL;
return -1;
}

View File

@@ -43,6 +43,9 @@
#include "los_tick.h"
#include "los_context.h"
#include "los_interrupt.h"
#include "sys/times.h"
#define DELAYTIMER_MAX 0x7FFFFFFFF
/* accumulative time delta from discontinuous modify */
STATIC struct timespec g_accDeltaFromSet;
@@ -96,7 +99,7 @@ int nanosleep(const struct timespec *rqtp, struct timespec *rmtp)
}
/* sleep in interrupt context or in task sched lock state */
errno = EPERM;
errno = EINTR;
return -1;
}
@@ -105,12 +108,12 @@ int timer_create(clockid_t clockID, struct sigevent *restrict evp, timer_t *rest
UINT32 ret;
UINT32 swtmrID;
if (!timerID || (clockID != CLOCK_REALTIME)) {
if (!timerID || (clockID != CLOCK_REALTIME) || !evp) {
errno = EINVAL;
return -1;
}
if (!evp || evp->sigev_notify != SIGEV_THREAD || evp->sigev_notify_attributes) {
if ((evp->sigev_notify != SIGEV_THREAD) || evp->sigev_notify_attributes) {
errno = ENOTSUP;
return -1;
}
@@ -152,7 +155,7 @@ int timer_settime(timer_t timerID, int flags,
if (flags != 0) {
/* flags not supported currently */
errno = ENOSYS;
errno = ENOTSUP;
return -1;
}
@@ -190,6 +193,7 @@ int timer_settime(timer_t timerID, int flags,
swtmr->ucMode = (interval ? LOS_SWTMR_MODE_PERIOD : LOS_SWTMR_MODE_NO_SELFDELETE);
swtmr->uwInterval = (interval ? interval : expiry);
swtmr->ucOverrun = 0;
LOS_IntRestore(intSave);
if ((value->it_value.tv_sec == 0) && (value->it_value.tv_nsec == 0)) {
@@ -229,7 +233,9 @@ int timer_gettime(timer_t timerID, struct itimerspec *value)
errno = EINVAL;
return -1;
}
if (ret == LOS_ERRNO_SWTMR_NOT_STARTED) {
tick = 0;
}
OsTick2TimeSpec(&value->it_value, tick);
OsTick2TimeSpec(&value->it_interval, (swtmr->ucMode == LOS_SWTMR_MODE_ONCE) ? 0 : swtmr->uwInterval);
return 0;
@@ -237,10 +243,13 @@ int timer_gettime(timer_t timerID, struct itimerspec *value)
int timer_getoverrun(timer_t timerID)
{
(void)timerID;
SWTMR_CTRL_S *swtmr = NULL;
swtmr = OS_SWT_FROM_SID((UINT32)(UINTPTR)timerID);
errno = ENOSYS;
return -1;
if ((swtmr->ucOverrun) >= (UINT8)DELAYTIMER_MAX) {
return (INT32)DELAYTIMER_MAX;
}
return (int)swtmr->ucOverrun;
}
STATIC VOID OsGetHwTime(struct timespec *hwTime)
@@ -696,3 +705,17 @@ unsigned sleep(unsigned seconds)
specTime.tv_nsec = (long)(nanoseconds % OS_SYS_NS_PER_SECOND);
return nanosleep(&specTime, NULL);
}
clock_t times(struct tms *tms)
{
clock_t clockTick = (clock_t)LOS_TickCountGet();
if (tms != NULL) {
tms->tms_cstime = clockTick;
tms->tms_cutime = clockTick;
tms->tms_stime = clockTick;
tms->tms_utime = clockTick;
}
return clockTick;
}

View File

@@ -111,5 +111,27 @@ STATIC INLINE VOID OsTick2TimeSpec(struct timespec *tp, UINT32 tick)
tp->tv_sec = (time_t)(ns / OS_SYS_NS_PER_SECOND);
tp->tv_nsec = (long)(ns % OS_SYS_NS_PER_SECOND);
}
STATIC INLINE INT32 OsGetTickTimeFromNow(const struct timespec *ts, clockid_t clockId, UINT64 *absTicks)
{
struct timespec tp;
UINT64 nseconds;
UINT64 currTime;
const UINT32 nsPerTick = OS_SYS_NS_PER_SECOND / LOSCFG_BASE_CORE_TICK_PER_SECOND;
if (!ValidTimeSpec(ts)) {
return EINVAL;
}
clock_gettime(clockId, &tp);
currTime = (UINT64)tp.tv_sec * OS_SYS_NS_PER_SECOND + tp.tv_nsec;
nseconds = (UINT64)ts->tv_sec * OS_SYS_NS_PER_SECOND + ts->tv_nsec;
if (currTime >= nseconds) {
return ETIMEDOUT;
}
*absTicks = ((nseconds - currTime) + nsPerTick - 1) / nsPerTick + 1;
return 0;
}
#endif

View File

@@ -104,7 +104,7 @@ extern "C" {
*
* Solution: Check whether the mutex is being locked during an interrupt.
*/
#define LOS_ERRNO_MUX_PEND_INTERR LOS_ERRNO_OS_ERROR(LOS_MOD_MUX, 0x05)
#define LOS_ERRNO_MUX_IN_INTERR LOS_ERRNO_OS_ERROR(LOS_MOD_MUX, 0x05)
/**
* @ingroup los_mux
@@ -256,7 +256,7 @@ extern UINT32 LOS_MuxDelete(UINT32 muxHandle);
* is not applicable for the current operation.
* @retval #LOS_ERRNO_MUX_UNAVAILABLE The mutex fails to be locked because it is locked by another thread and
* a period of time is not set for waiting for the mutex to become available.
* @retval #LOS_ERRNO_MUX_PEND_INTERR The mutex is being locked during an interrupt.
* @retval #LOS_ERRNO_MUX_IN_INTERR The mutex is being locked during an interrupt.
* @retval #LOS_ERRNO_MUX_PEND_IN_LOCK The mutex is waited on when the task scheduling is disabled.
* @retval #LOS_ERRNO_MUX_TIMEOUT The mutex waiting times out.
* @retval #LOS_OK The mutex is successfully locked.
@@ -284,7 +284,7 @@ extern UINT32 LOS_MuxPend(UINT32 muxHandle, UINT32 timeout);
*
* @retval #LOS_ERRNO_MUX_INVALID The mutex state (for example, the mutex does not exist or is not in use
* or owned by other thread) is not applicable for the current operation.
* @retval #LOS_ERRNO_MUX_PEND_INTERR The mutex is being released during an interrupt.
* @retval #LOS_ERRNO_MUX_IN_INTERR The mutex is being released during an interrupt.
* @retval #LOS_OK The mutex is successfully released.
* @par Dependency:
* <ul><li>los_mux.h: the header file that contains the API declaration.</li></ul>

View File

@@ -333,7 +333,17 @@ extern "C" {
/**
* @ingroup los_queue
* In struct QUEUE_INFO_S, the length of each waitReadTask/waitWriteTask/waitMemTask array depends on the value
* Queue error code: The buffer size passed in during queue readding or writting is bigger than the biggest size.
*
* Value: 0x02000620
*
* Solution: Decrease the buffer size.
*/
#define LOS_ERRNO_QUEUE_BUFFER_SIZE_TOO_BIG LOS_ERRNO_OS_ERROR(LOS_MOD_QUE, 0x20)
/**
* @ingroup los_queue
* In struct QueueInfo, the length of each waitReadTask/waitWriteTask/waitMemTask array depends on the value
* LOSCFG_BASE_CORE_TSK_LIMIT. The type of each array element is UINT32, which means that each element could mark 32(=2^5) tasks.
* OS_WAIT_TASK_ARRAY_LEN is used to calculate the array length.
* OS_WAIT_TASK_ID_TO_ARRAY_IDX is used to transfer task ID to array index.
@@ -387,7 +397,7 @@ typedef struct tagQueueInfo {
* <ul><li>los_queue.h: the header file that contains the API declaration.</li></ul>
* @see LOS_QueueDelete
*/
extern UINT32 LOS_QueueCreate(CHAR *queueName,
extern UINT32 LOS_QueueCreate(const CHAR *queueName,
UINT16 len,
UINT32 *queueID,
UINT32 flags,

View File

@@ -43,21 +43,20 @@ extern "C" {
#endif /* __cplusplus */
#define OS_SCHED_MINI_PERIOD (g_sysClock / LOSCFG_BASE_CORE_TICK_PER_SECOND_MINI)
#define OS_TICK_RESPONSE_PRECISION (UINT32)((OS_SCHED_MINI_PERIOD * 75) / 100)
#define OS_SCHED_MAX_RESPONSE_TIME (UINT64)(((UINT64)-1) - 1U)
extern UINT32 g_taskScheduled;
typedef BOOL (*SchedScan)(VOID);
extern UINT64 g_sysSchedStartTime;
VOID OsSchedResetSchedResponseTime(UINT64 responseTime);
VOID OsSchedSetIdleTaskSchedParam(LosTaskCB *idleTask);
UINT32 OsSchedSwtmrScanRegister(SchedScan func);
VOID OsSchedUpdateExpireTime(UINT64 startTime);
VOID OsSchedUpdateExpireTime(VOID);
UINT64 OsSchedGetNextExpireTime(UINT64 startTime);
VOID OsSchedTaskDeQueue(LosTaskCB *taskCB);
@@ -89,15 +88,9 @@ BOOL OsSchedTaskSwitch(VOID);
LosTaskCB *OsGetTopTask(VOID);
UINT32 OsSchedRealSleepTimeSet(VOID (*func)(UINT64));
STATIC INLINE UINT64 OsGetCurrSchedTimeCycle(VOID)
{
if (g_sysSchedStartTime != OS_64BIT_MAX) {
return (LOS_SysCycleGet() - g_sysSchedStartTime);
}
return 0;
return LOS_SysCycleGet();
}
/**

View File

@@ -55,10 +55,15 @@ typedef struct {
LOS_DL_LIST sortLink;
} SortLinkAttribute;
extern SortLinkAttribute g_taskSortLink;
extern SortLinkAttribute g_swtmrSortLink;
#define OS_SORT_LINK_INVALID_TIME ((UINT64)-1)
#define SET_SORTLIST_VALUE(sortList, value) (((SortLinkList *)(sortList))->responseTime = (value))
#define GET_SORTLIST_VALUE(sortList) (((SortLinkList *)(sortList))->responseTime)
#define OS_SORT_LINK_UINT64_MAX ((UINT64)-1)
STATIC INLINE UINT64 OsSortLinkGetRemainTime(UINT64 currTime, const SortLinkList *targetSortList)
{
if (currTime >= targetSortList->responseTime) {
@@ -67,14 +72,42 @@ STATIC INLINE UINT64 OsSortLinkGetRemainTime(UINT64 currTime, const SortLinkList
return (targetSortList->responseTime - currTime);
}
STATIC INLINE VOID OsDeleteNodeSortLink(SortLinkList *sortList)
{
LOS_ListDelete(&sortList->sortLinkNode);
SET_SORTLIST_VALUE(sortList, OS_SORT_LINK_INVALID_TIME);
}
STATIC INLINE UINT64 GetSortLinkNextExpireTime(SortLinkAttribute *sortHeader, UINT64 startTime, UINT32 tickPrecision)
{
LOS_DL_LIST *head = &sortHeader->sortLink;
LOS_DL_LIST *list = head->pstNext;
if (LOS_ListEmpty(head)) {
return OS_SORT_LINK_UINT64_MAX - tickPrecision;
}
SortLinkList *listSorted = LOS_DL_LIST_ENTRY(list, SortLinkList, sortLinkNode);
if (listSorted->responseTime <= (startTime + tickPrecision)) {
return (startTime + tickPrecision);
}
return listSorted->responseTime;
}
STATIC INLINE UINT64 OsGetNextExpireTime(UINT64 startTime, UINT32 tickPrecision)
{
UINT64 taskExpireTime = GetSortLinkNextExpireTime(&g_taskSortLink, startTime, tickPrecision);
UINT64 swtmrExpireTime = GetSortLinkNextExpireTime(&g_swtmrSortLink, startTime, tickPrecision);
return (taskExpireTime < swtmrExpireTime) ? taskExpireTime : swtmrExpireTime;
}
SortLinkAttribute *OsGetSortLinkAttribute(SortLinkType type);
UINT64 OsGetNextExpireTime(UINT64 startTime);
UINT32 OsSortLinkInit(SortLinkAttribute *sortLinkHeader);
VOID OsDeleteNodeSortLink(SortLinkList *sortList);
VOID OsAdd2SortLink(SortLinkList *node, UINT64 startTime, UINT32 waitTicks, SortLinkType type);
VOID OsDeleteSortLink(SortLinkList *node);
UINT32 OsSortLinkGetTargetExpireTime(UINT64 currTime, const SortLinkList *targetSortList);
UINT32 OsSortLinkGetNextExpireTime(const SortLinkAttribute *sortLinkHeader);
UINT64 OsSortLinkGetTargetExpireTime(UINT64 currTime, const SortLinkList *targetSortList);
UINT64 OsSortLinkGetNextExpireTime(const SortLinkAttribute *sortLinkHeader);
#ifdef __cplusplus
#if __cplusplus

View File

@@ -271,6 +271,7 @@ typedef struct tagSwTmrCtrl {
struct tagSwTmrCtrl *pstNext; /* Pointer to the next software timer */
UINT8 ucState; /* Software timer state */
UINT8 ucMode; /* Software timer mode */
UINT8 ucOverrun; /* Times that a software timer repeats timing */
#if (LOSCFG_BASE_CORE_SWTMR_ALIGN == 1)
UINT8 ucRouses; /* wake up enable */
UINT8 ucSensitive; /* align enable */
@@ -499,27 +500,7 @@ extern UINT32 OsSwtmrInit(VOID);
*/
extern UINT32 OsSwtmrGetNextTimeout(VOID);
/**
* @ingroup los_swtmr
* @brief Adjust software timer list.
*
* @par Description:
* <ul>
* <li>This API is used to adjust software timer list.</li>
* </ul>
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @param sleepTime [IN] UINT32 Sleep time.
*
* @retval UINT32 Sleep time.
* @par Dependency:
* <ul><li>los_swtmr.h: the header file that contains the API declaration.</li></ul>
* @see None.
*/
extern VOID OsSwtmrAdjust(UINT32 sleepTime);
extern VOID OsSwtmrResponseTimeReset(UINT64 startTime);
#ifdef __cplusplus
#if __cplusplus

View File

@@ -1142,25 +1142,6 @@ extern UINT32 LOS_NewTaskIDGet(VOID);
*/
extern CHAR* LOS_TaskNameGet(UINT32 taskID);
/* *
* @ingroup los_task
* @brief: cpu delay.
*
* @par Description:
* This API is used to cpu delay, no task switching.
*
* @attention:
* <ul><li>None.</li></ul>
*
* @param UINT64 [IN] delay times, microseconds.
*
* @retval: None.
* @par Dependency:
* <ul><li>los_task.h: the header file that contains the API declaration.</li></ul>
* @see None.
*/
extern VOID LOS_UDelay(UINT64 microseconds);
/* *
* @ingroup los_task
* @brief: cpu delay.
@@ -1779,6 +1760,8 @@ STATIC INLINE LosTaskCB *OsCurrTaskGet(VOID)
return g_losTask.runTask;
}
extern VOID LOS_TaskResRecycle(VOID);
#ifdef __cplusplus
#if __cplusplus
}

View File

@@ -137,6 +137,8 @@ extern UINT32 g_sysClock;
#define OS_SYS_NS_PER_SECOND 1000000000
#define OS_SYS_NS_PER_MS 1000000
#define OS_SYS_NS_PER_US 1000
#define OS_CYCLE_PER_TICK (g_sysClock / LOSCFG_BASE_CORE_TICK_PER_SECOND)
@@ -249,7 +251,7 @@ typedef struct TagSysTime {
UINT8 ucWeek; /**< value 0 - 6 */
} SYS_TIME_S;
VOID OsTickTimerReload(UINT64 responseTime);
UINT64 OsTickTimerReload(UINT64 period);
#if (LOSCFG_BASE_CORE_TICK_WTIMER == 0)
VOID OsTickTimerBaseReset(UINT64 currTime);
@@ -257,6 +259,8 @@ VOID OsTickTimerBaseReset(UINT64 currTime);
UINT32 OsTickTimerInit(VOID);
VOID OsTickSysTimerStartTimeSet(UINT64 currTime);
/**
* @ingroup los_tick
* @brief Obtain the number of Ticks.
@@ -357,6 +361,63 @@ extern UINT32 LOS_MS2Tick(UINT32 millisec);
*/
extern UINT32 LOS_TickTimerRegister(const ArchTickTimer *timer, const HWI_PROC_FUNC tickHandler);
/* *
* @ingroup los_task
* @brief: cpu delay.
*
* @par Description:
* This API is used to cpu delay, no task switching.
*
* @attention:
* <ul><li>None.</li></ul>
*
* @param UINT64 [IN] delay times, microseconds.
*
* @retval: None.
* @par Dependency:
* <ul><li>los_task.h: the header file that contains the API declaration.</li></ul>
* @see None.
*/
extern VOID LOS_UDelay(UINT64 microseconds);
/* *
* @ingroup los_task
* @brief: cpu delay.
*
* @par Description:
* This API is used to cpu delay, no task switching.
*
* @attention:
* <ul><li>None.</li></ul>
*
* @param UINT32 [IN] delay times, millisecond.
*
* @retval: None.
* @par Dependency:
* <ul><li>los_task.h: the header file that contains the API declaration.</li></ul>
* @see None.
*/
extern VOID LOS_MDelay(UINT32 millisec);
/* *
* @ingroup los_task
* @brief: cpu nanosecond get.
*
* @par Description:
* This API is used to get the current number of nanoseconds.
*
* @attention:
* <ul><li>None.</li></ul>
*
* @param none.
*
* @retval: None.
* @par Dependency:
* <ul><li>los_task.h: the header file that contains the API declaration.</li></ul>
* @see None.
*/
extern UINT64 LOS_CurrNanosec(VOID);
/**
* @ingroup los_tick
* @brief Handle the system tick timeout.
@@ -405,6 +466,8 @@ typedef struct TagCpuTick {
*/
#define OS_SYS_US_PER_SECOND 1000000
#define OS_SYS_US_PER_MS 1000
/**
* @ingroup los_tick
* The maximum length of name.

View File

@@ -165,7 +165,7 @@ STATIC_INLINE UINT32 OsMuxValidCheck(LosMuxCB *muxPended)
}
if (OS_INT_ACTIVE) {
return LOS_ERRNO_MUX_PEND_INTERR;
return LOS_ERRNO_MUX_IN_INTERR;
}
if (g_losTaskLock) {
@@ -279,6 +279,11 @@ LITE_OS_SEC_TEXT UINT32 LOS_MuxPost(UINT32 muxHandle)
OS_RETURN_ERROR(LOS_ERRNO_MUX_INVALID);
}
if (OS_INT_ACTIVE) {
LOS_IntRestore(intSave);
OS_RETURN_ERROR(LOS_ERRNO_MUX_IN_INTERR);
}
runningTask = (LosTaskCB *)g_losTask.runTask;
if ((muxPosted->muxCount == 0) || (muxPosted->owner != runningTask)) {
LOS_IntRestore(intSave);

View File

@@ -90,7 +90,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 OsQueueInit(VOID)
Output : queueID --- Queue ID
Return : LOS_OK on success or error code on failure
*****************************************************************************/
LITE_OS_SEC_TEXT_INIT UINT32 LOS_QueueCreate(CHAR *queueName,
LITE_OS_SEC_TEXT_INIT UINT32 LOS_QueueCreate(const CHAR *queueName,
UINT16 len,
UINT32 *queueID,
UINT32 flags,
@@ -234,9 +234,9 @@ static INLINE VOID OsQueueBufferOperate(LosQueueCB *queueCB, UINT32 operateType,
if (OS_QUEUE_IS_POINT(operateType)) {
if (OS_QUEUE_IS_READ(operateType)) {
*(UINT32 *)bufferAddr = *(UINT32 *)(VOID *)queueNode;
*(UINTPTR *)bufferAddr = *(UINTPTR *)(VOID *)queueNode;
} else {
*(UINT32 *)(VOID *)queueNode = *(UINT32 *)bufferAddr; // change to pp when calling OsQueueOperate
*(UINTPTR *)(VOID *)queueNode = *(UINTPTR *)bufferAddr;
}
} else {
if (OS_QUEUE_IS_READ(operateType)) {
@@ -271,6 +271,10 @@ static INLINE UINT32 OsQueueOperateParamCheck(const LosQueueCB *queueCB, UINT32
return LOS_ERRNO_QUEUE_WRITE_SIZE_TOO_BIG;
}
if (*bufferSize >= SECUREC_MEM_MAX_LEN) {
return LOS_ERRNO_QUEUE_BUFFER_SIZE_TOO_BIG;
}
return LOS_OK;
}

View File

@@ -32,6 +32,7 @@
#include "los_sched.h"
#include "los_task.h"
#include "los_tick.h"
#include "los_swtmr.h"
#include "los_debug.h"
#include "los_hook.h"
#if (LOSCFG_KERNEL_PM == 1)
@@ -49,6 +50,7 @@ extern "C" {
#define OS_SCHED_TIME_SLICES ((LOSCFG_BASE_CORE_TIMESLICE_TIMEOUT * OS_SYS_NS_PER_US) / OS_NS_PER_CYCLE)
#define OS_TIME_SLICE_MIN (INT32)((50 * OS_SYS_NS_PER_US) / OS_NS_PER_CYCLE) /* 50us */
#define OS_TICK_RESPONSE_TIME_MAX LOSCFG_BASE_CORE_TICK_RESPONSE_MAX
#define OS_TICK_RESPONSE_PRECISION (UINT32)((OS_SCHED_MINI_PERIOD * 75) / 100)
#if (LOSCFG_BASE_CORE_TICK_RESPONSE_MAX == 0)
#error "Must specify the maximum value that tick timer counter supports!"
#endif
@@ -63,25 +65,7 @@ STATIC UINT32 g_queueBitmap;
STATIC UINT32 g_schedResponseID = 0;
STATIC UINT16 g_tickIntLock = 0;
STATIC UINT64 g_tickStartTime = 0;
STATIC UINT64 g_schedResponseTime = OS_SCHED_MAX_RESPONSE_TIME;
STATIC VOID (*SchedRealSleepTimeSet)(UINT64) = NULL;
UINT64 g_sysSchedStartTime = OS_64BIT_MAX;
STATIC VOID OsSchedSetStartTime(UINT64 currCycle)
{
g_sysSchedStartTime = currCycle;
}
UINT32 OsSchedRealSleepTimeSet(VOID (*func)(UINT64))
{
if (func == NULL) {
return LOS_NOK;
}
SchedRealSleepTimeSet = func;
return LOS_OK;
}
VOID OsSchedResetSchedResponseTime(UINT64 responseTime)
{
@@ -101,27 +85,21 @@ STATIC INLINE VOID OsTimeSliceUpdate(LosTaskCB *taskCB, UINT64 currTime)
taskCB->startTime = currTime;
}
STATIC INLINE VOID OsSchedTickReload(UINT64 nextResponseTime, UINT32 responseID, BOOL isTimeSlice)
STATIC INLINE VOID OsSchedSetNextExpireTime(UINT32 responseID, UINT64 taskEndTime)
{
UINT64 currTime, nextExpireTime;
UINT32 usedTime;
UINT64 nextResponseTime = 0;
BOOL isTimeSlice = FALSE;
currTime = OsGetCurrSchedTimeCycle();
if (g_tickStartTime != 0) {
usedTime = currTime - g_tickStartTime;
g_tickStartTime = 0;
} else {
usedTime = 0;
UINT64 currTime = OsGetCurrSchedTimeCycle();
UINT64 nextExpireTime = OsGetNextExpireTime(currTime, OS_TICK_RESPONSE_PRECISION);
/* The response time of the task time slice is aligned to the next response time in the delay queue */
if ((nextExpireTime > taskEndTime) && ((nextExpireTime - taskEndTime) > OS_SCHED_MINI_PERIOD)) {
nextExpireTime = taskEndTime;
isTimeSlice = TRUE;
}
if ((nextResponseTime > usedTime) && ((nextResponseTime - usedTime) > OS_TICK_RESPONSE_PRECISION)) {
nextResponseTime -= usedTime;
} else {
nextResponseTime = OS_TICK_RESPONSE_PRECISION;
}
nextExpireTime = currTime + nextResponseTime;
if (nextExpireTime >= g_schedResponseTime) {
if ((g_schedResponseTime <= nextExpireTime) ||
((g_schedResponseTime - nextExpireTime) < OS_TICK_RESPONSE_PRECISION)) {
return;
}
@@ -131,46 +109,15 @@ STATIC INLINE VOID OsSchedTickReload(UINT64 nextResponseTime, UINT32 responseID,
} else {
g_schedResponseID = OS_INVALID;
}
g_schedResponseTime = nextExpireTime;
OsTickTimerReload(nextResponseTime);
nextResponseTime = nextExpireTime - currTime;
if (nextResponseTime < OS_TICK_RESPONSE_PRECISION) {
nextResponseTime = OS_TICK_RESPONSE_PRECISION;
}
g_schedResponseTime = currTime + OsTickTimerReload(nextResponseTime);
}
STATIC INLINE VOID OsSchedSetNextExpireTime(UINT64 startTime, UINT32 responseID, UINT64 taskEndTime)
{
UINT64 nextExpireTime;
UINT64 nextResponseTime = 0;
BOOL isTimeSlice = FALSE;
nextExpireTime = OsGetNextExpireTime(startTime);
/* The response time of the task time slice is aligned to the next response time in the delay queue */
if ((nextExpireTime > taskEndTime) && ((nextExpireTime - taskEndTime) > OS_SCHED_MINI_PERIOD)) {
nextExpireTime = taskEndTime;
isTimeSlice = TRUE;
}
if ((g_schedResponseTime > nextExpireTime) &&
((g_schedResponseTime - nextExpireTime) >= OS_TICK_RESPONSE_PRECISION)) {
nextResponseTime = nextExpireTime - startTime;
if (nextResponseTime > OS_TICK_RESPONSE_TIME_MAX) {
if (SchedRealSleepTimeSet != NULL) {
SchedRealSleepTimeSet(nextResponseTime);
}
nextResponseTime = OS_TICK_RESPONSE_TIME_MAX;
}
if (SchedRealSleepTimeSet != NULL) {
SchedRealSleepTimeSet(0);
}
} else {
/* There is no point earlier than the current expiration date */
g_tickStartTime = 0;
return;
}
OsSchedTickReload(nextResponseTime, responseID, isTimeSlice);
}
VOID OsSchedUpdateExpireTime(UINT64 startTime)
VOID OsSchedUpdateExpireTime(VOID)
{
UINT64 endTime;
BOOL isPmMode = FALSE;
@@ -185,11 +132,11 @@ VOID OsSchedUpdateExpireTime(UINT64 startTime)
#endif
if ((runTask->taskID != g_idleTaskID) && !isPmMode) {
INT32 timeSlice = (runTask->timeSlice <= OS_TIME_SLICE_MIN) ? OS_SCHED_TIME_SLICES : runTask->timeSlice;
endTime = startTime + timeSlice;
endTime = runTask->startTime + timeSlice;
} else {
endTime = OS_SCHED_MAX_RESPONSE_TIME - OS_TICK_RESPONSE_PRECISION;
}
OsSchedSetNextExpireTime(startTime, runTask->taskID, endTime);
OsSchedSetNextExpireTime(runTask->taskID, endTime);
}
STATIC INLINE VOID OsSchedPriQueueEnHead(LOS_DL_LIST *priqueueItem, UINT32 priority)
@@ -468,6 +415,11 @@ UINT32 OsTaskNextSwitchTimeGet(VOID)
return ticks;
}
UINT64 OsSchedGetNextExpireTime(UINT64 startTime)
{
return OsGetNextExpireTime(startTime, OS_TICK_RESPONSE_PRECISION);
}
UINT32 OsSchedInit(VOID)
{
UINT16 pri;
@@ -503,6 +455,8 @@ LosTaskCB *OsGetTopTask(VOID)
VOID OsSchedStart(VOID)
{
PRINTK("Entering scheduler\n");
(VOID)LOS_IntLock();
LosTaskCB *newTask = OsGetTopTask();
@@ -510,18 +464,19 @@ VOID OsSchedStart(VOID)
g_losTask.newTask = newTask;
g_losTask.runTask = g_losTask.newTask;
/* Initialize the schedule timeline and enable scheduling */
g_taskScheduled = TRUE;
OsSchedSetStartTime(LOS_SysCycleGet());
newTask->startTime = OsGetCurrSchedTimeCycle();
OsSchedTaskDeQueue(newTask);
OsTickSysTimerStartTimeSet(newTask->startTime);
OsSwtmrResponseTimeReset(newTask->startTime);
/* Initialize the schedule timeline and enable scheduling */
g_taskScheduled = TRUE;
g_schedResponseTime = OS_SCHED_MAX_RESPONSE_TIME;
g_schedResponseID = OS_INVALID;
OsSchedSetNextExpireTime(newTask->startTime, newTask->taskID, newTask->startTime + newTask->timeSlice);
PRINTK("Entering scheduler\n");
OsSchedSetNextExpireTime(newTask->taskID, newTask->startTime + newTask->timeSlice);
}
BOOL OsSchedTaskSwitch(VOID)
@@ -563,7 +518,7 @@ BOOL OsSchedTaskSwitch(VOID)
if (g_schedResponseID == runTask->taskID) {
g_schedResponseTime = OS_SCHED_MAX_RESPONSE_TIME;
}
OsSchedSetNextExpireTime(newTask->startTime, newTask->taskID, endTime);
OsSchedSetNextExpireTime(newTask->taskID, endTime);
return isTaskSwitch;
}
@@ -595,7 +550,7 @@ VOID LOS_SchedTickHandler(VOID)
}
UINT32 intSave = LOS_IntLock();
g_tickStartTime = OsGetCurrSchedTimeCycle();
UINT64 tickStartTime = OsGetCurrSchedTimeCycle();
if (g_schedResponseID == OS_INVALID) {
g_tickIntLock++;
if (g_swtmrScan != NULL) {
@@ -606,14 +561,14 @@ VOID LOS_SchedTickHandler(VOID)
g_tickIntLock--;
}
OsTimeSliceUpdate(g_losTask.runTask, g_tickStartTime);
OsTimeSliceUpdate(g_losTask.runTask, tickStartTime);
g_losTask.runTask->startTime = OsGetCurrSchedTimeCycle();
g_schedResponseTime = OS_SCHED_MAX_RESPONSE_TIME;
if (LOS_CHECK_SCHEDULE) {
ArchTaskSchedule();
} else {
OsSchedUpdateExpireTime(g_losTask.runTask->startTime);
OsSchedUpdateExpireTime();
}
LOS_IntRestore(intSave);

View File

@@ -39,8 +39,8 @@ extern "C" {
#endif
#endif /* __cplusplus */
STATIC SortLinkAttribute g_taskSortLink;
STATIC SortLinkAttribute g_swtmrSortLink;
SortLinkAttribute g_taskSortLink;
SortLinkAttribute g_swtmrSortLink;
UINT32 OsSortLinkInit(SortLinkAttribute *sortLinkHeader)
{
@@ -78,29 +78,6 @@ STATIC INLINE VOID OsAddNode2SortLink(SortLinkAttribute *sortLinkHeader, SortLin
} while (1);
}
VOID OsDeleteNodeSortLink(SortLinkList *sortList)
{
LOS_ListDelete(&sortList->sortLinkNode);
SET_SORTLIST_VALUE(sortList, OS_SORT_LINK_INVALID_TIME);
}
STATIC INLINE UINT64 OsGetSortLinkNextExpireTime(SortLinkAttribute *sortHeader, UINT64 startTime)
{
LOS_DL_LIST *head = &sortHeader->sortLink;
LOS_DL_LIST *list = head->pstNext;
if (LOS_ListEmpty(head)) {
return OS_SCHED_MAX_RESPONSE_TIME - OS_TICK_RESPONSE_PRECISION;
}
SortLinkList *listSorted = LOS_DL_LIST_ENTRY(list, SortLinkList, sortLinkNode);
if (listSorted->responseTime <= (startTime + OS_TICK_RESPONSE_PRECISION)) {
return startTime + OS_TICK_RESPONSE_PRECISION;
}
return listSorted->responseTime;
}
VOID OsAdd2SortLink(SortLinkList *node, UINT64 startTime, UINT32 waitTicks, SortLinkType type)
{
UINT32 intSave;
@@ -144,30 +121,16 @@ SortLinkAttribute *OsGetSortLinkAttribute(SortLinkType type)
return NULL;
}
UINT64 OsGetNextExpireTime(UINT64 startTime)
{
UINT32 intSave;
SortLinkAttribute *taskHeader = &g_taskSortLink;
SortLinkAttribute *swtmrHeader = &g_swtmrSortLink;
intSave = LOS_IntLock();
UINT64 taskExpirTime = OsGetSortLinkNextExpireTime(taskHeader, startTime);
UINT64 swtmrExpirTime = OsGetSortLinkNextExpireTime(swtmrHeader, startTime);
LOS_IntRestore(intSave);
return (taskExpirTime < swtmrExpirTime) ? taskExpirTime : swtmrExpirTime;
}
UINT32 OsSortLinkGetTargetExpireTime(UINT64 currTime, const SortLinkList *targetSortList)
UINT64 OsSortLinkGetTargetExpireTime(UINT64 currTime, const SortLinkList *targetSortList)
{
if (currTime >= targetSortList->responseTime) {
return 0;
}
return (UINT32)(((targetSortList->responseTime - currTime) * LOSCFG_BASE_CORE_TICK_PER_SECOND) / g_sysClock);
return (targetSortList->responseTime - currTime);
}
UINT32 OsSortLinkGetNextExpireTime(const SortLinkAttribute *sortLinkHeader)
UINT64 OsSortLinkGetNextExpireTime(const SortLinkAttribute *sortLinkHeader)
{
LOS_DL_LIST *head = (LOS_DL_LIST *)&sortLinkHeader->sortLink;

View File

@@ -238,7 +238,7 @@ LITE_OS_SEC_TEXT VOID OsSwtmrStart(UINT64 currTime, SWTMR_CTRL_S *swtmr)
}
#endif
OsAdd2SortLink(&swtmr->stSortList, swtmr->startTime, swtmr->uwInterval, OS_SORT_LINK_SWTMR);
OsSchedUpdateExpireTime(currTime);
OsSchedUpdateExpireTime();
}
/*****************************************************************************
@@ -273,7 +273,8 @@ LITE_OS_SEC_TEXT VOID OsSwtmrStop(SWTMR_CTRL_S *swtmr)
OsDeleteSortLink(&swtmr->stSortList);
swtmr->ucState = OS_SWTMR_STATUS_CREATED;
OsSchedUpdateExpireTime(OsGetCurrSchedTimeCycle());
swtmr->ucOverrun = 0;
OsSchedUpdateExpireTime();
#if (LOSCFG_BASE_CORE_SWTMR_ALIGN == 1)
g_swtmrAlignID[swtmr->usTimerID % LOSCFG_BASE_CORE_SWTMR_LIMIT].isAligned = 0;
#endif
@@ -289,6 +290,7 @@ STATIC VOID OsSwtmrTimeoutHandle(UINT64 currTime, SWTMR_CTRL_S *swtmr)
(VOID)LOS_QueueWriteCopy(g_swtmrHandlerQueue, &swtmrHandler, sizeof(SwtmrHandlerItem), LOS_NO_WAIT);
if (swtmr->ucMode == LOS_SWTMR_MODE_PERIOD) {
swtmr->ucOverrun++;
OsSwtmrStart(currTime, swtmr);
} else if (swtmr->ucMode == LOS_SWTMR_MODE_NO_SELFDELETE) {
swtmr->ucState = OS_SWTMR_STATUS_CREATED;
@@ -325,6 +327,24 @@ STATIC BOOL OsSwtmrScan(VOID)
return needSchedule;
}
LITE_OS_SEC_TEXT VOID OsSwtmrResponseTimeReset(UINT64 startTime)
{
LOS_DL_LIST *listHead = &g_swtmrSortLinkList->sortLink;
LOS_DL_LIST *listNext = listHead->pstNext;
while (listNext != listHead) {
SortLinkList *sortList = LOS_DL_LIST_ENTRY(listNext, SortLinkList, sortLinkNode);
SWTMR_CTRL_S *swtmr = LOS_DL_LIST_ENTRY(sortList, SWTMR_CTRL_S, stSortList);
OsDeleteNodeSortLink(sortList);
#if (LOSCFG_BASE_CORE_SWTMR_ALIGN == 1)
g_swtmrAlignID[swtmr->usTimerID % LOSCFG_BASE_CORE_SWTMR_LIMIT].isAligned = 0;
#endif
swtmr->startTime = startTime;
OsSwtmrStart(startTime, swtmr);
listNext = listNext->pstNext;
}
}
/*****************************************************************************
Function : OsSwtmrGetNextTimeout
Description : Get next timeout
@@ -335,14 +355,23 @@ Return : Count of the Timer list
LITE_OS_SEC_TEXT UINT32 OsSwtmrGetNextTimeout(VOID)
{
UINT32 intSave = LOS_IntLock();
UINT32 ticks = OsSortLinkGetNextExpireTime(g_swtmrSortLinkList);
UINT64 time = OsSortLinkGetNextExpireTime(g_swtmrSortLinkList);
LOS_IntRestore(intSave);
return ticks;
time = time / OS_CYCLE_PER_TICK;
if (time > OS_NULL_INT) {
time = OS_NULL_INT;
}
return time;
}
LITE_OS_SEC_TEXT UINT32 OsSwtmrTimeGet(const SWTMR_CTRL_S *swtmr)
{
return OsSortLinkGetTargetExpireTime(OsGetCurrSchedTimeCycle(), &swtmr->stSortList);
UINT64 time = OsSortLinkGetTargetExpireTime(OsGetCurrSchedTimeCycle(), &swtmr->stSortList);
time = time / OS_CYCLE_PER_TICK;
if (time > OS_NULL_INT) {
time = OS_NULL_INT;
}
return (UINT32)time;
}
/*****************************************************************************
@@ -492,6 +521,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 LOS_SwtmrCreate(UINT32 interval,
swtmr->ucSensitive = sensitive;
#endif
swtmr->ucState = OS_SWTMR_STATUS_CREATED;
swtmr->ucOverrun = 0;
*swtmrId = swtmr->usTimerID;
SET_SORTLIST_VALUE(&swtmr->stSortList, OS_SORT_LINK_INVALID_TIME);
OsHookCall(LOS_HOOK_TYPE_SWTMR_CREATE, swtmr);

View File

@@ -1486,19 +1486,7 @@ LITE_OS_SEC_TEXT_MINOR VOID LOS_Msleep(UINT32 mSecs)
(VOID)LOS_TaskDelay(interval);
}
VOID LOS_UDelay(UINT64 microseconds)
VOID LOS_TaskResRecycle(VOID)
{
UINT64 endTime;
if (microseconds == 0) {
return;
}
endTime = (microseconds / OS_SYS_US_PER_SECOND) * g_sysClock +
(microseconds % OS_SYS_US_PER_SECOND) * g_sysClock / OS_SYS_US_PER_SECOND;
endTime = LOS_SysCycleGet() + endTime;
while (LOS_SysCycleGet() < endTime) {
}
return;
OsRecyleFinishedTask();
}

View File

@@ -36,13 +36,15 @@
#include "los_swtmr.h"
#include "los_sched.h"
#include "los_debug.h"
#include "stdint.h"
LITE_OS_SEC_BSS STATIC ArchTickTimer *g_sysTickTimer = NULL;
LITE_OS_SEC_BSS UINT32 g_ticksPerSec;
LITE_OS_SEC_BSS UINT32 g_uwCyclePerSec;
LITE_OS_SEC_BSS UINT32 g_cyclesPerTick;
LITE_OS_SEC_BSS UINT32 g_sysClock;
LITE_OS_SEC_BSS BOOL g_sysTimerIsInit = FALSE;
LITE_OS_SEC_BSS STATIC BOOL g_sysTimerIsInit = FALSE;
LITE_OS_SEC_BSS STATIC UINT64 g_tickTimerStartTime;
#if (LOSCFG_BASE_CORE_TICK_WTIMER == 0)
STATIC UINT64 g_tickTimerBase;
@@ -72,12 +74,12 @@ LITE_OS_SEC_TEXT VOID OsTickHandler(VOID)
LOS_SchedTickHandler();
}
LITE_OS_SEC_TEXT VOID OsTickTimerReload(UINT64 responseTime)
LITE_OS_SEC_TEXT UINT64 OsTickTimerReload(UINT64 period)
{
#if (LOSCFG_BASE_CORE_TICK_WTIMER == 0)
g_tickTimerBase = LOS_SysCycleGet();
#endif
g_sysTickTimer->reload(responseTime);
return g_sysTickTimer->reload(period);
}
LITE_OS_SEC_TEXT UINT64 LOS_SysCycleGet(VOID)
@@ -120,6 +122,10 @@ STATIC UINT32 TickTimerCheck(const ArchTickTimer *tick)
return LOS_ERRNO_TICK_CFG_INVALID;
}
if (tick->periodMax == 0) {
return LOS_ERRNO_TICK_CFG_INVALID;
}
if ((tick->init == NULL) || (tick->reload == NULL) ||
(tick->lock == NULL) || (tick->unlock == NULL) ||
(tick->getCycle == NULL)) {
@@ -172,6 +178,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 OsTickTimerInit(VOID)
g_sysTimerIsInit = TRUE;
LOS_IntRestore(intSave);
return LOS_OK;
}
@@ -223,6 +230,11 @@ LITE_OS_SEC_TEXT UINT32 LOS_TickTimerRegister(const ArchTickTimer *timer, const
return LOS_OK;
}
LITE_OS_SEC_TEXT_MINOR VOID OsTickSysTimerStartTimeSet(UINT64 currTime)
{
g_tickTimerStartTime = currTime;
}
/*****************************************************************************
Function : LOS_TickCountGet
Description : get current tick
@@ -232,7 +244,7 @@ Return : current tick
*****************************************************************************/
LITE_OS_SEC_TEXT_MINOR UINT64 LOS_TickCountGet(VOID)
{
return LOS_SysCycleGet() / OS_CYCLE_PER_TICK;
return (LOS_SysCycleGet() - g_tickTimerStartTime) / OS_CYCLE_PER_TICK;
}
/*****************************************************************************
@@ -336,3 +348,58 @@ LITE_OS_SEC_TEXT_INIT UINT32 OsCpuTick2US(CpuTick *cpuTick, UINT32 *usHi, UINT32
return LOS_OK;
}
/*****************************************************************************
Function : LOS_MS2Tick
Description : get current nanoseconds
Input : None
Output : None
Return : nanoseconds
*****************************************************************************/
UINT64 LOS_CurrNanosec(VOID)
{
UINT64 nanos;
nanos = LOS_SysCycleGet() * (OS_SYS_NS_PER_SECOND / OS_SYS_NS_PER_MS) / (g_sysClock / OS_SYS_NS_PER_MS);
return nanos;
}
/*****************************************************************************
Function : LOS_UDelay
Description : cpu delay function
Input : microseconds ---------- microseconds
Output : None
Return : None
*****************************************************************************/
VOID LOS_UDelay(UINT64 microseconds)
{
UINT64 endTime;
if (microseconds == 0) {
return;
}
endTime = (microseconds / OS_SYS_US_PER_SECOND) * g_sysClock +
(microseconds % OS_SYS_US_PER_SECOND) * g_sysClock / OS_SYS_US_PER_SECOND;
endTime = LOS_SysCycleGet() + endTime;
while (LOS_SysCycleGet() < endTime) {
}
return;
}
/*****************************************************************************
Function : LOS_MDelay
Description : cpu delay function
Input : millisec ---------- milliseconds
Output : None
Return : None
*****************************************************************************/
VOID LOS_MDelay(UINT32 millisec)
{
UINT32 delayUs = (UINT32_MAX / OS_SYS_US_PER_MS) * OS_SYS_US_PER_MS;
while (millisec > UINT32_MAX / OS_SYS_US_PER_MS) {
LOS_UDelay(delayUs);
millisec -= (UINT32_MAX / OS_SYS_US_PER_MS);
}
LOS_UDelay(millisec * OS_SYS_US_PER_MS);
return;
}

View File

@@ -1037,24 +1037,24 @@ STATIC UINT32 OsMemPoolDelete(VOID *pool)
UINT32 LOS_MemInit(VOID *pool, UINT32 size)
{
if ((pool == NULL) || (size <= OS_MEM_MIN_POOL_SIZE)) {
return OS_ERROR;
return LOS_NOK;
}
if (((UINTPTR)pool & (OS_MEM_ALIGN_SIZE - 1)) || \
(size & (OS_MEM_ALIGN_SIZE - 1))) {
PRINT_ERR("LiteOS heap memory address or size configured not aligned:address:0x%x,size:0x%x, alignsize:%d\n", \
(UINTPTR)pool, size, OS_MEM_ALIGN_SIZE);
return OS_ERROR;
return LOS_NOK;
}
if (OsMemPoolInit(pool, size)) {
return OS_ERROR;
return LOS_NOK;
}
#if (LOSCFG_MEM_MUL_POOL == 1)
if (OsMemPoolAdd(pool, size)) {
(VOID)OsMemPoolDeinit(pool);
return OS_ERROR;
return LOS_NOK;
}
#endif
@@ -1067,11 +1067,11 @@ UINT32 LOS_MemInit(VOID *pool, UINT32 size)
UINT32 LOS_MemDeInit(VOID *pool)
{
if (pool == NULL) {
return OS_ERROR;
return LOS_NOK;
}
if (OsMemPoolDelete(pool)) {
return OS_ERROR;
return LOS_NOK;
}
OsMemPoolDeinit(pool);
@@ -1593,11 +1593,11 @@ UINT32 LOS_MemFreeByTaskID(VOID *pool, UINT32 taskID)
{
UINT32 args[2] = { taskID, (UINT32)(UINTPTR)pool };
if (pool == NULL) {
return OS_ERROR;
return LOS_NOK;
}
if (taskID >= LOSCFG_BASE_CORE_TSK_LIMIT) {
return OS_ERROR;
return LOS_NOK;
}
OsAllMemNodeDoHandle(pool, MemNodeFreeByTaskIDHandle, (VOID *)args);

View File

@@ -64,6 +64,11 @@ static_library("test_hwi") {
"it_los_hwi_032.c",
"it_los_hwi_033.c",
"it_los_hwi_034.c",
"it_los_hwi_036.c",
"it_los_hwi_037.c",
"it_los_hwi_038.c",
"it_los_hwi_039.c",
"it_los_hwi_040.c",
"llt_los_hwi_035.c",
]

View File

@@ -57,6 +57,11 @@ VOID ItSuiteLosHwi()
ItLosHwi030();
ItLosHwi031();
ItLosHwi034();
ItLosHwi036();
ItLosHwi037();
ItLosHwi038();
ItLosHwi039();
ItLosHwi040();
#if (LOS_KERNEL_MULTI_HWI_TEST == 1)
ItLosHwi003();
ItLosHwi005();

View File

@@ -73,6 +73,12 @@ extern VOID ItLosHwi030(VOID);
extern VOID ItLosHwi031(VOID);
extern VOID ItLosHwi034(VOID);
extern VOID LltLosHwi035(VOID);
extern VOID ItLosHwi036(VOID);
extern VOID ItLosHwi037(VOID);
extern VOID ItLosHwi038(VOID);
extern VOID ItLosHwi039(VOID);
extern VOID ItLosHwi040(VOID);
#if (LOS_KERNEL_MULTI_HWI_TEST == 1)
extern VOID ItLosHwi003(VOID);

View File

@@ -0,0 +1,75 @@
/*
* 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 "osTest.h"
#include "it_los_hwi.h"
static UINT32 Testcase(VOID)
{
UINT32 intSave;
UINT32 deltaTicks;
UINT64 timeRecordNS;
UINT64 timeUpdateNS;
UINT64 delayMs = 10; // delay 10 MS
UINT32 deltaMs;
UINT64 delayTicks;
UINT32 loop = 10; // loop 10 time
delayTicks = delayMs * LOSCFG_BASE_CORE_TICK_PER_SECOND / OS_SYS_MS_PER_SECOND;
for (int i = 0; i <= loop; i++, delayTicks++) {
timeRecordNS = LOS_CurrNanosec();
LOS_TaskDelay(delayTicks);
timeUpdateNS = LOS_CurrNanosec();
deltaTicks = ((timeUpdateNS - timeRecordNS) * LOSCFG_BASE_CORE_TICK_PER_SECOND / OS_SYS_NS_PER_SECOND);
if (deltaTicks >= (delayTicks - 1) && deltaTicks <= (delayTicks + 1)) {
continue;
} else {
ICUNIT_ASSERT_EQUAL(deltaTicks, delayTicks, deltaTicks);
}
}
intSave = LOS_IntLock();
for (int i = 1; i <= loop; i++) {
timeRecordNS = LOS_CurrNanosec();
LOS_MDelay(i);
timeUpdateNS = LOS_CurrNanosec();
deltaMs = (timeUpdateNS - timeRecordNS) / OS_SYS_NS_PER_MS;
ICUNIT_ASSERT_EQUAL(deltaMs, i, deltaMs);
}
LOS_IntRestore(intSave);
return LOS_OK;
}
VOID ItLosHwi036(VOID) // IT_Layer_ModuleORFeature_No
{
TEST_ADD_CASE("ItLosHwi036", Testcase, TEST_LOS, TEST_HWI, TEST_LEVEL3, TEST_PRESSURE);
}

View File

@@ -0,0 +1,58 @@
/*
* 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 "osTest.h"
#include "it_los_hwi.h"
static UINT32 Testcase(VOID)
{
UINT32 intSave;
UINT64 timeRecordNS;
UINT64 timeUpdateNS;
UINT32 deltaMs;
UINT32 loop = 10; // loop 10 time
intSave = LOS_IntLock();
for (int i = 1; i <= loop; i++) {
timeRecordNS = LOS_CurrNanosec();
LOS_MDelay(i);
timeUpdateNS = LOS_CurrNanosec();
deltaMs = (timeUpdateNS - timeRecordNS) / OS_SYS_NS_PER_MS;
ICUNIT_ASSERT_EQUAL(deltaMs, i, deltaMs);
}
LOS_IntRestore(intSave);
return LOS_OK;
}
VOID ItLosHwi037(VOID) // IT_Layer_ModuleORFeature_No
{
TEST_ADD_CASE("ItLosHwi037", Testcase, TEST_LOS, TEST_HWI, TEST_LEVEL3, TEST_PRESSURE);
}

View File

@@ -0,0 +1,60 @@
/*
* 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 "osTest.h"
#include "it_los_hwi.h"
static UINT32 Testcase(VOID)
{
UINT32 deltaTicks;
UINT64 timeRecordNS;
UINT64 timeUpdateNS;
UINT64 tickRecord;
UINT64 tickUpdate;
UINT32 loop = 10; // loop 10 time.
timeRecordNS = LOS_CurrNanosec();
tickRecord = LOS_TickCountGet();
LOS_TaskDelay(1);
for (int i = 1; i <= loop; i++) {
LOS_MDelay(i * 10); // i * 10, Set delay time.
timeUpdateNS = LOS_CurrNanosec();
tickUpdate = LOS_TickCountGet();
deltaTicks = (UINT32)((timeUpdateNS - timeRecordNS) * LOSCFG_BASE_CORE_TICK_PER_SECOND / OS_SYS_NS_PER_SECOND);
ICUNIT_ASSERT_WITHIN_EQUAL(deltaTicks, tickUpdate - tickRecord - 1, tickUpdate - tickRecord + 1, deltaTicks);
}
return LOS_OK;
}
VOID ItLosHwi038(VOID) // IT_Layer_ModuleORFeature_No
{
TEST_ADD_CASE("ItLosHwi038", Testcase, TEST_LOS, TEST_HWI, TEST_LEVEL3, TEST_PRESSURE);
}

View File

@@ -0,0 +1,72 @@
/*
* 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 "osTest.h"
#include "it_los_hwi.h"
static VOID HwiF01(VOID)
{
TestHwiClear(HWI_NUM_TEST);
g_testCount++;
EXIT:
return;
}
static UINT32 Testcase(VOID)
{
UINT32 ret;
HWI_PRIOR_T hwiPrio = 2;
HWI_MODE_T mode = 0;
HWI_ARG_T arg = 0;
g_testCount = 0;
ret = LOS_HwiCreate(HWI_NUM_TEST, hwiPrio, mode, (HWI_PROC_FUNC)HwiF01, arg);
ICUNIT_ASSERT_EQUAL(ret, LOS_OK, ret);
LOS_HwiDisable(HWI_NUM_TEST);
TestHwiTrigger(HWI_NUM_TEST);
ICUNIT_GOTO_EQUAL(g_testCount, 0, g_testCount, EXIT); // Compare wiht the expected value 0.
LOS_HwiEnable(HWI_NUM_TEST);
ICUNIT_GOTO_EQUAL(g_testCount, 1, g_testCount, EXIT); // Compare wiht the expected value 1.
TestHwiDelete(HWI_NUM_TEST);
return LOS_OK;
EXIT:
TestHwiDelete(HWI_NUM_TEST);
return LOS_OK;
}
VOID ItLosHwi039(VOID) // IT_Layer_ModuleORFeature_No
{
TEST_ADD_CASE("ItLosHwi039", Testcase, TEST_LOS, TEST_HWI, TEST_LEVEL3, TEST_PRESSURE);
}

View File

@@ -0,0 +1,168 @@
/*
* 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 "osTest.h"
#include "it_los_hwi.h"
static UINT32 TesttriggerIrq(HWI_HANDLE_T hwiNum)
{
g_testCount++;
printf("This is TesttriggerIrq\n");
return LOS_OK;
}
static UINT32 TestclearIrq(HWI_HANDLE_T hwiNum)
{
g_testCount++;
printf("This is TestclearIrq\n");
return LOS_OK;
}
static UINT32 TestenableIrq(HWI_HANDLE_T hwiNum)
{
g_testCount++;
printf("This is TestenableIrq\n");
return LOS_OK;
}
static UINT32 TestdisableIrq(HWI_HANDLE_T hwiNum)
{
g_testCount++;
printf("This is TestdisableIrq\n");
return LOS_OK;
}
static UINT32 TestsetIrqPriority(HWI_HANDLE_T hwiNum, UINT8 priority)
{
g_testCount++;
printf("This is TestsetIrqPriority\n");
return LOS_OK;
}
static UINT32 TestgetCurIrqNum(VOID)
{
g_testCount++;
printf("This is TestgetCurIrqNum\n");
return HWI_NUM_TEST;
}
static VOID HwiF01(VOID)
{
TestHwiClear(HWI_NUM_TEST);
g_testCount++;
return;
}
static UINT32 Testcase(VOID)
{
UINT32 ret = LOS_OK;
UINT32 irqNum = 0;
HWI_PRIOR_T hwiPrio = 2; // 2, Set hwi priority.
HWI_MODE_T mode = 0;
HWI_ARG_T arg = 0;
HwiControllerOps *ops = NULL;
HwiControllerOps *opsBac = (HwiControllerOps *)malloc(sizeof(HwiControllerOps));
if (opsBac == NULL) {
ret = LOS_NOK;
}
ICUNIT_ASSERT_EQUAL(ret, LOS_OK, ret);
(VOID)memset_s(opsBac, sizeof(HwiControllerOps), 0, sizeof(HwiControllerOps));
g_testCount = 0;
ret = LOS_HwiCreate(HWI_NUM_TEST, hwiPrio, mode, (HWI_PROC_FUNC)HwiF01, arg);
ICUNIT_ASSERT_EQUAL(ret, LOS_OK, ret);
ret = LOS_HwiTrigger(LOSCFG_PLATFORM_HWI_LIMIT + 1);
ICUNIT_ASSERT_EQUAL(ret, OS_ERRNO_HWI_NUM_INVALID, ret);
ret = LOS_HwiEnable(LOSCFG_PLATFORM_HWI_LIMIT + 1);
ICUNIT_ASSERT_EQUAL(ret, OS_ERRNO_HWI_NUM_INVALID, ret);
ret = LOS_HwiDisable(LOSCFG_PLATFORM_HWI_LIMIT + 1);
ICUNIT_ASSERT_EQUAL(ret, OS_ERRNO_HWI_NUM_INVALID, ret);
ret = LOS_HwiClear(LOSCFG_PLATFORM_HWI_LIMIT + 1);
ICUNIT_ASSERT_EQUAL(ret, OS_ERRNO_HWI_NUM_INVALID, ret);
hwiPrio = 3; // 3, Set hwi priority.
ret = LOS_HwiSetPriority(LOSCFG_PLATFORM_HWI_LIMIT + 1, hwiPrio);
ICUNIT_ASSERT_NOT_EQUAL(ret, LOS_OK, ret);
ops = LOS_HwiOpsGet();
(VOID)memcpy_s(opsBac, sizeof(HwiControllerOps), ops, sizeof(HwiControllerOps));
ops->triggerIrq = TesttriggerIrq;
ops->enableIrq = TestenableIrq;
ops->disableIrq = TestdisableIrq;
ops->setIrqPriority = TestsetIrqPriority;
ops->getCurIrqNum = TestgetCurIrqNum;
ops->clearIrq = TestclearIrq;
LOS_HwiTrigger(HWI_NUM_TEST);
ICUNIT_GOTO_EQUAL(g_testCount, 1, g_testCount, EXIT); // Compare wiht the expected value 1.
LOS_HwiEnable(HWI_NUM_TEST);
ICUNIT_GOTO_EQUAL(g_testCount, 2, g_testCount, EXIT); // Compare wiht the expected value 2.
LOS_HwiDisable(HWI_NUM_TEST);
ICUNIT_GOTO_EQUAL(g_testCount, 3, g_testCount, EXIT); // Compare wiht the expected value 3.
LOS_HwiClear(HWI_NUM_TEST);
ICUNIT_GOTO_EQUAL(g_testCount, 4, g_testCount, EXIT); // Compare wiht the expected value 4.
LOS_HwiSetPriority(HWI_NUM_TEST, 3); // 3, Set hwi priority.
ICUNIT_GOTO_EQUAL(g_testCount, 5, g_testCount, EXIT); // Compare wiht the expected value 5.
irqNum = LOS_HwiCurIrqNum();
ICUNIT_ASSERT_EQUAL(irqNum, HWI_NUM_TEST, irqNum);
ICUNIT_GOTO_EQUAL(g_testCount, 6, g_testCount, EXIT); // Compare wiht the expected value 6.
ops->triggerIrq = opsBac->triggerIrq;
ops->enableIrq = opsBac->enableIrq;
ops->disableIrq = opsBac->disableIrq;
ops->setIrqPriority = opsBac->setIrqPriority;
ops->getCurIrqNum = opsBac->getCurIrqNum;
ops->clearIrq = opsBac->clearIrq;
free(opsBac);
ret = LOS_HwiDisable(HWI_NUM_TEST);
ICUNIT_ASSERT_EQUAL(ret, LOS_OK, ret);
LOS_HwiTrigger(HWI_NUM_TEST);
ICUNIT_GOTO_EQUAL(g_testCount, 6, g_testCount, EXIT); // Compare wiht the expected value 6.
ret = LOS_HwiEnable(HWI_NUM_TEST);
ICUNIT_GOTO_EQUAL(g_testCount, 7, g_testCount, EXIT); // Compare wiht the expected value 7.
ICUNIT_ASSERT_EQUAL(ret, LOS_OK, ret);
LOS_HwiTrigger(HWI_NUM_TEST);
ICUNIT_GOTO_EQUAL(g_testCount, 8, g_testCount, EXIT); // Compare wiht the expected value 8.
TestHwiDelete(HWI_NUM_TEST);
return LOS_OK;
EXIT:
TestHwiDelete(HWI_NUM_TEST);
free(opsBac);
return LOS_OK;
}
VOID ItLosHwi040(VOID) // IT_Layer_ModuleORFeature_No
{
TEST_ADD_CASE("ItLosHwi040", Testcase, TEST_LOS, TEST_HWI, TEST_LEVEL3, TEST_PRESSURE);
}

View File

@@ -38,10 +38,10 @@ static UINT32 TestCase(VOID)
UINT32 ret;
ret = LOS_MemInit(NULL, TEST_MEM_SIZE);
ICUNIT_ASSERT_EQUAL(ret, OS_ERROR, ret);
ICUNIT_ASSERT_EQUAL(ret, LOS_NOK, ret);
ret = LOS_MemInit(g_memPool, MIN_MEM_POOL_SIZE - 1);
ICUNIT_ASSERT_EQUAL(ret, OS_ERROR, ret);
ICUNIT_ASSERT_EQUAL(ret, LOS_NOK, ret);
return LOS_OK;
}

View File

@@ -43,14 +43,14 @@ static VOID HwiF01(void)
ret = LOS_MuxPend(g_mutexTest, 0);
ICUNIT_ASSERT_EQUAL_VOID(ret, LOS_ERRNO_MUX_PEND_INTERR, ret);
ICUNIT_ASSERT_EQUAL_VOID(ret, LOS_ERRNO_MUX_IN_INTERR, ret);
ret = LOS_MuxPend(g_mutexTest, LOS_WAIT_FOREVER);
ICUNIT_ASSERT_EQUAL_VOID(ret, LOS_ERRNO_MUX_PEND_INTERR, ret);
ICUNIT_ASSERT_EQUAL_VOID(ret, LOS_ERRNO_MUX_IN_INTERR, ret);
ret = LOS_MuxPost(g_mutexTest);
ICUNIT_ASSERT_EQUAL_VOID(ret, LOS_ERRNO_MUX_INVALID, ret);
ICUNIT_ASSERT_EQUAL_VOID(ret, LOS_ERRNO_MUX_IN_INTERR, ret);
ret = LOS_MuxDelete(g_mutexTest);
ICUNIT_ASSERT_EQUAL_VOID(ret, LOS_OK, ret);

View File

@@ -40,7 +40,7 @@ static VOID HwiF01(void)
TestHwiClear(HWI_NUM_TEST);
ret = LOS_MuxPost(g_mutexTest);
ICUNIT_ASSERT_EQUAL_VOID(ret, LOS_OK, ret);
ICUNIT_ASSERT_EQUAL_VOID(ret, LOS_ERRNO_MUX_IN_INTERR, ret);
g_testCount++;
}
@@ -65,7 +65,7 @@ static UINT32 Testcase(VOID)
ICUNIT_ASSERT_EQUAL(g_testCount, 1, g_testCount); // 1, Here, assert that g_testCount is equal to 1.
ret = LOS_MuxPost(g_mutexTest);
ICUNIT_ASSERT_EQUAL(ret, LOS_ERRNO_MUX_INVALID, ret);
ICUNIT_ASSERT_EQUAL(ret, LOS_OK, ret);
ret = LOS_MuxDelete(g_mutexTest);
ICUNIT_ASSERT_EQUAL(ret, LOS_OK, ret);

View File

@@ -40,7 +40,7 @@ static VOID HwiF01(void)
TestHwiClear(HWI_NUM_TEST);
ret = LOS_MuxPost(g_mutexTest);
ICUNIT_ASSERT_EQUAL_VOID(ret, LOS_OK, ret);
ICUNIT_ASSERT_EQUAL_VOID(ret, LOS_ERRNO_MUX_IN_INTERR, ret);
g_testCount++;
}
@@ -64,7 +64,7 @@ static UINT32 Testcase(VOID)
ICUNIT_ASSERT_EQUAL(g_testCount, 1, g_testCount); // 1, Here, assert that g_testCount is equal to 1.
ret = LOS_MuxPost(g_mutexTest);
ICUNIT_ASSERT_EQUAL(ret, LOS_ERRNO_MUX_INVALID, ret);
ICUNIT_ASSERT_EQUAL(ret, LOS_OK, ret);
ret = LOS_MuxDelete(g_mutexTest);
ICUNIT_ASSERT_EQUAL(ret, LOS_OK, ret);

View File

@@ -46,15 +46,15 @@ static VOID Func01(void)
TestHwiDelete(HWI_NUM_TEST);
} else if (g_testCount == 3) { // 3, Here, The current possible value of the variable.
ICUNIT_ASSERT_EQUAL_VOID(ret, LOS_ERRNO_MUX_PEND_INTERR, ret);
ICUNIT_ASSERT_EQUAL_VOID(ret, LOS_ERRNO_MUX_IN_INTERR, ret);
}
ret = LOS_MuxPost(g_mutexTest);
if (g_testCount == 3) { // 3, Here, The current possible value of the variable.
ICUNIT_ASSERT_EQUAL_VOID(ret, LOS_OK, ret);
ICUNIT_ASSERT_EQUAL_VOID(ret, LOS_ERRNO_MUX_IN_INTERR, ret);
} else if (g_testCount == 4) { // 4, Here, The current possible value of the variable.
ICUNIT_ASSERT_EQUAL_VOID(ret, LOS_ERRNO_MUX_INVALID, ret);
ICUNIT_ASSERT_EQUAL_VOID(ret, LOS_OK, ret);
}
g_testCount++;
@@ -64,7 +64,7 @@ static VOID HwiF01(void)
{
TestHwiClear(HWI_NUM_TEST);
ICUNIT_ASSERT_EQUAL_VOID(g_testCount, 1, g_testCount);
ICUNIT_ASSERT_EQUAL_VOID(g_testCount, 1, g_testCount);
g_testCount++;

View File

@@ -45,7 +45,7 @@ static VOID HwiF02(void)
g_testCount++;
ret = LOS_MuxPost(g_mutexTest);
ICUNIT_ASSERT_EQUAL_VOID(ret, LOS_ERRNO_MUX_INVALID, ret);
ICUNIT_ASSERT_EQUAL_VOID(ret, LOS_ERRNO_MUX_IN_INTERR, ret);
}
static VOID HwiF01(void)
@@ -57,7 +57,7 @@ static VOID HwiF01(void)
g_testCount++;
ret = LOS_MuxPend(g_mutexTest, LOS_WAIT_FOREVER);
ICUNIT_ASSERT_EQUAL_VOID(ret, LOS_ERRNO_MUX_PEND_INTERR, ret);
ICUNIT_ASSERT_EQUAL_VOID(ret, LOS_ERRNO_MUX_IN_INTERR, ret);
ret = LOS_HwiCreate(HWI_NUM_TEST0, 1, 0, (HWI_PROC_FUNC)HwiF02, 0);
ICUNIT_ASSERT_EQUAL_VOID(ret, LOS_OK, ret);

View File

@@ -45,10 +45,10 @@ static UINT32 Testcase(VOID)
ret = LOS_QueueCreate(NULL, QUEUE_BASE_NUM, &queueID[index], 0, QUEUE_BASE_MSGSIZE);
ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT);
}
ret = LOS_QueueWrite(LOSCFG_BASE_IPC_QUEUE_LIMIT - 1, &buff1, QUEUE_BASE_MSGSIZE, 0);
ret = LOS_QueueWrite(queueID[limit - 1], &buff1, QUEUE_BASE_MSGSIZE, 0);
ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT);
ret = LOS_QueueRead(LOSCFG_BASE_IPC_QUEUE_LIMIT - 1, &buff2, QUEUE_BASE_MSGSIZE, 0);
ret = LOS_QueueRead(queueID[limit - 1], &buff2, QUEUE_BASE_MSGSIZE, 0);
ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT);
ret = LOS_QueueCreate("Q1", QUEUE_BASE_NUM, &queueID[index], 0, QUEUE_BASE_MSGSIZE);

View File

@@ -46,11 +46,11 @@ static UINT32 Testcase(VOID)
ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT);
}
// 2, is test for LOSCFG_BASE_IPC_QUEUE_LIMIT - 2
ret = LOS_QueueWrite(LOSCFG_BASE_IPC_QUEUE_LIMIT - 2, &buff1, QUEUE_BASE_MSGSIZE, 0);
ret = LOS_QueueWrite(queueID[limit - 1], &buff1, QUEUE_BASE_MSGSIZE, 0);
ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT);
// 2, is test for LOSCFG_BASE_IPC_QUEUE_LIMIT - 2
ret = LOS_QueueRead(LOSCFG_BASE_IPC_QUEUE_LIMIT - 2, &buff2, QUEUE_BASE_MSGSIZE, 0);
ret = LOS_QueueRead(queueID[limit - 1], &buff2, QUEUE_BASE_MSGSIZE, 0);
ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT);
EXIT:

View File

@@ -45,8 +45,7 @@ static UINT32 Testcase(VOID)
ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT);
ret = LOS_QueueRead(g_testQueueID01, &buff2, 0xffffffff, 0);
ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT);
ICUNIT_GOTO_EQUAL(*((char *)(intptr_t)buff2 + 7), buff1[7], *((char *)(intptr_t)buff2 + 7), EXIT); // 7, QUEUE_BASE_MSGSIZE - 1
ICUNIT_GOTO_EQUAL(ret, LOS_ERRNO_QUEUE_BUFFER_SIZE_TOO_BIG, ret, EXIT);
ret = LOS_QueueDelete(g_testQueueID01);
ICUNIT_ASSERT_EQUAL(ret, LOS_OK, ret);

View File

@@ -45,8 +45,7 @@ static UINT32 Testcase(VOID)
ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT);
ret = LOS_QueueRead(g_testQueueID01, &buff2, (0xffffffff - 1), 0);
ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT);
ICUNIT_GOTO_EQUAL(*((char *)(intptr_t)buff2 + 7), buff1[7], *((char *)(intptr_t)buff2 + 7), EXIT); // 7, Verify that the data is correct
ICUNIT_GOTO_EQUAL(ret, LOS_ERRNO_QUEUE_BUFFER_SIZE_TOO_BIG, ret, EXIT);
ret = LOS_QueueDelete(g_testQueueID01);
ICUNIT_ASSERT_EQUAL(ret, LOS_OK, ret);

View File

@@ -46,10 +46,10 @@ static UINT32 Testcase(VOID)
ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT);
}
ret = LOS_QueueWriteHead(LOSCFG_BASE_IPC_QUEUE_LIMIT - 1, &buff1, QUEUE_BASE_MSGSIZE, 0);
ret = LOS_QueueWriteHead(queueID[limit - 1], &buff1, QUEUE_BASE_MSGSIZE, 0);
ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT);
ret = LOS_QueueRead(LOSCFG_BASE_IPC_QUEUE_LIMIT - 1, &buff2, QUEUE_BASE_MSGSIZE, 0);
ret = LOS_QueueRead(queueID[limit - 1], &buff2, QUEUE_BASE_MSGSIZE, 0);
ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT);
ret = LOS_QueueCreate("Q1", QUEUE_BASE_NUM, &queueID[index], 0, QUEUE_BASE_MSGSIZE);

View File

@@ -46,10 +46,10 @@ static UINT32 Testcase(VOID)
ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT);
}
ret = LOS_QueueWriteHead(LOSCFG_BASE_IPC_QUEUE_LIMIT - 1, &buff1, QUEUE_BASE_MSGSIZE, 0);
ret = LOS_QueueWriteHead(queueID[limit - 1], &buff1, QUEUE_BASE_MSGSIZE, 0);
ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT);
ret = LOS_QueueRead(LOSCFG_BASE_IPC_QUEUE_LIMIT - 1, &buff2, QUEUE_BASE_MSGSIZE, 0);
ret = LOS_QueueRead(queueID[limit - 1], &buff2, QUEUE_BASE_MSGSIZE, 0);
ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT);
EXIT:

View File

@@ -107,6 +107,8 @@ static_library("test_swtmr") {
"It_los_swtmr_077.c",
"It_los_swtmr_078.c",
"It_los_swtmr_079.c",
"It_los_swtmr_080.c",
"It_los_swtmr_081.c",
"It_los_swtmr_Align_001.c",
"It_los_swtmr_Align_002.c",
"It_los_swtmr_Align_003.c",

View File

@@ -114,6 +114,8 @@ VOID ItSuiteLosSwtmr(void)
ItLosSwtmr077();
ItLosSwtmr078();
ItLosSwtmr079();
ItLosSwtmr080();
ItLosSwtmr081();
#if (LOSCFG_BASE_CORE_SWTMR_ALIGN == 1)
ItLosSwtmrAlign005();
ItLosSwtmrAlign006();

View File

@@ -148,6 +148,8 @@ extern VOID ItLosSwtmr076(VOID);
extern VOID ItLosSwtmr077(VOID);
extern VOID ItLosSwtmr078(VOID);
extern VOID ItLosSwtmr079(VOID);
extern VOID ItLosSwtmr080(VOID);
extern VOID ItLosSwtmr081(VOID);
extern VOID ItLosSwtmrAlign001(VOID);
extern VOID ItLosSwtmrAlign002(VOID);

View File

@@ -72,8 +72,8 @@ static UINT32 Testcase(VOID)
ret = LOS_SwtmrTimeGet(swTmrID, &tick);
ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT);
// 2 - 1, Here, assert that uwTick is equal to this .
ICUNIT_GOTO_EQUAL(tick, 2 - 1, tick, EXIT);
// 1, Here, assert that uwTick is equal to this .
ICUNIT_GOTO_EQUAL(tick, 1, tick, EXIT);
// 2, Here, assert that g_testCount is equal to this .
ICUNIT_GOTO_EQUAL(g_testCount, 2, g_testCount, EXIT);

View File

@@ -0,0 +1,87 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "osTest.h"
#include "It_los_swtmr.h"
static UINT32 g_testCount1 = 0;
static VOID Case1(UINT32 arg)
{
g_testCount1++;
return;
}
static UINT32 Testcase(VOID)
{
UINT32 ret;
g_testCount1 = 0;
UINT64 tickRecord;
UINT64 tickUpdate;
UINT64 delayTicks;
const UINT64 delayMs = 10; // delay 10 MS
// 4, Timeout interval of a periodic software timer.
ret = LOS_SwtmrCreate(4, LOS_SWTMR_MODE_PERIOD, Case1, &g_swtmrId1, 0xffff
#if (LOSCFG_BASE_CORE_SWTMR_ALIGN == 1)
, OS_SWTMR_ROUSES_ALLOW, OS_SWTMR_ALIGN_INSENSITIVE
#endif
);
ICUNIT_ASSERT_EQUAL(ret, LOS_OK, ret);
ret = LOS_SwtmrStart(g_swtmrId1);
ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT);
tickRecord = LOS_TickCountGet();
LOS_MDelay(delayMs);
tickUpdate = LOS_TickCountGet();
// 0, Here, assert that g_testCount is equal to this.
ICUNIT_ASSERT_EQUAL(g_testCount1, 0, g_testCount);
delayTicks = delayMs * LOSCFG_BASE_CORE_TICK_PER_SECOND / OS_SYS_MS_PER_SECOND;
ICUNIT_ASSERT_WITHIN_EQUAL(delayTicks, tickUpdate - tickRecord - 1, tickUpdate - tickRecord + 1, delayTicks);
// 10, set task delay time.
LOS_TaskDelay(10);
// 2, Here, assert that g_testCount is equal to this.
ICUNIT_ASSERT_EQUAL(g_testCount1, 2, g_testCount);
EXIT:
LOS_SwtmrDelete(g_swtmrId1);
return LOS_OK;
}
VOID ItLosSwtmr080() // IT_Layer_ModuleORFeature_No
{
TEST_ADD_CASE("ItLosSwtmr080", Testcase, TEST_LOS, TEST_SWTMR, TEST_LEVEL1, TEST_FUNCTION);
}

Some files were not shown because too many files have changed in this diff Show More