return true;\r
}\r
\r
-/** Writes byte addressed memory to the target's memory spaces.\r
+/** Writes word addressed memory to the target's memory spaces.\r
*\r
* \param[in] WriteAddress Start address to write to within the target's address space\r
* \param[in] WriteBuffer Buffer to source data from\r
- * \param[in] WriteLength Total number of bytes to write to the device\r
+ * \param[in] WriteLength Total number of bytes to write to the device (must be an integer multiple of 2)\r
*\r
* \return Boolean true if the command sequence complete successfully\r
*/\r
/* Wait until the NVM controller is no longer busy */\r
if (!(TINYNVM_WaitWhileNVMControllerBusy()))\r
return false;\r
+ \r
+ /* Must have an integer number of words to write - if extra bytes, abort programming */\r
+ if (WriteLength & 0x01)\r
+ return false;\r
\r
/* Set the NVM control register to the WORD WRITE command for memory reading */\r
TINYNVM_SendWriteNVMRegister(XPROG_Param_NVMCMDRegAddr);\r
/* Send the address of the location to write to */\r
TINYNVM_SendPointerAddress(WriteAddress);\r
\r
- while (WriteLength--)\r
+ while (WriteLength)\r
{\r
- /* Write the byte of data to the target */\r
+ /* Wait until the NVM controller is no longer busy */\r
+ if (!(TINYNVM_WaitWhileNVMControllerBusy()))\r
+ return false;\r
+\r
+ /* Write the low byte of data to the target */\r
XPROGTarget_SendByte(TPI_CMD_SST | TPI_POINTER_INDIRECT_PI);\r
XPROGTarget_SendByte(*(WriteBuffer++));\r
+ \r
+ /* Write the high byte of data to the target */\r
+ XPROGTarget_SendByte(TPI_CMD_SST | TPI_POINTER_INDIRECT_PI);\r
+ XPROGTarget_SendByte(*(WriteBuffer++));\r
+\r
+ /* Need to decrement the write length twice, since we read out a whole word */\r
+ WriteLength -= 2;\r
}\r
\r
return true;\r