Fix up the incomplete Webserver project so that it integrates with the uIP stack...
[pub/USBasp.git] / Projects / AVRISP-MKII / Lib / V2Protocol.c
index 093c078..d6de774 100644 (file)
@@ -50,6 +50,24 @@ ISR(TIMER0_COMPA_vect, ISR_BLOCK)
          TimeoutMSRemaining--;\r
 }\r
 \r
+/** Initializes the hardware and software associated with the V2 protocol command handling. */\r
+void V2Protocol_Init(void)\r
+{\r
+       #if defined(ADC)\r
+       /* Initialize the ADC converter for VTARGET level detection on supported AVR models */\r
+       ADC_Init(ADC_FREE_RUNNING | ADC_PRESCALE_128);\r
+       ADC_SetupChannel(VTARGET_ADC_CHANNEL);\r
+       ADC_StartReading(VTARGET_ADC_CHANNEL | ADC_RIGHT_ADJUSTED | ADC_REFERENCE_AVCC);\r
+       #endif\r
+       \r
+       /* Millisecond timer initialization for managing the command timeout counter */\r
+       OCR0A  = ((F_CPU / 64) / 1000);\r
+       TCCR0A = (1 << WGM01);\r
+       TCCR0B = ((1 << CS01) | (1 << CS00));\r
+       \r
+       V2Params_LoadNonVolatileParamValues();\r
+}\r
+\r
 /** Master V2 Protocol packet handler, for received V2 Protocol packets from a connected host.\r
  *  This routine decodes the issued command and passes off the handling of the command to the\r
  *  appropriate function.\r
@@ -58,6 +76,7 @@ void V2Protocol_ProcessCommand(void)
 {\r
        uint8_t V2Command = Endpoint_Read_Byte();\r
        \r
+       /* Set total command processing timeout value, enable timeout management interrupt */\r
        TimeoutMSRemaining = COMMAND_TIMEOUT_MS;\r
        TIMSK0 |= (1 << OCIE0A);\r
 \r
@@ -121,6 +140,7 @@ void V2Protocol_ProcessCommand(void)
                        break;\r
        }\r
                \r
+       /* Disable timeout management interrupt once processing has completed */\r
        TIMSK0 &= ~(1 << OCIE0A);\r
 \r
        Endpoint_WaitUntilReady();\r
@@ -158,12 +178,12 @@ static void V2Protocol_SignOn(void)
        Endpoint_Write_Byte(CMD_SIGN_ON);\r
        Endpoint_Write_Byte(STATUS_CMD_OK);\r
        Endpoint_Write_Byte(sizeof(PROGRAMMER_ID) - 1);\r
-       Endpoint_Write_Stream_LE(PROGRAMMER_ID, (sizeof(PROGRAMMER_ID) - 1));\r
+       Endpoint_Write_Stream_LE(PROGRAMMER_ID, (sizeof(PROGRAMMER_ID) - 1), NO_STREAM_CALLBACK);\r
        Endpoint_ClearIN();\r
 }\r
 \r
-/** Handler for the CMD_RESET_PROTECTION command, currently implemented as a dummy ACK function\r
- *  as no ISP short-circuit protection is currently implemented.\r
+/** Handler for the CMD_RESET_PROTECTION command, implemented as a dummy ACK function as\r
+ *  no target short-circuit protection is currently implemented.\r
  */\r
 static void V2Protocol_ResetProtection(void)\r
 {\r
@@ -220,7 +240,7 @@ static void V2Protocol_GetSetParam(const uint8_t V2Command)
  */\r
 static void V2Protocol_LoadAddress(void)\r
 {\r
-       Endpoint_Read_Stream_BE(&CurrentAddress, sizeof(CurrentAddress));\r
+       Endpoint_Read_Stream_BE(&CurrentAddress, sizeof(CurrentAddress), NO_STREAM_CALLBACK);\r
 \r
        Endpoint_ClearOUT();\r
        Endpoint_SetEndpointDirection(ENDPOINT_DIR_IN);\r