mbed library sources. Supersedes mbed-src.
Dependents: Nucleo_Hello_Encoder BLE_iBeaconScan AM1805_DEMO DISCO-F429ZI_ExportTemplate1 ... more
mbed_lp_ticker_wrapper.cpp
00001 /* mbed Microcontroller Library 00002 * Copyright (c) 2018 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 "hal/mbed_lp_ticker_wrapper.h" 00018 00019 #if DEVICE_LPTICKER && (LPTICKER_DELAY_TICKS > 0) 00020 00021 #include "hal/LowPowerTickerWrapper.h" 00022 #include "platform/mbed_critical.h" 00023 00024 // Do not use SingletonPtr since this must be initialized in a critical section 00025 static LowPowerTickerWrapper *ticker_wrapper; 00026 static uint64_t ticker_wrapper_data[(sizeof(LowPowerTickerWrapper) + 7) / 8]; 00027 static bool init = false; 00028 00029 static void lp_ticker_wrapper_init() 00030 { 00031 ticker_wrapper->init(); 00032 } 00033 00034 static uint32_t lp_ticker_wrapper_read() 00035 { 00036 return ticker_wrapper->read(); 00037 } 00038 00039 static void lp_ticker_wrapper_set_interrupt(timestamp_t timestamp) 00040 { 00041 ticker_wrapper->set_interrupt(timestamp); 00042 } 00043 00044 static void lp_ticker_wrapper_disable_interrupt() 00045 { 00046 ticker_wrapper->disable_interrupt(); 00047 } 00048 00049 static void lp_ticker_wrapper_clear_interrupt() 00050 { 00051 ticker_wrapper->clear_interrupt(); 00052 } 00053 00054 static void lp_ticker_wrapper_fire_interrupt() 00055 { 00056 ticker_wrapper->fire_interrupt(); 00057 } 00058 00059 static const ticker_info_t *lp_ticker_wrapper_get_info() 00060 { 00061 return ticker_wrapper->get_info(); 00062 } 00063 00064 static void lp_ticker_wrapper_free() 00065 { 00066 ticker_wrapper->free(); 00067 } 00068 00069 static const ticker_interface_t lp_interface = { 00070 lp_ticker_wrapper_init, 00071 lp_ticker_wrapper_read, 00072 lp_ticker_wrapper_disable_interrupt, 00073 lp_ticker_wrapper_clear_interrupt, 00074 lp_ticker_wrapper_set_interrupt, 00075 lp_ticker_wrapper_fire_interrupt, 00076 lp_ticker_wrapper_free, 00077 lp_ticker_wrapper_get_info 00078 }; 00079 00080 void lp_ticker_wrapper_irq_handler(ticker_irq_handler_type handler) 00081 { 00082 core_util_critical_section_enter(); 00083 00084 if (!init) { 00085 // Force ticker to initialize 00086 get_lp_ticker_data(); 00087 } 00088 00089 ticker_wrapper->irq_handler(handler); 00090 00091 core_util_critical_section_exit(); 00092 } 00093 00094 const ticker_data_t *get_lp_ticker_wrapper_data(const ticker_data_t *data) 00095 { 00096 core_util_critical_section_enter(); 00097 00098 if (!init) { 00099 ticker_wrapper = new (ticker_wrapper_data) LowPowerTickerWrapper(data, &lp_interface, LPTICKER_DELAY_TICKS, LPTICKER_DELAY_TICKS); 00100 init = true; 00101 } 00102 00103 core_util_critical_section_exit(); 00104 00105 return &ticker_wrapper->data; 00106 } 00107 00108 void lp_ticker_wrapper_suspend() 00109 { 00110 if (!init) { 00111 // Force ticker to initialize 00112 get_lp_ticker_data(); 00113 } 00114 00115 ticker_wrapper->suspend(); 00116 } 00117 00118 void lp_ticker_wrapper_resume() 00119 { 00120 if (!init) { 00121 // Force ticker to initialize 00122 get_lp_ticker_data(); 00123 } 00124 00125 ticker_wrapper->resume(); 00126 } 00127 00128 #endif
Generated on Tue Jul 12 2022 20:41:15 by 1.7.2