3 Copyright (C) Dean Camera, 2009.
5 dean [at] fourwalledcubicle [dot] com
6 www.fourwalledcubicle.com
10 Copyright 2009 Dean Camera (dean [at] fourwalledcubicle [dot] com)
12 Permission to use, copy, modify, and distribute this software
13 and its documentation for any purpose and without fee is hereby
14 granted, provided that the above copyright notice appear in all
15 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 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
33 * Header file for PDIProtocol.c.
36 #ifndef _PDI_PROTOCOL_
37 #define _PDI_PROTOCOL_
41 #include <util/delay.h>
44 #include "V2Protocol.h"
45 #include "PDITarget.h"
46 #include "NVMTarget.h"
48 /* Preprocessor Checks: */
49 #if ((BOARD == BOARD_XPLAIN) || (BOARD == BOARD_XPLAIN_REV1))
50 #undef ENABLE_ISP_PROTOCOL
52 #if !defined(ENABLE_PDI_PROTOCOL)
53 #define ENABLE_PDI_PROTOCOL
58 #define XPRG_CMD_ENTER_PROGMODE 0x01
59 #define XPRG_CMD_LEAVE_PROGMODE 0x02
60 #define XPRG_CMD_ERASE 0x03
61 #define XPRG_CMD_WRITE_MEM 0x04
62 #define XPRG_CMD_READ_MEM 0x05
63 #define XPRG_CMD_CRC 0x06
64 #define XPRG_CMD_SET_PARAM 0x07
66 #define XPRG_MEM_TYPE_APPL 1
67 #define XPRG_MEM_TYPE_BOOT 2
68 #define XPRG_MEM_TYPE_EEPROM 3
69 #define XPRG_MEM_TYPE_FUSE 4
70 #define XPRG_MEM_TYPE_LOCKBITS 5
71 #define XPRG_MEM_TYPE_USERSIG 6
72 #define XPRG_MEM_TYPE_FACTORY_CALIBRATION 7
74 #define XPRG_ERASE_CHIP 1
75 #define XPRG_ERASE_APP 2
76 #define XPRG_ERASE_BOOT 3
77 #define XPRG_ERASE_EEPROM 4
78 #define XPRG_ERASE_APP_PAGE 5
79 #define XPRG_ERASE_BOOT_PAGE 6
80 #define XPRG_ERASE_EEPROM_PAGE 7
81 #define XPRG_ERASE_USERSIG 8
83 #define XPRG_MEM_WRITE_ERASE 0
84 #define XPRG_MEM_WRITE_WRITE 1
86 #define XPRG_CRC_APP 1
87 #define XPRG_CRC_BOOT 2
88 #define XPRG_CRC_FLASH 3
91 #define XPRG_ERR_FAILED 1
92 #define XPRG_ERR_COLLISION 2
93 #define XPRG_ERR_TIMEOUT 3
95 #define XPRG_PARAM_NVMBASE 0x01
96 #define XPRG_PARAM_EEPPAGESIZE 0x02
98 #define XPRG_PROTOCOL_PDI 0x00
99 #define XPRG_PROTOCOL_JTAG 0x01
101 #define XPRG_PAGEMODE_WRITE (1 << 1)
102 #define XPRG_PAGEMODE_ERASE (1 << 0)
104 /* External Variables: */
105 extern uint32_t XPROG_Param_NVMBase
;
107 /* Function Prototypes: */
108 void PDIProtocol_XPROG_SetMode(void);
109 void PDIProtocol_XPROG_Command(void);
111 #if defined(INCLUDE_FROM_PDIPROTOCOL_C)
112 static void PDIProtocol_EnterXPROGMode(void);
113 static void PDIProtocol_LeaveXPROGMode(void);
114 static void PDIProtocol_SetParam(void);
115 static void PDIProtocol_Erase(void);
116 static void PDIProtocol_WriteMemory(void);
117 static void PDIProtocol_ReadMemory(void);
118 static void PDIProtocol_ReadCRC(void);