Added const where possible to the source functions in the Projects directory.

Added command timeout to the AVRISP project so that incorrectly connected targets no longer freeze the device.

Removed string descriptors from the TeensyHID bootloader to reduce its size.
pull/1469/head
Dean Camera 15 years ago
parent 35dac470f2
commit d1608d4af3

@ -10,8 +10,11 @@
* *
* <b>New:</b> * <b>New:</b>
* - Added TPI programming support for 6-pin ATTINY to the AVRISP programmer project * - Added TPI programming support for 6-pin ATTINY to the AVRISP programmer project
* - Added command timeout counter to the AVRISP project so that the device no longer freezes when incorrectly connected
* to a target
* *
* <b>Changed:</b> * <b>Changed:</b>
* - Slowed down bit-banged PDI programming in the AVRISP project slightly to prevent transmission errors
* *
* <b>Fixed:</b> * <b>Fixed:</b>
* *

@ -37,7 +37,7 @@
* - "Fingerlicking Wingdinger" (WARNING: Bad Language if no Javascript), a MIDI controller: http://noisybox.net/electronics/wingdinger/ * - "Fingerlicking Wingdinger" (WARNING: Bad Language if no Javascript), a MIDI controller: http://noisybox.net/electronics/wingdinger/
* - Garmin GPS USB to NMEA standard serial sentence translator: http://github.com/nall/garmin-transmogrifier/tree/master * - Garmin GPS USB to NMEA standard serial sentence translator: http://github.com/nall/garmin-transmogrifier/tree/master
* - Generic HID Device Creator : http://generichid.sourceforge.net/ * - Generic HID Device Creator : http://generichid.sourceforge.net/
* - Mobo 4.3, some sort of Audio related device: http://sites.google.com/site/lofturj/mobo4_3 * - Mobo 4.3, a USB controlled all band (160-10m) HF SDR transceiver: http://sites.google.com/site/lofturj/mobo4_3
* - NES Controller USB modification: http://projects.peterpolidoro.net/video/NESUSB.htm * - NES Controller USB modification: http://projects.peterpolidoro.net/video/NESUSB.htm
* - MakeTV Episode Dispenser: http://www.youtube.com/watch?v=BkWUi18hl3g * - MakeTV Episode Dispenser: http://www.youtube.com/watch?v=BkWUi18hl3g
* - Opendous-JTAG, an open source JTAG device: http://code.google.com/p/opendous-jtag/ * - Opendous-JTAG, an open source JTAG device: http://code.google.com/p/opendous-jtag/

@ -78,7 +78,7 @@ void SetupHardware(void)
ADC_StartReading(VTARGET_ADC_CHANNEL | ADC_RIGHT_ADJUSTED | ADC_REFERENCE_AVCC); ADC_StartReading(VTARGET_ADC_CHANNEL | ADC_RIGHT_ADJUSTED | ADC_REFERENCE_AVCC);
#endif #endif
/* Millisecond timer initialization for timeouts and delays */ /* Millisecond timer initialization for managing the command timeout counter */
OCR0A = ((F_CPU / 64) / 1000); OCR0A = ((F_CPU / 64) / 1000);
TCCR0A = (1 << WGM01); TCCR0A = (1 << WGM01);
TCCR0B = ((1 << CS01) | (1 << CS00)); TCCR0B = ((1 << CS01) | (1 << CS00));

@ -72,17 +72,20 @@
*/ */
static inline void ISPProtocol_DelayMS(uint8_t DelayMS) static inline void ISPProtocol_DelayMS(uint8_t DelayMS)
{ {
TCNT0 = 0; OCR2A = ((F_CPU / 64) / 1000);
TIFR0 = (1 << OCF1A); TCCR2A = (1 << WGM01);
TCCR2B = ((1 << CS01) | (1 << CS00));
while (DelayMS) while (DelayMS)
{ {
if (TIFR0 & (1 << OCF1A)) if (TIFR2 & (1 << OCF2A))
{ {
TIFR0 = (1 << OCF1A); TIFR2 = (1 << OCF2A);
DelayMS--; DelayMS--;
} }
} }
TCCR2B = 0;
} }
/* Function Prototypes: */ /* Function Prototypes: */

@ -122,26 +122,15 @@ uint8_t ISPTarget_WaitForProgComplete(const uint8_t ProgrammingMode, const uint1
break; break;
case PROG_MODE_WORD_VALUE_MASK: case PROG_MODE_WORD_VALUE_MASK:
case PROG_MODE_PAGED_VALUE_MASK: case PROG_MODE_PAGED_VALUE_MASK:
TCNT0 = 0;
TIFR0 = (1 << OCF1A);
uint8_t TimeoutMS = TARGET_BUSY_TIMEOUT_MS;
do do
{ {
SPI_SendByte(ReadMemCommand); SPI_SendByte(ReadMemCommand);
SPI_SendByte(PollAddress >> 8); SPI_SendByte(PollAddress >> 8);
SPI_SendByte(PollAddress & 0xFF); SPI_SendByte(PollAddress & 0xFF);
if (TIFR0 & (1 << OCF1A))
{
TIFR0 = (1 << OCF1A);
TimeoutMS--;
}
} }
while ((SPI_TransferByte(0x00) != PollValue) && TimeoutMS); while ((SPI_TransferByte(0x00) != PollValue) && TimeoutMSRemaining);
if (!(TimeoutMS)) if (!(TimeoutMSRemaining))
ProgrammingStatus = STATUS_CMD_TOUT; ProgrammingStatus = STATUS_CMD_TOUT;
break; break;
@ -161,27 +150,16 @@ uint8_t ISPTarget_WaitForProgComplete(const uint8_t ProgrammingMode, const uint1
*/ */
uint8_t ISPTarget_WaitWhileTargetBusy(void) uint8_t ISPTarget_WaitWhileTargetBusy(void)
{ {
TCNT0 = 0;
TIFR0 = (1 << OCF1A);
uint8_t TimeoutMS = TARGET_BUSY_TIMEOUT_MS;
do do
{ {
SPI_SendByte(0xF0); SPI_SendByte(0xF0);
SPI_SendByte(0x00); SPI_SendByte(0x00);
SPI_SendByte(0x00); SPI_SendByte(0x00);
if (TIFR0 & (1 << OCF1A))
{
TIFR0 = (1 << OCF1A);
TimeoutMS--;
}
} }
while ((SPI_ReceiveByte() & 0x01) && TimeoutMS); while ((SPI_ReceiveByte() & 0x01) && TimeoutMSRemaining);
if (!(TimeoutMS)) if (!(TimeoutMSRemaining))
return STATUS_RDY_BSY_TOUT; return STATUS_RDY_BSY_TOUT;
else else
return STATUS_CMD_OK; return STATUS_CMD_OK;

@ -58,9 +58,6 @@
/** Total number of allowable ISP programming speeds supported by the device */ /** Total number of allowable ISP programming speeds supported by the device */
#define TOTAL_ISP_PROGRAMMING_SPEEDS 7 #define TOTAL_ISP_PROGRAMMING_SPEEDS 7
/** Timeout in milliseconds of target busy-wait loops waiting for a command to complete */
#define TARGET_BUSY_TIMEOUT_MS 100
/* Function Prototypes: */ /* Function Prototypes: */
uint8_t ISPTarget_GetSPIPrescalerMask(void); uint8_t ISPTarget_GetSPIPrescalerMask(void);
void ISPTarget_ChangeTargetResetLine(const bool ResetTarget); void ISPTarget_ChangeTargetResetLine(const bool ResetTarget);

@ -43,6 +43,13 @@ uint32_t CurrentAddress;
bool MustSetAddress; bool MustSetAddress;
/** ISR for the management of the command execution timeout counter */
ISR(TIMER0_COMPA_vect, ISR_BLOCK)
{
if (TimeoutMSRemaining)
TimeoutMSRemaining--;
}
/** Master V2 Protocol packet handler, for received V2 Protocol packets from a connected host. /** Master V2 Protocol packet handler, for received V2 Protocol packets from a connected host.
* This routine decodes the issued command and passes off the handling of the command to the * This routine decodes the issued command and passes off the handling of the command to the
* appropriate function. * appropriate function.
@ -51,6 +58,9 @@ void V2Protocol_ProcessCommand(void)
{ {
uint8_t V2Command = Endpoint_Read_Byte(); uint8_t V2Command = Endpoint_Read_Byte();
TimeoutMSRemaining = COMMAND_TIMEOUT_MS;
TIMSK0 |= (1 << OCIE0A);
switch (V2Command) switch (V2Command)
{ {
case CMD_SIGN_ON: case CMD_SIGN_ON:
@ -111,6 +121,8 @@ void V2Protocol_ProcessCommand(void)
break; break;
} }
TIMSK0 &= ~(1 << OCIE0A);
Endpoint_WaitUntilReady(); Endpoint_WaitUntilReady();
Endpoint_SetEndpointDirection(ENDPOINT_DIR_OUT); Endpoint_SetEndpointDirection(ENDPOINT_DIR_OUT);
} }

@ -49,10 +49,9 @@
/* Preprocessor Checks: */ /* Preprocessor Checks: */
#if ((BOARD == BOARD_XPLAIN) || (BOARD == BOARD_XPLAIN_REV1)) #if ((BOARD == BOARD_XPLAIN) || (BOARD == BOARD_XPLAIN_REV1))
#undef ENABLE_ISP_PROTOCOL #undef ENABLE_ISP_PROTOCOL
#undef ENABLE_TPI_PROTOCOL
#if !defined(ENABLE_PDI_PROTOCOL) #if !defined(ENABLE_XPROG_PROTOCOL)
#define ENABLE_PDI_PROTOCOL #define ENABLE_XPROG_PROTOCOL
#endif #endif
#endif #endif
@ -60,6 +59,12 @@
/** Programmer ID string, returned to the host during the CMD_SIGN_ON command processing */ /** Programmer ID string, returned to the host during the CMD_SIGN_ON command processing */
#define PROGRAMMER_ID "AVRISP_MK2" #define PROGRAMMER_ID "AVRISP_MK2"
/** Timeout period for each issued command from the host before it is aborted */
#define COMMAND_TIMEOUT_MS 200
/** Command timeout counter register, GPIOR for speed */
#define TimeoutMSRemaining GPIOR1
/* External Variables: */ /* External Variables: */
extern uint32_t CurrentAddress; extern uint32_t CurrentAddress;
extern bool MustSetAddress; extern bool MustSetAddress;

@ -43,44 +43,44 @@ uint8_t EEMEM EEPROM_Rest_Polarity = 0x00;
static ParameterItem_t ParameterTable[] = static ParameterItem_t ParameterTable[] =
{ {
{ .ParamID = PARAM_BUILD_NUMBER_LOW, { .ParamID = PARAM_BUILD_NUMBER_LOW,
.ParamValue = (LUFA_VERSION_INTEGER >> 8), .ParamPrivileges = PARAM_PRIV_READ,
.ParamPrivileges = PARAM_PRIV_READ }, .ParamValue = (LUFA_VERSION_INTEGER >> 8) },
{ .ParamID = PARAM_BUILD_NUMBER_HIGH, { .ParamID = PARAM_BUILD_NUMBER_HIGH,
.ParamValue = (LUFA_VERSION_INTEGER & 0xFF), .ParamPrivileges = PARAM_PRIV_READ,
.ParamPrivileges = PARAM_PRIV_READ }, .ParamValue = (LUFA_VERSION_INTEGER & 0xFF), },
{ .ParamID = PARAM_HW_VER, { .ParamID = PARAM_HW_VER,
.ParamValue = 0x00, .ParamPrivileges = PARAM_PRIV_READ,
.ParamPrivileges = PARAM_PRIV_READ }, .ParamValue = 0x00 },
{ .ParamID = PARAM_SW_MAJOR, { .ParamID = PARAM_SW_MAJOR,
.ParamValue = 0x01, .ParamPrivileges = PARAM_PRIV_READ,
.ParamPrivileges = PARAM_PRIV_READ }, .ParamValue = 0x01 },
{ .ParamID = PARAM_SW_MINOR, { .ParamID = PARAM_SW_MINOR,
.ParamValue = 0x0D, .ParamPrivileges = PARAM_PRIV_READ,
.ParamPrivileges = PARAM_PRIV_READ }, .ParamValue = 0x0D },
{ .ParamID = PARAM_VTARGET, { .ParamID = PARAM_VTARGET,
.ParamValue = 0x32, .ParamPrivileges = PARAM_PRIV_READ,
.ParamPrivileges = PARAM_PRIV_READ }, .ParamValue = 0x32 },
{ .ParamID = PARAM_SCK_DURATION, { .ParamID = PARAM_SCK_DURATION,
.ParamValue = (TOTAL_ISP_PROGRAMMING_SPEEDS - 1), .ParamPrivileges = PARAM_PRIV_READ | PARAM_PRIV_WRITE,
.ParamPrivileges = PARAM_PRIV_READ | PARAM_PRIV_WRITE }, .ParamValue = (TOTAL_ISP_PROGRAMMING_SPEEDS - 1) },
{ .ParamID = PARAM_RESET_POLARITY, { .ParamID = PARAM_RESET_POLARITY,
.ParamValue = 0x00, .ParamPrivileges = PARAM_PRIV_WRITE,
.ParamPrivileges = PARAM_PRIV_WRITE }, .ParamValue = 0x00 },
{ .ParamID = PARAM_STATUS_TGT_CONN, { .ParamID = PARAM_STATUS_TGT_CONN,
.ParamValue = 0x00, .ParamPrivileges = PARAM_PRIV_READ,
.ParamPrivileges = PARAM_PRIV_READ }, .ParamValue = 0x00 },
{ .ParamID = PARAM_DISCHARGEDELAY, { .ParamID = PARAM_DISCHARGEDELAY,
.ParamValue = 0x00, .ParamPrivileges = PARAM_PRIV_WRITE,
.ParamPrivileges = PARAM_PRIV_WRITE }, .ParamValue = 0x00 },
}; };

@ -62,8 +62,8 @@
typedef struct typedef struct
{ {
const uint8_t ParamID; /**< Parameter ID number to uniquely identify the parameter within the device */ const uint8_t ParamID; /**< Parameter ID number to uniquely identify the parameter within the device */
const uint8_t ParamPrivileges; /**< Parameter privileges to allow the host to read or write the parameter's value */
uint8_t ParamValue; /**< Current parameter's value within the device */ uint8_t ParamValue; /**< Current parameter's value within the device */
uint8_t ParamPrivileges; /**< Parameter privileges to allow the host to read or write the parameter's value */
} ParameterItem_t; } ParameterItem_t;
/* Function Prototypes: */ /* Function Prototypes: */

@ -37,6 +37,7 @@
#include "TINYNVM.h" #include "TINYNVM.h"
#if defined(ENABLE_XPROG_PROTOCOL) || defined(__DOXYGEN__) #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. /** 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) 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 */ /* 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 */ /* 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); XPROGTarget_SendByte(TPI_CMD_SLDCS | TPI_STATUS_REG);
if (XPROGTarget_ReceiveByte() & TPI_STATUS_NVM) if (XPROGTarget_ReceiveByte() & TPI_STATUS_NVM)
return true; return true;
if (TIFR0 & (1 << OCF1A))
{
TIFR0 = (1 << OCF1A);
TimeoutMS--;
}
} }
return false; return false;

@ -56,7 +56,13 @@
#endif #endif
/* Defines: */ /* 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: */ /* Function Prototypes: */
bool TINYNVM_WaitWhileNVMBusBusy(void); bool TINYNVM_WaitWhileNVMBusBusy(void);

@ -58,10 +58,10 @@ void XMEGANVM_SendNVMRegAddress(const uint8_t Register)
void XMEGANVM_SendAddress(const uint32_t AbsoluteAddress) void XMEGANVM_SendAddress(const uint32_t AbsoluteAddress)
{ {
/* Send the given 32-bit address to the target, LSB first */ /* Send the given 32-bit address to the target, LSB first */
XPROGTarget_SendByte(AbsoluteAddress & 0xFF); XPROGTarget_SendByte(((uint8_t*)&AbsoluteAddress)[0]);
XPROGTarget_SendByte(AbsoluteAddress >> 8); XPROGTarget_SendByte(((uint8_t*)&AbsoluteAddress)[1]);
XPROGTarget_SendByte(AbsoluteAddress >> 16); XPROGTarget_SendByte(((uint8_t*)&AbsoluteAddress)[2]);
XPROGTarget_SendByte(AbsoluteAddress >> 24); 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 /** 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) 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 */ /* 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 */ /* 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); XPROGTarget_SendByte(PDI_CMD_LDCS | PDI_STATUS_REG);
if (XPROGTarget_ReceiveByte() & PDI_STATUS_NVM) if (XPROGTarget_ReceiveByte() & PDI_STATUS_NVM)
return true; return true;
if (TIFR0 & (1 << OCF1A))
{
TIFR0 = (1 << OCF1A);
TimeoutMS--;
}
} }
return false; return false;
@ -101,13 +90,8 @@ bool XMEGANVM_WaitWhileNVMBusBusy(void)
*/ */
bool XMEGANVM_WaitWhileNVMControllerBusy(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 */ /* 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 */ /* Send a LDS command to read the NVM STATUS register to check the BUSY flag */
XPROGTarget_SendByte(PDI_CMD_LDS | (PDI_DATSIZE_4BYTES << 2)); 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 */ /* Check to see if the BUSY flag is still set */
if (!(XPROGTarget_ReceiveByte() & (1 << 7))) if (!(XPROGTarget_ReceiveByte() & (1 << 7)))
return true; return true;
if (TIFR0 & (1 << OCF1A))
{
TIFR0 = (1 << OCF1A);
TimeoutMS--;
}
} }
return false; return false;
@ -158,22 +136,24 @@ bool XMEGANVM_GetMemoryCRC(const uint8_t CRCCommand, uint32_t* const CRCDest)
if (!(XMEGANVM_WaitWhileNVMControllerBusy())) if (!(XMEGANVM_WaitWhileNVMControllerBusy()))
return false; return false;
*CRCDest = 0; uint32_t MemoryCRC = 0;
/* Read the first generated CRC byte value */ /* Read the first generated CRC byte value */
XPROGTarget_SendByte(PDI_CMD_LDS | (PDI_DATSIZE_4BYTES << 2)); XPROGTarget_SendByte(PDI_CMD_LDS | (PDI_DATSIZE_4BYTES << 2));
XMEGANVM_SendNVMRegAddress(XMEGA_NVM_REG_DAT0); XMEGANVM_SendNVMRegAddress(XMEGA_NVM_REG_DAT0);
*CRCDest = XPROGTarget_ReceiveByte(); MemoryCRC = XPROGTarget_ReceiveByte();
/* Read the second generated CRC byte value */ /* Read the second generated CRC byte value */
XPROGTarget_SendByte(PDI_CMD_LDS | (PDI_DATSIZE_4BYTES << 2)); XPROGTarget_SendByte(PDI_CMD_LDS | (PDI_DATSIZE_4BYTES << 2));
XMEGANVM_SendNVMRegAddress(XMEGA_NVM_REG_DAT1); 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 */ /* Read the third generated CRC byte value */
XPROGTarget_SendByte(PDI_CMD_LDS | (PDI_DATSIZE_4BYTES << 2)); XPROGTarget_SendByte(PDI_CMD_LDS | (PDI_DATSIZE_4BYTES << 2));
XMEGANVM_SendNVMRegAddress(XMEGA_NVM_REG_DAT2); XMEGANVM_SendNVMRegAddress(XMEGA_NVM_REG_DAT2);
*CRCDest |= ((uint32_t)XPROGTarget_ReceiveByte() << 16); MemoryCRC |= ((uint32_t)XPROGTarget_ReceiveByte() << 16);
*CRCDest = MemoryCRC;
return true; 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 * \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 */ /* Wait until the NVM controller is no longer busy */
if (!(XMEGANVM_WaitWhileNVMControllerBusy())) 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 */ /* 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); 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(); *(ReadBuffer++) = XPROGTarget_ReceiveByte();
return true; return true;
@ -254,7 +234,7 @@ bool XMEGANVM_WriteByteMemory(const uint8_t WriteCommand, const uint32_t WriteAd
*/ */
bool XMEGANVM_WritePageMemory(const uint8_t WriteBuffCommand, const uint8_t EraseBuffCommand, 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 WritePageCommand, const uint8_t PageMode, const uint32_t WriteAddress,
const uint8_t* WriteBuffer, const uint16_t WriteSize) const uint8_t* WriteBuffer, uint16_t WriteSize)
{ {
if (PageMode & XPRG_PAGEMODE_ERASE) 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 */ /* 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); 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++)); XPROGTarget_SendByte(*(WriteBuffer++));
} }

@ -56,8 +56,6 @@
#endif #endif
/* Defines: */ /* Defines: */
#define XMEGA_NVM_BUSY_TIMEOUT_MS 100
#define XMEGA_NVM_REG_ADDR0 0x00 #define XMEGA_NVM_REG_ADDR0 0x00
#define XMEGA_NVM_REG_ADDR1 0x01 #define XMEGA_NVM_REG_ADDR1 0x01
#define XMEGA_NVM_REG_ADDR2 0x02 #define XMEGA_NVM_REG_ADDR2 0x02
@ -111,11 +109,11 @@
bool XMEGANVM_WaitWhileNVMBusBusy(void); bool XMEGANVM_WaitWhileNVMBusBusy(void);
bool XMEGANVM_WaitWhileNVMControllerBusy(void); bool XMEGANVM_WaitWhileNVMControllerBusy(void);
bool XMEGANVM_GetMemoryCRC(const uint8_t CRCCommand, uint32_t* const CRCDest); 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_WriteByteMemory(const uint8_t WriteCommand, const uint32_t WriteAddress, const uint8_t* WriteBuffer);
bool XMEGANVM_WritePageMemory(const uint8_t WriteBuffCommand, const uint8_t EraseBuffCommand, 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 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); bool XMEGANVM_EraseMemory(const uint8_t EraseCommand, const uint32_t Address);
#endif #endif

@ -46,7 +46,6 @@ uint32_t XPROG_Param_EEPageSize;
/** Currently selected XPROG programming protocol */ /** Currently selected XPROG programming protocol */
uint8_t XPROG_SelectedProtocol = XPRG_PROTOCOL_PDI; 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 /** Handler for the CMD_XPROG_SETMODE command, which sets the programmer-to-target protocol used for PDI/TPI
* programming. * programming.
*/ */

@ -174,7 +174,7 @@ void XPROGTarget_EnableTargetTPI(void)
BITBANG_TPIDATA_PORT |= BITBANG_TPIDATA_MASK; BITBANG_TPIDATA_PORT |= BITBANG_TPIDATA_MASK;
/* Fire timer capture ISR every 100 cycles to manage the software USART */ /* Fire timer capture ISR every 100 cycles to manage the software USART */
OCR1A = 80; OCR1A = 100;
TCCR1B = (1 << WGM13) | (1 << WGM12) | (1 << CS10); TCCR1B = (1 << WGM13) | (1 << WGM12) | (1 << CS10);
TIMSK1 = (1 << ICIE1); TIMSK1 = (1 << ICIE1);
@ -217,7 +217,7 @@ void XPROGTarget_EnableTargetPDI(void)
asm volatile ("NOP"::); asm volatile ("NOP"::);
/* Fire timer compare ISR every 100 cycles to manage the software USART */ /* Fire timer compare ISR every 100 cycles to manage the software USART */
OCR1A = 80; OCR1A = 100;
TCCR1B = (1 << WGM12) | (1 << CS10); TCCR1B = (1 << WGM12) | (1 << CS10);
TIMSK1 = (1 << OCIE1A); TIMSK1 = (1 << OCIE1A);
@ -353,7 +353,7 @@ uint8_t XPROGTarget_ReceiveByte(void)
} }
/* Wait until a byte has been received before reading */ /* Wait until a byte has been received before reading */
while (!(UCSR1A & (1 << RXC1))); while (!(UCSR1A & (1 << RXC1)) && TimeoutMSRemaining);
return UDR1; return UDR1;
#else #else
/* Switch to Rx mode if currently in Tx mode */ /* Switch to Rx mode if currently in Tx mode */
@ -369,7 +369,7 @@ uint8_t XPROGTarget_ReceiveByte(void)
/* Wait until a byte has been received before reading */ /* Wait until a byte has been received before reading */
SoftUSART_BitCount = BITS_IN_USART_FRAME; 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) */ /* Throw away the parity and stop bits to leave only the data (start bit is already discarded) */
return (uint8_t)SoftUSART_Data; return (uint8_t)SoftUSART_Data;

@ -43,6 +43,8 @@
#include <LUFA/Common/Common.h> #include <LUFA/Common/Common.h>
#include "../V2Protocol.h"
/* Preprocessor Checks: */ /* Preprocessor Checks: */
#if ((BOARD == BOARD_XPLAIN) || (BOARD == BOARD_XPLAIN_REV1)) #if ((BOARD == BOARD_XPLAIN) || (BOARD == BOARD_XPLAIN_REV1))
#undef ENABLE_ISP_PROTOCOL #undef ENABLE_ISP_PROTOCOL

@ -1,11 +1,3 @@
/*
LUFA Library
Copyright (C) Dean Camera, 2009.
dean [at] fourwalledcubicle [dot] com
www.fourwalledcubicle.com
*/
/* /*
USB Missile Launcher Demo USB Missile Launcher Demo
Copyright (C) Dave Fletcher, 2009. Copyright (C) Dave Fletcher, 2009.
@ -158,7 +150,7 @@ void Read_Joystick_Status(void)
* \param[in] Report Report data to send. * \param[in] Report Report data to send.
* \param[in] ReportSize Report length in bytes. * \param[in] ReportSize Report length in bytes.
*/ */
void Send_Command_Report(uint8_t *Report, uint16_t ReportSize) void Send_Command_Report(uint8_t* const Report, const uint16_t ReportSize)
{ {
memcpy(CmdBuffer, Report, 8); memcpy(CmdBuffer, Report, 8);
WriteNextReport(CmdBuffer, ReportSize); WriteNextReport(CmdBuffer, ReportSize);
@ -168,7 +160,7 @@ void Send_Command_Report(uint8_t *Report, uint16_t ReportSize)
* *
* \param[in] Command One of the command constants. * \param[in] Command One of the command constants.
*/ */
void Send_Command(uint8_t* Command) void Send_Command(uint8_t* const Command)
{ {
if ((CmdState == CMD_STOP && Command != CMD_STOP) || if ((CmdState == CMD_STOP && Command != CMD_STOP) ||
(CmdState != CMD_STOP && Command == CMD_STOP)) (CmdState != CMD_STOP && Command == CMD_STOP))
@ -252,7 +244,7 @@ void DiscardNextReport(void)
* \param[in] ReportOUTData Buffer containing the report to send to the device * \param[in] ReportOUTData Buffer containing the report to send to the device
* \param[in] ReportLength Length of the report to send * \param[in] ReportLength Length of the report to send
*/ */
void WriteNextReport(uint8_t* ReportOUTData, uint16_t ReportLength) void WriteNextReport(uint8_t* const ReportOUTData, const uint16_t ReportLength)
{ {
/* Select and unfreeze HID data OUT pipe */ /* Select and unfreeze HID data OUT pipe */
Pipe_SelectPipe(HID_DATA_OUT_PIPE); Pipe_SelectPipe(HID_DATA_OUT_PIPE);

@ -82,8 +82,8 @@
void SetupHardware(void); void SetupHardware(void);
void Read_Joystick_Status(void); void Read_Joystick_Status(void);
void Send_Command_Report(uint8_t* Report, uint16_t ReportSize); void Send_Command_Report(uint8_t* const Report, const uint16_t ReportSize);
void Send_Command(uint8_t* Command); void Send_Command(uint8_t* const Command);
void HID_Host_Task(void); void HID_Host_Task(void);
@ -94,6 +94,6 @@
void EVENT_USB_Host_DeviceEnumerationComplete(void); void EVENT_USB_Host_DeviceEnumerationComplete(void);
void DiscardNextReport(void); void DiscardNextReport(void);
void WriteNextReport(uint8_t* ReportOUTData, uint16_t ReportLength); void WriteNextReport(uint8_t* const ReportOUTData, const uint16_t ReportLength);
#endif #endif

Loading…
Cancel
Save