[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [avr-gcc-list] Macro to read /write long to eeprom
From: |
Royce Pereira |
Subject: |
Re: [avr-gcc-list] Macro to read /write long to eeprom |
Date: |
Wed, 10 Aug 2005 01:06:23 +0530 |
User-agent: |
Opera M2/8.02 (Win32, build 7680) |
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/