X-Git-Url: http://git.linex4red.de/pub/USBasp.git/blobdiff_plain/1ed6925b5bf417848b83887b32e3ede05a1c691b..d1608d4af321529f0ddef9defcd97669ae9018c3:/Projects/AVRISP/Lib/V2Protocol.c diff --git a/Projects/AVRISP/Lib/V2Protocol.c b/Projects/AVRISP/Lib/V2Protocol.c index c0028f72a..4fcb5aa00 100644 --- a/Projects/AVRISP/Lib/V2Protocol.c +++ b/Projects/AVRISP/Lib/V2Protocol.c @@ -43,6 +43,13 @@ uint32_t CurrentAddress; bool MustSetAddress; +/** ISR for the management of the command execution timeout counter */ +ISR(TIMER0_COMPA_vect, ISR_BLOCK) +{ + if (TimeoutMSRemaining) + TimeoutMSRemaining--; +} + /** Master V2 Protocol packet handler, for received V2 Protocol packets from a connected host. * This routine decodes the issued command and passes off the handling of the command to the * appropriate function. @@ -50,7 +57,10 @@ bool MustSetAddress; void V2Protocol_ProcessCommand(void) { uint8_t V2Command = Endpoint_Read_Byte(); - + + TimeoutMSRemaining = COMMAND_TIMEOUT_MS; + TIMSK0 |= (1 << OCIE0A); + switch (V2Command) { case CMD_SIGN_ON: @@ -66,6 +76,7 @@ void V2Protocol_ProcessCommand(void) case CMD_RESET_PROTECTION: V2Protocol_ResetProtection(); break; +#if defined(ENABLE_ISP_PROTOCOL) case CMD_ENTER_PROGMODE_ISP: ISPProtocol_EnterISPMode(); break; @@ -83,10 +94,6 @@ void V2Protocol_ProcessCommand(void) case CMD_CHIP_ERASE_ISP: ISPProtocol_ChipErase(); break; -#if defined(ENABLE_XPROG_PROTOCOL) - case CMD_XPROG_SETMODE: - V2Protocol_XPROG_SetMode(); -#endif case CMD_READ_FUSE_ISP: case CMD_READ_LOCK_ISP: case CMD_READ_SIGNATURE_ISP: @@ -100,11 +107,22 @@ void V2Protocol_ProcessCommand(void) case CMD_SPI_MULTI: ISPProtocol_SPIMulti(); break; +#endif +#if defined(ENABLE_XPROG_PROTOCOL) + case CMD_XPROG_SETMODE: + XPROGProtocol_SetMode(); + break; + case CMD_XPROG: + XPROGProtocol_Command(); + break; +#endif default: V2Protocol_UnknownCommand(V2Command); break; } - + + TIMSK0 &= ~(1 << OCIE0A); + Endpoint_WaitUntilReady(); Endpoint_SetEndpointDirection(ENDPOINT_DIR_OUT); } @@ -114,7 +132,7 @@ void V2Protocol_ProcessCommand(void) * * \param[in] V2Command Issued V2 Protocol command byte from the host */ -static void V2Protocol_UnknownCommand(uint8_t V2Command) +static void V2Protocol_UnknownCommand(const uint8_t V2Command) { /* Discard all incoming data */ while (Endpoint_BytesInEndpoint() == AVRISP_DATA_EPSIZE) @@ -163,7 +181,7 @@ static void V2Protocol_ResetProtection(void) * * \param[in] V2Command Issued V2 Protocol command byte from the host */ -static void V2Protocol_GetSetParam(uint8_t V2Command) +static void V2Protocol_GetSetParam(const uint8_t V2Command) { uint8_t ParamID = Endpoint_Read_Byte(); uint8_t ParamValue;