3 Copyright (C) Dean Camera, 2014.
5 dean [at] fourwalledcubicle [dot] com
10 Copyright 2014 Dean Camera (dean [at] fourwalledcubicle [dot] com)
12 Permission to use, copy, modify, distribute, and sell this
13 software and its documentation for any purpose is hereby granted
14 without fee, provided that the above copyright notice appear in
15 all copies and that both that the copyright notice and this
16 permission notice and warranty disclaimer appear in supporting
17 documentation, and that the name of the author not be used in
18 advertising or publicity pertaining to distribution of the
19 software without specific, written prior permission.
21 The author disclaims all warranties with regard to this
22 software, including all implied warranties of merchantability
23 and fitness. In no event shall the author be liable for any
24 special, indirect or consequential damages or any damages
25 whatsoever resulting from loss of use, data or profits, whether
26 in an action of contract, negligence or other tortious action,
27 arising out of or in connection with the use or performance of
33 * Header file for XPROGProtocol.c.
36 #ifndef _XPROG_PROTOCOL_
37 #define _XPROG_PROTOCOL_
41 #include <util/delay.h>
44 #include <LUFA/Drivers/USB/USB.h>
46 #include "../V2Protocol.h"
49 #include "Config/AppConfig.h"
51 /* Preprocessor Checks: */
52 #if ((BOARD == BOARD_XPLAIN) || (BOARD == BOARD_XPLAIN_REV1))
53 /* On the XPLAIN board, we only need PDI programming
54 for the ATXMEGA128A1 - disable ISP to prevent hardware
55 damage and force-enable XPROG.
57 #undef ENABLE_ISP_PROTOCOL
59 #if !defined(ENABLE_XPROG_PROTOCOL)
60 #define ENABLE_XPROG_PROTOCOL
65 #define XPROG_CMD_ENTER_PROGMODE 0x01
66 #define XPROG_CMD_LEAVE_PROGMODE 0x02
67 #define XPROG_CMD_ERASE 0x03
68 #define XPROG_CMD_WRITE_MEM 0x04
69 #define XPROG_CMD_READ_MEM 0x05
70 #define XPROG_CMD_CRC 0x06
71 #define XPROG_CMD_SET_PARAM 0x07
73 #define XPROG_MEM_TYPE_APPL 1
74 #define XPROG_MEM_TYPE_BOOT 2
75 #define XPROG_MEM_TYPE_EEPROM 3
76 #define XPROG_MEM_TYPE_FUSE 4
77 #define XPROG_MEM_TYPE_LOCKBITS 5
78 #define XPROG_MEM_TYPE_USERSIG 6
79 #define XPROG_MEM_TYPE_FACTORY_CALIBRATION 7
81 #define XPROG_ERASE_CHIP 1
82 #define XPROG_ERASE_APP 2
83 #define XPROG_ERASE_BOOT 3
84 #define XPROG_ERASE_EEPROM 4
85 #define XPROG_ERASE_APP_PAGE 5
86 #define XPROG_ERASE_BOOT_PAGE 6
87 #define XPROG_ERASE_EEPROM_PAGE 7
88 #define XPROG_ERASE_USERSIG 8
90 #define XPROG_MEM_WRITE_ERASE 0
91 #define XPROG_MEM_WRITE_WRITE 1
93 #define XPROG_CRC_APP 1
94 #define XPROG_CRC_BOOT 2
95 #define XPROG_CRC_FLASH 3
97 #define XPROG_ERR_OK 0
98 #define XPROG_ERR_FAILED 1
99 #define XPROG_ERR_COLLISION 2
100 #define XPROG_ERR_TIMEOUT 3
102 #define XPROG_PARAM_NVMBASE 0x01
103 #define XPROG_PARAM_EEPPAGESIZE 0x02
104 #define XPROG_PARAM_NVMCMD_REG 0x03
105 #define XPROG_PARAM_NVMCSR_REG 0x04
106 #define XPROG_PARAM_UNKNOWN_1 0x05
108 #define XPROG_PROTOCOL_PDI 0x00
109 #define XPROG_PROTOCOL_JTAG 0x01
110 #define XPROG_PROTOCOL_TPI 0x02
112 #define XPROG_PAGEMODE_WRITE (1 << 1)
113 #define XPROG_PAGEMODE_ERASE (1 << 0)
115 /* External Variables: */
116 extern uint32_t XPROG_Param_NVMBase;
117 extern uint16_t XPROG_Param_EEPageSize;
118 extern uint8_t XPROG_Param_NVMCSRRegAddr;
119 extern uint8_t XPROG_Param_NVMCMDRegAddr;
121 /* Function Prototypes: */
122 void XPROGProtocol_SetMode(void);
123 void XPROGProtocol_Command(void);
125 #if (defined(INCLUDE_FROM_XPROGPROTOCOL_C) && defined(ENABLE_XPROG_PROTOCOL))
126 static void XPROGProtocol_EnterXPROGMode(void);
127 static void XPROGProtocol_LeaveXPROGMode(void);
128 static void XPROGProtocol_SetParam(void);
129 static void XPROGProtocol_Erase(void);
130 static void XPROGProtocol_WriteMemory(void);
131 static void XPROGProtocol_ReadMemory(void);
132 static void XPROGProtocol_ReadCRC(void);