update xmem

This commit is contained in:
Xenofon (Fontas) Fafoutis 2018-04-04 11:08:35 +01:00
parent b4b6ab1bdf
commit 46d1dd1293
1 changed files with 13 additions and 13 deletions

View File

@ -60,7 +60,7 @@
void void
xmem_init(void) xmem_init(void)
{ {
ext_flash_open(); ext_flash_open(NULL);
} }
@ -71,21 +71,21 @@ xmem_pread(void *_p, int size, unsigned long addr)
uint8_t x; uint8_t x;
int i; int i;
rv = ext_flash_open(); rv = ext_flash_open(NULL);
if(!rv) { if(!rv) {
PRINTF("Could not open flash to save config\n"); PRINTF("Could not open flash to save config\n");
ext_flash_close(); ext_flash_close(NULL);
return -1; return -1;
} }
rv = ext_flash_read(addr, size, _p); rv = ext_flash_read(NULL, addr, size, _p);
for (i = 0; i < size; i++){ for (i = 0; i < size; i++){
x = ~*((uint8_t *)_p + i); x = ~*((uint8_t *)_p + i);
*((uint8_t *)_p+i) = x; *((uint8_t *)_p+i) = x;
} }
ext_flash_close(); ext_flash_close(NULL);
if(rv) if(rv)
return size; return size;
@ -104,11 +104,11 @@ xmem_pwrite(const void *_buf, int size, unsigned long addr)
uint8_t tmp_buf[XMEM_BUFF_LENGHT]; uint8_t tmp_buf[XMEM_BUFF_LENGHT];
rv = ext_flash_open(); rv = ext_flash_open(NULL);
if(!rv) { if(!rv) {
PRINTF("Could not open flash to save config!\n"); PRINTF("Could not open flash to save config!\n");
ext_flash_close(); ext_flash_close(NULL);
return -1; return -1;
} }
@ -117,14 +117,14 @@ xmem_pwrite(const void *_buf, int size, unsigned long addr)
for (i = 0; i < to_write; i++) { for (i = 0; i < to_write; i++) {
tmp_buf[i] = ~*((uint8_t *)_buf + j + i); tmp_buf[i] = ~*((uint8_t *)_buf + j + i);
} }
rv = ext_flash_write(addr + j, to_write, tmp_buf); rv = ext_flash_write(NULL, addr + j, to_write, tmp_buf);
if (!rv) { if (!rv) {
PRINTF("Could not write flash memory!\n"); PRINTF("Could not write flash memory!\n");
return size - remain; return size - remain;
} }
} }
ext_flash_close(); ext_flash_close(NULL);
return size; return size;
} }
@ -135,12 +135,12 @@ xmem_erase(long size, unsigned long addr)
{ {
int rv; int rv;
rv = ext_flash_open(); rv = ext_flash_open(NULL);
if(!rv) { if(!rv) {
PRINTF("Could not open flash to save config\n"); PRINTF("Could not open flash to save config\n");
ext_flash_close(); ext_flash_close(NULL);
return -1; return -1;
} }
@ -154,9 +154,9 @@ xmem_erase(long size, unsigned long addr)
return -1; return -1;
} }
rv = ext_flash_erase(addr, size); rv = ext_flash_erase(NULL, addr, size);
ext_flash_close(); ext_flash_close(NULL);
watchdog_periodic(); watchdog_periodic();