📄 upsd_flash.lst
字号:
C51 COMPILER V7.10 UPSD_FLASH 05/22/2006 11:27:18 PAGE 4
180
181
182 /* Module: flash_write_with_toggle
183 Programs a single byte, checks status using toggle method.
184 You'll need to include the header files generated by PSDsoft
185 Express. Important: if memory paging is used, the correct page
186 value must be set in the PSD page register prior to calling this
187 function. */
188 /*
189 unsigned char flash_write_with_toggle(addr,dat)
190 volatile unsigned char *addr;
191 unsigned char dat;
192
193 {
194 unsigned char done;
195 unsigned char error;
196 unsigned char err;
197 volatile unsigned char toggle_A;
198 volatile unsigned char toggle_B;
199
200 done = FALSE;
201 err = FALSE;
202
203 // Note: the following constants (FLASH_BOOT_XXXX)
204 // are declared type volatile in the header file
205 // so they are not optimized away by the compiler
206
207 *(FLASH_BOOT_X555) = 0xAA; // unlock main flash, write 0xAA to addess 0xX555
208 *(FLASH_BOOT_XAAA) = 0x55; // unlock main flash, write 0x55 to addess 0xXAAA
209 *(FLASH_BOOT_X555) = 0xA0; // write 0xA0 command to program
210
211 *(addr) = dat; // write byte to flash
212
213 // now use toggling method to verify successful write
214
215 toggle_A = *(addr); // Read the location that was just programmed
216
217 toggle_A = toggle_A & NVM_DATA_TOGGLE; // mask toggle bit at DQ6
218
219 do
220 {
221 toggle_B = *(addr); // Again read the location that was just programmed
222
223 error = toggle_B & NVM_ERROR; // save timeout error flag at DQ5
224
225 toggle_B = toggle_B & NVM_DATA_TOGGLE; // mask toggle bit at DQ6
226
227 if (toggle_A == toggle_B) // compare toggle bit DQ6
228
229 done = TRUE; // bit did not toggle, dat byte programmed into
230 // flash OK, indicate successful exit criteria
231 else
232 {
233 if (error == NVM_ERROR ) // check for timeout error
234 err = TRUE; // indicate timeout error occurred
235
236 toggle_A = toggle_B; // save most recent sample of toggle bit
237 // to compare with next sample
238 }
239
240 } while((done == FALSE) && (err == FALSE));
241
C51 COMPILER V7.10 UPSD_FLASH 05/22/2006 11:27:18 PAGE 5
242
243 if (err == TRUE) // make sure timeout error and dat toggle didn't
244 // occur simultaneously
245 {
246 toggle_B = *(addr); // Read location in flash again
247
248 toggle_B = toggle_B & NVM_DATA_TOGGLE; // mask toggle bit at DQ6
249
250 if (toggle_A == toggle_B) // compare toggle bit DQ6
251
252 done = TRUE; // dat byte programmed into flash OK at the same
253 // time timout error occured, indicate successful
254 // exit criteria
255
256 *(FLASH_BOOT_X555) = 0xF0; // reset the flash array (short reset instruction)
257 // now delay 3 msec per dat sheet
258 }
259
260 return(done); // a successful flash write returns 1, timeout error returns 0
261 }*/
262
263
264 /* Module: flash_erase_bulk
265 Erases the entire main Flash memory (all sectors).
266 You'll need to include the header files generated by PSDsoft
267 Express. Important: The address passed to this function should
268 be independent of memory paging or else the PSD page
269 register value should be set to the correct page prior to calling this
270 function.
271 Note: The address that is passed in this function can be an address that
272 resides in any Flash segment that has a chip select. For example, if
273 fs0 and fs5 are used in the design, passing an address in this function
274 that resides in either fs0 or fs5 will invoke the bulk erase operation. */
275
276 /*
277 unsigned char flash_erase_bulk(
278 volatile unsigned char xdata* flash_bulk_erase_address)
279 {
280 unsigned char done;
281 unsigned char poll;
282 unsigned char error;
283 unsigned char err;
284
285 done = FALSE;
286 err = FALSE;
287
288 // Note: the following constants (FLASH_COMMON_XXXX)
289 // are declared type volatile in the header file
290 // so they are not optimized away by the compiler
291
292 *(FLASH_COMMON_X555) = 0xAA; // unlock main flash, write 0xAA to addess 0xX555
293 *(FLASH_COMMON_XAAA) = 0x55; // unlock main flash, write 0x55 to addess 0xXAAA
294 *(FLASH_COMMON_X555) = 0x80; // write 0x80 command to erase entire chip
295 *(FLASH_COMMON_X555) = 0xAA; // continue unlock sequence
296 *(FLASH_COMMON_XAAA) = 0x55; // continue unlock sequence
297 *(FLASH_COMMON_X555) = 0x10; // write 0x10 command to complete erase command
298
299 do // now use dat polling method to verify successful erase
300 {
301 poll = *(flash_bulk_erase_address); // read flash status from any address
302 // within the defined flash address space
303
C51 COMPILER V7.10 UPSD_FLASH 05/22/2006 11:27:18 PAGE 6
304 error = poll & NVM_ERROR; // save timeout error bit at DQ5
305
306 poll = poll & NVM_DATA_POLL; // look at D7
307
308 if (poll == NVM_DATA_POLL) // compare DQ7
309
310 done = TRUE; // bulk erase OK,
311 // indicate successful exit criteria
312
313 else if (error == NVM_ERROR) // check for timeout error
314 err = TRUE; // indicate timeout error occurred
315
316 } while((done == FALSE) && (err == FALSE));
317
318
319 if (err == TRUE) // make sure timeout error and dat poll didn't
320 // occur simultaneously
321 {
322 poll = *(flash_bulk_erase_address); // Read flash status again
323
324 poll = poll & NVM_DATA_POLL; // get DQ7 of poll byte read from flash
325
326 if (poll == NVM_DATA_POLL) // compare DQ7
327
328 done = TRUE; // the flash erased OK at the same
329 // time timout error occured, indicate successful
330 // exit criteria
331
332 *(FLASH_COMMON_X555) = 0xF0; // reset the flash array (short reset instruction)
333 // now delay 3 msec per dat sheet
334 }
335
336 return(done); // a successful flash erase returns 1, timeout error returns 0
337
338 }*/
339 /*
340 unsigned char flash_boot_erase_bulk(
341 volatile unsigned char xdata* flash_bulk_erase_address)
342 {
343 unsigned char done;
344 unsigned char poll;
345 unsigned char error;
346 unsigned char err;
347
348 done = FALSE;
349 err = FALSE;
350
351 // Note: the following constants (FLASH_COMMON_XXXX)
352 // are declared type volatile in the header file
353 // so they are not optimized away by the compiler
354
355 *(FLASH_BOOT_X555) = 0xAA; // unlock main flash, write 0xAA to addess 0xX555
356 *(FLASH_BOOT_XAAA) = 0x55; // unlock main flash, write 0x55 to addess 0xXAAA
357 *(FLASH_BOOT_X555) = 0x80; // write 0x80 command to erase entire chip
358 *(FLASH_BOOT_X555) = 0xAA; // continue unlock sequence
359 *(FLASH_BOOT_XAAA) = 0x55; // continue unlock sequence
360 *(FLASH_BOOT_X555) = 0x10; // write 0x10 command to complete erase command
361
362 do // now use dat polling method to verify successful erase
363 {
364 poll = *(flash_bulk_erase_address); // read flash status from any address
365 // within the defined flash address space
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -