<commit_before>/* mbed Microcontroller Library
 * Copyright (c) 2017-2017 ARM Limited
 *
 * Licensed 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 <stddef.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>

// mbed Includes
#include "mbed_assert.h"
#include "platform/mbed_power_mgmt.h"
#include "mbed_critical.h"

// Cordio Includes
#include "ll_init_api.h"
#include "ll_defs.h"
#include "custom_chci_tr.h"
#include "pal_bb.h"
#include "pal_cfg.h"
#include "lhci_api.h"
#include "wsf_assert.h"
#include "wsf_buf.h"
#include "wsf_timer.h"
#include "wsf_trace.h"
#include "dm_api.h"

// Nordic Includes
#include "nrf.h"
#include "nrf5x_lf_clk_helper.h"

#include "NRFCordioHCIDriver.h"
#include "NRFCordioHCITransportDriver.h"

#ifdef DEBUG
#include <stdio.h>
#include <stdarg.h>
#define DBG_WARN(...) printf(__VA_ARGS__)
#else
#define DBG_WARN(...)
#endif

using namespace ble::vendor::nordic;
using namespace ble::vendor::cordio;

/*! \brief      Memory that should be reserved for the stack. */
#if defined(NRF52840_XXAA)

#undef MBED_CONF_CORDIO_LL_EXTENDED_ADVERTISING_SIZE
#undef MBED_CONF_CORDIO_LL_MAX_ACL_SIZE
#undef MBED_CONF_CORDIO_LL_TX_BUFFERS
#undef MBED_CONF_CORDIO_LL_PHY_CODED_SUPPORT
#define MBED_CONF_CORDIO_LL_EXTENDED_ADVERTISING_SIZE MBED_CONF_CORDIO_LL_NRF52840_EXTENDED_ADVERTISING_SIZE
#define MBED_CONF_CORDIO_LL_MAX_ACL_SIZE              MBED_CONF_CORDIO_LL_NRF52840_MAX_ACL_SIZE
#define MBED_CONF_CORDIO_LL_TX_BUFFERS                MBED_CONF_CORDIO_LL_NRF52840_TX_BUFFERS
#define MBED_CONF_CORDIO_LL_PHY_CODED_SUPPORT         MBED_CONF_CORDIO_LL_NRF52840_PHY_CODED_SUPPORT

#define CORDIO_LL_MEMORY_FOOTPRINT  15400UL

#else

#define CORDIO_LL_MEMORY_FOOTPRINT  12500UL

#endif

/*! \brief      Typical implementation revision number (LlRtCfg_t::implRev). */
#define LL_IMPL_REV             0x2303

#if MBED_CONF_NORDIC_NRF_LF_CLOCK_SRC == NRF_LF_SRC_SYNTH
#define NRF_LF_CLK_SRC CLOCK_LFCLKSRC_SRC_Synth
#elif MBED_CONF_NORDIC_NRF_LF_CLOCK_SRC == NRF_LF_SRC_XTAL
#define NRF_LF_CLK_SRC CLOCK_LFCLKSRC_SRC_Xtal
#elif MBED_CONF_NORDIC_NRF_LF_CLOCK_SRC == NRF_LF_SRC_RC
#define NRF_LF_CLK_SRC CLOCK_LFCLKSRC_SRC_RC
#endif

// Note to implementer: this should be amended if the Cordio stack is updated

// The Nordic-specific baseband configuration
// The BB_ config macros are set in the bb_api.h header file
const BbRtCfg_t NRFCordioHCIDriver::_bb_cfg = {
    /*clkPpm*/ 20,
    /*rfSetupDelayUsec*/ BB_RF_SETUP_DELAY_US,
    /*maxScanPeriodMsec*/ BB_MAX_SCAN_PERIOD_MS,
    /*schSetupDelayUsec*/ BB_SCH_SETUP_DELAY_US
};

/* +12 for message headroom, + 2 event header, +255 maximum parameter length. */
static const uint16_t maxRptBufSize = 12 + 2 + 255;

/* +12 for message headroom, +4 for header. */
static const uint16_t aclBufSize = 12 + MBED_CONF_CORDIO_LL_MAX_ACL_SIZE + 4 + BB_DATA_PDU_TAILROOM;

const LlRtCfg_t NRFCordioHCIDriver::_ll_cfg = {
/* Device */
/** Company ID (default to ARM Ltd. ID). */
/*uint16_t*/  .compId = LL_COMP_ID_ARM,
/** Implementation revision number. */
/*uint16_t*/  .implRev = LL_IMPL_REV,
/** Core specification implementation level (LL_VER_BT_CORE_SPEC_4_2). */
/*uint8_t*/   .btVer = LL_VER_BT_CORE_SPEC_5_0,
/** Unused. Align next field to word boundary. */
/*uint32_t*/  ._align32 = 0,

/* Advertiser */
/** Maximum number of advertising sets. */
/*uint8_t*/   .maxAdvSets = MBED_CONF_CORDIO_LL_MAX_ADVERTISING_SETS,
/** Maximum number of pending legacy or extended advertising reports. */<commit_msg>added timerboundary to config<commit_after>/* mbed Microcontroller Library
 * Copyright (c) 2017-2017 ARM Limited
 *
 * Licensed 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 <stddef.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>

// mbed Includes
#include "mbed_assert.h"
#include "platform/mbed_power_mgmt.h"
#include "mbed_critical.h"

// Cordio Includes
#include "ll_init_api.h"
#include "ll_defs.h"
#include "custom_chci_tr.h"
#include "pal_bb.h"
#include "pal_cfg.h"
#include "lhci_api.h"
#include "wsf_assert.h"
#include "wsf_buf.h"
#include "wsf_timer.h"
#include "wsf_trace.h"
#include "dm_api.h"

// Nordic Includes
#include "nrf.h"
#include "nrf5x_lf_clk_helper.h"

#include "NRFCordioHCIDriver.h"
#include "NRFCordioHCITransportDriver.h"

#ifdef DEBUG
#include <stdio.h>
#include <stdarg.h>
#define DBG_WARN(...) printf(__VA_ARGS__)
#else
#define DBG_WARN(...)
#endif

using namespace ble::vendor::nordic;
using namespace ble::vendor::cordio;

/*! \brief      Memory that should be reserved for the stack. */
#if defined(NRF52840_XXAA)

#undef MBED_CONF_CORDIO_LL_EXTENDED_ADVERTISING_SIZE
#undef MBED_CONF_CORDIO_LL_MAX_ACL_SIZE
#undef MBED_CONF_CORDIO_LL_TX_BUFFERS
#undef MBED_CONF_CORDIO_LL_PHY_CODED_SUPPORT
#define MBED_CONF_CORDIO_LL_EXTENDED_ADVERTISING_SIZE MBED_CONF_CORDIO_LL_NRF52840_EXTENDED_ADVERTISING_SIZE
#define MBED_CONF_CORDIO_LL_MAX_ACL_SIZE              MBED_CONF_CORDIO_LL_NRF52840_MAX_ACL_SIZE
#define MBED_CONF_CORDIO_LL_TX_BUFFERS                MBED_CONF_CORDIO_LL_NRF52840_TX_BUFFERS
#define MBED_CONF_CORDIO_LL_PHY_CODED_SUPPORT         MBED_CONF_CORDIO_LL_NRF52840_PHY_CODED_SUPPORT

#define CORDIO_LL_MEMORY_FOOTPRINT  15400UL

#else

#define CORDIO_LL_MEMORY_FOOTPRINT  12500UL

#endif

/*! \brief      Typical implementation revision number (LlRtCfg_t::implRev). */
#define LL_IMPL_REV             0x2303

#if MBED_CONF_NORDIC_NRF_LF_CLOCK_SRC == NRF_LF_SRC_SYNTH
#define NRF_LF_CLK_SRC CLOCK_LFCLKSRC_SRC_Synth
#elif MBED_CONF_NORDIC_NRF_LF_CLOCK_SRC == NRF_LF_SRC_XTAL
#define NRF_LF_CLK_SRC CLOCK_LFCLKSRC_SRC_Xtal
#elif MBED_CONF_NORDIC_NRF_LF_CLOCK_SRC == NRF_LF_SRC_RC
#define NRF_LF_CLK_SRC CLOCK_LFCLKSRC_SRC_RC
#endif

// Note to implementer: this should be amended if the Cordio stack is updated

// The Nordic-specific baseband configuration
// The BB_ config macros are set in the bb_api.h header file
const BbRtCfg_t NRFCordioHCIDriver::_bb_cfg = {
    /*clkPpm*/ 20,
    /*rfSetupDelayUs*/ BB_RF_SETUP_DELAY_US,
    /*maxScanPeriodMs*/ BB_MAX_SCAN_PERIOD_MS,
    /*schSetupDelayUs*/ BB_SCH_SETUP_DELAY_US,
    /*BbTimerBoundaryUs*/
#if (BB_CLK_RATE_HZ == 32768)
  BB_RTC_MAX_VALUE_US
#elif (BB_CLK_RATE_HZ == 8000000)
  BB_TIMER_8MHZ_MAX_VALUE_US
#elif (BB_CLK_RATE_HZ == 1000000)
  BB_TIMER_1MHZ_MAX_VALUE_US
#else
  #error "Unsupported platform."
#endif
};

/* +12 for message headroom, + 2 event header, +255 maximum parameter length. */
static const uint16_t maxRptBufSize = 12 + 2 + 255;

/* +12 for message headroom, +4 for header. */
static const uint16_t aclBufSize = 12 + MBED_CONF_CORDIO_LL_MAX_ACL_SIZE + 4 + BB_DATA_PDU_TAILROOM;

const LlRtCfg_t NRFCordioHCIDriver::_ll_cfg = {
/* Device */
/** Company ID (default to ARM Ltd. ID). */
/*uint16_t*/  .compId = LL_COMP_ID_ARM,
/** Implementation revision number. */
/*uint16_t*/  .implRev = LL_IMPL_REV,
/** Core specification implementation level (LL_VER_BT_CORE_SPEC_4_2). */
/*uint8_t*/   .btVer = LL_VER_BT_CORE_SPEC_5_0,
/** Unused. Align next field to word boundary. */
/*uint32_t*/  ._align32 = 0,

/* Advertiser */
/** Maximum number of advertising sets. */
/*uint8_t*/   .maxAdvSets = MBED_CONF_CORDIO_LL_MAX_ADVERTISING_SETS,
/** Maximum number of pending legacy or extended advertising reports. */
{'fraction_non_alphanumeric': 0.09385230993088396, 'fraction_numerical': 0.02485752394810234, 'mean_word_length': 5.0825958702064895, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2775481', 'n_tokens_mistral': 3333, 'n_tokens_neox': 3142, 'n_words': 723}