Exemple #1
0
/******************************************************************************
* Function Name: phy_set_autonegotiate
* Description  : Starts autonegotiate and reports the other side's 
*              : physical capability
* Arguments    : none
* Return Value : bit 8 - Full duplex 100 mbps
*              : bit 7 - Half duplex 100 mbps
*              : bit 6 - Full duplex 10 mbps
*              : bit 5 - Half duplex 10 mbps
*              : bit 4:0 - Always set to 00001 (IEEE 802.3)
*              : -1 if error
******************************************************************************/
int16_t phy_set_autonegotiate( void )
{
  uint16_t reg;
  uint32_t count;

  _phy_write(AN_ADVERTISEMENT_REG, 0x01E1);
  _phy_write(BASIC_MODE_CONTROL_REG, 0x1200);
  
  count = 0;

  do
  {
      reg = _phy_read(BASIC_MODE_STATUS_REG);
      count++;
  } while (!(reg & 0x0020) && count < PHY_AUTO_NEGOTIATON_WAIT);

  if (count >= PHY_AUTO_NEGOTIATON_WAIT)
  {
      return R_PHY_ERROR;
  }
  else
  {
      return ((int16_t)_phy_read(AN_LINK_PARTNER_ABILITY_REG));
  }
}
Exemple #2
0
/******************************************************************************
* Function Name: phy_set_autonegotiate
* Description  : Starts autonegotiate and reports the other side's 
*              : physical capability
* Arguments    : none
* Return Value : bit 8 - Full duplex 100 mbps
*              : bit 7 - Half duplex 100 mbps
*              : bit 6 - Full duplex 10 mbps
*              : bit 5 - Half duplex 10 mbps
*              : bit 4:0 - Always set to 00001 (IEEE 802.3)
*              : -1 if error
******************************************************************************/
int16_t phy_set_autonegotiate( void )
{
  uint16_t reg;
  uint32_t count;

  _phy_write(AN_ADVERTISEMENT_REG, 0x01E1);
  _phy_write(BASIC_MODE_CONTROL_REG, 0x1200);
  
  count = 0;

  do
  {
      reg = _phy_read(BASIC_MODE_STATUS_REG);
      count++;
	  vTaskDelay( 100 / portTICK_PERIOD_MS );
	  
	  /* Make sure we don't break out if reg just contains 0xffff. */
	  if( reg == 0xffff )
	  {
		reg = 0;
	  }
	  
  } while (!(reg & 0x0020) && (count < PHY_AUTO_NEGOTIATON_WAIT));

  if (count >= PHY_AUTO_NEGOTIATON_WAIT)
  {
      return R_PHY_ERROR;
  }
  else
  {
	  /* National DP83640 fix */
	  _phy_write(0x13, 0x0006);
	  reg = _phy_read(0x14);
	  _phy_write(0x14, (reg&0x7FFF)); 
      _phy_write(0x13, 0x0000);
	  
      /* Get the link partner response */
	  reg = (int16_t)_phy_read(AN_LINK_PARTNER_ABILITY_REG);
	  
	  if (reg & ( 1 << 8 ) )
	  {
		  return PHY_LINK_100F;
	  }
	  if (reg & ( 1 << 7 ) )
	  {
	  	  return PHY_LINK_100H;
	  }
	  if (reg & ( 1 << 6 ) )
	  {
		  return PHY_LINK_10F;
	  }
	  if (reg & 1 << 5 )
	  {
		  return PHY_LINK_10H;
	  }	  

	  return (-1);
  }
}
Exemple #3
0
/******************************************************************************
* Function Name: phy_set_autonegotiate
* Description  : Starts autonegotiate and reports the other side's 
*              : physical capability
* Arguments    : none
* Return Value : bit 8 - Full duplex 100 mbps
*              : bit 7 - Half duplex 100 mbps
*              : bit 6 - Full duplex 10 mbps
*              : bit 5 - Half duplex 10 mbps
*              : bit 4:0 - Always set to 00001 (IEEE 802.3)
*              : -1 if error
******************************************************************************/
short phy_set_autonegotiate( void )
{
  unsigned short reg;
  unsigned long count;

  _phy_write(AN_ADVERTISEMENT_REG, 0x01E1);
  _phy_write(BASIC_MODE_CONTROL_REG, 0x1200);
  
  count = 0;

  do
  {
      reg = _phy_read(BASIC_MODE_STATUS_REG);
      count++;
	  vTaskDelay( 100 / portTICK_RATE_MS );
	  
	  /* Make sure we don't break out if reg just contains 0xffff. */
	  if( reg == 0xffff )
	  {
		reg = 0;
	  }
	  
  } while (!(reg & 0x0020) && (count < PHY_AUTO_NEGOTIATON_WAIT));

  if (count >= PHY_AUTO_NEGOTIATON_WAIT)
  {
      return R_PHY_ERROR;
  }
  else
  {
      /* Get the link partner response */
	  reg = (short)_phy_read(AN_LINK_PARTNER_ABILITY_REG);
	  
	  if (reg & ( 1 << 8 ) )
	  {
		  return PHY_LINK_100F;
	  }
	  if (reg & ( 1 << 7 ) )
	  {
	  	  return PHY_LINK_100H;
	  }
	  if (reg & ( 1 << 6 ) )
	  {
		  return PHY_LINK_10F;
	  }
	  if (reg & 1 << 5 )
	  {
		  return PHY_LINK_10H;
	  }	  

	  return (-1);
  }
}
Exemple #4
0
/******************************************************************************
* Function Name: phy_init
* Description  : Resets Ethernet PHY device
* Arguments    : none
* Return Value : none
******************************************************************************/
int16_t  phy_init( void )
{
  uint16_t reg;
  uint32_t count;

  /* Reset PHY */
  _phy_write(BASIC_MODE_CONTROL_REG, 0x8000);

  count = 0;

  do
  {
      reg = _phy_read(BASIC_MODE_CONTROL_REG);
	  count++;
  } while (reg & 0x8000 && count < PHY_RESET_WAIT);

  if (count >= PHY_RESET_WAIT)
  {
      return R_PHY_ERROR;
  }
  else
  {
      return R_PHY_OK;
  }
}
Exemple #5
0
/******************************************************************************
* Function Name: phy_init
* Description  : Resets Ethernet PHY device
* Arguments    : none
* Return Value : none
******************************************************************************/
int16_t  phy_init( void )
{
  uint16_t reg;
  uint32_t count;

  /* Reset PHY */
  _phy_write(BASIC_MODE_CONTROL_REG, 0x8000);

  count = 0;

  do
  {
	  vTaskDelay( 2 / portTICK_RATE_MS );
      reg = _phy_read(BASIC_MODE_CONTROL_REG);
	  count++;
  } while (reg & 0x8000 && count < PHY_RESET_WAIT);

  if( count < PHY_RESET_WAIT )
  {	
   	return R_PHY_OK;
  }

  return R_PHY_ERROR;
}
Exemple #6
0
/******************************************************************************
* Function Name: phy_init
* Description  : Resets Ethernet PHY device
* Arguments    : none
* Return Value : none
******************************************************************************/
short  phy_init( void )
{
  unsigned short reg;
  unsigned long count;

  /* Reset PHY */
  _phy_write(BASIC_MODE_CONTROL_REG, 0x8000);

  count = 0;

  do
  {
	  vTaskDelay( 2 / portTICK_PERIOD_MS );
      reg = _phy_read(BASIC_MODE_CONTROL_REG);
	  count++;
  } while (reg & 0x8000 && count < PHY_RESET_WAIT);

  if( count < PHY_RESET_WAIT )
  {	  
   	return R_PHY_OK;
  }
  
  return R_PHY_ERROR;
}
Exemple #7
0
/******************************************************************************
* Function Name: phy_set_10half
* Description  : Sets Ethernet PHY device to 10 Mbps half duplexR
* Arguments    : none
* Return Value : none
******************************************************************************/
void phy_set_10half( void )
{
	_phy_write(BASIC_MODE_CONTROL_REG, 0x0000);
}
Exemple #8
0
/******************************************************************************
* Function Name: phy_set_100full
* Description  : Set Ethernet PHY device to 100 Mbps full duplex
* Arguments    : none
* Return Value : none
******************************************************************************/
void phy_set_100full( void )
{
	_phy_write(BASIC_MODE_CONTROL_REG, 0x2100);
}