X-Git-Url: http://git.linex4red.de/pub/USBasp.git/blobdiff_plain/7f9f97c792dee6875fbca9806422bdd7d6c5a657..03ee87b35abdb8b92e8b55ec040fa943f9a6786c:/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 093c07862..d6de77404 100644 --- a/Projects/AVRISP-MKII/Lib/V2Protocol.c +++ b/Projects/AVRISP-MKII/Lib/V2Protocol.c @@ -50,6 +50,24 @@ ISR(TIMER0_COMPA_vect, ISR_BLOCK) TimeoutMSRemaining--; } +/** Initializes the hardware and software associated with the V2 protocol command handling. */ +void V2Protocol_Init(void) +{ + #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 | 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. * This routine decodes the issued command and passes off the handling of the command to the * appropriate function. @@ -58,6 +76,7 @@ void V2Protocol_ProcessCommand(void) { uint8_t V2Command = Endpoint_Read_Byte(); + /* Set total command processing timeout value, enable timeout management interrupt */ TimeoutMSRemaining = COMMAND_TIMEOUT_MS; TIMSK0 |= (1 << OCIE0A); @@ -121,6 +140,7 @@ void V2Protocol_ProcessCommand(void) break; } + /* Disable timeout management interrupt once processing has completed */ TIMSK0 &= ~(1 << OCIE0A); Endpoint_WaitUntilReady(); @@ -158,12 +178,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 +240,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);