Skip to content

Commit 98e522c

Browse files
committed
Refactored write end command handler
1 parent d813e66 commit 98e522c

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

firmware/nand_programmer.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ typedef struct
158158
uint8_t *rx_buf;
159159
uint32_t addr;
160160
uint32_t len;
161-
int addr_is_valid;
161+
int addr_is_set;
162162
np_page_t page;
163163
uint32_t bytes_written;
164164
uint32_t bytes_ack;
@@ -370,7 +370,7 @@ static int np_cmd_nand_write_start(np_prog_t *prog)
370370

371371
prog->addr = addr;
372372
prog->len = len;
373-
prog->addr_is_valid = 1;
373+
prog->addr_is_set = 1;
374374

375375
prog->page.page = addr / prog->chip_info->page_size;
376376
prog->page.offset = 0;
@@ -447,7 +447,7 @@ static int np_cmd_nand_write_data(np_prog_t *prog)
447447
return NP_ERR_CMD_DATA_SIZE;
448448
}
449449

450-
if (!prog->addr_is_valid)
450+
if (!prog->addr_is_set)
451451
{
452452
ERROR_PRINT("Write address is not set\r\n");
453453
return NP_ERR_ADDR_INVALID;
@@ -506,15 +506,16 @@ static int np_cmd_nand_write_data(np_prog_t *prog)
506506

507507
static int np_cmd_nand_write_end(np_prog_t *prog)
508508
{
509-
if (prog->page.offset)
510-
goto Error;
509+
prog->addr_is_set = 0;
511510

512-
prog->addr_is_valid = 0;
511+
if (prog->page.offset)
512+
{
513+
ERROR_PRINT("Data of 0x%lx length was not written\r\n",
514+
prog->page.offset);
515+
return NP_ERR_NAND_WR;
516+
}
513517

514518
return np_send_ok_status();
515-
516-
Error:
517-
return NP_ERR_NAND_WR;
518519
}
519520

520521
static int np_cmd_nand_write(np_prog_t *prog)

0 commit comments

Comments
 (0)