X-Git-Url: http://git.linex4red.de/pub/USBasp.git/blobdiff_plain/271be037b736d66a7b7e0c4d5d30c5a24025277f..21cc9c9e19ce6bd757410cc6da29b5dc2ee8041c:/Projects/AVRISP/Lib/V2Protocol.c diff --git a/Projects/AVRISP/Lib/V2Protocol.c b/Projects/AVRISP/Lib/V2Protocol.c index 248c50d24..d03bd8924 100644 --- a/Projects/AVRISP/Lib/V2Protocol.c +++ b/Projects/AVRISP/Lib/V2Protocol.c @@ -36,12 +36,12 @@ #define INCLUDE_FROM_V2PROTOCOL_C #include "V2Protocol.h" -/** Master V2 Protocol packet handler, for receieved V2 Protocol packets from a connected host. +/** 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. */ -void V2Protocol_ProcessCommand(void) -{ +void V2Protocol_ProcessCommand(void) +{ uint8_t V2Command = Endpoint_Read_Byte(); switch (V2Command) @@ -95,17 +95,17 @@ void V2Protocol_ProcessCommand(void) } Endpoint_WaitUntilReady(); - Endpoint_SetEndpointDirection(ENDPOINT_DIR_OUT); -} + Endpoint_SetEndpointDirection(ENDPOINT_DIR_OUT); +} /** Handler for unknown V2 protocol commands. This discards all sent data and returns a * STATUS_CMD_UNKNOWN status back to the host. * - * \param V2Command Issued V2 Protocol command byte from the host + * \param[in] V2Command Issued V2 Protocol command byte from the host */ static void V2Protocol_Command_Unknown(uint8_t V2Command) { - /* Discard all incomming data */ + /* Discard all incoming data */ while (Endpoint_BytesInEndpoint() == AVRISP_DATA_EPSIZE) { Endpoint_ClearOUT(); @@ -120,7 +120,7 @@ static void V2Protocol_Command_Unknown(uint8_t V2Command) Endpoint_ClearIN(); } -/** Handler for the CMD_SIGN_ON command, returning the programmer ID string to the host. */ +/** Handler for the CMD_SIGN_ON command, returning the programmer ID string to the host. */ static void V2Protocol_Command_SignOn(void) { Endpoint_ClearOUT(); @@ -136,7 +136,7 @@ static void V2Protocol_Command_SignOn(void) /** Handler for the CMD_SET_PARAMETER and CMD_GET_PARAMETER commands from the host, setting or * getting a device parameter's value from the parameter table. * - * \param V2Command Issued V2 Protocol command byte from the host + * \param[in] V2Command Issued V2 Protocol command byte from the host */ static void V2Protocol_Command_GetSetParam(uint8_t V2Command) { @@ -151,7 +151,7 @@ static void V2Protocol_Command_GetSetParam(uint8_t V2Command) Endpoint_Write_Byte(V2Command); - uint8_t ParamPrivs = V2Params_GetParameterPrivellages(ParamID); + uint8_t ParamPrivs = V2Params_GetParameterPrivileges(ParamID); if ((V2Command == CMD_SET_PARAMETER) && (ParamPrivs & PARAM_PRIV_WRITE)) { @@ -289,7 +289,7 @@ static void V2Protocol_Command_LeaveISPMode(void) /** Handler for the CMD_PROGRAM_FLASH_ISP and CMD_PROGRAM_EEPROM_ISP commands, writing out bytes, * words or pages of data to the attached device. * - * \param V2Command Issued V2 Protocol command byte from the host + * \param[in] V2Command Issued V2 Protocol command byte from the host */ static void V2Protocol_Command_ProgramMemory(uint8_t V2Command) { @@ -301,13 +301,23 @@ static void V2Protocol_Command_ProgramMemory(uint8_t V2Command) uint8_t ProgrammingCommands[3]; uint8_t PollValue1; uint8_t PollValue2; - uint8_t ProgData[512]; - } Write_Memory_Params; + uint8_t ProgData[256]; // Note, the Jungo driver has a very short ACK timeout period, need to buffer the + } Write_Memory_Params; // whole page and ACK the packet as fast as possible to prevent it from aborting - uint8_t* NextWriteByte = Write_Memory_Params.ProgData; - Endpoint_Read_Stream_LE(&Write_Memory_Params, sizeof(Write_Memory_Params) - sizeof(Write_Memory_Params.ProgData)); Write_Memory_Params.BytesToWrite = SwapEndian_16(Write_Memory_Params.BytesToWrite); + + if (Write_Memory_Params.BytesToWrite > sizeof(Write_Memory_Params.ProgData)) + { + Endpoint_ClearOUT(); + Endpoint_SetEndpointDirection(ENDPOINT_DIR_IN); + + Endpoint_Write_Byte(V2Command); + Endpoint_Write_Byte(STATUS_CMD_FAILED); + Endpoint_ClearIN(); + return; + } + Endpoint_Read_Stream_LE(&Write_Memory_Params.ProgData, Write_Memory_Params.BytesToWrite); Endpoint_ClearOUT(); @@ -317,6 +327,8 @@ static void V2Protocol_Command_ProgramMemory(uint8_t V2Command) uint16_t PollAddress = 0; uint8_t PollValue = (V2Command == CMD_PROGRAM_FLASH_ISP) ? Write_Memory_Params.PollValue1 : Write_Memory_Params.PollValue2; + uint8_t* NextWriteByte = Write_Memory_Params.ProgData; + if (Write_Memory_Params.ProgrammingMode & PROG_MODE_PAGED_WRITES_MASK) { uint16_t StartAddress = (CurrentAddress & 0xFFFF); @@ -407,14 +419,13 @@ static void V2Protocol_Command_ProgramMemory(uint8_t V2Command) Endpoint_Write_Byte(V2Command); Endpoint_Write_Byte(ProgrammingStatus); - Endpoint_ClearIN(); } /** Handler for the CMD_READ_FLASH_ISP and CMD_READ_EEPROM_ISP commands, reading in bytes, * words or pages of data from the attached device. * - * \param V2Command Issued V2 Protocol command byte from the host + * \param[in] V2Command Issued V2 Protocol command byte from the host */ static void V2Protocol_Command_ReadMemory(uint8_t V2Command) { @@ -505,7 +516,7 @@ static void V2Protocol_Command_ChipErase(void) /** Handler for the CMD_READ_FUSE_ISP, CMD_READ_LOCK_ISP, CMD_READ_SIGNATURE_ISP and CMD_READ_OSCCAL commands, * reading the requested configuration byte from the device. * - * \param V2Command Issued V2 Protocol command byte from the host + * \param[in] V2Command Issued V2 Protocol command byte from the host */ static void V2Protocol_Command_ReadFuseLockSigOSCCAL(uint8_t V2Command) { @@ -535,7 +546,7 @@ static void V2Protocol_Command_ReadFuseLockSigOSCCAL(uint8_t V2Command) /** Handler for the CMD_WRITE_FUSE_ISP and CMD_WRITE_LOCK_ISP commands, writing the requested configuration * byte to the device. * - * \param V2Command Issued V2 Protocol command byte from the host + * \param[in] V2Command Issued V2 Protocol command byte from the host */ static void V2Protocol_Command_WriteFuseLock(uint8_t V2Command) {