You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by an...@apache.org on 2023/01/27 18:55:30 UTC

[mynewt-nimble] 07/09: nimble/ll: Add ble_ll_pdu

This is an automated email from the ASF dual-hosted git repository.

andk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git

commit c7381e887766caaaa9f7fac81fe80d3af21d2099
Author: Andrzej Kaczmarek <an...@codecoup.pl>
AuthorDate: Thu Jan 19 20:48:23 2023 +0100

    nimble/ll: Add ble_ll_pdu
    
    This is small step to declutter ble_ll and cleanup defs for PDU-related
    defs and helpers.
---
 nimble/controller/include/controller/ble_ll_pdu.h | 42 ++++++++++++++++
 nimble/controller/src/ble_ll_pdu.c                | 58 +++++++++++++++++++++++
 2 files changed, 100 insertions(+)

diff --git a/nimble/controller/include/controller/ble_ll_pdu.h b/nimble/controller/include/controller/ble_ll_pdu.h
new file mode 100644
index 00000000..60eef833
--- /dev/null
+++ b/nimble/controller/include/controller/ble_ll_pdu.h
@@ -0,0 +1,42 @@
+/*
+ * 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.
+ */
+
+#ifndef H_BLE_LL_PDU_
+#define H_BLE_LL_PDU_
+
+#include <stdint.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define BLE_LL_PDU_PREAMBLE_1M_LEN  (1)
+#define BLE_LL_PDU_PREAMBLE_2M_LEN  (2)
+#define BLE_LL_PDU_AA_LEN           (4)
+#define BLE_LL_PDU_HEADER_LEN       (2)
+#define BLE_LL_PDU_CRC_LEN          (3)
+
+uint32_t ble_ll_pdu_syncword_us(uint8_t phy_mode);
+uint32_t ble_ll_pdu_us(uint8_t payload_len, uint8_t phy_mode);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* H_BLE_LL_PDU_ */
diff --git a/nimble/controller/src/ble_ll_pdu.c b/nimble/controller/src/ble_ll_pdu.c
new file mode 100644
index 00000000..bcbb5ff0
--- /dev/null
+++ b/nimble/controller/src/ble_ll_pdu.c
@@ -0,0 +1,58 @@
+/*
+ * 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 <controller/ble_phy.h>
+#include <controller/ble_ll_pdu.h>
+
+static const uint16_t syncword_len[] = {
+    [BLE_PHY_MODE_1M] = (BLE_LL_PDU_PREAMBLE_1M_LEN + BLE_LL_PDU_AA_LEN) * 8,
+    [BLE_PHY_MODE_2M] = (BLE_LL_PDU_PREAMBLE_2M_LEN + BLE_LL_PDU_AA_LEN) * 4,
+    [BLE_PHY_MODE_CODED_125KBPS] = 80 + 256 + 16 + 24,
+    [BLE_PHY_MODE_CODED_500KBPS] = 80 + 256 + 16 + 24,
+};
+
+static const uint16_t payload0_len[] = {
+    [BLE_PHY_MODE_1M] = (BLE_LL_PDU_PREAMBLE_1M_LEN + BLE_LL_PDU_AA_LEN +
+                         BLE_LL_PDU_HEADER_LEN + BLE_LL_PDU_CRC_LEN) * 8,
+    [BLE_PHY_MODE_2M] = (BLE_LL_PDU_PREAMBLE_2M_LEN + BLE_LL_PDU_AA_LEN +
+                         BLE_LL_PDU_HEADER_LEN + BLE_LL_PDU_CRC_LEN) * 4,
+    [BLE_PHY_MODE_CODED_125KBPS] = 80 + 256 + 16 + 24 +
+                                   8 * (BLE_LL_PDU_HEADER_LEN * 8 + 24 + 3),
+    [BLE_PHY_MODE_CODED_500KBPS] = 80 + 256 + 16 + 24 +
+                                   2 * (BLE_LL_PDU_HEADER_LEN * 8 + 24 + 3),
+};
+
+static const uint8_t us_per_octet[] = {
+    [BLE_PHY_MODE_1M] = 8,
+    [BLE_PHY_MODE_2M] = 4,
+    [BLE_PHY_MODE_CODED_125KBPS] = 64,
+    [BLE_PHY_MODE_CODED_500KBPS] = 16,
+};
+
+uint32_t
+ble_ll_pdu_syncword_us(uint8_t phy_mode)
+{
+    return syncword_len[phy_mode];
+}
+
+uint32_t
+ble_ll_pdu_us(uint8_t payload_len, uint8_t phy_mode)
+{
+    return payload0_len[phy_mode] + (payload_len * us_per_octet[phy_mode]);
+}