forked from RyoheiHagimoto/mbed-os
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmbed_critical.h
97 lines (84 loc) · 3.03 KB
/
mbed_critical.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/*
* Copyright (c) 2015-2019, 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.
*/
#ifndef __MBED_UTIL_CRITICAL_H__
#define __MBED_UTIL_CRITICAL_H__
#include <stdbool.h>
#ifdef __cplusplus
extern "C" {
#endif
/** \addtogroup platform-public-api */
/** @{*/
/**
* \defgroup platform_critical critical section function
* @{
*/
/** Determine the current interrupts enabled state
*
* This function can be called to determine whether or not interrupts are currently enabled.
* @note
* NOTE:
* This function works for both cortex-A and cortex-M, although the underlying implementation
* differs.
* @return true if interrupts are enabled, false otherwise
*/
bool core_util_are_interrupts_enabled(void);
/** Determine if this code is executing from an interrupt
*
* This function can be called to determine if the code is running on interrupt context.
* @note
* NOTE:
* This function works for both cortex-A and cortex-M, although the underlying implementation
* differs.
* @return true if in an isr, false otherwise
*/
bool core_util_is_isr_active(void);
/** Mark the start of a critical section
*
* This function should be called to mark the start of a critical section of code.
* @note
* NOTES:
* 1) The use of this style of critical section is targetted at C based implementations.
* 2) These critical sections can be nested.
* 3) The interrupt enable state on entry to the first critical section (of a nested set, or single
* section) will be preserved on exit from the section.
* 4) This implementation will currently only work on code running in privileged mode.
*/
void core_util_critical_section_enter(void);
/** Mark the end of a critical section
*
* This function should be called to mark the end of a critical section of code.
* @note
* NOTES:
* 1) The use of this style of critical section is targetted at C based implementations.
* 2) These critical sections can be nested.
* 3) The interrupt enable state on entry to the first critical section (of a nested set, or single
* section) will be preserved on exit from the section.
* 4) This implementation will currently only work on code running in privileged mode.
*/
void core_util_critical_section_exit(void);
/**
* Determine if we are currently in a critical section
*
* @return true if in a critical section, false otherwise.
*/
bool core_util_in_critical_section(void);
/**@}*/
/**@}*/
#ifdef __cplusplus
} // extern "C"
#endif
#endif // __MBED_UTIL_CRITICAL_H__