Changed XPLAINBridge project to be both a USB to USART bridge and a PDI programmer, based on the state of a mode select pin.
This commit is contained in:
parent
2746154652
commit
60fd0ff418
14 changed files with 205 additions and 112 deletions
|
|
@ -42,8 +42,6 @@
|
|||
int main(void)
|
||||
{
|
||||
SetupHardware();
|
||||
|
||||
V2Params_LoadNonVolatileParamValues();
|
||||
|
||||
LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
|
||||
|
||||
|
|
@ -70,18 +68,7 @@ void SetupHardware(void)
|
|||
/* Hardware Initialization */
|
||||
LEDs_Init();
|
||||
USB_Init();
|
||||
|
||||
#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));
|
||||
V2Protocol_Init();
|
||||
}
|
||||
|
||||
/** Event handler for the library USB Connection event. */
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ void ISPProtocol_EnterISPMode(void)
|
|||
uint8_t EnterProgBytes[4];
|
||||
} Enter_ISP_Params;
|
||||
|
||||
Endpoint_Read_Stream_LE(&Enter_ISP_Params, sizeof(Enter_ISP_Params));
|
||||
Endpoint_Read_Stream_LE(&Enter_ISP_Params, sizeof(Enter_ISP_Params), NO_STREAM_CALLBACK);
|
||||
|
||||
Endpoint_ClearOUT();
|
||||
Endpoint_SetEndpointDirection(ENDPOINT_DIR_IN);
|
||||
|
|
@ -107,7 +107,7 @@ void ISPProtocol_LeaveISPMode(void)
|
|||
uint8_t PostDelayMS;
|
||||
} Leave_ISP_Params;
|
||||
|
||||
Endpoint_Read_Stream_LE(&Leave_ISP_Params, sizeof(Leave_ISP_Params));
|
||||
Endpoint_Read_Stream_LE(&Leave_ISP_Params, sizeof(Leave_ISP_Params), NO_STREAM_CALLBACK);
|
||||
|
||||
Endpoint_ClearOUT();
|
||||
Endpoint_SetEndpointDirection(ENDPOINT_DIR_IN);
|
||||
|
|
@ -142,7 +142,7 @@ void ISPProtocol_ProgramMemory(uint8_t V2Command)
|
|||
} Write_Memory_Params; // whole page and ACK the packet as fast as possible to prevent it from aborting
|
||||
|
||||
Endpoint_Read_Stream_LE(&Write_Memory_Params, (sizeof(Write_Memory_Params) -
|
||||
sizeof(Write_Memory_Params.ProgData)));
|
||||
sizeof(Write_Memory_Params.ProgData)), NO_STREAM_CALLBACK);
|
||||
|
||||
|
||||
Write_Memory_Params.BytesToWrite = SwapEndian_16(Write_Memory_Params.BytesToWrite);
|
||||
|
|
@ -158,7 +158,7 @@ void ISPProtocol_ProgramMemory(uint8_t V2Command)
|
|||
return;
|
||||
}
|
||||
|
||||
Endpoint_Read_Stream_LE(&Write_Memory_Params.ProgData, Write_Memory_Params.BytesToWrite);
|
||||
Endpoint_Read_Stream_LE(&Write_Memory_Params.ProgData, Write_Memory_Params.BytesToWrite, NO_STREAM_CALLBACK);
|
||||
|
||||
Endpoint_ClearOUT();
|
||||
Endpoint_SetEndpointDirection(ENDPOINT_DIR_IN);
|
||||
|
|
@ -287,7 +287,7 @@ void ISPProtocol_ReadMemory(uint8_t V2Command)
|
|||
uint8_t ReadMemoryCommand;
|
||||
} Read_Memory_Params;
|
||||
|
||||
Endpoint_Read_Stream_LE(&Read_Memory_Params, sizeof(Read_Memory_Params));
|
||||
Endpoint_Read_Stream_LE(&Read_Memory_Params, sizeof(Read_Memory_Params), NO_STREAM_CALLBACK);
|
||||
Read_Memory_Params.BytesToRead = SwapEndian_16(Read_Memory_Params.BytesToRead);
|
||||
|
||||
Endpoint_ClearOUT();
|
||||
|
|
@ -358,7 +358,7 @@ void ISPProtocol_ChipErase(void)
|
|||
uint8_t EraseCommandBytes[4];
|
||||
} Erase_Chip_Params;
|
||||
|
||||
Endpoint_Read_Stream_LE(&Erase_Chip_Params, sizeof(Erase_Chip_Params));
|
||||
Endpoint_Read_Stream_LE(&Erase_Chip_Params, sizeof(Erase_Chip_Params), NO_STREAM_CALLBACK);
|
||||
|
||||
Endpoint_ClearOUT();
|
||||
Endpoint_SetEndpointDirection(ENDPOINT_DIR_IN);
|
||||
|
|
@ -393,7 +393,7 @@ void ISPProtocol_ReadFuseLockSigOSCCAL(uint8_t V2Command)
|
|||
uint8_t ReadCommandBytes[4];
|
||||
} Read_FuseLockSigOSCCAL_Params;
|
||||
|
||||
Endpoint_Read_Stream_LE(&Read_FuseLockSigOSCCAL_Params, sizeof(Read_FuseLockSigOSCCAL_Params));
|
||||
Endpoint_Read_Stream_LE(&Read_FuseLockSigOSCCAL_Params, sizeof(Read_FuseLockSigOSCCAL_Params), NO_STREAM_CALLBACK);
|
||||
|
||||
Endpoint_ClearOUT();
|
||||
Endpoint_SetEndpointDirection(ENDPOINT_DIR_IN);
|
||||
|
|
@ -423,7 +423,7 @@ void ISPProtocol_WriteFuseLock(uint8_t V2Command)
|
|||
uint8_t WriteCommandBytes[4];
|
||||
} Write_FuseLockSig_Params;
|
||||
|
||||
Endpoint_Read_Stream_LE(&Write_FuseLockSig_Params, sizeof(Write_FuseLockSig_Params));
|
||||
Endpoint_Read_Stream_LE(&Write_FuseLockSig_Params, sizeof(Write_FuseLockSig_Params), NO_STREAM_CALLBACK);
|
||||
|
||||
Endpoint_ClearOUT();
|
||||
Endpoint_SetEndpointDirection(ENDPOINT_DIR_IN);
|
||||
|
|
@ -449,8 +449,8 @@ void ISPProtocol_SPIMulti(void)
|
|||
uint8_t TxData[255];
|
||||
} SPI_Multi_Params;
|
||||
|
||||
Endpoint_Read_Stream_LE(&SPI_Multi_Params, sizeof(SPI_Multi_Params) - sizeof(SPI_Multi_Params.TxData));
|
||||
Endpoint_Read_Stream_LE(&SPI_Multi_Params.TxData, SPI_Multi_Params.TxBytes);
|
||||
Endpoint_Read_Stream_LE(&SPI_Multi_Params, (sizeof(SPI_Multi_Params) - sizeof(SPI_Multi_Params.TxData)), NO_STREAM_CALLBACK);
|
||||
Endpoint_Read_Stream_LE(&SPI_Multi_Params.TxData, SPI_Multi_Params.TxBytes, NO_STREAM_CALLBACK);
|
||||
|
||||
Endpoint_ClearOUT();
|
||||
Endpoint_SetEndpointDirection(ENDPOINT_DIR_IN);
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
@ -160,7 +178,7 @@ 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();
|
||||
}
|
||||
|
||||
|
|
@ -222,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);
|
||||
|
|
|
|||
|
|
@ -70,6 +70,7 @@
|
|||
extern bool MustSetAddress;
|
||||
|
||||
/* Function Prototypes: */
|
||||
void V2Protocol_Init(void);
|
||||
void V2Protocol_ProcessCommand(void);
|
||||
|
||||
#if defined(INCLUDE_FROM_V2PROTOCOL_C)
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@ void XPROGProtocol_SetMode(void)
|
|||
uint8_t Protocol;
|
||||
} SetMode_XPROG_Params;
|
||||
|
||||
Endpoint_Read_Stream_LE(&SetMode_XPROG_Params, sizeof(SetMode_XPROG_Params));
|
||||
Endpoint_Read_Stream_LE(&SetMode_XPROG_Params, sizeof(SetMode_XPROG_Params), NO_STREAM_CALLBACK);
|
||||
|
||||
Endpoint_ClearOUT();
|
||||
Endpoint_SetEndpointDirection(ENDPOINT_DIR_IN);
|
||||
|
|
@ -202,7 +202,7 @@ static void XPROGProtocol_Erase(void)
|
|||
uint32_t Address;
|
||||
} Erase_XPROG_Params;
|
||||
|
||||
Endpoint_Read_Stream_LE(&Erase_XPROG_Params, sizeof(Erase_XPROG_Params));
|
||||
Endpoint_Read_Stream_LE(&Erase_XPROG_Params, sizeof(Erase_XPROG_Params), NO_STREAM_CALLBACK);
|
||||
Erase_XPROG_Params.Address = SwapEndian_32(Erase_XPROG_Params.Address);
|
||||
|
||||
Endpoint_ClearOUT();
|
||||
|
|
@ -262,10 +262,10 @@ static void XPROGProtocol_WriteMemory(void)
|
|||
} WriteMemory_XPROG_Params;
|
||||
|
||||
Endpoint_Read_Stream_LE(&WriteMemory_XPROG_Params, (sizeof(WriteMemory_XPROG_Params) -
|
||||
sizeof(WriteMemory_XPROG_Params).ProgData));
|
||||
sizeof(WriteMemory_XPROG_Params).ProgData), NO_STREAM_CALLBACK);
|
||||
WriteMemory_XPROG_Params.Address = SwapEndian_32(WriteMemory_XPROG_Params.Address);
|
||||
WriteMemory_XPROG_Params.Length = SwapEndian_16(WriteMemory_XPROG_Params.Length);
|
||||
Endpoint_Read_Stream_LE(&WriteMemory_XPROG_Params.ProgData, WriteMemory_XPROG_Params.Length);
|
||||
Endpoint_Read_Stream_LE(&WriteMemory_XPROG_Params.ProgData, WriteMemory_XPROG_Params.Length, NO_STREAM_CALLBACK);
|
||||
|
||||
Endpoint_ClearOUT();
|
||||
Endpoint_SetEndpointDirection(ENDPOINT_DIR_IN);
|
||||
|
|
@ -351,7 +351,7 @@ static void XPROGProtocol_ReadMemory(void)
|
|||
uint16_t Length;
|
||||
} ReadMemory_XPROG_Params;
|
||||
|
||||
Endpoint_Read_Stream_LE(&ReadMemory_XPROG_Params, sizeof(ReadMemory_XPROG_Params));
|
||||
Endpoint_Read_Stream_LE(&ReadMemory_XPROG_Params, sizeof(ReadMemory_XPROG_Params), NO_STREAM_CALLBACK);
|
||||
ReadMemory_XPROG_Params.Address = SwapEndian_32(ReadMemory_XPROG_Params.Address);
|
||||
ReadMemory_XPROG_Params.Length = SwapEndian_16(ReadMemory_XPROG_Params.Length);
|
||||
|
||||
|
|
@ -380,7 +380,7 @@ static void XPROGProtocol_ReadMemory(void)
|
|||
Endpoint_Write_Byte(ReturnStatus);
|
||||
|
||||
if (ReturnStatus == XPRG_ERR_OK)
|
||||
Endpoint_Write_Stream_LE(ReadBuffer, ReadMemory_XPROG_Params.Length);
|
||||
Endpoint_Write_Stream_LE(ReadBuffer, ReadMemory_XPROG_Params.Length, NO_STREAM_CALLBACK);
|
||||
|
||||
Endpoint_ClearIN();
|
||||
}
|
||||
|
|
@ -397,7 +397,7 @@ static void XPROGProtocol_ReadCRC(void)
|
|||
uint8_t CRCType;
|
||||
} ReadCRC_XPROG_Params;
|
||||
|
||||
Endpoint_Read_Stream_LE(&ReadCRC_XPROG_Params, sizeof(ReadCRC_XPROG_Params));
|
||||
Endpoint_Read_Stream_LE(&ReadCRC_XPROG_Params, sizeof(ReadCRC_XPROG_Params), NO_STREAM_CALLBACK);
|
||||
Endpoint_ClearOUT();
|
||||
Endpoint_SetEndpointDirection(ENDPOINT_DIR_IN);
|
||||
|
||||
|
|
|
|||
|
|
@ -119,7 +119,6 @@ LUFA_PATH = ../../
|
|||
LUFA_OPTS = -D USB_DEVICE_ONLY
|
||||
LUFA_OPTS += -D FIXED_CONTROL_ENDPOINT_SIZE=16
|
||||
LUFA_OPTS += -D FIXED_NUM_CONFIGURATIONS=1
|
||||
LUFA_OPTS += -D NO_STREAM_CALLBACKS
|
||||
LUFA_OPTS += -D USE_FLASH_DESCRIPTORS
|
||||
LUFA_OPTS += -D USE_STATIC_OPTIONS="(USB_DEVICE_OPT_FULLSPEED | USB_OPT_REG_ENABLED | USB_OPT_AUTO_PLL)"
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue