📄 sd.lst
字号:
1182 ************************************************/
1183 #pragma disable
1184 /*bit*/U8 DMA_load_sector(U32 sector, U8 dma_cs)
1185 {
1186 1 /* U8 data i = 5;
1187 1 do
1188 1 {
1189 1 SDCIF_CMD12();
1190 1 SDH_DMA_CS = dma_cs;
1191 1 SD_lba = sector << 9;
1192 1 if(SDCIF_CMD17())
1193 1 return OK;
1194 1 }
1195 1 while(--i);
1196 1 (*(void(*)())0)();
1197 1 return KO;*/
1198 1 U8 data i = 5;
1199 1 do
1200 1 {
1201 2 SDCIF_CMD12();
1202 2 if(SDHostRead512B_LBA(sector, dma_cs))
1203 2 {
1204 3 if(SDHostRead512B_LBA(sector, dma_cs))
1205 3 return OK;
1206 3 }
1207 2 SYSDelay();
1208 2 SYSDelay();
1209 2 }
1210 1 while(--i);
1211 1 return KO;
1212 1 }
1213 /************************************************
1214 函 数 名: SDHostWrite512B_LBA()
1215 功 能:从逻辑块地址开始写入512字节
1216 说 明:数据存放地址由SDH_DMA_CS决定
1217 调 用:
1218 全局变量:ErrVal, SD_lba(FlashAddr[3:0])
1219 入口参数:无
1220 出口参数:无
1221 返 回 值:0 -> success, 1 -> failure
1222 ************************************************/
1223 bit DMA_write_sector(U32 sector, U8 dma_cs)
1224 {
1225 1 //SDCIF_CMD12();
1226 1 SDH_DMA_CS = dma_cs;
1227 1 SD_lba = sector << 9;
1228 1 if(!SDCIF_CMD24())
1229 1 {
1230 2 if(!SDCIF_CMD24())
1231 2 {
1232 3 return KO;
1233 3 }
C51 COMPILER V8.08 SD 07/28/2007 11:42:15 PAGE 21
1234 2 }
1235 1 return OK;
1236 1 }
1237 /************************************************
1238 函 数 名: SD_SysInit()
1239 功 能:SD host和SD memory系统初始化
1240 说 明:
1241 调 用:
1242 全局变量:
1243 入口参数:无
1244 出口参数:无
1245 返 回 值:无
1246 ************************************************/
1247 void SD_SysInit(void)
1248 {
1249 1 /* SDCIF_Init();
1250 1 if(!GetSDMemoryOCR())//added MMC CMD1
1251 1 {
1252 1 #if TX_DEBUG
1253 1 SendChar(0xAB);
1254 1 #endif
1255 1
1256 1 SDIFCON0 = 0x00;
1257 1 //SYSDelay();
1258 1 //(*(void(*)())0)();
1259 1 LedFlash(50);
1260 1 }
1261 1 SDMemoryCardInit();*/
1262 1
1263 1 U8 i = 5;
1264 1 do
1265 1 {
1266 2 SDCIF_Init();
1267 2 if(!GetSDMemoryOCR())//added MMC CMD1
1268 2 {
1269 3 SDIFCON0 = 0x00;
1270 3 SYSDelay();
1271 3 }
1272 2 else
1273 2 break;
1274 2 }
1275 1 while(--i);
1276 1 if(!i)
1277 1 {
1278 2 #if TX_DEBUG
1279 2 SendChar(0xAB);
1280 2 #endif
1281 2 LedFlash(50);
1282 2 }
1283 1 SDMemoryCardInit();
1284 1 }
1285
1286
1287 /*F**************************************************************************
1288 * NAME: sd_format
1289 *----------------------------------------------------------------------------
1290 * PARAMS:
1291 *
1292 * return:
1293 * Address of the format parameter structure in code
1294 *----------------------------------------------------------------------------
1295 * PURPOSE:
C51 COMPILER V8.08 SD 07/28/2007 11:42:15 PAGE 22
1296 * This function is called by the fat_format function and returns a pointer
1297 * to a table containing the format parameters.
1298 *----------------------------------------------------------------------------
1299 * EXAMPLE:
1300 *----------------------------------------------------------------------------
1301 * NOTE:
1302 * The following values are maximum. The number of cylinder is calculated
1303 * with the real LBAs of the card.
1304 * SD FORMAT PARAMETERS
1305 * CAPACITY LBAs CYL HDs S/T CLUSTs S/C S/F FAT HID
1306 * 4MB 8032 251 2 16 198 16 2 12 27
1307 * 8MB 16224 507 2 16 1010 16 3 12 25
1308 * 16MB 32448 507 2 32 1011 32 3 12 57
1309 * 32MB 64896 507 4 32 2025 32 6 12 51
1310 * 64MB 129792 507 8 32 4053 32 12 12 39
1311 * 128MB 259584 1014 8 32 8106 32 32 16 95
1312 * 256MB 519168 1014 16 32 16216 32 64 16 95
1313 *
1314 * MMC FORMAT PARAMETERS
1315 * CAPACITY LBAs CYL HDs S/T CLUSTs S/C S/F FAT HID
1316 * 4MB 8192 128 2 32 975 8 3 12 32
1317 * 8MB 16384 256 2 32 1950 8 6 12 32
1318 * 16MB 32768 512 2 32 3908 8 12 12 32
1319 * 28MB 57344 448 4 32 13652 4 54 16 32
1320 * 32MB 65536 512 4 32 15632 4 62 16 32
1321 * 64MB 131072 512 8 32 31282 4 123 16 32
1322 * 128MB 262144 1024 8 32 62581 4 245 16 32
1323 * 256MB 524288 1024 16 32 62720 8 245 16 32
1324 *----------------------------------------------------------------------------
1325 * REQUIREMENTS:
1326 *****************************************************************************/
1327 #if( 0 )
s_format * sd_format (void)
{
s_format pdata *tab;
tab = (s_format pdata *)gl_buffer;
if (sd_flag == SD)
{
code s_format sd_tab_format[]=
{
/* nb_cylinder, nb_head, nb_sector, nb_hidden, nb_sector_per_cluster */
{ (Uint16)0, (Byte)2, (Byte)16, (Byte)27, (Byte)16 }, /* 4MB */
{ (Uint16)0, (Byte)2, (Byte)16, (Byte)25, (Byte)16 }, /* 8MB */
{ (Uint16)0, (Byte)2, (Byte)32, (Byte)57, (Byte)32 }, /* 16MB */
{ (Uint16)0, (Byte)4, (Byte)32, (Byte)51, (Byte)32 }, /* 32MB */
{ (Uint16)0, (Byte)8, (Byte)32, (Byte)39, (Byte)32 }, /* 64MB */
{ (Uint16)0, (Byte)8, (Byte)32, (Byte)95, (Byte)32 }, /* 128MB */
{ (Uint16)0, (Byte)16, (Byte)32, (Byte)95, (Byte)32 }, /* 256MB */
};
/* -- SD Type Selection -- */
if (Sd_disk_size() <= SD_SIZE_4MB)
{
*tab = sd_tab_format[SD_4MB];
/* calculation of cylinder number */
(*tab).nb_cylinder = (Sd_disk_size() + 1) /
(sd_tab_format[SD_4MB].nb_head *
sd_tab_format[SD_4MB].nb_sector);
return tab;
}
C51 COMPILER V8.08 SD 07/28/2007 11:42:15 PAGE 23
if (Sd_disk_size() <= SD_SIZE_8MB)
{
*tab = sd_tab_format[SD_8MB];
/* calculation of cylinder number */
(*tab).nb_cylinder = (Sd_disk_size() + 1) /
(sd_tab_format[SD_8MB].nb_head *
sd_tab_format[SD_8MB].nb_sector);
return tab;
}
if (Sd_disk_size() <= SD_SIZE_16MB)
{
*tab = sd_tab_format[SD_16MB];
/* calculation of cylinder number */
(*tab).nb_cylinder = (Sd_disk_size() + 1) /
(sd_tab_format[SD_16MB].nb_head *
sd_tab_format[SD_16MB].nb_sector);
return tab;
}
if (Sd_disk_size() <= SD_SIZE_32MB)
{
*tab = sd_tab_format[SD_32MB];
/* calculation of cylinder number */
(*tab).nb_cylinder = (Sd_disk_size() + 1) /
(sd_tab_format[SD_32MB].nb_head *
sd_tab_format[SD_32MB].nb_sector);
return tab;
}
if (Sd_disk_size() <= SD_SIZE_64MB)
{
*tab = sd_tab_format[SD_64MB];
/* calculation of cylinder number */
(*tab).nb_cylinder = (Sd_disk_size() + 1) /
(sd_tab_format[SD_64MB].nb_head *
sd_tab_format[SD_64MB].nb_sector);
return tab;
}
if (Sd_disk_size() <= SD_SIZE_128MB)
{
*tab = sd_tab_format[SD_128MB];
/* calculation of cylinder number */
(*tab).nb_cylinder = (Sd_disk_size() + 1) /
(sd_tab_format[SD_128MB].nb_head *
sd_tab_format[SD_128MB].nb_sector);
return tab;
}
else
{
*tab = sd_tab_format[SD_256MB];
/* calculation of cylinder number */
(*tab).nb_cylinder = (Sd_disk_size() + 1) /
(sd_tab_format[SD_256MB].nb_head *
sd_tab_format[SD_256MB].nb_sector);
return tab;
}
}
else
{
code s_format sd_tab_format[]=
{
/* nb_cylinder, nb_head, nb_sector, nb_hidden, nb_sector_per_cluster */
{ (Uint16)0, (Byte)2, (Byte)32, (Byte)32, (Byte)8 }, /* 4MB */
{ (Uint16)0, (Byte)2, (Byte)32, (Byte)32, (Byte)8 }, /* 8MB */
C51 COMPILER V8.08 SD 07/28/2007 11:42:15 PAGE 24
{ (Uint16)0, (Byte)2, (Byte)32, (Byte)32, (Byte)8 }, /* 16MB */
{ (Uint16)0, (Byte)4, (Byte)32, (Byte)32, (Byte)4 }, /* 28MB */
{ (Uint16)0, (Byte)4, (Byte)32, (Byte)32, (Byte)4 }, /* 32MB */
{ (Uint16)0, (Byte)8, (Byte)32, (Byte)32, (Byte)4 }, /* 64MB */
{ (Uint16)0, (Byte)8, (Byte)32, (Byte)32, (Byte)4 }, /* 128MB */
{ (Uint16)0, (Byte)16, (Byte)32, (Byte)32, (Byte)8 }, /* 256MB */
};
/* -- MMC Type Selection -- */
if (Sd_disk_size() <= MMC_SIZE_4MB)
{
*tab = sd_tab_format[MMC_4MB];
/* calculation of cylinder number */
(*tab).nb_cylinder = (Sd_disk_size() + 1) /
(sd_tab_format[MMC_4MB].nb_head *
sd_tab_format[MMC_4MB].nb_sector);
return tab;
}
if (Sd_disk_size() <= MMC_SIZE_8MB)
{
*tab = sd_tab_format[MMC_8MB];
/* calculation of cylinder number */
(*tab).nb_cylinder = (Sd_disk_size() + 1) /
(sd_tab_format[MMC_8MB].nb_head *
sd_tab_format[MMC_8MB].nb_sector);
return tab;
}
if (Sd_disk_size() <= MMC_SIZE_16MB)
{
*tab = sd_tab_format[MMC_16MB];
/* calculation of cylinder number */
(*tab).nb_cylinder = (Sd_disk_size() + 1) /
(sd_tab_format[MMC_16MB].nb_head *
sd_tab_format[MMC_16MB].nb_sector);
return tab;
}
if (Sd_disk_size() <= MMC_SIZE_28MB)
{
*tab = sd_tab_format[MMC_28MB];
/* calculation of cylinder number */
(*tab).nb_cylinder = (Sd_disk_size() + 1) /
(sd_tab_format[MMC_28MB].nb_head *
sd_tab_format[MMC_28MB].nb_sector);
return tab;
}
if (Sd_disk_size() <= MMC_SIZE_32MB)
{
*tab = sd_tab_format[MMC_32MB];
/* calculation of cylinder number */
(*tab).nb_cylinder = (Sd_disk_size() + 1) /
(sd_tab_format[MMC_32MB].nb_head *
sd_tab_format[MMC_32MB].nb_sector);
return tab;
}
if (Sd_disk_size() <= MMC_SIZE_64MB)
{
*tab = sd_tab_format[MMC_64MB];
/* calculation of cylinder number */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -