X-Git-Url: http://git.linex4red.de/pub/USBasp.git/blobdiff_plain/d4ca7fb44c7d326b96cf391f0275dc323dbe24de..03ee87b35abdb8b92e8b55ec040fa943f9a6786c:/Projects/AVRISP-MKII/Lib/XPROG/XMEGANVM.c?ds=inline diff --git a/Projects/AVRISP-MKII/Lib/XPROG/XMEGANVM.c b/Projects/AVRISP-MKII/Lib/XPROG/XMEGANVM.c index 0bdafc2ac..573f8fde5 100644 --- a/Projects/AVRISP-MKII/Lib/XPROG/XMEGANVM.c +++ b/Projects/AVRISP-MKII/Lib/XPROG/XMEGANVM.c @@ -1,13 +1,13 @@ /* LUFA Library - Copyright (C) Dean Camera, 2009. + Copyright (C) Dean Camera, 2010. dean [at] fourwalledcubicle [dot] com www.fourwalledcubicle.com */ /* - Copyright 2009 Dean Camera (dean [at] fourwalledcubicle [dot] 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 @@ -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; } @@ -196,12 +190,12 @@ bool XMEGANVM_ReadMemory(const uint32_t ReadAddress, uint8_t* ReadBuffer, uint16 /** Writes byte addressed memory to the target's memory spaces. * * \param[in] WriteCommand Command to send to the device to write each memory byte - * \param[in] WriteAddress Start address to write to within the target's address space - * \param[in] WriteBuffer Buffer to source data from + * \param[in] WriteAddress Address to write to within the target's address space + * \param[in] Byte Byte to write to the target * * \return Boolean true if the command sequence complete successfully */ -bool XMEGANVM_WriteByteMemory(const uint8_t WriteCommand, const uint32_t WriteAddress, const uint8_t* WriteBuffer) +bool XMEGANVM_WriteByteMemory(const uint8_t WriteCommand, const uint32_t WriteAddress, const uint8_t Byte) { /* Wait until the NVM controller is no longer busy */ if (!(XMEGANVM_WaitWhileNVMControllerBusy())) @@ -215,7 +209,7 @@ bool XMEGANVM_WriteByteMemory(const uint8_t WriteCommand, const uint32_t WriteAd /* Send new memory byte to the memory to the target */ XPROGTarget_SendByte(PDI_CMD_STS | (PDI_DATSIZE_4BYTES << 2)); XMEGANVM_SendAddress(WriteAddress); - XPROGTarget_SendByte(*(WriteBuffer++)); + XPROGTarget_SendByte(Byte); return true; }