Lines Matching +full:sfd +full:- +full:gpios
1 /* ieee802154_cc2520.c - TI CC2520 driver */
8 * SPDX-License-Identifier: Apache-2.0
47 * 1 - Debug related functions
48 * 2 - Generic helper functions (for any parts)
49 * 3 - GPIO related functions
50 * 4 - TX related helper functions
51 * 5 - RX related helper functions
52 * 6 - Radio device API functions
53 * 7 - Legacy radio device API functions
54 * 8 - Initialization
68 struct cc2520_context *cc2520 = dev->data; in cc2520_print_gpio_config()
146 LOG_DBG(" SFD"); in cc2520_print_exceptions()
207 const struct cc2520_config *cfg = dev->config; in z_cc2520_access()
243 return (spi_transceive_dt(&cfg->bus, &tx, &rx) == 0); in z_cc2520_access()
248 return (spi_write_dt(&cfg->bus, &tx) == 0); in z_cc2520_access()
270 timeout--; in verify_osc_stabilization()
279 struct cc2520_context *cc2520 = dev->data; in get_mac()
282 uint32_t *ptr = (uint32_t *)(cc2520->mac_addr + 4); in get_mac()
286 cc2520->mac_addr[7] = (cc2520->mac_addr[7] & ~0x01) | 0x02; in get_mac()
288 cc2520->mac_addr[4] = CONFIG_IEEE802154_CC2520_MAC4; in get_mac()
289 cc2520->mac_addr[5] = CONFIG_IEEE802154_CC2520_MAC5; in get_mac()
290 cc2520->mac_addr[6] = CONFIG_IEEE802154_CC2520_MAC6; in get_mac()
291 cc2520->mac_addr[7] = CONFIG_IEEE802154_CC2520_MAC7; in get_mac()
294 cc2520->mac_addr[0] = 0x00; in get_mac()
295 cc2520->mac_addr[1] = 0x12; in get_mac()
296 cc2520->mac_addr[2] = 0x4b; in get_mac()
297 cc2520->mac_addr[3] = 0x00; in get_mac()
299 return cc2520->mac_addr; in get_mac()
310 return -EIO; in cc2520_set_pan_id()
325 return -EIO; in cc2520_set_short_addr()
336 return -EIO; in cc2520_set_ieee_addr()
351 const struct cc2520_config *cfg = dev->config; in set_reset()
353 gpio_pin_set_raw(cfg->reset.port, cfg->reset.pin, value); in set_reset()
358 const struct cc2520_config *cfg = dev->config; in set_vreg_en()
360 gpio_pin_set_raw(cfg->vreg_en.port, cfg->vreg_en.pin, value); in set_vreg_en()
365 const struct cc2520_config *cfg = dev->config; in get_fifo()
367 return gpio_pin_get_raw(cfg->fifo.port, cfg->fifo.pin); in get_fifo()
372 const struct cc2520_config *cfg = dev->config; in get_fifop()
374 return gpio_pin_get_raw(cfg->fifop.port, cfg->fifop.pin); in get_fifop()
379 const struct cc2520_config *cfg = dev->config; in get_cca()
381 return gpio_pin_get_raw(cfg->cca.port, cfg->cca.pin); in get_cca()
390 if (atomic_get(&cc2520->tx) == 1) { in sfd_int_handler()
391 atomic_set(&cc2520->tx, 0); in sfd_int_handler()
392 k_sem_give(&cc2520->tx_sync); in sfd_int_handler()
402 /* Note: Errata document - 1.2 */ in fifop_int_handler()
403 if (!get_fifop(cc2520->dev) && !get_fifop(cc2520->dev)) { in fifop_int_handler()
407 if (!get_fifo(cc2520->dev)) { in fifop_int_handler()
408 cc2520->overflow = true; in fifop_int_handler()
411 k_sem_give(&cc2520->rx_lock); in fifop_int_handler()
417 const struct cc2520_config *cfg = dev->config; in enable_fifop_interrupt()
420 gpio_pin_interrupt_configure_dt(&cfg->fifop, mode); in enable_fifop_interrupt()
426 const struct cc2520_config *cfg = dev->config; in enable_sfd_interrupt()
429 gpio_pin_interrupt_configure_dt(&cfg->sfd, mode); in enable_sfd_interrupt()
434 const struct cc2520_config *cfg = dev->config; in setup_gpio_callbacks()
435 struct cc2520_context *cc2520 = dev->data; in setup_gpio_callbacks()
437 gpio_init_callback(&cc2520->sfd_cb, sfd_int_handler, BIT(cfg->sfd.pin)); in setup_gpio_callbacks()
438 if (gpio_add_callback(cfg->sfd.port, &cc2520->sfd_cb) != 0) { in setup_gpio_callbacks()
439 return -EIO; in setup_gpio_callbacks()
443 gpio_init_callback(&cc2520->fifop_cb, fifop_int_handler, BIT(cfg->fifop.pin)); in setup_gpio_callbacks()
444 if (gpio_add_callback(cfg->fifop.port, &cc2520->fifop_cb) != 0) { in setup_gpio_callbacks()
445 return -EIO; in setup_gpio_callbacks()
486 timeout--; in verify_tx_done()
499 /* Note: Errata document - 1.1 */ in flush_rxfifo()
525 if (!z_cc2520_access(dev, true, CC2520_INS_RXBUF, 0, buf->data, len)) { in read_rxfifo_content()
553 * lqi = (lqi - 50) * 4 in insert_radio_noise_details()
561 lqi = (lqi - 50U) << 2; in insert_radio_noise_details()
597 struct cc2520_context *cc2520 = dev->data; in cc2520_rx()
604 k_sem_take(&cc2520->rx_lock, K_FOREVER); in cc2520_rx()
606 if (cc2520->overflow) { in cc2520_rx()
608 cc2520->overflow = false; in cc2520_rx()
619 pkt = net_pkt_rx_alloc_with_buffer(cc2520->iface, pkt_len, in cc2520_rx()
627 pkt_len -= 2U; in cc2520_rx()
630 if (!read_rxfifo_content(dev, pkt->buffer, pkt_len)) { in cc2520_rx()
640 if (ieee802154_handle_ack(cc2520->iface, pkt) == NET_OK) { in cc2520_rx()
647 if (net_recv_data(cc2520->iface, pkt) < 0) { in cc2520_rx()
652 log_stack_usage(&cc2520->cc2520_rx_thread); in cc2520_rx()
679 return -EBUSY; in cc2520_cca()
690 return -EINVAL; in cc2520_set_channel()
694 return -ENOTSUP; in cc2520_set_channel()
698 channel = 11 + (channel - 11) * 5U; in cc2520_set_channel()
702 return -EIO; in cc2520_set_channel()
716 return -ENOTSUP; in cc2520_filter()
720 return cc2520_set_ieee_addr(dev, filter->ieee_addr); in cc2520_filter()
722 return cc2520_set_short_addr(dev, filter->short_addr); in cc2520_filter()
724 return cc2520_set_pan_id(dev, filter->pan_id); in cc2520_filter()
727 return -ENOTSUP; in cc2520_filter()
753 case -2: in cc2520_set_txpower()
756 case -4: in cc2520_set_txpower()
759 case -7: in cc2520_set_txpower()
762 case -18: in cc2520_set_txpower()
776 return -EIO; in cc2520_set_txpower()
784 uint8_t *frame = frag->data; in cc2520_tx()
785 uint8_t len = frag->len; in cc2520_tx()
786 struct cc2520_context *cc2520 = dev->data; in cc2520_tx()
792 return -ENOTSUP; in cc2520_tx()
810 k_sem_take(&cc2520->access_lock, K_FOREVER); in cc2520_tx()
815 atomic_set(&cc2520->tx, 1); in cc2520_tx()
816 k_sem_init(&cc2520->tx_sync, 0, K_SEM_MAX_LIMIT); in cc2520_tx()
824 k_sem_take(&cc2520->tx_sync, K_MSEC(10)); in cc2520_tx()
826 retry--; in cc2520_tx()
831 k_sem_give(&cc2520->access_lock); in cc2520_tx()
840 k_sem_give(&cc2520->access_lock); in cc2520_tx()
846 atomic_set(&cc2520->tx, 0); in cc2520_tx()
849 return -EIO; in cc2520_tx()
858 return -EIO; in cc2520_start()
879 return -EIO; in cc2520_stop()
885 /* driver-allocated attribute memory - constant across all driver instances */
918 return -EIO; in power_on_and_setup()
933 return -EIO; in power_on_and_setup()
952 return -EIO; in power_on_and_setup()
959 return -EIO; in power_on_and_setup()
969 const struct cc2520_config *cfg = dev->config; in configure_gpios()
971 if (!gpio_is_ready_dt(&cfg->vreg_en) || in configure_gpios()
972 !gpio_is_ready_dt(&cfg->reset) || in configure_gpios()
973 !gpio_is_ready_dt(&cfg->fifo) || in configure_gpios()
974 !gpio_is_ready_dt(&cfg->cca) || in configure_gpios()
975 !gpio_is_ready_dt(&cfg->sfd) || in configure_gpios()
976 !gpio_is_ready_dt(&cfg->fifop)) { in configure_gpios()
977 return -ENODEV; in configure_gpios()
980 gpio_pin_configure_dt(&cfg->vreg_en, GPIO_OUTPUT_LOW); in configure_gpios()
981 gpio_pin_configure_dt(&cfg->reset, GPIO_OUTPUT_LOW); in configure_gpios()
982 gpio_pin_configure_dt(&cfg->fifo, GPIO_INPUT); in configure_gpios()
983 gpio_pin_configure_dt(&cfg->cca, GPIO_INPUT); in configure_gpios()
984 gpio_pin_configure_dt(&cfg->sfd, GPIO_INPUT); in configure_gpios()
985 gpio_pin_configure_dt(&cfg->fifop, GPIO_INPUT); in configure_gpios()
992 const struct cc2520_config *cfg = dev->config; in cc2520_init()
993 struct cc2520_context *cc2520 = dev->data; in cc2520_init()
995 cc2520->dev = dev; in cc2520_init()
997 atomic_set(&cc2520->tx, 0); in cc2520_init()
998 k_sem_init(&cc2520->rx_lock, 0, K_SEM_MAX_LIMIT); in cc2520_init()
1001 k_sem_init(&cc2520->access_lock, 1, 1); in cc2520_init()
1005 LOG_ERR("Configuring GPIOS failed"); in cc2520_init()
1006 return -EIO; in cc2520_init()
1009 if (!spi_is_ready_dt(&cfg->bus)) { in cc2520_init()
1010 LOG_ERR("SPI bus %s not ready", cfg->bus.bus->name); in cc2520_init()
1011 return -EIO; in cc2520_init()
1018 return -EIO; in cc2520_init()
1021 k_thread_create(&cc2520->cc2520_rx_thread, cc2520->cc2520_rx_stack, in cc2520_init()
1025 k_thread_name_set(&cc2520->cc2520_rx_thread, "cc2520_rx"); in cc2520_init()
1035 struct cc2520_context *cc2520 = dev->data; in cc2520_iface_init()
1040 cc2520->iface = iface; in cc2520_iface_init()
1051 .sfd = GPIO_DT_SPEC_INST_GET(0, sfd_gpios),
1109 const struct cc2520_config *cfg = dev->config; in instruct_uccm_ccm()
1110 struct cc2520_context *ctx = dev->data; in instruct_uccm_ccm()
1141 k_sem_take(&ctx->access_lock, K_FOREVER); in instruct_uccm_ccm()
1143 ret = spi_write_dt(&cfg->bus, &tx); in instruct_uccm_ccm()
1145 k_sem_give(&ctx->access_lock); in instruct_uccm_ccm()
1158 nonce[0] = 0 | (apkt->ad_len ? 0x40 : 0) | (m << 3) | 1; in generate_nonce()
1162 nonce[14] = (uint8_t)(apkt->pkt->in_len >> 8); in generate_nonce()
1163 nonce[15] = (uint8_t)(apkt->pkt->in_len); in generate_nonce()
1173 const struct device *cc2520 = ctx->device; in insert_crypto_parameters()
1179 if (!apkt->pkt->out_buf || !apkt->pkt->out_buf_max) { in insert_crypto_parameters()
1181 return -EINVAL; in insert_crypto_parameters()
1184 if (!ctx->key.bit_stream || !ctx->keylen) { in insert_crypto_parameters()
1186 return -EINVAL; in insert_crypto_parameters()
1189 if (!(ctx->flags & CAP_INPLACE_OPS)) { in insert_crypto_parameters()
1190 LOG_ERR("It supports only in-place operation"); in insert_crypto_parameters()
1191 return -EINVAL; in insert_crypto_parameters()
1194 if (!apkt->ad || !apkt->ad_len) { in insert_crypto_parameters()
1196 return -EINVAL; in insert_crypto_parameters()
1199 if (apkt->pkt->in_buf && apkt->pkt->in_buf - apkt->ad_len != apkt->ad) { in insert_crypto_parameters()
1200 LOG_ERR("In-place needs ad and input in same memory"); in insert_crypto_parameters()
1201 return -EINVAL; in insert_crypto_parameters()
1204 if (!apkt->pkt->in_buf) { in insert_crypto_parameters()
1205 if (!ctx->mode_params.ccm_info.tag_len) { in insert_crypto_parameters()
1207 return -EINVAL; in insert_crypto_parameters()
1210 in_buf = apkt->ad; in insert_crypto_parameters()
1211 in_len = apkt->ad_len; in insert_crypto_parameters()
1217 memcpy(in_buf, apkt->ad, apkt->ad_len); in insert_crypto_parameters()
1218 memcpy(in_buf + apkt->ad_len, in insert_crypto_parameters()
1219 apkt->pkt->in_buf, apkt->pkt->in_len); in insert_crypto_parameters()
1220 in_len = apkt->ad_len + apkt->pkt->in_len; in insert_crypto_parameters()
1222 *auth_crypt = !apkt->tag ? apkt->pkt->in_len : in insert_crypto_parameters()
1223 apkt->pkt->in_len - ctx->mode_params.ccm_info.tag_len; in insert_crypto_parameters()
1226 if (ctx->mode_params.ccm_info.tag_len) { in insert_crypto_parameters()
1227 if ((ctx->mode_params.ccm_info.tag_len >> 2) > 3) { in insert_crypto_parameters()
1230 m = ctx->mode_params.ccm_info.tag_len >> 2; in insert_crypto_parameters()
1237 return -EIO; in insert_crypto_parameters()
1241 sys_memcpy_swap(data, ctx->key.bit_stream, ctx->keylen); in insert_crypto_parameters()
1246 return -EIO; in insert_crypto_parameters()
1254 return -EIO; in insert_crypto_parameters()
1264 const struct device *cc2520 = ctx->device; in cc2520_crypto_ccm()
1268 if (!apkt || !apkt->pkt) { in cc2520_crypto_ccm()
1270 return -EINVAL; in cc2520_crypto_ccm()
1279 apkt->pkt->out_len = apkt->pkt->in_len + apkt->ad_len + in cc2520_crypto_ccm()
1280 (m ? ctx->mode_params.ccm_info.tag_len : 0); in cc2520_crypto_ccm()
1282 if (apkt->pkt->out_len > apkt->pkt->out_buf_max) { in cc2520_crypto_ccm()
1284 apkt->pkt->out_len, apkt->pkt->out_buf_max); in cc2520_crypto_ccm()
1285 return -ENOBUFS; in cc2520_crypto_ccm()
1290 0x000, apkt->ad_len, m) || in cc2520_crypto_ccm()
1292 apkt->pkt->out_buf, apkt->pkt->out_len)) { in cc2520_crypto_ccm()
1294 return -EIO; in cc2520_crypto_ccm()
1297 if (apkt->tag) { in cc2520_crypto_ccm()
1298 memcpy(apkt->tag, apkt->pkt->out_buf + apkt->pkt->in_len, in cc2520_crypto_ccm()
1299 ctx->mode_params.ccm_info.tag_len); in cc2520_crypto_ccm()
1309 const struct device *cc2520 = ctx->device; in cc2520_crypto_uccm()
1313 if (!apkt || !apkt->pkt) { in cc2520_crypto_uccm()
1315 return -EINVAL; in cc2520_crypto_uccm()
1318 if (ctx->mode_params.ccm_info.tag_len && !apkt->tag) { in cc2520_crypto_uccm()
1320 return -EINVAL; in cc2520_crypto_uccm()
1328 apkt->pkt->out_len = apkt->pkt->in_len + apkt->ad_len; in cc2520_crypto_uccm()
1332 0x000, apkt->ad_len, m) || in cc2520_crypto_uccm()
1334 apkt->pkt->out_buf, apkt->pkt->out_len)) { in cc2520_crypto_uccm()
1336 return -EIO; in cc2520_crypto_uccm()
1341 return -EBADMSG; in cc2520_crypto_uccm()
1360 return -EINVAL; in cc2520_crypto_begin_session()
1363 if (ctx->mode_params.ccm_info.nonce_len != 13U) { in cc2520_crypto_begin_session()
1365 ctx->mode_params.ccm_info.nonce_len); in cc2520_crypto_begin_session()
1366 return -EINVAL; in cc2520_crypto_begin_session()
1370 ctx->ops.ccm_crypt_hndlr = cc2520_crypto_ccm; in cc2520_crypto_begin_session()
1372 ctx->ops.ccm_crypt_hndlr = cc2520_crypto_uccm; in cc2520_crypto_begin_session()
1375 ctx->ops.cipher_mode = mode; in cc2520_crypto_begin_session()
1376 ctx->device = dev; in cc2520_crypto_begin_session()
1386 ctx->ops.ccm_crypt_hndlr = NULL; in cc2520_crypto_free_session()
1387 ctx->device = NULL; in cc2520_crypto_free_session()