arduino yield函数的作用,arduino`yield()`函数的秘密是什么?

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

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.

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

解决方案However, I can call yield() on my Nano or ESP8266 without including

the Scheduler lib

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

Yielding

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.

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.

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

Update:

yield() is defined in Arduino.h as:

void yield(void);

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")));

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值