-
Notifications
You must be signed in to change notification settings - Fork 6.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bluetooth: Host: Add conversion macros from ms to various units
Add conversion macros from milliseconds to various units. The purpose of these macros is to make it more clear/easier for users to set and read values using milliseconds rather than the various BT units which may be in 0.625, 1.25 or 10ms units. This is especially useful when comparing related values using different units, such as advertising interval (0.625ms units) and periodic advertising interval units (1.25ms units). Users will have to be aware that these macros can provide slightly different values than what is provided, if the provided values do not match the units. Signed-off-by: Emil Gydesen <[email protected]>
- Loading branch information
Showing
15 changed files
with
237 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
cmake_minimum_required(VERSION 3.20.0) | ||
|
||
find_package(Zephyr COMPONENTS unittest REQUIRED HINTS $ENV{ZEPHYR_BASE}) | ||
|
||
project(bt_gap) | ||
|
||
target_sources(testbinary | ||
PRIVATE | ||
src/main.c | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
CONFIG_ZTEST=y | ||
|
||
CONFIG_BT=y |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* | ||
* Copyright (c) 2024 Nordic Semiconductor ASA | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#include <stddef.h> | ||
|
||
#include <zephyr/bluetooth/gap.h> | ||
#include <zephyr/ztest.h> | ||
#include <zephyr/ztest_test.h> | ||
#include <zephyr/ztest_assert.h> | ||
|
||
ZTEST_SUITE(gap_test_suite, NULL, NULL, NULL, NULL, NULL); | ||
|
||
static ZTEST(gap_test_suite, test_bt_conversion_macros) | ||
{ | ||
zassert_equal(BT_GAP_ADV_INTERVAL_TO_MS(0x0020U), 20U); | ||
/* Round down expected from 20.625 */ | ||
zassert_equal(BT_GAP_ADV_INTERVAL_TO_MS(0x0021U), 20U); | ||
/* Round down expected from 21.250 */ | ||
zassert_equal(BT_GAP_ADV_INTERVAL_TO_MS(0x0022U), 21U); | ||
|
||
zassert_equal(BT_GAP_ISO_INTERVAL_TO_MS(0x0004U), 5U); | ||
/* Round down expected from 6.25 */ | ||
zassert_equal(BT_GAP_ISO_INTERVAL_TO_MS(0x0005U), 6U); | ||
/* Round down expected from 7.50 */ | ||
zassert_equal(BT_GAP_ISO_INTERVAL_TO_MS(0x0006U), 7U); | ||
|
||
zassert_equal(BT_GAP_PER_ADV_INTERVAL_TO_MS(0x0008U), 10U); | ||
/* Round down expected from 11.25 */ | ||
zassert_equal(BT_GAP_PER_ADV_INTERVAL_TO_MS(0x0009U), 11U); | ||
/* Round down expected from 12.50 */ | ||
zassert_equal(BT_GAP_PER_ADV_INTERVAL_TO_MS(0x000aU), 12U); | ||
|
||
zassert_equal(BT_GAP_MS_TO_ADV_INTERVAL(20U), 0x0020U); | ||
/* Round down expected from 33.60 */ | ||
zassert_equal(BT_GAP_MS_TO_ADV_INTERVAL(21U), 0x0021U); | ||
/* Round down expected from 35.20 */ | ||
zassert_equal(BT_GAP_MS_TO_ADV_INTERVAL(22U), 0x0023U); | ||
|
||
zassert_equal(BT_GAP_MS_TO_PER_ADV_INTERVAL(10U), 0x0008U); | ||
/* Round down expected from 8.8 */ | ||
zassert_equal(BT_GAP_MS_TO_PER_ADV_INTERVAL(11U), 0x0008U); | ||
/* Round down expected from 9.6 */ | ||
zassert_equal(BT_GAP_MS_TO_PER_ADV_INTERVAL(12U), 0x0009U); | ||
|
||
zassert_equal(BT_GAP_MS_TO_PER_ADV_SYNC_TIMEOUT(4000u), 0x0190U); | ||
/* Round down expected from 400.5 */ | ||
zassert_equal(BT_GAP_MS_TO_PER_ADV_SYNC_TIMEOUT(4005u), 0x0190U); | ||
|
||
zassert_equal(BT_GAP_MS_TO_SCAN_INTERVAL(20U), 0x0020U); | ||
/* Round down expected from 33.60 */ | ||
zassert_equal(BT_GAP_MS_TO_SCAN_INTERVAL(21U), 0x0021U); | ||
/* Round down expected from 35.20 */ | ||
zassert_equal(BT_GAP_MS_TO_SCAN_INTERVAL(22U), 0x0023U); | ||
|
||
zassert_equal(BT_GAP_MS_TO_SCAN_WINDOW(20U), 0x0020U); | ||
/* Round down expected from 33.60 */ | ||
zassert_equal(BT_GAP_MS_TO_SCAN_WINDOW(21U), 0x0021U); | ||
/* Round down expected from 35.20 */ | ||
zassert_equal(BT_GAP_MS_TO_SCAN_WINDOW(22U), 0x0023U); | ||
|
||
zassert_equal(BT_GAP_MS_TO_CONN_INTERVAL(10U), 0x0008U); | ||
/* Round down expected from 8.8 */ | ||
zassert_equal(BT_GAP_MS_TO_CONN_INTERVAL(11U), 0x0008U); | ||
/* Round down expected from 9.6 */ | ||
zassert_equal(BT_GAP_MS_TO_CONN_INTERVAL(12U), 0x0009U); | ||
|
||
zassert_equal(BT_GAP_MS_TO_CONN_TIMEOUT(4000u), 0x0190U); | ||
/* Round down expected from 400.5 */ | ||
zassert_equal(BT_GAP_MS_TO_CONN_TIMEOUT(4005u), 0x0190U); | ||
|
||
zassert_equal(BT_GAP_MS_TO_CONN_EVENT_LEN(20U), 0x0020U); | ||
/* Round down expected from 33.60 */ | ||
zassert_equal(BT_GAP_MS_TO_CONN_EVENT_LEN(21U), 0x0021U); | ||
/* Round down expected from 35.20 */ | ||
zassert_equal(BT_GAP_MS_TO_CONN_EVENT_LEN(22U), 0x0023U); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
common: | ||
tags: | ||
- bluetooth | ||
- host | ||
tests: | ||
bluetooth.gap.test: | ||
type: unit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.