📄 netsrv.c
字号:
/*******************************************************************
*******************************************************************/
#include "..\system.h"
//#ifdef INTEL_X86_CPU
// #include <string.h>
//#endif
#include "..\utility.h"
#include "..\dbstru.h"
#include "..\SysCst.h"
#include "..\hardware.h"
#include "ne2000.h"
#include "netdrv.h"
#include "netsrv.h"
/*************************** 调试变量和函数 ********************************/
/*************************** Global variables ******************************/
struct netalias CurNet;
/***************************** 局部变量定义 ********************************/
static INT8U RecBuf[1600]; /* 接收缓冲区 */
static INT8U destMAC[MACLEN]; /* 目标MAC地址,使用广播地址 */
/************************** Global functions *******************************/
INT16U EthernetInit(void) {
INT16U Index = 0;
INT8U i = 0;
for (i = 0; i < MACLEN; i++) {
destMAC[i] = 255;
}
NetCfgInit();
for ( Index = 0; Index < MAX_CARD_NUMBER; Index++ ) {
if (netOpen(Index) != 0x00) {
return(netError(NET_NICNOTEXIST));
}
#ifdef INTEL_X86_CPU
Delay(10);
#endif
}
// return(NetAliasInit(&CurNet));
return(SYS_NOERR);
}
/* 初始化网络别名 */
INT16U NetAliasInit(NETALIAS *pNetAlias) {
if (TSYSA == getSysID()) {
pNetAlias->ICUIn = 0;
pNetAlias->ICUOut = 1;
pNetAlias->COMM1 = 2;
pNetAlias->COMM2 = 3;
} else if (TSYSB == getSysID()) {
pNetAlias->ICUIn = 0;
pNetAlias->ICUOut = 2;
pNetAlias->COMM1 = 1;
pNetAlias->COMM2 = 3;
} else {
/* failure occured, exit system */
return(netError(NET_INITALIASFAILED));
}
return(SYS_NOERR);
}
void EthernetClose(void) {
INT16U Index = 0;
for ( Index = 0; Index < MAX_CARD_NUMBER; Index++ ) {
netClose(Index);
}
}
/* 清空8019接收缓冲区 */
void ClearBuffer(INT16U CardID) {
do {
rtl8019ProcessInterrupt(CardID);
if (rtl8019Receive(CardID, RecBuf) == TRUE) {
;
}
} while (IsEmpty(CardID) != TRUE);
}
/*
Function Name: ReceiveFrom
Parameter: lpBuf - data receiving buffer
CardID - NIC alias or ID
Return Value: data length if succeed
0 if no data
-1 if another error found
Description: API for receiving data
*/
int ReceiveFrom(INT8U *lpBuf,INT16U CardID) {
rtl8019ProcessInterrupt(CardID);
if (rtl8019Receive(CardID, lpBuf) == TRUE) {
return(usrdatalen);
} else {
if (netError(NET_NODATA) == rcvErrStatus) {
return(0);
} else {
return(-1);
}
}
}
/*
Function Name: NetSend
Parameter: CardID - NIC alias or ID
lpBuf - sending data buffer
iLen - data length to be sent
Return Value: TRUE forever
For our hardware platform, there is no collision in ethernet.
Therefore, it will succeed forever when data is sending.
Description: API for sending data
*/
BOOL NetSend(INT16U CardID, INT8U *lpBuf, long int iLen)
{
long int i = 0;
long int length = 0;
#ifdef ARM_XSCALE_CPU
long int loop = 0, left = 0;
#endif
length = iLen;
#ifdef ARM_XSCALE_CPU
while ((iLen - loop*MAX_ETHERNET_FRAME_LEN) > 0)
{
loop++;
}
loop--;
left = length - loop*MAX_ETHERNET_FRAME_LEN;
for (i = 0; i < loop; i++ )
{
rtl8019Send(CardID, destMAC, lpBuf + i*MAX_ETHERNET_FRAME_LEN,
MAX_ETHERNET_FRAME_LEN );
}
if (left)
{
length = left;
if (length < MIN_ETHERNET_FRAME_LEN) {
length = MIN_ETHERNET_FRAME_LEN;
}
rtl8019Send(CardID, destMAC, lpBuf + i*MAX_ETHERNET_FRAME_LEN,
length );
}
#else
for (i = 0; i < (length / MAX_ETHERNET_FRAME_LEN); i++ )
{
rtl8019Send(CardID, destMAC, lpBuf + i*MAX_ETHERNET_FRAME_LEN,
MAX_ETHERNET_FRAME_LEN );
}
if (length % MAX_ETHERNET_FRAME_LEN)
{
length = length%MAX_ETHERNET_FRAME_LEN;
if (length < MIN_ETHERNET_FRAME_LEN) {
length = MIN_ETHERNET_FRAME_LEN;
}
rtl8019Send(CardID, destMAC, lpBuf + i*MAX_ETHERNET_FRAME_LEN,
length );
}
#endif
/* 等待发送结束 */
while (IsTransEnd(CardID) != TRUE);
return(TRUE);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -