Page 1 of 1

Which EEPROM address range is safe to write to?

Posted: 11 Nov 2017 22:28
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;
}

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

Posted: 11 Nov 2017 23:58
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...

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

Posted: 12 Nov 2017 00:57
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

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

Posted: 12 Nov 2017 13:02
by knst08
And what are the boundaries? I failed to find it in documentation.

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

Posted: 12 Nov 2017 13:16
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

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

Posted: 12 Nov 2017 14:01
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

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

Posted: 13 Nov 2017 17:12
by PoltoS
You are right!

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