lpc17xx_iap.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. #ifndef _LPC17XX_IAP_H_
  2. #define _LPC17XX_IAP_H_
  3. /*
  4. * Copyright (C) 2012 by Ole Reinhardt (ole.reinhardt@embedded-it.de)
  5. *
  6. * All rights reserved.
  7. *
  8. * Redistribution and use in source and binary forms, with or without
  9. * modification, are permitted provided that the following conditions
  10. * are met:
  11. *
  12. * 1. Redistributions of source code must retain the above copyright
  13. * notice, this list of conditions and the following disclaimer.
  14. * 2. Redistributions in binary form must reproduce the above copyright
  15. * notice, this list of conditions and the following disclaimer in the
  16. * documentation and/or other materials provided with the distribution.
  17. * 3. Neither the name of the copyright holders nor the names of
  18. * contributors may be used to endorse or promote products derived
  19. * from this software without specific prior written permission.
  20. *
  21. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  22. * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  23. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  24. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  25. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  26. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  27. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  28. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  29. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  30. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
  31. * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  32. * SUCH DAMAGE.
  33. *
  34. * For additional information see http://www.ethernut.de/
  35. *
  36. *
  37. * Parts taken from lpc177x_8x_iap.h 2011-11-21
  38. *
  39. * file lpc177x_8x_iap.h
  40. * brief Contains all functions support for IAP
  41. * on LPC177x_8x
  42. * version 1.0
  43. * date 21. November. 2011
  44. * author NXP MCU SW Application Team
  45. *
  46. * Copyright(C) 2011, NXP Semiconductor
  47. * All rights reserved.
  48. *
  49. ***********************************************************************
  50. * Software that is described herein is for illustrative purposes only
  51. * which provides customers with programming information regarding the
  52. * products. This software is supplied "AS IS" without any warranties.
  53. * NXP Semiconductors assumes no responsibility or liability for the
  54. * use of the software, conveys no license or title under any patent,
  55. * copyright, or mask work right to the product. NXP Semiconductors
  56. * reserves the right to make changes in the software without
  57. * notification. NXP Semiconductors also make no representation or
  58. * warranty that such application will be suitable for the specified
  59. * use without further testing or modification.
  60. * Permission to use, copy, modify, and distribute this software and its
  61. * documentation is hereby granted, under NXP Semiconductors'
  62. * relevant copyright in the software, without fee, provided that it
  63. * is used in conjunction with NXP Semiconductors microcontrollers. This
  64. * copyright, permission, and disclaimer notice must appear in all copies of
  65. * this code.
  66. **********************************************************************/
  67. /*----------------------------------------------------------------------------*
  68. General defines
  69. *----------------------------------------------------------------------------*/
  70. /* IAP entry location */
  71. #define IAP_LOCATION (0x1FFF1FF1UL)
  72. /**
  73. * \brief IAP command code definitions
  74. */
  75. typedef enum
  76. {
  77. IAP_PREPARE = 50, /* Prepare sector(s) for write operation */
  78. IAP_COPY_RAM2FLASH = 51, /* Copy RAM to Flash */
  79. IAP_ERASE = 52, /* Erase sector(s) */
  80. IAP_BLANK_CHECK = 53, /* Blank check sector(s) */
  81. IAP_READ_PART_ID = 54, /* Read chip part ID */
  82. IAP_READ_BOOT_VER = 55, /* Read chip boot code version */
  83. IAP_COMPARE = 56, /* Compare memory areas */
  84. IAP_REINVOKE_ISP = 57, /* Reinvoke ISP */
  85. IAP_READ_SERIAL_NUMBER = 58, /* Read serial number */
  86. } IAP_COMMAND_CODE;
  87. /**
  88. * \brief IAP status code definitions
  89. */
  90. typedef enum
  91. {
  92. CMD_SUCCESS, /* Command is executed successfully. */
  93. INVALID_COMMAND, /* Invalid command. */
  94. SRC_ADDR_ERROR, /* Source address is not on a word boundary. */
  95. DST_ADDR_ERROR, /* Destination address is not on a correct boundary. */
  96. SRC_ADDR_NOT_MAPPED, /* Source address is not mapped in the memory map. */
  97. DST_ADDR_NOT_MAPPED, /* Destination address is not mapped in the memory map. */
  98. COUNT_ERROR, /* Byte count is not multiple of 4 or is not a permitted value. */
  99. INVALID_SECTOR, /* Sector number is invalid. */
  100. SECTOR_NOT_BLANK, /* Sector is not blank. */
  101. SECTOR_NOT_PREPARED_FOR_WRITE_OPERATION, /* Command to prepare sector for write operation was not executed. */
  102. COMPARE_ERROR, /* Source and destination data is not same. */
  103. BUSY, /* Flash programming hardware interface is busy. */
  104. } IAP_STATUS_CODE;
  105. /**
  106. * \brief IAP write length definitions
  107. */
  108. typedef enum {
  109. IAP_WRITE_256 = 256,
  110. IAP_WRITE_512 = 512,
  111. IAP_WRITE_1024 = 1024,
  112. IAP_WRITE_4096 = 4096,
  113. } IAP_WRITE_SIZE;
  114. /**
  115. * \brief IAP command structure
  116. */
  117. typedef struct {
  118. uint32_t cmd; /* Command */
  119. uint32_t param[4]; /* Parameters */
  120. uint32_t status; /* status code */
  121. uint32_t result[4]; /* Result */
  122. } IAP_COMMAND_Type;
  123. /**
  124. * \brief IAP API
  125. */
  126. uint32_t Lpc17xxIapGetSectorNr (uint32_t addr);
  127. IAP_STATUS_CODE Lpc17xxIapSectorRead(uint32_t addr, void *data, size_t len);
  128. IAP_STATUS_CODE Lpc17xxIapSectorWrite(uint32_t dest, void* source, IAP_WRITE_SIZE size);
  129. IAP_STATUS_CODE Lpc17xxIapSectorErase(uint32_t start_sec, uint32_t end_sec);
  130. IAP_STATUS_CODE Lpc17xxIapSectorBlankCheck(uint32_t start_sec, uint32_t end_sec,
  131. uint32_t *first_nblank_off, uint32_t *first_nblank_val);
  132. IAP_STATUS_CODE Lpc17xxIapReadBootCodeVersion(uint8_t *major, uint8_t* minor);
  133. IAP_STATUS_CODE Lpc17xxIapReadDeviceSerialNumber(uint32_t *uid);
  134. int Lpc17xxIapParamRead(unsigned int pos, void *data, size_t len);
  135. int Lpc17xxIapParamWrite(unsigned int pos, const void *data, size_t len);
  136. #endif /* _LPC177X_IAP_H_ */