LowPowerTimeout
LowPowerTimeout 类层次结构
使用 LowPowerTimeout 接口设置中断以在指定的延迟后调用函数。您可以创建任意数量的 LowPowerTimeout 对象。这允许同时有多个未完成的中断。有关电源管理的更多信息,请参阅我们的电源管理 API。
注意
- ISR 中没有阻塞代码:避免任何调用等待,无限循环或阻塞调用。
- 在 ISR 中没有 printf,malloc 或 new:避免调用庞大的库函数。特别是,某些库函数(例如 printf,malloc 和 new)不可重入,并且当从 ISR 调用时它们的行为可能会被破坏。
LowPowerTimeout 类参考
其他继承成员 | |
公共成员函数继承自 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) |
受保护的成员函数继承自 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 |
LowPowerTimeout 示例
在给定时间后设置超时 LED 的时间:
/* mbed Example Program
* Copyright (c) 2006-2014 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"
LowPowerTimeout flipper;
DigitalOut led1(LED1);
DigitalOut led2(LED2);
void flip() {
led2 = !led2;
}
int main() {
led2 = 1;
flipper.attach(&flip, 2.0); // setup flipper to call flip after 2 seconds
// spin in a main loop. flipper will interrupt it to call flip
while(1) {
led1 = !led1;
wait(0.2);
}
}