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 XMEGANVM.c.
41 #include <avr/interrupt.h>
44 #include <LUFA/Common/Common.h>
46 #include "XPROGProtocol.h"
47 #include "XPROGTarget.h"
49 /* Preprocessor Checks: */
50 #if ((BOARD == BOARD_XPLAIN) || (BOARD == BOARD_XPLAIN_REV1))
51 #undef ENABLE_ISP_PROTOCOL
53 #if !defined(ENABLE_XPROG_PROTOCOL)
54 #define ENABLE_XPROG_PROTOCOL
59 #define XMEGA_NVM_REG_ADDR0 0x00
60 #define XMEGA_NVM_REG_ADDR1 0x01
61 #define XMEGA_NVM_REG_ADDR2 0x02
62 #define XMEGA_NVM_REG_DAT0 0x04
63 #define XMEGA_NVM_REG_DAT1 0x05
64 #define XMEGA_NVM_REG_DAT2 0x06
65 #define XMEGA_NVM_REG_CMD 0x0A
66 #define XMEGA_NVM_REG_CTRLA 0x0B
67 #define XMEGA_NVM_REG_CTRLB 0x0C
68 #define XMEGA_NVM_REG_INTCTRL 0x0D
69 #define XMEGA_NVM_REG_STATUS 0x0F
70 #define XMEGA_NVM_REG_LOCKBITS 0x10
72 #define XMEGA_NVM_CMD_NOOP 0x00
73 #define XMEGA_NVM_CMD_CHIPERASE 0x40
74 #define XMEGA_NVM_CMD_READNVM 0x43
75 #define XMEGA_NVM_CMD_LOADFLASHPAGEBUFF 0x23
76 #define XMEGA_NVM_CMD_ERASEFLASHPAGEBUFF 0x26
77 #define XMEGA_NVM_CMD_ERASEFLASHPAGE 0x2B
78 #define XMEGA_NVM_CMD_WRITEFLASHPAGE 0x2E
79 #define XMEGA_NVM_CMD_ERASEWRITEFLASH 0x2F
80 #define XMEGA_NVM_CMD_FLASHCRC 0x78
81 #define XMEGA_NVM_CMD_ERASEAPPSEC 0x20
82 #define XMEGA_NVM_CMD_ERASEAPPSECPAGE 0x22
83 #define XMEGA_NVM_CMD_WRITEAPPSECPAGE 0x24
84 #define XMEGA_NVM_CMD_ERASEWRITEAPPSECPAGE 0x25
85 #define XMEGA_NVM_CMD_APPCRC 0x38
86 #define XMEGA_NVM_CMD_ERASEBOOTSEC 0x68
87 #define XMEGA_NVM_CMD_ERASEBOOTSECPAGE 0x2A
88 #define XMEGA_NVM_CMD_WRITEBOOTSECPAGE 0x2C
89 #define XMEGA_NVM_CMD_ERASEWRITEBOOTSECPAGE 0x2D
90 #define XMEGA_NVM_CMD_BOOTCRC 0x39
91 #define XMEGA_NVM_CMD_READUSERSIG 0x03
92 #define XMEGA_NVM_CMD_ERASEUSERSIG 0x18
93 #define XMEGA_NVM_CMD_WRITEUSERSIG 0x1A
94 #define XMEGA_NVM_CMD_READCALIBRATION 0x02
95 #define XMEGA_NVM_CMD_READFUSE 0x07
96 #define XMEGA_NVM_CMD_WRITEFUSE 0x4C
97 #define XMEGA_NVM_CMD_WRITELOCK 0x08
98 #define XMEGA_NVM_CMD_LOADEEPROMPAGEBUFF 0x33
99 #define XMEGA_NVM_CMD_ERASEEEPROMPAGEBUFF 0x36
100 #define XMEGA_NVM_CMD_ERASEEEPROM 0x30
101 #define XMEGA_NVM_CMD_ERASEEEPROMPAGE 0x32
102 #define XMEGA_NVM_CMD_WRITEEEPROMPAGE 0x34
103 #define XMEGA_NVM_CMD_ERASEWRITEEEPROMPAGE 0x35
104 #define XMEGA_NVM_CMD_READEEPROM 0x06
106 /* Function Prototypes: */
107 void XMEGANVM_SendNVMRegAddress(const uint8_t Register
);
108 void XMEGANVM_SendAddress(const uint32_t AbsoluteAddress
);
109 bool XMEGANVM_WaitWhileNVMBusBusy(void);
110 bool XMEGANVM_WaitWhileNVMControllerBusy(void);
111 bool XMEGANVM_GetMemoryCRC(const uint8_t CRCCommand
, uint32_t* const CRCDest
);
112 bool XMEGANVM_ReadMemory(const uint32_t ReadAddress
, uint8_t* ReadBuffer
, uint16_t ReadSize
);
113 bool XMEGANVM_WriteByteMemory(const uint8_t WriteCommand
, const uint32_t WriteAddress
, const uint8_t* WriteBuffer
);
114 bool XMEGANVM_WritePageMemory(const uint8_t WriteBuffCommand
, const uint8_t EraseBuffCommand
,
115 const uint8_t WritePageCommand
, const uint8_t PageMode
, const uint32_t WriteAddress
,
116 const uint8_t* WriteBuffer
, uint16_t WriteSize
);
117 bool XMEGANVM_EraseMemory(const uint8_t EraseCommand
, const uint32_t Address
);