aboutsummaryrefslogtreecommitdiffstats
path: root/Projects/AVRISP-MKII/Lib/XPROG
diff options
context:
space:
mode:
authorDean Camera <dean@fourwalledcubicle.com>2010-01-25 04:13:44 +0000
committerDean Camera <dean@fourwalledcubicle.com>2010-01-25 04:13:44 +0000
commit74b6993d66d70c323beb4d7eccf5b8f45bf6d31f (patch)
tree0912f8438fb816ce6a66d37f5306e0ae9507fa49 /Projects/AVRISP-MKII/Lib/XPROG
parent857381185d60eed2ccee7dc7b88d49d90546f8a2 (diff)
downloadlufa-74b6993d66d70c323beb4d7eccf5b8f45bf6d31f.tar.gz
lufa-74b6993d66d70c323beb4d7eccf5b8f45bf6d31f.tar.bz2
lufa-74b6993d66d70c323beb4d7eccf5b8f45bf6d31f.zip
Cleanup and partially fix AVRISP-MKII project's TPI programming support.
Diffstat (limited to 'Projects/AVRISP-MKII/Lib/XPROG')
-rw-r--r--Projects/AVRISP-MKII/Lib/XPROG/TINYNVM.c32
-rw-r--r--Projects/AVRISP-MKII/Lib/XPROG/TINYNVM.h9
-rw-r--r--Projects/AVRISP-MKII/Lib/XPROG/XMEGANVM.c28
-rw-r--r--Projects/AVRISP-MKII/Lib/XPROG/XMEGANVM.h7
4 files changed, 53 insertions, 23 deletions
diff --git a/Projects/AVRISP-MKII/Lib/XPROG/TINYNVM.c b/Projects/AVRISP-MKII/Lib/XPROG/TINYNVM.c
index 93c2c6ee2..c650f0dd8 100644
--- a/Projects/AVRISP-MKII/Lib/XPROG/TINYNVM.c
+++ b/Projects/AVRISP-MKII/Lib/XPROG/TINYNVM.c
@@ -40,7 +40,7 @@
#warning TPI Protocol support is currently incomplete and is not suitable for general use.
/** Sends the given pointer address to the target's TPI pointer register */
-void TINYNVM_SendPointerAddress(const uint16_t AbsoluteAddress)
+static void TINYNVM_SendPointerAddress(const uint16_t AbsoluteAddress)
{
/* Send the given 16-bit address to the target, LSB first */
XPROGTarget_SendByte(TPI_CMD_SSTPR | 0);
@@ -49,6 +49,28 @@ void TINYNVM_SendPointerAddress(const uint16_t AbsoluteAddress)
XPROGTarget_SendByte(((uint8_t*)&AbsoluteAddress)[1]);
}
+/** Sends a SIN command to the target with the specified I/O address, ready for the data byte to be written.
+ *
+ * \param Address 6-bit I/O address to write to in the target's I/O memory space
+ */
+static void TINYNVM_SendReadNVMRegister(uint8_t Address)
+{
+ /* The TPI command for reading from the I/O space uses wierd addressing, where the I/O address's upper
+ * two bits of the 6-bit address are shifted left once */
+ XPROGTarget_SendByte(TPI_CMD_SIN | ((Address & 0x30) << 1) | (Address & 0x0F));
+}
+
+/** Sends a SOUT command to the target with the specified I/O address, ready for the data byte to be read.
+ *
+ * \param Address 6-bit I/O address to read from in the target's I/O memory space
+ */
+static void TINYNVM_SendWriteNVMRegister(uint8_t Address)
+{
+ /* The TPI command for writing to the I/O space uses wierd addressing, where the I/O address's upper
+ * two bits of the 6-bit address are shifted left once */
+ XPROGTarget_SendByte(TPI_CMD_SOUT | ((Address & 0x30) << 1) | (Address & 0x0F));
+}
+
/** Busy-waits while the NVM controller is busy performing a NVM operation, such as a FLASH page read.
*
* \return Boolean true if the NVM controller became ready within the timeout period, false otherwise
@@ -78,7 +100,7 @@ bool TINYNVM_WaitWhileNVMControllerBusy(void)
while (TimeoutMSRemaining)
{
/* Send the SIN command to read the TPI STATUS register to see the NVM bus is active */
- XPROGTarget_SendByte(TPI_CMD_SIN | XPROG_Param_NVMCSRRegAddr);
+ TINYNVM_SendReadNVMRegister(XPROG_Param_NVMCSRRegAddr);
if (XPROGTarget_ReceiveByte() & (1 << 7))
return true;
}
@@ -101,7 +123,7 @@ bool TINYNVM_ReadMemory(const uint32_t ReadAddress, uint8_t* ReadBuffer, uint16_
return false;
/* Set the NVM control register to the NO OP command for memory reading */
- XPROGTarget_SendByte(TPI_CMD_SOUT | XPROG_Param_NVMCMDRegAddr);
+ TINYNVM_SendWriteNVMRegister(XPROG_Param_NVMCMDRegAddr);
XPROGTarget_SendByte(TINY_NVM_CMD_NOOP);
/* Send the address of the location to read from */
@@ -132,7 +154,7 @@ bool TINYNVM_WriteMemory(const uint32_t WriteAddress, const uint8_t* WriteBuffer
return false;
/* Set the NVM control register to the WORD WRITE command for memory reading */
- XPROGTarget_SendByte(TPI_CMD_SOUT | XPROG_Param_NVMCMDRegAddr);
+ TINYNVM_SendWriteNVMRegister(XPROG_Param_NVMCMDRegAddr);
XPROGTarget_SendByte(TINY_NVM_CMD_WORDWRITE);
/* Send the address of the location to write to */
@@ -159,7 +181,7 @@ bool TINYNVM_EraseMemory(void)
return false;
/* Set the NVM control register to the CHIP ERASE command to erase the target */
- XPROGTarget_SendByte(TPI_CMD_SOUT | XPROG_Param_NVMCMDRegAddr);
+ TINYNVM_SendWriteNVMRegister(XPROG_Param_NVMCMDRegAddr);
XPROGTarget_SendByte(TINY_NVM_CMD_CHIPERASE);
/* Wait until the NVM bus is ready again */
diff --git a/Projects/AVRISP-MKII/Lib/XPROG/TINYNVM.h b/Projects/AVRISP-MKII/Lib/XPROG/TINYNVM.h
index ee5d38d19..e6a6749c9 100644
--- a/Projects/AVRISP-MKII/Lib/XPROG/TINYNVM.h
+++ b/Projects/AVRISP-MKII/Lib/XPROG/TINYNVM.h
@@ -61,11 +61,16 @@
#define TINY_NVM_CMD_SECTIONERASE 0x14
#define TINY_NVM_CMD_WORDWRITE 0x1D
- /* Function Prototypes: */
- void TINYNVM_SendPointerAddress(const uint16_t AbsoluteAddress);
+ /* Function Prototypes: */
bool TINYNVM_WaitWhileNVMBusBusy(void);
bool TINYNVM_ReadMemory(const uint32_t ReadAddress, uint8_t* ReadBuffer, uint16_t ReadLength);
bool TINYNVM_WriteMemory(const uint32_t WriteAddress, const uint8_t* WriteBuffer, uint16_t WriteLength);
bool TINYNVM_EraseMemory(void);
+ #if defined(INCLUDE_FROM_TINYNVM_C)
+ static void TINYNVM_SendReadNVMRegister(uint8_t Address);
+ static void TINYNVM_SendWriteNVMRegister(uint8_t Address);
+ static void TINYNVM_SendPointerAddress(const uint16_t AbsoluteAddress);
+ #endif
+
#endif
diff --git a/Projects/AVRISP-MKII/Lib/XPROG/XMEGANVM.c b/Projects/AVRISP-MKII/Lib/XPROG/XMEGANVM.c
index 573f8fde5..defd7ffe0 100644
--- a/Projects/AVRISP-MKII/Lib/XPROG/XMEGANVM.c
+++ b/Projects/AVRISP-MKII/Lib/XPROG/XMEGANVM.c
@@ -38,24 +38,11 @@
#if defined(ENABLE_XPROG_PROTOCOL) || defined(__DOXYGEN__)
-/** Sends the given NVM register address to the target.
- *
- * \param[in] Register NVM register whose absolute address is to be sent
- */
-void XMEGANVM_SendNVMRegAddress(const uint8_t Register)
-{
- /* Determine the absolute register address from the NVM base memory address and the NVM register address */
- uint32_t Address = XPROG_Param_NVMBase | Register;
-
- /* Send the calculated 32-bit address to the target, LSB first */
- XMEGANVM_SendAddress(Address);
-}
-
/** Sends the given 32-bit absolute address to the target.
*
* \param[in] AbsoluteAddress Absolute address to send to the target
*/
-void XMEGANVM_SendAddress(const uint32_t AbsoluteAddress)
+static void XMEGANVM_SendAddress(const uint32_t AbsoluteAddress)
{
/* Send the given 32-bit address to the target, LSB first */
XPROGTarget_SendByte(((uint8_t*)&AbsoluteAddress)[0]);
@@ -64,6 +51,19 @@ void XMEGANVM_SendAddress(const uint32_t AbsoluteAddress)
XPROGTarget_SendByte(((uint8_t*)&AbsoluteAddress)[3]);
}
+/** Sends the given NVM register address to the target.
+ *
+ * \param[in] Register NVM register whose absolute address is to be sent
+ */
+static void XMEGANVM_SendNVMRegAddress(const uint8_t Register)
+{
+ /* Determine the absolute register address from the NVM base memory address and the NVM register address */
+ uint32_t Address = XPROG_Param_NVMBase | Register;
+
+ /* Send the calculated 32-bit address to the target, LSB first */
+ XMEGANVM_SendAddress(Address);
+}
+
/** Busy-waits while the NVM controller is busy performing a NVM operation, such as a FLASH page read or CRC
* calculation.
*
diff --git a/Projects/AVRISP-MKII/Lib/XPROG/XMEGANVM.h b/Projects/AVRISP-MKII/Lib/XPROG/XMEGANVM.h
index cbd9e26f0..583a2878b 100644
--- a/Projects/AVRISP-MKII/Lib/XPROG/XMEGANVM.h
+++ b/Projects/AVRISP-MKII/Lib/XPROG/XMEGANVM.h
@@ -106,8 +106,6 @@
#define XMEGA_NVM_CMD_READEEPROM 0x06
/* Function Prototypes: */
- void XMEGANVM_SendNVMRegAddress(const uint8_t Register);
- void XMEGANVM_SendAddress(const uint32_t AbsoluteAddress);
bool XMEGANVM_WaitWhileNVMBusBusy(void);
bool XMEGANVM_WaitWhileNVMControllerBusy(void);
bool XMEGANVM_GetMemoryCRC(const uint8_t CRCCommand, uint32_t* const CRCDest);
@@ -118,4 +116,9 @@
const uint8_t* WriteBuffer, uint16_t WriteSize);
bool XMEGANVM_EraseMemory(const uint8_t EraseCommand, const uint32_t Address);
+ #if defined(INCLUDE_FROM_XMEGANVM_C)
+ static void XMEGANVM_SendNVMRegAddress(const uint8_t Register);
+ static void XMEGANVM_SendAddress(const uint32_t AbsoluteAddress);
+ #endif
+
#endif