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.
mbed_lp_ticker_wrapper.cpp
00001 /* mbed Microcontroller Library 00002 * Copyright (c) 2018 ARM Limited 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 #include "hal/mbed_lp_ticker_wrapper.h" 00017 00018 #if DEVICE_LPTICKER && (LPTICKER_DELAY_TICKS > 0) 00019 00020 #include "hal/LowPowerTickerWrapper.h" 00021 #include "platform/mbed_critical.h" 00022 00023 // Do not use SingletonPtr since this must be initialized in a critical section 00024 static LowPowerTickerWrapper *ticker_wrapper; 00025 static uint64_t ticker_wrapper_data[(sizeof(LowPowerTickerWrapper) + 7) / 8]; 00026 static bool init = false; 00027 00028 static void lp_ticker_wrapper_init() 00029 { 00030 ticker_wrapper->init(); 00031 } 00032 00033 static uint32_t lp_ticker_wrapper_read() 00034 { 00035 return ticker_wrapper->read(); 00036 } 00037 00038 static void lp_ticker_wrapper_set_interrupt(timestamp_t timestamp) 00039 { 00040 ticker_wrapper->set_interrupt(timestamp); 00041 } 00042 00043 static void lp_ticker_wrapper_disable_interrupt() 00044 { 00045 ticker_wrapper->disable_interrupt(); 00046 } 00047 00048 static void lp_ticker_wrapper_clear_interrupt() 00049 { 00050 ticker_wrapper->clear_interrupt(); 00051 } 00052 00053 static void lp_ticker_wrapper_fire_interrupt() 00054 { 00055 ticker_wrapper->fire_interrupt(); 00056 } 00057 00058 static const ticker_info_t *lp_ticker_wrapper_get_info() 00059 { 00060 return ticker_wrapper->get_info(); 00061 } 00062 00063 static void lp_ticker_wrapper_free() 00064 { 00065 ticker_wrapper->free(); 00066 } 00067 00068 static const ticker_interface_t lp_interface = { 00069 lp_ticker_wrapper_init, 00070 lp_ticker_wrapper_read, 00071 lp_ticker_wrapper_disable_interrupt, 00072 lp_ticker_wrapper_clear_interrupt, 00073 lp_ticker_wrapper_set_interrupt, 00074 lp_ticker_wrapper_fire_interrupt, 00075 lp_ticker_wrapper_free, 00076 lp_ticker_wrapper_get_info 00077 }; 00078 00079 void lp_ticker_wrapper_irq_handler(ticker_irq_handler_type handler) 00080 { 00081 core_util_critical_section_enter(); 00082 00083 if (!init) { 00084 // Force ticker to initialize 00085 get_lp_ticker_data(); 00086 } 00087 00088 ticker_wrapper->irq_handler(handler); 00089 00090 core_util_critical_section_exit(); 00091 } 00092 00093 const ticker_data_t *get_lp_ticker_wrapper_data(const ticker_data_t *data) 00094 { 00095 core_util_critical_section_enter(); 00096 00097 if (!init) { 00098 ticker_wrapper = new (ticker_wrapper_data) LowPowerTickerWrapper(data, &lp_interface, LPTICKER_DELAY_TICKS, LPTICKER_DELAY_TICKS); 00099 init = true; 00100 } 00101 00102 core_util_critical_section_exit(); 00103 00104 return &ticker_wrapper->data; 00105 } 00106 00107 void lp_ticker_wrapper_suspend() 00108 { 00109 if (!init) { 00110 // Force ticker to initialize 00111 get_lp_ticker_data(); 00112 } 00113 00114 ticker_wrapper->suspend(); 00115 } 00116 00117 void lp_ticker_wrapper_resume() 00118 { 00119 if (!init) { 00120 // Force ticker to initialize 00121 get_lp_ticker_data(); 00122 } 00123 00124 ticker_wrapper->resume(); 00125 } 00126 00127 #endif
Generated on Tue Aug 9 2022 00:37:14 by
