mirror of https://github.com/ARMmbed/mbed-os.git
Move in_critical_section implementation into the HAL
- Add function to HAL hal_in_critical_section() - Wrap assert in FEATURE_UVISOR macropull/5346/head
parent
04d2f3de78
commit
061795c489
|
|
@ -77,3 +77,8 @@ void hal_critical_section_exit(void)
|
||||||
__set_PRIMASK(_state._PRIMASK_state);
|
__set_PRIMASK(_state._PRIMASK_state);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool hal_in_critical_section(void)
|
||||||
|
{
|
||||||
|
return (_state_saved == true);
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,8 @@
|
||||||
#ifndef MBED_CRITICAL_SECTION_API_H
|
#ifndef MBED_CRITICAL_SECTION_API_H
|
||||||
#define MBED_CRITICAL_SECTION_API_H
|
#define MBED_CRITICAL_SECTION_API_H
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -60,6 +62,7 @@ extern "C" {
|
||||||
*/
|
*/
|
||||||
void hal_critical_section_enter(void);
|
void hal_critical_section_enter(void);
|
||||||
|
|
||||||
|
|
||||||
/** Mark the end of a critical section.
|
/** Mark the end of a critical section.
|
||||||
*
|
*
|
||||||
* The purpose of this function is to restore any state that was modified upon
|
* The purpose of this function is to restore any state that was modified upon
|
||||||
|
|
@ -79,6 +82,20 @@ void hal_critical_section_enter(void);
|
||||||
*/
|
*/
|
||||||
void hal_critical_section_exit(void);
|
void hal_critical_section_exit(void);
|
||||||
|
|
||||||
|
|
||||||
|
/** Determine if the application is currently running in a critical section
|
||||||
|
*
|
||||||
|
* The purpose of this function is to inform the caller whether or not the
|
||||||
|
* application is running in a critical section. This is done by checking if
|
||||||
|
* the current interrupt state has been saved in the underlying implementation,
|
||||||
|
* this could also be done by checking the state of the interrupts at the time
|
||||||
|
* of calling.
|
||||||
|
*
|
||||||
|
* @return True if running in a critical section, false if not.
|
||||||
|
*/
|
||||||
|
bool hal_in_critical_section(void);
|
||||||
|
|
||||||
|
|
||||||
/**@}*/
|
/**@}*/
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
|
||||||
|
|
@ -47,11 +47,12 @@ MBED_WEAK void hal_critical_section_enter(void)
|
||||||
state_saved = true;
|
state_saved = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
MBED_WEAK void hal_critical_section_exit()
|
MBED_WEAK void hal_critical_section_exit(void)
|
||||||
{
|
{
|
||||||
|
#ifndef FEATURE_UVISOR
|
||||||
// Interrupts must be disabled on invoking an exit from a critical section
|
// Interrupts must be disabled on invoking an exit from a critical section
|
||||||
MBED_ASSERT(!are_interrupts_enabled());
|
MBED_ASSERT(!are_interrupts_enabled());
|
||||||
|
#endif
|
||||||
state_saved = false;
|
state_saved = false;
|
||||||
|
|
||||||
// Restore the IRQs to their state prior to entering the critical section
|
// Restore the IRQs to their state prior to entering the critical section
|
||||||
|
|
@ -59,3 +60,8 @@ MBED_WEAK void hal_critical_section_exit()
|
||||||
__enable_irq();
|
__enable_irq();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MBED_WEAK bool hal_in_critical_section(void)
|
||||||
|
{
|
||||||
|
return (state_saved == true);
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -53,7 +53,7 @@ bool core_util_is_isr_active(void)
|
||||||
|
|
||||||
bool core_util_in_critical_section(void)
|
bool core_util_in_critical_section(void)
|
||||||
{
|
{
|
||||||
return (critical_section_reentrancy_counter != 0);
|
return hal_in_critical_section();
|
||||||
}
|
}
|
||||||
|
|
||||||
void core_util_critical_section_enter(void)
|
void core_util_critical_section_enter(void)
|
||||||
|
|
|
||||||
|
|
@ -1,43 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2015-2017, ARM Limited, All Rights Reserved
|
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
||||||
* not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
||||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
#include "nrf_nvic.h"
|
|
||||||
|
|
||||||
#include <stdbool.h>
|
|
||||||
#include <stdint.h> // uint32_t, UINT32_MAX
|
|
||||||
|
|
||||||
static uint8_t _sd_state = 0;
|
|
||||||
static volatile bool _state_saved = false;
|
|
||||||
|
|
||||||
void hal_critical_section_enter(void)
|
|
||||||
{
|
|
||||||
uint8_t temp_state = 0;
|
|
||||||
sd_nvic_critical_region_enter(&temp_state);
|
|
||||||
|
|
||||||
if (_state_saved == true) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
_sd_state = temp_state;
|
|
||||||
_state_saved = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void hal_critical_section_exit(void)
|
|
||||||
{
|
|
||||||
_state_saved = false;
|
|
||||||
|
|
||||||
sd_nvic_critical_region_exit(_sd_state);
|
|
||||||
}
|
|
||||||
|
|
@ -25,7 +25,7 @@ static void nordic_nvic_critical_region_enter(void);
|
||||||
static void nordic_nvic_critical_region_exit(void);
|
static void nordic_nvic_critical_region_exit(void);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void core_util_critical_section_enter()
|
void hal_critical_section_enter()
|
||||||
{
|
{
|
||||||
#ifdef NRF52
|
#ifdef NRF52
|
||||||
ASSERT(APP_LEVEL_PRIVILEGED == privilege_level_get())
|
ASSERT(APP_LEVEL_PRIVILEGED == privilege_level_get())
|
||||||
|
|
@ -39,7 +39,7 @@ void core_util_critical_section_enter()
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void core_util_critical_section_exit()
|
void hal_critical_section_exit()
|
||||||
{
|
{
|
||||||
#ifdef NRF52
|
#ifdef NRF52
|
||||||
ASSERT(APP_LEVEL_PRIVILEGED == privilege_level_get())
|
ASSERT(APP_LEVEL_PRIVILEGED == privilege_level_get())
|
||||||
|
|
@ -53,6 +53,13 @@ void core_util_critical_section_exit()
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool hal_in_critical_section(void)
|
||||||
|
{
|
||||||
|
return (nordic_cr_nested != 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#if defined(SOFTDEVICE_PRESENT)
|
#if defined(SOFTDEVICE_PRESENT)
|
||||||
/**@brief Enters critical region.
|
/**@brief Enters critical region.
|
||||||
*
|
*
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue