diff --git a/platform/drivers/NVM/W25Qx.c b/platform/drivers/NVM/W25Qx.c index 1d1d5fbf..49cb4598 100644 --- a/platform/drivers/NVM/W25Qx.c +++ b/platform/drivers/NVM/W25Qx.c @@ -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 +}; diff --git a/platform/drivers/NVM/W25Qx.h b/platform/drivers/NVM/W25Qx.h index 53a6965c..e8913982 100644 --- a/platform/drivers/NVM/W25Qx.h +++ b/platform/drivers/NVM/W25Qx.h @@ -24,12 +24,38 @@ #include #include #include +#include /** * 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. */