You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2026/10/15 11:47:51 UTC
(nuttx-apps) branch master updated (22f51f210 -> b1a17ba45)
This is an automated email from the ASF dual-hosted git repository.
xiaoxiang781216 pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx-apps.git
from 22f51f210 system/nxinit: add stdout and stderr service options
new 0932430d4 logging/nxscope: skip the sample divider when it is disabled
new 2d833fc97 logging/nxscope: add nxscope_put_samples() for sample blocks
new d8f128243 logging/nxscope: keep a stream frame intact until it is fully sent
new 0e157a57a logging/nxscope: report partial sends on the serial interface
new e09557ea8 logging/nxscope: route critical channels by the channel type
new b1a17ba45 include/logging/nxscope/nxscope.h: fix codespell issues
The 6 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
include/logging/nxscope/nxscope.h | 20 +--
include/logging/nxscope/nxscope_chan.h | 22 +++
logging/nxscope/nxscope.c | 6 +-
logging/nxscope/nxscope_chan.c | 267 +++++++++++++++++++++++++--------
logging/nxscope/nxscope_internals.c | 38 +++--
logging/nxscope/nxscope_iser.c | 27 +++-
6 files changed, 292 insertions(+), 88 deletions(-)
(nuttx-apps) 01/06: logging/nxscope: skip the sample divider when it is disabled
Posted by xi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx-apps.git
commit 0932430d44386d2da403af8098ed6144854b5c89
Author: raiden00pl <ra...@railab.me>
AuthorDate: Mon Aug 10 20:30:54 2026 +0200
logging/nxscope: skip the sample divider when it is disabled
With div == 0 the modulo is always zero, so the counter update and the
division ran on every sample of every undecimated stream for nothing.
Guard them; the decimating path is unchanged.
Assisted-by: Claude Code:claude-opus-5-5
Signed-off-by: raiden00pl <ra...@railab.me>
---
logging/nxscope/nxscope_chan.c | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/logging/nxscope/nxscope_chan.c b/logging/nxscope/nxscope_chan.c
index 5fb9e9b92..89971479e 100644
--- a/logging/nxscope/nxscope_chan.c
+++ b/logging/nxscope/nxscope_chan.c
@@ -176,11 +176,14 @@ static int nxscope_ch_validate(FAR struct nxscope_s *s, uint8_t ch,
#ifdef CONFIG_LOGGING_NXSCOPE_DIVIDER
/* Handle sample rate divider */
- s->cntr[ch] += 1;
- if (s->cntr[ch] % (s->chinfo[ch].div + 1) != 0)
+ if (s->chinfo[ch].div != 0)
{
- ret = -EAGAIN;
- goto errout;
+ s->cntr[ch] += 1;
+ if (s->cntr[ch] % (s->chinfo[ch].div + 1) != 0)
+ {
+ ret = -EAGAIN;
+ goto errout;
+ }
}
#endif
(nuttx-apps) 04/06: logging/nxscope: report partial sends on the serial interface
Posted by xi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx-apps.git
commit 0e157a57aa4149af7ef1ba68e50eede0fdcef459
Author: raiden00pl <ra...@railab.me>
AuthorDate: Fri Oct 2 10:05:16 2026 +0200
logging/nxscope: report partial sends on the serial interface
A non-blocking port accepts only what fits in its TX buffer, and the
rest of the frame was lost. Write what the port takes now and report a
partial send, so the stream retry completes the frame. The send does not
wait for room on a non-blocking port: a caller blocked on a full port
would also block its producers.
Assisted-by: Claude Code:claude-opus-5-5
Signed-off-by: raiden00pl <ra...@railab.me>
---
logging/nxscope/nxscope_iser.c | 27 +++++++++++++++++++++++++--
1 file changed, 25 insertions(+), 2 deletions(-)
diff --git a/logging/nxscope/nxscope_iser.c b/logging/nxscope/nxscope_iser.c
index 492617723..026acd352 100644
--- a/logging/nxscope/nxscope_iser.c
+++ b/logging/nxscope/nxscope_iser.c
@@ -27,6 +27,7 @@
#include <nuttx/config.h>
#include <nuttx/debug.h>
+#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
@@ -76,6 +77,8 @@ static int nxscope_ser_send(FAR struct nxscope_intf_s *intf,
FAR uint8_t *buff, int len)
{
FAR struct nxscope_intf_ser_s *priv = NULL;
+ int i = 0;
+ int ret = OK;
DEBUGASSERT(intf);
DEBUGASSERT(intf->priv);
@@ -84,9 +87,29 @@ static int nxscope_ser_send(FAR struct nxscope_intf_s *intf,
priv = (FAR struct nxscope_intf_ser_s *)intf->priv;
- /* Write data */
+ /* Write as much of the frame as the port takes now. A partial send is
+ * reported, the stream retry completes the frame later.
+ */
+
+ while (i < len)
+ {
+ ret = write(priv->fd, &buff[i], len - i);
+ if (ret > 0)
+ {
+ i += ret;
+ }
+ else if (ret < 0 && errno == EINTR)
+ {
+ continue;
+ }
+ else
+ {
+ ret = (ret < 0) ? -errno : OK;
+ break;
+ }
+ }
- return write(priv->fd, buff, len);
+ return (i == 0 && ret < 0) ? ret : i;
}
/****************************************************************************
(nuttx-apps) 02/06: logging/nxscope: add nxscope_put_samples() for sample blocks
Posted by xi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx-apps.git
commit 2d833fc973c1b013afb160d3cab57766a7a57ec4
Author: raiden00pl <ra...@railab.me>
AuthorDate: Thu Oct 1 10:32:55 2026 +0200
logging/nxscope: add nxscope_put_samples() for sample blocks
Put a block of samples of one channel with one lock and one channel
check. The divider, space check and buffer write are split out of
nxscope_ch_validate() and nxscope_put_common_m() unchanged and shared
by both paths, so a block put stores exactly what n per-sample puts do.
Measured on nRF52840 (PPK2, 100kS/s int16 over CDC/ACM): put path
~34% -> ~21% of CPU, idle ~27% -> ~34%.
Assisted-by: Claude Code:claude-opus-5-5
Signed-off-by: raiden00pl <ra...@railab.me>
---
include/logging/nxscope/nxscope_chan.h | 22 ++++
logging/nxscope/nxscope_chan.c | 215 ++++++++++++++++++++++++---------
2 files changed, 181 insertions(+), 56 deletions(-)
diff --git a/include/logging/nxscope/nxscope_chan.h b/include/logging/nxscope/nxscope_chan.h
index 8c7fb9087..3a2b9849b 100644
--- a/include/logging/nxscope/nxscope_chan.h
+++ b/include/logging/nxscope/nxscope_chan.h
@@ -285,6 +285,28 @@ int nxscope_put_vb32(FAR struct nxscope_s *s, uint8_t ch,
int nxscope_put_vchar(FAR struct nxscope_s *s, uint8_t ch,
FAR char *val, uint8_t d);
+/****************************************************************************
+ * Name: nxscope_put_samples
+ *
+ * Description:
+ * Put a block of vector samples of one channel without metadata on the
+ * stream buffer. Equivalent to n nxscope_put_vXXXX() calls, including
+ * the sample rate divider, under one lock and one channel check.
+ *
+ * Input Parameters:
+ * s - a pointer to a nxscope instance
+ * type - a channel data type
+ * ch - a channel id
+ * val - a pointer to the first sample data vector
+ * d - a dimmention of sample data vector
+ * n - a number of samples
+ * stride - a distance in bytes between consecutive samples
+ *
+ ****************************************************************************/
+
+int nxscope_put_samples(FAR struct nxscope_s *s, uint8_t type, uint8_t ch,
+ FAR void *val, uint8_t d, size_t n, size_t stride);
+
/****************************************************************************
* Name: nxscope_put_XXXX_m
*
diff --git a/logging/nxscope/nxscope_chan.c b/logging/nxscope/nxscope_chan.c
index 89971479e..472864c3a 100644
--- a/logging/nxscope/nxscope_chan.c
+++ b/logging/nxscope/nxscope_chan.c
@@ -103,33 +103,31 @@ static void nxscope_stream_overflow(FAR struct nxscope_s *s)
}
/****************************************************************************
- * Name: nxscope_ch_validate
+ * Name: nxscope_ch_check
+ *
+ * Description:
+ * Check that the stream is started, the channel is enabled and (with
+ * CONFIG_DEBUG_FEATURES) that the sample matches the channel config
+ *
****************************************************************************/
-static int nxscope_ch_validate(FAR struct nxscope_s *s, uint8_t ch,
- uint8_t type, uint8_t d, uint8_t mlen)
+static int nxscope_ch_check(FAR struct nxscope_s *s, uint8_t ch,
+ uint8_t type, uint8_t d, uint8_t mlen)
{
- union nxscope_chinfo_type_u utype;
- size_t next_i = 0;
- int ret = OK;
- size_t type_size = 0;
-
DEBUGASSERT(s);
/* Do nothing if stream not started */
if (!s->start)
{
- ret = -EAGAIN;
- goto errout;
+ return -EAGAIN;
}
/* Do nothing if channel not enabled */
if (s->chinfo[ch].enable != 1)
{
- ret = -EAGAIN;
- goto errout;
+ return -EAGAIN;
}
/* Some additional checks if debug features enabled */
@@ -140,8 +138,7 @@ static int nxscope_ch_validate(FAR struct nxscope_s *s, uint8_t ch,
if (ch > s->cmninfo.chmax)
{
_err("ERROR: invalid channel %d\n", ch);
- ret = -EINVAL;
- goto errout;
+ return -EINVAL;
}
/* Validate channel type */
@@ -150,8 +147,7 @@ static int nxscope_ch_validate(FAR struct nxscope_s *s, uint8_t ch,
{
_err("ERROR: invalid channel type %d != %d\n",
s->chinfo[ch].type.u8, type);
- ret = -EINVAL;
- goto errout;
+ return -EINVAL;
}
/* Validate channel vdim */
@@ -159,8 +155,7 @@ static int nxscope_ch_validate(FAR struct nxscope_s *s, uint8_t ch,
if (s->chinfo[ch].vdim != d)
{
_err("ERROR: invalid channel dim %d\n", d);
- ret = -EINVAL;
- goto errout;
+ return -EINVAL;
}
/* Validate channel metadata size */
@@ -168,25 +163,53 @@ static int nxscope_ch_validate(FAR struct nxscope_s *s, uint8_t ch,
if (s->chinfo[ch].mlen != mlen)
{
_err("ERROR: invalid channel mlen %d\n", mlen);
- ret = -EINVAL;
- goto errout;
+ return -EINVAL;
}
#endif
-#ifdef CONFIG_LOGGING_NXSCOPE_DIVIDER
- /* Handle sample rate divider */
+ return OK;
+}
+
+/****************************************************************************
+ * Name: nxscope_ch_div
+ *
+ * Description:
+ * Return true if the sample rate divider keeps this channel sample
+ *
+ ****************************************************************************/
+static bool nxscope_ch_div(FAR struct nxscope_s *s, uint8_t ch)
+{
+#ifdef CONFIG_LOGGING_NXSCOPE_DIVIDER
if (s->chinfo[ch].div != 0)
{
s->cntr[ch] += 1;
if (s->cntr[ch] % (s->chinfo[ch].div + 1) != 0)
{
- ret = -EAGAIN;
- goto errout;
+ return false;
}
}
#endif
+ return true;
+}
+
+/****************************************************************************
+ * Name: nxscope_ch_space
+ *
+ * Description:
+ * Check that the target buffer has room for one sample, flag a stream
+ * overflow if not
+ *
+ ****************************************************************************/
+
+static int nxscope_ch_space(FAR struct nxscope_s *s, uint8_t type,
+ uint8_t d, uint8_t mlen)
+{
+ union nxscope_chinfo_type_u utype;
+ size_t next_i = 0;
+ size_t type_size = 0;
+
/* Get utype */
utype.u8 = type;
@@ -217,17 +240,13 @@ static int nxscope_ch_validate(FAR struct nxscope_s *s, uint8_t ch,
{
_err("ERROR: no space in cribuf %zu < %zu\n", s->cribuf_len,
next_i);
- ret = -ENOBUFS;
- goto errout;
+ return -ENOBUFS;
}
- else
# endif
- {
- /* No more checks needed for critical channel */
- ret = OK;
- goto errout;
- }
+ /* No more checks needed for critical channel */
+
+ return OK;
}
#endif
@@ -238,12 +257,33 @@ static int nxscope_ch_validate(FAR struct nxscope_s *s, uint8_t ch,
{
_err("ERROR: no space for data %zu\n", s->stream_i);
nxscope_stream_overflow(s);
- ret = -ENOBUFS;
- goto errout;
+ return -ENOBUFS;
}
-errout:
- return ret;
+ return OK;
+}
+
+/****************************************************************************
+ * Name: nxscope_ch_validate
+ ****************************************************************************/
+
+static int nxscope_ch_validate(FAR struct nxscope_s *s, uint8_t ch,
+ uint8_t type, uint8_t d, uint8_t mlen)
+{
+ int ret;
+
+ ret = nxscope_ch_check(s, ch, type, d, mlen);
+ if (ret != OK)
+ {
+ return ret;
+ }
+
+ if (!nxscope_ch_div(s, ch))
+ {
+ return -EAGAIN;
+ }
+
+ return nxscope_ch_space(s, type, d, mlen);
}
/****************************************************************************
@@ -443,12 +483,20 @@ static void nxscope_put_sample(FAR uint8_t *buff, FAR size_t *buff_i,
}
/****************************************************************************
- * Name: nxscope_put_common_m
+ * Name: nxscope_put_buffer
+ *
+ * Description:
+ * Put one sample on the stream buffer, or send it at once for a critical
+ * channel
+ *
+ * NOTE: This function assumes that we have exclusive access to the nxscope
+ * stream buffer and that the sample was validated
+ *
****************************************************************************/
-static int nxscope_put_common_m(FAR struct nxscope_s *s, uint8_t type,
- uint8_t ch, FAR void *val, uint8_t d,
- FAR uint8_t *meta, uint8_t mlen)
+static int nxscope_put_buffer(FAR struct nxscope_s *s, uint8_t type,
+ uint8_t ch, FAR void *val, uint8_t d,
+ FAR uint8_t *meta, uint8_t mlen)
{
FAR uint8_t *buff = NULL;
FAR size_t *buff_i = NULL;
@@ -458,20 +506,6 @@ static int nxscope_put_common_m(FAR struct nxscope_s *s, uint8_t type,
union nxscope_chinfo_type_u utype;
#endif
- DEBUGASSERT(s);
-
-#ifndef CONFIG_LOGGING_NXSCOPE_DISABLE_PUTLOCK
- nxscope_lock(s);
-#endif
-
- /* Validate data */
-
- ret = nxscope_ch_validate(s, ch, type, d, mlen);
- if (ret != OK)
- {
- goto errout;
- }
-
/* Get buffer to send */
#ifdef CONFIG_LOGGING_NXSCOPE_CRICHANNELS
@@ -505,12 +539,37 @@ static int nxscope_put_common_m(FAR struct nxscope_s *s, uint8_t type,
if (ret < 0)
{
_err("ERROR: nxscope_stream_send failed %d\n", ret);
- goto errout;
}
}
#endif
-errout:
+ return ret;
+}
+
+/****************************************************************************
+ * Name: nxscope_put_common_m
+ ****************************************************************************/
+
+static int nxscope_put_common_m(FAR struct nxscope_s *s, uint8_t type,
+ uint8_t ch, FAR void *val, uint8_t d,
+ FAR uint8_t *meta, uint8_t mlen)
+{
+ int ret = OK;
+
+ DEBUGASSERT(s);
+
+#ifndef CONFIG_LOGGING_NXSCOPE_DISABLE_PUTLOCK
+ nxscope_lock(s);
+#endif
+
+ /* Validate data */
+
+ ret = nxscope_ch_validate(s, ch, type, d, mlen);
+ if (ret == OK)
+ {
+ ret = nxscope_put_buffer(s, type, ch, val, d, meta, mlen);
+ }
+
#ifndef CONFIG_LOGGING_NXSCOPE_DISABLE_PUTLOCK
nxscope_unlock(s);
#endif
@@ -965,6 +1024,50 @@ int nxscope_put_vuint16(FAR struct nxscope_s *s, uint8_t ch,
return nxscope_put_vuint16_m(s, ch, val, d, NULL, 0);
}
+/****************************************************************************
+ * Name: nxscope_put_samples
+ ****************************************************************************/
+
+int nxscope_put_samples(FAR struct nxscope_s *s, uint8_t type, uint8_t ch,
+ FAR void *val, uint8_t d, size_t n, size_t stride)
+{
+ FAR uint8_t *src = val;
+ size_t i = 0;
+ int ret = OK;
+
+ DEBUGASSERT(s);
+ DEBUGASSERT(val);
+
+#ifndef CONFIG_LOGGING_NXSCOPE_DISABLE_PUTLOCK
+ nxscope_lock(s);
+#endif
+
+ /* The same checks as per-sample puts, but once for the whole block */
+
+ ret = nxscope_ch_check(s, ch, type, d, 0);
+
+ for (i = 0; i < n && ret == OK; i++)
+ {
+ if (!nxscope_ch_div(s, ch))
+ {
+ continue;
+ }
+
+ ret = nxscope_ch_space(s, type, d, 0);
+ if (ret == OK)
+ {
+ ret = nxscope_put_buffer(s, type, ch, &src[i * stride], d,
+ NULL, 0);
+ }
+ }
+
+#ifndef CONFIG_LOGGING_NXSCOPE_DISABLE_PUTLOCK
+ nxscope_unlock(s);
+#endif
+
+ return ret;
+}
+
/****************************************************************************
* Name: nxscope_put_vint16
****************************************************************************/
(nuttx-apps) 06/06: include/logging/nxscope/nxscope.h: fix codespell issues
Posted by xi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx-apps.git
commit b1a17ba453b80980ac6a6b7112a790b1f5592c6f
Author: raiden00pl <ra...@railab.me>
AuthorDate: Tue Oct 13 18:55:38 2026 +0200
include/logging/nxscope/nxscope.h: fix codespell issues
fix codespell issues for nxscope.h
Signed-off-by: raiden00pl <ra...@railab.me>
---
include/logging/nxscope/nxscope.h | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/include/logging/nxscope/nxscope.h b/include/logging/nxscope/nxscope.h
index 5b414bd93..d120ebbaa 100644
--- a/include/logging/nxscope/nxscope.h
+++ b/include/logging/nxscope/nxscope.h
@@ -94,7 +94,7 @@ enum nxscope_hdr_id_e
NXSCOPE_HDRID_DIV = 7, /* Channels divider */
/* User defined frames.
- * Must be alway the last element.
+ * Must be always the last element.
*/
NXSCOPE_HDRID_USER = 8
@@ -162,7 +162,7 @@ enum nxscope_set_frame_req_s
{
NXSCOPE_SET_REQ_SINGLE = 0, /* Single channel request */
NXSCOPE_SET_REQ_BULK = 1, /* Set different values for all channels */
- NXSCOPE_SET_REQ_ALL = 2 /* Set one value for all channles */
+ NXSCOPE_SET_REQ_ALL = 2 /* Set one value for all channels */
};
/* Set frame common data */
@@ -174,16 +174,16 @@ begin_packed_struct struct nxscope_set_frame_s
uint8_t data[1]; /* n bytes data - depends on the request type */
} end_packed_struct;
-/* Chanel type */
+/* Channel type */
begin_packed_struct struct nxscope_chinfo_type_s
{
uint8_t dtype:5; /* Data type */
uint8_t _res:2; /* Reserved for future use */
- uint8_t cri:1; /* Criticial channel - no buffering */
+ uint8_t cri:1; /* Critical channel - no buffering */
} end_packed_struct;
-/* Chanel type union */
+/* Channel type union */
union nxscope_chinfo_type_u
{
@@ -197,10 +197,10 @@ begin_packed_struct struct nxscope_chinfo_s
{
uint8_t enable; /* Enable flag */
union nxscope_chinfo_type_u type; /* Channel data type */
- uint8_t vdim; /* Vector dimention */
+ uint8_t vdim; /* Vector dimension */
uint8_t div; /* Divider - starts from 0 */
uint8_t mlen; /* Metadata size */
- FAR char *name; /* Chanel name */
+ FAR char *name; /* Channel name */
} end_packed_struct;
/* Nxscope info common */
@@ -291,7 +291,7 @@ struct nxscope_cfg_s
FAR struct nxscope_callbacks_s *callbacks;
- /* Number of suppoted channels */
+ /* Number of supported channels */
uint8_t channels;
(nuttx-apps) 03/06: logging/nxscope: keep a stream frame intact until it is fully sent
Posted by xi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx-apps.git
commit d8f1282431f63a13aac88a0f7f658fd85f4280ed
Author: raiden00pl <ra...@railab.me>
AuthorDate: Fri Oct 2 10:05:16 2026 +0200
logging/nxscope: keep a stream frame intact until it is fully sent
A failed stream send kept the finalized frame for retry, but later puts
were appended after its footer and the retry sent them without a frame
header, so the client dropped them silently. A partial send was taken as
success and the rest of the frame was lost. A failed critical channel
send also marked the stream buffer for retry, so the next stream frame
went out unfinalized.
A retry now continues where the previous send stopped, puts while a
frame waits are dropped and flagged in the next frame, and only the
stream buffer keeps a frame for retry.
Assisted-by: Claude Code:claude-opus-5-5
Signed-off-by: raiden00pl <ra...@railab.me>
---
include/logging/nxscope/nxscope.h | 2 ++
logging/nxscope/nxscope.c | 6 ++++--
logging/nxscope/nxscope_chan.c | 19 ++++++++++++++++++-
logging/nxscope/nxscope_internals.c | 38 ++++++++++++++++++++++++++++---------
4 files changed, 53 insertions(+), 12 deletions(-)
diff --git a/include/logging/nxscope/nxscope.h b/include/logging/nxscope/nxscope.h
index 79d8c59fc..4f6f902ca 100644
--- a/include/logging/nxscope/nxscope.h
+++ b/include/logging/nxscope/nxscope.h
@@ -371,6 +371,8 @@ struct nxscope_s
size_t streambuf_len;
size_t stream_i;
bool stream_retry;
+ bool stream_ovf;
+ size_t stream_sent;
#ifdef CONFIG_LOGGING_NXSCOPE_CRICHANNELS
/* Critical buffer data */
diff --git a/logging/nxscope/nxscope.c b/logging/nxscope/nxscope.c
index 094395dd8..fa487d864 100644
--- a/logging/nxscope/nxscope.c
+++ b/logging/nxscope/nxscope.c
@@ -472,9 +472,11 @@ static void nxscope_stream_reset(FAR struct nxscope_s *s)
s->stream_i = s->proto_stream->hdrlen + 1;
- /* Reset flags */
+ /* Reset flags, keep an overflow from a frame that waited for retry */
- s->streambuf[s->proto_stream->hdrlen] = 0;
+ s->streambuf[s->proto_stream->hdrlen] =
+ s->stream_ovf ? NXSCOPE_STREAM_FLAGS_OVERFLOW : 0;
+ s->stream_ovf = false;
}
/****************************************************************************
diff --git a/logging/nxscope/nxscope_chan.c b/logging/nxscope/nxscope_chan.c
index 472864c3a..f8013726c 100644
--- a/logging/nxscope/nxscope_chan.c
+++ b/logging/nxscope/nxscope_chan.c
@@ -99,7 +99,16 @@ static void nxscope_stream_overflow(FAR struct nxscope_s *s)
{
DEBUGASSERT(s);
- s->streambuf[s->proto_stream->hdrlen] |= NXSCOPE_STREAM_FLAGS_OVERFLOW;
+ /* A frame waiting for retry is final: flag the next one */
+
+ if (s->stream_retry)
+ {
+ s->stream_ovf = true;
+ }
+ else
+ {
+ s->streambuf[s->proto_stream->hdrlen] |= NXSCOPE_STREAM_FLAGS_OVERFLOW;
+ }
}
/****************************************************************************
@@ -250,6 +259,14 @@ static int nxscope_ch_space(FAR struct nxscope_s *s, uint8_t type,
}
#endif
+ /* The frame in the buffer waits for its retry */
+
+ if (s->stream_retry)
+ {
+ nxscope_stream_overflow(s);
+ return -ENOBUFS;
+ }
+
next_i = (s->stream_i + 1 + type_size * d + mlen +
s->proto_stream->footlen);
diff --git a/logging/nxscope/nxscope_internals.c b/logging/nxscope/nxscope_internals.c
index b001b4187..7995c1965 100644
--- a/logging/nxscope/nxscope_internals.c
+++ b/logging/nxscope/nxscope_internals.c
@@ -55,15 +55,17 @@
int nxscope_stream_send(FAR struct nxscope_s *s, FAR uint8_t *buff,
FAR size_t *buff_i)
{
- int ret = OK;
+ bool stream = (buff == s->streambuf);
+ size_t sent = 0;
+ int ret = OK;
DEBUGASSERT(s);
DEBUGASSERT(buff);
DEBUGASSERT(buff_i);
- /* Finalize stream frame */
+ /* Finalize stream frame, unless it is a stream frame waiting for retry */
- if (!s->stream_retry)
+ if (!stream || !s->stream_retry)
{
ret = PROTO_FRAME_FINAL(s, s->proto_stream,
NXSCOPE_HDRID_STREAM, buff, buff_i);
@@ -74,17 +76,35 @@ int nxscope_stream_send(FAR struct nxscope_s *s, FAR uint8_t *buff,
}
}
- /* Send stream data */
+ /* Send stream data, a retry continues where the previous send stopped */
- ret = INTF_SEND(s, s->intf_stream, buff, *buff_i);
- if (ret < 0)
+ if (stream && s->stream_retry)
+ {
+ sent = s->stream_sent;
+ }
+
+ ret = INTF_SEND(s, s->intf_stream, &buff[sent], *buff_i - sent);
+ if (ret >= 0 && (size_t)ret < *buff_i - sent)
+ {
+ /* Partially sent */
+
+ sent += ret;
+ ret = -EAGAIN;
+ }
+
+ /* A partial send or a full port is backpressure, not an error */
+
+ if (ret < 0 && ret != -EAGAIN)
{
_err("ERROR: INTF_SEND failed %d\n", ret);
- s->stream_retry = true;
}
- else
+
+ /* Only the stream buffer keeps its frame for a retry */
+
+ if (stream)
{
- s->stream_retry = false;
+ s->stream_retry = (ret < 0);
+ s->stream_sent = (ret < 0) ? sent : 0;
}
errout:
(nuttx-apps) 05/06: logging/nxscope: route critical channels by the channel type
Posted by xi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx-apps.git
commit e09557ea8c629337052e2374dab3a4f20225149b
Author: raiden00pl <ra...@railab.me>
AuthorDate: Fri Oct 2 10:05:16 2026 +0200
logging/nxscope: route critical channels by the channel type
Critical routing used the type passed by the put call, which never has
the cri bit, so critical channels were always buffered. When reached,
the sample was written at the start of the critical buffer, where the
frame header overwrote it. Route by the channel info, lay the critical
buffer out as a stream frame and count the flags and channel id bytes
in its size check.
Assisted-by: Claude Code:claude-opus-5-5
Signed-off-by: raiden00pl <ra...@railab.me>
---
include/logging/nxscope/nxscope.h | 2 +-
logging/nxscope/nxscope_chan.c | 34 +++++++++++++++++++++++-----------
2 files changed, 24 insertions(+), 12 deletions(-)
diff --git a/include/logging/nxscope/nxscope.h b/include/logging/nxscope/nxscope.h
index 4f6f902ca..5b414bd93 100644
--- a/include/logging/nxscope/nxscope.h
+++ b/include/logging/nxscope/nxscope.h
@@ -309,7 +309,7 @@ struct nxscope_cfg_s
* It's the user's responsibility to correctly choose this value.
* The minimal buffer size for critical channels can be calculate
* with this formula:
- * buff_size = max(proto_stream->hdrlen + 1 + type_size * vdim +
+ * buff_size = max(proto_stream->hdrlen + 2 + type_size * vdim +
* meta_len + proto_stream->footlen)
*
* where max() means the maximum value from all initialized critical
diff --git a/logging/nxscope/nxscope_chan.c b/logging/nxscope/nxscope_chan.c
index f8013726c..5285d2799 100644
--- a/logging/nxscope/nxscope_chan.c
+++ b/logging/nxscope/nxscope_chan.c
@@ -212,8 +212,8 @@ static bool nxscope_ch_div(FAR struct nxscope_s *s, uint8_t ch)
*
****************************************************************************/
-static int nxscope_ch_space(FAR struct nxscope_s *s, uint8_t type,
- uint8_t d, uint8_t mlen)
+static int nxscope_ch_space(FAR struct nxscope_s *s, uint8_t ch,
+ uint8_t type, uint8_t d, uint8_t mlen)
{
union nxscope_chinfo_type_u utype;
size_t next_i = 0;
@@ -237,10 +237,12 @@ static int nxscope_ch_space(FAR struct nxscope_s *s, uint8_t type,
}
#ifdef CONFIG_LOGGING_NXSCOPE_CRICHANNELS
- if (utype.s.cri)
+ if (s->chinfo[ch].type.s.cri)
{
# ifdef CONFIG_DEBUG_FEATURES
- next_i = (s->proto_stream->hdrlen + 1 + type_size * d + mlen +
+ /* Header, flags, channel id, data, metadata and footer */
+
+ next_i = (s->proto_stream->hdrlen + 2 + type_size * d + mlen +
s->proto_stream->footlen);
/* Verify the size of the critical channels buffer */
@@ -300,7 +302,7 @@ static int nxscope_ch_validate(FAR struct nxscope_s *s, uint8_t ch,
return -EAGAIN;
}
- return nxscope_ch_space(s, type, d, mlen);
+ return nxscope_ch_space(s, ch, type, d, mlen);
}
/****************************************************************************
@@ -520,19 +522,23 @@ static int nxscope_put_buffer(FAR struct nxscope_s *s, uint8_t type,
int ret = OK;
#ifdef CONFIG_LOGGING_NXSCOPE_CRICHANNELS
size_t tmp = 0;
- union nxscope_chinfo_type_u utype;
+ bool cri = s->chinfo[ch].type.s.cri;
#endif
/* Get buffer to send */
#ifdef CONFIG_LOGGING_NXSCOPE_CRICHANNELS
- utype.u8 = type;
- if (utype.s.cri)
+ if (cri)
{
- /* Dedicated critical channels buffer */
+ /* Dedicated critical channels buffer, laid out as a stream frame:
+ * header, flags, then the sample
+ */
buff = s->cribuf;
+ tmp = s->proto_stream->hdrlen + 1;
buff_i = &tmp;
+
+ buff[s->proto_stream->hdrlen] = 0;
}
else
#endif
@@ -548,7 +554,7 @@ static int nxscope_put_buffer(FAR struct nxscope_s *s, uint8_t type,
nxscope_put_sample(buff, buff_i, type, ch, val, d, meta, mlen);
#ifdef CONFIG_LOGGING_NXSCOPE_CRICHANNELS
- if (utype.s.cri)
+ if (cri)
{
/* Send data without buffering */
@@ -557,6 +563,12 @@ static int nxscope_put_buffer(FAR struct nxscope_s *s, uint8_t type,
{
_err("ERROR: nxscope_stream_send failed %d\n", ret);
}
+ else
+ {
+ /* The send returns a byte count, a put returns OK */
+
+ ret = OK;
+ }
}
#endif
@@ -1070,7 +1082,7 @@ int nxscope_put_samples(FAR struct nxscope_s *s, uint8_t type, uint8_t ch,
continue;
}
- ret = nxscope_ch_space(s, type, d, 0);
+ ret = nxscope_ch_space(s, ch, type, d, 0);
if (ret == OK)
{
ret = nxscope_put_buffer(s, type, ch, &src[i * stride], d,