# 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.
#

syscfg.defs:
    BLE_DEVICE:
        description: >
            Used by package management system to include BLE hardware
            drivers.
        value: 1

    BLE_LP_CLOCK:
        description: >
            Used by BSP packages to configure LP clock for controller.
        value: 1

    BLE_HW_WHITELIST_ENABLE:
        description: >
            Used to enable hardware white list
        value: 1

    BLE_LL_SYSVIEW:
        description: >
            Enable SystemView tracing module for controller.
        value: 0

    BLE_LL_PRIO:
        description: 'The priority of the LL task'
        type: 'task_priority'
        value: 0

    # Sleep clock accuracy (sca). This is the amount of drift in the system
    # during when the device is sleeping (in parts per million).
    #
    # NOTE: 'the' master sca is an enumerated value based on the sca. Rather
    # than have a piece of code calculate this value, the developer must set
    # this value based on the value of the SCA using the following table:
    #
    #  SCA between 251 and 500 ppm (inclusive); master sca = 0
    #  SCA between 151 and 250 ppm (inclusive); master sca = 1
    #  SCA between 101 and 150 ppm (inclusive); master sca = 2
    #  SCA between 76 and 100 ppm (inclusive); master sca = 3
    #  SCA between 51 and 75 ppm (inclusive); master sca = 4
    #  SCA between 31 and 50 ppm (inclusive); master sca = 5
    #  SCA between 21 and 30 ppm (inclusive); master sca = 6
    #  SCA between 0 and 20 ppm (inclusive); master sca = 7
    #
    #  For example:
    #      if your clock drift is 101 ppm, your master should be set to 2.
    #      if your clock drift is 20, your master sca should be set to 7.
    #
    #  The values provided below are merely meant to be an example and should
    #  be replaced by values appropriate for your platform.
    BLE_LL_OUR_SCA:
        description: 'The system clock accuracy of the device.'
        value: '60'    # in ppm

    BLE_LL_MASTER_SCA:
        description: 'Enumerated value based on our sca'
        value: '4'

    BLE_LL_TX_PWR_DBM:
        description: 'Transmit power level.'
        value: '0'

    BLE_NUM_COMP_PKT_RATE:
        description: >
            Determines the maximum rate at which the controller will send the
            number of completed packets event to the host. Rate is in os time
            ticks.
        value: '(2 * OS_TICKS_PER_SEC)'

    BLE_LL_MFRG_ID:
        description: >
            Manufacturer ID. Should be set to unique ID per manufacturer.
        value: '0xFFFF'

    # Configuration items for the number of duplicate advertisers and the
    # number of advertisers from which we have heard a scan response.
    BLE_LL_NUM_SCAN_DUP_ADVS:
        description: 'The number of duplicate advertisers stored.'
        value: '8'
    BLE_LL_NUM_SCAN_RSP_ADVS:
        description: >
            The number of advertisers from which we have heard a scan
            response. Prevents sending duplicate events to host.
        value: '8'

    BLE_LL_WHITELIST_SIZE:
        description: 'Size of the LL whitelist.'
        value: '8'

    BLE_LL_RESOLV_LIST_SIZE:
        description: 'Size of the resolving list.'
        value: '4'

    # Data length management definitions for connections. These define the
    # maximum size of the PDU's that will be sent and/or received in a
    # connection.
    BLE_LL_MAX_PKT_SIZE:
        description: 'The maximum PDU size that can be sent/received'
        value: '251'
    BLE_LL_SUPP_MAX_RX_BYTES:
        description: 'The maximum supported received PDU size'
        value: 'MYNEWT_VAL_BLE_LL_MAX_PKT_SIZE'
    BLE_LL_SUPP_MAX_TX_BYTES:
        description: 'The maximum supported transmit PDU size'
        value: 'MYNEWT_VAL_BLE_LL_MAX_PKT_SIZE'
    BLE_LL_CONN_INIT_MAX_TX_BYTES:
        description: >
            Used to set the initial maximum transmit PDU size in a
            connection. If this is set to a value greater than 27,
            the controller will automatically attempt to do the
            data length update procedure. The host can always tell
            the controller to update this value.
        value: '27'

    # The number of slots that will be allocated to each connection
    BLE_LL_CONN_INIT_SLOTS:
        description: >
            This is the number of "slots" allocated to a connection when scheduling
            connections. Each slot is 1.25 msecs long. Note that a connection event may
            last longer than the number of slots allocated here and may also end earlier
            (depending on when the next scheduled event occurs and how much data needs
            to be transferred in the connection). However, you will be guaranteed that
            a connection event will be given this much time, if needed. Consecutively
            scheduled items will be at least this far apart
        value: '4'

    BLE_LL_CONN_INIT_MIN_WIN_OFFSET:
        description: >
            This is the minimum number of "slots" for WindowOffset value used for
            CONNECT_IND when creating new connection as a master. Each slot is 1.25
            msecs long. Increasing this value will delay first connection event after
            connection is created. However, older TI CC254x controllers cannot change
            connection parameters later if WindowOffset was set to 0 in CONNECT_IND. To
            ensure interoperability with such devices set this value to 2 (or more).
        value: '0'

    # Strict scheduling
    BLE_LL_STRICT_CONN_SCHEDULING:
        description: >
            Forces the scheduler on a central to schedule connections in fixed
            time intervals called periods. If set to 0, the scheduler is not forced
            to do this. If set to 1, the scheduler will only schedule connections at
            period boundaries. See comments in ble_ll_sched.h for more details.
        value: '0'

    BLE_LL_ADD_STRICT_SCHED_PERIODS:
        description: >
            The number of additional periods that will be allocated for strict
            scheduling. The total # of periods allocated for strict scheduling
            will be equal to the number of connections plus this number.
        value: '0'

    BLE_LL_USECS_PER_PERIOD:
        description: >
            The number of usecs per period.
        value: '3250'

    # The number of random bytes to store
    BLE_LL_RNG_BUFSIZE:
        description: >
            The number of random bytes that the link layer will try to
            always have available for the host to use. Decreasing this
            value may cause host delays if the host needs lots of random
            material often.
        value: '32'

    # Crystal setting time
    BLE_XTAL_SETTLE_TIME:
        description: >
            The settling time of the high-frequency oscillator. This is
            used to turn on/off the clock used for the radio (assuming
            the HW supports this). This value is in microseconds.
        value: '0'

    # Configuration for LL supported features.
    #
    # There are a total 8 features that the LL can support. These can be found
    # in v4.2, Vol 6 Part B Section 4.6.
    #
    # These feature definitions are used to inform a host or other controller
    # about the LL features supported by the controller.
    #
    # NOTE: 'the' controller always supports extended reject indicate and thus
    # is not listed here.


    BLE_LL_CFG_FEAT_LE_ENCRYPTION:
        description: >
            This option enables/disables encryption support in the controller.
            This option saves both both code and RAM.
        value: '1'

    BLE_LL_CFG_FEAT_CONN_PARAM_REQ:
        description: >
            This option enables/disables the connection parameter request
            procedure.  This is implemented in the controller but is disabled
            by default.
        value: '1'

    BLE_LL_CFG_FEAT_SLAVE_INIT_FEAT_XCHG:
        description: >
            This option allows a slave to initiate the feature exchange
            procedure.  This feature is implemented but currently has no impact
            on code or ram size
        value: '1'

    BLE_LL_CFG_FEAT_LE_PING:
        description: >
            This option allows a controller to send/receive LE pings.
            Currently, this feature is not implemented by the controller so
            turning it on or off has no effect.
        value: 'MYNEWT_VAL_BLE_LL_CFG_FEAT_LE_ENCRYPTION'

    BLE_LL_CFG_FEAT_DATA_LEN_EXT:
        description: >
            This option enables/disables the data length update procedure in
            the controller. If enabled, the controller is allowed to change the
            size of tx/rx pdu's used in a connection. This option has only
            minor impact on code size and non on RAM.
        value: '1'

    BLE_LL_CFG_FEAT_LL_PRIVACY:
        description: >
            This option is used to enable/disable LL privacy.
        value: '1'

    BLE_LL_CFG_FEAT_EXT_SCAN_FILT:
        description: >
            This option is used to enable/disable the extended scanner filter
            policy feature. Currently, this feature is not supported by the
            nimble controller.
        value: '0'

    BLE_LL_CFG_FEAT_LE_CSA2:
        description: >
            This option is used to enable/disable support for LE Channel
            Selection Algorithm #2.
        value: '0'

    BLE_LL_CFG_FEAT_LE_2M_PHY:
        description: >
            This option is used to enable/disable support for the 2Mbps PHY.
        value: '0'

    BLE_LL_CFG_FEAT_LE_CODED_PHY:
        description: >
            This option is used to enable/disable support for the coded PHY.
        value: '0'

    BLE_LL_CFG_FEAT_LL_EXT_ADV:
        description: >
            This option is used to enable/disable support for Extended
            Advertising Feature. That means extended scanner, advertiser
            and connect.
        value: MYNEWT_VAL_BLE_EXT_ADV

    BLE_LL_EXT_ADV_AUX_PTR_CNT:
         description: >
            This option configure a max number of scheduled outstanding auxiliary
            packets for receive on secondary advertising channel.
         value: 0

    BLE_PUBLIC_DEV_ADDR:
        description: >
            Allows the target or app to override the public device address
            used by the controller. If all zero, the controller will
            attempt to retrieve the public device address from its
            chip specific location. If non-zero, this address will
            be used.
        value: "(uint8_t[6]){0x00, 0x00, 0x00, 0x00, 0x00, 0x00}"

    BLE_LL_DIRECT_TEST_MODE:
        description: >
             Enables HCI Test commands needed for Bluetooth SIG certification
        value: 0

    BLE_LL_VND_EVENT_ON_ASSERT:
        description: >
            This options enables controller to send a vendor-specific event on
            an assertion in controller code. The event contains file name and
            line number where assertion occured.
        value: 0

    BLE_LL_SYSINIT_STAGE:
        description: >
            Sysinit stage for the NimBLE controller.
        value: 250

syscfg.vals.BLE_LL_CFG_FEAT_LL_EXT_ADV:
    BLE_LL_CFG_FEAT_LE_CSA2: 1
    BLE_HW_WHITELIST_ENABLE: 0
    BLE_LL_EXT_ADV_AUX_PTR_CNT: 5

# Enable vendor event on assert in standalone build to make failed assertions in
# controller code visible when connected to external host
syscfg.vals.!BLE_HOST:
    BLE_LL_VND_EVENT_ON_ASSERT: 1
