Skip to content

Commit f783e54

Browse files
Thalleykartben
authored andcommitted
tests: Bluetooth: Tester: Add mutex for uart_send
Since tester_send_with_index may be called in different threads, we need to guard the 2 calls to uart_send to avoid sending partial btp message from 2 or more threads. Signed-off-by: Emil Gydesen <[email protected]>
1 parent b6d32b9 commit f783e54

File tree

1 file changed

+3
-0
lines changed
  • tests/bluetooth/tester/src

1 file changed

+3
-0
lines changed

tests/bluetooth/tester/src/btp.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,7 @@ void tester_rsp_buffer_allocate(size_t len, uint8_t **data)
276276
*data = net_buf_simple_add(rsp_buf, len);
277277
}
278278

279+
K_MUTEX_DEFINE(uart_mutex);
279280
static void tester_send_with_index(uint8_t service, uint8_t opcode, uint8_t index,
280281
const uint8_t *data, size_t len)
281282
{
@@ -286,10 +287,12 @@ static void tester_send_with_index(uint8_t service, uint8_t opcode, uint8_t inde
286287
msg.index = index;
287288
msg.len = sys_cpu_to_le16(len);
288289

290+
k_mutex_lock(&uart_mutex, K_FOREVER);
289291
uart_send((uint8_t *)&msg, sizeof(msg));
290292
if (data && len) {
291293
uart_send(data, len);
292294
}
295+
k_mutex_unlock(&uart_mutex);
293296
}
294297

295298
static void tester_rsp_with_index(uint8_t service, uint8_t opcode, uint8_t index,

0 commit comments

Comments
 (0)