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

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

问题描述

Arduino 文档在 https://www 上解释了 yield().arduino.cc/en/Reference/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>

但是,我可以在我的 Nano 或 ESP8266 上调用 yield() 而不包含调度程序库——但只能在我的主程序中,而不是在包含文件中.此外,包含不适用于我的非会费.

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 库中实现:

The yield() function is also implemented inside the ESP8266 libraries:

产量

这是 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 中声明如下:

yield() is also declared in hooks.h as follows:

/**
 * 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天全站免登陆