andrzej-kaczmarek commented on a change in pull request #841: URL: https://github.com/apache/mynewt-nimble/pull/841#discussion_r450879340
########## File path: nimble/drivers/nrf5340/src/ble_phy.c ########## @@ -0,0 +1,2001 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +#include <stdint.h> +#include <string.h> +#include <assert.h> +#include <syscfg/syscfg.h> +#include <os/os.h> +#include <nimble/ble.h> +#include <nimble/nimble_opt.h> +#include <nimble/nimble_npl.h> +#include <controller/ble_phy.h> + +#include <ble/xcvr.h> +#include <controller/ble_phy_trace.h> +#include <controller/ble_ll.h> +#include <mcu/nrf5340_net_clock.h> +#include <mcu/cmsis_nvic.h> + +/* + * NOTE: This code uses 1-6 DPPI channels so care should be taken when using + * DPPI somewhere else. + * TODO maybe we could reduce number of used channels if we reuse same channel + * for mutually exclusive events but for now make it simpler to debug. + */ + +#define DPPI_CH_TIMER0_EVENTS_COMPARE_0 DPPIC_CHEN_CH0_Pos +#define DPPI_CH_TIMER0_EVENTS_COMPARE_3 DPPIC_CHEN_CH1_Pos +#define DPPI_CH_RADIO_EVENTS_END DPPIC_CHEN_CH2_Pos +#define DPPI_CH_RADIO_EVENTS_BCMATCH DPPIC_CHEN_CH3_Pos +#define DPPI_CH_RADIO_EVENTS_ADDRESS DPPIC_CHEN_CH4_Pos +#define DPPI_CH_RTC0_EVENTS_COMPARE_0 DPPIC_CHEN_CH5_Pos + +#define DPPI_CH_ENABLE_ALL (DPPIC_CHEN_CH0_Msk | DPPIC_CHEN_CH1_Msk | DPPIC_CHEN_CH2_Msk | \ + DPPIC_CHEN_CH3_Msk | DPPIC_CHEN_CH4_Msk | DPPIC_CHEN_CH5_Msk) + +#define DPPI_PUBLISH_TIMER0_EVENTS_COMPARE_0 ((DPPI_CH_TIMER0_EVENTS_COMPARE_0 << TIMER_PUBLISH_COMPARE_CHIDX_Pos) | \ + (TIMER_PUBLISH_COMPARE_EN_Enabled << TIMER_PUBLISH_COMPARE_EN_Pos)) +#define DPPI_PUBLISH_TIMER0_EVENTS_COMPARE_3 ((DPPI_CH_TIMER0_EVENTS_COMPARE_3 << TIMER_PUBLISH_COMPARE_CHIDX_Pos) | \ + (TIMER_PUBLISH_COMPARE_EN_Enabled << TIMER_PUBLISH_COMPARE_EN_Pos)) +#define DPPI_PUBLISH_RADIO_EVENTS_END ((DPPI_CH_RADIO_EVENTS_END << RADIO_PUBLISH_END_CHIDX_Pos) | \ + (RADIO_PUBLISH_END_EN_Enabled << RADIO_PUBLISH_END_EN_Pos)) +#define DPPI_PUBLISH_RADIO_EVENTS_BCMATCH ((DPPI_CH_RADIO_EVENTS_BCMATCH << RADIO_PUBLISH_BCMATCH_CHIDX_Pos) | \ + (RADIO_PUBLISH_BCMATCH_EN_Enabled << RADIO_PUBLISH_BCMATCH_EN_Pos)) +#define DPPI_PUBLISH_RADIO_EVENTS_ADDRESS ((DPPI_CH_RADIO_EVENTS_ADDRESS << RADIO_PUBLISH_ADDRESS_CHIDX_Pos) | \ + (RADIO_PUBLISH_ADDRESS_EN_Enabled << RADIO_PUBLISH_ADDRESS_EN_Pos)) +#define DPPI_PUBLISH_RTC0_EVENTS_COMPARE_0 ((DPPI_CH_RTC0_EVENTS_COMPARE_0 << RTC_PUBLISH_COMPARE_CHIDX_Pos) | \ + (RTC_PUBLISH_COMPARE_EN_Enabled << RTC_PUBLISH_COMPARE_EN_Pos)) + +#define DPPI_SUBSCRIBE_TIMER0_TASKS_START ((DPPI_CH_RTC0_EVENTS_COMPARE_0 << TIMER_SUBSCRIBE_START_CHIDX_Pos) | \ + (TIMER_SUBSCRIBE_START_EN_Enabled << TIMER_SUBSCRIBE_START_EN_Pos)) +#define DPPI_SUBSCRIBE_TIMER0_TASKS_CAPTURE1 ((DPPI_CH_RADIO_EVENTS_ADDRESS << TIMER_SUBSCRIBE_CAPTURE_CHIDX_Pos) | \ + (TIMER_SUBSCRIBE_CAPTURE_EN_Enabled << TIMER_SUBSCRIBE_CAPTURE_EN_Pos)) +#define DPPI_SUBSCRIBE_TIMER0_TASKS_CAPTURE2 ((DPPI_CH_RADIO_EVENTS_END << TIMER_SUBSCRIBE_CAPTURE_CHIDX_Pos) | \ + (TIMER_SUBSCRIBE_CAPTURE_EN_Enabled << TIMER_SUBSCRIBE_CAPTURE_EN_Pos)) +#define DPPI_SUBSCRIBE_TIMER0_TASKS_CAPTURE3 ((DPPI_CH_RADIO_EVENTS_ADDRESS << TIMER_SUBSCRIBE_CAPTURE_CHIDX_Pos) | \ + (TIMER_SUBSCRIBE_CAPTURE_EN_Enabled << TIMER_SUBSCRIBE_CAPTURE_EN_Pos)) +#define DPPI_SUBSCRIBE_RADIO_TASKS_DISABLE ((DPPI_CH_TIMER0_EVENTS_COMPARE_3 << RADIO_SUBSCRIBE_DISABLE_CHIDX_Pos) | \ + (RADIO_SUBSCRIBE_DISABLE_EN_Enabled << RADIO_SUBSCRIBE_DISABLE_EN_Pos)) +#define DPPI_SUBSCRIBE_RADIO_TASKS_RXEN ((DPPI_CH_TIMER0_EVENTS_COMPARE_0 << RADIO_SUBSCRIBE_RXEN_CHIDX_Pos) | \ + (RADIO_SUBSCRIBE_RXEN_EN_Enabled << RADIO_SUBSCRIBE_RXEN_EN_Pos)) +#define DPPI_SUBSCRIBE_RADIO_TASKS_TXEN ((DPPI_CH_TIMER0_EVENTS_COMPARE_0 << RADIO_SUBSCRIBE_TXEN_CHIDX_Pos) | \ + (RADIO_SUBSCRIBE_TXEN_EN_Enabled << RADIO_SUBSCRIBE_TXEN_EN_Pos)) +#define DPPI_SUBSCRIBE_AAR_TASKS_START ((DPPI_CH_RADIO_EVENTS_BCMATCH << AAR_SUBSCRIBE_START_CHIDX_Pos) | \ + (AAR_SUBSCRIBE_START_EN_Enabled << AAR_SUBSCRIBE_START_EN_Pos)) +#define DPPI_SUBSCRIBE_CCM_TASKS_CRYPT ((DPPI_CH_RADIO_EVENTS_ADDRESS << CCM_SUBSCRIBE_CRYPT_CHIDX_Pos) | \ + (CCM_SUBSCRIBE_CRYPT_EN_Enabled << CCM_SUBSCRIBE_CRYPT_EN_Pos)) + +#define DPPI_UNSUBSCRIBE_TIMER0_TASKS_START ((DPPI_CH_RTC0_EVENTS_COMPARE_0 << TIMER_SUBSCRIBE_START_CHIDX_Pos) | \ + (TIMER_SUBSCRIBE_START_EN_Disabled << TIMER_SUBSCRIBE_START_EN_Pos)) +#define DPPI_UNSUBSCRIBE_TIMER0_TASKS_CAPTURE1 ((DPPI_CH_RADIO_EVENTS_ADDRESS << TIMER_SUBSCRIBE_CAPTURE_CHIDX_Pos) | \ + (TIMER_SUBSCRIBE_CAPTURE_EN_Disabled << TIMER_SUBSCRIBE_CAPTURE_EN_Pos)) +#define DPPI_UNSUBSCRIBE_TIMER0_TASKS_CAPTURE2 ((DPPI_CH_RADIO_EVENTS_END << TIMER_SUBSCRIBE_CAPTURE_CHIDX_Pos) | \ + (TIMER_SUBSCRIBE_CAPTURE_EN_Disabled << TIMER_SUBSCRIBE_CAPTURE_EN_Pos)) +#define DPPI_UNSUBSCRIBE_TIMER0_TASKS_CAPTURE3 ((DPPI_CH_RADIO_EVENTS_ADDRESS << TIMER_SUBSCRIBE_CAPTURE_CHIDX_Pos) | \ + (TIMER_SUBSCRIBE_CAPTURE_EN_Disabled << TIMER_SUBSCRIBE_CAPTURE_EN_Pos)) +#define DPPI_UNSUBSCRIBE_RADIO_TASKS_DISABLE ((DPPI_CH_TIMER0_EVENTS_COMPARE_3 << RADIO_SUBSCRIBE_DISABLE_CHIDX_Pos) | \ + (RADIO_SUBSCRIBE_DISABLE_EN_Disabled << RADIO_SUBSCRIBE_DISABLE_EN_Pos)) +#define DPPI_UNSUBSCRIBE_RADIO_TASKS_RXEN ((DPPI_CH_TIMER0_EVENTS_COMPARE_0 << RADIO_SUBSCRIBE_RXEN_CHIDX_Pos) | \ + (RADIO_SUBSCRIBE_RXEN_EN_Disabled << RADIO_SUBSCRIBE_RXEN_EN_Pos)) +#define DPPI_UNSUBSCRIBE_RADIO_TASKS_TXEN ((DPPI_CH_TIMER0_EVENTS_COMPARE_0 << RADIO_SUBSCRIBE_TXEN_CHIDX_Pos) | \ + (RADIO_SUBSCRIBE_TXEN_EN_Disabled << RADIO_SUBSCRIBE_TXEN_EN_Pos)) +#define DPPI_UNSUBSCRIBE_AAR_TASKS_START ((DPPI_CH_RADIO_EVENTS_BCMATCH << AAR_SUBSCRIBE_START_CHIDX_Pos) | \ + (AAR_SUBSCRIBE_START_EN_Disabled << AAR_SUBSCRIBE_START_EN_Pos)) +#define DPPI_UNSUBSCRIBE_CCM_TASKS_CRYPT ((DPPI_CH_RADIO_EVENTS_ADDRESS << CCM_SUBSCRIBE_CRYPT_CHIDX_Pos) | \ + (CCM_SUBSCRIBE_CRYPT_EN_Disabled << CCM_SUBSCRIBE_CRYPT_EN_Pos)) + +extern uint8_t g_nrf_num_irks; +extern uint32_t g_nrf_irk_list[]; + +/* To disable all radio interrupts */ +#define NRF_RADIO_IRQ_MASK_ALL (0x34FF) + +/* + * We configure the nrf with a 1 byte S0 field, 8 bit length field, and + * zero bit S1 field. The preamble is 8 bits long. + */ +#define NRF_LFLEN_BITS (8) +#define NRF_S0LEN (1) +#define NRF_S1LEN_BITS (0) +#define NRF_CILEN_BITS (2) +#define NRF_TERMLEN_BITS (3) + +/* Maximum length of frames */ +#define NRF_MAXLEN (255) +#define NRF_BALEN (3) /* For base address of 3 bytes */ + +/* NRF_RADIO_NS->PCNF0 configuration values */ +#define NRF_PCNF0 (NRF_LFLEN_BITS << RADIO_PCNF0_LFLEN_Pos) | \ + (RADIO_PCNF0_S1INCL_Msk) | \ + (NRF_S0LEN << RADIO_PCNF0_S0LEN_Pos) | \ + (NRF_S1LEN_BITS << RADIO_PCNF0_S1LEN_Pos) +#define NRF_PCNF0_1M (NRF_PCNF0) | \ + (RADIO_PCNF0_PLEN_8bit << RADIO_PCNF0_PLEN_Pos) +#define NRF_PCNF0_2M (NRF_PCNF0) | \ + (RADIO_PCNF0_PLEN_16bit << RADIO_PCNF0_PLEN_Pos) +#define NRF_PCNF0_CODED (NRF_PCNF0) | \ + (RADIO_PCNF0_PLEN_LongRange << RADIO_PCNF0_PLEN_Pos) | \ + (NRF_CILEN_BITS << RADIO_PCNF0_CILEN_Pos) | \ + (NRF_TERMLEN_BITS << RADIO_PCNF0_TERMLEN_Pos) + +/* BLE PHY data structure */ +struct ble_phy_obj +{ + uint8_t phy_stats_initialized; + int8_t phy_txpwr_dbm; + uint8_t phy_chan; + uint8_t phy_state; + uint8_t phy_transition; + uint8_t phy_transition_late; + uint8_t phy_rx_started; + uint8_t phy_encrypted; + uint8_t phy_privacy; + uint8_t phy_tx_pyld_len; + uint8_t phy_cur_phy_mode; + uint8_t phy_tx_phy_mode; + uint8_t phy_rx_phy_mode; + uint8_t phy_bcc_offset; + int8_t rx_pwr_compensation; + uint32_t phy_aar_scratch; + uint32_t phy_access_address; + struct ble_mbuf_hdr rxhdr; + void *txend_arg; + ble_phy_tx_end_func txend_cb; + uint32_t phy_start_cputime; +}; +struct ble_phy_obj g_ble_phy_data; + +/* XXX: if 27 byte packets desired we can make this smaller */ +/* Global transmit/receive buffer */ +static uint32_t g_ble_phy_tx_buf[(BLE_PHY_MAX_PDU_LEN + 3) / 4]; +static uint32_t g_ble_phy_rx_buf[(BLE_PHY_MAX_PDU_LEN + 3) / 4]; + +#if MYNEWT_VAL(BLE_LL_CFG_FEAT_LE_ENCRYPTION) +/* Make sure word-aligned for faster copies */ +static uint32_t g_ble_phy_enc_buf[(BLE_PHY_MAX_PDU_LEN + 3) / 4]; +#endif + +/* RF center frequency for each channel index (offset from 2400 MHz) */ +static const uint8_t g_ble_phy_chan_freq[BLE_PHY_NUM_CHANS] = { + 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, /* 0-9 */ + 24, 28, 30, 32, 34, 36, 38, 40, 42, 44, /* 10-19 */ + 46, 48, 50, 52, 54, 56, 58, 60, 62, 64, /* 20-29 */ + 66, 68, 70, 72, 74, 76, 78, 2, 26, 80, /* 30-39 */ +}; + +#if (BLE_LL_BT5_PHY_SUPPORTED == 1) +/* packet start offsets (in usecs) */ +static const uint16_t g_ble_phy_mode_pkt_start_off[BLE_PHY_NUM_MODE] = { + [BLE_PHY_MODE_1M] = 40, + [BLE_PHY_MODE_2M] = 24, + [BLE_PHY_MODE_CODED_125KBPS] = 376, + [BLE_PHY_MODE_CODED_500KBPS] = 376 +}; +#endif + +/* Various radio timings */ +/* Radio ramp-up times in usecs (fast mode) */ +#define BLE_PHY_T_TXENFAST (XCVR_TX_RADIO_RAMPUP_USECS) +#define BLE_PHY_T_RXENFAST (XCVR_RX_RADIO_RAMPUP_USECS) + +/* delay between EVENTS_READY and start of tx */ +static const uint8_t g_ble_phy_t_txdelay[BLE_PHY_NUM_MODE] = { + [BLE_PHY_MODE_1M] = 4, + [BLE_PHY_MODE_2M] = 3, + [BLE_PHY_MODE_CODED_125KBPS] = 5, + [BLE_PHY_MODE_CODED_500KBPS] = 5 +}; +/* delay between EVENTS_END and end of txd packet */ +static const uint8_t g_ble_phy_t_txenddelay[BLE_PHY_NUM_MODE] = { + [BLE_PHY_MODE_1M] = 4, + [BLE_PHY_MODE_2M] = 3, + [BLE_PHY_MODE_CODED_125KBPS] = 9, + [BLE_PHY_MODE_CODED_500KBPS] = 3 +}; +/* delay between rxd access address (w/ TERM1 for coded) and EVENTS_ADDRESS */ +static const uint8_t g_ble_phy_t_rxaddrdelay[BLE_PHY_NUM_MODE] = { + [BLE_PHY_MODE_1M] = 6, + [BLE_PHY_MODE_2M] = 2, + [BLE_PHY_MODE_CODED_125KBPS] = 17, + [BLE_PHY_MODE_CODED_500KBPS] = 17 +}; +/* delay between end of rxd packet and EVENTS_END */ +static const uint8_t g_ble_phy_t_rxenddelay[BLE_PHY_NUM_MODE] = { + [BLE_PHY_MODE_1M] = 6, + [BLE_PHY_MODE_2M] = 2, + [BLE_PHY_MODE_CODED_125KBPS] = 27, + [BLE_PHY_MODE_CODED_500KBPS] = 22 +}; Review comment: did you check those numbers or just copied from nrf52? ########## File path: nimble/drivers/nrf5340/src/ble_phy.c ########## @@ -0,0 +1,2001 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +#include <stdint.h> +#include <string.h> +#include <assert.h> +#include <syscfg/syscfg.h> +#include <os/os.h> +#include <nimble/ble.h> +#include <nimble/nimble_opt.h> +#include <nimble/nimble_npl.h> +#include <controller/ble_phy.h> + +#include <ble/xcvr.h> +#include <controller/ble_phy_trace.h> +#include <controller/ble_ll.h> +#include <mcu/nrf5340_net_clock.h> +#include <mcu/cmsis_nvic.h> + +/* + * NOTE: This code uses 1-6 DPPI channels so care should be taken when using + * DPPI somewhere else. + * TODO maybe we could reduce number of used channels if we reuse same channel + * for mutually exclusive events but for now make it simpler to debug. + */ + +#define DPPI_CH_TIMER0_EVENTS_COMPARE_0 DPPIC_CHEN_CH0_Pos +#define DPPI_CH_TIMER0_EVENTS_COMPARE_3 DPPIC_CHEN_CH1_Pos +#define DPPI_CH_RADIO_EVENTS_END DPPIC_CHEN_CH2_Pos +#define DPPI_CH_RADIO_EVENTS_BCMATCH DPPIC_CHEN_CH3_Pos +#define DPPI_CH_RADIO_EVENTS_ADDRESS DPPIC_CHEN_CH4_Pos +#define DPPI_CH_RTC0_EVENTS_COMPARE_0 DPPIC_CHEN_CH5_Pos + +#define DPPI_CH_ENABLE_ALL (DPPIC_CHEN_CH0_Msk | DPPIC_CHEN_CH1_Msk | DPPIC_CHEN_CH2_Msk | \ + DPPIC_CHEN_CH3_Msk | DPPIC_CHEN_CH4_Msk | DPPIC_CHEN_CH5_Msk) + +#define DPPI_PUBLISH_TIMER0_EVENTS_COMPARE_0 ((DPPI_CH_TIMER0_EVENTS_COMPARE_0 << TIMER_PUBLISH_COMPARE_CHIDX_Pos) | \ + (TIMER_PUBLISH_COMPARE_EN_Enabled << TIMER_PUBLISH_COMPARE_EN_Pos)) +#define DPPI_PUBLISH_TIMER0_EVENTS_COMPARE_3 ((DPPI_CH_TIMER0_EVENTS_COMPARE_3 << TIMER_PUBLISH_COMPARE_CHIDX_Pos) | \ + (TIMER_PUBLISH_COMPARE_EN_Enabled << TIMER_PUBLISH_COMPARE_EN_Pos)) +#define DPPI_PUBLISH_RADIO_EVENTS_END ((DPPI_CH_RADIO_EVENTS_END << RADIO_PUBLISH_END_CHIDX_Pos) | \ + (RADIO_PUBLISH_END_EN_Enabled << RADIO_PUBLISH_END_EN_Pos)) +#define DPPI_PUBLISH_RADIO_EVENTS_BCMATCH ((DPPI_CH_RADIO_EVENTS_BCMATCH << RADIO_PUBLISH_BCMATCH_CHIDX_Pos) | \ + (RADIO_PUBLISH_BCMATCH_EN_Enabled << RADIO_PUBLISH_BCMATCH_EN_Pos)) +#define DPPI_PUBLISH_RADIO_EVENTS_ADDRESS ((DPPI_CH_RADIO_EVENTS_ADDRESS << RADIO_PUBLISH_ADDRESS_CHIDX_Pos) | \ + (RADIO_PUBLISH_ADDRESS_EN_Enabled << RADIO_PUBLISH_ADDRESS_EN_Pos)) +#define DPPI_PUBLISH_RTC0_EVENTS_COMPARE_0 ((DPPI_CH_RTC0_EVENTS_COMPARE_0 << RTC_PUBLISH_COMPARE_CHIDX_Pos) | \ + (RTC_PUBLISH_COMPARE_EN_Enabled << RTC_PUBLISH_COMPARE_EN_Pos)) + +#define DPPI_SUBSCRIBE_TIMER0_TASKS_START ((DPPI_CH_RTC0_EVENTS_COMPARE_0 << TIMER_SUBSCRIBE_START_CHIDX_Pos) | \ + (TIMER_SUBSCRIBE_START_EN_Enabled << TIMER_SUBSCRIBE_START_EN_Pos)) +#define DPPI_SUBSCRIBE_TIMER0_TASKS_CAPTURE1 ((DPPI_CH_RADIO_EVENTS_ADDRESS << TIMER_SUBSCRIBE_CAPTURE_CHIDX_Pos) | \ + (TIMER_SUBSCRIBE_CAPTURE_EN_Enabled << TIMER_SUBSCRIBE_CAPTURE_EN_Pos)) +#define DPPI_SUBSCRIBE_TIMER0_TASKS_CAPTURE2 ((DPPI_CH_RADIO_EVENTS_END << TIMER_SUBSCRIBE_CAPTURE_CHIDX_Pos) | \ + (TIMER_SUBSCRIBE_CAPTURE_EN_Enabled << TIMER_SUBSCRIBE_CAPTURE_EN_Pos)) +#define DPPI_SUBSCRIBE_TIMER0_TASKS_CAPTURE3 ((DPPI_CH_RADIO_EVENTS_ADDRESS << TIMER_SUBSCRIBE_CAPTURE_CHIDX_Pos) | \ + (TIMER_SUBSCRIBE_CAPTURE_EN_Enabled << TIMER_SUBSCRIBE_CAPTURE_EN_Pos)) +#define DPPI_SUBSCRIBE_RADIO_TASKS_DISABLE ((DPPI_CH_TIMER0_EVENTS_COMPARE_3 << RADIO_SUBSCRIBE_DISABLE_CHIDX_Pos) | \ + (RADIO_SUBSCRIBE_DISABLE_EN_Enabled << RADIO_SUBSCRIBE_DISABLE_EN_Pos)) +#define DPPI_SUBSCRIBE_RADIO_TASKS_RXEN ((DPPI_CH_TIMER0_EVENTS_COMPARE_0 << RADIO_SUBSCRIBE_RXEN_CHIDX_Pos) | \ + (RADIO_SUBSCRIBE_RXEN_EN_Enabled << RADIO_SUBSCRIBE_RXEN_EN_Pos)) +#define DPPI_SUBSCRIBE_RADIO_TASKS_TXEN ((DPPI_CH_TIMER0_EVENTS_COMPARE_0 << RADIO_SUBSCRIBE_TXEN_CHIDX_Pos) | \ + (RADIO_SUBSCRIBE_TXEN_EN_Enabled << RADIO_SUBSCRIBE_TXEN_EN_Pos)) +#define DPPI_SUBSCRIBE_AAR_TASKS_START ((DPPI_CH_RADIO_EVENTS_BCMATCH << AAR_SUBSCRIBE_START_CHIDX_Pos) | \ + (AAR_SUBSCRIBE_START_EN_Enabled << AAR_SUBSCRIBE_START_EN_Pos)) +#define DPPI_SUBSCRIBE_CCM_TASKS_CRYPT ((DPPI_CH_RADIO_EVENTS_ADDRESS << CCM_SUBSCRIBE_CRYPT_CHIDX_Pos) | \ + (CCM_SUBSCRIBE_CRYPT_EN_Enabled << CCM_SUBSCRIBE_CRYPT_EN_Pos)) + +#define DPPI_UNSUBSCRIBE_TIMER0_TASKS_START ((DPPI_CH_RTC0_EVENTS_COMPARE_0 << TIMER_SUBSCRIBE_START_CHIDX_Pos) | \ + (TIMER_SUBSCRIBE_START_EN_Disabled << TIMER_SUBSCRIBE_START_EN_Pos)) +#define DPPI_UNSUBSCRIBE_TIMER0_TASKS_CAPTURE1 ((DPPI_CH_RADIO_EVENTS_ADDRESS << TIMER_SUBSCRIBE_CAPTURE_CHIDX_Pos) | \ + (TIMER_SUBSCRIBE_CAPTURE_EN_Disabled << TIMER_SUBSCRIBE_CAPTURE_EN_Pos)) +#define DPPI_UNSUBSCRIBE_TIMER0_TASKS_CAPTURE2 ((DPPI_CH_RADIO_EVENTS_END << TIMER_SUBSCRIBE_CAPTURE_CHIDX_Pos) | \ + (TIMER_SUBSCRIBE_CAPTURE_EN_Disabled << TIMER_SUBSCRIBE_CAPTURE_EN_Pos)) +#define DPPI_UNSUBSCRIBE_TIMER0_TASKS_CAPTURE3 ((DPPI_CH_RADIO_EVENTS_ADDRESS << TIMER_SUBSCRIBE_CAPTURE_CHIDX_Pos) | \ + (TIMER_SUBSCRIBE_CAPTURE_EN_Disabled << TIMER_SUBSCRIBE_CAPTURE_EN_Pos)) +#define DPPI_UNSUBSCRIBE_RADIO_TASKS_DISABLE ((DPPI_CH_TIMER0_EVENTS_COMPARE_3 << RADIO_SUBSCRIBE_DISABLE_CHIDX_Pos) | \ + (RADIO_SUBSCRIBE_DISABLE_EN_Disabled << RADIO_SUBSCRIBE_DISABLE_EN_Pos)) +#define DPPI_UNSUBSCRIBE_RADIO_TASKS_RXEN ((DPPI_CH_TIMER0_EVENTS_COMPARE_0 << RADIO_SUBSCRIBE_RXEN_CHIDX_Pos) | \ + (RADIO_SUBSCRIBE_RXEN_EN_Disabled << RADIO_SUBSCRIBE_RXEN_EN_Pos)) +#define DPPI_UNSUBSCRIBE_RADIO_TASKS_TXEN ((DPPI_CH_TIMER0_EVENTS_COMPARE_0 << RADIO_SUBSCRIBE_TXEN_CHIDX_Pos) | \ + (RADIO_SUBSCRIBE_TXEN_EN_Disabled << RADIO_SUBSCRIBE_TXEN_EN_Pos)) +#define DPPI_UNSUBSCRIBE_AAR_TASKS_START ((DPPI_CH_RADIO_EVENTS_BCMATCH << AAR_SUBSCRIBE_START_CHIDX_Pos) | \ + (AAR_SUBSCRIBE_START_EN_Disabled << AAR_SUBSCRIBE_START_EN_Pos)) +#define DPPI_UNSUBSCRIBE_CCM_TASKS_CRYPT ((DPPI_CH_RADIO_EVENTS_ADDRESS << CCM_SUBSCRIBE_CRYPT_CHIDX_Pos) | \ + (CCM_SUBSCRIBE_CRYPT_EN_Disabled << CCM_SUBSCRIBE_CRYPT_EN_Pos)) Review comment: subscribe and unsubscribe macros are identical except EN bit is set to either 0 or 1, so I'd just create single macro with parameter ########## File path: nimble/drivers/nrf5340/src/ble_phy.c ########## @@ -0,0 +1,2001 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +#include <stdint.h> +#include <string.h> +#include <assert.h> +#include <syscfg/syscfg.h> +#include <os/os.h> +#include <nimble/ble.h> +#include <nimble/nimble_opt.h> +#include <nimble/nimble_npl.h> +#include <controller/ble_phy.h> + +#include <ble/xcvr.h> +#include <controller/ble_phy_trace.h> +#include <controller/ble_ll.h> +#include <mcu/nrf5340_net_clock.h> +#include <mcu/cmsis_nvic.h> + +/* + * NOTE: This code uses 1-6 DPPI channels so care should be taken when using + * DPPI somewhere else. + * TODO maybe we could reduce number of used channels if we reuse same channel + * for mutually exclusive events but for now make it simpler to debug. + */ + +#define DPPI_CH_TIMER0_EVENTS_COMPARE_0 DPPIC_CHEN_CH0_Pos +#define DPPI_CH_TIMER0_EVENTS_COMPARE_3 DPPIC_CHEN_CH1_Pos +#define DPPI_CH_RADIO_EVENTS_END DPPIC_CHEN_CH2_Pos +#define DPPI_CH_RADIO_EVENTS_BCMATCH DPPIC_CHEN_CH3_Pos +#define DPPI_CH_RADIO_EVENTS_ADDRESS DPPIC_CHEN_CH4_Pos +#define DPPI_CH_RTC0_EVENTS_COMPARE_0 DPPIC_CHEN_CH5_Pos Review comment: should be plain numbers instead of some CMSIS symbols ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected]
