X-Git-Url: http://git.linex4red.de/pub/USBasp.git/blobdiff_plain/cb779e3d7d32d7c43e0a45bb526de0a04135b0c7..279e1b6ece7fbc90db6cb642f1c289b45648cf9c:/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 673a0941c..b510d43a6 100644 --- a/Projects/AVRISP-MKII/Lib/V2Protocol.c +++ b/Projects/AVRISP-MKII/Lib/V2Protocol.c @@ -1,13 +1,13 @@ /* LUFA Library - Copyright (C) Dean Camera, 2010. + Copyright (C) Dean Camera, 2011. dean [at] fourwalledcubicle [dot] com www.lufa-lib.org */ /* - Copyright 2010 Dean Camera (dean [at] fourwalledcubicle [dot] com) + Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com) Permission to use, copy, modify, distribute, and sell this software and its documentation for any purpose is hereby granted @@ -44,10 +44,10 @@ bool MustLoadExtendedAddress; /** ISR to manage timeouts whilst processing a V2Protocol command */ -ISR(TIMER0_COMPA_vect, ISR_NOBLOCK) +ISR(WDT_vect, ISR_BLOCK) { - if (TimeoutTicksRemaining) - TimeoutTicksRemaining--; + TimeoutExpired = true; + wdt_disable(); } /** Initialises the hardware and software associated with the V2 protocol command handling. */ @@ -60,12 +60,11 @@ void V2Protocol_Init(void) ADC_StartReading(ADC_REFERENCE_AVCC | ADC_RIGHT_ADJUSTED | VTARGET_ADC_CHANNEL_MASK); #endif - /* Timeout timer initialization (10ms period) */ - OCR0A = ((F_CPU / 1024) / 100); - TCCR0A = (1 << WGM01); - TIMSK0 = (1 << OCIE0A); - V2Params_LoadNonVolatileParamValues(); + + #if defined(ENABLE_ISP_PROTOCOL) + ISPTarget_ConfigureRescueClock(); + #endif } /** Master V2 Protocol packet handler, for received V2 Protocol packets from a connected host. @@ -76,9 +75,10 @@ void V2Protocol_ProcessCommand(void) { uint8_t V2Command = Endpoint_Read_Byte(); - /* Start the timeout management timer */ - TimeoutTicksRemaining = COMMAND_TIMEOUT_TICKS; - TCCR0B = ((1 << CS02) | (1 << CS00)); + /* Start the watchdog with timeout interrupt enabled to manage the timeout */ + TimeoutExpired = false; + wdt_enable(WDTO_1S); + WDTCSR |= (1 << WDIE); switch (V2Command) { @@ -140,8 +140,8 @@ void V2Protocol_ProcessCommand(void) break; } - /* Disable the timeout management timer */ - TCCR0B = 0; + /* Disable the timeout management watchdog timer */ + wdt_disable(); Endpoint_WaitUntilReady(); Endpoint_SelectEndpoint(AVRISP_DATA_OUT_EPNUM); @@ -181,7 +181,7 @@ static void V2Protocol_SignOn(void) Endpoint_Write_Byte(CMD_SIGN_ON); Endpoint_Write_Byte(STATUS_CMD_OK); Endpoint_Write_Byte(sizeof(PROGRAMMER_ID) - 1); - Endpoint_Write_Stream_LE(PROGRAMMER_ID, (sizeof(PROGRAMMER_ID) - 1), NO_STREAM_CALLBACK); + Endpoint_Write_Stream_LE(PROGRAMMER_ID, (sizeof(PROGRAMMER_ID) - 1), NULL); Endpoint_ClearIN(); } @@ -245,7 +245,7 @@ static void V2Protocol_GetSetParam(const uint8_t V2Command) */ static void V2Protocol_LoadAddress(void) { - Endpoint_Read_Stream_BE(&CurrentAddress, sizeof(CurrentAddress), NO_STREAM_CALLBACK); + Endpoint_Read_Stream_BE(&CurrentAddress, sizeof(CurrentAddress), NULL); Endpoint_ClearOUT(); Endpoint_SelectEndpoint(AVRISP_DATA_IN_EPNUM);