Skip to content

Commit 341a0d4

Browse files
committed
fixed avr warning
1 parent bbf1723 commit 341a0d4

3 files changed

Lines changed: 12 additions & 5 deletions

File tree

examples/TaskBlink/TaskBlink.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include <Taskfun.h>
1+
#include "Taskfun.h"
22

33
// synchronize access to this shared global variable
44
SyncVar<bool> _on;
@@ -18,7 +18,7 @@ void Off(int) {
1818
while (1) {
1919
if (!_on) {
2020
digitalWrite(LED_BUILTIN, LOW);
21-
delay(1000);
21+
delay(1000);
2222
_on = true;
2323
}
2424
}

src/BTaskSwitcherAVR.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ bool BTaskSwitcher::disable() {
5151
return sreg & _BV(SREG_I);
5252
}
5353

54-
void __attribute__((naked)) BTaskSwitcher::switch_context() {
54+
// not a static class function to avoid compiler warning
55+
void __attribute__((naked)) avr_switch_context()
56+
{
5557
asm volatile("push r0");
5658
asm volatile("in r0, __SREG__");
5759
asm volatile("push r0");
@@ -90,7 +92,7 @@ void __attribute__((naked)) BTaskSwitcher::switch_context() {
9092
asm volatile("in r25, __SP_H__");
9193
asm volatile("call %x0"
9294
:
93-
: "i"(swap_stack));
95+
: "i"(BTaskSwitcher::swap_stack));
9496
asm volatile("out __SP_L__, r24");
9597
asm volatile("out __SP_H__, r25");
9698
asm volatile("pop r31");
@@ -127,7 +129,11 @@ void __attribute__((naked)) BTaskSwitcher::switch_context() {
127129
asm volatile("pop r0");
128130
asm volatile("out __SREG__, r0");
129131
asm volatile("pop r0");
130-
asm volatile("ret");
132+
asm volatile("ret");
133+
}
134+
135+
void BTaskSwitcher::switch_context() {
136+
avr_switch_context();
131137
}
132138

133139
void BTaskSwitcher::init_task(BTaskInfoBase* taskInfo, BTaskWrapper wrapper) {

src/BTaskSwitcherAVR.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
extern "C" void TIMER0_COMPA_vect();
55

66
#define __BTASKSWITCHER_ARCH_CLASS__ \
7+
friend void avr_switch_context(); \
78
friend void ::TIMER0_COMPA_vect();
89

910
#endif

0 commit comments

Comments
 (0)