Exemple #1
0
/**
@brief	This function established	the connection for the channel in Active (client) mode. 
		This function waits for the untill the connection is established.
		
@return	1 for success else 0.
*/ 
uint8 connect(SOCKET s, uint8 * addr, uint16 port)
{
	uint8 ret;
#ifdef __DEF_IINCHIP_DBG__
	printf("connect()\r\n");
#endif

	if 
		(
			((addr[0] == 0xFF) && (addr[1] == 0xFF) && (addr[2] == 0xFF) && (addr[3] == 0xFF)) ||
			((addr[0] == 0x00) && (addr[1] == 0x00) && (addr[2] == 0x00) && (addr[3] == 0x00)) ||
			(port == 0x00) 
		) 
	{
		ret = 0;
#ifdef __DEF_IINCHIP_DBG__
	printf("Fail[invalid ip,port]\r\n");
#endif
	}
	else
	{
		ret = 1;
		// set destination IP
		wiz_write_buf(Sn_DIPR0(s), addr,4);
		wiz_write_word(Sn_DPORT0(s),port);
		wiz_write_byte(Sn_CR(s),Sn_CR_CONNECT);
		/* m2008.01 [bj] :  wait for completion */
		while ( wiz_read_byte(Sn_CR(s)) ) ;
	}

	return ret;
}
Exemple #2
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. */
  )
{
    wiz_write_buf(SIPR0, addr, 4);  
}
Exemple #3
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. */
  )
{
  wiz_write_buf(SHAR0, addr, 6);  
}
Exemple #4
0
/**
@brief  It sets up SubnetMask address
*/
void setSUBR(uint8 * addr)
{   
    wiz_write_buf(SUBR0, addr, 4);
}
Exemple #5
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. */
  )
{
    wiz_write_buf(GAR0, addr, 4);
}
Exemple #6
0
/**
@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.
		
@return	This function return send data size for success else -1.
*/ 
uint16 sendto(
	SOCKET s,		/**< socket index */
	const uint8 * buf,	/**< a pointer to the data */
	uint16 len,			/**< the data size to send */
	uint8 * addr,		/**< the peer's Destination IP address */
	uint16 port		/**< the peer's destination port number */
	)
{
	uint16 ret=0;
	
	if (len > IINCHIP_TxMAX) ret = IINCHIP_TxMAX; // check size not to exceed MAX size.
	else ret = len;

	if
		(
			((addr[0] == 0x00) && (addr[1] == 0x00) && (addr[2] == 0x00) && (addr[3] == 0x00)) ||
			((port == 0x00)) ||(ret == 0)
		) 
	{
		/* +2008.01 [bj] : added return value */
		ret = 0;
	}
	else
	{
		wiz_write_buf(Sn_DIPR0(s),addr,4);
		wiz_write_word(Sn_DPORT0(s),port);
		send_data_processing(s, (uint8 *)buf, ret);
		
/* +2008.01 bj */ 
#ifdef __DEF_IINCHIP_INT__
		while ( (getISR(s) & Sn_IR_SEND_OK) != Sn_IR_SEND_OK ) 
#else
		while ( (wiz_read_byte(Sn_IR(s)) & Sn_IR_SEND_OK) != Sn_IR_SEND_OK ) 
#endif
		{
#ifdef __DEF_IINCHIP_INT__
			if (getISR(s) & Sn_IR_TIMEOUT)
#else
			if (wiz_read_byte(Sn_IR(s)) & Sn_IR_TIMEOUT)
#endif
			{
#ifdef __DEF_IINCHIP_DBG__
				printf("send fail.\r\n");
#endif
/* +2008.01 [bj]: clear interrupt */
#ifdef __DEF_IINCHIP_INT__
				putISR(s, getISR(s) & ~(Sn_IR_SEND_OK | Sn_IR_TIMEOUT));	 /* clear SEND_OK & TIMEOUT */
#else
				wiz_write_byte(Sn_IR(s), (Sn_IR_SEND_OK | Sn_IR_TIMEOUT)); /* clear SEND_OK & TIMEOUT */
#endif
			return 0;
			}
		}

/* +2008.01 bj */ 
#ifdef __DEF_IINCHIP_INT__
		putISR(s, getISR(s) & (~Sn_IR_SEND_OK));
#else
		wiz_write_byte(Sn_IR(s), Sn_IR_SEND_OK);
#endif

	}
	return ret;
}