Skip to content

Commit

Permalink
add new interrupt APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
Chalandi committed Oct 4, 2024
1 parent 7634352 commit 4b73457
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 17 deletions.
20 changes: 20 additions & 0 deletions Code/OSEK/HwPlatform/ARM/OsAsm.s
Original file line number Diff line number Diff line change
Expand Up @@ -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


//-----------------------------------------------------------------------------------------------------------------
Expand Down
53 changes: 40 additions & 13 deletions Code/OSEK/HwPlatform/ARM/OsHwPltfm.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
Expand All @@ -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
///
Expand Down
3 changes: 1 addition & 2 deletions Code/OSEK/HwPlatform/ARM/OsHwPltfm.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
21 changes: 20 additions & 1 deletion Code/OSEK/OsCat2Int.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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);
}

//------------------------------------------------------------------------------------------------------------------
Expand All @@ -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;
}

//------------------------------------------------------------------------------------------------------------------
Expand Down
3 changes: 2 additions & 1 deletion Code/OSEK/OsTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4b73457

Please sign in to comment.