BA
/
BaBoRo1
Embed:
(wiki syntax)
Show/hide line numbers
critical_section_api.h
00001 /** \addtogroup hal */ 00002 /** @{*/ 00003 /* mbed Microcontroller Library 00004 * Copyright (c) 2006-2017 ARM Limited 00005 * 00006 * Licensed under the Apache License, Version 2.0 (the "License"); 00007 * you may not use this file except in compliance with the License. 00008 * You may obtain a copy of the License at 00009 * 00010 * http://www.apache.org/licenses/LICENSE-2.0 00011 * 00012 * Unless required by applicable law or agreed to in writing, software 00013 * distributed under the License is distributed on an "AS IS" BASIS, 00014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00015 * See the License for the specific language governing permissions and 00016 * limitations under the License. 00017 */ 00018 #ifndef MBED_CRITICAL_SECTION_API_H 00019 #define MBED_CRITICAL_SECTION_API_H 00020 00021 #include <stdbool.h> 00022 00023 #ifdef __cplusplus 00024 extern "C" { 00025 #endif 00026 00027 /** 00028 * \defgroup hal_critical Critical Section HAL functions 00029 * @{ 00030 */ 00031 00032 /** 00033 * Mark the start of a critical section 00034 * 00035 * This function will be called by core_util_critical_section_enter() each time 00036 * the application requests to enter a critical section. The purpose of the 00037 * critical section is to ensure mutual-exclusion synchronisation of the 00038 * processor by preventing any change in processor control, the default 00039 * behaviour requires storing the state of interrupts in the system before 00040 * disabling them. 00041 * 00042 * The critical section code supports nesting. When a thread has entered a 00043 * critical section it can make additional calls to 00044 * core_util_critical_section_enter() without deadlocking itself. The critical 00045 * section driver API tracks the number of nested calls to the critical section. 00046 * The critical section will only be exited when 00047 * core_util_critical_section_exit() has been called once for each time it 00048 * entered the critical section. 00049 * 00050 * On the first call to enter a critical section this function MUST store the 00051 * state of any interrupts or other application settings it will modify to 00052 * facilitate the critical section. 00053 * 00054 * Each successive call to enter the critical section MUST ignore storing or 00055 * modifying any application state. 00056 * 00057 * The default implementation of this function which will save the current state 00058 * of interrupts before disabling them. This implementation can be found in 00059 * mbed_critical_section_api.c. This behaviour is can be overridden on a per 00060 * platform basis by providing a different implementation within the correct 00061 * targets directory. 00062 */ 00063 void hal_critical_section_enter(void); 00064 00065 00066 /** Mark the end of a critical section. 00067 * 00068 * The purpose of this function is to restore any state that was modified upon 00069 * entering the critical section, allowing other threads or interrupts to change 00070 * the processor control. 00071 * 00072 * This function will be called once by core_util_critical_section_exit() per 00073 * critical section on last call to exit. When called, the application MUST 00074 * restore the saved interrupt/application state that was saved when entering 00075 * the critical section. 00076 * 00077 * There is a default implementation of this function, it will restore the state 00078 * of interrupts that were previously saved when hal_critical_section_enter was 00079 * first called, this implementation can be found in 00080 * mbed_critical_section_api.c. This behaviour is overridable by providing a 00081 * different function implementation within the correct targets directory. 00082 */ 00083 void hal_critical_section_exit(void); 00084 00085 00086 /** Determine if the application is currently running in a critical section 00087 * 00088 * The purpose of this function is to inform the caller whether or not the 00089 * application is running in a critical section. This is done by checking if 00090 * the current interrupt state has been saved in the underlying implementation, 00091 * this could also be done by checking the state of the interrupts at the time 00092 * of calling. 00093 * 00094 * @return True if running in a critical section, false if not. 00095 */ 00096 bool hal_in_critical_section(void); 00097 00098 00099 /**@}*/ 00100 00101 #ifdef __cplusplus 00102 } 00103 #endif 00104 00105 #endif // MBED_CRITICAL_SECTION_API_H 00106 00107 /** @}*/
Generated on Tue Jul 12 2022 12:21:47 by
