diff --git a/.gitee/PULL_REQUEST_TEMPLATE.zh-CN.md b/.gitee/PULL_REQUEST_TEMPLATE.zh-CN.md
index 128e4c3e..2e36464c 100644
--- a/.gitee/PULL_REQUEST_TEMPLATE.zh-CN.md
+++ b/.gitee/PULL_REQUEST_TEMPLATE.zh-CN.md
@@ -12,7 +12,7 @@
### 是否需要同步至release(如:3.0LTS ... )分支?
-必须选择一项:
+必须选择一项(在MarkDown模式下用[x]替换[ ]即可勾选对应选项):
- [ ] 是,需要同步的分支:
- [ ] 否
diff --git a/BUILD.gn b/BUILD.gn
index 82c2d797..4402935c 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -143,6 +143,7 @@ config("kconfig_config") {
"$LITEOS_MENUCONFIG_H",
]
asmflags = cflags
+ cflags_cc = cflags
}
config("warn_config") {
diff --git a/arch/arm/arm9/gcc/los_arch_interrupt.h b/arch/arm/arm9/gcc/los_arch_interrupt.h
index bf8a2272..588cf60b 100644
--- a/arch/arm/arm9/gcc/los_arch_interrupt.h
+++ b/arch/arm/arm9/gcc/los_arch_interrupt.h
@@ -97,7 +97,8 @@ extern UINT32 g_intCount;
*
* Value: 0x02000900
*
- * Solution: Ensure that the interrupt number is valid. The value range of the interrupt number applicable for a Cortex-A7 platform is [OS_USER_HWI_MIN,OS_USER_HWI_MAX].
+ * Solution: Ensure that the interrupt number is valid.
+ * The value range of the interrupt number applicable for a arm9 platform is [OS_USER_HWI_MIN,OS_USER_HWI_MAX].
*/
#define OS_ERRNO_HWI_NUM_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x00)
@@ -147,7 +148,8 @@ extern UINT32 g_intCount;
*
* Value: 0x02000905
*
- * Solution: Ensure that the interrupt priority is valid. The value range of the interrupt priority applicable for a Cortex-A7 platform is [0,15].
+ * Solution: Ensure that the interrupt priority is valid.
+ * The value range of the interrupt priority applicable for a arm9 platform is [0,15].
*/
#define OS_ERRNO_HWI_PRIO_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x05)
@@ -157,7 +159,8 @@ extern UINT32 g_intCount;
*
* 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.
+ * 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)
@@ -204,25 +207,6 @@ extern VOID OsSetVector(UINT32 num, HWI_PROC_FUNC vector);
*/
extern VOID HalInterrupt(VOID);
-/* *
- * @ingroup los_arch_interrupt
- * @brief: Get an interrupt number.
- *
- * @par Description:
- * This API is used to get the current interrupt number.
- *
- * @attention:
- *
- *
- * @param: None.
- *
- * @retval: Interrupt Indexes number.
- * @par Dependency:
- * - los_arch_interrupt.h: the header file that contains the API declaration.
- * @see None.
- */
-extern UINT32 HalIntNumGet(VOID);
-
/* *
* @ingroup los_arch_interrupt
* @brief: Default vector handling function.
diff --git a/arch/arm/arm9/gcc/los_interrupt.c b/arch/arm/arm9/gcc/los_interrupt.c
index 5fab22bc..712e8445 100644
--- a/arch/arm/arm9/gcc/los_interrupt.c
+++ b/arch/arm/arm9/gcc/los_interrupt.c
@@ -48,9 +48,6 @@
#define OS_INT_ENABLE_ADDR (OS_INT_REG_BASE)
#define OS_INT_STATUS_ADDR (OS_INT_REG_BASE + 12)
-#define OS_INT_ENABLE(num) (*((volatile UINT32 *)OS_INT_ENABLE_ADDR) |= (1U << (num)))
-#define OS_INT_DISABLE(num) (*((volatile UINT32 *)OS_INT_ENABLE_ADDR ) &= ~(1U << (num)))
-
#define OS_INSTR_SET_MASK 0x01000020U
#define OS_ARM_INSTR_LEN 4
#define OS_THUMB_INSTR_LEN 2
@@ -112,20 +109,49 @@ VOID OsSetVector(UINT32 num, HWI_PROC_FUNC vector)
/* ****************************************************************************
- Function : HalIntNumGet
+ Function : HwiNumGet
Description : Get an interrupt number
Input : None
Output : None
Return : Interrupt Indexes number
**************************************************************************** */
-LITE_OS_SEC_TEXT_MINOR UINT32 HalIntNumGet(VOID)
+STATIC UINT32 HwiNumGet(VOID)
{
UINT32 status;
READ_UINT32(status, OS_INT_STATUS_ADDR);
+
return (31 - CLZ(status));
}
+STATIC UINT32 HwiUnmask(HWI_HANDLE_T hwiNum)
+{
+ if (hwiNum >= OS_HWI_MAX_NUM) {
+ return OS_ERRNO_HWI_NUM_INVALID;
+ }
+
+ *((volatile UINT32 *)OS_INT_ENABLE_ADDR) |= (1U << (hwiNum));
+
+ return LOS_OK;
+}
+
+STATIC UINT32 HwiMask(HWI_HANDLE_T hwiNum)
+{
+ if (hwiNum >= OS_HWI_MAX_NUM) {
+ return OS_ERRNO_HWI_NUM_INVALID;
+ }
+
+ *((volatile UINT32 *)OS_INT_ENABLE_ADDR) &= ~(1U << (hwiNum));
+
+ return LOS_OK;
+}
+
+HwiControllerOps g_archHwiOps = {
+ .enableIrq = HwiUnmask,
+ .disableIrq = HwiMask,
+ .getCurIrqNum = HwiNumGet,
+};
+
inline UINT32 ArchIsIntActive(VOID)
{
return (g_intCount > 0);
@@ -140,8 +166,8 @@ inline UINT32 ArchIsIntActive(VOID)
/*lint -e529*/
LITE_OS_SEC_TEXT_MINOR VOID HalHwiDefaultHandler(VOID)
{
- UINT32 irqNum = HalIntNumGet();
- PRINT_ERR("%s irqnum:%d\n", __FUNCTION__, irqNum);
+ UINT32 irqNum = HwiNumGet();
+ PRINT_ERR("%s irqnum:%u\n", __FUNCTION__, irqNum);
while (1) {}
}
@@ -175,7 +201,7 @@ LITE_OS_SEC_TEXT VOID HalInterrupt(VOID)
OsSchedUpdateSleepTime();
#endif
- hwiIndex = HalIntNumGet();
+ hwiIndex = HwiNumGet();
OsHookCall(LOS_HOOK_TYPE_ISR_ENTER, hwiIndex);
@@ -237,7 +263,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 ArchHwiCreate(HWI_HANDLE_T hwiNum,
#else
OsSetVector(hwiNum, handler);
#endif
- OS_INT_ENABLE(hwiNum);
+ HwiUnmask(hwiNum);
LOS_IntRestore(intSave);
return LOS_OK;
@@ -258,7 +284,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 ArchHwiDelete(HWI_HANDLE_T hwiNum)
return OS_ERRNO_HWI_NUM_INVALID;
}
- OS_INT_DISABLE(hwiNum);
+ HwiMask(hwiNum);
intSave = LOS_IntLock();
g_hwiForm[hwiNum + OS_SYS_VECTOR_CNT] = (HWI_PROC_FUNC)HalHwiDefaultHandler;
diff --git a/arch/arm/cortex-m3/keil/los_arch_interrupt.h b/arch/arm/cortex-m3/keil/los_arch_interrupt.h
index 2f0c67ea..665a7a96 100644
--- a/arch/arm/cortex-m3/keil/los_arch_interrupt.h
+++ b/arch/arm/cortex-m3/keil/los_arch_interrupt.h
@@ -109,7 +109,8 @@ extern UINT32 _BootVectors[];
*
* Value: 0x02000900
*
- * Solution: Ensure that the interrupt number is valid. The value range of the interrupt number applicable for a Cortex-A7 platform is [OS_USER_HWI_MIN,OS_USER_HWI_MAX].
+ * Solution: Ensure that the interrupt number is valid.
+ * The value range of the interrupt number applicable for a Cortex-M3 platform is [OS_USER_HWI_MIN,OS_USER_HWI_MAX].
*/
#define OS_ERRNO_HWI_NUM_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x00)
@@ -159,7 +160,8 @@ extern UINT32 _BootVectors[];
*
* Value: 0x02000905
*
- * Solution: Ensure that the interrupt priority is valid. The value range of the interrupt priority applicable for a Cortex-A7 platform is [0,15].
+ * Solution: Ensure that the interrupt priority is valid.
+ * The value range of the interrupt priority applicable for a Cortex-M3 platform is [0,15].
*/
#define OS_ERRNO_HWI_PRIO_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x05)
@@ -169,7 +171,8 @@ extern UINT32 _BootVectors[];
*
* 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.
+ * 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)
@@ -342,25 +345,6 @@ extern VOID OsSetVector(UINT32 num, HWI_PROC_FUNC vector);
*/
extern VOID HalInterrupt(VOID);
-/* *
- * @ingroup los_arch_interrupt
- * @brief: Get an interrupt number.
- *
- * @par Description:
- * This API is used to get the current interrupt number.
- *
- * @attention:
- *
- *
- * @param: None.
- *
- * @retval: Interrupt Indexes number.
- * @par Dependency:
- * - los_arch_interrupt.h: the header file that contains the API declaration.
- * @see None.
- */
-extern UINT32 HalIntNumGet(VOID);
-
/* *
* @ingroup los_arch_interrupt
* @brief: Default vector handling function.
diff --git a/arch/arm/cortex-m3/keil/los_interrupt.c b/arch/arm/cortex-m3/keil/los_interrupt.c
index 76bbe4ef..5ca320fb 100644
--- a/arch/arm/cortex-m3/keil/los_interrupt.c
+++ b/arch/arm/cortex-m3/keil/los_interrupt.c
@@ -108,17 +108,85 @@ WEAK VOID SysTick_Handler(VOID)
}
/* ****************************************************************************
- Function : HalIntNumGet
+ Function : HwiNumGet
Description : Get an interrupt number
Input : None
Output : None
Return : Interrupt Indexes number
**************************************************************************** */
-LITE_OS_SEC_TEXT_MINOR UINT32 HalIntNumGet(VOID)
+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);
@@ -133,8 +201,8 @@ inline UINT32 ArchIsIntActive(VOID)
/*lint -e529*/
LITE_OS_SEC_TEXT_MINOR VOID HalHwiDefaultHandler(VOID)
{
- UINT32 irqNum = HalIntNumGet();
- PRINT_ERR("%s irqnum:%d\n", __FUNCTION__, irqNum);
+ UINT32 irqNum = HwiNumGet();
+ PRINT_ERR("%s irqnum:%u\n", __FUNCTION__, irqNum);
while (1) {}
}
@@ -168,7 +236,7 @@ LITE_OS_SEC_TEXT VOID HalInterrupt(VOID)
g_intCount++;
LOS_IntRestore(intSave);
- hwiIndex = HalIntNumGet();
+ hwiIndex = HwiNumGet();
OsHookCall(LOS_HOOK_TYPE_ISR_ENTER, hwiIndex);
@@ -234,8 +302,8 @@ LITE_OS_SEC_TEXT_INIT UINT32 ArchHwiCreate(HWI_HANDLE_T hwiNum,
#else
OsSetVector(hwiNum, handler);
#endif
- NVIC_EnableIRQ((IRQn_Type)hwiNum);
- NVIC_SetPriority((IRQn_Type)hwiNum, hwiPrio);
+ HwiUnmask((IRQn_Type)hwiNum);
+ HwiSetPriority((IRQn_Type)hwiNum, hwiPrio);
LOS_IntRestore(intSave);
@@ -257,7 +325,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 ArchHwiDelete(HWI_HANDLE_T hwiNum)
return OS_ERRNO_HWI_NUM_INVALID;
}
- NVIC_DisableIRQ((IRQn_Type)hwiNum);
+ HwiMask((IRQn_Type)hwiNum);
intSave = LOS_IntLock();
diff --git a/arch/arm/cortex-m33/gcc/NTZ/los_arch_interrupt.h b/arch/arm/cortex-m33/gcc/NTZ/los_arch_interrupt.h
index 99c53032..dd9a4f22 100755
--- a/arch/arm/cortex-m33/gcc/NTZ/los_arch_interrupt.h
+++ b/arch/arm/cortex-m33/gcc/NTZ/los_arch_interrupt.h
@@ -109,7 +109,8 @@ extern UINT32 _BootVectors[];
*
* Value: 0x02000900
*
- * Solution: Ensure that the interrupt number is valid. The value range of the interrupt number applicable for a Cortex-A7 platform is [OS_USER_HWI_MIN,OS_USER_HWI_MAX].
+ * 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)
@@ -159,7 +160,8 @@ extern UINT32 _BootVectors[];
*
* Value: 0x02000905
*
- * Solution: Ensure that the interrupt priority is valid. The value range of the interrupt priority applicable for a Cortex-A7 platform is [0,15].
+ * 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)
@@ -169,7 +171,8 @@ extern UINT32 _BootVectors[];
*
* 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.
+ * 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)
@@ -342,25 +345,6 @@ extern VOID OsSetVector(UINT32 num, HWI_PROC_FUNC vector);
*/
extern VOID HalInterrupt(VOID);
-/* *
- * @ingroup los_arch_interrupt
- * @brief: Get an interrupt number.
- *
- * @par Description:
- * This API is used to get the current interrupt number.
- *
- * @attention:
- *
- *
- * @param: None.
- *
- * @retval: Interrupt Indexes number.
- * @par Dependency:
- * - los_arch_interrupt.h: the header file that contains the API declaration.
- * @see None.
- */
-extern UINT32 HalIntNumGet(VOID);
-
/* *
* @ingroup los_arch_interrupt
* @brief: Default vector handling function.
diff --git a/arch/arm/cortex-m33/gcc/NTZ/los_interrupt.c b/arch/arm/cortex-m33/gcc/NTZ/los_interrupt.c
index b908b3b5..4a3fbf76 100755
--- a/arch/arm/cortex-m33/gcc/NTZ/los_interrupt.c
+++ b/arch/arm/cortex-m33/gcc/NTZ/los_interrupt.c
@@ -40,6 +40,7 @@
#include "los_memory.h"
#include "los_membox.h"
+#define DEF_HANDLER_START_INDEX 2
/*lint -save -e40 -e522 -e533*/
UINT32 g_intCount = 0;
@@ -98,17 +99,85 @@ VOID OsSetVector(UINT32 num, HWI_PROC_FUNC vector)
#endif
/* ****************************************************************************
- Function : HalIntNumGet
+ Function : HwiNumGet
Description : Get an interrupt number
Input : None
Output : None
Return : Interrupt Indexes number
**************************************************************************** */
-LITE_OS_SEC_TEXT_MINOR UINT32 HalIntNumGet(VOID)
+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);
@@ -123,8 +192,8 @@ inline UINT32 ArchIsIntActive(VOID)
/*lint -e529*/
LITE_OS_SEC_TEXT_MINOR VOID HalHwiDefaultHandler(VOID)
{
- UINT32 irqNum = HalIntNumGet();
- PRINT_ERR("%s irqnum:%d\n", __FUNCTION__, irqNum);
+ UINT32 irqNum = HwiNumGet();
+ PRINT_ERR("%s irqnum:%u\n", __FUNCTION__, irqNum);
while (1) {}
}
@@ -158,7 +227,7 @@ LITE_OS_SEC_TEXT VOID HalInterrupt(VOID)
g_intCount++;
LOS_IntRestore(intSave);
- hwiIndex = HalIntNumGet();
+ hwiIndex = HwiNumGet();
OsHookCall(LOS_HOOK_TYPE_ISR_ENTER, hwiIndex);
@@ -224,8 +293,8 @@ LITE_OS_SEC_TEXT_INIT UINT32 ArchHwiCreate(HWI_HANDLE_T hwiNum,
#else
OsSetVector(hwiNum, handler);
#endif
- NVIC_EnableIRQ((IRQn_Type)hwiNum);
- NVIC_SetPriority((IRQn_Type)hwiNum, hwiPrio);
+ HwiUnmask((IRQn_Type)hwiNum);
+ HwiSetPriority((IRQn_Type)hwiNum, hwiPrio);
LOS_IntRestore(intSave);
@@ -247,7 +316,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 ArchHwiDelete(HWI_HANDLE_T hwiNum)
return OS_ERRNO_HWI_NUM_INVALID;
}
- NVIC_DisableIRQ((IRQn_Type)hwiNum);
+ HwiMask((IRQn_Type)hwiNum);
intSave = LOS_IntLock();
@@ -493,7 +562,7 @@ LITE_OS_SEC_TEXT_INIT VOID HalHwiInit(VOID)
UINT32 index;
g_hwiForm[0] = 0; /* [0] Top of Stack */
g_hwiForm[1] = 0; /* [1] reset */
- for (index = 2; index < OS_VECTOR_CNT; index++) {
+ for (index = DEF_HANDLER_START_INDEX; index < OS_VECTOR_CNT; index++) {
g_hwiForm[index] = (HWI_PROC_FUNC)HalHwiDefaultHandler;
}
/* Exception handler register */
diff --git a/arch/arm/cortex-m33/gcc/TZ/non_secure/los_arch_interrupt.h b/arch/arm/cortex-m33/gcc/TZ/non_secure/los_arch_interrupt.h
index 99c53032..dd9a4f22 100755
--- a/arch/arm/cortex-m33/gcc/TZ/non_secure/los_arch_interrupt.h
+++ b/arch/arm/cortex-m33/gcc/TZ/non_secure/los_arch_interrupt.h
@@ -109,7 +109,8 @@ extern UINT32 _BootVectors[];
*
* Value: 0x02000900
*
- * Solution: Ensure that the interrupt number is valid. The value range of the interrupt number applicable for a Cortex-A7 platform is [OS_USER_HWI_MIN,OS_USER_HWI_MAX].
+ * 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)
@@ -159,7 +160,8 @@ extern UINT32 _BootVectors[];
*
* Value: 0x02000905
*
- * Solution: Ensure that the interrupt priority is valid. The value range of the interrupt priority applicable for a Cortex-A7 platform is [0,15].
+ * 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)
@@ -169,7 +171,8 @@ extern UINT32 _BootVectors[];
*
* 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.
+ * 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)
@@ -342,25 +345,6 @@ extern VOID OsSetVector(UINT32 num, HWI_PROC_FUNC vector);
*/
extern VOID HalInterrupt(VOID);
-/* *
- * @ingroup los_arch_interrupt
- * @brief: Get an interrupt number.
- *
- * @par Description:
- * This API is used to get the current interrupt number.
- *
- * @attention:
- *
- *
- * @param: None.
- *
- * @retval: Interrupt Indexes number.
- * @par Dependency:
- * - los_arch_interrupt.h: the header file that contains the API declaration.
- * @see None.
- */
-extern UINT32 HalIntNumGet(VOID);
-
/* *
* @ingroup los_arch_interrupt
* @brief: Default vector handling function.
diff --git a/arch/arm/cortex-m33/gcc/TZ/non_secure/los_interrupt.c b/arch/arm/cortex-m33/gcc/TZ/non_secure/los_interrupt.c
index b908b3b5..b033c786 100755
--- a/arch/arm/cortex-m33/gcc/TZ/non_secure/los_interrupt.c
+++ b/arch/arm/cortex-m33/gcc/TZ/non_secure/los_interrupt.c
@@ -40,6 +40,7 @@
#include "los_memory.h"
#include "los_membox.h"
+#define DEF_HANDLER_START_INDEX 2
/*lint -save -e40 -e522 -e533*/
UINT32 g_intCount = 0;
@@ -98,17 +99,85 @@ VOID OsSetVector(UINT32 num, HWI_PROC_FUNC vector)
#endif
/* ****************************************************************************
- Function : HalIntNumGet
+ Function : HwiNumGet
Description : Get an interrupt number
Input : None
Output : None
Return : Interrupt Indexes number
**************************************************************************** */
-LITE_OS_SEC_TEXT_MINOR UINT32 HalIntNumGet(VOID)
+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);
@@ -123,8 +192,8 @@ inline UINT32 ArchIsIntActive(VOID)
/*lint -e529*/
LITE_OS_SEC_TEXT_MINOR VOID HalHwiDefaultHandler(VOID)
{
- UINT32 irqNum = HalIntNumGet();
- PRINT_ERR("%s irqnum:%d\n", __FUNCTION__, irqNum);
+ UINT32 irqNum = HwiNumGet();
+ PRINT_ERR("%s irqnum:%u\n", __FUNCTION__, irqNum);
while (1) {}
}
@@ -158,7 +227,7 @@ LITE_OS_SEC_TEXT VOID HalInterrupt(VOID)
g_intCount++;
LOS_IntRestore(intSave);
- hwiIndex = HalIntNumGet();
+ hwiIndex = HwiNumGet();
OsHookCall(LOS_HOOK_TYPE_ISR_ENTER, hwiIndex);
@@ -224,8 +293,8 @@ LITE_OS_SEC_TEXT_INIT UINT32 ArchHwiCreate(HWI_HANDLE_T hwiNum,
#else
OsSetVector(hwiNum, handler);
#endif
- NVIC_EnableIRQ((IRQn_Type)hwiNum);
- NVIC_SetPriority((IRQn_Type)hwiNum, hwiPrio);
+ HwiUnmask((IRQn_Type)hwiNum);
+ HwiSetPriority((IRQn_Type)hwiNum, hwiPrio);
LOS_IntRestore(intSave);
@@ -491,9 +560,9 @@ 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[0] = 0; /* [0] Top of Stack */
g_hwiForm[1] = 0; /* [1] reset */
- for (index = 2; index < OS_VECTOR_CNT; index++) {
+ for (index = DEF_HANDLER_START_INDEX; index < OS_VECTOR_CNT; index++) {
g_hwiForm[index] = (HWI_PROC_FUNC)HalHwiDefaultHandler;
}
/* Exception handler register */
diff --git a/arch/arm/cortex-m33/iar/NTZ/los_arch_interrupt.h b/arch/arm/cortex-m33/iar/NTZ/los_arch_interrupt.h
index f7cab4fe..ae51bace 100644
--- a/arch/arm/cortex-m33/iar/NTZ/los_arch_interrupt.h
+++ b/arch/arm/cortex-m33/iar/NTZ/los_arch_interrupt.h
@@ -109,7 +109,8 @@ extern UINT32 _BootVectors[];
*
* Value: 0x02000900
*
- * Solution: Ensure that the interrupt number is valid. The value range of the interrupt number applicable for a Cortex-A7 platform is [OS_USER_HWI_MIN,OS_USER_HWI_MAX].
+ * 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)
@@ -159,7 +160,8 @@ extern UINT32 _BootVectors[];
*
* Value: 0x02000905
*
- * Solution: Ensure that the interrupt priority is valid. The value range of the interrupt priority applicable for a Cortex-A7 platform is [0,15].
+ * 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)
@@ -169,7 +171,8 @@ extern UINT32 _BootVectors[];
*
* 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.
+ * 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)
@@ -342,25 +345,6 @@ extern VOID OsSetVector(UINT32 num, HWI_PROC_FUNC vector);
*/
extern VOID HalInterrupt(VOID);
-/* *
- * @ingroup los_hwi
- * @brief: Get an interrupt number.
- *
- * @par Description:
- * This API is used to get the current interrupt number.
- *
- * @attention:
- *
- *
- * @param: None.
- *
- * @retval: Interrupt Indexes number.
- * @par Dependency:
- * - los_hwi.h: the header file that contains the API declaration.
- * @see None.
- */
-extern UINT32 HalIntNumGet(VOID);
-
/* *
* @ingroup los_hwi
* @brief: Default vector handling function.
diff --git a/arch/arm/cortex-m33/iar/NTZ/los_interrupt.c b/arch/arm/cortex-m33/iar/NTZ/los_interrupt.c
index d0c08d3f..1516d82a 100644
--- a/arch/arm/cortex-m33/iar/NTZ/los_interrupt.c
+++ b/arch/arm/cortex-m33/iar/NTZ/los_interrupt.c
@@ -105,17 +105,85 @@ WEAK VOID SysTick_Handler(VOID)
}
/* ****************************************************************************
- Function : HalIntNumGet
+ Function : HwiNumGet
Description : Get an interrupt number
Input : None
Output : None
Return : Interrupt Indexes number
**************************************************************************** */
-LITE_OS_SEC_TEXT_MINOR UINT32 HalIntNumGet(VOID)
+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);
@@ -130,8 +198,8 @@ inline UINT32 ArchIsIntActive(VOID)
/*lint -e529*/
LITE_OS_SEC_TEXT_MINOR VOID HalHwiDefaultHandler(VOID)
{
- UINT32 irqNum = HalIntNumGet();
- PRINT_ERR("%s irqnum:%d\n", __FUNCTION__, irqNum);
+ UINT32 irqNum = HwiNumGet();
+ PRINT_ERR("%s irqnum:%u\n", __FUNCTION__, irqNum);
while (1) {}
}
@@ -167,7 +235,7 @@ LITE_OS_SEC_TEXT VOID HalInterrupt(VOID)
LOS_IntRestore(intSave);
- hwiIndex = HalIntNumGet();
+ hwiIndex = HwiNumGet();
OsHookCall(LOS_HOOK_TYPE_ISR_ENTER, hwiIndex);
@@ -233,8 +301,8 @@ LITE_OS_SEC_TEXT_INIT UINT32 ArchHwiCreate(HWI_HANDLE_T hwiNum,
#else
OsSetVector(hwiNum, handler);
#endif
- NVIC_EnableIRQ((IRQn_Type)hwiNum);
- NVIC_SetPriority((IRQn_Type)hwiNum, hwiPrio);
+ HwiUnmask((IRQn_Type)hwiNum);
+ HwiSetPriority((IRQn_Type)hwiNum, hwiPrio);
LOS_IntRestore(intSave);
diff --git a/arch/arm/cortex-m33/iar/TZ/non_secure/los_arch_interrupt.h b/arch/arm/cortex-m33/iar/TZ/non_secure/los_arch_interrupt.h
index f7cab4fe..ae51bace 100644
--- a/arch/arm/cortex-m33/iar/TZ/non_secure/los_arch_interrupt.h
+++ b/arch/arm/cortex-m33/iar/TZ/non_secure/los_arch_interrupt.h
@@ -109,7 +109,8 @@ extern UINT32 _BootVectors[];
*
* Value: 0x02000900
*
- * Solution: Ensure that the interrupt number is valid. The value range of the interrupt number applicable for a Cortex-A7 platform is [OS_USER_HWI_MIN,OS_USER_HWI_MAX].
+ * 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)
@@ -159,7 +160,8 @@ extern UINT32 _BootVectors[];
*
* Value: 0x02000905
*
- * Solution: Ensure that the interrupt priority is valid. The value range of the interrupt priority applicable for a Cortex-A7 platform is [0,15].
+ * 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)
@@ -169,7 +171,8 @@ extern UINT32 _BootVectors[];
*
* 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.
+ * 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)
@@ -342,25 +345,6 @@ extern VOID OsSetVector(UINT32 num, HWI_PROC_FUNC vector);
*/
extern VOID HalInterrupt(VOID);
-/* *
- * @ingroup los_hwi
- * @brief: Get an interrupt number.
- *
- * @par Description:
- * This API is used to get the current interrupt number.
- *
- * @attention:
- *
- *
- * @param: None.
- *
- * @retval: Interrupt Indexes number.
- * @par Dependency:
- * - los_hwi.h: the header file that contains the API declaration.
- * @see None.
- */
-extern UINT32 HalIntNumGet(VOID);
-
/* *
* @ingroup los_hwi
* @brief: Default vector handling function.
diff --git a/arch/arm/cortex-m33/iar/TZ/non_secure/los_interrupt.c b/arch/arm/cortex-m33/iar/TZ/non_secure/los_interrupt.c
index d0c08d3f..1516d82a 100644
--- a/arch/arm/cortex-m33/iar/TZ/non_secure/los_interrupt.c
+++ b/arch/arm/cortex-m33/iar/TZ/non_secure/los_interrupt.c
@@ -105,17 +105,85 @@ WEAK VOID SysTick_Handler(VOID)
}
/* ****************************************************************************
- Function : HalIntNumGet
+ Function : HwiNumGet
Description : Get an interrupt number
Input : None
Output : None
Return : Interrupt Indexes number
**************************************************************************** */
-LITE_OS_SEC_TEXT_MINOR UINT32 HalIntNumGet(VOID)
+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);
@@ -130,8 +198,8 @@ inline UINT32 ArchIsIntActive(VOID)
/*lint -e529*/
LITE_OS_SEC_TEXT_MINOR VOID HalHwiDefaultHandler(VOID)
{
- UINT32 irqNum = HalIntNumGet();
- PRINT_ERR("%s irqnum:%d\n", __FUNCTION__, irqNum);
+ UINT32 irqNum = HwiNumGet();
+ PRINT_ERR("%s irqnum:%u\n", __FUNCTION__, irqNum);
while (1) {}
}
@@ -167,7 +235,7 @@ LITE_OS_SEC_TEXT VOID HalInterrupt(VOID)
LOS_IntRestore(intSave);
- hwiIndex = HalIntNumGet();
+ hwiIndex = HwiNumGet();
OsHookCall(LOS_HOOK_TYPE_ISR_ENTER, hwiIndex);
@@ -233,8 +301,8 @@ LITE_OS_SEC_TEXT_INIT UINT32 ArchHwiCreate(HWI_HANDLE_T hwiNum,
#else
OsSetVector(hwiNum, handler);
#endif
- NVIC_EnableIRQ((IRQn_Type)hwiNum);
- NVIC_SetPriority((IRQn_Type)hwiNum, hwiPrio);
+ HwiUnmask((IRQn_Type)hwiNum);
+ HwiSetPriority((IRQn_Type)hwiNum, hwiPrio);
LOS_IntRestore(intSave);
diff --git a/arch/arm/cortex-m4/gcc/los_arch_interrupt.h b/arch/arm/cortex-m4/gcc/los_arch_interrupt.h
index 5ac9ecc0..326b72f2 100644
--- a/arch/arm/cortex-m4/gcc/los_arch_interrupt.h
+++ b/arch/arm/cortex-m4/gcc/los_arch_interrupt.h
@@ -109,7 +109,8 @@ extern UINT32 _BootVectors[];
*
* Value: 0x02000900
*
- * Solution: Ensure that the interrupt number is valid. The value range of the interrupt number applicable for a Cortex-A7 platform is [OS_USER_HWI_MIN,OS_USER_HWI_MAX].
+ * Solution: Ensure that the interrupt number is valid.
+ * The value range of the interrupt number applicable for a Cortex-M4 platform is [OS_USER_HWI_MIN,OS_USER_HWI_MAX].
*/
#define OS_ERRNO_HWI_NUM_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x00)
@@ -159,7 +160,8 @@ extern UINT32 _BootVectors[];
*
* Value: 0x02000905
*
- * Solution: Ensure that the interrupt priority is valid. The value range of the interrupt priority applicable for a Cortex-A7 platform is [0,15].
+ * Solution: Ensure that the interrupt priority is valid.
+ * The value range of the interrupt priority applicable for a Cortex-M4 platform is [0,15].
*/
#define OS_ERRNO_HWI_PRIO_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x05)
@@ -169,7 +171,8 @@ extern UINT32 _BootVectors[];
*
* 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.
+ * 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)
@@ -342,25 +345,6 @@ extern VOID OsSetVector(UINT32 num, HWI_PROC_FUNC vector);
*/
extern VOID HalInterrupt(VOID);
-/* *
- * @ingroup los_arch_interrupt
- * @brief: Get an interrupt number.
- *
- * @par Description:
- * This API is used to get the current interrupt number.
- *
- * @attention:
- *
- *
- * @param: None.
- *
- * @retval: Interrupt Indexes number.
- * @par Dependency:
- * - los_arch_interrupt.h: the header file that contains the API declaration.
- * @see None.
- */
-extern UINT32 HalIntNumGet(VOID);
-
/* *
* @ingroup los_arch_interrupt
* @brief: Default vector handling function.
diff --git a/arch/arm/cortex-m4/gcc/los_interrupt.c b/arch/arm/cortex-m4/gcc/los_interrupt.c
index e256fa8c..d87516ce 100644
--- a/arch/arm/cortex-m4/gcc/los_interrupt.c
+++ b/arch/arm/cortex-m4/gcc/los_interrupt.c
@@ -103,17 +103,85 @@ WEAK VOID SysTick_Handler(VOID)
}
/* ****************************************************************************
- Function : HalIntNumGet
+ Function : HwiNumGet
Description : Get an interrupt number
Input : None
Output : None
Return : Interrupt Indexes number
**************************************************************************** */
-LITE_OS_SEC_TEXT_MINOR UINT32 HalIntNumGet(VOID)
+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);
@@ -128,8 +196,8 @@ inline UINT32 ArchIsIntActive(VOID)
/*lint -e529*/
LITE_OS_SEC_TEXT_MINOR VOID HalHwiDefaultHandler(VOID)
{
- UINT32 irqNum = HalIntNumGet();
- PRINT_ERR("%s irqnum:%d\n", __FUNCTION__, irqNum);
+ UINT32 irqNum = HwiNumGet();
+ PRINT_ERR("%s irqnum:%u\n", __FUNCTION__, irqNum);
while (1) {}
}
@@ -163,7 +231,7 @@ LITE_OS_SEC_TEXT VOID HalInterrupt(VOID)
g_intCount++;
LOS_IntRestore(intSave);
- hwiIndex = HalIntNumGet();
+ hwiIndex = HwiNumGet();
OsHookCall(LOS_HOOK_TYPE_ISR_ENTER, hwiIndex);
@@ -229,8 +297,8 @@ LITE_OS_SEC_TEXT_INIT UINT32 ArchHwiCreate(HWI_HANDLE_T hwiNum,
#else
OsSetVector(hwiNum, handler);
#endif
- NVIC_EnableIRQ((IRQn_Type)hwiNum);
- NVIC_SetPriority((IRQn_Type)hwiNum, hwiPrio);
+ HwiUnmask((IRQn_Type)hwiNum);
+ HwiSetPriority((IRQn_Type)hwiNum, hwiPrio);
LOS_IntRestore(intSave);
@@ -252,7 +320,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 ArchHwiDelete(HWI_HANDLE_T hwiNum)
return OS_ERRNO_HWI_NUM_INVALID;
}
- NVIC_DisableIRQ((IRQn_Type)hwiNum);
+ HwiMask((IRQn_Type)hwiNum);
intSave = LOS_IntLock();
diff --git a/arch/arm/cortex-m4/iar/los_arch_interrupt.h b/arch/arm/cortex-m4/iar/los_arch_interrupt.h
index 5ac9ecc0..326b72f2 100644
--- a/arch/arm/cortex-m4/iar/los_arch_interrupt.h
+++ b/arch/arm/cortex-m4/iar/los_arch_interrupt.h
@@ -109,7 +109,8 @@ extern UINT32 _BootVectors[];
*
* Value: 0x02000900
*
- * Solution: Ensure that the interrupt number is valid. The value range of the interrupt number applicable for a Cortex-A7 platform is [OS_USER_HWI_MIN,OS_USER_HWI_MAX].
+ * Solution: Ensure that the interrupt number is valid.
+ * The value range of the interrupt number applicable for a Cortex-M4 platform is [OS_USER_HWI_MIN,OS_USER_HWI_MAX].
*/
#define OS_ERRNO_HWI_NUM_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x00)
@@ -159,7 +160,8 @@ extern UINT32 _BootVectors[];
*
* Value: 0x02000905
*
- * Solution: Ensure that the interrupt priority is valid. The value range of the interrupt priority applicable for a Cortex-A7 platform is [0,15].
+ * Solution: Ensure that the interrupt priority is valid.
+ * The value range of the interrupt priority applicable for a Cortex-M4 platform is [0,15].
*/
#define OS_ERRNO_HWI_PRIO_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x05)
@@ -169,7 +171,8 @@ extern UINT32 _BootVectors[];
*
* 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.
+ * 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)
@@ -342,25 +345,6 @@ extern VOID OsSetVector(UINT32 num, HWI_PROC_FUNC vector);
*/
extern VOID HalInterrupt(VOID);
-/* *
- * @ingroup los_arch_interrupt
- * @brief: Get an interrupt number.
- *
- * @par Description:
- * This API is used to get the current interrupt number.
- *
- * @attention:
- *
- *
- * @param: None.
- *
- * @retval: Interrupt Indexes number.
- * @par Dependency:
- * - los_arch_interrupt.h: the header file that contains the API declaration.
- * @see None.
- */
-extern UINT32 HalIntNumGet(VOID);
-
/* *
* @ingroup los_arch_interrupt
* @brief: Default vector handling function.
diff --git a/arch/arm/cortex-m4/iar/los_interrupt.c b/arch/arm/cortex-m4/iar/los_interrupt.c
index ec94ed17..8c071657 100644
--- a/arch/arm/cortex-m4/iar/los_interrupt.c
+++ b/arch/arm/cortex-m4/iar/los_interrupt.c
@@ -109,17 +109,85 @@ WEAK VOID SysTick_Handler(VOID)
}
/* ****************************************************************************
- Function : HalIntNumGet
+ Function : HwiNumGet
Description : Get an interrupt number
Input : None
Output : None
Return : Interrupt Indexes number
**************************************************************************** */
-LITE_OS_SEC_TEXT_MINOR UINT32 HalIntNumGet(VOID)
+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);
@@ -134,8 +202,8 @@ inline UINT32 ArchIsIntActive(VOID)
/*lint -e529*/
LITE_OS_SEC_TEXT_MINOR VOID HalHwiDefaultHandler(VOID)
{
- UINT32 irqNum = HalIntNumGet();
- PRINT_ERR("%s irqnum:%d\n", __FUNCTION__, irqNum);
+ UINT32 irqNum = HwiNumGet();
+ PRINT_ERR("%s irqnum:%u\n", __FUNCTION__, irqNum);
while (1) {}
}
@@ -169,7 +237,7 @@ LITE_OS_SEC_TEXT VOID HalInterrupt(VOID)
g_intCount++;
LOS_IntRestore(intSave);
- hwiIndex = HalIntNumGet();
+ hwiIndex = HwiNumGet();
OsHookCall(LOS_HOOK_TYPE_ISR_ENTER, hwiIndex);
@@ -235,8 +303,8 @@ LITE_OS_SEC_TEXT_INIT UINT32 ArchHwiCreate(HWI_HANDLE_T hwiNum,
#else
OsSetVector(hwiNum, handler);
#endif
- NVIC_EnableIRQ((IRQn_Type)hwiNum);
- NVIC_SetPriority((IRQn_Type)hwiNum, hwiPrio);
+ HwiUnmask((IRQn_Type)hwiNum);
+ HwiSetPriority((IRQn_Type)hwiNum, hwiPrio);
LOS_IntRestore(intSave);
diff --git a/arch/arm/cortex-m7/gcc/los_arch_interrupt.h b/arch/arm/cortex-m7/gcc/los_arch_interrupt.h
index 2b21441c..7e8dde0e 100644
--- a/arch/arm/cortex-m7/gcc/los_arch_interrupt.h
+++ b/arch/arm/cortex-m7/gcc/los_arch_interrupt.h
@@ -109,7 +109,8 @@ extern UINT32 _BootVectors[];
*
* Value: 0x02000900
*
- * Solution: Ensure that the interrupt number is valid. The value range of the interrupt number applicable for a Cortex-A7 platform is [OS_USER_HWI_MIN,OS_USER_HWI_MAX].
+ * Solution: Ensure that the interrupt number is valid.
+ * The value range of the interrupt number applicable for a Cortex-M7 platform is [OS_USER_HWI_MIN,OS_USER_HWI_MAX].
*/
#define OS_ERRNO_HWI_NUM_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x00)
@@ -159,7 +160,8 @@ extern UINT32 _BootVectors[];
*
* Value: 0x02000905
*
- * Solution: Ensure that the interrupt priority is valid. The value range of the interrupt priority applicable for a Cortex-A7 platform is [0,15].
+ * Solution: Ensure that the interrupt priority is valid.
+ * The value range of the interrupt priority applicable for a Cortex-M7 platform is [0,15].
*/
#define OS_ERRNO_HWI_PRIO_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x05)
@@ -169,7 +171,8 @@ extern UINT32 _BootVectors[];
*
* 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.
+ * 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)
@@ -342,25 +345,6 @@ extern VOID OsSetVector(UINT32 num, HWI_PROC_FUNC vector);
*/
extern VOID HalInterrupt(VOID);
-/* *
- * @ingroup los_arch_interrupt
- * @brief: Get an interrupt number.
- *
- * @par Description:
- * This API is used to get the current interrupt number.
- *
- * @attention:
- *
- *
- * @param: None.
- *
- * @retval: Interrupt Indexes number.
- * @par Dependency:
- * - los_arch_interrupt.h: the header file that contains the API declaration.
- * @see None.
- */
-extern UINT32 HalIntNumGet(VOID);
-
/* *
* @ingroup los_arch_interrupt
* @brief: Default vector handling function.
diff --git a/arch/arm/cortex-m7/gcc/los_interrupt.c b/arch/arm/cortex-m7/gcc/los_interrupt.c
index e2b7a30e..72e7d2ab 100644
--- a/arch/arm/cortex-m7/gcc/los_interrupt.c
+++ b/arch/arm/cortex-m7/gcc/los_interrupt.c
@@ -98,17 +98,85 @@ VOID OsSetVector(UINT32 num, HWI_PROC_FUNC vector)
#endif
/* ****************************************************************************
- Function : HalIntNumGet
+ Function : HwiNumGet
Description : Get an interrupt number
Input : None
Output : None
Return : Interrupt Indexes number
**************************************************************************** */
-LITE_OS_SEC_TEXT_MINOR UINT32 HalIntNumGet(VOID)
+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);
@@ -123,8 +191,8 @@ inline UINT32 ArchIsIntActive(VOID)
/*lint -e529*/
LITE_OS_SEC_TEXT_MINOR VOID HalHwiDefaultHandler(VOID)
{
- UINT32 irqNum = HalIntNumGet();
- PRINT_ERR("%s irqnum:%d\n", __FUNCTION__, irqNum);
+ UINT32 irqNum = HwiNumGet();
+ PRINT_ERR("%s irqnum:%u\n", __FUNCTION__, irqNum);
while (1) {}
}
@@ -158,7 +226,7 @@ LITE_OS_SEC_TEXT VOID HalInterrupt(VOID)
g_intCount++;
LOS_IntRestore(intSave);
- hwiIndex = HalIntNumGet();
+ hwiIndex = HwiNumGet();
OsHookCall(LOS_HOOK_TYPE_ISR_ENTER, hwiIndex);
@@ -224,8 +292,8 @@ LITE_OS_SEC_TEXT_INIT UINT32 ArchHwiCreate(HWI_HANDLE_T hwiNum,
#else
OsSetVector(hwiNum, handler);
#endif
- NVIC_EnableIRQ((IRQn_Type)hwiNum);
- NVIC_SetPriority((IRQn_Type)hwiNum, hwiPrio);
+ HwiUnmask((IRQn_Type)hwiNum);
+ HwiSetPriority((IRQn_Type)hwiNum, hwiPrio);
LOS_IntRestore(intSave);
diff --git a/arch/arm/cortex-m7/iar/los_arch_interrupt.h b/arch/arm/cortex-m7/iar/los_arch_interrupt.h
index 2b21441c..7e8dde0e 100644
--- a/arch/arm/cortex-m7/iar/los_arch_interrupt.h
+++ b/arch/arm/cortex-m7/iar/los_arch_interrupt.h
@@ -109,7 +109,8 @@ extern UINT32 _BootVectors[];
*
* Value: 0x02000900
*
- * Solution: Ensure that the interrupt number is valid. The value range of the interrupt number applicable for a Cortex-A7 platform is [OS_USER_HWI_MIN,OS_USER_HWI_MAX].
+ * Solution: Ensure that the interrupt number is valid.
+ * The value range of the interrupt number applicable for a Cortex-M7 platform is [OS_USER_HWI_MIN,OS_USER_HWI_MAX].
*/
#define OS_ERRNO_HWI_NUM_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x00)
@@ -159,7 +160,8 @@ extern UINT32 _BootVectors[];
*
* Value: 0x02000905
*
- * Solution: Ensure that the interrupt priority is valid. The value range of the interrupt priority applicable for a Cortex-A7 platform is [0,15].
+ * Solution: Ensure that the interrupt priority is valid.
+ * The value range of the interrupt priority applicable for a Cortex-M7 platform is [0,15].
*/
#define OS_ERRNO_HWI_PRIO_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x05)
@@ -169,7 +171,8 @@ extern UINT32 _BootVectors[];
*
* 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.
+ * 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)
@@ -342,25 +345,6 @@ extern VOID OsSetVector(UINT32 num, HWI_PROC_FUNC vector);
*/
extern VOID HalInterrupt(VOID);
-/* *
- * @ingroup los_arch_interrupt
- * @brief: Get an interrupt number.
- *
- * @par Description:
- * This API is used to get the current interrupt number.
- *
- * @attention:
- *
- *
- * @param: None.
- *
- * @retval: Interrupt Indexes number.
- * @par Dependency:
- * - los_arch_interrupt.h: the header file that contains the API declaration.
- * @see None.
- */
-extern UINT32 HalIntNumGet(VOID);
-
/* *
* @ingroup los_arch_interrupt
* @brief: Default vector handling function.
diff --git a/arch/arm/cortex-m7/iar/los_interrupt.c b/arch/arm/cortex-m7/iar/los_interrupt.c
index 278b2bdc..2c0613f7 100644
--- a/arch/arm/cortex-m7/iar/los_interrupt.c
+++ b/arch/arm/cortex-m7/iar/los_interrupt.c
@@ -105,17 +105,85 @@ WEAK VOID SysTick_Handler(VOID)
}
/* ****************************************************************************
- Function : HalIntNumGet
+ Function : HwiNumGet
Description : Get an interrupt number
Input : None
Output : None
Return : Interrupt Indexes number
**************************************************************************** */
-LITE_OS_SEC_TEXT_MINOR UINT32 HalIntNumGet(VOID)
+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);
@@ -130,8 +198,8 @@ inline UINT32 ArchIsIntActive(VOID)
/*lint -e529*/
LITE_OS_SEC_TEXT_MINOR VOID HalHwiDefaultHandler(VOID)
{
- UINT32 irqNum = HalIntNumGet();
- PRINT_ERR("%s irqnum:%d\n", __FUNCTION__, irqNum);
+ UINT32 irqNum = HwiNumGet();
+ PRINT_ERR("%s irqnum:%u\n", __FUNCTION__, irqNum);
while (1) {}
}
@@ -165,7 +233,7 @@ LITE_OS_SEC_TEXT VOID HalInterrupt(VOID)
g_intCount++;
LOS_IntRestore(intSave);
- hwiIndex = HalIntNumGet();
+ hwiIndex = HwiNumGet();
OsHookCall(LOS_HOOK_TYPE_ISR_ENTER, hwiIndex);
@@ -231,8 +299,8 @@ LITE_OS_SEC_TEXT_INIT UINT32 ArchHwiCreate(HWI_HANDLE_T hwiNum,
#else
OsSetVector(hwiNum, handler);
#endif
- NVIC_EnableIRQ((IRQn_Type)hwiNum);
- NVIC_SetPriority((IRQn_Type)hwiNum, hwiPrio);
+ HwiUnmask((IRQn_Type)hwiNum);
+ HwiSetPriority((IRQn_Type)hwiNum, hwiPrio);
LOS_IntRestore(intSave);
diff --git a/arch/csky/v2/gcc/los_arch_interrupt.h b/arch/csky/v2/gcc/los_arch_interrupt.h
index 1cb4c359..c9db621a 100644
--- a/arch/csky/v2/gcc/los_arch_interrupt.h
+++ b/arch/csky/v2/gcc/los_arch_interrupt.h
@@ -251,25 +251,6 @@ extern VOID OsSetVector(UINT32 num, HWI_PROC_FUNC vector);
*/
extern VOID HalInterrupt(VOID);
-/* *
- * @ingroup los_arch_interrupt
- * @brief: Get an interrupt number.
- *
- * @par Description:
- * This API is used to get the current interrupt number.
- *
- * @attention:
- *
- *
- * @param: None.
- *
- * @retval: Interrupt Indexes number.
- * @par Dependency:
- * - los_arch_interrupt.h: the header file that contains the API declaration.
- * @see None.
- */
-extern UINT32 HalIntNumGet(VOID);
-
/* *
* @ingroup los_arch_interrupt
* @brief: Default vector handling function.
diff --git a/arch/csky/v2/gcc/los_interrupt.c b/arch/csky/v2/gcc/los_interrupt.c
index c9280ca5..43786da3 100644
--- a/arch/csky/v2/gcc/los_interrupt.c
+++ b/arch/csky/v2/gcc/los_interrupt.c
@@ -117,64 +117,79 @@ UINT32 ArchIntLocked(VOID)
return !(intSave & (1 << INT_OFFSET));
}
-UINT32 HalIrqUnmask(UINT32 hwiNum)
+STATIC UINT32 HwiUnmask(HWI_HANDLE_T hwiNum)
{
UINT32 intSave;
+
if (!HwiNumValid(hwiNum)) {
return LOS_ERRNO_HWI_NUM_INVALID;
}
+
intSave = LOS_IntLock();
VIC_REG->ISER[hwiNum / OS_SYS_VECTOR_CNT] = (UINT32)(1UL << (hwiNum % OS_SYS_VECTOR_CNT));
VIC_REG->ISSR[hwiNum / OS_SYS_VECTOR_CNT] = (UINT32)(1UL << (hwiNum % OS_SYS_VECTOR_CNT));
LOS_IntRestore(intSave);
+
return LOS_OK;
}
-UINT32 HalIrqSetPriority(UINT32 hwiNum, UINT8 priority)
+STATIC UINT32 HwiSetPriority(HWI_HANDLE_T hwiNum, UINT8 priority)
{
UINT32 intSave;
+
if (!HwiNumValid(hwiNum)) {
return LOS_ERRNO_HWI_NUM_INVALID;
}
+
if (!HWI_PRI_VALID(priority)) {
return OS_ERRNO_HWI_PRIO_INVALID;
}
+
intSave = LOS_IntLock();
VIC_REG->IPR[hwiNum / PRI_PER_REG] |= (((priority << PRI_OFF_IN_REG) << (hwiNum % PRI_PER_REG)) * PRI_OFF_PER_INT);
LOS_IntRestore(intSave);
+
return LOS_OK;
}
-UINT32 HalIrqMask(HWI_HANDLE_T hwiNum)
+STATIC UINT32 HwiMask(HWI_HANDLE_T hwiNum)
{
UINT32 intSave;
+
if (!HwiNumValid(hwiNum)) {
return LOS_ERRNO_HWI_NUM_INVALID;
}
+
intSave = LOS_IntLock();
VIC_REG->ICER[hwiNum / OS_SYS_VECTOR_CNT] = (UINT32)(1UL << (hwiNum % OS_SYS_VECTOR_CNT));
LOS_IntRestore(intSave);
+
return LOS_OK;
}
-UINT32 HalIrqPending(UINT32 hwiNum)
+STATIC UINT32 HwiPending(HWI_HANDLE_T hwiNum)
{
UINT32 intSave;
+
if (!HwiNumValid(hwiNum)) {
return LOS_ERRNO_HWI_NUM_INVALID;
}
+
intSave = LOS_IntLock();
VIC_REG->ISPR[hwiNum / OS_SYS_VECTOR_CNT] = (UINT32)(1UL << (hwiNum % OS_SYS_VECTOR_CNT));
LOS_IntRestore(intSave);
+
return LOS_OK;
}
-UINT32 HalIrqClear(UINT32 hwiNum)
+STATIC UINT32 HwiClear(HWI_HANDLE_T hwiNum)
{
if (!HwiNumValid(hwiNum)) {
return LOS_ERRNO_HWI_NUM_INVALID;
}
+
VIC_REG->ICPR[hwiNum / OS_SYS_VECTOR_CNT] = (UINT32)(1UL << (hwiNum % OS_SYS_VECTOR_CNT));
+
return LOS_OK;
}
@@ -207,7 +222,7 @@ VOID OsSetVector(UINT32 num, HWI_PROC_FUNC vector, VOID *arg)
g_hwiForm[num + OS_SYS_VECTOR_CNT] = (HWI_PROC_FUNC)IrqEntry;
g_hwiHandlerForm[num + OS_SYS_VECTOR_CNT].pfnHandler = vector;
g_hwiHandlerForm[num + OS_SYS_VECTOR_CNT].pParm = arg;
- HalIrqUnmask(num);
+ HwiUnmask(num);
}
}
@@ -227,23 +242,32 @@ VOID OsSetVector(UINT32 num, HWI_PROC_FUNC vector)
if ((num + OS_SYS_VECTOR_CNT) < OS_VECTOR_CNT) {
g_hwiForm[num + OS_SYS_VECTOR_CNT] = IrqEntry;
g_hwiHandlerForm[num + OS_SYS_VECTOR_CNT] = vector;
- HalIrqUnmask(num);
+ HwiUnmask(num);
}
}
#endif
/* ****************************************************************************
- Function : HalIntNumGet
+ Function : HwiNumGet
Description : Get an interrupt number
Input : None
Output : None
Return : Interrupt Indexes number
**************************************************************************** */
-LITE_OS_SEC_TEXT_MINOR UINT32 HalIntNumGet(VOID)
+STATIC UINT32 HwiNumGet(VOID)
{
return HalGetPsr();
}
+HwiControllerOps g_archHwiOps = {
+ .triggerIrq = HwiPending,
+ .enableIrq = HwiUnmask,
+ .disableIrq = HwiMask,
+ .setIrqPriority = HwiSetPriority,
+ .getCurIrqNum = HwiNumGet,
+ .clearIrq = HwiClear,
+};
+
inline UINT32 ArchIsIntActive(VOID)
{
return (g_intCount > 0);
@@ -258,7 +282,7 @@ inline UINT32 ArchIsIntActive(VOID)
**************************************************************************** */
LITE_OS_SEC_TEXT_MINOR VOID HalHwiDefaultHandler(VOID)
{
- UINT32 irqNum = HalIntNumGet();
+ UINT32 irqNum = HwiNumGet();
irqNum = (irqNum >> PSR_VEC_OFFSET) & MASK_8_BITS;
PRINT_ERR("%s irqnum:%x\n", __FUNCTION__, irqNum);
while (1) {}
@@ -290,7 +314,7 @@ LITE_OS_SEC_TEXT VOID HalInterrupt(VOID)
g_intCount++;
LOS_IntRestore(intSave);
- hwiIndex = HalIntNumGet();
+ hwiIndex = HwiNumGet();
hwiIndex = (hwiIndex >> PSR_VEC_OFFSET) & MASK_8_BITS;
OsHookCall(LOS_HOOK_TYPE_ISR_ENTER, hwiIndex);
@@ -355,8 +379,8 @@ LITE_OS_SEC_TEXT_INIT UINT32 ArchHwiCreate(HWI_HANDLE_T hwiNum,
#else
OsSetVector(hwiNum, handler);
#endif
- HalIrqUnmask(hwiNum);
- (VOID)HalIrqSetPriority(hwiNum, (UINT8)hwiPrio);
+ HwiUnmask(hwiNum);
+ (VOID)HwiSetPriority(hwiNum, (UINT8)hwiPrio);
LOS_IntRestore(intSave);
return LOS_OK;
@@ -376,7 +400,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 ArchHwiDelete(HWI_HANDLE_T hwiNum)
if (hwiNum >= OS_HWI_MAX_NUM) {
return OS_ERRNO_HWI_NUM_INVALID;
}
- HalIrqMask(hwiNum);
+ HwiMask(hwiNum);
intSave = LOS_IntLock();
g_hwiHandlerForm[hwiNum + OS_SYS_VECTOR_CNT] = 0;
LOS_IntRestore(intSave);
diff --git a/arch/include/los_interrupt.h b/arch/include/los_interrupt.h
index 06daa6ce..a9208ef1 100644
--- a/arch/include/los_interrupt.h
+++ b/arch/include/los_interrupt.h
@@ -54,6 +54,17 @@ typedef VOID (*HWI_PROC_FUNC)(VOID *parm);
typedef VOID (*HWI_PROC_FUNC)(void);
#endif
+typedef struct {
+ UINT32 (*triggerIrq)(HWI_HANDLE_T hwiNum);
+ UINT32 (*clearIrq)(HWI_HANDLE_T hwiNum);
+ UINT32 (*enableIrq)(HWI_HANDLE_T hwiNum);
+ UINT32 (*disableIrq)(HWI_HANDLE_T hwiNum);
+ UINT32 (*setIrqPriority)(HWI_HANDLE_T hwiNum, UINT8 priority);
+ UINT32 (*getCurIrqNum)(VOID);
+} HwiControllerOps;
+
+extern HwiControllerOps g_archHwiOps;
+
/* stack protector */
extern UINT32 __stack_chk_guard;
@@ -64,6 +75,11 @@ UINT32 ArchIsIntActive(VOID);
#define OS_INT_INACTIVE (!(OS_INT_ACTIVE))
#define LOS_HwiCreate ArchHwiCreate
#define LOS_HwiDelete ArchHwiDelete
+#define LOS_HwiTrigger ArchIntTrigger
+#define LOS_HwiEnable ArchIntEnable
+#define LOS_HwiDisable ArchIntDisable
+#define LOS_HwiClear ArchIntClear
+#define LOS_HwiSetPriority ArchIntSetPriority
UINT32 ArchIntLock(VOID);
#define LOS_IntLock ArchIntLock
@@ -74,6 +90,8 @@ VOID ArchIntRestore(UINT32 intSave);
UINT32 ArchIntUnLock(VOID);
#define LOS_IntUnLock ArchIntUnLock
+#define LOS_HwiOpsGet ArchIntOpsGet
+
/**
* @ingroup los_interrupt
* @brief Delete hardware interrupt.
@@ -135,6 +153,51 @@ UINT32 ArchHwiCreate(HWI_HANDLE_T hwiNum,
HWI_PROC_FUNC handler,
HWI_ARG_T arg);
+STATIC INLINE UINT32 ArchIntTrigger(HWI_HANDLE_T hwiNum)
+{
+ if (g_archHwiOps.triggerIrq == NULL) {
+ return LOS_NOK;
+ }
+ return g_archHwiOps.triggerIrq(hwiNum);
+}
+
+STATIC INLINE UINT32 ArchIntEnable(HWI_HANDLE_T hwiNum)
+{
+ if (g_archHwiOps.enableIrq == NULL) {
+ return LOS_NOK;
+ }
+ return g_archHwiOps.enableIrq(hwiNum);
+}
+
+STATIC INLINE UINT32 ArchIntDisable(HWI_HANDLE_T hwiNum)
+{
+ if (g_archHwiOps.disableIrq == NULL) {
+ return LOS_NOK;
+ }
+ return g_archHwiOps.disableIrq(hwiNum);
+}
+
+STATIC INLINE UINT32 ArchIntClear(HWI_HANDLE_T hwiNum)
+{
+ if (g_archHwiOps.clearIrq == NULL) {
+ return LOS_NOK;
+ }
+ return g_archHwiOps.clearIrq(hwiNum);
+}
+
+STATIC INLINE UINT32 ArchIntSetPriority(HWI_HANDLE_T hwiNum, HWI_PRIOR_T priority)
+{
+ if (g_archHwiOps.setIrqPriority == NULL) {
+ return LOS_NOK;
+ }
+ return g_archHwiOps.setIrqPriority(hwiNum, priority);
+}
+
+STATIC INLINE HwiControllerOps *ArchIntOpsGet(VOID)
+{
+ return &g_archHwiOps;
+}
+
#ifdef __cplusplus
#if __cplusplus
}
diff --git a/arch/risc-v/nuclei/gcc/los_interrupt.c b/arch/risc-v/nuclei/gcc/los_interrupt.c
index e5cddd62..1644ace0 100644
--- a/arch/risc-v/nuclei/gcc/los_interrupt.c
+++ b/arch/risc-v/nuclei/gcc/los_interrupt.c
@@ -39,7 +39,43 @@
UINT32 g_intCount = 0;
-// LosExcInfo g_excInfo;
+STATIC UINT32 HwiUnmask(HWI_HANDLE_T hwiNum)
+{
+ if (hwiNum >= OS_HWI_MAX_NUM) {
+ return OS_ERRNO_HWI_NUM_INVALID;
+ }
+
+ ECLIC_EnableIRQ(hwiNum);
+
+ return LOS_OK;
+}
+
+STATIC UINT32 HwiMask(HWI_HANDLE_T hwiNum)
+{
+ if (hwiNum >= OS_HWI_MAX_NUM) {
+ return OS_ERRNO_HWI_NUM_INVALID;
+ }
+
+ ECLIC_DisableIRQ(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_HIGHEST || priority < OS_HWI_PRIO_LOWEST) {
+ return OS_ERRNO_HWI_PRIO_INVALID;
+ }
+
+ ECLIC_SetPriorityIRQ(hwiNum, (hwiPrio & 0xffff));
+
+ return LOS_OK;
+}
+
LITE_OS_SEC_TEXT_INIT VOID HalHwiInit(VOID)
{
// already setup interrupt vectors
@@ -59,11 +95,11 @@ LITE_OS_SEC_TEXT_INIT VOID HalHwiInit(VOID)
Output : None
Return : LOS_OK on success or error code on failure
*****************************************************************************/
- UINT32 ArchHwiCreate(HWI_HANDLE_T hwiNum,
- HWI_PRIOR_T hwiPrio,
- HWI_MODE_T mode,
- HWI_PROC_FUNC handler,
- HWI_ARG_T arg)
+UINT32 ArchHwiCreate(HWI_HANDLE_T hwiNum,
+ HWI_PRIOR_T hwiPrio,
+ HWI_MODE_T mode,
+ HWI_PROC_FUNC handler,
+ HWI_ARG_T arg)
{
if (hwiNum > SOC_INT_MAX) {
return OS_ERRNO_HWI_NUM_INVALID;
@@ -93,7 +129,7 @@ LITE_OS_SEC_TEXT_INIT VOID HalHwiInit(VOID)
ECLIC_SetVector(hwiNum, (rv_csr_t)handler);
}
/* enable interrupt */
- ECLIC_EnableIRQ(hwiNum);
+ HwiUnmask(hwiNum);
return LOS_OK;
}
@@ -108,7 +144,7 @@ LITE_OS_SEC_TEXT UINT32 ArchHwiDelete(HWI_HANDLE_T hwiNum)
// change func to default func
ECLIC_SetVector(hwiNum, (rv_csr_t)HalHwiDefaultHandler);
// disable interrupt
- ECLIC_DisableIRQ(hwiNum);
+ HwiMask(hwiNum);
return LOS_OK;
}
@@ -182,3 +218,8 @@ __attribute__((always_inline)) inline UINT32 ArchIsIntActive(VOID)
return (g_intCount > 0);
}
+const HwiControllerOps g_archHwiOps = {
+ .enableIrq = HwiUnmask,
+ .disableIrq = HwiMask,
+ .setIrqPriority = HwiSetPriority,
+};
diff --git a/arch/xtensa/lx6/gcc/los_arch_interrupt.h b/arch/xtensa/lx6/gcc/los_arch_interrupt.h
index 71bf22db..8f6831e5 100644
--- a/arch/xtensa/lx6/gcc/los_arch_interrupt.h
+++ b/arch/xtensa/lx6/gcc/los_arch_interrupt.h
@@ -214,7 +214,6 @@ extern VOID OsSetVector(UINT32 num, HWI_PROC_FUNC vector);
#endif
VOID HalInterrupt(VOID);
-UINT32 HalIntNumGet(VOID);
VOID HalHwiDefaultHandler(VOID);
VOID HalExcHandleEntry(UINTPTR faultAddr, EXC_CONTEXT_S *excBufAddr, UINT32 type);
VOID HalHwiInit(VOID);
diff --git a/arch/xtensa/lx6/gcc/los_interrupt.c b/arch/xtensa/lx6/gcc/los_interrupt.c
index 2237dd86..3032cccc 100644
--- a/arch/xtensa/lx6/gcc/los_interrupt.c
+++ b/arch/xtensa/lx6/gcc/los_interrupt.c
@@ -142,6 +142,7 @@ UINT32 ArchIntUnLock(VOID)
STATIC INLINE UINT32 ArchIntLocked(VOID)
{
UINT32 intSave;
+
__asm__ volatile("rsr %0, ps " : "=r"(intSave) : : "memory");
return (intSave & SPREG_PS_DI_MASK);
@@ -151,7 +152,7 @@ STATIC INLINE UINT32 ArchIntLocked(VOID)
* @ingroup los_hwi
* Trigger the interrupt
*/
-UINT32 HalIrqPending(HWI_HANDLE_T hwiNum)
+STATIC UINT32 HwiPending(HWI_HANDLE_T hwiNum)
{
if (!HwiNumValid(hwiNum)) {
return OS_ERRNO_HWI_NUM_INVALID;
@@ -162,11 +163,7 @@ UINT32 HalIrqPending(HWI_HANDLE_T hwiNum)
return LOS_OK;
}
-/* *
- * @ingroup los_hwi
- * Unmask the interrupt
- */
-UINT32 HalIrqUnmask(HWI_HANDLE_T hwiNum)
+UINT32 HwiUnmask(HWI_HANDLE_T hwiNum)
{
UINT32 ier;
@@ -180,11 +177,7 @@ UINT32 HalIrqUnmask(HWI_HANDLE_T hwiNum)
return LOS_OK;
}
-/* *
- * @ingroup los_hwi
- * Mask the interrupt
- */
-UINT32 HalIrqMask(HWI_HANDLE_T hwiNum)
+UINT32 HwiMask(HWI_HANDLE_T hwiNum)
{
UINT32 ier;
@@ -199,13 +192,13 @@ UINT32 HalIrqMask(HWI_HANDLE_T hwiNum)
}
/* ****************************************************************************
- Function : HalIntNumGet
+ Function : HwiNumGet
Description : Get an interrupt number
Input : None
Output : None
Return : Interrupt Indexes number
**************************************************************************** */
-UINT32 HalIntNumGet(VOID)
+STATIC UINT32 HwiNumGet(VOID)
{
UINT32 ier;
UINT32 intenable;
@@ -223,7 +216,7 @@ UINT32 HalIntNumGet(VOID)
* @ingroup los_hwi
* Clear the interrupt
*/
-UINT32 HalIrqClear(HWI_HANDLE_T vector)
+STATIC UINT32 HwiClear(HWI_HANDLE_T vector)
{
if (!HwiNumValid(vector)) {
return OS_ERRNO_HWI_NUM_INVALID;
@@ -234,6 +227,14 @@ UINT32 HalIrqClear(HWI_HANDLE_T vector)
return LOS_OK;
}
+HwiControllerOps g_archHwiOps = {
+ .triggerIrq = HwiPending,
+ .enableIrq = HwiUnmask,
+ .disableIrq = HwiMask,
+ .getCurIrqNum = HwiNumGet,
+ .clearIrq = HwiClear,
+};
+
INLINE UINT32 ArchIsIntActive(VOID)
{
return (g_intCount > 0);
@@ -248,8 +249,8 @@ INLINE UINT32 ArchIsIntActive(VOID)
**************************************************************************** */
VOID HalHwiDefaultHandler(VOID)
{
- UINT32 irqNum = HalIntNumGet();
- PRINT_ERR("%s irqnum:%d\n", __FUNCTION__, irqNum);
+ UINT32 irqNum = HwiNumGet();
+ PRINT_ERR("%s irqnum:%u\n", __FUNCTION__, irqNum);
while (1) {}
}
@@ -279,8 +280,8 @@ VOID HalInterrupt(VOID)
g_intCount++;
LOS_IntRestore(intSave);
- hwiIndex = HalIntNumGet();
- HalIrqClear(hwiIndex);
+ hwiIndex = HwiNumGet();
+ HwiClear(hwiIndex);
OsHookCall(LOS_HOOK_TYPE_ISR_ENTER, hwiIndex);
@@ -347,7 +348,7 @@ UINT32 ArchHwiCreate(HWI_HANDLE_T hwiNum,
#else
OsSetVector(hwiNum, handler);
#endif
- HalIrqUnmask(hwiNum);
+ HwiUnmask(hwiNum);
LOS_IntRestore(intSave);
@@ -369,7 +370,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 ArchHwiDelete(HWI_HANDLE_T hwiNum)
return OS_ERRNO_HWI_NUM_INVALID;
}
- HalIrqMask(hwiNum);
+ HwiMask(hwiNum);
intSave = LOS_IntLock();
@@ -514,9 +515,9 @@ VOID HalExcHandleEntry(UINTPTR faultAddr, EXC_CONTEXT_S *excBufAddr, UINT32 type
if ((taskCB == NULL) || (taskCB == OS_TCB_FROM_TID(g_taskMaxNum))) {
g_excInfo.phase = OS_EXC_IN_INIT;
g_excInfo.thrdPid = OS_NULL_INT;
- } else if (HalIntNumGet() != OS_NULL_INT) {
+ } else if (HwiNumGet() != OS_NULL_INT) {
g_excInfo.phase = OS_EXC_IN_HWI;
- g_excInfo.thrdPid = HalIntNumGet();
+ g_excInfo.thrdPid = HwiNumGet();
} else {
g_excInfo.phase = OS_EXC_IN_TASK;
g_excInfo.thrdPid = g_losTask.runTask->taskID;
@@ -551,7 +552,7 @@ VOID HalHwiInit(VOID)
EnableExceptionInterface();
for (UINT32 i = 0; i < OS_HWI_MAX_NUM; i++) {
g_hwiForm[i + OS_SYS_VECTOR_CNT] = HalHwiDefaultHandler;
- HalIrqMask(i);
+ HwiMask(i);
}
asm volatile ("wsr %0, vecbase" : : "r"(INIT_VECTOR_START));
return;
diff --git a/arch/xtensa/lx6/gcc/los_timer.c b/arch/xtensa/lx6/gcc/los_timer.c
index edcbe5b4..5b1944fb 100644
--- a/arch/xtensa/lx6/gcc/los_timer.c
+++ b/arch/xtensa/lx6/gcc/los_timer.c
@@ -73,7 +73,7 @@ STATIC UINT32 SysTickStart(HWI_PROC_FUNC handler)
__asm__ __volatile__("wsr %0, ccompare1; rsync" : : "a"(0));
__asm__ __volatile__("wsr %0, ccompare2; rsync" : : "a"(0));
- HalIrqUnmask(tick->irqNum);
+ HwiUnmask(tick->irqNum);
return LOS_OK;
}
@@ -109,12 +109,12 @@ STATIC UINT64 SysTickCycleGet(UINT32 *period)
STATIC VOID SysTickLock(VOID)
{
- HalIrqMask(OS_TICK_INT_NUM);
+ HwiMask(OS_TICK_INT_NUM);
}
STATIC VOID SysTickUnlock(VOID)
{
- HalIrqUnmask(OS_TICK_INT_NUM);
+ HwiUnmask(OS_TICK_INT_NUM);
}
ArchTickTimer *ArchSysTickTimerGet(VOID)
diff --git a/bundle.json b/bundle.json
new file mode 100644
index 00000000..fdb79b1d
--- /dev/null
+++ b/bundle.json
@@ -0,0 +1,61 @@
+{
+ "name": "@ohos/liteos_m",
+ "version": "3.1.0",
+ "description": "liteos-m kernel",
+ "publishAs": "code-segment",
+ "homePage": "https://gitee.com/openharmony",
+ "repository": "https://gitee.com/openharmony/kernel_liteos_m",
+ "license": "BSD 3-clause",
+ "domain": "os",
+ "language": "",
+ "private": false,
+ "scripts": {},
+ "tags": [
+ "kernel"
+ ],
+ "keywords": [
+ "kernel",
+ "liteos-m"
+ ],
+ "envs": [],
+ "dirs": [],
+ "author": {},
+ "contributors": [],
+ "segment": {
+ "destPath": "kernel/liteos_m"
+ },
+ "component": {
+ "name": "liteos_m",
+ "subsystem": "kernel",
+ "syscap": [
+ "SystemCapability.Kernel.liteos-m"
+ ],
+ "features": [],
+ "adapted_system_type": [
+ "mini"
+ ],
+ "rom": "300KB",
+ "ram": "100KB",
+ "deps": {
+ "components": [
+ "utils_lite"
+ ],
+ "third_party": [
+ "bounds_checking_function",
+ "cmsis",
+ "fatfs",
+ "littlefs",
+ "lwip",
+ "musl"
+ ]
+ },
+ "build": {
+ "sub_component": [
+ "//kernel/liteos_m:kernel",
+ "//kernel/liteos_m:build_kernel_image"
+ ],
+ "inner_kits": [],
+ "test": []
+ }
+ }
+}
\ No newline at end of file
diff --git a/components/fs/fatfs/BUILD.gn b/components/fs/fatfs/BUILD.gn
index 7667cf0d..0c999cf0 100644
--- a/components/fs/fatfs/BUILD.gn
+++ b/components/fs/fatfs/BUILD.gn
@@ -28,21 +28,15 @@
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import("//kernel/liteos_m/liteos.gni")
+import("//third_party/FatFs/FatFs.gni")
module_switch = defined(LOSCFG_FS_FAT)
module_name = get_path_info(rebase_path("."), "name")
kernel_module(module_name) {
- sources = [
- "$LITEOSTHIRDPARTY/FatFs/source/diskio.c",
- "$LITEOSTHIRDPARTY/FatFs/source/ff.c",
- "$LITEOSTHIRDPARTY/FatFs/source/ffsystem.c",
- "$LITEOSTHIRDPARTY/FatFs/source/ffunicode.c",
- "fatfs.c",
- ]
configs += [ "$LITEOSTOPDIR:warn_config" ]
+ sources = FATFS_SRC_FILES + [ "fatfs.c" ]
}
config("public") {
- include_dirs = [ "." ]
- include_dirs += [ "$LITEOSTHIRDPARTY/FatFs/source" ]
+ include_dirs = FATFS_INCLUDE_DIRS + [ "." ]
}
diff --git a/components/fs/fatfs/fatfs.h b/components/fs/fatfs/fatfs.h
index 21ad1e7f..6c92fde8 100644
--- a/components/fs/fatfs/fatfs.h
+++ b/components/fs/fatfs/fatfs.h
@@ -32,28 +32,21 @@
#ifndef _FATFS_H
#define _FATFS_H
-#include "fcntl.h"
#include "dirent.h"
-#include "unistd.h"
+#include "fatfs_conf.h"
+#include "fcntl.h"
+#include "fs_config.h"
#include "sys/mount.h"
#include "sys/stat.h"
#include "sys/statfs.h"
-#include "fs_config.h"
+#include "unistd.h"
+
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
-#ifndef FAT_MAX_OPEN_FILES
-#define FAT_MAX_OPEN_FILES 50
-#endif /* FAT_MAX_OPEN_FILES */
-
-/* Format options */
-#define FMT_FAT 0x01
-#define FMT_FAT32 0x02
-#define FMT_ANY 0x07
-
int fatfs_mount(const char *source, const char *target,
const char *filesystemtype, unsigned long mountflags,
const void *data);
diff --git a/components/fs/fatfs/fatfs_conf.h b/components/fs/fatfs/fatfs_conf.h
new file mode 100644
index 00000000..88127128
--- /dev/null
+++ b/components/fs/fatfs/fatfs_conf.h
@@ -0,0 +1,43 @@
+/*
+ * 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 _FATFS_CONF_H
+#define _FATFS_CONF_H
+
+#ifndef FAT_MAX_OPEN_FILES
+#define FAT_MAX_OPEN_FILES 50
+#endif /* FAT_MAX_OPEN_FILES */
+
+/* Format options */
+#define FMT_FAT 0x01
+#define FMT_FAT32 0x02
+#define FMT_ANY 0x07
+
+#endif // _FATFS_CONF_H
diff --git a/components/fs/littlefs/BUILD.gn b/components/fs/littlefs/BUILD.gn
index 3407d2d4..a7faa85a 100644
--- a/components/fs/littlefs/BUILD.gn
+++ b/components/fs/littlefs/BUILD.gn
@@ -28,21 +28,15 @@
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import("//kernel/liteos_m/liteos.gni")
+import("//third_party/littlefs/littlefs.gni")
module_switch = defined(LOSCFG_FS_LITTLEFS)
module_name = get_path_info(rebase_path("."), "name")
kernel_module(module_name) {
- sources = [
- "$LITEOSTHIRDPARTY/littlefs/bd/lfs_rambd.c",
- "$LITEOSTHIRDPARTY/littlefs/lfs.c",
- "$LITEOSTHIRDPARTY/littlefs/lfs_util.c",
- "lfs_api.c",
- ]
configs += [ "$LITEOSTOPDIR:warn_config" ]
+ sources = LITTLEFS_SRC_FILES_FOR_KERNEL_MODULE + [ "lfs_api.c" ]
}
config("public") {
- include_dirs = [ "." ]
- include_dirs += [ "$LITEOSTHIRDPARTY/littlefs" ]
- include_dirs += [ "$LITEOSTHIRDPARTY/littlefs/bd" ]
+ include_dirs = LITTLEFS_INCLUDE_DIRS + [ "." ]
}
diff --git a/components/fs/littlefs/lfs_api.h b/components/fs/littlefs/lfs_api.h
index b1ff93be..8776f49d 100644
--- a/components/fs/littlefs/lfs_api.h
+++ b/components/fs/littlefs/lfs_api.h
@@ -39,6 +39,7 @@
#include "errno.h"
#include "fs_operations.h"
#include "lfs.h"
+#include "lfs_conf.h"
#include "lfs_util.h"
#include "memory.h"
#include "pthread.h"
@@ -74,20 +75,6 @@ typedef struct {
lfs_dir_t dir;
} FileDirInfo;
-#define LITTLE_FS_MAX_OPEN_FILES 100
-#define LITTLE_FS_STANDARD_NAME_LENGTH 50
-#define LITTLE_FS_MAX_NAME_LEN 255
-
-#define MAX_DEF_BUF_NUM 21
-#define MAX_BUFFER_LEN 100
-#define MAX_WRITE_FILE_LEN 500
-#define MAX_READ_FILE_LEN 500
-#define LITTLEFS_MAX_LFN_LEN 255
-
-#ifndef LFS_MAX_OPEN_DIRS
-#define LFS_MAX_OPEN_DIRS 10
-#endif
-
LittleFsHandleStruct *GetFreeFd(int *fd);
int LfsMount(const char *source, const char *target, const char *fileSystemType, unsigned long mountflags,
diff --git a/components/fs/littlefs/lfs_conf.h b/components/fs/littlefs/lfs_conf.h
new file mode 100644
index 00000000..f0f785bb
--- /dev/null
+++ b/components/fs/littlefs/lfs_conf.h
@@ -0,0 +1,47 @@
+/*
+ * 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 _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
+
+#define MAX_DEF_BUF_NUM 21
+#define MAX_WRITE_FILE_LEN 500
+#define MAX_READ_FILE_LEN 500
+#define LITTLEFS_MAX_LFN_LEN 255
+
+#ifndef LFS_MAX_OPEN_DIRS
+#define LFS_MAX_OPEN_DIRS 10
+#endif
+
+#endif // _LFS_CONF_H
diff --git a/components/fs/vfs/vfs_config.h b/components/fs/vfs/vfs_config.h
index e70d722c..f0ad857d 100644
--- a/components/fs/vfs/vfs_config.h
+++ b/components/fs/vfs/vfs_config.h
@@ -98,14 +98,14 @@
/* max numbers of other descriptors except socket descriptors */
#ifdef LOSCFG_FS_FAT
-#include "fatfs.h"
+#include "fatfs_conf.h"
#define __FAT_NFILE FAT_MAX_OPEN_FILES
#else
#define __FAT_NFILE 0
#endif
#ifdef LOSCFG_FS_LITTLEFS
-#include "lfs_api.h"
+#include "lfs_conf.h"
#define __LFS_NFILE LITTLE_FS_MAX_OPEN_FILES
#else
#define __LFS_NFILE 0
@@ -123,12 +123,10 @@
#define CONFIG_NQUEUE_DESCRIPTORS 256
-#undef FD_SETSIZE
-#define FD_SETSIZE (CONFIG_NFILE_DESCRIPTORS + CONFIG_NSOCKET_DESCRIPTORS)
+#define TIMER_FD_OFFSET (CONFIG_NFILE_DESCRIPTORS + CONFIG_NSOCKET_DESCRIPTORS)
#define CONFIG_NEXPANED_DESCRIPTORS (CONFIG_NTIME_DESCRIPTORS + CONFIG_NQUEUE_DESCRIPTORS)
-#define FD_SET_TOTAL_SIZE (FD_SETSIZE + CONFIG_NEXPANED_DESCRIPTORS)
-#define TIMER_FD_OFFSET FD_SETSIZE
-#define MQUEUE_FD_OFFSET (FD_SETSIZE + CONFIG_NTIME_DESCRIPTORS)
+#define FD_SET_TOTAL_SIZE (TIMER_FD_OFFSET + CONFIG_NEXPANED_DESCRIPTORS)
+#define MQUEUE_FD_OFFSET (TIMER_FD_OFFSET + CONFIG_NTIME_DESCRIPTORS)
/* directory configure */
diff --git a/components/net/lwip-2.1/porting/include/lwip/lwipopts.h b/components/net/lwip-2.1/porting/include/lwip/lwipopts.h
index 529f04a8..2449d31b 100644
--- a/components/net/lwip-2.1/porting/include/lwip/lwipopts.h
+++ b/components/net/lwip-2.1/porting/include/lwip/lwipopts.h
@@ -134,10 +134,6 @@
#define LWIP_NETIF_LOOPBACK 1
#define LWIP_POSIX_SOCKETS_IO_NAMES 0
#define LWIP_RAW 1
-#ifdef LOSCFG_FS_VFS
-#include "vfs_config.h"
-#define LWIP_SOCKET_OFFSET CONFIG_NFILE_DESCRIPTORS
-#endif
#define LWIP_SO_RCVBUF 1
#define LWIP_SO_RCVTIMEO 1
#define LWIP_SO_SNDTIMEO 1
@@ -234,4 +230,9 @@
// use PBUF_RAM instead of PBUF_POOL in udp_input
#define USE_PBUF_RAM_UDP_INPUT 1
+#ifdef LOSCFG_FS_VFS
+#include "vfs_config.h"
+#define LWIP_SOCKET_OFFSET CONFIG_NFILE_DESCRIPTORS
+#endif
+
#endif /* _LWIP_PORTING_LWIPOPTS_H_ */
diff --git a/components/signal/BUILD.gn b/components/signal/BUILD.gn
index e473daa9..590f9556 100644
--- a/components/signal/BUILD.gn
+++ b/components/signal/BUILD.gn
@@ -31,6 +31,7 @@ import("//kernel/liteos_m/liteos.gni")
module_name = get_path_info(rebase_path("."), "name")
kernel_module(module_name) {
sources = [ "los_signal.c" ]
+ configs += [ "$LITEOSTOPDIR:warn_config" ]
}
config("public") {
diff --git a/components/signal/Kconfig b/components/signal/Kconfig
index c9bd7c97..6808b9c5 100644
--- a/components/signal/Kconfig
+++ b/components/signal/Kconfig
@@ -1,6 +1,6 @@
config KERNEL_SIGNAL
bool "Enable Signal"
- default n
+ default y
depends on KERNEL_EXTKERNEL
help
Select y to build LiteOS with signal.
diff --git a/kal/cmsis/BUILD.gn b/kal/cmsis/BUILD.gn
index 619ec86c..6bb15b1f 100644
--- a/kal/cmsis/BUILD.gn
+++ b/kal/cmsis/BUILD.gn
@@ -28,6 +28,7 @@
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import("//kernel/liteos_m/liteos.gni")
+import("//third_party/cmsis/cmsis.gni")
module_switch = defined(LOSCFG_KAL_CMSIS)
module_name = get_path_info(rebase_path("."), "name")
@@ -37,9 +38,5 @@ kernel_module(module_name) {
}
config("public") {
- include_dirs = [
- ".",
- "$LITEOSTHIRDPARTY/cmsis/CMSIS/RTOS2/Include",
- "$LITEOSTHIRDPARTY/cmsis/CMSIS/Core/Include",
- ]
+ include_dirs = CMSIS_INCLUDE_DIRS + [ "." ]
}
diff --git a/kal/cmsis/cmsis_liteos2.c b/kal/cmsis/cmsis_liteos2.c
index 539c53a2..c99bf731 100644
--- a/kal/cmsis/cmsis_liteos2.c
+++ b/kal/cmsis/cmsis_liteos2.c
@@ -46,7 +46,6 @@
#include "string.h"
#include "securec.h"
-
/* Kernel initialization state */
static osKernelState_t g_kernelState;
@@ -72,8 +71,10 @@ const osVersion_t g_stLosVersion = { 001, 001 };
#define KERNEL_ID "HUAWEI-LiteOS"
-// ==== Kernel Management Functions ====
+#define KERNEL_UNLOCKED 0
+#define KERNEL_LOCKED 1
+// ==== Kernel Management Functions ====
osStatus_t osKernelInitialize(void)
{
if (OS_INT_ACTIVE) {
@@ -84,7 +85,7 @@ osStatus_t osKernelInitialize(void)
return osError;
}
- if (LOS_OK == LOS_KernelInit()) {
+ if (LOS_KernelInit() == LOS_OK) {
g_kernelState = osKernelReady;
return osOK;
} else {
@@ -92,41 +93,27 @@ osStatus_t osKernelInitialize(void)
}
}
-
osStatus_t osKernelGetInfo(osVersion_t *version, char *id_buf, uint32_t id_size)
{
- uint32_t uwRet;
+ errno_t ret;
- if (OS_INT_ACTIVE) {
- return osErrorISR;
+ if ((version == NULL) || (id_buf == NULL) || (id_size == 0)) {
+ return osError;
}
- if (version != NULL) {
+ ret = memcpy_s(id_buf, id_size, KERNEL_ID, sizeof(KERNEL_ID));
+ if (ret == EOK) {
version->api = g_stLosVersion.api;
version->kernel = g_stLosVersion.kernel;
+ return osOK;
+ } else {
+ PRINT_ERR("[%s] memcpy_s failed, error type = %d\n", __func__, ret);
+ return osError;
}
-
- if ((id_buf != NULL) && (id_size != 0U)) {
- if (id_size > sizeof(KERNEL_ID)) {
- id_size = sizeof(KERNEL_ID);
- }
- uwRet = memcpy_s(id_buf, id_size, KERNEL_ID, id_size);
- if (uwRet != EOK) {
- PRINT_ERR("%s[%d] memcpy failed, error type = %lu\n", __FUNCTION__, __LINE__, uwRet);
- return osError;
- }
- }
-
- return osOK;
}
-
osKernelState_t osKernelGetState(void)
{
- if (OS_INT_ACTIVE) {
- return osKernelError;
- }
-
if (!g_taskScheduled) {
if (g_kernelState == osKernelReady) {
return osKernelReady;
@@ -140,26 +127,23 @@ osKernelState_t osKernelGetState(void)
}
}
-
osStatus_t osKernelStart(void)
{
if (OS_INT_ACTIVE) {
return osErrorISR;
}
+ if (g_kernelState != osKernelReady) {
+ return osError;
+ }
- if (g_kernelState == osKernelReady) {
- if (LOS_OK == LOS_Start()) {
- g_kernelState = osKernelRunning;
- return osOK;
- } else {
- return osError;
- }
+ if (LOS_Start() == LOS_OK) {
+ g_kernelState = osKernelRunning;
+ return osOK;
} else {
return osError;
}
}
-
int32_t osKernelLock(void)
{
int32_t lock;
@@ -173,16 +157,15 @@ int32_t osKernelLock(void)
}
if (g_losTaskLock > 0) {
- lock = 1;
+ lock = KERNEL_LOCKED;
} else {
LOS_TaskLock();
- lock = 0;
+ lock = KERNEL_UNLOCKED;
}
return lock;
}
-
int32_t osKernelUnlock(void)
{
int32_t lock;
@@ -200,15 +183,14 @@ int32_t osKernelUnlock(void)
if (g_losTaskLock != 0) {
return (int32_t)osError;
}
- lock = 1;
+ lock = KERNEL_LOCKED;
} else {
- lock = 0;
+ lock = KERNEL_UNLOCKED;
}
return lock;
}
-
int32_t osKernelRestoreLock(int32_t lock)
{
if (OS_INT_ACTIVE) {
@@ -220,15 +202,15 @@ int32_t osKernelRestoreLock(int32_t lock)
}
switch (lock) {
- case 0:
+ case KERNEL_UNLOCKED:
LOS_TaskUnlock();
if (g_losTaskLock != 0) {
break;
}
- return 0;
- case 1:
+ return KERNEL_UNLOCKED;
+ case KERNEL_LOCKED:
LOS_TaskLock();
- return 1;
+ return KERNEL_LOCKED;
default:
break;
}
@@ -236,7 +218,6 @@ int32_t osKernelRestoreLock(int32_t lock)
return (int32_t)osError;
}
-
uint32_t osKernelGetTickCount(void)
{
uint64_t ticks = LOS_TickCountGet();
@@ -245,51 +226,34 @@ uint32_t osKernelGetTickCount(void)
uint32_t osKernelGetTickFreq(void)
{
- uint32_t freq;
-
- if (OS_INT_ACTIVE) {
- freq = 0U;
- } else {
- freq = LOSCFG_BASE_CORE_TICK_PER_SECOND;
- }
-
- return (freq);
+ return (uint32_t)LOSCFG_BASE_CORE_TICK_PER_SECOND;
}
uint32_t osKernelGetSysTimerCount(void)
{
- uint32_t countLow;
- if (OS_INT_ACTIVE) {
- countLow = 0U;
- } else {
- countLow = (UINT32)LOS_SysCycleGet();
- }
- return countLow;
+ return (uint32_t)LOS_SysCycleGet();
}
-
uint32_t osKernelGetSysTimerFreq(void)
{
return g_sysClock;
}
-
// ==== Thread Management Functions ====
-
osThreadId_t osThreadNew(osThreadFunc_t func, void *argument, const osThreadAttr_t *attr)
{
- UINT32 uwTid;
- UINT32 uwRet;
+ UINT32 tid;
+ UINT32 ret;
LosTaskCB *pstTaskCB = NULL;
TSK_INIT_PARAM_S stTskInitParam = {NULL};
- UINT16 usPriority;
+ UINT16 priority;
if (OS_INT_ACTIVE || (func == NULL)) {
return (osThreadId_t)NULL;
}
- usPriority = attr ? LOS_PRIORITY(attr->priority) : LOSCFG_BASE_CORE_TSK_DEFAULT_PRIO;
- if (!ISVALID_LOS_PRIORITY(usPriority)) {
+ priority = attr ? LOS_PRIORITY(attr->priority) : LOSCFG_BASE_CORE_TSK_DEFAULT_PRIO;
+ if (!ISVALID_LOS_PRIORITY(priority)) {
/* unsupported priority */
return (osThreadId_t)NULL;
}
@@ -298,22 +262,21 @@ osThreadId_t osThreadNew(osThreadFunc_t func, void *argument, const osThreadAttr
stTskInitParam.uwArg = (UINT32)argument;
stTskInitParam.uwStackSize = attr ? attr->stack_size : LOSCFG_BASE_CORE_TSK_DEFAULT_STACK_SIZE;
stTskInitParam.pcName = (CHAR *)(attr ? attr->name : "[NULL]");
- stTskInitParam.usTaskPrio = usPriority;
- if (attr->attr_bits == osThreadJoinable) {
+ stTskInitParam.usTaskPrio = priority;
+ if ((attr != NULL) && (attr->attr_bits == osThreadJoinable)) {
stTskInitParam.uwResved = LOS_TASK_ATTR_JOINABLE;
}
- uwRet = LOS_TaskCreate(&uwTid, &stTskInitParam);
+ ret = LOS_TaskCreate(&tid, &stTskInitParam);
- if (LOS_OK != uwRet) {
+ if (ret != LOS_OK) {
return (osThreadId_t)NULL;
}
- pstTaskCB = OS_TCB_FROM_TID(uwTid);
+ pstTaskCB = OS_TCB_FROM_TID(tid);
return (osThreadId_t)pstTaskCB;
}
-
const char *osThreadGetName(osThreadId_t thread_id)
{
LosTaskCB *pstTaskCB = NULL;
@@ -327,13 +290,8 @@ const char *osThreadGetName(osThreadId_t thread_id)
return pstTaskCB->taskName;
}
-
osThreadId_t osThreadGetId(void)
{
- if (OS_INT_ACTIVE) {
- return NULL;
- }
-
return (osThreadId_t)(g_losTask.runTask);
}
@@ -368,7 +326,8 @@ osThreadState_t osThreadGetState(osThreadId_t thread_id)
} else if (taskStatus & OS_TASK_STATUS_READY) {
stState = osThreadReady;
} else if (taskStatus &
- (OS_TASK_STATUS_DELAY | OS_TASK_STATUS_PEND | OS_TASK_STATUS_SUSPEND)) {
+ (OS_TASK_STATUS_DELAY | OS_TASK_STATUS_PEND |
+ OS_TASK_STATUS_SUSPEND | OS_TASK_STATUS_PEND_TIME)) {
stState = osThreadBlocked;
} else if (taskStatus & OS_TASK_STATUS_UNUSED) {
stState = osThreadInactive;
@@ -379,7 +338,6 @@ osThreadState_t osThreadGetState(osThreadId_t thread_id)
return stState;
}
-
uint32_t osThreadGetStackSize(osThreadId_t thread_id)
{
LosTaskCB *pstTaskCB = NULL;
@@ -393,11 +351,10 @@ uint32_t osThreadGetStackSize(osThreadId_t thread_id)
return pstTaskCB->stackSize;
}
-
uint32_t osTaskStackWaterMarkGet(UINT32 taskID)
{
- UINT32 uwCount = 0;
- UINT32 *ptopOfStack;
+ UINT32 count = 0;
+ UINT32 *ptopOfStack = NULL;
UINT32 intSave;
LosTaskCB *pstTaskCB = NULL;
@@ -418,16 +375,15 @@ uint32_t osTaskStackWaterMarkGet(UINT32 taskID)
while (*ptopOfStack == (UINT32)OS_TASK_STACK_INIT) {
++ptopOfStack;
- ++uwCount;
+ ++count;
}
- uwCount *= sizeof(UINT32);
+ count *= sizeof(UINT32);
LOS_IntRestore(intSave);
- return uwCount;
+ return count;
}
-
uint32_t osThreadGetStackSpace(osThreadId_t thread_id)
{
LosTaskCB *pstTaskCB = NULL;
@@ -441,11 +397,10 @@ uint32_t osThreadGetStackSpace(osThreadId_t thread_id)
return osTaskStackWaterMarkGet(pstTaskCB->taskID);
}
-
osStatus_t osThreadSetPriority(osThreadId_t thread_id, osPriority_t priority)
{
- UINT32 uwRet;
- UINT16 usPriority;
+ UINT32 ret;
+ UINT16 prio;
LosTaskCB *pstTaskCB = NULL;
if (OS_INT_ACTIVE) {
@@ -456,16 +411,16 @@ osStatus_t osThreadSetPriority(osThreadId_t thread_id, osPriority_t priority)
return osErrorParameter;
}
- usPriority = LOS_PRIORITY(priority);
- if (!ISVALID_LOS_PRIORITY(usPriority)) {
+ prio = LOS_PRIORITY(priority);
+ if (!ISVALID_LOS_PRIORITY(prio)) {
return osErrorParameter;
}
pstTaskCB = (LosTaskCB *)thread_id;
- uwRet = LOS_TaskPriSet(pstTaskCB->taskID, usPriority);
- switch (uwRet) {
+ ret = LOS_TaskPriSet(pstTaskCB->taskID, prio);
+ switch (ret) {
case LOS_ERRNO_TSK_PRIOR_ERROR:
- case LOS_ERRNO_TSK_OPERATE_IDLE:
+ case LOS_ERRNO_TSK_OPERATE_SYSTEM_TASK:
case LOS_ERRNO_TSK_ID_INVALID:
return osErrorParameter;
@@ -477,10 +432,9 @@ osStatus_t osThreadSetPriority(osThreadId_t thread_id, osPriority_t priority)
}
}
-
osPriority_t osThreadGetPriority(osThreadId_t thread_id)
{
- UINT16 usRet;
+ UINT16 ret;
LosTaskCB *pstTaskCB = NULL;
if (OS_INT_ACTIVE || thread_id == NULL) {
@@ -488,37 +442,35 @@ osPriority_t osThreadGetPriority(osThreadId_t thread_id)
}
pstTaskCB = (LosTaskCB *)thread_id;
- usRet = LOS_TaskPriGet(pstTaskCB->taskID);
+ ret = LOS_TaskPriGet(pstTaskCB->taskID);
- if (usRet == (UINT16)OS_INVALID) {
+ if ((ret == (UINT16)OS_INVALID) || (ret > OS_TASK_PRIORITY_LOWEST)) {
return osPriorityError;
}
- return (osPriority_t)CMSIS_PRIORITY(usRet);
+ return (osPriority_t)CMSIS_PRIORITY(ret);
}
-
osStatus_t osThreadYield(void)
{
- UINT32 uwRet;
+ UINT32 ret;
if (OS_INT_ACTIVE) {
return osErrorISR;
}
- uwRet = LOS_TaskYield();
+ ret = LOS_TaskYield();
- if (uwRet == LOS_OK) {
+ if (ret == LOS_OK) {
return osOK;
}
return osError;
}
-
osStatus_t osThreadSuspend(osThreadId_t thread_id)
{
- UINT32 uwRet;
+ UINT32 ret;
LosTaskCB *pstTaskCB = NULL;
if (OS_INT_ACTIVE) {
@@ -530,8 +482,8 @@ osStatus_t osThreadSuspend(osThreadId_t thread_id)
}
pstTaskCB = (LosTaskCB *)thread_id;
- uwRet = LOS_TaskSuspend(pstTaskCB->taskID);
- switch (uwRet) {
+ ret = LOS_TaskSuspend(pstTaskCB->taskID);
+ switch (ret) {
case LOS_ERRNO_TSK_OPERATE_IDLE:
case LOS_ERRNO_TSK_SUSPEND_SWTMR_NOT_ALLOWED:
case LOS_ERRNO_TSK_ID_INVALID:
@@ -547,10 +499,9 @@ osStatus_t osThreadSuspend(osThreadId_t thread_id)
}
}
-
osStatus_t osThreadResume(osThreadId_t thread_id)
{
- UINT32 uwRet;
+ UINT32 ret;
LosTaskCB *pstTaskCB = NULL;
if (OS_INT_ACTIVE) {
@@ -562,9 +513,9 @@ osStatus_t osThreadResume(osThreadId_t thread_id)
}
pstTaskCB = (LosTaskCB *)thread_id;
- uwRet = LOS_TaskResume(pstTaskCB->taskID);
+ ret = LOS_TaskResume(pstTaskCB->taskID);
- switch (uwRet) {
+ switch (ret) {
case LOS_ERRNO_TSK_ID_INVALID:
return osErrorParameter;
@@ -577,7 +528,6 @@ osStatus_t osThreadResume(osThreadId_t thread_id)
}
}
-
osStatus_t osThreadDetach(osThreadId_t thread_id)
{
UINT32 ret;
@@ -597,7 +547,6 @@ osStatus_t osThreadDetach(osThreadId_t thread_id)
return osOK;
}
-
osStatus_t osThreadJoin(osThreadId_t thread_id)
{
UINT32 ret;
@@ -617,10 +566,9 @@ osStatus_t osThreadJoin(osThreadId_t thread_id)
return osOK;
}
-
osStatus_t osThreadTerminate(osThreadId_t thread_id)
{
- UINT32 uwRet;
+ UINT32 ret;
LosTaskCB *pstTaskCB = NULL;
if (OS_INT_ACTIVE) {
@@ -632,9 +580,9 @@ osStatus_t osThreadTerminate(osThreadId_t thread_id)
}
pstTaskCB = (LosTaskCB *)thread_id;
- uwRet = LOS_TaskDelete(pstTaskCB->taskID);
+ ret = LOS_TaskDelete(pstTaskCB->taskID);
- switch (uwRet) {
+ switch (ret) {
case LOS_ERRNO_TSK_OPERATE_IDLE:
case LOS_ERRNO_TSK_SUSPEND_SWTMR_NOT_ALLOWED:
case LOS_ERRNO_TSK_ID_INVALID:
@@ -648,10 +596,9 @@ osStatus_t osThreadTerminate(osThreadId_t thread_id)
}
}
-
uint32_t osThreadGetCount(void)
{
- uint32_t uwCount = 0;
+ uint32_t count = 0;
if (OS_INT_ACTIVE) {
return 0U;
@@ -659,54 +606,54 @@ uint32_t osThreadGetCount(void)
for (uint32_t index = 0; index <= LOSCFG_BASE_CORE_TSK_LIMIT; index++) {
if (!((g_taskCBArray + index)->taskStatus & OS_TASK_STATUS_UNUSED)) {
- uwCount++;
+ count++;
}
}
- return uwCount;
+ return count;
}
-
void osThreadExit(void)
{
(void)LOS_TaskDelete(LOS_CurTaskIDGet());
UNREACHABLE;
}
-
osStatus_t osDelay(uint32_t ticks)
{
- UINT32 uwRet = LOS_OK;
+ UINT32 ret;
+ if (OS_INT_ACTIVE) {
+ return osErrorISR;
+ }
if (ticks == 0) {
- return osOK;
+ return osErrorParameter;
}
- if (osKernelGetState() != osKernelRunning) {
- LOS_UDelay(ticks * OS_US_PER_TICK);
- } else {
- uwRet = LOS_TaskDelay(ticks);
- }
- if (uwRet == LOS_OK) {
+ ret = LOS_TaskDelay(ticks);
+ if (ret == LOS_OK) {
return osOK;
} else {
return osError;
}
}
-
osStatus_t osDelayUntil(uint32_t ticks)
{
- UINT32 uwRet;
+ UINT32 ret;
UINT32 uwTicks;
UINT32 tickCount = osKernelGetTickCount();
+ if (OS_INT_ACTIVE) {
+ return osErrorISR;
+ }
+
if (ticks < tickCount) {
return osError;
}
uwTicks = (UINT32)(ticks - tickCount);
- uwRet = LOS_TaskDelay(uwTicks);
- if (uwRet == LOS_OK) {
+ ret = LOS_TaskDelay(uwTicks);
+ if (ret == LOS_OK) {
return osOK;
} else {
return osError;
@@ -718,11 +665,19 @@ osStatus_t osDelayUntil(uint32_t ticks)
osTimerId_t osTimerNew(osTimerFunc_t func, osTimerType_t type, void *argument, const osTimerAttr_t *attr)
{
UNUSED(attr);
- UINT32 usSwTmrID;
+ UINT32 swtmrId;
UINT8 mode;
- if ((NULL == func) || ((osTimerOnce != type) && (osTimerPeriodic != type))) {
- return (osTimerId_t)NULL;
+ if ((func == NULL) || OS_INT_ACTIVE) {
+ return NULL;
+ }
+
+ if (type == osTimerOnce) {
+ mode = LOS_SWTMR_MODE_NO_SELFDELETE;
+ } else if (type == osTimerPeriodic) {
+ mode = LOS_SWTMR_MODE_PERIOD;
+ } else {
+ return NULL;
}
if (osTimerOnce == type) {
@@ -731,20 +686,18 @@ osTimerId_t osTimerNew(osTimerFunc_t func, osTimerType_t type, void *argument, c
mode = LOS_SWTMR_MODE_PERIOD;
}
#if (LOSCFG_BASE_CORE_SWTMR_ALIGN == 1)
- if (LOS_OK != LOS_SwtmrCreate(1, mode, (SWTMR_PROC_FUNC)func, &usSwTmrID, (UINT32)(UINTPTR)argument,
- osTimerRousesAllow, osTimerAlignIgnore)) {
+ if (LOS_SwtmrCreate(1, mode, (SWTMR_PROC_FUNC)func, &swtmrId, (UINT32)(UINTPTR)argument,
+ osTimerRousesAllow, osTimerAlignIgnore) != LOS_OK) {
return (osTimerId_t)NULL;
}
#else
- if (LOS_OK != LOS_SwtmrCreate(1, mode, (SWTMR_PROC_FUNC)func, &usSwTmrID, (UINT32)(UINTPTR)argument)) {
+ if (LOS_SwtmrCreate(1, mode, (SWTMR_PROC_FUNC)func, &swtmrId, (UINT32)(UINTPTR)argument) != LOS_OK) {
return (osTimerId_t)NULL;
}
#endif
-
- return (osTimerId_t)OS_SWT_FROM_SID(usSwTmrID);
+ return (osTimerId_t)OS_SWT_FROM_SID(swtmrId);
}
-
#if (LOSCFG_BASE_CORE_SWTMR_ALIGN == 1)
osTimerId_t osTimerExtNew(osTimerFunc_t func, osTimerType_t type, void *argument, const osTimerAttr_t *attr,
osTimerRouses_t ucRouses, osTimerAlign_t ucSensitive)
@@ -771,81 +724,87 @@ osTimerId_t osTimerExtNew(osTimerFunc_t func, osTimerType_t type, void *argument
}
#endif
-
osStatus_t osTimerStart(osTimerId_t timer_id, uint32_t ticks)
{
- UINT32 uwRet;
- SWTMR_CTRL_S *pstSwtmr;
-
- if ((0 == ticks) || (NULL == timer_id)) {
+ UINT32 ret;
+ SWTMR_CTRL_S *pstSwtmr = NULL;
+ if (OS_INT_ACTIVE) {
+ return osErrorISR;
+ }
+ if ((ticks == 0) || (timer_id == NULL)) {
return osErrorParameter;
}
UINT32 intSave = LOS_IntLock();
pstSwtmr = (SWTMR_CTRL_S *)timer_id;
pstSwtmr->uwInterval = ticks;
- uwRet = LOS_SwtmrStart(pstSwtmr->usTimerID);
+ ret = LOS_SwtmrStart(pstSwtmr->usTimerID);
LOS_IntRestore(intSave);
- if (LOS_OK == uwRet) {
+ if (ret == LOS_OK) {
return osOK;
- } else if (LOS_ERRNO_SWTMR_ID_INVALID == uwRet) {
+ } else if (ret == LOS_ERRNO_SWTMR_ID_INVALID) {
return osErrorParameter;
} else {
return osErrorResource;
}
}
-
const char *osTimerGetName(osTimerId_t timer_id)
{
UNUSED(timer_id);
return (const char *)NULL;
}
-
osStatus_t osTimerStop(osTimerId_t timer_id)
{
- UINT32 uwRet;
+ UINT32 ret;
SWTMR_CTRL_S *pstSwtmr = (SWTMR_CTRL_S *)timer_id;
- if (NULL == pstSwtmr) {
+ if (OS_INT_ACTIVE) {
+ return osErrorISR;
+ }
+
+ if (pstSwtmr == NULL) {
return osErrorParameter;
}
- uwRet = LOS_SwtmrStop(pstSwtmr->usTimerID);
- if (LOS_OK == uwRet) {
+ ret = LOS_SwtmrStop(pstSwtmr->usTimerID);
+ if (ret == LOS_OK) {
return osOK;
- } else if (LOS_ERRNO_SWTMR_ID_INVALID == uwRet) {
+ } else if (ret == LOS_ERRNO_SWTMR_ID_INVALID) {
return osErrorParameter;
} else {
return osErrorResource;
}
}
-
uint32_t osTimerIsRunning(osTimerId_t timer_id)
{
- if (NULL == timer_id) {
+ if (OS_INT_ACTIVE) {
+ return osErrorISR;
+ }
+ if (timer_id == NULL) {
return 0;
}
return (OS_SWTMR_STATUS_TICKING == ((SWTMR_CTRL_S *)timer_id)->ucState);
}
-
osStatus_t osTimerDelete(osTimerId_t timer_id)
{
- UINT32 uwRet;
+ UINT32 ret;
SWTMR_CTRL_S *pstSwtmr = (SWTMR_CTRL_S *)timer_id;
- if (NULL == pstSwtmr) {
+ if (OS_INT_ACTIVE) {
+ return osErrorISR;
+ }
+ if (pstSwtmr == NULL) {
return osErrorParameter;
}
-
- uwRet = LOS_SwtmrDelete(pstSwtmr->usTimerID);
- if (LOS_OK == uwRet) {
+ ret = LOS_SwtmrDelete(pstSwtmr->usTimerID);
+ if (ret == LOS_OK) {
return osOK;
- } else if (LOS_ERRNO_SWTMR_ID_INVALID == uwRet) {
+ } else if (ret == LOS_ERRNO_SWTMR_ID_INVALID) {
return osErrorParameter;
} else {
return osErrorResource;
@@ -856,7 +815,7 @@ osStatus_t osTimerDelete(osTimerId_t timer_id)
osEventFlagsId_t osEventFlagsNew(const osEventFlagsAttr_t *attr)
{
PEVENT_CB_S pstEventCB;
- UINT32 uwRet;
+ UINT32 ret;
UNUSED(attr);
@@ -869,51 +828,50 @@ osEventFlagsId_t osEventFlagsNew(const osEventFlagsAttr_t *attr)
return (osEventFlagsId_t)NULL;
}
- uwRet = LOS_EventInit(pstEventCB);
- if (uwRet == LOS_ERRNO_EVENT_PTR_NULL) {
- return (osEventFlagsId_t)NULL;
- } else {
+ ret = LOS_EventInit(pstEventCB);
+ if (ret == LOS_OK) {
return (osEventFlagsId_t)pstEventCB;
+ } else {
+ if (LOS_MemFree(m_aucSysMem0, pstEventCB) != LOS_OK) {
+ PRINT_ERR("[%s] memory free fail!\n", __func__);
+ }
+ return NULL;
}
}
-
const char *osEventFlagsGetName(osEventFlagsId_t ef_id)
{
- UNUSED(ef_id);
-
if (OS_INT_ACTIVE) {
- return (const char *)NULL;
+ return NULL;
}
-
- return (const char *)NULL;
+ return NULL;
}
-
uint32_t osEventFlagsSet(osEventFlagsId_t ef_id, uint32_t flags)
{
PEVENT_CB_S pstEventCB = (PEVENT_CB_S)ef_id;
- UINT32 uwRet;
+ UINT32 ret;
uint32_t rflags;
+
if (pstEventCB == NULL) {
return osFlagsErrorParameter;
}
- uwRet = LOS_EventWrite(pstEventCB, (UINT32)flags);
- if (uwRet != LOS_OK) {
- return (uint32_t)osFlagsErrorParameter;
- } else {
+
+ ret = LOS_EventWrite(pstEventCB, (UINT32)flags);
+ if (ret == LOS_OK) {
rflags = pstEventCB->uwEventID;
return rflags;
+ } else {
+ return (uint32_t)osFlagsErrorResource;
}
}
-
uint32_t osEventFlagsClear(osEventFlagsId_t ef_id, uint32_t flags)
{
PEVENT_CB_S pstEventCB = (PEVENT_CB_S)ef_id;
UINT32 intSave;
uint32_t rflags;
- UINT32 uwRet;
+ UINT32 ret;
if (pstEventCB == NULL) {
return (uint32_t)osFlagsErrorParameter;
@@ -922,16 +880,15 @@ uint32_t osEventFlagsClear(osEventFlagsId_t ef_id, uint32_t flags)
intSave = LOS_IntLock();
rflags = pstEventCB->uwEventID;
- uwRet = LOS_EventClear(pstEventCB, ~flags);
+ ret = LOS_EventClear(pstEventCB, ~flags);
LOS_IntRestore(intSave);
- if (uwRet != LOS_OK) {
- return (uint32_t)osFlagsErrorParameter;
- } else {
+ if (ret == LOS_OK) {
return rflags;
+ } else {
+ return (uint32_t)osFlagsErrorResource;
}
}
-
uint32_t osEventFlagsGet(osEventFlagsId_t ef_id)
{
PEVENT_CB_S pstEventCB = (PEVENT_CB_S)ef_id;
@@ -952,35 +909,39 @@ uint32_t osEventFlagsGet(osEventFlagsId_t ef_id)
uint32_t osEventFlagsWait(osEventFlagsId_t ef_id, uint32_t flags, uint32_t options, uint32_t timeout)
{
PEVENT_CB_S pstEventCB = (PEVENT_CB_S)ef_id;
- UINT32 uwMode = 0;
- UINT32 uwRet;
+ UINT32 mode = 0;
+ UINT32 ret;
uint32_t rflags;
+ if (OS_INT_ACTIVE && (timeout != 0)) {
+ return (uint32_t)osFlagsErrorParameter;
+ }
+
if (options > (osFlagsWaitAny | osFlagsWaitAll | osFlagsNoClear)) {
return (uint32_t)osFlagsErrorParameter;
}
if ((options & osFlagsWaitAll) == osFlagsWaitAll) {
- uwMode |= LOS_WAITMODE_AND;
+ mode |= LOS_WAITMODE_AND;
} else {
- uwMode |= LOS_WAITMODE_OR;
+ mode |= LOS_WAITMODE_OR;
}
if ((options & osFlagsNoClear) == osFlagsNoClear) {
- uwMode &= ~LOS_WAITMODE_CLR;
+ mode &= ~LOS_WAITMODE_CLR;
} else {
- uwMode |= LOS_WAITMODE_CLR;
+ mode |= LOS_WAITMODE_CLR;
}
- uwRet = LOS_EventRead(pstEventCB, (UINT32)flags, uwMode, (UINT32)timeout);
- switch (uwRet) {
+ ret = LOS_EventRead(pstEventCB, (UINT32)flags, mode, (UINT32)timeout);
+ switch (ret) {
case LOS_ERRNO_EVENT_PTR_NULL:
case LOS_ERRNO_EVENT_EVENTMASK_INVALID:
+ case LOS_ERRNO_EVENT_FLAGS_INVALID:
case LOS_ERRNO_EVENT_SETBIT_INVALID:
return (uint32_t)osFlagsErrorParameter;
case LOS_ERRNO_EVENT_READ_IN_INTERRUPT:
- case LOS_ERRNO_EVENT_FLAGS_INVALID:
case LOS_ERRNO_EVENT_READ_IN_LOCK:
return (uint32_t)osFlagsErrorResource;
@@ -988,7 +949,7 @@ uint32_t osEventFlagsWait(osEventFlagsId_t ef_id, uint32_t flags, uint32_t optio
return (uint32_t)osFlagsErrorTimeout;
default:
- rflags = (uint32_t)uwRet;
+ rflags = (uint32_t)ret;
return rflags;
}
}
@@ -997,31 +958,33 @@ osStatus_t osEventFlagsDelete(osEventFlagsId_t ef_id)
{
PEVENT_CB_S pstEventCB = (PEVENT_CB_S)ef_id;
UINT32 intSave;
- osStatus_t uwRet;
-
+ osStatus_t ret;
+ if (OS_INT_ACTIVE) {
+ return osErrorISR;
+ }
intSave = LOS_IntLock();
if (LOS_EventDestroy(pstEventCB) == LOS_OK) {
- uwRet = osOK;
+ ret = osOK;
} else {
- uwRet = osErrorParameter;
+ ret = osErrorParameter;
}
LOS_IntRestore(intSave);
if (LOS_MemFree(m_aucSysMem0, (void *)pstEventCB) == LOS_OK) {
- uwRet = osOK;
+ ret = osOK;
} else {
- uwRet = osErrorParameter;
+ ret = osErrorParameter;
}
- return uwRet;
+ return ret;
}
// ==== Mutex Management Functions ====
#if (LOSCFG_BASE_IPC_MUX == 1)
osMutexId_t osMutexNew(const osMutexAttr_t *attr)
{
- UINT32 uwRet;
- UINT32 uwMuxId;
+ UINT32 ret;
+ UINT32 muxId;
UNUSED(attr);
@@ -1029,61 +992,64 @@ osMutexId_t osMutexNew(const osMutexAttr_t *attr)
return NULL;
}
- uwRet = LOS_MuxCreate(&uwMuxId);
- if (uwRet == LOS_OK) {
- return (osMutexId_t)(GET_MUX(uwMuxId));
+ ret = LOS_MuxCreate(&muxId);
+ if (ret == LOS_OK) {
+ return (osMutexId_t)(GET_MUX(muxId));
} else {
return (osMutexId_t)NULL;
}
}
-
osStatus_t osMutexAcquire(osMutexId_t mutex_id, uint32_t timeout)
{
- UINT32 uwRet;
+ LosMuxCB *muxCB = (LosMuxCB *)mutex_id;
+ UINT32 ret;
- if (mutex_id == NULL) {
+ if (muxCB == NULL) {
return osErrorParameter;
}
-
- if (OS_INT_ACTIVE && (timeout != LOS_NO_WAIT)) {
- timeout = 0;
+ if (OS_INT_ACTIVE) {
+ return osErrorISR;
}
- uwRet = LOS_MuxPend(((LosMuxCB *)mutex_id)->muxID, timeout);
- if (uwRet == LOS_OK) {
+ ret = LOS_MuxPend(muxCB->muxID, timeout);
+ if (ret == LOS_OK) {
return osOK;
- } else if (uwRet == LOS_ERRNO_MUX_TIMEOUT) {
- return osErrorTimeout;
- } else if (uwRet == LOS_ERRNO_MUX_INVALID) {
+ } else if (ret == LOS_ERRNO_MUX_INVALID) {
return osErrorParameter;
+ } else if (ret == LOS_ERRNO_MUX_TIMEOUT) {
+ return osErrorTimeout;
} else {
return osErrorResource;
}
}
-
osStatus_t osMutexRelease(osMutexId_t mutex_id)
{
- UINT32 uwRet;
+ LosMuxCB *muxCB = (LosMuxCB *)mutex_id;
+ UINT32 ret;
- if (mutex_id == NULL) {
+ if (muxCB == NULL) {
return osErrorParameter;
}
+ if (OS_INT_ACTIVE) {
+ return osErrorISR;
+ }
- uwRet = LOS_MuxPost(((LosMuxCB *)mutex_id)->muxID);
- if (uwRet == LOS_OK) {
+ ret = LOS_MuxPost(muxCB->muxID);
+ if (ret == LOS_OK) {
return osOK;
+ } else if (ret == LOS_ERRNO_MUX_INVALID) {
+ return osErrorParameter;
} else {
return osErrorResource;
}
}
-
osThreadId_t osMutexGetOwner(osMutexId_t mutex_id)
{
UINT32 intSave;
- LosTaskCB *pstTaskCB;
+ LosTaskCB *pstTaskCB = NULL;
if (OS_INT_ACTIVE) {
return NULL;
@@ -1100,10 +1066,9 @@ osThreadId_t osMutexGetOwner(osMutexId_t mutex_id)
return (osThreadId_t)pstTaskCB;
}
-
osStatus_t osMutexDelete(osMutexId_t mutex_id)
{
- UINT32 uwRet;
+ UINT32 ret;
if (OS_INT_ACTIVE) {
return osErrorISR;
@@ -1113,10 +1078,10 @@ osStatus_t osMutexDelete(osMutexId_t mutex_id)
return osErrorParameter;
}
- uwRet = LOS_MuxDelete(((LosMuxCB *)mutex_id)->muxID);
- if (uwRet == LOS_OK) {
+ ret = LOS_MuxDelete(((LosMuxCB *)mutex_id)->muxID);
+ if (ret == LOS_OK) {
return osOK;
- } else if (uwRet == LOS_ERRNO_MUX_INVALID) {
+ } else if (ret == LOS_ERRNO_MUX_INVALID) {
return osErrorParameter;
} else {
return osErrorResource;
@@ -1126,105 +1091,100 @@ osStatus_t osMutexDelete(osMutexId_t mutex_id)
// ==== Semaphore Management Functions ====
#if (LOSCFG_BASE_IPC_SEM == 1)
-
osSemaphoreId_t osSemaphoreNew(uint32_t max_count, uint32_t initial_count, const osSemaphoreAttr_t *attr)
{
- UINT32 uwRet = LOS_NOK;
- UINT32 uwSemId;
- UINT32 intSave;
+ UINT32 ret;
+ UINT32 semId;
UNUSED(attr);
- if (OS_INT_ACTIVE) {
- return (osSemaphoreId_t)NULL;
+ if ((initial_count > max_count) || (max_count > OS_SEM_COUNTING_MAX_COUNT) || (max_count == 0) || OS_INT_ACTIVE) {
+ return NULL;
}
- if (max_count > 0 && max_count <= OS_SEM_COUNTING_MAX_COUNT) {
- uwRet = LOS_SemCreate((UINT16)initial_count, &uwSemId);
+ if (max_count == 1) {
+ ret = LOS_BinarySemCreate((UINT16)initial_count, &semId);
+ } else {
+ ret = LOS_SemCreate((UINT16)initial_count, &semId);
}
- if (uwRet == LOS_OK) {
- osSemaphoreId_t semaphore_id = (osSemaphoreId_t)(GET_SEM(uwSemId));
- intSave = LOS_IntLock();
- ((LosSemCB *)semaphore_id)->maxSemCount = max_count;
- LOS_IntRestore(intSave);
- return semaphore_id;
+ if (ret == LOS_OK) {
+ return (osSemaphoreId_t)(GET_SEM(semId));
} else {
return (osSemaphoreId_t)NULL;
}
}
+const char *osSemaphoreGetName(osSemaphoreId_t semaphore_id)
+{
+ UNUSED(semaphore_id);
+ return NULL;
+}
osStatus_t osSemaphoreAcquire(osSemaphoreId_t semaphore_id, uint32_t timeout)
{
- UINT32 uwRet;
+ LosSemCB *semCB = (LosSemCB *)semaphore_id;
+ UINT32 ret;
- if (semaphore_id == NULL) {
+ if ((semCB == NULL) || (OS_INT_ACTIVE && (timeout != 0))) {
return osErrorParameter;
}
- if (OS_INT_ACTIVE && (timeout != LOS_NO_WAIT)) {
- return osErrorISR;
- }
-
- uwRet = LOS_SemPend(((LosSemCB *)semaphore_id)->semID, timeout);
- if (uwRet == LOS_OK) {
+ ret = LOS_SemPend(semCB->semID, timeout);
+ if (ret == LOS_OK) {
return osOK;
- } else if (uwRet == LOS_ERRNO_SEM_TIMEOUT) {
- return osErrorTimeout;
- } else if (uwRet == LOS_ERRNO_SEM_INVALID) {
+ } else if (ret == LOS_ERRNO_SEM_INVALID) {
return osErrorParameter;
- } else if (uwRet == LOS_ERRNO_SEM_PEND_INTERR) {
- return osErrorISR;
+ } else if (ret == LOS_ERRNO_SEM_TIMEOUT) {
+ return osErrorTimeout;
} else {
return osErrorResource;
}
}
-
osStatus_t osSemaphoreRelease(osSemaphoreId_t semaphore_id)
{
- UINT32 uwRet;
+ UINT32 ret;
if (semaphore_id == NULL) {
return osErrorParameter;
}
- uwRet = LOS_SemPost(((LosSemCB *)semaphore_id)->semID);
- if (uwRet == LOS_OK) {
+ ret = LOS_SemPost(((LosSemCB *)semaphore_id)->semID);
+ if (ret == LOS_OK) {
return osOK;
- } else if (uwRet == LOS_ERRNO_SEM_INVALID) {
+ } else if (ret == LOS_ERRNO_SEM_INVALID) {
return osErrorParameter;
} else {
return osErrorResource;
}
}
-
uint32_t osSemaphoreGetCount(osSemaphoreId_t semaphore_id)
{
+ LosSemCB *semCB = (LosSemCB *)semaphore_id;
UINT32 intSave;
- UINT32 uwCount;
+ UINT16 count;
- if (OS_INT_ACTIVE) {
- return 0;
- }
-
- if (semaphore_id == NULL) {
+ if (semCB == NULL) {
return 0;
}
intSave = LOS_IntLock();
- uwCount = ((LosSemCB *)semaphore_id)->semCount;
+ if (semCB->semStat == 0) {
+ LOS_IntRestore(intSave);
+ return 0;
+ }
+
+ count = semCB->semCount;
LOS_IntRestore(intSave);
- return uwCount;
+ return (uint32_t)count;
}
-
osStatus_t osSemaphoreDelete(osSemaphoreId_t semaphore_id)
{
- UINT32 uwRet;
+ UINT32 ret;
if (OS_INT_ACTIVE) {
return osErrorISR;
@@ -1234,10 +1194,10 @@ osStatus_t osSemaphoreDelete(osSemaphoreId_t semaphore_id)
return osErrorParameter;
}
- uwRet = LOS_SemDelete(((LosSemCB *)semaphore_id)->semID);
- if (uwRet == LOS_OK) {
+ ret = LOS_SemDelete(((LosSemCB *)semaphore_id)->semID);
+ if (ret == LOS_OK) {
return osOK;
- } else if (uwRet == LOS_ERRNO_SEM_INVALID) {
+ } else if (ret == LOS_ERRNO_SEM_INVALID) {
return osErrorParameter;
} else {
return osErrorResource;
@@ -1245,23 +1205,29 @@ osStatus_t osSemaphoreDelete(osSemaphoreId_t semaphore_id)
}
#endif
-
// ==== Message Queue Management Functions ====
#if (LOSCFG_BASE_IPC_QUEUE == 1)
+typedef enum {
+ ATTR_CAPACITY = 0,
+ ATTR_MSGSIZE = 1,
+ ATTR_COUNT = 2,
+ ATTR_SPACE = 3
+} QueueAttribute;
+
osMessageQueueId_t osMessageQueueNew(uint32_t msg_count, uint32_t msg_size, const osMessageQueueAttr_t *attr)
{
- UINT32 uwQueueID;
- UINT32 uwRet;
+ UINT32 queueId;
+ UINT32 ret;
UNUSED(attr);
osMessageQueueId_t handle;
- if (0 == msg_count || 0 == msg_size || OS_INT_ACTIVE) {
+ if ((msg_count == 0) || (msg_size == 0) || OS_INT_ACTIVE) {
return (osMessageQueueId_t)NULL;
}
- uwRet = LOS_QueueCreate((char *)NULL, (UINT16)msg_count, &uwQueueID, 0, (UINT16)msg_size);
- if (uwRet == LOS_OK) {
- handle = (osMessageQueueId_t)(GET_QUEUE_HANDLE(uwQueueID));
+ ret = LOS_QueueCreate((char *)NULL, (UINT16)msg_count, &queueId, 0, (UINT16)msg_size);
+ if (ret == LOS_OK) {
+ handle = (osMessageQueueId_t)(GET_QUEUE_HANDLE(queueId));
} else {
handle = (osMessageQueueId_t)NULL;
}
@@ -1269,124 +1235,103 @@ osMessageQueueId_t osMessageQueueNew(uint32_t msg_count, uint32_t msg_size, cons
return handle;
}
+STATIC osStatus_t osMessageQueueOp(osMessageQueueId_t mq_id, VOID *msg_ptr, UINT32 timeout, QueueReadWrite rw)
+{
+ LosQueueCB *queueCB = (LosQueueCB *)mq_id;
+ UINT32 ret;
+ UINT32 bufferSize;
+
+ if ((queueCB == NULL) || (msg_ptr == NULL) || (OS_INT_ACTIVE && (timeout != 0))) {
+ return osErrorParameter;
+ }
+
+ bufferSize = (UINT32)(queueCB->queueSize - sizeof(UINT32));
+ if (rw == OS_QUEUE_WRITE) {
+ ret = LOS_QueueWriteCopy(queueCB->queueID, msg_ptr, bufferSize, timeout);
+ } else {
+ ret = LOS_QueueReadCopy(queueCB->queueID, msg_ptr, &bufferSize, timeout);
+ }
+
+ if (ret == LOS_OK) {
+ return osOK;
+ } else if ((ret == LOS_ERRNO_QUEUE_INVALID) || (ret == LOS_ERRNO_QUEUE_NOT_CREATE)) {
+ return osErrorParameter;
+ } else if (ret == LOS_ERRNO_QUEUE_TIMEOUT) {
+ return osErrorTimeout;
+ } else {
+ return osErrorResource;
+ }
+}
osStatus_t osMessageQueuePut(osMessageQueueId_t mq_id, const void *msg_ptr, uint8_t msg_prio, uint32_t timeout)
{
UNUSED(msg_prio);
- UINT32 uwRet;
- UINT32 uwBufferSize;
- LosQueueCB *pstQueue = (LosQueueCB *)mq_id;
-
- if (pstQueue == NULL || msg_ptr == NULL || ((OS_INT_ACTIVE) && (0 != timeout))) {
- return osErrorParameter;
- }
- if (pstQueue->queueSize < sizeof(UINT32)) {
- return osErrorParameter;
- }
- uwBufferSize = (UINT32)(pstQueue->queueSize - sizeof(UINT32));
- uwRet = LOS_QueueWriteCopy((UINT32)pstQueue->queueID, (void *)msg_ptr, uwBufferSize, timeout);
- if (uwRet == LOS_OK) {
- return osOK;
- } else if (uwRet == LOS_ERRNO_QUEUE_INVALID || uwRet == LOS_ERRNO_QUEUE_NOT_CREATE) {
- return osErrorParameter;
- } else if (uwRet == LOS_ERRNO_QUEUE_TIMEOUT) {
- return osErrorTimeout;
- } else {
- return osErrorResource;
- }
+ return osMessageQueueOp(mq_id, (VOID *)msg_ptr, (UINT32)timeout, OS_QUEUE_WRITE);
}
-
osStatus_t osMessageQueueGet(osMessageQueueId_t mq_id, void *msg_ptr, uint8_t *msg_prio, uint32_t timeout)
{
UNUSED(msg_prio);
- UINT32 uwRet;
- UINT32 uwBufferSize;
- LosQueueCB *pstQueue = (LosQueueCB *)mq_id;
+ return osMessageQueueOp(mq_id, (VOID *)msg_ptr, (UINT32)timeout, OS_QUEUE_READ);
+}
- if (pstQueue == NULL || msg_ptr == NULL || ((OS_INT_ACTIVE) && (0 != timeout))) {
- return osErrorParameter;
+STATIC UINT16 osMessageQueueGetAttr(osMessageQueueId_t mq_id, QueueAttribute attr)
+{
+ LosQueueCB *queueCB = (LosQueueCB *)mq_id;
+ UINT16 attrVal = 0;
+
+ if (queueCB == NULL) {
+ return 0;
}
- uwBufferSize = (UINT32)(pstQueue->queueSize - sizeof(UINT32));
- uwRet = LOS_QueueReadCopy((UINT32)pstQueue->queueID, msg_ptr, &uwBufferSize, timeout);
- if (uwRet == LOS_OK) {
- return osOK;
- } else if (uwRet == LOS_ERRNO_QUEUE_INVALID || uwRet == LOS_ERRNO_QUEUE_NOT_CREATE) {
- return osErrorParameter;
- } else if (uwRet == LOS_ERRNO_QUEUE_TIMEOUT) {
- return osErrorTimeout;
- } else {
- return osErrorResource;
+ if (queueCB->queueState == OS_QUEUE_UNUSED) {
+ return 0;
}
+
+ switch (attr) {
+ case ATTR_CAPACITY:
+ attrVal = queueCB->queueLen;
+ break;
+ case ATTR_MSGSIZE:
+ attrVal = queueCB->queueSize - sizeof(UINT32);
+ break;
+ case ATTR_COUNT:
+ attrVal = queueCB->readWriteableCnt[OS_QUEUE_READ];
+ break;
+ case ATTR_SPACE:
+ attrVal = queueCB->readWriteableCnt[OS_QUEUE_WRITE];
+ break;
+ default:
+ break;
+ }
+
+ return attrVal;
}
uint32_t osMessageQueueGetCapacity(osMessageQueueId_t mq_id)
{
- uint32_t capacity;
- LosQueueCB *pstQueue = (LosQueueCB *)mq_id;
-
- if (pstQueue == NULL) {
- capacity = 0U;
- } else {
- capacity = pstQueue->queueLen;
- }
-
- return (capacity);
+ return (uint32_t)osMessageQueueGetAttr(mq_id, ATTR_CAPACITY);
}
uint32_t osMessageQueueGetMsgSize(osMessageQueueId_t mq_id)
{
- uint32_t size;
- LosQueueCB *pstQueue = (LosQueueCB *)mq_id;
-
- if (pstQueue == NULL) {
- size = 0U;
- } else {
- size = pstQueue->queueSize - sizeof(UINT32);
- }
-
- return (size);
+ return (uint32_t)osMessageQueueGetAttr(mq_id, ATTR_MSGSIZE);
}
-
uint32_t osMessageQueueGetCount(osMessageQueueId_t mq_id)
{
- uint32_t count;
- UINT32 intSave;
- LosQueueCB *pstQueue = (LosQueueCB *)mq_id;
-
- if (pstQueue == NULL) {
- count = 0U;
- } else {
- intSave = LOS_IntLock();
- count = (uint32_t)(pstQueue->readWriteableCnt[OS_QUEUE_READ]);
- LOS_IntRestore(intSave);
- }
- return count;
+ return (uint32_t)osMessageQueueGetAttr(mq_id, ATTR_COUNT);
}
-
uint32_t osMessageQueueGetSpace(osMessageQueueId_t mq_id)
{
- uint32_t space;
- UINT32 intSave;
- LosQueueCB *pstQueue = (LosQueueCB *)mq_id;
-
- if (pstQueue == NULL) {
- space = 0U;
- } else {
- intSave = LOS_IntLock();
- space = (uint32_t)pstQueue->readWriteableCnt[OS_QUEUE_WRITE];
- LOS_IntRestore(intSave);
- }
- return space;
+ return (uint32_t)osMessageQueueGetAttr(mq_id, ATTR_SPACE);
}
osStatus_t osMessageQueueDelete(osMessageQueueId_t mq_id)
{
LosQueueCB *pstQueue = (LosQueueCB *)mq_id;
- UINT32 uwRet;
+ UINT32 ret;
if (pstQueue == NULL) {
return osErrorParameter;
@@ -1396,17 +1341,22 @@ osStatus_t osMessageQueueDelete(osMessageQueueId_t mq_id)
return osErrorISR;
}
- uwRet = LOS_QueueDelete((UINT32)pstQueue->queueID);
- if (uwRet == LOS_OK) {
+ ret = LOS_QueueDelete((UINT32)pstQueue->queueID);
+ if (ret == LOS_OK) {
return osOK;
- } else if (uwRet == LOS_ERRNO_QUEUE_NOT_FOUND || uwRet == LOS_ERRNO_QUEUE_NOT_CREATE) {
+ } else if (ret == LOS_ERRNO_QUEUE_NOT_FOUND || ret == LOS_ERRNO_QUEUE_NOT_CREATE) {
return osErrorParameter;
} else {
return osErrorResource;
}
}
-#endif
+const char *osMessageQueueGetName(osMessageQueueId_t mq_id)
+{
+ UNUSED(mq_id);
+ return NULL;
+}
+#endif
#define MP_ALLOC 1U
#define MD_ALLOC 2U
@@ -1459,20 +1409,27 @@ osMemoryPoolId_t osMemoryPoolNew(uint32_t block_count, uint32_t block_size, cons
return NULL;
}
mp->status = MP_ALLOC;
- } else {
+ } else if ((attr != NULL) && (attr->cb_mem != NULL)) {
mp = attr->cb_mem;
mp->status = 0;
+ } else {
+ return NULL;
}
if (memMP == 0) {
mp->poolBase = LOS_MemAlloc(OS_SYS_MEM_ADDR, size);
- if (mp->poolBase == NULL) {
+ if ((mp->poolBase == NULL) && (mp->status & MP_ALLOC)) {
(void)LOS_MemFree(OS_SYS_MEM_ADDR, mp);
return NULL;
}
mp->status |= MD_ALLOC;
- } else {
+ } else if ((attr != NULL) && (attr->mp_mem != NULL)) {
mp->poolBase = attr->mp_mem;
+ } else {
+ if (mp->status & MP_ALLOC) {
+ (void)LOS_MemFree(OS_SYS_MEM_ADDR, mp);
+ }
+ return NULL;
}
mp->poolSize = size;
mp->name = name;
@@ -1698,32 +1655,25 @@ const char *osMemoryPoolGetName(osMemoryPoolId_t mp_id)
// ==== Thread Flags Functions ====
uint32_t osThreadFlagsSet(osThreadId_t thread_id, uint32_t flags)
{
- UINT32 ret;
LosTaskCB *taskCB = (LosTaskCB *)thread_id;
+ UINT32 ret;
EVENT_CB_S *eventCB = NULL;
- UINT32 curFlags;
+ UINT32 eventSave;
if (taskCB == NULL) {
return (uint32_t)osFlagsErrorParameter;
}
eventCB = &(taskCB->event);
- curFlags = eventCB->uwEventID | flags;
-
+ eventSave = eventCB->uwEventID;
ret = LOS_EventWrite(eventCB, (UINT32)flags);
- if (ret == LOS_ERRNO_EVENT_SETBIT_INVALID) {
+ if (ret == LOS_OK) {
+ return ((uint32_t)eventSave | flags);
+ } else if (ret == LOS_ERRNO_EVENT_SETBIT_INVALID) {
return (uint32_t)osFlagsErrorParameter;
- }
-
- if (ret != LOS_OK) {
+ } else {
return (uint32_t)osFlagsErrorResource;
}
-
- if (curFlags & taskCB->eventMask) {
- return curFlags & (~taskCB->eventMask);
- }
-
- return curFlags;
}
uint32_t osThreadFlagsClear(uint32_t flags)
diff --git a/kal/libc/musl/BUILD.gn b/kal/libc/musl/BUILD.gn
index 97e6038e..27c0cc57 100644
--- a/kal/libc/musl/BUILD.gn
+++ b/kal/libc/musl/BUILD.gn
@@ -28,6 +28,7 @@
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import("//kernel/liteos_m/liteos.gni")
+import("//third_party/musl/porting/liteos_m/kernel/musl.gni")
module_switch = defined(LOSCFG_LIBC_MUSL)
module_name = get_path_info(rebase_path("."), "name")
@@ -43,5 +44,5 @@ kernel_module(module_name) {
}
config("public") {
- include_dirs = [ "//third_party/musl/porting/liteos_m/kernel/include" ]
+ include_dirs = MUSL_INCLUDE_DIRS
}
diff --git a/kal/libc/newlib/BUILD.gn b/kal/libc/newlib/BUILD.gn
index 99d28da7..27639840 100644
--- a/kal/libc/newlib/BUILD.gn
+++ b/kal/libc/newlib/BUILD.gn
@@ -37,6 +37,7 @@ kernel_module(module_name) {
"porting/src/malloc.c",
"porting/src/network/htonl.c",
"porting/src/network/htons.c",
+ "porting/src/network/ntohl.c",
"porting/src/network/ntohs.c",
"porting/src/other_adapt.c",
"porting/src/time.c",
diff --git a/kal/libc/newlib/porting/include/sys/select.h b/kal/libc/newlib/porting/include/sys/select.h
new file mode 100644
index 00000000..e5197a4c
--- /dev/null
+++ b/kal/libc/newlib/porting/include/sys/select.h
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2021-2021 Huawei Device Co., Ltd. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its contributors may be used
+ * to endorse or promote products derived from this software without specific prior written
+ * permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _ADAPT_SYS_SELECT_H
+#define _ADAPT_SYS_SELECT_H
+
+#ifdef LOSCFG_FS_VFS
+#include "vfs_config.h"
+
+#undef FD_SETSIZE
+#define FD_SETSIZE TIMER_FD_OFFSET
+
+#else
+
+#undef FD_SETSIZE
+#define FD_SETSIZE 1024
+
+#endif
+
+#include_next
+
+#endif //_ADAPT_SYS_SELECT_H
diff --git a/kal/libc/newlib/porting/src/network/ntohl.c b/kal/libc/newlib/porting/src/network/ntohl.c
new file mode 100644
index 00000000..cdee459b
--- /dev/null
+++ b/kal/libc/newlib/porting/src/network/ntohl.c
@@ -0,0 +1,38 @@
+/*
+ * 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
+#include
+
+uint32_t ntohl(uint32_t n)
+{
+ union { int i; char c; } u = { 1 };
+ return u.c ? bswap_32(n) : n;
+}
diff --git a/kal/posix/Kconfig b/kal/posix/Kconfig
index dcf32c15..73571f9e 100644
--- a/kal/posix/Kconfig
+++ b/kal/posix/Kconfig
@@ -62,13 +62,13 @@ config POSIX_MQUEUE_API
config POSIX_PIPE_API
bool "Enable POSIX Pipe API"
- default n
+ default y
help
Answer Y to enable LiteOS support POSIX Pipe API.
config POSIX_SIGNAL_API
bool "Enable POSIX Signal API"
- default n
+ default y
depends on KERNEL_SIGNAL
help
Answer Y to enable LiteOS support POSIX Signal API.
diff --git a/kal/posix/src/pipe.c b/kal/posix/src/pipe.c
index 845b5450..0aa10a8d 100644
--- a/kal/posix/src/pipe.c
+++ b/kal/posix/src/pipe.c
@@ -28,7 +28,7 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#include
+#include
#include
#include "securec.h"
#include "los_fs.h"
diff --git a/kal/posix/src/signal.c b/kal/posix/src/signal.c
index dd8dc1f2..1cc402c4 100644
--- a/kal/posix/src/signal.c
+++ b/kal/posix/src/signal.c
@@ -77,60 +77,6 @@ void (*signal(int sig, void (*func)(int)))(int)
return h;
}
-int sigemptyset(sigset_t *set)
-{
- if (set == NULL) {
- errno = EINVAL;
- return -1;
- }
-
- *set = 0;
- return 0;
-}
-
-int sigfillset(sigset_t *set)
-{
- if (set == NULL) {
- errno = EINVAL;
- return -1;
- }
-
- *set = ~0;
- return 0;
-}
-
-int sigaddset(sigset_t *set, int sig)
-{
- if ((set == NULL) || !OS_SIGNAL_VALID(sig)) {
- errno = EINVAL;
- return -1;
- }
-
- *set |= LOS_SIGNAL_MASK(sig);
- return 0;
-}
-
-int sigdelset(sigset_t *set, int sig)
-{
- if ((set == NULL) || !OS_SIGNAL_VALID(sig)) {
- errno = EINVAL;
- return -1;
- }
-
- *set &= ~LOS_SIGNAL_MASK(sig);
- return 0;
-}
-
-int sigismember(const sigset_t *set, int sig)
-{
- if ((set == NULL) || !OS_SIGNAL_VALID(sig)) {
- errno = EINVAL;
- return -1;
- }
-
- return ((*set & LOS_SIGNAL_MASK(sig)) != 0);
-}
-
int sigprocmask(int how, const sigset_t *set, sigset_t *oset)
{
unsigned int ret = LOS_SignalMask(how, set, oset);
diff --git a/testsuites/BUILD.gn b/testsuites/BUILD.gn
index dad5f6c8..a2aaf305 100644
--- a/testsuites/BUILD.gn
+++ b/testsuites/BUILD.gn
@@ -31,12 +31,7 @@ import("//kernel/liteos_m/liteos.gni")
config("include") {
defines = []
- include_dirs = [
- "include",
- "//kernel/liteos_m/kernel/include",
- "//kernel/liteos_m/kernel/arch/include",
- "//kernel/liteos_m/components/cpup",
- ]
+ include_dirs = [ "include" ]
if (defined(LOSCFG_KERNEL_TEST_FULL)) {
defines += [ "LOS_KERNEL_TEST_FULL=1" ]
diff --git a/testsuites/sample/kernel/atomic/it_los_atomic_005.c b/testsuites/sample/kernel/atomic/it_los_atomic_005.c
index 0402a1eb..f00a1e50 100644
--- a/testsuites/sample/kernel/atomic/it_los_atomic_005.c
+++ b/testsuites/sample/kernel/atomic/it_los_atomic_005.c
@@ -42,35 +42,35 @@ static UINT32 TestCase(VOID)
{
volatile INT64 value = 0;
UINT64 ret;
- UINT64 uwNewVal;
+ UINT64 newVal;
- uwNewVal = 0xff;
- ret = LOS_AtomicXchg64bits(&value, uwNewVal);
+ newVal = 0xff;
+ ret = LOS_AtomicXchg64bits(&value, newVal);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
ICUNIT_ASSERT_EQUAL(value, 0xff, value);
- uwNewVal = 0xffff;
- ret = LOS_AtomicXchg64bits(&value, uwNewVal);
+ newVal = 0xffff;
+ ret = LOS_AtomicXchg64bits(&value, newVal);
ICUNIT_ASSERT_EQUAL(ret, 0xff, ret);
ICUNIT_ASSERT_EQUAL(value, 0xffff, value);
- uwNewVal = 0xffffff;
- ret = LOS_AtomicXchg64bits(&value, uwNewVal);
+ newVal = 0xffffff;
+ ret = LOS_AtomicXchg64bits(&value, newVal);
ICUNIT_ASSERT_EQUAL(ret, 0xffff, ret);
ICUNIT_ASSERT_EQUAL(value, 0xffffff, value);
- uwNewVal = 0xffffffff;
- ret = LOS_AtomicXchg64bits(&value, uwNewVal);
+ newVal = 0xffffffff;
+ ret = LOS_AtomicXchg64bits(&value, newVal);
ICUNIT_ASSERT_EQUAL(ret, 0xffffff, ret);
ICUNIT_ASSERT_EQUAL(value, 0xffffffff, value);
- uwNewVal = 0xffffffffffff;
- ret = LOS_AtomicXchg64bits(&value, uwNewVal);
+ newVal = 0xffffffffffff;
+ ret = LOS_AtomicXchg64bits(&value, newVal);
ICUNIT_ASSERT_EQUAL(ret, 0xffffffff, ret);
ICUNIT_ASSERT_EQUAL(value, 0xffffffffffff, value);
- uwNewVal = 0xffffffffffffffff;
- ret = LOS_AtomicXchg64bits(&value, uwNewVal);
+ newVal = 0xffffffffffffffff;
+ ret = LOS_AtomicXchg64bits(&value, newVal);
ICUNIT_ASSERT_EQUAL(ret, 0xffffffffffff, ret);
ICUNIT_ASSERT_EQUAL(value, 0xffffffffffffffff, value);
diff --git a/testsuites/src/osTest.c b/testsuites/src/osTest.c
index feceee46..801c81ea 100644
--- a/testsuites/src/osTest.c
+++ b/testsuites/src/osTest.c
@@ -302,16 +302,12 @@ UINT64 LosCpuCycleGet(VOID)
#define HWI_BIT 2
VOID TestHwiTrigger(UINT32 hwiNum)
{
-#if defined(__CSKY_V2__) || defined(__XTENSA_LX6__)
- HalIrqPending(hwiNum);
-#else
- *(volatile UINT32 *)(OS_NVIC_SETPEND + ((hwiNum >> HWI_SHIFT_NUM) << HWI_BIT)) = 1 << (hwiNum & 0x1F);
-#endif
+ LOS_HwiTrigger(hwiNum);
}
VOID TestHwiUnTrigger(UINT32 hwiNum)
{
- *(volatile UINT32 *)(OS_NVIC_CLRPEND + ((hwiNum >> HWI_SHIFT_NUM) << HWI_BIT)) = 1 << (hwiNum & 0x1F);
+ LOS_HwiClear(hwiNum);
}
#define OS_NVIC_CLRENA_BASE 0xE000E180
#define NVIC_CLR_IRQ(uwHwiNum) \
diff --git a/testsuites/unittest/posix/src/common_test.h b/testsuites/unittest/posix/src/common_test.h
index 4744d7c2..a075f41b 100644
--- a/testsuites/unittest/posix/src/common_test.h
+++ b/testsuites/unittest/posix/src/common_test.h
@@ -29,8 +29,8 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#ifndef KERNEL_TEST_H
-#define KERNEL_TEST_H
+#ifndef COMMON_TEST_H
+#define COMMON_TEST_H
#define TESTCOUNT_NUM_1 1
#define TESTCOUNT_NUM_2 2
@@ -83,6 +83,14 @@
} \
} while (0)
+#define ICUNIT_ASSERT_NOT_EQUAL_VOID(param, value, retcode) \
+ do { \
+ if ((param) == (value)) { \
+ TEST_ASSERT_EQUAL(param, value); \
+ return; \
+ } \
+ } while (0)
+
#define ICUNIT_TRACK_EQUAL(param, value, retcode) \
do { \
if ((param) != (value)) { \
diff --git a/testsuites/unittest/posix/src/fs/posix_fs_func_test.c b/testsuites/unittest/posix/src/fs/posix_fs_func_test.c
index a641414b..0257303a 100644
--- a/testsuites/unittest/posix/src/fs/posix_fs_func_test.c
+++ b/testsuites/unittest/posix/src/fs/posix_fs_func_test.c
@@ -54,7 +54,7 @@
LITE_TEST_SUIT(Posix, PosixFs, PosixFsFuncTestSuite);
/* Corresponding to different platforms, only need to modify TEST_ROOT */
-#define TEST_ROOT "/ram"
+#define TEST_ROOT "/littlefs"
#define TEST_FILE_PTAH_RIGHT TEST_ROOT"/FILE0" /* file path, to open/rd/close */
@@ -1459,6 +1459,7 @@ LITE_TEST_CASE(PosixFsFuncTestSuite, testFsStat003, Function | MediumTest | Leve
ssize_t size;
char writeBuf[TEST_BUF_SIZE] = "write test";
+ (void)memset_s(&buf, sizeof(buf), 0, sizeof(buf));
fd = open(tmpFileName, O_CREAT | O_RDWR, 0777);
TEST_ASSERT_TRUE(ret != -1);
diff --git a/testsuites/unittest/posix/src/math/math_func_test.c b/testsuites/unittest/posix/src/math/math_func_test.c
index 98a78ffe..c752b706 100644
--- a/testsuites/unittest/posix/src/math/math_func_test.c
+++ b/testsuites/unittest/posix/src/math/math_func_test.c
@@ -276,8 +276,8 @@ LITE_TEST_CASE(PosixMathFuncTestSuite, testMathPow002, Function | MediumTest | L
LITE_TEST_CASE(PosixMathFuncTestSuite, testMathPow003, Function | MediumTest | Level1)
{
double testValues[][TEST_EXPECTED + 1] = {
- {0.0, -7, -HUGE_VAL},
- {-0.0, -6.22, -HUGE_VAL},
+ {0.0, -7, HUGE_VAL},
+ {-0.0, -6.22, HUGE_VAL},
{-7.23, 3.57, NAN},
{121223, 5674343, HUGE_VAL}
};
diff --git a/testsuites/unittest/posix/src/mqueue/mqueue_func_test.c b/testsuites/unittest/posix/src/mqueue/mqueue_func_test.c
index ec211f01..6dc684c1 100644
--- a/testsuites/unittest/posix/src/mqueue/mqueue_func_test.c
+++ b/testsuites/unittest/posix/src/mqueue/mqueue_func_test.c
@@ -34,8 +34,10 @@
#include
#include
#include "common_test.h"
+#include "kernel_test.h"
+#include "log.h"
-#define MQUEUE_STANDARD_NAME_LENGTH 50
+#define MQUEUE_STANDARD_NAME_LENGTH 52
#define MQUEUE_NO_ERROR 0
#define MQUEUE_SEND_STRING_TEST "mq_test"
#define MQUEUE_SHORT_ARRAY_LENGTH strlen(MQUEUE_SEND_STRING_TEST)
@@ -49,7 +51,7 @@ const int MQ_MAX_MSG = 16; // mqueue message number
const char MQ_MSG[] = "MessageToSend"; // mqueue message to send
const int MQ_MSG_LEN = sizeof(MQ_MSG); // mqueue message len to send
-const int MAX_MQ_NUMBER = 1024; // max mqueue number
+const int MAX_MQ_NUMBER = LOSCFG_BASE_IPC_QUEUE_LIMIT - 1; // max mqueue number
const int MAX_MQ_NAME_LEN = 256; // max mqueue name length
const int MAX_MQ_MSG_SIZE = 65530; // max mqueue message size
@@ -289,6 +291,7 @@ LITE_TEST_CASE(MqueueFuncTestSuite, testMqOpenENFILE, Function | MediumTest | Le
mqd_t queue[MAX_MQ_NUMBER + 1];
int flag = 0;
int i;
+ (void)memset_s(queue, sizeof(queue), 0, sizeof(queue));
for (i=0; i__tm_zone = "UTC+8";
ftime = strftime(buffer, 80, "%F %T %Z", tmTime);
- TEST_ASSERT_EQUAL_INT(0, ftime);
+ TEST_ASSERT_EQUAL_INT(20, ftime);
LOG("\nresult: %s, expected : %s", buffer, "1970-01-01 13:14:40");
};
@@ -546,7 +547,7 @@ RUN_TEST_SUITE(PosixTimeFuncTestSuite);
void PosixTimeFuncTest()
{
- LOG("begin PosixTimeFuncTest....");
+ LOG("begin PosixTimeFuncTest....\n");
RUN_ONE_TESTCASE(testTimeUSleep001);
RUN_ONE_TESTCASE(testTimeUSleep002);