Skip to content

Commit d535124

Browse files
committed
Added commands wrappers to sepatare led control
1 parent e262e60 commit d535124

File tree

1 file changed

+44
-16
lines changed

1 file changed

+44
-16
lines changed

firmware/nand_programmer.c

Lines changed: 44 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -209,25 +209,32 @@ static int np_send_bad_block_info(uint32_t addr)
209209
return 0;
210210
}
211211

212-
static int np_cmd_nand_read_id(np_prog_t *prog)
212+
static int _np_cmd_nand_read_id(np_prog_t *prog)
213213
{
214214
np_resp_id_t resp;
215215
size_t resp_len = sizeof(resp);
216216

217217
DEBUG_PRINT("Read ID command\r\n");
218218

219-
led_rd_set(true);
220-
221219
resp.header.code = NP_RESP_DATA;
222220
resp.header.info = resp_len - sizeof(resp.header);
223221
nand_read_id(&resp.nand_id);
224222

225223
if (np_comm_cb)
226224
np_comm_cb->send((uint8_t *)&resp, resp_len);
227225

226+
return 0;
227+
}
228+
229+
static int np_cmd_nand_read_id(np_prog_t *prog)
230+
{
231+
int ret;
232+
233+
led_rd_set(true);
234+
ret = _np_cmd_nand_read_id(prog);
228235
led_rd_set(false);
229236

230-
return 0;
237+
return ret;
231238
}
232239

233240
static int np_nand_erase(np_prog_t *prog, uint32_t page)
@@ -257,7 +264,7 @@ static int np_nand_erase(np_prog_t *prog, uint32_t page)
257264
return 0;
258265
}
259266

260-
static int np_cmd_nand_erase(np_prog_t *prog)
267+
static int _np_cmd_nand_erase(np_prog_t *prog)
261268
{
262269
uint32_t addr, page, pages_in_block, len;
263270
np_erase_cmd_t *erase_cmd = (np_erase_cmd_t *)prog->rx_buf;
@@ -267,8 +274,6 @@ static int np_cmd_nand_erase(np_prog_t *prog)
267274

268275
DEBUG_PRINT("Erase at 0x%lx %lx bytes command\r\n", addr, len);
269276

270-
led_wr_set(true);
271-
272277
if (addr & (prog->chip_info->block_size - 1))
273278
return np_send_error(NP_ERR_ADDR_NOT_ALIGN);
274279

@@ -296,9 +301,18 @@ static int np_cmd_nand_erase(np_prog_t *prog)
296301
page += pages_in_block;
297302
}
298303

304+
return np_send_ok_status();
305+
}
306+
307+
static int np_cmd_nand_erase(np_prog_t *prog)
308+
{
309+
int ret;
310+
311+
led_wr_set(true);
312+
ret = _np_cmd_nand_erase(prog);
299313
led_wr_set(false);
300314

301-
return np_send_ok_status();
315+
return ret;
302316
}
303317

304318
static int np_send_write_ack(uint32_t bytes_ack)
@@ -526,7 +540,7 @@ static int np_nand_read(uint32_t addr, np_page_t *page,
526540
return 0;
527541
}
528542

529-
static int np_cmd_nand_read(np_prog_t *prog)
543+
static int _np_cmd_nand_read(np_prog_t *prog)
530544
{
531545
uint32_t addr;
532546
static np_page_t page;
@@ -536,8 +550,6 @@ static int np_cmd_nand_read(np_prog_t *prog)
536550
np_read_cmd_t *read_cmd = (np_read_cmd_t *)prog->rx_buf;
537551
np_resp_t *resp = (np_resp_t *)np_packet_send_buf;
538552

539-
led_rd_set(true);
540-
541553
DEBUG_PRINT("Read at 0x%lx %lx bytes command\r\n", read_cmd->addr,
542554
read_cmd->len);
543555

@@ -598,9 +610,18 @@ static int np_cmd_nand_read(np_prog_t *prog)
598610
}
599611
}
600612

613+
return 0;
614+
}
615+
616+
static int np_cmd_nand_read(np_prog_t *prog)
617+
{
618+
int ret;
619+
620+
led_rd_set(true);
621+
ret = _np_cmd_nand_read(prog);
601622
led_rd_set(false);
602623

603-
return 0;
624+
return ret;
604625
}
605626

606627
static int np_cmd_nand_select(np_prog_t *prog)
@@ -660,13 +681,11 @@ static int np_read_bad_block_info_from_page(np_prog_t *prog, uint32_t block,
660681
return 0;
661682
}
662683

663-
static int np_cmd_read_bad_blocks(np_prog_t *prog)
684+
static int _np_cmd_read_bad_blocks(np_prog_t *prog)
664685
{
665686
bool is_bad;
666687
uint32_t block, block_num, page_num, page;
667688

668-
led_rd_set(true);
669-
670689
block_num = prog->chip_info->size / prog->chip_info->block_size;
671690
page_num = prog->chip_info->block_size / prog->chip_info->page_size;
672691

@@ -689,9 +708,18 @@ static int np_cmd_read_bad_blocks(np_prog_t *prog)
689708
}
690709
}
691710

711+
return np_send_ok_status();
712+
}
713+
714+
int np_cmd_read_bad_blocks(np_prog_t *prog)
715+
{
716+
int ret;
717+
718+
led_rd_set(true);
719+
ret = _np_cmd_read_bad_blocks(prog);
692720
led_rd_set(false);
693721

694-
return np_send_ok_status();
722+
return ret;
695723
}
696724

697725
static np_cmd_handler_t cmd_handler[] =

0 commit comments

Comments
 (0)