Mbed OS 文档翻译 之 参考(API(驱动(LowPowerTicker)))

LowPowerTicker

                            

                                                                            LowPowerTicker 类层次结构

LowPowerTicker 类与 Ticker 类具有相同的方法,但在深度睡眠模式下运行且分辨率较低。当您只需要毫秒精度时,使用 LowPowerTicker 接口设置重复中断;它以指定的速率重复调用函数。由于 LowPowerTicker 类可以在深度睡眠模式下运行,因此它在激活时不会阻止深度睡眠。

您可以创建任意数量的 LowPowerTicker 对象,同时允许多个未完成的中断。该函数可以是静态函数,特定对象的成员函数或 Callback 对象。

警告和说明

  • ISR 中没有阻塞代码:避免任何调用等待,无限循环或阻塞调用。

  • 在 ISR 中没有 printf,malloc 或 new:避免调用庞大的库函数。特别是,某些库函数(例如 printf,malloc 和 new)不可重入,并且当从 ISR 调用时它们的行为可能会被破坏。

LowPowerTicker 类参考

mbed::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:

main.cpp                                                                                                                                             导入到 Mbed IDE

/* 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);
    }
}
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值