arduino`yield()`函数的秘诀是什么? [英] What is the secret of the arduino `yield()`function?

查看:920
本文介绍了arduino`yield()`函数的秘诀是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Arduino文档在 https://www.arduino.cc/en/上解释yield()参考/计划程序有关到期"的信息.显然,它是Scheduler库的一部分:

The Arduino docs explain yield() at https://www.arduino.cc/en/Reference/Scheduler with regards to the Due. Apparently it is part of the Scheduler library:

#include <Scheduler.h>

但是,我可以在不包含Scheduler lib的情况下在Nano或ESP8266上调用yield(),但只能在主程序中进行,而不能在include文件中进行.另外,包含内容不适用于我的非Dues.

However, I can call yield() on my Nano or ESP8266 without including the Scheduler lib -- but only in my main program, not inside include files. Also, the include does not work on my non-Dues.

yield()我缺少的秘密是什么?-yield()在Due以外的Arduino平台上有什么作用?

What's the secret that I'm missing about yield() or- what does yield() do on Arduino platforms other than Due?

推荐答案

但是,我可以在Nano或ESP8266上调用yield()而不包括 调度程序库

However, I can call yield() on my Nano or ESP8266 without including the Scheduler lib

yield()函数也在 ESP8266 库中实现:

屈服

这是ESP8266与 更经典的Arduino微控制器. ESP8266运行很多 实用程序功能在后台–保持WiFi连接,管理 TCP/IP堆栈,并执行其他职责.阻止这些 运行中的功能可能会导致ESP8266崩溃并重置 本身.为避免这些神秘的重置,请避免较长的阻塞循环 在您的草图中.

This is one of the most critical differences between the ESP8266 and a more classical Arduino microcontroller. The ESP8266 runs a lot of utility functions in the background – keeping WiFi connected, managing the TCP/IP stack, and performing other duties. Blocking these functions from running can cause the ESP8266 to crash and reset itself. To avoid these mysterious resets, avoid long, blocking loops in your sketch.

ESP8266 Arduino库的惊人创造者也实现了 yield()函数,该函数调用后台函数以允许 他们去做自己的事情.

The amazing creators of the ESP8266 Arduino libraries also implemented a yield() function, which calls on the background functions to allow them to do their things.

这就是为什么您可以在包含ESP8266标头的主程序中调用yield()的原因.

That's why you can call yield() from within your main program where the ESP8266 header is included.

请参见 ESP8266事物连接指南.

更新:

yield()在Arduino.h中定义为:

yield() is defined in Arduino.h as:

void yield(void);

yield()也在hooks.h中声明如下:

/**
 * Empty yield() hook.
 *
 * This function is intended to be used by library writers to build
 * libraries or sketches that supports cooperative threads.
 *
 * Its defined as a weak symbol and it can be redefined to implement a
 * real cooperative scheduler.
 */
static void __empty() {
    // Empty
}
void yield(void) __attribute__ ((weak, alias("__empty")));

因此,在Nano上,它可能什么也不做(除非您有其他库#included).

So, on the Nano, it probably does nothing (unless you have other libraries #included).

这篇关于arduino`yield()`函数的秘诀是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆