#3 - wrap your variable access in a cli(), sei() to prevent interrupts.
Here is a fast method that also preserves the interrupt state:
{
char sreg = SREG;
...
cli()
// variable access
SREG = sreg;
}
#4 there is a command line option to force near calls "-mshort-calls". I
don't know if external routines are accessed with near calls or not. It
would be nice if the near calls were on a source file basis with far calls
between source file modules. AFAIK there is no short/long attribute for
procedures.
These questions might be better answered in the avr-gcc-list@nongnu.org
group
| -----Original Message-----
| From: AVR-Chat@yahoogroups.com [mailto:AVR-Chat@yahoogroups.com] On Behalf
| Of Reza
| Sent: Thursday, December 07, 2006 7:23 AM
| To: AVR-Chat@yahoogroups.com
| Subject: [AVR-Chat] What is your suggestion?
|
| Hi all;
|
| 1st excuse me for poor english;
|
| I'm working with AVR micros more than three years. Working in a
| company in Automation department. I use Code Vision AVR compiler for
| test perposes and WinAVR with AvrStudio 4 for final project. but
| there are some problems in all projects:
|
| 1- In some cases i need a software environment to test entire model
| as completely as possible. I tested proteus for simulation but is is
| a powerfull but bad designed program. AvrStudio has no capability to
| write plugins for.
| in some cases I need to define harware for my model. I tested using a
| simulator working in DOS/Windows for my applications but having a
| great simulation software needs great time to spend.
|
| 2- In some cases, specially defining a serial port protocol, I need
| to use state machine, rather than using multi-task kernels. but
| defining and implementation of a state machine is a time consuming
| task. and when you want to change any logic you may need to review
| all work. is there any tools which could be customized to generate
| AVR assembly or C code in help of state machine design?
|
| 3- in C when you want to access a variable in both main code and
| interrupt handlers, you have to declare it as volatile to avoid
| memory access optimization using registers. but if variable be of
| type int, or something larger than one byte in size, bcz access made
| in more than one instruction you may get invalid results. consider
| this:
|
| volatile short n;
|
| SIGNAL(...)
| {
| n++;
| }
|
| main()
| {
| int t = n;
| ....
| }
|
| in main() function assembler code looks like this:
|
| lds r24,n
| lds r25,n+1
|
| if an interrupt happens between two lds instructions and if <n>
| have a value of 255 before first lds, you will get 511. in these cases
| i may use cli/sei to block interrupts, but is there another way to
| notify the compiler to generate code for me? accessing to data types
| other than byte is not atomic.
|
| 4- some compilers have an ability to use near calls when possible
| rather than long calls to reduce code size. is there any way in GCC
| to declare a function as <near> or something? by now I use assembly
| code to reduce code size, using rcalls, instead of call instructions.
|
| Thanks for any suggestion;
|
|
|
|
|
| Yahoo! Groups Links
|
|
|Message
RE: [AVR-Chat] What is your suggestion?
2006-12-07 by larry barello
Attachments
- No local attachments were found for this message.