Lines Matching +full:tx +full:- +full:dummy
1 /* ENC28J60 Stand-alone Ethernet Controller with SPI
5 * SPDX-License-Identifier: Apache-2.0
34 const struct eth_enc28j60_config *config = dev->config; in eth_enc28j60_soft_reset()
40 const struct spi_buf_set tx = { in eth_enc28j60_soft_reset() local
45 return spi_write_dt(&config->spi, &tx); in eth_enc28j60_soft_reset()
50 const struct eth_enc28j60_config *config = dev->config; in eth_enc28j60_set_bank()
60 const struct spi_buf_set tx = { in eth_enc28j60_set_bank() local
72 if (!spi_transceive_dt(&config->spi, &tx, &rx)) { in eth_enc28j60_set_bank()
76 spi_write_dt(&config->spi, &tx); in eth_enc28j60_set_bank()
78 LOG_DBG("%s: Failure while setting bank to 0x%04x", dev->name, reg_addr); in eth_enc28j60_set_bank()
86 const struct eth_enc28j60_config *config = dev->config; in eth_enc28j60_write_reg()
92 const struct spi_buf_set tx = { in eth_enc28j60_write_reg() local
100 spi_write_dt(&config->spi, &tx); in eth_enc28j60_write_reg()
106 const struct eth_enc28j60_config *config = dev->config; in eth_enc28j60_read_reg()
112 const struct spi_buf_set tx = { in eth_enc28j60_read_reg() local
134 if (!spi_transceive_dt(&config->spi, &tx, &rx)) { in eth_enc28j60_read_reg()
135 *value = buf[rx_size - 1]; in eth_enc28j60_read_reg()
137 LOG_DBG("%s: Failure while reading register 0x%04x", dev->name, reg_addr); in eth_enc28j60_read_reg()
146 const struct eth_enc28j60_config *config = dev->config; in eth_enc28j60_set_eth_reg()
152 const struct spi_buf_set tx = { in eth_enc28j60_set_eth_reg() local
160 spi_write_dt(&config->spi, &tx); in eth_enc28j60_set_eth_reg()
168 const struct eth_enc28j60_config *config = dev->config; in eth_enc28j60_clear_eth_reg()
174 const struct spi_buf_set tx = { in eth_enc28j60_clear_eth_reg() local
182 spi_write_dt(&config->spi, &tx); in eth_enc28j60_clear_eth_reg()
189 const struct eth_enc28j60_config *config = dev->config; in eth_enc28j60_write_mem()
197 const struct spi_buf_set tx = { in eth_enc28j60_write_mem() local
206 num_remaining = buf_len - MAX_BUFFER_LENGTH * num_segments; in eth_enc28j60_write_mem()
212 if (spi_write_dt(&config->spi, &tx)) { in eth_enc28j60_write_mem()
213 LOG_ERR("%s: Failed to write memory", dev->name); in eth_enc28j60_write_mem()
222 if (spi_write_dt(&config->spi, &tx)) { in eth_enc28j60_write_mem()
223 LOG_ERR("%s: Failed to write memory", dev->name); in eth_enc28j60_write_mem()
232 const struct eth_enc28j60_config *config = dev->config; in eth_enc28j60_read_mem()
238 const struct spi_buf_set tx = { in eth_enc28j60_read_mem() local
257 num_remaining = buf_len - MAX_BUFFER_LENGTH * num_segments; in eth_enc28j60_read_mem()
264 if (spi_transceive_dt(&config->spi, &tx, &rx)) { in eth_enc28j60_read_mem()
265 LOG_ERR("%s: Failed to read memory", dev->name); in eth_enc28j60_read_mem()
274 if (spi_transceive_dt(&config->spi, &tx, &rx)) { in eth_enc28j60_read_mem()
275 LOG_ERR("%s: Failed to read memory", dev->name); in eth_enc28j60_read_mem()
336 k_sem_give(&context->int_sem); in eth_enc28j60_gpio_callback()
342 const struct eth_enc28j60_config *config = dev->config; in eth_enc28j60_init_buffers()
377 config->hw_rx_filter); in eth_enc28j60_init_buffers()
384 if ((k_uptime_get_32() - start_wait) > CONFIG_ETH_ENC28J60_CLKRDY_INIT_WAIT_MS) { in eth_enc28j60_init_buffers()
386 return -ETIMEDOUT; in eth_enc28j60_init_buffers()
398 const struct eth_enc28j60_config *config = dev->config; in eth_enc28j60_init_mac()
399 struct eth_enc28j60_runtime *context = dev->data; in eth_enc28j60_init_mac()
412 if (config->full_duplex) { in eth_enc28j60_init_mac()
419 if (config->full_duplex) { in eth_enc28j60_init_mac()
433 context->mac_address[5]); in eth_enc28j60_init_mac()
435 context->mac_address[4]); in eth_enc28j60_init_mac()
437 context->mac_address[3]); in eth_enc28j60_init_mac()
439 context->mac_address[2]); in eth_enc28j60_init_mac()
441 context->mac_address[1]); in eth_enc28j60_init_mac()
443 context->mac_address[0]); in eth_enc28j60_init_mac()
448 const struct eth_enc28j60_config *config = dev->config; in eth_enc28j60_init_phy()
450 if (config->full_duplex) { in eth_enc28j60_init_phy()
463 return ctx->iface; in get_iface()
468 struct eth_enc28j60_runtime *context = dev->data; in eth_enc28j60_tx()
476 LOG_DBG("%s: pkt %p (len %u)", dev->name, pkt, len); in eth_enc28j60_tx()
478 k_sem_take(&context->tx_rx_sem, K_FOREVER); in eth_enc28j60_tx()
504 for (frag = pkt->frags; frag; frag = frag->frags) { in eth_enc28j60_tx()
505 eth_enc28j60_write_mem(dev, frag->data, frag->len); in eth_enc28j60_tx()
527 k_sem_give(&context->tx_rx_sem); in eth_enc28j60_tx()
530 LOG_ERR("%s: TX failed!", dev->name); in eth_enc28j60_tx()
543 return -EIO; in eth_enc28j60_tx()
546 LOG_DBG("%s: Tx successful", dev->name); in eth_enc28j60_tx()
553 const struct eth_enc28j60_config *config = dev->config; in enc28j60_read_packet()
554 struct eth_enc28j60_runtime *context = dev->data; in enc28j60_read_packet()
558 uint8_t dummy[4]; in enc28j60_read_packet() local
562 AF_UNSPEC, 0, K_MSEC(config->timeout)); in enc28j60_read_packet()
564 LOG_ERR("%s: Could not allocate rx buffer", dev->name); in enc28j60_read_packet()
569 pkt_buf = pkt->buffer; in enc28j60_read_packet()
577 data_ptr = pkt_buf->data; in enc28j60_read_packet()
593 frm_len -= spi_frame_len; in enc28j60_read_packet()
594 pkt_buf = pkt_buf->frags; in enc28j60_read_packet()
598 eth_enc28j60_read_mem(dev, dummy, 4); in enc28j60_read_packet()
604 eth_enc28j60_read_mem(dev, dummy, 1); in enc28j60_read_packet()
607 net_pkt_set_iface(pkt, context->iface); in enc28j60_read_packet()
610 LOG_DBG("%s: Received packet of length %u", dev->name, lengthfr); in enc28j60_read_packet()
618 struct eth_enc28j60_runtime *context = dev->data; in eth_enc28j60_rx()
631 k_sem_take(&context->tx_rx_sem, K_FOREVER); in eth_enc28j60_rx()
657 next_packet--; in eth_enc28j60_rx()
666 frm_len = sys_get_le16(info) - 4; in eth_enc28j60_rx()
684 k_sem_give(&context->tx_rx_sem); in eth_enc28j60_rx()
702 struct eth_enc28j60_runtime *context = dev->data; in eth_enc28j60_rx_thread()
706 k_sem_take(&context->int_sem, K_FOREVER); in eth_enc28j60_rx_thread()
721 LOG_INF("%s: Link up", dev->name); in eth_enc28j60_rx_thread()
725 if (context->iface_initialized) { in eth_enc28j60_rx_thread()
726 net_eth_carrier_on(context->iface); in eth_enc28j60_rx_thread()
728 context->iface_carrier_on_init = true; in eth_enc28j60_rx_thread()
731 LOG_INF("%s: Link down", dev->name); in eth_enc28j60_rx_thread()
733 if (context->iface_initialized) { in eth_enc28j60_rx_thread()
734 net_eth_carrier_off(context->iface); in eth_enc28j60_rx_thread()
763 struct eth_enc28j60_runtime *context = dev->data; in eth_enc28j60_iface_init()
765 net_if_set_link_addr(iface, context->mac_address, in eth_enc28j60_iface_init()
766 sizeof(context->mac_address), in eth_enc28j60_iface_init()
769 if (context->iface == NULL) { in eth_enc28j60_iface_init()
770 context->iface = iface; in eth_enc28j60_iface_init()
776 if (context->iface_carrier_on_init) { in eth_enc28j60_iface_init()
781 context->iface_initialized = true; in eth_enc28j60_iface_init()
793 const struct eth_enc28j60_config *config = dev->config; in eth_enc28j60_init()
794 struct eth_enc28j60_runtime *context = dev->data; in eth_enc28j60_init()
797 if (!spi_is_ready_dt(&config->spi)) { in eth_enc28j60_init()
798 LOG_ERR("%s: SPI master port %s not ready", dev->name, config->spi.bus->name); in eth_enc28j60_init()
799 return -EINVAL; in eth_enc28j60_init()
803 if (!gpio_is_ready_dt(&config->interrupt)) { in eth_enc28j60_init()
804 LOG_ERR("%s: GPIO port %s not ready", dev->name, config->interrupt.port->name); in eth_enc28j60_init()
805 return -EINVAL; in eth_enc28j60_init()
808 if (gpio_pin_configure_dt(&config->interrupt, GPIO_INPUT)) { in eth_enc28j60_init()
809 LOG_ERR("%s: Unable to configure GPIO pin %u", dev->name, config->interrupt.pin); in eth_enc28j60_init()
810 return -EINVAL; in eth_enc28j60_init()
813 gpio_init_callback(&(context->gpio_cb), eth_enc28j60_gpio_callback, in eth_enc28j60_init()
814 BIT(config->interrupt.pin)); in eth_enc28j60_init()
816 if (gpio_add_callback(config->interrupt.port, &(context->gpio_cb))) { in eth_enc28j60_init()
817 return -EINVAL; in eth_enc28j60_init()
820 gpio_pin_interrupt_configure_dt(&config->interrupt, in eth_enc28j60_init()
824 LOG_ERR("%s: Soft-reset failed", dev->name); in eth_enc28j60_init()
825 return -EIO; in eth_enc28j60_init()
832 if (config->random_mac) { in eth_enc28j60_init()
833 gen_random_mac(context->mac_address, MICROCHIP_OUI_B0, MICROCHIP_OUI_B1, in eth_enc28j60_init()
835 LOG_INF("Random MAC Addr %02x:%02x:%02x:%02x:%02x:%02x", context->mac_address[0], in eth_enc28j60_init()
836 context->mac_address[1], context->mac_address[2], context->mac_address[3], in eth_enc28j60_init()
837 context->mac_address[4], context->mac_address[5]); in eth_enc28j60_init()
840 context->mac_address[0] = MICROCHIP_OUI_B0; in eth_enc28j60_init()
841 context->mac_address[1] = MICROCHIP_OUI_B1; in eth_enc28j60_init()
842 context->mac_address[2] = MICROCHIP_OUI_B2; in eth_enc28j60_init()
846 return -ETIMEDOUT; in eth_enc28j60_init()
862 /* Start interruption-poll thread */ in eth_enc28j60_init()
863 k_thread_create(&context->thread, context->thread_stack, in eth_enc28j60_init()
870 LOG_INF("%s: Initialized", dev->name); in eth_enc28j60_init()