|
|
@@ -7,11 +7,15 @@
|
|
|
#include "snfud_def.h"
|
|
|
#include "FreeRTOS.h"
|
|
|
#include "task.h"
|
|
|
+#include "timer.h"
|
|
|
|
|
|
#if DEVICE_TYPE_SELECT == SPI_NAND_FLASH
|
|
|
#define SNF_GET_CHIP(flash) ((flash)->user_data)
|
|
|
#define SNF_SET_CHIP(chip, flash) (flash)->user_data = chip
|
|
|
#define SNFUD_ASSERT(EXPR) if (!(EXPR)) {printf("ERR: [func:%s line:%d] Assert(%s) fail.\n", __func__, __LINE__, #EXPR); while (1);}
|
|
|
+#define SNFUD_RETRY_PROCESS(delay, retry, result) \
|
|
|
+ if (retry-- == 0) {result = SFUD_ERR_TIMEOUT; break;} \
|
|
|
+ else {snf_delay_us(delay);}
|
|
|
|
|
|
|
|
|
enum {
|
|
|
@@ -185,6 +189,13 @@ static sfud_err snf_qspi_fast_read_enable(sfud_flash *flash, uint8_t data_line_w
|
|
|
}
|
|
|
#endif /* SNFUD_USING_QSPI */
|
|
|
|
|
|
+static void snf_delay_us(unsigned int us) {
|
|
|
+ int time = get_timer(0);
|
|
|
+ while (get_timer(0) - time < us) {
|
|
|
+ taskYIELD();
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
static int snf_reg_read(const sfud_flash *flash, uint8_t opcode, uint8_t *value)
|
|
|
{
|
|
|
int result = SFUD_SUCCESS;
|
|
|
@@ -260,19 +271,21 @@ static sfud_err snf_wait_read_busy(const sfud_flash *flash, uint8_t *status)
|
|
|
|
|
|
chip = SNF_GET_CHIP(flash);
|
|
|
if (!chip->priv_info || !chip->priv_info->crbsyBit) {
|
|
|
- return snf_wait_busy(flash, status);
|
|
|
+ read_busy_bit = SNFUD_STATUS_REG_BUSY;
|
|
|
+ } else {
|
|
|
+ read_busy_bit = (1 << chip->priv_info->crbsyBit);
|
|
|
}
|
|
|
- read_busy_bit = chip->priv_info->crbsyBit;
|
|
|
|
|
|
+ snf_delay_us(45); //delay 45 us.
|
|
|
while (1) {
|
|
|
- result = snf_reg_read(flash, SNFUD_CMD_STATUS_REG, status);
|
|
|
+ result = snf_reg_read(flash, SNFUD_CMD_STATUS_REG, status); // spend 7~8us
|
|
|
if (result == SFUD_SUCCESS) {
|
|
|
- if (!(*status & (1 << read_busy_bit))) {
|
|
|
+ if (!(*status & read_busy_bit)) {
|
|
|
return SFUD_SUCCESS;
|
|
|
}
|
|
|
}
|
|
|
/* retry counts */
|
|
|
- SFUD_RETRY_PROCESS(flash->retry.delay, retry_times, result);
|
|
|
+ SNFUD_RETRY_PROCESS(10, retry_times, result); //delay 10us every time.
|
|
|
}
|
|
|
|
|
|
return SFUD_ERR_TIMEOUT;
|
|
|
@@ -661,7 +674,7 @@ static int snf_write_physical_blcok(snfud_flash_chip *chip, uint32_t phy_blk, ui
|
|
|
if (result != SFUD_SUCCESS) {
|
|
|
SFUD_INFO("%s write page fail, result:%d.", __func__, result);
|
|
|
return result;
|
|
|
- }
|
|
|
+ }
|
|
|
curr_page++;
|
|
|
remain -= write_size;
|
|
|
pdata += write_size;
|
|
|
@@ -692,7 +705,7 @@ static int snf_read_physical_blcok(snfud_flash_chip *chip, uint32_t phy_blk, uin
|
|
|
if (result != SFUD_SUCCESS) {
|
|
|
SFUD_INFO("%s read page fail, result:%d", __func__, result);
|
|
|
return result;
|
|
|
- }
|
|
|
+ }
|
|
|
curr_page++;
|
|
|
remain -= read_size;
|
|
|
pdata += read_size;
|
|
|
@@ -1284,7 +1297,7 @@ sfud_err snfud_chip_erase(const sfud_flash *flash)
|
|
|
if (flash->spi.unlock) {
|
|
|
flash->spi.unlock(&flash->spi);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
SFUD_INFO("%s done.", __func__);
|
|
|
|
|
|
return result;
|
|
|
@@ -1585,7 +1598,6 @@ sfud_err snfud_read_one(const sfud_flash *flash, uint32_t addr, size_t size, uin
|
|
|
snf_part_info *part;
|
|
|
uint8_t status;
|
|
|
uint32_t blk;
|
|
|
-
|
|
|
|
|
|
SNFUD_ASSERT(flash);
|
|
|
/* must be call this function after initialize OK */
|