mbed library sources. Supersedes mbed-src.
Dependents: Nucleo_Hello_Encoder BLE_iBeaconScan AM1805_DEMO DISCO-F429ZI_ExportTemplate1 ... more
lp_ticker_api.h
00001 00002 /** \addtogroup hal */ 00003 /** @{*/ 00004 /* mbed Microcontroller Library 00005 * Copyright (c) 2015 ARM Limited 00006 * SPDX-License-Identifier: Apache-2.0 00007 * 00008 * Licensed under the Apache License, Version 2.0 (the "License"); 00009 * you may not use this file except in compliance with the License. 00010 * You may obtain a copy of the License at 00011 * 00012 * http://www.apache.org/licenses/LICENSE-2.0 00013 * 00014 * Unless required by applicable law or agreed to in writing, software 00015 * distributed under the License is distributed on an "AS IS" BASIS, 00016 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00017 * See the License for the specific language governing permissions and 00018 * limitations under the License. 00019 */ 00020 #ifndef MBED_LPTICKER_API_H 00021 #define MBED_LPTICKER_API_H 00022 00023 #include "device.h" 00024 00025 #if DEVICE_LPTICKER 00026 00027 #include "hal/ticker_api.h" 00028 00029 #ifdef __cplusplus 00030 extern "C" { 00031 #endif 00032 00033 /** 00034 * \defgroup hal_lp_ticker Low Power Ticker 00035 * Low level interface to the low power ticker of a target 00036 * 00037 * # Defined behavior 00038 * * Has a reported frequency between 4KHz and 64KHz - verified by ::lp_ticker_info_test 00039 * * Has a counter that is at least 12 bits wide - verified by ::lp_ticker_info_test 00040 * * Continues operating in deep sleep mode - verified by ::lp_ticker_deepsleep_test 00041 * * All behavior defined by the @ref hal_ticker_shared "ticker specification" 00042 * 00043 * # Undefined behavior 00044 * * See the @ref hal_ticker_shared "ticker specification" 00045 * * Calling any function other than lp_ticker_init after calling lp_ticker_free 00046 * 00047 * # Potential bugs 00048 * * Glitches due to ripple counter - Verified by ::lp_ticker_glitch_test 00049 * 00050 * @see hal_lp_ticker_tests 00051 * 00052 * @{ 00053 */ 00054 00055 /** 00056 * \defgroup hal_lp_ticker_tests Low Power Ticker tests 00057 * Tests to validate the proper implementation of the low power ticker 00058 * 00059 * To run the low power ticker hal tests use the command: 00060 * 00061 * mbed test -t <toolchain> -m <target> -n tests-mbed_hal-common_ticker*,tests-mbed_hal-lp_ticker* 00062 * 00063 */ 00064 00065 typedef void (*ticker_irq_handler_type)(const ticker_data_t *const); 00066 00067 /** Set low power ticker IRQ handler 00068 * 00069 * @param ticker_irq_handler IRQ handler to be connected 00070 * 00071 * @return previous ticker IRQ handler 00072 * 00073 * @note by default IRQ handler is set to ::ticker_irq_handler 00074 * @note this function is primarily for testing purposes and it's not required part of HAL implementation 00075 * 00076 */ 00077 ticker_irq_handler_type set_lp_ticker_irq_handler(ticker_irq_handler_type ticker_irq_handler); 00078 00079 /** Get low power ticker's data 00080 * 00081 * @return The low power ticker data 00082 */ 00083 const ticker_data_t *get_lp_ticker_data(void); 00084 00085 /** The wrapper for ticker_irq_handler, to pass lp ticker's data 00086 * 00087 */ 00088 void lp_ticker_irq_handler(void); 00089 00090 /* HAL lp ticker */ 00091 00092 /** Initialize the low power ticker 00093 * 00094 * Initialize or re-initialize the ticker. This resets all the 00095 * clocking and prescaler registers, along with disabling 00096 * the compare interrupt. 00097 * 00098 * Pseudo Code: 00099 * @code 00100 * void lp_ticker_init() 00101 * { 00102 * // Enable clock gate so processor can read LPTMR registers 00103 * POWER_CTRL |= POWER_CTRL_LPTMR_Msk; 00104 * 00105 * // Disable the timer and ensure it is powered down 00106 * LPTMR_CTRL &= ~(LPTMR_CTRL_ENABLE_Msk | LPTMR_CTRL_COMPARE_ENABLE_Msk); 00107 * 00108 * // Configure divisors - no division necessary 00109 * LPTMR_PRESCALE = 0; 00110 * LPTMR_CTRL |= LPTMR_CTRL_ENABLE_Msk; 00111 * 00112 * // Install the interrupt handler 00113 * NVIC_SetVector(LPTMR_IRQn, (uint32_t)lp_ticker_irq_handler); 00114 * NVIC_EnableIRQ(LPTMR_IRQn); 00115 * } 00116 * @endcode 00117 */ 00118 void lp_ticker_init(void); 00119 00120 /** Deinitialize the lower power ticker 00121 * 00122 * Powerdown the lp ticker in preparation for sleep, powerdown, or reset. 00123 * 00124 * After calling this function no other ticker functions should be called except 00125 * lp_ticker_init(). Calling any function other than init after freeing is 00126 * undefined. 00127 * 00128 * @note This function stops the ticker from counting. 00129 */ 00130 void lp_ticker_free(void); 00131 00132 /** Read the current tick 00133 * 00134 * If no rollover has occurred, the seconds passed since lp_ticker_init() 00135 * was called can be found by dividing the ticks returned by this function 00136 * by the frequency returned by ::lp_ticker_get_info. 00137 * 00138 * @return The current timer's counter value in ticks 00139 * 00140 * Pseudo Code: 00141 * @code 00142 * uint32_t lp_ticker_read() 00143 * { 00144 * uint16_t count; 00145 * uint16_t last_count; 00146 * 00147 * // Loop until the same tick is read twice since this 00148 * // is ripple counter on a different clock domain. 00149 * count = LPTMR_COUNT; 00150 * do { 00151 * last_count = count; 00152 * count = LPTMR_COUNT; 00153 * } while (last_count != count); 00154 * 00155 * return count; 00156 * } 00157 * @endcode 00158 */ 00159 uint32_t lp_ticker_read(void); 00160 00161 /** Set interrupt for specified timestamp 00162 * 00163 * @param timestamp The time in ticks to be set 00164 * 00165 * @note no special handling needs to be done for times in the past 00166 * as the common timer code will detect this and call 00167 * lp_ticker_fire_interrupt() if this is the case 00168 * 00169 * @note calling this function with timestamp of more than the supported 00170 * number of bits returned by ::lp_ticker_get_info results in undefined 00171 * behavior. 00172 * 00173 * Pseudo Code: 00174 * @code 00175 * void lp_ticker_set_interrupt(timestamp_t timestamp) 00176 * { 00177 * LPTMR_COMPARE = timestamp; 00178 * LPTMR_CTRL |= LPTMR_CTRL_COMPARE_ENABLE_Msk; 00179 * } 00180 * @endcode 00181 */ 00182 void lp_ticker_set_interrupt(timestamp_t timestamp); 00183 00184 /** Disable low power ticker interrupt 00185 * 00186 * Pseudo Code: 00187 * @code 00188 * void lp_ticker_disable_interrupt(void) 00189 * { 00190 * // Disable the compare interrupt 00191 * LPTMR_CTRL &= ~LPTMR_CTRL_COMPARE_ENABLE_Msk; 00192 * } 00193 * @endcode 00194 */ 00195 void lp_ticker_disable_interrupt(void); 00196 00197 /** Clear the low power ticker interrupt 00198 * 00199 * Pseudo Code: 00200 * @code 00201 * void lp_ticker_clear_interrupt(void) 00202 * { 00203 * // Write to the ICR (interrupt clear register) of the LPTMR 00204 * LPTMR_ICR = LPTMR_ICR_COMPARE_Msk; 00205 * } 00206 * @endcode 00207 */ 00208 void lp_ticker_clear_interrupt(void); 00209 00210 /** Set pending interrupt that should be fired right away. 00211 * 00212 * Pseudo Code: 00213 * @code 00214 * void lp_ticker_fire_interrupt(void) 00215 * { 00216 * NVIC_SetPendingIRQ(LPTMR_IRQn); 00217 * } 00218 * @endcode 00219 */ 00220 void lp_ticker_fire_interrupt(void); 00221 00222 /** Get frequency and counter bits of this ticker. 00223 * 00224 * Pseudo Code: 00225 * @code 00226 * const ticker_info_t* lp_ticker_get_info() 00227 * { 00228 * static const ticker_info_t info = { 00229 * 32768, // 32KHz 00230 * 16 // 16 bit counter 00231 * }; 00232 * return &info; 00233 * } 00234 * @endcode 00235 */ 00236 const ticker_info_t *lp_ticker_get_info(void); 00237 00238 /**@}*/ 00239 00240 #ifdef __cplusplus 00241 } 00242 #endif 00243 00244 #endif 00245 00246 #endif 00247 00248 /** @}*/
Generated on Tue Jul 12 2022 20:41:15 by 1.7.2