static inline void init_test() { PRINT("%s: run 802.15.4 loopback tester\n", __func__); net_set_mac(src_mac, sizeof(src_mac)); any_addr.in6_addr = in6addr_src; any_addr.family = AF_INET6; loopback_addr.in6_addr = in6addr_dest; loopback_addr.family = AF_INET6; }
static inline void init_server() { PRINT("%s: run mcast tester\n", __func__); sys_rand32_init(); net_set_mac(my_mac, sizeof(my_mac)); #ifdef CONFIG_NETWORKING_WITH_IPV4 { uip_ipaddr_t addr; uip_ipaddr(&addr, 192,0,2,2); uip_sethostaddr(&addr); } #else /* IPv6 */ { uip_ipaddr_t *addr; #ifdef CONFIG_NETWORKING_IPV6_NO_ND /* Set the routes and neighbor cache only if we do not have * neighbor discovery enabled. This setting should only be * used if running in qemu and using slip (tun device). */ const uip_lladdr_t *lladdr = (const uip_lladdr_t *)&peer_mac; addr = (uip_ipaddr_t *)&in6addr_peer; uip_ds6_defrt_add(addr, 0); /* We cannot send to peer unless it is in neighbor * cache. Neighbor cache should be populated automatically * but do it here so that test works from first packet. */ uip_ds6_nbr_add(addr, lladdr, 0, NBR_REACHABLE); #else /* Hard code the route to peer just in case, not to * be done in real life applications. */ addr = (uip_ipaddr_t *)&in6addr_peer; uip_ds6_defrt_add(addr, 0); #endif addr = (uip_ipaddr_t *)&in6addr_my; uip_ds6_addr_add(addr, 0, ADDR_MANUAL); } #endif }
static int eth_initialize(struct device *port) { struct eth_runtime *context = port->driver_data; const struct eth_config *config = port->config->config_info; uint32_t base_addr; union { struct { uint8_t bytes[6]; uint8_t pad[2]; } __attribute__((packed)); uint32_t words[2]; } mac_addr; if (!eth_setup(port)) return -EPERM; base_addr = context->base_addr; /* Read the MAC address from the device. */ mac_addr.words[1] = eth_read(base_addr, REG_ADDR_MACADDR_HI); mac_addr.words[0] = eth_read(base_addr, REG_ADDR_MACADDR_LO); net_set_mac(mac_addr.bytes, sizeof(mac_addr.bytes)); /* Initialize the frame filter enabling unicast messages */ eth_write(base_addr, REG_ADDR_MAC_FRAME_FILTER, MAC_FILTER_4_PM); /* Initialize transmit descriptor. */ context->tx_desc.tdes0 = 0; context->tx_desc.tdes1 = 0; context->tx_desc.buf1_ptr = (uint8_t *)context->tx_buf; context->tx_desc.tx_end_of_ring = 1; context->tx_desc.first_seg_in_frm = 1; context->tx_desc.last_seg_in_frm = 1; context->tx_desc.tx_end_of_ring = 1; /* Initialize receive descriptor. */ context->rx_desc.rdes0 = 0; context->rx_desc.rdes1 = 0; context->rx_desc.buf1_ptr = (uint8_t *)context->rx_buf; context->rx_desc.own = 1; context->rx_desc.first_desc = 1; context->rx_desc.last_desc = 1; context->rx_desc.rx_buf1_sz = UIP_BUFSIZE; context->rx_desc.rx_end_of_ring = 1; /* Install transmit and receive descriptors. */ eth_write(base_addr, REG_ADDR_RX_DESC_LIST, (uint32_t)&context->rx_desc); eth_write(base_addr, REG_ADDR_TX_DESC_LIST, (uint32_t)&context->tx_desc); eth_write(base_addr, REG_ADDR_MAC_CONF, /* Set the RMII speed to 100Mbps */ MAC_CONF_14_RMII_100M | /* Enable full-duplex mode */ MAC_CONF_11_DUPLEX | /* Enable transmitter */ MAC_CONF_3_TX_EN | /* Enable receiver */ MAC_CONF_2_RX_EN); eth_write(base_addr, REG_ADDR_INT_ENABLE, INT_ENABLE_NORMAL | /* Enable receive interrupts */ INT_ENABLE_RX); /* Mask all the MMC interrupts */ eth_write(base_addr, REG_MMC_RX_INTR_MASK, MMC_DEFAULT_MASK); eth_write(base_addr, REG_MMC_TX_INTR_MASK, MMC_DEFAULT_MASK); eth_write(base_addr, REG_MMC_RX_IPC_INTR_MASK, MMC_DEFAULT_MASK); eth_write(base_addr, REG_ADDR_DMA_OPERATION, /* Enable receive store-and-forward mode for simplicity. */ OP_MODE_25_RX_STORE_N_FORWARD | /* Enable transmit store-and-forward mode for simplicity. */ OP_MODE_21_TX_STORE_N_FORWARD | /* Place the transmitter state machine in the Running state. */ OP_MODE_13_START_TX | /* Place the receiver state machine in the Running state. */ OP_MODE_1_START_RX); SYS_LOG_INF("Enabled 100M full-duplex mode."); net_driver_ethernet_register_tx(eth_net_tx); config->config_func(port); return 0; }