fixed dataflash sector count

also added range checks to read/write
This commit is contained in:
bsx 2011-06-15 13:16:12 +02:00
parent 1cad26360f
commit bf8a5b9e45
1 changed files with 5 additions and 1 deletions

View File

@ -28,6 +28,8 @@
#define SB_PROTECT (1 << 1) #define SB_PROTECT (1 << 1)
#define SB_PAGESIZE (1 << 0) #define SB_PAGESIZE (1 << 0)
#define MAX_PAGE (2048)
#define CS_LOW() gpioSetValue(RB_SPI_CS_DF, 0) #define CS_LOW() gpioSetValue(RB_SPI_CS_DF, 0)
#define CS_HIGH() gpioSetValue(RB_SPI_CS_DF, 1) #define CS_HIGH() gpioSetValue(RB_SPI_CS_DF, 1)
@ -77,6 +79,7 @@ DRESULT dataflash_read(BYTE *buff, DWORD sector, BYTE count) {
/* convert sector numbers to page numbers */ /* convert sector numbers to page numbers */
sector *= 2; sector *= 2;
count *= 2; count *= 2;
if (sector+count > MAX_PAGE) return RES_PARERR;
do { do {
wait_for_ready(); wait_for_ready();
@ -109,6 +112,7 @@ DRESULT dataflash_write(const BYTE *buff, DWORD sector, BYTE count) {
/* convert sector numbers to page numbers */ /* convert sector numbers to page numbers */
sector *= 2; sector *= 2;
count *= 2; count *= 2;
if (sector+count > MAX_PAGE) return RES_PARERR;
do { do {
wait_for_ready(); wait_for_ready();
@ -193,7 +197,7 @@ DRESULT dataflash_ioctl(BYTE ctrl, void *buff) {
break; break;
case GET_SECTOR_COUNT: case GET_SECTOR_COUNT:
// TODO: read from device ID register // TODO: read from device ID register
*(WORD*)buff = 2048; *(WORD*)buff = MAX_PAGE/2;
res = RES_OK; res = RES_OK;
break; break;
case GET_SECTOR_SIZE: case GET_SECTOR_SIZE: