Skip to content

Commit bfb76cf

Browse files
7134956bbogush
authored andcommitted
Qt: Add flash work range support.
Change-Id: Ib80992629ee040564d2e9eefc0ce35ff94b5147d Qt: Fix progress in part mode Change-Id: I94bc055082f9928a3df4af166b70526cc3179fc6
1 parent 20a5494 commit bfb76cf

File tree

5 files changed

+146
-55
lines changed

5 files changed

+146
-55
lines changed

qt/chip_db.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,12 @@ quint64 ChipDb::extendedTotalSizeGetByName(const QString &name)
347347
return totalSize + totalSpare;
348348
}
349349

350+
quint64 ChipDb::blockCountGetByName(const QString &name)
351+
{
352+
ChipInfo *info = chipInfoGetByName(name);
353+
return info->getTotalSize() / info->getBlockSize();
354+
}
355+
350356
void ChipDb::addChip(ChipInfo *chipInfo)
351357
{
352358
chipInfoVector.append(chipInfo);

qt/chip_db.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ class ChipDb
5757
quint64 totalSizeGetByName(const QString &name);
5858
quint64 extendedTotalSizeGetById(int id);
5959
quint64 extendedTotalSizeGetByName(const QString &name);
60+
quint64 blockCountGetByName(const QString &name);
6061
void addChip(ChipInfo *chipInfo);
6162
void delChip(int index);
6263
int size();

qt/main_window.cpp

Lines changed: 62 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@
2828
#define HEADER_HEX_WIDTH 340
2929
#define BUFFER_ROW_HEIGHT 20
3030

31-
#define START_ADDRESS 0x00000000
32-
3331
#define CHIP_NAME_DEFAULT "NONE"
3432
#define CHIP_INDEX_DEFAULT 0
3533
#define CHIP_INDEX2ID(index) (index - 1)
@@ -59,6 +57,13 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent),
5957
logger->setTextEdit(ui->logTextEdit);
6058

6159
initBufTable();
60+
#ifdef Q_OS_WIN32
61+
QFont font("Courier New", 9);
62+
ui->firstSpinBox->setFont(font);
63+
ui->lastSpinBox->setFont(font);
64+
#endif
65+
ui->firstSpinBox->setEnabled(false);
66+
ui->lastSpinBox->setEnabled(false);
6267

6368
prog = new Programmer(this);
6469
updateProgSettings();
@@ -126,6 +131,22 @@ void MainWindow::setUiStateSelected(bool isSelected)
126131
ui->actionRead->setEnabled(isSelected);
127132
ui->actionWrite->setEnabled(isSelected);
128133
ui->actionReadBadBlocks->setEnabled(isSelected);
134+
135+
ui->firstSpinBox->setEnabled(isSelected);
136+
ui->lastSpinBox->setEnabled(isSelected);
137+
if (isSelected)
138+
{
139+
QString chipName = ui->chipSelectComboBox->currentText();
140+
quint32 blocksCount = currentChipDb->blockCountGetByName(chipName);
141+
ui->firstSpinBox->setMaximum(blocksCount - 1);
142+
ui->firstSpinBox->setValue(0);
143+
ui->lastSpinBox->setMaximum(blocksCount - 1);
144+
ui->lastSpinBox->setValue(blocksCount - 1);
145+
quint64 chipSize = prog->isIncSpare() ?
146+
currentChipDb->extendedTotalSizeGetByName(chipName) :
147+
currentChipDb->totalSizeGetByName(chipName);
148+
ui->blockSizeValueLabel->setText(QString("0x%1").arg(chipSize / blocksCount, 8, 16, QLatin1Char( '0' )));
149+
}
129150
}
130151

131152
void MainWindow::slotProgConnectCompleted(quint64 status)
@@ -205,23 +226,21 @@ void MainWindow::slotProgEraseCompleted(quint64 status)
205226
void MainWindow::slotProgEraseProgress(quint64 progress)
206227
{
207228
uint32_t progressPercent;
208-
QString chipName = ui->chipSelectComboBox->currentText();
209-
quint64 eraseSize = prog->isIncSpare() ?
210-
currentChipDb->extendedTotalSizeGetByName(chipName) :
211-
currentChipDb->totalSizeGetByName(chipName);
212229

213-
progressPercent = progress * 100ULL / eraseSize;
230+
progressPercent = progress * 100ULL / areaSize;
214231
setProgress(progressPercent);
215232
}
216233

217234
void MainWindow::slotProgErase()
218235
{
219-
QString chipName = ui->chipSelectComboBox->currentText();
220-
quint64 eraseSize = prog->isIncSpare() ?
221-
currentChipDb->extendedTotalSizeGetByName(chipName) :
222-
currentChipDb->totalSizeGetByName(chipName);
236+
quint64 start_address =
237+
ui->blockSizeValueLabel->text().toULongLong(nullptr, 16)
238+
* ui->firstSpinBox->value();
239+
areaSize =
240+
ui->blockSizeValueLabel->text().toULongLong(nullptr, 16)
241+
* (ui->lastSpinBox->value() + 1) - start_address;
223242

224-
if (!eraseSize)
243+
if (!areaSize)
225244
{
226245
qCritical() << "Chip size is not set";
227246
return;
@@ -236,7 +255,7 @@ void MainWindow::slotProgErase()
236255
connect(prog, SIGNAL(eraseChipProgress(quint64)), this,
237256
SLOT(slotProgEraseProgress(quint64)));
238257

239-
prog->eraseChip(START_ADDRESS, eraseSize);
258+
prog->eraseChip(start_address, areaSize);
240259
}
241260

242261
void MainWindow::slotProgReadCompleted(quint64 readBytes)
@@ -277,12 +296,8 @@ void MainWindow::slotProgReadCompleted(quint64 readBytes)
277296
void MainWindow::slotProgReadProgress(quint64 progress)
278297
{
279298
uint32_t progressPercent;
280-
QString chipName = ui->chipSelectComboBox->currentText();
281-
quint64 readSize = prog->isIncSpare() ?
282-
currentChipDb->extendedTotalSizeGetByName(chipName) :
283-
currentChipDb->totalSizeGetByName(chipName);
284299

285-
progressPercent = progress * 100ULL / readSize;
300+
progressPercent = progress * 100ULL / areaSize;
286301
setProgress(progressPercent);
287302

288303
buffer.mutex.lock();
@@ -293,12 +308,14 @@ void MainWindow::slotProgReadProgress(quint64 progress)
293308

294309
void MainWindow::slotProgRead()
295310
{
296-
QString chipName = ui->chipSelectComboBox->currentText();
297-
quint64 readSize = prog->isIncSpare() ?
298-
currentChipDb->extendedTotalSizeGetByName(chipName) :
299-
currentChipDb->totalSizeGetByName(chipName);
311+
quint64 start_address =
312+
ui->blockSizeValueLabel->text().toULongLong(nullptr, 16)
313+
* ui->firstSpinBox->value();
314+
areaSize =
315+
ui->blockSizeValueLabel->text().toULongLong(nullptr, 16)
316+
* (ui->lastSpinBox->value() + 1) - start_address;
300317

301-
if (!readSize)
318+
if (!areaSize)
302319
{
303320
qCritical() << "Chip size is not set";
304321
return;
@@ -342,7 +359,7 @@ void MainWindow::slotProgRead()
342359
ui->filePathLineEdit->setDisabled(true);
343360
ui->selectFilePushButton->setDisabled(true);
344361

345-
prog->readChip(&buffer, START_ADDRESS, readSize, true);
362+
prog->readChip(&buffer, start_address, areaSize, true);
346363
}
347364

348365
void MainWindow::slotProgWriteCompleted(int status)
@@ -366,7 +383,7 @@ void MainWindow::slotProgWriteProgress(quint64 progress)
366383
{
367384
uint32_t progressPercent;
368385

369-
progressPercent = progress * 100ULL / progSize;
386+
progressPercent = progress * 100ULL / areaSize;
370387
setProgress(progressPercent);
371388

372389
std::unique_lock<std::mutex> lck(buffer.mutex);
@@ -426,13 +443,24 @@ void MainWindow::slotProgWrite()
426443
return;
427444
}
428445

429-
progSize = static_cast<uint32_t>(workFile.size());
446+
quint64 start_address =
447+
ui->blockSizeValueLabel->text().toULongLong(nullptr, 16)
448+
* ui->firstSpinBox->value();
449+
450+
areaSize = workFile.size();
430451

431-
if (progSize % pageSize)
452+
if (areaSize % pageSize)
432453
{
433-
progSize = (progSize / pageSize + 1) * pageSize;
454+
areaSize = (areaSize / pageSize + 1) * pageSize;
434455
}
435456

457+
quint64 setSize =
458+
ui->blockSizeValueLabel->text().toULongLong(nullptr, 16)
459+
* (ui->lastSpinBox->value() + 1) - start_address;
460+
461+
if (setSize < areaSize)
462+
areaSize = setSize;
463+
436464
qInfo() << "Writing data ...";
437465

438466
connect(prog, SIGNAL(writeChipCompleted(int)), this,
@@ -462,7 +490,7 @@ void MainWindow::slotProgWrite()
462490
}
463491

464492
buffer.ready = true;
465-
prog->writeChip(&buffer, START_ADDRESS, progSize, pageSize);
493+
prog->writeChip(&buffer, start_address, areaSize, pageSize);
466494
}
467495

468496
void MainWindow::slotProgReadBadBlocksCompleted(quint64 status)
@@ -702,6 +730,11 @@ void MainWindow::updateProgSettings()
702730
prog->setHwEccEnabled(settings.value(SETTINGS_ENABLE_HW_ECC).toBool());
703731
if (settings.contains(SETTINGS_ENABLE_ALERT))
704732
isAlertEnabled = settings.value(SETTINGS_ENABLE_ALERT).toBool();
733+
734+
if (ui->chipSelectComboBox->currentIndex() > 0)
735+
{
736+
setUiStateSelected(true);
737+
}
705738
}
706739

707740
void MainWindow::slotSettingsParallelChipDb()

qt/main_window.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class MainWindow : public QMainWindow
3636
QElapsedTimer timer;
3737
bool isAlertEnabled;
3838
QFile workFile;
39-
quint64 progSize;
39+
quint64 areaSize;
4040
uint32_t pageSize;
4141

4242
void initBufTable();

qt/main_window.ui

Lines changed: 76 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -23,30 +23,6 @@
2323
</property>
2424
<layout class="QGridLayout" name="gridLayout_4">
2525
<item row="1" column="0">
26-
<layout class="QGridLayout" name="gridLayout">
27-
<property name="sizeConstraint">
28-
<enum>QLayout::SetDefaultConstraint</enum>
29-
</property>
30-
<item row="1" column="1">
31-
<widget class="QLabel" name="label_2">
32-
<property name="text">
33-
<string>Work file:</string>
34-
</property>
35-
</widget>
36-
</item>
37-
<item row="1" column="2">
38-
<widget class="QLineEdit" name="filePathLineEdit"/>
39-
</item>
40-
<item row="1" column="0">
41-
<widget class="QPushButton" name="selectFilePushButton">
42-
<property name="text">
43-
<string>Select File</string>
44-
</property>
45-
</widget>
46-
</item>
47-
</layout>
48-
</item>
49-
<item row="0" column="0">
5026
<layout class="QGridLayout" name="gridLayout_3">
5127
<item row="2" column="5">
5228
<widget class="QLabel" name="deviceValueLabel">
@@ -158,7 +134,7 @@
158134
</item>
159135
</layout>
160136
</item>
161-
<item row="2" column="0">
137+
<item row="5" column="0">
162138
<widget class="QSplitter" name="splitter">
163139
<property name="orientation">
164140
<enum>Qt::Vertical</enum>
@@ -248,6 +224,81 @@
248224
</widget>
249225
</widget>
250226
</item>
227+
<item row="0" column="0">
228+
<layout class="QGridLayout" name="gridLayout">
229+
<property name="sizeConstraint">
230+
<enum>QLayout::SetDefaultConstraint</enum>
231+
</property>
232+
<item row="1" column="1">
233+
<widget class="QLabel" name="label_2">
234+
<property name="text">
235+
<string>Work file:</string>
236+
</property>
237+
</widget>
238+
</item>
239+
<item row="1" column="2">
240+
<widget class="QLineEdit" name="filePathLineEdit"/>
241+
</item>
242+
<item row="1" column="0">
243+
<widget class="QPushButton" name="selectFilePushButton">
244+
<property name="text">
245+
<string>Select File</string>
246+
</property>
247+
</widget>
248+
</item>
249+
</layout>
250+
</item>
251+
<item row="2" column="0">
252+
<layout class="QGridLayout" name="AddressGridLayout" columnstretch="0,0,0,0,0,0,0">
253+
<item row="1" column="6">
254+
<spacer name="horizontalSpacer_3">
255+
<property name="orientation">
256+
<enum>Qt::Horizontal</enum>
257+
</property>
258+
<property name="sizeHint" stdset="0">
259+
<size>
260+
<width>40</width>
261+
<height>20</height>
262+
</size>
263+
</property>
264+
</spacer>
265+
</item>
266+
<item row="1" column="0">
267+
<widget class="QLabel" name="firstLabel">
268+
<property name="text">
269+
<string>First block:</string>
270+
</property>
271+
</widget>
272+
</item>
273+
<item row="1" column="2">
274+
<widget class="QLabel" name="lastLabel">
275+
<property name="text">
276+
<string>Last block:</string>
277+
</property>
278+
</widget>
279+
</item>
280+
<item row="1" column="1">
281+
<widget class="QSpinBox" name="firstSpinBox"/>
282+
</item>
283+
<item row="1" column="3">
284+
<widget class="QSpinBox" name="lastSpinBox"/>
285+
</item>
286+
<item row="1" column="4">
287+
<widget class="QLabel" name="blockSizeLabel">
288+
<property name="text">
289+
<string>Block size:</string>
290+
</property>
291+
</widget>
292+
</item>
293+
<item row="1" column="5">
294+
<widget class="QLabel" name="blockSizeValueLabel">
295+
<property name="text">
296+
<string>0x0</string>
297+
</property>
298+
</widget>
299+
</item>
300+
</layout>
301+
</item>
251302
</layout>
252303
</widget>
253304
<widget class="QMenuBar" name="menuBar">

0 commit comments

Comments
 (0)