source: asp3_tinet_ecnl_arm/trunk/asp3_dcre/mbed/hal/lp_ticker_api.h@ 374

Last change on this file since 374 was 374, checked in by coas-nagasima, 5 years ago

mbed関連を更新
シリアルドライバをmbedのHALを使うよう変更
ファイルディスクリプタの処理を更新

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