aboutsummaryrefslogtreecommitdiffstats
path: root/Projects/AVRISP-MKII/Lib/XPROG
diff options
context:
space:
mode:
authorDean Camera <dean@fourwalledcubicle.com>2010-01-17 04:39:33 +0000
committerDean Camera <dean@fourwalledcubicle.com>2010-01-17 04:39:33 +0000
commitf3d370a7778dc8e374efc3b76e26f8ecefc27e84 (patch)
tree8e6b6a3842e05e78d7bb51a38975ff09286558c0 /Projects/AVRISP-MKII/Lib/XPROG
parentb0ce1eab668ac2e4779bbf8c3e6ef193d0ab0368 (diff)
downloadlufa-f3d370a7778dc8e374efc3b76e26f8ecefc27e84.tar.gz
lufa-f3d370a7778dc8e374efc3b76e26f8ecefc27e84.tar.bz2
lufa-f3d370a7778dc8e374efc3b76e26f8ecefc27e84.zip
Clean up and add more comments to the AVRISP-MKII project. Make sure the SPI_MULTI command handler supports multiple packet responses. Use slightly smaller/faster repeated indirect-load commands when retrieving the PDI target's memory CRCs.
Diffstat (limited to 'Projects/AVRISP-MKII/Lib/XPROG')
-rw-r--r--Projects/AVRISP-MKII/Lib/XPROG/XMEGANVM.c24
-rw-r--r--Projects/AVRISP-MKII/Lib/XPROG/XMEGANVM.h2
-rw-r--r--Projects/AVRISP-MKII/Lib/XPROG/XPROGProtocol.c6
-rw-r--r--Projects/AVRISP-MKII/Lib/XPROG/XPROGProtocol.h6
4 files changed, 17 insertions, 21 deletions
diff --git a/Projects/AVRISP-MKII/Lib/XPROG/XMEGANVM.c b/Projects/AVRISP-MKII/Lib/XPROG/XMEGANVM.c
index c23b9d75b..573f8fde5 100644
--- a/Projects/AVRISP-MKII/Lib/XPROG/XMEGANVM.c
+++ b/Projects/AVRISP-MKII/Lib/XPROG/XMEGANVM.c
@@ -136,24 +136,18 @@ bool XMEGANVM_GetMemoryCRC(const uint8_t CRCCommand, uint32_t* const CRCDest)
if (!(XMEGANVM_WaitWhileNVMControllerBusy()))
return false;
- uint32_t MemoryCRC = 0;
-
- /* Read the first generated CRC byte value */
- XPROGTarget_SendByte(PDI_CMD_LDS | (PDI_DATSIZE_4BYTES << 2));
+ /* Load the PDI pointer register with the DAT0 register start address */
+ XPROGTarget_SendByte(PDI_CMD_ST | (PDI_POINTER_DIRECT << 2) | PDI_DATSIZE_4BYTES);
XMEGANVM_SendNVMRegAddress(XMEGA_NVM_REG_DAT0);
- MemoryCRC = XPROGTarget_ReceiveByte();
-
- /* Read the second generated CRC byte value */
- XPROGTarget_SendByte(PDI_CMD_LDS | (PDI_DATSIZE_4BYTES << 2));
- XMEGANVM_SendNVMRegAddress(XMEGA_NVM_REG_DAT1);
- MemoryCRC |= ((uint16_t)XPROGTarget_ReceiveByte() << 8);
- /* Read the third generated CRC byte value */
- XPROGTarget_SendByte(PDI_CMD_LDS | (PDI_DATSIZE_4BYTES << 2));
- XMEGANVM_SendNVMRegAddress(XMEGA_NVM_REG_DAT2);
- MemoryCRC |= ((uint32_t)XPROGTarget_ReceiveByte() << 16);
+ /* Send the REPEAT command to grab the CRC bytes */
+ XPROGTarget_SendByte(PDI_CMD_REPEAT | PDI_DATSIZE_1BYTE);
+ XPROGTarget_SendByte(XMEGA_CRC_LENGTH - 1);
- *CRCDest = MemoryCRC;
+ /* Read in the CRC bytes from the target */
+ XPROGTarget_SendByte(PDI_CMD_LD | (PDI_POINTER_INDIRECT_PI << 2) | PDI_DATSIZE_1BYTE);
+ for (uint8_t i = 0; i < XMEGA_CRC_LENGTH; i++)
+ ((uint8_t*)CRCDest)[i] = XPROGTarget_ReceiveByte();
return true;
}
diff --git a/Projects/AVRISP-MKII/Lib/XPROG/XMEGANVM.h b/Projects/AVRISP-MKII/Lib/XPROG/XMEGANVM.h
index 63fe05cc3..cbd9e26f0 100644
--- a/Projects/AVRISP-MKII/Lib/XPROG/XMEGANVM.h
+++ b/Projects/AVRISP-MKII/Lib/XPROG/XMEGANVM.h
@@ -56,6 +56,8 @@
#endif
/* Defines: */
+ #define XMEGA_CRC_LENGTH 3
+
#define XMEGA_NVM_REG_ADDR0 0x00
#define XMEGA_NVM_REG_ADDR1 0x01
#define XMEGA_NVM_REG_ADDR2 0x02
diff --git a/Projects/AVRISP-MKII/Lib/XPROG/XPROGProtocol.c b/Projects/AVRISP-MKII/Lib/XPROG/XPROGProtocol.c
index 9c6ee7e0c..1be159c38 100644
--- a/Projects/AVRISP-MKII/Lib/XPROG/XPROGProtocol.c
+++ b/Projects/AVRISP-MKII/Lib/XPROG/XPROGProtocol.c
@@ -38,7 +38,7 @@
#if defined(ENABLE_XPROG_PROTOCOL) || defined(__DOXYGEN__)
/** Base absolute address for the target's NVM controller for PDI programming */
-uint32_t XPROG_Param_NVMBase = 0x010001C0;
+uint32_t XPROG_Param_NVMBase = 0x010001C0;
/** Size in bytes of the target's EEPROM page */
uint16_t XPROG_Param_EEPageSize;
@@ -455,10 +455,10 @@ static void XPROGProtocol_SetParam(void)
case XPRG_PARAM_EEPPAGESIZE:
XPROG_Param_EEPageSize = Endpoint_Read_Word_BE();
break;
- case XPRG_PARAM_NVMCMD:
+ case XPRG_PARAM_NVMCMD_REG:
XPROG_Param_NVMCMDRegAddr = Endpoint_Read_Byte();
break;
- case XPRG_PARAM_NVMCSR:
+ case XPRG_PARAM_NVMCSR_REG:
XPROG_Param_NVMCSRRegAddr = Endpoint_Read_Byte();
break;
default:
diff --git a/Projects/AVRISP-MKII/Lib/XPROG/XPROGProtocol.h b/Projects/AVRISP-MKII/Lib/XPROG/XPROGProtocol.h
index 2bc7d8a50..8e5d1b06d 100644
--- a/Projects/AVRISP-MKII/Lib/XPROG/XPROGProtocol.h
+++ b/Projects/AVRISP-MKII/Lib/XPROG/XPROGProtocol.h
@@ -98,12 +98,12 @@
#define XPRG_PARAM_NVMBASE 0x01
#define XPRG_PARAM_EEPPAGESIZE 0x02
- #define XPRG_PARAM_NVMCMD 0x03
- #define XPRG_PARAM_NVMCSR 0x04
+ #define XPRG_PARAM_NVMCMD_REG 0x03 /* Undocumented, Reverse-engineered */
+ #define XPRG_PARAM_NVMCSR_REG 0x04 /* Undocumented, Reverse-engineered */
#define XPRG_PROTOCOL_PDI 0x00
#define XPRG_PROTOCOL_JTAG 0x01
- #define XPRG_PROTOCOL_TPI 0x02
+ #define XPRG_PROTOCOL_TPI 0x02 /* Undocumented, Reverse-engineered */
#define XPRG_PAGEMODE_WRITE (1 << 1)
#define XPRG_PAGEMODE_ERASE (1 << 0)