Added implementation of the standard NVM device API to W25Qx driver.

pull/218/head
Silvano Seva 2023-11-18 13:10:39 +01:00
rodzic 7174246492
commit ab66054341
2 zmienionych plików z 87 dodań i 0 usunięć

Wyświetl plik

@ -278,3 +278,64 @@ int W25Qx_writeData(uint32_t addr, const void *buf, size_t len)
return 0;
}
static const struct nvmParams W25Qx_params =
{
.write_size = 1,
.erase_size = SECT_SIZE,
.erase_cycles = 100000,
.type = NVM_FLASH
};
static int nvm_api_readSecReg(const struct nvmDevice *dev, uint32_t offset, void *data, size_t len)
{
(void) dev;
return W25Qx_readSecurityRegister(offset, data, len);
}
static int nvm_api_read(const struct nvmDevice *dev, uint32_t offset, void *data, size_t len)
{
(void) dev;
return W25Qx_readData(offset, data, len);
}
static int nvm_api_write(const struct nvmDevice *dev, uint32_t offset, const void *data, size_t len)
{
(void) dev;
return W25Qx_writeData(offset, data, len);
}
static int nvm_api_erase(const struct nvmDevice *dev, uint32_t offset, size_t size)
{
(void) dev;
return W25Qx_erase(offset, size);
}
static const struct nvmParams *nvm_api_params(const struct nvmDevice *dev)
{
(void) dev;
return &W25Qx_params;
}
const struct nvmApi W25Qx_api =
{
.read = nvm_api_read,
.write = nvm_api_write,
.erase = nvm_api_erase,
.sync = NULL,
.params = nvm_api_params
};
const struct nvmApi W25Qx_secReg_api =
{
.read = nvm_api_readSecReg,
.write = NULL,
.erase = NULL,
.sync = NULL,
.params = nvm_api_params
};

Wyświetl plik

@ -24,12 +24,38 @@
#include <stdint.h>
#include <stdbool.h>
#include <sys/types.h>
#include <interfaces/nvmem.h>
/**
* Driver for Winbond W25Qx family of SPI flash devices, used as external non
* volatile memory on various radios to store both calibration and contact data.
*/
/**
* Device driver API for W25Qx main memory.
*/
extern const struct nvmApi W25Qx_api;
/**
* Device driver API for W25Qx security registers.
*/
extern const struct nvmApi W25Qx_secReg_api;
/**
* Instantiate an W25Qx nonvolatile memory device.
*
* @param name: device name.
* @param driver: device driver API.
*/
#define W25Qx_DEVICE_DEFINE(name, driver) \
struct nvmDevice name = \
{ \
.config = NULL, \
.priv = NULL, \
.api = &driver \
};
/**
* Initialise driver for external flash.
*/