From bd5e8f07b71b4fa0c058c0edfa8ff3f59ab31610 Mon Sep 17 00:00:00 2001 From: Dean Camera Date: Wed, 23 Dec 2009 13:28:44 +0000 Subject: Stub out more of the TPI programming protocol routines in the AVRISP project. --- Projects/AVRISP/Lib/ISPProtocol.c | 14 +++++----- Projects/AVRISP/Lib/ISPProtocol.h | 20 ++++++++++++++ Projects/AVRISP/Lib/ISPTarget.c | 2 +- Projects/AVRISP/Lib/TPIProtocol.c | 44 +++++++++++++++++++++++++++++ Projects/AVRISP/Lib/TPIProtocol.h | 58 +++++++++++++++++++++++++++++++++++++++ Projects/AVRISP/Lib/TPITarget.c | 22 +++++++++++++-- Projects/AVRISP/Lib/TPITarget.h | 18 ++++++++++++ Projects/AVRISP/Lib/V2Protocol.c | 3 ++ Projects/AVRISP/Lib/V2Protocol.h | 23 ++-------------- 9 files changed, 173 insertions(+), 31 deletions(-) create mode 100644 Projects/AVRISP/Lib/TPIProtocol.c create mode 100644 Projects/AVRISP/Lib/TPIProtocol.h (limited to 'Projects/AVRISP/Lib') diff --git a/Projects/AVRISP/Lib/ISPProtocol.c b/Projects/AVRISP/Lib/ISPProtocol.c index 9b8666afb..e769cee8a 100644 --- a/Projects/AVRISP/Lib/ISPProtocol.c +++ b/Projects/AVRISP/Lib/ISPProtocol.c @@ -63,7 +63,7 @@ void ISPProtocol_EnterISPMode(void) CurrentAddress = 0; - V2Protocol_DelayMS(Enter_ISP_Params.ExecutionDelayMS); + ISPProtocol_DelayMS(Enter_ISP_Params.ExecutionDelayMS); SPI_Init(ISPTarget_GetSPIPrescalerMask() | SPI_SCK_LEAD_RISING | SPI_SAMPLE_LEADING | SPI_MODE_MASTER); while (Enter_ISP_Params.SynchLoops-- && (ResponseStatus == STATUS_CMD_FAILED)) @@ -71,11 +71,11 @@ void ISPProtocol_EnterISPMode(void) uint8_t ResponseBytes[4]; ISPTarget_ChangeTargetResetLine(true); - V2Protocol_DelayMS(Enter_ISP_Params.PinStabDelayMS); + ISPProtocol_DelayMS(Enter_ISP_Params.PinStabDelayMS); for (uint8_t RByte = 0; RByte < sizeof(ResponseBytes); RByte++) { - V2Protocol_DelayMS(Enter_ISP_Params.ByteDelay); + ISPProtocol_DelayMS(Enter_ISP_Params.ByteDelay); ResponseBytes[RByte] = SPI_TransferByte(Enter_ISP_Params.EnterProgBytes[RByte]); } @@ -87,7 +87,7 @@ void ISPProtocol_EnterISPMode(void) else { ISPTarget_ChangeTargetResetLine(false); - V2Protocol_DelayMS(Enter_ISP_Params.PinStabDelayMS); + ISPProtocol_DelayMS(Enter_ISP_Params.PinStabDelayMS); } } @@ -110,10 +110,10 @@ void ISPProtocol_LeaveISPMode(void) Endpoint_ClearOUT(); Endpoint_SetEndpointDirection(ENDPOINT_DIR_IN); - V2Protocol_DelayMS(Leave_ISP_Params.PreDelayMS); + ISPProtocol_DelayMS(Leave_ISP_Params.PreDelayMS); ISPTarget_ChangeTargetResetLine(false); SPI_ShutDown(); - V2Protocol_DelayMS(Leave_ISP_Params.PostDelayMS); + ISPProtocol_DelayMS(Leave_ISP_Params.PostDelayMS); Endpoint_Write_Byte(CMD_LEAVE_PROGMODE_ISP); Endpoint_Write_Byte(STATUS_CMD_OK); @@ -357,7 +357,7 @@ void ISPProtocol_ChipErase(void) SPI_SendByte(Erase_Chip_Params.EraseCommandBytes[SByte]); if (!(Erase_Chip_Params.PollMethod)) - V2Protocol_DelayMS(Erase_Chip_Params.EraseDelayMS); + ISPProtocol_DelayMS(Erase_Chip_Params.EraseDelayMS); else ResponseStatus = ISPTarget_WaitWhileTargetBusy(); diff --git a/Projects/AVRISP/Lib/ISPProtocol.h b/Projects/AVRISP/Lib/ISPProtocol.h index 4bbffbbd1..85a669a4e 100644 --- a/Projects/AVRISP/Lib/ISPProtocol.h +++ b/Projects/AVRISP/Lib/ISPProtocol.h @@ -64,6 +64,26 @@ #define PROG_MODE_PAGED_READYBUSY_MASK (1 << 6) #define PROG_MODE_COMMIT_PAGE_MASK (1 << 7) + /* Inline Functions: */ + /** Blocking delay for a given number of milliseconds, via a hardware timer. + * + * \param[in] DelayMS Number of milliseconds to delay for + */ + static inline void ISPProtocol_DelayMS(uint8_t DelayMS) + { + TCNT0 = 0; + TIFR0 = (1 << OCF1A); + + while (DelayMS) + { + if (TIFR0 & (1 << OCF1A)) + { + TIFR0 = (1 << OCF1A); + DelayMS--; + } + } + } + /* Function Prototypes: */ void ISPProtocol_EnterISPMode(void); void ISPProtocol_LeaveISPMode(void); diff --git a/Projects/AVRISP/Lib/ISPTarget.c b/Projects/AVRISP/Lib/ISPTarget.c index ce364c6cc..e99e3e53c 100644 --- a/Projects/AVRISP/Lib/ISPTarget.c +++ b/Projects/AVRISP/Lib/ISPTarget.c @@ -118,7 +118,7 @@ uint8_t ISPTarget_WaitForProgComplete(const uint8_t ProgrammingMode, const uint1 { case PROG_MODE_WORD_TIMEDELAY_MASK: case PROG_MODE_PAGED_TIMEDELAY_MASK: - V2Protocol_DelayMS(DelayMS); + ISPProtocol_DelayMS(DelayMS); break; case PROG_MODE_WORD_VALUE_MASK: case PROG_MODE_PAGED_VALUE_MASK: diff --git a/Projects/AVRISP/Lib/TPIProtocol.c b/Projects/AVRISP/Lib/TPIProtocol.c new file mode 100644 index 000000000..a95e94b60 --- /dev/null +++ b/Projects/AVRISP/Lib/TPIProtocol.c @@ -0,0 +1,44 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2009. + + dean [at] fourwalledcubicle [dot] com + www.fourwalledcubicle.com +*/ + +/* + Copyright 2009 Dean Camera (dean [at] fourwalledcubicle [dot] com) + + Permission to use, copy, modify, and distribute this software + and its documentation for any purpose and without fee is hereby + granted, 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 + software without specific, written prior permission. + + The author disclaim all warranties with regard to this + software, including all implied warranties of merchantability + and fitness. In no event shall the author be liable for any + special, indirect or consequential damages or any damages + whatsoever resulting from loss of use, data or profits, whether + in an action of contract, negligence or other tortious action, + arising out of or in connection with the use or performance of + this software. +*/ + +/** \file + * + * TPI Protocol handler, to process V2 Protocol wrapped TPI commands used in Atmel programmer devices. + */ + +#define INCLUDE_FROM_TPIPROTOCOL_C +#include "TPIProtocol.h" + +#if defined(ENABLE_TPI_PROTOCOL) || defined(__DOXYGEN__) +#warning TPI Programming Protocol is currently incomplete and is not suitable for general use. + +// TODO + +#endif diff --git a/Projects/AVRISP/Lib/TPIProtocol.h b/Projects/AVRISP/Lib/TPIProtocol.h new file mode 100644 index 000000000..2b6849c1e --- /dev/null +++ b/Projects/AVRISP/Lib/TPIProtocol.h @@ -0,0 +1,58 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2009. + + dean [at] fourwalledcubicle [dot] com + www.fourwalledcubicle.com +*/ + +/* + Copyright 2009 Dean Camera (dean [at] fourwalledcubicle [dot] com) + + Permission to use, copy, modify, and distribute this software + and its documentation for any purpose and without fee is hereby + granted, 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 + software without specific, written prior permission. + + The author disclaim all warranties with regard to this + software, including all implied warranties of merchantability + and fitness. In no event shall the author be liable for any + special, indirect or consequential damages or any damages + whatsoever resulting from loss of use, data or profits, whether + in an action of contract, negligence or other tortious action, + arising out of or in connection with the use or performance of + this software. +*/ + +/** \file + * + * Header file for TPIProtocol.c. + */ + +#ifndef _TPI_PROTOCOL_ +#define _TPI_PROTOCOL_ + + /* Includes: */ + #include + #include + #include + + #include "V2Protocol.h" + #include "TPITarget.h" + #include "TINYNVM.h" + + /* Preprocessor Checks: */ + #if ((BOARD == BOARD_XPLAIN) || (BOARD == BOARD_XPLAIN_REV1)) + #undef ENABLE_ISP_PROTOCOL + #undef ENABLE_TPI_PROTOCOL + + #if !defined(ENABLE_PDI_PROTOCOL) + #define ENABLE_PDI_PROTOCOL + #endif + #endif + +#endif diff --git a/Projects/AVRISP/Lib/TPITarget.c b/Projects/AVRISP/Lib/TPITarget.c index 8b47006c9..464d40305 100644 --- a/Projects/AVRISP/Lib/TPITarget.c +++ b/Projects/AVRISP/Lib/TPITarget.c @@ -312,8 +312,26 @@ void TPITarget_SendBreak(void) */ bool TPITarget_WaitWhileNVMBusBusy(void) { - // TODO - + TCNT0 = 0; + TIFR0 = (1 << OCF1A); + + uint8_t TimeoutMS = TPI_NVM_TIMEOUT_MS; + + /* Poll the STATUS register to check to see if NVM access has been enabled */ + while (TimeoutMS) + { + /* Send the LDCS command to read the TPI STATUS register to see the NVM bus is active */ + TPITarget_SendByte(TPI_CMD_SLDCS | TPI_STATUS_REG); + if (TPITarget_ReceiveByte() & TPI_STATUS_NVM) + return true; + + if (TIFR0 & (1 << OCF1A)) + { + TIFR0 = (1 << OCF1A); + TimeoutMS--; + } + } + return false; } diff --git a/Projects/AVRISP/Lib/TPITarget.h b/Projects/AVRISP/Lib/TPITarget.h index 715af16d1..e11e07551 100644 --- a/Projects/AVRISP/Lib/TPITarget.h +++ b/Projects/AVRISP/Lib/TPITarget.h @@ -68,7 +68,25 @@ #define TPI_NVM_TIMEOUT_MS 200 + #define TPI_CMD_SLD 0x20 + #define TPI_CMD_SST 0x60 + #define TPI_CMD_SSTPR 0x68 + #define TPI_CMD_SIN 0x10 + #define TPI_CMD_SOUT 0x90 + #define TPI_CMD_SLDCS 0x80 + #define TPI_CMD_SSTCS 0xC0 + #define TPI_CMD_SKEY 0xE0 + + #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 (1 << 2) /* Function Prototypes: */ void TPITarget_EnableTargetTPI(void); diff --git a/Projects/AVRISP/Lib/V2Protocol.c b/Projects/AVRISP/Lib/V2Protocol.c index 4bd1162a3..3bfcc11af 100644 --- a/Projects/AVRISP/Lib/V2Protocol.c +++ b/Projects/AVRISP/Lib/V2Protocol.c @@ -105,6 +105,9 @@ void V2Protocol_ProcessCommand(void) case CMD_XPROG: PDIProtocol_XPROG_Command(); break; +#endif +#if defined(ENABLE_TPI_PROTOCOL) + // TODO #endif default: V2Protocol_UnknownCommand(V2Command); diff --git a/Projects/AVRISP/Lib/V2Protocol.h b/Projects/AVRISP/Lib/V2Protocol.h index 4ea1cba19..b43ae89c5 100644 --- a/Projects/AVRISP/Lib/V2Protocol.h +++ b/Projects/AVRISP/Lib/V2Protocol.h @@ -45,6 +45,7 @@ #include "V2ProtocolParams.h" #include "ISPProtocol.h" #include "PDIProtocol.h" + #include "TPIProtocol.h" /* Preprocessor Checks: */ #if ((BOARD == BOARD_XPLAIN) || (BOARD == BOARD_XPLAIN_REV1)) @@ -61,27 +62,7 @@ #define PROGRAMMER_ID "AVRISP_MK2" /** Timeout in milliseconds of target busy-wait loops waiting for a command to complete */ - #define TARGET_BUSY_TIMEOUT_MS 240 - - /* Inline Functions: */ - /** Blocking delay for a given number of milliseconds, via a hardware timer. - * - * \param[in] DelayMS Number of milliseconds to delay for - */ - static inline void V2Protocol_DelayMS(uint8_t DelayMS) - { - TCNT0 = 0; - TIFR0 = (1 << OCF1A); - - while (DelayMS) - { - if (TIFR0 & (1 << OCF1A)) - { - TIFR0 = (1 << OCF1A); - DelayMS--; - } - } - } + #define TARGET_BUSY_TIMEOUT_MS 240 /* External Variables: */ extern uint32_t CurrentAddress; -- cgit v1.2.3