mbed library sources. Supersedes mbed-src.
Dependents: Nucleo_Hello_Encoder BLE_iBeaconScan AM1805_DEMO DISCO-F429ZI_ExportTemplate1 ... more
Ticker.cpp
00001 /* mbed Microcontroller Library 00002 * Copyright (c) 2006-2013 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 "platform/FunctionPointer.h" 00021 #include "hal/ticker_api.h" 00022 #include "platform/mbed_critical.h" 00023 00024 namespace mbed { 00025 00026 void Ticker::detach() 00027 { 00028 core_util_critical_section_enter(); 00029 remove(); 00030 // unlocked only if we were attached (we locked it) and this is not low power ticker 00031 if (_function && _lock_deepsleep) { 00032 sleep_manager_unlock_deep_sleep(); 00033 } 00034 00035 _function = 0; 00036 core_util_critical_section_exit(); 00037 } 00038 00039 void Ticker::setup(us_timestamp_t t) 00040 { 00041 core_util_critical_section_enter(); 00042 remove(); 00043 _delay = t; 00044 insert_absolute(_delay + ticker_read_us(_ticker_data)); 00045 core_util_critical_section_exit(); 00046 } 00047 00048 void Ticker::handler() 00049 { 00050 insert_absolute(event.timestamp + _delay); 00051 if (_function) { 00052 _function(); 00053 } 00054 } 00055 00056 void Ticker::attach_us(Callback<void()> func, us_timestamp_t t) 00057 { 00058 core_util_critical_section_enter(); 00059 // lock only for the initial callback setup and this is not low power ticker 00060 if (!_function && _lock_deepsleep) { 00061 sleep_manager_lock_deep_sleep(); 00062 } 00063 _function = func; 00064 setup(t); 00065 core_util_critical_section_exit(); 00066 } 00067 00068 } // namespace mbed
Generated on Tue Jul 12 2022 20:41:16 by 1.7.2