Add svn:eol-style property to source files, so that the line endings are correctly...
[pub/USBasp.git] / Bootloaders / DFU / BootloaderDFU.h
index 4583d6c..43ea70f 100644 (file)
-/*\r
-             LUFA Library\r
-     Copyright (C) Dean Camera, 2010.\r
-              \r
-  dean [at] fourwalledcubicle [dot] com\r
-      www.fourwalledcubicle.com\r
-*/\r
-\r
-/*\r
-  Copyright 2010  Dean Camera (dean [at] fourwalledcubicle [dot] com)\r
-\r
-  Permission to use, copy, modify, distribute, and sell this \r
-  software and its documentation for any purpose is hereby granted\r
-  without fee, provided that the above copyright notice appear in \r
-  all copies and that both that the copyright notice and this\r
-  permission notice and warranty disclaimer appear in supporting \r
-  documentation, and that the name of the author not be used in \r
-  advertising or publicity pertaining to distribution of the \r
-  software without specific, written prior permission.\r
-\r
-  The author disclaim all warranties with regard to this\r
-  software, including all implied warranties of merchantability\r
-  and fitness.  In no event shall the author be liable for any\r
-  special, indirect or consequential damages or any damages\r
-  whatsoever resulting from loss of use, data or profits, whether\r
-  in an action of contract, negligence or other tortious action,\r
-  arising out of or in connection with the use or performance of\r
-  this software.\r
-*/\r
-\r
-/** \file\r
- *\r
- *  Header file for BootloaderDFU.c.\r
- */\r
-\r
-#ifndef _BOOTLOADER_H_\r
-#define _BOOTLOADER_H_\r
-\r
-       /* Includes: */\r
-               #include <avr/io.h>\r
-               #include <avr/wdt.h>\r
-               #include <avr/boot.h>\r
-               #include <avr/pgmspace.h>\r
-               #include <avr/eeprom.h>\r
-               #include <avr/power.h>\r
-               #include <avr/interrupt.h>\r
-               #include <stdbool.h>\r
-       \r
-               #include "Descriptors.h"\r
-               \r
-               #include <LUFA/Drivers/USB/USB.h>\r
-       \r
-       /* Macros: */\r
-               /** Configuration define. Define this token to true to case the bootloader to reject all memory commands\r
-                *  until a memory erase has been performed. When used in conjunction with the lockbits of the AVR, this\r
-                *  can protect the AVR's firmware from being dumped from a secured AVR. When false, memory operations are\r
-                *  allowed at any time.\r
-                */\r
-               #define SECURE_MODE              false\r
-\r
-               /** Major bootloader version number. */\r
-               #define BOOTLOADER_VERSION_MINOR 2\r
-\r
-               /** Minor bootloader version number. */\r
-               #define BOOTLOADER_VERSION_REV   0\r
-\r
-               /** Complete bootloader version number expressed as a packed byte, constructed from the \r
-                *  two individual bootloader version macros.\r
-                */\r
-               #define BOOTLOADER_VERSION       ((BOOTLOADER_VERSION_MINOR << 4) | BOOTLOADER_VERSION_REV)\r
-\r
-               /** First byte of the bootloader identification bytes, used to identify a device's bootloader. */\r
-               #define BOOTLOADER_ID_BYTE1      0xDC\r
-\r
-               /** Second byte of the bootloader identification bytes, used to identify a device's bootloader. */\r
-               #define BOOTLOADER_ID_BYTE2      0xFB\r
-               \r
-               /** Convenience macro, used to determine if the issued command is the given one-byte long command.\r
-                *\r
-                *  \param[in] dataarr  Command byte array to check against\r
-                *  \param[in] cb1      First command byte to check\r
-                */\r
-               #define IS_ONEBYTE_COMMAND(dataarr, cb1)       (dataarr[0] == (cb1))\r
-\r
-               /** Convenience macro, used to determine if the issued command is the given two-byte long command.\r
-                *\r
-                *  \param[in] dataarr  Command byte array to check against\r
-                *  \param[in] cb1      First command byte to check\r
-                *  \param[in] cb2      Second command byte to check\r
-                */\r
-               #define IS_TWOBYTE_COMMAND(dataarr, cb1, cb2) ((dataarr[0] == (cb1)) && (dataarr[1] == (cb2)))\r
-       \r
-               /** Length of the DFU file suffix block, appended to the end of each complete memory write command.\r
-                *  The DFU file suffix is currently unused (but is designed to give extra file information, such as\r
-                *  a CRC of the complete firmware for error checking) and so is discarded.\r
-                */\r
-               #define DFU_FILE_SUFFIX_SIZE     16\r
-\r
-               /** Length of the DFU file filler block, appended to the start of each complete memory write command.\r
-                *  Filler bytes are added to the start of each complete memory write command, and must be discarded.\r
-                */\r
-               #define DFU_FILLER_BYTES_SIZE    26\r
-       \r
-               /** DFU class command request to detach from the host. */\r
-               #define DFU_DETATCH              0x00\r
-\r
-               /** DFU class command request to send data from the host to the bootloader. */\r
-               #define DFU_DNLOAD               0x01\r
-\r
-               /** DFU class command request to send data from the bootloader to the host. */\r
-               #define DFU_UPLOAD               0x02\r
-\r
-               /** DFU class command request to get the current DFU status and state from the bootloader. */\r
-               #define DFU_GETSTATUS            0x03\r
-\r
-               /** DFU class command request to reset the current DFU status and state variables to their defaults. */\r
-               #define DFU_CLRSTATUS            0x04\r
-\r
-               /** DFU class command request to get the current DFU state of the bootloader. */\r
-               #define DFU_GETSTATE             0x05\r
-\r
-               /** DFU class command request to abort the current multi-request transfer and return to the dfuIDLE state. */\r
-               #define DFU_ABORT                0x06\r
-\r
-               /** DFU command to begin programming the device's memory. */\r
-               #define COMMAND_PROG_START       0x01\r
-\r
-               /** DFU command to begin reading the device's memory. */\r
-               #define COMMAND_DISP_DATA        0x03\r
-\r
-               /** DFU command to issue a write command. */\r
-               #define COMMAND_WRITE            0x04\r
-\r
-               /** DFU command to issue a read command. */\r
-               #define COMMAND_READ             0x05\r
-\r
-               /** DFU command to issue a memory base address change command, to set the current 64KB flash page\r
-                *  that subsequent flash operations should use. */\r
-               #define COMMAND_CHANGE_BASE_ADDR 0x06\r
-\r
-       /* Type Defines: */\r
-               /** Type define for a non-returning function pointer to the loaded application. */\r
-               typedef void (*AppPtr_t)(void) ATTR_NO_RETURN;\r
-               \r
-               /** Type define for a structure containing a complete DFU command issued by the host. */\r
-               typedef struct\r
-               {\r
-                       uint8_t  Command; /**< Single byte command to perform, one of the COMMAND_* macro values */\r
-                       uint8_t  Data[5]; /**< Command parameters */\r
-                       uint16_t DataSize; /**< Size of the command parameters */\r
-               } DFU_Command_t;\r
-\r
-       /* Enums: */\r
-               /** DFU bootloader states. Refer to the DFU class specification for information on each state. */\r
-               enum DFU_State_t\r
-               {\r
-                       appIDLE                      = 0,\r
-                       appDETACH                    = 1,\r
-                       dfuIDLE                      = 2,\r
-                       dfuDNLOAD_SYNC               = 3,\r
-                       dfuDNBUSY                    = 4,\r
-                       dfuDNLOAD_IDLE               = 5,\r
-                       dfuMANIFEST_SYNC             = 6,\r
-                       dfuMANIFEST                  = 7,\r
-                       dfuMANIFEST_WAIT_RESET       = 8,\r
-                       dfuUPLOAD_IDLE               = 9,\r
-                       dfuERROR                         = 10\r
-               };\r
-\r
-               /** DFU command status error codes. Refer to the DFU class specification for information on each error code. */\r
-               enum DFU_Status_t\r
-               {\r
-                       OK                           = 0,\r
-                       errTARGET                    = 1,\r
-                       errFILE                      = 2,\r
-                       errWRITE                     = 3,\r
-                       errERASE                     = 4,\r
-                       errCHECK_ERASED              = 5,\r
-                       errPROG                      = 6,\r
-                       errVERIFY                    = 7,\r
-                       errADDRESS                   = 8,\r
-                       errNOTDONE                   = 9,\r
-                       errFIRMWARE                  = 10,\r
-                       errVENDOR                    = 11,\r
-                       errUSBR                      = 12,\r
-                       errPOR                       = 13,\r
-                       errUNKNOWN                   = 14,\r
-                       errSTALLEDPKT                = 15\r
-               };\r
-                               \r
-       /* Function Prototypes: */\r
-               void SetupHardware(void);\r
-               void ResetHardware(void);\r
-\r
-               void EVENT_USB_Device_UnhandledControlRequest(void);\r
-\r
-               #if defined(INCLUDE_FROM_BOOTLOADER_C)\r
-                       static void DiscardFillerBytes(uint8_t NumberOfBytes);\r
-                       static void ProcessBootloaderCommand(void);\r
-                       static void LoadStartEndAddresses(void);\r
-                       static void ProcessMemProgCommand(void);\r
-                       static void ProcessMemReadCommand(void);\r
-                       static void ProcessWriteCommand(void);\r
-                       static void ProcessReadCommand(void);\r
-               #endif\r
-               \r
-#endif\r
+/*
+             LUFA Library
+     Copyright (C) Dean Camera, 2010.
+              
+  dean [at] fourwalledcubicle [dot] com
+      www.fourwalledcubicle.com
+*/
+
+/*
+  Copyright 2010  Dean Camera (dean [at] fourwalledcubicle [dot] com)
+
+  Permission to use, copy, modify, distribute, and sell this 
+  software and its documentation for any purpose is hereby granted
+  without fee, provided that the above copyright notice appear in 
+  all copies and that both that the copyright notice and this
+  permission notice and warranty disclaimer appear in supporting 
+  documentation, and that the name of the author not be used in 
+  advertising or publicity pertaining to distribution of the 
+  software without specific, written prior permission.
+
+  The author disclaim all warranties with regard to this
+  software, including all implied warranties of merchantability
+  and fitness.  In no event shall the author be liable for any
+  special, indirect or consequential damages or any damages
+  whatsoever resulting from loss of use, data or profits, whether
+  in an action of contract, negligence or other tortious action,
+  arising out of or in connection with the use or performance of
+  this software.
+*/
+
+/** \file
+ *
+ *  Header file for BootloaderDFU.c.
+ */
+
+#ifndef _BOOTLOADER_H_
+#define _BOOTLOADER_H_
+
+       /* Includes: */
+               #include <avr/io.h>
+               #include <avr/wdt.h>
+               #include <avr/boot.h>
+               #include <avr/pgmspace.h>
+               #include <avr/eeprom.h>
+               #include <avr/power.h>
+               #include <avr/interrupt.h>
+               #include <stdbool.h>
+       
+               #include "Descriptors.h"
+               
+               #include <LUFA/Drivers/USB/USB.h>
+       
+       /* Macros: */
+               /** Configuration define. Define this token to true to case the bootloader to reject all memory commands
+                *  until a memory erase has been performed. When used in conjunction with the lockbits of the AVR, this
+                *  can protect the AVR's firmware from being dumped from a secured AVR. When false, memory operations are
+                *  allowed at any time.
+                */
+               #define SECURE_MODE              false
+
+               /** Major bootloader version number. */
+               #define BOOTLOADER_VERSION_MINOR 2
+
+               /** Minor bootloader version number. */
+               #define BOOTLOADER_VERSION_REV   0
+
+               /** Complete bootloader version number expressed as a packed byte, constructed from the 
+                *  two individual bootloader version macros.
+                */
+               #define BOOTLOADER_VERSION       ((BOOTLOADER_VERSION_MINOR << 4) | BOOTLOADER_VERSION_REV)
+
+               /** First byte of the bootloader identification bytes, used to identify a device's bootloader. */
+               #define BOOTLOADER_ID_BYTE1      0xDC
+
+               /** Second byte of the bootloader identification bytes, used to identify a device's bootloader. */
+               #define BOOTLOADER_ID_BYTE2      0xFB
+               
+               /** Convenience macro, used to determine if the issued command is the given one-byte long command.
+                *
+                *  \param[in] dataarr  Command byte array to check against
+                *  \param[in] cb1      First command byte to check
+                */
+               #define IS_ONEBYTE_COMMAND(dataarr, cb1)       (dataarr[0] == (cb1))
+
+               /** Convenience macro, used to determine if the issued command is the given two-byte long command.
+                *
+                *  \param[in] dataarr  Command byte array to check against
+                *  \param[in] cb1      First command byte to check
+                *  \param[in] cb2      Second command byte to check
+                */
+               #define IS_TWOBYTE_COMMAND(dataarr, cb1, cb2) ((dataarr[0] == (cb1)) && (dataarr[1] == (cb2)))
+       
+               /** Length of the DFU file suffix block, appended to the end of each complete memory write command.
+                *  The DFU file suffix is currently unused (but is designed to give extra file information, such as
+                *  a CRC of the complete firmware for error checking) and so is discarded.
+                */
+               #define DFU_FILE_SUFFIX_SIZE     16
+
+               /** Length of the DFU file filler block, appended to the start of each complete memory write command.
+                *  Filler bytes are added to the start of each complete memory write command, and must be discarded.
+                */
+               #define DFU_FILLER_BYTES_SIZE    26
+       
+               /** DFU class command request to detach from the host. */
+               #define DFU_DETATCH              0x00
+
+               /** DFU class command request to send data from the host to the bootloader. */
+               #define DFU_DNLOAD               0x01
+
+               /** DFU class command request to send data from the bootloader to the host. */
+               #define DFU_UPLOAD               0x02
+
+               /** DFU class command request to get the current DFU status and state from the bootloader. */
+               #define DFU_GETSTATUS            0x03
+
+               /** DFU class command request to reset the current DFU status and state variables to their defaults. */
+               #define DFU_CLRSTATUS            0x04
+
+               /** DFU class command request to get the current DFU state of the bootloader. */
+               #define DFU_GETSTATE             0x05
+
+               /** DFU class command request to abort the current multi-request transfer and return to the dfuIDLE state. */
+               #define DFU_ABORT                0x06
+
+               /** DFU command to begin programming the device's memory. */
+               #define COMMAND_PROG_START       0x01
+
+               /** DFU command to begin reading the device's memory. */
+               #define COMMAND_DISP_DATA        0x03
+
+               /** DFU command to issue a write command. */
+               #define COMMAND_WRITE            0x04
+
+               /** DFU command to issue a read command. */
+               #define COMMAND_READ             0x05
+
+               /** DFU command to issue a memory base address change command, to set the current 64KB flash page
+                *  that subsequent flash operations should use. */
+               #define COMMAND_CHANGE_BASE_ADDR 0x06
+
+       /* Type Defines: */
+               /** Type define for a non-returning function pointer to the loaded application. */
+               typedef void (*AppPtr_t)(void) ATTR_NO_RETURN;
+               
+               /** Type define for a structure containing a complete DFU command issued by the host. */
+               typedef struct
+               {
+                       uint8_t  Command; /**< Single byte command to perform, one of the COMMAND_* macro values */
+                       uint8_t  Data[5]; /**< Command parameters */
+                       uint16_t DataSize; /**< Size of the command parameters */
+               } DFU_Command_t;
+
+       /* Enums: */
+               /** DFU bootloader states. Refer to the DFU class specification for information on each state. */
+               enum DFU_State_t
+               {
+                       appIDLE                      = 0,
+                       appDETACH                    = 1,
+                       dfuIDLE                      = 2,
+                       dfuDNLOAD_SYNC               = 3,
+                       dfuDNBUSY                    = 4,
+                       dfuDNLOAD_IDLE               = 5,
+                       dfuMANIFEST_SYNC             = 6,
+                       dfuMANIFEST                  = 7,
+                       dfuMANIFEST_WAIT_RESET       = 8,
+                       dfuUPLOAD_IDLE               = 9,
+                       dfuERROR                         = 10
+               };
+
+               /** DFU command status error codes. Refer to the DFU class specification for information on each error code. */
+               enum DFU_Status_t
+               {
+                       OK                           = 0,
+                       errTARGET                    = 1,
+                       errFILE                      = 2,
+                       errWRITE                     = 3,
+                       errERASE                     = 4,
+                       errCHECK_ERASED              = 5,
+                       errPROG                      = 6,
+                       errVERIFY                    = 7,
+                       errADDRESS                   = 8,
+                       errNOTDONE                   = 9,
+                       errFIRMWARE                  = 10,
+                       errVENDOR                    = 11,
+                       errUSBR                      = 12,
+                       errPOR                       = 13,
+                       errUNKNOWN                   = 14,
+                       errSTALLEDPKT                = 15
+               };
+                               
+       /* Function Prototypes: */
+               void SetupHardware(void);
+               void ResetHardware(void);
+
+               void EVENT_USB_Device_UnhandledControlRequest(void);
+
+               #if defined(INCLUDE_FROM_BOOTLOADER_C)
+                       static void DiscardFillerBytes(uint8_t NumberOfBytes);
+                       static void ProcessBootloaderCommand(void);
+                       static void LoadStartEndAddresses(void);
+                       static void ProcessMemProgCommand(void);
+                       static void ProcessMemReadCommand(void);
+                       static void ProcessWriteCommand(void);
+                       static void ProcessReadCommand(void);
+               #endif
+               
+#endif