📄 rtl8019.c
字号:
/****************************************************************
* ARMSYS7 S3C44B0X developer's notes *
****************************************************************
1. 2005.5.17::
***************************************************************/
#include "..\inc\config.h"
#include "..\inc\board.h"
#include "..\inc\utils.h"
#include "..\inc\Rtl8019.h"
#include "..\inc\tftp\eth.h"
#include "..\inc\tftp\mac.h"
//#define DEBUG_NET
#define RPSTART 0x4c
#define RPSTOP 0x80
#define SPSTART 0x40
static U8 rBNRY;
static U8 SrcMacID[ETH_ALEN] = {0x01,0x12,0x34,0x56,0x67,0x89}; //{0x00,0x80,0x48,0x12,0x34,0x56};
//static U8 DstMacID[ETH_ALEN];
static U8 net_start;
void SetRegPage(U8 PageIdx)
{
U8 temp;
temp = inportb(BaseAddr);
// temp = (temp&(0x3a|net_start))|(PageIdx<<6); //ensure bit0 clear!!!
temp = (temp&0x3b)|(PageIdx<<6);
outportb(temp, BaseAddr);
}
static void SetMacID()
{
SetRegPage(1);
outportb(SrcMacID[0], PAR0);
outportb(SrcMacID[1], PAR1);
outportb(SrcMacID[2], PAR2);
outportb(SrcMacID[3], PAR3);
outportb(SrcMacID[4], PAR4);
outportb(SrcMacID[5], PAR5);
}
static U8 Rst8019()
{
int i;
outportb(0x5a, RstAddr);
i = 20000;
while(i--);
SetRegPage(0);
return (inportb(ISR)&0x80);
}
static void WakeRtl8019as()
{
SetRegPage(3);
outportb(0xcf, CR9346); //set eem1-0, 11 ,enable write config register
outportb(0x70, CONFIG3); //clear pwrdn, sleep mode, set led0 as led_link, led1 as led_rx
outportb(0x3f, CR9346); //disable write config register
}
static void InitRS8019()
{
net_start = 1;
outportb(0x21, BaseAddr); /* set page 0 and stop */
outportb(RPSTART, Pstart); /* set Pstart 0x4c */
outportb(RPSTOP, Pstop); /* set Pstop 0x80 */
outportb(RPSTART, BNRY); /* BNRY-> the last page has been read */
outportb(SPSTART, TPSR); /* transmit page start register, 0x40 */
outportb(0xcc, RCR); /* set RCR 0xcc */
outportb(0xe0, TCR); /* set TCR 0xe0 */
//#ifdef RTL8019_OP_16
// outportb(0xc9, DCR); /* set DCR 0xc9, 16bit DMA */
//#else
outportb(0xc8, DCR); /* 8bit DMA */
//#endif
outportb(0x03, IMR); /* set IMR 0x03 */
outportb(0xff, ISR);
SetRegPage(1);
outportb(RPSTART+1, CURR);
outportb(0x00, MAR0);
outportb(0x41, MAR1);
outportb(0x00, MAR2);
outportb(0x80, MAR3);
outportb(0x00, MAR4);
outportb(0x00, MAR5);
outportb(0x00, MAR6);
outportb(0x00, MAR7);
outportb(0x22, BaseAddr); /* set page 0 and start */
net_start = 0;
rBNRY = RPSTART;
}
int board_eth_init(void)
{
int i;
WakeRtl8019as();
if(!Rst8019())
{
// puts("Rtl8019 Reset Failed!\n");
// printf("%x ", inportb(ISR));
// return -1;
}
// puts("Rtl8019 Reset Successfully\n");
InitRS8019();
i = inportb(ID8019L);
i |= inportb(ID8019H)<<8;
SetMacID();
return 0;
}
int board_eth_lnk_stat(void)
{
return 0;
}
int board_eth_send(unsigned char *data, unsigned int len)
{
static sFlag = 0;
int i;
U8 send_page;
send_page = SPSTART;
send_page += (sFlag&1)?6:0;
sFlag++;
if(len<60)
for(; len<60; len++)
data[len] = 0x20; //just for pad, any data
SetRegPage(0);
outportb(0x22, BaseAddr);
outportb(0, RSAR0);
outportb(send_page, RSAR1);
outportb(len&0xff, RBCR0);
outportb(len>>8, RBCR1);
outportb(0x12, BaseAddr);
#ifdef RTL8019_OP_16
len += len&1;
for(i=0; i<(len>>1); i++)
outportw(((U16 *)data)[i], RWPORT);
#else
for(i=0; i<len; i++)
outportb(data[i], RWPORT); // tarns to ram
#endif
while(inportb(BaseAddr)&4);
outportb(send_page, TPSR);
outportb(len&0xff, TBCR0);
outportb(len>>8, TBCR1);
outportb(0x1e, BaseAddr); // begin to send
return 0;
}
int board_eth_rcv(unsigned char *data, unsigned int *len)
{
U8 RxPageBeg, RxPageEnd;
U8 RxNextPage;
U8 RxStatus;
int i, RxLength;
U16 *data_16;
data_16 = (U16 *)data;
SetRegPage(0);
outportb(rBNRY, BNRY); //???
if(inportb(ISR)&1) //接收成功
outportb(0x1, ISR); //清除中断标志
else
return -1;
SetRegPage(1);
RxPageEnd = inportb(CURR);
SetRegPage(0);
RxPageBeg = rBNRY+1;
if(RxPageBeg>=RPSTOP)
RxPageBeg = RPSTART;
outportb(0x22, BaseAddr);
outportb(0, RSAR0);
outportb(RxPageBeg, RSAR1);
outportb(4, RBCR0);
outportb(0, RBCR1);
outportb(0xa, BaseAddr);
#ifdef RTL8019_OP_16
RxLength = inportw(RWPORT);
RxStatus = RxLength&0xff;
RxNextPage = RxLength>>8;
RxLength = inportw(RWPORT);
RxLength += RxLength&1;
#else
RxStatus = inportb(RWPORT);
RxNextPage = inportb(RWPORT);
RxLength = inportb(RWPORT);
RxLength |= inportb(RWPORT)<<8;
#endif
if(RxLength>ETH_FRAME_LEN)
{
if(RxPageEnd==RPSTART)
rBNRY = RPSTOP-1;
else
rBNRY = RxPageEnd-1;
outportb(rBNRY, BNRY);
return -1;
}
outportb(4, RSAR0);
outportb(RxPageBeg, RSAR1);
outportb(RxLength, RBCR0);
outportb(RxLength>>8, RBCR1);
outportb(0xa, BaseAddr);
#ifdef RTL8019_OP_16
i = 2;
data_16 -= i;
RxLength >>= 1;
for(; RxLength--;) {
if(!(i&0x7f)) {
outportb(RxPageBeg, BNRY);
RxPageBeg++;
if(RxPageBeg>=RPSTOP)
RxPageBeg = RPSTART;
}
data_16[i++] = inportw(RWPORT);
}
#else
i = 4;
data -= i;
for(; RxLength--;)
{
if(!(i&0xff))
{
outportb(RxPageBeg, BNRY);
RxPageBeg++;
if(RxPageBeg>=RPSTOP)
RxPageBeg = RPSTART;
}
data[i++] = inportb(RWPORT);
}
#endif
outportb(RxPageBeg, BNRY);
rBNRY = RxPageBeg;
return 0;
}
int board_eth_get_addr(unsigned char *addr)
{
Memcpy(addr, SrcMacID, ETH_ALEN);
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -