Pumpkin, Inc.

Pumpkin User Forums

portiaravr.c

For issues specific to Atmel's AVR and MegaAVR microcontrollers, including Atmel AVRStudio and ImageCraft's ICCAVR C compiler.

portiaravr.c

Postby MiM » Wed Dec 15, 2004 1:52 am

In lines 91+92 and 166+167 of this file there is the 16-bit stack pointer loaded using 2 subsequent instructions:

asm("OUT 0x3D,Rxx ");
asm("OUT 0x3E,Ryy ");

However this looks like a potentially dangerous operation as there is a risk of an interrupt occurence just between those 2 instructions while the stack pointer holds an incorrect value. To avoid it I think the stack pointer load should better look like this:

__disable_interrupt();
asm("OUT 0x3D,Rxx ");
asm("OUT 0x3E,Ryy ");
__enable_interrupt();

MiM
 
Posts: 4
Joined: Tue Oct 19, 2004 11:00 pm
Location: Bratislava, SK, EU

Re: portiaravr.c

Postby aek » Wed Dec 15, 2004 2:42 am

You are absolutely right.

Wrap them with interrupt disabling (as you propose) and you'll be alright.

The gcc and ImageCraft ports handle it properly in OSCtxSw(), but not in OSDispatch().

How embarassing -- what was I thinking?

------------------

-------
aek
aek
 
Posts: 1888
Joined: Sat Aug 26, 2000 11:00 pm

Re: portiaravr.c

Postby aek » Fri Dec 17, 2004 1:27 am

OK, we've issued a Service Bulletin SB-26 for this problem.

Patch files will be posted to the various download directories shortly.

------------------

[This message has been edited by aek (edited December 17, 2004).]

-------
aek
aek
 
Posts: 1888
Joined: Sat Aug 26, 2000 11:00 pm

Re: portiaravr.c

Postby aek » Fri Dec 17, 2004 8:09 am

Minor correction to MiM's observation:
quote:
In lines 91+92 and 166+167 of this file there is the 16-bit stack pointer loaded using 2 subsequent instructions:
No change is necessary to OSCtxSw() in portiaravr.c (lines 166 & 167) because interrupts are already disabled at the start of OSCtxSw() (IN R17,0x3F, CLI), and are re-enabled at the end (OUT 0x3F,R17). Adding a wrapper there will not hurt anything, though ...

With this observation, it's simply OSDispatch() in all three ports that is incorrect and needs the CLI/SEI "wrapper" around the write to the 16-bit SP.

------------------

-------
aek
aek
 
Posts: 1888
Joined: Sat Aug 26, 2000 11:00 pm

Re: portiaravr.c

Postby Kelly Painter » Fri Dec 17, 2004 8:50 am

This sounds like something I should be concerned about. How should the Imagecraft port OSDispatch() be modified to be interrupt safe?

Thanks,
Kelly

Kelly Painter
 
Posts: 1
Joined: Mon Aug 11, 2003 11:00 pm
Location: Santa Barbara, CA, USA

Re: portiaravr.c

Postby aek » Fri Dec 17, 2004 8:52 am

I'm working on a set of patches for all the AVR compilers we support ... stay tuned ...

------------------

-------
aek
aek
 
Posts: 1888
Joined: Sat Aug 26, 2000 11:00 pm


Return to Atmel AVR and MegaAVR

Who is online

Users browsing this forum: No registered users and 0 guests