Ejemplo n.º 1
0
uint8_t process_request(TCP_CONFIG *config)
{
	uint16_t bytes_to_send =0;
	uint8_t rets=0;

	if(bytesReceived>tcp_data_buffer_size)
		return 0; // Content overflow

	// Assuming GIT request, read and parse if you with to use urls for anything
	recv_data_processing(config->s, tcp_data_buffer, bytesReceived); // Data from the GIT request
	sprintf(website,"HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n\
			<html>\n<head>\n<center><h1>%d</h1></center>\n<meta http-equiv=\"refresh\" content=\"1.5\" >",ADCRead(0));

	bytes_to_send = strlen((char *)website);
	rets = send(config->s, website,bytes_to_send , 0); // Send Response with html
	bytesReceived=0;

	IINCHIP_WRITE(Sn_CR(config->s), Sn_CR_DISCON); 	// Shut down connection
	while (IINCHIP_READ(Sn_CR(config->s)));			//
	IINCHIP_WRITE(Sn_CR(config->s), Sn_CR_CLOSE);	//
	while (IINCHIP_READ(Sn_CR(config->s)));			//
	IINCHIP_WRITE(Sn_IR(config->s), 0xFF);			//

	return 1;
}
Ejemplo n.º 2
0
/*
@brief  This function sets up Source IP address.
@param addr a pointer to a 4 -byte array responsible to set the Source IP address.
*/
void setSIPR(uint8 *addr)
{
  IINCHIP_WRITE((WIZC_SIPR0),addr[0]);
  IINCHIP_WRITE((WIZC_SIPR1),addr[1]);
  IINCHIP_WRITE((WIZC_SIPR2),addr[2]);
  IINCHIP_WRITE((WIZC_SIPR3),addr[3]);
}
Ejemplo n.º 3
0
/*
@brief  It sets up SubnetMask address
@param addr a pointer to a 4 -byte array responsible to set the SubnetMask address
*/ 
void setSUBR(uint8 *addr)
{
  IINCHIP_WRITE((WIZC_SUBR0),addr[0]);
  IINCHIP_WRITE((WIZC_SUBR1),addr[1]);
  IINCHIP_WRITE((WIZC_SUBR2),addr[2]);
  IINCHIP_WRITE((WIZC_SUBR3),addr[3]);
}
Ejemplo n.º 4
0
int8 dhcp_init(uint8 sock, pFunc ip_update_hook, pFunc ip_conflict_hook, wiz_NetInfo *def)
{
	if(sock >= TOTAL_SOCK_NUM) {
		ERRA("wrong socket number(%d)", sock);
		return RET_NOK;
	}

#ifdef DHCP_ALARM
		dhcp_alarm = TRUE;
#endif
#ifdef DHCP_ASYNC
		dhcp_async = TRUE;
#endif

	memset(&di, 0, sizeof(di));
	memcpy(&storage, def, sizeof(storage));
	memset(&workinfo, 0, sizeof(workinfo));
	memcpy(workinfo.Mac, storage.Mac, 6);
	SetNetInfo(&workinfo);
	di.xid = 0x12345678;
	di.sock = sock;
	if(ip_update_hook) di.ip_update = ip_update_hook;
	if(ip_conflict_hook) di.ip_conflict = ip_conflict_hook;
	IINCHIP_WRITE(WIZC_SIPR0, 0);
	IINCHIP_WRITE(WIZC_SIPR1, 0);
	IINCHIP_WRITE(WIZC_SIPR2, 0);
	IINCHIP_WRITE(WIZC_SIPR3, 0);

	return RET_OK;
}
Ejemplo n.º 5
0
/*
@brief  This function sets up gateway IP address.
@param addr a pointer to a 4 -byte array responsible to set the GW address.
*/ 
void setGAR(uint8 *addr)
{
  IINCHIP_WRITE((WIZC_GAR0),addr[0]);
  IINCHIP_WRITE((WIZC_GAR1),addr[1]);
  IINCHIP_WRITE((WIZC_GAR2),addr[2]);
  IINCHIP_WRITE((WIZC_GAR3),addr[3]);
}
Ejemplo n.º 6
0
// return values:
// 1 on success
// 0 otherwise
int EthernetDNSClass::_startDNSSession()
{
   (void)this->_closeDNSSession();
   
   int i;
   for (i = NUM_SOCKETS-1; i>=0; i--)
      if (SOCK_CLOSED == IINCHIP_READ(Sn_SR(i))) {
         if (socket(i, Sn_MR_UDP, DNS_CLIENT_PORT, 0) > 0) {
            this->_socket = i;
            break;
         }
      }

   if (this->_socket < 0)
      return 0;
	
	uint16 port = DNS_SERVER_PORT;

   for (i=0; i<4; i++)
      IINCHIP_WRITE((Sn_DIPR0(this->_socket) + i), this->_dnsData.serverIpAddr[i]);

   IINCHIP_WRITE(Sn_DPORT0(this->_socket), (uint8)((port & 0xff00) >> 8));
   IINCHIP_WRITE((Sn_DPORT0(this->_socket) + 1), (uint8)(port & 0x00ff));
   
   return 1;
}
Ejemplo n.º 7
0
/**
@brief	This function sets up Source IP address.
*/
void setSIPR(
	uint8 * addr	/**< a pointer to a 4 -byte array responsible to set the Source IP address. */
	)
{
	IINCHIP_WRITE((SIPR + 0),addr[0]);
	IINCHIP_WRITE((SIPR + 1),addr[1]);
	IINCHIP_WRITE((SIPR + 2),addr[2]);
	IINCHIP_WRITE((SIPR + 3),addr[3]);
}
Ejemplo n.º 8
0
/**
@brief	It sets up SubnetMask address
*/ 
void setSUBR(
	uint8 * addr	/**< a pointer to a 4 -byte array responsible to set the SubnetMask address */
	)
{
	IINCHIP_WRITE((SUBR + 0),addr[0]);
	IINCHIP_WRITE((SUBR + 1),addr[1]);
	IINCHIP_WRITE((SUBR + 2),addr[2]);
	IINCHIP_WRITE((SUBR + 3),addr[3]);
}
Ejemplo n.º 9
0
/**
@brief	This function sets up gateway IP address.
*/ 
void setGAR(
	uint8 * addr	/**< a pointer to a 4 -byte array responsible to set the Gateway IP address. */
	)
{
	IINCHIP_WRITE((GAR + 0),addr[0]);
	IINCHIP_WRITE((GAR + 1),addr[1]);
	IINCHIP_WRITE((GAR + 2),addr[2]);
	IINCHIP_WRITE((GAR + 3),addr[3]);
}
Ejemplo n.º 10
0
/**
@brief	This Socket function open TCP server socket.
@return 	1 - success, 0 - fail.
*/
int8 TCPServerOpen(SOCKET s, uint16 port)
{
    uint8 ret;
#ifdef __DEF_IINCHIP_DBG__
    printf("TCPServerOpen()\r\n");
#endif

    TCPClose(s);
    IINCHIP_WRITE(Sn_MR(s),Sn_MR_TCP);
    if (port != 0) {
        IINCHIP_WRITE(Sn_PORT0(s),(uint8)((port & 0xff00) >> 8));
        IINCHIP_WRITE((Sn_PORT0(s) + 1),(uint8)(port & 0x00ff));
    } else {
Ejemplo n.º 11
0
/**
@brief	This Socket function initialize the channel in perticular mode, and set the port and wait for W5200 done it.
@return 	1 for sucess else 0.
*/  
uint8 socket(SOCKET s, uint8 protocol, uint16 port, uint8 flag)
{
	uint8 ret;
#ifdef __DEF_IINCHIP_DBG__
	printf("socket()\r\n");
#endif
	if ((protocol == Sn_MR_TCP) || (protocol == Sn_MR_UDP) || (protocol == Sn_MR_IPRAW) || (protocol == Sn_MR_MACRAW) || (protocol == Sn_MR_PPPOE))
	{
		close(s);
		IINCHIP_WRITE(Sn_MR(s),protocol | flag);
		if (port != 0) {
			IINCHIP_WRITE(Sn_PORT0(s),(uint8)((port & 0xff00) >> 8));
			IINCHIP_WRITE((Sn_PORT0(s) + 1),(uint8)(port & 0x00ff));
		} else {
Ejemplo n.º 12
0
uint8_t tcp_socket_init(TCP_CONFIG *config)
{

	static bool startup=false;
	if(!startup)
	{
		GPIO_Configuration();
		Reset_W5200();
		WIZ_SPI_Init();
		Set_network(config->Source_IP, config->Gateway, config->MAC, config->Subnet);
		startup=true;
		while (getSn_SR(config->s) != SOCK_CLOSED);
	}

	if(socket(config->s,Sn_MR_TCP,config->Source_Port,0x00)== 0)    /* reinitialize the socket */
	{
		return 0; //TCP socket failed
	}

	while (getSn_SR(config->s) != SOCK_INIT); // Wait for socket to open

	IINCHIP_WRITE(Sn_CR(config->s), Sn_CR_LISTEN); // Start listening on port specified
	while (IINCHIP_READ(Sn_CR(config->s))); // Check status
	while (getSn_SR(config->s) != SOCK_LISTEN); // Wait for listen
	return 1;
}
Ejemplo n.º 13
0
/**
@brief   This Socket function initialize the channel in perticular mode, and set the port and wait for W5200 done it.
@return  1 for sucess else 0.
*/
uint8 socket(SOCKET s, uint8 protocol, uint16 port, uint8 flag)
{
   uint8 ret;
   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)
      )
   {
      close(s);
      IINCHIP_WRITE(Sn_MR(s) ,protocol | flag);
      if (port != 0) {
         IINCHIP_WRITE( Sn_PORT0(s) ,(uint8)((port & 0xff00) >> 8));
         IINCHIP_WRITE( Sn_PORT1(s) ,(uint8)(port & 0x00ff));
      } else {
Ejemplo n.º 14
0
/**
@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.
*/
uint8 socket(
    SOCKET s, 		/**< for socket number */
    uint8 protocol, 	/**< for socket protocol */
    uint16 port, 		/**< the source port for the socket */
    uint8 flag		/**< the option for the socket */
)
{
    uint8 ret;
#ifdef __DEF_IINCHIP_DBG__
    printf("socket()\r\n");
#endif
    if ((protocol == Sn_MR_TCP) || (protocol == Sn_MR_UDP) || (protocol == Sn_MR_IPRAW) || (protocol == Sn_MR_MACRAW) || (protocol == Sn_MR_PPPOE))
    {
        close(s);
        IINCHIP_WRITE(Sn_MR(s),protocol | flag);
        if (port != 0)
        {
            IINCHIP_WRITE(Sn_PORT0(s),(uint8)((port & 0xff00) >> 8));
            IINCHIP_WRITE((Sn_PORT0(s) + 1),(uint8)(port & 0x00ff));
        }
Ejemplo n.º 15
0
/*
@brief  This function sets up MAC address.
@param addr a pointer to a 6 -byte array responsible to set the MAC address. 
*/ 
void setSHAR(uint8 *addr)
{
  IINCHIP_WRITE((WIZC_SHAR0),addr[0]);
  IINCHIP_WRITE((WIZC_SHAR1),addr[1]);
  IINCHIP_WRITE((WIZC_SHAR2),addr[2]);
  IINCHIP_WRITE((WIZC_SHAR3),addr[3]);
  IINCHIP_WRITE((WIZC_SHAR4),addr[4]);
  IINCHIP_WRITE((WIZC_SHAR5),addr[5]);
}
Ejemplo n.º 16
0
/**
@brief	This function sets up MAC address.
*/ 
void setSHAR(
	uint8 * addr	/**< a pointer to a 6 -byte array responsible to set the MAC address. */
	)
{
	IINCHIP_WRITE((SHAR + 0),addr[0]);
	IINCHIP_WRITE((SHAR + 1),addr[1]);
	IINCHIP_WRITE((SHAR + 2),addr[2]);
	IINCHIP_WRITE((SHAR + 3),addr[3]);
	IINCHIP_WRITE((SHAR + 4),addr[4]);
	IINCHIP_WRITE((SHAR + 5),addr[5]);
}
Ejemplo n.º 17
0
void     setSn_IMR(SOCKET s, uint8 mask)
{
   IINCHIP_WRITE(Sn_IMR(s),mask);
}
Ejemplo n.º 18
0
/**
@brief  This function set the transmit & receive buffer size as per the channels
*/
void wizMemInit( uint8 * tx_size, uint8 * rx_size  )
{
    int16 i;
    int16 ssum,rsum;

#ifdef __DEF_IINCHIP_DBG__
    printf("sysinit()\r\n");
#endif

    ssum = 0;
    rsum = 0;

    SBUFBASEADDRESS[0] = (uint16)(__DEF_IINCHIP_MAP_TXBUF__);   /* Set base address of Tx memory for channel #0 */
    RBUFBASEADDRESS[0] = (uint16)(__DEF_IINCHIP_MAP_RXBUF__);   /* Set base address of Rx memory for channel #0 */

    for (i = 0 ; i < MAX_SOCK_NUM; i++)	// Set the size, masking and base address of Tx & Rx memory by each channel
    {
        IINCHIP_WRITE((Sn_TXMEM_SIZE(i)),tx_size[i]);
        IINCHIP_WRITE((Sn_RXMEM_SIZE(i)),rx_size[i]);

#ifdef __DEF_IINCHIP_DBG__
        printf("Sn_TXMEM_SIZE = %d\r\n",IINCHIP_READ(Sn_TXMEM_SIZE(i)));
        printf("Sn_RXMEM_SIZE = %d\r\n",IINCHIP_READ(Sn_RXMEM_SIZE(i)));
#endif

        SSIZE[i] = (int16)(0);
        RSIZE[i] = (int16)(0);

        if (ssum <= 16384)
        {
            switch( tx_size[i] )
            {
            case 1:
                SSIZE[i] = (int16)(1024);
                SMASK[i] = (uint16)(0x03FF);
                break;
            case 2:
                SSIZE[i] = (int16)(2048);
                SMASK[i] = (uint16)(0x07FF);
                break;
            case 4:
                SSIZE[i] = (int16)(4096);
                SMASK[i] = (uint16)(0x0FFF);
                break;
            case 8:
                SSIZE[i] = (int16)(8192);
                SMASK[i] = (uint16)(0x1FFF);
                break;
            case 16:
                SSIZE[i] = (int16)(16384);
                SMASK[i] = (uint16)(0x3FFF);
                break;
            }
        }

        if (rsum <= 16384)
        {
            switch( rx_size[i] )
            {
            case 1:
                RSIZE[i] = (int16)(1024);
                RMASK[i] = (uint16)(0x03FF);
                break;
            case 2:
                RSIZE[i] = (int16)(2048);
                RMASK[i] = (uint16)(0x07FF);
                break;
            case 4:
                RSIZE[i] = (int16)(4096);
                RMASK[i] = (uint16)(0x0FFF);
                break;
            case 8:
                RSIZE[i] = (int16)(8192);
                RMASK[i] = (uint16)(0x1FFF);
                break;
            case 16:
                RSIZE[i] = (int16)(16384);
                RMASK[i] = (uint16)(0x3FFF);
                break;
            }
        }
        ssum += SSIZE[i];
        rsum += RSIZE[i];

        if (i != 0)			// Sets 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];
        }
#ifdef __DEF_IINCHIP_DBG__
        printf("ch = %d\r\n",i);
        printf("SBUFBASEADDRESS = %d\r\n",(uint16)SBUFBASEADDRESS[i]);
        printf("RBUFBASEADDRESS = %d\r\n",(uint16)RBUFBASEADDRESS[i]);
        printf("SSIZE = %d\r\n",SSIZE[i]);
        printf("RSIZE = %d\r\n",RSIZE[i]);
#endif
    }
}
Ejemplo n.º 19
0
void setMR(uint8 val)
{
  IINCHIP_WRITE(MR,val);
}
Ejemplo n.º 20
0
void     setPn_BDPTHR(uint8 p, uint16 depth)
{
   IINCHIP_WRITE(Pn_BDPTHR(p),depth);
}
Ejemplo n.º 21
0
/**
@brief  This function set the transmit & receive buffer size as per the channels is used
Note for TMSR and RMSR bits are as follows\n
bit 1-0 : memory size of channel #0 \n
bit 3-2 : memory size of channel #1 \n
bit 5-4 : memory size of channel #2 \n
bit 7-6 : memory size of channel #3 \n
bit 9-8 : memory size of channel #4 \n
bit 11-10 : memory size of channel #5 \n
bit 12-12 : memory size of channel #6 \n
bit 15-14 : memory size of channel #7 \n
Maximum memory size for Tx, Rx in the W5500 is 16K Bytes,\n
In the range of 16KBytes, the memory size could be allocated dynamically by each channel.\n
Be attentive to sum of memory size shouldn't exceed 8Kbytes\n
and to data transmission and receiption from non-allocated channel may cause some problems.\n
If the 16KBytes memory is already  assigned to centain channel, \n
other 3 channels couldn't be used, for there's no available memory.\n
If two 4KBytes memory are assigned to two each channels, \n
other 2 channels couldn't be used, for there's no available memory.\n
*/
void sysinit( uint8 * tx_size, uint8 * rx_size  )
{
  int16 i;
  int16 ssum,rsum;
#ifdef __DEF_IINCHIP_DBG__
  printf("sysinit()\r\n");
#endif
  ssum = 0;
  rsum = 0;

  for (i = 0 ; i < MAX_SOCK_NUM; i++)       // Set the size, masking and base address of Tx & Rx memory by each channel
  {
          IINCHIP_WRITE( (Sn_TXMEM_SIZE(i)), tx_size[i]);
          IINCHIP_WRITE( (Sn_RXMEM_SIZE(i)), rx_size[i]);
          
#ifdef __DEF_IINCHIP_DBG__
         printf("tx_size[%d]: %d, Sn_TXMEM_SIZE = %d\r\n",i, tx_size[i], IINCHIP_READ(Sn_TXMEM_SIZE(i)));
         printf("rx_size[%d]: %d, Sn_RXMEM_SIZE = %d\r\n",i, rx_size[i], IINCHIP_READ(Sn_RXMEM_SIZE(i)));
#endif
    SSIZE[i] = (int16)(0);
    RSIZE[i] = (int16)(0);


    if (ssum <= 16384)
    {
         switch( tx_size[i] )
      {
      case 1:
        SSIZE[i] = (int16)(1024);
        break;
      case 2:
        SSIZE[i] = (int16)(2048);
        break;
      case 4:
        SSIZE[i] = (int16)(4096);
        break;
      case 8:
        SSIZE[i] = (int16)(8192);
        break;
      case 16:
        SSIZE[i] = (int16)(16384);
      break;
      default :
        RSIZE[i] = (int16)(2048);
        break;
      }
    }

   if (rsum <= 16384)
    {
         switch( rx_size[i] )
      {
      case 1:
        RSIZE[i] = (int16)(1024);
        break;
      case 2:
        RSIZE[i] = (int16)(2048);
        break;
      case 4:
        RSIZE[i] = (int16)(4096);
        break;
      case 8:
        RSIZE[i] = (int16)(8192);
        break;
      case 16:
        RSIZE[i] = (int16)(16384);
        break;
      default :
        RSIZE[i] = (int16)(2048);
        break;
      }
    }
    ssum += SSIZE[i];
    rsum += RSIZE[i];

  }
}
Ejemplo n.º 22
0
Archivo: w5300.c Proyecto: lqu/W5300E01
void     setIR(uint16 val)
{
   IINCHIP_WRITE(IR, val);   
}
Ejemplo n.º 23
0
Archivo: w5300.c Proyecto: lqu/W5300E01
void     setIMR(uint16 mask)
{
   IINCHIP_WRITE(IMR, mask);
}
Ejemplo n.º 24
0
void     setSn_MSSR(SOCKET s, uint16 mss)
{
   IINCHIP_WRITE(Sn_MSSR(s),mss);
}
Ejemplo n.º 25
0
void     setSn_KPALVTR(SOCKET s, uint8 time)
{
   uint16 keepalive=0;
   keepalive = (IINCHIP_READ(Sn_KPALVTR(s)) & 0x00FF) + ((uint16)time<<8);
   IINCHIP_WRITE(Sn_KPALVTR(s),keepalive);
}
Ejemplo n.º 26
0
void     setSn_DIPR(SOCKET s, uint8* addr)
{
   IINCHIP_WRITE(Sn_DIPR(s),  ((uint16)(addr[0]<<8)) + addr[1]);
   IINCHIP_WRITE(Sn_DIPR2(s), ((uint16)(addr[2]<<8)) + addr[3]);  
}
Ejemplo n.º 27
0
void     setSn_DPORTR(SOCKET s, uint16 port)
{
   IINCHIP_WRITE(Sn_DPORTR(s),port);
}
Ejemplo n.º 28
0
void     setSn_IR(SOCKET s, uint8 ir)
{
      IINCHIP_WRITE(Sn_IR(s),ir);
}
Ejemplo n.º 29
0
void     setSn_MR(SOCKET s, uint16 mode)
{
   IINCHIP_WRITE(Sn_MR(s),mode);
}
Ejemplo n.º 30
0
void     setSn_CR(SOCKET s, uint16 com)
{
   IINCHIP_WRITE(Sn_CR(s),com);
   while(IINCHIP_READ(Sn_CR(s))); // wait until Sn_CR is cleared.
}