Initial commit

Dependencies:   FastPWM

Committer:
lypinator
Date:
Wed Sep 16 01:11:49 2020 +0000
Revision:
0:bb348c97df44
Added PWM

Who changed what in which revision?

UserRevisionLine numberNew contents of line
lypinator 0:bb348c97df44 1 /*
lypinator 0:bb348c97df44 2 * PackageLicenseDeclared: Apache-2.0
lypinator 0:bb348c97df44 3 * Copyright (c) 2017 ARM Limited
lypinator 0:bb348c97df44 4 *
lypinator 0:bb348c97df44 5 * Licensed under the Apache License, Version 2.0 (the "License");
lypinator 0:bb348c97df44 6 * you may not use this file except in compliance with the License.
lypinator 0:bb348c97df44 7 * You may obtain a copy of the License at
lypinator 0:bb348c97df44 8 *
lypinator 0:bb348c97df44 9 * http://www.apache.org/licenses/LICENSE-2.0
lypinator 0:bb348c97df44 10 *
lypinator 0:bb348c97df44 11 * Unless required by applicable law or agreed to in writing, software
lypinator 0:bb348c97df44 12 * distributed under the License is distributed on an "AS IS" BASIS,
lypinator 0:bb348c97df44 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
lypinator 0:bb348c97df44 14 * See the License for the specific language governing permissions and
lypinator 0:bb348c97df44 15 * limitations under the License.
lypinator 0:bb348c97df44 16 */
lypinator 0:bb348c97df44 17
lypinator 0:bb348c97df44 18 #ifndef MBED_CRITICALSECTIONLOCK_H
lypinator 0:bb348c97df44 19 #define MBED_CRITICALSECTIONLOCK_H
lypinator 0:bb348c97df44 20
lypinator 0:bb348c97df44 21 #include "platform/mbed_critical.h"
lypinator 0:bb348c97df44 22 #include "platform/mbed_toolchain.h"
lypinator 0:bb348c97df44 23
lypinator 0:bb348c97df44 24 namespace mbed {
lypinator 0:bb348c97df44 25
lypinator 0:bb348c97df44 26 /** \addtogroup platform */
lypinator 0:bb348c97df44 27 /** @{*/
lypinator 0:bb348c97df44 28 /**
lypinator 0:bb348c97df44 29 * \defgroup platform_CriticalSectionLock CriticalSectionLock functions
lypinator 0:bb348c97df44 30 * @{
lypinator 0:bb348c97df44 31 */
lypinator 0:bb348c97df44 32
lypinator 0:bb348c97df44 33 /** RAII object for disabling, then restoring, interrupt state
lypinator 0:bb348c97df44 34 * Usage:
lypinator 0:bb348c97df44 35 * @code
lypinator 0:bb348c97df44 36 *
lypinator 0:bb348c97df44 37 * // RAII style usage
lypinator 0:bb348c97df44 38 * unsigned int atomic_counter_increment(unsigned int &counter) {
lypinator 0:bb348c97df44 39 * CriticalSectionLock lock;
lypinator 0:bb348c97df44 40 * // Code in this block will run with interrupts disabled
lypinator 0:bb348c97df44 41 * // Interrupts will be restored to their previous state automatically
lypinator 0:bb348c97df44 42 * // at the end of function scope
lypinator 0:bb348c97df44 43 * return ++counter;
lypinator 0:bb348c97df44 44 * }
lypinator 0:bb348c97df44 45 *
lypinator 0:bb348c97df44 46 * // free locking usage
lypinator 0:bb348c97df44 47 * unsigned int atomic_counter_decrement(unsigned int &counter) {
lypinator 0:bb348c97df44 48 * CriticalSectionLock::enable();
lypinator 0:bb348c97df44 49 * // Code in this block will run with interrupts disabled
lypinator 0:bb348c97df44 50 * counter--;
lypinator 0:bb348c97df44 51 * CriticalSectionLock::disable(); // need explicitly to disable critical section lock
lypinator 0:bb348c97df44 52 * // interrupts will be restored to their previous state here
lypinator 0:bb348c97df44 53 * return counter;
lypinator 0:bb348c97df44 54 * }
lypinator 0:bb348c97df44 55 *
lypinator 0:bb348c97df44 56 * @endcode
lypinator 0:bb348c97df44 57 */
lypinator 0:bb348c97df44 58 class CriticalSectionLock {
lypinator 0:bb348c97df44 59 public:
lypinator 0:bb348c97df44 60 CriticalSectionLock()
lypinator 0:bb348c97df44 61 {
lypinator 0:bb348c97df44 62 core_util_critical_section_enter();
lypinator 0:bb348c97df44 63 }
lypinator 0:bb348c97df44 64
lypinator 0:bb348c97df44 65 ~CriticalSectionLock()
lypinator 0:bb348c97df44 66 {
lypinator 0:bb348c97df44 67 core_util_critical_section_exit();
lypinator 0:bb348c97df44 68 }
lypinator 0:bb348c97df44 69
lypinator 0:bb348c97df44 70 /** Mark the start of a critical section
lypinator 0:bb348c97df44 71 * @deprecated This function is inconsistent with RAII and is being removed in the future. Replaced by static function CriticalSectionLock::enable.
lypinator 0:bb348c97df44 72 *
lypinator 0:bb348c97df44 73 */
lypinator 0:bb348c97df44 74 MBED_DEPRECATED_SINCE("mbed-os-5.8",
lypinator 0:bb348c97df44 75 "This function is inconsistent with RAII and is being removed in the future."
lypinator 0:bb348c97df44 76 "Replaced by static function CriticalSectionLock::enable.")
lypinator 0:bb348c97df44 77 void lock()
lypinator 0:bb348c97df44 78 {
lypinator 0:bb348c97df44 79 core_util_critical_section_enter();
lypinator 0:bb348c97df44 80 }
lypinator 0:bb348c97df44 81
lypinator 0:bb348c97df44 82 /** Mark the end of a critical section
lypinator 0:bb348c97df44 83 * @deprecated This function is inconsistent with RAII and is being removed in the future. Replaced by static function CriticalSectionLock::enable.
lypinator 0:bb348c97df44 84 *
lypinator 0:bb348c97df44 85 */
lypinator 0:bb348c97df44 86 MBED_DEPRECATED_SINCE("mbed-os-5.8",
lypinator 0:bb348c97df44 87 "This function is inconsistent with RAII and is being removed in the future."
lypinator 0:bb348c97df44 88 "Replaced by static function CriticalSectionLock::disable.")
lypinator 0:bb348c97df44 89 void unlock()
lypinator 0:bb348c97df44 90 {
lypinator 0:bb348c97df44 91 core_util_critical_section_exit();
lypinator 0:bb348c97df44 92 }
lypinator 0:bb348c97df44 93
lypinator 0:bb348c97df44 94 /** Mark the start of a critical section
lypinator 0:bb348c97df44 95 */
lypinator 0:bb348c97df44 96 static void enable()
lypinator 0:bb348c97df44 97 {
lypinator 0:bb348c97df44 98 core_util_critical_section_enter();
lypinator 0:bb348c97df44 99 }
lypinator 0:bb348c97df44 100
lypinator 0:bb348c97df44 101 /** Mark the end of a critical section
lypinator 0:bb348c97df44 102 */
lypinator 0:bb348c97df44 103 static void disable()
lypinator 0:bb348c97df44 104 {
lypinator 0:bb348c97df44 105 core_util_critical_section_exit();
lypinator 0:bb348c97df44 106 }
lypinator 0:bb348c97df44 107 };
lypinator 0:bb348c97df44 108
lypinator 0:bb348c97df44 109 /**@}*/
lypinator 0:bb348c97df44 110
lypinator 0:bb348c97df44 111 /**@}*/
lypinator 0:bb348c97df44 112
lypinator 0:bb348c97df44 113 } // namespace mbed
lypinator 0:bb348c97df44 114
lypinator 0:bb348c97df44 115 #endif