Gime Sillero / Serial_keloke_01_gnuarmeclipse_kl46z

Dependencies:   mbed

Committer:
Gimena
Date:
Fri Nov 01 20:20:14 2019 +0000
Revision:
0:53fdcc368020
PUERTO SERIE

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Gimena 0:53fdcc368020 1
Gimena 0:53fdcc368020 2 /** \addtogroup hal */
Gimena 0:53fdcc368020 3 /** @{*/
Gimena 0:53fdcc368020 4 /* mbed Microcontroller Library
Gimena 0:53fdcc368020 5 * Copyright (c) 2015 ARM Limited
Gimena 0:53fdcc368020 6 * SPDX-License-Identifier: Apache-2.0
Gimena 0:53fdcc368020 7 *
Gimena 0:53fdcc368020 8 * Licensed under the Apache License, Version 2.0 (the "License");
Gimena 0:53fdcc368020 9 * you may not use this file except in compliance with the License.
Gimena 0:53fdcc368020 10 * You may obtain a copy of the License at
Gimena 0:53fdcc368020 11 *
Gimena 0:53fdcc368020 12 * http://www.apache.org/licenses/LICENSE-2.0
Gimena 0:53fdcc368020 13 *
Gimena 0:53fdcc368020 14 * Unless required by applicable law or agreed to in writing, software
Gimena 0:53fdcc368020 15 * distributed under the License is distributed on an "AS IS" BASIS,
Gimena 0:53fdcc368020 16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Gimena 0:53fdcc368020 17 * See the License for the specific language governing permissions and
Gimena 0:53fdcc368020 18 * limitations under the License.
Gimena 0:53fdcc368020 19 */
Gimena 0:53fdcc368020 20 #ifndef MBED_LPTICKER_API_H
Gimena 0:53fdcc368020 21 #define MBED_LPTICKER_API_H
Gimena 0:53fdcc368020 22
Gimena 0:53fdcc368020 23 #include "device.h"
Gimena 0:53fdcc368020 24
Gimena 0:53fdcc368020 25 #if DEVICE_LPTICKER
Gimena 0:53fdcc368020 26
Gimena 0:53fdcc368020 27 #include "hal/ticker_api.h"
Gimena 0:53fdcc368020 28
Gimena 0:53fdcc368020 29 #ifdef __cplusplus
Gimena 0:53fdcc368020 30 extern "C" {
Gimena 0:53fdcc368020 31 #endif
Gimena 0:53fdcc368020 32
Gimena 0:53fdcc368020 33 /**
Gimena 0:53fdcc368020 34 * \defgroup hal_lp_ticker Low Power Ticker
Gimena 0:53fdcc368020 35 * Low level interface to the low power ticker of a target
Gimena 0:53fdcc368020 36 *
Gimena 0:53fdcc368020 37 * # Defined behavior
Gimena 0:53fdcc368020 38 * * Has a reported frequency between 4KHz and 64KHz - verified by ::lp_ticker_info_test
Gimena 0:53fdcc368020 39 * * Has a counter that is at least 12 bits wide - verified by ::lp_ticker_info_test
Gimena 0:53fdcc368020 40 * * Continues operating in deep sleep mode - verified by ::lp_ticker_deepsleep_test
Gimena 0:53fdcc368020 41 * * All behavior defined by the @ref hal_ticker_shared "ticker specification"
Gimena 0:53fdcc368020 42 *
Gimena 0:53fdcc368020 43 * # Undefined behavior
Gimena 0:53fdcc368020 44 * * See the @ref hal_ticker_shared "ticker specification"
Gimena 0:53fdcc368020 45 * * Calling any function other than lp_ticker_init after calling lp_ticker_free
Gimena 0:53fdcc368020 46 *
Gimena 0:53fdcc368020 47 * # Potential bugs
Gimena 0:53fdcc368020 48 * * Glitches due to ripple counter - Verified by ::lp_ticker_glitch_test
Gimena 0:53fdcc368020 49 *
Gimena 0:53fdcc368020 50 * @see hal_lp_ticker_tests
Gimena 0:53fdcc368020 51 *
Gimena 0:53fdcc368020 52 * @{
Gimena 0:53fdcc368020 53 */
Gimena 0:53fdcc368020 54
Gimena 0:53fdcc368020 55 /**
Gimena 0:53fdcc368020 56 * \defgroup hal_lp_ticker_tests Low Power Ticker tests
Gimena 0:53fdcc368020 57 * Tests to validate the proper implementation of the low power ticker
Gimena 0:53fdcc368020 58 *
Gimena 0:53fdcc368020 59 * To run the low power ticker hal tests use the command:
Gimena 0:53fdcc368020 60 *
Gimena 0:53fdcc368020 61 * mbed test -t <toolchain> -m <target> -n tests-mbed_hal-common_ticker*,tests-mbed_hal-lp_ticker*
Gimena 0:53fdcc368020 62 *
Gimena 0:53fdcc368020 63 */
Gimena 0:53fdcc368020 64
Gimena 0:53fdcc368020 65 typedef void (*ticker_irq_handler_type)(const ticker_data_t *const);
Gimena 0:53fdcc368020 66
Gimena 0:53fdcc368020 67 /** Set low power ticker IRQ handler
Gimena 0:53fdcc368020 68 *
Gimena 0:53fdcc368020 69 * @param ticker_irq_handler IRQ handler to be connected
Gimena 0:53fdcc368020 70 *
Gimena 0:53fdcc368020 71 * @return previous ticker IRQ handler
Gimena 0:53fdcc368020 72 *
Gimena 0:53fdcc368020 73 * @note by default IRQ handler is set to ::ticker_irq_handler
Gimena 0:53fdcc368020 74 * @note this function is primarily for testing purposes and it's not required part of HAL implementation
Gimena 0:53fdcc368020 75 *
Gimena 0:53fdcc368020 76 */
Gimena 0:53fdcc368020 77 ticker_irq_handler_type set_lp_ticker_irq_handler(ticker_irq_handler_type ticker_irq_handler);
Gimena 0:53fdcc368020 78
Gimena 0:53fdcc368020 79 /** Get low power ticker's data
Gimena 0:53fdcc368020 80 *
Gimena 0:53fdcc368020 81 * @return The low power ticker data
Gimena 0:53fdcc368020 82 */
Gimena 0:53fdcc368020 83 const ticker_data_t *get_lp_ticker_data(void);
Gimena 0:53fdcc368020 84
Gimena 0:53fdcc368020 85 /** The wrapper for ticker_irq_handler, to pass lp ticker's data
Gimena 0:53fdcc368020 86 *
Gimena 0:53fdcc368020 87 */
Gimena 0:53fdcc368020 88 void lp_ticker_irq_handler(void);
Gimena 0:53fdcc368020 89
Gimena 0:53fdcc368020 90 /* HAL lp ticker */
Gimena 0:53fdcc368020 91
Gimena 0:53fdcc368020 92 /** Initialize the low power ticker
Gimena 0:53fdcc368020 93 *
Gimena 0:53fdcc368020 94 * Initialize or re-initialize the ticker. This resets all the
Gimena 0:53fdcc368020 95 * clocking and prescaler registers, along with disabling
Gimena 0:53fdcc368020 96 * the compare interrupt.
Gimena 0:53fdcc368020 97 *
Gimena 0:53fdcc368020 98 * Pseudo Code:
Gimena 0:53fdcc368020 99 * @code
Gimena 0:53fdcc368020 100 * void lp_ticker_init()
Gimena 0:53fdcc368020 101 * {
Gimena 0:53fdcc368020 102 * // Enable clock gate so processor can read LPTMR registers
Gimena 0:53fdcc368020 103 * POWER_CTRL |= POWER_CTRL_LPTMR_Msk;
Gimena 0:53fdcc368020 104 *
Gimena 0:53fdcc368020 105 * // Disable the timer and ensure it is powered down
Gimena 0:53fdcc368020 106 * LPTMR_CTRL &= ~(LPTMR_CTRL_ENABLE_Msk | LPTMR_CTRL_COMPARE_ENABLE_Msk);
Gimena 0:53fdcc368020 107 *
Gimena 0:53fdcc368020 108 * // Configure divisors - no division necessary
Gimena 0:53fdcc368020 109 * LPTMR_PRESCALE = 0;
Gimena 0:53fdcc368020 110 * LPTMR_CTRL |= LPTMR_CTRL_ENABLE_Msk;
Gimena 0:53fdcc368020 111 *
Gimena 0:53fdcc368020 112 * // Install the interrupt handler
Gimena 0:53fdcc368020 113 * NVIC_SetVector(LPTMR_IRQn, (uint32_t)lp_ticker_irq_handler);
Gimena 0:53fdcc368020 114 * NVIC_EnableIRQ(LPTMR_IRQn);
Gimena 0:53fdcc368020 115 * }
Gimena 0:53fdcc368020 116 * @endcode
Gimena 0:53fdcc368020 117 */
Gimena 0:53fdcc368020 118 void lp_ticker_init(void);
Gimena 0:53fdcc368020 119
Gimena 0:53fdcc368020 120 /** Deinitialize the lower power ticker
Gimena 0:53fdcc368020 121 *
Gimena 0:53fdcc368020 122 * Powerdown the lp ticker in preparation for sleep, powerdown, or reset.
Gimena 0:53fdcc368020 123 *
Gimena 0:53fdcc368020 124 * After calling this function no other ticker functions should be called except
Gimena 0:53fdcc368020 125 * lp_ticker_init(). Calling any function other than init after freeing is
Gimena 0:53fdcc368020 126 * undefined.
Gimena 0:53fdcc368020 127 *
Gimena 0:53fdcc368020 128 * @note This function stops the ticker from counting.
Gimena 0:53fdcc368020 129 */
Gimena 0:53fdcc368020 130 void lp_ticker_free(void);
Gimena 0:53fdcc368020 131
Gimena 0:53fdcc368020 132 /** Read the current tick
Gimena 0:53fdcc368020 133 *
Gimena 0:53fdcc368020 134 * If no rollover has occurred, the seconds passed since lp_ticker_init()
Gimena 0:53fdcc368020 135 * was called can be found by dividing the ticks returned by this function
Gimena 0:53fdcc368020 136 * by the frequency returned by ::lp_ticker_get_info.
Gimena 0:53fdcc368020 137 *
Gimena 0:53fdcc368020 138 * @return The current timer's counter value in ticks
Gimena 0:53fdcc368020 139 *
Gimena 0:53fdcc368020 140 * Pseudo Code:
Gimena 0:53fdcc368020 141 * @code
Gimena 0:53fdcc368020 142 * uint32_t lp_ticker_read()
Gimena 0:53fdcc368020 143 * {
Gimena 0:53fdcc368020 144 * uint16_t count;
Gimena 0:53fdcc368020 145 * uint16_t last_count;
Gimena 0:53fdcc368020 146 *
Gimena 0:53fdcc368020 147 * // Loop until the same tick is read twice since this
Gimena 0:53fdcc368020 148 * // is ripple counter on a different clock domain.
Gimena 0:53fdcc368020 149 * count = LPTMR_COUNT;
Gimena 0:53fdcc368020 150 * do {
Gimena 0:53fdcc368020 151 * last_count = count;
Gimena 0:53fdcc368020 152 * count = LPTMR_COUNT;
Gimena 0:53fdcc368020 153 * } while (last_count != count);
Gimena 0:53fdcc368020 154 *
Gimena 0:53fdcc368020 155 * return count;
Gimena 0:53fdcc368020 156 * }
Gimena 0:53fdcc368020 157 * @endcode
Gimena 0:53fdcc368020 158 */
Gimena 0:53fdcc368020 159 uint32_t lp_ticker_read(void);
Gimena 0:53fdcc368020 160
Gimena 0:53fdcc368020 161 /** Set interrupt for specified timestamp
Gimena 0:53fdcc368020 162 *
Gimena 0:53fdcc368020 163 * @param timestamp The time in ticks to be set
Gimena 0:53fdcc368020 164 *
Gimena 0:53fdcc368020 165 * @note no special handling needs to be done for times in the past
Gimena 0:53fdcc368020 166 * as the common timer code will detect this and call
Gimena 0:53fdcc368020 167 * lp_ticker_fire_interrupt() if this is the case
Gimena 0:53fdcc368020 168 *
Gimena 0:53fdcc368020 169 * @note calling this function with timestamp of more than the supported
Gimena 0:53fdcc368020 170 * number of bits returned by ::lp_ticker_get_info results in undefined
Gimena 0:53fdcc368020 171 * behavior.
Gimena 0:53fdcc368020 172 *
Gimena 0:53fdcc368020 173 * Pseudo Code:
Gimena 0:53fdcc368020 174 * @code
Gimena 0:53fdcc368020 175 * void lp_ticker_set_interrupt(timestamp_t timestamp)
Gimena 0:53fdcc368020 176 * {
Gimena 0:53fdcc368020 177 * LPTMR_COMPARE = timestamp;
Gimena 0:53fdcc368020 178 * LPTMR_CTRL |= LPTMR_CTRL_COMPARE_ENABLE_Msk;
Gimena 0:53fdcc368020 179 * }
Gimena 0:53fdcc368020 180 * @endcode
Gimena 0:53fdcc368020 181 */
Gimena 0:53fdcc368020 182 void lp_ticker_set_interrupt(timestamp_t timestamp);
Gimena 0:53fdcc368020 183
Gimena 0:53fdcc368020 184 /** Disable low power ticker interrupt
Gimena 0:53fdcc368020 185 *
Gimena 0:53fdcc368020 186 * Pseudo Code:
Gimena 0:53fdcc368020 187 * @code
Gimena 0:53fdcc368020 188 * void lp_ticker_disable_interrupt(void)
Gimena 0:53fdcc368020 189 * {
Gimena 0:53fdcc368020 190 * // Disable the compare interrupt
Gimena 0:53fdcc368020 191 * LPTMR_CTRL &= ~LPTMR_CTRL_COMPARE_ENABLE_Msk;
Gimena 0:53fdcc368020 192 * }
Gimena 0:53fdcc368020 193 * @endcode
Gimena 0:53fdcc368020 194 */
Gimena 0:53fdcc368020 195 void lp_ticker_disable_interrupt(void);
Gimena 0:53fdcc368020 196
Gimena 0:53fdcc368020 197 /** Clear the low power ticker interrupt
Gimena 0:53fdcc368020 198 *
Gimena 0:53fdcc368020 199 * Pseudo Code:
Gimena 0:53fdcc368020 200 * @code
Gimena 0:53fdcc368020 201 * void lp_ticker_clear_interrupt(void)
Gimena 0:53fdcc368020 202 * {
Gimena 0:53fdcc368020 203 * // Write to the ICR (interrupt clear register) of the LPTMR
Gimena 0:53fdcc368020 204 * LPTMR_ICR = LPTMR_ICR_COMPARE_Msk;
Gimena 0:53fdcc368020 205 * }
Gimena 0:53fdcc368020 206 * @endcode
Gimena 0:53fdcc368020 207 */
Gimena 0:53fdcc368020 208 void lp_ticker_clear_interrupt(void);
Gimena 0:53fdcc368020 209
Gimena 0:53fdcc368020 210 /** Set pending interrupt that should be fired right away.
Gimena 0:53fdcc368020 211 *
Gimena 0:53fdcc368020 212 * Pseudo Code:
Gimena 0:53fdcc368020 213 * @code
Gimena 0:53fdcc368020 214 * void lp_ticker_fire_interrupt(void)
Gimena 0:53fdcc368020 215 * {
Gimena 0:53fdcc368020 216 * NVIC_SetPendingIRQ(LPTMR_IRQn);
Gimena 0:53fdcc368020 217 * }
Gimena 0:53fdcc368020 218 * @endcode
Gimena 0:53fdcc368020 219 */
Gimena 0:53fdcc368020 220 void lp_ticker_fire_interrupt(void);
Gimena 0:53fdcc368020 221
Gimena 0:53fdcc368020 222 /** Get frequency and counter bits of this ticker.
Gimena 0:53fdcc368020 223 *
Gimena 0:53fdcc368020 224 * Pseudo Code:
Gimena 0:53fdcc368020 225 * @code
Gimena 0:53fdcc368020 226 * const ticker_info_t* lp_ticker_get_info()
Gimena 0:53fdcc368020 227 * {
Gimena 0:53fdcc368020 228 * static const ticker_info_t info = {
Gimena 0:53fdcc368020 229 * 32768, // 32KHz
Gimena 0:53fdcc368020 230 * 16 // 16 bit counter
Gimena 0:53fdcc368020 231 * };
Gimena 0:53fdcc368020 232 * return &info;
Gimena 0:53fdcc368020 233 * }
Gimena 0:53fdcc368020 234 * @endcode
Gimena 0:53fdcc368020 235 */
Gimena 0:53fdcc368020 236 const ticker_info_t *lp_ticker_get_info(void);
Gimena 0:53fdcc368020 237
Gimena 0:53fdcc368020 238 /**@}*/
Gimena 0:53fdcc368020 239
Gimena 0:53fdcc368020 240 #ifdef __cplusplus
Gimena 0:53fdcc368020 241 }
Gimena 0:53fdcc368020 242 #endif
Gimena 0:53fdcc368020 243
Gimena 0:53fdcc368020 244 #endif
Gimena 0:53fdcc368020 245
Gimena 0:53fdcc368020 246 #endif
Gimena 0:53fdcc368020 247
Gimena 0:53fdcc368020 248 /** @}*/