Skip to content

Commit 061795c

Browse files
author
Steven Cartmell
committed
Move in_critical_section implementation into the HAL
- Add function to HAL hal_in_critical_section() - Wrap assert in FEATURE_UVISOR macro
1 parent 04d2f3d commit 061795c

File tree

6 files changed

+40
-48
lines changed

6 files changed

+40
-48
lines changed

features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_MCU_NRF51822/hal_patch/critical_section_api.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,8 @@ void hal_critical_section_exit(void)
7777
__set_PRIMASK(_state._PRIMASK_state);
7878
}
7979
}
80+
81+
bool hal_in_critical_section(void)
82+
{
83+
return (_state_saved == true);
84+
}

hal/critical_section_api.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
#ifndef MBED_CRITICAL_SECTION_API_H
1919
#define MBED_CRITICAL_SECTION_API_H
2020

21+
#include <stdbool.h>
22+
2123
#ifdef __cplusplus
2224
extern "C" {
2325
#endif
@@ -60,6 +62,7 @@ extern "C" {
6062
*/
6163
void hal_critical_section_enter(void);
6264

65+
6366
/** Mark the end of a critical section.
6467
*
6568
* The purpose of this function is to restore any state that was modified upon
@@ -79,6 +82,20 @@ void hal_critical_section_enter(void);
7982
*/
8083
void hal_critical_section_exit(void);
8184

85+
86+
/** Determine if the application is currently running in a critical section
87+
*
88+
* The purpose of this function is to inform the caller whether or not the
89+
* application is running in a critical section. This is done by checking if
90+
* the current interrupt state has been saved in the underlying implementation,
91+
* this could also be done by checking the state of the interrupts at the time
92+
* of calling.
93+
*
94+
* @return True if running in a critical section, false if not.
95+
*/
96+
bool hal_in_critical_section(void);
97+
98+
8299
/**@}*/
83100

84101
#ifdef __cplusplus

hal/mbed_critical_section_api.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,21 @@ MBED_WEAK void hal_critical_section_enter(void)
4747
state_saved = true;
4848
}
4949

50-
MBED_WEAK void hal_critical_section_exit()
50+
MBED_WEAK void hal_critical_section_exit(void)
5151
{
52+
#ifndef FEATURE_UVISOR
5253
// Interrupts must be disabled on invoking an exit from a critical section
5354
MBED_ASSERT(!are_interrupts_enabled());
54-
55+
#endif
5556
state_saved = false;
5657

5758
// Restore the IRQs to their state prior to entering the critical section
5859
if (critical_interrupts_enabled == true) {
5960
__enable_irq();
6061
}
6162
}
63+
64+
MBED_WEAK bool hal_in_critical_section(void)
65+
{
66+
return (state_saved == true);
67+
}

platform/mbed_critical.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ bool core_util_is_isr_active(void)
5353

5454
bool core_util_in_critical_section(void)
5555
{
56-
return (critical_section_reentrancy_counter != 0);
56+
return hal_in_critical_section();
5757
}
5858

5959
void core_util_critical_section_enter(void)

targets/TARGET_NORDIC/TARGET_NRF5/critical_section_api.c

Lines changed: 0 additions & 43 deletions
This file was deleted.

targets/TARGET_NORDIC/TARGET_NRF5/nordic_critical.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ static void nordic_nvic_critical_region_enter(void);
2525
static void nordic_nvic_critical_region_exit(void);
2626
#endif
2727

28-
void core_util_critical_section_enter()
28+
void hal_critical_section_enter()
2929
{
3030
#ifdef NRF52
3131
ASSERT(APP_LEVEL_PRIVILEGED == privilege_level_get())
@@ -39,7 +39,7 @@ void core_util_critical_section_enter()
3939
#endif
4040
}
4141

42-
void core_util_critical_section_exit()
42+
void hal_critical_section_exit()
4343
{
4444
#ifdef NRF52
4545
ASSERT(APP_LEVEL_PRIVILEGED == privilege_level_get())
@@ -53,6 +53,13 @@ void core_util_critical_section_exit()
5353
#endif
5454
}
5555

56+
57+
bool hal_in_critical_section(void)
58+
{
59+
return (nordic_cr_nested != 0);
60+
}
61+
62+
5663
#if defined(SOFTDEVICE_PRESENT)
5764
/**@brief Enters critical region.
5865
*

0 commit comments

Comments
 (0)