Reorganized GDx nonvolatile memory devices

nvm-refactor
Silvano Seva 2024-04-05 21:07:32 +02:00
rodzic 0aa2818d4a
commit 854197d15e
3 zmienionych plików z 31 dodań i 39 usunięć

Wyświetl plik

@ -31,22 +31,23 @@
*/
/**
* Device driver API for AT24Cx EEPROM memory.
* Device driver and information block for AT24Cx EEPROM memory.
*/
extern const struct nvmApi AT24Cx_api;
extern const struct nvmOps AT24Cx_ops;
extern const struct nvmInfo AT24Cx_info;
/**
* Instantiate an AT24Cx nonvolatile memory device.
*
* @param name: instance name.
* @param sz: memory size, in bytes.
*/
#define AT24Cx_DEVICE_DEFINE(name) \
struct nvmDevice name = \
{ \
.config = NULL, \
.priv = NULL, \
.api = &AT24Cx_api \
#define AT24Cx_DEVICE_DEFINE(name, sz) \
struct nvmDevice name = \
{ \
.ops = &AT24Cx_ops, \
.info = &AT24Cx_info, \
.size = sz \
};
/**

Wyświetl plik

@ -96,15 +96,6 @@ int AT24Cx_writeData(uint32_t addr, const void *buf, size_t len)
return 0;
}
static const struct nvmParams AT24Cx_params =
{
.write_size = 1,
.erase_size = 1,
.erase_cycles = 1000000,
.type = NVM_EEPROM,
};
static int nvm_api_read(const struct nvmDevice *dev, uint32_t offset, void *data, size_t len)
{
(void) dev;
@ -119,18 +110,19 @@ static int nvm_api_write(const struct nvmDevice *dev, uint32_t offset, const voi
return AT24Cx_writeData(offset, data, len);
}
static const struct nvmParams *nvm_api_params(const struct nvmDevice *dev)
{
(void) dev;
return &AT24Cx_params;
}
const struct nvmApi AT24Cx_api =
const struct nvmOps AT24Cx_ops =
{
.read = nvm_api_read,
.write = nvm_api_write,
.erase = NULL,
.sync = NULL,
.params = nvm_api_params
.sync = NULL
};
const struct nvmInfo AT24Cx_info =
{
.write_size = 1,
.erase_size = 1,
.erase_cycles = 1000000,
.device_info = NVM_EEPROM,
};

Wyświetl plik

@ -27,23 +27,21 @@
#include "AT24Cx.h"
#include "W25Qx.h"
W25Qx_DEVICE_DEFINE(W25Q80, W25Qx_api)
AT24Cx_DEVICE_DEFINE(AT24C512)
W25Qx_DEVICE_DEFINE(eflash, 0x100000) // 1 MB, 8 Mbit
AT24Cx_DEVICE_DEFINE(eeprom, 0x10000) // 64 kB, 512 kbit
static const struct nvmArea areas[] =
static const struct nvmDescriptor nvmDevices[] =
{
{
.name = "External flash",
.dev = &W25Q80,
.startAddr = 0x0000,
.size = 0x100000, // 1 MB, 8 Mbit
.dev = &eflash,
.partNum = 0,
.partitions = NULL
},
{
.name = "EEPROM",
.dev = &AT24C512,
.startAddr = 0x0000,
.size = 0x10000, // 64 kB, 512 kbit
.dev = &eeprom,
.partNum = 0,
.partitions = NULL
}
};
@ -124,11 +122,12 @@ void nvm_terminate()
AT24Cx_terminate();
}
size_t nvm_getMemoryAreas(const struct nvmArea **list)
const struct nvmDescriptor *nvm_getDesc(const size_t index)
{
*list = &areas[0];
if(index > 2)
return NULL;
return (sizeof(areas) / sizeof(struct nvmArea));
return &nvmDevices[index];
}
void nvm_readCalibData(void *buf)