1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-10-15 11:26:40 +03:00

Added general yield()-hook for cooperative scheduling development

This commit is contained in:
Cristian Maglie
2012-10-31 01:37:37 +01:00
parent cf4d72c043
commit 107c1929bd
9 changed files with 49 additions and 30 deletions

View File

@@ -122,12 +122,6 @@ void yield(void) {
coopDoYield(cur);
}
void wait(uint32_t ms) {
uint32_t start = millis();
while (millis() - start < ms)
yield();
}
}; // extern "C"
SchedulerClass::SchedulerClass() {

View File

@@ -22,9 +22,6 @@
extern "C" {
typedef void (*SchedulerTask)(void);
typedef void (*SchedulerParametricTask)(void *);
void wait(uint32_t ms);
void yield();
}
class SchedulerClass {
@@ -34,7 +31,6 @@ public:
static void start(SchedulerTask task, uint32_t stackSize = 1024);
static void start(SchedulerParametricTask task, void *data, uint32_t stackSize = 1024);
static void wait(uint32_t ms) { ::wait(ms); };
static void yield() { ::yield(); };
};

View File

@@ -14,10 +14,8 @@
This example code is in the public domain
http://arduino.cc/en/Tutorial/MultipleBlinks
*/
// Include Scheduler since we want to manage multiple tasks.
#include <Scheduler.h>
@@ -44,21 +42,20 @@ void loop() {
digitalWrite(led1, HIGH);
// IMPORTANT:
// We must use 'wait' instead of 'delay' to guarantee
// that the other tasks get executed.
// ('wait' passes control to other tasks while waiting)
wait(1000);
// When multiple tasks are running 'delay' passes control to
// other tasks while waiting and guarantees they get executed.
delay(1000);
digitalWrite(led1, LOW);
wait(1000);
delay(1000);
}
// Task no.2: blink LED with 0.1 second delay.
void loop2() {
digitalWrite(led2, HIGH);
wait(100);
delay(100);
digitalWrite(led2, LOW);
wait(100);
delay(100);
}
// Task no.3: accept commands from Serial port

View File

@@ -12,8 +12,6 @@ Scheduler KEYWORD1
# Methods and Functions (KEYWORD2)
#######################################
yield KEYWORD2
wait KEYWORD2
startLoop KEYWORD2
#######################################