Add branch for the conversion of demos to use standard C header files for configurati...
[pub/USBasp.git] / Projects / AVRISP-MKII / Lib / XPROG / XPROGProtocol.h
1 /*
2 LUFA Library
3 Copyright (C) Dean Camera, 2012.
4
5 dean [at] fourwalledcubicle [dot] com
6 www.lufa-lib.org
7 */
8
9 /*
10 Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com)
11
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.
20
21 The author disclaim 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
28 this software.
29 */
30
31 /** \file
32 *
33 * Header file for XPROGProtocol.c.
34 */
35
36 #ifndef _XPROG_PROTOCOL_
37 #define _XPROG_PROTOCOL_
38
39 /* Includes: */
40 #include <avr/io.h>
41 #include <util/delay.h>
42 #include <stdio.h>
43
44 #include <LUFA/Drivers/USB/USB.h>
45
46 #include "../V2Protocol.h"
47 #include "XMEGANVM.h"
48 #include "TINYNVM.h"
49
50 /* Preprocessor Checks: */
51 #if ((BOARD == BOARD_XPLAIN) || (BOARD == BOARD_XPLAIN_REV1))
52 /* On the XPLAIN board, we only need PDI programming
53 for the ATXMEGA128A1 - disable ISP to prevent hardware
54 damage and force-enable XPROG.
55 */
56 #undef ENABLE_ISP_PROTOCOL
57
58 #if !defined(ENABLE_XPROG_PROTOCOL)
59 #define ENABLE_XPROG_PROTOCOL
60 #endif
61 #endif
62
63 /* Macros: */
64 #define XPRG_CMD_ENTER_PROGMODE 0x01
65 #define XPRG_CMD_LEAVE_PROGMODE 0x02
66 #define XPRG_CMD_ERASE 0x03
67 #define XPRG_CMD_WRITE_MEM 0x04
68 #define XPRG_CMD_READ_MEM 0x05
69 #define XPRG_CMD_CRC 0x06
70 #define XPRG_CMD_SET_PARAM 0x07
71
72 #define XPRG_MEM_TYPE_APPL 1
73 #define XPRG_MEM_TYPE_BOOT 2
74 #define XPRG_MEM_TYPE_EEPROM 3
75 #define XPRG_MEM_TYPE_FUSE 4
76 #define XPRG_MEM_TYPE_LOCKBITS 5
77 #define XPRG_MEM_TYPE_USERSIG 6
78 #define XPRG_MEM_TYPE_FACTORY_CALIBRATION 7
79
80 #define XPRG_ERASE_CHIP 1
81 #define XPRG_ERASE_APP 2
82 #define XPRG_ERASE_BOOT 3
83 #define XPRG_ERASE_EEPROM 4
84 #define XPRG_ERASE_APP_PAGE 5
85 #define XPRG_ERASE_BOOT_PAGE 6
86 #define XPRG_ERASE_EEPROM_PAGE 7
87 #define XPRG_ERASE_USERSIG 8
88
89 #define XPRG_MEM_WRITE_ERASE 0
90 #define XPRG_MEM_WRITE_WRITE 1
91
92 #define XPRG_CRC_APP 1
93 #define XPRG_CRC_BOOT 2
94 #define XPRG_CRC_FLASH 3
95
96 #define XPRG_ERR_OK 0
97 #define XPRG_ERR_FAILED 1
98 #define XPRG_ERR_COLLISION 2
99 #define XPRG_ERR_TIMEOUT 3
100
101 #define XPRG_PARAM_NVMBASE 0x01
102 #define XPRG_PARAM_EEPPAGESIZE 0x02
103 #define XPRG_PARAM_NVMCMD_REG 0x03
104 #define XPRG_PARAM_NVMCSR_REG 0x04
105 #define XPRG_PARAM_UNKNOWN_1 0x05
106
107 #define XPRG_PROTOCOL_PDI 0x00
108 #define XPRG_PROTOCOL_JTAG 0x01
109 #define XPRG_PROTOCOL_TPI 0x02
110
111 #define XPRG_PAGEMODE_WRITE (1 << 1)
112 #define XPRG_PAGEMODE_ERASE (1 << 0)
113
114 /* External Variables: */
115 extern uint32_t XPROG_Param_NVMBase;
116 extern uint16_t XPROG_Param_EEPageSize;
117 extern uint8_t XPROG_Param_NVMCSRRegAddr;
118 extern uint8_t XPROG_Param_NVMCMDRegAddr;
119
120 /* Function Prototypes: */
121 void XPROGProtocol_SetMode(void);
122 void XPROGProtocol_Command(void);
123
124 #if (defined(INCLUDE_FROM_XPROGPROTOCOL_C) && defined(ENABLE_XPROG_PROTOCOL))
125 static void XPROGProtocol_EnterXPROGMode(void);
126 static void XPROGProtocol_LeaveXPROGMode(void);
127 static void XPROGProtocol_SetParam(void);
128 static void XPROGProtocol_Erase(void);
129 static void XPROGProtocol_WriteMemory(void);
130 static void XPROGProtocol_ReadMemory(void);
131 static void XPROGProtocol_ReadCRC(void);
132 #endif
133
134 #endif
135