diff options
author | Dean Camera <dean@fourwalledcubicle.com> | 2009-12-15 00:58:22 +0000 |
---|---|---|
committer | Dean Camera <dean@fourwalledcubicle.com> | 2009-12-15 00:58:22 +0000 |
commit | 8ea051de637f09f0fd2895f5a18ee9f337b9b1f1 (patch) | |
tree | c9f2ea264bce8fd561572d530e0249a2288aef5e /Projects/AVRISP/Lib/NVMTarget.c | |
parent | a7880ac1cdbfe8ddaf957173bc08f334aad8bca7 (diff) | |
download | lufa-8ea051de637f09f0fd2895f5a18ee9f337b9b1f1.tar.gz lufa-8ea051de637f09f0fd2895f5a18ee9f337b9b1f1.tar.bz2 lufa-8ea051de637f09f0fd2895f5a18ee9f337b9b1f1.zip |
Add Lock/Fuse byte programming support to the AVRISP PDI programming protocol code.
Diffstat (limited to 'Projects/AVRISP/Lib/NVMTarget.c')
-rw-r--r-- | Projects/AVRISP/Lib/NVMTarget.c | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/Projects/AVRISP/Lib/NVMTarget.c b/Projects/AVRISP/Lib/NVMTarget.c index c2ed92d2e..d84ae6b85 100644 --- a/Projects/AVRISP/Lib/NVMTarget.c +++ b/Projects/AVRISP/Lib/NVMTarget.c @@ -114,6 +114,10 @@ bool NVMTarget_GetMemoryCRC(uint8_t CRCCommand, uint32_t* CRCDest) NVMTarget_SendNVMRegAddress(NVM_REG_CTRLA);
PDITarget_SendByte(1 << 0);
+ /* Wait until the NVM bus is ready again */
+ if (!(PDITarget_WaitWhileNVMBusBusy()))
+ return false;
+
/* Wait until the NVM controller is no longer busy */
if (!(NVMTarget_WaitWhileNVMControllerBusy()))
return false;
@@ -180,6 +184,37 @@ bool NVMTarget_ReadMemory(uint32_t ReadAddress, uint8_t* ReadBuffer, uint16_t Re return true;
}
+/** Writes byte addressed memory to the target's memory spaces.
+ *
+ * \param[in] WriteCommand Command to send to the device to write each memory page
+ * \param[in] WriteAddress Start address to write to within the target's address space
+ * \param[in] WriteBuffer Buffer to source data from
+ * \param[in] WriteSize Number of bytes to write
+ *
+ * \return Boolean true if the command sequence complete sucessfully
+ */
+bool NVMTarget_WriteByteMemory(uint8_t WriteCommand, uint32_t WriteAddress, uint8_t* WriteBuffer, uint16_t WriteSize)
+{
+ for (uint8_t i = 0; i < WriteSize; i++)
+ {
+ /* Wait until the NVM controller is no longer busy */
+ if (!(NVMTarget_WaitWhileNVMControllerBusy()))
+ return false;
+
+ /* Send the memory write command to the target */
+ PDITarget_SendByte(PDI_CMD_STS | (PDI_DATSIZE_4BYTES << 2));
+ NVMTarget_SendNVMRegAddress(NVM_REG_CMD);
+ PDITarget_SendByte(WriteCommand);
+
+ /* Send each new memory byte to the memory to the target */
+ PDITarget_SendByte(PDI_CMD_STS | (PDI_DATSIZE_4BYTES << 2));
+ NVMTarget_SendAddress(WriteAddress++);
+ PDITarget_SendByte(*(WriteBuffer++));
+ }
+
+ return true;
+}
+
/** Erases a specific memory space of the target.
*
* \param[in] EraseCommand NVM erase command to send to the device
|