Reorganized ttwrplus nonvolatile memory devices

Silvano Seva 2024-04-05 21:20:50 +02:00
rodzic 65afc9bc4c
commit 358c66a2a6
3 zmienionych plików z 59 dodań i 44 usunięć

Wyświetl plik

@ -22,51 +22,46 @@
#include <zephyr/drivers/flash.h>
#include "flash_zephyr.h"
#define TO_DEV_HANDLE(x) ((const struct zephyrFlashDevice *) x)
static int nvm_api_read(const struct nvmDevice *dev, uint32_t offset,
void *data, size_t len)
{
const struct device *fDev = (const struct device *)(dev->config);
return flash_read(fDev, offset, data, len);
return flash_read(TO_DEV_HANDLE(dev)->device, offset, data, len);
}
static int nvm_api_write(const struct nvmDevice *dev, uint32_t offset,
const void *data, size_t len)
{
const struct device *fDev = (const struct device *)(dev->config);
return flash_write(fDev, offset, data, len);
return flash_write(TO_DEV_HANDLE(dev)->device, offset, data, len);
}
static int nvm_api_erase(const struct nvmDevice *dev, uint32_t offset, size_t size)
{
const struct device *fDev = (const struct device *)(dev->config);
return flash_erase(fDev, offset, size);
return flash_erase(TO_DEV_HANDLE(dev)->device, offset, size);
}
static const struct nvmParams *nvm_api_params(const struct nvmDevice *dev)
{
struct nvmParams *params = (struct nvmParams *)(dev->priv);
const struct device *fDev = (const struct device *)(dev->config);
int zephirFlash_init(const struct zephyrFlashDevice* dev)
{
// Retrieve write size
const struct flash_parameters *info = flash_get_parameters(fDev);
params->write_size = info->write_block_size;
const struct flash_parameters *info = flash_get_parameters(TO_DEV_HANDLE(dev)->device);
struct nvmInfo *pInfo = (struct nvmInfo *)(TO_DEV_HANDLE(dev)->info);
// TODO: erase size and erase cycles to be retrieved from the real device.
params->erase_size = 4096;
params->erase_cycles = 100000;
params->type = NVM_FLASH;
pInfo->write_size = info->write_block_size;
pInfo->erase_size = 4096;
pInfo->erase_cycles = 100000;
pInfo->device_info = NVM_FLASH | NVM_WRITE | NVM_BITWRITE | NVM_ERASE;
return params;
return 0;
}
const struct nvmApi zephyr_flash_api =
const struct nvmOps zephyr_flash_ops =
{
.read = nvm_api_read,
.write = nvm_api_write,
.erase = nvm_api_erase,
.sync = NULL,
.params = nvm_api_params
.sync = NULL
};

Wyświetl plik

@ -27,11 +27,22 @@
* Wrapper interface for the Zephyr RTOS flash memory device driver.
*/
/**
* Driver data structure for Zephyr RTOS flash memory device.
*/
struct zephyrFlashDevice
{
const struct nvmOps *ops; ///< Device operations
const struct nvmInfo *info; ///< Device info
const size_t size; ///< Device size
const struct device *device; ///< Underlying Zephyr RTOS device driver
};
/**
* Device driver API for Zephyr RTOS flash memory.
*/
extern const struct nvmApi zephyr_flash_api;
extern const struct nvmOps zephyr_flash_ops;
/**
* Instantiate a nonvolatile memory device based on Zephyr RTOS flash device
@ -39,14 +50,25 @@ extern const struct nvmApi zephyr_flash_api;
*
* @param name: device name.
* @param alias: devicetree alias of the flash device.
* @param sz: memory size, in bytes.
*/
#define ZEPHYR_FLASH_DEVICE_DEFINE(name, alias) \
static struct nvmParams flash_params_##name; \
static const struct nvmDevice name = \
{ \
.config = DEVICE_DT_GET(DT_ALIAS(alias)), \
.priv = &flash_params_##name, \
.api = &zephyr_flash_api \
#define ZEPHYR_FLASH_DEVICE_DEFINE(name, alias, sz) \
static struct nvmInfo nvm_devInfo_##name; \
static const struct zephyrFlashDevice name = \
{ \
.ops = &zephyr_flash_ops, \
.info = &nvm_devInfo_##name, \
.size = sz, \
.device = DEVICE_DT_GET(DT_ALIAS(alias)) \
};
/**
* Initialize a Zephyr RTOS flash device driver instance.
*
* @param dev: device handle.
* @return zero on success, a negative error code otherwise.
*/
int zephirFlash_init(const struct zephyrFlashDevice* dev);
#endif /* FLASH_ZEPHYR_H */

Wyświetl plik

@ -23,23 +23,20 @@
#include <interfaces/nvmem.h>
#include "flash_zephyr.h"
ZEPHYR_FLASH_DEVICE_DEFINE(extFlash, flash);
ZEPHYR_FLASH_DEVICE_DEFINE(eflash, flash, FIXED_PARTITION_SIZE(storage_partition));
static const struct nvmArea areas[] =
static const struct nvmDescriptor nvMemory =
{
{
.name = "External flash",
.dev = &extFlash,
.startAddr = FIXED_PARTITION_OFFSET(storage_partition),
.size = FIXED_PARTITION_SIZE(storage_partition),
.partitions = NULL
}
.name = "External flash",
.dev = (const struct nvmDevice *) &eflash,
.partNum = 0,
.partitions = NULL
};
void nvm_init()
{
zephirFlash_init(&eflash);
}
void nvm_terminate()
@ -47,11 +44,12 @@ void nvm_terminate()
}
size_t nvm_getMemoryAreas(const struct nvmArea **list)
const struct nvmDescriptor *nvm_getDesc(const size_t index)
{
*list = &areas[0];
if(index > 0)
return NULL;
return (sizeof(areas) / sizeof(struct nvmArea));
return &nvMemory;
}
void nvm_readCalibData(void *buf)