📄 nf.lst
字号:
502 2 Nf_send_address(nf_logical_block << 1);
503 2 }
504 1
505 1 Nf_send_address (((Byte*)&gl_address)[3]); /* 2nd address cycle */
506 1 Nf_send_address (((Byte*)&gl_address)[2]); /* 3rd address cycle */
507 1 if (NF_4_CYCLE_ADDRESS_BIT) /* Size of card >= 64Mbytes ?*/
508 1 Nf_send_address (((Byte*)&gl_address)[1]); /* 4th address cycle */
509 1
510 1 Nf_wait_busy();
511 1
512 1 /* Read the physical block number */
513 1 ((Byte*)&physical_block)[0] = Nf_rd_byte();
514 1 ((Byte*)&physical_block)[1] = Nf_rd_byte();
515 1
516 1 /* Calculate the physical sector address */
517 1 nf_current_physical_sector_addr = ((Uint32)(physical_block) << 5) + (gl_ptr_mem & NF_BLOCK_MASK);
518 1 Nf_CS_OFF();
519 1 return OK;
520 1 }
521
522
523 /*F**************************************************************************
524 * NAME: nf_read_close
525 *----------------------------------------------------------------------------
526 * PARAMS:
527 *
528 * return:
529 *----------------------------------------------------------------------------
530 * PURPOSE:
531 * Low level memory read close
532 *----------------------------------------------------------------------------
533 * EXAMPLE:
534 *----------------------------------------------------------------------------
535 * NOTE:
536 *----------------------------------------------------------------------------
537 * REQUIREMENTS:
538 *****************************************************************************/
539 void nf_read_close (void)
540 {
541 1 Nf_CS_OFF();
542 1 }
543
544
545 /*F*************************************************************************
546 * NAME: nf_read_byte
547 *---------------------------------------------------------------------------
548 * PARAMS:
549 *
C51 COMPILER V7.50 NF 09/20/2005 21:47:45 PAGE 10
550 * return:
551 * Data read from memory
552 *---------------------------------------------------------------------------
553 * PURPOSE:
554 * Low level memory read function
555 *----------------------------------------------------------------------------
556 * EXAMPLE:
557 *----------------------------------------------------------------------------
558 * NOTE:
559 *----------------------------------------------------------------------------
560 * REQUIREMENTS:
561 ****************************************************************************/
562 Byte nf_read_byte (void)
563 {
564 1 Byte b;
565 1
566 1 if (!gl_cpt_page)
567 1 {
568 2 Nf_CS_ON();
569 2 Nf_wait_busy();
570 2 Nf_read_open_A_area(nf_current_physical_sector_addr, 0x00);
571 2 b = Nf_rd_byte();
572 2 Nf_CS_OFF();
573 2 }
574 1 else
575 1 {
576 2 b = Nf_rd_byte();
577 2 }
578 1
579 1 gl_cpt_page++;
580 1
581 1 /* Detection of the end of data page */
582 1 if (((Byte*)&gl_cpt_page)[0] == NF_DATA_SIZE_H)
583 1 {
584 2 /* read spare data bytes */
585 2 Nf_rd_byte();
586 2 Nf_rd_byte();
587 2 Nf_rd_byte();
588 2 Nf_rd_byte();
589 2 Nf_rd_byte();
590 2 Nf_rd_byte();
591 2 Nf_rd_byte();
592 2 Nf_rd_byte();
593 2 Nf_rd_byte();
594 2 Nf_rd_byte();
595 2 Nf_rd_byte();
596 2 Nf_rd_byte();
597 2 Nf_rd_byte();
598 2 Nf_rd_byte();
599 2 Nf_rd_byte();
600 2 Nf_rd_byte();
601 2
602 2 gl_ptr_mem++; /* new page */
603 2 gl_cpt_page=0; /* start at column 0 */
604 2
605 2 if (!(((Byte*)&gl_ptr_mem)[3] & NF_BLOCK_MASK)) /* New block ? */
606 2 {
607 3 nf_read_open(gl_ptr_mem);
608 3 }
609 2 else
610 2 {
611 3 nf_current_physical_sector_addr++;
C51 COMPILER V7.50 NF 09/20/2005 21:47:45 PAGE 11
612 3 }
613 2 }
614 1 return b;
615 1 }
616
617
618 /*F**************************************************************************
619 * NAME: nf_read_sector
620 *----------------------------------------------------------------------------
621 * PARAMS:
622 * nb_sector: number of contiguous sector to read
623 * global: gl_ptr_mem
624 *
625 * return: OK read done
626 * KO read failure
627 *----------------------------------------------------------------------------
628 * PURPOSE:
629 * This function is an optimized function that writes nb-sector * 512 bytes
630 * from NF card to USB controller
631 *----------------------------------------------------------------------------
632 * EXAMPLE:
633 *----------------------------------------------------------------------------
634 * NOTE:
635 * nb_sector always >= 1, can not be zero
636 *----------------------------------------------------------------------------
637 * REQUIREMENTS:
638 *****************************************************************************/
639 bit nf_read_sector(Uint16 nb_sector)
640 {
641 1 Byte i;
642 1 bit begin_ping_pong;
643 1
644 1 begin_ping_pong = TRUE;
645 1
646 1 do
647 1 {
648 2 Nf_CS_ON();
649 2 Nf_wait_busy();
650 2 Nf_read_open_A_area(nf_current_physical_sector_addr, 0x00);
651 2
652 2 for (i = 8; i != 0; i--)
653 2 {
654 3 Usb_write_byte(Nf_rd_byte()); /* read 64 bytes from card */
655 3 Usb_write_byte(Nf_rd_byte());
656 3 Usb_write_byte(Nf_rd_byte());
657 3 Usb_write_byte(Nf_rd_byte());
658 3 Usb_write_byte(Nf_rd_byte());
659 3 Usb_write_byte(Nf_rd_byte());
660 3 Usb_write_byte(Nf_rd_byte());
661 3 Usb_write_byte(Nf_rd_byte());
662 3 Usb_write_byte(Nf_rd_byte());
663 3 Usb_write_byte(Nf_rd_byte());
664 3 Usb_write_byte(Nf_rd_byte());
665 3 Usb_write_byte(Nf_rd_byte());
666 3 Usb_write_byte(Nf_rd_byte());
667 3 Usb_write_byte(Nf_rd_byte());
668 3 Usb_write_byte(Nf_rd_byte());
669 3 Usb_write_byte(Nf_rd_byte());
670 3 Usb_write_byte(Nf_rd_byte());
671 3 Usb_write_byte(Nf_rd_byte());
672 3 Usb_write_byte(Nf_rd_byte());
673 3 Usb_write_byte(Nf_rd_byte());
C51 COMPILER V7.50 NF 09/20/2005 21:47:45 PAGE 12
674 3 Usb_write_byte(Nf_rd_byte());
675 3 Usb_write_byte(Nf_rd_byte());
676 3 Usb_write_byte(Nf_rd_byte());
677 3 Usb_write_byte(Nf_rd_byte());
678 3 Usb_write_byte(Nf_rd_byte());
679 3 Usb_write_byte(Nf_rd_byte());
680 3 Usb_write_byte(Nf_rd_byte());
681 3 Usb_write_byte(Nf_rd_byte());
682 3 Usb_write_byte(Nf_rd_byte());
683 3 Usb_write_byte(Nf_rd_byte());
684 3 Usb_write_byte(Nf_rd_byte());
685 3 Usb_write_byte(Nf_rd_byte());
686 3 Usb_write_byte(Nf_rd_byte());
687 3 Usb_write_byte(Nf_rd_byte());
688 3 Usb_write_byte(Nf_rd_byte());
689 3 Usb_write_byte(Nf_rd_byte());
690 3 Usb_write_byte(Nf_rd_byte());
691 3 Usb_write_byte(Nf_rd_byte());
692 3 Usb_write_byte(Nf_rd_byte());
693 3 Usb_write_byte(Nf_rd_byte());
694 3 Usb_write_byte(Nf_rd_byte());
695 3 Usb_write_byte(Nf_rd_byte());
696 3 Usb_write_byte(Nf_rd_byte());
697 3 Usb_write_byte(Nf_rd_byte());
698 3 Usb_write_byte(Nf_rd_byte());
699 3 Usb_write_byte(Nf_rd_byte());
700 3 Usb_write_byte(Nf_rd_byte());
701 3 Usb_write_byte(Nf_rd_byte());
702 3 Usb_write_byte(Nf_rd_byte());
703 3 Usb_write_byte(Nf_rd_byte());
704 3 Usb_write_byte(Nf_rd_byte());
705 3 Usb_write_byte(Nf_rd_byte());
706 3 Usb_write_byte(Nf_rd_byte());
707 3 Usb_write_byte(Nf_rd_byte());
708 3 Usb_write_byte(Nf_rd_byte());
709 3 Usb_write_byte(Nf_rd_byte());
710 3 Usb_write_byte(Nf_rd_byte());
711 3 Usb_write_byte(Nf_rd_byte());
712 3 Usb_write_byte(Nf_rd_byte());
713 3 Usb_write_byte(Nf_rd_byte());
714 3 Usb_write_byte(Nf_rd_byte());
715 3 Usb_write_byte(Nf_rd_byte());
716 3 Usb_write_byte(Nf_rd_byte());
717 3 Usb_write_byte(Nf_rd_byte());
718 3
719 3 if (begin_ping_pong)
720 3 {
721 4 begin_ping_pong = FALSE;
722 4 }
723 3 else
724 3 {
725 4 while (!Usb_tx_complete()); /* wait end of transfer */
726 4 Usb_clear_TXCMPL(); /* ack transfer */
727 4 }
728 3 Usb_set_TXRDY(); /* start usb transfer */
729 3 }
730 2
731 2 gl_ptr_mem++; /* new page */
732 2 Nf_CS_OFF();
733 2 if (! ( ((Byte*)&gl_ptr_mem)[3] & NF_BLOCK_MASK ) ) /* New block ? */
734 2 {
735 3 nf_read_open(gl_ptr_mem);
C51 COMPILER V7.50 NF 09/20/2005 21:47:45 PAGE 13
736 3 }
737 2 else
738 2 {
739 3 nf_current_physical_sector_addr++;
740 3 }
741 2 nb_sector--;
742 2 }
743 1 while (nb_sector != 0);
744 1
745 1 while (!Usb_tx_complete()); /* wait end of last transfer */
746 1 Usb_clear_TXCMPL(); /* ack transfer */
747 1
748 1 return OK;
749 1 }
750
751
752 /*F**************************************************************************
753 * NAME: nf_write_open
754 *----------------------------------------------------------------------------
755 *----------------------------------------------------------------------------
756 * PARAMS:
757 * pos: address of the the next write data
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -