mbed library sources. Supersedes mbed-src.

Dependents:   SPIne CH_Communicatuin_Test CH_Communicatuin_Test2 MCP_SPIne ... more

Fork of mbed-dev-f303 by Ben Katz

Committer:
benkatz
Date:
Wed May 02 18:08:16 2018 +0000
Revision:
179:97f825502e2a
Parent:
174:b96e65c34a4d

        

Who changed what in which revision?

UserRevisionLine numberNew 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 174:b96e65c34a4d 22
AnnaBridge 174:b96e65c34a4d 23 namespace mbed {
AnnaBridge 174:b96e65c34a4d 24
AnnaBridge 174:b96e65c34a4d 25 /** RAII object for disabling, then restoring, interrupt state
AnnaBridge 174:b96e65c34a4d 26 * Usage:
AnnaBridge 174:b96e65c34a4d 27 * @code
AnnaBridge 174:b96e65c34a4d 28 *
AnnaBridge 174:b96e65c34a4d 29 * void f() {
AnnaBridge 174:b96e65c34a4d 30 * // some code here
AnnaBridge 174:b96e65c34a4d 31 * {
AnnaBridge 174:b96e65c34a4d 32 * CriticalSectionLock lock;
AnnaBridge 174:b96e65c34a4d 33 * // Code in this block will run with interrupts disabled
AnnaBridge 174:b96e65c34a4d 34 * }
AnnaBridge 174:b96e65c34a4d 35 * // interrupts will be restored to their previous state
AnnaBridge 174:b96e65c34a4d 36 * }
AnnaBridge 174:b96e65c34a4d 37 * @endcode
AnnaBridge 174:b96e65c34a4d 38 */
AnnaBridge 174:b96e65c34a4d 39 class CriticalSectionLock {
AnnaBridge 174:b96e65c34a4d 40 public:
AnnaBridge 174:b96e65c34a4d 41 CriticalSectionLock()
AnnaBridge 174:b96e65c34a4d 42 {
AnnaBridge 174:b96e65c34a4d 43 core_util_critical_section_enter();
AnnaBridge 174:b96e65c34a4d 44 }
AnnaBridge 174:b96e65c34a4d 45
AnnaBridge 174:b96e65c34a4d 46 ~CriticalSectionLock()
AnnaBridge 174:b96e65c34a4d 47 {
AnnaBridge 174:b96e65c34a4d 48 core_util_critical_section_exit();
AnnaBridge 174:b96e65c34a4d 49 }
AnnaBridge 174:b96e65c34a4d 50
AnnaBridge 174:b96e65c34a4d 51 /** Mark the start of a critical section
AnnaBridge 174:b96e65c34a4d 52 *
AnnaBridge 174:b96e65c34a4d 53 */
AnnaBridge 174:b96e65c34a4d 54 void lock()
AnnaBridge 174:b96e65c34a4d 55 {
AnnaBridge 174:b96e65c34a4d 56 core_util_critical_section_enter();
AnnaBridge 174:b96e65c34a4d 57 }
AnnaBridge 174:b96e65c34a4d 58
AnnaBridge 174:b96e65c34a4d 59 /** Mark the end of a critical section
AnnaBridge 174:b96e65c34a4d 60 *
AnnaBridge 174:b96e65c34a4d 61 */
AnnaBridge 174:b96e65c34a4d 62 void unlock()
AnnaBridge 174:b96e65c34a4d 63 {
AnnaBridge 174:b96e65c34a4d 64 core_util_critical_section_exit();
AnnaBridge 174:b96e65c34a4d 65 }
AnnaBridge 174:b96e65c34a4d 66 };
AnnaBridge 174:b96e65c34a4d 67
AnnaBridge 174:b96e65c34a4d 68
AnnaBridge 174:b96e65c34a4d 69 } // namespace mbed
AnnaBridge 174:b96e65c34a4d 70
AnnaBridge 174:b96e65c34a4d 71 #endif