Lines Matching +full:conf +full:- +full:rx

1 /* ieee802154_rf2xx.c - ATMEL RF2XX IEEE 802.15.4 Driver */
6 * Copyright (c) 2019-2020 Gerson Fernando Budke
8 * SPDX-License-Identifier: Apache-2.0
67 .rssi = -40,
84 k_sem_give(&ctx->trx_isr_lock); in trx_isr_handler()
109 * Ensures that RX automatically ACK will be sent when requested. in rf2xx_trx_set_tx_state()
111 * Datasheet: Figure 7-13. Timing Example of an RX_AACK Transaction in rf2xx_trx_set_tx_state()
133 * Set extended RX mode in rf2xx_trx_set_rx_state()
141 struct rf2xx_context *ctx = dev->data; in rf2xx_set_rssi_base()
144 if (ctx->cc_page == IEEE802154_ATTR_PHY_CHANNEL_PAGE_ZERO_OQPSK_2450_BPSK_868_915) { in rf2xx_set_rssi_base()
148 } else if (ctx->cc_page == IEEE802154_ATTR_PHY_CHANNEL_PAGE_TWO_OQPSK_868_915) { in rf2xx_set_rssi_base()
156 ctx->trx_rssi_base = base; in rf2xx_set_rssi_base()
161 struct rf2xx_context *ctx = dev->data; in rf2xx_trx_rx()
175 if (ctx->trx_model != RF2XX_TRX_MODEL_231) { in rf2xx_trx_rx()
176 pkt_len = ctx->rx_phr; in rf2xx_trx_rx()
182 if (!ctx->promiscuous && pkt_len < RX2XX_FRAME_MIN_PHR_SIZE) { in rf2xx_trx_rx()
183 LOG_ERR("Invalid RX frame length"); in rf2xx_trx_rx()
192 if (ctx->trx_model != RF2XX_TRX_MODEL_231) { in rf2xx_trx_rx()
196 ctx->pkt_ed = rx_buf[pkt_len + RX2XX_FRAME_ED_INDEX]; in rf2xx_trx_rx()
201 ctx->pkt_ed = (rf2xx_iface_reg_read(dev, RF2XX_PHY_RSSI_REG) in rf2xx_trx_rx()
204 ctx->pkt_lqi = rx_buf[pkt_len + RX2XX_FRAME_LQI_INDEX]; in rf2xx_trx_rx()
206 if (!ctx->promiscuous && trac == RF2XX_TRX_PHY_STATE_TRAC_INVALID) { in rf2xx_trx_rx()
207 LOG_ERR("Invalid RX frame"); in rf2xx_trx_rx()
214 pkt_len -= RX2XX_FRAME_FCS_LENGTH; in rf2xx_trx_rx()
217 pkt = net_pkt_rx_alloc_with_buffer(ctx->iface, pkt_len, in rf2xx_trx_rx()
220 LOG_ERR("No RX buffer available"); in rf2xx_trx_rx()
224 memcpy(pkt->buffer->data, rx_buf + RX2XX_FRAME_HEADER_SIZE, pkt_len); in rf2xx_trx_rx()
225 net_buf_add(pkt->buffer, pkt_len); in rf2xx_trx_rx()
226 net_pkt_set_ieee802154_lqi(pkt, ctx->pkt_lqi); in rf2xx_trx_rx()
227 net_pkt_set_ieee802154_rssi_dbm(pkt, ctx->pkt_ed + ctx->trx_rssi_base); in rf2xx_trx_rx()
230 pkt_len, ctx->pkt_lqi, ctx->trx_rssi_base + ctx->pkt_ed, in rf2xx_trx_rx()
231 ctx->pkt_ed); in rf2xx_trx_rx()
233 if (net_recv_data(ctx->iface, pkt) < 0) { in rf2xx_trx_rx()
234 LOG_DBG("RX Packet dropped by NET stack"); in rf2xx_trx_rx()
240 log_stack_usage(&ctx->trx_thread); in rf2xx_trx_rx()
246 struct rf2xx_context *ctx = dev->data; in rf2xx_process_rx_frame()
252 if (ctx->trx_model != RF2XX_TRX_MODEL_231) { in rf2xx_process_rx_frame()
274 struct rf2xx_context *ctx = dev->data; in rf2xx_process_tx_frame()
276 ctx->trx_trac = (rf2xx_iface_reg_read(dev, RF2XX_TRX_STATE_REG) >> in rf2xx_process_tx_frame()
278 k_sem_give(&ctx->trx_tx_sync); in rf2xx_process_tx_frame()
303 k_sem_take(&ctx->trx_isr_lock, K_FOREVER); in rf2xx_thread_main()
305 isr_status = rf2xx_iface_reg_read(ctx->dev, in rf2xx_thread_main()
314 * IRQ_4 (CCA_ED_DONE) Multi-functional interrupt: in rf2xx_thread_main()
322 * RX: Indicates the completion of a frame in rf2xx_thread_main()
335 if (ctx->trx_model != RF2XX_TRX_MODEL_231) { in rf2xx_thread_main()
336 rf2xx_iface_sram_read(ctx->dev, 0, in rf2xx_thread_main()
337 &ctx->rx_phr, 1); in rf2xx_thread_main()
341 rf2xx_process_trx_end(ctx->dev); in rf2xx_thread_main()
348 const struct rf2xx_config *conf = dev->config; in get_mac() local
349 struct rf2xx_context *ctx = dev->data; in get_mac()
350 uint32_t *ptr = (uint32_t *)(ctx->mac_addr); in get_mac()
352 if (!conf->has_mac) { in get_mac()
354 ptr = (uint32_t *)(ctx->mac_addr + 4); in get_mac()
363 ctx->mac_addr[0] = (ctx->mac_addr[0] & ~0x01) | 0x02; in get_mac()
365 return ctx->mac_addr; in get_mac()
383 struct rf2xx_context *ctx = dev->data; in rf2xx_configure_sub_channel()
387 if (ctx->cc_page == IEEE802154_ATTR_PHY_CHANNEL_PAGE_ZERO_OQPSK_2450_BPSK_868_915) { in rf2xx_configure_sub_channel()
391 } else if (ctx->cc_page == IEEE802154_ATTR_PHY_CHANNEL_PAGE_TWO_OQPSK_868_915) { in rf2xx_configure_sub_channel()
408 struct rf2xx_context *ctx = dev->data; in rf2xx_configure_trx_path()
412 if (ctx->cc_page == IEEE802154_ATTR_PHY_CHANNEL_PAGE_ZERO_OQPSK_2450_BPSK_868_915) { in rf2xx_configure_trx_path()
436 struct rf2xx_context *ctx = dev->data; in rf2xx_set_channel()
441 if (ctx->trx_model == RF2XX_TRX_MODEL_212) { in rf2xx_set_channel()
442 if ((ctx->cc_page == IEEE802154_ATTR_PHY_CHANNEL_PAGE_ZERO_OQPSK_2450_BPSK_868_915 in rf2xx_set_channel()
443 || ctx->cc_page == IEEE802154_ATTR_PHY_CHANNEL_PAGE_TWO_OQPSK_868_915) in rf2xx_set_channel()
446 return channel > 26 ? -EINVAL : -ENOTSUP; in rf2xx_set_channel()
448 if (ctx->cc_page == IEEE802154_ATTR_PHY_CHANNEL_PAGE_FIVE_OQPSK_780 && in rf2xx_set_channel()
451 return channel > 7 ? -EINVAL : -ENOTSUP; in rf2xx_set_channel()
458 /* 2.4G O-QPSK, channel page zero */ in rf2xx_set_channel()
461 return channel < 11 ? -ENOTSUP : -EINVAL; in rf2xx_set_channel()
473 const struct rf2xx_config *conf = dev->config; in rf2xx_set_txpower() local
474 struct rf2xx_context *ctx = dev->data; in rf2xx_set_txpower()
491 if (conf->tx_pwr_table_size == 1) { in rf2xx_set_txpower()
497 min = conf->tx_pwr_min[1]; in rf2xx_set_txpower()
498 if (conf->tx_pwr_min[0] == 0x01) { in rf2xx_set_txpower()
499 min *= -1.0f; in rf2xx_set_txpower()
502 max = conf->tx_pwr_max[1]; in rf2xx_set_txpower()
503 if (conf->tx_pwr_max[0] == 0x01) { in rf2xx_set_txpower()
504 min *= -1.0f; in rf2xx_set_txpower()
507 step = (max - min) / ((float)conf->tx_pwr_table_size - 1.0f); in rf2xx_set_txpower()
513 LOG_DBG("Tx-power values: min %f, max %f, step %f, entries %d", in rf2xx_set_txpower()
514 (double)min, (double)max, (double)step, conf->tx_pwr_table_size); in rf2xx_set_txpower()
517 LOG_INF("TX-power %d dBm below min of %f dBm, using %f dBm", in rf2xx_set_txpower()
521 LOG_INF("TX-power %d dBm above max of %f dBm, using %f dBm", in rf2xx_set_txpower()
526 idx = abs((int) (((float)(dbm - max) / step))); in rf2xx_set_txpower()
527 LOG_DBG("Tx-power idx: %d", idx); in rf2xx_set_txpower()
529 if (idx >= conf->tx_pwr_table_size) { in rf2xx_set_txpower()
530 idx = conf->tx_pwr_table_size - 1; in rf2xx_set_txpower()
533 val = conf->tx_pwr_table[idx]; in rf2xx_set_txpower()
535 if (ctx->trx_model != RF2XX_TRX_MODEL_212) { in rf2xx_set_txpower()
540 LOG_DBG("Tx-power normalized: %d dBm, PHY_TX_PWR 0x%02x, idx %d", in rf2xx_set_txpower()
616 return rf2xx_set_ieee_addr(dev, set, filter->ieee_addr); in rf2xx_filter()
618 return rf2xx_set_short_addr(dev, set, filter->short_addr); in rf2xx_filter()
620 return rf2xx_set_pan_id(dev, set, filter->pan_id); in rf2xx_filter()
623 return -ENOTSUP; in rf2xx_filter()
629 if ((frag->data[0] & RF2XX_FRAME_CTRL_ACK_REQUEST_BIT) == 0) { in rf2xx_handle_ack()
634 rf2xx_ack_psdu[2] = frag->data[2]; in rf2xx_handle_ack()
636 if (ctx->trx_trac == RF2XX_TRX_PHY_STATE_TRAC_SUCCESS_DATA_PENDING) { in rf2xx_handle_ack()
642 if (ieee802154_handle_ack(ctx->iface, &rf2xx_ack_pkt) != NET_OK) { in rf2xx_handle_ack()
657 struct rf2xx_context *ctx = dev->data; in rf2xx_tx()
662 if (ctx->tx_mode != mode) { in rf2xx_tx()
684 return -ENOTSUP; in rf2xx_tx()
687 ctx->tx_mode = mode; in rf2xx_tx()
693 k_sem_reset(&ctx->trx_tx_sync); in rf2xx_tx()
694 rf2xx_iface_frame_write(dev, frag->data, frag->len); in rf2xx_tx()
696 k_sem_take(&ctx->trx_tx_sync, K_FOREVER); in rf2xx_tx()
698 switch (ctx->trx_trac) { in rf2xx_tx()
700 * CSMA-CA in rf2xx_tx()
703 response = -EBUSY; in rf2xx_tx()
709 response = -EAGAIN; in rf2xx_tx()
713 response = -EINTR; in rf2xx_tx()
734 const struct rf2xx_config *conf = dev->config; in rf2xx_start() local
740 gpio_pin_interrupt_configure_dt(&conf->irq_gpio, in rf2xx_start()
749 const struct rf2xx_config *conf = dev->config; in rf2xx_stop() local
753 gpio_pin_interrupt_configure_dt(&conf->irq_gpio, GPIO_INT_DISABLE); in rf2xx_stop()
779 struct rf2xx_context *ctx = dev->data; in rf2xx_promiscuous_set()
782 ctx->promiscuous = promiscuous; in rf2xx_promiscuous_set()
809 int ret = -EINVAL; in rf2xx_configure()
819 ret = rf2xx_pan_coord_set(dev, config->pan_coordinator); in rf2xx_configure()
823 ret = rf2xx_promiscuous_set(dev, config->promiscuous); in rf2xx_configure()
837 struct rf2xx_context *ctx = dev->data; in rf2xx_attr_get()
841 value->phy_supported_channel_pages = ctx->cc_page; in rf2xx_attr_get()
845 value->phy_supported_channels = &ctx->cc_channels; in rf2xx_attr_get()
849 return -ENOENT; in rf2xx_attr_get()
855 const struct rf2xx_config *conf = dev->config; in power_on_and_setup() local
856 struct rf2xx_context *ctx = dev->data; in power_on_and_setup()
870 ctx->trx_model = rf2xx_iface_reg_read(dev, RF2XX_PART_NUM_REG); in power_on_and_setup()
871 ctx->trx_version = rf2xx_iface_reg_read(dev, RF2XX_VERSION_NUM_REG); in power_on_and_setup()
875 * 231-Rev-A (Version 0x02) in power_on_and_setup()
876 * 232-Rev-A (Version 0x02) in power_on_and_setup()
877 * 233-Rev-A (Version 0x01) (Warning) in power_on_and_setup()
878 * 233-Rev-B (Version 0x02) in power_on_and_setup()
880 if (ctx->trx_model <= RF2XX_TRX_MODEL_230) { in power_on_and_setup()
882 return -ENODEV; in power_on_and_setup()
885 if (ctx->trx_model == RF2XX_TRX_MODEL_233 && ctx->trx_version == 0x01) { in power_on_and_setup()
890 if (ctx->trx_model == RF2XX_TRX_MODEL_212) { in power_on_and_setup()
891 ctx->trx_rssi_base = -100; in power_on_and_setup()
892 } else if (ctx->trx_model == RF2XX_TRX_MODEL_233) { in power_on_and_setup()
893 ctx->trx_rssi_base = -94; in power_on_and_setup()
894 } else if (ctx->trx_model == RF2XX_TRX_MODEL_231) { in power_on_and_setup()
895 ctx->trx_rssi_base = -91; in power_on_and_setup()
897 ctx->trx_rssi_base = -90; in power_on_and_setup()
911 if (ctx->trx_model != RF2XX_TRX_MODEL_232) { in power_on_and_setup()
916 if (ctx->trx_model == RF2XX_TRX_MODEL_212) { in power_on_and_setup()
921 ctx->tx_mode = IEEE802154_TX_MODE_CSMA_CA; in power_on_and_setup()
922 ctx->promiscuous = false; in power_on_and_setup()
929 gpio_init_callback(&ctx->irq_cb, trx_isr_handler, in power_on_and_setup()
930 BIT(conf->irq_gpio.pin)); in power_on_and_setup()
932 if (gpio_add_callback(conf->irq_gpio.port, &ctx->irq_cb) < 0) { in power_on_and_setup()
934 return -ENXIO; in power_on_and_setup()
942 const struct rf2xx_config *conf = dev->config; in configure_gpios() local
945 if (!gpio_is_ready_dt(&conf->irq_gpio)) { in configure_gpios()
947 return -ENODEV; in configure_gpios()
949 gpio_pin_configure_dt(&conf->irq_gpio, GPIO_INPUT); in configure_gpios()
950 gpio_pin_interrupt_configure_dt(&conf->irq_gpio, in configure_gpios()
954 if (!gpio_is_ready_dt(&conf->reset_gpio)) { in configure_gpios()
956 return -ENODEV; in configure_gpios()
958 gpio_pin_configure_dt(&conf->reset_gpio, GPIO_OUTPUT_INACTIVE); in configure_gpios()
961 if (!gpio_is_ready_dt(&conf->slptr_gpio)) { in configure_gpios()
963 return -ENODEV; in configure_gpios()
965 gpio_pin_configure_dt(&conf->slptr_gpio, GPIO_OUTPUT_INACTIVE); in configure_gpios()
968 if (conf->dig2_gpio.port != NULL) { in configure_gpios()
969 if (!gpio_is_ready_dt(&conf->dig2_gpio)) { in configure_gpios()
971 return -ENODEV; in configure_gpios()
974 conf->dig2_gpio.port->name); in configure_gpios()
975 gpio_pin_configure_dt(&conf->dig2_gpio, GPIO_INPUT); in configure_gpios()
976 gpio_pin_interrupt_configure_dt(&conf->dig2_gpio, in configure_gpios()
981 if (conf->clkm_gpio.port != NULL) { in configure_gpios()
982 if (!gpio_is_ready_dt(&conf->clkm_gpio)) { in configure_gpios()
984 return -ENODEV; in configure_gpios()
987 conf->clkm_gpio.port->name); in configure_gpios()
988 gpio_pin_configure_dt(&conf->clkm_gpio, GPIO_INPUT); in configure_gpios()
996 const struct rf2xx_config *conf = dev->config; in configure_spi() local
998 if (!spi_is_ready_dt(&conf->spi)) { in configure_spi()
1000 conf->spi.bus->name); in configure_spi()
1001 return -ENODEV; in configure_spi()
1009 struct rf2xx_context *ctx = dev->data; in rf2xx_init()
1010 const struct rf2xx_config *conf = dev->config; in rf2xx_init() local
1015 ctx->dev = dev; in rf2xx_init()
1017 k_sem_init(&ctx->trx_tx_sync, 0, 1); in rf2xx_init()
1018 k_sem_init(&ctx->trx_isr_lock, 0, 1); in rf2xx_init()
1022 return -EIO; in rf2xx_init()
1027 return -EIO; in rf2xx_init()
1034 return -EIO; in rf2xx_init()
1039 k_thread_create(&ctx->trx_thread, in rf2xx_init()
1040 ctx->trx_stack, in rf2xx_init()
1047 "rf2xx_trx [%d]", conf->inst); in rf2xx_init()
1048 k_thread_name_set(&ctx->trx_thread, thread_name); in rf2xx_init()
1058 struct rf2xx_context *ctx = dev->data; in rf2xx_iface_init()
1063 ctx->iface = iface; in rf2xx_iface_init()
1065 if (ctx->trx_model == RF2XX_TRX_MODEL_212) { in rf2xx_iface_init()
1066 if (ctx->cc_page == IEEE802154_ATTR_PHY_CHANNEL_PAGE_ZERO_OQPSK_2450_BPSK_868_915 || in rf2xx_iface_init()
1067 ctx->cc_page == IEEE802154_ATTR_PHY_CHANNEL_PAGE_TWO_OQPSK_868_915) { in rf2xx_iface_init()
1068 ctx->cc_range.from_channel = 0U; in rf2xx_iface_init()
1069 ctx->cc_range.to_channel = 10U; in rf2xx_iface_init()
1070 } else if (ctx->cc_page == IEEE802154_ATTR_PHY_CHANNEL_PAGE_FIVE_OQPSK_780) { in rf2xx_iface_init()
1071 ctx->cc_range.from_channel = 0U; in rf2xx_iface_init()
1072 ctx->cc_range.to_channel = 3U; in rf2xx_iface_init()
1074 __ASSERT(false, "Unsupported channel page %u.", ctx->cc_page); in rf2xx_iface_init()
1077 __ASSERT(ctx->cc_page == in rf2xx_iface_init()
1079 "Unsupported channel page %u.", ctx->cc_page); in rf2xx_iface_init()
1080 ctx->cc_range.from_channel = 11U; in rf2xx_iface_init()
1081 ctx->cc_range.to_channel = 26U; in rf2xx_iface_init()
1121 "rf2xx: Error TX-PWR-MIN len is different of two"); \
1123 "rf2xx: Error TX-PWR-MAX len is different of two"); \
1125 "rf2xx: Error TX-PWR-TABLE len must be greater than zero"); \