Which EEPROM address range is safe to write to?

Discussion about Z-Uno product. Visit http://z-uno.z-wave.me for more details.
Post Reply
knst08
Posts: 28
Joined: 15 Oct 2017 20:14

Which EEPROM address range is safe to write to?

Post by knst08 »

I've found that 0x2000 - 0x2100 is used for z-wave configuration. Are there any other address range that are used by z-uno core?

When I write to eeprom z-uno hangs with some probability. I'm trying to utilize EEPROM in the way it would not exhaust its resource too fast.
So I have SettingsHeader structure storing data length and is Actual flag. Loading of settings starts with configured start of EEPROM address range reads header if it is not actual reads the next one and so on till it gets to header stored most recently , take data bytes length from it and reads the data right after the header. Saving setting first rewrites current header to set isActual to false and writes new one with new data after it.

Code: Select all

struct SettingsHeader 
{
    boolean isActual;
    word length;
    word rewriteCycles;
    byte crc;
};

struct SettingsData
{
    byte startUpRelayOnOff;
    byte crc;
};

void SettingsManager::saveSetting(){
    Serial.print("Saving");
    Serial.flush();
    Settings* settings = context->settings;
    SettingsData data;

    actualHeader.isActual = false;
    actualHeader.crc = calcCrc8((byte*)&actualHeader, sizeof(SettingsHeader) - 1);
    EEPROM.put(actualHeaderAddress, &actualHeader, sizeof(SettingsHeader));  
    actualHeaderAddress += sizeof(SettingsHeader) + sizeof(SettingsData);



    //Write to EEPROM start if it is full
    if (actualHeaderAddress >= EEPROM_ADDR_MAX){
        actualHeaderAddress = EEPROM_ADDR_MIN;
    }


    //build new data
    data.startUpRelayOnOff = settings->startUpRelayOnOff;
    data.crc = calcCrc8((byte*)&data, sizeof(SettingsData) - 1);

    //build new header
    actualHeader.isActual = true;
    actualHeader.rewriteCycles ++;
    actualHeader.length = sizeof(SettingsData);
    actualHeader.crc = calcCrc8((byte*)&actualHeader, sizeof(SettingsHeader) - 1);


    //save new header
    EEPROM.put(actualHeaderAddress, &actualHeader, sizeof(SettingsHeader));    

    //save new data
    EEPROM.put(actualHeaderAddress + sizeof(SettingsHeader), &data, sizeof(SettingsData));    
    Serial.print("Saved");
    Serial.flush();
     
}

byte SettingsManager::calcCrc8(byte * data, byte count) {
    byte result = 0xDF;

    while(count--) {
        result ^= *data;
        data++;
    }
    return result;
}
knst08
Posts: 28
Joined: 15 Oct 2017 20:14

Re: Which EEPROM address range is safe to write to?

Post by knst08 »

Hang issue was due to stack overflow. Restructuring of the code helped.

But the question regarding EEPROM address range to be used from sketch is actual...
User avatar
PoltoS
Posts: 7565
Joined: 26 Jan 2011 19:36

Re: Which EEPROM address range is safe to write to?

Post by PoltoS »

Z-Uno will not give you a way to write to its private (or Z-Wave internal) memory. Anything you can specify is safe. Out of boundaries are ignored
knst08
Posts: 28
Joined: 15 Oct 2017 20:14

Re: Which EEPROM address range is safe to write to?

Post by knst08 »

And what are the boundaries? I failed to find it in documentation.
User avatar
PoltoS
Posts: 7565
Joined: 26 Jan 2011 19:36

Re: Which EEPROM address range is safe to write to?

Post by PoltoS »

Before it was 0-360kB (https://z-uno.z-wave.me/Reference/EEPROM/)

But not it is even more. Need to check with R&D
knst08
Posts: 28
Joined: 15 Oct 2017 20:14

Re: Which EEPROM address range is safe to write to?

Post by knst08 »

From z-uno source:

HLCore.cpp

Code: Select all

void zunoLoadCFGParam(byte param_number, dword * value) {
	param_number -= 64;
	param_number <<= 2;
	zunoSysCall(ZUNO_FUNC_EEPROM_READ, dword(START_CONFIGPARAM_EEPROM_ADDR + param_number), word(4), value);
}
ZUNO_Definitions.h:

Code: Select all

// EEPROM
#define START_CONFIGPARAM_EEPROM_ADDR			0x2000

Looks like 0x2000 - 0x2064 is reserved for z-wave settings and writing in this range will lead to unpredictable values if zunoLoadCFGParamis called
User avatar
PoltoS
Posts: 7565
Joined: 26 Jan 2011 19:36

Re: Which EEPROM address range is safe to write to?

Post by PoltoS »

You are right!

Reference updated:
http://z-uno.z-wave.me/Reference/EEPROM/
Post Reply