Merge pull request #314 from rusefi/rusefi-20.3.x
reviving 24 series eeprom
This commit is contained in:
parent
4f0d4f085f
commit
63b50e410c
|
@ -116,6 +116,9 @@ typedef struct {
|
|||
|
||||
const EepromDevice *EepromFindDevice(uint8_t id);
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
#endif
|
||||
EepromFileStream *EepromFileOpen(EepromFileStream *efs,
|
||||
const EepromFileConfig *eepcfg,
|
||||
const EepromDevice *eepdev);
|
||||
|
@ -127,8 +130,8 @@ size_t EepromWriteByte(EepromFileStream *efs, uint8_t data);
|
|||
size_t EepromWriteHalfword(EepromFileStream *efs, uint16_t data);
|
||||
size_t EepromWriteWord(EepromFileStream *efs, uint32_t data);
|
||||
|
||||
msg_t eepfs_getsize(void *ip);
|
||||
msg_t eepfs_getposition(void *ip);
|
||||
msg_t eepfs_getsize(void *ip, fileoffset_t *offset);
|
||||
msg_t eepfs_getposition(void *ip, fileoffset_t *offset);
|
||||
msg_t eepfs_lseek(void *ip, fileoffset_t offset);
|
||||
msg_t eepfs_close(void *ip);
|
||||
msg_t eepfs_geterror(void *ip);
|
||||
|
|
|
@ -189,8 +189,8 @@ static msg_t eeprom_write(const I2CEepromFileConfig *eepcfg, uint32_t offset,
|
|||
*/
|
||||
static size_t __clamp_size(void *ip, size_t n) {
|
||||
|
||||
if (((size_t)eepfs_getposition(ip) + n) > (size_t)eepfs_getsize(ip))
|
||||
return eepfs_getsize(ip) - eepfs_getposition(ip);
|
||||
if (((size_t)eepfs_getposition(ip, NULL) + n) > (size_t)eepfs_getsize(ip, NULL))
|
||||
return eepfs_getsize(ip, NULL) - eepfs_getposition(ip, NULL);
|
||||
else
|
||||
return n;
|
||||
}
|
||||
|
@ -205,10 +205,10 @@ static msg_t __fitted_write(void *ip, const uint8_t *data, size_t len, uint32_t
|
|||
osalDbgAssert(len > 0, "len must be greater than 0");
|
||||
|
||||
status = eeprom_write(((I2CEepromFileStream *)ip)->cfg,
|
||||
eepfs_getposition(ip), data, len);
|
||||
eepfs_getposition(ip, NULL), data, len);
|
||||
if (status == MSG_OK) {
|
||||
*written += len;
|
||||
eepfs_lseek(ip, eepfs_getposition(ip) + len);
|
||||
eepfs_lseek(ip, eepfs_getposition(ip, NULL) + len);
|
||||
}
|
||||
|
||||
return status;
|
||||
|
@ -240,9 +240,9 @@ static size_t write(void *ip, const uint8_t *bp, size_t n) {
|
|||
|
||||
pagesize = ((EepromFileStream *)ip)->cfg->pagesize;
|
||||
firstpage = (((EepromFileStream *)ip)->cfg->barrier_low +
|
||||
eepfs_getposition(ip)) / pagesize;
|
||||
eepfs_getposition(ip, NULL)) / pagesize;
|
||||
lastpage = (((EepromFileStream *)ip)->cfg->barrier_low +
|
||||
eepfs_getposition(ip) + n - 1) / pagesize;
|
||||
eepfs_getposition(ip, NULL) + n - 1) / pagesize;
|
||||
|
||||
/* data fits in single page */
|
||||
if (firstpage == lastpage) {
|
||||
|
@ -253,7 +253,7 @@ static size_t write(void *ip, const uint8_t *bp, size_t n) {
|
|||
|
||||
else {
|
||||
/* write first piece of data to first page boundary */
|
||||
len = ((firstpage + 1) * pagesize) - eepfs_getposition(ip);
|
||||
len = ((firstpage + 1) * pagesize) - eepfs_getposition(ip, NULL);
|
||||
len -= ((EepromFileStream *)ip)->cfg->barrier_low;
|
||||
if (__fitted_write(ip, bp, len, &written) != MSG_OK)
|
||||
return written;
|
||||
|
@ -302,9 +302,9 @@ static size_t read(void *ip, uint8_t *bp, size_t n) {
|
|||
if (n == 1) {
|
||||
uint8_t __buf[2];
|
||||
/* if NOT last byte of file requested */
|
||||
if ((eepfs_getposition(ip) + 1) < eepfs_getsize(ip)) {
|
||||
if ((eepfs_getposition(ip, NULL) + 1) < eepfs_getsize(ip, NULL)) {
|
||||
if (read(ip, __buf, 2) == 2) {
|
||||
eepfs_lseek(ip, (eepfs_getposition(ip) + 1));
|
||||
eepfs_lseek(ip, (eepfs_getposition(ip, NULL) + 1));
|
||||
bp[0] = __buf[0];
|
||||
return 1;
|
||||
}
|
||||
|
@ -312,9 +312,9 @@ static size_t read(void *ip, uint8_t *bp, size_t n) {
|
|||
return 0;
|
||||
}
|
||||
else {
|
||||
eepfs_lseek(ip, (eepfs_getposition(ip) - 1));
|
||||
eepfs_lseek(ip, (eepfs_getposition(ip, NULL) - 1));
|
||||
if (read(ip, __buf, 2) == 2) {
|
||||
eepfs_lseek(ip, (eepfs_getposition(ip) + 2));
|
||||
eepfs_lseek(ip, (eepfs_getposition(ip, NULL) + 2));
|
||||
bp[0] = __buf[1];
|
||||
return 1;
|
||||
}
|
||||
|
@ -326,11 +326,11 @@ static size_t read(void *ip, uint8_t *bp, size_t n) {
|
|||
|
||||
/* call low level function */
|
||||
status = eeprom_read(((I2CEepromFileStream *)ip)->cfg,
|
||||
eepfs_getposition(ip), bp, n);
|
||||
eepfs_getposition(ip, NULL), bp, n);
|
||||
if (status != MSG_OK)
|
||||
return 0;
|
||||
else {
|
||||
eepfs_lseek(ip, (eepfs_getposition(ip) + n));
|
||||
eepfs_lseek(ip, (eepfs_getposition(ip, NULL) + n));
|
||||
return n;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -264,8 +264,8 @@ static msg_t ll_eeprom_write(const SPIEepromFileConfig *eepcfg, uint32_t offset,
|
|||
*/
|
||||
static size_t __clamp_size(void *ip, size_t n) {
|
||||
|
||||
if (((size_t)eepfs_getposition(ip) + n) > (size_t)eepfs_getsize(ip))
|
||||
return eepfs_getsize(ip) - eepfs_getposition(ip);
|
||||
if (((size_t)eepfs_getposition(ip, NULL) + n) > (size_t)eepfs_getsize(ip, NULL))
|
||||
return eepfs_getsize(ip, NULL) - eepfs_getposition(ip, NULL);
|
||||
else
|
||||
return n;
|
||||
}
|
||||
|
@ -280,10 +280,10 @@ static msg_t __fitted_write(void *ip, const uint8_t *data, size_t len, uint32_t
|
|||
osalDbgAssert(len > 0, "len must be greater than 0");
|
||||
|
||||
status = ll_eeprom_write(((SPIEepromFileStream *)ip)->cfg,
|
||||
eepfs_getposition(ip), data, len);
|
||||
eepfs_getposition(ip, NULL), data, len);
|
||||
if (status == MSG_OK) {
|
||||
*written += len;
|
||||
eepfs_lseek(ip, eepfs_getposition(ip) + len);
|
||||
eepfs_lseek(ip, eepfs_getposition(ip, NULL) + len);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
@ -315,8 +315,8 @@ static size_t write(void *ip, const uint8_t *bp, size_t n) {
|
|||
return 0;
|
||||
|
||||
pagesize = cfg->pagesize;
|
||||
firstpage = (cfg->barrier_low + eepfs_getposition(ip)) / pagesize;
|
||||
lastpage = ((cfg->barrier_low + eepfs_getposition(ip) + n) - 1) / pagesize;
|
||||
firstpage = (cfg->barrier_low + eepfs_getposition(ip, NULL)) / pagesize;
|
||||
lastpage = ((cfg->barrier_low + eepfs_getposition(ip, NULL) + n) - 1) / pagesize;
|
||||
|
||||
/* data fits in single page */
|
||||
if (firstpage == lastpage) {
|
||||
|
@ -327,7 +327,7 @@ static size_t write(void *ip, const uint8_t *bp, size_t n) {
|
|||
|
||||
else {
|
||||
/* write first piece of data to first page boundary */
|
||||
len = ((firstpage + 1) * pagesize) - eepfs_getposition(ip);
|
||||
len = ((firstpage + 1) * pagesize) - eepfs_getposition(ip, NULL);
|
||||
len -= cfg->barrier_low;
|
||||
if (__fitted_write(ip, bp, len, &written) != MSG_OK)
|
||||
return written;
|
||||
|
@ -373,11 +373,11 @@ static size_t read(void *ip, uint8_t *bp, size_t n) {
|
|||
|
||||
/* call low level function */
|
||||
status = ll_eeprom_read(((SPIEepromFileStream *)ip)->cfg,
|
||||
eepfs_getposition(ip), bp, n);
|
||||
eepfs_getposition(ip, NULL), bp, n);
|
||||
if (status != MSG_OK)
|
||||
return 0;
|
||||
else {
|
||||
eepfs_lseek(ip, (eepfs_getposition(ip) + n));
|
||||
eepfs_lseek(ip, (eepfs_getposition(ip, NULL) + n));
|
||||
return n;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -78,6 +78,9 @@ const EepromDevice *EepromFindDevice(uint8_t id) {
|
|||
* @note Fucntion allways successfully open file. All checking makes
|
||||
* in read/write functions.
|
||||
*/
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
#endif
|
||||
EepromFileStream *EepromFileOpen(EepromFileStream *efs,
|
||||
const EepromFileConfig *eepcfg,
|
||||
const EepromDevice *eepdev) {
|
||||
|
@ -132,7 +135,7 @@ size_t EepromWriteWord(EepromFileStream *efs, uint32_t data) {
|
|||
return fileStreamWrite(efs, (uint8_t *)&data, sizeof(data));
|
||||
}
|
||||
|
||||
msg_t eepfs_getsize(void *ip) {
|
||||
msg_t eepfs_getsize(void *ip, fileoffset_t *offset) {
|
||||
|
||||
uint32_t h, l;
|
||||
|
||||
|
@ -144,7 +147,7 @@ msg_t eepfs_getsize(void *ip) {
|
|||
return h - l;
|
||||
}
|
||||
|
||||
msg_t eepfs_getposition(void *ip) {
|
||||
msg_t eepfs_getposition(void *ip, fileoffset_t *offset) {
|
||||
|
||||
osalDbgCheck((ip != NULL) && (((EepromFileStream *)ip)->vmt != NULL));
|
||||
|
||||
|
@ -157,7 +160,7 @@ msg_t eepfs_lseek(void *ip, fileoffset_t offset) {
|
|||
|
||||
osalDbgCheck((ip != NULL) && (((EepromFileStream *)ip)->vmt != NULL));
|
||||
|
||||
size = eepfs_getsize(ip);
|
||||
size = eepfs_getsize(ip, NULL);
|
||||
if (offset > size)
|
||||
offset = size;
|
||||
((EepromFileStream *)ip)->position = offset;
|
||||
|
|
Loading…
Reference in New Issue