📄 mmc.lst
字号:
905 * - pos must always be synchronized on a block boundary address
906 *----------------------------------------------------------------------------
907 * REQUIREMENTS:
908 *****************************************************************************/
909 bit mmc_write_open (Uint32 pos)
910 {
911 1 gl_ptr_mem = pos << 9; /* gl_ptr_mem = pos * 512 */
912 1 if (mmc_mem_busy)
913 1 {
914 2 mmc_mem_busy = FALSE;
915 2 while (Mmc_card_busy()); /* wait end of programming */
916 2 }
917 1 Mmc_disable_flow_ctrl(); /* enable clock for command */
918 1 Mmc_set_write(); /* dir from uc to card */
919 1 Mmc_write_block_cmd(gl_ptr_mem); /* send write block */
920 1 // while (!Mmc_command_sent()); /* wait end of transmission */
921 1 gl_mem_tick = MMC_RESP_TIME;
922 1 while (mmc_check_response() == MMC_ERR_RESP)
C51 COMPILER V6.20c MMC 07/10/2002 15:17:49 PAGE 16
923 1 {
924 2 if (gl_mem_tick == MMC_TIME_OUT)
925 2 {
926 3 return KO;
927 3 }
928 2 }
929 1 if ((mmc_read_response() & MMC_TRAN_STATE_MSK) != MMC_TRAN_STATE)
930 1 {
931 2 return KO;
932 2 }
933 1 else
934 1 {
935 2 Mmc_enable_flow_ctrl(); /* stop clock when FIFO 1&2 empty */
936 2 Mmc_enable_send(); /* send data after response */
937 2 return OK;
938 2 }
939 1 }
940
941
942 /*F**************************************************************************
943 * NAME: mmc_write_close
944 *----------------------------------------------------------------------------
945 * PARAMS:
946 * global: gl_ptr_mem
947 *
948 * return:
949 *----------------------------------------------------------------------------
950 * PURPOSE:
951 * Memory card write close
952 * finish programming end of block
953 * release MMC card
954 *----------------------------------------------------------------------------
955 * EXAMPLE:
956 *----------------------------------------------------------------------------
957 * NOTE:
958 *----------------------------------------------------------------------------
959 * REQUIREMENTS:
960 *****************************************************************************/
961 void mmc_write_close (void)
962 {
963 1 while ((((Byte*)&gl_ptr_mem)[3] != 0x00) || ((((Byte*)&gl_ptr_mem)[2] & MMC_PAGE_MASK) != 0x00))
964 1 {
965 2 Mmc_wr_byte(0x00); /* dummy write to end of block */
966 2 gl_ptr_mem++;
967 2 }
968 1 Mmc_disable_flow_ctrl(); /* re-enable clock for CRC status */
969 1 mmc_mem_busy = TRUE; /* memory is busy */
970 1 }
971
972
973 /*F**************************************************************************
974 * NAME: mmc_write_byte
975 *----------------------------------------------------------------------------
976 * PARAMS:
977 * b: data to write
978 * global: gl_ptr_mem
979 *
980 * return:
981 * write status: OK: write done
982 * KO: write not done
983 *----------------------------------------------------------------------------
984 * PURPOSE:
C51 COMPILER V6.20c MMC 07/10/2002 15:17:49 PAGE 17
985 * Card byte write function
986 *----------------------------------------------------------------------------
987 * EXAMPLE:
988 *----------------------------------------------------------------------------
989 * NOTE:
990 *----------------------------------------------------------------------------
991 * REQUIREMENTS:
992 *****************************************************************************/
993 bit mmc_write_byte (Byte b)
994 {
995 1 if (mmc_mem_busy)
996 1 {
997 2 mmc_mem_busy = FALSE;
998 2 while (Mmc_card_busy()); /* wait end of programming */
999 2 Mmc_write_block_cmd(gl_ptr_mem); /* write next block */
1000 2 Mmc_enable_flow_ctrl(); /* stop clock when FIFO 1&2 empty */
1001 2 Mmc_enable_send(); /* send data after response */
1002 2 Mmc_wr_byte(b); /* write 1 byte to card */
1003 2 gl_ptr_mem++;
1004 2 return OK; /* write done */
1005 2 }
1006 1 else
1007 1 {
1008 2 Mmc_wr_byte(b); /* write 1 byte to card */
1009 2 gl_ptr_mem++;
1010 2
1011 2 /* check if end of block */
1012 2 if ((((Byte*)&gl_ptr_mem)[3] == 0x00) && ((((Byte*)&gl_ptr_mem)[2] & MMC_PAGE_MASK) == 0x00))
1013 2 {
1014 3 Mmc_disable_flow_ctrl(); /* re-enable clock for CRC status */
1015 3 mmc_mem_busy = TRUE; /* memory is busy */
1016 3 }
1017 2 return OK; /* write done */
1018 2 }
1019 1 }
1020
1021
1022 /*F**************************************************************************
1023 * NAME: mmc_write_sector
1024 *----------------------------------------------------------------------------
1025 * PARAMS:
1026 * global: gl_ptr_mem
1027 *
1028 * return:
1029 * write status: OK: write done
1030 * KO: write not done
1031 *----------------------------------------------------------------------------
1032 * PURPOSE:
1033 * This function is an optimized function that writes 512 bytes from USB
1034 * controller to MMC card
1035 *----------------------------------------------------------------------------
1036 * EXAMPLE:
1037 *----------------------------------------------------------------------------
1038 * NOTE:
1039 *----------------------------------------------------------------------------
1040 * REQUIREMENTS:
1041 *****************************************************************************/
1042 bit mmc_write_sector (void)
1043 {
1044 1 Byte i;
1045 1
1046 1 if (mmc_mem_busy)
C51 COMPILER V6.20c MMC 07/10/2002 15:17:49 PAGE 18
1047 1 {
1048 2 mmc_mem_busy = FALSE;
1049 2 while (Mmc_card_busy()); /* wait end of programming */
1050 2 Mmc_write_block_cmd(gl_ptr_mem); /* write next block */
1051 2 Mmc_enable_flow_ctrl(); /* stop clock when FIFO 1&2 empty */
1052 2 Mmc_enable_send(); /* send data after response */
1053 2 }
1054 1
1055 1 for (i = 8; i != 0; i--) /* write 8x64b = 512b */
1056 1 {
1057 2 while (!Usb_rx_complete()); /* wait end of reception */
1058 2 Mmc_wr_byte(Usb_read_byte()); /* write 16 bytes to FIFO */
1059 2 Mmc_wr_byte(Usb_read_byte());
1060 2 Mmc_wr_byte(Usb_read_byte());
1061 2 Mmc_wr_byte(Usb_read_byte());
1062 2 Mmc_wr_byte(Usb_read_byte());
1063 2 Mmc_wr_byte(Usb_read_byte());
1064 2 Mmc_wr_byte(Usb_read_byte());
1065 2 Mmc_wr_byte(Usb_read_byte());
1066 2 Mmc_wr_byte(Usb_read_byte());
1067 2 Mmc_wr_byte(Usb_read_byte());
1068 2 Mmc_wr_byte(Usb_read_byte());
1069 2 Mmc_wr_byte(Usb_read_byte());
1070 2 Mmc_wr_byte(Usb_read_byte());
1071 2 Mmc_wr_byte(Usb_read_byte());
1072 2 Mmc_wr_byte(Usb_read_byte());
1073 2 Mmc_wr_byte(Usb_read_byte());
1074 2 while (Mmc_write_busy()); /* wait no more data in FIFO 1 */
1075 2 Mmc_wr_byte(Usb_read_byte()); /* write 16 bytes to FIFO */
1076 2 Mmc_wr_byte(Usb_read_byte());
1077 2 Mmc_wr_byte(Usb_read_byte());
1078 2 Mmc_wr_byte(Usb_read_byte());
1079 2 Mmc_wr_byte(Usb_read_byte());
1080 2 Mmc_wr_byte(Usb_read_byte());
1081 2 Mmc_wr_byte(Usb_read_byte());
1082 2 Mmc_wr_byte(Usb_read_byte());
1083 2 Mmc_wr_byte(Usb_read_byte());
1084 2 Mmc_wr_byte(Usb_read_byte());
1085 2 Mmc_wr_byte(Usb_read_byte());
1086 2 Mmc_wr_byte(Usb_read_byte());
1087 2 Mmc_wr_byte(Usb_read_byte());
1088 2 Mmc_wr_byte(Usb_read_byte());
1089 2 Mmc_wr_byte(Usb_read_byte());
1090 2 Mmc_wr_byte(Usb_read_byte());
1091 2 while (Mmc_write_busy()); /* wait no more data in FIFO 1 */
1092 2 Mmc_wr_byte(Usb_read_byte()); /* write 16 bytes to FIFO */
1093 2 Mmc_wr_byte(Usb_read_byte());
1094 2 Mmc_wr_byte(Usb_read_byte());
1095 2 Mmc_wr_byte(Usb_read_byte());
1096 2 Mmc_wr_byte(Usb_read_byte());
1097 2 Mmc_wr_byte(Usb_read_byte());
1098 2 Mmc_wr_byte(Usb_read_byte());
1099 2 Mmc_wr_byte(Usb_read_byte());
1100 2 Mmc_wr_byte(Usb_read_byte());
1101 2 Mmc_wr_byte(Usb_read_byte());
1102 2 Mmc_wr_byte(Usb_read_byte());
1103 2 Mmc_wr_byte(Usb_read_byte());
1104 2 Mmc_wr_byte(Usb_read_byte());
1105 2 Mmc_wr_byte(Usb_read_byte());
1106 2 Mmc_wr_byte(Usb_read_byte());
1107 2 Mmc_wr_byte(Usb_read_byte());
1108 2 while (Mmc_write_busy()); /* wait no more data in FIFO 1 */
C51 COMPILER V6.20c MMC 07/10/2002 15:17:49 PAGE 19
1109 2 Mmc_wr_byte(Usb_read_byte()); /* write 16 bytes to FIFO */
1110 2 Mmc_wr_byte(Usb_read_byte());
1111 2 Mmc_wr_byte(Usb_read_byte());
1112 2 Mmc_wr_byte(Usb_read_byte());
1113 2 Mmc_wr_byte(Usb_read_byte());
1114 2 Mmc_wr_byte(Usb_read_byte());
1115 2 Mmc_wr_byte(Usb_read_byte());
1116 2 Mmc_wr_byte(Usb_read_byte());
1117 2 Mmc_wr_byte(Usb_read_byte());
1118 2 Mmc_wr_byte(Usb_read_byte());
1119 2 Mmc_wr_byte(Usb_read_byte());
1120 2 Mmc_wr_byte(Usb_read_byte());
1121 2 Mmc_wr_byte(Usb_read_byte());
1122 2 Mmc_wr_byte(Usb_read_byte());
1123 2 Mmc_wr_byte(Usb_read_byte());
1124 2 Mmc_wr_byte(Usb_read_byte());
1125 2 Usb_clear_RXOUT(); /* usb read acknowledgement */
1126 2 }
1127 1 gl_ptr_mem += 512;
1128 1 /* always end of page */
1129 1 Mmc_disable_flow_ctrl(); /* re-enable clock for CRC status */
1130 1 mmc_mem_busy = TRUE;
1131 1 return OK; /* write done */
1132 1 }
1133
1134
1135 /*F**************************************************************************
1136 * NAME: mmc_format
1137 *----------------------------------------------------------------------------
1138 * PARAMS:
1139 *
1140 * return:
1141 * Address of the format parameter structure in code
1142 *----------------------------------------------------------------------------
1143 * PURPOSE:
1144 * This function is called by the fat_format function and returns a pointer
1145 * to a table containing the format parameters.
1146 *----------------------------------------------------------------------------
1147 * EXAMPLE:
1148 *----------------------------------------------------------------------------
1149 * NOTE:
1150 * MMC FORMAT PARAMETERS
1151 * CAPACITY LBAs CYL HDs S/T CLUSTs S/C S/F FAT HID
1152 * 4MB 7872 123 2 32 975 8 3 12 32
1153 * 8MB 15680 245 2 32 1950 8 6 12 32
1154 * 16MB 31360 490 2 32 3908 8 12 12 32
1155 * 28MB 54784 428 4 32 13652 4 54 16 32
1156 * 32MB 62720 490 4 32 15632 4 62 16 32
1157 * 64MB 125440 490 8 32 31282 4 123 16 32
1158 * 128MB 250880 980 8 32 62581 4 245 16 32
1159 * 256MB 501760 980 16 32 62720 8 245 16 32
1160 *----------------------------------------------------------------------------
1161 * REQUIREMENTS:
1162 *****************************************************************************/
1163 s_format code * mmc_format (void)
1164 {
1165 1 code s_format mmc_tab_format[]=
1166 1 {
1167 1 /* nb_cylinder, nb_head, nb_sector, nb_hidden, nb_sector_per_cluster */
1168 1 { (Uint16)123, (Byte)2, (Byte)32, (Byte)32, (Byte)8 }, /* 4MB */
1169 1 { (Uint16)245, (Byte)2, (Byte)32, (Byte)32, (Byte)8 }, /* 8MB */
1170 1 { (Uint16)490, (Byte)2, (Byte)32, (Byte)32, (Byte)8 }, /* 16MB */
C51 COMPILER V6.20c MMC 07/10/2002 15:17:49 PAGE 20
1171 1 { (Uint16)428, (Byte)4, (Byte)32, (Byte)32, (Byte)4 }, /* 28MB */
1172 1 { (Uint16)490, (Byte)4, (Byte)32, (Byte)32, (Byte)4 }, /* 32MB */
1173 1 { (Uint16)490, (Byte)8, (Byte)32, (Byte)32, (Byte)4 }, /* 64MB */
1174 1 { (Uint16)980, (Byte)8, (Byte)32, (Byte)32, (Byte)4 }, /* 128MB */
1175 1 { (Uint16)980, (Byte)16, (Byte)32, (Byte)32, (Byte)8 }, /* 256MB */
1176 1 };
1177 1
1178 1 /* -- MMC Type Selection -- */
1179 1 if (Mmc_disk_size() >= MMC_SIZE_256MB) return &mmc_tab_format[MMC_256MB];
1180 1 if (Mmc_disk_size() >= MMC_SIZE_128MB) return &mmc_tab_format[MMC_128MB];
1181 1 if (Mmc_disk_size() >= MMC_SIZE_64MB) return &mmc_tab_format[MMC_64MB];
1182 1 if (Mmc_disk_size() >= MMC_SIZE_32MB) return &mmc_tab_format[MMC_32MB];
1183 1 if (Mmc_disk_size() >= MMC_SIZE_28MB) return &mmc_tab_format[MMC_28MB];
1184 1 if (Mmc_disk_size() >= MMC_SIZE_16MB) return &mmc_tab_format[MMC_16MB];
1185 1 if (Mmc_disk_size() >= MMC_SIZE_8MB) return &mmc_tab_format[MMC_8MB];
1186 1 return &mmc_tab_format[MMC_4MB];
1187 1 }
1188
1189
1190
1191
1192
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 2183 ----
CONSTANT SIZE = 48 ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = 1 3
IDATA SIZE = 4 ----
BIT SIZE = 1 2
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -