📄 mmc.lst
字号:
601 * NOTE:
602 * - pos may not be on the beginning of a block only if MMC card has the
603 * READ_BL_PARTIAL capability this has interest only if
604 * block size > 512 bytes
605 *----------------------------------------------------------------------------
606 * REQUIREMENTS:
607 *****************************************************************************/
608 bit mmc_read_open (Uint32 pos)
609 {
610 1 gl_ptr_mem = pos << 9; /* gl_ptr_mem = pos * 512 */
611 1 if (mmc_mem_busy)
612 1 {
C51 COMPILER V6.20c MMC 07/10/2002 15:17:49 PAGE 11
613 2 mmc_mem_busy = FALSE;
614 2 while (Mmc_card_busy()); /* wait end of programming */
615 2 }
616 1 Mmc_enable_flow_ctrl(); /* stop clock when FIFO 1&2 full*/
617 1 Mmc_set_read(); /* dir from card to uc */
618 1 Mmc_read_block_cmd(gl_ptr_mem); /* send read block */
619 1 // while (!Mmc_command_sent()); /* wait end of transmission */
620 1 gl_mem_tick = MMC_RESP_TIME;
621 1 while (mmc_check_response() == MMC_ERR_RESP)
622 1 {
623 2 if (gl_mem_tick == MMC_TIME_OUT)
624 2 {
625 3 return KO;
626 3 }
627 2 }
628 1 if ((mmc_read_response() & MMC_TRAN_STATE_MSK) == MMC_TRAN_STATE)
629 1 {
630 2 gl_mem_tick = MMC_DATA_TIME;
631 2 while (!Mmc_read_ready()) /* wait data in FIFO 1 */
632 2 {
633 3 if (gl_mem_tick == MMC_TIME_OUT)
634 3 {
635 4 return KO;
636 4 }
637 3 }
638 2 return OK;
639 2 }
640 1 else
641 1 {
642 2 return KO;
643 2 }
644 1 }
645
646
647 /*F**************************************************************************
648 * NAME: mmc_read_close
649 *----------------------------------------------------------------------------
650 * PARAMS:
651 *
652 * return:
653 *----------------------------------------------------------------------------
654 * PURPOSE:
655 * Memory card read close: release MMC card
656 *----------------------------------------------------------------------------
657 * EXAMPLE:
658 *----------------------------------------------------------------------------
659 * NOTE:
660 * End of block check is done by testing both FIFOs empty
661 *----------------------------------------------------------------------------
662 * REQUIREMENTS:
663 *****************************************************************************/
664 void mmc_read_close (void)
665 {
666 1 while (!Mmc_end_of_block_read()) /* check if end of block */
667 1 {
668 2 ACC = Mmc_rd_byte(); /* dummy read to end of block */
669 2 }
670 1 // Mmc_disable();
671 1 }
672
673
674 /*F*************************************************************************
C51 COMPILER V6.20c MMC 07/10/2002 15:17:49 PAGE 12
675 * NAME: mmc_read_byte
676 *---------------------------------------------------------------------------
677 * PARAMS:
678 * global: gl_ptr_mem
679 *
680 * return:
681 * Data read from memory
682 * gl_mem_failure set to TRUE if command failure (card removed)
683 *----------------------------------------------------------------------------
684 * PURPOSE:
685 * Card byte read function
686 *----------------------------------------------------------------------------
687 * EXAMPLE:
688 *----------------------------------------------------------------------------
689 * NOTE:
690 * The end of block read is detected when both FIFOs are empty
691 *----------------------------------------------------------------------------
692 * REQUIREMENTS:
693 ****************************************************************************/
694 Byte mmc_read_byte (void)
695 {
696 1 if (Mmc_end_of_block_read()) /* check if end of block */
697 1 {
698 2 Mmc_read_block_cmd(gl_ptr_mem); /* read next block */
699 2 gl_mem_tick = MMC_RESP_TIME;
700 2 while (mmc_check_response() == MMC_ERR_RESP)
701 2 {
702 3 if (gl_mem_tick == MMC_TIME_OUT)
703 3 {
704 4 gl_mem_failure = TRUE;
705 4 return 0xAA;
706 4 }
707 3 }
708 2 if ((mmc_read_response() & MMC_TRAN_STATE_MSK) == MMC_TRAN_STATE)
709 2 {
710 3 gl_mem_tick = MMC_DATA_TIME;
711 3 while (!Mmc_read_ready()) /* wait data in FIFO 1 */
712 3 {
713 4 if (gl_mem_tick == MMC_TIME_OUT)
714 4 {
715 5 gl_mem_failure = TRUE;
716 5 return 0xAA;
717 5 }
718 4 }
719 3 }
720 2 else
721 2 {
722 3 gl_mem_failure = TRUE;
723 3 return 0xAA;
724 3 }
725 2 }
726 1 gl_ptr_mem++;
727 1 return Mmc_rd_byte();
728 1 }
729
730
731 /*F**************************************************************************
732 * NAME: mmc_read_sector
733 *----------------------------------------------------------------------------
734 * PARAMS:
735 * global: gl_ptr_mem
736 *
C51 COMPILER V6.20c MMC 07/10/2002 15:17:49 PAGE 13
737 * return: OK read done
738 * KO read failure
739 *----------------------------------------------------------------------------
740 * PURPOSE:
741 * This function is an optimized function that writes 512 bytes from MMC
742 * card to USB controller
743 *----------------------------------------------------------------------------
744 * EXAMPLE:
745 *----------------------------------------------------------------------------
746 * NOTE:
747 *----------------------------------------------------------------------------
748 * REQUIREMENTS:
749 *****************************************************************************/
750 bit mmc_read_sector (void)
751 {
752 1 Byte i;
753 1
754 1 if (Mmc_end_of_block_read()) /* check if end of block */
755 1 {
756 2 Mmc_read_block_cmd(gl_ptr_mem); /* read next block */
757 2 // while (!Mmc_command_sent()); /* wait end of transmission */
758 2 gl_mem_tick = MMC_RESP_TIME;
759 2 while (mmc_check_response() == MMC_ERR_RESP)
760 2 {
761 3 if (gl_mem_tick == MMC_TIME_OUT)
762 3 {
763 4 gl_mem_failure = TRUE;
764 4 return KO;
765 4 }
766 3 }
767 2 if ((mmc_read_response() & MMC_TRAN_STATE_MSK) == MMC_TRAN_STATE)
768 2 {
769 3 gl_mem_tick = MMC_DATA_TIME;
770 3 while (!Mmc_read_ready()) /* wait data in FIFO 1 */
771 3 {
772 4 if (gl_mem_tick == MMC_TIME_OUT)
773 4 {
774 5 gl_mem_failure = TRUE;
775 5 return KO;
776 5 }
777 4 }
778 3 }
779 2 else
780 2 {
781 3 gl_mem_failure = TRUE;
782 3 return KO;
783 3 }
784 2 }
785 1 for (i = 8; i != 0; i--) /* read 8x64b = 512b */
786 1 {
787 2 Usb_write_byte(Mmc_rd_byte()); /* read 16 bytes from FIFO */
788 2 Usb_write_byte(Mmc_rd_byte());
789 2 Usb_write_byte(Mmc_rd_byte());
790 2 Usb_write_byte(Mmc_rd_byte());
791 2 Usb_write_byte(Mmc_rd_byte());
792 2 Usb_write_byte(Mmc_rd_byte());
793 2 Usb_write_byte(Mmc_rd_byte());
794 2 Usb_write_byte(Mmc_rd_byte());
795 2 Usb_write_byte(Mmc_rd_byte());
796 2 Usb_write_byte(Mmc_rd_byte());
797 2 Usb_write_byte(Mmc_rd_byte());
798 2 Usb_write_byte(Mmc_rd_byte());
C51 COMPILER V6.20c MMC 07/10/2002 15:17:49 PAGE 14
799 2 Usb_write_byte(Mmc_rd_byte());
800 2 Usb_write_byte(Mmc_rd_byte());
801 2 Usb_write_byte(Mmc_rd_byte());
802 2 Usb_write_byte(Mmc_rd_byte());
803 2 gl_mem_tick = MMC_DATA_TIME;
804 2 while (!Mmc_read_ready()) /* wait data in FIFO 1 */
805 2 {
806 3 if (gl_mem_tick == MMC_TIME_OUT)
807 3 {
808 4 gl_mem_failure = TRUE;
809 4 return KO;
810 4 }
811 3 }
812 2 Usb_write_byte(Mmc_rd_byte()); /* read 16 bytes from FIFO */
813 2 Usb_write_byte(Mmc_rd_byte());
814 2 Usb_write_byte(Mmc_rd_byte());
815 2 Usb_write_byte(Mmc_rd_byte());
816 2 Usb_write_byte(Mmc_rd_byte());
817 2 Usb_write_byte(Mmc_rd_byte());
818 2 Usb_write_byte(Mmc_rd_byte());
819 2 Usb_write_byte(Mmc_rd_byte());
820 2 Usb_write_byte(Mmc_rd_byte());
821 2 Usb_write_byte(Mmc_rd_byte());
822 2 Usb_write_byte(Mmc_rd_byte());
823 2 Usb_write_byte(Mmc_rd_byte());
824 2 Usb_write_byte(Mmc_rd_byte());
825 2 Usb_write_byte(Mmc_rd_byte());
826 2 Usb_write_byte(Mmc_rd_byte());
827 2 Usb_write_byte(Mmc_rd_byte());
828 2 gl_mem_tick = MMC_DATA_TIME;
829 2 while (!Mmc_read_ready()) /* wait data in FIFO 1 */
830 2 {
831 3 if (gl_mem_tick == MMC_TIME_OUT)
832 3 {
833 4 gl_mem_failure = TRUE;
834 4 return KO;
835 4 }
836 3 }
837 2 Usb_write_byte(Mmc_rd_byte()); /* read 16 bytes from FIFO */
838 2 Usb_write_byte(Mmc_rd_byte());
839 2 Usb_write_byte(Mmc_rd_byte());
840 2 Usb_write_byte(Mmc_rd_byte());
841 2 Usb_write_byte(Mmc_rd_byte());
842 2 Usb_write_byte(Mmc_rd_byte());
843 2 Usb_write_byte(Mmc_rd_byte());
844 2 Usb_write_byte(Mmc_rd_byte());
845 2 Usb_write_byte(Mmc_rd_byte());
846 2 Usb_write_byte(Mmc_rd_byte());
847 2 Usb_write_byte(Mmc_rd_byte());
848 2 Usb_write_byte(Mmc_rd_byte());
849 2 Usb_write_byte(Mmc_rd_byte());
850 2 Usb_write_byte(Mmc_rd_byte());
851 2 Usb_write_byte(Mmc_rd_byte());
852 2 Usb_write_byte(Mmc_rd_byte());
853 2 gl_mem_tick = MMC_DATA_TIME;
854 2 while (!Mmc_read_ready()) /* wait data in FIFO 1 */
855 2 {
856 3 if (gl_mem_tick == MMC_TIME_OUT)
857 3 {
858 4 gl_mem_failure = TRUE;
859 4 return KO;
860 4 }
C51 COMPILER V6.20c MMC 07/10/2002 15:17:49 PAGE 15
861 3 }
862 2 Usb_write_byte(Mmc_rd_byte()); /* read 16 bytes from FIFO */
863 2 Usb_write_byte(Mmc_rd_byte());
864 2 Usb_write_byte(Mmc_rd_byte());
865 2 Usb_write_byte(Mmc_rd_byte());
866 2 Usb_write_byte(Mmc_rd_byte());
867 2 Usb_write_byte(Mmc_rd_byte());
868 2 Usb_write_byte(Mmc_rd_byte());
869 2 Usb_write_byte(Mmc_rd_byte());
870 2 Usb_write_byte(Mmc_rd_byte());
871 2 Usb_write_byte(Mmc_rd_byte());
872 2 Usb_write_byte(Mmc_rd_byte());
873 2 Usb_write_byte(Mmc_rd_byte());
874 2 Usb_write_byte(Mmc_rd_byte());
875 2 Usb_write_byte(Mmc_rd_byte());
876 2 Usb_write_byte(Mmc_rd_byte());
877 2 Usb_write_byte(Mmc_rd_byte());
878 2
879 2 Usb_set_TXRDY(); /* start usb transfer */
880 2 while (!Usb_tx_complete()); /* wait end of transfer */
881 2 Usb_clear_TXCMPL(); /* ack transfer */
882 2 }
883 1 gl_ptr_mem += 512;
884 1 return OK;
885 1 }
886
887
888 /*F**************************************************************************
889 * NAME: mmc_write_open
890 *----------------------------------------------------------------------------
891 * PARAMS:
892 * pos: address of the the next write data
893 * global: gl_ptr_mem
894 *
895 * return:
896 * status: OK: open done
897 * KO: open not done
898 *----------------------------------------------------------------------------
899 * PURPOSE:
900 * Open memory card in write mode (write block)
901 *----------------------------------------------------------------------------
902 * EXAMPLE:
903 *----------------------------------------------------------------------------
904 * NOTE:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -