Skip to content

Commit 02a2948

Browse files
Cristib05mmahadevan108
authored andcommitted
mcux/sdk-ng/components/osa: Update OSA_InterruptEnable/Disable functions
Calls from OSA_InterruptEnable/Disable cannot be nested. Modified existing code to call OSA_EnableIRQGlobal/OSA_DisableIRQGlobal that support nested calls. Signed-off-by: Cristian Bulacu <[email protected]>
1 parent b73b5db commit 02a2948

File tree

2 files changed

+30
-12
lines changed

2 files changed

+30
-12
lines changed

mcux/mcux-sdk-ng/components/osa/fsl_os_abstraction.h

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1104,22 +1104,36 @@ int OSA_MsgQAvailableMsgs(osa_msgq_handle_t msgqHandle);
11041104
osa_status_t OSA_MsgQDestroy(osa_msgq_handle_t msgqHandle);
11051105

11061106
/*!
1107-
* @brief Enable all interrupts.
1107+
* @brief Enable all interrupts managed by OS.
1108+
*
1109+
* Different operating system may have different implementaions.
1110+
* The enabled interrupt range may be configured through operating system.
1111+
* This function supports nested calls.
11081112
*/
11091113
void OSA_InterruptEnable(void);
11101114

11111115
/*!
1112-
* @brief Disable all interrupts.
1116+
* @brief Disable all interrupts managed by OS.
1117+
*
1118+
* Different operating system may have different implementaions.
1119+
* The disabled interrupt range may be configured through operating system.
1120+
* This function supports nested calls.
11131121
*/
11141122
void OSA_InterruptDisable(void);
11151123

11161124
/*!
11171125
* @brief Enable all interrupts using PRIMASK.
1126+
*
1127+
* This function enable all interrupts apart from non-maskable interrupts.
1128+
* This function supports nested calls.
11181129
*/
11191130
void OSA_EnableIRQGlobal(void);
11201131

11211132
/*!
11221133
* @brief Disable all interrupts using PRIMASK.
1134+
*
1135+
* This function disable all interrupts apart from non-maskable interrupts.
1136+
* This function supports nested calls.
11231137
*/
11241138
void OSA_DisableIRQGlobal(void);
11251139

mcux/mcux-sdk-ng/components/osa/fsl_os_abstraction_zephyr.c

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ static sys_dlist_t s_OSA_TaskList = {0}; /*!< List of alive tasks. Used for bi
7474
static bool s_OSA_IsInitialized = false; /*!< Indicates whether OSA_Init() was called. */
7575
#endif
7676

77-
static uint32_t s_OSA_InterruptDisableCount = 0; /*!< Used for correct enabling/disabling IRQs based on call count. */
77+
static uint32_t s_OSA_DisableIRQGlobalNesting = 0; /*!< Used for correct enabling/disabling IRQs based on call count. */
78+
static uint32_t s_OSA_InterruptRegPrimask = 0;
7879

7980
const uint8_t gUseRtos_c = USE_RTOS; /*!< USE_RTOS = 0 for BareMetal and 1 for OS. */
8081

@@ -222,7 +223,7 @@ void OSA_Init(void)
222223
sys_dlist_init(&s_OSA_TaskList);
223224
#if 0
224225
// Initialization to 0 should be done automatically since it is static varriable
225-
s_OSA_InterruptDisableCount = 0;
226+
s_OSA_DisableIRQGlobalNesting = 0;
226227
#endif
227228
s_OSA_IsInitialized = true;
228229
}
@@ -242,23 +243,23 @@ void OSA_Start(void)
242243

243244
void OSA_InterruptEnable(void)
244245
{
245-
__enable_irq();
246+
OSA_EnableIRQGlobal();
246247
}
247248

248249
void OSA_InterruptDisable(void)
249250
{
250-
__disable_irq();
251+
OSA_DisableIRQGlobal();
251252
}
252253

253254
void OSA_EnableIRQGlobal(void)
254255
{
255-
if (s_OSA_InterruptDisableCount > 0U)
256+
if (s_OSA_DisableIRQGlobalNesting > 0U)
256257
{
257-
s_OSA_InterruptDisableCount--;
258+
s_OSA_DisableIRQGlobalNesting--;
258259

259-
if (0U == s_OSA_InterruptDisableCount)
260+
if (0U == s_OSA_DisableIRQGlobalNesting)
260261
{
261-
__enable_irq();
262+
irq_unlock(s_OSA_InterruptRegPrimask);
262263
}
263264
/* call core API to enable the global interrupt*/
264265
}
@@ -267,10 +268,13 @@ void OSA_EnableIRQGlobal(void)
267268
void OSA_DisableIRQGlobal(void)
268269
{
269270
/* call core API to disable the global interrupt*/
270-
__disable_irq();
271+
if (0U == s_OSA_DisableIRQGlobalNesting)
272+
{
273+
s_OSA_InterruptRegPrimask = irq_lock();
274+
}
271275

272276
/* update counter*/
273-
s_OSA_InterruptDisableCount++;
277+
s_OSA_DisableIRQGlobalNesting++;
274278
}
275279

276280
/*!

0 commit comments

Comments
 (0)