Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: TYBLE16_simple_data_logger TYBLE16_MP3_Air
Ticker.cpp
00001 /* mbed Microcontroller Library 00002 * Copyright (c) 2006-2019 ARM Limited 00003 * SPDX-License-Identifier: Apache-2.0 00004 * 00005 * Licensed under the Apache License, Version 2.0 (the "License"); 00006 * you may not use this file except in compliance with the License. 00007 * You may obtain a copy of the License at 00008 * 00009 * http://www.apache.org/licenses/LICENSE-2.0 00010 * 00011 * Unless required by applicable law or agreed to in writing, software 00012 * distributed under the License is distributed on an "AS IS" BASIS, 00013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00014 * See the License for the specific language governing permissions and 00015 * limitations under the License. 00016 */ 00017 #include "drivers/Ticker.h" 00018 00019 #include "drivers/TimerEvent.h" 00020 #include "hal/ticker_api.h" 00021 #include "platform/mbed_critical.h" 00022 #include "platform/mbed_power_mgmt.h" 00023 00024 namespace mbed { 00025 00026 Ticker::Ticker() : TimerEvent(), _delay(0), _function(0), _lock_deepsleep(true) 00027 { 00028 } 00029 00030 // When low power ticker is in use, then do not disable deep sleep. 00031 Ticker::Ticker(const ticker_data_t *data) : TimerEvent(data), _delay(0), _function(0), _lock_deepsleep(!data->interface->runs_in_deep_sleep) 00032 { 00033 } 00034 00035 void Ticker::detach() 00036 { 00037 core_util_critical_section_enter(); 00038 remove(); 00039 // unlocked only if we were attached (we locked it) and this is not low power ticker 00040 if (_function && _lock_deepsleep) { 00041 sleep_manager_unlock_deep_sleep(); 00042 } 00043 00044 _function = 0; 00045 core_util_critical_section_exit(); 00046 } 00047 00048 void Ticker::setup(us_timestamp_t t) 00049 { 00050 core_util_critical_section_enter(); 00051 remove(); 00052 _delay = t; 00053 insert_absolute(_delay + ticker_read_us(_ticker_data)); 00054 core_util_critical_section_exit(); 00055 } 00056 00057 void Ticker::handler() 00058 { 00059 insert_absolute(event.timestamp + _delay); 00060 if (_function) { 00061 _function(); 00062 } 00063 } 00064 00065 void Ticker::attach_us(Callback<void()> func, us_timestamp_t t) 00066 { 00067 core_util_critical_section_enter(); 00068 // lock only for the initial callback setup and this is not low power ticker 00069 if (!_function && _lock_deepsleep) { 00070 sleep_manager_lock_deep_sleep(); 00071 } 00072 _function = func; 00073 setup(t); 00074 core_util_critical_section_exit(); 00075 } 00076 00077 } // namespace mbed
Generated on Tue Jul 12 2022 13:55:00 by
