Fixed Set/Clear Feature requests directed to a non-configured endpoint not returning...
[pub/USBasp.git] / Projects / AVRISP-MKII / Lib / V2Protocol.c
index d6de774..431f9c2 100644 (file)
@@ -42,14 +42,6 @@ uint32_t CurrentAddress;
 /** Flag to indicate that the next read/write operation must update the device's current address */\r
 bool MustSetAddress;\r
 \r
-\r
-/** ISR for the management of the command execution timeout counter */\r
-ISR(TIMER0_COMPA_vect, ISR_BLOCK)\r
-{\r
-       if (TimeoutMSRemaining)\r
-         TimeoutMSRemaining--;\r
-}\r
-\r
 /** Initializes the hardware and software associated with the V2 protocol command handling. */\r
 void V2Protocol_Init(void)\r
 {\r
@@ -57,7 +49,7 @@ void V2Protocol_Init(void)
        /* 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
+       ADC_StartReading(VTARGET_ADC_CHANNEL_MASK | ADC_RIGHT_ADJUSTED | ADC_REFERENCE_AVCC);\r
        #endif\r
        \r
        /* Millisecond timer initialization for managing the command timeout counter */\r
@@ -76,10 +68,8 @@ 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
+       \r
        switch (V2Command)\r
        {\r
                case CMD_SIGN_ON:\r
@@ -139,11 +129,9 @@ void V2Protocol_ProcessCommand(void)
                        V2Protocol_UnknownCommand(V2Command);\r
                        break;\r
        }\r
-               \r
-       /* Disable timeout management interrupt once processing has completed */\r
-       TIMSK0 &= ~(1 << OCIE0A);\r
 \r
        Endpoint_WaitUntilReady();\r
+       Endpoint_SelectEndpoint(AVRISP_DATA_OUT_EPNUM);\r
        Endpoint_SetEndpointDirection(ENDPOINT_DIR_OUT);\r
 }\r
 \r
@@ -162,6 +150,7 @@ static void V2Protocol_UnknownCommand(const uint8_t V2Command)
        }\r
 \r
        Endpoint_ClearOUT();\r
+       Endpoint_SelectEndpoint(AVRISP_DATA_IN_EPNUM);\r
        Endpoint_SetEndpointDirection(ENDPOINT_DIR_IN);\r
 \r
        Endpoint_Write_Byte(V2Command);\r
@@ -173,6 +162,7 @@ static void V2Protocol_UnknownCommand(const uint8_t V2Command)
 static void V2Protocol_SignOn(void)\r
 {\r
        Endpoint_ClearOUT();\r
+       Endpoint_SelectEndpoint(AVRISP_DATA_IN_EPNUM);\r
        Endpoint_SetEndpointDirection(ENDPOINT_DIR_IN);\r
 \r
        Endpoint_Write_Byte(CMD_SIGN_ON);\r
@@ -188,6 +178,7 @@ static void V2Protocol_SignOn(void)
 static void V2Protocol_ResetProtection(void)\r
 {\r
        Endpoint_ClearOUT();\r
+       Endpoint_SelectEndpoint(AVRISP_DATA_IN_EPNUM);\r
        Endpoint_SetEndpointDirection(ENDPOINT_DIR_IN);\r
        \r
        Endpoint_Write_Byte(CMD_RESET_PROTECTION);\r
@@ -210,6 +201,7 @@ static void V2Protocol_GetSetParam(const uint8_t V2Command)
          ParamValue = Endpoint_Read_Byte();\r
 \r
        Endpoint_ClearOUT();\r
+       Endpoint_SelectEndpoint(AVRISP_DATA_IN_EPNUM);\r
        Endpoint_SetEndpointDirection(ENDPOINT_DIR_IN);\r
        \r
        Endpoint_Write_Byte(V2Command);\r
@@ -243,6 +235,7 @@ static void V2Protocol_LoadAddress(void)
        Endpoint_Read_Stream_BE(&CurrentAddress, sizeof(CurrentAddress), NO_STREAM_CALLBACK);\r
 \r
        Endpoint_ClearOUT();\r
+       Endpoint_SelectEndpoint(AVRISP_DATA_IN_EPNUM);\r
        Endpoint_SetEndpointDirection(ENDPOINT_DIR_IN);\r
        \r
        MustSetAddress = true;\r