avr-chat
[Top][All Lists]
Advanced

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

Re: [avr-chat] How can I individualise specific CPUs?


From: Daniel O'Connor
Subject: Re: [avr-chat] How can I individualise specific CPUs?
Date: Wed, 23 Sep 2009 10:48:59 +0930
User-agent: KMail/1.9.10

On Wed, 23 Sep 2009, Juergen Harms wrote:
> I create the eeprom address space by allocating non-initialised
> variables as target for receiving the copy from the flash template -
> may sound complicated but is very easy to realize (attention is only
> needed where the template needs to contain eeprom addresses). The
> intialisation of the flash-to-eeprom transfer is triggered at boot
> when key-bytes in eeprom contain 0xFF (hence if the eeprom is void).
> In case
> re-initialisation of eeprom becomes necessary, that can be triggered
> by forcing these bytes to 0xFF.
>
> That works out nicely for my application (I have much more flash
> capacity than I need, and timewise there does not appear to be a
> penality).

When I did this I used a checksum at the end - if it didn't match it 
would load rewrite EEPROM from the hard coded flash version.

/* Holds all the settings needed */
typedef struct {
    uint8_t     fermenter_ROM[8];
...
} __attribute__((packed)) settings_t;

/* Current settings in RAM */
static settings_t       settings;

/* Our map of EEPROM */
struct {
    settings_t  settings;
    uint16_t    crc;
} ee_area __attribute__((section(".eeprom")));

/* Defaults that are shoved into EEPROM if it isn't inited */
const PROGMEM settings_t        default_settings = {
    .fermenter_ROM = { 0x10, 0x8b, 0x7a, 0x53, 0x01, 0x08, 0x00, 0xb4 },
};

Then you can write to it with..
    eeprom_busy_wait();
    eeprom_write_block(&settings, &ee_area.settings,                    
                        sizeof(settings_t));
    dptr = (uint8_t *)&settings;
    crc = 0;
    for (i = 0; i < sizeof(settings_t); i++)
        crc = _crc16_update(crc, dptr[i]);

    eeprom_write_word(&ee_area.crc, crc);

(I always block write it)

-- 
Daniel O'Connor software and network engineer
for Genesis Software - http://www.gsoft.com.au
"The nice thing about standards is that there
are so many of them to choose from."
  -- Andrew Tanenbaum
GPG Fingerprint - 5596 B766 97C0 0E94 4347 295E E593 DC20 7B3F CE8C

Attachment: signature.asc
Description: This is a digitally signed message part.


reply via email to

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