📄 tcpip.c
字号:
//send(s, sendok,leny);
break;
// case 0xa2: receive_kbv();break;
// case 0xa3: get_pausef();break;
// case 0xa4: get_resume();break;
// case 0xa5: lostpow_set();break;
case 0xa5:
leny=10;
send(s, sendok,leny);
_nop_();
leny=560;
temp1bytem4=sumre_Result(real_buf,leny);
real_buf[leny-4]=temp1bytem4x[3];
real_buf[leny-3]=temp1bytem4x[2];
real_buf[leny-2]=temp1bytem4x[1];
real_buf[leny-1]=temp1bytem4x[0];
send(s, real_buf,leny);
//send_realdat();
break;
case 0xa7: //get 2 da form pc
for(y=0;y<4;y++)
{for(leny=0;leny<16;leny++)
vi2da0(y+leny)=dst_buf[y*16+leny+8];
}
leny=10;
send(s, sendok,leny);
break;
case 0xa8: //locate start cell
y=tabmap[dst_buf[8]]; //get channell
zn=y/16 ;// zone
zc=y%16 ;//
//zx=tabdcdc[(nwstp0(zn+zc)&0x03)]|tabgal[y%16%4] ; //status
if((y/16)==0x00) //zone<2,da7 da4 da3=1 0 0 or =101;
zn=0x80;
else if((y/16)==0x01)
zn=0x84;
else if((y/16)==0x02)
zn=0x88;
else
zn=0x8c; //4 zone
XBYTE[dridata]=tabdcdc[(nwstp0(zn+zc)&0x03)]|tabgal[y%16%4] ; //status //0x00; //sleep
XBYTE[driadds]=zn|(y%16/4) ; //the no. gal //0
_nop_();
XBYTE[driadds]=0x00;
leny=10;
send(s, sendok,leny);
break;
case 0xa9: //locate start test
realchafg=dst_buf[8]; //get channell
realtstfg=2;
leny=10;
send(s, sendok,leny);
break;
case 0xaa: //send cali data and close channel
leny=10;
send(s, sendok,leny);
leny=12;
send(s, cali_buf,leny);
//
y=tabmap[realchafg]; //channel after mapping
zn=y/16 ;// zone
zc=y%16 ;//
//zx=tabdcdc[(nwstp0(zn+zc)&0x03)]|tabgal[y%16%4] ; //status
if((y/16)==0x00) //zone<2,da7 da4 da3=1 0 0 or =101;
zn=0x80;
else if((y/16)==0x01)
zn=0x84;
else if((y/16)==0x02)
zn=0x88;
else
zn=0x8c; //4 zone
XBYTE[dridata]=0xff ; // //sleep
XBYTE[driadds]=zn|(y%16/4) ; //the no. gal //0
_nop_();
XBYTE[driadds]=0x00;
//
break;
case 0xac: //sch
for(leny=0;leny<len-8;leny++) //version./ zone
{
caliwrfg=(dst_buf[8+1]&0x0f); //sch zone num.
kbbuf(leny)=dst_buf[leny+8];
}
_nop_();
leny=10;
send(s, sendok,leny);
break;
case 0xad:
leny=10;
send(s, sendok,leny);
_nop_();
readat256();
leny=kbbuf(0)+kbbuf(1)*256;
send(s, kbbufa,leny);
break;
default: break;
} //switch
} //if
else
{ sysstate=0x44; //error flag
_nop_();
}
} //if(sysstate==1)
/////////
if(sysstate==0x44)
{leny=10;
send(s, sender,leny);
}
// send(s, sendok,len);
/////
// send(s, dst_buf,len);
// delay(20) ;
break;
}
break;
case SOCK_CLOSE_WAIT: // Close of connection
close(s);
_nop_();
break;
case SOCK_CLOSED:
aa=0; // Relea
sysstate=0;
break; //goto START;
default:
break;
} //switch
_nop_();
} //while(aa)
if(sysstate==1)
{ close(s);
// delay(100);
_nop_();
}
_nop_();
s = 0;
socket(s, SOCK_STREAM, Source_port, 0); ///sock_stream=tcp protocol
{aa=2000;
while(aa--)
{checkint1(); //check int1
if(I_STATUS[0]==0x02)
aa=0;
}
NBlisten(s) ; //server
}
// goto START;
///&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& P3.3=INT1 chekint1
} //if(I_STATUS[0]==0x04)
else if(I_STATUS[0]==0x08)
{aa=2000;
while (aa--)
{
if((select(s, SEL_CONTROL))==SOCK_CLOSE_WAIT)
{_nop_();
close(s);
aa=0;
}
_nop_();
}
_nop_();
s = 0;
socket(s, SOCK_STREAM, Source_port, 0); ///sock_stream=tcp protocol
{aa=2000;
while(aa--)
{checkint1(); //check int1
if(I_STATUS[0]==0x02)
aa=0;
}
// NBlisten(s) ; //server
}
NBlisten(s) ; //server
}
}
if (status & 0x02) { // channel 1 interrupt(sysinit, sockinit, established, closed, timeout, send_ok, recv_ok)
I_STATUS[1] = INT_STATUS(1);
INT_REG = 0x02;
}
if (status & 0x04) { // channel 2 interrupt(sysinit, sockinit, established, closed, timeout, send_ok, recv_ok)
I_STATUS[2] = INT_STATUS(2);
INT_REG = 0x04;
}
if (status & 0x08) { // channel 3 interrupt(sysinit, sockinit, established, closed, timeout, send_ok, recv_ok)
I_STATUS[3] = INT_STATUS(3);
INT_REG = 0x08;
}
if (status & 0x10) { // channel 0 receive interrupt
// ISR_RX(0);
INT_REG = 0x10;
}
if (status & 0x20) { // channel 1 receive interrupt
// ISR_RX(1);
INT_REG = 0x20;
}
if (status & 0x40) { // channel 2 receive interrupt
// ISR_RX(2);
INT_REG = 0x40;
}
if (status & 0x80) { // channel 3 receive interrupt
// ISR_RX(3);
INT_REG = 0x80;
}
status = INT_REG;
}
INT_REG = 0xFF;
Int7_En(); // INT7 DISABLE
}
/////////////
void checkint1(void) //reentrant
{ if(chekint1==0)
{
u_char status;
// Int7_Ds(); // INT7 DISABLE
status = INT_REG;
while (status) {
if (status & 0x01) { // channel 0 interrupt(sysinit, sockinit, established, closed, timeout, send_ok, recv_ok)
I_STATUS[0] = INT_STATUS(0);
INT_REG = 0x01;
}
if (status & 0x02) { // channel 1 interrupt(sysinit, sockinit, established, closed, timeout, send_ok, recv_ok)
I_STATUS[1] = INT_STATUS(1);
INT_REG = 0x02;
}
if (status & 0x04) { // channel 2 interrupt(sysinit, sockinit, established, closed, timeout, send_ok, recv_ok)
I_STATUS[2] = INT_STATUS(2);
INT_REG = 0x04;
}
if (status & 0x08) { // channel 3 interrupt(sysinit, sockinit, established, closed, timeout, send_ok, recv_ok)
I_STATUS[3] = INT_STATUS(3);
INT_REG = 0x08;
}
if (status & 0x10) { // channel 0 receive interrupt
// ISR_RX(0);
INT_REG = 0x10;
}
if (status & 0x20) { // channel 1 receive interrupt
// ISR_RX(1);
INT_REG = 0x20;
}
if (status & 0x40) { // channel 2 receive interrupt
// ISR_RX(2);
INT_REG = 0x40;
}
if (status & 0x80) { // channel 3 receive interrupt
// ISR_RX(3);
INT_REG = 0x80;
}
status = INT_REG;
}
INT_REG = 0xFF;
}//check int1
// Int7_En(); // INT7 DISABLE
}
void initW3100A(void)
{
*(IDM_OR_PTR)=0;
Local_Port = 8000; // This default value will be set if you didn't designate it when you create a socket
// If you don't designate port number and create a socket continuously,
// the port number will be assigned with incremented by one to Local_Port
SEQ_NUM.lVal = 0x12340000; // Sets the initial SEQ# to be used for TCP communication. (It should be ramdom value)
COMMAND(0) = CSW_RESET; // Software RESET
}
void sysinit(u_char sbufsize, u_char rbufsize)
{
char i;
int ssum,rsum;
uint cc=2000;
ssum = 0;
rsum = 0;
TX_DMEM_SIZE = sbufsize; // Set Tx memory size for each channel
RX_DMEM_SIZE = rbufsize; // Set Rx memory size for each channel
SBUFBASEADDRESS[0] = (u_char *)SEND_DATA_BUF; // Set Base Address of Tx memory for channel #0
RBUFBASEADDRESS[0] = (u_char *)RECV_DATA_BUF; // Set Base Address of Rx memory for channel #0
for(i = 0 ; i < MAX_SOCK_NUM; i++) // Set maximum memory size for Tx and Rx, mask, base address of memory by each channel
{
SSIZE[i] = 0;
RSIZE[i] = 0;
if(ssum < 8192)
{
switch((sbufsize >> i*2) & 0x03) // Set maximum Tx memory size
{
case 0:
SSIZE[i] = 1024;
SMASK[i] = 0x000003FF;
break;
case 1:
SSIZE[i] = 2048;
SMASK[i] = 0x000007FF;
break;
case 2:
SSIZE[i] = 4096;
SMASK[i] = 0x00000FFF;
break;
case 3:
SSIZE[i] = 8192;
SMASK[i] = 0x00001FFF;
break;
}
}
if( rsum < 8192)
{
switch((rbufsize>> i*2) & 0x03) // Set maximum Rx memory size
{
case 0:
RSIZE[i] = 1024;
RMASK[i] = 0x000003FF;
break;
case 1:
RSIZE[i] = 2048;
RMASK[i] = 0x000007FF;
break;
case 2:
RSIZE[i] = 4096;
RMASK[i] = 0x00000FFF;
break;
case 3:
RSIZE[i] = 8192;
RMASK[i] = 0x00001FFF;
break;
}
}
ssum += SSIZE[i];
rsum += RSIZE[i];
if(i != 0) // Set base address of Tx and Rx memory for channel #1,#2,#3
{
SBUFBASEADDRESS[i] = SBUFBASEADDRESS[i-1] + SSIZE[i-1];
RBUFBASEADDRESS[i] = RBUFBASEADDRESS[i-1] + RSIZE[i-1];
}
}
I_STATUS[0] = 0;
COMMAND(0) = CSYS_INIT;
while(cc--)
{ if(cc==2)
tcpinitfg=1;
if((I_STATUS[0] & SSYS_INIT_OK)==SSYS_INIT_OK)
cc=0;
}
// while(!(I_STATUS[0] & SSYS_INIT_OK));
_nop_();
}
void setsubmask(u_char * addr)
{
u_char i;
for (i = 0; i < 4; i++) {
delay(2) ;
*(SUBNET_MASK_PTR + i) = addr[i];
delay(2) ;
}
}
void setgateway(u_char * addr)
{
u_char i;
for (i = 0; i < 4; i++) {
*(GATEWAY_PTR + i) = addr[i];
}
}
void setIP(u_char * addr)
{
u_char i;
for (i = 0; i < 4; i++) {
*(SRC_IP_PTR + i) = addr[i];
}
}
void setMACAddr(u_char *addr)
{
u_char i;
for (i = 0; i < 6; i++) {
*(SRC_HA_PTR+i) = addr[i];
}
}
void setdesAddr(u_char *addr)
{
u_char i;
for (i = 0; i < 4; i++) {
*(DST_IP_PTR(0)+i) = addr[i];
}
}
void setIPprotocol(SOCKET s, u_char ipprotocol)
{
IP_PROTOCOL(s) = ipprotocol;
}
void settimeout(u_char * val)
{
u_char i;
for (i = 0; i < 2; i++) {
*(TIMEOUT_PTR + i) = val[i];
}
}
void setINTMask(u_char mask)
{
INTMASK = mask;
}
void setTOS(SOCKET s, u_char tos)
{
TOS(s) = tos;
}
//#endif
int socket(SOCKET s, u_char protocol, u_int port, u_char flag) reentrant
{
u_char k;
u_int cc;
cc=2000;
OPT_PROTOCOL(s) = protocol | flag; // Designate socket protocol and option
if (port != 0) // setup designated port number
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -