isp.h 6.3 KB

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