Skip to content

Commit 8dea17f

Browse files
committed
pbio/drv/bluetooth_stm32_cc2640: Reduce I/O operations for setting the same data.
1 parent 2822375 commit 8dea17f

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

lib/pbio/drv/bluetooth/bluetooth_stm32_cc2640.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,13 +1070,26 @@ void pbdrv_bluetooth_peripheral_disconnect(pbio_task_t *task) {
10701070
static PT_THREAD(broadcast_task(struct pt *pt, pbio_task_t *task)) {
10711071
pbdrv_bluetooth_value_t *value = task->context;
10721072

1073+
static struct {
1074+
pbdrv_bluetooth_value_t v;
1075+
uint8_t d[31];
1076+
} previous_value;
1077+
10731078
PT_BEGIN(pt);
10741079

10751080
if (value->size > B_MAX_ADV_LEN) {
10761081
task->status = PBIO_ERROR_INVALID_ARG;
10771082
PT_EXIT(pt);
10781083
}
10791084

1085+
// Avoid I/O operations if the user tries to broadcast the same data
1086+
// over and over in a tight loop.
1087+
if (is_broadcasting && !memcmp((void *)&previous_value, (void *)value, sizeof(pbdrv_bluetooth_value_t) + value->size)) {
1088+
task->status = PBIO_SUCCESS;
1089+
PT_EXIT(pt);
1090+
}
1091+
memcpy((void *)&previous_value, (void *)value, sizeof(pbdrv_bluetooth_value_t) + value->size);
1092+
10801093
// HACK: calling GAP_updateAdvertisingData() repeatedly will cause the
10811094
// Bluetooth chips on Technic and City hubs to eventually lock up. So we
10821095
// call the standard Bluetooth command instead. We still get the vendor-

0 commit comments

Comments
 (0)