Skip to content

Commit

Permalink
VSCP client bootloader code in "working" state
Browse files Browse the repository at this point in the history
  • Loading branch information
grodansparadis committed Dec 12, 2024
1 parent 57f501c commit 46eea66
Show file tree
Hide file tree
Showing 10 changed files with 488 additions and 242 deletions.
1 change: 0 additions & 1 deletion src/common/crc.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@ crcInit(void)
int dividend;
unsigned char bit;


/*
* Compute the remainder of each possible dividend.
*/
Expand Down
39 changes: 18 additions & 21 deletions src/vscp/common/vscp-bootdevice-pic1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@
// #include <spdlog/sinks/stdout_color_sinks.h>
#include <spdlog/spdlog.h>

#include <iomanip>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <sstream>

///////////////////////////////////////////////////////////////////////////////
// Constructor
Expand Down Expand Up @@ -228,16 +228,13 @@ CBootDevice_PIC1::deviceInfo(void)
//

int
CBootDevice_PIC1::deviceInit(cguid &ourguid, uint16_t devicecode, bool bAbortOnFirmwareCodeFail)
CBootDevice_PIC1::deviceInit(cguid& ourguid, uint16_t devicecode, bool bAbortOnFirmwareCodeFail)
{
int rv;

// Save our local GUID
m_ourguid = ourguid;

// Save Firmware device code
m_firmwaredeviceCode = devicecode;

/*
First do a test to see if the device is already in boot mode
if it is 0x14nn/0x15nn should be returned (nn == nodeid).
Expand Down Expand Up @@ -359,7 +356,7 @@ CBootDevice_PIC1::deviceInit(cguid &ourguid, uint16_t devicecode, bool bAbortOnF
// Set device in boot mode
cguid guid;
m_stdRegs.getGUID(guid);
msg.data[0] = (uint8_t) m_nodeid; // Nickname to read register from
msg.data[0] = (uint8_t)m_nodeid; // Nickname to read register from
msg.data[1] = VSCP_BOOTLOADER_PIC1; // VSCP PIC1 bootloader algorithm
msg.data[2] = guid.getAt(0);
msg.data[3] = guid.getAt(3);
Expand Down Expand Up @@ -566,7 +563,7 @@ int
CBootDevice_PIC1::writeDeviceControlRegs(uint32_t addr, uint8_t flags, uint8_t cmd, uint8_t cmdData0, uint8_t cmdData1)
{
int rv;
// vscpEventEx event;
//vscpEventEx event;
canalMsg msg;

// Save the internal addresss
Expand Down Expand Up @@ -640,7 +637,7 @@ CBootDevice_PIC1::checkResponseLevel1(uint32_t response_id)
// Response received from all - return success
spdlog::debug("checkResponseLevel1: RECEIVE OK");
if (nullptr != m_statusCallback) {
// m_statusCallback(-1, "checkResponseLevel1: Response received OK.");
//m_statusCallback(-1, "checkResponseLevel1: Response received OK.");
}
return VSCP_ERROR_SUCCESS;
}
Expand Down Expand Up @@ -688,7 +685,7 @@ CBootDevice_PIC1::checkResponseLevel2(uint32_t id)
// Response received - return success
spdlog::debug("checkResponseLevel2: RECEIVE OK");
if (nullptr != m_statusCallback) {
// m_statusCallback(-1, "checkResponseLevel2: Response received OK.");
//m_statusCallback(-1, "checkResponseLevel2: Response received OK.");
}
return VSCP_ERROR_SUCCESS;
}
Expand Down Expand Up @@ -831,7 +828,7 @@ CBootDevice_PIC1::writeFirmwareBlock(uint32_t start, uint32_t end)
}

// Init the block
if (VSCP_ERROR_SUCCESS != (rv = fillMemoryBuffer(pbuf, size, start))) {
if (VSCP_ERROR_SUCCESS != (rv = fillMemoryBuffer(pbuf, size, start, end))) {
spdlog::error("writeFirmwareBlock: Failed to fill code block with data.");
if (nullptr != m_statusCallback) {
m_statusCallback(-1,
Expand All @@ -855,7 +852,7 @@ CBootDevice_PIC1::writeFirmwareBlock(uint32_t start, uint32_t end)
}

// Start at beginning
paddr += minAddr - start;
paddr += minAddr-start;

for (uint32_t blk = 0; blk < nPackets; blk++) {
spdlog::debug("Loading flash on remote device... block={0} {1:X}", blk, blk * 8);
Expand All @@ -865,11 +862,11 @@ CBootDevice_PIC1::writeFirmwareBlock(uint32_t start, uint32_t end)
}
paddr += 8;
if (nullptr != m_statusCallback) {
m_statusCallback((100 * blk) / nPackets, "" /*vscp_str_format("blk %d.", blk).c_str()*/);
m_statusCallback((100 * blk) / nPackets, ""/*vscp_str_format("blk %d.", blk).c_str()*/);
}

} // for
} // code
} // code

delete[] pbuf;
return VSCP_ERROR_SUCCESS;
Expand All @@ -882,18 +879,18 @@ CBootDevice_PIC1::writeFirmwareBlock(uint32_t start, uint32_t end)
int
CBootDevice_PIC1::deviceLoad(std::function<void(int, const char *)> statusCallback, bool bAbortOnFirmwareCodeFail)
{
// bool bRun = true;
//bool bRun = true;
int rv;

m_checksum = 0;
// uint32_t progress = 0;
m_checksum = 0;
//uint32_t progress = 0;
uint32_t addr = 0;
std::string strStatus;

// uint8_t pbuf[BUFFER_SIZE_CODE];
// uint32_t nPackets;
// uint32_t minAddr;
// uint32_t maxAddr;
//uint8_t pbuf[BUFFER_SIZE_CODE];
//uint32_t nPackets;
// uint32_t minAddr;
// uint32_t maxAddr;

if (nullptr != m_statusCallback) {
m_statusCallback(0, "Starting firmware download");
Expand Down
Loading

0 comments on commit 46eea66

Please sign in to comment.