Skip to content

Commit edf3651

Browse files
Peter Van HoyweghenPeter Van Hoyweghen
authored andcommitted
Port Scheduler library to Arduino Zero.
1 parent 79f5715 commit edf3651

File tree

2 files changed

+51
-4
lines changed

2 files changed

+51
-4
lines changed
Lines changed: 3 additions & 3 deletions
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 cores 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
99
architectures=sam

libraries/Scheduler/src/Scheduler.cpp

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,21 +54,68 @@ static void __attribute__((naked)) __attribute__((noinline)) coopTaskStart(void)
5454
"mov r0, r5;"
5555
"blx r4;"
5656
"mov r0, #1;"
57+
/* shedule. address of next task context is put in r0 */
5758
"bl coopSchedule;"
59+
#if defined(ARDUINO_ARCH_SAMD)
60+
/* for cortex m0, ldm and stm are restricted to low registers */
61+
/* load high registers */
62+
"add r0, #16;" /* they are 4 words higher in memory */
63+
"ldmia r0, {r1-r6};" /* load them in low registers first... */
64+
"mov r8, r1;" /* ...and move them into high registers... */
65+
"mov r9, r2;"
66+
"mov r10, r3;"
67+
"mov r11, r4;"
68+
"mov r12, r5;"
69+
"mov lr, r6;"
70+
/* load low registers */
71+
"sub r0, r0, #40;" /* back to begin of context */
72+
"ldmia r0, {r4-r7};"
73+
#else
5874
"ldmia r0, {r4-r12, lr};"
75+
#endif
76+
/* restore task stack */
5977
"mov sp, r12;"
78+
/* resume task */
6079
"bx lr;"
6180
);
6281
}
6382

6483
static void __attribute__((naked)) __attribute__((noinline)) coopDoYield(CoopTask* curTask) {
6584
asm (
6685
"mov r12, sp;"
67-
"stmia r0, {r4-r12, lr};"
86+
/* store low registers */
87+
"stmia r0, {r4-r7};"
88+
/* store high registers */
89+
"mov r1, r8;" /* move them to low registers first */
90+
"mov r2, r9;"
91+
"mov r3, r10;"
92+
"mov r4, r11;"
93+
"mov r5, r12;"
94+
"mov r6, lr;"
95+
"stmia r0, {r1-r6};"
6896
"mov r0, #0;"
97+
/* shedule. address of next task context is put in r0 */
6998
"bl coopSchedule;"
99+
#if defined(ARDUINO_ARCH_SAMD)
100+
/* for cortex m0, ldm and stm are restricted to low registers */
101+
/* load high registers */
102+
"add r0, #16;" /* they are 4 words higher in memory */
103+
"ldmia r0, {r1-r6};" /* load them in low registers first... */
104+
"mov r8, r1;" /* ...and move them into high registers... */
105+
"mov r9, r2;"
106+
"mov r10, r3;"
107+
"mov r11, r4;"
108+
"mov r12, r5;"
109+
"mov lr, r6;"
110+
/* load low registers */
111+
"sub r0, r0, #40;" /* back to begin of context */
112+
"ldmia r0, {r4-r7};"
113+
#else
70114
"ldmia r0, {r4-r12, lr};"
115+
#endif
116+
/* restore task stack */
71117
"mov sp, r12;"
118+
/* resume task */
72119
"bx lr;"
73120
);
74121
}

0 commit comments

Comments
 (0)