mbed library sources. Supersedes mbed-src.

Dependents:   Nucleo_Hello_Encoder BLE_iBeaconScan AM1805_DEMO DISCO-F429ZI_ExportTemplate1 ... more

Committer:
AnnaBridge
Date:
Wed Feb 20 22:31:08 2019 +0000
Revision:
189:f392fc9709a3
Parent:
184:08ed48f1de7f
mbed library release version 165

Who changed what in which revision?

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