Reorganized ttwrplus nonvolatile memory devices

pull/239/merge
Silvano Seva 2024-04-05 21:20:50 +02:00
rodzic 0a2dc3567d
commit 6a1cdb5fd5
3 zmienionych plików z 58 dodań i 56 usunięć

Wyświetl plik

@ -1,8 +1,8 @@
/***************************************************************************
* Copyright (C) 2023 by Federico Amedeo Izzo IU2NUO, *
* Niccolò Izzo IU2KIN *
* Frederik Saraci IU2NRO *
* Silvano Seva IU2KWO *
* Copyright (C) 2023 - 2024 by Federico Amedeo Izzo IU2NUO, *
* Niccolò Izzo IU2KIN *
* Frederik Saraci IU2NRO *
* Silvano Seva IU2KWO *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
@ -22,51 +22,45 @@
#include <zephyr/drivers/flash.h>
#include "flash_zephyr.h"
#define TO_DEV_HANDLE(x) ((const struct device *) 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->priv), 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->priv), 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->priv), 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 nvmDevice* 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->priv));
// 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;
dev->info->write_size = info->write_block_size;
dev->info->erase_size = 4096;
dev->info->erase_cycles = 100000;
dev->info->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

@ -1,8 +1,8 @@
/***************************************************************************
* Copyright (C) 2023 by Federico Amedeo Izzo IU2NUO, *
* Niccolò Izzo IU2KIN *
* Frederik Saraci IU2NRO *
* Silvano Seva IU2KWO *
* Copyright (C) 2023 - 2024 by Federico Amedeo Izzo IU2NUO, *
* Niccolò Izzo IU2KIN *
* Frederik Saraci IU2NRO *
* Silvano Seva IU2KWO *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
@ -30,8 +30,7 @@
/**
* 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 +38,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 nvmDevice name = \
{ \
.priv = DEVICE_DT_GET(DT_ALIAS(alias)) \
.ops = &zephyr_flash_ops, \
.info = &nvm_devInfo_##name, \
.size = sz \
};
/**
* 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 nvmDevice* dev);
#endif /* FLASH_ZEPHYR_H */

Wyświetl plik

@ -1,8 +1,8 @@
/***************************************************************************
* Copyright (C) 2023 by Federico Amedeo Izzo IU2NUO, *
* Niccolò Izzo IU2KIN *
* Frederik Saraci IU2NRO *
* Silvano Seva IU2KWO *
* Copyright (C) 2023 - 2024 by Federico Amedeo Izzo IU2NUO, *
* Niccolò Izzo IU2KIN *
* Frederik Saraci IU2NRO *
* Silvano Seva IU2KWO *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
@ -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 = &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)