LowPowerTicker
LowPowerTicker 类层次结构
LowPowerTicker 类与 Ticker 类具有相同的方法,但在深度睡眠模式下运行且分辨率较低。当您只需要毫秒精度时,使用 LowPowerTicker 接口设置重复中断;它以指定的速率重复调用函数。由于 LowPowerTicker 类可以在深度睡眠模式下运行,因此它在激活时不会阻止深度睡眠。
您可以创建任意数量的 LowPowerTicker 对象,同时允许多个未完成的中断。该函数可以是静态函数,特定对象的成员函数或 Callback 对象。
警告和说明
-
ISR 中没有阻塞代码:避免任何调用等待,无限循环或阻塞调用。
-
在 ISR 中没有 printf,malloc 或 new:避免调用庞大的库函数。特别是,某些库函数(例如 printf,malloc 和 new)不可重入,并且当从 ISR 调用时它们的行为可能会被破坏。
LowPowerTicker 类参考
其他继承成员 | |
公共成员函数继承自 mbed::Ticker | |
Ticker (const ticker_data_t *data) | |
void | attach (Callback< void()> func, float t) |
template<typename T , typename M > | |
void | attach (T *obj, M method, float t) |
void | attach_us (Callback< void()> func, us_timestamp_t t) |
template<typename T , typename M > | |
void | attach_us (T *obj, M method, us_timestamp_t t) |
void | detach () |
公共成员函数继承自 mbed::TimerEvent | |
TimerEvent (const ticker_data_t *data) | |
virtual | ~TimerEvent () |
静态公共成员函数继承自 mbed::TimerEvent | |
static void | irq (uint32_t id) |
受保护的成员函数继承自 mbed::Ticker | |
void | setup (us_timestamp_t t) |
virtual void | handler () |
受保护的成员函数继承自 mbed::TimerEvent | |
void | insert (timestamp_t timestamp) |
void | insert_absolute (us_timestamp_t timestamp) |
void | remove () |
受保护的属性继承自 mbed::Ticker | |
us_timestamp_t | _delay |
Callback< void()> | _function |
bool | _lock_deepsleep |
受保护的属性继承自 mbed::TimerEvent | |
ticker_event_t | event |
const ticker_data_t * | _ticker_data |
LowPowerTicker 示例
尝试此程序设置 LowPowerTicker 以重复反转 LED:
/* mbed Example Program
* Copyright (c) 2017-2017 ARM Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "mbed.h"
LowPowerTicker flipper;
DigitalOut led1(LED1);
void flip() {
led1 = !led1;
}
int main() {
led1 = 1;
flipper.attach(&flip, 2.0); // the address of the function to be attached (flip) and the interval (2 seconds)
while(1) {
wait(0.2);
}
}