Kenji Arai / mbed-os_TYBLE16

Dependents:   TYBLE16_simple_data_logger TYBLE16_MP3_Air

Committer:
kenjiArai
Date:
Tue Dec 17 23:23:45 2019 +0000
Revision:
0:5b88d5760320
mbed-os5 only for TYBLE16

Who changed what in which revision?

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