X-Git-Url: http://git.linex4red.de/pub/USBasp.git/blobdiff_plain/8f6b4ddf764c3a54e42d00a7502c82c5c3e71b1c..b9b03aadb219d06fbad9d110e508db93e45461af:/Bootloaders/DFU/BootloaderDFU.c?ds=inline diff --git a/Bootloaders/DFU/BootloaderDFU.c b/Bootloaders/DFU/BootloaderDFU.c index f3580163e..11177c5a6 100644 --- a/Bootloaders/DFU/BootloaderDFU.c +++ b/Bootloaders/DFU/BootloaderDFU.c @@ -139,7 +139,7 @@ int main (void) /** Event handler for the USB_Disconnect event. This indicates that the bootloader should exit and the user * application started. */ -EVENT_HANDLER(USB_Disconnect) +void EVENT_USB_Disconnect(void) { /* Upon disconnection, run user application */ RunBootloader = false; @@ -149,21 +149,15 @@ EVENT_HANDLER(USB_Disconnect) * control requests that are not handled internally by the USB library (including the DFU commands, which are * all issued via the control endpoint), so that they can be handled appropriately for the application. */ -EVENT_HANDLER(USB_UnhandledControlPacket) +void EVENT_USB_UnhandledControlPacket(void) { - /* Discard unused wIndex value */ - Endpoint_Discard_Word(); - - /* Discard unused wValue value */ - Endpoint_Discard_Word(); - /* Get the size of the command and data from the wLength value */ - SentCommand.DataSize = Endpoint_Read_Word_LE(); + SentCommand.DataSize = USB_ControlRequest.wLength; - switch (bRequest) + switch (USB_ControlRequest.bRequest) { case DFU_DNLOAD: - Endpoint_ClearControlSETUP(); + Endpoint_ClearSETUP(); /* Check if bootloader is waiting to terminate */ if (WaitForExit) @@ -225,7 +219,7 @@ EVENT_HANDLER(USB_UnhandledControlPacket) { uint16_t Words[2]; uint32_t Long; - } CurrFlashAddress = {Words: {StartAddr, Flash64KBPage}}; + } CurrFlashAddress = {.Words = {StartAddr, Flash64KBPage}}; uint32_t CurrFlashPageStartAddress = CurrFlashAddress.Long; uint8_t WordsInFlashPage = 0; @@ -235,7 +229,7 @@ EVENT_HANDLER(USB_UnhandledControlPacket) /* Check if endpoint is empty - if so clear it and wait until ready for next packet */ if (!(Endpoint_BytesInEndpoint())) { - Endpoint_ClearControlOUT(); + Endpoint_ClearOUT(); while (!(Endpoint_IsOUTReceived())); } @@ -279,7 +273,7 @@ EVENT_HANDLER(USB_UnhandledControlPacket) /* Check if endpoint is empty - if so clear it and wait until ready for next packet */ if (!(Endpoint_BytesInEndpoint())) { - Endpoint_ClearControlOUT(); + Endpoint_ClearOUT(); while (!(Endpoint_IsOUTReceived())); } @@ -296,15 +290,15 @@ EVENT_HANDLER(USB_UnhandledControlPacket) } } - Endpoint_ClearControlOUT(); + Endpoint_ClearOUT(); /* Acknowledge status stage */ while (!(Endpoint_IsINReady())); - Endpoint_ClearControlIN(); + Endpoint_ClearIN(); break; case DFU_UPLOAD: - Endpoint_ClearControlSETUP(); + Endpoint_ClearSETUP(); while (!(Endpoint_IsINReady())); @@ -336,14 +330,14 @@ EVENT_HANDLER(USB_UnhandledControlPacket) { uint16_t Words[2]; uint32_t Long; - } CurrFlashAddress = {Words: {StartAddr, Flash64KBPage}}; + } CurrFlashAddress = {.Words = {StartAddr, Flash64KBPage}}; while (WordsRemaining--) { /* Check if endpoint is full - if so clear it and wait until ready for next packet */ if (Endpoint_BytesInEndpoint() == FIXED_CONTROL_ENDPOINT_SIZE) { - Endpoint_ClearControlIN(); + Endpoint_ClearIN(); while (!(Endpoint_IsINReady())); } @@ -368,7 +362,7 @@ EVENT_HANDLER(USB_UnhandledControlPacket) /* Check if endpoint is full - if so clear it and wait until ready for next packet */ if (Endpoint_BytesInEndpoint() == FIXED_CONTROL_ENDPOINT_SIZE) { - Endpoint_ClearControlIN(); + Endpoint_ClearIN(); while (!(Endpoint_IsINReady())); } @@ -384,15 +378,15 @@ EVENT_HANDLER(USB_UnhandledControlPacket) DFU_State = dfuIDLE; } - Endpoint_ClearControlIN(); + Endpoint_ClearIN(); /* Acknowledge status stage */ while (!(Endpoint_IsOUTReceived())); - Endpoint_ClearControlOUT(); + Endpoint_ClearOUT(); break; case DFU_GETSTATUS: - Endpoint_ClearControlSETUP(); + Endpoint_ClearSETUP(); /* Write 8-bit status value */ Endpoint_Write_Byte(DFU_Status); @@ -407,46 +401,46 @@ EVENT_HANDLER(USB_UnhandledControlPacket) /* Write 8-bit state string ID number */ Endpoint_Write_Byte(0); - Endpoint_ClearControlIN(); + Endpoint_ClearIN(); /* Acknowledge status stage */ while (!(Endpoint_IsOUTReceived())); - Endpoint_ClearControlOUT(); + Endpoint_ClearOUT(); break; case DFU_CLRSTATUS: - Endpoint_ClearControlSETUP(); + Endpoint_ClearSETUP(); /* Reset the status value variable to the default OK status */ DFU_Status = OK; /* Acknowledge status stage */ while (!(Endpoint_IsINReady())); - Endpoint_ClearControlIN(); + Endpoint_ClearIN(); break; case DFU_GETSTATE: - Endpoint_ClearControlSETUP(); + Endpoint_ClearSETUP(); /* Write the current device state to the endpoint */ Endpoint_Write_Byte(DFU_State); - Endpoint_ClearControlIN(); + Endpoint_ClearIN(); /* Acknowledge status stage */ while (!(Endpoint_IsOUTReceived())); - Endpoint_ClearControlOUT(); + Endpoint_ClearOUT(); break; case DFU_ABORT: - Endpoint_ClearControlSETUP(); + Endpoint_ClearSETUP(); /* Reset the current state variable to the default idle state */ DFU_State = dfuIDLE; /* Acknowledge status stage */ while (!(Endpoint_IsINReady())); - Endpoint_ClearControlIN(); + Endpoint_ClearIN(); break; } @@ -463,7 +457,7 @@ static void DiscardFillerBytes(uint8_t NumberOfBytes) { if (!(Endpoint_BytesInEndpoint())) { - Endpoint_ClearControlOUT(); + Endpoint_ClearOUT(); /* Wait until next data packet received */ while (!(Endpoint_IsOUTReceived())); @@ -531,8 +525,8 @@ static void LoadStartEndAddresses(void) { uint8_t Bytes[2]; uint16_t Word; - } Address[2] = {{Bytes: {SentCommand.Data[2], SentCommand.Data[1]}}, - {Bytes: {SentCommand.Data[4], SentCommand.Data[3]}}}; + } Address[2] = {{.Bytes = {SentCommand.Data[2], SentCommand.Data[1]}}, + {.Bytes = {SentCommand.Data[4], SentCommand.Data[3]}}}; /* Load in the start and ending read addresses from the sent data packet */ StartAddr = Address[0].Word; @@ -557,7 +551,7 @@ static void ProcessMemProgCommand(void) { uint16_t Words[2]; uint32_t Long; - } CurrFlashAddress = {Words: {StartAddr, Flash64KBPage}}; + } CurrFlashAddress = {.Words = {StartAddr, Flash64KBPage}}; /* Erase the current page's temp buffer */ boot_page_erase(CurrFlashAddress.Long); @@ -639,7 +633,7 @@ static void ProcessWriteCommand(void) { uint8_t Bytes[2]; AppPtr_t FuncPtr; - } Address = {Bytes: {SentCommand.Data[4], SentCommand.Data[3]}}; + } Address = {.Bytes = {SentCommand.Data[4], SentCommand.Data[3]}}; AppStartPtr = Address.FuncPtr;