diff options
author | Dean Camera <dean@fourwalledcubicle.com> | 2010-10-13 14:05:35 +0000 |
---|---|---|
committer | Dean Camera <dean@fourwalledcubicle.com> | 2010-10-13 14:05:35 +0000 |
commit | 5a4def747897c1c6ffbe465506d846c7c686d3e9 (patch) | |
tree | e5a9ca31ab554e993f1a9041e44976cf7b253921 /Projects/AVRISP-MKII/Lib/XPROG | |
parent | a8871c7fba73307226bd13e2cad4c840c850e6f1 (diff) | |
download | lufa-5a4def747897c1c6ffbe465506d846c7c686d3e9.tar.gz lufa-5a4def747897c1c6ffbe465506d846c7c686d3e9.tar.bz2 lufa-5a4def747897c1c6ffbe465506d846c7c686d3e9.zip |
Clean up excessive whitespace at the end of each line using the wspurify tool made by Laszlo Monda
Diffstat (limited to 'Projects/AVRISP-MKII/Lib/XPROG')
-rw-r--r-- | Projects/AVRISP-MKII/Lib/XPROG/TINYNVM.c | 31 | ||||
-rw-r--r-- | Projects/AVRISP-MKII/Lib/XPROG/TINYNVM.h | 23 | ||||
-rw-r--r-- | Projects/AVRISP-MKII/Lib/XPROG/XMEGANVM.c | 63 | ||||
-rw-r--r-- | Projects/AVRISP-MKII/Lib/XPROG/XMEGANVM.h | 27 | ||||
-rw-r--r-- | Projects/AVRISP-MKII/Lib/XPROG/XPROGProtocol.c | 105 | ||||
-rw-r--r-- | Projects/AVRISP-MKII/Lib/XPROG/XPROGProtocol.h | 33 | ||||
-rw-r--r-- | Projects/AVRISP-MKII/Lib/XPROG/XPROGTarget.c | 21 | ||||
-rw-r--r-- | Projects/AVRISP-MKII/Lib/XPROG/XPROGTarget.h | 37 |
8 files changed, 174 insertions, 166 deletions
diff --git a/Projects/AVRISP-MKII/Lib/XPROG/TINYNVM.c b/Projects/AVRISP-MKII/Lib/XPROG/TINYNVM.c index d45e42a1a..7522dc81f 100644 --- a/Projects/AVRISP-MKII/Lib/XPROG/TINYNVM.c +++ b/Projects/AVRISP-MKII/Lib/XPROG/TINYNVM.c @@ -1,7 +1,7 @@ /* LUFA Library Copyright (C) Dean Camera, 2010. - + dean [at] fourwalledcubicle [dot] com www.fourwalledcubicle.com */ @@ -9,13 +9,13 @@ /* Copyright 2010 Dean Camera (dean [at] fourwalledcubicle [dot] com) - Permission to use, copy, modify, distribute, and sell this + Permission to use, copy, modify, distribute, and sell this software and its documentation for any purpose is hereby granted - without fee, provided that the above copyright notice appear in + without fee, provided that the above copyright notice appear in all copies and that both that the copyright notice and this - permission notice and warranty disclaimer appear in supporting - documentation, and that the name of the author not be used in - advertising or publicity pertaining to distribution of the + permission notice and warranty disclaimer appear in supporting + documentation, and that the name of the author not be used in + advertising or publicity pertaining to distribution of the software without specific, written prior permission. The author disclaim all warranties with regard to this @@ -138,17 +138,17 @@ bool TINYNVM_ReadMemory(const uint16_t ReadAddress, /* Set the NVM control register to the NO OP command for memory reading */ TINYNVM_SendWriteNVMRegister(XPROG_Param_NVMCMDRegAddr); XPROGTarget_SendByte(TINY_NVM_CMD_NOOP); - + /* Send the address of the location to read from */ TINYNVM_SendPointerAddress(ReadAddress); - + while (ReadSize-- && TimeoutTicksRemaining) { /* Read the byte of data from the target */ XPROGTarget_SendByte(TPI_CMD_SLD | TPI_POINTER_INDIRECT_PI); *(ReadBuffer++) = XPROGTarget_ReceiveByte(); } - + return (TimeoutTicksRemaining != 0); } @@ -167,7 +167,7 @@ bool TINYNVM_WriteMemory(const uint16_t WriteAddress, /* Wait until the NVM controller is no longer busy */ if (!(TINYNVM_WaitWhileNVMControllerBusy())) return false; - + /* Must have an integer number of words to write - if extra byte, word-align via a dummy high byte */ if (WriteLength & 0x01) WriteBuffer[WriteLength++] = 0xFF; @@ -175,10 +175,10 @@ bool TINYNVM_WriteMemory(const uint16_t WriteAddress, /* Set the NVM control register to the WORD WRITE command for memory reading */ TINYNVM_SendWriteNVMRegister(XPROG_Param_NVMCMDRegAddr); XPROGTarget_SendByte(TINY_NVM_CMD_WORDWRITE); - + /* Send the address of the location to write to */ TINYNVM_SendPointerAddress(WriteAddress); - + while (WriteLength) { /* Wait until the NVM controller is no longer busy */ @@ -188,7 +188,7 @@ bool TINYNVM_WriteMemory(const uint16_t WriteAddress, /* Write the low byte of data to the target */ XPROGTarget_SendByte(TPI_CMD_SST | TPI_POINTER_INDIRECT_PI); XPROGTarget_SendByte(*(WriteBuffer++)); - + /* Write the high byte of data to the target */ XPROGTarget_SendByte(TPI_CMD_SST | TPI_POINTER_INDIRECT_PI); XPROGTarget_SendByte(*(WriteBuffer++)); @@ -196,7 +196,7 @@ bool TINYNVM_WriteMemory(const uint16_t WriteAddress, /* Need to decrement the write length twice, since we read out a whole word */ WriteLength -= 2; } - + return true; } @@ -226,8 +226,9 @@ bool TINYNVM_EraseMemory(const uint8_t EraseCommand, /* Wait until the NVM controller is no longer busy */ if (!(TINYNVM_WaitWhileNVMControllerBusy())) return false; - + return true; } #endif + diff --git a/Projects/AVRISP-MKII/Lib/XPROG/TINYNVM.h b/Projects/AVRISP-MKII/Lib/XPROG/TINYNVM.h index cbb2c27aa..339b299d2 100644 --- a/Projects/AVRISP-MKII/Lib/XPROG/TINYNVM.h +++ b/Projects/AVRISP-MKII/Lib/XPROG/TINYNVM.h @@ -1,7 +1,7 @@ /* LUFA Library Copyright (C) Dean Camera, 2010. - + dean [at] fourwalledcubicle [dot] com www.fourwalledcubicle.com */ @@ -9,13 +9,13 @@ /* Copyright 2010 Dean Camera (dean [at] fourwalledcubicle [dot] com) - Permission to use, copy, modify, distribute, and sell this + Permission to use, copy, modify, distribute, and sell this software and its documentation for any purpose is hereby granted - without fee, provided that the above copyright notice appear in + without fee, provided that the above copyright notice appear in all copies and that both that the copyright notice and this - permission notice and warranty disclaimer appear in supporting - documentation, and that the name of the author not be used in - advertising or publicity pertaining to distribution of the + permission notice and warranty disclaimer appear in supporting + documentation, and that the name of the author not be used in + advertising or publicity pertaining to distribution of the software without specific, written prior permission. The author disclaim all warranties with regard to this @@ -40,16 +40,16 @@ #include <avr/io.h> #include <avr/interrupt.h> #include <stdbool.h> - + #include <LUFA/Common/Common.h> - + #include "XPROGProtocol.h" #include "XPROGTarget.h" - + /* Preprocessor Checks: */ #if ((BOARD == BOARD_XPLAIN) || (BOARD == BOARD_XPLAIN_REV1)) #undef ENABLE_ISP_PROTOCOL - + #if !defined(ENABLE_XPROG_PROTOCOL) #define ENABLE_XPROG_PROTOCOL #endif @@ -61,7 +61,7 @@ #define TINY_NVM_CMD_SECTIONERASE 0x14 #define TINY_NVM_CMD_WORDWRITE 0x1D - /* Function Prototypes: */ + /* Function Prototypes: */ bool TINYNVM_WaitWhileNVMBusBusy(void); bool TINYNVM_WaitWhileNVMControllerBusy(void); bool TINYNVM_ReadMemory(const uint16_t ReadAddress, @@ -80,3 +80,4 @@ #endif #endif + diff --git a/Projects/AVRISP-MKII/Lib/XPROG/XMEGANVM.c b/Projects/AVRISP-MKII/Lib/XPROG/XMEGANVM.c index 22f4e93e0..322f2ea80 100644 --- a/Projects/AVRISP-MKII/Lib/XPROG/XMEGANVM.c +++ b/Projects/AVRISP-MKII/Lib/XPROG/XMEGANVM.c @@ -1,7 +1,7 @@ /* LUFA Library Copyright (C) Dean Camera, 2010. - + dean [at] fourwalledcubicle [dot] com www.fourwalledcubicle.com */ @@ -9,13 +9,13 @@ /* Copyright 2010 Dean Camera (dean [at] fourwalledcubicle [dot] com) - Permission to use, copy, modify, distribute, and sell this + Permission to use, copy, modify, distribute, and sell this software and its documentation for any purpose is hereby granted - without fee, provided that the above copyright notice appear in + without fee, provided that the above copyright notice appear in all copies and that both that the copyright notice and this - permission notice and warranty disclaimer appear in supporting - documentation, and that the name of the author not be used in - advertising or publicity pertaining to distribution of the + permission notice and warranty disclaimer appear in supporting + documentation, and that the name of the author not be used in + advertising or publicity pertaining to distribution of the software without specific, written prior permission. The author disclaim all warranties with regard to this @@ -76,13 +76,13 @@ bool XMEGANVM_WaitWhileNVMBusBusy(void) { /* 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); - + uint8_t StatusRegister = XPROGTarget_ReceiveByte(); - + /* We might have timed out waiting for the status register read response, check here */ if (!(TimeoutTicksRemaining)) return false; - + /* Check the status register read response to see if the NVM bus is enabled */ if (StatusRegister & PDI_STATUS_NVM) return true; @@ -102,7 +102,7 @@ bool XMEGANVM_WaitWhileNVMControllerBusy(void) /* Send a LDS command to read the NVM STATUS register to check the BUSY flag */ XPROGTarget_SendByte(PDI_CMD_LDS | (PDI_DATSIZE_4BYTES << 2)); XMEGANVM_SendNVMRegAddress(XMEGA_NVM_REG_STATUS); - + uint8_t StatusRegister = XPROGTarget_ReceiveByte(); /* We might have timed out waiting for the status register read response, check here */ @@ -127,7 +127,7 @@ bool XMEGANVM_GetMemoryCRC(const uint8_t CRCCommand, uint32_t* const CRCDest) /* Wait until the NVM controller is no longer busy */ if (!(XMEGANVM_WaitWhileNVMControllerBusy())) return false; - + /* Set the NVM command to the correct CRC read command */ XPROGTarget_SendByte(PDI_CMD_STS | (PDI_DATSIZE_4BYTES << 2)); XMEGANVM_SendNVMRegAddress(XMEGA_NVM_REG_CMD); @@ -145,7 +145,7 @@ bool XMEGANVM_GetMemoryCRC(const uint8_t CRCCommand, uint32_t* const CRCDest) /* Wait until the NVM controller is no longer busy */ if (!(XMEGANVM_WaitWhileNVMControllerBusy())) return false; - + /* Load the PDI pointer register with the DAT0 register start address */ XPROGTarget_SendByte(PDI_CMD_ST | (PDI_POINTER_DIRECT << 2) | PDI_DATSIZE_4BYTES); XMEGANVM_SendNVMRegAddress(XMEGA_NVM_REG_DAT0); @@ -153,12 +153,12 @@ bool XMEGANVM_GetMemoryCRC(const uint8_t CRCCommand, uint32_t* const CRCDest) /* Send the REPEAT command to grab the CRC bytes */ XPROGTarget_SendByte(PDI_CMD_REPEAT | PDI_DATSIZE_1BYTE); XPROGTarget_SendByte(XMEGA_CRC_LENGTH - 1); - + /* Read in the CRC bytes from the target */ XPROGTarget_SendByte(PDI_CMD_LD | (PDI_POINTER_INDIRECT_PI << 2) | PDI_DATSIZE_1BYTE); for (uint8_t i = 0; i < XMEGA_CRC_LENGTH; i++) ((uint8_t*)CRCDest)[i] = XPROGTarget_ReceiveByte(); - + return (TimeoutTicksRemaining != 0); } @@ -175,7 +175,7 @@ bool XMEGANVM_ReadMemory(const uint32_t ReadAddress, uint8_t* ReadBuffer, uint16 /* Wait until the NVM controller is no longer busy */ if (!(XMEGANVM_WaitWhileNVMControllerBusy())) return false; - + /* Send the READNVM command to the NVM controller for reading of an arbitrary location */ XPROGTarget_SendByte(PDI_CMD_STS | (PDI_DATSIZE_4BYTES << 2)); XMEGANVM_SendNVMRegAddress(XMEGA_NVM_REG_CMD); @@ -188,12 +188,12 @@ bool XMEGANVM_ReadMemory(const uint32_t ReadAddress, uint8_t* ReadBuffer, uint16 /* Send the REPEAT command with the specified number of bytes to read */ XPROGTarget_SendByte(PDI_CMD_REPEAT | PDI_DATSIZE_1BYTE); XPROGTarget_SendByte(ReadSize - 1); - + /* Send a LD command with indirect access and post-increment to read out the bytes */ XPROGTarget_SendByte(PDI_CMD_LD | (PDI_POINTER_INDIRECT_PI << 2) | PDI_DATSIZE_1BYTE); while (ReadSize-- && TimeoutTicksRemaining) *(ReadBuffer++) = XPROGTarget_ReceiveByte(); - + return (TimeoutTicksRemaining != 0); } @@ -215,12 +215,12 @@ bool XMEGANVM_WriteByteMemory(const uint8_t WriteCommand, const uint32_t WriteAd XPROGTarget_SendByte(PDI_CMD_STS | (PDI_DATSIZE_4BYTES << 2)); XMEGANVM_SendNVMRegAddress(XMEGA_NVM_REG_CMD); XPROGTarget_SendByte(WriteCommand); - + /* Send new memory byte to the memory of the target */ XPROGTarget_SendByte(PDI_CMD_STS | (PDI_DATSIZE_4BYTES << 2)); XMEGANVM_SendAddress(WriteAddress); XPROGTarget_SendByte(Byte); - + return true; } @@ -275,13 +275,13 @@ bool XMEGANVM_WritePageMemory(const uint8_t WriteBuffCommand, const uint8_t Eras /* Send the REPEAT command with the specified number of bytes to write */ XPROGTarget_SendByte(PDI_CMD_REPEAT | PDI_DATSIZE_1BYTE); XPROGTarget_SendByte(WriteSize - 1); - + /* Send a ST command with indirect access and post-increment to write the bytes */ XPROGTarget_SendByte(PDI_CMD_ST | (PDI_POINTER_INDIRECT_PI << 2) | PDI_DATSIZE_1BYTE); while (WriteSize--) XPROGTarget_SendByte(*(WriteBuffer++)); } - + if (PageMode & XPRG_PAGEMODE_WRITE) { /* Wait until the NVM controller is no longer busy */ @@ -292,7 +292,7 @@ bool XMEGANVM_WritePageMemory(const uint8_t WriteBuffCommand, const uint8_t Eras XPROGTarget_SendByte(PDI_CMD_STS | (PDI_DATSIZE_4BYTES << 2)); XMEGANVM_SendNVMRegAddress(XMEGA_NVM_REG_CMD); XPROGTarget_SendByte(WritePageCommand); - + /* Send the address of the first page location to write the memory page */ XPROGTarget_SendByte(PDI_CMD_STS | (PDI_DATSIZE_4BYTES << 2)); XMEGANVM_SendAddress(WriteAddress); @@ -322,11 +322,11 @@ bool XMEGANVM_EraseMemory(const uint8_t EraseCommand, const uint32_t Address) XPROGTarget_SendByte(PDI_CMD_STS | (PDI_DATSIZE_4BYTES << 2)); XMEGANVM_SendNVMRegAddress(XMEGA_NVM_REG_CMD); XPROGTarget_SendByte(EraseCommand); - + /* Set CMDEX bit in NVM CTRLA register to start the erase sequence */ XPROGTarget_SendByte(PDI_CMD_STS | (PDI_DATSIZE_4BYTES << 2)); XMEGANVM_SendNVMRegAddress(XMEGA_NVM_REG_CTRLA); - XPROGTarget_SendByte(1 << 0); + XPROGTarget_SendByte(1 << 0); } else if (EraseCommand == XMEGA_NVM_CMD_ERASEEEPROM) { @@ -356,21 +356,21 @@ bool XMEGANVM_EraseMemory(const uint8_t EraseCommand, const uint32_t Address) /* Send the REPEAT command with the specified number of bytes to write */ XPROGTarget_SendByte(PDI_CMD_REPEAT | PDI_DATSIZE_1BYTE); 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 */ XPROGTarget_SendByte(PDI_CMD_ST | (PDI_POINTER_INDIRECT_PI << 2) | PDI_DATSIZE_1BYTE); for (uint8_t PageByte = 0; PageByte < XPROG_Param_EEPageSize; PageByte++) XPROGTarget_SendByte(0x00); - + /* Send the memory erase command to the target */ XPROGTarget_SendByte(PDI_CMD_STS | (PDI_DATSIZE_4BYTES << 2)); XMEGANVM_SendNVMRegAddress(XMEGA_NVM_REG_CMD); XPROGTarget_SendByte(EraseCommand); - + /* Set CMDEX bit in NVM CTRLA register to start the EEPROM erase sequence */ XPROGTarget_SendByte(PDI_CMD_STS | (PDI_DATSIZE_4BYTES << 2)); XMEGANVM_SendNVMRegAddress(XMEGA_NVM_REG_CTRLA); - XPROGTarget_SendByte(1 << 0); + XPROGTarget_SendByte(1 << 0); } else { @@ -378,18 +378,19 @@ bool XMEGANVM_EraseMemory(const uint8_t EraseCommand, const uint32_t Address) XPROGTarget_SendByte(PDI_CMD_STS | (PDI_DATSIZE_4BYTES << 2)); XMEGANVM_SendNVMRegAddress(XMEGA_NVM_REG_CMD); XPROGTarget_SendByte(EraseCommand); - + /* Other erase modes just need us to address a byte within the target memory space */ XPROGTarget_SendByte(PDI_CMD_STS | (PDI_DATSIZE_4BYTES << 2)); XMEGANVM_SendAddress(Address); XPROGTarget_SendByte(0x00); } - + /* Wait until the NVM bus is ready again */ if (!(XMEGANVM_WaitWhileNVMBusBusy())) return false; - + return true; } #endif + diff --git a/Projects/AVRISP-MKII/Lib/XPROG/XMEGANVM.h b/Projects/AVRISP-MKII/Lib/XPROG/XMEGANVM.h index af38afdac..f65e88ad8 100644 --- a/Projects/AVRISP-MKII/Lib/XPROG/XMEGANVM.h +++ b/Projects/AVRISP-MKII/Lib/XPROG/XMEGANVM.h @@ -1,7 +1,7 @@ /* LUFA Library Copyright (C) Dean Camera, 2010. - + dean [at] fourwalledcubicle [dot] com www.fourwalledcubicle.com */ @@ -9,13 +9,13 @@ /* Copyright 2010 Dean Camera (dean [at] fourwalledcubicle [dot] com) - Permission to use, copy, modify, distribute, and sell this + Permission to use, copy, modify, distribute, and sell this software and its documentation for any purpose is hereby granted - without fee, provided that the above copyright notice appear in + without fee, provided that the above copyright notice appear in all copies and that both that the copyright notice and this - permission notice and warranty disclaimer appear in supporting - documentation, and that the name of the author not be used in - advertising or publicity pertaining to distribution of the + permission notice and warranty disclaimer appear in supporting + documentation, and that the name of the author not be used in + advertising or publicity pertaining to distribution of the software without specific, written prior permission. The author disclaim all warranties with regard to this @@ -40,16 +40,16 @@ #include <avr/io.h> #include <avr/interrupt.h> #include <stdbool.h> - + #include <LUFA/Common/Common.h> - + #include "XPROGProtocol.h" #include "XPROGTarget.h" - + /* Preprocessor Checks: */ #if ((BOARD == BOARD_XPLAIN) || (BOARD == BOARD_XPLAIN_REV1)) #undef ENABLE_ISP_PROTOCOL - + #if !defined(ENABLE_XPROG_PROTOCOL) #define ENABLE_XPROG_PROTOCOL #endif @@ -57,7 +57,7 @@ /* Defines: */ #define XMEGA_CRC_LENGTH 3 - + #define XMEGA_NVM_REG_ADDR0 0x00 #define XMEGA_NVM_REG_ADDR1 0x01 #define XMEGA_NVM_REG_ADDR2 0x02 @@ -70,7 +70,7 @@ #define XMEGA_NVM_REG_INTCTRL 0x0D #define XMEGA_NVM_REG_STATUS 0x0F #define XMEGA_NVM_REG_LOCKBITS 0x10 - + #define XMEGA_NVM_CMD_NOOP 0x00 #define XMEGA_NVM_CMD_CHIPERASE 0x40 #define XMEGA_NVM_CMD_READNVM 0x43 @@ -118,7 +118,8 @@ #if defined(INCLUDE_FROM_XMEGANVM_C) static void XMEGANVM_SendNVMRegAddress(const uint8_t Register); - static void XMEGANVM_SendAddress(const uint32_t AbsoluteAddress); + static void XMEGANVM_SendAddress(const uint32_t AbsoluteAddress); #endif #endif + diff --git a/Projects/AVRISP-MKII/Lib/XPROG/XPROGProtocol.c b/Projects/AVRISP-MKII/Lib/XPROG/XPROGProtocol.c index 85820fd31..edd362b48 100644 --- a/Projects/AVRISP-MKII/Lib/XPROG/XPROGProtocol.c +++ b/Projects/AVRISP-MKII/Lib/XPROG/XPROGProtocol.c @@ -1,7 +1,7 @@ /* LUFA Library Copyright (C) Dean Camera, 2010. - + dean [at] fourwalledcubicle [dot] com www.fourwalledcubicle.com */ @@ -9,13 +9,13 @@ /* Copyright 2010 Dean Camera (dean [at] fourwalledcubicle [dot] com) - Permission to use, copy, modify, distribute, and sell this + Permission to use, copy, modify, distribute, and sell this software and its documentation for any purpose is hereby granted - without fee, provided that the above copyright notice appear in + without fee, provided that the above copyright notice appear in all copies and that both that the copyright notice and this - permission notice and warranty disclaimer appear in supporting - documentation, and that the name of the author not be used in - advertising or publicity pertaining to distribution of the + permission notice and warranty disclaimer appear in supporting + documentation, and that the name of the author not be used in + advertising or publicity pertaining to distribution of the software without specific, written prior permission. The author disclaim all warranties with regard to this @@ -61,18 +61,18 @@ void XPROGProtocol_SetMode(void) { uint8_t Protocol; } SetMode_XPROG_Params; - + Endpoint_Read_Stream_LE(&SetMode_XPROG_Params, sizeof(SetMode_XPROG_Params), NO_STREAM_CALLBACK); Endpoint_ClearOUT(); Endpoint_SelectEndpoint(AVRISP_DATA_IN_EPNUM); Endpoint_SetEndpointDirection(ENDPOINT_DIR_IN); - + XPROG_SelectedProtocol = SetMode_XPROG_Params.Protocol; - + Endpoint_Write_Byte(CMD_XPROG_SETMODE); Endpoint_Write_Byte((SetMode_XPROG_Params.Protocol != XPRG_PROTOCOL_JTAG) ? STATUS_CMD_OK : STATUS_CMD_FAILED); - Endpoint_ClearIN(); + Endpoint_ClearIN(); } /** Handler for the CMD_XPROG command, which wraps up XPROG commands in a V2 wrapper which need to be @@ -81,7 +81,7 @@ void XPROGProtocol_SetMode(void) void XPROGProtocol_Command(void) { uint8_t XPROGCommand = Endpoint_Read_Byte(); - + switch (XPROGCommand) { case XPRG_CMD_ENTER_PROGMODE: @@ -114,7 +114,7 @@ static void XPROGProtocol_EnterXPROGMode(void) Endpoint_ClearOUT(); Endpoint_SelectEndpoint(AVRISP_DATA_IN_EPNUM); Endpoint_SetEndpointDirection(ENDPOINT_DIR_IN); - + bool NVMBusEnabled = false; if (XPROG_SelectedProtocol == XPRG_PROTOCOL_PDI) @@ -123,11 +123,11 @@ static void XPROGProtocol_EnterXPROGMode(void) XPROGTarget_EnableTargetPDI(); /* Store the RESET key into the RESET PDI register to keep the XMEGA in reset */ - XPROGTarget_SendByte(PDI_CMD_STCS | PDI_RESET_REG); + XPROGTarget_SendByte(PDI_CMD_STCS | PDI_RESET_REG); XPROGTarget_SendByte(PDI_RESET_KEY); /* Lower direction change guard time to 0 USART bits */ - XPROGTarget_SendByte(PDI_CMD_STCS | PDI_CTRL_REG); + XPROGTarget_SendByte(PDI_CMD_STCS | PDI_CTRL_REG); XPROGTarget_SendByte(0x07); /* Enable access to the XPROG NVM bus by sending the documented NVM access key to the device */ @@ -142,20 +142,20 @@ static void XPROGProtocol_EnterXPROGMode(void) { /* Enable TPI programming mode with the attached target */ XPROGTarget_EnableTargetTPI(); - + /* Lower direction change guard time to 0 USART bits */ XPROGTarget_SendByte(TPI_CMD_SSTCS | TPI_CTRL_REG); XPROGTarget_SendByte(0x07); - + /* Enable access to the XPROG NVM bus by sending the documented NVM access key to the device */ - XPROGTarget_SendByte(TPI_CMD_SKEY); + XPROGTarget_SendByte(TPI_CMD_SKEY); for (uint8_t i = sizeof(TPI_NVMENABLE_KEY); i > 0; i--) XPROGTarget_SendByte(TPI_NVMENABLE_KEY[i - 1]); /* Wait until the NVM bus becomes active */ NVMBusEnabled = TINYNVM_WaitWhileNVMBusBusy(); } - + Endpoint_Write_Byte(CMD_XPROG); Endpoint_Write_Byte(XPRG_CMD_ENTER_PROGMODE); Endpoint_Write_Byte(NVMBusEnabled ? XPRG_ERR_OK : XPRG_ERR_FAILED); @@ -170,17 +170,17 @@ static void XPROGProtocol_LeaveXPROGMode(void) Endpoint_ClearOUT(); Endpoint_SelectEndpoint(AVRISP_DATA_IN_EPNUM); Endpoint_SetEndpointDirection(ENDPOINT_DIR_IN); - + if (XPROG_SelectedProtocol == XPRG_PROTOCOL_PDI) { XMEGANVM_WaitWhileNVMBusBusy(); /* Clear the RESET key in the RESET PDI register to allow the XMEGA to run */ - XPROGTarget_SendByte(PDI_CMD_STCS | PDI_RESET_REG); + XPROGTarget_SendByte(PDI_CMD_STCS | PDI_RESET_REG); XPROGTarget_SendByte(0x00); /* Do it twice to make sure it takes affect (silicon bug?) */ - XPROGTarget_SendByte(PDI_CMD_STCS | PDI_RESET_REG); + XPROGTarget_SendByte(PDI_CMD_STCS | PDI_RESET_REG); XPROGTarget_SendByte(0x00); XPROGTarget_DisableTargetPDI(); @@ -190,12 +190,12 @@ static void XPROGProtocol_LeaveXPROGMode(void) TINYNVM_WaitWhileNVMBusBusy(); /* Clear the NVMEN bit in the TPI CONTROL register to disable TPI mode */ - XPROGTarget_SendByte(TPI_CMD_SSTCS | TPI_CTRL_REG); + XPROGTarget_SendByte(TPI_CMD_SSTCS | TPI_CTRL_REG); XPROGTarget_SendByte(0x00); - + XPROGTarget_DisableTargetTPI(); } - + Endpoint_Write_Byte(CMD_XPROG); Endpoint_Write_Byte(XPRG_CMD_LEAVE_PROGMODE); Endpoint_Write_Byte(XPRG_ERR_OK); @@ -219,11 +219,11 @@ static void XPROGProtocol_Erase(void) Endpoint_ClearOUT(); Endpoint_SelectEndpoint(AVRISP_DATA_IN_EPNUM); Endpoint_SetEndpointDirection(ENDPOINT_DIR_IN); - + uint8_t EraseCommand; if (XPROG_SelectedProtocol == XPRG_PROTOCOL_PDI) - { + { /* Determine which NVM command to send to the device depending on the memory to erase */ switch (Erase_XPROG_Params.MemoryType) { @@ -255,7 +255,7 @@ static void XPROGProtocol_Erase(void) EraseCommand = XMEGA_NVM_CMD_NOOP; break; } - + /* Erase the target memory, indicate timeout if occurred */ if (!(XMEGANVM_EraseMemory(EraseCommand, Erase_XPROG_Params.Address))) ReturnStatus = XPRG_ERR_TIMEOUT; @@ -266,16 +266,16 @@ static void XPROGProtocol_Erase(void) EraseCommand = TINY_NVM_CMD_CHIPERASE; else EraseCommand = TINY_NVM_CMD_SECTIONERASE; - + /* Erase the target memory, indicate timeout if occurred */ if (!(TINYNVM_EraseMemory(EraseCommand, Erase_XPROG_Params.Address))) ReturnStatus = XPRG_ERR_TIMEOUT; } - + Endpoint_Write_Byte(CMD_XPROG); Endpoint_Write_Byte(XPRG_CMD_ERASE); Endpoint_Write_Byte(ReturnStatus); - Endpoint_ClearIN(); + Endpoint_ClearIN(); } /** Handler for the XPROG WRITE_MEMORY command to write to a specific memory space within the attached device. */ @@ -291,7 +291,7 @@ static void XPROGProtocol_WriteMemory(void) uint16_t Length; uint8_t ProgData[256]; } WriteMemory_XPROG_Params; - + Endpoint_Read_Stream_LE(&WriteMemory_XPROG_Params, (sizeof(WriteMemory_XPROG_Params) - sizeof(WriteMemory_XPROG_Params).ProgData), NO_STREAM_CALLBACK); WriteMemory_XPROG_Params.Address = SwapEndian_32(WriteMemory_XPROG_Params.Address); @@ -309,7 +309,7 @@ static void XPROGProtocol_WriteMemory(void) uint8_t WriteBuffCommand = XMEGA_NVM_CMD_LOADFLASHPAGEBUFF; uint8_t EraseBuffCommand = XMEGA_NVM_CMD_ERASEFLASHPAGEBUFF; bool PagedMemory = true; - + switch (WriteMemory_XPROG_Params.MemoryType) { case XPRG_MEM_TYPE_APPL: @@ -321,7 +321,7 @@ static void XPROGProtocol_WriteMemory(void) case XPRG_MEM_TYPE_EEPROM: WriteCommand = XMEGA_NVM_CMD_ERASEWRITEEEPROMPAGE; WriteBuffCommand = XMEGA_NVM_CMD_LOADEEPROMPAGEBUFF; - EraseBuffCommand = XMEGA_NVM_CMD_ERASEEEPROMPAGEBUFF; + EraseBuffCommand = XMEGA_NVM_CMD_ERASEEEPROMPAGEBUFF; break; case XPRG_MEM_TYPE_USERSIG: WriteCommand = XMEGA_NVM_CMD_WRITEUSERSIG; @@ -335,9 +335,9 @@ static void XPROGProtocol_WriteMemory(void) PagedMemory = false; break; } - + /* Send the appropriate memory write commands to the device, indicate timeout if occurred */ - if ((PagedMemory && !(XMEGANVM_WritePageMemory(WriteBuffCommand, EraseBuffCommand, WriteCommand, + if ((PagedMemory && !(XMEGANVM_WritePageMemory(WriteBuffCommand, EraseBuffCommand, WriteCommand, WriteMemory_XPROG_Params.PageMode, WriteMemory_XPROG_Params.Address, WriteMemory_XPROG_Params.ProgData, WriteMemory_XPROG_Params.Length))) || (!PagedMemory && !(XMEGANVM_WriteByteMemory(WriteCommand, WriteMemory_XPROG_Params.Address, @@ -355,10 +355,10 @@ static void XPROGProtocol_WriteMemory(void) ReturnStatus = XPRG_ERR_TIMEOUT; } } - + Endpoint_Write_Byte(CMD_XPROG); Endpoint_Write_Byte(XPRG_CMD_WRITE_MEM); - Endpoint_Write_Byte(ReturnStatus); + Endpoint_Write_Byte(ReturnStatus); Endpoint_ClearIN(); } @@ -375,7 +375,7 @@ static void XPROGProtocol_ReadMemory(void) uint32_t Address; uint16_t Length; } ReadMemory_XPROG_Params; - + Endpoint_Read_Stream_LE(&ReadMemory_XPROG_Params, sizeof(ReadMemory_XPROG_Params), NO_STREAM_CALLBACK); ReadMemory_XPROG_Params.Address = SwapEndian_32(ReadMemory_XPROG_Params.Address); ReadMemory_XPROG_Params.Length = SwapEndian_16(ReadMemory_XPROG_Params.Length); @@ -385,7 +385,7 @@ static void XPROGProtocol_ReadMemory(void) Endpoint_SetEndpointDirection(ENDPOINT_DIR_IN); uint8_t ReadBuffer[256]; - + if (XPROG_SelectedProtocol == XPRG_PROTOCOL_PDI) { /* Read the PDI target's memory, indicate timeout if occurred */ @@ -402,10 +402,10 @@ static void XPROGProtocol_ReadMemory(void) Endpoint_Write_Byte(CMD_XPROG); Endpoint_Write_Byte(XPRG_CMD_READ_MEM); Endpoint_Write_Byte(ReturnStatus); - + if (ReturnStatus == XPRG_ERR_OK) Endpoint_Write_Stream_LE(ReadBuffer, ReadMemory_XPROG_Params.Length, NO_STREAM_CALLBACK); - + Endpoint_ClearIN(); } @@ -415,18 +415,18 @@ static void XPROGProtocol_ReadMemory(void) static void XPROGProtocol_ReadCRC(void) { uint8_t ReturnStatus = XPRG_ERR_OK; - + struct { uint8_t CRCType; } ReadCRC_XPROG_Params; - + Endpoint_Read_Stream_LE(&ReadCRC_XPROG_Params, sizeof(ReadCRC_XPROG_Params), NO_STREAM_CALLBACK); Endpoint_ClearOUT(); Endpoint_SelectEndpoint(AVRISP_DATA_IN_EPNUM); Endpoint_SetEndpointDirection(ENDPOINT_DIR_IN); - + uint32_t MemoryCRC; if (XPROG_SelectedProtocol == XPRG_PROTOCOL_PDI) @@ -446,7 +446,7 @@ static void XPROGProtocol_ReadCRC(void) CRCCommand = XMEGA_NVM_CMD_FLASHCRC; break; } - + /* Perform and retrieve the memory CRC, indicate timeout if occurred */ if (!(XMEGANVM_GetMemoryCRC(CRCCommand, &MemoryCRC))) ReturnStatus = XPRG_ERR_TIMEOUT; @@ -456,18 +456,18 @@ static void XPROGProtocol_ReadCRC(void) /* TPI does not support memory CRC */ ReturnStatus = XPRG_ERR_FAILED; } - + Endpoint_Write_Byte(CMD_XPROG); Endpoint_Write_Byte(XPRG_CMD_CRC); Endpoint_Write_Byte(ReturnStatus); - + if (ReturnStatus == XPRG_ERR_OK) { Endpoint_Write_Byte(MemoryCRC >> 16); - Endpoint_Write_Word_LE(MemoryCRC & 0xFFFF); + Endpoint_Write_Word_LE(MemoryCRC & 0xFFFF); } - - Endpoint_ClearIN(); + + Endpoint_ClearIN(); } /** Handler for the XPROG SET_PARAM command to set a XPROG parameter for use when communicating with the @@ -478,7 +478,7 @@ static void XPROGProtocol_SetParam(void) uint8_t ReturnStatus = XPRG_ERR_OK; uint8_t XPROGParam = Endpoint_Read_Byte(); - + /* Determine which parameter is being set, store the new parameter value */ switch (XPROGParam) { @@ -502,7 +502,7 @@ static void XPROGProtocol_SetParam(void) Endpoint_ClearOUT(); Endpoint_SelectEndpoint(AVRISP_DATA_IN_EPNUM); Endpoint_SetEndpointDirection(ENDPOINT_DIR_IN); - + Endpoint_Write_Byte(CMD_XPROG); Endpoint_Write_Byte(XPRG_CMD_SET_PARAM); Endpoint_Write_Byte(ReturnStatus); @@ -510,3 +510,4 @@ static void XPROGProtocol_SetParam(void) } #endif + diff --git a/Projects/AVRISP-MKII/Lib/XPROG/XPROGProtocol.h b/Projects/AVRISP-MKII/Lib/XPROG/XPROGProtocol.h index 978a5a2ab..a4a7a8413 100644 --- a/Projects/AVRISP-MKII/Lib/XPROG/XPROGProtocol.h +++ b/Projects/AVRISP-MKII/Lib/XPROG/XPROGProtocol.h @@ -1,7 +1,7 @@ /* LUFA Library Copyright (C) Dean Camera, 2010. - + dean [at] fourwalledcubicle [dot] com www.fourwalledcubicle.com */ @@ -9,13 +9,13 @@ /* Copyright 2010 Dean Camera (dean [at] fourwalledcubicle [dot] com) - Permission to use, copy, modify, distribute, and sell this + Permission to use, copy, modify, distribute, and sell this software and its documentation for any purpose is hereby granted - without fee, provided that the above copyright notice appear in + without fee, provided that the above copyright notice appear in all copies and that both that the copyright notice and this - permission notice and warranty disclaimer appear in supporting - documentation, and that the name of the author not be used in - advertising or publicity pertaining to distribution of the + permission notice and warranty disclaimer appear in supporting + documentation, and that the name of the author not be used in + advertising or publicity pertaining to distribution of the software without specific, written prior permission. The author disclaim all warranties with regard to this @@ -40,10 +40,10 @@ #include <avr/io.h> #include <util/delay.h> #include <stdio.h> - + #include <LUFA/Drivers/USB/USB.h> #include <LUFA/Drivers/Peripheral/SerialStream.h> - + #include "../V2Protocol.h" #include "XPROGTarget.h" #include "XMEGANVM.h" @@ -52,12 +52,12 @@ /* Preprocessor Checks: */ #if ((BOARD == BOARD_XPLAIN) || (BOARD == BOARD_XPLAIN_REV1)) #undef ENABLE_ISP_PROTOCOL - + #if !defined(ENABLE_XPROG_PROTOCOL) #define ENABLE_XPROG_PROTOCOL #endif #endif - + /* Macros: */ #define XPRG_CMD_ENTER_PROGMODE 0x01 #define XPRG_CMD_LEAVE_PROGMODE 0x02 @@ -100,25 +100,25 @@ #define XPRG_PARAM_EEPPAGESIZE 0x02 #define XPRG_PARAM_NVMCMD_REG 0x03 #define XPRG_PARAM_NVMCSR_REG 0x04 - + #define XPRG_PROTOCOL_PDI 0x00 #define XPRG_PROTOCOL_JTAG 0x01 #define XPRG_PROTOCOL_TPI 0x02 - + #define XPRG_PAGEMODE_WRITE (1 << 1) #define XPRG_PAGEMODE_ERASE (1 << 0) - + /* External Variables: */ extern uint32_t XPROG_Param_NVMBase; extern uint16_t XPROG_Param_EEPageSize; extern uint8_t XPROG_Param_NVMCSRRegAddr; extern uint8_t XPROG_Param_NVMCMDRegAddr; extern uint8_t XPROG_SelectedProtocol; - + /* Function Prototypes: */ void XPROGProtocol_SetMode(void); void XPROGProtocol_Command(void); - + #if (defined(INCLUDE_FROM_XPROGPROTOCOL_C) && defined(ENABLE_XPROG_PROTOCOL)) static void XPROGProtocol_EnterXPROGMode(void); static void XPROGProtocol_LeaveXPROGMode(void); @@ -128,5 +128,6 @@ static void XPROGProtocol_ReadMemory(void); static void XPROGProtocol_ReadCRC(void); #endif - + #endif + diff --git a/Projects/AVRISP-MKII/Lib/XPROG/XPROGTarget.c b/Projects/AVRISP-MKII/Lib/XPROG/XPROGTarget.c index 2e5200561..28cb6abca 100644 --- a/Projects/AVRISP-MKII/Lib/XPROG/XPROGTarget.c +++ b/Projects/AVRISP-MKII/Lib/XPROG/XPROGTarget.c @@ -1,7 +1,7 @@ /* LUFA Library Copyright (C) Dean Camera, 2010. - + dean [at] fourwalledcubicle [dot] com www.fourwalledcubicle.com */ @@ -9,13 +9,13 @@ /* Copyright 2010 Dean Camera (dean [at] fourwalledcubicle [dot] com) - Permission to use, copy, modify, distribute, and sell this + Permission to use, copy, modify, distribute, and sell this software and its documentation for any purpose is hereby granted - without fee, provided that the above copyright notice appear in + without fee, provided that the above copyright notice appear in all copies and that both that the copyright notice and this - permission notice and warranty disclaimer appear in supporting - documentation, and that the name of the author not be used in - advertising or publicity pertaining to distribution of the + permission notice and warranty disclaimer appear in supporting + documentation, and that the name of the author not be used in + advertising or publicity pertaining to distribution of the software without specific, written prior permission. The author disclaim all warranties with regard to this @@ -49,11 +49,11 @@ void XPROGTarget_EnableTargetPDI(void) /* Set Tx and XCK as outputs, Rx as input */ DDRD |= (1 << 5) | (1 << 3); DDRD &= ~(1 << 2); - + /* Set DATA line high for at least 90ns to disable /RESET functionality */ PORTD |= (1 << 3); _delay_us(1); - + /* Set up the synchronous USART for XMEGA communications - 8 data bits, even parity, 2 stop bits */ UBRR1 = (F_CPU / XPROG_HARDWARE_SPEED); UCSR1B = (1 << TXEN1); @@ -77,7 +77,7 @@ void XPROGTarget_EnableTargetTPI(void) /* Set Tx and XCK as outputs, Rx as input */ DDRD |= (1 << 5) | (1 << 3); DDRD &= ~(1 << 2); - + /* Set up the synchronous USART for TINY communications - 8 data bits, even parity, 2 stop bits */ UBRR1 = (F_CPU / XPROG_HARDWARE_SPEED); UCSR1B = (1 << TXEN1); @@ -133,7 +133,7 @@ void XPROGTarget_SendByte(const uint8_t Byte) /* Switch to Tx mode if currently in Rx mode */ if (!(IsSending)) XPROGTarget_SetTxMode(); - + /* Wait until there is space in the hardware Tx buffer before writing */ while (!(UCSR1A & (1 << UDRE1))); UCSR1A |= (1 << TXC1); @@ -202,3 +202,4 @@ static void XPROGTarget_SetRxMode(void) } #endif + diff --git a/Projects/AVRISP-MKII/Lib/XPROG/XPROGTarget.h b/Projects/AVRISP-MKII/Lib/XPROG/XPROGTarget.h index 0e5d373ef..6aedea6fb 100644 --- a/Projects/AVRISP-MKII/Lib/XPROG/XPROGTarget.h +++ b/Projects/AVRISP-MKII/Lib/XPROG/XPROGTarget.h @@ -1,7 +1,7 @@ /* LUFA Library Copyright (C) Dean Camera, 2010. - + dean [at] fourwalledcubicle [dot] com www.fourwalledcubicle.com */ @@ -9,13 +9,13 @@ /* Copyright 2010 Dean Camera (dean [at] fourwalledcubicle [dot] com) - Permission to use, copy, modify, distribute, and sell this + Permission to use, copy, modify, distribute, and sell this software and its documentation for any purpose is hereby granted - without fee, provided that the above copyright notice appear in + without fee, provided that the above copyright notice appear in all copies and that both that the copyright notice and this - permission notice and warranty disclaimer appear in supporting - documentation, and that the name of the author not be used in - advertising or publicity pertaining to distribution of the + permission notice and warranty disclaimer appear in supporting + documentation, and that the name of the author not be used in + advertising or publicity pertaining to distribution of the software without specific, written prior permission. The author disclaim all warranties with regard to this @@ -40,27 +40,27 @@ #include <avr/io.h> #include <avr/interrupt.h> #include <stdbool.h> - + #include <LUFA/Common/Common.h> - + #include "../V2Protocol.h" #include "XPROGProtocol.h" - + /* Preprocessor Checks: */ #if ((BOARD == BOARD_XPLAIN) || (BOARD == BOARD_XPLAIN_REV1)) #undef ENABLE_ISP_PROTOCOL - + #if !defined(ENABLE_XPROG_PROTOCOL) #define ENABLE_XPROG_PROTOCOL #endif #endif - + /** Serial carrier TPI/PDI speed when hardware TPI/PDI mode is used. */ #define XPROG_HARDWARE_SPEED 500000 /** Total number of bits in a single USART frame. */ #define BITS_IN_USART_FRAME 12 - + #define PDI_CMD_LDS 0x00 #define PDI_CMD_LD 0x20 #define PDI_CMD_STS 0x40 @@ -69,11 +69,11 @@ #define PDI_CMD_REPEAT 0xA0 #define PDI_CMD_STCS 0xC0 #define PDI_CMD_KEY 0xE0 - + #define PDI_STATUS_REG 0 #define PDI_RESET_REG 1 #define PDI_CTRL_REG 2 - + #define PDI_STATUS_NVM (1 << 1) #define PDI_RESET_KEY 0x59 @@ -83,7 +83,7 @@ #define PDI_DATSIZE_2BYTES 1 #define PDI_DATSIZE_3BYTES 2 #define PDI_DATSIZE_4BYTES 3 - + #define PDI_POINTER_INDIRECT 0 #define PDI_POINTER_INDIRECT_PI 1 #define PDI_POINTER_DIRECT 2 @@ -100,14 +100,14 @@ #define TPI_STATUS_REG 0x00 #define TPI_CTRL_REG 0x02 #define TPI_ID_REG 0x0F - + #define TPI_STATUS_NVM (1 << 1) #define TPI_NVMENABLE_KEY (uint8_t[]){0x12, 0x89, 0xAB, 0x45, 0xCD, 0xD8, 0x88, 0xFF} #define TPI_POINTER_INDIRECT 0 #define TPI_POINTER_INDIRECT_PI 4 - + /* Function Prototypes: */ void XPROGTarget_EnableTargetPDI(void); void XPROGTarget_EnableTargetTPI(void); @@ -117,10 +117,11 @@ uint8_t XPROGTarget_ReceiveByte(void); void XPROGTarget_SendBreak(void); bool XPROGTarget_WaitWhileNVMBusBusy(void); - + #if (defined(INCLUDE_FROM_XPROGTARGET_C) && defined(ENABLE_XPROG_PROTOCOL)) static void XPROGTarget_SetTxMode(void); static void XPROGTarget_SetRxMode(void); #endif #endif + |