Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Erik Strand
lufa
Commits
9decc2bc
Commit
9decc2bc
authored
Dec 24, 2009
by
Dean Camera
Browse files
Combine PDIProtocol and TPIProtocol into a single XPROGProtocol set of files.
parent
05fcf7e2
Changes
15
Hide whitespace changes
Inline
Side-by-side
Projects/AVRISP/AVRISP.txt
View file @
9decc2bc
...
...
@@ -243,29 +243,16 @@
* <td>Define to enable SPI programming protocol support. <i>Ignored when compiled for the XPLAIN board.</i></td>
* </tr>
* <tr>
* <td>ENABLE_
PDI
_PROTOCOL</td>
* <td>ENABLE_
XPROG
_PROTOCOL</td>
* <td>Makefile CDEFS</td>
* <td>Define to enable
XMEGA PD
I programming protocol support. <i>Ignored when compiled for the XPLAIN board.</i></td>
* <td>Define to enable
PDI and TP
I programming protocol support. <i>Ignored when compiled for the XPLAIN board.</i></td>
* </tr>
* <tr>
* <td>
ENABLE_TPI_PROTOCOL
</td>
* <td>
XPROG_VIA_HARDWARE_USART
</td>
* <td>Makefile CDEFS</td>
* <td>Define to enable 6-PIN ATTINY TPI programming protocol support. <i>Ignored when compiled for the XPLAIN board.</i></td>
* </tr>
* <tr>
* <td>PDI_VIA_HARDWARE_USART</td>
* <td>Makefile CDEFS</td>
* <td>Define to force the PDI protocol (when enabled) to use the much faster hardware USART instead of bit-banging to
* match the official AVRISP pinout. This breaks pinout compatibility with the official AVRISP MKII (and requires
* seperate ISP and PDI programming headers) but increases programming speed dramatically.
* <i>Ignored when compiled for the XPLAIN board.</i></td>
* </tr>
* <tr>
* <td>TPI_VIA_HARDWARE_USART</td>
* <td>Makefile CDEFS</td>
* <td>Define to force the TPI protocol (when enabled) to use the much faster hardware USART instead of bit-banging to
* <td>Define to force the PDI and TPI protocols (when enabled) to use the much faster hardware USART instead of bit-banging to
* match the official AVRISP pinout. This breaks pinout compatibility with the official AVRISP MKII (and requires
* seperate ISP and TPI programming headers) but increases programming speed dramatically.
* seperate ISP and
PDI/
TPI programming headers) but increases programming speed dramatically.
* <i>Ignored when compiled for the XPLAIN board.</i></td>
* </tr>
* </table>
...
...
Projects/AVRISP/Lib/ISP/ISPProtocol.h
View file @
9decc2bc
...
...
@@ -46,10 +46,9 @@
/* 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
#if !defined(ENABLE_
XPROG
_PROTOCOL)
#define ENABLE_
XPROG
_PROTOCOL
#endif
#endif
...
...
Projects/AVRISP/Lib/ISP/ISPTarget.h
View file @
9decc2bc
...
...
@@ -48,10 +48,9 @@
/* 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
#if !defined(ENABLE_
XPROG
_PROTOCOL)
#define ENABLE_
XPROG
_PROTOCOL
#endif
#endif
...
...
Projects/AVRISP/Lib/V2Protocol.c
View file @
9decc2bc
...
...
@@ -100,16 +100,13 @@ void V2Protocol_ProcessCommand(void)
ISPProtocol_SPIMulti
();
break
;
#endif
#if defined(ENABLE_
PDI
_PROTOCOL)
#if defined(ENABLE_
XPROG
_PROTOCOL)
case
CMD_XPROG_SETMODE
:
PDI
Protocol_
XPROG_
SetMode
();
XPROG
Protocol_SetMode
();
break
;
case
CMD_XPROG
:
PDI
Protocol_
XPROG_
Command
();
XPROG
Protocol_Command
();
break
;
#endif
#if defined(ENABLE_TPI_PROTOCOL)
// TODO
#endif
default:
V2Protocol_UnknownCommand
(
V2Command
);
...
...
Projects/AVRISP/Lib/XPROG/PDITarget.c
View file @
9decc2bc
...
...
@@ -36,12 +36,12 @@
#define INCLUDE_FROM_PDITARGET_C
#include "PDITarget.h"
#if defined(ENABLE_
PDI
_PROTOCOL) || defined(__DOXYGEN__)
#if defined(ENABLE_
XPROG
_PROTOCOL) || defined(__DOXYGEN__)
/** Flag to indicate if the USART is currently in Tx or Rx mode. */
volatile
bool
IsSending
;
#if !defined(
PDI
_VIA_HARDWARE_USART)
#if !defined(
XPROG
_VIA_HARDWARE_USART)
/** Software USART raw frame bits for transmission/reception. */
volatile
uint16_t
SoftUSART_Data
;
...
...
@@ -99,7 +99,7 @@ ISR(TIMER1_COMPA_vect, ISR_BLOCK)
/** Enables the target's PDI interface, holding the target in reset until PDI mode is exited. */
void
PDITarget_EnableTargetPDI
(
void
)
{
#if defined(
PDI
_VIA_HARDWARE_USART)
#if defined(
XPROG
_VIA_HARDWARE_USART)
/* Set Tx and XCK as outputs, Rx as input */
DDRD
|=
(
1
<<
5
)
|
(
1
<<
3
);
DDRD
&=
~
(
1
<<
2
);
...
...
@@ -142,7 +142,7 @@ void PDITarget_EnableTargetPDI(void)
/** Disables the target's PDI interface, exits programming mode and starts the target's application. */
void
PDITarget_DisableTargetPDI
(
void
)
{
#if defined(
PDI
_VIA_HARDWARE_USART)
#if defined(
XPROG
_VIA_HARDWARE_USART)
/* Turn off receiver and transmitter of the USART, clear settings */
UCSR1A
|=
(
1
<<
TXC1
)
|
(
1
<<
RXC1
);
UCSR1B
=
0
;
...
...
@@ -168,7 +168,7 @@ void PDITarget_DisableTargetPDI(void)
*/
void
PDITarget_SendByte
(
const
uint8_t
Byte
)
{
#if defined(
PDI
_VIA_HARDWARE_USART)
#if defined(
XPROG
_VIA_HARDWARE_USART)
/* Switch to Tx mode if currently in Rx mode */
if
(
!
(
IsSending
))
{
...
...
@@ -221,7 +221,7 @@ void PDITarget_SendByte(const uint8_t Byte)
*/
uint8_t
PDITarget_ReceiveByte
(
void
)
{
#if defined(
PDI
_VIA_HARDWARE_USART)
#if defined(
XPROG
_VIA_HARDWARE_USART)
/* Switch to Rx mode if currently in Tx mode */
if
(
IsSending
)
{
...
...
@@ -264,7 +264,7 @@ uint8_t PDITarget_ReceiveByte(void)
/** Sends a BREAK via the USART to the attached target, consisting of a full frame of idle bits. */
void
PDITarget_SendBreak
(
void
)
{
#if defined(
PDI
_VIA_HARDWARE_USART)
#if defined(
XPROG
_VIA_HARDWARE_USART)
/* Switch to Tx mode if currently in Rx mode */
if
(
!
(
IsSending
))
{
...
...
Projects/AVRISP/Lib/XPROG/PDITarget.h
View file @
9decc2bc
...
...
@@ -46,16 +46,15 @@
/* 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
#if !defined(ENABLE_
XPROG
_PROTOCOL)
#define ENABLE_
XPROG
_PROTOCOL
#endif
#endif
/* Defines: */
#if ((BOARD == BOARD_XPLAIN) || (BOARD == BOARD_XPLAIN_REV1))
#define
PDI
_VIA_HARDWARE_USART
#define
XPROG
_VIA_HARDWARE_USART
#else
#define BITBANG_PDIDATA_PORT PORTB
#define BITBANG_PDIDATA_DDR DDRB
...
...
Projects/AVRISP/Lib/XPROG/TINYNVM.c
View file @
9decc2bc
...
...
@@ -36,7 +36,7 @@
#define INCLUDE_FROM_TINYNVM_C
#include "TINYNVM.h"
#if defined(ENABLE_
TPI
_PROTOCOL) || defined(__DOXYGEN__)
#if defined(ENABLE_
XPROG
_PROTOCOL) || defined(__DOXYGEN__)
// TODO
...
...
Projects/AVRISP/Lib/XPROG/TINYNVM.h
View file @
9decc2bc
...
...
@@ -49,10 +49,9 @@
/* 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
#if !defined(ENABLE_
XPROG
_PROTOCOL)
#define ENABLE_
XPROG
_PROTOCOL
#endif
#endif
...
...
Projects/AVRISP/Lib/XPROG/TPITarget.c
View file @
9decc2bc
...
...
@@ -36,12 +36,12 @@
#define INCLUDE_FROM_TPITARGET_C
#include "TPITarget.h"
#if defined(ENABLE_
TPI
_PROTOCOL) || defined(__DOXYGEN__)
#if defined(ENABLE_
XPROG
_PROTOCOL) || defined(__DOXYGEN__)
/** Flag to indicate if the USART is currently in Tx or Rx mode. */
volatile
bool
IsSending
;
#if !defined(
TPI
_VIA_HARDWARE_USART)
#if !defined(
XPROG
_VIA_HARDWARE_USART)
/** Software USART raw frame bits for transmission/reception. */
volatile
uint16_t
SoftUSART_Data
;
...
...
@@ -105,7 +105,7 @@ void TPITarget_EnableTargetTPI(void)
asm
volatile
(
"NOP"
::
);
asm
volatile
(
"NOP"
::
);
#if defined(
TPI
_VIA_HARDWARE_USART)
#if defined(
XPROG
_VIA_HARDWARE_USART)
/* Set Tx and XCK as outputs, Rx as input */
DDRD
|=
(
1
<<
5
)
|
(
1
<<
3
);
DDRD
&=
~
(
1
<<
2
);
...
...
@@ -141,7 +141,7 @@ void TPITarget_EnableTargetTPI(void)
/** Disables the target's TPI interface, exits programming mode and starts the target's application. */
void
TPITarget_DisableTargetTPI
(
void
)
{
#if defined(
TPI
_VIA_HARDWARE_USART)
#if defined(
XPROG
_VIA_HARDWARE_USART)
/* Turn off receiver and transmitter of the USART, clear settings */
UCSR1A
|=
(
1
<<
TXC1
)
|
(
1
<<
RXC1
);
UCSR1B
=
0
;
...
...
@@ -171,7 +171,7 @@ void TPITarget_DisableTargetTPI(void)
*/
void
TPITarget_SendByte
(
const
uint8_t
Byte
)
{
#if defined(
TPI
_VIA_HARDWARE_USART)
#if defined(
XPROG
_VIA_HARDWARE_USART)
/* Switch to Tx mode if currently in Rx mode */
if
(
!
(
IsSending
))
{
...
...
@@ -224,7 +224,7 @@ void TPITarget_SendByte(const uint8_t Byte)
*/
uint8_t
TPITarget_ReceiveByte
(
void
)
{
#if defined(
TPI
_VIA_HARDWARE_USART)
#if defined(
XPROG
_VIA_HARDWARE_USART)
/* Switch to Rx mode if currently in Tx mode */
if
(
IsSending
)
{
...
...
@@ -267,7 +267,7 @@ uint8_t TPITarget_ReceiveByte(void)
/** Sends a BREAK via the USART to the attached target, consisting of a full frame of idle bits. */
void
TPITarget_SendBreak
(
void
)
{
#if defined(
TPI
_VIA_HARDWARE_USART)
#if defined(
XPROG
_VIA_HARDWARE_USART)
/* Switch to Tx mode if currently in Rx mode */
if
(
!
(
IsSending
))
{
...
...
Projects/AVRISP/Lib/XPROG/TPITarget.h
View file @
9decc2bc
...
...
@@ -46,10 +46,9 @@
/* 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
#if !defined(ENABLE_
XPROG
_PROTOCOL)
#define ENABLE_
XPROG
_PROTOCOL
#endif
#endif
...
...
Projects/AVRISP/Lib/XPROG/XMEGANVM.c
View file @
9decc2bc
...
...
@@ -36,7 +36,7 @@
#define INCLUDE_FROM_XMEGA_NVM_C
#include "XMEGANVM.h"
#if defined(ENABLE_
PDI
_PROTOCOL) || defined(__DOXYGEN__)
#if defined(ENABLE_
XPROG
_PROTOCOL) || defined(__DOXYGEN__)
/** Sends the given NVM register address to the target.
*
...
...
Projects/AVRISP/Lib/XPROG/XMEGANVM.h
View file @
9decc2bc
...
...
@@ -49,10 +49,9 @@
/* 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
#if !defined(ENABLE_
XPROG
_PROTOCOL)
#define ENABLE_
XPROG
_PROTOCOL
#endif
#endif
...
...
Projects/AVRISP/Lib/XPROG/XPROGProtocol.c
View file @
9decc2bc
...
...
@@ -30,23 +30,27 @@
/** \file
*
*
PDI
Protocol handler, to process V2 Protocol wrapped
PDI
commands used in Atmel programmer devices.
*
XPROG
Protocol handler, to process V2 Protocol wrapped
XPROG
commands used in Atmel programmer devices.
*/
#define INCLUDE_FROM_
PDI
PROTOCOL_C
#include "
PDI
Protocol.h"
#define INCLUDE_FROM_
XPROG
PROTOCOL_C
#include "
XPROG
Protocol.h"
#if defined(ENABLE_
PDI
_PROTOCOL) || defined(__DOXYGEN__)
#if defined(ENABLE_
XPROG
_PROTOCOL) || defined(__DOXYGEN__)
/** Base absolute address for the target's NVM controller */
uint32_t
XPROG_Param_NVMBase
=
0x010001C0
;
/** Size in bytes of the target's EEPROM page */
uint32_t
XPROG_Param_EEPageSize
;
/** Handler for the CMD_XPROG_SETMODE command, which sets the programmer-to-target protocol used for PDI
* XMEGA programming (either PDI or JTAG). Only PDI programming is supported.
/** Currently selected XPROG programming protocol */
uint8_t
XPROG_SelectedProtocol
;
/** Handler for the CMD_XPROG_SETMODE command, which sets the programmer-to-target protocol used for PDI/TPI
* programming.
*/
void
PDI
Protocol_
XPROG_
SetMode
(
void
)
void
XPROG
Protocol_SetMode
(
void
)
{
struct
{
...
...
@@ -58,66 +62,75 @@ void PDIProtocol_XPROG_SetMode(void)
Endpoint_ClearOUT
();
Endpoint_SetEndpointDirection
(
ENDPOINT_DIR_IN
);
Serial_TxByte
(
SetMode_XPROG_Params
.
Protocol
)
;
XPROG_SelectedProtocol
=
SetMode_XPROG_Params
.
Protocol
;
Endpoint_Write_Byte
(
CMD_XPROG_SETMODE
);
Endpoint_Write_Byte
((
SetMode_XPROG_Params
.
Protocol
=
=
XPRG_PROTOCOL_
PDI
)
?
STATUS_CMD_OK
:
STATUS_CMD_FAILED
);
Endpoint_Write_Byte
((
SetMode_XPROG_Params
.
Protocol
!
=
XPRG_PROTOCOL_
JTAG
)
?
STATUS_CMD_OK
:
STATUS_CMD_FAILED
);
Endpoint_ClearIN
();
}
/** Handler for the CMD_XPROG command, which wraps up XPROG commands in a V2 wrapper which need to be
* removed and processed so that the underlying XPROG command can be handled.
*/
void
PDI
Protocol_
XPROG_
Command
(
void
)
void
XPROG
Protocol_Command
(
void
)
{
uint8_t
XPROGCommand
=
Endpoint_Read_Byte
();
switch
(
XPROGCommand
)
{
case
XPRG_CMD_ENTER_PROGMODE
:
PDI
Protocol_EnterXPROGMode
();
XPROG
Protocol_EnterXPROGMode
();
break
;
case
XPRG_CMD_LEAVE_PROGMODE
:
PDI
Protocol_LeaveXPROGMode
();
XPROG
Protocol_LeaveXPROGMode
();
break
;
case
XPRG_CMD_ERASE
:
PDI
Protocol_Erase
();
XPROG
Protocol_Erase
();
break
;
case
XPRG_CMD_WRITE_MEM
:
PDI
Protocol_WriteMemory
();
XPROG
Protocol_WriteMemory
();
break
;
case
XPRG_CMD_READ_MEM
:
PDI
Protocol_ReadMemory
();
XPROG
Protocol_ReadMemory
();
break
;
case
XPRG_CMD_CRC
:
PDI
Protocol_ReadCRC
();
XPROG
Protocol_ReadCRC
();
break
;
case
XPRG_CMD_SET_PARAM
:
PDI
Protocol_SetParam
();
XPROG
Protocol_SetParam
();
break
;
}
}
/** Handler for the XPROG ENTER_PROGMODE command to establish a
PDI
connection with the attached device. */
static
void
PDI
Protocol_EnterXPROGMode
(
void
)
/** Handler for the XPROG ENTER_PROGMODE command to establish a connection with the attached device. */
static
void
XPROG
Protocol_EnterXPROGMode
(
void
)
{
Endpoint_ClearOUT
();
Endpoint_SetEndpointDirection
(
ENDPOINT_DIR_IN
);
/* Enable PDI programming mode with the attached target */
PDITarget_EnableTargetPDI
();
/* Store the RESET key into the RESET PDI register to keep the XMEGA in reset */
PDITarget_SendByte
(
PDI_CMD_STCS
|
PDI_RESET_REG
);
PDITarget_SendByte
(
PDI_RESET_KEY
);
bool
NVMBusEnabled
;
/* Enable access to the XPROG NVM bus by sending the documented NVM access key to the device */
PDITarget_SendByte
(
PDI_CMD_KEY
);
for
(
uint8_t
i
=
sizeof
(
PDI_NVMENABLE_KEY
);
i
>
0
;
i
--
)
PDITarget_SendByte
(
PDI_NVMENABLE_KEY
[
i
-
1
]);
/* Wait until the NVM bus becomes active */
bool
NVMBusEnabled
=
PDITarget_WaitWhileNVMBusBusy
();
if
(
XPROG_SelectedProtocol
==
XPRG_PROTOCOL_PDI
)
{
/* Enable PDI programming mode with the attached target */
PDITarget_EnableTargetPDI
();
/* Store the RESET key into the RESET PDI register to keep the XMEGA in reset */
PDITarget_SendByte
(
PDI_CMD_STCS
|
PDI_RESET_REG
);
PDITarget_SendByte
(
PDI_RESET_KEY
);
/* Enable access to the XPROG NVM bus by sending the documented NVM access key to the device */
PDITarget_SendByte
(
PDI_CMD_KEY
);
for
(
uint8_t
i
=
sizeof
(
PDI_NVMENABLE_KEY
);
i
>
0
;
i
--
)
PDITarget_SendByte
(
PDI_NVMENABLE_KEY
[
i
-
1
]);
/* Wait until the NVM bus becomes active */
NVMBusEnabled
=
PDITarget_WaitWhileNVMBusBusy
();
}
else
{
// TODO
}
Endpoint_Write_Byte
(
CMD_XPROG
);
Endpoint_Write_Byte
(
XPRG_CMD_ENTER_PROGMODE
);
...
...
@@ -128,17 +141,24 @@ static void PDIProtocol_EnterXPROGMode(void)
/** Handler for the XPROG LEAVE_PROGMODE command to terminate the PDI programming connection with
* the attached device.
*/
static
void
PDI
Protocol_LeaveXPROGMode
(
void
)
static
void
XPROG
Protocol_LeaveXPROGMode
(
void
)
{
Endpoint_ClearOUT
();
Endpoint_SetEndpointDirection
(
ENDPOINT_DIR_IN
);
/* Clear the RESET key in the RESET PDI register to allow the XMEGA to run */
PDITarget_SendByte
(
PDI_CMD_STCS
|
PDI_RESET_REG
);
PDITarget_SendByte
(
0x00
);
PDITarget_
DisableTargetPDI
(
);
if
(
XPROG_SelectedProtocol
==
XPRG_PROTOCOL_PDI
)
{
/* Clear the RESET key in the RESET PDI register to allow the XMEGA to run */
PDITarget_SendByte
(
PDI_CMD_STCS
|
PDI_RESET_REG
);
PDITarget_
SendByte
(
0x00
);
PDITarget_DisableTargetPDI
();
}
else
{
// TODO
}
Endpoint_Write_Byte
(
CMD_XPROG
);
Endpoint_Write_Byte
(
XPRG_CMD_LEAVE_PROGMODE
);
Endpoint_Write_Byte
(
XPRG_ERR_OK
);
...
...
@@ -146,7 +166,7 @@ static void PDIProtocol_LeaveXPROGMode(void)
}
/** Handler for the XPRG ERASE command to erase a specific memory address space in the attached device. */
static
void
PDI
Protocol_Erase
(
void
)
static
void
XPROG
Protocol_Erase
(
void
)
{
uint8_t
ReturnStatus
=
XPRG_ERR_OK
;
...
...
@@ -164,27 +184,34 @@ static void PDIProtocol_Erase(void)
uint8_t
EraseCommand
=
XMEGA_NVM_CMD_NOOP
;
/* Determine which NVM command to send to the device depending on the memory to erase */
if
(
Erase_XPROG_Params
.
MemoryType
==
XPRG_ERASE_CHIP
)
EraseCommand
=
XMEGA_NVM_CMD_CHIPERASE
;
else
if
(
Erase_XPROG_Params
.
MemoryType
==
XPRG_ERASE_APP
)
EraseCommand
=
XMEGA_NVM_CMD_ERASEAPPSEC
;
else
if
(
Erase_XPROG_Params
.
MemoryType
==
XPRG_ERASE_BOOT
)
EraseCommand
=
XMEGA_NVM_CMD_ERASEBOOTSEC
;
else
if
(
Erase_XPROG_Params
.
MemoryType
==
XPRG_ERASE_EEPROM
)
EraseCommand
=
XMEGA_NVM_CMD_ERASEEEPROM
;
else
if
(
Erase_XPROG_Params
.
MemoryType
==
XPRG_ERASE_APP_PAGE
)
EraseCommand
=
XMEGA_NVM_CMD_ERASEAPPSECPAGE
;
else
if
(
Erase_XPROG_Params
.
MemoryType
==
XPRG_ERASE_BOOT_PAGE
)
EraseCommand
=
XMEGA_NVM_CMD_ERASEBOOTSECPAGE
;
else
if
(
Erase_XPROG_Params
.
MemoryType
==
XPRG_ERASE_EEPROM_PAGE
)
EraseCommand
=
XMEGA_NVM_CMD_ERASEEEPROMPAGE
;
else
if
(
Erase_XPROG_Params
.
MemoryType
==
XPRG_ERASE_USERSIG
)
EraseCommand
=
XMEGA_NVM_CMD_ERASEUSERSIG
;
/* Erase the target memory, indicate timeout if ocurred */
if
(
!
(
XMEGANVM_EraseMemory
(
EraseCommand
,
Erase_XPROG_Params
.
Address
)))
ReturnStatus
=
XPRG_ERR_TIMEOUT
;
if
(
XPROG_SelectedProtocol
==
XPRG_PROTOCOL_PDI
)
{
/* Determine which NVM command to send to the device depending on the memory to erase */
if
(
Erase_XPROG_Params
.
MemoryType
==
XPRG_ERASE_CHIP
)
EraseCommand
=
XMEGA_NVM_CMD_CHIPERASE
;
else
if
(
Erase_XPROG_Params
.
MemoryType
==
XPRG_ERASE_APP
)
EraseCommand
=
XMEGA_NVM_CMD_ERASEAPPSEC
;
else
if
(
Erase_XPROG_Params
.
MemoryType
==
XPRG_ERASE_BOOT
)
EraseCommand
=
XMEGA_NVM_CMD_ERASEBOOTSEC
;
else
if
(
Erase_XPROG_Params
.
MemoryType
==
XPRG_ERASE_EEPROM
)
EraseCommand
=
XMEGA_NVM_CMD_ERASEEEPROM
;
else
if
(
Erase_XPROG_Params
.
MemoryType
==
XPRG_ERASE_APP_PAGE
)
EraseCommand
=
XMEGA_NVM_CMD_ERASEAPPSECPAGE
;
else
if
(
Erase_XPROG_Params
.
MemoryType
==
XPRG_ERASE_BOOT_PAGE
)
EraseCommand
=
XMEGA_NVM_CMD_ERASEBOOTSECPAGE
;
else
if
(
Erase_XPROG_Params
.
MemoryType
==
XPRG_ERASE_EEPROM_PAGE
)
EraseCommand
=
XMEGA_NVM_CMD_ERASEEEPROMPAGE
;
else
if
(
Erase_XPROG_Params
.
MemoryType
==
XPRG_ERASE_USERSIG
)
EraseCommand
=
XMEGA_NVM_CMD_ERASEUSERSIG
;
/* Erase the target memory, indicate timeout if ocurred */
if
(
!
(
XMEGANVM_EraseMemory
(
EraseCommand
,
Erase_XPROG_Params
.
Address
)))
ReturnStatus
=
XPRG_ERR_TIMEOUT
;
}
else
{
// TODO
}
Endpoint_Write_Byte
(
CMD_XPROG
);
Endpoint_Write_Byte
(
XPRG_CMD_ERASE
);
...
...
@@ -193,7 +220,7 @@ static void PDIProtocol_Erase(void)
}
/** Handler for the XPROG WRITE_MEMORY command to write to a specific memory space within the attached device. */
static
void
PDI
Protocol_WriteMemory
(
void
)
static
void
XPROG
Protocol_WriteMemory
(
void
)
{
uint8_t
ReturnStatus
=
XPRG_ERR_OK
;
...
...
@@ -220,46 +247,53 @@ static void PDIProtocol_WriteMemory(void)
uint8_t
WriteBuffCommand
=
XMEGA_NVM_CMD_LOADFLASHPAGEBUFF
;
uint8_t
EraseBuffCommand
=
XMEGA_NVM_CMD_ERASEFLASHPAGEBUFF
;
bool
PagedMemory
=
true
;
if
(
WriteMemory_XPROG_Params
.
MemoryType
==
XPRG_MEM_TYPE_APPL
)
{
WriteCommand
=
XMEGA_NVM_CMD_WRITEAPPSECPAGE
;
}
else
if
(
WriteMemory_XPROG_Params
.
MemoryType
==
XPRG_MEM_TYPE_BOOT
)
{
WriteCommand
=
XMEGA_NVM_CMD_WRITEBOOTSECPAGE
;
}
else
if
(
WriteMemory_XPROG_Params
.
MemoryType
==
XPRG_MEM_TYPE_EEPROM
)
{
WriteCommand
=
XMEGA_NVM_CMD_WRITEEEPROMPAGE
;
WriteBuffCommand
=
XMEGA_NVM_CMD_LOADEEPROMPAGEBUFF
;
EraseBuffCommand
=
XMEGA_NVM_CMD_ERASEEEPROMPAGEBUFF
;
}
else
if
(
WriteMemory_XPROG_Params
.
MemoryType
==
XPRG_MEM_TYPE_USERSIG
)
{
/* User signature is paged, but needs us to manually indicate the mode bits since the host doesn't set them */
WriteMemory_XPROG_Params
.
PageMode
=
(
XPRG_PAGEMODE_ERASE
|
XPRG_PAGEMODE_WRITE
);
WriteCommand
=
XMEGA_NVM_CMD_WRITEUSERSIG
;
}
else
if
(
WriteMemory_XPROG_Params
.
MemoryType
==
XPRG_MEM_TYPE_FUSE
)
{
WriteCommand
=
XMEGA_NVM_CMD_WRITEFUSE
;
PagedMemory
=
false
;
}
else
if
(
WriteMemory_XPROG_Params
.
MemoryType
==
XPRG_MEM_TYPE_LOCKBITS
)
if
(
XPROG_SelectedProtocol
==
XPRG_PROTOCOL_PDI
)
{
WriteCommand
=
XMEGA_NVM_CMD_WRITELOCK
;
PagedMemory
=
false
;
if
(
WriteMemory_XPROG_Params
.
MemoryType
==
XPRG_MEM_TYPE_APPL
)
{
WriteCommand
=
XMEGA_NVM_CMD_WRITEAPPSECPAGE
;
}
else
if
(
WriteMemory_XPROG_Params
.
MemoryType
==
XPRG_MEM_TYPE_BOOT
)
{
WriteCommand
=
XMEGA_NVM_CMD_WRITEBOOTSECPAGE
;
}
else
if
(
WriteMemory_XPROG_Params
.
MemoryType
==
XPRG_MEM_TYPE_EEPROM
)
{
WriteCommand
=
XMEGA_NVM_CMD_WRITEEEPROMPAGE
;
WriteBuffCommand
=
XMEGA_NVM_CMD_LOADEEPROMPAGEBUFF
;
EraseBuffCommand
=
XMEGA_NVM_CMD_ERASEEEPROMPAGEBUFF
;
}
else
if
(
WriteMemory_XPROG_Params
.
MemoryType
==
XPRG_MEM_TYPE_USERSIG
)
{
/* User signature is paged, but needs us to manually indicate the mode bits since the host doesn't set them */
WriteMemory_XPROG_Params
.
PageMode
=
(
XPRG_PAGEMODE_ERASE
|
XPRG_PAGEMODE_WRITE
);
WriteCommand
=
XMEGA_NVM_CMD_WRITEUSERSIG
;
}
else
if
(
WriteMemory_XPROG_Params
.
MemoryType
==
XPRG_MEM_TYPE_FUSE
)
{
WriteCommand
=
XMEGA_NVM_CMD_WRITEFUSE
;
PagedMemory
=
false
;
}
else
if
(
WriteMemory_XPROG_Params
.
MemoryType
==
XPRG_MEM_TYPE_LOCKBITS
)
{
WriteCommand
=
XMEGA_NVM_CMD_WRITELOCK
;
PagedMemory
=
false
;
}
/* Send the appropriate memory write commands to the device, indicate timeout if occurred */
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
,
WriteMemory_XPROG_Params
.
ProgData
)))
{
ReturnStatus
=
XPRG_ERR_TIMEOUT
;
}
}
/* Send the appropriate memory write commands to the device, indicate timeout if occurred */
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
,
WriteMemory_XPROG_Params
.
ProgData
)))
else
{
ReturnStatus
=
XPRG_ERR_TIMEOUT
;
// TODO
}
Endpoint_Write_Byte
(
CMD_XPROG
);
...
...
@@ -271,7 +305,7 @@ static void PDIProtocol_WriteMemory(void)
/** Handler for the XPROG READ_MEMORY command to read data from a specific address space within the
* attached device.
*/
static
void
PDI
Protocol_ReadMemory
(
void
)
static
void
XPROG
Protocol_ReadMemory
(
void
)
{
uint8_t
ReturnStatus
=
XPRG_ERR_OK
;
...
...
@@ -291,9 +325,16 @@ static void PDIProtocol_ReadMemory(void)