Ejemplo n.º 1
0
static void k64f_phy_task(void *data) {
  struct netif *netif = (struct netif*)data;
  bool connection_status;
  enet_dev_if_t * enetIfPtr = (enet_dev_if_t*)&enetDevIf[BOARD_DEBUG_ENET_INSTANCE];
  PHY_STATE crt_state = {STATE_UNKNOWN, (enet_phy_speed_t)STATE_UNKNOWN, (enet_phy_duplex_t)STATE_UNKNOWN};
  PHY_STATE prev_state;

  prev_state = crt_state;
  while (true) {
    // Get current status
    phy_get_link_status(enetIfPtr, &connection_status);
    crt_state.connected = connection_status ? 1 : 0;
    phy_get_link_speed(enetIfPtr, &crt_state.speed);
    phy_get_link_duplex(enetIfPtr, &crt_state.duplex);

    // Compare with previous state
    if (crt_state.connected != prev_state.connected) {
      if (crt_state.connected)
        tcpip_callback_with_block((tcpip_callback_fn)netif_set_link_up, (void*) netif, 1);
      else
        tcpip_callback_with_block((tcpip_callback_fn)netif_set_link_down, (void*) netif, 1);
    }

    if (crt_state.speed != prev_state.speed)
      BW_ENET_RCR_RMII_10T(enetIfPtr->deviceNumber, crt_state.speed == kEnetSpeed10M ? kEnetCfgSpeed10M : kEnetCfgSpeed100M);

    // TODO: duplex change requires disable/enable of Ethernet interface, to be implemented

    prev_state = crt_state;
    osDelay(PHY_TASK_PERIOD_MS);
  }
}
Ejemplo n.º 2
0
static void k64f_phy_task(void *data) {
  struct netif *netif = (struct netif*)data;
  bool connection_status;
  enet_dev_if_t * enetIfPtr = (enet_dev_if_t*)&enetDevIf[BOARD_DEBUG_ENET_INSTANCE];
  PHY_STATE crt_state = {STATE_UNKNOWN, (enet_phy_speed_t)STATE_UNKNOWN, (enet_phy_duplex_t)STATE_UNKNOWN};
  PHY_STATE prev_state;

  prev_state = crt_state;

  // TODO: this can't be an infinite loop anymore. Events, people. Give me events. WHERE ARE MY EVENTS ?!
  // TODO: maybe this should also be called from the Ethernet interrupt handler ? (probably not thouogh, since the interrupt
  //       handler doesn't seem to have a PHY-related source (but check this!))
  // TODO: +--> what actually happens is that the requests to read/write PHY registers via the MII interface should be
  //       asynchronous (and their completion can generate an interrupt), so completely ignore this for now and assume
  //       that the Ethernet cable is always connected and the link speed never changes. Yuck.

  while (true) {
    // Get current status
    phy_get_link_status(enetIfPtr, &connection_status);
    crt_state.connected = connection_status ? 1 : 0;
    phy_get_link_speed(enetIfPtr, &crt_state.speed);
    phy_get_link_duplex(enetIfPtr, &crt_state.duplex);

    // Compare with previous state
    if (crt_state.connected != prev_state.connected) {
      if (crt_state.connected)
        tcpip_callback_with_block((tcpip_callback_fn)netif_set_link_up, (void*) netif, 1);
      else
        tcpip_callback_with_block((tcpip_callback_fn)netif_set_link_down, (void*) netif, 1);
    }

    if (crt_state.speed != prev_state.speed)
      BW_ENET_RCR_RMII_10T(enetIfPtr->deviceNumber, crt_state.speed == kEnetSpeed10M ? kEnetCfgSpeed10M : kEnetCfgSpeed100M);

    // TODO: duplex change requires disable/enable of Ethernet interface, to be implemented

    prev_state = crt_state;
    osDelay(PHY_TASK_PERIOD_MS);
  }
}
Ejemplo n.º 3
0
/** \brief  Low level init of the MAC and PHY.
 *
 *  \param[in]      netif  Pointer to LWIP netif structure
 */
NyLPC_TBool low_level_init(const unsigned char* i_ethaddr,int i_addr_len)
{
    enet_dev_if_t * enetIfPtr;
    uint32_t device = BOARD_DEBUG_ENET_INSTANCE;
    enet_rxbd_config_t rxbdCfg;
    enet_txbd_config_t txbdCfg;
    enet_phy_speed_t phy_speed;
    enet_phy_duplex_t phy_duplex;
    
    //RX/TXメモリはデバイス選択時に確保
    k64f_init_eth_hardware();
  
    /* Initialize device*/
    enetIfPtr = (enet_dev_if_t *)&enetDevIf[device];
    enetIfPtr->deviceNumber = device;
    enetIfPtr->macCfgPtr = &g_enetMacCfg[device];
    enetIfPtr->phyCfgPtr = &g_enetPhyCfg[device];
    enetIfPtr->macApiPtr = &g_enetMacApi;
    enetIfPtr->phyApiPtr = (void *)&g_enetPhyApi;
    //macアドレスのコピー
    memcpy(enetIfPtr->macCfgPtr->macAddr,(char*)i_ethaddr,i_addr_len);
	//enetIfPtr->macContextPtrはgetInterface
	if(ENET_MAC_CONTEXT_BUF!=NULL){
		free(ENET_MAC_CONTEXT_BUF);
		ENET_MAC_CONTEXT_BUF=NULL;
	}
	ENET_MAC_CONTEXT_BUF=calloc(1, sizeof(enet_mac_context_t));
	if(ENET_MAC_CONTEXT_BUF==NULL){
		return NyLPC_TBool_FALSE;//ERR_BUF;
	}
	enetIfPtr->macContextPtr = (enet_mac_context_t *)ENET_MAC_CONTEXT_BUF;

	/* Initialize enet buffers*/
	if(!k64f_rx_setup(&rxbdCfg)) {
		return NyLPC_TBool_FALSE;//ERR_BUF;
	}
	/* Initialize enet buffers*/
	if(!k64f_tx_setup(&txbdCfg)) {
		return NyLPC_TBool_FALSE;//ERR_BUF;
	}
	/* Initialize enet module*/
	if (enet_mac_init(enetIfPtr, &rxbdCfg, &txbdCfg) == kStatus_ENET_Success)
	{
		/* Initialize PHY*/
		if (enetIfPtr->macCfgPtr->isPhyAutoDiscover) {
			if (((enet_phy_api_t *)(enetIfPtr->phyApiPtr))->phy_auto_discover(enetIfPtr) != kStatus_PHY_Success)
				return NyLPC_TBool_FALSE;//ERR_IF;
		}
		if (((enet_phy_api_t *)(enetIfPtr->phyApiPtr))->phy_init(enetIfPtr) != kStatus_PHY_Success)
			return NyLPC_TBool_FALSE;//ERR_IF;		
		enetIfPtr->isInitialized = true;
	}else{
		// TODOETH: cleanup memory
		return NyLPC_TBool_FALSE;//ERR_IF;
	}
	
	/* Get link information from PHY */
	phy_get_link_speed(enetIfPtr, &phy_speed);
	phy_get_link_duplex(enetIfPtr, &phy_duplex);
	BW_ENET_RCR_RMII_10T(enetIfPtr->deviceNumber, phy_speed == kEnetSpeed10M ? kEnetCfgSpeed10M : kEnetCfgSpeed100M);
	BW_ENET_TCR_FDEN(enetIfPtr->deviceNumber, phy_duplex == kEnetFullDuplex ? kEnetCfgFullDuplex : kEnetCfgHalfDuplex);
	
	/* Enable Ethernet module*/
	enet_hal_config_ethernet(device, true, true);
	
	/* Active Receive buffer descriptor must be done after module enable*/
	enet_hal_active_rxbd(enetIfPtr->deviceNumber);
	enet_hal_active_txbd(enetIfPtr->deviceNumber);
	
	return NyLPC_TBool_TRUE;//ERR_OK;
}
Ejemplo n.º 4
0
/** \brief  Low level init of the MAC and PHY.
 *
 *  \param[in]      netif  Pointer to LWIP netif structure
 */
static err_t low_level_init(struct netif *netif)
{
  enet_dev_if_t * enetIfPtr;
  uint32_t device = BOARD_DEBUG_ENET_INSTANCE_ADDR;
  enet_rxbd_config_t rxbdCfg;
  enet_txbd_config_t txbdCfg;
  enet_phy_speed_t phy_speed;
  enet_phy_duplex_t phy_duplex;

  k64f_init_eth_hardware();
  
  /* Initialize device*/
  enetIfPtr = (enet_dev_if_t *)&enetDevIf[BOARD_DEBUG_ENET_INSTANCE];
  enetIfPtr->deviceNumber = device;
  enetIfPtr->macCfgPtr = &g_enetMacCfg[BOARD_DEBUG_ENET_INSTANCE];
  enetIfPtr->phyCfgPtr = &g_enetPhyCfg[BOARD_DEBUG_ENET_INSTANCE];
  enetIfPtr->macApiPtr = &g_enetMacApi;
  enetIfPtr->phyApiPtr = (void *)&g_enetPhyApi;
  memcpy(enetIfPtr->macCfgPtr->macAddr, (char*)netif->hwaddr, kEnetMacAddrLen);

  /* Allocate buffer for ENET mac context*/
  enetIfPtr->macContextPtr = (enet_mac_context_t *)calloc(1, sizeof(enet_mac_context_t));
  if (!enetIfPtr->macContextPtr) {
    return ERR_BUF;
  }

  /* Initialize enet buffers*/
  if(k64f_rx_setup(netif, &rxbdCfg) != ERR_OK) {
    return ERR_BUF;
  }
  /* Initialize enet buffers*/
  if(k64f_tx_setup(netif, &txbdCfg) != ERR_OK) {
    return ERR_BUF;
  }
  /* Initialize enet module*/
  if (enet_mac_init(enetIfPtr, &rxbdCfg, &txbdCfg) == kStatus_ENET_Success)
  {
    /* Initialize PHY*/
    if (enetIfPtr->macCfgPtr->isPhyAutoDiscover) {
      if (((enet_phy_api_t *)(enetIfPtr->phyApiPtr))->phy_auto_discover(enetIfPtr) != kStatus_PHY_Success)
        return ERR_IF;
    }
    if (((enet_phy_api_t *)(enetIfPtr->phyApiPtr))->phy_init(enetIfPtr) != kStatus_PHY_Success)
      return ERR_IF;

    enetIfPtr->isInitialized = true;
  }
  else
  {
    // TODOETH: cleanup memory
    return ERR_IF;
  }

  /* Get link information from PHY */
  phy_get_link_speed(enetIfPtr, &phy_speed);
  phy_get_link_duplex(enetIfPtr, &phy_duplex);
  BW_ENET_RCR_RMII_10T(enetIfPtr->deviceNumber, phy_speed == kEnetSpeed10M ? kEnetCfgSpeed10M : kEnetCfgSpeed100M);
  BW_ENET_TCR_FDEN(enetIfPtr->deviceNumber, phy_duplex == kEnetFullDuplex ? kEnetCfgFullDuplex : kEnetCfgHalfDuplex);

  /* Enable Ethernet module*/
  enet_hal_config_ethernet(BOARD_DEBUG_ENET_INSTANCE_ADDR, true, true);

  /* Active Receive buffer descriptor must be done after module enable*/
  enet_hal_active_rxbd(enetIfPtr->deviceNumber);

  return ERR_OK;
}