diff --git a/arch/arm/arm9/gcc/los_arch_interrupt.h b/arch/arm/arm9/gcc/los_arch_interrupt.h index bf8a2272a57dab1b772e288793579c53a969158a..588cf60ba88a77a4fa61caa7b02995b7d8d8dc4e 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: - * - * @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 5fab22bc338505a62fd2595d8160adde0d816fe9..712e8445d00a16e0f8ef0d0aa927c2588d991ab9 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 2f0c67ea6e3d1f0637d4164f868918fc1b64c0dd..665a7a96ec523ad81e8ef5f0b6e6074098ff4937 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: - * - * @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 76bbe4effab9a3a6fb5209589d62837a8a576bb8..5ca320fb26becd9dd8c7e2dc0ba485bf6bcf7232 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 99c53032107dae998be4f005ae8391f6366ece0b..dd9a4f22a295ba48c30a523433c0b840e90fefde 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: - * - * @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 b908b3b57204590e79beb5ba2be751ea5c0ebf0f..4a3fbf7633b2963f922453b08da9e439e848d584 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 99c53032107dae998be4f005ae8391f6366ece0b..dd9a4f22a295ba48c30a523433c0b840e90fefde 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: - * - * @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 b908b3b57204590e79beb5ba2be751ea5c0ebf0f..b033c78615737dac0522344585708826ec836b3d 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 f7cab4fe2aceb7b10cc6223936797cd6d60a5abe..ae51bace7b3e5f522b90021e4763112449e0e360 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: - * - * @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 d0c08d3f8043a0c62f4d4257f2337ed32de3e8c7..1516d82ad96f6332b5ffac0b0b2ccce6821d65a1 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 f7cab4fe2aceb7b10cc6223936797cd6d60a5abe..ae51bace7b3e5f522b90021e4763112449e0e360 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: - * - * @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 d0c08d3f8043a0c62f4d4257f2337ed32de3e8c7..1516d82ad96f6332b5ffac0b0b2ccce6821d65a1 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 5ac9ecc01b517074e566bfd06463804a300b7e00..326b72f23ab47c830c27eb424165daab69f0bf0d 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: - * - * @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 e256fa8c78a4a80c98b95fffc11ae911892e66a1..d87516ce58075754ce561ec7fe99d14f4194e513 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 5ac9ecc01b517074e566bfd06463804a300b7e00..326b72f23ab47c830c27eb424165daab69f0bf0d 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: - * - * @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 ec94ed176c28924496ca0e3cdadbf4e004410131..8c071657ed71ca9a0b8e7eaae11c36e70b59bb78 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 2b21441c2c2146d02b26fad62f8860f9674da78a..7e8dde0eafafb2527c3935914e696a713761cdf8 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: - * - * @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 e2b7a30e3db91114cc01b01bd6321f13e8ed78c0..72e7d2ab03438fe5b394235d825ba215748417ec 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 2b21441c2c2146d02b26fad62f8860f9674da78a..7e8dde0eafafb2527c3935914e696a713761cdf8 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: - * - * @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 278b2bdcf8532fceaa0bd96de0eaa92edb08a8ab..2c0613f7d7df5b06c33223f9794c67b393f7a018 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 1cb4c3596583338d068050dab9e2cddaf4f26e1a..c9db621afc9f76321e6268c44446c8882d67b412 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: - * - * @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 c9280ca52252859db8da116314568d595ddd7309..43786da3963bdc564044db37b6a568b62d35ed91 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 06daa6cecc2b75ed7a53997c9afe16ad952b120d..a9208ef1238c5f80c3543b8afc32033aaf149d95 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 e5cddd622a98ef3950cd0dcc0622942e95289049..1644ace0b35f5b88393e7323a1931c8755295fa0 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 71bf22dbbd7552730b21b380caa5f5af21149557..8f6831e5459cb313108912664c1d14d94503fcb0 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 2237dd86f51d26dc18470d5d12cd5dcb8d8f4c67..3032cccc5e34dddeeb9d48a6b891ae35b0a59dcf 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 edcbe5b45bff317dc25c5b03bd300dfa1c98d6f7..5b1944fb44072b61aff51e8a189cd4cd2223f14a 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/testsuites/src/osTest.c b/testsuites/src/osTest.c index 05b580cb12b92e576c0d5c1ee47014c5dee67ec6..4b634cfaaaa82ce268d085fed8beccd3a20582a6 100644 --- a/testsuites/src/osTest.c +++ b/testsuites/src/osTest.c @@ -299,16 +299,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) \