X-Git-Url: http://git.linex4red.de/pub/USBasp.git/blobdiff_plain/ce8d0424b1a59bb2b0bd3ab8f69f4e4cf8c9930b..a9e0935a90346beb0c981924becc1f55d969a08b:/Projects/AVRISP-MKII/Lib/V2Protocol.c?ds=sidebyside diff --git a/Projects/AVRISP-MKII/Lib/V2Protocol.c b/Projects/AVRISP-MKII/Lib/V2Protocol.c index cea42eae5..096551d81 100644 --- a/Projects/AVRISP-MKII/Lib/V2Protocol.c +++ b/Projects/AVRISP-MKII/Lib/V2Protocol.c @@ -42,6 +42,14 @@ uint32_t CurrentAddress; /** Flag to indicate that the next read/write operation must update the device's current address */ bool MustSetAddress; + +/** ISR to manage timeouts whilst processing a V2Protocol command */ +ISR(TIMER0_COMPA_vect, ISR_NOBLOCK) +{ + if (TimeoutMSRemaining) + TimeoutMSRemaining--; +} + /** Initializes the hardware and software associated with the V2 protocol command handling. */ void V2Protocol_Init(void) { @@ -55,7 +63,7 @@ void V2Protocol_Init(void) /* Millisecond timer initialization for managing the command timeout counter */ OCR0A = ((F_CPU / 64) / 1000); TCCR0A = (1 << WGM01); - TCCR0B = ((1 << CS01) | (1 << CS00)); + TIMSK0 = (1 << OCIE0A); V2Params_LoadNonVolatileParamValues(); } @@ -68,6 +76,10 @@ void V2Protocol_ProcessCommand(void) { uint8_t V2Command = Endpoint_Read_Byte(); + /* Start the timeout management timer */ + TimeoutMSRemaining = COMMAND_TIMEOUT_MS; + TCCR0B = ((1 << CS01) | (1 << CS00)); + switch (V2Command) { case CMD_SIGN_ON: @@ -127,8 +139,12 @@ void V2Protocol_ProcessCommand(void) V2Protocol_UnknownCommand(V2Command); break; } + + /* Disable the timeout management timer */ + TCCR0B = 0; Endpoint_WaitUntilReady(); + Endpoint_SelectEndpoint(AVRISP_DATA_OUT_EPNUM); Endpoint_SetEndpointDirection(ENDPOINT_DIR_OUT); } @@ -147,6 +163,7 @@ static void V2Protocol_UnknownCommand(const uint8_t V2Command) } Endpoint_ClearOUT(); + Endpoint_SelectEndpoint(AVRISP_DATA_IN_EPNUM); Endpoint_SetEndpointDirection(ENDPOINT_DIR_IN); Endpoint_Write_Byte(V2Command); @@ -158,6 +175,7 @@ static void V2Protocol_UnknownCommand(const uint8_t V2Command) static void V2Protocol_SignOn(void) { Endpoint_ClearOUT(); + Endpoint_SelectEndpoint(AVRISP_DATA_IN_EPNUM); Endpoint_SetEndpointDirection(ENDPOINT_DIR_IN); Endpoint_Write_Byte(CMD_SIGN_ON); @@ -173,6 +191,7 @@ static void V2Protocol_SignOn(void) static void V2Protocol_ResetProtection(void) { Endpoint_ClearOUT(); + Endpoint_SelectEndpoint(AVRISP_DATA_IN_EPNUM); Endpoint_SetEndpointDirection(ENDPOINT_DIR_IN); Endpoint_Write_Byte(CMD_RESET_PROTECTION); @@ -195,6 +214,7 @@ static void V2Protocol_GetSetParam(const uint8_t V2Command) ParamValue = Endpoint_Read_Byte(); Endpoint_ClearOUT(); + Endpoint_SelectEndpoint(AVRISP_DATA_IN_EPNUM); Endpoint_SetEndpointDirection(ENDPOINT_DIR_IN); Endpoint_Write_Byte(V2Command); @@ -228,6 +248,7 @@ static void V2Protocol_LoadAddress(void) Endpoint_Read_Stream_BE(&CurrentAddress, sizeof(CurrentAddress), NO_STREAM_CALLBACK); Endpoint_ClearOUT(); + Endpoint_SelectEndpoint(AVRISP_DATA_IN_EPNUM); Endpoint_SetEndpointDirection(ENDPOINT_DIR_IN); MustSetAddress = true;