24 static uint8 DNS[4]={0};
26 static uint16 local_port = 0xC000;
42 DBGA(
"MR value is %02x",IINCHIP_READ_COMMON(WIZC_MR));
50 DBG(
"device_mem_init()");
57 IINCHIP_WRITE_SOCKETREG( i, WIZS_TXMEM_SIZE, tx_size[i]);
58 IINCHIP_WRITE_SOCKETREG( i, WIZS_RXMEM_SIZE, rx_size[i]);
60 DBGA(
"tx_size[%d]: %d, Sn_TXMEM_SIZE = %d",i, tx_size[i], IINCHIP_READ_SOCKETREG( i, WIZS_TXMEM_SIZE));
61 DBGA(
"rx_size[%d]: %d, Sn_RXMEM_SIZE = %d",i, rx_size[i], IINCHIP_READ_SOCKETREG( i, WIZS_RXMEM_SIZE));
63 SSIZE[i] = (int16)(0);
64 RSIZE[i] = (int16)(0);
67 #if 1 //--4Channel사용시 적용 안됨 --20120522
68 if(tx_size[i]==1 || tx_size[i]==2 || tx_size[i]==4 || tx_size[i]==8 || tx_size[i]==16)
70 if(tx_size[i]==1 || tx_size[i]==2 || tx_size[i]==4 || tx_size[i]==8)
74 SSIZE[i] = 0x400 * mul;
75 SMASK[i] = 0x400 * mul - 1;
78 #if 1 //--4Channel사용시 적용 안됨 --20120522
79 if(rx_size[i]==1 || rx_size[i]==2 || rx_size[i]==4 || rx_size[i]==8 || rx_size[i]==16)
81 if(rx_size[i]==1 || rx_size[i]==2 || rx_size[i]==4 || rx_size[i]==8)
85 RSIZE[i] = 0x400 * mul;
86 RMASK[i] = 0x400 * mul - 1;
97 DBGA(
"SBUFBASEADDRESS = %d",(uint16)SBUFBASEADDRESS[i]);
98 DBGA(
"RBUFBASEADDRESS = %d",(uint16)RBUFBASEADDRESS[i]);
99 DBGA(
"SSIZE = %d",SSIZE[i]);
100 DBGA(
"RSIZE = %d",RSIZE[i]);
106 if(netinfo->
mac[0] != 0x00 || netinfo->
mac[1] != 0x00 || netinfo->
mac[2] != 0x00 ||
107 netinfo->
mac[3] != 0x00 || netinfo->
mac[4] != 0x00 || netinfo->
mac[5] != 0x00)
108 setSHAR(netinfo->
mac);
109 if(netinfo->
ip[0] != 0x00 || netinfo->
ip[1] != 0x00 || netinfo->
ip[2] != 0x00 ||
110 netinfo->
ip[3] != 0x00) setSIPR(netinfo->
ip);
111 if(netinfo->
sn[0] != 0x00 || netinfo->
sn[1] != 0x00 || netinfo->
sn[2] != 0x00 ||
112 netinfo->
sn[3] != 0x00) setSUBR(netinfo->
sn);
113 if(netinfo->
gw[0] != 0x00 || netinfo->
gw[1] != 0x00 || netinfo->
gw[2] != 0x00 ||
114 netinfo->
gw[3] != 0x00) setGAR(netinfo->
gw);
115 if(netinfo->
dns[0] != 0x00 || netinfo->
dns[1] != 0x00 || netinfo->
dns[2] != 0x00 ||
116 netinfo->
dns[3] != 0x00){
117 DNS[0] = netinfo->
dns[0];
118 DNS[1] = netinfo->
dns[1];
119 DNS[2] = netinfo->
dns[2];
120 DNS[3] = netinfo->
dns[3];
123 if(netinfo->
dhcp != 0) DHCP = netinfo->
dhcp;
128 uint8 zero[6] = {0,};
130 DBGA(
"Reset Address(%d)", member);
145 DNS[0] = DNS[1] = DNS[2] = DNS[3] = 0;
148 ERRA(
"wrong member value (%d)", member);
154 getSHAR(netinfo->
mac);
155 getSIPR(netinfo->
ip);
156 getSUBR(netinfo->
sn);
158 netinfo->
dns[0] = DNS[0];
159 netinfo->
dns[1] = DNS[1];
160 netinfo->
dns[2] = DNS[2];
161 netinfo->
dns[3] = DNS[3];
162 netinfo->
dhcp = DHCP;
168 getDPORT(s, dstport);
175 setRTR(option_value);
178 setRCR((uint8)(option_value&0x00FF));
181 setIMR((uint8)(option_value&0x00FF));
191 ERRA(
"wrong socket number(%d)", s);
210 if((IINCHIP_READ_SOCKETREG(s, WIZC_MR)&0x0F) != Sn_MR_TCP)
219 ERRA(
"wrong socket number(%d)", s);
227 case SOCK_MACRAW:
return 12;
228 case SOCK_PPPOE:
return 13;
233 if((IINCHIP_READ_SOCKETREG(s, WIZC_MR)&0x0F) != Sn_MR_UDP)
241 return getSn_TX_FSR(s);
246 return getSn_RX_RSR(s);
252 ERRA(
"wrong socket number(%d)", s);
257 if(local_port == 0xffff) local_port = 0xc000;
270 IINCHIP_WRITE_SOCKETREG(s, WIZS_MR, Sn_MR_TCP);
271 IINCHIP_WRITE_SOCKETREG(s, WIZS_PORT0 + 0, (uint8)((port & 0xff00) >> 8));
272 IINCHIP_WRITE_SOCKETREG(s, WIZS_PORT0 + 1, (uint8)(port & 0x00ff));
273 IINCHIP_WRITE_SOCKETREG(s, WIZS_CR, Sn_CR_OPEN);
274 while(IINCHIP_READ_SOCKETREG(s, WIZS_CR));
275 DBGA(
"Sn_SR = %.2x , Protocol = %.2x", IINCHIP_READ_SOCKETREG(s, WIZS_SR), IINCHIP_READ_SOCKETREG(s, WIZS_MR));
279 if(IINCHIP_READ_SOCKETREG(s, WIZS_SR) != SOCK_INIT) {
280 DBGA(
"wrong status(%d)", IINCHIP_READ_SOCKETREG(s, WIZS_SR));
285 IINCHIP_WRITE_SOCKETREG(s, WIZS_CR, Sn_CR_LISTEN);
286 while(IINCHIP_READ_SOCKETREG(s, WIZS_CR));
298 if(ret !=
RET_OK)
return ret;
309 uint8 srcip[4], snmask[4];
312 ERRA(
"wrong socket number(%d)", s);
314 }
else if(dip == NULL) {
320 if(local_port == 0xffff) local_port = 0xc000;
333 IINCHIP_WRITE_SOCKETREG(s, WIZS_MR, Sn_MR_TCP);
334 IINCHIP_WRITE_SOCKETREG(s, WIZS_PORT0 + 0, (uint8)((sport & 0xff00) >> 8));
335 IINCHIP_WRITE_SOCKETREG(s, WIZS_PORT0 + 1, (uint8)(sport & 0x00ff));
336 IINCHIP_WRITE_SOCKETREG(s, WIZS_CR, Sn_CR_OPEN);
337 while(IINCHIP_READ_SOCKETREG(s, WIZS_CR));
338 DBGA(
"Sn_SR = %.2x , Protocol = %.2x", IINCHIP_READ_SOCKETREG(s, WIZS_SR), IINCHIP_READ_SOCKETREG(s, WIZS_MR));
343 if( ((dip[0] == 0xFF) && (dip[1] == 0xFF) &&
344 (dip[2] == 0xFF) && (dip[3] == 0xFF)) ||
345 ((dip[0] == 0x00) && (dip[1] == 0x00) &&
346 (dip[2] == 0x00) && (dip[3] == 0x00)) || (sport == 0x00) )
348 DBG(
"invalid ip or port");
349 DBGA(
"SOCK(%d)-[%02x.%02x.%02x.%02x, %d]",s,
350 dip[0], dip[1], dip[2], dip[3] , sport);
353 else if( (srcip[0]==0 && srcip[1]==0 && srcip[2]==0 && srcip[3]==0) &&
354 (snmask[0]!=0 || snmask[1]!=0 || snmask[2]!=0 || snmask[3]!=0) )
356 DBG(
"Source IP is NULL while SN Mask is Not NULL");
370 IINCHIP_WRITE_SOCKETREG(s, WIZS_DIPR0 + 0, dip[0]);
371 IINCHIP_WRITE_SOCKETREG(s, WIZS_DIPR0 + 1, dip[1]);
372 IINCHIP_WRITE_SOCKETREG(s, WIZS_DIPR0 + 2, dip[2]);
373 IINCHIP_WRITE_SOCKETREG(s, WIZS_DIPR0 + 3, dip[3]);
374 IINCHIP_WRITE_SOCKETREG(s, WIZS_DPORT0 + 0, (uint8)((dport & 0xff00) >> 8));
375 IINCHIP_WRITE_SOCKETREG(s, WIZS_DPORT0 + 1, (uint8)(dport & 0x00ff));
377 IINCHIP_WRITE_SOCKETREG(s, WIZS_CR,Sn_CR_CONNECT);
378 while (IINCHIP_READ_SOCKETREG(s, WIZS_CR));
389 ERRA(
"wrong socket number(%d)", s);
394 socksr = IINCHIP_READ_SOCKETREG(s, WIZS_SR);
397 if(socksr == SOCK_ESTABLISHED) {
402 }
else if(IINCHIP_READ_SOCKETREG(s, WIZS_IR) & Sn_IR_TIMEOUT) {
403 IINCHIP_WRITE_SOCKETREG(s, WIZS_IR, Sn_IR_TIMEOUT);
417 if(ret !=
RET_OK)
return ret;
431 ERRA(
"wrong socket number(%d)", s);
437 IINCHIP_WRITE_SOCKETREG(s, WIZS_CR, Sn_CR_DISCON);
438 while(IINCHIP_READ_SOCKETREG(s, WIZS_CR));
440 status = getSn_SR(s);
449 #define TIMEOUT_CLOSE_WAIT 200
453 ERRA(
"wrong socket number(%d)", s);
457 status = getSn_SR(s);
458 if(status == SOCK_CLOSED)
goto END_OK;
464 IINCHIP_WRITE_SOCKETREG(s, WIZS_CR, Sn_CR_CLOSE);
465 while(IINCHIP_READ_SOCKETREG(s, WIZS_CR));
469 IINCHIP_WRITE_SOCKETREG(s, WIZS_IR, 0xFF);
475 #define TIMEOUT_CLOSE_WAIT 200
479 ERRA(
"wrong socket number(%d)", s);
483 status = getSn_SR(s);
484 if(status == SOCK_CLOSED)
goto END_OK;
485 if(status == SOCK_CLOSE_WAIT) {
488 IINCHIP_WRITE_SOCKETREG(s, WIZS_CR, Sn_CR_CLOSE);
489 while(IINCHIP_READ_SOCKETREG(s, WIZS_CR));
494 IINCHIP_WRITE_SOCKETREG(s, WIZS_IR, 0xFF);
498 int32
TCPSend(uint8 s,
const int8 *buf, uint16 len)
521 ERRA(
"wrong socket number(%d)", s);
523 }
else if(len == 0) {
528 status = getSn_SR(s);
531 if((IINCHIP_READ_SOCKETREG(s, WIZS_MR) & 0x0F) != Sn_MR_TCP)
return SOCKERR_NOT_TCP;
536 init_windowfull_retry_cnt(s);
537 if(len > getIINCHIP_TxMAX(s)) len = getIINCHIP_TxMAX(s);
540 send_data_processing(s, (uint8*)buf, len);
548 txrd_checker[s] = IINCHIP_READ_SOCKETREG(s, WIZS_TX_RD0 + 0);
549 txrd_checker[s] = (txrd_checker[s] << 8) + IINCHIP_READ_SOCKETREG(s, WIZS_TX_RD0 + 1);
551 IINCHIP_WRITE_SOCKETREG(s, WIZS_CR,Sn_CR_SEND);
552 while (IINCHIP_READ_SOCKETREG(s, WIZS_CR));
580 ERRA(
"wrong socket number(%d)", s);
584 status = getSn_SR(s);
587 if((IINCHIP_READ_SOCKETREG(s, WIZS_MR) & 0x0F) != Sn_MR_TCP)
return SOCKERR_NOT_TCP;
592 status = incr_windowfull_retry_cnt(s);
604 txrd_checker[s] = IINCHIP_READ_SOCKETREG(s, WIZS_TX_RD0 + 0);
605 txrd_checker[s] = (txrd_checker[s] << 8) + IINCHIP_READ_SOCKETREG(s, WIZS_TX_RD0 + 1);
607 IINCHIP_WRITE_SOCKETREG(s, WIZS_CR,Sn_CR_SEND);
608 while (IINCHIP_READ_SOCKETREG(s, WIZS_CR));
619 if(!(IINCHIP_READ_SOCKETREG(s, WIZS_IR) & Sn_IR_SEND_OK)) {
620 if(IINCHIP_READ_SOCKETREG(s, WIZS_SR) == SOCK_CLOSED) {
627 }
else IINCHIP_WRITE_SOCKETREG(s, WIZS_IR, Sn_IR_SEND_OK);
632 txrd = IINCHIP_READ_SOCKETREG(s, WIZS_TX_RD0 + 0);
633 txrd = (txrd << 8) + IINCHIP_READ_SOCKETREG(s, WIZS_TX_RD0 + 1);
635 if(txrd > txrd_checker[s])
return txrd - txrd_checker[s];
636 else return (0xffff - txrd_checker[s]) + txrd + 1;
645 ERRA(
"wrong socket number(%d)", s);
647 }
else if(len == 0) {
654 status = getSn_SR(s);
657 if((IINCHIP_READ_SOCKETREG(s, WIZS_MR) & 0x0F) != Sn_MR_TCP)
return SOCKERR_NOT_TCP;
662 if(len < RSR_len) RSR_len = len;
663 recv_data_processing(s, (uint8*)buf, RSR_len);
667 IINCHIP_WRITE_SOCKETREG(s, WIZS_CR, Sn_CR_RECV);
668 while(IINCHIP_READ_SOCKETREG(s, WIZS_CR));
677 ERRA(
"wrong socket number(%d)", s);
682 if(local_port == 0xffff) local_port = 0xc000;
696 IINCHIP_WRITE_SOCKETREG(s, WIZS_MR, Sn_MR_UDP);
697 IINCHIP_WRITE_SOCKETREG(s, WIZS_PORT0 + 0, (uint8)((port & 0xff00) >> 8));
698 IINCHIP_WRITE_SOCKETREG(s, WIZS_PORT0 + 1, (uint8)(port & 0x00ff));
699 IINCHIP_WRITE_SOCKETREG(s, WIZS_CR, Sn_CR_OPEN);
700 while(IINCHIP_READ_SOCKETREG(s, WIZS_CR));
701 DBGA(
"Sn_SR = %.2x , Protocol = %.2x", IINCHIP_READ_SOCKETREG(s, WIZS_SR), IINCHIP_READ_SOCKETREG(s, WIZS_MR));
709 ERRA(
"wrong socket number(%d)", s);
717 IINCHIP_WRITE_SOCKETREG(s, WIZS_CR, Sn_CR_CLOSE);
718 while(IINCHIP_READ_SOCKETREG(s, WIZS_CR));
719 IINCHIP_WRITE_SOCKETREG(s, WIZS_IR, 0xFF);
724 int32
UDPSend(uint8 s,
const int8 *buf, uint16 len, uint8 *addr, uint16 port)
728 ret =
UDPSendNB(s, buf, len, addr, port);
729 if(ret <
RET_OK)
return ret;
734 if(ret ==
RET_OK)
return len;
739 int32
UDPSendNB(uint8 s,
const int8 *buf, uint16 len, uint8 *addr, uint16 port)
741 uint8 srcip[4], snmask[4], status = 0;
744 ERRA(
"wrong socket number(%d)", s);
746 }
else if(len == 0 || addr == NULL) {
747 if(len == 0)
ERR(
"Zero length");
748 else ERR(
"NULL Dst IP");
752 status = getSn_SR(s);
755 if((IINCHIP_READ_SOCKETREG(s, WIZS_MR) & 0x0F) != Sn_MR_UDP)
return SOCKERR_NOT_UDP;
758 if (len > getIINCHIP_TxMAX(s)) len = getIINCHIP_TxMAX(s);
763 if((addr[0]==0x00 && addr[1]==0x00 && addr[2]==0x00 &&
764 addr[3]==0x00) || (port==0x00))
766 DBG(
"invalid ip or port");
767 DBGA(
"SOCK(%d)-[%02x.%02x.%02x.%02x, %d, %d]",s,
768 addr[0], addr[1], addr[2], addr[3] , port, len);
771 else if( (srcip[0]==0 && srcip[1]==0 && srcip[2]==0 && srcip[3]==0) &&
772 (snmask[0]!=0 || snmask[1]!=0 || snmask[2]!=0 || snmask[3]!=0) )
774 DBG(
"Source IP is NULL while SN Mask is Not NULL");
785 IINCHIP_WRITE_SOCKETREG(s, WIZS_DIPR0 + 0, addr[0]);
786 IINCHIP_WRITE_SOCKETREG(s, WIZS_DIPR0 + 1, addr[1]);
787 IINCHIP_WRITE_SOCKETREG(s, WIZS_DIPR0 + 2, addr[2]);
788 IINCHIP_WRITE_SOCKETREG(s, WIZS_DIPR0 + 3, addr[3]);
789 IINCHIP_WRITE_SOCKETREG(s, WIZS_DPORT0 + 0,(uint8)((port & 0xff00) >> 8));
790 IINCHIP_WRITE_SOCKETREG(s, WIZS_DPORT0 + 1,(uint8)(port & 0x00ff));
792 send_data_processing(s, (uint8*)buf, len);
797 IINCHIP_WRITE_SOCKETREG(s, WIZS_CR, Sn_CR_SEND);
798 while(IINCHIP_READ_SOCKETREG(s, WIZS_CR));
807 uint8 ir = IINCHIP_READ_SOCKETREG(s, WIZS_IR);
810 if(!(ir & Sn_IR_SEND_OK)) {
811 if(ir & Sn_IR_TIMEOUT) {
814 IINCHIP_WRITE_SOCKETREG(s, WIZS_IR, (Sn_IR_SEND_OK | Sn_IR_TIMEOUT));
819 }
else IINCHIP_WRITE_SOCKETREG(s, WIZS_IR, Sn_IR_SEND_OK);
825 int32
UDPRecv(uint8 s, int8 *buf, uint16 len, uint8 *addr, uint16 *port)
827 uint8 prebuf[8], status = 0;
828 uint16 tmp_len = 0, RSR_len = 0;
831 ERRA(
"wrong socket number(%d)", s);
833 }
else if(len == 0) {
838 status = getSn_SR(s);
841 if((IINCHIP_READ_SOCKETREG(s, WIZS_MR) & 0x0F) != Sn_MR_UDP)
return SOCKERR_NOT_UDP;
846 DBGA(
"wrong data received (%d)", RSR_len);
847 recv_data_ignore(s, RSR_len);
851 IINCHIP_WRITE_SOCKETREG(s, WIZS_CR, Sn_CR_RECV);
852 while(IINCHIP_READ_SOCKETREG(s, WIZS_CR));
856 recv_data_processing(s, prebuf, 8);
858 IINCHIP_WRITE_SOCKETREG(s, WIZS_CR, Sn_CR_RECV);
868 *port = (*port << 8) + prebuf[5];
871 tmp_len = (tmp_len << 8) + prebuf[7];
874 while(IINCHIP_READ_SOCKETREG(s, WIZS_CR));
876 DBGA(
"UDP Recv - addr(%d.%d.%d.%d:%d), t(%d), R(%d)",
877 addr[0], addr[1], addr[2], addr[3], *port, tmp_len, RSR_len);
879 ERR(
"UDP Recv len Zero - remove rest all");
884 IINCHIP_WRITE_SOCKETREG(s, WIZS_CR, Sn_CR_RECV);
885 while(IINCHIP_READ_SOCKETREG(s, WIZS_CR));
893 tmp_len = RSR_len - len;
895 DBGA(
"Recv buffer not enough - len(%d)", len);
899 switch (IINCHIP_READ_SOCKETREG(s, WIZS_MR) & 0x07)
902 recv_data_processing(s, (uint8*)buf, RSR_len);
904 IINCHIP_WRITE_SOCKETREG(s, WIZS_CR, Sn_CR_RECV);
909 while(IINCHIP_READ_SOCKETREG(s, WIZS_CR));
910 DBG(
"Ignore rest data");
911 recv_data_ignore(s, tmp_len);
915 IINCHIP_WRITE_SOCKETREG(s, WIZS_CR, Sn_CR_RECV);
916 while(IINCHIP_READ_SOCKETREG(s, WIZS_CR));
918 if(tmp_len)
DBGA(
"another rest data(%d)", tmp_len);
919 else DBG(
"No rest data");
928 while(IINCHIP_READ_SOCKETREG(s, WIZS_CR));
948 uint8 socket(uint8 s, uint8 protocol, uint16 port, uint8 flag)
951 #ifdef __DEF_IINCHIP_DBG__
952 printf(
"socket()\r\n");
954 if ( ((protocol&0x0F) == Sn_MR_TCP) || ((protocol&0x0F) == Sn_MR_UDP) || ((protocol&0x0F) == Sn_MR_IPRAW) || ((protocol&0x0F) == Sn_MR_MACRAW) || ((protocol&0x0F) == Sn_MR_PPPOE) )
957 IINCHIP_WRITE_SOCKETREG(s, WIZS_MR ,protocol | flag);
959 IINCHIP_WRITE_SOCKETREG(s, WIZS_PORT0 ,(uint8)((port & 0xff00) >> 8));
960 IINCHIP_WRITE_SOCKETREG(s, (WIZS_PORT0 + 1),(uint8)(port & 0x00ff));
963 IINCHIP_WRITE_SOCKETREG(s, WIZS_PORT0 ,(uint8)((local_port & 0xff00) >> 8));
964 IINCHIP_WRITE_SOCKETREG(s, (WIZS_PORT0 + 1),(uint8)(local_port & 0x00ff));
966 IINCHIP_WRITE_SOCKETREG( s, WIZS_CR ,Sn_CR_OPEN);
969 while( IINCHIP_READ_SOCKETREG(s, WIZS_CR ) )
978 #ifdef __DEF_IINCHIP_DBG__
979 printf(
"Sn_SR = %.2x , Protocol = %.2x\r\n", IINCHIP_READ_SOCKETREG(s, WIZC_SR ), IINCHIP_READ_SOCKETREG(s, WIZC_MR ));
986 #ifdef __DEF_IINCHIP_DBG__
987 printf(
"close()\r\n");
990 IINCHIP_WRITE_SOCKETREG( s, WIZS_CR ,Sn_CR_CLOSE);
993 while( IINCHIP_READ_SOCKETREG(s, WIZS_CR ) )
997 IINCHIP_WRITE_SOCKETREG( s, WIZS_IR , 0xFF);
1000 uint8 listen(uint8 s)
1003 #ifdef __DEF_IINCHIP_DBG__
1004 printf(
"listen()\r\n");
1006 if (IINCHIP_READ_SOCKETREG(s, WIZS_SR ) == SOCK_INIT)
1008 IINCHIP_WRITE_SOCKETREG( s, WIZS_CR ,Sn_CR_LISTEN);
1010 while( IINCHIP_READ_SOCKETREG(s, WIZS_CR ) )
1018 #ifdef __DEF_IINCHIP_DBG__
1019 printf(
"Fail[invalid ip,port]\r\n");
1025 uint8 connect(uint8 s, uint8 * addr, uint16 port)
1028 #ifdef __DEF_IINCHIP_DBG__
1029 printf(
"connect()\r\n");
1033 ((addr[0] == 0xFF) && (addr[1] == 0xFF) && (addr[2] == 0xFF) && (addr[3] == 0xFF)) ||
1034 ((addr[0] == 0x00) && (addr[1] == 0x00) && (addr[2] == 0x00) && (addr[3] == 0x00)) ||
1039 #ifdef __DEF_IINCHIP_DBG__
1040 printf(
"Fail[invalid ip,port]\r\n");
1047 IINCHIP_WRITE_SOCKETREG( s, WIZS_DIPR0 ,addr[0]);
1048 IINCHIP_WRITE_SOCKETREG( s, (WIZS_DIPR0 + 1),addr[1]);
1049 IINCHIP_WRITE_SOCKETREG( s, (WIZS_DIPR0 + 2),addr[2]);
1050 IINCHIP_WRITE_SOCKETREG( s, (WIZS_DIPR0 + 3),addr[3]);
1051 IINCHIP_WRITE_SOCKETREG( s, WIZS_DPORT0 ,(uint8)((port & 0xff00) >> 8));
1052 IINCHIP_WRITE_SOCKETREG( s, (WIZS_DPORT0 + 1),(uint8)(port & 0x00ff));
1054 IINCHIP_WRITE_SOCKETREG( s, WIZS_CR ,Sn_CR_CONNECT);
1056 while ( IINCHIP_READ_SOCKETREG(s, WIZS_CR ) ) ;
1064 void disconnect(uint8 s)
1066 #ifdef __DEF_IINCHIP_DBG__
1067 printf(
"disconnect()\r\n");
1069 IINCHIP_WRITE_SOCKETREG( s, WIZS_CR ,Sn_CR_DISCON);
1072 while( IINCHIP_READ_SOCKETREG(s, WIZS_CR ) )
1077 #define __FERRSIZE_PRINF__
1078 #ifdef __FERRSIZE_PRINF__
1081 uint16 send(uint8 s,
const uint8 * buf, uint16 len)
1087 #ifdef __DEF_IINCHIP_DBG__
1088 printf(
"send()\r\n");
1090 if (len > getIINCHIP_TxMAX(s)) ret = getIINCHIP_TxMAX(s);
1096 freesize = getSn_TX_FSR(s);
1097 #ifdef __FERRSIZE_PRINF__
1107 }
while (freesize < ret);
1110 send_data_processing(s, (uint8 *)buf, ret);
1111 IINCHIP_WRITE_SOCKETREG( s, WIZS_CR ,Sn_CR_SEND);
1114 while( IINCHIP_READ_SOCKETREG(s, WIZS_CR ) );
1116 while ( (IINCHIP_READ_SOCKETREG(s, WIZS_IR ) & Sn_IR_SEND_OK) != Sn_IR_SEND_OK )
1119 status = IINCHIP_READ_SOCKETREG(s, WIZS_SR);
1120 if ((status != SOCK_ESTABLISHED) && (status != SOCK_CLOSE_WAIT) )
1122 printf(
"CH: %d Impossible case 1, socket state: %x\r\n", s, status);
1127 if(IINCHIP_READ_SOCKETREG(s, WIZS_IR ) == SOCK_CLOSED)
1129 printf(
"SEND_OK Problem!!\r\n");
1134 IINCHIP_WRITE_SOCKETREG( s, WIZS_IR , Sn_IR_SEND_OK);
1136 #ifdef __DEF_IINCHIP_INT__
1137 putISR(s, getISR(s) & (~Sn_IR_SEND_OK));
1139 IINCHIP_WRITE_SOCKETREG( s, WIZS_IR , Sn_IR_SEND_OK);
1145 uint16 recv(uint8 s, uint8 * buf, uint16 len)
1148 #ifdef __DEF_IINCHIP_DBG__
1149 printf(
"recv()\r\n");
1153 recv_data_processing(s, buf, len);
1154 IINCHIP_WRITE_SOCKETREG( s, WIZS_CR ,Sn_CR_RECV);
1156 while( IINCHIP_READ_SOCKETREG(s, WIZS_CR ));
1163 uint16 sendto(uint8 s,
const uint8 * buf, uint16 len, uint8 * addr, uint16 port)
1167 #ifdef __DEF_IINCHIP_DBG__
1168 printf(
"sendto()\r\n");
1170 if (len > getIINCHIP_TxMAX(s)) ret = getIINCHIP_TxMAX(s);
1173 if( ((addr[0] == 0x00) && (addr[1] == 0x00) && (addr[2] == 0x00) && (addr[3] == 0x00)) || ((port == 0x00)) )
1177 #ifdef __DEF_IINCHIP_DBG__
1178 printf(
"%d Fail[%.2x.%.2x.%.2x.%.2x, %.d, %d]\r\n",s, addr[0], addr[1], addr[2], addr[3] , port, len);
1179 printf(
"Fail[invalid ip,port]\r\n");
1184 #ifndef __DEF_IINCHIP_DBG__
1185 printf(
"\r\nDestination IP : %d.%d.%d.%d", addr[0],addr[1],addr[2],addr[3]);
1187 IINCHIP_WRITE_SOCKETREG( s, WIZS_DIPR0 ,addr[0]);
1188 IINCHIP_WRITE_SOCKETREG( s, (WIZS_DIPR0 + 1),addr[1]);
1189 IINCHIP_WRITE_SOCKETREG( s, (WIZS_DIPR0 + 2),addr[2]);
1190 IINCHIP_WRITE_SOCKETREG( s, (WIZS_DIPR0 + 3),addr[3]);
1191 IINCHIP_WRITE_SOCKETREG( s, WIZS_DPORT0 ,(uint8)((port & 0xff00) >> 8));
1192 IINCHIP_WRITE_SOCKETREG( s, (WIZS_DPORT0 + 1),(uint8)(port & 0x00ff));
1194 send_data_processing(s, (uint8 *)buf, ret);
1196 IINCHIP_WRITE_SOCKETREG( s, WIZS_CR ,Sn_CR_SEND);
1198 while( IINCHIP_READ_SOCKETREG(s, WIZS_CR ) )
1202 while( (IINCHIP_READ_SOCKETREG(s, WIZS_IR ) & Sn_IR_SEND_OK) != Sn_IR_SEND_OK )
1204 if (IINCHIP_READ_SOCKETREG(s, WIZS_IR ) & Sn_IR_TIMEOUT)
1206 #ifndef __DEF_IINCHIP_DBG__
1207 printf(
"\r\n Sendto fail.\r\n");
1210 IINCHIP_WRITE_SOCKETREG( s, WIZS_IR , (Sn_IR_SEND_OK | Sn_IR_TIMEOUT));
1215 IINCHIP_WRITE_SOCKETREG( s, WIZS_IR , Sn_IR_SEND_OK);
1220 uint16 recvfrom(uint8 s, uint8 * buf, uint16 len, uint8 * addr, uint16 *port)
1225 #ifdef __DEF_IINCHIP_DBG__
1226 printf(
"recvfrom()\r\n");
1231 ptr = IINCHIP_READ_SOCKETREG(s, WIZS_RX_RD0 );
1232 ptr = ((ptr & 0x00ff) << 8) + IINCHIP_READ_SOCKETREG(s, WIZS_RX_RD0 + 1);
1233 #ifdef __DEF_IINCHIP_DBG__
1234 printf(
"ISR_RX: rd_ptr : %.4x\r\n", ptr);
1236 switch (IINCHIP_READ_SOCKETREG(s, WIZC_MR ) & 0x07)
1239 IINCHIP_READ_RXBUF_SEQ(s, ptr, 0x08, head);
1247 *port = (*port << 8) + head[5];
1249 data_len = (data_len << 8) + head[7];
1251 #ifndef __DEF_IINCHIP_DBG__
1252 printf(
"UDP msg arrived\r\n");
1253 printf(
"source Port : %d\r\n", *port);
1254 printf(
"source IP : %d.%d.%d.%d\r\n", addr[0], addr[1], addr[2], addr[3]);
1257 IINCHIP_READ_RXBUF_SEQ(s, ptr, data_len, buf);
1260 IINCHIP_WRITE_SOCKETREG( s, WIZS_RX_RD0 ,(uint8)((ptr & 0xff00) >> 8));
1261 IINCHIP_WRITE_SOCKETREG( s, (WIZS_RX_RD0 + 1),(uint8)(ptr & 0x00ff));
1265 IINCHIP_READ_RXBUF_SEQ(s, ptr, 0x06, head);
1273 data_len = (data_len << 8) + head[5];
1275 #ifdef __DEF_IINCHIP_DBG__
1276 printf(
"IP RAW msg arrived\r\n");
1277 printf(
"source IP : %d.%d.%d.%d\r\n", addr[0], addr[1], addr[2], addr[3]);
1280 IINCHIP_READ_RXBUF_SEQ(s, ptr, data_len, buf);
1284 IINCHIP_WRITE_SOCKETREG( s, WIZS_RX_RD0 ,(uint8)((ptr & 0xff00) >> 8));
1285 IINCHIP_WRITE_SOCKETREG( s, (WIZS_RX_RD0 + 1),(uint8)(ptr & 0x00ff));
1288 IINCHIP_READ_RXBUF_SEQ(s, ptr, 2, head);
1291 data_len = (data_len<<8) + head[1] - 2;
1294 printf(
"data_len over 1514\r\n");
1298 IINCHIP_READ_RXBUF_SEQ(s, ptr, data_len, buf);
1302 IINCHIP_WRITE_SOCKETREG( s, WIZS_RX_RD0 ,(uint8)((ptr & 0xff00) >> 8));
1303 IINCHIP_WRITE_SOCKETREG( s, (WIZS_RX_RD0 + 1),(uint8)(ptr & 0x00ff));
1305 #ifdef __DEF_IINCHIP_DGB__
1306 printf(
"MAC RAW msg arrived\r\n");
1307 printf(
"dest mac=%.2X.%.2X.%.2X.%.2X.%.2X.%.2X\r\n",buf[0],buf[1],buf[2],buf[3],buf[4],buf[5]);
1308 printf(
"src mac=%.2X.%.2X.%.2X.%.2X.%.2X.%.2X\r\n",buf[6],buf[7],buf[8],buf[9],buf[10],buf[11]);
1309 printf(
"type =%.2X%.2X\r\n",buf[12],buf[13]);
1316 IINCHIP_WRITE_SOCKETREG( s, WIZS_CR ,Sn_CR_RECV);
1319 while( IINCHIP_READ_SOCKETREG(s, WIZS_CR) ) ;
1322 #ifdef __DEF_IINCHIP_DBG__
1323 printf(
"recvfrom() end ..\r\n");
1328 void macraw_open(
void)
1331 uint16 dummyPort = 0;
1337 socket(sock_num, Sn_MR_MACRAW, dummyPort,mFlag);
1341 uint16 macraw_send(
const uint8 * buf, uint16 len )
1348 #ifndef __DEF_IINCHIP_DBG__
1349 printf(
"macsend()\r\n");
1352 if (len > getIINCHIP_TxMAX(sock_num)) ret = getIINCHIP_TxMAX(sock_num);
1355 #ifdef __DEF_IINCHIP_DGB__
1356 printf(
"ret : %d \r\n", ret);
1357 printf(
"MAC RAW msg SEND\r\n");
1358 printf(
"dest mac=%.2X.%.2X.%.2X.%.2X.%.2X.%.2X\r\n",buf[0],buf[1],buf[2],buf[3],buf[4],buf[5]);
1359 printf(
"src mac=%.2X.%.2X.%.2X.%.2X.%.2X.%.2X\r\n",buf[6],buf[7],buf[8],buf[9],buf[10],buf[11]);
1360 printf(
"type =%.2X%.2X\r\n",buf[12],buf[13]);
1361 for(idx=0; idx<(ret-14); idx++)
1363 if( (idx%16)==0 ) printf(
"\r\n");
1364 printf(
"%.2X ", buf[idx+14]);
1369 send_data_processing(sock_num, (uint8 *)buf, len);
1372 IINCHIP_WRITE_SOCKETREG(sock_num, WIZS_CR,Sn_CR_SEND);
1373 while( IINCHIP_READ_SOCKETREG(sock_num, WIZS_CR) );
1374 while ( (IINCHIP_READ_SOCKETREG(sock_num, WIZS_IR) & Sn_IR_SEND_OK) != Sn_IR_SEND_OK );
1375 IINCHIP_WRITE_SOCKETREG(sock_num, WIZS_IR, Sn_IR_SEND_OK);
1377 #ifdef __DEF_IINCHIP_DBG__
1378 printf(
"macsend() over\r\n");
1383 uint16 macraw_recv( uint8 * buf, uint16 len )
1387 uint16 dummyPort = 0;
1392 #ifdef __DEF_IINCHIP_DBG__
1393 printf(
"macrecv()\r\n");
1399 #ifdef __DEF_IINCHIP_DBG__
1400 printf(
"ISR_RX: rd_ptr : %.4x\r\n", ptr);
1404 ptr = IINCHIP_READ_SOCKETREG(0, WIZS_RX_RD0);
1405 ptr = (uint16)((ptr & 0x00ff) << 8) + IINCHIP_READ_SOCKETREG(0, WIZS_RX_RD0 + 1);
1407 data_len = IINCHIP_READ_RXBUF(0, ptr);
1409 data_len = ((data_len<<8) + IINCHIP_READ_RXBUF(0, ptr)) - 2;
1412 #ifdef __DEF_IINCHIP_DBG__
1413 printf(
"\r\nptr: %X, data_len: %X", ptr, data_len);
1417 printf(
"data_len over 1514\r\n");
1418 printf(
"\r\nptr: %X, data_len: %X", ptr, data_len);
1421 IINCHIP_READ_RXBUF_SEQ(sock_num, 0, 64, (uint8*)(buf));
1424 for(idx=0; idx<1024; idx++)
1426 if(idx>0 && (idx%16)==0) printf(
"\r\n");
1427 printf(
"%.2X, ", buf[idx]);
1429 printf(
"------------\r\n");
1434 socket(sock_num, Sn_MR_MACRAW, dummyPort,mFlag);
1438 IINCHIP_READ_RXBUF_SEQ(sock_num, ptr, data_len, (uint8*)(buf));
1440 #ifdef __DEF_IINCHIP_DBG__
1441 printf(
"ptr: %X \r\n", ptr);
1443 IINCHIP_WRITE_SOCKETREG(sock_num, WIZS_RX_RD0,(uint8)((ptr & 0xff00) >> 8));
1444 IINCHIP_WRITE_SOCKETREG(sock_num, (WIZS_RX_RD0 + 1),(uint8)(ptr & 0x00ff));
1445 IINCHIP_WRITE_SOCKETREG(sock_num, WIZS_CR, Sn_CR_RECV);
1446 while( IINCHIP_READ_SOCKETREG(sock_num, WIZS_CR) ) ;
1449 #ifdef __DEF_IINCHIP_DBG__
1450 printf(
"macrecv() end ..\r\n");