avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-gcc-list] Macro to read /write long to eeprom


From: Peter Bosscha
Subject: Re: [avr-gcc-list] Macro to read /write long to eeprom
Date: Wed, 10 Aug 2005 07:46:36 +0200

Slightly off-topic but a handy tip:
 
For eeprom, perform a read before write, every byte takes 9milisec (Mega128) to write.
So, if you have sequential writes you could spend waiting quite a bit.
 
We have large structures in eeprom, parts of which are saved/updated regularly. Doing a read before write saved us seconds in wait time.
 
In my case I implemented simple calls like eeprom_rwb (read-write-byte), the stack & code size overhead are trivial compared to the time saved.
 
Peter.

>>> "Royce Pereira" <address@hidden> 09/08/2005 21:36 >>>
Hello,

On Wed, 10 Aug 2005 00:41:20 +0530, Dave Hansen <address@hidden> wrote:

> From: "Royce Pereira" <address@hidden>
>>
>> Hi,
>> Is there a macro to read or write a long word (32 bits) to eeprom?
>> For the last hour I've been trying to write one unsuccessfully.
>
> Not directly, but you can do something like
>
>    #include <avr/eeprom.h>
>
>    inline void eeprom_write_long(long *dest, long val)
>    {
>       eeprom_write_block(&val, dest, sizeof(val));
>    }
>
>    inline long eeprom_read_long(long *src)
>    {
>       long retval;
>
>       eeprom_read_block(&retval, src, sizeof(retval));
>       return retval;
>    }
>
> WARNING: untested code, but it should be close.  Note that (IMHO) 
> eeprom_write_block's parameters are backwards, but that's what's been 
> provided.
------------------------------------------------
Actually I managed something with the existing word rd/wr macros. But I've 
yet to see how the code size compares with the read/write block method..

uint32_t eeprom_read_long( uint16_t *loc)
    {
        uint32_t num;
        num = eeprom_read_word((uint16_t *)(loc+1));
        num <<=16;
        num |= eeprom_read_word((uint16_t *)loc);
        return num;
    }
//=========================
void eeprom_write_long(uint16_t *loc, uint32_t val)
    {
        eeprom_write_word(loc, val & 0xffff);
        eeprom_write_word(++loc, val >>16);

        return;
    }

Thanks, all,

--Royce.
--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/


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

--
This message is subject to the CSIR's copyright, terms and conditions and e-mail legal notice.
Views expressed herein do not necessarily represent the views of the CSIR.

CSIR E-mail Legal Notice

CSIR Copyright, Terms and Conditions

For electronic copies of the CSIR Copyright, Terms and Conditions and the CSIR Legal Notice
send a blank message with "REQUEST LEGAL" in the subject line to CSIR HelpDesk


This message has been scanned for viruses and dangerous content by MailScanner,
and is believed to be clean. MailScanner thanks Transtec Computers for their support.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]