Update all demos, projects and bootloaders to indent all function parameters, one...
[pub/USBasp.git] / Projects / AVRISP-MKII / Lib / V2Protocol.c
index 3e12bdc..9e210c2 100644 (file)
 /** Current memory address for FLASH/EEPROM memory read/write commands */
 uint32_t CurrentAddress;
 
-/** Flag to indicate that the next read/write operation must update the device's current address */
-bool MustSetAddress;
+/** Flag to indicate that the next read/write operation must update the device's current extended FLASH address */
+bool MustLoadExtendedAddress;
 
 
 /** ISR to manage timeouts whilst processing a V2Protocol command */
 ISR(TIMER0_COMPA_vect, ISR_NOBLOCK)
 {
-       if (TimeoutMSRemaining)
-         TimeoutMSRemaining--;
+       if (TimeoutTicksRemaining)
+         TimeoutTicksRemaining--;
 }
 
 /** Initializes the hardware and software associated with the V2 protocol command handling. */
@@ -60,8 +60,8 @@ void V2Protocol_Init(void)
        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);
+       /* Timeout timer initialization (10ms period) */
+       OCR0A  = ((F_CPU / 1024) / 100);
        TCCR0A = (1 << WGM01);
        TIMSK0 = (1 << OCIE0A);
        
@@ -77,8 +77,8 @@ void V2Protocol_ProcessCommand(void)
        uint8_t V2Command = Endpoint_Read_Byte();
        
        /* Start the timeout management timer */
-       TimeoutMSRemaining = COMMAND_TIMEOUT_MS;
-       TCCR0B = ((1 << CS01) | (1 << CS00));
+       TimeoutTicksRemaining = COMMAND_TIMEOUT_TICKS;
+       TCCR0B = ((1 << CS02) | (1 << CS00));
        
        switch (V2Command)
        {
@@ -251,7 +251,8 @@ static void V2Protocol_LoadAddress(void)
        Endpoint_SelectEndpoint(AVRISP_DATA_IN_EPNUM);
        Endpoint_SetEndpointDirection(ENDPOINT_DIR_IN);
        
-       MustSetAddress = true;
+       if (CurrentAddress & (1UL << 31))
+         MustLoadExtendedAddress = true;
 
        Endpoint_Write_Byte(CMD_LOAD_ADDRESS);
        Endpoint_Write_Byte(STATUS_CMD_OK);