iap.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. /*
  2. * @brief Common IAP support functions
  3. *
  4. * @note
  5. * Copyright(C) NXP Semiconductors, 2013
  6. * All rights reserved.
  7. *
  8. * @par
  9. * Software that is described herein is for illustrative purposes only
  10. * which provides customers with programming information regarding the
  11. * LPC products. This software is supplied "AS IS" without any warranties of
  12. * any kind, and NXP Semiconductors and its licenser disclaim any and
  13. * all warranties, express or implied, including all implied warranties of
  14. * merchantability, fitness for a particular purpose and non-infringement of
  15. * intellectual property rights. NXP Semiconductors assumes no responsibility
  16. * or liability for the use of the software, conveys no license or rights under any
  17. * patent, copyright, mask work right, or any other intellectual property rights in
  18. * or to any products. NXP Semiconductors reserves the right to make changes
  19. * in the software without notification. NXP Semiconductors also makes no
  20. * representation or warranty that such application will be suitable for the
  21. * specified use without further testing or modification.
  22. *
  23. * @par
  24. * Permission to use, copy, modify, and distribute this software and its
  25. * documentation is hereby granted, under NXP Semiconductors' and its
  26. * licensor's relevant copyrights in the software, without fee, provided that it
  27. * is used in conjunction with NXP Semiconductors microcontrollers. This
  28. * copyright, permission, and disclaimer notice must appear in all copies of
  29. * this code.
  30. */
  31. #ifndef __IAP_H_
  32. #define __IAP_H_
  33. #ifdef __cplusplus
  34. extern "C" {
  35. #endif
  36. /** @defgroup COMMON_IAP CHIP: Common Chip ISP/IAP commands and return codes
  37. * @ingroup CHIP_Common
  38. * @{
  39. */
  40. /* IAP command definitions */
  41. #define IAP_PREWRRITE_CMD 50 /*!< Prepare sector for write operation command */
  42. #define IAP_WRISECTOR_CMD 51 /*!< Write Sector command */
  43. #define IAP_ERSSECTOR_CMD 52 /*!< Erase Sector command */
  44. #define IAP_BLANK_CHECK_SECTOR_CMD 53 /*!< Blank check sector */
  45. #define IAP_REPID_CMD 54 /*!< Read PartID command */
  46. #define IAP_READ_BOOT_CODE_CMD 55 /*!< Read Boot code version */
  47. #define IAP_COMPARE_CMD 56 /*!< Compare two RAM address locations */
  48. #define IAP_REINVOKE_ISP_CMD 57 /*!< Reinvoke ISP */
  49. #define IAP_READ_UID_CMD 58 /*!< Read UID */
  50. #define IAP_ERASE_PAGE_CMD 59 /*!< Erase page */
  51. #define IAP_EEPROM_WRITE 61 /*!< EEPROM Write command */
  52. #define IAP_EEPROM_READ 62 /*!< EEPROM READ command */
  53. /* IAP response definitions */
  54. #define IAP_CMD_SUCCESS 0 /*!< Command is executed successfully */
  55. #define IAP_INVALID_COMMAND 1 /*!< Invalid command */
  56. #define IAP_SRC_ADDR_ERROR 2 /*!< Source address is not on word boundary */
  57. #define IAP_DST_ADDR_ERROR 3 /*!< Destination address is not on a correct boundary */
  58. #define IAP_SRC_ADDR_NOT_MAPPED 4 /*!< Source address is not mapped in the memory map */
  59. #define IAP_DST_ADDR_NOT_MAPPED 5 /*!< Destination address is not mapped in the memory map */
  60. #define IAP_COUNT_ERROR 6 /*!< Byte count is not multiple of 4 or is not a permitted value */
  61. #define IAP_INVALID_SECTOR 7 /*!< Sector number is invalid or end sector number is greater than start sector number */
  62. #define IAP_SECTOR_NOT_BLANK 8 /*!< Sector is not blank */
  63. #define IAP_SECTOR_NOT_PREPARED 9 /*!< Command to prepare sector for write operation was not executed */
  64. #define IAP_COMPARE_ERROR 10 /*!< Source and destination data not equal */
  65. #define IAP_BUSY 11 /*!< Flash programming hardware interface is busy */
  66. #define IAP_PARAM_ERROR 12 /*!< nsufficient number of parameters or invalid parameter */
  67. #define IAP_ADDR_ERROR 13 /*!< Address is not on word boundary */
  68. #define IAP_ADDR_NOT_MAPPED 14 /*!< Address is not mapped in the memory map */
  69. #define IAP_CMD_LOCKED 15 /*!< Command is locked */
  70. #define IAP_INVALID_CODE 16 /*!< Unlock code is invalid */
  71. #define IAP_INVALID_BAUD_RATE 17 /*!< Invalid baud rate setting */
  72. #define IAP_INVALID_STOP_BIT 18 /*!< Invalid stop bit setting */
  73. #define IAP_CRP_ENABLED 19 /*!< Code read protection enabled */
  74. /* IAP_ENTRY API function type */
  75. typedef void (*IAP_ENTRY_T)(unsigned int[5], unsigned int[4]);
  76. /**
  77. * @brief Prepare sector for write operation
  78. * @param strSector : Start sector number
  79. * @param endSector : End sector number
  80. * @return Status code to indicate the command is executed successfully or not
  81. * @note This command must be executed before executing "Copy RAM to flash"
  82. * or "Erase Sector" command.
  83. * The end sector must be greater than or equal to start sector number
  84. */
  85. uint8_t Chip_IAP_PreSectorForReadWrite(uint32_t strSector, uint32_t endSector);
  86. /**
  87. * @brief Copy RAM to flash
  88. * @param dstAdd : Destination flash address where data bytes are to be written
  89. * @param srcAdd : Source flash address where data bytes are to be read
  90. * @param byteswrt : Number of bytes to be written
  91. * @return Status code to indicate the command is executed successfully or not
  92. * @note The addresses should be a 256 byte boundary and the number of bytes
  93. * should be 256 | 512 | 1024 | 4096
  94. */
  95. uint8_t Chip_IAP_CopyRamToFlash(uint32_t dstAdd, uint32_t *srcAdd, uint32_t byteswrt);
  96. /**
  97. * @brief Erase sector
  98. * @param strSector : Start sector number
  99. * @param endSector : End sector number
  100. * @return Status code to indicate the command is executed successfully or not
  101. * @note The end sector must be greater than or equal to start sector number
  102. */
  103. uint8_t Chip_IAP_EraseSector(uint32_t strSector, uint32_t endSector);
  104. /**
  105. * @brief Blank check a sector or multiples sector of on-chip flash memory
  106. * @param strSector : Start sector number
  107. * @param endSector : End sector number
  108. * @return Offset of the first non blank word location if the status code is SECTOR_NOT_BLANK
  109. * @note The end sector must be greater than or equal to start sector number
  110. */
  111. // FIXME - There are two return value (result[0] & result[1]
  112. // Result0:Offset of the first non blank word location if the Status Code is
  113. // SECTOR_NOT_BLANK.
  114. // Result1:Contents of non blank word location.
  115. uint8_t Chip_IAP_BlankCheckSector(uint32_t strSector, uint32_t endSector);
  116. /**
  117. * @brief Read part identification number
  118. * @return Part identification number
  119. */
  120. uint32_t Chip_IAP_ReadPID(void);
  121. /**
  122. * @brief Read boot code version number
  123. * @return Boot code version number
  124. */
  125. uint8_t Chip_IAP_ReadBootCode(void);
  126. /**
  127. * @brief Compare the memory contents at two locations
  128. * @param dstAdd : Destination of the RAM address of data bytes to be compared
  129. * @param srcAdd : Source of the RAM address of data bytes to be compared
  130. * @param bytescmp : Number of bytes to be compared
  131. * @return Offset of the first mismatch of the status code is COMPARE_ERROR
  132. * @note The addresses should be a word boundary and number of bytes should be
  133. * a multiply of 4
  134. */
  135. uint8_t Chip_IAP_Compare(uint32_t dstAdd, uint32_t srcAdd, uint32_t bytescmp);
  136. /**
  137. * @brief IAP reinvoke ISP to invoke the bootloader in ISP mode
  138. * @return none
  139. */
  140. uint8_t Chip_IAP_ReinvokeISP(void);
  141. /**
  142. * @brief Read the unique ID
  143. * @return Status code to indicate the command is executed successfully or not
  144. */
  145. uint32_t Chip_IAP_ReadUID(void);
  146. /**
  147. * @brief Erase a page or multiple papers of on-chip flash memory
  148. * @param strPage : Start page number
  149. * @param endPage : End page number
  150. * @return Status code to indicate the command is executed successfully or not
  151. * @note The page number must be greater than or equal to start page number
  152. */
  153. // FIXME - There are four return value
  154. // Result0:The first 32-bit word (at the lowest address)
  155. // Result1:The second 32-bit word.
  156. // Result2:The third 32-bit word.
  157. // Result3:The fourth 32-bit word.
  158. uint8_t Chip_IAP_ErasePage(uint32_t strPage, uint32_t endPage);
  159. /**
  160. * @}
  161. */
  162. #ifdef __cplusplus
  163. }
  164. #endif
  165. #endif /* __IAP_H_ */