diff options
author | Dean Camera <dean@fourwalledcubicle.com> | 2011-01-22 17:48:06 +0000 |
---|---|---|
committer | Dean Camera <dean@fourwalledcubicle.com> | 2011-01-22 17:48:06 +0000 |
commit | 26017b68b0632c91e71eb29e87ca94670425e081 (patch) | |
tree | 111734f4a05e27e4cfb33779ab8d949388aaee4c /Projects/AVRISP-MKII/Lib/V2Protocol.c | |
parent | ef44b8c036daf4806a369dfdcd5adf72cf85b824 (diff) | |
download | lufa-26017b68b0632c91e71eb29e87ca94670425e081.tar.gz lufa-26017b68b0632c91e71eb29e87ca94670425e081.tar.bz2 lufa-26017b68b0632c91e71eb29e87ca94670425e081.zip |
Changed AVRISP-MKII project to use the Watchdog interrupt for command timeouts, to reduce CPU usage and free timer 0 for other uses in the future.
Diffstat (limited to 'Projects/AVRISP-MKII/Lib/V2Protocol.c')
-rw-r--r-- | Projects/AVRISP-MKII/Lib/V2Protocol.c | 22 |
1 files changed, 9 insertions, 13 deletions
diff --git a/Projects/AVRISP-MKII/Lib/V2Protocol.c b/Projects/AVRISP-MKII/Lib/V2Protocol.c index f6ea47709..b510d43a6 100644 --- a/Projects/AVRISP-MKII/Lib/V2Protocol.c +++ b/Projects/AVRISP-MKII/Lib/V2Protocol.c @@ -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,11 +60,6 @@ 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) - 1); - TCCR0A = (1 << WGM01); - TIMSK0 = (1 << OCIE0A); - V2Params_LoadNonVolatileParamValues(); #if defined(ENABLE_ISP_PROTOCOL) @@ -80,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) { @@ -144,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); |