Lines Matching +full:cca +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()
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 sys_rand_get(&cc2520->mac_addr[4], 4U); in get_mac()
284 cc2520->mac_addr[7] = (cc2520->mac_addr[7] & ~0x01) | 0x02; in get_mac()
286 cc2520->mac_addr[4] = CONFIG_IEEE802154_CC2520_MAC4; in get_mac()
287 cc2520->mac_addr[5] = CONFIG_IEEE802154_CC2520_MAC5; in get_mac()
288 cc2520->mac_addr[6] = CONFIG_IEEE802154_CC2520_MAC6; in get_mac()
289 cc2520->mac_addr[7] = CONFIG_IEEE802154_CC2520_MAC7; in get_mac()
292 cc2520->mac_addr[0] = 0x00; in get_mac()
293 cc2520->mac_addr[1] = 0x12; in get_mac()
294 cc2520->mac_addr[2] = 0x4b; in get_mac()
295 cc2520->mac_addr[3] = 0x00; in get_mac()
297 return cc2520->mac_addr; in get_mac()
308 return -EIO; in cc2520_set_pan_id()
323 return -EIO; in cc2520_set_short_addr()
334 return -EIO; in cc2520_set_ieee_addr()
349 const struct cc2520_config *cfg = dev->config; in set_reset()
351 gpio_pin_set_raw(cfg->reset.port, cfg->reset.pin, value); in set_reset()
356 const struct cc2520_config *cfg = dev->config; in set_vreg_en()
358 gpio_pin_set_raw(cfg->vreg_en.port, cfg->vreg_en.pin, value); in set_vreg_en()
363 const struct cc2520_config *cfg = dev->config; in get_fifo()
365 return gpio_pin_get_raw(cfg->fifo.port, cfg->fifo.pin); in get_fifo()
370 const struct cc2520_config *cfg = dev->config; in get_fifop()
372 return gpio_pin_get_raw(cfg->fifop.port, cfg->fifop.pin); in get_fifop()
377 const struct cc2520_config *cfg = dev->config; in get_cca()
379 return gpio_pin_get_raw(cfg->cca.port, cfg->cca.pin); in get_cca()
388 if (atomic_get(&cc2520->tx) == 1) { in sfd_int_handler()
389 atomic_set(&cc2520->tx, 0); in sfd_int_handler()
390 k_sem_give(&cc2520->tx_sync); in sfd_int_handler()
400 /* Note: Errata document - 1.2 */ in fifop_int_handler()
401 if (!get_fifop(cc2520->dev) && !get_fifop(cc2520->dev)) { in fifop_int_handler()
405 if (!get_fifo(cc2520->dev)) { in fifop_int_handler()
406 cc2520->overflow = true; in fifop_int_handler()
409 k_sem_give(&cc2520->rx_lock); in fifop_int_handler()
415 const struct cc2520_config *cfg = dev->config; in enable_fifop_interrupt()
418 gpio_pin_interrupt_configure_dt(&cfg->fifop, mode); in enable_fifop_interrupt()
424 const struct cc2520_config *cfg = dev->config; in enable_sfd_interrupt()
427 gpio_pin_interrupt_configure_dt(&cfg->sfd, mode); in enable_sfd_interrupt()
432 const struct cc2520_config *cfg = dev->config; in setup_gpio_callbacks()
433 struct cc2520_context *cc2520 = dev->data; in setup_gpio_callbacks()
435 gpio_init_callback(&cc2520->sfd_cb, sfd_int_handler, BIT(cfg->sfd.pin)); in setup_gpio_callbacks()
436 if (gpio_add_callback(cfg->sfd.port, &cc2520->sfd_cb) != 0) { in setup_gpio_callbacks()
437 return -EIO; in setup_gpio_callbacks()
441 gpio_init_callback(&cc2520->fifop_cb, fifop_int_handler, BIT(cfg->fifop.pin)); in setup_gpio_callbacks()
442 if (gpio_add_callback(cfg->fifop.port, &cc2520->fifop_cb) != 0) { in setup_gpio_callbacks()
443 return -EIO; in setup_gpio_callbacks()
484 timeout--; in verify_tx_done()
497 /* Note: Errata document - 1.1 */ in flush_rxfifo()
523 if (!z_cc2520_access(dev, true, CC2520_INS_RXBUF, 0, buf->data, len)) { in read_rxfifo_content()
551 * lqi = (lqi - 50) * 4 in insert_radio_noise_details()
559 lqi = (lqi - 50U) << 2; in insert_radio_noise_details()
598 struct cc2520_context *cc2520 = dev->data; in cc2520_rx()
605 k_sem_take(&cc2520->rx_lock, K_FOREVER); in cc2520_rx()
607 if (cc2520->overflow) { in cc2520_rx()
609 cc2520->overflow = false; in cc2520_rx()
620 pkt = net_pkt_rx_alloc_with_buffer(cc2520->iface, pkt_len, in cc2520_rx()
628 pkt_len -= 2U; in cc2520_rx()
631 if (!read_rxfifo_content(dev, pkt->buffer, pkt_len)) { in cc2520_rx()
641 if (ieee802154_handle_ack(cc2520->iface, pkt) == NET_OK) { in cc2520_rx()
648 if (net_recv_data(cc2520->iface, pkt) < 0) { in cc2520_rx()
653 log_stack_usage(&cc2520->cc2520_rx_thread); in cc2520_rx()
680 return -EBUSY; in cc2520_cca()
691 return -EINVAL; in cc2520_set_channel()
695 return -ENOTSUP; in cc2520_set_channel()
699 channel = 11 + (channel - 11) * 5U; in cc2520_set_channel()
703 return -EIO; in cc2520_set_channel()
717 return -ENOTSUP; in cc2520_filter()
721 return cc2520_set_ieee_addr(dev, filter->ieee_addr); in cc2520_filter()
723 return cc2520_set_short_addr(dev, filter->short_addr); in cc2520_filter()
725 return cc2520_set_pan_id(dev, filter->pan_id); in cc2520_filter()
728 return -ENOTSUP; in cc2520_filter()
754 case -2: in cc2520_set_txpower()
757 case -4: in cc2520_set_txpower()
760 case -7: in cc2520_set_txpower()
763 case -18: in cc2520_set_txpower()
777 return -EIO; in cc2520_set_txpower()
785 uint8_t *frame = frag->data; in cc2520_tx()
786 uint8_t len = frag->len; in cc2520_tx()
787 struct cc2520_context *cc2520 = dev->data; in cc2520_tx()
793 return -ENOTSUP; in cc2520_tx()
811 k_sem_take(&cc2520->access_lock, K_FOREVER); in cc2520_tx()
816 atomic_set(&cc2520->tx, 1); in cc2520_tx()
817 k_sem_init(&cc2520->tx_sync, 0, K_SEM_MAX_LIMIT); in cc2520_tx()
825 k_sem_take(&cc2520->tx_sync, K_MSEC(10)); in cc2520_tx()
827 retry--; in cc2520_tx()
832 k_sem_give(&cc2520->access_lock); in cc2520_tx()
841 k_sem_give(&cc2520->access_lock); in cc2520_tx()
847 atomic_set(&cc2520->tx, 0); in cc2520_tx()
850 return -EIO; in cc2520_tx()
859 return -EIO; in cc2520_start()
880 return -EIO; in cc2520_stop()
886 /* driver-allocated attribute memory - constant across all driver instances */
919 return -EIO; in power_on_and_setup()
934 return -EIO; in power_on_and_setup()
953 return -EIO; in power_on_and_setup()
960 return -EIO; in power_on_and_setup()
970 const struct cc2520_config *cfg = dev->config; in configure_gpios()
972 if (!gpio_is_ready_dt(&cfg->vreg_en) || in configure_gpios()
973 !gpio_is_ready_dt(&cfg->reset) || in configure_gpios()
974 !gpio_is_ready_dt(&cfg->fifo) || in configure_gpios()
975 !gpio_is_ready_dt(&cfg->cca) || in configure_gpios()
976 !gpio_is_ready_dt(&cfg->sfd) || in configure_gpios()
977 !gpio_is_ready_dt(&cfg->fifop)) { in configure_gpios()
978 return -ENODEV; in configure_gpios()
981 gpio_pin_configure_dt(&cfg->vreg_en, GPIO_OUTPUT_LOW); in configure_gpios()
982 gpio_pin_configure_dt(&cfg->reset, GPIO_OUTPUT_LOW); in configure_gpios()
983 gpio_pin_configure_dt(&cfg->fifo, GPIO_INPUT); in configure_gpios()
984 gpio_pin_configure_dt(&cfg->cca, GPIO_INPUT); in configure_gpios()
985 gpio_pin_configure_dt(&cfg->sfd, GPIO_INPUT); in configure_gpios()
986 gpio_pin_configure_dt(&cfg->fifop, GPIO_INPUT); in configure_gpios()
993 const struct cc2520_config *cfg = dev->config; in cc2520_init()
994 struct cc2520_context *cc2520 = dev->data; in cc2520_init()
996 cc2520->dev = dev; in cc2520_init()
998 atomic_set(&cc2520->tx, 0); in cc2520_init()
999 k_sem_init(&cc2520->rx_lock, 0, K_SEM_MAX_LIMIT); in cc2520_init()
1002 k_sem_init(&cc2520->access_lock, 1, 1); in cc2520_init()
1006 LOG_ERR("Configuring GPIOS failed"); in cc2520_init()
1007 return -EIO; in cc2520_init()
1010 if (!spi_is_ready_dt(&cfg->bus)) { in cc2520_init()
1011 LOG_ERR("SPI bus %s not ready", cfg->bus.bus->name); in cc2520_init()
1012 return -EIO; in cc2520_init()
1019 return -EIO; in cc2520_init()
1022 k_thread_create(&cc2520->cc2520_rx_thread, cc2520->cc2520_rx_stack, in cc2520_init()
1026 k_thread_name_set(&cc2520->cc2520_rx_thread, "cc2520_rx"); in cc2520_init()
1036 struct cc2520_context *cc2520 = dev->data; in cc2520_iface_init()
1041 cc2520->iface = iface; in cc2520_iface_init()
1051 .cca = GPIO_DT_SPEC_INST_GET(0, cca_gpios),
1062 .cca = cc2520_cca,
1110 const struct cc2520_config *cfg = dev->config; in instruct_uccm_ccm()
1111 struct cc2520_context *ctx = dev->data; in instruct_uccm_ccm()
1142 k_sem_take(&ctx->access_lock, K_FOREVER); in instruct_uccm_ccm()
1144 ret = spi_write_dt(&cfg->bus, &tx); in instruct_uccm_ccm()
1146 k_sem_give(&ctx->access_lock); in instruct_uccm_ccm()
1159 nonce[0] = 0 | (apkt->ad_len ? 0x40 : 0) | (m << 3) | 1; in generate_nonce()
1163 nonce[14] = (uint8_t)(apkt->pkt->in_len >> 8); in generate_nonce()
1164 nonce[15] = (uint8_t)(apkt->pkt->in_len); in generate_nonce()
1174 const struct device *cc2520 = ctx->device; in insert_crypto_parameters()
1180 if (!apkt->pkt->out_buf || !apkt->pkt->out_buf_max) { in insert_crypto_parameters()
1182 return -EINVAL; in insert_crypto_parameters()
1185 if (!ctx->key.bit_stream || !ctx->keylen) { in insert_crypto_parameters()
1187 return -EINVAL; in insert_crypto_parameters()
1190 if (!(ctx->flags & CAP_INPLACE_OPS)) { in insert_crypto_parameters()
1191 LOG_ERR("It supports only in-place operation"); in insert_crypto_parameters()
1192 return -EINVAL; in insert_crypto_parameters()
1195 if (!apkt->ad || !apkt->ad_len) { in insert_crypto_parameters()
1197 return -EINVAL; in insert_crypto_parameters()
1200 if (apkt->pkt->in_buf && apkt->pkt->in_buf - apkt->ad_len != apkt->ad) { in insert_crypto_parameters()
1201 LOG_ERR("In-place needs ad and input in same memory"); in insert_crypto_parameters()
1202 return -EINVAL; in insert_crypto_parameters()
1205 if (!apkt->pkt->in_buf) { in insert_crypto_parameters()
1206 if (!ctx->mode_params.ccm_info.tag_len) { in insert_crypto_parameters()
1208 return -EINVAL; in insert_crypto_parameters()
1211 in_buf = apkt->ad; in insert_crypto_parameters()
1212 in_len = apkt->ad_len; in insert_crypto_parameters()
1218 memcpy(in_buf, apkt->ad, apkt->ad_len); in insert_crypto_parameters()
1219 memcpy(in_buf + apkt->ad_len, in insert_crypto_parameters()
1220 apkt->pkt->in_buf, apkt->pkt->in_len); in insert_crypto_parameters()
1221 in_len = apkt->ad_len + apkt->pkt->in_len; in insert_crypto_parameters()
1223 *auth_crypt = !apkt->tag ? apkt->pkt->in_len : in insert_crypto_parameters()
1224 apkt->pkt->in_len - ctx->mode_params.ccm_info.tag_len; in insert_crypto_parameters()
1227 if (ctx->mode_params.ccm_info.tag_len) { in insert_crypto_parameters()
1228 if ((ctx->mode_params.ccm_info.tag_len >> 2) > 3) { in insert_crypto_parameters()
1231 m = ctx->mode_params.ccm_info.tag_len >> 2; in insert_crypto_parameters()
1238 return -EIO; in insert_crypto_parameters()
1242 sys_memcpy_swap(data, ctx->key.bit_stream, ctx->keylen); in insert_crypto_parameters()
1247 return -EIO; in insert_crypto_parameters()
1255 return -EIO; in insert_crypto_parameters()
1265 const struct device *cc2520 = ctx->device; in cc2520_crypto_ccm()
1269 if (!apkt || !apkt->pkt) { in cc2520_crypto_ccm()
1271 return -EINVAL; in cc2520_crypto_ccm()
1280 apkt->pkt->out_len = apkt->pkt->in_len + apkt->ad_len + in cc2520_crypto_ccm()
1281 (m ? ctx->mode_params.ccm_info.tag_len : 0); in cc2520_crypto_ccm()
1283 if (apkt->pkt->out_len > apkt->pkt->out_buf_max) { in cc2520_crypto_ccm()
1285 apkt->pkt->out_len, apkt->pkt->out_buf_max); in cc2520_crypto_ccm()
1286 return -ENOBUFS; in cc2520_crypto_ccm()
1291 0x000, apkt->ad_len, m) || in cc2520_crypto_ccm()
1293 apkt->pkt->out_buf, apkt->pkt->out_len)) { in cc2520_crypto_ccm()
1295 return -EIO; in cc2520_crypto_ccm()
1298 if (apkt->tag) { in cc2520_crypto_ccm()
1299 memcpy(apkt->tag, apkt->pkt->out_buf + apkt->pkt->in_len, in cc2520_crypto_ccm()
1300 ctx->mode_params.ccm_info.tag_len); in cc2520_crypto_ccm()
1310 const struct device *cc2520 = ctx->device; in cc2520_crypto_uccm()
1314 if (!apkt || !apkt->pkt) { in cc2520_crypto_uccm()
1316 return -EINVAL; in cc2520_crypto_uccm()
1319 if (ctx->mode_params.ccm_info.tag_len && !apkt->tag) { in cc2520_crypto_uccm()
1321 return -EINVAL; in cc2520_crypto_uccm()
1329 apkt->pkt->out_len = apkt->pkt->in_len + apkt->ad_len; in cc2520_crypto_uccm()
1333 0x000, apkt->ad_len, m) || in cc2520_crypto_uccm()
1335 apkt->pkt->out_buf, apkt->pkt->out_len)) { in cc2520_crypto_uccm()
1337 return -EIO; in cc2520_crypto_uccm()
1342 return -EBADMSG; in cc2520_crypto_uccm()
1361 return -EINVAL; in cc2520_crypto_begin_session()
1364 if (ctx->mode_params.ccm_info.nonce_len != 13U) { in cc2520_crypto_begin_session()
1366 ctx->mode_params.ccm_info.nonce_len); in cc2520_crypto_begin_session()
1367 return -EINVAL; in cc2520_crypto_begin_session()
1371 ctx->ops.ccm_crypt_hndlr = cc2520_crypto_ccm; in cc2520_crypto_begin_session()
1373 ctx->ops.ccm_crypt_hndlr = cc2520_crypto_uccm; in cc2520_crypto_begin_session()
1376 ctx->ops.cipher_mode = mode; in cc2520_crypto_begin_session()
1377 ctx->device = dev; in cc2520_crypto_begin_session()
1387 ctx->ops.ccm_crypt_hndlr = NULL; in cc2520_crypto_free_session()
1388 ctx->device = NULL; in cc2520_crypto_free_session()