From 4b73457bfbca4cdc97f921c8d22fdd1bdf3982fa Mon Sep 17 00:00:00 2001 From: Amine Chalandi Date: Fri, 4 Oct 2024 19:12:00 +0200 Subject: [PATCH] add new interrupt APIs --- Code/OSEK/HwPlatform/ARM/OsAsm.s | 20 +++++++++++ Code/OSEK/HwPlatform/ARM/OsHwPltfm.c | 53 +++++++++++++++++++++------- Code/OSEK/HwPlatform/ARM/OsHwPltfm.h | 3 +- Code/OSEK/OsCat2Int.c | 21 ++++++++++- Code/OSEK/OsTypes.h | 3 +- 5 files changed, 83 insertions(+), 17 deletions(-) diff --git a/Code/OSEK/HwPlatform/ARM/OsAsm.s b/Code/OSEK/HwPlatform/ARM/OsAsm.s index 54d8a53..2746e3d 100644 --- a/Code/OSEK/HwPlatform/ARM/OsAsm.s +++ b/Code/OSEK/HwPlatform/ARM/OsAsm.s @@ -262,7 +262,27 @@ OsGetSysBasepriReg: dsb bx lr +//----------------------------------------------------------------------------------------------------------------- +// \brief OsGetSysPrimaskReg : uint32 OsGetSysPrimaskReg(void) +// +// \descr get the system primask register +// +// \param void +// +// \return uint32 primask value +//----------------------------------------------------------------------------------------------------------------- +.thumb_func +.section ".text" +.align 4 +.globl OsGetSysPrimaskReg +.type OsGetSysPrimaskReg, % function + +OsGetSysPrimaskReg: + mrs r0, primask + isb + dsb + bx lr //----------------------------------------------------------------------------------------------------------------- diff --git a/Code/OSEK/HwPlatform/ARM/OsHwPltfm.c b/Code/OSEK/HwPlatform/ARM/OsHwPltfm.c index e8e6825..75228d3 100644 --- a/Code/OSEK/HwPlatform/ARM/OsHwPltfm.c +++ b/Code/OSEK/HwPlatform/ARM/OsHwPltfm.c @@ -7,17 +7,32 @@ // // Date : 27.12.2017 // -// Description : Hardware Platform definition for ARM Cortex-M4 +// Description : Hardware Platform definition for ARM Cortex-M33 // // ***************************************************************************** +//------------------------------------------------------------------------------------------------------------------ +// Includes +//------------------------------------------------------------------------------------------------------------------ #include"OsTypes.h" #include"OsHwPltfm.h" #include"OsInternal.h" #include"OsTcb.h" -#define USE_OS_PRIO -uint32 osRemapOsPriorityValue(uint32 level, uint32 IntPrioBit); +//------------------------------------------------------------------------------------------------------------------ +// Defines +//------------------------------------------------------------------------------------------------------------------ +#define OS_REMAP_ARM_INTERRUPT_PRIO + +//------------------------------------------------------------------------------------------------------------------ +// Static functions prototypes +//------------------------------------------------------------------------------------------------------------------ +static uint32 osRemapOsPriorityValue(uint32 level, uint32 IntPrioBit); + +//------------------------------------------------------------------------------------------------------------------ +// Globals +//------------------------------------------------------------------------------------------------------------------ +uint32 osSavedIntState = 0; //------------------------------------------------------------------------------------------------------------------ /// \brief OsIsInterruptContext @@ -164,12 +179,12 @@ uint32 osGetInterruptPriorityMask(void) /// /// \return void //------------------------------------------------------------------------------------------------------------------ -uint32 osRemapOsPriorityValue(uint32 level, uint32 IntPrioBit) +static uint32 osRemapOsPriorityValue(uint32 level, uint32 IntPrioBit) { -#ifdef USE_OS_PRIO +#ifdef OS_REMAP_ARM_INTERRUPT_PRIO /* note: remap the level prio: ARM is using lower value for highest prio contrary to the OS which uses lower value for lower prio */ - if(level > ((1ul << IntPrioBit) -1)) + if(level > ((1ul << IntPrioBit) - 1)) { level = (1ul << IntPrioBit) - 1; } @@ -190,19 +205,31 @@ uint32 osRemapOsPriorityValue(uint32 level, uint32 IntPrioBit) //------------------------------------------------------------------------------------------------------------------ void osSaveAndDisableIntState(void) { + osSavedIntState = OsGetSysPrimaskReg(); + DISABLE_INTERRUPTS(); } +//------------------------------------------------------------------------------------------------------------------ +/// \brief +/// +/// \descr +/// +/// \param void +/// +/// \return void +//------------------------------------------------------------------------------------------------------------------ void osRestoreSavedIntState(void) { + if(osSavedIntState) + { + DISABLE_INTERRUPTS(); + } + else + { + ENABLE_INTERRUPTS(); + } } -#if 0 -void OsRunCat2Isr(void) -{ - /* run ISR */ - CALL_ISR(SysTickTimer); -} -#endif //------------------------------------------------------------------------------------------------------------------ /// \brief osGetActiveInterruptVectorId /// diff --git a/Code/OSEK/HwPlatform/ARM/OsHwPltfm.h b/Code/OSEK/HwPlatform/ARM/OsHwPltfm.h index 70331c9..4a6c287 100644 --- a/Code/OSEK/HwPlatform/ARM/OsHwPltfm.h +++ b/Code/OSEK/HwPlatform/ARM/OsHwPltfm.h @@ -55,8 +55,7 @@ void OsCatchAllCpuExceptions(void); void OsIsr_SysTickTimerFunc(void); boolean OsIsInterruptContext(void); void osInitInterrupts(void); -//void osMaskNestedIntPrio(void); -//void osMaskNonNestedIntPrio(void); +uint32 OsGetSysPrimaskReg(void); void OsIsr_FeUndefinedFunc(void); void OsRunCat2Isr(void); #endif diff --git a/Code/OSEK/OsCat2Int.c b/Code/OSEK/OsCat2Int.c index 2f269a2..5fce209 100644 --- a/Code/OSEK/OsCat2Int.c +++ b/Code/OSEK/OsCat2Int.c @@ -62,6 +62,10 @@ //------------------------------------------------------------------------------------------------------------------ void OsIncNestingDepthLevel(void) { + /* called by the OS with interrupt disabled, no need to lock the internal resource */ + if(0 == OsGetSysPrimaskReg()) + OsKernelError(E_OS_ENABLEDINT); + OCB_Cfg.OsInterruptNestingDepth++; if(OCB_Cfg.OsInterruptNestingDepth >= OS_INTERRUPT_NESTING_DEPTH_LEVEL) @@ -79,7 +83,14 @@ void OsIncNestingDepthLevel(void) //------------------------------------------------------------------------------------------------------------------ void OsDecNestingDepthLevel(void) { + /* called by the OS with interrupt disabled, no need to lock the internal resource */ + if(0 == OsGetSysPrimaskReg()) + OsKernelError(E_OS_ENABLEDINT); + OCB_Cfg.OsInterruptNestingDepth--; + + if(OCB_Cfg.OsInterruptNestingDepth >= OS_INTERRUPT_NESTING_DEPTH_LEVEL) + OsKernelError(E_OS_KERNEL_PANIC); } //------------------------------------------------------------------------------------------------------------------ @@ -93,7 +104,15 @@ void OsDecNestingDepthLevel(void) //------------------------------------------------------------------------------------------------------------------ uint32 osGetIntNestingLevel(void) { - return OCB_Cfg.OsInterruptNestingDepth; + uint32 osInterruptNestingDepth = 0; + + /* might or might not be called durring interrupt nesting */ + + osSaveAndDisableIntState(); + osInterruptNestingDepth = OCB_Cfg.OsInterruptNestingDepth; + osRestoreSavedIntState(); + + return osInterruptNestingDepth; } //------------------------------------------------------------------------------------------------------------------ diff --git a/Code/OSEK/OsTypes.h b/Code/OSEK/OsTypes.h index a817126..f1242cc 100644 --- a/Code/OSEK/OsTypes.h +++ b/Code/OSEK/OsTypes.h @@ -88,7 +88,8 @@ typedef enum E_OS_SYS_API_ERROR = 23, E_OS_SYS_ALARM_MANAGEMENT = 24, E_OS_SYS_WARNING = 25, - E_OS_KERNEL_PANIC = 26 + E_OS_KERNEL_PANIC = 26, + E_OS_ENABLEDINT = 27 }OsStatusType; typedef enum