#ifndef _flash_utils_h
#define _flash_utils_h

#include <stdint.h>

#define FLASH_ROW_SIZE 256

/*! This struct defines 256 bytes of user data, stored in non-volatile
 *  memory, including a special 4-byte word which is used to turn on
 *  remote programming.
 */
typedef struct {
        //! check if we want to enable the remote programming functionality
        uint32_t copy_fw;

        //! store fan configuration and speeds
        uint16_t setfrpms[3];
        uint16_t fan_installed[3];
        uint16_t fan_cmdrpm[3];
        uint16_t fan_ppr[3];

        //! provide some (optional) user data storage
        uint8_t user_data[228];
} user_flash_t;

extern user_flash_t user_flash;


void flash_erase_row(uint32_t *dst);

void flash_write_words(uint32_t *dst, uint32_t *src, uint32_t n_words);

void flash_write_row(uint32_t *dst, uint32_t *src);

void flash_copy(uint32_t *dst, uint32_t *src, uint32_t size);

#endif
