Skip to content

Commit

Permalink
os/board/rtl8721csm: improve one-shot adv CPU usage
Browse files Browse the repository at this point in the history
- adv data will not be updated if it is the same as the previous adv sent
- reduced CPU usage due to less updating of adv data
  • Loading branch information
yeetee179 authored and hs36-kim committed Dec 17, 2024
1 parent 9e60686 commit 86222d1
Show file tree
Hide file tree
Showing 15 changed files with 236 additions and 192 deletions.
59 changes: 31 additions & 28 deletions apps/examples/ble_rmc/ble_rmc_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ static uint8_t g_adv_resp[] = {
};
static uint8_t g_adv_resp_2[] = {
0x11, 0x09, '2', 'I', 'Z', 'E', 'N', 'R', 'T', ' ', 'T', 'E', 'S', 'T', '(', '0', '2', ')',
};
};

static void ble_device_scanned_cb_for_test(ble_scanned_device *scanned_device)
{
Expand Down Expand Up @@ -219,12 +219,6 @@ static void ble_server_mtu_update_cb(ble_conn_handle con_handle, uint16_t mtu_si
return;
}

static void ble_server_oneshot_adv_cb(uint16_t adv_result)
{
printf("result : %d\n", adv_result);
return;
}

static void utc_cb_charact_a_1(ble_server_attr_cb_type_e type, ble_conn_handle conn_handle, ble_attr_handle attr_handle, void *arg)
{
char *arg_str = "None";
Expand Down Expand Up @@ -288,7 +282,6 @@ static ble_server_init_config server_config = {
ble_server_connected_cb,
ble_server_disconnected_cb,
ble_server_mtu_update_cb,
ble_server_oneshot_adv_cb,
true,
gatt_profile, sizeof(gatt_profile) / sizeof(ble_server_gatt_t)};

Expand Down Expand Up @@ -829,42 +822,52 @@ int ble_rmc_main(int argc, char *argv[])

if (strncmp(argv[1], "advon", 6) == 0) {
ret = ble_server_one_shot_adv_init();
uint8_t type1 = 0;
uint8_t adv_id_0 = 0;
ble_data adv_data_1[1] = { 0x99, };
ble_data scan_rsp_data_1[1] = { 0x98, };
ble_data adv_data_2[1] = { 0x99, };
ble_data scan_rsp_data_2[1] = { 0x98, };

adv_data_1->data = g_adv_raw;
adv_data_1->length = sizeof(g_adv_raw);
scan_rsp_data_1->data = g_adv_resp;
scan_rsp_data_1->length = sizeof(g_adv_resp);
ret = ble_server_one_shot_adv_set(adv_id_0, adv_data_1, scan_rsp_data_1, type1);


uint8_t type3 = 3;
uint8_t adv_id_1 = 1;
adv_data_2->data = g_adv_raw_2;
adv_data_2->length = sizeof(g_adv_raw_2);
scan_rsp_data_2->data = g_adv_resp_2;
scan_rsp_data_2->length = sizeof(g_adv_resp_2);
ret = ble_server_one_shot_adv_set(adv_id_1, adv_data_2, scan_rsp_data_2, type3);
}

if (strncmp(argv[1], "advoff", 7) == 0) {
ret = ble_server_one_shot_adv_deinit();
}

if (strncmp(argv[1], "adv", 4) == 0) {

uint8_t adv_id_0 = 0;
uint8_t adv_id_1 = 1;
int ret = 0xff;
ble_data adv_data_1[1] = { 0x99, };
ble_data scan_rsp_data_1[1] = { 0x98, };
uint8_t type1 = 0;
uint8_t type2 = 3;
int counter = 0;
int counter = 0;
while(1){
counter++;
if (counter == 100)
break;

usleep(80000);
adv_data_1->data = g_adv_raw;
adv_data_1->length = sizeof(g_adv_raw);

scan_rsp_data_1->data = g_adv_resp;
scan_rsp_data_1->length = sizeof(g_adv_resp);
counter++;
if (counter == 100)
break;

ret = ble_server_one_shot_adv(adv_data_1, scan_rsp_data_1, type1);
usleep(80000);
ret = ble_server_one_shot_adv(adv_id_0);

usleep(20000);
adv_data_1->data = g_adv_raw_2;
adv_data_1->length = sizeof(g_adv_raw_2);

scan_rsp_data_1->data = g_adv_resp_2;
scan_rsp_data_1->length = sizeof(g_adv_resp_2);

ret = ble_server_one_shot_adv(adv_data_1, scan_rsp_data_1, type2);
ret = ble_server_one_shot_adv(adv_id_1);
}
}

Expand Down
8 changes: 0 additions & 8 deletions apps/examples/ble_tester/ble_tester_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -264,13 +264,6 @@ static void ble_server_mtu_update_cb(ble_conn_handle con_handle, uint16_t mtu_si
return;
}

static void ble_server_oneshot_adv_cb(uint16_t adv_result)
{
RMC_LOG(RMC_SERVER_TAG, "'%s' is called\n", __FUNCTION__);
RMC_LOG(RMC_SERVER_TAG, "result : %d\n", adv_result);
return;
}

static void utc_cb_charact_a_1(ble_server_attr_cb_type_e type, ble_conn_handle conn_handle, ble_attr_handle attr_handle, void *arg)
{
char *arg_str = "None";
Expand Down Expand Up @@ -395,7 +388,6 @@ static ble_server_init_config server_config = {
ble_server_connected_cb,
ble_server_disconnected_cb,
ble_server_mtu_update_cb,
ble_server_oneshot_adv_cb,
true,
gatt_profile,
sizeof(gatt_profile) / sizeof(ble_server_gatt_t)
Expand Down
2 changes: 0 additions & 2 deletions framework/include/ble_manager/ble_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,11 @@ typedef struct {
typedef void (*ble_server_connected_t)(ble_conn_handle con_handle, ble_server_connection_type_e conn_type, uint8_t mac[BLE_BD_ADDR_MAX_LEN]);
typedef void (*ble_server_disconnected_t)(ble_conn_handle con_handle, uint16_t cause);
typedef void (*ble_server_mtu_update_t)(ble_conn_handle con_handle, uint16_t mtu_size);
typedef void (*ble_server_oneshot_adv_t)(uint16_t adv_result);

typedef struct {
ble_server_connected_t connected_cb;
ble_server_disconnected_t disconnected_cb;
ble_server_mtu_update_t mtu_update_cb;
ble_server_oneshot_adv_t oneshot_adv_cb;
// true : Secure Manager is enabled. Bondable.
// false : Secure Manager is disabled. Requesting Pairing will be rejected. Non-Bondable.
bool is_secured_connect_allowed;
Expand Down
14 changes: 11 additions & 3 deletions framework/src/ble_manager/ble_manager_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -481,10 +481,18 @@ ble_result_e ble_server_one_shot_adv_deinit(void)
RETURN_RESULT(res, msg);
}

ble_result_e ble_server_one_shot_adv(ble_data *data_adv, ble_data *data_scan_rsp, uint8_t type)
ble_result_e ble_server_one_shot_adv_set(uint8_t adv_id, ble_data *data_adv, ble_data *data_scan_rsp, uint8_t type)
{
blemgr_msg_params param = {3, {(void *)data_adv, (void *)data_scan_rsp, (void *)&type}};
blemgr_msg_s msg = {BLE_CMD_ONE_SHOT_ADV, BLE_MANAGER_FAIL, (void *)(&param), NULL};
blemgr_msg_params param = {4, {(void *)&adv_id, (void *)data_adv, (void *)data_scan_rsp, (void *)&type}};
blemgr_msg_s msg = {BLE_CMD_ONE_SHOT_ADV_SET, BLE_MANAGER_FAIL, (void *)(&param), NULL};
int res = blemgr_post_message(&msg);

RETURN_RESULT(res, msg);
}

ble_result_e ble_server_one_shot_adv(uint8_t adv_id)
{
blemgr_msg_s msg = {BLE_CMD_ONE_SHOT_ADV, BLE_MANAGER_FAIL, (void *)(&adv_id), NULL};
int res = blemgr_post_message(&msg);

RETURN_RESULT(res, msg);
Expand Down
1 change: 1 addition & 0 deletions framework/src/ble_manager/ble_manager_event.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ typedef enum {
BLE_CMD_STOP_ADV,
BLE_CMD_ONE_SHOT_ADV_INIT,
BLE_CMD_ONE_SHOT_ADV_DEINIT,
BLE_CMD_ONE_SHOT_ADV_SET,
BLE_CMD_ONE_SHOT_ADV,
BLE_CMD_CREATE_MULTI_ADV,
BLE_CMD_DELETE_MULTI_ADV,
Expand Down
16 changes: 13 additions & 3 deletions framework/src/ble_manager/ble_manager_lwnl.c
Original file line number Diff line number Diff line change
Expand Up @@ -535,11 +535,21 @@ trble_result_e ble_drv_one_shot_adv_deinit()
return res;
}

trble_result_e ble_drv_one_shot_adv(trble_data *data_adv, trble_data *data_scan_rsp, uint8_t *type)
trble_result_e ble_drv_one_shot_adv_set(uint8_t *adv_id, trble_data *data_adv, trble_data *data_scan_rsp, uint8_t *type)
{
trble_result_e res = TRBLE_SUCCESS;
lwnl_msg_params msg_data = { 3, {(void *)data_adv, (void *)data_scan_rsp, (void *)type} };
lwnl_msg msg = {BLE_INTF_NAME, {LWNL_REQ_BLE_ONE_SHOT_ADV}, sizeof(msg_data), (void *)&msg_data, (void *)&res};
lwnl_msg_params msg_data = { 4, {(void *) adv_id, (void *)data_adv, (void *)data_scan_rsp, (void *)type} };
lwnl_msg msg = {BLE_INTF_NAME, {LWNL_REQ_BLE_ONE_SHOT_ADV_SET}, sizeof(msg_data), (void *)&msg_data, (void *)&res};
if (_send_msg(&msg) < 0) {
res = TRBLE_FILE_ERROR;
}
return res;
}

trble_result_e ble_drv_one_shot_adv(uint8_t adv_id)
{
trble_result_e res = TRBLE_SUCCESS;
lwnl_msg msg = {BLE_INTF_NAME, {LWNL_REQ_BLE_ONE_SHOT_ADV}, sizeof(adv_id), (void *)&adv_id, (void *)&res};
if (_send_msg(&msg) < 0) {
res = TRBLE_FILE_ERROR;
}
Expand Down
18 changes: 13 additions & 5 deletions framework/src/ble_manager/ble_manager_state.c
Original file line number Diff line number Diff line change
Expand Up @@ -1016,14 +1016,22 @@ ble_result_e blemgr_handle_request(blemgr_msg_s *msg)
ret = ble_drv_one_shot_adv_deinit();
} break;

case BLE_CMD_ONE_SHOT_ADV: {
case BLE_CMD_ONE_SHOT_ADV_SET: {
BLE_STATE_CHECK;
blemgr_msg_params *param = (blemgr_msg_params *)msg->param;
trble_data *data_adv = (trble_data *)param->param[0];
trble_data *data_scan_rsp = (trble_data *)param->param[1];
uint8_t *type = (uint8_t *)param->param[2];
uint8_t *adv_id = (uint8_t *)param->param[0];
trble_data *data_adv = (trble_data *)param->param[1];
trble_data *data_scan_rsp = (trble_data *)param->param[2];
uint8_t *type = (uint8_t *)param->param[3];

ret = ble_drv_one_shot_adv_set(adv_id, data_adv, data_scan_rsp, type);
} break;

case BLE_CMD_ONE_SHOT_ADV: {
BLE_STATE_CHECK;
uint8_t adv_id = *(uint8_t *)msg->param;

ret = ble_drv_one_shot_adv(data_adv, data_scan_rsp, type);
ret = ble_drv_one_shot_adv(adv_id);
} break;

case BLE_CMD_STOP_ADV: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -726,9 +726,15 @@ trble_result_e rtw_ble_server_one_shot_adv_deinit(void)
return TRBLE_SUCCESS;
}

trble_result_e rtw_ble_server_one_shot_adv(uint8_t* data_adv, uint16_t length_adv, uint8_t* data_scan_rsp, uint16_t length_scan_rsp, uint8_t *type)
trble_result_e rtw_ble_server_one_shot_adv_set(uint8_t *adv_id, uint8_t* data_adv, uint16_t length_adv, uint8_t* data_scan_rsp, uint16_t length_scan_rsp, uint8_t *type)
{
ble_tizenrt_legacy_adv_concurrent_send_adv_id(data_adv, length_adv, data_scan_rsp, length_scan_rsp, type);
ble_tizenrt_legacy_adv_concurrent_data_set(adv_id, data_adv, length_adv, data_scan_rsp, length_scan_rsp, type);
return TRBLE_SUCCESS;
}

trble_result_e rtw_ble_server_one_shot_adv(uint8_t adv_id)
{
ble_tizenrt_legacy_adv_concurrent_send_adv_id(adv_id);
return TRBLE_SUCCESS;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ trble_result_e rtw_ble_combo_init(trble_client_init_config* init_client, trble_s
server_init_parm.profile = init_server->profile;
server_init_parm.connected_cb = init_server->connected_cb;
server_init_parm.mtu_update_cb = init_server->mtu_update_cb;
server_init_parm.oneshot_adv_cb = init_server->oneshot_adv_cb;
server_init_parm.is_secured_connect_allowed = init_server->is_secured_connect_allowed;

ble_tizenrt_scatternet_app_init();
Expand Down
Loading

0 comments on commit 86222d1

Please sign in to comment.