Skip to content

Port Scheduler library to Arduino Zero. #3958

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 28, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions libraries/Scheduler/library.properties
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name=Scheduler
version=0.4.3
version=0.4.4
author=Arduino
maintainer=Arduino <[email protected]>
sentence=Allows multiple tasks to run at the same time, without interrupting each other. For Arduino DUE only.
paragraph=The Scheduler library enables the Arduino Due 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.
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
architectures=sam,samd
57 changes: 55 additions & 2 deletions libraries/Scheduler/src/Scheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,22 +53,75 @@ static void __attribute__((naked)) __attribute__((noinline)) coopTaskStart(void)
asm (
"mov r0, r5;"
"blx r4;"
"mov r0, #1;"
/* 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 */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall this be put inside ifdef too, so we can use the more efficient store instruction when available (without copying the high registers into the 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};"
"mov r0, #0;"
#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;"
);
}
Expand Down