1 /** 2 * \file 3 * 4 * \brief In System Programming API 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 _ISP_H_ 48 #define _ISP_H_ 49 50 #include "conf_isp.h" 51 52 #ifdef __cplusplus 53 extern "C" { 54 #endif 55 56 /** 57 * \defgroup isp In System Programming API 58 * 59 * @{ 60 */ 61 62 /** 63 * \name Main In System Programming functions 64 * @{ 65 */ 66 67 /** 68 * \brief Initializes the ISP interface 69 * 70 * Example, load the JTAG ID in signature memory 71 */ 72 void isp_init(void); 73 74 /** 75 * \brief Gives the security state of the chip 76 * 77 * \return \c 1 if chip is secured, otherwise \c 0. 78 */ 79 bool isp_is_security(void); 80 81 /** 82 * \brief Change the boot process configuration 83 * to enable/disable the ISP mode for the next startup. 84 * 85 * \param force Enable the ISP mode for the next startup if true 86 */ 87 void isp_force_boot_isp(bool force); 88 89 /** 90 * \brief Erase the application flash area and eventually the eeprom 91 * 92 * \return \c 1 if function was successfully done, otherwise \c 0. 93 */ 94 bool isp_erase_chip(void); 95 96 /** 97 * \brief Erase a part of the application flash area 98 * This function must be called again as long as it returns 0. 99 * 100 * \return \c 1 if the whole application flash area is erased, otherwise it is 101 * not finished. 102 * 103 * This function has been created to split a long erase so that 104 * the ISP application is able to answer external pending requests. 105 */ 106 107 bool isp_erase_chip_split(void); 108 109 /** 110 * \brief Resets the device to start the user application 111 * 112 * The ISP mode must be disabled before (See isp_force_boot_isp(false)) 113 * to allow the boot process to jump to the user application. 114 * 115 * \note: this function is usually implemented by using a watchdog reset 116 * or a software reset to restart the CPU. 117 */ 118 void isp_start_appli(void); 119 //! @} 120 121 122 //! Data type for holding flash memory addresses 123 #ifdef ISP_SMALL_MEMORY_SIZE 124 typedef uint16_t isp_addr_t; 125 #else 126 typedef uint32_t isp_addr_t; 127 #endif 128 129 //! Memory API definition 130 typedef struct { 131 //! Size of the memory (unit Byte) 132 uint32_t size; 133 //! Function to read memory 134 void (*fnct_read) (void *dst, isp_addr_t src, uint16_t nbytes); 135 //! Function to write memory 136 void (*fnct_write) (isp_addr_t dst, const void *src, uint16_t nbytes); 137 } isp_mem_t; 138 139 /** 140 * \name Memory units index values 141 * Used to access at a memory through \ref isp_memories list. 142 * @{ 143 */ 144 #define ISP_MEM_FLASH 0x00 145 #define ISP_MEM_EEPROM 0x01 146 #define ISP_MEM_SECURITY 0x02 147 #define ISP_MEM_CONFIGURATION 0x03 148 #define ISP_MEM_BOOTLOADER 0x04 149 #define ISP_MEM_SIGNATURE 0x05 150 #define ISP_MEM_USER 0x06 151 #define ISP_MEM_INT_RAM 0x07 152 #define ISP_MEM_EXT_MEM_CS0 0x08 153 #define ISP_MEM_EXT_MEM_CS1 0x09 154 #define ISP_MEM_EXT_MEM_CS2 0x0A 155 #define ISP_MEM_EXT_MEM_CS3 0x0B 156 #define ISP_MEM_EXT_MEM_CS4 0x0C 157 #define ISP_MEM_EXT_MEM_CS5 0x0D 158 #define ISP_MEM_EXT_MEM_CS6 0x0E 159 #define ISP_MEM_EXT_MEM_CS7 0x0F 160 #define ISP_MEM_EXT_MEM_DF 0x10 161 #define ISP_MEM_COUNT 0x11 // Number of memory units 162 //! @} 163 164 //! Memories list structure 165 typedef union { 166 isp_mem_t const *mem[ISP_MEM_COUNT]; 167 struct { 168 isp_mem_t const *flash; 169 isp_mem_t const *eeprom; 170 isp_mem_t const *security; 171 isp_mem_t const *conf; 172 isp_mem_t const *bootloader; 173 isp_mem_t const *signature; 174 isp_mem_t const *user; 175 isp_mem_t const *int_ram; 176 isp_mem_t const *ext_mem_cs0; 177 isp_mem_t const *ext_mem_cs1; 178 isp_mem_t const *ext_mem_cs2; 179 isp_mem_t const *ext_mem_cs3; 180 isp_mem_t const *ext_mem_cs4; 181 isp_mem_t const *ext_mem_cs5; 182 isp_mem_t const *ext_mem_cs6; 183 isp_mem_t const *ext_mem_cs7; 184 isp_mem_t const *ext_mem_df; 185 }list; 186 } isp_mems_t; 187 188 //! Memories list declaration 189 extern const isp_mems_t isp_memories; 190 191 COMPILER_PACK_SET(1) // alignment requested to simulate a memory 192 193 //! Memory signature structure to store JTAG ID 194 typedef union { 195 uint8_t mem[4]; 196 struct { 197 uint8_t manufacture; 198 uint8_t product_number_msb; 199 uint8_t product_number_lsb; 200 uint8_t product_revision; 201 }; 202 } isp_mem_signature_t; 203 204 205 /** 206 * Memory bootloader structure 207 * 208 * In the FLIP protocol, this structure is used to store medium 209 * and minor bootloader versions: 210 * - Example, Version 0x00 give 1.0.0 on batchisp log 211 * - Example, Version 0x03 give 1.0.3 on batchisp log 212 * - Example, Version 0x25 give 1.2.5 on batchisp log 213 * - id1 & id2 are not used and must always be 0. 214 */ 215 typedef struct { 216 uint8_t version; 217 uint8_t id1; 218 uint8_t id2; 219 } isp_mem_bootloader_t; 220 221 COMPILER_PACK_RESET() 222 223 //! @} 224 225 #ifdef __cplusplus 226 } 227 #endif 228 229 #endif // _ISP_H_ 230