Fix AVRISP-MKII clone project's TPI Chip Erase command processing - ensure erase...
authorDean Camera <dean@fourwalledcubicle.com>
Mon, 8 Feb 2010 03:16:09 +0000 (03:16 +0000)
committerDean Camera <dean@fourwalledcubicle.com>
Mon, 8 Feb 2010 03:16:09 +0000 (03:16 +0000)
Change If-Else chains over to switch statements in XPROGProtocol.c for clarity.

Demos/Device/ClassDriver/DualVirtualSerial/DualVirtualSerial.txt
Demos/Device/LowLevel/DualVirtualSerial/DualVirtualSerial.txt
LUFA/Drivers/USB/Class/Device/CDC.h
LUFA/Drivers/USB/Class/Host/CDC.h
LUFA/ManPages/VIDAndPIDValues.txt
Projects/AVRISP-MKII/Lib/XPROG/TINYNVM.c
Projects/AVRISP-MKII/Lib/XPROG/TINYNVM.h
Projects/AVRISP-MKII/Lib/XPROG/XPROGProtocol.c
Projects/AVRISP-MKII/Lib/XPROG/XPROGTarget.h

index 40b7c5a..b1ba267 100644 (file)
@@ -13,7 +13,6 @@
  *  - Series 7 USB AVRs\r
  *  - Series 6 USB AVRs\r
  *  - Series 4 USB AVRs\r
- *  - Series 2 USB AVRs\r
  *\r
  *  \section SSec_Info USB Information:\r
  *\r
index 40b7c5a..b1ba267 100644 (file)
@@ -13,7 +13,6 @@
  *  - Series 7 USB AVRs\r
  *  - Series 6 USB AVRs\r
  *  - Series 4 USB AVRs\r
- *  - Series 2 USB AVRs\r
  *\r
  *  \section SSec_Info USB Information:\r
  *\r
index d248868..e6a2bfd 100644 (file)
                                        struct\r
                                        {\r
                                                uint8_t HostToDevice; /**< Control line states from the host to device, as a set of CDC_CONTROL_LINE_OUT_*\r
-                                                                                          *   masks.\r
+                                                                                          *   masks. This value is updated each time \ref CDC_Device_USBTask() is called.\r
                                                                                           */\r
                                                uint8_t DeviceToHost; /**< Control line states from the device to host, as a set of CDC_CONTROL_LINE_IN_*\r
-                                                                                          *   masks.\r
+                                                                                          *   masks - to notify the host of changes to these values, call the\r
+                                                                                          *   \ref CDC_Device_SendControlLineStateChange() function.\r
                                                                                           */\r
-                                       } ControlLineStates;\r
+                                       } ControlLineStates; /**< Current states of the virtual serial port's control lines between the device and host. */\r
 \r
                                        struct\r
                                        {\r
                                                                                          *   CDCDevice_LineCodingParity_t enum\r
                                                                                          */\r
                                                uint8_t  DataBits; /**< Bits of data per character of the virtual serial port */\r
-                                       } LineEncoding;                 \r
+                                       } LineEncoding; /** Line encoding used in the virtual serial port, for the device's information. This is generally\r
+                                                        *  only used if the virtual serial port data is to be reconstructed on a physical UART.\r
+                                                        */             \r
                                } State; /**< State data for the USB class interface within the device. All elements in this section\r
                                          *   are reset to their defaults when the interface is enumerated.\r
                                          */\r
index 466f141..9433c59 100644 (file)
                                        struct\r
                                        {\r
                                                uint8_t HostToDevice; /**< Control line states from the host to device, as a set of CDC_CONTROL_LINE_OUT_*\r
-                                                                                          *   masks.\r
+                                                                                          *   masks - to notify the device of changes to these values, call the\r
+                                                                                          *   \ref CDC_Host_SendControlLineStateChange() function.\r
                                                                                           */\r
                                                uint8_t DeviceToHost; /**< Control line states from the device to host, as a set of CDC_CONTROL_LINE_IN_*\r
-                                                                                          *   masks.\r
+                                                                                          *   masks. This value is updated each time \ref CDC_Host_USBTask() is called.\r
                                                                                           */\r
-                                       } ControlLineStates;\r
+                                       } ControlLineStates; /**< Current states of the virtual serial port's control lines between the device and host. */\r
                                        \r
                                        struct\r
                                        {\r
                                                                                          *   CDCDevice_LineCodingParity_t enum\r
                                                                                          */\r
                                                uint8_t  DataBits; /**< Bits of data per character of the virtual serial port */\r
-                                       } LineEncoding;\r
+                                       } LineEncoding; /** Line encoding used in the virtual serial port, for the device's information. This is generally\r
+                                                        *  only used if the virtual serial port data is to be reconstructed on a physical UART. When set\r
+                                                        *  by the host application, the \ref CDC_Host_SetLineEncoding() function must be called to push\r
+                                                        *  the changes to the device.\r
+                                                        */\r
                                } State; /**< State data for the USB class interface within the device. All elements in this section\r
                                                  *   <b>may</b> be set to initial values, but may also be ignored to default to sane values when\r
                                                  *   the interface is enumerated.\r
index 339fd47..5c17d52 100644 (file)
  *     0x204D\r
  *    </td>\r
  *    <td>\r
- *     Keyboard and Mouse Combination Demo Application\r
+ *     Combined Keyboard and Mouse Demo Application\r
  *    </td>\r
  *   </tr>\r
  *\r
index f327a47..34ffb1e 100644 (file)
@@ -204,13 +204,13 @@ bool TINYNVM_EraseMemory(const uint8_t EraseCommand, const uint16_t Address)
        TINYNVM_SendWriteNVMRegister(XPROG_Param_NVMCMDRegAddr);\r
        XPROGTarget_SendByte(EraseCommand);\r
 \r
-       /* Write to a location within the target address space to start the erase process */\r
-       TINYNVM_SendPointerAddress(Address);\r
+       /* Write to a high byte location within the target address space to start the erase process */\r
+       TINYNVM_SendPointerAddress(Address | 0x0001);\r
        XPROGTarget_SendByte(TPI_CMD_SST | TPI_POINTER_INDIRECT);\r
        XPROGTarget_SendByte(0x00);\r
 \r
-       /* Wait until the NVM bus is ready again */\r
-       if (!(TINYNVM_WaitWhileNVMBusBusy()))\r
+       /* Wait until the NVM controller is no longer busy */\r
+       if (!(TINYNVM_WaitWhileNVMControllerBusy()))\r
          return false;\r
        \r
        return true;\r
index f8aa140..223bbcc 100644 (file)
@@ -63,6 +63,7 @@
 \r
        /* Function Prototypes: */              \r
                bool TINYNVM_WaitWhileNVMBusBusy(void);\r
+               bool TINYNVM_WaitWhileNVMControllerBusy(void);\r
                bool TINYNVM_ReadMemory(const uint16_t ReadAddress, uint8_t* ReadBuffer, uint16_t ReadLength);\r
                bool TINYNVM_WriteMemory(const uint16_t WriteAddress, uint8_t* WriteBuffer, uint16_t WriteLength);\r
                bool TINYNVM_EraseMemory(const uint8_t EraseCommand, const uint16_t Address);\r
index e7b57da..24305dc 100644 (file)
@@ -208,27 +208,38 @@ static void XPROGProtocol_Erase(void)
        Endpoint_ClearOUT();\r
        Endpoint_SetEndpointDirection(ENDPOINT_DIR_IN);\r
        \r
-       uint8_t EraseCommand = XMEGA_NVM_CMD_NOOP;\r
-       \r
        if (XPROG_SelectedProtocol == XPRG_PROTOCOL_PDI)\r
        {\r
+               uint8_t EraseCommand = XMEGA_NVM_CMD_NOOP;\r
+       \r
                /* Determine which NVM command to send to the device depending on the memory to erase */\r
-               if (Erase_XPROG_Params.MemoryType == XPRG_ERASE_CHIP)\r
-                 EraseCommand = XMEGA_NVM_CMD_CHIPERASE;\r
-               else if (Erase_XPROG_Params.MemoryType == XPRG_ERASE_APP)\r
-                 EraseCommand = XMEGA_NVM_CMD_ERASEAPPSEC;\r
-               else if (Erase_XPROG_Params.MemoryType == XPRG_ERASE_BOOT)\r
-                 EraseCommand = XMEGA_NVM_CMD_ERASEBOOTSEC;\r
-               else if (Erase_XPROG_Params.MemoryType == XPRG_ERASE_EEPROM)\r
-                 EraseCommand = XMEGA_NVM_CMD_ERASEEEPROM;\r
-               else if (Erase_XPROG_Params.MemoryType == XPRG_ERASE_APP_PAGE)\r
-                 EraseCommand = XMEGA_NVM_CMD_ERASEAPPSECPAGE;\r
-               else if (Erase_XPROG_Params.MemoryType == XPRG_ERASE_BOOT_PAGE)\r
-                 EraseCommand = XMEGA_NVM_CMD_ERASEBOOTSECPAGE;\r
-               else if (Erase_XPROG_Params.MemoryType == XPRG_ERASE_EEPROM_PAGE)\r
-                 EraseCommand = XMEGA_NVM_CMD_ERASEEEPROMPAGE;\r
-               else if (Erase_XPROG_Params.MemoryType == XPRG_ERASE_USERSIG)\r
-                 EraseCommand = XMEGA_NVM_CMD_ERASEUSERSIG;\r
+               switch (Erase_XPROG_Params.MemoryType)\r
+               {\r
+                       case XPRG_ERASE_CHIP:\r
+                               EraseCommand = XMEGA_NVM_CMD_CHIPERASE;\r
+                               break;\r
+                       case XPRG_ERASE_APP:\r
+                               EraseCommand = XMEGA_NVM_CMD_ERASEAPPSEC;\r
+                               break;\r
+                       case XPRG_ERASE_BOOT:\r
+                               EraseCommand = XMEGA_NVM_CMD_ERASEBOOTSEC;\r
+                               break;\r
+                       case XPRG_ERASE_EEPROM:\r
+                               EraseCommand = XMEGA_NVM_CMD_ERASEEEPROM;\r
+                               break;\r
+                       case XPRG_ERASE_APP_PAGE:\r
+                               EraseCommand = XMEGA_NVM_CMD_ERASEAPPSECPAGE;\r
+                               break;\r
+                       case XPRG_ERASE_BOOT_PAGE:\r
+                               EraseCommand = XMEGA_NVM_CMD_ERASEBOOTSECPAGE;\r
+                               break;\r
+                       case XPRG_ERASE_EEPROM_PAGE:\r
+                               EraseCommand = XMEGA_NVM_CMD_ERASEEEPROMPAGE;\r
+                               break;\r
+                       case XPRG_ERASE_USERSIG:\r
+                               EraseCommand = XMEGA_NVM_CMD_ERASEUSERSIG;\r
+                               break;\r
+               }\r
                \r
                /* Erase the target memory, indicate timeout if ocurred */\r
                if (!(XMEGANVM_EraseMemory(EraseCommand, Erase_XPROG_Params.Address)))\r
@@ -277,36 +288,33 @@ static void XPROGProtocol_WriteMemory(void)
                uint8_t WriteBuffCommand = XMEGA_NVM_CMD_LOADFLASHPAGEBUFF;\r
                uint8_t EraseBuffCommand = XMEGA_NVM_CMD_ERASEFLASHPAGEBUFF;\r
                bool    PagedMemory      = true;\r
-\r
-               if (WriteMemory_XPROG_Params.MemoryType == XPRG_MEM_TYPE_APPL)\r
-               {\r
-                       WriteCommand     = XMEGA_NVM_CMD_WRITEAPPSECPAGE;\r
-               }\r
-               else if (WriteMemory_XPROG_Params.MemoryType == XPRG_MEM_TYPE_BOOT)\r
-               {\r
-                       WriteCommand     = XMEGA_NVM_CMD_WRITEBOOTSECPAGE;\r
-               }\r
-               else if (WriteMemory_XPROG_Params.MemoryType == XPRG_MEM_TYPE_EEPROM)\r
-               {\r
-                       WriteCommand     = XMEGA_NVM_CMD_WRITEEEPROMPAGE;\r
-                       WriteBuffCommand = XMEGA_NVM_CMD_LOADEEPROMPAGEBUFF;\r
-                       EraseBuffCommand = XMEGA_NVM_CMD_ERASEEEPROMPAGEBUFF;\r
-               }\r
-               else if (WriteMemory_XPROG_Params.MemoryType == XPRG_MEM_TYPE_USERSIG)\r
-               {\r
-                       /* User signature is paged, but needs us to manually indicate the mode bits since the host doesn't set them */\r
-                       WriteMemory_XPROG_Params.PageMode = (XPRG_PAGEMODE_ERASE | XPRG_PAGEMODE_WRITE);\r
-                       WriteCommand     = XMEGA_NVM_CMD_WRITEUSERSIG;\r
-               }\r
-               else if (WriteMemory_XPROG_Params.MemoryType == XPRG_MEM_TYPE_FUSE)\r
-               {\r
-                       WriteCommand     = XMEGA_NVM_CMD_WRITEFUSE;\r
-                       PagedMemory      = false;\r
-               }\r
-               else if (WriteMemory_XPROG_Params.MemoryType == XPRG_MEM_TYPE_LOCKBITS)\r
+               \r
+               switch (WriteMemory_XPROG_Params.MemoryType)\r
                {\r
-                       WriteCommand     = XMEGA_NVM_CMD_WRITELOCK;\r
-                       PagedMemory      = false;\r
+                       case XPRG_MEM_TYPE_APPL:\r
+                               WriteCommand     = XMEGA_NVM_CMD_WRITEAPPSECPAGE;\r
+                               break;\r
+                       case XPRG_MEM_TYPE_BOOT:\r
+                               WriteCommand     = XMEGA_NVM_CMD_WRITEBOOTSECPAGE;\r
+                               break;\r
+                       case XPRG_MEM_TYPE_EEPROM:\r
+                               WriteCommand     = XMEGA_NVM_CMD_WRITEEEPROMPAGE;\r
+                               WriteBuffCommand = XMEGA_NVM_CMD_LOADEEPROMPAGEBUFF;\r
+                               EraseBuffCommand = XMEGA_NVM_CMD_ERASEEEPROMPAGEBUFF;                   \r
+                               break;\r
+                       case XPRG_MEM_TYPE_USERSIG:\r
+                               /* User signature is paged, but needs us to manually indicate the mode bits since the host doesn't set them */\r
+                               WriteMemory_XPROG_Params.PageMode = (XPRG_PAGEMODE_ERASE | XPRG_PAGEMODE_WRITE);\r
+                               WriteCommand     = XMEGA_NVM_CMD_WRITEUSERSIG;\r
+                               break;\r
+                       case XPRG_MEM_TYPE_FUSE:\r
+                               WriteCommand     = XMEGA_NVM_CMD_WRITEFUSE;\r
+                               PagedMemory      = false;\r
+                               break;\r
+                       case XPRG_MEM_TYPE_LOCKBITS:\r
+                               WriteCommand     = XMEGA_NVM_CMD_WRITELOCK;\r
+                               PagedMemory      = false;\r
+                               break;\r
                }\r
                \r
                /* Send the appropriate memory write commands to the device, indicate timeout if occurred */\r
@@ -394,21 +402,29 @@ static void XPROGProtocol_ReadCRC(void)
        } ReadCRC_XPROG_Params;\r
        \r
        Endpoint_Read_Stream_LE(&ReadCRC_XPROG_Params, sizeof(ReadCRC_XPROG_Params), NO_STREAM_CALLBACK);\r
+\r
        Endpoint_ClearOUT();\r
        Endpoint_SetEndpointDirection(ENDPOINT_DIR_IN);\r
        \r
-       uint8_t  CRCCommand = XMEGA_NVM_CMD_NOOP;\r
        uint32_t MemoryCRC;\r
 \r
        if (XPROG_SelectedProtocol == XPRG_PROTOCOL_PDI)\r
        {\r
+               uint8_t CRCCommand;\r
+\r
                /* Determine which NVM command to send to the device depending on the memory to CRC */\r
-               if (ReadCRC_XPROG_Params.CRCType == XPRG_CRC_APP)\r
-                 CRCCommand = XMEGA_NVM_CMD_APPCRC;\r
-               else if (ReadCRC_XPROG_Params.CRCType == XPRG_CRC_BOOT)\r
-                 CRCCommand = XMEGA_NVM_CMD_BOOTCRC;\r
-               else\r
-                 CRCCommand = XMEGA_NVM_CMD_FLASHCRC;\r
+               switch (ReadCRC_XPROG_Params.CRCType)\r
+               {\r
+                       case XPRG_CRC_APP:\r
+                               CRCCommand = XMEGA_NVM_CMD_APPCRC;\r
+                               break;\r
+                       case XPRG_CRC_BOOT:\r
+                               CRCCommand = XMEGA_NVM_CMD_BOOTCRC;\r
+                               break;\r
+                       default:\r
+                               CRCCommand = XMEGA_NVM_CMD_FLASHCRC;\r
+                               break;\r
+               }\r
                \r
                /* Perform and retrieve the memory CRC, indicate timeout if occurred */\r
                if (!(XMEGANVM_GetMemoryCRC(CRCCommand, &MemoryCRC)))\r
index 41bc14a..bc2953d 100644 (file)
                #define TPI_NVMENABLE_KEY          (uint8_t[]){0x12, 0x89, 0xAB, 0x45, 0xCD, 0xD8, 0x88, 0xFF}\r
 \r
                #define TPI_POINTER_INDIRECT       0\r
-               #define TPI_POINTER_INDIRECT_PI    (1 << 2)\r
+               #define TPI_POINTER_INDIRECT_PI    4\r
                \r
        /* Function Prototypes: */\r
                void    XPROGTarget_EnableTargetPDI(void);\r