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