mbed-os5 only for TYBLE16
Dependents: TYBLE16_simple_data_logger TYBLE16_MP3_Air
platform/source/DeepSleepLock.cpp@1:9db0e321a9f4, 2019-12-31 (annotated)
- Committer:
- kenjiArai
- Date:
- Tue Dec 31 06:02:27 2019 +0000
- Revision:
- 1:9db0e321a9f4
updated based on mbed-os5.15.0
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kenjiArai | 1:9db0e321a9f4 | 1 | /* mbed Microcontroller Library |
kenjiArai | 1:9db0e321a9f4 | 2 | * Copyright (c) 2017-2019 ARM Limited |
kenjiArai | 1:9db0e321a9f4 | 3 | * SPDX-License-Identifier: Apache-2.0 |
kenjiArai | 1:9db0e321a9f4 | 4 | * |
kenjiArai | 1:9db0e321a9f4 | 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
kenjiArai | 1:9db0e321a9f4 | 6 | * you may not use this file except in compliance with the License. |
kenjiArai | 1:9db0e321a9f4 | 7 | * You may obtain a copy of the License at |
kenjiArai | 1:9db0e321a9f4 | 8 | * |
kenjiArai | 1:9db0e321a9f4 | 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
kenjiArai | 1:9db0e321a9f4 | 10 | * |
kenjiArai | 1:9db0e321a9f4 | 11 | * Unless required by applicable law or agreed to in writing, software |
kenjiArai | 1:9db0e321a9f4 | 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
kenjiArai | 1:9db0e321a9f4 | 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
kenjiArai | 1:9db0e321a9f4 | 14 | * See the License for the specific language governing permissions and |
kenjiArai | 1:9db0e321a9f4 | 15 | * limitations under the License. |
kenjiArai | 1:9db0e321a9f4 | 16 | */ |
kenjiArai | 1:9db0e321a9f4 | 17 | |
kenjiArai | 1:9db0e321a9f4 | 18 | #include "platform/DeepSleepLock.h" |
kenjiArai | 1:9db0e321a9f4 | 19 | |
kenjiArai | 1:9db0e321a9f4 | 20 | #include "platform/mbed_atomic.h" |
kenjiArai | 1:9db0e321a9f4 | 21 | #include "platform/mbed_critical.h" |
kenjiArai | 1:9db0e321a9f4 | 22 | #include "platform/mbed_error.h" |
kenjiArai | 1:9db0e321a9f4 | 23 | #include "platform/mbed_power_mgmt.h" |
kenjiArai | 1:9db0e321a9f4 | 24 | |
kenjiArai | 1:9db0e321a9f4 | 25 | namespace mbed { |
kenjiArai | 1:9db0e321a9f4 | 26 | |
kenjiArai | 1:9db0e321a9f4 | 27 | DeepSleepLock::DeepSleepLock(): _lock_count(1) |
kenjiArai | 1:9db0e321a9f4 | 28 | { |
kenjiArai | 1:9db0e321a9f4 | 29 | sleep_manager_lock_deep_sleep(); |
kenjiArai | 1:9db0e321a9f4 | 30 | } |
kenjiArai | 1:9db0e321a9f4 | 31 | |
kenjiArai | 1:9db0e321a9f4 | 32 | DeepSleepLock::~DeepSleepLock() |
kenjiArai | 1:9db0e321a9f4 | 33 | { |
kenjiArai | 1:9db0e321a9f4 | 34 | if (_lock_count) { |
kenjiArai | 1:9db0e321a9f4 | 35 | sleep_manager_unlock_deep_sleep(); |
kenjiArai | 1:9db0e321a9f4 | 36 | } |
kenjiArai | 1:9db0e321a9f4 | 37 | } |
kenjiArai | 1:9db0e321a9f4 | 38 | |
kenjiArai | 1:9db0e321a9f4 | 39 | void DeepSleepLock::lock() |
kenjiArai | 1:9db0e321a9f4 | 40 | { |
kenjiArai | 1:9db0e321a9f4 | 41 | uint16_t count = core_util_atomic_incr_u16(&_lock_count, 1); |
kenjiArai | 1:9db0e321a9f4 | 42 | if (1 == count) { |
kenjiArai | 1:9db0e321a9f4 | 43 | sleep_manager_lock_deep_sleep(); |
kenjiArai | 1:9db0e321a9f4 | 44 | } |
kenjiArai | 1:9db0e321a9f4 | 45 | if (0 == count) { |
kenjiArai | 1:9db0e321a9f4 | 46 | MBED_ERROR1(MBED_MAKE_ERROR(MBED_MODULE_PLATFORM, MBED_ERROR_CODE_OVERFLOW), "DeepSleepLock overflow (> USHRT_MAX)", count); |
kenjiArai | 1:9db0e321a9f4 | 47 | } |
kenjiArai | 1:9db0e321a9f4 | 48 | } |
kenjiArai | 1:9db0e321a9f4 | 49 | |
kenjiArai | 1:9db0e321a9f4 | 50 | void DeepSleepLock::unlock() |
kenjiArai | 1:9db0e321a9f4 | 51 | { |
kenjiArai | 1:9db0e321a9f4 | 52 | uint16_t count = core_util_atomic_decr_u16(&_lock_count, 1); |
kenjiArai | 1:9db0e321a9f4 | 53 | if (count == 0) { |
kenjiArai | 1:9db0e321a9f4 | 54 | sleep_manager_unlock_deep_sleep(); |
kenjiArai | 1:9db0e321a9f4 | 55 | } |
kenjiArai | 1:9db0e321a9f4 | 56 | if (count == USHRT_MAX) { |
kenjiArai | 1:9db0e321a9f4 | 57 | core_util_critical_section_exit(); |
kenjiArai | 1:9db0e321a9f4 | 58 | MBED_ERROR1(MBED_MAKE_ERROR(MBED_MODULE_PLATFORM, MBED_ERROR_CODE_UNDERFLOW), "DeepSleepLock underflow (< 0)", count); |
kenjiArai | 1:9db0e321a9f4 | 59 | } |
kenjiArai | 1:9db0e321a9f4 | 60 | } |
kenjiArai | 1:9db0e321a9f4 | 61 | |
kenjiArai | 1:9db0e321a9f4 | 62 | } // namespace mbed |