Mbed OS Reference
Loading...
Searching...
No Matches
critical_section_api.h
1/** \addtogroup hal */
2/** @{*/
3/* mbed Microcontroller Library
4 * Copyright (c) 2006-2017 ARM Limited
5 * SPDX-License-Identifier: Apache-2.0
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 */
19#ifndef MBED_CRITICAL_SECTION_API_H
20#define MBED_CRITICAL_SECTION_API_H
21
22#include <stdbool.h>
23
24#ifdef __cplusplus
25extern "C" {
26#endif
27
28/**
29 * \defgroup hal_critical Critical Section HAL functions
30 * @{
31 */
32
33/**
34 * Mark the start of a critical section
35 *
36 * This function will be called by core_util_critical_section_enter() each time
37 * the application requests to enter a critical section. The purpose of the
38 * critical section is to ensure mutual-exclusion synchronisation of the
39 * processor by preventing any change in processor control, the default
40 * behaviour requires storing the state of interrupts in the system before
41 * disabling them.
42 *
43 * The critical section code supports nesting. When a thread has entered a
44 * critical section it can make additional calls to
45 * core_util_critical_section_enter() without deadlocking itself. The critical
46 * section driver API tracks the number of nested calls to the critical section.
47 * The critical section will only be exited when
48 * core_util_critical_section_exit() has been called once for each time it
49 * entered the critical section.
50 *
51 * On the first call to enter a critical section this function MUST store the
52 * state of any interrupts or other application settings it will modify to
53 * facilitate the critical section.
54 *
55 * Each successive call to enter the critical section MUST ignore storing or
56 * modifying any application state.
57 *
58 * The default implementation of this function which will save the current state
59 * of interrupts before disabling them. This implementation can be found in
60 * mbed_critical_section_api.c. This behaviour is can be overridden on a per
61 * platform basis by providing a different implementation within the correct
62 * targets directory.
63 */
65
66
67/** Mark the end of a critical section.
68 *
69 * The purpose of this function is to restore any state that was modified upon
70 * entering the critical section, allowing other threads or interrupts to change
71 * the processor control.
72 *
73 * This function will be called once by core_util_critical_section_exit() per
74 * critical section on last call to exit. When called, the application MUST
75 * restore the saved interrupt/application state that was saved when entering
76 * the critical section.
77 *
78 * There is a default implementation of this function, it will restore the state
79 * of interrupts that were previously saved when hal_critical_section_enter was
80 * first called, this implementation can be found in
81 * mbed_critical_section_api.c. This behaviour is overridable by providing a
82 * different function implementation within the correct targets directory.
83 */
85
86
87/** Determine if the application is currently running in a critical section
88 *
89 * The purpose of this function is to inform the caller whether or not the
90 * application is running in a critical section. This is done by checking if
91 * the current interrupt state has been saved in the underlying implementation,
92 * this could also be done by checking the state of the interrupts at the time
93 * of calling.
94 *
95 * @return True if running in a critical section, false if not.
96 */
98
99
100/**@}*/
101
102#ifdef __cplusplus
103}
104#endif
105
106#endif // MBED_CRITICAL_SECTION_API_H
107
108/** @}*/
void hal_critical_section_enter(void)
Mark the start of a critical section.
bool hal_in_critical_section(void)
Determine if the application is currently running in a critical section.
void hal_critical_section_exit(void)
Mark the end of a critical section.