Add optional double-banking support to the Device mode Class Drivers, on a per-endpoi...
[pub/USBasp.git] / Projects / AVRISP / Lib / V2Protocol.c
index 3a1b78e..6099234 100644 (file)
@@ -101,7 +101,7 @@ void V2Protocol_ProcessCommand(void)
 /** Handler for unknown V2 protocol commands. This discards all sent data and returns a\r
  *  STATUS_CMD_UNKNOWN status back to the host.\r
  *\r
 /** Handler for unknown V2 protocol commands. This discards all sent data and returns a\r
  *  STATUS_CMD_UNKNOWN status back to the host.\r
  *\r
- *  \param V2Command  Issued V2 Protocol command byte from the host\r
+ *  \param[in] V2Command  Issued V2 Protocol command byte from the host\r
  */\r
 static void V2Protocol_Command_Unknown(uint8_t V2Command)\r
 {\r
  */\r
 static void V2Protocol_Command_Unknown(uint8_t V2Command)\r
 {\r
@@ -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\r
  *  getting a device parameter's value from the parameter table.\r
  *\r
 /** Handler for the CMD_SET_PARAMETER and CMD_GET_PARAMETER commands from the host, setting or\r
  *  getting a device parameter's value from the parameter table.\r
  *\r
- *  \param V2Command  Issued V2 Protocol command byte from the host\r
+ *  \param[in] V2Command  Issued V2 Protocol command byte from the host\r
  */\r
 static void V2Protocol_Command_GetSetParam(uint8_t V2Command)\r
 {\r
  */\r
 static void V2Protocol_Command_GetSetParam(uint8_t V2Command)\r
 {\r
@@ -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,\r
  *  words or pages of data to the attached device.\r
  *\r
 /** Handler for the CMD_PROGRAM_FLASH_ISP and CMD_PROGRAM_EEPROM_ISP commands, writing out bytes,\r
  *  words or pages of data to the attached device.\r
  *\r
- *  \param V2Command  Issued V2 Protocol command byte from the host\r
+ *  \param[in] V2Command  Issued V2 Protocol command byte from the host\r
  */\r
 static void V2Protocol_Command_ProgramMemory(uint8_t V2Command)\r
 {\r
  */\r
 static void V2Protocol_Command_ProgramMemory(uint8_t V2Command)\r
 {\r
@@ -308,6 +308,18 @@ static void V2Protocol_Command_ProgramMemory(uint8_t V2Command)
 \r
        Endpoint_Read_Stream_LE(&Write_Memory_Params, sizeof(Write_Memory_Params) - sizeof(Write_Memory_Params.ProgData));\r
        Write_Memory_Params.BytesToWrite = SwapEndian_16(Write_Memory_Params.BytesToWrite);\r
 \r
        Endpoint_Read_Stream_LE(&Write_Memory_Params, sizeof(Write_Memory_Params) - sizeof(Write_Memory_Params.ProgData));\r
        Write_Memory_Params.BytesToWrite = SwapEndian_16(Write_Memory_Params.BytesToWrite);\r
+       \r
+       if (Write_Memory_Params.BytesToWrite > sizeof(Write_Memory_Params.ProgData))\r
+       {\r
+               Endpoint_ClearOUT();\r
+               Endpoint_SetEndpointDirection(ENDPOINT_DIR_IN);\r
+\r
+               Endpoint_Write_Byte(V2Command);\r
+               Endpoint_Write_Byte(STATUS_CMD_FAILED);\r
+               Endpoint_ClearIN();\r
+               return;\r
+       }\r
+       \r
        Endpoint_Read_Stream_LE(&Write_Memory_Params.ProgData, Write_Memory_Params.BytesToWrite);\r
 \r
        Endpoint_ClearOUT();\r
        Endpoint_Read_Stream_LE(&Write_Memory_Params.ProgData, Write_Memory_Params.BytesToWrite);\r
 \r
        Endpoint_ClearOUT();\r
@@ -407,14 +419,13 @@ static void V2Protocol_Command_ProgramMemory(uint8_t V2Command)
 \r
        Endpoint_Write_Byte(V2Command);\r
        Endpoint_Write_Byte(ProgrammingStatus);\r
 \r
        Endpoint_Write_Byte(V2Command);\r
        Endpoint_Write_Byte(ProgrammingStatus);\r
-       \r
        Endpoint_ClearIN();\r
 }\r
 \r
 /** Handler for the CMD_READ_FLASH_ISP and CMD_READ_EEPROM_ISP commands, reading in bytes,\r
  *  words or pages of data from the attached device.\r
  *\r
        Endpoint_ClearIN();\r
 }\r
 \r
 /** Handler for the CMD_READ_FLASH_ISP and CMD_READ_EEPROM_ISP commands, reading in bytes,\r
  *  words or pages of data from the attached device.\r
  *\r
- *  \param V2Command  Issued V2 Protocol command byte from the host\r
+ *  \param[in] V2Command  Issued V2 Protocol command byte from the host\r
  */\r
 static void V2Protocol_Command_ReadMemory(uint8_t V2Command)\r
 {\r
  */\r
 static void V2Protocol_Command_ReadMemory(uint8_t V2Command)\r
 {\r
@@ -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,\r
  *  reading the requested configuration byte from the device.\r
  *\r
 /** Handler for the CMD_READ_FUSE_ISP, CMD_READ_LOCK_ISP, CMD_READ_SIGNATURE_ISP and CMD_READ_OSCCAL commands,\r
  *  reading the requested configuration byte from the device.\r
  *\r
- *  \param V2Command  Issued V2 Protocol command byte from the host\r
+ *  \param[in] V2Command  Issued V2 Protocol command byte from the host\r
  */\r
 static void V2Protocol_Command_ReadFuseLockSigOSCCAL(uint8_t V2Command)\r
 {\r
  */\r
 static void V2Protocol_Command_ReadFuseLockSigOSCCAL(uint8_t V2Command)\r
 {\r
@@ -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\r
  *  byte to the device.\r
  *\r
 /** Handler for the CMD_WRITE_FUSE_ISP and CMD_WRITE_LOCK_ISP commands, writing the requested configuration\r
  *  byte to the device.\r
  *\r
- *  \param V2Command  Issued V2 Protocol command byte from the host\r
+ *  \param[in] V2Command  Issued V2 Protocol command byte from the host\r
  */\r
 static void V2Protocol_Command_WriteFuseLock(uint8_t V2Command)\r
 {\r
  */\r
 static void V2Protocol_Command_WriteFuseLock(uint8_t V2Command)\r
 {\r