Skip to content

Commit 2294a27

Browse files
Peter Van HoyweghenPeter Van Hoyweghen
Peter Van Hoyweghen
authored and
Peter Van Hoyweghen
committed
Port Scheduler library to Arduino Zero.
1 parent ce1b8f3 commit 2294a27

File tree

2 files changed

+59
-6
lines changed

2 files changed

+59
-6
lines changed

library.properties

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
name=Scheduler
2-
version=0.4.3
2+
version=0.4.4
33
author=Arduino
44
maintainer=Arduino <[email protected]>
5-
sentence=Allows multiple tasks to run at the same time, without interrupting each other. For Arduino DUE only.
6-
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.
5+
sentence=Allows multiple tasks to run at the same time, without interrupting each other. For Arduino sam and samd architectures only (Due, Zero...).
6+
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.
77
category=Other
88
url=http://www.arduino.cc/en/Reference/Scheduler
9-
architectures=sam
9+
architectures=sam,samd

src/Scheduler.cpp

+55-2
Original file line numberDiff line numberDiff line change
@@ -53,22 +53,75 @@ static void __attribute__((naked)) __attribute__((noinline)) coopTaskStart(void)
5353
asm (
5454
"mov r0, r5;"
5555
"blx r4;"
56-
"mov r0, #1;"
56+
/* schedule. */
57+
"mov r0, #1;" /* returned from task func: task done */
5758
"bl coopSchedule;"
59+
/* r0 holds address of next task context */
60+
#if defined(ARDUINO_ARCH_SAMD)
61+
/* for cortex m0, ldm and stm are restricted to low registers */
62+
/* load high registers */
63+
"add r0, #16;" /* they are 4 words higher in memory */
64+
"ldmia r0, {r1-r6};" /* load them in low registers first... */
65+
"mov r8, r1;" /* ...and move them into high registers... */
66+
"mov r9, r2;"
67+
"mov r10, r3;"
68+
"mov r11, r4;"
69+
"mov r12, r5;"
70+
"mov lr, r6;"
71+
/* load low registers */
72+
"sub r0, r0, #40;" /* back to begin of context */
73+
"ldmia r0, {r4-r7};"
74+
#else
5875
"ldmia r0, {r4-r12, lr};"
76+
#endif
77+
/* restore task stack */
5978
"mov sp, r12;"
79+
/* resume task */
6080
"bx lr;"
6181
);
6282
}
6383

6484
static void __attribute__((naked)) __attribute__((noinline)) coopDoYield(CoopTask* curTask) {
6585
asm (
6686
"mov r12, sp;"
87+
#if defined(ARDUINO_ARCH_SAMD)
88+
/* store low registers */
89+
"stmia r0, {r4-r7};"
90+
/* store high registers */
91+
"mov r1, r8;" /* move them to low registers first. */
92+
"mov r2, r9;"
93+
"mov r3, r10;"
94+
"mov r4, r11;"
95+
"mov r5, r12;"
96+
"mov r6, lr;"
97+
"stmia r0, {r1-r6};"
98+
#else
6799
"stmia r0, {r4-r12, lr};"
68-
"mov r0, #0;"
100+
#endif
101+
/* schedule. */
102+
"mov r0, #0;" /* previous task did not complete */
69103
"bl coopSchedule;"
104+
/* r0 holds address of next task context */
105+
#if defined(ARDUINO_ARCH_SAMD)
106+
/* for cortex m0, ldm and stm are restricted to low registers */
107+
/* load high registers */
108+
"add r0, #16;" /* they are 4 words higher in memory */
109+
"ldmia r0, {r1-r6};" /* load them in low registers first... */
110+
"mov r8, r1;" /* ...and move them into high registers... */
111+
"mov r9, r2;"
112+
"mov r10, r3;"
113+
"mov r11, r4;"
114+
"mov r12, r5;"
115+
"mov lr, r6;"
116+
/* load low registers */
117+
"sub r0, r0, #40;" /* back to begin of context */
118+
"ldmia r0, {r4-r7};"
119+
#else
70120
"ldmia r0, {r4-r12, lr};"
121+
#endif
122+
/* restore task stack */
71123
"mov sp, r12;"
124+
/* resume task */
72125
"bx lr;"
73126
);
74127
}

0 commit comments

Comments
 (0)