Skip to content

Commit

Permalink
app: allow DFU and Sidewalk to run in parallel
Browse files Browse the repository at this point in the history
remove disabling of Sidewalk when entering to DFU mode

Signed-off-by: Robert Gałat <robert.galat@nordicsemi.no>
  • Loading branch information
RobertGalatNordic committed Nov 13, 2024
1 parent 871ea7b commit 4645257
Show file tree
Hide file tree
Showing 13 changed files with 47 additions and 40 deletions.
4 changes: 0 additions & 4 deletions Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ if SIDEWALK
config MAIN_STACK_SIZE
default 2048

config BT_ID_MAX
default 3 if SIDEWALK_DFU
default 2

config SIDEWALK_SUBGHZ_SUPPORT
bool "Enable Sub-GHz link type support in Sidewalk libraries"
default y
Expand Down
8 changes: 8 additions & 0 deletions Kconfig.dependencies
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ config SIDEWALK_BLE
help
Sidewalk Bluetooth Low Energy (BLE) module

config BT_ID_MAX
default 3 if SIDEWALK_DFU
default 2

config BT_APP_IFC
bool "Enable BT app wrapper"
default y if SIDEWALK_BLE

config SIDEWALK_ASSERT
bool
default SIDEWALK
Expand Down
4 changes: 0 additions & 4 deletions samples/sid_end_device/src/hello/app.c
Original file line number Diff line number Diff line change
Expand Up @@ -269,13 +269,9 @@ static void app_btn_dfu_state(uint32_t unused)
ARG_UNUSED(unused);
static bool go_to_dfu_state = true;
if (go_to_dfu_state) {
sidewalk_event_send(sidewalk_event_exit, NULL, NULL);
sidewalk_event_send(app_event_enter_dfu_mode, NULL, NULL);
application_state_working(&global_state_notifier, false);
} else {
sidewalk_event_send(app_event_exit_dfu_mode, NULL, NULL);
sidewalk_event_send(sidewalk_event_autostart, NULL, NULL);
application_state_working(&global_state_notifier, true);
}

go_to_dfu_state = !go_to_dfu_state;
Expand Down
2 changes: 0 additions & 2 deletions samples/sid_end_device/src/sensor_monitoring/app.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,9 @@ static void app_btn_dfu_state(uint32_t unused)
ARG_UNUSED(unused);
static bool go_to_dfu_state = true;
if (go_to_dfu_state) {
sidewalk_event_send(sidewalk_event_exit, NULL, NULL);
sidewalk_event_send(app_event_enter_dfu_mode, NULL, NULL);
} else {
sidewalk_event_send(app_event_exit_dfu_mode, NULL, NULL);
sidewalk_event_send(sidewalk_event_autostart, NULL, NULL);
}

go_to_dfu_state = !go_to_dfu_state;
Expand Down
2 changes: 2 additions & 0 deletions subsys/sal/common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ zephyr_include_directories(sid_pal_ifc)
zephyr_include_directories(sid_time_ops)

add_subdirectory_ifdef(CONFIG_SIDEWALK_ON_DEV_CERT sid_on_dev_cert)

zephyr_library_sources(sid_ifc/bt_app_callbacks.c)
2 changes: 1 addition & 1 deletion subsys/sal/common/sid_ifc/bt_app_callbacks.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ int app_bt_enable(bt_ready_cb_t cb)
bt_enable_count++;
if (cb) {
cb(0);
return 0;
}
return 0;
}

int app_bt_disable()
Expand Down
9 changes: 4 additions & 5 deletions subsys/sal/common/sid_ifc/bt_app_callbacks.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,20 @@
#include <stdbool.h>
#include <zephyr/bluetooth/bluetooth.h>

#if defined (CONFIG_BT_APP_IFC)
int app_bt_enable(bt_ready_cb_t cb);

int app_bt_disable();

enum BT_id_values{
_BT_ID_DEFAULT = BT_ID_DEFAULT,
#if defined (CONFIG_SIDEWALK)
BT_ID_SIDEWALK,
#endif
#if defined (CONFIG_SIDEWALK_DFU)
BT_ID_SMP_DFU,
#endif
_BT_ID_MAX = CONFIG_BT_ID_MAX
_BT_ID_MAX
};

BUILD_ASSERT(_BT_ID_MAX <= CONFIG_BT_ID_MAX, "Too many BT Ids! Configured limit is %d, but used %d", CONFIG_BT_ID_MAX, _BT_ID_MAX);

BUILD_ASSERT(_BT_ID_MAX <= CONFIG_BT_ID_MAX, "Too many BT Ids! increase CONFIG_BT_ID_MAX, to match _BT_ID_MAX");
#endif
#endif
5 changes: 3 additions & 2 deletions subsys/sal/sid_pal/src/sid_ble_advert.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <sid_ble_uuid.h>

#include <sid_ble_uuid.h>
#include <bt_app_callbacks.h>

#include <zephyr/bluetooth/bluetooth.h>
#include <zephyr/bluetooth/uuid.h>
Expand Down Expand Up @@ -37,15 +38,15 @@ LOG_MODULE_REGISTER(sid_ble_advert, CONFIG_SIDEWALK_BLE_ADAPTER_LOG_LEVEL);

/* Advertising parameters. */
static struct bt_le_adv_param adv_param_fast = {
.id = CONFIG_SIDEWALK_BLE_ID,
.id = BT_ID_SIDEWALK,
.options = (AMA_ADV_OPTIONS),
.interval_min = MS_TO_INTERVAL_VAL(CONFIG_SIDEWALK_BLE_ADV_INT_FAST),
.interval_max = MS_TO_INTERVAL_VAL(CONFIG_SIDEWALK_BLE_ADV_INT_FAST +
CONFIG_SIDEWALK_BLE_ADV_INT_PRECISION),
};

static struct bt_le_adv_param adv_param_slow = {
.id = CONFIG_SIDEWALK_BLE_ID,
.id = BT_ID_SIDEWALK,
.options = (AMA_ADV_OPTIONS),
.interval_min = MS_TO_INTERVAL_VAL(CONFIG_SIDEWALK_BLE_ADV_INT_SLOW),
.interval_max = MS_TO_INTERVAL_VAL(CONFIG_SIDEWALK_BLE_ADV_INT_SLOW +
Expand Down
4 changes: 2 additions & 2 deletions tests/unit_tests/pal_ble_adapter/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ config SIDEWALK_LOG_LEVEL
config SIDEWALK_BLE_ADAPTER_LOG_LEVEL
default 0

config SIDEWALK_BLE_ID
default 1
config BT_APP_IFC
default y

config BT_ID_MAX
default 2
Expand Down
5 changes: 3 additions & 2 deletions tests/unit_tests/pal_ble_adapter/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <cmock_sid_ble_adapter_callbacks.h>
#include <cmock_sid_ble_service.h>
#include <errno.h>
#include <bt_app_callbacks.h>

#include <stdbool.h>

Expand Down Expand Up @@ -174,7 +175,7 @@ void test_sid_pal_ble_adapter_init(void)

TEST_ASSERT_EQUAL(SID_ERROR_NONE, sid_pal_ble_adapter_create(&p_test_ble_ifc));

bt_id_create_fake.return_val = CONFIG_SIDEWALK_BLE_ID;
bt_id_create_fake.return_val = BT_ID_SIDEWALK;
__cmock_sid_ble_conn_init_Expect();
__cmock_sid_ble_advert_init_IgnoreAndReturn(0);
TEST_ASSERT_EQUAL(SID_ERROR_NONE, p_test_ble_ifc->init(&test_ble_cfg));
Expand All @@ -193,7 +194,7 @@ void test_sid_pal_ble_adapter_deinit(void)
TEST_ASSERT_EQUAL(SID_ERROR_NONE, sid_pal_ble_adapter_create(&p_test_ble_ifc));
__cmock_settings_load_ExpectAndReturn(ESUCCESS);
__cmock_sid_ble_conn_init_Expect();
bt_id_create_fake.return_val = CONFIG_SIDEWALK_BLE_ID;
bt_id_create_fake.return_val = BT_ID_SIDEWALK;
__cmock_sid_ble_advert_init_IgnoreAndReturn(0);
TEST_ASSERT_EQUAL(SID_ERROR_NONE, p_test_ble_ifc->init(&test_ble_cfg));

Expand Down
7 changes: 3 additions & 4 deletions tests/unit_tests/sid_ble_advert/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ config SIDEWALK_BUILD
config SIDEWALK_LOG_LEVEL
default 0

config BT_APP_IFC
default y

module = SIDEWALK_BLE_ADAPTER
module-str = Sidewalk BLE interface
source "${ZEPHYR_BASE}/subsys/logging/Kconfig.template.log_config"
Expand All @@ -29,8 +32,4 @@ config SIDEWALK_BLE_ADV_INT_TRANSITION
int "test value for Sidewalk configuration macro"
default 30

config SIDEWALK_BLE_ID
int "test value for Sidewalk configuration"
default 1

source "Kconfig.zephyr"
6 changes: 3 additions & 3 deletions tests/unit_tests/sid_ble_connection/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ config SIDEWALK_LOG_LEVEL
config SIDEWALK_BLE_ADAPTER_LOG_LEVEL
default 0

config SIDEWALK_BLE_ID
default 1

config BT_ID_MAX
default 2

config BT_APP_IFC
default y

source "Kconfig.zephyr"
29 changes: 18 additions & 11 deletions tests/unit_tests/sid_ble_connection/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

#include <stdbool.h>
#include <errno.h>
#include <bt_app_callbacks.h>

DEFINE_FFF_GLOBALS;

Expand All @@ -24,15 +25,15 @@ FAKE_VALUE_FUNC(struct bt_conn *, bt_conn_ref, struct bt_conn *);
FAKE_VOID_FUNC(bt_conn_unref, struct bt_conn *);
FAKE_VALUE_FUNC(const bt_addr_le_t *, bt_conn_get_dst, const struct bt_conn *);
FAKE_VALUE_FUNC(int, bt_conn_disconnect, struct bt_conn *, uint8_t);
FAKE_VALUE_FUNC(int,bt_conn_get_info,const struct bt_conn *, struct bt_conn_info *);
FAKE_VALUE_FUNC(int, bt_conn_get_info, const struct bt_conn *, struct bt_conn_info *);

#define FFF_FAKES_LIST(FAKE) \
FAKE(bt_conn_cb_register) \
FAKE(bt_gatt_cb_register) \
FAKE(bt_conn_ref) \
FAKE(bt_conn_unref) \
FAKE(bt_conn_get_dst) \
FAKE(bt_conn_disconnect)\
FAKE(bt_conn_disconnect) \
FAKE(bt_conn_get_info)

#define CONNECTED (true)
Expand Down Expand Up @@ -104,8 +105,9 @@ void test_sid_ble_conn_params_get(void)
TEST_ASSERT_NULL(params);
}

int bt_conn_get_info_fake1(const struct bt_conn * a, struct bt_conn_info * b){
b->id = CONFIG_SIDEWALK_BLE_ID;
int bt_conn_get_info_fake1(const struct bt_conn *a, struct bt_conn_info *b)
{
b->id = BT_ID_SIDEWALK;
return 0;
}

Expand All @@ -122,9 +124,9 @@ void test_sid_ble_conn_positive(void)

bt_conn_get_dst_fake.return_val = &test_addr;
bt_conn_ref_fake.return_val = &test_conn;
int (*custom_fakes[])(const struct bt_conn *, struct bt_conn_info *) = {bt_conn_get_info_fake1};
int (*custom_fakes[])(const struct bt_conn *,
struct bt_conn_info *) = { bt_conn_get_info_fake1 };
SET_CUSTOM_FAKE_SEQ(bt_conn_get_info, custom_fakes, 1);


sid_ble_conn_deinit();
sid_ble_conn_init();
Expand Down Expand Up @@ -153,7 +155,8 @@ void test_sid_ble_set_conn_cb_positive(void)

bt_conn_get_dst_fake.return_val = &test_addr;
bt_conn_ref_fake.return_val = &test_conn;
int (*custom_fakes[])(const struct bt_conn *, struct bt_conn_info *) = {bt_conn_get_info_fake1};
int (*custom_fakes[])(const struct bt_conn *,
struct bt_conn_info *) = { bt_conn_get_info_fake1 };
SET_CUSTOM_FAKE_SEQ(bt_conn_get_info, custom_fakes, 1);

sid_ble_conn_init();
Expand Down Expand Up @@ -185,7 +188,8 @@ void test_sid_ble_conn_cb_set_call_count(void)

bt_conn_get_dst_fake.return_val = &test_addr;
bt_conn_ref_fake.return_val = &test_conn;
int (*custom_fakes[])(const struct bt_conn *, struct bt_conn_info *) = {bt_conn_get_info_fake1};
int (*custom_fakes[])(const struct bt_conn *,
struct bt_conn_info *) = { bt_conn_get_info_fake1 };
SET_CUSTOM_FAKE_SEQ(bt_conn_get_info, custom_fakes, 1);

sid_ble_conn_init();
Expand Down Expand Up @@ -222,7 +226,8 @@ void test_sid_ble_disconnected_wrong_conn(void)

bt_conn_get_dst_fake.return_val = &test_addr;
bt_conn_ref_fake.return_val = &test_conn;
int (*custom_fakes[])(const struct bt_conn *, struct bt_conn_info *) = {bt_conn_get_info_fake1};
int (*custom_fakes[])(const struct bt_conn *,
struct bt_conn_info *) = { bt_conn_get_info_fake1 };
SET_CUSTOM_FAKE_SEQ(bt_conn_get_info, custom_fakes, 1);

sid_ble_conn_init();
Expand All @@ -249,7 +254,8 @@ void test_sid_ble_cb_set_before_init(void)
struct bt_conn test_conn = { .dummy = 0xDC };

bt_conn_ref_fake.return_val = &test_conn;
int (*custom_fakes[])(const struct bt_conn *, struct bt_conn_info *) = {bt_conn_get_info_fake1};
int (*custom_fakes[])(const struct bt_conn *,
struct bt_conn_info *) = { bt_conn_get_info_fake1 };
SET_CUSTOM_FAKE_SEQ(bt_conn_get_info, custom_fakes, 1);

sid_ble_conn_deinit();
Expand Down Expand Up @@ -287,7 +293,8 @@ void test_sid_ble_conn_mtu_callback_curent_connection(void)

sid_ble_conn_init();
bt_conn_ref_fake.return_val = &curr_conn;
int (*custom_fakes[])(const struct bt_conn *, struct bt_conn_info *) = {bt_conn_get_info_fake1};
int (*custom_fakes[])(const struct bt_conn *,
struct bt_conn_info *) = { bt_conn_get_info_fake1 };
SET_CUSTOM_FAKE_SEQ(bt_conn_get_info, custom_fakes, 1);

__cmock_sid_ble_adapter_conn_connected_ExpectAnyArgs();
Expand Down

0 comments on commit 4645257

Please sign in to comment.