Mark Harris
/
SIEMENS_DLFEEDER_LOOP
Loop based controller for dual lane siemens siplace feeder.
Embed:
(wiki syntax)
Show/hide line numbers
IAP_LPC11U.cpp
00001 #if defined(TARGET_LPC11UXX) | defined(TARGET_LPC11U6X) 00002 00003 #include "IAP_LPC11U.h" 00004 00005 namespace 00006 { 00007 //This data must be global so it is not read from the stack 00008 unsigned int m_Command[5], m_Result[5]; 00009 typedef void (*IAP)(unsigned int [], unsigned int []); 00010 const IAP IAP_Entry = (IAP)0x1FFF1FF1; 00011 } 00012 00013 static inline void _iap_CriticalEntry() 00014 { 00015 //Disable interrupts 00016 __disable_irq(); 00017 00018 //Safely perform IAP entry 00019 IAP_Entry(m_Command, m_Result); 00020 00021 //Enable interrupts 00022 __enable_irq(); 00023 } 00024 00025 IapReturnCode IAP_PrepareSectors(unsigned int sector_start, unsigned int sector_end) 00026 { 00027 //Prepare the command array 00028 m_Command[0] = 50; 00029 m_Command[1] = sector_start; //The start of the sector to be prepared 00030 m_Command[2] = sector_end; //The end of the sector to be prepared 00031 00032 //Invoke critical IAP call... 00033 _iap_CriticalEntry(); 00034 00035 //Extract the result code 00036 IapReturnCode ret = (IapReturnCode)m_Result[0]; 00037 00038 //Return the result code 00039 return ret; 00040 } 00041 00042 IapReturnCode IAP_CopyRAMToFlash(void* ram_address, void* flash_address, unsigned int length) 00043 { 00044 //Prepare the command array 00045 m_Command[0] = 51; 00046 m_Command[1] = (unsigned int)flash_address; //Flash address where the contents are to be copied (it should be within 256bytes boundary) 00047 m_Command[2] = (unsigned int)ram_address; //RAM address to be copied (it should be in word boundary) 00048 m_Command[3] = length; //Number of data to be copied in bytes: 256, 512, 1024, or 4096 00049 m_Command[4] = SystemCoreClock / 1000; 00050 00051 //Invoke critical IAP call... 00052 _iap_CriticalEntry(); 00053 00054 //Extract the result code 00055 IapReturnCode ret = (IapReturnCode)m_Result[0]; 00056 00057 //Return the result code 00058 return ret; 00059 } 00060 00061 IapReturnCode IAP_EraseSectors(unsigned int sector_start, unsigned int sector_end) 00062 { 00063 //Prepare the command array 00064 m_Command[0] = 52; 00065 m_Command[1] = sector_start; //The start of the sector to be erased 00066 m_Command[2] = sector_end; //The end of the sector to be erased 00067 m_Command[3] = SystemCoreClock / 1000; //System Clock Frequency (CCLK) in kHz 00068 00069 //Invoke critical IAP call... 00070 _iap_CriticalEntry(); 00071 00072 //Extract the result code 00073 IapReturnCode ret = (IapReturnCode)m_Result[0]; 00074 00075 //Return the result code 00076 return ret; 00077 } 00078 00079 IapReturnCode IAP_BlankCheckSectors(unsigned int sector_start, unsigned int sector_end) 00080 { 00081 //Prepare the command array 00082 m_Command[0] = 53; 00083 m_Command[1] = sector_start; //The start of the sector to be checked 00084 m_Command[2] = sector_end; //The end of the sector to be checked 00085 00086 //Invoke critical IAP call... 00087 _iap_CriticalEntry(); 00088 00089 //Extract the result code 00090 IapReturnCode ret = (IapReturnCode)m_Result[0]; 00091 00092 //Return the result code 00093 return ret; 00094 } 00095 00096 unsigned int IAP_ReadPartID() 00097 { 00098 //Prepare the command array 00099 m_Command[0] = 54; 00100 00101 //Invoke critical IAP call... 00102 _iap_CriticalEntry(); 00103 00104 //Extract the part ID 00105 unsigned int ret = m_Result[1]; 00106 00107 //Return the part ID 00108 return ret; 00109 } 00110 00111 unsigned short IAP_ReadBootCodeVersion() 00112 { 00113 //Prepare the command array 00114 m_Command[0] = 55; 00115 00116 //Invoke critical IAP call... 00117 _iap_CriticalEntry(); 00118 00119 //Extract the boot code version 00120 unsigned int ret = (unsigned short)m_Result[1]; 00121 00122 //Return the boot code version 00123 return ret; 00124 } 00125 00126 IapReturnCode IAP_Compare(void* address1, void* address2, unsigned int bytes) 00127 { 00128 //Prepare the command array 00129 m_Command[0] = 56; 00130 m_Command[1] = (unsigned int)address1; //Starting flash or RAM address of data bytes to be compared. This address should be a word boundary. 00131 m_Command[2] = (unsigned int)address2; //Starting flash or RAM address of data bytes to be compared. This address should be a word boundary. 00132 m_Command[3] = bytes; //Number of bytes to be compared; should be a multiple of 4. 00133 00134 //Invoke critical IAP call... 00135 _iap_CriticalEntry(); 00136 00137 //Extract the result code 00138 IapReturnCode ret = (IapReturnCode)m_Result[0]; 00139 00140 //Return the result code 00141 return ret; 00142 } 00143 00144 /* This function resets some microcontroller peripherals to reset 00145 * hardware configuration to ensure that the USB In-System Programming module 00146 * will work properly. It is normally called from reset and assumes some reset 00147 * configuration settings for the MCU. 00148 * Some of the peripheral configurations may be redundant in your specific 00149 * project. 00150 */ 00151 void IAP_ReinvokeISP() 00152 { 00153 //Make sure USB clock is turned on before calling ISP 00154 //LPC_SYSCON->SYSAHBCLKCTRL |= 0x04000; 00155 00156 //Make sure 32-bit Timer 1 is turned on before calling ISP 00157 //LPC_SYSCON->SYSAHBCLKCTRL |= 0x00400; 00158 00159 //Make sure GPIO clock is turned on before calling ISP 00160 LPC_SYSCON->SYSAHBCLKCTRL |= 0x00040; 00161 00162 //Make sure IO configuration clock is turned on before calling ISP 00163 //LPC_SYSCON->SYSAHBCLKCTRL |= 0x10000; 00164 00165 #if defined(TARGET_LPC11U6X) 00166 //Set the vector table offset to address 0 00167 SCB->VTOR = 0; 00168 #endif 00169 00170 //Make sure AHB clock divider is 1:1 00171 LPC_SYSCON->SYSAHBCLKDIV = 1; 00172 00173 //Prepare the command array 00174 m_Command[0] = 57; 00175 00176 //Initialize the storage state machine 00177 //*((unsigned int*)(0x10000054)) = 0x0; 00178 00179 //Set stack pointer to ROM value (reset default) 00180 //This must be the last piece of code executed before calling ISP, 00181 //because most C expressions and function returns will fail after the stack pointer is changed. 00182 //__set_MSP(*((unsigned int*)0x00000000)); 00183 00184 //Invoke IAP call... 00185 IAP_Entry(m_Command, m_Result); 00186 00187 //Shouldn't return 00188 } 00189 00190 UID IAP_ReadUID() 00191 { 00192 //Prepare the command array 00193 m_Command[0] = 58; 00194 00195 //Invoke critical IAP call... 00196 _iap_CriticalEntry(); 00197 00198 //Extract the UID 00199 UID ret = { 00200 m_Result[1], 00201 m_Result[2], 00202 m_Result[3], 00203 m_Result[4] 00204 }; 00205 00206 //Return the UID 00207 return ret; 00208 } 00209 00210 IapReturnCode IAP_ErasePage(unsigned int page_start, unsigned int page_end) 00211 { 00212 //Prepare the command array 00213 m_Command[0] = 59; 00214 m_Command[1] = page_start; //The start of the page to be erased 00215 m_Command[2] = page_end; //The end of the page to be erased 00216 m_Command[3] = SystemCoreClock / 1000; //System Clock Frequency (CCLK) in kHz 00217 00218 //Invoke critical IAP call... 00219 _iap_CriticalEntry(); 00220 00221 //Extract the result code 00222 IapReturnCode ret = (IapReturnCode)m_Result[0]; 00223 00224 //Return the result code 00225 return ret; 00226 } 00227 00228 IapReturnCode IAP_WriteEEPROM(unsigned int ee_address, char* buffer, unsigned int length) 00229 { 00230 //Prepare the command array 00231 m_Command[0] = 61; 00232 m_Command[1] = ee_address; //EEPROM address (byte, half-word or word aligned) 00233 m_Command[2] = (unsigned int)buffer; //RAM address (byte, half-word or word aligned) 00234 m_Command[3] = length; //Number of bytes to be written (byte, half-word writes are ok) 00235 m_Command[4] = SystemCoreClock / 1000; //System Clock Frequency (CCLK) in kHz 00236 00237 //Invoke critical IAP call... 00238 _iap_CriticalEntry(); 00239 00240 //Extract the result code 00241 IapReturnCode ret = (IapReturnCode)m_Result[0]; 00242 00243 //Return the result code 00244 return ret; 00245 } 00246 00247 IapReturnCode IAP_ReadEEPROM(unsigned int ee_address, char* buffer, unsigned int length) 00248 { 00249 //Prepare the command array 00250 m_Command[0] = 62; 00251 m_Command[1] = ee_address; //EEPROM address (byte, half-word or word aligned) 00252 m_Command[2] = (unsigned int)buffer; //RAM address (byte, half-word or word aligned) 00253 m_Command[3] = length; //Number of bytes to be read (byte, half-word reads are ok) 00254 m_Command[4] = SystemCoreClock / 1000; //System Clock Frequency (CCLK) in kHz 00255 00256 //Invoke critical IAP call... 00257 _iap_CriticalEntry(); 00258 00259 //Extract the result code 00260 IapReturnCode ret = (IapReturnCode)m_Result[0]; 00261 00262 //Return the result code 00263 return ret; 00264 } 00265 00266 #endif
Generated on Wed Jul 13 2022 18:38:35 by 1.7.2