Commit d5abb7e8 authored by Grzegorz Daniluk's avatar Grzegorz Daniluk

flash: adding erase function matching sdb-lib convention

parent bcb4fdef
...@@ -103,6 +103,26 @@ int flash_read(uint32_t addr, uint8_t *buf, int count) ...@@ -103,6 +103,26 @@ int flash_read(uint32_t addr, uint8_t *buf, int count)
return count; return count;
} }
int flash_erase(uint32_t addr, int count)
{
int i;
int sectors;
/*calc number of sectors to be removed*/
if(count % FLASH_BLOCKSIZE > 0)
sectors = 1;
else
sectors = 0;
sectors += (count / FLASH_BLOCKSIZE);
for(i=0; i<sectors; ++i) {
flash_serase(addr + i*FLASH_BLOCKSIZE);
while(flash_rsr() & 0x01);
}
return count;
}
/* /*
* Sector erase * Sector erase
*/ */
......
...@@ -11,10 +11,13 @@ ...@@ -11,10 +11,13 @@
#include "types.h" #include "types.h"
#define FLASH_BLOCKSIZE 512
/* Flash interface functions */ /* Flash interface functions */
void flash_init(void); void flash_init(void);
int flash_write(uint32_t addr, uint8_t *buf, int count); int flash_write(uint32_t addr, uint8_t *buf, int count);
int flash_read(uint32_t addr, uint8_t *buf, int count); int flash_read(uint32_t addr, uint8_t *buf, int count);
int flash_erase(uint32_t addr, int count);
void flash_serase(uint32_t addr); void flash_serase(uint32_t addr);
void flash_berase(void); void flash_berase(void);
uint8_t flash_rsr(void); uint8_t flash_rsr(void);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment