mbed-os5 only for TYBLE16

Dependents:   TYBLE16_simple_data_logger TYBLE16_MP3_Air

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?

UserRevisionLine numberNew contents of line
kenjiArai 1:9db0e321a9f4 1 /* mbed Microcontroller Library
kenjiArai 1:9db0e321a9f4 2 * Copyright (c) 2006-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 #include "drivers/Ticker.h"
kenjiArai 1:9db0e321a9f4 18
kenjiArai 1:9db0e321a9f4 19 #include "drivers/TimerEvent.h"
kenjiArai 1:9db0e321a9f4 20 #include "hal/ticker_api.h"
kenjiArai 1:9db0e321a9f4 21 #include "platform/mbed_critical.h"
kenjiArai 1:9db0e321a9f4 22 #include "platform/mbed_power_mgmt.h"
kenjiArai 1:9db0e321a9f4 23
kenjiArai 1:9db0e321a9f4 24 namespace mbed {
kenjiArai 1:9db0e321a9f4 25
kenjiArai 1:9db0e321a9f4 26 Ticker::Ticker() : TimerEvent(), _delay(0), _function(0), _lock_deepsleep(true)
kenjiArai 1:9db0e321a9f4 27 {
kenjiArai 1:9db0e321a9f4 28 }
kenjiArai 1:9db0e321a9f4 29
kenjiArai 1:9db0e321a9f4 30 // When low power ticker is in use, then do not disable deep sleep.
kenjiArai 1:9db0e321a9f4 31 Ticker::Ticker(const ticker_data_t *data) : TimerEvent(data), _delay(0), _function(0), _lock_deepsleep(!data->interface->runs_in_deep_sleep)
kenjiArai 1:9db0e321a9f4 32 {
kenjiArai 1:9db0e321a9f4 33 }
kenjiArai 1:9db0e321a9f4 34
kenjiArai 1:9db0e321a9f4 35 void Ticker::detach()
kenjiArai 1:9db0e321a9f4 36 {
kenjiArai 1:9db0e321a9f4 37 core_util_critical_section_enter();
kenjiArai 1:9db0e321a9f4 38 remove();
kenjiArai 1:9db0e321a9f4 39 // unlocked only if we were attached (we locked it) and this is not low power ticker
kenjiArai 1:9db0e321a9f4 40 if (_function && _lock_deepsleep) {
kenjiArai 1:9db0e321a9f4 41 sleep_manager_unlock_deep_sleep();
kenjiArai 1:9db0e321a9f4 42 }
kenjiArai 1:9db0e321a9f4 43
kenjiArai 1:9db0e321a9f4 44 _function = 0;
kenjiArai 1:9db0e321a9f4 45 core_util_critical_section_exit();
kenjiArai 1:9db0e321a9f4 46 }
kenjiArai 1:9db0e321a9f4 47
kenjiArai 1:9db0e321a9f4 48 void Ticker::setup(us_timestamp_t t)
kenjiArai 1:9db0e321a9f4 49 {
kenjiArai 1:9db0e321a9f4 50 core_util_critical_section_enter();
kenjiArai 1:9db0e321a9f4 51 remove();
kenjiArai 1:9db0e321a9f4 52 _delay = t;
kenjiArai 1:9db0e321a9f4 53 insert_absolute(_delay + ticker_read_us(_ticker_data));
kenjiArai 1:9db0e321a9f4 54 core_util_critical_section_exit();
kenjiArai 1:9db0e321a9f4 55 }
kenjiArai 1:9db0e321a9f4 56
kenjiArai 1:9db0e321a9f4 57 void Ticker::handler()
kenjiArai 1:9db0e321a9f4 58 {
kenjiArai 1:9db0e321a9f4 59 insert_absolute(event.timestamp + _delay);
kenjiArai 1:9db0e321a9f4 60 if (_function) {
kenjiArai 1:9db0e321a9f4 61 _function();
kenjiArai 1:9db0e321a9f4 62 }
kenjiArai 1:9db0e321a9f4 63 }
kenjiArai 1:9db0e321a9f4 64
kenjiArai 1:9db0e321a9f4 65 void Ticker::attach_us(Callback<void()> func, us_timestamp_t t)
kenjiArai 1:9db0e321a9f4 66 {
kenjiArai 1:9db0e321a9f4 67 core_util_critical_section_enter();
kenjiArai 1:9db0e321a9f4 68 // lock only for the initial callback setup and this is not low power ticker
kenjiArai 1:9db0e321a9f4 69 if (!_function && _lock_deepsleep) {
kenjiArai 1:9db0e321a9f4 70 sleep_manager_lock_deep_sleep();
kenjiArai 1:9db0e321a9f4 71 }
kenjiArai 1:9db0e321a9f4 72 _function = func;
kenjiArai 1:9db0e321a9f4 73 setup(t);
kenjiArai 1:9db0e321a9f4 74 core_util_critical_section_exit();
kenjiArai 1:9db0e321a9f4 75 }
kenjiArai 1:9db0e321a9f4 76
kenjiArai 1:9db0e321a9f4 77 } // namespace mbed