DOS to Unix line-encoding conversion.

git-svn-id: svn+ssh://oldsvn/home/mlalondesvn/svn/cral@57 3ee9b42a-b53c-0410-a25e-f0b6218d5d5b
master
follower 17 years ago
parent f7c399c222
commit 8245c6d8be

@ -1,484 +1,484 @@
/* /*
* *
@file socket.c @file socket.c
@brief setting chip register for socket @brief setting chip register for socket
* *
*/ */
#include <avr/io.h> #include <avr/io.h>
#include <avr/interrupt.h> #include <avr/interrupt.h>
#include "types.h" #include "types.h"
#ifdef __DEF_IINCHIP_DBG__ #ifdef __DEF_IINCHIP_DBG__
#include <stdio.h> #include <stdio.h>
#endif #endif
#include "w5100.h" #include "w5100.h"
#include "socket.h" #include "socket.h"
static uint16 local_port; static uint16 local_port;
/** /**
@brief This Socket function initialize the channel in perticular mode, and set the port and wait for W5100 done it. @brief This Socket function initialize the channel in perticular mode, and set the port and wait for W5100 done it.
@return 1 for sucess else 0. @return 1 for sucess else 0.
*/ */
uint8 socket( uint8 socket(
SOCKET s, /**< for socket number */ SOCKET s, /**< for socket number */
uint8 protocol, /**< for socket protocol */ uint8 protocol, /**< for socket protocol */
uint16 port, /**< the source port for the socket */ uint16 port, /**< the source port for the socket */
uint8 flag /**< the option for the socket */ uint8 flag /**< the option for the socket */
) )
{ {
uint8 ret; uint8 ret;
#ifdef __DEF_IINCHIP_DBG__ #ifdef __DEF_IINCHIP_DBG__
printf("socket()\r\n"); printf("socket()\r\n");
#endif #endif
if ((protocol == Sn_MR_TCP) || (protocol == Sn_MR_UDP) || (protocol == Sn_MR_IPRAW) || (protocol == Sn_MR_MACRAW) || (protocol == Sn_MR_PPPOE)) if ((protocol == Sn_MR_TCP) || (protocol == Sn_MR_UDP) || (protocol == Sn_MR_IPRAW) || (protocol == Sn_MR_MACRAW) || (protocol == Sn_MR_PPPOE))
{ {
close(s); close(s);
IINCHIP_WRITE(Sn_MR(s),protocol | flag); IINCHIP_WRITE(Sn_MR(s),protocol | flag);
if (port != 0) { if (port != 0) {
IINCHIP_WRITE(Sn_PORT0(s),(uint8)((port & 0xff00) >> 8)); IINCHIP_WRITE(Sn_PORT0(s),(uint8)((port & 0xff00) >> 8));
IINCHIP_WRITE((Sn_PORT0(s) + 1),(uint8)(port & 0x00ff)); IINCHIP_WRITE((Sn_PORT0(s) + 1),(uint8)(port & 0x00ff));
} else { } else {
local_port++; // if don't set the source port, set local_port number. local_port++; // if don't set the source port, set local_port number.
IINCHIP_WRITE(Sn_PORT0(s),(uint8)((local_port & 0xff00) >> 8)); IINCHIP_WRITE(Sn_PORT0(s),(uint8)((local_port & 0xff00) >> 8));
IINCHIP_WRITE((Sn_PORT0(s) + 1),(uint8)(local_port & 0x00ff)); IINCHIP_WRITE((Sn_PORT0(s) + 1),(uint8)(local_port & 0x00ff));
} }
IINCHIP_WRITE(Sn_CR(s),Sn_CR_OPEN); // run sockinit Sn_CR IINCHIP_WRITE(Sn_CR(s),Sn_CR_OPEN); // run sockinit Sn_CR
ret = 1; ret = 1;
} }
else else
{ {
ret = 0; ret = 0;
} }
#ifdef __DEF_IINCHIP_DBG__ #ifdef __DEF_IINCHIP_DBG__
printf("Sn_SR = %.2x , Protocol = %.2x\r\n", IINCHIP_READ(Sn_SR(s)), IINCHIP_READ(Sn_MR(s))); printf("Sn_SR = %.2x , Protocol = %.2x\r\n", IINCHIP_READ(Sn_SR(s)), IINCHIP_READ(Sn_MR(s)));
#endif #endif
return ret; return ret;
} }
/** /**
@brief This function close the socket and parameter is "s" which represent the socket number @brief This function close the socket and parameter is "s" which represent the socket number
*/ */
void close(SOCKET s) void close(SOCKET s)
{ {
#ifdef __DEF_IINCHIP_DBG__ #ifdef __DEF_IINCHIP_DBG__
printf("close()\r\n"); printf("close()\r\n");
#endif #endif
IINCHIP_WRITE(Sn_CR(s),Sn_CR_CLOSE); IINCHIP_WRITE(Sn_CR(s),Sn_CR_CLOSE);
} }
/** /**
@brief This function established the connection for the channel in passive (server) mode. This function waits for the request from the peer. @brief This function established the connection for the channel in passive (server) mode. This function waits for the request from the peer.
@return 1 for success else 0. @return 1 for success else 0.
*/ */
uint8 listen( uint8 listen(
SOCKET s /**< the socket number */ SOCKET s /**< the socket number */
) )
{ {
uint8 ret; uint8 ret;
#ifdef __DEF_IINCHIP_DBG__ #ifdef __DEF_IINCHIP_DBG__
printf("listen()\r\n"); printf("listen()\r\n");
#endif #endif
if (IINCHIP_READ(Sn_SR(s)) == SOCK_INIT) if (IINCHIP_READ(Sn_SR(s)) == SOCK_INIT)
{ {
IINCHIP_WRITE(Sn_CR(s),Sn_CR_LISTEN); IINCHIP_WRITE(Sn_CR(s),Sn_CR_LISTEN);
ret = 1; ret = 1;
} }
else else
{ {
ret = 0; ret = 0;
#ifdef __DEF_IINCHIP_DBG__ #ifdef __DEF_IINCHIP_DBG__
printf("Fail[invalid ip,port]\r\n"); printf("Fail[invalid ip,port]\r\n");
#endif #endif
} }
return ret; return ret;
} }
/** /**
@brief This function established the connection for the channel in Active (client) mode. @brief This function established the connection for the channel in Active (client) mode.
This function waits for the untill the connection is established. This function waits for the untill the connection is established.
@return 1 for success else 0. @return 1 for success else 0.
*/ */
uint8 connect(SOCKET s, uint8 * addr, uint16 port) uint8 connect(SOCKET s, uint8 * addr, uint16 port)
{ {
uint8 ret; uint8 ret;
#ifdef __DEF_IINCHIP_DBG__ #ifdef __DEF_IINCHIP_DBG__
printf("connect()\r\n"); printf("connect()\r\n");
#endif #endif
if if
( (
((addr[0] == 0xFF) && (addr[1] == 0xFF) && (addr[2] == 0xFF) && (addr[3] == 0xFF)) || ((addr[0] == 0xFF) && (addr[1] == 0xFF) && (addr[2] == 0xFF) && (addr[3] == 0xFF)) ||
((addr[0] == 0x00) && (addr[1] == 0x00) && (addr[2] == 0x00) && (addr[3] == 0x00)) || ((addr[0] == 0x00) && (addr[1] == 0x00) && (addr[2] == 0x00) && (addr[3] == 0x00)) ||
(port == 0x00) (port == 0x00)
) )
{ {
ret = 0; ret = 0;
#ifdef __DEF_IINCHIP_DBG__ #ifdef __DEF_IINCHIP_DBG__
printf("Fail[invalid ip,port]\r\n"); printf("Fail[invalid ip,port]\r\n");
#endif #endif
} }
else else
{ {
ret = 1; ret = 1;
// set destination IP // set destination IP
IINCHIP_WRITE(Sn_DIPR0(s),addr[0]); IINCHIP_WRITE(Sn_DIPR0(s),addr[0]);
IINCHIP_WRITE((Sn_DIPR0(s) + 1),addr[1]); IINCHIP_WRITE((Sn_DIPR0(s) + 1),addr[1]);
IINCHIP_WRITE((Sn_DIPR0(s) + 2),addr[2]); IINCHIP_WRITE((Sn_DIPR0(s) + 2),addr[2]);
IINCHIP_WRITE((Sn_DIPR0(s) + 3),addr[3]); IINCHIP_WRITE((Sn_DIPR0(s) + 3),addr[3]);
IINCHIP_WRITE(Sn_DPORT0(s),(uint8)((port & 0xff00) >> 8)); IINCHIP_WRITE(Sn_DPORT0(s),(uint8)((port & 0xff00) >> 8));
IINCHIP_WRITE((Sn_DPORT0(s) + 1),(uint8)(port & 0x00ff)); IINCHIP_WRITE((Sn_DPORT0(s) + 1),(uint8)(port & 0x00ff));
IINCHIP_WRITE(Sn_CR(s),Sn_CR_CONNECT); IINCHIP_WRITE(Sn_CR(s),Sn_CR_CONNECT);
// wait for completion // wait for completion
while (IINCHIP_READ(Sn_CR(s))) while (IINCHIP_READ(Sn_CR(s)))
{ {
if (IINCHIP_READ(Sn_SR(s)) == SOCK_CLOSED) if (IINCHIP_READ(Sn_SR(s)) == SOCK_CLOSED)
{ {
#ifdef __DEF_IINCHIP_DBG__ #ifdef __DEF_IINCHIP_DBG__
printf("SOCK_CLOSED.\r\n"); printf("SOCK_CLOSED.\r\n");
#endif #endif
ret = 0; break; ret = 0; break;
} }
} }
} }
return ret; return ret;
} }
/** /**
@brief This function used for disconnect the socket and parameter is "s" which represent the socket number @brief This function used for disconnect the socket and parameter is "s" which represent the socket number
@return 1 for success else 0. @return 1 for success else 0.
*/ */
void disconnect(SOCKET s) void disconnect(SOCKET s)
{ {
#ifdef __DEF_IINCHIP_DBG__ #ifdef __DEF_IINCHIP_DBG__
printf("disconnect()\r\n"); printf("disconnect()\r\n");
#endif #endif
IINCHIP_WRITE(Sn_CR(s),Sn_CR_DISCON); IINCHIP_WRITE(Sn_CR(s),Sn_CR_DISCON);
} }
/** /**
@brief This function used to send the data in TCP mode @brief This function used to send the data in TCP mode
@return 1 for success else 0. @return 1 for success else 0.
*/ */
uint16 send( uint16 send(
SOCKET s, /**< the socket index */ SOCKET s, /**< the socket index */
const uint8 * buf, /**< a pointer to data */ const uint8 * buf, /**< a pointer to data */
uint16 len /**< the data size to be send */ uint16 len /**< the data size to be send */
) )
{ {
uint8 status=0; uint8 status=0;
uint16 ret=0; uint16 ret=0;
uint16 freesize=0; uint16 freesize=0;
#ifdef __DEF_IINCHIP_DBG__ #ifdef __DEF_IINCHIP_DBG__
printf("send()\r\n"); printf("send()\r\n");
#endif #endif
if (len > getIINCHIP_TxMAX(s)) ret = getIINCHIP_TxMAX(s); // check size not to exceed MAX size. if (len > getIINCHIP_TxMAX(s)) ret = getIINCHIP_TxMAX(s); // check size not to exceed MAX size.
else ret = len; else ret = len;
// if freebuf is available, start. // if freebuf is available, start.
do do
{ {
freesize = getSn_TX_FSR(s); freesize = getSn_TX_FSR(s);
status = IINCHIP_READ(Sn_SR(s)); status = IINCHIP_READ(Sn_SR(s));
if ((status != SOCK_ESTABLISHED) && (status != SOCK_CLOSE_WAIT)) if ((status != SOCK_ESTABLISHED) && (status != SOCK_CLOSE_WAIT))
{ {
ret = 0; ret = 0;
break; break;
} }
#ifdef __DEF_IINCHIP_DBG__ #ifdef __DEF_IINCHIP_DBG__
printf("socket %d freesize(%d) empty or error\r\n", s, freesize); printf("socket %d freesize(%d) empty or error\r\n", s, freesize);
#endif #endif
} while (freesize < ret); } while (freesize < ret);
// copy data // copy data
send_data_processing(s, (uint8 *)buf, ret); send_data_processing(s, (uint8 *)buf, ret);
IINCHIP_WRITE(Sn_CR(s),Sn_CR_SEND); IINCHIP_WRITE(Sn_CR(s),Sn_CR_SEND);
// wait for completion // wait for completion
while ( (IINCHIP_READ(Sn_IR(s)) & Sn_IR_SEND_OK) != Sn_IR_SEND_OK ) while ( (IINCHIP_READ(Sn_IR(s)) & Sn_IR_SEND_OK) != Sn_IR_SEND_OK )
{ {
status = IINCHIP_READ(Sn_SR(s)); status = IINCHIP_READ(Sn_SR(s));
if (status == SOCK_CLOSED) if (status == SOCK_CLOSED)
{ {
#ifdef __DEF_IINCHIP_DBG__ #ifdef __DEF_IINCHIP_DBG__
printf("SOCK_CLOSED.\r\n"); printf("SOCK_CLOSED.\r\n");
#endif #endif
putISR(s, getISR(s) & (Sn_IR_RECV | Sn_IR_DISCON | Sn_IR_CON)); putISR(s, getISR(s) & (Sn_IR_RECV | Sn_IR_DISCON | Sn_IR_CON));
IINCHIP_WRITE(Sn_IR(s), (Sn_IR_SEND_OK | Sn_IR_TIMEOUT)); IINCHIP_WRITE(Sn_IR(s), (Sn_IR_SEND_OK | Sn_IR_TIMEOUT));
return 0; return 0;
} }
} }
putISR(s, getISR(s) & (~Sn_IR_SEND_OK)); putISR(s, getISR(s) & (~Sn_IR_SEND_OK));
IINCHIP_WRITE(Sn_IR(s), Sn_IR_SEND_OK); IINCHIP_WRITE(Sn_IR(s), Sn_IR_SEND_OK);
return ret; return ret;
} }
/** /**
@brief This function is an application I/F function which is used to receive the data in TCP mode. @brief This function is an application I/F function which is used to receive the data in TCP mode.
It continues to wait for data as much as the application wants to receive. It continues to wait for data as much as the application wants to receive.
@return received data size for success else -1. @return received data size for success else -1.
*/ */
uint16 recv( uint16 recv(
SOCKET s, /**< socket index */ SOCKET s, /**< socket index */
uint8 * buf, /**< a pointer to copy the data to be received */ uint8 * buf, /**< a pointer to copy the data to be received */
uint16 len /**< the data size to be read */ uint16 len /**< the data size to be read */
) )
{ {
uint16 ret=0; uint16 ret=0;
#ifdef __DEF_IINCHIP_DBG__ #ifdef __DEF_IINCHIP_DBG__
printf("recv()\r\n"); printf("recv()\r\n");
#endif #endif
if ( len > 0 ) if ( len > 0 )
{ {
recv_data_processing(s, buf, len); recv_data_processing(s, buf, len);
IINCHIP_WRITE(Sn_CR(s),Sn_CR_RECV); IINCHIP_WRITE(Sn_CR(s),Sn_CR_RECV);
ret = len; ret = len;
} }
return ret; return ret;
} }
/** /**
@brief This function is an application I/F function which is used to send the data for other then TCP mode. @brief This function is an application I/F function which is used to send the data for other then TCP mode.
Unlike TCP transmission, The peer's destination address and the port is needed. Unlike TCP transmission, The peer's destination address and the port is needed.
@return This function return send data size for success else -1. @return This function return send data size for success else -1.
*/ */
uint16 sendto( uint16 sendto(
SOCKET s, /**< socket index */ SOCKET s, /**< socket index */
const uint8 * buf, /**< a pointer to the data */ const uint8 * buf, /**< a pointer to the data */
uint16 len, /**< the data size to send */ uint16 len, /**< the data size to send */
uint8 * addr, /**< the peer's Destination IP address */ uint8 * addr, /**< the peer's Destination IP address */
uint16 port /**< the peer's destination port number */ uint16 port /**< the peer's destination port number */
) )
{ {
uint8 status=0; uint8 status=0;
uint8 isr=0; uint8 isr=0;
uint16 ret=0; uint16 ret=0;
#ifdef __DEF_IINCHIP_DBG__ #ifdef __DEF_IINCHIP_DBG__
printf("sendto()\r\n"); printf("sendto()\r\n");
#endif #endif
if (len > getIINCHIP_TxMAX(s)) ret = getIINCHIP_TxMAX(s); // check size not to exceed MAX size. if (len > getIINCHIP_TxMAX(s)) ret = getIINCHIP_TxMAX(s); // check size not to exceed MAX size.
else ret = len; else ret = len;
if if
( (
((addr[0] == 0x00) && (addr[1] == 0x00) && (addr[2] == 0x00) && (addr[3] == 0x00)) || ((addr[0] == 0x00) && (addr[1] == 0x00) && (addr[2] == 0x00) && (addr[3] == 0x00)) ||
((port == 0x00)) ||(ret == 0) ((port == 0x00)) ||(ret == 0)
) )
{ {
; ;
#ifdef __DEF_IINCHIP_DBG__ #ifdef __DEF_IINCHIP_DBG__
printf("%d Fail[%.2x.%.2x.%.2x.%.2x, %.d, %d]\r\n",s, addr[0], addr[1], addr[2], addr[3] , port, len); printf("%d Fail[%.2x.%.2x.%.2x.%.2x, %.d, %d]\r\n",s, addr[0], addr[1], addr[2], addr[3] , port, len);
printf("Fail[invalid ip,port]\r\n"); printf("Fail[invalid ip,port]\r\n");
#endif #endif
} }
else else
{ {
IINCHIP_WRITE(Sn_DIPR0(s),addr[0]); IINCHIP_WRITE(Sn_DIPR0(s),addr[0]);
IINCHIP_WRITE((Sn_DIPR0(s) + 1),addr[1]); IINCHIP_WRITE((Sn_DIPR0(s) + 1),addr[1]);
IINCHIP_WRITE((Sn_DIPR0(s) + 2),addr[2]); IINCHIP_WRITE((Sn_DIPR0(s) + 2),addr[2]);
IINCHIP_WRITE((Sn_DIPR0(s) + 3),addr[3]); IINCHIP_WRITE((Sn_DIPR0(s) + 3),addr[3]);
IINCHIP_WRITE(Sn_DPORT0(s),(uint8)((port & 0xff00) >> 8)); IINCHIP_WRITE(Sn_DPORT0(s),(uint8)((port & 0xff00) >> 8));
IINCHIP_WRITE((Sn_DPORT0(s) + 1),(uint8)(port & 0x00ff)); IINCHIP_WRITE((Sn_DPORT0(s) + 1),(uint8)(port & 0x00ff));
// copy data // copy data
send_data_processing(s, (uint8 *)buf, ret); send_data_processing(s, (uint8 *)buf, ret);
IINCHIP_WRITE(Sn_CR(s),Sn_CR_SEND); IINCHIP_WRITE(Sn_CR(s),Sn_CR_SEND);
while ( (IINCHIP_READ(Sn_IR(s)) & Sn_IR_SEND_OK) != Sn_IR_SEND_OK ) while ( (IINCHIP_READ(Sn_IR(s)) & Sn_IR_SEND_OK) != Sn_IR_SEND_OK )
{ {
status = IINCHIP_READ(Sn_SR(s)); status = IINCHIP_READ(Sn_SR(s));
#ifndef __DEF_IINCHIP_INT__ #ifndef __DEF_IINCHIP_INT__
isr = IINCHIP_READ(Sn_IR(s)); isr = IINCHIP_READ(Sn_IR(s));
#endif #endif
if ((isr & Sn_IR_TIMEOUT) || (getISR(s) & Sn_IR_TIMEOUT)) if ((isr & Sn_IR_TIMEOUT) || (getISR(s) & Sn_IR_TIMEOUT))
{ {
#ifdef __DEF_IINCHIP_DBG__ #ifdef __DEF_IINCHIP_DBG__
printf("send fail.\r\n"); printf("send fail.\r\n");
#endif #endif
putISR(s, getISR(s) & (Sn_IR_RECV | Sn_IR_DISCON | Sn_IR_CON)); /* clear SEND_OK & TIMEOUT in I_STATUS[s] */ putISR(s, getISR(s) & (Sn_IR_RECV | Sn_IR_DISCON | Sn_IR_CON)); /* clear SEND_OK & TIMEOUT in I_STATUS[s] */
IINCHIP_WRITE(Sn_IR(s), (Sn_IR_SEND_OK | Sn_IR_TIMEOUT)); // clear SEND_OK & TIMEOUT in Sn_IR(s) IINCHIP_WRITE(Sn_IR(s), (Sn_IR_SEND_OK | Sn_IR_TIMEOUT)); // clear SEND_OK & TIMEOUT in Sn_IR(s)
return 0; return 0;
} }
} }
putISR(s, getISR(s) & (~Sn_IR_SEND_OK)); putISR(s, getISR(s) & (~Sn_IR_SEND_OK));
IINCHIP_WRITE(Sn_IR(s), Sn_IR_SEND_OK); IINCHIP_WRITE(Sn_IR(s), Sn_IR_SEND_OK);
} }
return ret; return ret;
} }
/** /**
@brief This function is an application I/F function which is used to receive the data in other then @brief This function is an application I/F function which is used to receive the data in other then
TCP mode. This function is used to receive UDP, IP_RAW and MAC_RAW mode, and handle the header as well. TCP mode. This function is used to receive UDP, IP_RAW and MAC_RAW mode, and handle the header as well.
@return This function return received data size for success else -1. @return This function return received data size for success else -1.
*/ */
uint16 recvfrom( uint16 recvfrom(
SOCKET s, /**< the socket number */ SOCKET s, /**< the socket number */
uint8 * buf, /**< a pointer to copy the data to be received */ uint8 * buf, /**< a pointer to copy the data to be received */
uint16 len, /**< the data size to read */ uint16 len, /**< the data size to read */
uint8 * addr, /**< a pointer to store the peer's IP address */ uint8 * addr, /**< a pointer to store the peer's IP address */
uint16 *port /**< a pointer to store the peer's port number. */ uint16 *port /**< a pointer to store the peer's port number. */
) )
{ {
uint8 head[8]; uint8 head[8];
uint16 data_len=0; uint16 data_len=0;
uint16 ptr=0; uint16 ptr=0;
#ifdef __DEF_IINCHIP_DBG__ #ifdef __DEF_IINCHIP_DBG__
printf("recvfrom()\r\n"); printf("recvfrom()\r\n");
#endif #endif
if ( len > 0 ) if ( len > 0 )
{ {
ptr = IINCHIP_READ(Sn_RX_RD0(s)); ptr = IINCHIP_READ(Sn_RX_RD0(s));
ptr = ((ptr & 0x00ff) << 8) + IINCHIP_READ(Sn_RX_RD0(s) + 1); ptr = ((ptr & 0x00ff) << 8) + IINCHIP_READ(Sn_RX_RD0(s) + 1);
#ifdef __DEF_IINCHIP_DBG__ #ifdef __DEF_IINCHIP_DBG__
printf("ISR_RX: rd_ptr : %.4x\r\n", ptr); printf("ISR_RX: rd_ptr : %.4x\r\n", ptr);
#endif #endif
switch (IINCHIP_READ(Sn_MR(s)) & 0x07) switch (IINCHIP_READ(Sn_MR(s)) & 0x07)
{ {
case Sn_MR_UDP : case Sn_MR_UDP :
read_data(s, (uint8 *)ptr, head, 0x08); read_data(s, (uint8 *)ptr, head, 0x08);
ptr += 8; ptr += 8;
// read peer's IP address, port number. // read peer's IP address, port number.
addr[0] = head[0]; addr[0] = head[0];
addr[1] = head[1]; addr[1] = head[1];
addr[2] = head[2]; addr[2] = head[2];
addr[3] = head[3]; addr[3] = head[3];
*port = head[4]; *port = head[4];
*port = (*port << 8) + head[5]; *port = (*port << 8) + head[5];
data_len = head[6]; data_len = head[6];
data_len = (data_len << 8) + head[7]; data_len = (data_len << 8) + head[7];
#ifdef __DEF_IINCHIP_DBG__ #ifdef __DEF_IINCHIP_DBG__
printf("UDP msg arrived\r\n"); printf("UDP msg arrived\r\n");
printf("source Port : %d\r\n", *port); printf("source Port : %d\r\n", *port);
printf("source IP : %d.%d.%d.%d\r\n", addr[0], addr[1], addr[2], addr[3]); printf("source IP : %d.%d.%d.%d\r\n", addr[0], addr[1], addr[2], addr[3]);
#endif #endif
read_data(s, (uint8 *)ptr, buf, data_len); // data copy. read_data(s, (uint8 *)ptr, buf, data_len); // data copy.
ptr += data_len; ptr += data_len;
IINCHIP_WRITE(Sn_RX_RD0(s),(uint8)((ptr & 0xff00) >> 8)); IINCHIP_WRITE(Sn_RX_RD0(s),(uint8)((ptr & 0xff00) >> 8));
IINCHIP_WRITE((Sn_RX_RD0(s) + 1),(uint8)(ptr & 0x00ff)); IINCHIP_WRITE((Sn_RX_RD0(s) + 1),(uint8)(ptr & 0x00ff));
break; break;
case Sn_MR_IPRAW : case Sn_MR_IPRAW :
read_data(s, (uint8 *)ptr, head, 0x06); read_data(s, (uint8 *)ptr, head, 0x06);
ptr += 6; ptr += 6;
addr[0] = head[0]; addr[0] = head[0];
addr[1] = head[1]; addr[1] = head[1];
addr[2] = head[2]; addr[2] = head[2];
addr[3] = head[3]; addr[3] = head[3];
data_len = head[4]; data_len = head[4];
data_len = (data_len << 8) + head[5]; data_len = (data_len << 8) + head[5];
#ifdef __DEF_IINCHIP_DBG__ #ifdef __DEF_IINCHIP_DBG__
printf("IP RAW msg arrived\r\n"); printf("IP RAW msg arrived\r\n");
printf("source IP : %d.%d.%d.%d\r\n", addr[0], addr[1], addr[2], addr[3]); printf("source IP : %d.%d.%d.%d\r\n", addr[0], addr[1], addr[2], addr[3]);
#endif #endif
read_data(s, (uint8 *)ptr, buf, data_len); // data copy. read_data(s, (uint8 *)ptr, buf, data_len); // data copy.
ptr += data_len; ptr += data_len;
IINCHIP_WRITE(Sn_RX_RD0(s),(uint8)((ptr & 0xff00) >> 8)); IINCHIP_WRITE(Sn_RX_RD0(s),(uint8)((ptr & 0xff00) >> 8));
IINCHIP_WRITE((Sn_RX_RD0(s) + 1),(uint8)(ptr & 0x00ff)); IINCHIP_WRITE((Sn_RX_RD0(s) + 1),(uint8)(ptr & 0x00ff));
break; break;
case Sn_MR_MACRAW : case Sn_MR_MACRAW :
read_data(s,(uint8*)ptr,head,2); read_data(s,(uint8*)ptr,head,2);
ptr+=2; ptr+=2;
data_len = head[0]; data_len = head[0];
data_len = (data_len<<8) + head[1] - 2; data_len = (data_len<<8) + head[1] - 2;
read_data(s,(uint8*) ptr,buf,data_len); read_data(s,(uint8*) ptr,buf,data_len);
ptr += data_len; ptr += data_len;
IINCHIP_WRITE(Sn_RX_RD0(s),(uint8)((ptr & 0xff00) >> 8)); IINCHIP_WRITE(Sn_RX_RD0(s),(uint8)((ptr & 0xff00) >> 8));
IINCHIP_WRITE((Sn_RX_RD0(s) + 1),(uint8)(ptr & 0x00ff)); IINCHIP_WRITE((Sn_RX_RD0(s) + 1),(uint8)(ptr & 0x00ff));
#ifdef __DEF_IINCHIP_DGB__ #ifdef __DEF_IINCHIP_DGB__
printf("MAC RAW msg arrived\r\n"); printf("MAC RAW msg arrived\r\n");
printf("dest mac=%.2X.%.2X.%.2X.%.2X.%.2X.%.2X\r\n",buf[0],buf[1],buf[2],buf[3],buf[4],buf[5]); printf("dest mac=%.2X.%.2X.%.2X.%.2X.%.2X.%.2X\r\n",buf[0],buf[1],buf[2],buf[3],buf[4],buf[5]);
printf("src mac=%.2X.%.2X.%.2X.%.2X.%.2X.%.2X\r\n",buf[6],buf[7],buf[8],buf[9],buf[10],buf[11]); printf("src mac=%.2X.%.2X.%.2X.%.2X.%.2X.%.2X\r\n",buf[6],buf[7],buf[8],buf[9],buf[10],buf[11]);
printf("type =%.2X%.2X\r\n",buf[12],buf[13]); printf("type =%.2X%.2X\r\n",buf[12],buf[13]);
#endif #endif
break; break;
default : default :
break; break;
} }
IINCHIP_WRITE(Sn_CR(s),Sn_CR_RECV); IINCHIP_WRITE(Sn_CR(s),Sn_CR_RECV);
} }
#ifdef __DEF_IINCHIP_DBG__ #ifdef __DEF_IINCHIP_DBG__
printf("recvfrom() end ..\r\n"); printf("recvfrom() end ..\r\n");
#endif #endif
return data_len; return data_len;
} }
uint16 igmpsend(SOCKET s, const uint8 * buf, uint16 len) uint16 igmpsend(SOCKET s, const uint8 * buf, uint16 len)
{ {
//uint8 status=0; //uint8 status=0;
uint8 isr=0; uint8 isr=0;
uint16 ret=0; uint16 ret=0;
#ifdef __DEF_IINCHIP_DBG__ #ifdef __DEF_IINCHIP_DBG__
printf("igmpsend()\r\n"); printf("igmpsend()\r\n");
#endif #endif
if (len > getIINCHIP_TxMAX(s)) ret = getIINCHIP_TxMAX(s); // check size not to exceed MAX size. if (len > getIINCHIP_TxMAX(s)) ret = getIINCHIP_TxMAX(s); // check size not to exceed MAX size.
else ret = len; else ret = len;
if (ret == 0) if (ret == 0)
{ {
; ;
#ifdef __DEF_IINCHIP_DBG__ #ifdef __DEF_IINCHIP_DBG__
//printf("%d Fail[%d]\r\n",len); //printf("%d Fail[%d]\r\n",len);
#endif #endif
} }
else else
{ {
// copy data // copy data
send_data_processing(s, (uint8 *)buf, ret); send_data_processing(s, (uint8 *)buf, ret);
IINCHIP_WRITE(Sn_CR(s),Sn_CR_SEND); IINCHIP_WRITE(Sn_CR(s),Sn_CR_SEND);
while (IINCHIP_READ(Sn_CR(s))) while (IINCHIP_READ(Sn_CR(s)))
{ {
// status = IINCHIP_READ(Sn_SR(s)); // status = IINCHIP_READ(Sn_SR(s));
#ifndef __DEF_IINCHIP_INT__ #ifndef __DEF_IINCHIP_INT__
isr = IINCHIP_READ(Sn_IR(s)); isr = IINCHIP_READ(Sn_IR(s));
#endif #endif
if ((getISR(s) & Sn_IR_TIMEOUT) || (isr & Sn_IR_TIMEOUT)) if ((getISR(s) & Sn_IR_TIMEOUT) || (isr & Sn_IR_TIMEOUT))
{ {
#ifdef __DEF_IINCHIP_DBG__ #ifdef __DEF_IINCHIP_DBG__
printf("igmpsend fail.\r\n"); printf("igmpsend fail.\r\n");
#endif #endif
putISR(s, getISR(s) & (Sn_IR_RECV | Sn_IR_DISCON | Sn_IR_CON)); putISR(s, getISR(s) & (Sn_IR_RECV | Sn_IR_DISCON | Sn_IR_CON));
IINCHIP_WRITE(Sn_IR(s), (Sn_IR_SEND_OK | Sn_IR_TIMEOUT)); IINCHIP_WRITE(Sn_IR(s), (Sn_IR_SEND_OK | Sn_IR_TIMEOUT));
return 0; return 0;
} }
} }
putISR(s, getISR(s) & (~Sn_IR_SEND_OK)); putISR(s, getISR(s) & (~Sn_IR_SEND_OK));
IINCHIP_WRITE(Sn_IR(s), Sn_IR_SEND_OK); IINCHIP_WRITE(Sn_IR(s), Sn_IR_SEND_OK);
} }
return ret; return ret;
} }

Loading…
Cancel
Save