X-Git-Url: http://git.linex4red.de/pub/USBasp.git/blobdiff_plain/d4ca7fb44c7d326b96cf391f0275dc323dbe24de..aca7863350509a1f390eda93ac0150378d8cd16c:/Projects/AVRISP-MKII/Lib/V2Protocol.c diff --git a/Projects/AVRISP-MKII/Lib/V2Protocol.c b/Projects/AVRISP-MKII/Lib/V2Protocol.c index aee142be1..3df8045aa 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, 2009. + Copyright (C) Dean Camera, 2010. dean [at] fourwalledcubicle [dot] com www.fourwalledcubicle.com */ /* - Copyright 2009 Dean Camera (dean [at] fourwalledcubicle [dot] com) + Copyright 2010 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 @@ -42,12 +42,22 @@ uint32_t CurrentAddress; /** Flag to indicate that the next read/write operation must update the device's current address */ bool MustSetAddress; - -/** ISR for the management of the command execution timeout counter */ -ISR(TIMER0_COMPA_vect, ISR_BLOCK) +/** Initializes the hardware and software associated with the V2 protocol command handling. */ +void V2Protocol_Init(void) { - if (TimeoutMSRemaining) - TimeoutMSRemaining--; + #if defined(ADC) + /* Initialize the ADC converter for VTARGET level detection on supported AVR models */ + ADC_Init(ADC_FREE_RUNNING | ADC_PRESCALE_128); + ADC_SetupChannel(VTARGET_ADC_CHANNEL); + ADC_StartReading(VTARGET_ADC_CHANNEL_MASK | ADC_RIGHT_ADJUSTED | ADC_REFERENCE_AVCC); + #endif + + /* Millisecond timer initialization for managing the command timeout counter */ + OCR0A = ((F_CPU / 64) / 1000); + TCCR0A = (1 << WGM01); + TCCR0B = ((1 << CS01) | (1 << CS00)); + + V2Params_LoadNonVolatileParamValues(); } /** Master V2 Protocol packet handler, for received V2 Protocol packets from a connected host. @@ -59,8 +69,7 @@ void V2Protocol_ProcessCommand(void) uint8_t V2Command = Endpoint_Read_Byte(); TimeoutMSRemaining = COMMAND_TIMEOUT_MS; - TIMSK0 |= (1 << OCIE0A); - + switch (V2Command) { case CMD_SIGN_ON: @@ -120,8 +129,6 @@ void V2Protocol_ProcessCommand(void) V2Protocol_UnknownCommand(V2Command); break; } - - TIMSK0 &= ~(1 << OCIE0A); Endpoint_WaitUntilReady(); Endpoint_SetEndpointDirection(ENDPOINT_DIR_OUT); @@ -158,12 +165,12 @@ 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)); + Endpoint_Write_Stream_LE(PROGRAMMER_ID, (sizeof(PROGRAMMER_ID) - 1), NO_STREAM_CALLBACK); Endpoint_ClearIN(); } -/** Handler for the CMD_RESET_PROTECTION command, currently implemented as a dummy ACK function - * as no ISP short-circuit protection is currently implemented. +/** Handler for the CMD_RESET_PROTECTION command, implemented as a dummy ACK function as + * no target short-circuit protection is currently implemented. */ static void V2Protocol_ResetProtection(void) { @@ -220,7 +227,7 @@ static void V2Protocol_GetSetParam(const uint8_t V2Command) */ static void V2Protocol_LoadAddress(void) { - Endpoint_Read_Stream_BE(&CurrentAddress, sizeof(CurrentAddress)); + Endpoint_Read_Stream_BE(&CurrentAddress, sizeof(CurrentAddress), NO_STREAM_CALLBACK); Endpoint_ClearOUT(); Endpoint_SetEndpointDirection(ENDPOINT_DIR_IN);