diff --git a/CHANGELOG.md b/CHANGELOG.md index ac0a796..2615353 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,12 +2,12 @@ ## 3.0.0 - * Build environment updated for using MSYS2 MinGW UCRT 64-bit. - * Using VSCP-framework v ... - * Using VSCP-bootloader v ... +* Build environment updated for using MSYS2 MinGW UCRT 64-bit. +* Using VSCP-framework v2.1.0 +* Using VSCP-bootloader v3.0.0 ## 2.0.0 - * [VSCP-framework repository](https://github.com/BlueAndi/vscp-framework) was restructured and the CLI tools moved to this dedicated repository. - * vscp-helper-lib updated to v15.0.0. The linux variant is only in release mode available. The windows variant in release and debug mode. - * ```dataNum``` variable in the VSCP message (from VSCP-framework) was renamed to ```dataSize```. Therefore the source code was updated accordingly. +* [VSCP-framework repository](https://github.com/BlueAndi/vscp-framework) was restructured and the CLI tools moved to this dedicated repository. +* vscp-helper-lib updated to v15.0.0. The linux variant is only in release mode available. The windows variant in release and debug mode. +* ```dataNum``` variable in the VSCP message (from VSCP-framework) was renamed to ```dataSize```. Therefore the source code was updated accordingly. diff --git a/common/vscp-bootloader b/common/vscp-bootloader index 9adc3d2..7869beb 160000 --- a/common/vscp-bootloader +++ b/common/vscp-bootloader @@ -1 +1 @@ -Subproject commit 9adc3d26e9646ea7030964714ba454e03d72475c +Subproject commit 7869beb903791adc4ccd959bf8df20f5e81eaa3d diff --git a/common/vscp-framework b/common/vscp-framework index 53efc39..d50773e 160000 --- a/common/vscp-framework +++ b/common/vscp-framework @@ -1 +1 @@ -Subproject commit 53efc39c18284e0b28071b538b53a202438ed620 +Subproject commit d50773e25fcd38f33bed618d9aaa07f0ba2bb0c7 diff --git a/logger/main.c b/logger/main.c index abd78e4..220f93c 100644 --- a/logger/main.c +++ b/logger/main.c @@ -57,6 +57,16 @@ This module contains the main entry point. CONSTANTS *******************************************************************************/ +#ifndef VERSION +/** Version */ +#define VERSION "x.x.x" +#endif /* VERSION */ + +#ifndef BUILDTYPE +/** Build type */ +#define BUILDTYPE "debug" +#endif /* BUILDTYPE */ + /** Program name */ #define MAIN_PROG_NAME "VSCP logger" diff --git a/logger/makefile b/logger/makefile index 5613266..fecbf57 100644 --- a/logger/makefile +++ b/logger/makefile @@ -33,7 +33,7 @@ ################################################################################ # Software version -VERSION= 0.2.0 +VERSION= 3.0.0 # Binary file name BIN= vscpLoggerPc diff --git a/nodeSim/main.c b/nodeSim/main.c index d1b8c9e..1dcb628 100644 --- a/nodeSim/main.c +++ b/nodeSim/main.c @@ -67,6 +67,16 @@ This module contains the main entry point. CONSTANTS *******************************************************************************/ +#ifndef VERSION +/** Version */ +#define VERSION "x.x.x" +#endif /* VERSION */ + +#ifndef BUILDTYPE +/** Build type */ +#define BUILDTYPE "debug" +#endif /* BUILDTYPE */ + /** Program name */ #define MAIN_PROG_NAME "VSCP level 1 node" diff --git a/nodeSim/makefile b/nodeSim/makefile index 0293803..94edd04 100644 --- a/nodeSim/makefile +++ b/nodeSim/makefile @@ -33,7 +33,7 @@ ################################################################################ # Software version -VERSION= 0.5.0 +VERSION= 3.0.0 # Binary file name BIN= vscpExamplePc diff --git a/nodeSim/vscp_user/vscp_tp_adapter.c b/nodeSim/vscp_user/vscp_tp_adapter.c index 9bdf6c3..f9094c6 100644 --- a/nodeSim/vscp_user/vscp_tp_adapter.c +++ b/nodeSim/vscp_user/vscp_tp_adapter.c @@ -132,7 +132,7 @@ static const char* vscp_tp_adapter_protocolTypes[] = /* 12 */ "Enter Boot Loader Mode", /* 13 */ "Enter Boot Loader Mode ACK", /* 14 */ "Enter Boot Loader Mode NACK", - /* 15 */ "Start Block Data Transfer", + /* 15 */ "Start Block", /* 16 */ "Block Data", /* 17 */ "Block Data ACK", /* 18 */ "Block Data NACK", @@ -167,8 +167,11 @@ static const char* vscp_tp_adapter_protocolTypes[] = /* 47 */ "Reserved", /* 48 */ "Activate New Image ACK", /* 49 */ "Activate New Image NACK", - /* 50 */ "Start Block Data Transfer ACK", - /* 51 */ "Start Block Data Transfer NACK" + /* 50 */ "Start Block ACK", + /* 51 */ "Start Block NACK", + /* 52 */ "Block Chunk ACK", + /* 53 */ "Block Chunk NACK", + /* 54 */ "Boot Loader Check" }; /** User friendly strings for VSCP helper library function return status. */ @@ -250,8 +253,6 @@ static const char* vscp_tp_adapter_errorStr[] = extern void vscp_tp_adapter_init(void) { /* Nothing to do */ - - return; } /** @@ -290,6 +291,20 @@ extern BOOL vscp_tp_adapter_readMessage(vscp_RxMessage * const msg) LOG_WARNING_INT32("Couldn't receive event: ", vscphlpRet); LOG_WARNING_STR("vscphlp_receiveEventEx failed: ", vscp_tp_adapter_getErrorStr(vscphlpRet)); } + /* Any simulated message available? */ + else if (TRUE == vscp_tp_adapter_messageReceived) + { + *msg = vscp_tp_adapter_rxMessage; + + vscp_tp_adapter_messageReceived = FALSE; + + status = TRUE; + } + else + { + /* Nothing to do. */ + ; + } } /* Handle all level 1 events? */ else if (VSCP_TP_ADAPTER_LVL_1 == client->lvl) @@ -318,17 +333,13 @@ extern BOOL vscp_tp_adapter_readMessage(vscp_RxMessage * const msg) status = TRUE; } } + else + { + /* Skip it. */ + ; + } } } - /* Any simulated message available? */ - else if (TRUE == vscp_tp_adapter_messageReceived) - { - *msg = vscp_tp_adapter_rxMessage; - - vscp_tp_adapter_messageReceived = FALSE; - - status = TRUE; - } if (FALSE != status) { @@ -677,8 +688,6 @@ extern void vscp_tp_adapter_disconnect(void) } vscp_tp_adapter_isConnected = FALSE; - - return; } /** @@ -690,7 +699,6 @@ extern void vscp_tp_adapter_simulateReceivedMessage(vscp_RxMessage const * const { vscp_tp_adapter_rxMessage = *msg; vscp_tp_adapter_messageReceived = TRUE; - return; } /******************************************************************************* @@ -851,8 +859,6 @@ static void vscp_tp_adapter_showMessage(vscp_Message const * const msg, BOOL isR } printf("\n"); - - return; } /** diff --git a/programmer/main.c b/programmer/main.c index 9cbad9c..b47f2f1 100644 --- a/programmer/main.c +++ b/programmer/main.c @@ -45,6 +45,7 @@ This module contains the main entry point. #include #include #include +#include #include "log.h" #include "platform.h" #include "vscphelperlib.h" @@ -60,6 +61,16 @@ This module contains the main entry point. CONSTANTS *******************************************************************************/ +#ifndef VERSION +/** Version */ +#define VERSION "x.x.x" +#endif /* VERSION */ + +#ifndef BUILDTYPE +/** Build type */ +#define BUILDTYPE "debug" +#endif /* BUILDTYPE */ + /** Program name */ #define MAIN_PROG_NAME "VSCP L1 programmer" @@ -154,10 +165,11 @@ typedef enum MAIN_PRG_STATE_READ_REG_PAGE_SELECT_RSP, /**< Wait for read page select register response */ MAIN_PRG_STATE_ENTER_BOOT_LOADER_MODE, /**< Enter boot loader mode */ MAIN_PRG_STATE_ENTER_BOOT_LOADER_MODE_ACK, /**< Wait for enter boot loader mode acknowledge */ - MAIN_PRG_STATE_START_BLOCK_TRANSFER, /**< Start block transfer */ - MAIN_PRG_STATE_START_BLOCK_TRANSFER_ACK, /**< Wait for start block transfer acknowledge */ - MAIN_PRG_STATE_BLOCK_DATA, /**< Block transfer */ - MAIN_PRG_STATE_BLOCK_DATA_ACK, /**< Wait for block transfer acknowledge */ + MAIN_PRG_STATE_START_BLOCK, /**< Start block transfer */ + MAIN_PRG_STATE_START_BLOCK_ACK, /**< Wait for start block transfer acknowledge */ + MAIN_PRG_STATE_BLOCK_DATA, /**< Block data */ + MAIN_PRG_STATE_BLOCK_CHUNK_ACK, /**< Wait for block chunk acknowledge */ + MAIN_PRG_STATE_BLOCK_DATA_ACK, /**< Wait for block data acknowledge */ MAIN_PRG_STATE_PROGRAM_BLOCK, /**< Program block */ MAIN_PRG_STATE_PROGRAM_BLOCK_ACK, /**< Wait for program block acknowledge */ MAIN_PRG_STATE_ACTIVATE_NEW_IMAGE, /**< Activate new image */ @@ -190,6 +202,9 @@ typedef struct uint32_t recIndexBackup; /**< Backup of record index, needed for block transfer retry */ uint32_t recDataIndexBackup; /**< Backup of record data index, needed for block transfer retry */ + unsigned long lastTime; /**< Last time in ms. Used for software timer functionality. */ + uint8_t retry; /**< Number of current retries */ + } main_Programming; /******************************************************************************* @@ -207,6 +222,7 @@ static CMDLINEPARSER_RET main_clpUnknown(void* const userData, char const * cons static Crc16CCITT main_calculateCrc(intelHexParser_Record* recSet, uint32_t recNum, uint32_t blockSize, BOOL fillBlock); static uint32_t main_calculateDataSize(intelHexParser_Record* recSet, uint32_t recNum); static void main_programNode(main_Programming * const progCon, long hSession, intelHexParser_Record* recSet, uint32_t recNum, vscpEventEx const * const rxEvent); +static unsigned long main_millis(); /******************************************************************************* LOCAL VARIABLES @@ -973,9 +989,10 @@ static uint32_t main_calculateDataSize(intelHexParser_Record* recSet, uint32_t r */ static void main_programNode(main_Programming * const progCon, long hSession, intelHexParser_Record* recSet, uint32_t recNum, vscpEventEx const * const rxEvent) { - uint32_t index = 0; - vscpEventEx txEvent; - Crc16CCITT imageCrc = 0; + uint32_t index = 0; + vscpEventEx txEvent; + Crc16CCITT imageCrc = 0; + unsigned long timeDiff = 0; if ((NULL == progCon) || (NULL == recSet)) @@ -1013,6 +1030,12 @@ static void main_programNode(main_Programming * const progCon, long hSession, in log_printf("Wait for response.\n"); progCon->state = MAIN_PRG_STATE_READ_REG_PAGE_SELECT_RSP; + progCon->lastTime = main_millis(); + + if (0 == progCon->retry) + { + progCon->retry = 3; + } } break; @@ -1034,6 +1057,26 @@ static void main_programNode(main_Programming * const progCon, long hSession, in progCon->state = MAIN_PRG_STATE_ENTER_BOOT_LOADER_MODE; } } + + timeDiff = main_millis() - progCon->lastTime; + if (1000 < timeDiff) + { + log_printf("Timeout!\n"); + + if (1 < progCon->retry) + { + log_printf("Retry.\n"); + + progCon->state = MAIN_PRG_STATE_READ_REG_PAGE_SELECT; + --progCon->retry; + } + else + { + log_printf("Error!\n"); + + progCon->state = MAIN_PRG_STATE_ERROR; + } + } break; case MAIN_PRG_STATE_ENTER_BOOT_LOADER_MODE: @@ -1064,6 +1107,12 @@ static void main_programNode(main_Programming * const progCon, long hSession, in log_printf("Wait for acknowledge.\n"); progCon->state = MAIN_PRG_STATE_ENTER_BOOT_LOADER_MODE_ACK; + progCon->lastTime = main_millis(); + + if (0 == progCon->retry) + { + progCon->retry = 3; + } } break; @@ -1113,7 +1162,7 @@ static void main_programNode(main_Programming * const progCon, long hSession, in } else { - progCon->state = MAIN_PRG_STATE_START_BLOCK_TRANSFER; + progCon->state = MAIN_PRG_STATE_START_BLOCK; } } else if ((VSCP_TYPE_PROTOCOL_NACK_BOOT_LOADER == rxEvent->vscp_type) && @@ -1129,11 +1178,31 @@ static void main_programNode(main_Programming * const progCon, long hSession, in progCon->state = MAIN_PRG_STATE_ERROR; } } + + timeDiff = main_millis() - progCon->lastTime; + if (1000 < timeDiff) + { + log_printf("Timeout!\n"); + + if (1 < progCon->retry) + { + log_printf("Retry.\n"); + + progCon->state = MAIN_PRG_STATE_ENTER_BOOT_LOADER_MODE; + --progCon->retry; + } + else + { + log_printf("Error!\n"); + + progCon->state = MAIN_PRG_STATE_ERROR; + } + } break; - case MAIN_PRG_STATE_START_BLOCK_TRANSFER: + case MAIN_PRG_STATE_START_BLOCK: - log_printf("Start block data transfer.\n"); + log_printf("Start block data.\n"); txEvent.vscp_class = VSCP_CLASS1_PROTOCOL; txEvent.vscp_type = VSCP_TYPE_PROTOCOL_START_BLOCK; @@ -1154,13 +1223,19 @@ static void main_programNode(main_Programming * const progCon, long hSession, in } else { - log_printf("Wait for acknowledge.\n"); + log_printf("Wait for start block acknowledge.\n"); - progCon->state = MAIN_PRG_STATE_START_BLOCK_TRANSFER_ACK; + progCon->state = MAIN_PRG_STATE_START_BLOCK_ACK; + progCon->lastTime = main_millis(); + + if (0 == progCon->retry) + { + progCon->retry = 3; + } } break; - case MAIN_PRG_STATE_START_BLOCK_TRANSFER_ACK: + case MAIN_PRG_STATE_START_BLOCK_ACK: if ((NULL != rxEvent) && (VSCP_CLASS1_PROTOCOL == rxEvent->vscp_class)) { @@ -1189,10 +1264,30 @@ static void main_programNode(main_Programming * const progCon, long hSession, in progCon->state = MAIN_PRG_STATE_ERROR; } } + + timeDiff = main_millis() - progCon->lastTime; + if (1000 < timeDiff) + { + log_printf("Timeout!\n"); + + if (1 < progCon->retry) + { + log_printf("Retry.\n"); + + progCon->state = MAIN_PRG_STATE_START_BLOCK; + --progCon->retry; + } + else + { + log_printf("Error!\n"); + + progCon->state = MAIN_PRG_STATE_ERROR; + } + } break; case MAIN_PRG_STATE_BLOCK_DATA: - log_printf("Block %u data transfer %u\n", progCon->blockIndex, progCon->blockFragmentIndex); + log_printf("Block %u data %u\n", progCon->blockIndex, progCon->blockFragmentIndex); txEvent.vscp_class = VSCP_CLASS1_PROTOCOL; txEvent.vscp_type = VSCP_TYPE_PROTOCOL_BLOCK_DATA; @@ -1224,7 +1319,15 @@ static void main_programNode(main_Programming * const progCon, long hSession, in txEvent.data[index] = MAIN_BLOCK_FILL_BYTE; progCon->blockCrcCalculated = crc16ccitt_update(progCon->blockCrcCalculated, &txEvent.data[index], 1); - + ++progCon->blockFragmentIndex; + + /* Block finished? */ + if (progCon->blockSize <= (progCon->blockFragmentIndex * 8)) + { + log_printf("Wait for block data acknowledge.\n"); + + progCon->state = MAIN_PRG_STATE_BLOCK_DATA_ACK; + } ++txEvent.sizeData; } /* Error */ @@ -1246,15 +1349,72 @@ static void main_programNode(main_Programming * const progCon, long hSession, in progCon->state = MAIN_PRG_STATE_ERROR; } else + { + log_printf("Wait for block chunk acknowledge.\n"); + + progCon->state = MAIN_PRG_STATE_BLOCK_CHUNK_ACK; + progCon->lastTime = main_millis(); + + if (0 == progCon->retry) + { + progCon->retry = 1; + } + } + } + break; + + case MAIN_PRG_STATE_BLOCK_CHUNK_ACK: + { + BOOL isTimeout = FALSE; + BOOL isAckReceived = FALSE; + + timeDiff = main_millis() - progCon->lastTime; + if (1000 < timeDiff) + { + isTimeout = TRUE; + } + + if ((NULL != rxEvent) && + (VSCP_CLASS1_PROTOCOL == rxEvent->vscp_class)) + { + if (VSCP_TYPE_PROTOCOL_BLOCK_CHUNK_NACK == rxEvent->vscp_type) + { + /* Repeat */ + log_printf("Repeat data chunk not implemented yet.\n"); /* TODO */ + } + else if (VSCP_TYPE_PROTOCOL_BLOCK_CHUNK_ACK == rxEvent->vscp_type) + { + isAckReceived = TRUE; + } + else + { + /* Nothing to do. */ + ; + } + } + + if ((FALSE != isTimeout) || + (FALSE != isAckReceived)) { ++progCon->blockFragmentIndex; /* Block finished? */ if (progCon->blockSize <= (progCon->blockFragmentIndex * 8)) { - log_printf("Wait for acknowledge.\n"); + log_printf("Wait for block data acknowledge.\n"); progCon->state = MAIN_PRG_STATE_BLOCK_DATA_ACK; + progCon->lastTime = main_millis(); + + if (0 == progCon->retry) + { + progCon->retry = 3; + } + } + /* Block not finished, send next chunk. */ + else + { + progCon->state = MAIN_PRG_STATE_BLOCK_DATA; } } } @@ -1283,7 +1443,7 @@ static void main_programNode(main_Programming * const progCon, long hSession, in log_printf("Block %u failed to transfer (invalid CRC 0x%04X, expected 0x%04X).\n", progCon->blockIndex, receivedCrc, progCon->blockCrcCalculated); ++progCon->blockRetry; - progCon->state = MAIN_PRG_STATE_START_BLOCK_TRANSFER; + progCon->state = MAIN_PRG_STATE_START_BLOCK; } else { @@ -1299,31 +1459,47 @@ static void main_programNode(main_Programming * const progCon, long hSession, in log_printf("Error code: %u\n", rxEvent->data[0]); ++progCon->blockRetry; - progCon->state = MAIN_PRG_STATE_START_BLOCK_TRANSFER; + progCon->state = MAIN_PRG_STATE_START_BLOCK; } + else + { + /* Nothing to do. */ + ; + } + } - /* Transfer block again? */ - if (MAIN_PRG_STATE_START_BLOCK_TRANSFER == progCon->state) + if (MAIN_PRG_STATE_BLOCK_DATA_ACK == progCon->state) + { + timeDiff = main_millis() - progCon->lastTime; + if (1000 < timeDiff) { - /* Maximum number of retries reached? */ - if (MAIN_MAX_BLOCK_TRANSFER_RETRIES <= progCon->blockRetry) - { - progCon->state = MAIN_PRG_STATE_ERROR; - } - else - { - log_printf("Transfer block %u again (%u).", progCon->blockIndex, progCon->blockRetry); + log_printf("Timeout!\n"); - /* Restore the position in the intel hex records */ - progCon->recIndex = progCon->recIndexBackup; - progCon->recDataIndex = progCon->recDataIndexBackup; - } + progCon->state = MAIN_PRG_STATE_START_BLOCK; + } + } + + /* Transfer block again? */ + if (MAIN_PRG_STATE_START_BLOCK == progCon->state) + { + /* Maximum number of retries reached? */ + if (MAIN_MAX_BLOCK_TRANSFER_RETRIES <= progCon->blockRetry) + { + progCon->state = MAIN_PRG_STATE_ERROR; } else { - progCon->blockRetry = 0; + log_printf("Transfer block %u again (%u).\n", progCon->blockIndex, progCon->blockRetry); + + /* Restore the position in the intel hex records */ + progCon->recIndex = progCon->recIndexBackup; + progCon->recDataIndex = progCon->recDataIndexBackup; } } + else + { + progCon->blockRetry = 0; + } break; case MAIN_PRG_STATE_PROGRAM_BLOCK: @@ -1347,7 +1523,7 @@ static void main_programNode(main_Programming * const progCon, long hSession, in } else { - log_printf("Wait for acknowledge.\n"); + log_printf("Wait for program block acknowledge.\n"); progCon->state = MAIN_PRG_STATE_PROGRAM_BLOCK_ACK; } @@ -1377,7 +1553,7 @@ static void main_programNode(main_Programming * const progCon, long hSession, in } else { - progCon->state = MAIN_PRG_STATE_START_BLOCK_TRANSFER; + progCon->state = MAIN_PRG_STATE_START_BLOCK; } } else if ((VSCP_TYPE_PROTOCOL_PROGRAM_BLOCK_DATA_NACK == rxEvent->vscp_type) && @@ -1413,7 +1589,7 @@ static void main_programNode(main_Programming * const progCon, long hSession, in } else { - log_printf("Wait for acknowledge.\n"); + log_printf("Wait for activate new image acknowledge.\n"); progCon->state = MAIN_PRG_STATE_ACTIVATE_NEW_IMAGE_ACK; } @@ -1460,4 +1636,16 @@ static void main_programNode(main_Programming * const progCon, long hSession, in } return; -} \ No newline at end of file +} + +/** + * Get the current time in milliseconds. + * + * @return unsigned long + */ +static unsigned long main_millis() +{ + clock_t now = clock(); + + return (((unsigned long)now) * 1000UL) / CLOCKS_PER_SEC; +} diff --git a/programmer/makefile b/programmer/makefile index 664e1d3..ceacbcc 100644 --- a/programmer/makefile +++ b/programmer/makefile @@ -33,7 +33,7 @@ ################################################################################ # Software version -VERSION= 0.2.0 +VERSION= 3.0.0 # Binary file name BIN= vscpProgrammerPc