--- F:\version_ecos\packages\devs\eth\arm\at91\current\src\if_at91.c 2008-03-07 08:35:36.000000000 +-0200 +++ F:\ecos_ronetix\packages\devs\eth\arm\at91\current\src\if_at91.c 2008-06-01 23:09:54.000000000 +-0200 @@ -64,13 +66,15 @@ #include #include #include #include #include #include +#ifdef PHY_PRESENT #include +#endif #include #include // Set up the level of debug output #if CYGPKG_DEVS_ETH_ARM_AT91_DEBUG_LEVEL > 0 #define debug1_printf(args...) diag_printf(args) @@ -165,13 +169,15 @@ typedef struct at91_eth_priv_s { cyg_uint32 intr_vector; char *esa_key; // RedBoot 'key' for device ESA cyg_uint8 *enaddr; cyg_uint32 base; // Base address of device +#ifdef PHY_PRESENT eth_phy_access_t *phy; +#endif rbd_t rbd[CYGNUM_DEVS_ETH_ARM_AT91_RX_BUFS]; rb_t rb[CYGNUM_DEVS_ETH_ARM_AT91_RX_BUFS]; tbd_t tbd[CYGNUM_DEVS_ETH_ARM_AT91_TX_BUFS]; unsigned long curr_tx_key; cyg_bool tx_busy; cyg_uint32 last_tbd_idx; @@ -298,18 +304,19 @@ CYG_FAIL("Unable to program MII clock"); } HAL_WRITE_UINT32(AT91_EMAC + AT91_EMAC_NCFG, cfg); } - +#ifdef PHY_PRESENT ETH_PHY_REG_LEVEL_ACCESS_FUNS(at91_phy, at91_init_phy, NULL, at91_write_phy, at91_read_phy); - +#endif //====================================================================== // Receiver buffer handling // Initialize the receiver buffers and descriptors static void at91_rb_init(at91_eth_priv_t *priv) @@ -482,13 +489,15 @@ { struct eth_drv_sc *sc = (struct eth_drv_sc *)tab->device_instance; at91_eth_priv_t *priv = (at91_eth_priv_t *)sc->driver_private; bool esa_ok = false; unsigned char enaddr[6] = { CYGPKG_DEVS_ETH_ARM_AT91_MACADDR}; unsigned char enzero[6] = { 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}; +#ifdef PHY_PRESENT unsigned short phy_state = 0; +#endif cyg_uint32 ncfg = 0; debug1_printf("\nAT91_ETH: Initialising @ %x\n",priv->base); priv->tx_busy = false; priv->curr_tbd_idx = 0; @@ -557,57 +566,64 @@ // Setup the transmit descriptors at91_tb_init(priv); // And tell the EMAC where the first transmit buffer descriptor is HAL_WRITE_UINT32(priv->base + AT91_EMAC_TBQP, (cyg_uint32)priv->tbd); +#ifdef PHY_PRESENT // Setup the PHY CYG_ASSERTC(priv->phy); at91_mdio_enable(); if (!_eth_phy_init(priv->phy)) { at91_mdio_disable(); + debug2_printf("_eth_phy_init failed\n"); return (false); } // Get the current mode and print it phy_state = _eth_phy_state(priv->phy); +#endif at91_mdio_disable(); HAL_READ_UINT32(priv->base + AT91_EMAC_NCFG,ncfg); - +#ifdef PHY_PRESENT if ((phy_state & ETH_PHY_STAT_LINK) != 0) { if (((phy_state & ETH_PHY_STAT_100MB) != 0)) { debug1_printf("AT91_ETH: 100Mbyte/s"); +#endif ncfg |= AT91_EMAC_NCFG_SPD_100Mbps; +#ifdef PHY_PRESENT } else { debug1_printf("AT91_ETH: 10Mbyte/s"); ncfg &= ~(AT91_EMAC_NCFG_SPD_100Mbps); } if((phy_state & ETH_PHY_STAT_FDX)) { debug1_printf(" Full Duplex\n"); +#endif ncfg |= AT91_EMAC_NCFG_FD; +#ifdef PHY_PRESENT } else { debug1_printf(" Half Duplex\n"); ncfg &= ~(AT91_EMAC_NCFG_FD); } } else { debug1_printf("AT91_ETH: No Link\n"); } - +#endif //Setup the network configuration ncfg |= (AT91_EMAC_NCFG_RLCE); HAL_WRITE_UINT32(priv->base + AT91_EMAC_NCFG,ncfg); @@ -721,20 +737,27 @@ at91_eth_send(struct eth_drv_sc *sc, struct eth_drv_sg *sg_list, int sg_len, int total_len, unsigned long key) { at91_eth_priv_t *priv = (at91_eth_priv_t *)sc->driver_private; int i; cyg_uint32 sr; - +#ifdef SRAM1_ORIGIN /* define it in plf_io.h if present */ + cyg_uint32 total_bytes = 0; /* position in SRAM1 */ +#endif priv->tx_busy = true; priv->last_tbd_idx = priv->curr_tbd_idx; for(i = 0;itbd[priv->curr_tbd_idx].addr = SRAM1_ORIGIN+total_bytes; +#else priv->tbd[priv->curr_tbd_idx].addr = sg_list[i].buf; +#endif sr = (sg_list[i].len & AT91_EMAC_TBD_SR_LEN_MASK); // Set the End Of Frame bit in the last descriptor if(i == (sg_len-1)) { sr |= AT91_EMAC_TBD_SR_EOF; @@ -747,12 +770,15 @@ } else { priv->tbd[priv->curr_tbd_idx].sr = (sr | AT91_EMAC_TBD_SR_WRAP); priv->curr_tbd_idx = 0; } +#ifdef SRAM1_ORIGIN + total_bytes += sg_list[i].len; +#endif } // Store away the key for when the transmit has completed // and we need to tell the stack which transmit has completed. priv->curr_tx_key = key; @@ -936,19 +962,22 @@ cyg_uint32 total_bytes = 0; for(i = 0;irbd[priv->curr_rbd_idx].sr & AT91_EMAC_RBD_SR_EOF) { bytes_in_buffer = ((priv->rbd[priv->curr_rbd_idx].sr & AT91_EMAC_RBD_SR_LEN_MASK) - - total_bytes) - buffer_pos; + - total_bytes); } else { bytes_in_buffer = AT91_EMAC_RX_BUFF_SIZE - buffer_pos; } @@ -1001,14 +1030,17 @@ return(CYGNUM_HAL_INTERRUPT_EMAC); } at91_eth_priv_t at91_priv_data = { .intr_vector = CYGNUM_HAL_INTERRUPT_EMAC, - .base = AT91_EMAC, + .base = AT91_EMAC +#ifdef PHY_PRESENT + , .phy = &at91_phy +#endif }; ETH_DRV_SC(at91_sc, &at91_priv_data, // Driver specific data "eth0", // Name for this interface at91_eth_start,