1.5.1.2 Using The Library

The PRIME Storage service library is called to read/write persistent data from/to non-volatile memory.

The following example illustrates how the Storage service can be used.

Example of PRIME Storage library usage

#include <string.h>
#include "app.h"
#include "service/storage/srv_storage.h"
#include "bsp/bsp.h"

typedef struct {
    uint16_t key;
    uint8_t eui48[6];
} PRIME_MAC_EUI48;

#define MAC_CONFIG_KEY 0xAA55

void APP_Initialize ( void )
{
    PRIME_MAC_EUI48 macEUI48;

    SRV_STORAGE_GetConfigInfo(SRV_STORAGE_TYPE_MAC_INFO, sizeof(macEUI48), &macEUI48);

    if (macEUI48.key == MAC_CONFIG_KEY)
    {
        LED_GREEN_On();
    }
    else
    {
        LED_BLUE_On();
    }
}

void APP_SetEUI48(uint8_t* eui48)
{
    PRIME_MAC_EUI48 macEUI48;

    macEUI48.key = MAC_CONFIG_KEY;
    memcpy(macEUI48.eui48, eui48, 6);
    SRV_STORAGE_SetConfigInfo(SRV_STORAGE_TYPE_MAC_INFO, sizeof(eui48), &eui48);
}