新聞中心

EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > 十一 ARM9(2440)的網(wǎng)卡接口擴(kuò)展

十一 ARM9(2440)的網(wǎng)卡接口擴(kuò)展

作者: 時(shí)間:2016-11-27 來源:網(wǎng)絡(luò) 收藏

本文引用地址:http://m.butianyuan.cn/article/201611/322174.htm

dm_reg_write(DM9000_NSR, 0x2c);//清除TX狀態(tài)

dm_reg_write(DM9000_IMR, 0x81);//打開DM9000接收數(shù)據(jù)中斷

}

int dm_rec_packet(unsigned char *datas)

{

unsigned char int_status;

unsigned char rx_ready;

unsigned short rx_status;

unsigned short rx_length;

unsigned short temp;

int i;

int_status = dm_reg_read(DM9000_ISR);//讀取ISR

if(int_status & 0x1)//判斷是否有數(shù)據(jù)要接受

{
dm_reg_write(DM9000_ISR,0x01);//清除中斷*******************F
rx_ready = dm_reg_read(DM9000_MRCMDX);//先讀取一個無效的數(shù)據(jù)
Uart_Printf("ready1=%dn",rx_ready);

rx_ready = (unsigned char)DM_DATA_PORT;//真正讀取到的數(shù)據(jù)包首字節(jié)
Uart_Printf("ready2=%dn",rx_ready);

if(rx_ready == 1)//判讀首字節(jié)是否為1或0

{

DM_ADDR_PORT = DM9000_MRCMD;//連續(xù)讀取數(shù)據(jù)包內(nèi)容

rx_status = DM_DATA_PORT;//狀態(tài)字節(jié)

rx_length = DM_DATA_PORT;//數(shù)據(jù)長度

Uart_Printf("nlength=%dn",rx_length);

for(i=0; i//16位數(shù)據(jù)轉(zhuǎn)換為8位數(shù)據(jù)存儲

{

delay(20);

temp = DM_DATA_PORT;

datas[i] = temp & 0x0ff;

datas[i + 1] = (temp >> 8) & 0x0ff;

}
if((datas[12]==8)&&(datas[13]==6))
{
if((datas[20]==0)&&(datas[21]==1))
Uart_Printf("ARP請求n");
if((datas[20]==0)&&(datas[21]==2))
Uart_Printf("ARP應(yīng)答n");
for(i=1; i<=rx_length; i++)
{
Uart_Printf("%d",datas[i-1]);
if(i%6==0)
Uart_Printf("n");
}
}

}

}

else if(rx_ready !=0)//停止設(shè)備

{

//dm_reg_write(DM9000_IMR,0x80);//停止中斷

//dm_reg_write(DM9000_ISR,0x0F);//清中斷狀態(tài)

//dm_reg_write(DM9000_RCR,0x0);//停止接收

//還需要復(fù)位系統(tǒng),這里暫時(shí)沒有處理

}

dm_reg_write(DM9000_ISR, 0x1);//清中斷

return rx_length;

}

void __irq uartISR(void)

{

char ch;

rSUBSRCPND |= 0x1;

rSRCPND |= 0x1<<28;

rINTPND |= 0x1<<28;

ch=rURXH0;

if(ch == s)

tran=1;//表示發(fā)送一個ARP數(shù)據(jù)請求包


while(!(rUTRSTAT0 & 0x2));
rUTXH0=ch;
//for(i=0;i<100;i++);

}
void __irq DM9000ISR(void)

{


DisableIrq(BIT_EINT4_7);
Uart_Printf("nEINT7 Occuredn");

if(rEINTPEND&(1<<7))

{

rEINTPEND = rEINTPEND | (0x1<<7);

packet_len = dm_rec_packet(buffer);//接收網(wǎng)卡數(shù)據(jù)




}

rSRCPND = rSRCPND | (0x1<<4);

rINTPND = rINTPND | (0x1<<4);


EnableIrq(BIT_EINT4_7);

}


void init()
{
//uart0 port

rGPHCON = 0x00faaa;

rGPHUP= 0x7ff;

rULCON0 = 0x3;

rUCON0 = 0x5;

rUFCON0 = 0;

rUMCON0 = 0;

rUBRDIV0 = 26;

rSRCPND = (0x1<<27)|(0x1<<28);

rSUBSRCPND = 0x1;

rINTPND = (0x1<<27)|(0x1<<28);

rINTSUBMSK = ~(0x1);

rINTMSK = ~((0x1<<27)|(0x1<<28));

pISR_UART0 = (U32)uartISR;

//EINT7

rGPFCON = 2<<14;

rEXTINT0 = (rEXTINT0 & (~(0x07<<28))) | (0x01<<28);

rEINTMASK &= ~(1<<7);

rSRCPND = rSRCPND | (0x1<<4);

rINTPND = rINTPND | (0x1<<4);
rGPFCON = (rGPFCON & (~(0x03<<14))) | (0x02<<14);//GPF7設(shè)置為EINT7
rEXTINT0 = (rEXTINT0 & (~(0x07<<28))) | (0x01<<28);
rEINTMASK = rEINTMASK & (~(0x01<<7));
ClearPending(BIT_EINT4_7);

pISR_EINT4_7 = (U32)DM9000ISR;
rINTMSK &= ~(1<<4);


}

void Main(void)

{
tran=0;
MMU_Init();
init();
dm_init();

while(1)
{
if(tran==1)
{
dm_tran_packet(arpsendbuf1, 42 );//因?yàn)镻C機(jī)不斷向外發(fā)送數(shù)據(jù),其中剛開始就有ARP數(shù)據(jù)包,
tran=0;//所以為了方便查看,PC機(jī)通過串口發(fā)送s時(shí),DM9000
}
//向PC機(jī)發(fā)送一個ARP數(shù)據(jù)請求,再收到的ARP數(shù)據(jù)就是PC機(jī)的應(yīng)答信號

}

}


上一頁 1 2 下一頁

評論


推薦視頻

更多>>

技術(shù)專區(qū)

關(guān)閉