LPCOpen Platform for LPC112X microcontrollers  112X
LPCOpen Platform for the NXP LPC112X family of Microcontrollers
iap.c
Go to the documentation of this file.
1 /*
2  * @brief Common FLASH 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 licensor 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 
32 #include "chip.h"
33 
34 /*****************************************************************************
35  * Private types/enumerations/variables
36  ****************************************************************************/
37 
38 /*****************************************************************************
39  * Public types/enumerations/variables
40  ****************************************************************************/
41 
42 /*****************************************************************************
43  * Private functions
44  ****************************************************************************/
45 
46 /*****************************************************************************
47  * Public functions
48  ****************************************************************************/
49 
50 /* Prepare sector for write operation */
51 uint8_t Chip_IAP_PreSectorForReadWrite(uint32_t strSector, uint32_t endSector)
52 {
53  uint32_t command[5], result[5];
54 
55  command[0] = IAP_PREWRRITE_CMD;
56  command[1] = strSector;
57  command[2] = endSector;
58  iap_entry(command, result);
59 
60  return result[0];
61 }
62 
63 /* Copy RAM to flash */
64 uint8_t Chip_IAP_CopyRamToFlash(uint32_t dstAdd, uint32_t *srcAdd, uint32_t byteswrt)
65 {
66  uint32_t command[5], result[5];
67 
68  command[0] = IAP_WRISECTOR_CMD;
69  command[1] = dstAdd;
70  command[2] = (uint32_t) srcAdd;
71  command[3] = byteswrt;
72  command[4] = SystemCoreClock / 1000;
73  iap_entry(command, result);
74 
75  return result[0];
76 }
77 
78 /* Erase sector */
79 uint8_t Chip_IAP_EraseSector(uint32_t strSector, uint32_t endSector)
80 {
81  uint32_t command[5], result[5];
82 
83  command[0] = IAP_ERSSECTOR_CMD;
84  command[1] = strSector;
85  command[2] = endSector;
86  command[3] = SystemCoreClock / 1000;
87  iap_entry(command, result);
88 
89  return result[0];
90 }
91 
92 /* Blank check sector */
93 uint8_t Chip_IAP_BlankCheckSector(uint32_t strSector, uint32_t endSector)
94 {
95  uint32_t command[5], result[5];
96 
97  command[0] = IAP_BLANK_CHECK_SECTOR_CMD;
98  command[1] = strSector;
99  command[2] = endSector;
100  iap_entry(command, result);
101 
102  return result[0];
103 }
104 
105 /* Read part identification number */
106 uint32_t Chip_IAP_ReadPID(void)
107 {
108  uint32_t command[5], result[5];
109 
110  command[0] = IAP_REPID_CMD;
111  iap_entry(command, result);
112 
113  return result[1];
114 }
115 
116 /* Read boot code version number */
117 uint32_t Chip_IAP_ReadBootCode(void)
118 {
119  uint32_t command[5], result[5];
120 
121  command[0] = IAP_READ_BOOT_CODE_CMD;
122  iap_entry(command, result);
123 
124  return result[1] & 0xffff;
125 }
126 
127 /* IAP compare */
128 uint8_t Chip_IAP_Compare(uint32_t dstAdd, uint32_t srcAdd, uint32_t bytescmp)
129 {
130  uint32_t command[5], result[5];
131 
132  command[0] = IAP_COMPARE_CMD;
133  command[1] = dstAdd;
134  command[2] = srcAdd;
135  command[3] = bytescmp;
136  iap_entry(command, result);
137 
138  return result[0];
139 }
140 
141 /* Reinvoke ISP */
142 uint8_t Chip_IAP_ReinvokeISP(void)
143 {
144  uint32_t command[5], result[5];
145 
146  command[0] = IAP_REINVOKE_ISP_CMD;
147  iap_entry(command, result);
148 
149  return result[0];
150 }
151 
152 /* Read the unique ID */
153 uint32_t Chip_IAP_ReadUID(uint32_t* uid)
154 {
155  uint32_t command[5], result[5];
156  uint32_t i;
157 
158  command[0] = IAP_READ_UID_CMD;
159  iap_entry(command, result);
160 
161  for (i=0; i<4; i++)
162  *(uid+i) = result[i+1];
163 
164  return result[0];
165 }
166 
167 /* Erase page */
168 uint8_t Chip_IAP_ErasePage(uint32_t strPage, uint32_t endPage)
169 {
170  uint32_t command[5], result[5];
171 
172  command[0] = IAP_ERASE_PAGE_CMD;
173  command[1] = strPage;
174  command[2] = endPage;
175  command[3] = SystemCoreClock / 1000;
176  iap_entry(command, result);
177 
178  return result[0];
179 }