Skip to content

Commit 94b95c9

Browse files
committed
Implemented progress indication for erase command
1 parent 309ca54 commit 94b95c9

File tree

8 files changed

+83
-3
lines changed

8 files changed

+83
-3
lines changed

firmware/nand_programmer.c

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,8 @@ enum
134134
NP_STATUS_ERROR = 0x01,
135135
NP_STATUS_BB = 0x02,
136136
NP_STATUS_WRITE_ACK = 0x03,
137-
NP_STATUS_BB_SKIP = 0x04,
137+
NP_STATUS_BB_SKIP = 0x04,
138+
NP_STATUS_PROGRESS = 0x05,
138139
};
139140

140141
typedef struct __attribute__((__packed__))
@@ -162,6 +163,12 @@ typedef struct __attribute__((__packed__))
162163
uint8_t err_code;
163164
} np_resp_err_t;
164165

166+
typedef struct __attribute__((__packed__))
167+
{
168+
np_resp_t header;
169+
uint32_t progress;
170+
} np_resp_progress_t;
171+
165172
typedef struct __attribute__((__packed__))
166173
{
167174
uint8_t major;
@@ -250,6 +257,17 @@ static int np_send_bad_block_info(uint32_t addr, uint32_t size, bool is_skipped)
250257
return 0;
251258
}
252259

260+
static int np_send_progress(uint32_t progress)
261+
{
262+
np_resp_t resp_header = { NP_RESP_STATUS, NP_STATUS_PROGRESS };
263+
np_resp_progress_t resp_progress = { resp_header, progress };
264+
265+
if (np_comm_cb->send((uint8_t *)&resp_progress, sizeof(resp_progress)))
266+
return -1;
267+
268+
return 0;
269+
}
270+
253271
static int _np_cmd_nand_read_id(np_prog_t *prog)
254272
{
255273
np_resp_id_t resp;
@@ -379,11 +397,11 @@ static int np_nand_erase(np_prog_t *prog, uint32_t page)
379397
static int _np_cmd_nand_erase(np_prog_t *prog)
380398
{
381399
int ret;
382-
uint32_t addr, page, pages_in_block, len;
400+
uint32_t addr, page, pages_in_block, len, total_len;
383401
np_erase_cmd_t *erase_cmd = (np_erase_cmd_t *)prog->rx_buf;
384402
bool is_bad = false, skip_bb = erase_cmd->flags.skip_bb;
385403

386-
len = erase_cmd->len;
404+
total_len = len = erase_cmd->len;
387405
addr = erase_cmd->addr;
388406

389407
DEBUG_PRINT("Erase at 0x%lx %lx bytes command\r\n", addr, len);
@@ -445,6 +463,8 @@ static int _np_cmd_nand_erase(np_prog_t *prog)
445463
/* On partial erase do not count bad blocks */
446464
if (!is_bad || (is_bad && erase_cmd->len == prog->chip_info.size))
447465
len -= prog->chip_info.block_size;
466+
467+
np_send_progress(total_len - len);
448468
}
449469

450470
return np_send_ok_status();

qt/cmd.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ typedef enum
8989
STATUS_BB = 0x02,
9090
STATUS_WRITE_ACK = 0x03,
9191
STATUS_BB_SKIP = 0x04,
92+
STATUS_PROGRESS = 0x05,
9293
} StatusData;
9394

9495
typedef struct __attribute__((__packed__))
@@ -144,5 +145,11 @@ typedef struct __attribute__((__packed__))
144145
uint8_t errCode;
145146
} RespError;
146147

148+
typedef struct __attribute__((__packed__))
149+
{
150+
RespHeader header;
151+
uint32_t progress;
152+
} RespProgress;
153+
147154
#endif // CMD_H
148155

qt/main_window.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,11 +253,25 @@ void MainWindow::slotProgReadDeviceId()
253253

254254
void MainWindow::slotProgEraseCompleted(int status)
255255
{
256+
disconnect(prog, SIGNAL(eraseChipProgress(unsigned int)), this,
257+
SLOT(slotProgEraseProgress(unsigned int)));
256258
disconnect(prog, SIGNAL(eraseChipCompleted(int)), this,
257259
SLOT(slotProgEraseCompleted(int)));
258260

259261
if (!status)
260262
qInfo() << "Chip has been erased successfully";
263+
264+
setProgress(100);
265+
}
266+
267+
void MainWindow::slotProgEraseProgress(unsigned int progress)
268+
{
269+
uint32_t progressPercent;
270+
int index = ui->chipSelectComboBox->currentIndex();
271+
uint32_t eraseSize = chipDb.sizeGetById(CHIP_INDEX2ID(index));
272+
273+
progressPercent = progress * 100ULL / eraseSize;
274+
setProgress(progressPercent);
261275
}
262276

263277
void MainWindow::slotProgErase()
@@ -273,8 +287,12 @@ void MainWindow::slotProgErase()
273287

274288
qInfo() << "Erasing chip ...";
275289

290+
setProgress(0);
291+
276292
connect(prog, SIGNAL(eraseChipCompleted(int)), this,
277293
SLOT(slotProgEraseCompleted(int)));
294+
connect(prog, SIGNAL(eraseChipProgress(unsigned int)), this,
295+
SLOT(slotProgEraseProgress(unsigned int)));
278296

279297
prog->eraseChip(START_ADDRESS, eraseSize);
280298
}
@@ -470,3 +488,8 @@ void MainWindow::slotAboutDialog()
470488

471489
aboutDialog.exec();
472490
}
491+
492+
void MainWindow::setProgress(unsigned int progress)
493+
{
494+
statusBar()->showMessage(tr("Progress: %1%").arg(progress));
495+
}

qt/main_window.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,15 @@ class MainWindow : public QMainWindow
3636
void setUiStateConnected(bool isConnected);
3737
void setUiStateSelected(bool isSelected);
3838
void updateChipList();
39+
void setProgress(unsigned int progress);
3940

4041
private slots:
4142
void slotProgConnectCompleted(int status);
4243
void slotProgReadDeviceIdCompleted(int status);
4344
void slotProgReadCompleted(int status);
4445
void slotProgWriteCompleted(int status);
4546
void slotProgEraseCompleted(int status);
47+
void slotProgEraseProgress(unsigned int progress);
4648
void slotProgReadBadBlocksCompleted(int status);
4749
void slotProgSelectCompleted(int status);
4850

qt/programmer.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,17 +155,26 @@ void Programmer::readChipId(ChipId *chipId)
155155

156156
void Programmer::eraseChipCb(int ret)
157157
{
158+
QObject::disconnect(&reader, SIGNAL(progress(unsigned int)), this,
159+
SLOT(eraseProgressChipCb(unsigned int)));
158160
QObject::disconnect(&reader, SIGNAL(result(int)), this,
159161
SLOT(eraseChipCb(int)));
160162
emit eraseChipCompleted(ret);
161163
}
162164

165+
void Programmer::eraseProgressChipCb(unsigned int progress)
166+
{
167+
emit eraseChipProgress(progress);
168+
}
169+
163170
void Programmer::eraseChip(uint32_t addr, uint32_t len)
164171
{
165172
EraseCmd eraseCmd;
166173

167174
QObject::connect(&reader, SIGNAL(result(int)), this,
168175
SLOT(eraseChipCb(int)));
176+
QObject::connect(&reader, SIGNAL(progress(unsigned int)), this,
177+
SLOT(eraseProgressChipCb(unsigned int)));
169178

170179
eraseCmd.cmd.code = CMD_NAND_ERASE;
171180
eraseCmd.addr = addr;

qt/programmer.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ class Programmer : public QObject
5959
void writeChipCompleted(int ret);
6060
void readChipCompleted(int ret);
6161
void eraseChipCompleted(int ret);
62+
void eraseChipProgress(unsigned int progress);
6263
void readChipBadBlocksCompleted(int ret);
6364
void confChipCompleted(int ret);
6465

@@ -67,6 +68,7 @@ private slots:
6768
void writeCb(int ret);
6869
void readCb(int ret);
6970
void eraseChipCb(int ret);
71+
void eraseProgressChipCb(unsigned int progress);
7072
void readChipBadBlocksCb(int ret);
7173
void confChipCb(int ret);
7274
void logCb(QtMsgType msgType, QString msg);

qt/reader.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,19 @@ int Reader::handleError(uint8_t *pbuf, uint32_t len)
114114
return -1;
115115
}
116116

117+
int Reader::handleProgress(uint8_t *pbuf, uint32_t len)
118+
{
119+
RespProgress *resp = reinterpret_cast<RespProgress *>(pbuf);
120+
size_t size = sizeof(RespProgress);
121+
122+
if (len < size)
123+
return 0;
124+
125+
emit progress(resp->progress);
126+
127+
return static_cast<int>(size);
128+
}
129+
117130
int Reader::handleStatus(uint8_t *pbuf, uint32_t len)
118131
{
119132
RespHeader *header = reinterpret_cast<RespHeader *>(pbuf);
@@ -126,6 +139,8 @@ int Reader::handleStatus(uint8_t *pbuf, uint32_t len)
126139
return handleBadBlock(pbuf, len, false);
127140
case STATUS_BB_SKIP:
128141
return handleBadBlock(pbuf, len, true);
142+
case STATUS_PROGRESS:
143+
return handleProgress(pbuf, len);
129144
case STATUS_OK:
130145
// Exit read loop
131146
if (!rlen)

qt/reader.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class Reader : public QThread
3131
int readStart();
3232
int read(uint8_t *pbuf, uint32_t len);
3333
int handleError(uint8_t *pbuf, uint32_t len);
34+
int handleProgress(uint8_t *pbuf, uint32_t len);
3435
int handleBadBlock(uint8_t *pbuf, uint32_t len, bool isSkipped);
3536
int handleStatus(uint8_t *pbuf, uint32_t len);
3637
int handleData(uint8_t *pbuf, uint32_t len);
@@ -47,6 +48,7 @@ class Reader : public QThread
4748
bool isReadLess);
4849
signals:
4950
void result(int ret);
51+
void progress(unsigned int progress);
5052
void log(QtMsgType msgType, QString msg);
5153
};
5254

0 commit comments

Comments
 (0)