X-Git-Url: http://git.linex4red.de/pub/USBasp.git/blobdiff_plain/8ecdc2b1441417bf97661a3d3edd17a5afd707bf..c58c53dba90fdc19d38f5e5d6957f2ede2a740f3:/Projects/AVRISP-MKII/Lib/V2Protocol.c?ds=inline diff --git a/Projects/AVRISP-MKII/Lib/V2Protocol.c b/Projects/AVRISP-MKII/Lib/V2Protocol.c index 4fcb5aa00..3df8045aa 100644 --- a/Projects/AVRISP-MKII/Lib/V2Protocol.c +++ b/Projects/AVRISP-MKII/Lib/V2Protocol.c @@ -1,21 +1,21 @@ /* 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) - - Permission to use, copy, modify, and distribute this software - and its documentation for any purpose and without fee is hereby - granted, provided that the above copyright notice appear in all - copies and that both that the copyright notice and this - permission notice and warranty disclaimer appear in supporting - documentation, and that the name of the author not be used in - advertising or publicity pertaining to distribution of the + 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 + without fee, provided that the above copyright notice appear in + all copies and that both that the copyright notice and this + permission notice and warranty disclaimer appear in supporting + documentation, and that the name of the author not be used in + advertising or publicity pertaining to distribution of the software without specific, written prior permission. The author disclaim all warranties with regard to this @@ -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);