The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.

Dependents:   hello SerialTestv11 SerialTestv12 Sierpinski ... more

mbed 2

This is the mbed 2 library. If you'd like to learn about Mbed OS please see the mbed-os docs.

Committer:
AnnaBridge
Date:
Wed Feb 20 20:53:29 2019 +0000
Revision:
172:65be27845400
Parent:
165:d1b4690b3f8b
mbed library release version 165

Who changed what in which revision?

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