Skip to content

Commit

Permalink
Added vscphubd pre
Browse files Browse the repository at this point in the history
  • Loading branch information
grodansparadis committed Apr 30, 2024
1 parent 5c977cc commit 02fc597
Show file tree
Hide file tree
Showing 19 changed files with 8,307 additions and 1,394 deletions.
1 change: 1 addition & 0 deletions src/vscp/common/vscp.h
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,7 @@ struct vscpMyNode {
#define VSCP_ERROR_PARSING 62 /* Failed to parse input */
#define VSCP_ERROR_INVALID_FRAME 63 /* A protocol has wrong format */
#define VSCP_ERROR_SIZE 64 /* The size is wring */
#define VSCP_ERROR_NACK 65 /* NACK received */

/*!
HLO (High Level Object) type (bits 7,6,5,4)
Expand Down
42 changes: 22 additions & 20 deletions src/vscp/common/vscp_bootdevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@
An abstract memory model is used for the firmware. In this
model memory contents of different types is placed into
different memory regions. When a block of datra from that region
is sent to the remote device it is up to that device to
place the data at the correct location. This model can be used
for code, ram, eeprom, fuses, config data etc. The pic1 bootloader
different memory regions. When a block of datra from that region
is sent to the remote device it is up to that device to
place the data at the correct location. This model can be used
for code, ram, eeprom, fuses, config data etc. The pic1 bootloader
use the Microchip abstract memory model. The VSCP bootloader let
the receiving end take the decision on where a block should be written
the receiving end take the decision on where a block should be written
Sequency of use
----------------
Expand Down Expand Up @@ -125,8 +125,8 @@ class CBootDevice {
*/
CBootDevice(CVscpClient *pclient,
uint16_t nodeid,
std::function<void(int, const char*)> statusCallback = nullptr,
uint32_t timeout = REGISTER_DEFAULT_TIMEOUT);
std::function<void(int, const char *)> statusCallback = nullptr,
uint32_t timeout = REGISTER_DEFAULT_TIMEOUT);

/*!
Constructor
Expand All @@ -140,8 +140,8 @@ class CBootDevice {
CBootDevice(CVscpClient *pclient,
uint16_t nodeid,
cguid &guidif,
std::function<void(int, const char*)> statusCallback = nullptr,
uint32_t timeout = REGISTER_DEFAULT_TIMEOUT);
std::function<void(int, const char *)> statusCallback = nullptr,
uint32_t timeout = REGISTER_DEFAULT_TIMEOUT);

/*!
Constructor
Expand All @@ -153,19 +153,19 @@ class CBootDevice {
*/
CBootDevice(CVscpClient *pclient,
cguid &guid,
std::function<void(int, const char*)> statusCallback = nullptr,
uint32_t timeout = REGISTER_DEFAULT_TIMEOUT);
std::function<void(int, const char *)> statusCallback = nullptr,
uint32_t timeout = REGISTER_DEFAULT_TIMEOUT);

/*!
Destructor
*/
virtual ~CBootDevice(void);

/// Timeout for response
static const uint16_t BOOT_COMMAND_DEFAULT_RESPONSE_TIMEOUT = 5000;
static const uint16_t BOOT_COMMAND_DEFAULT_RESPONSE_TIMEOUT = 5;

/// Max size for a programming block
static const uint32_t BOOT_MAX_BLOCK_SIZE = (1024*1024*2);
static const uint32_t BOOT_MAX_BLOCK_SIZE = (1024 * 1024 * 2);

/// Hexfiles type
enum type_hex_file {
Expand Down Expand Up @@ -201,10 +201,10 @@ class CBootDevice {
@param end Stop address for memory range (inclusive - end is part of address space)
@param pmin Pointer to variable that will get min address
@param pmax Pointer to variable that will get max address
@return VSCP_ERROR_SUCCESS on success.
@return VSCP_ERROR_SUCCESS on success.
VSCP_ERROR_INVALID_POINTER if ponters are invalid.
VSCP_ERROR_INVALID_PARAMETER if end <= start
VSCP_ERROR_ERROR if no memory defined in the selected range. value of
VSCP_ERROR_ERROR if no memory defined in the selected range. value of
pmin/pmax is zero in this case.
*/
virtual int getMinMaxForRange(uint32_t start, uint32_t end, uint32_t *pmin, uint32_t *pmax);
Expand All @@ -227,11 +227,13 @@ class CBootDevice {

/*!
Set a device in bootmode
@param ourguid GUID for local device
@param devicecode This is the device code expected by the user
@param bAbortOnFirmwareCodeFail Set to true to fail if firmware code fetched from
MDF is not the same as the one read from the remote device.
@return VSCP_ERROR_SUCCESS on success.
*/
virtual int deviceInit(bool bAbortOnFirmwareCodeFail = false) = 0;
virtual int deviceInit(cguid &ourguid, uint8_t devicecode, bool bAbortOnFirmwareCodeFail = false) = 0;

/*!
Perform the actual firmware load process
Expand Down Expand Up @@ -264,7 +266,7 @@ class CBootDevice {
int is percentage,
str is real text description
*/
std::function<void(int,const char*)> m_statusCallback;
std::function<void(int, const char *)> m_statusCallback;

/*!
The device code tell the type of hardware of the remote device
Expand All @@ -275,6 +277,9 @@ class CBootDevice {
*/
uint8_t m_firmwaredeviceCode;

/// Our local GUID
cguid m_ourguid;

/// node id for device
uint8_t m_nodeid;

Expand All @@ -294,9 +299,6 @@ class CBootDevice {
// This is the minimum code address (startvector)
uint32_t m_startAddr;

/// # data bytes in file
uint32_t m_totalCntData;

/// Standard registers
CStandardRegisters m_stdRegs;

Expand Down
13 changes: 8 additions & 5 deletions src/vscp/common/vscp_bootdevice_pic1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,10 +224,13 @@ CBootDevice_PIC1::deviceInfo(void)
//

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

// Save our local GUID
m_ourguid = ourguid;

/*
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 @@ -339,7 +342,7 @@ CBootDevice_PIC1::deviceInit(bool bAbortOnFirmwareCodeFail)
m_firmwaredeviceCode,
m_stdRegs.getFirmwareDeviceCode());
if (nullptr != m_statusCallback) {
m_statusCallback(-1, "Firware device code is not equal the one on the device local: {0} device: {1}");
m_statusCallback(-1, "Firmware device code is not equal the one on the device local: {0} device: {1}");
}
if (bAbortOnFirmwareCodeFail) {
return VSCP_ERROR_PARAMETER;
Expand Down Expand Up @@ -378,7 +381,7 @@ CBootDevice_PIC1::deviceInit(bool bAbortOnFirmwareCodeFail)
while (bRun) {

time(&tnow);
if ((unsigned long) (tnow - tstart) > PIC_BOOTLOADER_RESPONSE_TIMEOUT) {
if ((unsigned long) (tnow - tstart) > BOOT_COMMAND_DEFAULT_RESPONSE_TIMEOUT) {
bRun = false;
}

Expand Down Expand Up @@ -639,7 +642,7 @@ CBootDevice_PIC1::checkResponseLevel1(uint32_t response_id)

// check for timeout
time(&tnow);
if ((unsigned long) (tnow - tstart) > PIC_BOOTLOADER_RESPONSE_TIMEOUT) {
if ((unsigned long) (tnow - tstart) > BOOT_COMMAND_DEFAULT_RESPONSE_TIMEOUT) {
bRun = false; // End
}
}
Expand Down Expand Up @@ -685,7 +688,7 @@ CBootDevice_PIC1::checkResponseLevel2(uint32_t id)

// check for timeout
time(&tnow);
if ((tnow - tstart) > PIC_BOOTLOADER_RESPONSE_TIMEOUT) {
if ((tnow - tstart) > BOOT_COMMAND_DEFAULT_RESPONSE_TIMEOUT) {
bRun = false; // abort timeout
}
}
Expand Down
9 changes: 4 additions & 5 deletions src/vscp/common/vscp_bootdevice_pic1.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,6 @@ class CBootDevice_PIC1 : public CBootDevice {
static const uint8_t VSCP_PIC1_WRITE_REGISTER = 0x0B;
static const uint8_t VSCP_PIC1_ENTER_BOOTLODER_MODE = 0x0C;

static const uint8_t PIC_BOOTLOADER_RESPONSE_TIMEOUT = 5;

// Flash memory
static const uint32_t MEM_CODE_START = 0x000000;
static const uint32_t MEM_CODE_END = 0x1fffff;
Expand Down Expand Up @@ -129,8 +127,7 @@ class CBootDevice_PIC1 : public CBootDevice {
MEM_TYPE_USERID // 0x200000
};

// Default timeout for response
static const uint8_t BOOT_COMMAND_RESPONSE_TIMEOUT = 5;


// flags
// CONTROL is defined as follows
Expand Down Expand Up @@ -183,11 +180,13 @@ class CBootDevice_PIC1 : public CBootDevice {

/*!
Initialize boot mode, ie set device in bootmode
@param outguid Our local GUID
@param devicecode Device code user expect device tro have
@param bAbortOnFirmwareCodeFail Set to true to fail if firmware code fetched from
MDF is not the same as the one read from the remote device.
@return VSCP_ERROR_SUCCESS on success.
*/
int deviceInit(bool bAbortOnFirmwareCodeFail = false);
int deviceInit(cguid& ourguid, uint8_t devicecode, bool bAbortOnFirmwareCodeFail = false);

/*!
Write a boot block to the device
Expand Down
Loading

0 comments on commit 02fc597

Please sign in to comment.