]> git.gir.st - tmk_keyboard.git/blob - protocol/lufa/LUFA-git/Projects/AVRISP-MKII/Lib/XPROG/XMEGANVM.h
Squashed 'tmk_core/' changes from caca2c0..dc0e46e
[tmk_keyboard.git] / protocol / lufa / LUFA-git / Projects / AVRISP-MKII / Lib / XPROG / XMEGANVM.h
1 /*
2 LUFA Library
3 Copyright (C) Dean Camera, 2014.
4
5 dean [at] fourwalledcubicle [dot] com
6 www.lufa-lib.org
7 */
8
9 /*
10 Copyright 2014 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 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
28 this software.
29 */
30
31 /** \file
32 *
33 * Header file for XMEGANVM.c.
34 */
35
36 #ifndef _XMEGA_NVM_
37 #define _XMEGA_NVM_
38
39 /* Includes: */
40 #include <avr/io.h>
41 #include <avr/interrupt.h>
42 #include <stdbool.h>
43
44 #include <LUFA/Common/Common.h>
45
46 #include "XPROGProtocol.h"
47 #include "XPROGTarget.h"
48 #include "Config/AppConfig.h"
49
50 /* Preprocessor Checks: */
51 #if ((BOARD == BOARD_XPLAIN) || (BOARD == BOARD_XPLAIN_REV1))
52 #undef ENABLE_ISP_PROTOCOL
53
54 #if !defined(ENABLE_XPROG_PROTOCOL)
55 #define ENABLE_XPROG_PROTOCOL
56 #endif
57 #endif
58
59 /* Defines: */
60 #define XMEGA_CRC_LENGTH_BYTES 3
61
62 #define XMEGA_NVM_REG_ADDR0 0x00
63 #define XMEGA_NVM_REG_ADDR1 0x01
64 #define XMEGA_NVM_REG_ADDR2 0x02
65 #define XMEGA_NVM_REG_DAT0 0x04
66 #define XMEGA_NVM_REG_DAT1 0x05
67 #define XMEGA_NVM_REG_DAT2 0x06
68 #define XMEGA_NVM_REG_CMD 0x0A
69 #define XMEGA_NVM_REG_CTRLA 0x0B
70 #define XMEGA_NVM_REG_CTRLB 0x0C
71 #define XMEGA_NVM_REG_INTCTRL 0x0D
72 #define XMEGA_NVM_REG_STATUS 0x0F
73 #define XMEGA_NVM_REG_LOCKBITS 0x10
74
75 #define XMEGA_NVM_BIT_CTRLA_CMDEX (1 << 0)
76
77 #define XMEGA_NVM_CMD_NOOP 0x00
78 #define XMEGA_NVM_CMD_CHIPERASE 0x40
79 #define XMEGA_NVM_CMD_READNVM 0x43
80 #define XMEGA_NVM_CMD_LOADFLASHPAGEBUFF 0x23
81 #define XMEGA_NVM_CMD_ERASEFLASHPAGEBUFF 0x26
82 #define XMEGA_NVM_CMD_ERASEFLASHPAGE 0x2B
83 #define XMEGA_NVM_CMD_WRITEFLASHPAGE 0x2E
84 #define XMEGA_NVM_CMD_ERASEWRITEFLASH 0x2F
85 #define XMEGA_NVM_CMD_FLASHCRC 0x78
86 #define XMEGA_NVM_CMD_ERASEAPPSEC 0x20
87 #define XMEGA_NVM_CMD_ERASEAPPSECPAGE 0x22
88 #define XMEGA_NVM_CMD_WRITEAPPSECPAGE 0x24
89 #define XMEGA_NVM_CMD_ERASEWRITEAPPSECPAGE 0x25
90 #define XMEGA_NVM_CMD_APPCRC 0x38
91 #define XMEGA_NVM_CMD_ERASEBOOTSEC 0x68
92 #define XMEGA_NVM_CMD_ERASEBOOTSECPAGE 0x2A
93 #define XMEGA_NVM_CMD_WRITEBOOTSECPAGE 0x2C
94 #define XMEGA_NVM_CMD_ERASEWRITEBOOTSECPAGE 0x2D
95 #define XMEGA_NVM_CMD_BOOTCRC 0x39
96 #define XMEGA_NVM_CMD_READUSERSIG 0x03
97 #define XMEGA_NVM_CMD_ERASEUSERSIG 0x18
98 #define XMEGA_NVM_CMD_WRITEUSERSIG 0x1A
99 #define XMEGA_NVM_CMD_READCALIBRATION 0x02
100 #define XMEGA_NVM_CMD_READFUSE 0x07
101 #define XMEGA_NVM_CMD_WRITEFUSE 0x4C
102 #define XMEGA_NVM_CMD_WRITELOCK 0x08
103 #define XMEGA_NVM_CMD_LOADEEPROMPAGEBUFF 0x33
104 #define XMEGA_NVM_CMD_ERASEEEPROMPAGEBUFF 0x36
105 #define XMEGA_NVM_CMD_ERASEEEPROM 0x30
106 #define XMEGA_NVM_CMD_ERASEEEPROMPAGE 0x32
107 #define XMEGA_NVM_CMD_WRITEEEPROMPAGE 0x34
108 #define XMEGA_NVM_CMD_ERASEWRITEEEPROMPAGE 0x35
109 #define XMEGA_NVM_CMD_READEEPROM 0x06
110
111 /* Function Prototypes: */
112 bool XMEGANVM_WaitWhileNVMBusBusy(void);
113 bool XMEGANVM_WaitWhileNVMControllerBusy(void);
114 bool XMEGANVM_EnablePDI(void);
115 void XMEGANVM_DisablePDI(void);
116 bool XMEGANVM_GetMemoryCRC(const uint8_t CRCCommand,
117 uint32_t* const CRCDest);
118 bool XMEGANVM_ReadMemory(const uint32_t ReadAddress,
119 uint8_t* ReadBuffer,
120 uint16_t ReadSize);
121 bool XMEGANVM_WriteByteMemory(const uint8_t WriteCommand,
122 const uint32_t WriteAddress,
123 const uint8_t Byte);
124 bool XMEGANVM_WritePageMemory(const uint8_t WriteBuffCommand,
125 const uint8_t EraseBuffCommand,
126 const uint8_t WritePageCommand,
127 const uint8_t PageMode,
128 const uint32_t WriteAddress,
129 const uint8_t* WriteBuffer,
130 uint16_t WriteSize);
131 bool XMEGANVM_EraseMemory(const uint8_t EraseCommand,
132 const uint32_t Address);
133
134 #if defined(INCLUDE_FROM_XMEGANVM_C)
135 static void XMEGANVM_SendNVMRegAddress(const uint8_t Register);
136 static void XMEGANVM_SendAddress(const uint32_t AbsoluteAddress);
137 #endif
138
139 #endif
140
Imprint / Impressum