Skip to content

Commit 06f5dc8

Browse files
author
Jyri Sarha
committed
debug_stream: Add text message record type and a ds_msg() to send them
Add new record type for simple text messages to the debug stream protocol and a function for sending the messages. This functionality is for debugging purposes when for some reason or another the usual methods do not work. ds_msg() can be used like printf and the printed messages can be displayed on host side with debug_stream.py. Signed-off-by: Jyri Sarha <jyri.sarha@linux.intel.com>
1 parent 0bd5581 commit 06f5dc8

File tree

5 files changed

+74
-0
lines changed

5 files changed

+74
-0
lines changed

src/debug/debug_stream/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@
33
add_local_sources_ifdef(CONFIG_SOF_DEBUG_STREAM_SLOT sof debug_stream_slot.c)
44

55
add_local_sources_ifdef(CONFIG_SOF_DEBUG_STREAM_THREAD_INFO sof debug_stream_thread_info.c)
6+
7+
add_local_sources_ifdef(CONFIG_SOF_DEBUG_STREAM_TEXT_MSG sof debug_stream_text_msg.c)

src/debug/debug_stream/Kconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,13 @@ config SOF_DEBUG_STREAM_THREAD_INFO_INTERVAL
4444
Decides how often thread info runs and checks execution cycle
4545
statistics and stack usage.
4646

47+
config SOF_DEBUG_STREAM_TEXT_MSG
48+
bool "Enable text message sending through Debug-Stream"
49+
help
50+
Enable debug message sending over debug stream. To use this
51+
feature one only needs to enable debug stream with this
52+
config option and print the debug messages with
53+
ds_msg(). See include/user/debug_stream_text_msg.h for
54+
prototype.
55+
4756
endif
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// SPDX-License-Identifier: BSD-3-Clause
2+
//
3+
// Copyright(c) 2024 Intel Corporation.
4+
5+
#include <sys/types.h>
6+
#include <stdarg.h>
7+
#include <stdio.h>
8+
#include <soc.h>
9+
#include <adsp_debug_window.h>
10+
#include <sof/common.h>
11+
12+
#include <user/debug_stream_text_msg.h>
13+
14+
void ds_msg(const char *format, ...)
15+
{
16+
va_list args;
17+
struct {
18+
struct debug_stream_text_msg msg;
19+
char text[128];
20+
} __packed buf = { 0 };
21+
ssize_t len;
22+
23+
va_start(args, format);
24+
len = vsnprintf(buf.text, sizeof(buf.text), format, args);
25+
va_end(args);
26+
27+
if (len < 0)
28+
return;
29+
len = MIN(len, sizeof(buf.text));
30+
31+
buf.msg.hdr.id = DEBUG_STREAM_RECORD_ID_TEXT_MSG;
32+
buf.msg.hdr.size_words = SOF_DIV_ROUND_UP(sizeof(buf.msg) + len,
33+
sizeof(buf.msg.hdr.data[0]));
34+
debug_stream_slot_send_record(&buf.msg.hdr);
35+
}
36+
EXPORT_SYMBOL(ds_msg);
37+

src/include/user/debug_stream.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,5 +48,6 @@ struct debug_stream_record {
4848
/* Debug Stream record identifiers */
4949
#define DEBUG_STREAM_RECORD_ID_UNINITIALIZED 0 /* invalid record marker */
5050
#define DEBUG_STREAM_RECORD_ID_THREAD_INFO 1 /* Thread info record */
51+
#define DEBUG_STREAM_RECORD_ID_TEXT_MSG 2 /* Text message */
5152

5253
#endif /* __SOC_DEBUG_STREAM_H__ */
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/* SPDX-License-Identifier: BSD-3-Clause
2+
*
3+
* Copyright(c) 2024 Intel Corporation.
4+
*/
5+
6+
#ifndef __SOC_DEBUG_STREAM_TEXT_MSG_H__
7+
#define __SOC_DEBUG_STREAM_TEXT_MSG_H__
8+
9+
#include <user/debug_stream_slot.h>
10+
11+
/*
12+
* Debug Stream text message.
13+
*/
14+
struct debug_stream_text_msg {
15+
struct debug_stream_record hdr;
16+
char msg[];
17+
} __packed;
18+
19+
/*
20+
* To send debug messages over debug stream. Enable
21+
* CONFIG_SOF_DEBUG_STREAM_TEXT_MSG to enable this function.
22+
*/
23+
void ds_msg(const char *format, ...);
24+
25+
#endif /* __SOC_DEBUG_STREAM_TEXT_MSG_H__ */

0 commit comments

Comments
 (0)