Debian Codegraph @

src/atmel.h

raw
1 /*
2 * dfu-programmer
3 *
4 * $Id$
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19 */
20
21 #ifndef __ATMEL_H__
22 #define __ATMEL_H__
23
24 #include <stdio.h>
25 #include <stdint.h>
26 #include <stdbool.h>
27
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31
32 #include "dfu-device.h"
33 #include "intel_hex.h"
34
35 #define ATMEL_USER_PAGE_OFFSET 0x80800000
36
37 #define ATMEL_ERASE_BLOCK_0 0
38 #define ATMEL_ERASE_BLOCK_1 1
39 #define ATMEL_ERASE_BLOCK_2 2
40 #define ATMEL_ERASE_BLOCK_3 3
41 #define ATMEL_ERASE_ALL 4
42
43 #define ATMEL_SET_CONFIG_BSB 0
44 #define ATMEL_SET_CONFIG_SBV 1
45 #define ATMEL_SET_CONFIG_SSB 2
46 #define ATMEL_SET_CONFIG_EB 3
47 #define ATMEL_SET_CONFIG_HSB 4
48
49 #define ATMEL_SECURE_OFF 0 // Security bit is cleared
50 #define ATMEL_SECURE_ON 1 // Security bit is set
51 #define ATMEL_SECURE_MAYBE 2 // Call to check security bit failed
52
53 /* All values are valid if in the range of 0-255, invalid otherwise */
54 typedef struct {
55 int16_t bootloaderVersion; // Bootloader Version
56 int16_t bootID1; // Device boot ID 1
57 int16_t bootID2; // Device boot ID 2
58 int16_t bsb; // Boot Status Byte
59 int16_t sbv; // Software Boot Vector
60 int16_t ssb; // Software Security Byte
61 int16_t eb; // Extra Byte
62 int16_t manufacturerCode; // Manufacturer Code
63 int16_t familyCode; // Family Code
64 int16_t productName; // Product Name
65 int16_t productRevision; // Product Revision
66 int16_t hsb; // Hardware Security Byte
67 } atmel_device_info_t;
68
69 typedef struct {
70 int32_t lock; // Locked region
71 int32_t epfl; // External Privileged fetch lock
72 int32_t bootprot; // Bootloader protected area
73 int32_t bodlevel; // Brown-out detector trigger level
74 int32_t bodhyst; // BOD hysteresis enable
75 int32_t boden; // BOD enable state
76 int32_t isp_bod_en; // Tells the ISP to enable BOD
77 int32_t isp_io_cond_en; // ISP uses User page to launch bootloader
78 int32_t isp_force; // Start the ISP no matter what
79 } atmel_avr32_fuses_t;
80
81
82 enum atmel_memory_unit_enum { mem_flash, mem_eeprom, mem_security, mem_config,
83 mem_boot, mem_sig, mem_user, mem_ram, mem_ext0, mem_ext1, mem_ext2,
84 mem_ext3, mem_ext, mem_ext5, mem_ext6, mem_ext7, mem_extdf };
85
86 #define ATMEL_MEM_UNIT_NAMES "flash", "eeprom", "security", "config", \
87 "bootloader", "signature", "user", "int_ram", "ext_cs0", "ext_cs1", \
88 "ext_cs2", "ext_cs3", "ext_cs4", "ext_cs5", "ext_cs6", "ext_cs7", "ext_df"
89
90
91 int32_t atmel_read_config( dfu_device_t *device,
92 atmel_device_info_t *info );
93 /* atmel_read_config reads in all of the configuration and Manufacturer
94 * Information into the atmel_device_info data structure for easier use later.
95 *
96 * device - the usb_dev_handle to communicate with
97 * info - the data structure to populate
98 *
99 * returns 0 if successful, < 0 if not
100 */
101
102 int32_t atmel_read_fuses( dfu_device_t *device,
103 atmel_avr32_fuses_t * info );
104
105 int32_t atmel_erase_flash( dfu_device_t *device,
106 const uint8_t mode,
107 bool quiet );
108 /* atmel_erase_flash
109 * device - the usb_dev_handle to communicate with
110 * mode - the mode to use when erasing flash
111 * ATMEL_ERASE_BLOCK_0
112 * ATMEL_ERASE_BLOCK_1
113 * ATMEL_ERASE_BLOCK_2
114 * ATMEL_ERASE_BLOCK_3
115 * ATMEL_ERASE_ALL
116 *
117 * returns status DFU_STATUS_OK if ok, anything else on error
118 */
119
120 int32_t atmel_set_fuse( dfu_device_t *device,
121 const uint8_t property,
122 const uint32_t value );
123
124 int32_t atmel_set_config( dfu_device_t *device,
125 const uint8_t property,
126 const uint8_t value );
127
128 int32_t atmel_read_flash( dfu_device_t *device,
129 intel_buffer_in_t *buin,
130 uint8_t mem_segment,
131 const bool quiet);
132 /* read the flash from buin->info.data_start to data_end and place
133 * in buin.data. mem_segment is the segment of memory from the
134 * atmel_memory_unit_enum.
135 */
136
137 int32_t atmel_blank_check( dfu_device_t *device,
138 const uint32_t start,
139 const uint32_t end,
140 bool quiet );
141 /* check if memory between start byte and end byte (inclusive) is blank
142 * returns 0 for success, < 0 for communication errors, > 0 for not blank
143 */
144
145 int32_t atmel_start_app_reset( dfu_device_t *device );
146 /* Reset the processor and start application.
147 * This is done internally by forcing a watchdog reset.
148 * Depending on fuse settings this may go straight back into the bootloader.
149 */
150
151 int32_t atmel_start_app_noreset( dfu_device_t *device );
152 /* Start the app by jumping to the start of the app area.
153 * This does not do a true device reset.
154 */
155
156 int32_t atmel_secure( dfu_device_t *device );
157
158 int32_t atmel_getsecure( dfu_device_t *device );
159
160 int32_t atmel_flash( dfu_device_t *device,
161 intel_buffer_out_t *bout,
162 const bool eeprom,
163 const bool force,
164 const bool hide_progress );
165 /* Flash data from the buffer to the main program memory on the device.
166 * buffer contains the data to flash where buffer[0] is aligned with memory
167 * address zero (which could be inside the bootloader and unavailable).
168 * buffer[start / end] correspond to the start / end of available memory
169 * outside the bootloader.
170 * flash_page_size is the size of flash pages - used for alignment
171 * eeprom bool tells if you want to flash to eeprom or flash memory
172 * hide_progress bool sets whether to display progress
173 */
174
175 int32_t atmel_user( dfu_device_t *device,
176 intel_buffer_out_t *bout );
177 /* Flash data to the user page. Provide the buffer and the size of
178 * flash pages for the device (this is the size of the user page).
179 * Note that only the entire user page can be flashed because it is
180 * deleted before it is flashed to. Therfore buffer must fill this
181 * space (start at zero and contain page_size bytes).
182 */
183
184 void atmel_print_device_info( FILE *stream, atmel_device_info_t *info );
185
186 #ifdef __cplusplus
187 }
188 #endif
189
190 #endif