[avr-gcc-list] Unused registers?

2009-10-21 Thread Thomas Pircher
Hi all,

I came across a strange behaviour of avr-gcc. In one of our programs (4k
in Flash) the assembler code shows that the registers r2, r3, r5 and r6
are not used at all. Since we are (as everyone, I guess) short in code
space, I am wondering if there are some tricks that can make avr-gcc use
those registers, too.

I'm not saying avr-gcc has a bug, as those registers are used when I
compile other code.

Ideally, what I would like to know is if there is some special magic to
make avr-gcc use all available registers and reduce the code size enough
that we can squeeze in all the features asked for by marketing ;)

I'm using WinAVR 20071221 but 20090313 shows the same behaviour.

avr-size prog.elf
   textdata bss dec hex filename
   4092   0  804172104c prog.elf

Cheers,
Thomas


___
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.org
http://lists.nongnu.org/mailman/listinfo/avr-gcc-list


Re: [avr-gcc-list] Unused registers?

2009-10-21 Thread Ruud Vlaming
Hi Tomas,

In general it is very hard to force gcc to utilize all registers or particular
registers. And if you succeed, observe that in most of the times it 
results in extra mov's, so it does not tend to reduce code. One exception
is with framepointers. Gcc should avoid framepointers if you asked it
to do so (compileroption), and make use of the extra registers. 
Sometimes however it does not (i do not understand why), i.e.
sometimes gcc makes a framepointer for saving data instead
of utilizing unused registers. In that case you can try the following
trick. For example, to advise gcc to use register r6 for 'cVal':

  register volatile char cVal asm (r6);

(Of course you can try that anyway, but i bet it will make code
not shorter in general). I am curious what results you obtain.

Having said that, i am sure there must be plenty of other
opportunities to reduce your code. I am still shaving of bytes
from my apps although i already thought they were a their
minimal size a year ago. I've become a real code reduction
expert by now. My motto is: You can always take off 10%.
Thus, even if you already did so. ;-)

Ruud
http://www.femtoos.org/

On Wednesday 21 October 2009 10:59, Thomas Pircher wrote:
 Hi all,
 
 I came across a strange behaviour of avr-gcc. In one of our programs (4k
 in Flash) the assembler code shows that the registers r2, r3, r5 and r6
 are not used at all. Since we are (as everyone, I guess) short in code
 space, I am wondering if there are some tricks that can make avr-gcc use
 those registers, too.
 
 I'm not saying avr-gcc has a bug, as those registers are used when I
 compile other code.
 
 Ideally, what I would like to know is if there is some special magic to
 make avr-gcc use all available registers and reduce the code size enough
 that we can squeeze in all the features asked for by marketing ;)
 
 I'm using WinAVR 20071221 but 20090313 shows the same behaviour.
 
 avr-size prog.elf
textdata bss dec hex filename
4092   0  804172104c prog.elf
 
 Cheers,
 Thomas
 
 
 ___
 AVR-GCC-list mailing list
 AVR-GCC-list@nongnu.org
 http://lists.nongnu.org/mailman/listinfo/avr-gcc-list
 


___
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.org
http://lists.nongnu.org/mailman/listinfo/avr-gcc-list


RE: [avr-gcc-list] including default eeprom values in flash memory

2009-10-21 Thread Prashant D. Kharade
Hi,

One method, which I have read on the net  also used by myself in my
project is as follows.

As per this we have to write the default eeprom values in our 'C' file.

1. Create one variable named eeload.
2. In your main program, if eeload !=250 (any random value) then put all
your default values in EEprom.
3. And also load eeload = 250.
4. Because of this, next time eeload will be 250  default values will
not be reloaded.
5. Hence after you load your main hex file, at first instant all the
default eeprom values will get loaded alongwith eeload=250.
6. This part of code will never get executed in future because eeload =
250.

Hope this will help you.
Good Luck

Prashant
India

-Original Message-
From: avr-gcc-list-bounces+pdkharade=adorpower@nongnu.org
[mailto:avr-gcc-list-bounces+pdkharade=adorpower@nongnu.org] On
Behalf Of Michael Clift
Sent: 21 October 2009 15:04
To: avr-gcc-list@nongnu.org
Subject: [avr-gcc-list] including default eeprom values in flash memory

Hi, I am using winavr, and would like to include the default eeprom 
values (normally output to .eep) in flash memory. I want to do this so 
that my application can easily default the eeprom. Whats the best way to

do this? can it be done with a modification to the linker script? or 
should it be done in the makefile somehow?



Regards, Michael.



___
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.org
http://lists.nongnu.org/mailman/listinfo/avr-gcc-list

No virus found in this incoming message.
Checked by AVG - www.avg.com 
Version: 8.5.423 / Virus Database: 270.14.24/2449 - Release Date:
10/20/09 18:42:00



___
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.org
http://lists.nongnu.org/mailman/listinfo/avr-gcc-list


R: [avr-gcc-list] including default eeprom values in flash memory

2009-10-21 Thread palmerino tallarico
Hi
I'm using this (for example):

File eedata.c 

#include eedata.h

TOTAL_DATA total_data;
ERROR_DATA error_data;

TOTAL_DATA __attribute__((section(.eeprom))) e2total_data =
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};

ERROR_DATA __attribute__((section(.eeprom))) error_data = {0,0};

File eedata.h

#define TOTAL_DATA_ADDR 0  // Starting address of SYS_DATA image
data in eeprom 
#define ERROR_DATA_ADDR (TOTAL_DATA_ADDR + sizeof(total_data))
// Starting address of ERROR_DATA image in eeprom

typedef struct  {
  u32 .; (fill as you need)
}TOTAL_DATA;

extern TOTAL_DATA total_data

typedef struct  {
  u16 ;
}ERROR_DATA;

extern ERROR_DATA error_data;

hope this help U!

Rino Tallarico
_

-Messaggio originale-
Da: avr-gcc-list-bounces+palmerinotallarico=vodafone...@nongnu.org
[mailto:avr-gcc-list-bounces+palmerinotallarico=vodafone...@nongnu.org] Per
conto di Prashant D. Kharade
Inviato: mercoledì 21 ottobre 2009 12.35
A: Michael Clift; avr-gcc-list@nongnu.org
Oggetto: RE: [avr-gcc-list] including default eeprom values in flash memory

Hi,

One method, which I have read on the net  also used by myself in my
project is as follows.

As per this we have to write the default eeprom values in our 'C' file.

1. Create one variable named eeload.
2. In your main program, if eeload !=250 (any random value) then put all
your default values in EEprom.
3. And also load eeload = 250.
4. Because of this, next time eeload will be 250  default values will
not be reloaded.
5. Hence after you load your main hex file, at first instant all the
default eeprom values will get loaded alongwith eeload=250.
6. This part of code will never get executed in future because eeload =
250.

Hope this will help you.
Good Luck

Prashant
India

-Original Message-
From: avr-gcc-list-bounces+pdkharade=adorpower@nongnu.org
[mailto:avr-gcc-list-bounces+pdkharade=adorpower@nongnu.org] On
Behalf Of Michael Clift
Sent: 21 October 2009 15:04
To: avr-gcc-list@nongnu.org
Subject: [avr-gcc-list] including default eeprom values in flash memory

Hi, I am using winavr, and would like to include the default eeprom 
values (normally output to .eep) in flash memory. I want to do this so 
that my application can easily default the eeprom. Whats the best way to

do this? can it be done with a modification to the linker script? or 
should it be done in the makefile somehow?



Regards, Michael.



___
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.org
http://lists.nongnu.org/mailman/listinfo/avr-gcc-list

No virus found in this incoming message.
Checked by AVG - www.avg.com 
Version: 8.5.423 / Virus Database: 270.14.24/2449 - Release Date:
10/20/09 18:42:00



___
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.org
http://lists.nongnu.org/mailman/listinfo/avr-gcc-list



___
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.org
http://lists.nongnu.org/mailman/listinfo/avr-gcc-list


Re: [avr-gcc-list] including default eeprom values in flash memory

2009-10-21 Thread Parthasaradhi Nayani

From: Michael Clift mich...@clift.com.au

    Hi, I am using winavr, and would like to include the default eeprom values 
(normally output to .eep) in flash memory. I want to do this so that my 
application can easily default the eeprom. 

Hello,
EEPROM data in FLASH memory? then the easy way is to use the PGM space 
attribute to the variables you want in flash.

Nayani




  ___
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.org
http://lists.nongnu.org/mailman/listinfo/avr-gcc-list


[avr-gcc-list] Re: including default eeprom values in flash memory

2009-10-21 Thread Heike C. Zimmerer
Michael Clift mich...@clift.com.au writes:

 Hi, I am using winavr, and would like to include the default eeprom
 values (normally output to .eep) in flash memory. I want to do this so
 that my application can easily default the eeprom. Whats the best way
 to do this? can it be done with a modification to the linker script?
 or should it be done in the makefile somehow?

If you put the data into a struct like this:

struct test {
  int i;
  char s[6];
};
struct test x PROGMEM = {7, HELLO};

then just read byte per byte from x for sizeof(x) times and write it
into your EEPROM.

Heike



___
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.org
http://lists.nongnu.org/mailman/listinfo/avr-gcc-list


Re: [avr-gcc-list] including default eeprom values in flash memory

2009-10-21 Thread David Kelly
On Wed, Oct 21, 2009 at 07:40:50AM -0700, Parthasaradhi Nayani wrote:
 
 From: Michael Clift mich...@clift.com.au
 
 ??? Hi, I am using winavr, and would like to include the default
 eeprom values (normally output to .eep) in flash memory. I want to
 do this so that my application can easily default the eeprom. 
 
 Hello,
 EEPROM data in FLASH memory? then the easy way is to use the PGM space
 attribute to the variables you want in flash.

Ditto. Declare the variables twice, once with a name that is obvious to
you is EEPROM in the EEPROM space, and again with a name that is obvious
to you is stored in FLASH. Then when/if you wish to restore EEPROM
contents to their initial default values use the PGM modifier to read
from FLASH and call the routine(s) used to write EEPROM.

Duplicating the default data in your source code sounds wasteful but it
will be easier to understand 6 months from now than an edit of the
Makefile plus hacks to the memory segment definitions. I think it is
possible that way to write the .eeprom segment to two places in memory,
is just that you don't want to do it that way when there is an easier
way that is also easier to understand.

-- 
David Kelly N4HHE, dke...@hiwaay.net

Whom computers would destroy, they must first drive mad.


___
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.org
http://lists.nongnu.org/mailman/listinfo/avr-gcc-list


Re: [avr-gcc-list] including default eeprom values in flash memory

2009-10-21 Thread Dusan Ferbas

Hi,

I am using for many years a system, I published as open source (LGPL 
like) at http://www.ethernut.de/en/documents/phat.html. Look for 
'SPIFlashFileSystem' link to a zip file.
This is a complete project, but there is a subdirectory eeparams, 
which can be extracted from it.


Common problem is, that your variables in EEPROM changes between 
firmware revisions. Idea is to assign a unique ID to each data 
structure and to place a table with these IDs, offsets and lengths at 
the beginning of EEPROM area. Default table occupies space in flash. 
However this is not suitable for uPs with limited code, I found it 
usefull, because the code supports also fw downgrade, while 
preserving variables existing in both revisions and placing default 
values for new ones.


At 11:34 21.10.2009, Michael Clift wrote:
Hi, I am using winavr, and would like to include the default eeprom 
values (normally output to .eep) in flash memory. I want to do this 
so that my application can easily default the eeprom. Whats the best 
way to do this? can it be done with a modification to the linker 
script? or should it be done in the makefile somehow?


Dusan 




___
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.org
http://lists.nongnu.org/mailman/listinfo/avr-gcc-list


Re: [avr-gcc-list] including default eeprom values in flash memory

2009-10-21 Thread Bob Paddock
 Ditto. Declare the variables twice, once with a name that is obvious to
 you is EEPROM in the EEPROM space, and again with a name that is obvious
 to you is stored in FLASH. Then when/if you wish to restore EEPROM
 contents to their initial default values use the PGM modifier to read
 from FLASH and call the routine(s) used to write EEPROM.

I have been trying to find the origin of a story, without success so
far, related to
restoring  default EEPROM settings to factory settings.

Story goes like this:

A lady took her car back to the dealer, and asked that they disable the
front seat passenger air bags, as her son always road there.  The dealer
did as the lady asked.  Some time later something happened, possibly
a jump start due to dead battery, which caused the ECU to restore
the EEPROM to factory specs, which included turning the passenger side
air bag back on.  There was then an accident, where boy was killed.

Even if the story is not true, it still illustrates just how hard it is to do
a safe embedded system.

Programming is a race between writing a program that any idiot can use,
and the Universe building bigger and better idiots.  The Universe is winning.



-- 
http://www.wearablesmartsensors.com/
http://www.softwaresafety.net/
http://www.designer-iii.com/
http://www.unusualresearch.com/


___
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.org
http://lists.nongnu.org/mailman/listinfo/avr-gcc-list


Re: [avr-gcc-list] including default eeprom values in flash memory

2009-10-21 Thread Michael Clift

Thanks for all the responses guys, some interesting ideas.
I don't really want to put all of my EEPROM data into one structure, as 
I have many eeprom variables with initializers distributed across a 
number of files.


What I ended up doing, was to change the .eep output format to binary, 
then I copied this to an object file as described here 
http://www.nongnu.org/avr-libc/user-manual/FAQ.html#faq_binarydata
I then linked this object into my main code. It works a treat, only I 
have to build my code twice to get the initial values updated to flash, 
once to create .eep, and again to link in the object.


The main reason for doing this, is that I have a boot loader that I want 
our clients to be able to use, only the boot loader does not support 
eeprom loading. It also saves me having to program the eeprom in production.



Regards, Michael.



___
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.org
http://lists.nongnu.org/mailman/listinfo/avr-gcc-list