|
|
|
@ -82,9 +82,12 @@ bool TINYNVM_WaitWhileNVMBusBusy(void)
|
|
|
|
|
/* 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;
|
|
|
|
|
{
|
|
|
|
|
TimeoutMSRemaining = COMMAND_TIMEOUT_MS;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -103,9 +106,12 @@ bool TINYNVM_WaitWhileNVMControllerBusy(void)
|
|
|
|
|
|
|
|
|
|
/* Check to see if the BUSY flag is still set */
|
|
|
|
|
if (!(XPROGTarget_ReceiveByte() & (1 << 7)))
|
|
|
|
|
return true;
|
|
|
|
|
{
|
|
|
|
|
TimeoutMSRemaining = COMMAND_TIMEOUT_MS;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -167,6 +173,10 @@ bool TINYNVM_WriteMemory(const uint16_t WriteAddress, uint8_t* WriteBuffer, uint
|
|
|
|
|
|
|
|
|
|
while (WriteLength)
|
|
|
|
|
{
|
|
|
|
|
/* Wait until the NVM controller is no longer busy */
|
|
|
|
|
if (!(TINYNVM_WaitWhileNVMControllerBusy()))
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
/* Write the low byte of data to the target */
|
|
|
|
|
XPROGTarget_SendByte(TPI_CMD_SST | TPI_POINTER_INDIRECT_PI);
|
|
|
|
|
XPROGTarget_SendByte(*(WriteBuffer++));
|
|
|
|
@ -175,10 +185,6 @@ bool TINYNVM_WriteMemory(const uint16_t WriteAddress, uint8_t* WriteBuffer, uint
|
|
|
|
|
XPROGTarget_SendByte(TPI_CMD_SST | TPI_POINTER_INDIRECT_PI);
|
|
|
|
|
XPROGTarget_SendByte(*(WriteBuffer++));
|
|
|
|
|
|
|
|
|
|
/* Wait until the NVM controller is no longer busy */
|
|
|
|
|
if (!(TINYNVM_WaitWhileNVMControllerBusy()))
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
/* Need to decrement the write length twice, since we read out a whole word */
|
|
|
|
|
WriteLength -= 2;
|
|
|
|
|
}
|
|
|
|
|