aboutsummaryrefslogtreecommitdiffstats
path: root/Projects/AVRISP/Lib/XPROG
diff options
context:
space:
mode:
Diffstat (limited to 'Projects/AVRISP/Lib/XPROG')
-rw-r--r--Projects/AVRISP/Lib/XPROG/TINYNVM.c14
-rw-r--r--Projects/AVRISP/Lib/XPROG/TINYNVM.h8
-rw-r--r--Projects/AVRISP/Lib/XPROG/XMEGANVM.c54
-rw-r--r--Projects/AVRISP/Lib/XPROG/XMEGANVM.h6
-rw-r--r--Projects/AVRISP/Lib/XPROG/XPROGProtocol.c3
-rw-r--r--Projects/AVRISP/Lib/XPROG/XPROGTarget.c10
-rw-r--r--Projects/AVRISP/Lib/XPROG/XPROGTarget.h2
7 files changed, 36 insertions, 61 deletions
diff --git a/Projects/AVRISP/Lib/XPROG/TINYNVM.c b/Projects/AVRISP/Lib/XPROG/TINYNVM.c
index f4b90ffa5..3ddd2eda0 100644
--- a/Projects/AVRISP/Lib/XPROG/TINYNVM.c
+++ b/Projects/AVRISP/Lib/XPROG/TINYNVM.c
@@ -37,6 +37,7 @@
#include "TINYNVM.h"
#if defined(ENABLE_XPROG_PROTOCOL) || defined(__DOXYGEN__)
+#warning TPI Protocol support is currently incomplete and is not suitable for general use.
/** Busy-waits while the NVM controller is busy performing a NVM operation, such as a FLASH page read.
*
@@ -44,24 +45,13 @@
*/
bool TINYNVM_WaitWhileNVMBusBusy(void)
{
- TCNT0 = 0;
- TIFR0 = (1 << OCF1A);
-
- uint8_t TimeoutMS = TINY_NVM_BUSY_TIMEOUT_MS;
-
/* Poll the STATUS register to check to see if NVM access has been enabled */
- while (TimeoutMS)
+ while (TimeoutMSRemaining)
{
/* Send the SLDCS command to read the TPI STATUS register to see the NVM bus is active */
XPROGTarget_SendByte(TPI_CMD_SLDCS | TPI_STATUS_REG);
if (XPROGTarget_ReceiveByte() & TPI_STATUS_NVM)
return true;
-
- if (TIFR0 & (1 << OCF1A))
- {
- TIFR0 = (1 << OCF1A);
- TimeoutMS--;
- }
}
return false;
diff --git a/Projects/AVRISP/Lib/XPROG/TINYNVM.h b/Projects/AVRISP/Lib/XPROG/TINYNVM.h
index ecf429e77..75d11293d 100644
--- a/Projects/AVRISP/Lib/XPROG/TINYNVM.h
+++ b/Projects/AVRISP/Lib/XPROG/TINYNVM.h
@@ -56,7 +56,13 @@
#endif
/* Defines: */
- #define TINY_NVM_BUSY_TIMEOUT_MS 100
+ #define TINY_NVM_REG_NVMCSR 0x32
+ #define TINY_NVM_REG_NVMCMD 0x33
+
+ #define TINY_NVM_CMD_NOOP 0x00
+ #define TINY_NVM_CMD_CHIPERASE 0x10
+ #define TINY_NVM_CMD_SECTIONERASE 0x14
+ #define TINY_NVM_CMD_WORDWRITE 0x1D
/* Function Prototypes: */
bool TINYNVM_WaitWhileNVMBusBusy(void);
diff --git a/Projects/AVRISP/Lib/XPROG/XMEGANVM.c b/Projects/AVRISP/Lib/XPROG/XMEGANVM.c
index 6280f60fb..c83ae0115 100644
--- a/Projects/AVRISP/Lib/XPROG/XMEGANVM.c
+++ b/Projects/AVRISP/Lib/XPROG/XMEGANVM.c
@@ -58,10 +58,10 @@ void XMEGANVM_SendNVMRegAddress(const uint8_t Register)
void XMEGANVM_SendAddress(const uint32_t AbsoluteAddress)
{
/* Send the given 32-bit address to the target, LSB first */
- XPROGTarget_SendByte(AbsoluteAddress & 0xFF);
- XPROGTarget_SendByte(AbsoluteAddress >> 8);
- XPROGTarget_SendByte(AbsoluteAddress >> 16);
- XPROGTarget_SendByte(AbsoluteAddress >> 24);
+ XPROGTarget_SendByte(((uint8_t*)&AbsoluteAddress)[0]);
+ XPROGTarget_SendByte(((uint8_t*)&AbsoluteAddress)[1]);
+ XPROGTarget_SendByte(((uint8_t*)&AbsoluteAddress)[2]);
+ XPROGTarget_SendByte(((uint8_t*)&AbsoluteAddress)[3]);
}
/** Busy-waits while the NVM controller is busy performing a NVM operation, such as a FLASH page read or CRC
@@ -71,24 +71,13 @@ void XMEGANVM_SendAddress(const uint32_t AbsoluteAddress)
*/
bool XMEGANVM_WaitWhileNVMBusBusy(void)
{
- TCNT0 = 0;
- TIFR0 = (1 << OCF1A);
-
- uint8_t TimeoutMS = XMEGA_NVM_BUSY_TIMEOUT_MS;
-
/* Poll the STATUS register to check to see if NVM access has been enabled */
- while (TimeoutMS)
+ while (TimeoutMSRemaining)
{
/* Send the LDCS command to read the PDI STATUS register to see the NVM bus is active */
XPROGTarget_SendByte(PDI_CMD_LDCS | PDI_STATUS_REG);
if (XPROGTarget_ReceiveByte() & PDI_STATUS_NVM)
return true;
-
- if (TIFR0 & (1 << OCF1A))
- {
- TIFR0 = (1 << OCF1A);
- TimeoutMS--;
- }
}
return false;
@@ -101,13 +90,8 @@ bool XMEGANVM_WaitWhileNVMBusBusy(void)
*/
bool XMEGANVM_WaitWhileNVMControllerBusy(void)
{
- TCNT0 = 0;
- TIFR0 = (1 << OCF1A);
-
- uint8_t TimeoutMS = XMEGA_NVM_BUSY_TIMEOUT_MS;
-
/* Poll the NVM STATUS register while the NVM controller is busy */
- while (TimeoutMS)
+ while (TimeoutMSRemaining)
{
/* Send a LDS command to read the NVM STATUS register to check the BUSY flag */
XPROGTarget_SendByte(PDI_CMD_LDS | (PDI_DATSIZE_4BYTES << 2));
@@ -116,12 +100,6 @@ bool XMEGANVM_WaitWhileNVMControllerBusy(void)
/* Check to see if the BUSY flag is still set */
if (!(XPROGTarget_ReceiveByte() & (1 << 7)))
return true;
-
- if (TIFR0 & (1 << OCF1A))
- {
- TIFR0 = (1 << OCF1A);
- TimeoutMS--;
- }
}
return false;
@@ -158,22 +136,24 @@ bool XMEGANVM_GetMemoryCRC(const uint8_t CRCCommand, uint32_t* const CRCDest)
if (!(XMEGANVM_WaitWhileNVMControllerBusy()))
return false;
- *CRCDest = 0;
+ uint32_t MemoryCRC = 0;
/* Read the first generated CRC byte value */
XPROGTarget_SendByte(PDI_CMD_LDS | (PDI_DATSIZE_4BYTES << 2));
XMEGANVM_SendNVMRegAddress(XMEGA_NVM_REG_DAT0);
- *CRCDest = XPROGTarget_ReceiveByte();
+ 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);
- *CRCDest |= ((uint16_t)XPROGTarget_ReceiveByte() << 8);
+ 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);
- *CRCDest |= ((uint32_t)XPROGTarget_ReceiveByte() << 16);
+ MemoryCRC |= ((uint32_t)XPROGTarget_ReceiveByte() << 16);
+
+ *CRCDest = MemoryCRC;
return true;
}
@@ -186,7 +166,7 @@ bool XMEGANVM_GetMemoryCRC(const uint8_t CRCCommand, uint32_t* const CRCDest)
*
* \return Boolean true if the command sequence complete successfully
*/
-bool XMEGANVM_ReadMemory(const uint32_t ReadAddress, uint8_t* ReadBuffer, const uint16_t ReadSize)
+bool XMEGANVM_ReadMemory(const uint32_t ReadAddress, uint8_t* ReadBuffer, uint16_t ReadSize)
{
/* Wait until the NVM controller is no longer busy */
if (!(XMEGANVM_WaitWhileNVMControllerBusy()))
@@ -207,7 +187,7 @@ bool XMEGANVM_ReadMemory(const uint32_t ReadAddress, uint8_t* ReadBuffer, const
/* Send a LD command with indirect access and postincrement to read out the bytes */
XPROGTarget_SendByte(PDI_CMD_LD | (PDI_POINTER_INDIRECT_PI << 2) | PDI_DATSIZE_1BYTE);
- for (uint16_t i = 0; i < ReadSize; i++)
+ while (ReadSize--)
*(ReadBuffer++) = XPROGTarget_ReceiveByte();
return true;
@@ -253,8 +233,8 @@ bool XMEGANVM_WriteByteMemory(const uint8_t WriteCommand, const uint32_t WriteAd
* \return Boolean true if the command sequence complete successfully
*/
bool XMEGANVM_WritePageMemory(const uint8_t WriteBuffCommand, const uint8_t EraseBuffCommand,
- const uint8_t WritePageCommand, const uint8_t PageMode, const uint32_t WriteAddress,
- const uint8_t* WriteBuffer, const uint16_t WriteSize)
+ const uint8_t WritePageCommand, const uint8_t PageMode, const uint32_t WriteAddress,
+ const uint8_t* WriteBuffer, uint16_t WriteSize)
{
if (PageMode & XPRG_PAGEMODE_ERASE)
{
@@ -294,7 +274,7 @@ bool XMEGANVM_WritePageMemory(const uint8_t WriteBuffCommand, const uint8_t Eras
/* Send a ST command with indirect access and postincrement to write the bytes */
XPROGTarget_SendByte(PDI_CMD_ST | (PDI_POINTER_INDIRECT_PI << 2) | PDI_DATSIZE_1BYTE);
- for (uint16_t i = 0; i < WriteSize; i++)
+ while (WriteSize--)
XPROGTarget_SendByte(*(WriteBuffer++));
}
diff --git a/Projects/AVRISP/Lib/XPROG/XMEGANVM.h b/Projects/AVRISP/Lib/XPROG/XMEGANVM.h
index 6a4de1fb1..d1a14abda 100644
--- a/Projects/AVRISP/Lib/XPROG/XMEGANVM.h
+++ b/Projects/AVRISP/Lib/XPROG/XMEGANVM.h
@@ -56,8 +56,6 @@
#endif
/* Defines: */
- #define XMEGA_NVM_BUSY_TIMEOUT_MS 100
-
#define XMEGA_NVM_REG_ADDR0 0x00
#define XMEGA_NVM_REG_ADDR1 0x01
#define XMEGA_NVM_REG_ADDR2 0x02
@@ -111,11 +109,11 @@
bool XMEGANVM_WaitWhileNVMBusBusy(void);
bool XMEGANVM_WaitWhileNVMControllerBusy(void);
bool XMEGANVM_GetMemoryCRC(const uint8_t CRCCommand, uint32_t* const CRCDest);
- bool XMEGANVM_ReadMemory(const uint32_t ReadAddress, uint8_t* ReadBuffer, const uint16_t ReadSize);
+ bool XMEGANVM_ReadMemory(const uint32_t ReadAddress, uint8_t* ReadBuffer, uint16_t ReadSize);
bool XMEGANVM_WriteByteMemory(const uint8_t WriteCommand, const uint32_t WriteAddress, const uint8_t* WriteBuffer);
bool XMEGANVM_WritePageMemory(const uint8_t WriteBuffCommand, const uint8_t EraseBuffCommand,
const uint8_t WritePageCommand, const uint8_t PageMode, const uint32_t WriteAddress,
- const uint8_t* WriteBuffer, const uint16_t WriteSize);
+ const uint8_t* WriteBuffer, uint16_t WriteSize);
bool XMEGANVM_EraseMemory(const uint8_t EraseCommand, const uint32_t Address);
#endif
diff --git a/Projects/AVRISP/Lib/XPROG/XPROGProtocol.c b/Projects/AVRISP/Lib/XPROG/XPROGProtocol.c
index edcc874d7..bccb96c2c 100644
--- a/Projects/AVRISP/Lib/XPROG/XPROGProtocol.c
+++ b/Projects/AVRISP/Lib/XPROG/XPROGProtocol.c
@@ -38,7 +38,7 @@
#if defined(ENABLE_XPROG_PROTOCOL) || defined(__DOXYGEN__)
/** Base absolute address for the target's NVM controller */
-uint32_t XPROG_Param_NVMBase = 0x010001C0;
+uint32_t XPROG_Param_NVMBase = 0x010001C0;
/** Size in bytes of the target's EEPROM page */
uint32_t XPROG_Param_EEPageSize;
@@ -46,7 +46,6 @@ uint32_t XPROG_Param_EEPageSize;
/** Currently selected XPROG programming protocol */
uint8_t XPROG_SelectedProtocol = XPRG_PROTOCOL_PDI;
-
/** Handler for the CMD_XPROG_SETMODE command, which sets the programmer-to-target protocol used for PDI/TPI
* programming.
*/
diff --git a/Projects/AVRISP/Lib/XPROG/XPROGTarget.c b/Projects/AVRISP/Lib/XPROG/XPROGTarget.c
index 708b237ef..59c85f382 100644
--- a/Projects/AVRISP/Lib/XPROG/XPROGTarget.c
+++ b/Projects/AVRISP/Lib/XPROG/XPROGTarget.c
@@ -174,7 +174,7 @@ void XPROGTarget_EnableTargetTPI(void)
BITBANG_TPIDATA_PORT |= BITBANG_TPIDATA_MASK;
/* Fire timer capture ISR every 100 cycles to manage the software USART */
- OCR1A = 80;
+ OCR1A = 100;
TCCR1B = (1 << WGM13) | (1 << WGM12) | (1 << CS10);
TIMSK1 = (1 << ICIE1);
@@ -217,7 +217,7 @@ void XPROGTarget_EnableTargetPDI(void)
asm volatile ("NOP"::);
/* Fire timer compare ISR every 100 cycles to manage the software USART */
- OCR1A = 80;
+ OCR1A = 100;
TCCR1B = (1 << WGM12) | (1 << CS10);
TIMSK1 = (1 << OCIE1A);
@@ -353,7 +353,7 @@ uint8_t XPROGTarget_ReceiveByte(void)
}
/* Wait until a byte has been received before reading */
- while (!(UCSR1A & (1 << RXC1)));
+ while (!(UCSR1A & (1 << RXC1)) && TimeoutMSRemaining);
return UDR1;
#else
/* Switch to Rx mode if currently in Tx mode */
@@ -369,8 +369,8 @@ uint8_t XPROGTarget_ReceiveByte(void)
/* Wait until a byte has been received before reading */
SoftUSART_BitCount = BITS_IN_USART_FRAME;
- while (SoftUSART_BitCount);
-
+ while (SoftUSART_BitCount && TimeoutMSRemaining);
+
/* Throw away the parity and stop bits to leave only the data (start bit is already discarded) */
return (uint8_t)SoftUSART_Data;
#endif
diff --git a/Projects/AVRISP/Lib/XPROG/XPROGTarget.h b/Projects/AVRISP/Lib/XPROG/XPROGTarget.h
index 58c1caa37..44602164e 100644
--- a/Projects/AVRISP/Lib/XPROG/XPROGTarget.h
+++ b/Projects/AVRISP/Lib/XPROG/XPROGTarget.h
@@ -42,6 +42,8 @@
#include <stdbool.h>
#include <LUFA/Common/Common.h>
+
+ #include "../V2Protocol.h"
/* Preprocessor Checks: */
#if ((BOARD == BOARD_XPLAIN) || (BOARD == BOARD_XPLAIN_REV1))