1 /**
2  * \file
3  *
4  * \brief FLIP protocol definitions.
5  *
6  * Copyright (c) 2011-2015 Atmel Corporation. All rights reserved.
7  *
8  * \asf_license_start
9  *
10  * \page License
11  *
12  * Redistribution and use in source and binary forms, with or without
13  * modification, are permitted provided that the following conditions are met:
14  *
15  * 1. Redistributions of source code must retain the above copyright notice,
16  *    this list of conditions and the following disclaimer.
17  *
18  * 2. Redistributions in binary form must reproduce the above copyright notice,
19  *    this list of conditions and the following disclaimer in the documentation
20  *    and/or other materials provided with the distribution.
21  *
22  * 3. The name of Atmel may not be used to endorse or promote products derived
23  *    from this software without specific prior written permission.
24  *
25  * 4. This software may only be redistributed and used in connection with an
26  *    Atmel microcontroller product.
27  *
28  * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
29  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
30  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
31  * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR
32  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
34  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
35  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
36  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
37  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
38  * POSSIBILITY OF SUCH DAMAGE.
39  *
40  * \asf_license_stop
41  *
42  */
43 /*
44  * Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a>
45  */
46 
47 #ifndef _FLIP_PROTOCOL_H_
48 #define _FLIP_PROTOCOL_H_
49 
50 #ifdef __cplusplus
51 extern "C" {
52 #endif
53 
54 /**
55  * \defgroup flip_protocol Atmel FLIP Protocol definitions
56  *
57  * To perform firmware upgrade, Atmel has developed an application called "FLIP"
58  * This software is a flexible application which lets you program and
59  * configure Atmel's microcontroller devices in their final environment
60  * without needing any dedicated hardware.
61  * @{
62  */
63 
64 //! \defgroup FLIP Protocol versions
65 //@{
66 #define  FLIP_PROTOCOL_VERSION_2     2 // Used by UC3 parts and Xmega parts
67 #define  FLIP_PROTOCOL_VERSION_1     1 // Used by Mega
68 #define  FLIP_PROTOCOL_VERSION_0     0 // Used by C51 parts
69 //@}
70 
71 
72 /**
73  * \defgroup flip_pv1 Definitions for FLIP Protocol version 1
74  *
75  * Note: Used by Mega parts.
76  *
77  * @{
78  */
79 
80 COMPILER_PACK_SET(1)
81 /**
82  * \brief FLIP message structure
83  */
84 typedef struct {
85 	uint8_t cmd_id;
86 	uint8_t arg[5];
87 } flip_msg_v1_t;
88 COMPILER_PACK_RESET()
89 
90 //! Size of buffer used by FLIP to receive or send data
91 #define  FLIP_V1_BUF_TRANS_SIZE  1024
92 
93 //! \name FLIP commands
94 //@{
95 #define  FLIP_V1_CMD_PROG_START            0x01
96 #define  FLIP_V1_CMD_READ                  0x03
97 #define  FLIP_V1_CMD_WRITE                 0x04
98 #define  FLIP_V1_CMD_READ_ID               0x05
99 #define  FLIP_V1_CMD_CHANGE_BASE_ADDR      0x06
100 
101 //! \name FLIP_V1_CMD_PROG_START first argument
102 //@{
103 #define FLIP_V1_CMD_PROG_START_ARG_FLASH   0x00
104 #define FLIP_V1_CMD_PROG_START_ARG_EEPROM  0x01
105 #define FLIP_V1_CMD_PROG_START_ARG_CUSTOM  0x08
106 //@}
107 
108 //! \name FLIP_V1_CMD_READ first argument
109 //@{
110 #define FLIP_V1_CMD_READ_ARG_FLASH      0x00
111 #define FLIP_V1_CMD_READ_ARG_FLASHCHECK 0x01
112 #define FLIP_V1_CMD_READ_ARG_EEPROM     0x02
113 #define FLIP_V1_CMD_READ_ARG_CUSTOM     0x03
114 //@}
115 
116 //! \name FLIP_V1_CMD_WRITE first argument
117 //@{
118 #define FLIP_V1_CMD_WRITE_ARG_ERASE     0x00
119 #define FLIP_V1_CMD_WRITE_ARG_RST       0x03
120 //! \name FLIP_V1_CMD_WRITE_ARG_ERASE following argument
121 //@{
122 #define FLIP_V1_CMD_WRITE_ARG_ERASE_CHIP 0xFF
123 //@}
124 //! \name FLIP_V1_CMD_WRITE_ARG_RST following arguments
125 //@{
126 #define FLIP_V1_CMD_WRITE_ARG_RST_HW    0x00
127 #define FLIP_V1_CMD_WRITE_ARG_RST_SF    0x01
128 //@}
129 //@}
130 
131 //! \name FLIP_V1_CMD_READ_ID first argument
132 //@{
133 #define FLIP_V1_CMD_READ_ID_ARG_BOOTLOADER 0x00
134 #define FLIP_V1_CMD_READ_ID_ARG_SIGNATURE  0x01
135 //! \name FLIP_V1_CMD_READ_ID_ARG_SIGNATURE following arguments
136 //@{
137 #define FLIP_V1_CMD_READ_ID_SIGNATURE_ARG_MANUF              0x30
138 #define FLIP_V1_CMD_READ_ID_SIGNATURE_ARG_FAMILY             0x31
139 #define FLIP_V1_CMD_READ_ID_SIGNATURE_ARG_PRODUCT            0x60
140 #define FLIP_V1_CMD_READ_ID_SIGNATURE_ARG_REVISION           0x61
141 //@}
142 //@}
143 
144 //! \name FLIP_V1_CMD_CHANGE_BASE_ADDR first argument
145 //@{
146 #define FLIP_V1_CMD_CHANGE_BASE_ADDR_ARG0   0x03
147 #define FLIP_V1_CMD_CHANGE_BASE_ADDR_ARG1   0x00
148 //@}
149 
150 //@}
151 //@}
152 
153 
154 /**
155  * \defgroup flip_pv2 Definitions for Atmel FLIP Protocol version 2
156  *
157  * Note: Used by uc3 and Xmega parts
158  *
159  * @{
160  */
161 
162 COMPILER_PACK_SET(1)
163 /**
164  * \brief FLIP message structure
165  */
166 typedef struct {
167 	uint8_t group;
168 	uint8_t cmd_id;
169 	uint8_t arg[4];
170 } flip_msg_v2_t;
171 COMPILER_PACK_RESET()
172 
173 //! Size of buffer used by FLIP to receive or send data
174 //! Note:  Write uses 2K and Read uses 1KB
175 #define  FLIP_V2_BUF_TRANS_SIZE  (2*1024)
176 
177 //! \name Command Groups
178 //@{
179 #define FLIP_V2_CMD_GRP_DNLOAD                0x01
180 #define FLIP_V2_CMD_GRP_UPLOAD                0x03
181 #define FLIP_V2_CMD_GRP_EXEC                  0x04
182 #define FLIP_V2_CMD_GRP_SELECT                0x06
183 //@}
184 
185 //! \name FLIP_V2_CMD_GRP_DNLOAD first argument
186 //@{
187 #define FLIP_V2_CMD_PROGRAM_START             0x00
188 //@}
189 
190 
191 //! \name FLIP_V2_CMD_GRP_UPLOAD first argument
192 //@{
193 #define FLIP_V2_CMD_READ_MEMORY               0x00
194 #define FLIP_V2_CMD_BLANK_CHECK               0x01
195 //@}
196 
197 //! \name FLIP_V2_CMD_GRP_EXEC first argument
198 //@{
199 #define FLIP_V2_CMD_ERASE                     0x00
200 #define FLIP_V2_CMD_START_APPLI               0x03
201 //! \name FLIP_V2_CMD_ERASE following argument
202 //@{
203 #define FLIP_V2_CMD_ERASE_ARG_CHIP            0xFF
204 //@}
205 //! \name FLIP_V2_CMD_START_APPLI following arguments
206 //@{
207 #define FLIP_V2_CMD_START_APPLI_ARG_RESET     0x00
208 #define FLIP_V2_CMD_START_APPLI_ARG_NO_RESET  0x01
209 //@}
210 //@}
211 
212 //! \name FLIP_V2_CMD_GRP_SELECT first argument
213 //@{
214 #define FLIP_V2_CMD_SELECT_MEMORY             0x03
215 //! \name FLIP_V2_CMD_SELECT_MEMORY following arguments
216 //@{
217 #define FLIP_V2_CMD_SELECT_MEMORY_ARG_UNIT    0x00
218 #define FLIP_V2_CMD_SELECT_MEMORY_ARG_PAGE    0x01
219 //@}
220 //! \name FLIP_V2_CMD_SELECT_MEMORY_ARG_UNIT following arguments
221 //! Memory units field
222 //@{
223 #define FLIP_V2_CMD_SELECT_MEM_FLASH          0x00
224 #define FLIP_V2_CMD_SELECT_MEM_EEPROM         0x01
225 #define FLIP_V2_CMD_SELECT_MEM_SECURITY       0x02
226 #define FLIP_V2_CMD_SELECT_MEM_CONFIGURATION  0x03
227 #define FLIP_V2_CMD_SELECT_MEM_BOOTLOADER     0x04
228 #define FLIP_V2_CMD_SELECT_MEM_SIGNATURE      0x05
229 #define FLIP_V2_CMD_SELECT_MEM_USER           0x06
230 #define FLIP_V2_CMD_SELECT_MEM_INT_RAM        0x07
231 #define FLIP_V2_CMD_SELECT_MEM_EXT_MEM_CS0    0x08
232 #define FLIP_V2_CMD_SELECT_MEM_EXT_MEM_CS1    0x09
233 #define FLIP_V2_CMD_SELECT_MEM_EXT_MEM_CS2    0x0A
234 #define FLIP_V2_CMD_SELECT_MEM_EXT_MEM_CS3    0x0B
235 #define FLIP_V2_CMD_SELECT_MEM_EXT_MEM_CS4    0x0C
236 #define FLIP_V2_CMD_SELECT_MEM_EXT_MEM_CS5    0x0D
237 #define FLIP_V2_CMD_SELECT_MEM_EXT_MEM_CS6    0x0E
238 #define FLIP_V2_CMD_SELECT_MEM_EXT_MEM_CS7    0x0F
239 #define FLIP_V2_CMD_SELECT_MEM_EXT_MEM_DF     0x10
240 #define FLIP_V2_CMD_SELECT_MEM_COUNT          0x11	// Number of memory units
241 //@}
242 //@}
243 
244 //@}
245 
246 //@}
247 
248 
249 #ifdef __cplusplus
250 }
251 #endif
252 
253 #endif // _FLIP_PROTOCOL_H_
254