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
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 true 00079 }; 00080 00081 void lp_ticker_wrapper_irq_handler(ticker_irq_handler_type handler) 00082 { 00083 core_util_critical_section_enter(); 00084 00085 if (!init) { 00086 // Force ticker to initialize 00087 get_lp_ticker_data(); 00088 } 00089 00090 ticker_wrapper->irq_handler(handler); 00091 00092 core_util_critical_section_exit(); 00093 } 00094 00095 const ticker_data_t *get_lp_ticker_wrapper_data(const ticker_data_t *data) 00096 { 00097 core_util_critical_section_enter(); 00098 00099 if (!init) { 00100 ticker_wrapper = new (ticker_wrapper_data) LowPowerTickerWrapper(data, &lp_interface, LPTICKER_DELAY_TICKS, LPTICKER_DELAY_TICKS); 00101 init = true; 00102 } 00103 00104 core_util_critical_section_exit(); 00105 00106 return &ticker_wrapper->data; 00107 } 00108 00109 void lp_ticker_wrapper_suspend() 00110 { 00111 if (!init) { 00112 // Force ticker to initialize 00113 get_lp_ticker_data(); 00114 } 00115 00116 ticker_wrapper->suspend(); 00117 } 00118 00119 void lp_ticker_wrapper_resume() 00120 { 00121 if (!init) { 00122 // Force ticker to initialize 00123 get_lp_ticker_data(); 00124 } 00125 00126 ticker_wrapper->resume(); 00127 } 00128 00129 #endif
Generated on Tue Jul 12 2022 13:54:33 by
