mirror of
https://github.com/arduino/Arduino.git
synced 2025-03-13 10:29:35 +01:00
Removed copy of Scheduler lib, available through lib manager
This commit is contained in:
parent
69e03275d6
commit
36b7701402
@ -1,22 +0,0 @@
|
||||
= Scheduler Library for Arduino =
|
||||
|
||||
The Scheduler library enables the Arduino Due to run multiple functions at the same time. This allows tasks to happen without interrupting each other.
|
||||
|
||||
For more information about this library please visit us at
|
||||
http://www.arduino.cc/en/Reference/Scheduler
|
||||
|
||||
== License ==
|
||||
|
||||
Copyright (c) 2012 The Android Open Source Project. All right reserved.
|
||||
|
||||
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.
|
@ -1,81 +0,0 @@
|
||||
/*
|
||||
Multiple Blinks
|
||||
|
||||
Demonstrates the use of the Scheduler library for the Arduino Due
|
||||
|
||||
Hardware required :
|
||||
* LEDs connected to pins 11, 12, and 13
|
||||
|
||||
created 8 Oct 2012
|
||||
by Cristian Maglie
|
||||
Modified by
|
||||
Scott Fitzgerald 19 Oct 2012
|
||||
|
||||
This example code is in the public domain
|
||||
|
||||
http://www.arduino.cc/en/Tutorial/MultipleBlinks
|
||||
*/
|
||||
|
||||
// Include Scheduler since we want to manage multiple tasks.
|
||||
#include <Scheduler.h>
|
||||
|
||||
int led1 = 13;
|
||||
int led2 = 12;
|
||||
int led3 = 11;
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
|
||||
// Setup the 3 pins as OUTPUT
|
||||
pinMode(led1, OUTPUT);
|
||||
pinMode(led2, OUTPUT);
|
||||
pinMode(led3, OUTPUT);
|
||||
|
||||
// Add "loop2" and "loop3" to scheduling.
|
||||
// "loop" is always started by default.
|
||||
Scheduler.startLoop(loop2);
|
||||
Scheduler.startLoop(loop3);
|
||||
}
|
||||
|
||||
// Task no.1: blink LED with 1 second delay.
|
||||
void loop() {
|
||||
digitalWrite(led1, HIGH);
|
||||
|
||||
// IMPORTANT:
|
||||
// When multiple tasks are running 'delay' passes control to
|
||||
// other tasks while waiting and guarantees they get executed.
|
||||
delay(1000);
|
||||
|
||||
digitalWrite(led1, LOW);
|
||||
delay(1000);
|
||||
}
|
||||
|
||||
// Task no.2: blink LED with 0.1 second delay.
|
||||
void loop2() {
|
||||
digitalWrite(led2, HIGH);
|
||||
delay(100);
|
||||
digitalWrite(led2, LOW);
|
||||
delay(100);
|
||||
}
|
||||
|
||||
// Task no.3: accept commands from Serial port
|
||||
// '0' turns off LED
|
||||
// '1' turns on LED
|
||||
void loop3() {
|
||||
if (Serial.available()) {
|
||||
char c = Serial.read();
|
||||
if (c == '0') {
|
||||
digitalWrite(led3, LOW);
|
||||
Serial.println("Led turned off!");
|
||||
}
|
||||
if (c == '1') {
|
||||
digitalWrite(led3, HIGH);
|
||||
Serial.println("Led turned on!");
|
||||
}
|
||||
}
|
||||
|
||||
// IMPORTANT:
|
||||
// We must call 'yield' at a regular basis to pass
|
||||
// control to other tasks.
|
||||
yield();
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
#######################################
|
||||
# Syntax Coloring Map For Scheduler
|
||||
#######################################
|
||||
|
||||
#######################################
|
||||
# Datatypes (KEYWORD1)
|
||||
#######################################
|
||||
|
||||
Scheduler KEYWORD1 Scheduler
|
||||
|
||||
#######################################
|
||||
# Methods and Functions (KEYWORD2)
|
||||
#######################################
|
||||
|
||||
startLoop KEYWORD2
|
||||
|
||||
#######################################
|
||||
# Constants (LITERAL1)
|
||||
#######################################
|
||||
|
@ -1,9 +0,0 @@
|
||||
name=Scheduler
|
||||
version=0.4.4
|
||||
author=Arduino
|
||||
maintainer=Arduino <info@arduino.cc>
|
||||
sentence=Allows multiple tasks to run at the same time, without interrupting each other. For Arduino sam and samd architectures only (Due, Zero...).
|
||||
paragraph=The Scheduler library enables the Arduino to run multiple functions at the same time. This allows tasks to happen without interrupting each other.</br>This is a cooperative scheduler in that the CPU switches from one task to another. The library includes methods for passing control between tasks.
|
||||
category=Other
|
||||
url=http://www.arduino.cc/en/Reference/Scheduler
|
||||
architectures=sam,samd
|
@ -1,208 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2012 The Android Open Source Project
|
||||
*
|
||||
* 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 "Scheduler.h"
|
||||
|
||||
extern "C" {
|
||||
|
||||
#define NUM_REGS 10 // r4-r11, sp, pc
|
||||
|
||||
typedef struct CoopTask {
|
||||
uint32_t regs[NUM_REGS];
|
||||
void* stackPtr;
|
||||
struct CoopTask* next;
|
||||
struct CoopTask* prev;
|
||||
} CoopTask;
|
||||
|
||||
static CoopTask *cur = 0;
|
||||
|
||||
static CoopTask* __attribute__((noinline)) coopSchedule(char taskDied) {
|
||||
CoopTask* next = cur->next;
|
||||
|
||||
if (taskDied) {
|
||||
// Halt if last task died.
|
||||
if (next == cur)
|
||||
while (1)
|
||||
;
|
||||
|
||||
// Delete task
|
||||
if (cur->stackPtr)
|
||||
free(cur->stackPtr);
|
||||
cur->next->prev = cur->prev;
|
||||
cur->prev->next = cur->next;
|
||||
free(cur);
|
||||
}
|
||||
cur = next;
|
||||
return next;
|
||||
}
|
||||
|
||||
static void __attribute__((naked)) __attribute__((noinline)) coopTaskStart(void) {
|
||||
asm (
|
||||
"mov r0, r5;"
|
||||
"blx r4;"
|
||||
/* schedule. */
|
||||
"mov r0, #1;" /* returned from task func: task done */
|
||||
"bl coopSchedule;"
|
||||
/* r0 holds address of next task context */
|
||||
#if defined(ARDUINO_ARCH_SAMD)
|
||||
/* for cortex m0, ldm and stm are restricted to low registers */
|
||||
/* load high registers */
|
||||
"add r0, #16;" /* they are 4 words higher in memory */
|
||||
"ldmia r0, {r1-r6};" /* load them in low registers first... */
|
||||
"mov r8, r1;" /* ...and move them into high registers... */
|
||||
"mov r9, r2;"
|
||||
"mov r10, r3;"
|
||||
"mov r11, r4;"
|
||||
"mov r12, r5;"
|
||||
"mov lr, r6;"
|
||||
/* load low registers */
|
||||
"sub r0, r0, #40;" /* back to begin of context */
|
||||
"ldmia r0, {r4-r7};"
|
||||
#else
|
||||
"ldmia r0, {r4-r12, lr};"
|
||||
#endif
|
||||
/* restore task stack */
|
||||
"mov sp, r12;"
|
||||
/* resume task */
|
||||
"bx lr;"
|
||||
);
|
||||
}
|
||||
|
||||
static void __attribute__((naked)) __attribute__((noinline)) coopDoYield(CoopTask* curTask) {
|
||||
asm (
|
||||
"mov r12, sp;"
|
||||
#if defined(ARDUINO_ARCH_SAMD)
|
||||
/* store low registers */
|
||||
"stmia r0, {r4-r7};"
|
||||
/* store high registers */
|
||||
"mov r1, r8;" /* move them to low registers first. */
|
||||
"mov r2, r9;"
|
||||
"mov r3, r10;"
|
||||
"mov r4, r11;"
|
||||
"mov r5, r12;"
|
||||
"mov r6, lr;"
|
||||
"stmia r0, {r1-r6};"
|
||||
#else
|
||||
"stmia r0, {r4-r12, lr};"
|
||||
#endif
|
||||
/* schedule. */
|
||||
"mov r0, #0;" /* previous task did not complete */
|
||||
"bl coopSchedule;"
|
||||
/* r0 holds address of next task context */
|
||||
#if defined(ARDUINO_ARCH_SAMD)
|
||||
/* for cortex m0, ldm and stm are restricted to low registers */
|
||||
/* load high registers */
|
||||
"add r0, #16;" /* they are 4 words higher in memory */
|
||||
"ldmia r0, {r1-r6};" /* load them in low registers first... */
|
||||
"mov r8, r1;" /* ...and move them into high registers... */
|
||||
"mov r9, r2;"
|
||||
"mov r10, r3;"
|
||||
"mov r11, r4;"
|
||||
"mov r12, r5;"
|
||||
"mov lr, r6;"
|
||||
/* load low registers */
|
||||
"sub r0, r0, #40;" /* back to begin of context */
|
||||
"ldmia r0, {r4-r7};"
|
||||
#else
|
||||
"ldmia r0, {r4-r12, lr};"
|
||||
#endif
|
||||
/* restore task stack */
|
||||
"mov sp, r12;"
|
||||
/* resume task */
|
||||
"bx lr;"
|
||||
);
|
||||
}
|
||||
|
||||
static int coopInit(void) {
|
||||
CoopTask* task;
|
||||
|
||||
task = reinterpret_cast<CoopTask *>(malloc(sizeof(CoopTask)));
|
||||
if (!task)
|
||||
return 0;
|
||||
task->next = task;
|
||||
task->prev = task;
|
||||
task->stackPtr = 0;
|
||||
cur = task;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int coopSpawn(SchedulerParametricTask taskF, void* taskData, uint32_t stackSz) {
|
||||
uint8_t *stack = (uint8_t*)malloc(stackSz);
|
||||
if (!stack)
|
||||
return 0;
|
||||
|
||||
CoopTask *task = reinterpret_cast<CoopTask *>(malloc(sizeof(CoopTask)));
|
||||
if (!task) {
|
||||
free(stack);
|
||||
return 0;
|
||||
}
|
||||
task->stackPtr = stack;
|
||||
task->regs[0] = (uint32_t) taskF;
|
||||
task->regs[1] = (uint32_t) taskData;
|
||||
task->regs[8] = ((uint32_t)(stack + stackSz)) & ~7;
|
||||
task->regs[9] = (uint32_t) & coopTaskStart;
|
||||
|
||||
task->prev = cur;
|
||||
task->next = cur->next;
|
||||
cur->next->prev = task;
|
||||
cur->next = task;
|
||||
|
||||
// These are here so compiler is sure that function is
|
||||
// referenced in both variants (cancels a warning)
|
||||
if (stackSz == 0xFFFFFFFF)
|
||||
coopSchedule(0);
|
||||
if (stackSz == 0xFFFFFFFE)
|
||||
coopSchedule(1);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
void yield(void) {
|
||||
coopDoYield(cur);
|
||||
}
|
||||
|
||||
}; // extern "C"
|
||||
|
||||
SchedulerClass::SchedulerClass() {
|
||||
coopInit();
|
||||
}
|
||||
|
||||
static void startLoopHelper(void *taskData) {
|
||||
SchedulerTask task = reinterpret_cast<SchedulerTask>(taskData);
|
||||
while (true)
|
||||
task();
|
||||
}
|
||||
|
||||
void SchedulerClass::startLoop(SchedulerTask task, uint32_t stackSize) {
|
||||
coopSpawn(startLoopHelper, reinterpret_cast<void *>(task), stackSize);
|
||||
}
|
||||
|
||||
static void startTaskHelper(void *taskData) {
|
||||
SchedulerTask task = reinterpret_cast<SchedulerTask>(taskData);
|
||||
task();
|
||||
}
|
||||
|
||||
void SchedulerClass::start(SchedulerTask task, uint32_t stackSize) {
|
||||
coopSpawn(startTaskHelper, reinterpret_cast<void *>(task), stackSize);
|
||||
}
|
||||
|
||||
void SchedulerClass::start(SchedulerParametricTask task, void *taskData, uint32_t stackSize) {
|
||||
coopSpawn(task, taskData, stackSize);
|
||||
}
|
||||
|
||||
SchedulerClass Scheduler;
|
||||
|
@ -1,40 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2012 The Android Open Source Project
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef _SCHEDULER_H_
|
||||
#define _SCHEDULER_H_
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
extern "C" {
|
||||
typedef void (*SchedulerTask)(void);
|
||||
typedef void (*SchedulerParametricTask)(void *);
|
||||
}
|
||||
|
||||
class SchedulerClass {
|
||||
public:
|
||||
SchedulerClass();
|
||||
static void startLoop(SchedulerTask task, uint32_t stackSize = 1024);
|
||||
static void start(SchedulerTask task, uint32_t stackSize = 1024);
|
||||
static void start(SchedulerParametricTask task, void *data, uint32_t stackSize = 1024);
|
||||
|
||||
static void yield() { ::yield(); };
|
||||
};
|
||||
|
||||
extern SchedulerClass Scheduler;
|
||||
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user