Skip to content

Commit 5750007

Browse files
committed
The proposed solution to improve the presentation of the code in port.c
was not a good result in initial tests I did worked, but I was using in a function and in this case macros are then researched the impact of using functions inline, and so I thought acclaim, besides the fact that the result be the same when properly parameterized. http://www.parashift.com/c++-faq/inline-vs-macros.html
1 parent d6a379c commit 5750007

File tree

1 file changed

+96
-97
lines changed

1 file changed

+96
-97
lines changed

arduino.DuinOS/DuinOS/port.c

Lines changed: 96 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -125,131 +125,130 @@ extern volatile tskTCB * volatile pxCurrentTCB;
125125
* The interrupts will have been disabled during the call to portSAVE_CONTEXT()
126126
* so we need not worry about reading/writing to the stack pointer.
127127
*/
128-
#define portSAVE_CONTEXT() \
129-
asm volatile ( "push r0 \n\t" \
130-
"in r0, __SREG__ \n\t" \
131-
"cli \n\t" \
132-
"push r0 \n\t" \
128+
inline void portSAVE_CONTEXT() __attribute__((__always_inline__,__noreturn__));
129+
inline void portSAVE_CONTEXT(){
130+
asm volatile ( "push r0 \n\t"
131+
"in r0, __SREG__ \n\t"
132+
"cli \n\t"
133+
"push r0 \n\t"
133134
);
134-
/* CDCP - begin*/
135135
#if defined(__AVR_HAVE_RAMPZ__)
136136
/*
137137
* have RAMPZ Extended Z-pointer Register for ELPM/SPM
138138
* the uC have extend program memory
139139
* 0x3b --> RAMPZ
140140
* 0x3c --> EIND
141141
*/
142-
asm volatile ( "in r0, 0x3b \n\t" \
143-
"push r0 \n\t" \
144-
"in r0, 0x3c \n\t" \
145-
"push r0 \n\t" \
142+
asm volatile ( "in r0, 0x3b \n\t"
143+
"push r0 \n\t"
144+
"in r0, 0x3c \n\t"
145+
"push r0 \n\t"
146146
);
147147
#endif
148-
asm volatile ( "push r1 \n\t" \
149-
"clr r1 \n\t" \
150-
"push r2 \n\t" \
151-
"push r3 \n\t" \
152-
"push r4 \n\t" \
153-
"push r5 \n\t" \
154-
"push r6 \n\t" \
155-
"push r7 \n\t" \
156-
"push r8 \n\t" \
157-
"push r9 \n\t" \
158-
"push r10 \n\t" \
159-
"push r11 \n\t" \
160-
"push r12 \n\t" \
161-
"push r13 \n\t" \
162-
"push r14 \n\t" \
163-
"push r15 \n\t" \
164-
"push r16 \n\t" \
165-
"push r17 \n\t" \
166-
"push r18 \n\t" \
167-
"push r19 \n\t" \
168-
"push r20 \n\t" \
169-
"push r21 \n\t" \
170-
"push r22 \n\t" \
171-
"push r23 \n\t" \
172-
"push r24 \n\t" \
173-
"push r25 \n\t" \
174-
"push r26 \n\t" \
175-
"push r27 \n\t" \
176-
"push r28 \n\t" \
177-
"push r29 \n\t" \
178-
"push r30 \n\t" \
179-
"push r31 \n\t" \
180-
"lds r26, pxCurrentTCB \n\t" \
181-
"lds r27, pxCurrentTCB + 1 \n\t" \
182-
"in r0, 0x3d \n\t" \
183-
"st x+, r0 \n\t" \
184-
"in r0, 0x3e \n\t" \
185-
"st x+, r0 \n\t" \
148+
asm volatile ( "push r1 \n\t"
149+
"clr r1 \n\t"
150+
"push r2 \n\t"
151+
"push r3 \n\t"
152+
"push r4 \n\t"
153+
"push r5 \n\t"
154+
"push r6 \n\t"
155+
"push r7 \n\t"
156+
"push r8 \n\t"
157+
"push r9 \n\t"
158+
"push r10 \n\t"
159+
"push r11 \n\t"
160+
"push r12 \n\t"
161+
"push r13 \n\t"
162+
"push r14 \n\t"
163+
"push r15 \n\t"
164+
"push r16 \n\t"
165+
"push r17 \n\t"
166+
"push r18 \n\t"
167+
"push r19 \n\t"
168+
"push r20 \n\t"
169+
"push r21 \n\t"
170+
"push r22 \n\t"
171+
"push r23 \n\t"
172+
"push r24 \n\t"
173+
"push r25 \n\t"
174+
"push r26 \n\t"
175+
"push r27 \n\t"
176+
"push r28 \n\t"
177+
"push r29 \n\t"
178+
"push r30 \n\t"
179+
"push r31 \n\t"
180+
"lds r26, pxCurrentTCB \n\t"
181+
"lds r27, pxCurrentTCB + 1 \n\t"
182+
"in r0, 0x3d \n\t"
183+
"st x+, r0 \n\t"
184+
"in r0, 0x3e \n\t"
185+
"st x+, r0 \n\t"
186186
);
187-
187+
}
188188

189189
/*
190190
* Opposite to portSAVE_CONTEXT(). Interrupts will have been disabled during
191191
* the context save so we can write to the stack pointer.
192192
*/
193-
194-
#define portRESTORE_CONTEXT() \
195-
asm volatile ( "lds r26, pxCurrentTCB \n\t" \
196-
"lds r27, pxCurrentTCB + 1 \n\t" \
197-
"ld r28, x+ \n\t" \
198-
"out __SP_L__, r28 \n\t" \
199-
"ld r29, x+ \n\t" \
200-
"out __SP_H__, r29 \n\t" \
201-
"pop r31 \n\t" \
202-
"pop r30 \n\t" \
203-
"pop r29 \n\t" \
204-
"pop r28 \n\t" \
205-
"pop r27 \n\t" \
206-
"pop r26 \n\t" \
207-
"pop r25 \n\t" \
208-
"pop r24 \n\t" \
209-
"pop r23 \n\t" \
210-
"pop r22 \n\t" \
211-
"pop r21 \n\t" \
212-
"pop r20 \n\t" \
213-
"pop r19 \n\t" \
214-
"pop r18 \n\t" \
215-
"pop r17 \n\t" \
216-
"pop r16 \n\t" \
217-
"pop r15 \n\t" \
218-
"pop r14 \n\t" \
219-
"pop r13 \n\t" \
220-
"pop r12 \n\t" \
221-
"pop r11 \n\t" \
222-
"pop r10 \n\t" \
223-
"pop r9 \n\t" \
224-
"pop r8 \n\t" \
225-
"pop r7 \n\t" \
226-
"pop r6 \n\t" \
227-
"pop r5 \n\t" \
228-
"pop r4 \n\t" \
229-
"pop r3 \n\t" \
230-
"pop r2 \n\t" \
231-
"pop r1 \n\t" \
232-
"pop r0 \n\t" \
193+
inline void portRESTORE_CONTEXT() __attribute__((__always_inline__,__noreturn__));
194+
inline void portRESTORE_CONTEXT(){
195+
asm volatile ( "lds r26, pxCurrentTCB \n\t"
196+
"lds r27, pxCurrentTCB + 1 \n\t"
197+
"ld r28, x+ \n\t"
198+
"out __SP_L__, r28 \n\t"
199+
"ld r29, x+ \n\t"
200+
"out __SP_H__, r29 \n\t"
201+
"pop r31 \n\t"
202+
"pop r30 \n\t"
203+
"pop r29 \n\t"
204+
"pop r28 \n\t"
205+
"pop r27 \n\t"
206+
"pop r26 \n\t"
207+
"pop r25 \n\t"
208+
"pop r24 \n\t"
209+
"pop r23 \n\t"
210+
"pop r22 \n\t"
211+
"pop r21 \n\t"
212+
"pop r20 \n\t"
213+
"pop r19 \n\t"
214+
"pop r18 \n\t"
215+
"pop r17 \n\t"
216+
"pop r16 \n\t"
217+
"pop r15 \n\t"
218+
"pop r14 \n\t"
219+
"pop r13 \n\t"
220+
"pop r12 \n\t"
221+
"pop r11 \n\t"
222+
"pop r10 \n\t"
223+
"pop r9 \n\t"
224+
"pop r8 \n\t"
225+
"pop r7 \n\t"
226+
"pop r6 \n\t"
227+
"pop r5 \n\t"
228+
"pop r4 \n\t"
229+
"pop r3 \n\t"
230+
"pop r2 \n\t"
231+
"pop r1 \n\t"
232+
"pop r0 \n\t"
233233
);
234-
235234
#if defined(__AVR_HAVE_RAMPZ__)
236235
/*
237236
* have RAMPZ Extended Z-pointer Register for ELPM/SPM
238237
* the uC have extend program memory
239238
* 0x3b --> RAMPZ
240239
* 0x3c --> EIND
241240
*/
242-
asm volatile ( "out 0x3c, r0 \n\t" \
243-
"pop r0 \n\t" \
244-
"out 0x3b, r0 \n\t" \
245-
"pop r0 \n\t" \
241+
asm volatile ( "out 0x3c, r0 \n\t"
242+
"pop r0 \n\t"
243+
"out 0x3b, r0 \n\t"
244+
"pop r0 \n\t"
246245
);
247246
#endif
248247

249-
asm volatile ( "out __SREG__, r0 \n\t" \
250-
"pop r0 \n\t" \
248+
asm volatile ( "out __SREG__, r0 \n\t"
249+
"pop r0 \n\t"
251250
);
252-
251+
}
253252
/*-----------------------------------------------------------*/
254253

255254
/*

0 commit comments

Comments
 (0)