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:
Anna Bridge
Date:
Fri Jun 22 15:38:59 2018 +0100
Revision:
169:a7c7b631e539
Parent:
165:d1b4690b3f8b
Child:
172:65be27845400
mbed library. Release version 162

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