You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by GitBox <gi...@apache.org> on 2022/02/17 07:20:30 UTC

[GitHub] [mynewt-nimble] mkasenberg opened a new pull request #1180: bsim: Add EDTT hci test app

mkasenberg opened a new pull request #1180:
URL: https://github.com/apache/mynewt-nimble/pull/1180


   adopted from Zephyr.


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

To unsubscribe, e-mail: commits-unsubscribe@mynewt.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [mynewt-nimble] andrzej-kaczmarek merged pull request #1180: bsim: Add EDTT hci test app

Posted by GitBox <gi...@apache.org>.
andrzej-kaczmarek merged pull request #1180:
URL: https://github.com/apache/mynewt-nimble/pull/1180


   


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

To unsubscribe, e-mail: commits-unsubscribe@mynewt.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [mynewt-nimble] andrzej-kaczmarek commented on a change in pull request #1180: bsim: Add EDTT hci test app

Posted by GitBox <gi...@apache.org>.
andrzej-kaczmarek commented on a change in pull request #1180:
URL: https://github.com/apache/mynewt-nimble/pull/1180#discussion_r809875631



##########
File path: babblesim/apps/edtt_test/transport/edtt/pkg.yml
##########
@@ -0,0 +1,36 @@
+#
+# 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.
+#
+
+pkg.name: babblesim/apps/edtt_test/transport/edtt
+pkg.description: Provides communication with EDTT bridge over named pipes
+pkg.author: "Apache Mynewt <de...@mynewt.apache.org>"
+pkg.homepage: "http://mynewt.apache.org/"
+pkg.deps:
+    - "@apache-mynewt-core/sys/console/stub"
+    - "@apache-mynewt-core/sys/log/stub"
+    - "@apache-mynewt-core/sys/stats/full"
+    - "@apache-mynewt-core/kernel/os"
+    - nimble/controller
+    - nimble/transport

Review comment:
       should only depend on nimble/controller

##########
File path: babblesim/apps/edtt_test/hci_test_app/syscfg.yml
##########
@@ -0,0 +1,31 @@
+#
+# 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.vals:
+    BLE_HOST: 0
+    BLE_HCI_TRANSPORT: custom
+    MCU_UART_POLLER_PRIO: 3

Review comment:
       I think we could just change uart poller prio in bsim bsp to smth like 9, I assume it should have lowest priority of all tasks. Then edtt poller can be set to 2 (as it is now) and there's no need to override uart.

##########
File path: babblesim/apps/edtt_test/transport/edtt/syscfg.yml
##########
@@ -0,0 +1,57 @@
+#
+# 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:
+    EDTT_HCI_LOG_FILE:
+        description: >
+            Path to the HCI log file. Skip file extension
+            because device id and .log will be appended.
+        value: "hci_logs"
+    MCU_EDTT_POLLER_PRIO:
+        description: 'Priority of native EDTT poller task.'
+        type: task_priority
+        value: 2
+    BLE_HCI_EDTT_PORT:
+        description: 'The port to use for the HCI edtt interface'
+        value: 0
+
+    BLE_HCI_ACL_OUT_COUNT:
+        description: >
+            This count is used in creating a pool of elements used by the
+            code to enqueue various elements. In the case of the controller
+            only HCI, this number should be equal to the number of mbufs in
+            the msys pool. For host only, it is really dependent on the
+            number of ACL buffers that the controller tells the host it
+            has.
+        value: 12
+
+    BLE_TRANS_EDTT_SYSINIT_STAGE:
+        description: >
+            Sysinit stage for the UART BLE transport.
+        value: 500
+
+syscfg.vals.BLE_EXT_ADV:
+    BLE_HCI_EVT_BUF_SIZE: 257
+
+syscfg.vals:
+    BLE_ACL_BUF_COUNT: 32
+    BLE_ACL_BUF_SIZE: 255
+    BLE_HCI_EVT_BUF_SIZE: 70

Review comment:
       just set to 257 always, we have plenty of ram on native target

##########
File path: babblesim/targets/edtthci/syscfg.yml
##########
@@ -0,0 +1,10 @@
+syscfg.vals:
+  # EDTT requires 0x123456789ABC address for the first device
+  # and 0x456789ABCDEF for the second one
+  BLE_LL_PUBLIC_DEV_ADDR: 0x123456789ABC  # d=1
+  # BLE_LL_PUBLIC_DEV_ADDR: 0x456789ABCDEF # d=2
+
+  # Default task settings
+  OS_MAIN_STACK_SIZE: 8000
+  EDTT_HCI_LOG_FILE: ("hci_logs")
+  EDTT_HCI_LOGS: 1

Review comment:
       this does not seem to be defined anywhere, I guess it should be used instead of -DEDTT_HCI_LOGS ?

##########
File path: babblesim/apps/edtt_test/transport/edtt/pkg.yml
##########
@@ -0,0 +1,36 @@
+#
+# 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.
+#
+
+pkg.name: babblesim/apps/edtt_test/transport/edtt
+pkg.description: Provides communication with EDTT bridge over named pipes
+pkg.author: "Apache Mynewt <de...@mynewt.apache.org>"
+pkg.homepage: "http://mynewt.apache.org/"
+pkg.deps:
+    - "@apache-mynewt-core/sys/console/stub"
+    - "@apache-mynewt-core/sys/log/stub"
+    - "@apache-mynewt-core/sys/stats/full"
+    - "@apache-mynewt-core/kernel/os"
+    - nimble/controller
+    - nimble/transport
+
+pkg.apis:
+    - ble_transport
+
+pkg.init:
+    ble_hci_edtt_init: 'MYNEWT_VAL(BLE_TRANS_EDTT_SYSINIT_STAGE)'

Review comment:
       just add static priority

##########
File path: babblesim/apps/edtt_test/hci_test_app/pkg.yml
##########
@@ -0,0 +1,36 @@
+#
+# 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.
+#
+pkg.name: babblesim/apps/edtt_test/hci_test_app
+pkg.type: app
+pkg.description: nRF52 on BabbleSim - EDTT tester
+pkg.author: "Codecoup"
+pkg.homepage: "http://mynewt.apache.org/"
+pkg.keywords:
+
+pkg.deps:
+    - "@apache-mynewt-core/sys/console/stub"
+    - "@apache-mynewt-core/sys/log/stub"
+    - "@apache-mynewt-core/sys/stats/full"
+    - "@apache-mynewt-core/kernel/os"
+    - nimble/controller
+    - nimble/transport
+    - babblesim/apps/edtt_test/transport/edtt
+
+pkg.req_apis:
+    - ble_transport

Review comment:
       not needed, this is already required by nimble/transport

##########
File path: babblesim/apps/edtt_test/transport/edtt/syscfg.yml
##########
@@ -0,0 +1,57 @@
+#
+# 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:
+    EDTT_HCI_LOG_FILE:
+        description: >
+            Path to the HCI log file. Skip file extension
+            because device id and .log will be appended.
+        value: "hci_logs"
+    MCU_EDTT_POLLER_PRIO:
+        description: 'Priority of native EDTT poller task.'
+        type: task_priority
+        value: 2
+    BLE_HCI_EDTT_PORT:
+        description: 'The port to use for the HCI edtt interface'

Review comment:
       EDTT_HCI_PORT

##########
File path: babblesim/apps/edtt_test/transport/edtt/syscfg.yml
##########
@@ -0,0 +1,57 @@
+#
+# 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:
+    EDTT_HCI_LOG_FILE:
+        description: >
+            Path to the HCI log file. Skip file extension
+            because device id and .log will be appended.
+        value: "hci_logs"
+    MCU_EDTT_POLLER_PRIO:

Review comment:
       EDTT_POLLER_PRIO

##########
File path: babblesim/targets/edtthci/pkg.yml
##########
@@ -0,0 +1,5 @@
+pkg.name: babblesim/targets/edtthci

Review comment:
       missing license

##########
File path: babblesim/targets/edtthci/syscfg.yml
##########
@@ -0,0 +1,10 @@
+syscfg.vals:

Review comment:
       missing license

##########
File path: babblesim/targets/edtthci/syscfg.yml
##########
@@ -0,0 +1,10 @@
+syscfg.vals:
+  # EDTT requires 0x123456789ABC address for the first device
+  # and 0x456789ABCDEF for the second one
+  BLE_LL_PUBLIC_DEV_ADDR: 0x123456789ABC  # d=1
+  # BLE_LL_PUBLIC_DEV_ADDR: 0x456789ABCDEF # d=2
+
+  # Default task settings
+  OS_MAIN_STACK_SIZE: 8000

Review comment:
       not needed

##########
File path: babblesim/apps/edtt_test/hci_test_app/pkg.yml
##########
@@ -0,0 +1,36 @@
+#
+# 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.
+#
+pkg.name: babblesim/apps/edtt_test/hci_test_app
+pkg.type: app
+pkg.description: nRF52 on BabbleSim - EDTT tester
+pkg.author: "Codecoup"
+pkg.homepage: "http://mynewt.apache.org/"
+pkg.keywords:
+
+pkg.deps:
+    - "@apache-mynewt-core/sys/console/stub"
+    - "@apache-mynewt-core/sys/log/stub"
+    - "@apache-mynewt-core/sys/stats/full"
+    - "@apache-mynewt-core/kernel/os"
+    - nimble/controller
+    - nimble/transport
+    - babblesim/apps/edtt_test/transport/edtt

Review comment:
       app pkg should depend on nimble/transport and transport/edtt only, then transport should depend on nimble/controller




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

To unsubscribe, e-mail: commits-unsubscribe@mynewt.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [mynewt-nimble] andrzej-kaczmarek commented on pull request #1180: bsim: Add EDTT hci test app

Posted by GitBox <gi...@apache.org>.
andrzej-kaczmarek commented on pull request #1180:
URL: https://github.com/apache/mynewt-nimble/pull/1180#issuecomment-1044301334


   also I'd simplify directory structure:
   babblesim/edtt/hci_test_app
   babblesim/edtt/hci_transport


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

To unsubscribe, e-mail: commits-unsubscribe@mynewt.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [mynewt-nimble] sjanc commented on a change in pull request #1180: bsim: Add EDTT hci test app

Posted by GitBox <gi...@apache.org>.
sjanc commented on a change in pull request #1180:
URL: https://github.com/apache/mynewt-nimble/pull/1180#discussion_r809127709



##########
File path: babblesim/apps/edtt_test/transport/edtt/pkg.yml
##########
@@ -0,0 +1,37 @@
+#
+# 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.
+#
+
+pkg.name: babblesim/apps/edtt_test/transport/edtt
+pkg.description: XXX

Review comment:
       give some meaningful description or leave it empty

##########
File path: babblesim/apps/edtt_test/hci_test_app/syscfg.yml
##########
@@ -0,0 +1,36 @@
+# 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.vals:
+    BSIM_NRF52: 1
+    OS_MAIN_STACK_SIZE: 8000
+    BLE_HCI_TRANSPORT: custom
+
+    MCU_TIMER_POLLER_PRIO: 0
+    BLE_LL_PRIO: 1
+    MCU_EDTT_POLLER_PRIO: 2
+    MCU_UART_POLLER_PRIO: 3
+    BLE_HOST: 0
+
+    # EDTT requires 0x123456789ABC address for first device
+    # and 0x456789ABCDEF for second
+    BLE_LL_PUBLIC_DEV_ADDR: 0x123456789ABC
+#    BLE_LL_PUBLIC_DEV_ADDR: 0x456789ABCDEF
+
+    # For LL/CON/ADV/BV-09-C, LL/CON/ADV/BV-10-C
+    BLE_LL_CFG_FEAT_LE_CSA2: 1

Review comment:
       should we enabled all features supported here?

##########
File path: babblesim/apps/edtt_test/transport/edtt/src/ble_hci_edtt.c
##########
@@ -0,0 +1,1165 @@
+/*
+ * Copyright (c) 2019 Oticon A/S
+ * Copyright (c) 2021 Codecoup
+ *
+ * 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 <assert.h>
+#include <string.h>
+#include <stdint.h>
+#include <bs_tracing.h>
+#include "sysinit/sysinit.h"
+#include "syscfg/syscfg.h"
+#include "os/os_cputime.h"
+#include "os/os.h"
+
+/* BLE */
+#include "nimble/ble.h"
+#include "nimble/hci_common.h"
+#include "nimble/ble_hci_trans.h"
+
+#include "bs_symbols.h"
+#include "bs_types.h"
+#include "time_machine.h"
+#include "ble_hci_edtt.h"
+#include "edtt_driver.h"
+#include "commands.h"
+
+#define BLE_HCI_EDTT_EVT_COUNT  \
+    (MYNEWT_VAL(BLE_HCI_EVT_HI_BUF_COUNT) + MYNEWT_VAL(BLE_HCI_EVT_LO_BUF_COUNT))
+
+#define BLE_HCI_EDTT_NONE        0x00
+#define BLE_HCI_EDTT_CMD         0x01
+#define BLE_HCI_EDTT_ACL         0x02
+#define BLE_HCI_EDTT_EVT         0x04
+
+#define K_NO_WAIT 0
+#define K_FOREVER 1
+
+#define BT_HCI_OP_VS_WRITE_BD_ADDR 0xFC06
+
+/* Callbacks for sending commands and acl data to ble_ll task */
+static ble_hci_trans_rx_cmd_fn *ble_hci_edtt_rx_cmd_cb;
+static void *ble_hci_edtt_rx_cmd_arg;
+static ble_hci_trans_rx_acl_fn *ble_hci_edtt_rx_acl_cb;
+static void *ble_hci_edtt_rx_acl_arg;
+
+/* Memory pool for hci events (high prio). 16 blocks x 70 bytes */
+static struct os_mempool ble_hci_edtt_evt_hi_pool;
+static os_membuf_t ble_hci_edtt_evt_hi_buf[
+    OS_MEMPOOL_SIZE(MYNEWT_VAL(BLE_HCI_EVT_HI_BUF_COUNT),
+                    MYNEWT_VAL(BLE_HCI_EVT_BUF_SIZE))
+];
+
+/* Memory pool for hci events (low prio). 16 blocks x 70 bytes */
+static struct os_mempool ble_hci_edtt_evt_lo_pool;
+static os_membuf_t ble_hci_edtt_evt_lo_buf[
+    OS_MEMPOOL_SIZE(MYNEWT_VAL(BLE_HCI_EVT_LO_BUF_COUNT),
+                    MYNEWT_VAL(BLE_HCI_EVT_BUF_SIZE))
+];
+
+/* Memory pool for hci commands. Only 1 block, so supports only 1 command at once. */
+static struct os_mempool ble_hci_edtt_cmd_pool;
+static os_membuf_t ble_hci_edtt_cmd_buf[
+    OS_MEMPOOL_SIZE(1, BLE_HCI_TRANS_CMD_SZ)
+];
+
+/*
+ * The MBUF payload size must accommodate the HCI data header size plus the
+ * maximum ACL data packet length. The ACL block size is the size of the
+ * mbufs we will allocate.
+ */
+#define ACL_BLOCK_SIZE  OS_ALIGN(MYNEWT_VAL(BLE_ACL_BUF_SIZE) \
+                                 + BLE_MBUF_MEMBLOCK_OVERHEAD \
+                                 + BLE_HCI_DATA_HDR_SZ, OS_ALIGNMENT)
+
+/* mbuf pool for acl data. 15 buffers x (255 bytes + some hdrs len)  */
+static struct os_mbuf_pool ble_hci_edtt_acl_mbuf_pool;
+static struct os_mempool_ext ble_hci_edtt_acl_pool;
+static os_membuf_t ble_hci_edtt_acl_buf[
+    OS_MEMPOOL_SIZE(MYNEWT_VAL(BLE_ACL_BUF_COUNT),
+                    ACL_BLOCK_SIZE)
+];
+
+/* A packet for queueing EDTT/HCI commands and events */
+struct ble_hci_edtt_pkt {
+    STAILQ_ENTRY(ble_hci_edtt_pkt) next;
+    uint32_t timestamp;
+    uint8_t type;
+    void *data;
+};
+
+/* Memory pool for ble_hci_edtt_pkt packets */
+static struct os_mempool ble_hci_edtt_pkt_pool;
+static os_membuf_t ble_hci_edtt_pkt_buf[
+    OS_MEMPOOL_SIZE(BLE_HCI_EDTT_EVT_COUNT + 1 +
+                    MYNEWT_VAL(BLE_HCI_ACL_OUT_COUNT),
+                    sizeof(struct ble_hci_edtt_pkt))
+];
+
+STAILQ_HEAD(ble_hci_edtt_pkt_queue, ble_hci_edtt_pkt);
+static struct ble_hci_edtt_pkt_queue data_queue;
+static struct ble_hci_edtt_pkt_queue rx_queue;
+static struct ble_hci_edtt_pkt_queue event_queue;
+
+static uint16_t waiting_opcode;
+static enum commands_t waiting_response;
+static uint8_t m_events;
+
+#define EDTT_POLLER_STACK_SZ OS_STACK_ALIGN(4000)
+static int edtt_poller_running;
+static struct os_task edtt_poller_task;
+static os_stack_t edtt_poller_stack[EDTT_POLLER_STACK_SZ];
+
+#if EDTT_HCI_LOGS
+extern unsigned int global_device_nbr;
+static FILE *fptr;
+
+static void
+log_hex_array(uint8_t *buf, int len)
+{
+    int i;
+    for (i = 0; i < len; i++) {
+        fprintf(fptr, "%02X ", buf[i]);
+    }
+}
+
+static void
+log_hci_cmd(uint16_t opcode, uint8_t *buf, int len)
+{
+    if (fptr) {
+        fprintf(fptr, "> %llu %02d %02d ", now, BLE_HCI_OCF(opcode), (BLE_HCI_OGF(opcode)));
+        log_hex_array(buf, len);
+        fputs("\n\n", fptr);
+        fflush(fptr);
+    }
+}
+
+static void
+log_hci_evt(struct ble_hci_ev *hdr)
+{
+    if (fptr) {
+        fprintf(fptr, "< %llu %02d ", now, hdr->opcode);
+        log_hex_array(hdr->data, hdr->length);
+        fputs("\n\n", fptr);
+        fflush(fptr);
+    }
+}
+
+static void
+log_hci_init()
+{
+    int flen = (int) strlen(MYNEWT_VAL(EDTT_HCI_LOG_FILE)) + 7;
+    char *fpath = (char *) calloc(flen, sizeof(char));
+    sprintf(fpath, "%s_%02d.log", MYNEWT_VAL(EDTT_HCI_LOG_FILE), global_device_nbr);
+    fptr = fopen(fpath, "w");
+    free(fpath);
+}
+#endif
+
+/**
+ * Allocates a buffer (mbuf) for ACL operation.
+ *
+ * @return                      The allocated buffer on success;
+ *                              NULL on buffer exhaustion.
+ */
+static struct os_mbuf *
+ble_hci_trans_acl_buf_alloc(void)
+{
+    struct os_mbuf *m;
+    uint8_t usrhdr_len;
+
+#if MYNEWT_VAL(BLE_CONTROLLER)
+    usrhdr_len = sizeof(struct ble_mbuf_hdr);
+#else
+    usrhdr_len = 0;
+#endif
+
+    m = os_mbuf_get_pkthdr(&ble_hci_edtt_acl_mbuf_pool, usrhdr_len);
+    return m;
+}
+
+static int
+ble_hci_edtt_acl_tx(struct os_mbuf *om)
+{
+    struct ble_hci_edtt_pkt *pkt;
+    os_sr_t sr;
+
+    /* If this packet is zero length, just free it */
+    if (OS_MBUF_PKTLEN(om) == 0) {
+        os_mbuf_free_chain(om);
+        return 0;
+    }
+
+    pkt = os_memblock_get(&ble_hci_edtt_pkt_pool);
+    if (pkt == NULL) {
+        os_mbuf_free_chain(om);
+        return BLE_ERR_MEM_CAPACITY;
+    }
+
+    pkt->type = BLE_HCI_EDTT_ACL;
+    pkt->data = om;
+
+    OS_ENTER_CRITICAL(sr);
+    STAILQ_INSERT_TAIL(&rx_queue, pkt, next);
+    OS_EXIT_CRITICAL(sr);
+
+    return 0;
+}
+
+static int
+ble_hci_edtt_cmdevt_tx(uint8_t *hci_ev, uint8_t edtt_type)
+{
+    struct ble_hci_edtt_pkt *pkt;
+    os_sr_t sr;
+
+    pkt = os_memblock_get(&ble_hci_edtt_pkt_pool);
+    if (pkt == NULL) {
+        ble_hci_trans_buf_free(hci_ev);
+        return BLE_ERR_MEM_CAPACITY;
+    }
+
+    pkt->type = edtt_type;
+    pkt->data = hci_ev;
+
+    OS_ENTER_CRITICAL(sr);
+    STAILQ_INSERT_TAIL(&rx_queue, pkt, next);
+    OS_EXIT_CRITICAL(sr);
+
+    return 0;
+}
+
+static void
+ble_hci_edtt_set_rx_cbs(ble_hci_trans_rx_cmd_fn *cmd_cb,
+                        void *cmd_arg,
+                        ble_hci_trans_rx_acl_fn *acl_cb,
+                        void *acl_arg)
+{
+    ble_hci_edtt_rx_cmd_cb = cmd_cb;
+    ble_hci_edtt_rx_cmd_arg = cmd_arg;
+    ble_hci_edtt_rx_acl_cb = acl_cb;
+    ble_hci_edtt_rx_acl_arg = acl_arg;
+}
+
+/* Free data buffer */
+static void
+ble_hci_edtt_free_buf(uint8_t type, uint8_t *cmdevt, struct os_mbuf *acl)
+{
+    switch (type) {
+        case BLE_HCI_EDTT_NONE:
+            break;
+
+        case BLE_HCI_EDTT_CMD:
+        case BLE_HCI_EDTT_EVT:
+            ble_hci_trans_buf_free(cmdevt);
+            break;
+
+        case BLE_HCI_EDTT_ACL:
+            os_mbuf_free_chain(acl);
+            break;
+
+        default:
+            assert(0);
+            break;
+    }
+}
+
+static void
+edtt_pkt_dequeue_and_free(struct ble_hci_edtt_pkt_queue *queue, struct ble_hci_edtt_pkt *pkt)
+{
+    /* Dequeue pkt header */
+    STAILQ_REMOVE(queue, pkt, ble_hci_edtt_pkt, next);
+    /* Free data buffer */
+    ble_hci_edtt_free_buf(pkt->type, pkt->data, pkt->data);
+    /* Free buffer of pkt header */
+    os_memblock_put(&ble_hci_edtt_pkt_pool, pkt);
+}
+
+/* Get first element of queue, without dequeueing */
+static struct ble_hci_edtt_pkt *
+edtt_pkt_get(struct ble_hci_edtt_pkt_queue *queue, uint8_t block)
+{
+    struct ble_hci_edtt_pkt *pkt;
+
+    if (block == K_FOREVER) {
+        while (STAILQ_EMPTY(queue)) {}
+
+        pkt = STAILQ_FIRST(queue);
+        assert(pkt != NULL);
+    } else {
+        pkt = STAILQ_FIRST(queue);
+    }
+
+    return pkt;
+}
+
+/**
+ * Sends an HCI event from the controller to the host.
+ *
+ * @param cmd                   The HCI event to send.  This buffer must be
+ *                                  allocated via ble_hci_trans_buf_alloc().
+ *
+ * @return                      0 on success;
+ *                              A BLE_ERR_[...] error code on failure.
+ */
+int
+ble_hci_trans_ll_evt_tx(uint8_t *cmd)
+{
+    int rc;
+
+    rc = ble_hci_edtt_cmdevt_tx(cmd, BLE_HCI_EDTT_EVT);
+    return rc;
+}
+
+/**
+ * Sends ACL data from controller to host.
+ *
+ * @param om                    The ACL data packet to send.
+ *
+ * @return                      0 on success;
+ *                              A BLE_ERR_[...] error code on failure.
+ */
+int
+ble_hci_trans_ll_acl_tx(struct os_mbuf *om)
+{
+    int rc;
+
+    rc = ble_hci_edtt_acl_tx(om);
+    return rc;
+}
+
+int
+ble_hci_trans_hs_cmd_tx(uint8_t *cmd)
+{
+    int rc;
+
+    rc = ble_hci_edtt_cmdevt_tx(cmd, BLE_HCI_EDTT_CMD);
+    return rc;
+}
+
+int
+ble_hci_trans_hs_acl_tx(struct os_mbuf *om)
+{
+    int rc;
+
+    rc = ble_hci_edtt_acl_tx(om);
+    return rc;
+}
+
+/**
+ * Allocates a flat buffer of the specified type.
+ *
+ * @param type                  The type of buffer to allocate; one of the
+ *                                  BLE_HCI_TRANS_BUF_[...] constants.
+ *
+ * @return                      The allocated buffer on success;
+ *                              NULL on buffer exhaustion.
+ */
+uint8_t *
+ble_hci_trans_buf_alloc(int type) {
+    uint8_t *buf;
+
+    switch (type) {
+        case BLE_HCI_TRANS_BUF_CMD:
+            buf = os_memblock_get(&ble_hci_edtt_cmd_pool);
+            break;
+        case BLE_HCI_TRANS_BUF_EVT_HI:
+            buf = os_memblock_get(&ble_hci_edtt_evt_hi_pool);
+            if (buf == NULL) {
+                /* If no high-priority event buffers remain, try to grab a
+                 * low-priority one.
+                 */
+                buf = os_memblock_get(&ble_hci_edtt_evt_lo_pool);
+            }
+            break;
+
+        case BLE_HCI_TRANS_BUF_EVT_LO:
+            buf = os_memblock_get(&ble_hci_edtt_evt_lo_pool);
+            break;
+
+        default:
+            assert(0);
+            buf = NULL;
+    }
+
+    return buf;
+}
+
+/**
+ * Frees the specified flat buffer.  The buffer must have been allocated via
+ * ble_hci_trans_buf_alloc().
+ *
+ * @param buf                   The buffer to free.
+ */
+void
+ble_hci_trans_buf_free(uint8_t *buf)
+{
+    int rc;
+
+    /*
+     * XXX: this may look a bit odd, but the controller uses the command
+     * buffer to send back the command complete/status as an immediate
+     * response to the command. This was done to insure that the controller
+     * could always send back one of these events when a command was received.
+     * Thus, we check to see which pool the buffer came from so we can free
+     * it to the appropriate pool
+     */
+    if (os_memblock_from(&ble_hci_edtt_evt_hi_pool, buf)) {
+        rc = os_memblock_put(&ble_hci_edtt_evt_hi_pool, buf);
+        assert(rc == 0);
+    } else if (os_memblock_from(&ble_hci_edtt_evt_lo_pool, buf)) {
+        rc = os_memblock_put(&ble_hci_edtt_evt_lo_pool, buf);
+        assert(rc == 0);
+    } else {
+        assert(os_memblock_from(&ble_hci_edtt_cmd_pool, buf));
+        rc = os_memblock_put(&ble_hci_edtt_cmd_pool, buf);
+        assert(rc == 0);
+    }
+}
+
+int
+ble_hci_trans_set_acl_free_cb(os_mempool_put_fn *cb, void *arg)
+{
+    ble_hci_edtt_acl_pool.mpe_put_cb = cb;
+    ble_hci_edtt_acl_pool.mpe_put_arg = arg;
+    return 0;
+}
+
+void
+ble_hci_trans_cfg_ll(ble_hci_trans_rx_cmd_fn *cmd_cb,
+                     void *cmd_arg,
+                     ble_hci_trans_rx_acl_fn *acl_cb,
+                     void *acl_arg)
+{
+    ble_hci_edtt_set_rx_cbs(cmd_cb, cmd_arg, acl_cb, acl_arg);
+}
+
+void
+ble_hci_trans_cfg_hs(ble_hci_trans_rx_cmd_fn *cmd_cb,
+                     void *cmd_arg,
+                     ble_hci_trans_rx_acl_fn *acl_cb,
+                     void *acl_arg)
+{
+    ble_hci_edtt_set_rx_cbs(cmd_cb, cmd_arg, acl_cb, acl_arg);
+}
+
+int
+ble_hci_trans_reset(void)
+{
+    struct ble_hci_edtt_pkt *pkt;
+
+    while ((pkt = STAILQ_FIRST(&data_queue)) != NULL) {
+        edtt_pkt_dequeue_and_free(&data_queue, pkt);
+    }
+
+    while ((pkt = STAILQ_FIRST(&event_queue)) != NULL) {
+        edtt_pkt_dequeue_and_free(&event_queue, pkt);
+    }
+
+    while ((pkt = STAILQ_FIRST(&rx_queue)) != NULL) {
+        edtt_pkt_dequeue_and_free(&rx_queue, pkt);
+    }
+
+    return 0;
+}
+
+/**
+ * @brief Clean out excess bytes from the input buffer
+ */
+static void
+read_excess_bytes(uint16_t size)
+{
+    if (size > 0) {
+        uint8_t buffer[size];
+
+        edtt_read((uint8_t *) buffer, size, EDTTT_BLOCK);
+        bs_trace_raw_time(3, "command size wrong! (%u extra bytes removed)", size);
+    }
+}
+
+/**
+ * @brief Provide an error response when an HCI command send failed
+ */
+static void
+error_response(int error)
+{
+    uint16_t response = waiting_response;
+    int le_error = error;
+    uint16_t size = sizeof(le_error);
+
+    edtt_write((uint8_t *) &response, sizeof(response), EDTTT_BLOCK);
+    edtt_write((uint8_t *) &size, sizeof(size), EDTTT_BLOCK);
+    edtt_write((uint8_t *) &le_error, sizeof(le_error), EDTTT_BLOCK);
+    waiting_response = CMD_NOTHING;
+    waiting_opcode = 0;
+}
+
+/**
+ * @brief Allocate buffer for HCI command, fill in parameters and send the
+ * command...
+ */
+static int
+send_hci_cmd_to_ctrl(uint16_t opcode, uint8_t param_len, uint16_t response) {
+    struct ble_hci_cmd *buf;
+    int err = 0;
+    waiting_response = response;
+    waiting_opcode = opcode;
+
+    buf = (void *) ble_hci_trans_buf_alloc(BLE_HCI_TRANS_BUF_CMD);
+
+    if (buf != NULL) {
+        buf->opcode = opcode;
+        buf->length = param_len;
+
+        if (param_len) {
+            edtt_read((uint8_t *) buf->data, param_len, EDTTT_BLOCK);
+        }
+
+#if EDTT_HCI_LOGS
+        log_hci_cmd(opcode, buf->data, param_len);
+#endif
+
+        err = ble_hci_edtt_rx_cmd_cb((uint8_t *) buf, NULL);
+        if (err) {
+            ble_hci_trans_buf_free((uint8_t *) buf);
+            bs_trace_raw_time(3, "Failed to send HCI command %d (err %d)", opcode, err);
+            error_response(err);
+        }
+    } else {
+        bs_trace_raw_time(3, "Failed to create buffer for HCI command 0x%04x", opcode);
+        error_response(-1);
+    }
+    return err;
+}
+
+/**
+ * @brief Echo function - echo input received...
+ */
+static void
+echo(uint16_t size)
+{
+    uint16_t response = CMD_ECHO_RSP;
+    uint16_t le_size = size;

Review comment:
       why is this le_ ? should it be converted from host to le ?




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

To unsubscribe, e-mail: commits-unsubscribe@mynewt.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org