📄 upsd_flash.lst
字号:
C51 COMPILER V7.10 UPSD_FLASH 05/22/2006 11:27:18 PAGE 7
366
367 error = poll & NVM_ERROR; // save timeout error bit at DQ5
368
369 poll = poll & NVM_DATA_POLL; // look at D7
370
371 if (poll == NVM_DATA_POLL) // compare DQ7
372
373 done = TRUE; // bulk erase OK,
374 // indicate successful exit criteria
375
376 else if (error == NVM_ERROR) // check for timeout error
377 err = TRUE; // indicate timeout error occurred
378
379 } while((done == FALSE) && (err == FALSE));
380
381
382 if (err == TRUE) // make sure timeout error and dat poll didn't
383 // occur simultaneously
384 {
385 poll = *(flash_bulk_erase_address); // Read flash status again
386
387 poll = poll & NVM_DATA_POLL; // get DQ7 of poll byte read from flash
388
389 if (poll == NVM_DATA_POLL) // compare DQ7
390
391 done = TRUE; // the flash erased OK at the same
392 // time timout error occured, indicate successful
393 // exit criteria
394
395 *(FLASH_BOOT_X555) = 0xF0; // reset the flash array (short reset instruction)
396 // now delay 3 msec per dat sheet
397 }
398
399 return(done); // a successful flash erase returns 1, timeout error returns 0
400
401 }
402 */
403
404
405 /*Module: flash_reset
406 Resets the main Flash memory to Read Array mode.
407 After this reset, the Flash memory may be read like a ROM device.
408 You'll need to include the header files generated by PSDsoft
409 Express. */
410 /*
411 void flash_reset() // reset flash, read array mode
412
413 {
414
415 // Note: the following constants (FLASH_COMMON_XXXX)
416 // are declared type volatile in the header file
417 // so they are not optimized away by the compiler
418
419 *(FLASH_COMMON_X555) = 0xAA; // unlock main flash, write 0xAA to addess 0xX555
420 *(FLASH_COMMON_XAAA) = 0x55; // unlock main flash, write 0x55 to addess 0xXAAA
421 *(FLASH_COMMON_X555) = 0xF0; // write 0xF0 command to reset
422 // Flash memory to Read Array Mode
423 // now delay 3 msec per dat sheet
424 }*/
425
426
427
C51 COMPILER V7.10 UPSD_FLASH 05/22/2006 11:27:18 PAGE 8
428 /* Module: flash_read_id
429 Reads the Flash Identifier byte from main Flash memory. You'll need
430 to include the header files generated by PSDsoft Express.
431 Important: The address passed to this function should be independent
432 of memory paging or else the PSD page register value should be set to
433 the correct page prior to calling this function.
434
435 Note: The flash memory in the boot area of a PSD813F2 or PSD813F4 does
436 not provide an ID. Only the main Flash memory in all PSD813FX provides
437 an ID. */
438
439
440 /*
441 unsigned char flash_read_id(flash_id_address) // read flash identifier
442 volatile unsigned char *flash_id_address;
443
444 {
445 unsigned char id;
446
447 // Note: the following constants (FLASH_COMMON_XXXX)
448 // are declared type volatile in the header file
449 // so they are not optimized away by the compiler
450
451 *(FLASH_COMMON_X555) = 0xAA; // unlock main flash, write 0xAA to addess 0xX555
452 *(FLASH_COMMON_XAAA) = 0x55; // unlock main flash, write 0x55 to addess 0xXAAA
453 *(FLASH_COMMON_X555) = 0x90; // write 0x90 command to get ID
454
455 id = *(flash_id_address); // read flash status, address bit A6 = 0
456 // A1 = 0
457 // A0 = 1
458 *(FLASH_COMMON_X555) = 0xF0; // reset the flash array (short reset instruction)
459 // now delay 3 msec per dat sheet
460
461 return (id); // return byte ID value
462 }
463 */
464
465
466
467 /* Module: flash_erase_sector
468 Erases the specified sector in main Flash memory.
469 Need to include mapflash.h. Important: The address passed to this function
470 should be independent of memory paging or else the PSD page register should
471 be set to the correct page prior to calling this function. */
472
473
474 unsigned char flash_erase_sector(
475 volatile unsigned char xdata * sector_erase_address)
476
477 {
478 1 char done;
479 1
480 1 unsigned char poll;
481 1 unsigned char error;
482 1 unsigned char err;
483 1
484 1 done = FALSE;
485 1
486 1 *(FLASH_COMMON_X555) = 0xAA; // unlock main flash, write 0xAA to addess 0xX555
487 1 *(FLASH_COMMON_XAAA) = 0x55; // unlock main flash, write 0x55 to addess 0xXAAA
488 1 *(FLASH_COMMON_X555) = 0x80; // write 0x80 command
489 1 *(FLASH_COMMON_X555) = 0xAA; // continue unlock sequence
C51 COMPILER V7.10 UPSD_FLASH 05/22/2006 11:27:18 PAGE 9
490 1 *(FLASH_COMMON_XAAA) = 0x55; // continue unlock sequence
491 1 *(sector_erase_address) = 0x30; // write 0x30 command to indicate sector erase command
492 1
493 1
494 1 do // now use data polling method to verify successful erase
495 1 {
496 2 poll = *(sector_erase_address); // read flash status from any address
497 2 // within the flash address sector space
498 2
499 2 error = poll & NVM_ERROR; // save timeout error bit at DQ5
500 2
501 2 poll = poll & NVM_DATA_POLL; // look at D7
502 2
503 2 if (poll == NVM_DATA_POLL) // compare DQ7
504 2
505 2 done = TRUE; // erase OK,
506 2 // indicate successful exit criteria
507 2
508 2 else if (error == NVM_ERROR) // check for timeout error
509 2
510 2 err = TRUE; // indicate timeout error occurred
511 2
512 2 } while((done == FALSE) && (error == FALSE));
513 1
514 1
515 1 if (err == TRUE) // make sure timeout error and data poll didn't
516 1 // occur simultaneously
517 1 {
518 2 poll = *(sector_erase_address); // Read flash status again
519 2
520 2 poll = poll & NVM_DATA_POLL; // get DQ7 of poll byte read from flash
521 2
522 2 if (poll == NVM_DATA_POLL) // compare DQ7
523 2
524 2 done = TRUE; // the flash erased OK at the same
525 2 // time timout error occured, indicate successful
526 2
527 2 *(FLASH_COMMON_X555) = 0xF0; // reset the flash array (short reset instruction)
528 2
529 2 } // exit criteria
530 1
531 1 return(done); // a successful flash erase returns 1, timeout error returns 0
532 1 }
533
534
535
536
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 471 ----
CONSTANT SIZE = ---- ----
XDATA SIZE = 13 ----
PDATA SIZE = ---- ----
DATA SIZE = ---- ----
IDATA SIZE = ---- ----
BIT SIZE = ---- ----
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -