mbed library sources, mbed-dev only for TYBLE16
Fork of mbed-dev by
Please refer flowing link.
/users/kenjiArai/notebook/tyble16-module-will-become-a-mbed-family--mbedliza/
platform/CriticalSectionLock.h@182:976b131d2800, 2018-02-25 (annotated)
- Committer:
- kenjiArai
- Date:
- Sun Feb 25 02:00:51 2018 +0000
- Revision:
- 182:976b131d2800
- Parent:
- 181:57724642e740
Only for TYBLE16
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
AnnaBridge | 174:b96e65c34a4d | 1 | /* |
AnnaBridge | 174:b96e65c34a4d | 2 | * PackageLicenseDeclared: Apache-2.0 |
AnnaBridge | 174:b96e65c34a4d | 3 | * Copyright (c) 2017 ARM Limited |
AnnaBridge | 174:b96e65c34a4d | 4 | * |
AnnaBridge | 174:b96e65c34a4d | 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
AnnaBridge | 174:b96e65c34a4d | 6 | * you may not use this file except in compliance with the License. |
AnnaBridge | 174:b96e65c34a4d | 7 | * You may obtain a copy of the License at |
AnnaBridge | 174:b96e65c34a4d | 8 | * |
AnnaBridge | 174:b96e65c34a4d | 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
AnnaBridge | 174:b96e65c34a4d | 10 | * |
AnnaBridge | 174:b96e65c34a4d | 11 | * Unless required by applicable law or agreed to in writing, software |
AnnaBridge | 174:b96e65c34a4d | 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
AnnaBridge | 174:b96e65c34a4d | 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
AnnaBridge | 174:b96e65c34a4d | 14 | * See the License for the specific language governing permissions and |
AnnaBridge | 174:b96e65c34a4d | 15 | * limitations under the License. |
AnnaBridge | 174:b96e65c34a4d | 16 | */ |
AnnaBridge | 174:b96e65c34a4d | 17 | |
AnnaBridge | 174:b96e65c34a4d | 18 | #ifndef MBED_CRITICALSECTIONLOCK_H |
AnnaBridge | 174:b96e65c34a4d | 19 | #define MBED_CRITICALSECTIONLOCK_H |
AnnaBridge | 174:b96e65c34a4d | 20 | |
AnnaBridge | 174:b96e65c34a4d | 21 | #include "platform/mbed_critical.h" |
AnnaBridge | 181:57724642e740 | 22 | #include "platform/mbed_toolchain.h" |
AnnaBridge | 174:b96e65c34a4d | 23 | |
AnnaBridge | 174:b96e65c34a4d | 24 | namespace mbed { |
AnnaBridge | 174:b96e65c34a4d | 25 | |
AnnaBridge | 178:79309dc6340a | 26 | /** \addtogroup platform */ |
AnnaBridge | 178:79309dc6340a | 27 | /** @{*/ |
AnnaBridge | 178:79309dc6340a | 28 | /** |
AnnaBridge | 178:79309dc6340a | 29 | * \defgroup platform_CriticalSectionLock CriticalSectionLock functions |
AnnaBridge | 178:79309dc6340a | 30 | * @{ |
AnnaBridge | 178:79309dc6340a | 31 | */ |
AnnaBridge | 178:79309dc6340a | 32 | |
AnnaBridge | 174:b96e65c34a4d | 33 | /** RAII object for disabling, then restoring, interrupt state |
AnnaBridge | 174:b96e65c34a4d | 34 | * Usage: |
AnnaBridge | 174:b96e65c34a4d | 35 | * @code |
AnnaBridge | 174:b96e65c34a4d | 36 | * |
AnnaBridge | 174:b96e65c34a4d | 37 | * void f() { |
AnnaBridge | 174:b96e65c34a4d | 38 | * // some code here |
AnnaBridge | 174:b96e65c34a4d | 39 | * { |
AnnaBridge | 174:b96e65c34a4d | 40 | * CriticalSectionLock lock; |
AnnaBridge | 174:b96e65c34a4d | 41 | * // Code in this block will run with interrupts disabled |
AnnaBridge | 174:b96e65c34a4d | 42 | * } |
AnnaBridge | 174:b96e65c34a4d | 43 | * // interrupts will be restored to their previous state |
AnnaBridge | 174:b96e65c34a4d | 44 | * } |
AnnaBridge | 174:b96e65c34a4d | 45 | * @endcode |
AnnaBridge | 174:b96e65c34a4d | 46 | */ |
AnnaBridge | 174:b96e65c34a4d | 47 | class CriticalSectionLock { |
AnnaBridge | 174:b96e65c34a4d | 48 | public: |
AnnaBridge | 174:b96e65c34a4d | 49 | CriticalSectionLock() |
AnnaBridge | 174:b96e65c34a4d | 50 | { |
AnnaBridge | 174:b96e65c34a4d | 51 | core_util_critical_section_enter(); |
AnnaBridge | 174:b96e65c34a4d | 52 | } |
AnnaBridge | 174:b96e65c34a4d | 53 | |
AnnaBridge | 174:b96e65c34a4d | 54 | ~CriticalSectionLock() |
AnnaBridge | 174:b96e65c34a4d | 55 | { |
AnnaBridge | 174:b96e65c34a4d | 56 | core_util_critical_section_exit(); |
AnnaBridge | 174:b96e65c34a4d | 57 | } |
AnnaBridge | 174:b96e65c34a4d | 58 | |
AnnaBridge | 174:b96e65c34a4d | 59 | /** Mark the start of a critical section |
AnnaBridge | 174:b96e65c34a4d | 60 | * |
AnnaBridge | 174:b96e65c34a4d | 61 | */ |
AnnaBridge | 174:b96e65c34a4d | 62 | void lock() |
AnnaBridge | 174:b96e65c34a4d | 63 | { |
AnnaBridge | 174:b96e65c34a4d | 64 | core_util_critical_section_enter(); |
AnnaBridge | 174:b96e65c34a4d | 65 | } |
AnnaBridge | 174:b96e65c34a4d | 66 | |
AnnaBridge | 174:b96e65c34a4d | 67 | /** Mark the end of a critical section |
AnnaBridge | 174:b96e65c34a4d | 68 | * |
AnnaBridge | 174:b96e65c34a4d | 69 | */ |
AnnaBridge | 174:b96e65c34a4d | 70 | void unlock() |
AnnaBridge | 174:b96e65c34a4d | 71 | { |
AnnaBridge | 174:b96e65c34a4d | 72 | core_util_critical_section_exit(); |
AnnaBridge | 174:b96e65c34a4d | 73 | } |
AnnaBridge | 174:b96e65c34a4d | 74 | }; |
AnnaBridge | 174:b96e65c34a4d | 75 | |
AnnaBridge | 178:79309dc6340a | 76 | /**@}*/ |
AnnaBridge | 178:79309dc6340a | 77 | |
AnnaBridge | 178:79309dc6340a | 78 | /**@}*/ |
AnnaBridge | 174:b96e65c34a4d | 79 | |
AnnaBridge | 174:b96e65c34a4d | 80 | } // namespace mbed |
AnnaBridge | 174:b96e65c34a4d | 81 | |
AnnaBridge | 174:b96e65c34a4d | 82 | #endif |