Forum Menu




 


Log in Problems?
New User? Sign Up!
AVR Freaks Forum Index

Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Author Message
tomwbarclay
PostPosted: Feb 14, 2012 - 08:03 PM
Newbie


Joined: Jan 23, 2011
Posts: 10


Hi,
I am sure that this has been asked , and answered many times, but here goes ... For generally good reason I have set the global compiler optimization to level 2 (as part of the AVR Studio5 project page),
however I have some low level functions to make an 8 bit bus (RD, WR, CS, D0-D7 and A0-A5) assembled from the remnants of the GPIO pins left over once main functions have been allocated. If I set global optimization to 0 then I get control of the timing to approx 50ns steps using local bus GPIO functions.
My problem is that if optimization is > 0 then the timing control goes haywire .. it mostly gets optimized to an unpredictable state, (certainly by me).
I am sure that there must be an attribute or pragma (seems to be out of favor with GCC) that forces local optimization to be at level 0 (ie none and ignore any global optimization settings). I have scoured the GCC manual and as many sites as I can as well as experimenting but so far no luck. Any help appreciated.
 
 View user's profile Send private message  
Reply with quote Back to top
jkuusama
PostPosted: Feb 14, 2012 - 08:20 PM
Hangaround


Joined: Sep 21, 2004
Posts: 210


I don't know about a pragma, but you can put the function in a file of it's own and set the optimization per file.
 
 View user's profile Send private message  
Reply with quote Back to top
catweax
PostPosted: Feb 15, 2012 - 10:40 AM
Hangaround


Joined: Aug 25, 2011
Posts: 392
Location: Europe

Have you tried a generic search engine already?

If not for pragmas, maybe for function attributes?
 
 View user's profile Send private message  
Reply with quote Back to top
danicampora
PostPosted: Feb 15, 2012 - 11:16 AM
Hangaround


Joined: Oct 10, 2007
Posts: 395
Location: Valls, Spain

LOL! excellent response catweax!

_________________
Daniel Campora
http://www.lear.com
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
tomwbarclay
PostPosted: Feb 15, 2012 - 04:19 PM
Newbie


Joined: Jan 23, 2011
Posts: 10


I had found the GCC function attributes pages and tried various that might have some impact but none did what I wanted. I will try putting the functions in a seperate file and see if I can set the optimisation to 0 for that file in the AVRStudio5 project ... cheers.
 
 View user's profile Send private message  
Reply with quote Back to top
catweax
PostPosted: Feb 15, 2012 - 04:21 PM
Hangaround


Joined: Aug 25, 2011
Posts: 392
Location: Europe

Tried the pragmas? Actually I just notice that I swapped the links in my previous post. The second link will take you to the optimisation pragmas.
 
 View user's profile Send private message  
Reply with quote Back to top
tomwbarclay
PostPosted: Feb 16, 2012 - 01:00 PM
Newbie


Joined: Jan 23, 2011
Posts: 10


Hi, I tried pragmas but got a message saying they were ignored. Apparently GCC uses attributes. Anyway the resolution is (for me anyway)

a) create a new project an build a static library
b) in this project set optimization 0. (so timing is retained)
c) put the lib file (.a) and the header file(.h) into a lib folder inside the main project.
d) On the project properties page , toolchain tab
(i) Compiler - add this folder to the include directories
(ii) Linker - Add the library path and name into the relevant boxes.
Then build the main project as normal.

I have found that this works OK. The main project can be set at optimize level 2 and the timing is retained, as expected. One niggle is that I get a warning "input non relaxable" as the lib was built with optimization 0 and resists further optimization.
Generally I adopt a zero-tolerance policy on warnings as they tend to lead to problems if unaddressed but I guess I will have to live with this one for now.

Thanks for your suggestions.
 
 View user's profile Send private message  
Reply with quote Back to top
Bigbang
PostPosted: Feb 21, 2012 - 10:20 AM
Newbie


Joined: Feb 21, 2012
Posts: 4


Nice Suggestions.

_________________
2012 movies
 
 View user's profile Send private message  
Reply with quote Back to top
JohanEkdahl
PostPosted: Feb 21, 2012 - 10:27 AM
10k+ Postman


Joined: Mar 27, 2002
Posts: 18585
Location: Lund, Sweden

The steps that create a library are not necessary for the solution of the cuirrent problem. It would have been enough to specify a separate optimization switch (i.e. no optimization) for the compilation of the source file in question and keep it in the original project.

I'm not at an AS5-enabled machine right now so can't tell the details about specifying compiler switches inividually for different source files.

Clarification: I'm not against creating libraries, but it has little to do with the solution of the current problem.
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
tomwbarclay
PostPosted: Mar 05, 2012 - 01:34 PM
Newbie


Joined: Jan 23, 2011
Posts: 10


Hi, I did try and find a way to set the optimization of a single file within the AVRStudio5 project structure and user interface but could not find a way to do it. I am sure it can be done by manually editing the make file , but this file will be overwritten if I change the project properties. If the problem can be solved in a more elegant way then I am all ears. Thanks again.
 
 View user's profile Send private message  
Reply with quote Back to top
hce
PostPosted: Mar 05, 2012 - 03:21 PM
Raving lunatic


Joined: Jan 07, 2003
Posts: 4580
Location: Oslo, Norway

http://gcc.gnu.org/onlinedocs/gcc/Funct ... ibute-2557

Code:
void function(void) __attribute__((optimize=3))
{
    ...
}
 
 View user's profile Send private message  
Reply with quote Back to top
tomwbarclay
PostPosted: Mar 07, 2012 - 12:11 PM
Newbie


Joined: Jan 23, 2011
Posts: 10


Thanks for the info, I guess I couldn't see it for looking. The AVR32 UC3 GCC compiler seems to accept the following, (slightly different) syntax

void function(void) __attribute__((optimize(3)))
{
...
}

I'll post later if it actually works (I'm confident it will). Thanks again
 
 View user's profile Send private message  
Reply with quote Back to top
tomwbarclay
PostPosted: Mar 07, 2012 - 12:16 PM
Newbie


Joined: Jan 23, 2011
Posts: 10


Oops .. spoke too soon ,,, actual syntax required is

__attribute__((optimize(3))) void function(void)
{
...
}

Still confident it will work.
 
 View user's profile Send private message  
Reply with quote Back to top
Display posts from previous:     
Jump to:  
All times are GMT + 1 Hour
Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Powered by PNphpBB2 © 2003-2006 The PNphpBB Group
Credits