?? 8019app.bak
字號:
#ifndef __8019APP_H__
#define __8019APP_H__
#include <8019.h>
#define BITISR_RX 0x01
#define BITRSR_RXOK 0x01
void init_8019(void);
void delayms(uchar t);
void dmaread(uchar bc_h,uchar bc_l,uchar st_h,uchar st_l,uchar xdata *saveaddr);//from inram to dmaport
void dmawrite(uchar bc_h,uchar bc_l,uchar st_h,uchar st_l,uchar xdata *writeaddr);//from dmaport to inram
void sendpacket(uchar ct_h,uchar ct_l);//ct_h:msb of count,ct_l:lsb of count
void tx_wait(void);//wait to tx
void recvpacket(void);
void processethpacket(void);
uchar readpacketheader(void);//return if the packet header
void eth_send(uint num);
//void handle_packet(void);
uchar packet_come(void); //if any packet comes
extern uchar xdata *mac;
extern uchar xdata *rcv_hdr;
//uchar xdata *eth;
uchar next_packet;
uchar curr_recv;
bit net_overlow;
bit flagresend;//sometimes need resend the packet
uchar curr_use,next_use;
/***********************
void main(void)
{
uchar temp;
next_packet=0;
flagresend=FALSE;
mac=0;
rcv_hdr=0x1000;
eth=&rcv_hdr[4];
init_8019();
temp=0;
}
*************************/
void init_8019(void)
{
uchar xdata *addr;
uchar temp0,temp1;
EN_RESET=0x00;
delayms(2);//delay 2ms
EN_CMD=EN_PAGE0+EN_NODMA+EN_STOP;// Remote DMA, Stop and reset the chip
delayms(2);
EN0_RCNTHI=0;
EN0_RCNTLO=0;
EN0_RXCR=ENRXCR_MON;//RX configuration reg,Monitor mode (no packets rcvd)
EN0_TXCR=ENTXCR_LOOP;//TX configuration reg,set internal loopback mode
EN0_DCFG=ENDCFG_FT10+ENDCFG_BMS+ENDCFG_WTS;// fifo treshold, Normal operation,
// word/byte transfer mode selection
//shit !!!!!!!,in vains
/***********************************************************
dmaread(0,2*ETHER_ADDR_LEN,0,0,mac); //get the mac of nic
************************************************************/
EN_CMD=EN_PAGE0+EN_NODMA ;//Remote DMA
EN0_STARTPG= RX_START_PG ;//Starting page of ring buffer;First page of RX Ring
EN0_BOUNDARY= RX_START_PG;//Boundary page of ring buffer
EN0_STOPPG=NE_STOP_PG ;//Ending page +1 of ring buffer;End Page = Last page + 1 of RX Ring
EN0_ISR= -1 ;//Interrupt status reg,clear all
EN0_IMR= 0 ;//Interrupt mask reg = Disable All Interrupt
EN_CMD= EN_PAGE1+EN_NODMA ;//Page 1, Remote DMA
addr=EN1_PHYS;
for(temp1=0;temp1<ETHER_ADDR_LEN;temp1++)
{
temp0=mac[temp1];
addr[temp1]=temp0;
}
EN_CMD= EN_PAGE1+EN_NODMA+EN_STOP ;//Page 1,Remote DMA, Stop and reset the chip
addr=EN1_MULT;
for(temp1=0;temp1<ETHER_ADDR_LEN;temp1++)
addr[temp1]=0xff;
EN_CMD= EN_PAGE0+EN_NODMA+EN_START;//Remote DMA, Start the chip, clear reset
EN_CMD= EN_PAGE1+EN_NODMA+EN_STOP ;//Page 1,Remote DMA, Stop and reset the chip
EN1_CURPAG= RX_CURR_PG ;//Current memory page = RX_CURR_PG
EN_CMD= EN_PAGE0+EN_NODMA+EN_START;//Remote DMA, Start the chip, clear reset
EN0_TXCR= 0 ;//TX configuration reg = Normal Operation
EN0_RXCR= ENRXCR_BCST ;//RX configuration reg = Accept broadcasts
EN0_ISR= -1 ;//Clear the pending Interrupt
next_packet= RX_CURR_PG;
curr_use=0;
next_use=1;
}
void delayms(uchar t)
{
uchar temp,temp1;
for(temp=0;temp<t;temp++)
{
for(temp1=0;temp1<125;temp1++); //one ++ is about 8us
}
}
void dmaread(uchar bc_h,uchar bc_l,uchar st_h,uchar st_l,uchar xdata *saveaddr)
{
uint tempint,tempint1;
uchar temp;
tempint=bc_h*0x100+bc_l;
EN_CMD=EN_PAGE0+EN_NODMA+EN_START;
EN0_RCNTHI=bc_h ;//MSB Remote byte count reg
EN0_RCNTLO=bc_l ;//LSB Remote byte count reg
EN0_RSARHI=st_h ;//MSB Remote start address reg
EN0_RSARLO=st_l ;//LSB Remote start address reg
EN_CMD=EN_PAGE0+EN_RREAD+EN_START;//Remote Read, Start the chip, clear reset
for(tempint1=0;tempint1<tempint;tempint1++)
{
temp=EN_DATA;//dma port
saveaddr[tempint1]=temp;
}
}
void dmawrite(uchar bc_h,uchar bc_l,uchar st_h,uchar st_l,uchar xdata *writeaddr)
{
uint xdata tempint,tempint1;
uchar temp;
tempint=bc_h*0x100+bc_l;
EN_CMD= EN_PAGE0+EN_NODMA+EN_START;//Remote DMA, Start the chip, clear reset
EN0_TCNTHI=bc_h ;//High byte of tx byte count
EN0_TCNTLO=bc_l ;//Low byte of tx byte count
EN0_RSARHI=st_h ;//MSB Remote start address reg
EN0_RSARLO=st_l ;//LSB Remote start address reg
EN_CMD= EN_PAGE0+EN_RWRITE+EN_START;//Remote Write, Start the chip, clear reset
for(tempint1=0;tempint1<tempint;tempint1++)
{
temp=writeaddr[tempint1];
EN_DATA=temp;
}
}
void sendpacket(uchar ct_h,uchar ct_l)
{
uint tempint;
uchar temp;
tempint=ct_h*0x100+ct_l;
tx_wait();
temp=EN0_ISR;// Interrupt status reg
if((temp&(ENISR_TX_ERR+ENISR_TX))!=0)// Pending Tx interrupts?
{
temp=EN0_TSR;//Read Transmit status reg
EN0_ISR=ENISR_TX_ERR+ENISR_TX;//clear the corresponding bits
}
if(tempint>GIANT)return;
if(tempint<RUNT){ct_h=0;ct_l=RUNT;tempint=RUNT;}
EN0_TCNTHI=ct_h ;// High byte of tx byte count
EN0_TCNTLO=ct_l ; //Low byte of tx byte count
EN0_TPSR=NE_START_PG;// Transmit starting page, First page of TX buffer
EN_CMD= EN_PAGE0+EN_NODMA+EN_TRANS+EN_START;// Remote DMA, Transmit a frame
}
void tx_wait(void)
{
uchar temp;
temp=EN_CMD;
if((temp&EN_TRANS)==0)return;
delayms(250);
delayms(250);//wait 500ms
}
void eth_send(uint num)
{
uchar num_h,num_l;
uchar xdata *senddata;
senddata=ETH_SEND_ADDR;
num_h=num>>8;
num_l=num&0xff;
/*先寫到網卡芯片RAM,然后再通過命令送出去了*/
dmawrite(num_h,num_l,NE_START_PG,0,senddata);
sendpacket(num_h,num_l);
}
uchar packet_come(void) //if any packet comes
{
uchar temp;
EN_CMD=EN_PAGE0+EN_NODMA+EN_START;
temp=EN0_ISR;
/*如果溢出的話,也要返回,否則以后就玩不轉了*/
if((temp&ENISR_OVER)==ENISR_OVER)return(TRUE);
EN_CMD=EN_PAGE1+EN_NODMA+EN_START;
temp=EN1_CURPAG;
/*要知道,EN1_CURPAG是自動加的,next_packet可不會,所以數據包到了,他倆就不同了*/
if(next_packet!=temp)return(TRUE);//new packet come
return(FALSE);
}
void recvpacket(void)
{
uchar temp;
uchar temp1;
EN_CMD=EN_PAGE0+EN_NODMA+EN_START ;
temp=EN0_ISR;// Get pending interrupts
if(temp==0)return;
if((temp&ENISR_OVER)==ENISR_OVER)
{
// i want to reset the NIC
EN_CMD=EN_PAGE0+EN_NODMA ;//Remote DMA
EN0_BOUNDARY= RX_START_PG;//Boundary page of ring buffer
EN_CMD= EN_PAGE1+EN_NODMA+EN_STOP ;//Page 1,Remote DMA, Stop and reset the chip
EN1_CURPAG= RX_CURR_PG ;//Current memory page = RX_CURR_PG
EN_CMD= EN_PAGE0+EN_NODMA+EN_START;//Remote DMA, Start the chip, clear reset
next_packet= RX_CURR_PG;
EN0_ISR=temp;
net_overlow=TRUE;
return;
}
if((temp&ENISR_COUNTERS)==ENISR_COUNTERS)
// some errors, read Tally Counters,about no use
{
temp1=EN0_COUNTER0;
temp1=EN0_COUNTER1;
temp1=EN0_COUNTER2;
EN0_ISR=ENISR_COUNTERS;// Interrupt status reg;ReSet CNT (Error Tally Counters)
}
if( ( (temp&ENISR_RX)==ENISR_RX)||((temp&ENISR_RX_ERR)==ENISR_RX_ERR))//packet received
{
EN0_ISR=ENISR_RX_ERR+ENISR_RX;//clear those request
//get the rx page
EN_CMD=EN_PAGE1+EN_NODMA+EN_START;
temp=EN1_CURPAG;
EN_CMD=EN_PAGE0+EN_NODMA+EN_START;
while(temp!=next_packet)//rece new packet
{
curr_recv=next_packet;//curr_recv used in process
dmaread(0,SIZE_OF_8019_HDR+SIZE_OF_ETH_PKT_HDR,next_packet,0,rcv_hdr);
temp1=rcv_hdr[0] ; //Get the buffer status byte (the same as EN0_RSR)
if(((temp1&ENRSR_RXOK)!=ENRSR_RXOK)&&((temp1&ENRSR_PHY)!=ENRSR_PHY))
{
next_packet=temp;
goto recv_break;
}
next_packet=rcv_hdr[1];//next page
if((next_packet>NE_STOP_PG)||(next_packet<RX_START_PG))
{
next_packet=temp;//curr_page
goto recv_break;
}
processethpacket();
if(next_packet==RX_START_PG)EN0_BOUNDARY=NE_STOP_PG-1;
else EN0_BOUNDARY=next_packet-1;
EN_CMD=EN_PAGE1+EN_NODMA+EN_START;
temp=EN1_CURPAG;
EN_CMD=EN_PAGE0+EN_NODMA+EN_START;
}
}
recv_break:
EN0_ISR=ENISR_RDC ;//Interrupt status reg
}
void processethpacket(void)
{
uchar temp;
uint tempint;
dmaread(rcv_hdr[3],rcv_hdr[2],curr_recv,0,rcv_hdr);
handle_packet();
}
#endif
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -