X-Git-Url: http://rtime.felk.cvut.cz/gitweb/pes-rpp/rpp-lib.git/blobdiff_plain/b780d6193082bb4a2aabe7bb47b53396ead91f1e..49901f543393051038bf8dd7fb1cffb0ee9a7be8:/rpp/src/rpp/eth.c diff --git a/rpp/src/rpp/eth.c b/rpp/src/rpp/eth.c index cb3e298..6eb21b0 100644 --- a/rpp/src/rpp/eth.c +++ b/rpp/src/rpp/eth.c @@ -68,21 +68,21 @@ /* Number of EMAC Instances */ -#define MAX_EMAC_INSTANCE 1 +#define MAX_EMAC_INSTANCE 1 -#define DEFAULT_PHY_ADDR 0x1 -#define FIND_FIRST_PHY_ALIVE 1 /* or use default (phy_address: 1) */ -#define NUM_OF_PHYs 32 +#define DEFAULT_PHY_ADDR 0x1 +#define FIND_FIRST_PHY_ALIVE 1 /* or use default (phy_address: 1) */ +#define NUM_OF_PHYs 32 /* Size of the Buffer descriptor defined by the EMAC in bytes */ -#define SIZE_OF_DESC 16 +#define SIZE_OF_DESC 16 /* Channel number used for for RX, TX, unicast, broadcast or damaged frames; * there are different channels for rx and tx operations (i.e. RXCH0 != TXCH0) */ -#define CHANNEL 0 +#define CHANNEL 0 /* take in account oversized frames */ -#define MAX_TRANSFER_UNIT 1500 +#define MAX_TRANSFER_UNIT 1500 /* WARNING! * Be very carefull when setting this value. We have to keep in mind @@ -104,27 +104,27 @@ * This is the implementation limitation. The PBUF_LEN_MAX should therefore * be multiple of PBUF_POOL_BUFSIZE */ -#define PBUF_LEN_MAX (PBUF_POOL_BUFSIZE * 6) +#define PBUF_LEN_MAX (PBUF_POOL_BUFSIZE * 6) /* Maximum number of PBUFs preallocated in the driver * init function to be used for the RX */ -#define MAX_RX_PBUF_ALLOC 10 -#define MIN_PKT_LEN 60 +#define MAX_RX_PBUF_ALLOC 10 +#define MIN_PKT_LEN 60 /* Define those to better describe the network interface. */ -#define IFNAME0 'e' -#define IFNAME1 'n' +#define IFNAME0 'e' +#define IFNAME1 'n' /* Time to wait for autonegotiation in ticks. */ -#define TICKS_PHY_AUTONEG 4000 +#define TICKS_PHY_AUTONEG 4000 /** * TODO -- not implemented * When cable is connected (link status goes up) * autonegotiation and/or dhcp is started. */ -#define PHY_LINK_MONITOR_INT 0 +#define PHY_LINK_MONITOR_INT 0 /* Statically allocated structure describing interface state -- one per instance */ @@ -146,6 +146,7 @@ boolean_t isPostInitialized() uint32_t rpp_eth_phylinkstat(uint32_t instNum) { struct hdkif *hdkif = &hdkif_data[instNum]; + return PHY_link_status_get(hdkif->mdio_base, hdkif->phy_addr, 1); } @@ -186,7 +187,7 @@ err_t rpp_eth_stringToIP(ip_addr_t * ip, uint8_t * ipstr) ipaddr = (ipaddr << 8) + tmp; dots++; - if(dots > 3)break; + if (dots > 3)break; tmp = 0; fldEdit = FALSE; @@ -283,8 +284,7 @@ static void hdkif_macaddrset(u32_t inst_num, u8_t *mac_addr) */ static void hdkif_inst_config(struct hdkif *hdkif) { - if (hdkif->inst_num == 0) - { + if (hdkif->inst_num == 0) { hdkif->emac_base = EMAC_BASE_m(0); hdkif->emac_ctrl_base = EMAC_CTRL_BASE_m(0); hdkif->emac_ctrl_ram = EMAC_CTRL_RAM_BASE_m(0); @@ -311,8 +311,7 @@ int8_t rpp_eth_init() return FAILURE; /* Config each EMAC instance */ - for (instNum = 0; instNum < MAX_EMAC_INSTANCE; instNum++) - { + for (instNum = 0; instNum < MAX_EMAC_INSTANCE; instNum++) { struct hdkif *hdkif = &hdkif_data[instNum]; hdkif->inst_num = instNum; @@ -376,12 +375,12 @@ int8_t rpp_eth_init_postInit(uint32_t instNum, uint8_t *macArray) * and initialize netif with specific function */ netif_tmp = netif_add(netif, &ip_addr, &net_mask, &gw_addr, - &hdkif_data[instNum], rpp_eth_lwip_init, - ethernet_input); + &hdkif_data[instNum], rpp_eth_lwip_init, + ethernet_input); #else netif_tmp = netif_add(netif, &ip_addr, &net_mask, &gw_addr, - &hdkif_data[instNum], rpp_eth_lwip_init, - tcpip_input); + &hdkif_data[instNum], rpp_eth_lwip_init, + tcpip_input); #endif if (netif_tmp == NULL) return NETIF_ADD_ERR; @@ -584,8 +583,8 @@ static err_t rpp_eth_hw_init(struct hdkif *hdkif) * when complete link register will be updated */ hdkif->phy_autoneg_start(hdkif->mdio_base, hdkif->phy_addr, - PHY_100BASETXDUPL_m | PHY_100BASETX_m | - PHY_10BASETDUPL_m | PHY_10BASET_m); + PHY_100BASETXDUPL_m | PHY_100BASETX_m | + PHY_10BASETDUPL_m | PHY_10BASET_m); /* * TODO: you can implement init of receive flow control somewhere @@ -731,9 +730,9 @@ static err_t rpp_eth_hw_init_postInit(struct netif *netif) #ifdef DEBUG num_bd = (((uintptr_t)rxch->active_tail - (uintptr_t)rxch->active_head) - / sizeof(struct emac_rx_bd)) + 1; + / sizeof(struct emac_rx_bd)) + 1; rpp_debug_printf("%d pbuf chains allocated for %d rx buffer descriptors\n", - pbuf_cnt, num_bd); + pbuf_cnt, num_bd); #endif /* Set header descriptor pointers -- this shows EMAC which descriptor @@ -764,7 +763,7 @@ static err_t rpp_eth_hw_init_postInit(struct netif *netif) */ for (regContent = 0; regContent < 8; regContent++) { EMACMACAddrSet(hdkif->emac_base, regContent, hdkif->mac_addr, - EMAC_MACADDR_NO_MATCH_NO_FILTER); + EMAC_MACADDR_NO_MATCH_NO_FILTER); } #if !PHY_LINK_MONITOR_INT @@ -828,6 +827,7 @@ static err_t rpp_eth_hw_init_postInit(struct netif *netif) err_t rpp_eth_send(struct netif *netif, struct pbuf *p) { err_t retVal = SUCCESS; + SYS_ARCH_DECL_PROTECT(lev); /** @@ -898,8 +898,8 @@ static err_t rpp_eth_send_raw(struct netif *netif, struct pbuf *pbuf) /* First 'part' of packet flags */ curr_bd->flags_pktlen = pbuf->tot_len | - EMAC_DSC_FLAG_SOP | - EMAC_DSC_FLAG_OWNER; + EMAC_DSC_FLAG_SOP | + EMAC_DSC_FLAG_OWNER; /* Copy pbuf information into TX BDs -- * remember that the pbuf for a single packet might be chained! @@ -957,7 +957,7 @@ static err_t rpp_eth_send_raw(struct netif *netif, struct pbuf *pbuf) while (HWREG(hdkif->emac_base + EMAC_TXHDP(CHANNEL)) != 0) ; EMACTxHdrDescPtrWrite(hdkif->emac_base, - (unsigned int)(active_head), CHANNEL); + (unsigned int)(active_head), CHANNEL); } } txch->active_tail = active_tail; @@ -1012,7 +1012,7 @@ void rpp_eth_send_raw_thr(void *arg) /* Ack the Interrupt in the EMAC peripheral */ EMACTxCPWrite(hdkif->emac_base, CHANNEL, - (uint32_t)curr_bd); + (uint32_t)curr_bd); /* Free the corresponding pbuf * Sidenote: Each fragment of the single packet points @@ -1268,11 +1268,11 @@ boolean_t HostPendErrHandler(void) rpp_sci_printk("HOSTPEND err\n"); reg = HWREG(hdkif->emac_base + EMAC_MACSTATUS); rpp_sci_printk("TXCHERR: %d at CH: %d\n", - ((reg >> EMAC_MACSTATUS_TXERRCODE_SHIFT) & 0x7), - ((reg >> EMAC_MACSTATUS_TXERRCH_SHIFT) & 0x7)); + ((reg >> EMAC_MACSTATUS_TXERRCODE_SHIFT) & 0x7), + ((reg >> EMAC_MACSTATUS_TXERRCH_SHIFT) & 0x7)); rpp_sci_printk("RXCHERR: %d at CH: %d\n", - ((reg >> EMAC_MACSTATUS_RXERRCODE_SHIFT) & 0x7), - ((reg >> EMAC_MACSTATUS_RXERRCH_SHIFT) & 0x7)); + ((reg >> EMAC_MACSTATUS_RXERRCODE_SHIFT) & 0x7), + ((reg >> EMAC_MACSTATUS_RXERRCH_SHIFT) & 0x7)); { /* Print out all the RX BDs */ struct rxch *rxch; @@ -1289,16 +1289,16 @@ boolean_t HostPendErrHandler(void) glob_len += curr_bd->pbuf->len; rpp_sci_printk("[%p: buf: %p buffoff_len: 0x%x " - "\tflags: 0x%x pktlen: 0x%x]", - curr_bd, - curr_bd->bufptr, - curr_bd->bufoff_len, - (curr_bd->flags_pktlen >> 16) & 0xFFFF, - curr_bd->flags_pktlen & 0xFFFF); + "\tflags: 0x%x pktlen: 0x%x]", + curr_bd, + curr_bd->bufptr, + curr_bd->bufoff_len, + (curr_bd->flags_pktlen >> 16) & 0xFFFF, + curr_bd->flags_pktlen & 0xFFFF); rpp_sci_printk(" pbuf: tot_len: 0x%x \tlen: 0x%x ref: 0x%x\n", - curr_bd->pbuf->tot_len, - curr_bd->pbuf->len, - curr_bd->pbuf->ref); + curr_bd->pbuf->tot_len, + curr_bd->pbuf->len, + curr_bd->pbuf->ref); } rpp_sci_printk("glob_len: %d\n", glob_len); } @@ -1325,9 +1325,9 @@ boolean_t LinkIntHandler(void) while (index) { hdkif = &hdkif_data[--index]; if ((hdkif->phy_addr == - (HWREG(hdkif->mdio_base + MDIO_USERPHYSEL0) & 0x1f)) && - (EMACIntVectorGet(hdkif->emac_base) & - EMAC_MACINVECTOR_LINKINT0)) + (HWREG(hdkif->mdio_base + MDIO_USERPHYSEL0) & 0x1f)) && + (EMACIntVectorGet(hdkif->emac_base) & + EMAC_MACINVECTOR_LINKINT0)) phyFound = TRUE; } if (!phyFound) @@ -1374,9 +1374,9 @@ boolean_t LinkIntHandler(void) #if STATIC_IP_ADDRESS netif_set_up(netif); #elif LWIP_DHCP /* STATIC_IP_ADDRESS-LWIP_DHCP */ - if (dhcp_start(netif) != ERR_OK) { /* XXX: can't be used from ISR (mem_malloc()) */ + if (dhcp_start(netif) != ERR_OK) /* XXX: can't be used from ISR (mem_malloc()) */ return DHCP_MEM_ERR; - } + #if ONCE_LINK_SETUP while (netif->dhcp->state != DHCP_BOUND) ;