
/*
 * nvram.h
 *
 *  Created on: 4 Jun 2017, modified for STM32F1 series using 2 pages of Flash rather than NVRAM
 *      Author: Mike
 * 
 * The design stores 8 bit data with an 8 bit tag value : this allows up to 253 different tags to be used (0x00 and 0xFF are reserved)
 * 
 * In the application here, each element in a 10x10 ignition timing map is given its own tag, along with the rpm and vacuum axis values,
 * and an overall timing correction tag. 
 * 
 */


#pragma once
#include "stdint.h"

#if defined __cplusplus
extern "C"
{
#endif

#pragma pack(push, 1)

    ///\brief State of item
    /// this is expected to be packed into 16 bits 
    typedef union
    {
        struct
        {
            unsigned tag : 8;
            unsigned filler;
            int val : 16;
        } data;
        uint32_t word;
    } nvram_info_t;
#pragma pack(pop)
    typedef nvram_info_t CF_DATA;

    // Save data according to its tag field
    extern void write_nvram_data(nvram_info_t data);

    // find data according to the tag field or return null if no info
    extern nvram_info_t *find_nvram_data(uint8_t tag);

#if defined __cplusplus
}
#endif
