kopia lustrzana https://github.com/OpenRTX/OpenRTX
Added implementation of the standard NVM device API to AT24Cx driver.
rodzic
ab66054341
commit
d20f0e2c8d
|
@ -23,12 +23,32 @@
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
#include <interfaces/nvmem.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Driver for ATMEL AT24Cx family of I2C EEPROM devices, used as external non
|
* Driver for ATMEL AT24Cx family of I2C EEPROM devices, used as external non
|
||||||
* volatile memory on various radios to store global settings and contact data.
|
* volatile memory on various radios to store global settings and contact data.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Device driver API for AT24Cx EEPROM memory.
|
||||||
|
*/
|
||||||
|
extern const struct nvmApi AT24Cx_api;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiate an AT24Cx nonvolatile memory device.
|
||||||
|
*
|
||||||
|
* @param name: instance name.
|
||||||
|
*/
|
||||||
|
#define AT24Cx_DEVICE_DEFINE(name) \
|
||||||
|
struct nvmDevice name = \
|
||||||
|
{ \
|
||||||
|
.config = NULL, \
|
||||||
|
.priv = NULL, \
|
||||||
|
.api = &AT24Cx_api \
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialise driver for external EEPROM.
|
* Initialise driver for external EEPROM.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -96,3 +96,41 @@ int AT24Cx_writeData(uint32_t addr, const void *buf, size_t len)
|
||||||
return 0;
|
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;
|
||||||
|
|
||||||
|
return AT24Cx_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 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 =
|
||||||
|
{
|
||||||
|
.read = nvm_api_read,
|
||||||
|
.write = nvm_api_write,
|
||||||
|
.erase = NULL,
|
||||||
|
.sync = NULL,
|
||||||
|
.params = nvm_api_params
|
||||||
|
};
|
||||||
|
|
Ładowanie…
Reference in New Issue