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