Skip to content

Commit

Permalink
#24
Browse files Browse the repository at this point in the history
  • Loading branch information
mvladic committed Jul 3, 2020
1 parent 61daf10 commit de6958a
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 60 deletions.
112 changes: 56 additions & 56 deletions src/eez/modules/bp3c/flash_slave.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -465,16 +465,6 @@ void doStart() {

enterBootloaderMode(g_slotIndex);

if (!syncWithSlave(g_slotIndex)) {
#if OPTION_DISPLAY
psu::gui::hideProgressPage();
#endif

DebugTrace("Failed to sync with slave\n");

psu::gui::errorMessage("Failed to start update!");
}

sendMessageToLowPriorityThread(THREAD_MESSAGE_FLASH_SLAVE_UPLOAD_HEX_FILE);
}

Expand All @@ -490,63 +480,73 @@ void start(int slotIndex, const char *hexFilePath) {
}

void uploadHexFile() {
bool eofReached = false;
File file;
psu::sd_card::BufferedFileRead bufferedFile(file);
size_t totalSize = 0;
HexRecord hexRecord;
uint32_t addressUpperBits = 0;

if (!eraseAll(g_slotIndex)) {
DebugTrace("Failed to erase all!\n");
goto Exit;
}

if (!file.open(g_hexFilePath, FILE_OPEN_EXISTING | FILE_READ)) {
DebugTrace("Can't open firmware hex file!\n");
goto Exit;
}

#if OPTION_DISPLAY
totalSize = file.size();
#endif

while (!eofReached && readHexRecord(bufferedFile, hexRecord)) {
#if OPTION_DISPLAY
updateProgress(g_slotIndex, file.tell(), totalSize);
#endif
if (syncWithSlave(g_slotIndex)) {
bool eofReached = false;
File file;
psu::sd_card::BufferedFileRead bufferedFile(file);
size_t totalSize = 0;
HexRecord hexRecord;
uint32_t addressUpperBits = 0;

if (!eraseAll(g_slotIndex)) {
DebugTrace("Failed to erase all!\n");
goto Exit;
}

if (hexRecord.recordType == 0x04) {
addressUpperBits = ((hexRecord.data[0] << 8) + hexRecord.data[1]) << 16;
} else if (hexRecord.recordType == 0x00) {
uint32_t address = addressUpperBits | hexRecord.address;
if (!writeMemory(g_slotIndex, address, hexRecord.data, hexRecord.recordLength)) {
DebugTrace("Failed to write memory at address %08x\n", address);
break;
if (!file.open(g_hexFilePath, FILE_OPEN_EXISTING | FILE_READ)) {
DebugTrace("Can't open firmware hex file!\n");
goto Exit;
}

#if OPTION_DISPLAY
totalSize = file.size();
#endif

while (!eofReached && readHexRecord(bufferedFile, hexRecord)) {
#if OPTION_DISPLAY
updateProgress(g_slotIndex, file.tell(), totalSize);
#endif

if (hexRecord.recordType == 0x04) {
addressUpperBits = ((hexRecord.data[0] << 8) + hexRecord.data[1]) << 16;
} else if (hexRecord.recordType == 0x00) {
uint32_t address = addressUpperBits | hexRecord.address;
if (!writeMemory(g_slotIndex, address, hexRecord.data, hexRecord.recordLength)) {
DebugTrace("Failed to write memory at address %08x\n", address);
break;
}
} else if (hexRecord.recordType == 0x01) {
eofReached = true;
}
} else if (hexRecord.recordType == 0x01) {
eofReached = true;
}
}

// uint8_t hour, minute, second;
// psu::datetime::getTime(hour, minute, second);
// DebugTrace("[%02d:%02d:%02d] Flash finished\n", hour, minute, second);
// uint8_t hour, minute, second;
// psu::datetime::getTime(hour, minute, second);
// DebugTrace("[%02d:%02d:%02d] Flash finished\n", hour, minute, second);

file.close();
file.close();

Exit:

#if OPTION_DISPLAY
psu::gui::hideProgressPage();
#endif

if (eofReached) {
uint16_t value = 0xA5A5;
bp3c::eeprom::write(g_slotIndex, (const uint8_t *)&value, 2, 4);
g_slots[g_slotIndex]->firmwareInstalled = true;
} else {
psu::gui::errorMessage("Downloading failed!");
}
} else {
#if OPTION_DISPLAY
psu::gui::hideProgressPage();
psu::gui::hideProgressPage();
#endif

if (eofReached) {
uint16_t value = 0xA5A5;
bp3c::eeprom::write(g_slotIndex, (const uint8_t *)&value, 2, 4);
g_slots[g_slotIndex]->firmwareInstalled = true;
} else {
psu::gui::errorMessage("Downloading failed!");
DebugTrace("Failed to sync with slave\n");

psu::gui::errorMessage("Failed to start update!");
}

sendMessageToPsu(PSU_MESSAGE_FLASH_SLAVE_LEAVE_BOOTLOADER_MODE);
Expand Down
12 changes: 8 additions & 4 deletions src/eez/modules/psu/gui/data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1490,7 +1490,8 @@ void data_no_channel_index(int slotIndex, DataOperationEnum operation, Cursor cu
}

void data_slot_channel_index(int slotIndex, DataOperationEnum operation, Cursor cursor, Value &value) {
if (g_slots[slotIndex]->moduleInfo->moduleCategory == MODULE_CATEGORY_DCPSUPPLY) {
auto testResult = g_slots[slotIndex]->getTestResult();
if (g_slots[slotIndex]->moduleInfo->moduleCategory == MODULE_CATEGORY_DCPSUPPLY && (testResult == TEST_OK || testResult == TEST_SKIPPED)) {
data_channel_index(*Channel::getBySlotIndex(slotIndex), operation, cursor, value);
} else {
data_no_channel_index(slotIndex, operation, cursor, value);
Expand All @@ -1510,23 +1511,26 @@ void data_slot3_channel_index(DataOperationEnum operation, Cursor cursor, Value
}

void data_slot_max_channel_index(DataOperationEnum operation, Cursor cursor, Value &value) {
if (g_slots[persist_conf::getMaxSlotIndex()]->moduleInfo->moduleCategory == MODULE_CATEGORY_DCPSUPPLY) {
auto testResult = g_slots[persist_conf::getMaxSlotIndex()]->getTestResult();
if (g_slots[persist_conf::getMaxSlotIndex()]->moduleInfo->moduleCategory == MODULE_CATEGORY_DCPSUPPLY && (testResult == TEST_OK || testResult == TEST_SKIPPED)) {
data_channel_index(Channel::get(persist_conf::getMaxChannelIndex()), operation, cursor, value);
} else {
data_no_channel_index(persist_conf::getMaxSlotIndex(), operation, cursor, value);
}
}

void data_slot_min1_channel_index(DataOperationEnum operation, Cursor cursor, Value &value) {
if (g_slots[persist_conf::getMin1SlotIndex()]->moduleInfo->moduleCategory == MODULE_CATEGORY_DCPSUPPLY) {
auto testResult = g_slots[persist_conf::getMin1SlotIndex()]->getTestResult();
if (g_slots[persist_conf::getMin1SlotIndex()]->moduleInfo->moduleCategory == MODULE_CATEGORY_DCPSUPPLY && (testResult == TEST_OK || testResult == TEST_SKIPPED)) {
data_channel_index(Channel::get(persist_conf::getMin1ChannelIndex()), operation, cursor, value);
} else {
data_no_channel_index(persist_conf::getMin1SlotIndex(), operation, cursor, value);
}
}

void data_slot_min2_channel_index(DataOperationEnum operation, Cursor cursor, Value &value) {
if (g_slots[persist_conf::getMin2SlotIndex()]->moduleInfo->moduleCategory == MODULE_CATEGORY_DCPSUPPLY) {
auto testResult = g_slots[persist_conf::getMin2SlotIndex()]->getTestResult();
if (g_slots[persist_conf::getMin2SlotIndex()]->moduleInfo->moduleCategory == MODULE_CATEGORY_DCPSUPPLY && (testResult == TEST_OK || testResult == TEST_SKIPPED)) {
data_channel_index(Channel::get(persist_conf::getMin2ChannelIndex()), operation, cursor, value);
} else {
data_no_channel_index(persist_conf::getMin2SlotIndex(), operation, cursor, value);
Expand Down

0 comments on commit de6958a

Please sign in to comment.