📄 main.c
字号:
#include <stdio.h>
#include <sys/unistd.h>
#include <io.h>
#include <string.h>
#include "system.h"
#include "alt_types.h"
#include "altera_avalon_pio_regs.h"
#include "sdconfig.h"
#include "sdcmd.h"
#include "sdcrc.h"
#include "sddriver.h"
#include "sdhal.h"
/*****************************************/
int main(void)
{
alt_u8 SDCBuff[SD_BLOCKSIZE];
alt_u8 find_boot = 0;
alt_u32 card_capacity;
int i;
printf("\nExp21 - SD Card Initiate and Read test!");
if(SD_Initialize() == SD_NO_ERR)
{
printf("\nSD card initialize successfully!");
printf("\nStart read SD card infomation now...");
//读取卡的第启动扇区
i = 0;
do{
if(SD_ReadBlock(i, SDCBuff) == SD_NO_ERR) //打印分区表信息
{
if(SDCBuff[0] == 0xEB)
{
find_boot = 1;
break;
}
}
}
while(i++ < 256); //在前256个扇区中寻找起始扇区
if(find_boot) //打印分区表信息
{
printf("\nStart boot sector is: %d", i);
printf("\nMaster bootstrap loader code (Hex):");
for(i=0; i<SD_BLOCKSIZE; i++)
{
if(i % 16 == 0)
printf("\n");
printf("%02X ", SDCBuff[i]);
}
//打印分区表信息
printf("\n===============================================");
printf("\nJMP Insturction: %02X %02X %02X", SDCBuff[0], SDCBuff[1], SDCBuff[2]);
printf("\nBytes/Sector: %d", SDCBuff[0x0c]*256+SDCBuff[0x0b]);
printf("\nSectors/Cluster: %d", SDCBuff[0x0d]);
printf("\nReserved Sectors: %d", SDCBuff[0x0f]*256+SDCBuff[0x0e]);
printf("\nNumber of FATs: %d", SDCBuff[0x11]*256+SDCBuff[0x10]);
card_capacity = (SDCBuff[0x23]<<24)|(SDCBuff[0x22]<<16)|(SDCBuff[0x21]<<8)|SDCBuff[0x20];
printf("\nCard's Sectors: %u", card_capacity);
printf("\nCard's Capacity: %u Bytes",card_capacity*SD_BLOCKSIZE);
printf("\n... ...");
}
else
printf("\nFind start boot sector fail!");
}
else
printf("\nSD card initialize failed!");
while(1);
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -