Use non-abbreviated XPROG/PDI/TPI constant names.

pull/1469/head
Dean Camera 11 years ago
parent 560e5f75fb
commit 85141b37f9

@ -97,14 +97,14 @@ bool XMEGANVM_WaitWhileNVMBusBusy(void)
bool XMEGANVM_WaitWhileNVMControllerBusy(void) bool XMEGANVM_WaitWhileNVMControllerBusy(void)
{ {
/* Preload the pointer register with the NVM STATUS register address to check the BUSY flag */ /* Preload the pointer register with the NVM STATUS register address to check the BUSY flag */
XPROGTarget_SendByte(PDI_CMD_ST(PDI_POINTER_DIRECT, PDI_DATSIZE_4BYTES)); XPROGTarget_SendByte(PDI_CMD_ST(PDI_POINTER_DIRECT, PDI_DATASIZE_4BYTES));
XMEGANVM_SendNVMRegAddress(XMEGA_NVM_REG_STATUS); XMEGANVM_SendNVMRegAddress(XMEGA_NVM_REG_STATUS);
/* Poll the NVM STATUS register while the NVM controller is busy */ /* Poll the NVM STATUS register while the NVM controller is busy */
for (;;) for (;;)
{ {
/* Fetch the current status value via the pointer register (without auto-increment afterwards) */ /* Fetch the current status value via the pointer register (without auto-increment afterwards) */
XPROGTarget_SendByte(PDI_CMD_LD(PDI_POINTER_INDIRECT, PDI_DATSIZE_1BYTE)); XPROGTarget_SendByte(PDI_CMD_LD(PDI_POINTER_INDIRECT, PDI_DATASIZE_1BYTE));
uint8_t StatusRegister = XPROGTarget_ReceiveByte(); uint8_t StatusRegister = XPROGTarget_ReceiveByte();
@ -182,12 +182,12 @@ bool XMEGANVM_GetMemoryCRC(const uint8_t CRCCommand,
return false; return false;
/* Set the NVM command to the correct CRC read command */ /* Set the NVM command to the correct CRC read command */
XPROGTarget_SendByte(PDI_CMD_STS(PDI_DATSIZE_4BYTES, PDI_DATSIZE_1BYTE)); XPROGTarget_SendByte(PDI_CMD_STS(PDI_DATASIZE_4BYTES, PDI_DATASIZE_1BYTE));
XMEGANVM_SendNVMRegAddress(XMEGA_NVM_REG_CMD); XMEGANVM_SendNVMRegAddress(XMEGA_NVM_REG_CMD);
XPROGTarget_SendByte(CRCCommand); XPROGTarget_SendByte(CRCCommand);
/* Set CMDEX bit in NVM CTRLA register to start the CRC generation */ /* Set CMDEX bit in NVM CTRLA register to start the CRC generation */
XPROGTarget_SendByte(PDI_CMD_STS(PDI_DATSIZE_4BYTES, PDI_DATSIZE_1BYTE)); XPROGTarget_SendByte(PDI_CMD_STS(PDI_DATASIZE_4BYTES, PDI_DATASIZE_1BYTE));
XMEGANVM_SendNVMRegAddress(XMEGA_NVM_REG_CTRLA); XMEGANVM_SendNVMRegAddress(XMEGA_NVM_REG_CTRLA);
XPROGTarget_SendByte(XMEGA_NVM_BIT_CTRLA_CMDEX); XPROGTarget_SendByte(XMEGA_NVM_BIT_CTRLA_CMDEX);
@ -200,15 +200,15 @@ bool XMEGANVM_GetMemoryCRC(const uint8_t CRCCommand,
return false; return false;
/* Load the PDI pointer register with the DAT0 register start address */ /* Load the PDI pointer register with the DAT0 register start address */
XPROGTarget_SendByte(PDI_CMD_ST(PDI_POINTER_DIRECT, PDI_DATSIZE_4BYTES)); XPROGTarget_SendByte(PDI_CMD_ST(PDI_POINTER_DIRECT, PDI_DATASIZE_4BYTES));
XMEGANVM_SendNVMRegAddress(XMEGA_NVM_REG_DAT0); XMEGANVM_SendNVMRegAddress(XMEGA_NVM_REG_DAT0);
/* Send the REPEAT command to grab the CRC bytes */ /* Send the REPEAT command to grab the CRC bytes */
XPROGTarget_SendByte(PDI_CMD_REPEAT(PDI_DATSIZE_1BYTE)); XPROGTarget_SendByte(PDI_CMD_REPEAT(PDI_DATASIZE_1BYTE));
XPROGTarget_SendByte(XMEGA_CRC_LENGTH_BYTES - 1); XPROGTarget_SendByte(XMEGA_CRC_LENGTH_BYTES - 1);
/* Read in the CRC bytes from the target */ /* Read in the CRC bytes from the target */
XPROGTarget_SendByte(PDI_CMD_LD(PDI_POINTER_INDIRECT_PI, PDI_DATSIZE_1BYTE)); XPROGTarget_SendByte(PDI_CMD_LD(PDI_POINTER_INDIRECT_PI, PDI_DATASIZE_1BYTE));
for (uint8_t i = 0; i < XMEGA_CRC_LENGTH_BYTES; i++) for (uint8_t i = 0; i < XMEGA_CRC_LENGTH_BYTES; i++)
((uint8_t*)CRCDest)[i] = XPROGTarget_ReceiveByte(); ((uint8_t*)CRCDest)[i] = XPROGTarget_ReceiveByte();
@ -232,29 +232,29 @@ bool XMEGANVM_ReadMemory(const uint32_t ReadAddress,
return false; return false;
/* Send the READNVM command to the NVM controller for reading of an arbitrary location */ /* Send the READNVM command to the NVM controller for reading of an arbitrary location */
XPROGTarget_SendByte(PDI_CMD_STS(PDI_DATSIZE_4BYTES, PDI_DATSIZE_1BYTE)); XPROGTarget_SendByte(PDI_CMD_STS(PDI_DATASIZE_4BYTES, PDI_DATASIZE_1BYTE));
XMEGANVM_SendNVMRegAddress(XMEGA_NVM_REG_CMD); XMEGANVM_SendNVMRegAddress(XMEGA_NVM_REG_CMD);
XPROGTarget_SendByte(XMEGA_NVM_CMD_READNVM); XPROGTarget_SendByte(XMEGA_NVM_CMD_READNVM);
if (ReadSize > 1) if (ReadSize > 1)
{ {
/* Load the PDI pointer register with the start address we want to read from */ /* Load the PDI pointer register with the start address we want to read from */
XPROGTarget_SendByte(PDI_CMD_ST(PDI_POINTER_DIRECT, PDI_DATSIZE_4BYTES)); XPROGTarget_SendByte(PDI_CMD_ST(PDI_POINTER_DIRECT, PDI_DATASIZE_4BYTES));
XMEGANVM_SendAddress(ReadAddress); XMEGANVM_SendAddress(ReadAddress);
/* Send the REPEAT command with the specified number of bytes to read */ /* Send the REPEAT command with the specified number of bytes to read */
XPROGTarget_SendByte(PDI_CMD_REPEAT(PDI_DATSIZE_1BYTE)); XPROGTarget_SendByte(PDI_CMD_REPEAT(PDI_DATASIZE_1BYTE));
XPROGTarget_SendByte(ReadSize - 1); XPROGTarget_SendByte(ReadSize - 1);
/* Send a LD command with indirect access and post-increment to read out the bytes */ /* Send a LD command with indirect access and post-increment to read out the bytes */
XPROGTarget_SendByte(PDI_CMD_LD(PDI_POINTER_INDIRECT_PI, PDI_DATSIZE_1BYTE)); XPROGTarget_SendByte(PDI_CMD_LD(PDI_POINTER_INDIRECT_PI, PDI_DATASIZE_1BYTE));
while (ReadSize-- && TimeoutTicksRemaining) while (ReadSize-- && TimeoutTicksRemaining)
*(ReadBuffer++) = XPROGTarget_ReceiveByte(); *(ReadBuffer++) = XPROGTarget_ReceiveByte();
} }
else else
{ {
/* Send a LDS command with the read address to read out the requested byte */ /* Send a LDS command with the read address to read out the requested byte */
XPROGTarget_SendByte(PDI_CMD_LDS(PDI_DATSIZE_4BYTES, PDI_DATSIZE_1BYTE)); XPROGTarget_SendByte(PDI_CMD_LDS(PDI_DATASIZE_4BYTES, PDI_DATASIZE_1BYTE));
XMEGANVM_SendAddress(ReadAddress); XMEGANVM_SendAddress(ReadAddress);
*(ReadBuffer++) = XPROGTarget_ReceiveByte(); *(ReadBuffer++) = XPROGTarget_ReceiveByte();
} }
@ -279,12 +279,12 @@ bool XMEGANVM_WriteByteMemory(const uint8_t WriteCommand,
return false; return false;
/* Send the memory write command to the target */ /* Send the memory write command to the target */
XPROGTarget_SendByte(PDI_CMD_STS(PDI_DATSIZE_4BYTES, PDI_DATSIZE_1BYTE)); XPROGTarget_SendByte(PDI_CMD_STS(PDI_DATASIZE_4BYTES, PDI_DATASIZE_1BYTE));
XMEGANVM_SendNVMRegAddress(XMEGA_NVM_REG_CMD); XMEGANVM_SendNVMRegAddress(XMEGA_NVM_REG_CMD);
XPROGTarget_SendByte(WriteCommand); XPROGTarget_SendByte(WriteCommand);
/* Send new memory byte to the memory of the target */ /* Send new memory byte to the memory of the target */
XPROGTarget_SendByte(PDI_CMD_STS(PDI_DATSIZE_4BYTES, PDI_DATSIZE_1BYTE)); XPROGTarget_SendByte(PDI_CMD_STS(PDI_DATASIZE_4BYTES, PDI_DATASIZE_1BYTE));
XMEGANVM_SendAddress(WriteAddress); XMEGANVM_SendAddress(WriteAddress);
XPROGTarget_SendByte(Byte); XPROGTarget_SendByte(Byte);
@ -311,19 +311,19 @@ bool XMEGANVM_WritePageMemory(const uint8_t WriteBuffCommand,
const uint8_t* WriteBuffer, const uint8_t* WriteBuffer,
uint16_t WriteSize) uint16_t WriteSize)
{ {
if (PageMode & XPRG_PAGEMODE_ERASE) if (PageMode & XPROG_PAGEMODE_ERASE)
{ {
/* Wait until the NVM controller is no longer busy */ /* Wait until the NVM controller is no longer busy */
if (!(XMEGANVM_WaitWhileNVMControllerBusy())) if (!(XMEGANVM_WaitWhileNVMControllerBusy()))
return false; return false;
/* Send the memory buffer erase command to the target */ /* Send the memory buffer erase command to the target */
XPROGTarget_SendByte(PDI_CMD_STS(PDI_DATSIZE_4BYTES, PDI_DATSIZE_1BYTE)); XPROGTarget_SendByte(PDI_CMD_STS(PDI_DATASIZE_4BYTES, PDI_DATASIZE_1BYTE));
XMEGANVM_SendNVMRegAddress(XMEGA_NVM_REG_CMD); XMEGANVM_SendNVMRegAddress(XMEGA_NVM_REG_CMD);
XPROGTarget_SendByte(EraseBuffCommand); XPROGTarget_SendByte(EraseBuffCommand);
/* Set CMDEX bit in NVM CTRLA register to start the buffer erase */ /* Set CMDEX bit in NVM CTRLA register to start the buffer erase */
XPROGTarget_SendByte(PDI_CMD_STS(PDI_DATSIZE_4BYTES, PDI_DATSIZE_1BYTE)); XPROGTarget_SendByte(PDI_CMD_STS(PDI_DATASIZE_4BYTES, PDI_DATASIZE_1BYTE));
XMEGANVM_SendNVMRegAddress(XMEGA_NVM_REG_CTRLA); XMEGANVM_SendNVMRegAddress(XMEGA_NVM_REG_CTRLA);
XPROGTarget_SendByte(XMEGA_NVM_BIT_CTRLA_CMDEX); XPROGTarget_SendByte(XMEGA_NVM_BIT_CTRLA_CMDEX);
} }
@ -335,37 +335,37 @@ bool XMEGANVM_WritePageMemory(const uint8_t WriteBuffCommand,
return false; return false;
/* Send the memory buffer write command to the target */ /* Send the memory buffer write command to the target */
XPROGTarget_SendByte(PDI_CMD_STS(PDI_DATSIZE_4BYTES, PDI_DATSIZE_1BYTE)); XPROGTarget_SendByte(PDI_CMD_STS(PDI_DATASIZE_4BYTES, PDI_DATASIZE_1BYTE));
XMEGANVM_SendNVMRegAddress(XMEGA_NVM_REG_CMD); XMEGANVM_SendNVMRegAddress(XMEGA_NVM_REG_CMD);
XPROGTarget_SendByte(WriteBuffCommand); XPROGTarget_SendByte(WriteBuffCommand);
/* Load the PDI pointer register with the start address we want to write to */ /* Load the PDI pointer register with the start address we want to write to */
XPROGTarget_SendByte(PDI_CMD_ST(PDI_POINTER_DIRECT, PDI_DATSIZE_4BYTES)); XPROGTarget_SendByte(PDI_CMD_ST(PDI_POINTER_DIRECT, PDI_DATASIZE_4BYTES));
XMEGANVM_SendAddress(WriteAddress); XMEGANVM_SendAddress(WriteAddress);
/* Send the REPEAT command with the specified number of bytes to write */ /* Send the REPEAT command with the specified number of bytes to write */
XPROGTarget_SendByte(PDI_CMD_REPEAT(PDI_DATSIZE_1BYTE)); XPROGTarget_SendByte(PDI_CMD_REPEAT(PDI_DATASIZE_1BYTE));
XPROGTarget_SendByte(WriteSize - 1); XPROGTarget_SendByte(WriteSize - 1);
/* Send a ST command with indirect access and post-increment to write the bytes */ /* Send a ST command with indirect access and post-increment to write the bytes */
XPROGTarget_SendByte(PDI_CMD_ST(PDI_POINTER_INDIRECT_PI, PDI_DATSIZE_1BYTE)); XPROGTarget_SendByte(PDI_CMD_ST(PDI_POINTER_INDIRECT_PI, PDI_DATASIZE_1BYTE));
while (WriteSize--) while (WriteSize--)
XPROGTarget_SendByte(*(WriteBuffer++)); XPROGTarget_SendByte(*(WriteBuffer++));
} }
if (PageMode & XPRG_PAGEMODE_WRITE) if (PageMode & XPROG_PAGEMODE_WRITE)
{ {
/* Wait until the NVM controller is no longer busy */ /* Wait until the NVM controller is no longer busy */
if (!(XMEGANVM_WaitWhileNVMControllerBusy())) if (!(XMEGANVM_WaitWhileNVMControllerBusy()))
return false; return false;
/* Send the memory write command to the target */ /* Send the memory write command to the target */
XPROGTarget_SendByte(PDI_CMD_STS(PDI_DATSIZE_4BYTES, PDI_DATSIZE_1BYTE)); XPROGTarget_SendByte(PDI_CMD_STS(PDI_DATASIZE_4BYTES, PDI_DATASIZE_1BYTE));
XMEGANVM_SendNVMRegAddress(XMEGA_NVM_REG_CMD); XMEGANVM_SendNVMRegAddress(XMEGA_NVM_REG_CMD);
XPROGTarget_SendByte(WritePageCommand); XPROGTarget_SendByte(WritePageCommand);
/* Send the address of the first page location to write the memory page */ /* Send the address of the first page location to write the memory page */
XPROGTarget_SendByte(PDI_CMD_STS(PDI_DATSIZE_4BYTES, PDI_DATSIZE_1BYTE)); XPROGTarget_SendByte(PDI_CMD_STS(PDI_DATASIZE_4BYTES, PDI_DATASIZE_1BYTE));
XMEGANVM_SendAddress(WriteAddress); XMEGANVM_SendAddress(WriteAddress);
XPROGTarget_SendByte(0x00); XPROGTarget_SendByte(0x00);
} }
@ -391,24 +391,24 @@ bool XMEGANVM_EraseMemory(const uint8_t EraseCommand,
if (EraseCommand == XMEGA_NVM_CMD_CHIPERASE) if (EraseCommand == XMEGA_NVM_CMD_CHIPERASE)
{ {
/* Send the memory erase command to the target */ /* Send the memory erase command to the target */
XPROGTarget_SendByte(PDI_CMD_STS(PDI_DATSIZE_4BYTES, PDI_DATSIZE_1BYTE)); XPROGTarget_SendByte(PDI_CMD_STS(PDI_DATASIZE_4BYTES, PDI_DATASIZE_1BYTE));
XMEGANVM_SendNVMRegAddress(XMEGA_NVM_REG_CMD); XMEGANVM_SendNVMRegAddress(XMEGA_NVM_REG_CMD);
XPROGTarget_SendByte(EraseCommand); XPROGTarget_SendByte(EraseCommand);
/* Set CMDEX bit in NVM CTRLA register to start the erase sequence */ /* Set CMDEX bit in NVM CTRLA register to start the erase sequence */
XPROGTarget_SendByte(PDI_CMD_STS(PDI_DATSIZE_4BYTES, PDI_DATSIZE_1BYTE)); XPROGTarget_SendByte(PDI_CMD_STS(PDI_DATASIZE_4BYTES, PDI_DATASIZE_1BYTE));
XMEGANVM_SendNVMRegAddress(XMEGA_NVM_REG_CTRLA); XMEGANVM_SendNVMRegAddress(XMEGA_NVM_REG_CTRLA);
XPROGTarget_SendByte(XMEGA_NVM_BIT_CTRLA_CMDEX); XPROGTarget_SendByte(XMEGA_NVM_BIT_CTRLA_CMDEX);
} }
else if (EraseCommand == XMEGA_NVM_CMD_ERASEEEPROM) else if (EraseCommand == XMEGA_NVM_CMD_ERASEEEPROM)
{ {
/* Send the EEPROM page buffer erase command to the target */ /* Send the EEPROM page buffer erase command to the target */
XPROGTarget_SendByte(PDI_CMD_STS(PDI_DATSIZE_4BYTES, PDI_DATSIZE_1BYTE)); XPROGTarget_SendByte(PDI_CMD_STS(PDI_DATASIZE_4BYTES, PDI_DATASIZE_1BYTE));
XMEGANVM_SendNVMRegAddress(XMEGA_NVM_REG_CMD); XMEGANVM_SendNVMRegAddress(XMEGA_NVM_REG_CMD);
XPROGTarget_SendByte(XMEGA_NVM_CMD_ERASEEEPROMPAGEBUFF); XPROGTarget_SendByte(XMEGA_NVM_CMD_ERASEEEPROMPAGEBUFF);
/* Set CMDEX bit in NVM CTRLA register to start the buffer erase */ /* Set CMDEX bit in NVM CTRLA register to start the buffer erase */
XPROGTarget_SendByte(PDI_CMD_STS(PDI_DATSIZE_4BYTES, PDI_DATSIZE_1BYTE)); XPROGTarget_SendByte(PDI_CMD_STS(PDI_DATASIZE_4BYTES, PDI_DATASIZE_1BYTE));
XMEGANVM_SendNVMRegAddress(XMEGA_NVM_REG_CTRLA); XMEGANVM_SendNVMRegAddress(XMEGA_NVM_REG_CTRLA);
XPROGTarget_SendByte(XMEGA_NVM_BIT_CTRLA_CMDEX); XPROGTarget_SendByte(XMEGA_NVM_BIT_CTRLA_CMDEX);
@ -417,42 +417,42 @@ bool XMEGANVM_EraseMemory(const uint8_t EraseCommand,
return false; return false;
/* Send the EEPROM memory buffer write command to the target */ /* Send the EEPROM memory buffer write command to the target */
XPROGTarget_SendByte(PDI_CMD_STS(PDI_DATSIZE_4BYTES, PDI_DATSIZE_1BYTE)); XPROGTarget_SendByte(PDI_CMD_STS(PDI_DATASIZE_4BYTES, PDI_DATASIZE_1BYTE));
XMEGANVM_SendNVMRegAddress(XMEGA_NVM_REG_CMD); XMEGANVM_SendNVMRegAddress(XMEGA_NVM_REG_CMD);
XPROGTarget_SendByte(XMEGA_NVM_CMD_LOADEEPROMPAGEBUFF); XPROGTarget_SendByte(XMEGA_NVM_CMD_LOADEEPROMPAGEBUFF);
/* Load the PDI pointer register with the EEPROM page start address */ /* Load the PDI pointer register with the EEPROM page start address */
XPROGTarget_SendByte(PDI_CMD_ST(PDI_POINTER_DIRECT, PDI_DATSIZE_4BYTES)); XPROGTarget_SendByte(PDI_CMD_ST(PDI_POINTER_DIRECT, PDI_DATASIZE_4BYTES));
XMEGANVM_SendAddress(Address); XMEGANVM_SendAddress(Address);
/* Send the REPEAT command with the specified number of bytes to write */ /* Send the REPEAT command with the specified number of bytes to write */
XPROGTarget_SendByte(PDI_CMD_REPEAT(PDI_DATSIZE_1BYTE)); XPROGTarget_SendByte(PDI_CMD_REPEAT(PDI_DATASIZE_1BYTE));
XPROGTarget_SendByte(XPROG_Param_EEPageSize - 1); XPROGTarget_SendByte(XPROG_Param_EEPageSize - 1);
/* Send a ST command with indirect access and post-increment to tag each byte in the EEPROM page buffer */ /* Send a ST command with indirect access and post-increment to tag each byte in the EEPROM page buffer */
XPROGTarget_SendByte(PDI_CMD_ST(PDI_POINTER_INDIRECT_PI, PDI_DATSIZE_1BYTE)); XPROGTarget_SendByte(PDI_CMD_ST(PDI_POINTER_INDIRECT_PI, PDI_DATASIZE_1BYTE));
for (uint8_t PageByte = 0; PageByte < XPROG_Param_EEPageSize; PageByte++) for (uint8_t PageByte = 0; PageByte < XPROG_Param_EEPageSize; PageByte++)
XPROGTarget_SendByte(0x00); XPROGTarget_SendByte(0x00);
/* Send the memory erase command to the target */ /* Send the memory erase command to the target */
XPROGTarget_SendByte(PDI_CMD_STS(PDI_DATSIZE_4BYTES, PDI_DATSIZE_1BYTE)); XPROGTarget_SendByte(PDI_CMD_STS(PDI_DATASIZE_4BYTES, PDI_DATASIZE_1BYTE));
XMEGANVM_SendNVMRegAddress(XMEGA_NVM_REG_CMD); XMEGANVM_SendNVMRegAddress(XMEGA_NVM_REG_CMD);
XPROGTarget_SendByte(EraseCommand); XPROGTarget_SendByte(EraseCommand);
/* Set CMDEX bit in NVM CTRLA register to start the EEPROM erase sequence */ /* Set CMDEX bit in NVM CTRLA register to start the EEPROM erase sequence */
XPROGTarget_SendByte(PDI_CMD_STS(PDI_DATSIZE_4BYTES, PDI_DATSIZE_1BYTE)); XPROGTarget_SendByte(PDI_CMD_STS(PDI_DATASIZE_4BYTES, PDI_DATASIZE_1BYTE));
XMEGANVM_SendNVMRegAddress(XMEGA_NVM_REG_CTRLA); XMEGANVM_SendNVMRegAddress(XMEGA_NVM_REG_CTRLA);
XPROGTarget_SendByte(XMEGA_NVM_BIT_CTRLA_CMDEX); XPROGTarget_SendByte(XMEGA_NVM_BIT_CTRLA_CMDEX);
} }
else else
{ {
/* Send the memory erase command to the target */ /* Send the memory erase command to the target */
XPROGTarget_SendByte(PDI_CMD_STS(PDI_DATSIZE_4BYTES, PDI_DATSIZE_1BYTE)); XPROGTarget_SendByte(PDI_CMD_STS(PDI_DATASIZE_4BYTES, PDI_DATASIZE_1BYTE));
XMEGANVM_SendNVMRegAddress(XMEGA_NVM_REG_CMD); XMEGANVM_SendNVMRegAddress(XMEGA_NVM_REG_CMD);
XPROGTarget_SendByte(EraseCommand); XPROGTarget_SendByte(EraseCommand);
/* Other erase modes just need us to address a byte within the target memory space */ /* Other erase modes just need us to address a byte within the target memory space */
XPROGTarget_SendByte(PDI_CMD_STS(PDI_DATSIZE_4BYTES, PDI_DATSIZE_1BYTE)); XPROGTarget_SendByte(PDI_CMD_STS(PDI_DATASIZE_4BYTES, PDI_DATASIZE_1BYTE));
XMEGANVM_SendAddress(Address); XMEGANVM_SendAddress(Address);
XPROGTarget_SendByte(0x00); XPROGTarget_SendByte(0x00);
} }

@ -116,7 +116,8 @@
bool XMEGANVM_GetMemoryCRC(const uint8_t CRCCommand, bool XMEGANVM_GetMemoryCRC(const uint8_t CRCCommand,
uint32_t* const CRCDest); uint32_t* const CRCDest);
bool XMEGANVM_ReadMemory(const uint32_t ReadAddress, bool XMEGANVM_ReadMemory(const uint32_t ReadAddress,
uint8_t* ReadBuffer, uint16_t ReadSize); uint8_t* ReadBuffer,
uint16_t ReadSize);
bool XMEGANVM_WriteByteMemory(const uint8_t WriteCommand, bool XMEGANVM_WriteByteMemory(const uint8_t WriteCommand,
const uint32_t WriteAddress, const uint32_t WriteAddress,
const uint8_t Byte); const uint8_t Byte);

@ -50,7 +50,7 @@ uint8_t XPROG_Param_NVMCMDRegAddr = 0x33;
uint8_t XPROG_Param_NVMCSRRegAddr = 0x32; uint8_t XPROG_Param_NVMCSRRegAddr = 0x32;
/** Currently selected XPROG programming protocol */ /** Currently selected XPROG programming protocol */
uint8_t XPROG_SelectedProtocol = XPRG_PROTOCOL_PDI; uint8_t XPROG_SelectedProtocol = XPROG_PROTOCOL_PDI;
/** Handler for the CMD_XPROG_SETMODE command, which sets the programmer-to-target protocol used for PDI/TPI /** Handler for the CMD_XPROG_SETMODE command, which sets the programmer-to-target protocol used for PDI/TPI
* programming. * programming.
@ -71,7 +71,7 @@ void XPROGProtocol_SetMode(void)
XPROG_SelectedProtocol = SetMode_XPROG_Params.Protocol; XPROG_SelectedProtocol = SetMode_XPROG_Params.Protocol;
Endpoint_Write_8(CMD_XPROG_SETMODE); Endpoint_Write_8(CMD_XPROG_SETMODE);
Endpoint_Write_8((SetMode_XPROG_Params.Protocol != XPRG_PROTOCOL_JTAG) ? STATUS_CMD_OK : STATUS_CMD_FAILED); Endpoint_Write_8((SetMode_XPROG_Params.Protocol != XPROG_PROTOCOL_JTAG) ? STATUS_CMD_OK : STATUS_CMD_FAILED);
Endpoint_ClearIN(); Endpoint_ClearIN();
} }
@ -84,25 +84,25 @@ void XPROGProtocol_Command(void)
switch (XPROGCommand) switch (XPROGCommand)
{ {
case XPRG_CMD_ENTER_PROGMODE: case XPROG_CMD_ENTER_PROGMODE:
XPROGProtocol_EnterXPROGMode(); XPROGProtocol_EnterXPROGMode();
break; break;
case XPRG_CMD_LEAVE_PROGMODE: case XPROG_CMD_LEAVE_PROGMODE:
XPROGProtocol_LeaveXPROGMode(); XPROGProtocol_LeaveXPROGMode();
break; break;
case XPRG_CMD_ERASE: case XPROG_CMD_ERASE:
XPROGProtocol_Erase(); XPROGProtocol_Erase();
break; break;
case XPRG_CMD_WRITE_MEM: case XPROG_CMD_WRITE_MEM:
XPROGProtocol_WriteMemory(); XPROGProtocol_WriteMemory();
break; break;
case XPRG_CMD_READ_MEM: case XPROG_CMD_READ_MEM:
XPROGProtocol_ReadMemory(); XPROGProtocol_ReadMemory();
break; break;
case XPRG_CMD_CRC: case XPROG_CMD_CRC:
XPROGProtocol_ReadCRC(); XPROGProtocol_ReadCRC();
break; break;
case XPRG_CMD_SET_PARAM: case XPROG_CMD_SET_PARAM:
XPROGProtocol_SetParam(); XPROGProtocol_SetParam();
break; break;
} }
@ -117,14 +117,14 @@ static void XPROGProtocol_EnterXPROGMode(void)
bool NVMBusEnabled = false; bool NVMBusEnabled = false;
if (XPROG_SelectedProtocol == XPRG_PROTOCOL_PDI) if (XPROG_SelectedProtocol == XPROG_PROTOCOL_PDI)
NVMBusEnabled = XMEGANVM_EnablePDI(); NVMBusEnabled = XMEGANVM_EnablePDI();
else if (XPROG_SelectedProtocol == XPRG_PROTOCOL_TPI) else if (XPROG_SelectedProtocol == XPROG_PROTOCOL_TPI)
NVMBusEnabled = TINYNVM_EnableTPI(); NVMBusEnabled = TINYNVM_EnableTPI();
Endpoint_Write_8(CMD_XPROG); Endpoint_Write_8(CMD_XPROG);
Endpoint_Write_8(XPRG_CMD_ENTER_PROGMODE); Endpoint_Write_8(XPROG_CMD_ENTER_PROGMODE);
Endpoint_Write_8(NVMBusEnabled ? XPRG_ERR_OK : XPRG_ERR_FAILED); Endpoint_Write_8(NVMBusEnabled ? XPROG_ERR_OK : XPROG_ERR_FAILED);
Endpoint_ClearIN(); Endpoint_ClearIN();
} }
@ -137,7 +137,7 @@ static void XPROGProtocol_LeaveXPROGMode(void)
Endpoint_SelectEndpoint(AVRISP_DATA_IN_EPADDR); Endpoint_SelectEndpoint(AVRISP_DATA_IN_EPADDR);
Endpoint_SetEndpointDirection(ENDPOINT_DIR_IN); Endpoint_SetEndpointDirection(ENDPOINT_DIR_IN);
if (XPROG_SelectedProtocol == XPRG_PROTOCOL_PDI) if (XPROG_SelectedProtocol == XPROG_PROTOCOL_PDI)
XMEGANVM_DisablePDI(); XMEGANVM_DisablePDI();
else else
TINYNVM_DisableTPI(); TINYNVM_DisableTPI();
@ -149,15 +149,15 @@ static void XPROGProtocol_LeaveXPROGMode(void)
#endif #endif
Endpoint_Write_8(CMD_XPROG); Endpoint_Write_8(CMD_XPROG);
Endpoint_Write_8(XPRG_CMD_LEAVE_PROGMODE); Endpoint_Write_8(XPROG_CMD_LEAVE_PROGMODE);
Endpoint_Write_8(XPRG_ERR_OK); Endpoint_Write_8(XPROG_ERR_OK);
Endpoint_ClearIN(); Endpoint_ClearIN();
} }
/** Handler for the XPRG ERASE command to erase a specific memory address space in the attached device. */ /** Handler for the XPRG ERASE command to erase a specific memory address space in the attached device. */
static void XPROGProtocol_Erase(void) static void XPROGProtocol_Erase(void)
{ {
uint8_t ReturnStatus = XPRG_ERR_OK; uint8_t ReturnStatus = XPROG_ERR_OK;
struct struct
{ {
@ -174,33 +174,33 @@ static void XPROGProtocol_Erase(void)
uint8_t EraseCommand; uint8_t EraseCommand;
if (XPROG_SelectedProtocol == XPRG_PROTOCOL_PDI) if (XPROG_SelectedProtocol == XPROG_PROTOCOL_PDI)
{ {
/* Determine which NVM command to send to the device depending on the memory to erase */ /* Determine which NVM command to send to the device depending on the memory to erase */
switch (Erase_XPROG_Params.MemoryType) switch (Erase_XPROG_Params.MemoryType)
{ {
case XPRG_ERASE_CHIP: case XPROG_ERASE_CHIP:
EraseCommand = XMEGA_NVM_CMD_CHIPERASE; EraseCommand = XMEGA_NVM_CMD_CHIPERASE;
break; break;
case XPRG_ERASE_APP: case XPROG_ERASE_APP:
EraseCommand = XMEGA_NVM_CMD_ERASEAPPSEC; EraseCommand = XMEGA_NVM_CMD_ERASEAPPSEC;
break; break;
case XPRG_ERASE_BOOT: case XPROG_ERASE_BOOT:
EraseCommand = XMEGA_NVM_CMD_ERASEBOOTSEC; EraseCommand = XMEGA_NVM_CMD_ERASEBOOTSEC;
break; break;
case XPRG_ERASE_EEPROM: case XPROG_ERASE_EEPROM:
EraseCommand = XMEGA_NVM_CMD_ERASEEEPROM; EraseCommand = XMEGA_NVM_CMD_ERASEEEPROM;
break; break;
case XPRG_ERASE_APP_PAGE: case XPROG_ERASE_APP_PAGE:
EraseCommand = XMEGA_NVM_CMD_ERASEAPPSECPAGE; EraseCommand = XMEGA_NVM_CMD_ERASEAPPSECPAGE;
break; break;
case XPRG_ERASE_BOOT_PAGE: case XPROG_ERASE_BOOT_PAGE:
EraseCommand = XMEGA_NVM_CMD_ERASEBOOTSECPAGE; EraseCommand = XMEGA_NVM_CMD_ERASEBOOTSECPAGE;
break; break;
case XPRG_ERASE_EEPROM_PAGE: case XPROG_ERASE_EEPROM_PAGE:
EraseCommand = XMEGA_NVM_CMD_ERASEEEPROMPAGE; EraseCommand = XMEGA_NVM_CMD_ERASEEEPROMPAGE;
break; break;
case XPRG_ERASE_USERSIG: case XPROG_ERASE_USERSIG:
EraseCommand = XMEGA_NVM_CMD_ERASEUSERSIG; EraseCommand = XMEGA_NVM_CMD_ERASEUSERSIG;
break; break;
default: default:
@ -210,22 +210,22 @@ static void XPROGProtocol_Erase(void)
/* Erase the target memory, indicate timeout if occurred */ /* Erase the target memory, indicate timeout if occurred */
if (!(XMEGANVM_EraseMemory(EraseCommand, Erase_XPROG_Params.Address))) if (!(XMEGANVM_EraseMemory(EraseCommand, Erase_XPROG_Params.Address)))
ReturnStatus = XPRG_ERR_TIMEOUT; ReturnStatus = XPROG_ERR_TIMEOUT;
} }
else else
{ {
if (Erase_XPROG_Params.MemoryType == XPRG_ERASE_CHIP) if (Erase_XPROG_Params.MemoryType == XPROG_ERASE_CHIP)
EraseCommand = TINY_NVM_CMD_CHIPERASE; EraseCommand = TINY_NVM_CMD_CHIPERASE;
else else
EraseCommand = TINY_NVM_CMD_SECTIONERASE; EraseCommand = TINY_NVM_CMD_SECTIONERASE;
/* Erase the target memory, indicate timeout if occurred */ /* Erase the target memory, indicate timeout if occurred */
if (!(TINYNVM_EraseMemory(EraseCommand, Erase_XPROG_Params.Address))) if (!(TINYNVM_EraseMemory(EraseCommand, Erase_XPROG_Params.Address)))
ReturnStatus = XPRG_ERR_TIMEOUT; ReturnStatus = XPROG_ERR_TIMEOUT;
} }
Endpoint_Write_8(CMD_XPROG); Endpoint_Write_8(CMD_XPROG);
Endpoint_Write_8(XPRG_CMD_ERASE); Endpoint_Write_8(XPROG_CMD_ERASE);
Endpoint_Write_8(ReturnStatus); Endpoint_Write_8(ReturnStatus);
Endpoint_ClearIN(); Endpoint_ClearIN();
} }
@ -233,7 +233,7 @@ static void XPROGProtocol_Erase(void)
/** Handler for the XPROG WRITE_MEMORY command to write to a specific memory space within the attached device. */ /** Handler for the XPROG WRITE_MEMORY command to write to a specific memory space within the attached device. */
static void XPROGProtocol_WriteMemory(void) static void XPROGProtocol_WriteMemory(void)
{ {
uint8_t ReturnStatus = XPRG_ERR_OK; uint8_t ReturnStatus = XPROG_ERR_OK;
struct struct
{ {
@ -263,7 +263,7 @@ static void XPROGProtocol_WriteMemory(void)
Endpoint_SelectEndpoint(AVRISP_DATA_IN_EPADDR); Endpoint_SelectEndpoint(AVRISP_DATA_IN_EPADDR);
Endpoint_SetEndpointDirection(ENDPOINT_DIR_IN); Endpoint_SetEndpointDirection(ENDPOINT_DIR_IN);
if (XPROG_SelectedProtocol == XPRG_PROTOCOL_PDI) if (XPROG_SelectedProtocol == XPROG_PROTOCOL_PDI)
{ {
/* Assume FLASH page programming by default, as it is the common case */ /* Assume FLASH page programming by default, as it is the common case */
uint8_t WriteCommand = XMEGA_NVM_CMD_WRITEFLASHPAGE; uint8_t WriteCommand = XMEGA_NVM_CMD_WRITEFLASHPAGE;
@ -273,25 +273,25 @@ static void XPROGProtocol_WriteMemory(void)
switch (WriteMemory_XPROG_Params.MemoryType) switch (WriteMemory_XPROG_Params.MemoryType)
{ {
case XPRG_MEM_TYPE_APPL: case XPROG_MEM_TYPE_APPL:
WriteCommand = XMEGA_NVM_CMD_WRITEAPPSECPAGE; WriteCommand = XMEGA_NVM_CMD_WRITEAPPSECPAGE;
break; break;
case XPRG_MEM_TYPE_BOOT: case XPROG_MEM_TYPE_BOOT:
WriteCommand = XMEGA_NVM_CMD_WRITEBOOTSECPAGE; WriteCommand = XMEGA_NVM_CMD_WRITEBOOTSECPAGE;
break; break;
case XPRG_MEM_TYPE_EEPROM: case XPROG_MEM_TYPE_EEPROM:
WriteCommand = XMEGA_NVM_CMD_ERASEWRITEEEPROMPAGE; WriteCommand = XMEGA_NVM_CMD_ERASEWRITEEEPROMPAGE;
WriteBuffCommand = XMEGA_NVM_CMD_LOADEEPROMPAGEBUFF; WriteBuffCommand = XMEGA_NVM_CMD_LOADEEPROMPAGEBUFF;
EraseBuffCommand = XMEGA_NVM_CMD_ERASEEEPROMPAGEBUFF; EraseBuffCommand = XMEGA_NVM_CMD_ERASEEEPROMPAGEBUFF;
break; break;
case XPRG_MEM_TYPE_USERSIG: case XPROG_MEM_TYPE_USERSIG:
WriteCommand = XMEGA_NVM_CMD_WRITEUSERSIG; WriteCommand = XMEGA_NVM_CMD_WRITEUSERSIG;
break; break;
case XPRG_MEM_TYPE_FUSE: case XPROG_MEM_TYPE_FUSE:
WriteCommand = XMEGA_NVM_CMD_WRITEFUSE; WriteCommand = XMEGA_NVM_CMD_WRITEFUSE;
PagedMemory = false; PagedMemory = false;
break; break;
case XPRG_MEM_TYPE_LOCKBITS: case XPROG_MEM_TYPE_LOCKBITS:
WriteCommand = XMEGA_NVM_CMD_WRITELOCK; WriteCommand = XMEGA_NVM_CMD_WRITELOCK;
PagedMemory = false; PagedMemory = false;
break; break;
@ -304,7 +304,7 @@ static void XPROGProtocol_WriteMemory(void)
(!PagedMemory && !(XMEGANVM_WriteByteMemory(WriteCommand, WriteMemory_XPROG_Params.Address, (!PagedMemory && !(XMEGANVM_WriteByteMemory(WriteCommand, WriteMemory_XPROG_Params.Address,
WriteMemory_XPROG_Params.ProgData[0])))) WriteMemory_XPROG_Params.ProgData[0]))))
{ {
ReturnStatus = XPRG_ERR_TIMEOUT; ReturnStatus = XPROG_ERR_TIMEOUT;
} }
} }
else else
@ -313,12 +313,12 @@ static void XPROGProtocol_WriteMemory(void)
if (!(TINYNVM_WriteMemory(WriteMemory_XPROG_Params.Address, WriteMemory_XPROG_Params.ProgData, if (!(TINYNVM_WriteMemory(WriteMemory_XPROG_Params.Address, WriteMemory_XPROG_Params.ProgData,
WriteMemory_XPROG_Params.Length))) WriteMemory_XPROG_Params.Length)))
{ {
ReturnStatus = XPRG_ERR_TIMEOUT; ReturnStatus = XPROG_ERR_TIMEOUT;
} }
} }
Endpoint_Write_8(CMD_XPROG); Endpoint_Write_8(CMD_XPROG);
Endpoint_Write_8(XPRG_CMD_WRITE_MEM); Endpoint_Write_8(XPROG_CMD_WRITE_MEM);
Endpoint_Write_8(ReturnStatus); Endpoint_Write_8(ReturnStatus);
Endpoint_ClearIN(); Endpoint_ClearIN();
} }
@ -328,7 +328,7 @@ static void XPROGProtocol_WriteMemory(void)
*/ */
static void XPROGProtocol_ReadMemory(void) static void XPROGProtocol_ReadMemory(void)
{ {
uint8_t ReturnStatus = XPRG_ERR_OK; uint8_t ReturnStatus = XPROG_ERR_OK;
struct struct
{ {
@ -347,24 +347,24 @@ static void XPROGProtocol_ReadMemory(void)
uint8_t ReadBuffer[256]; uint8_t ReadBuffer[256];
if (XPROG_SelectedProtocol == XPRG_PROTOCOL_PDI) if (XPROG_SelectedProtocol == XPROG_PROTOCOL_PDI)
{ {
/* Read the PDI target's memory, indicate timeout if occurred */ /* Read the PDI target's memory, indicate timeout if occurred */
if (!(XMEGANVM_ReadMemory(ReadMemory_XPROG_Params.Address, ReadBuffer, ReadMemory_XPROG_Params.Length))) if (!(XMEGANVM_ReadMemory(ReadMemory_XPROG_Params.Address, ReadBuffer, ReadMemory_XPROG_Params.Length)))
ReturnStatus = XPRG_ERR_TIMEOUT; ReturnStatus = XPROG_ERR_TIMEOUT;
} }
else else
{ {
/* Read the TPI target's memory, indicate timeout if occurred */ /* Read the TPI target's memory, indicate timeout if occurred */
if (!(TINYNVM_ReadMemory(ReadMemory_XPROG_Params.Address, ReadBuffer, ReadMemory_XPROG_Params.Length))) if (!(TINYNVM_ReadMemory(ReadMemory_XPROG_Params.Address, ReadBuffer, ReadMemory_XPROG_Params.Length)))
ReturnStatus = XPRG_ERR_TIMEOUT; ReturnStatus = XPROG_ERR_TIMEOUT;
} }
Endpoint_Write_8(CMD_XPROG); Endpoint_Write_8(CMD_XPROG);
Endpoint_Write_8(XPRG_CMD_READ_MEM); Endpoint_Write_8(XPROG_CMD_READ_MEM);
Endpoint_Write_8(ReturnStatus); Endpoint_Write_8(ReturnStatus);
if (ReturnStatus == XPRG_ERR_OK) if (ReturnStatus == XPROG_ERR_OK)
Endpoint_Write_Stream_LE(ReadBuffer, ReadMemory_XPROG_Params.Length, NULL); Endpoint_Write_Stream_LE(ReadBuffer, ReadMemory_XPROG_Params.Length, NULL);
Endpoint_ClearIN(); Endpoint_ClearIN();
@ -375,7 +375,7 @@ static void XPROGProtocol_ReadMemory(void)
*/ */
static void XPROGProtocol_ReadCRC(void) static void XPROGProtocol_ReadCRC(void)
{ {
uint8_t ReturnStatus = XPRG_ERR_OK; uint8_t ReturnStatus = XPROG_ERR_OK;
struct struct
{ {
@ -390,17 +390,17 @@ static void XPROGProtocol_ReadCRC(void)
uint32_t MemoryCRC; uint32_t MemoryCRC;
if (XPROG_SelectedProtocol == XPRG_PROTOCOL_PDI) if (XPROG_SelectedProtocol == XPROG_PROTOCOL_PDI)
{ {
uint8_t CRCCommand; uint8_t CRCCommand;
/* Determine which NVM command to send to the device depending on the memory to CRC */ /* Determine which NVM command to send to the device depending on the memory to CRC */
switch (ReadCRC_XPROG_Params.CRCType) switch (ReadCRC_XPROG_Params.CRCType)
{ {
case XPRG_CRC_APP: case XPROG_CRC_APP:
CRCCommand = XMEGA_NVM_CMD_APPCRC; CRCCommand = XMEGA_NVM_CMD_APPCRC;
break; break;
case XPRG_CRC_BOOT: case XPROG_CRC_BOOT:
CRCCommand = XMEGA_NVM_CMD_BOOTCRC; CRCCommand = XMEGA_NVM_CMD_BOOTCRC;
break; break;
default: default:
@ -410,19 +410,19 @@ static void XPROGProtocol_ReadCRC(void)
/* Perform and retrieve the memory CRC, indicate timeout if occurred */ /* Perform and retrieve the memory CRC, indicate timeout if occurred */
if (!(XMEGANVM_GetMemoryCRC(CRCCommand, &MemoryCRC))) if (!(XMEGANVM_GetMemoryCRC(CRCCommand, &MemoryCRC)))
ReturnStatus = XPRG_ERR_TIMEOUT; ReturnStatus = XPROG_ERR_TIMEOUT;
} }
else else
{ {
/* TPI does not support memory CRC */ /* TPI does not support memory CRC */
ReturnStatus = XPRG_ERR_FAILED; ReturnStatus = XPROG_ERR_FAILED;
} }
Endpoint_Write_8(CMD_XPROG); Endpoint_Write_8(CMD_XPROG);
Endpoint_Write_8(XPRG_CMD_CRC); Endpoint_Write_8(XPROG_CMD_CRC);
Endpoint_Write_8(ReturnStatus); Endpoint_Write_8(ReturnStatus);
if (ReturnStatus == XPRG_ERR_OK) if (ReturnStatus == XPROG_ERR_OK)
{ {
Endpoint_Write_8(MemoryCRC >> 16); Endpoint_Write_8(MemoryCRC >> 16);
Endpoint_Write_16_LE(MemoryCRC & 0xFFFF); Endpoint_Write_16_LE(MemoryCRC & 0xFFFF);
@ -436,33 +436,33 @@ static void XPROGProtocol_ReadCRC(void)
*/ */
static void XPROGProtocol_SetParam(void) static void XPROGProtocol_SetParam(void)
{ {
uint8_t ReturnStatus = XPRG_ERR_OK; uint8_t ReturnStatus = XPROG_ERR_OK;
uint8_t XPROGParam = Endpoint_Read_8(); uint8_t XPROGParam = Endpoint_Read_8();
/* Determine which parameter is being set, store the new parameter value */ /* Determine which parameter is being set, store the new parameter value */
switch (XPROGParam) switch (XPROGParam)
{ {
case XPRG_PARAM_NVMBASE: case XPROG_PARAM_NVMBASE:
XPROG_Param_NVMBase = Endpoint_Read_32_BE(); XPROG_Param_NVMBase = Endpoint_Read_32_BE();
break; break;
case XPRG_PARAM_EEPPAGESIZE: case XPROG_PARAM_EEPPAGESIZE:
XPROG_Param_EEPageSize = Endpoint_Read_16_BE(); XPROG_Param_EEPageSize = Endpoint_Read_16_BE();
break; break;
case XPRG_PARAM_NVMCMD_REG: case XPROG_PARAM_NVMCMD_REG:
XPROG_Param_NVMCMDRegAddr = Endpoint_Read_8(); XPROG_Param_NVMCMDRegAddr = Endpoint_Read_8();
break; break;
case XPRG_PARAM_NVMCSR_REG: case XPROG_PARAM_NVMCSR_REG:
XPROG_Param_NVMCSRRegAddr = Endpoint_Read_8(); XPROG_Param_NVMCSRRegAddr = Endpoint_Read_8();
break; break;
case XPRG_PARAM_UNKNOWN_1: case XPROG_PARAM_UNKNOWN_1:
/* TODO: Undocumented parameter added in AVRStudio 5.1, purpose unknown. Must ACK and discard or /* TODO: Undocumented parameter added in AVRStudio 5.1, purpose unknown. Must ACK and discard or
the communication with AVRStudio 5.1 will fail. the communication with AVRStudio 5.1 will fail.
*/ */
Endpoint_Discard_16(); Endpoint_Discard_16();
break; break;
default: default:
ReturnStatus = XPRG_ERR_FAILED; ReturnStatus = XPROG_ERR_FAILED;
break; break;
} }
@ -471,7 +471,7 @@ static void XPROGProtocol_SetParam(void)
Endpoint_SetEndpointDirection(ENDPOINT_DIR_IN); Endpoint_SetEndpointDirection(ENDPOINT_DIR_IN);
Endpoint_Write_8(CMD_XPROG); Endpoint_Write_8(CMD_XPROG);
Endpoint_Write_8(XPRG_CMD_SET_PARAM); Endpoint_Write_8(XPROG_CMD_SET_PARAM);
Endpoint_Write_8(ReturnStatus); Endpoint_Write_8(ReturnStatus);
Endpoint_ClearIN(); Endpoint_ClearIN();
} }

@ -47,7 +47,7 @@
#include "XMEGANVM.h" #include "XMEGANVM.h"
#include "TINYNVM.h" #include "TINYNVM.h"
#include "Config/AppConfig.h" #include "Config/AppConfig.h"
/* Preprocessor Checks: */ /* Preprocessor Checks: */
#if ((BOARD == BOARD_XPLAIN) || (BOARD == BOARD_XPLAIN_REV1)) #if ((BOARD == BOARD_XPLAIN) || (BOARD == BOARD_XPLAIN_REV1))
/* On the XPLAIN board, we only need PDI programming /* On the XPLAIN board, we only need PDI programming
@ -62,55 +62,55 @@
#endif #endif
/* Macros: */ /* Macros: */
#define XPRG_CMD_ENTER_PROGMODE 0x01 #define XPROG_CMD_ENTER_PROGMODE 0x01
#define XPRG_CMD_LEAVE_PROGMODE 0x02 #define XPROG_CMD_LEAVE_PROGMODE 0x02
#define XPRG_CMD_ERASE 0x03 #define XPROG_CMD_ERASE 0x03
#define XPRG_CMD_WRITE_MEM 0x04 #define XPROG_CMD_WRITE_MEM 0x04
#define XPRG_CMD_READ_MEM 0x05 #define XPROG_CMD_READ_MEM 0x05
#define XPRG_CMD_CRC 0x06 #define XPROG_CMD_CRC 0x06
#define XPRG_CMD_SET_PARAM 0x07 #define XPROG_CMD_SET_PARAM 0x07
#define XPRG_MEM_TYPE_APPL 1 #define XPROG_MEM_TYPE_APPL 1
#define XPRG_MEM_TYPE_BOOT 2 #define XPROG_MEM_TYPE_BOOT 2
#define XPRG_MEM_TYPE_EEPROM 3 #define XPROG_MEM_TYPE_EEPROM 3
#define XPRG_MEM_TYPE_FUSE 4 #define XPROG_MEM_TYPE_FUSE 4
#define XPRG_MEM_TYPE_LOCKBITS 5 #define XPROG_MEM_TYPE_LOCKBITS 5
#define XPRG_MEM_TYPE_USERSIG 6 #define XPROG_MEM_TYPE_USERSIG 6
#define XPRG_MEM_TYPE_FACTORY_CALIBRATION 7 #define XPROG_MEM_TYPE_FACTORY_CALIBRATION 7
#define XPRG_ERASE_CHIP 1 #define XPROG_ERASE_CHIP 1
#define XPRG_ERASE_APP 2 #define XPROG_ERASE_APP 2
#define XPRG_ERASE_BOOT 3 #define XPROG_ERASE_BOOT 3
#define XPRG_ERASE_EEPROM 4 #define XPROG_ERASE_EEPROM 4
#define XPRG_ERASE_APP_PAGE 5 #define XPROG_ERASE_APP_PAGE 5
#define XPRG_ERASE_BOOT_PAGE 6 #define XPROG_ERASE_BOOT_PAGE 6
#define XPRG_ERASE_EEPROM_PAGE 7 #define XPROG_ERASE_EEPROM_PAGE 7
#define XPRG_ERASE_USERSIG 8 #define XPROG_ERASE_USERSIG 8
#define XPRG_MEM_WRITE_ERASE 0 #define XPROG_MEM_WRITE_ERASE 0
#define XPRG_MEM_WRITE_WRITE 1 #define XPROG_MEM_WRITE_WRITE 1
#define XPRG_CRC_APP 1 #define XPROG_CRC_APP 1
#define XPRG_CRC_BOOT 2 #define XPROG_CRC_BOOT 2
#define XPRG_CRC_FLASH 3 #define XPROG_CRC_FLASH 3
#define XPRG_ERR_OK 0 #define XPROG_ERR_OK 0
#define XPRG_ERR_FAILED 1 #define XPROG_ERR_FAILED 1
#define XPRG_ERR_COLLISION 2 #define XPROG_ERR_COLLISION 2
#define XPRG_ERR_TIMEOUT 3 #define XPROG_ERR_TIMEOUT 3
#define XPRG_PARAM_NVMBASE 0x01 #define XPROG_PARAM_NVMBASE 0x01
#define XPRG_PARAM_EEPPAGESIZE 0x02 #define XPROG_PARAM_EEPPAGESIZE 0x02
#define XPRG_PARAM_NVMCMD_REG 0x03 #define XPROG_PARAM_NVMCMD_REG 0x03
#define XPRG_PARAM_NVMCSR_REG 0x04 #define XPROG_PARAM_NVMCSR_REG 0x04
#define XPRG_PARAM_UNKNOWN_1 0x05 #define XPROG_PARAM_UNKNOWN_1 0x05
#define XPRG_PROTOCOL_PDI 0x00 #define XPROG_PROTOCOL_PDI 0x00
#define XPRG_PROTOCOL_JTAG 0x01 #define XPROG_PROTOCOL_JTAG 0x01
#define XPRG_PROTOCOL_TPI 0x02 #define XPROG_PROTOCOL_TPI 0x02
#define XPRG_PAGEMODE_WRITE (1 << 1) #define XPROG_PAGEMODE_WRITE (1 << 1)
#define XPRG_PAGEMODE_ERASE (1 << 0) #define XPROG_PAGEMODE_ERASE (1 << 0)
/* External Variables: */ /* External Variables: */
extern uint32_t XPROG_Param_NVMBase; extern uint32_t XPROG_Param_NVMBase;

@ -83,10 +83,10 @@
#define PDI_RESET_KEY 0x59 #define PDI_RESET_KEY 0x59
#define PDI_NVMENABLE_KEY (uint8_t[]){0x12, 0x89, 0xAB, 0x45, 0xCD, 0xD8, 0x88, 0xFF} #define PDI_NVMENABLE_KEY (uint8_t[]){0x12, 0x89, 0xAB, 0x45, 0xCD, 0xD8, 0x88, 0xFF}
#define PDI_DATSIZE_1BYTE 0 #define PDI_DATASIZE_1BYTE 0
#define PDI_DATSIZE_2BYTES 1 #define PDI_DATASIZE_2BYTES 1
#define PDI_DATSIZE_3BYTES 2 #define PDI_DATASIZE_3BYTES 2
#define PDI_DATSIZE_4BYTES 3 #define PDI_DATASIZE_4BYTES 3
#define PDI_POINTER_INDIRECT 0 #define PDI_POINTER_INDIRECT 0
#define PDI_POINTER_INDIRECT_PI 1 #define PDI_POINTER_INDIRECT_PI 1

Loading…
Cancel
Save