This is an automated email from the ASF dual-hosted git repository. GUIDINGLI pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit fb548a4c7fbece63e645f3ad892f6081da1ec5bd Author: Bowen Wang <[email protected]> AuthorDate: Sat Nov 28 09:11:07 2026 +0800 !drivers/rpmsg/rpmsg_port: always carry the timestamps in the port header The timestamps sit in rpmsg_port_header_s with RETX and at the tail of the buffer without it, so the frame layout, the payload size and the timestamp accessors all depend on CONFIG_RPMSG_PORT_RETX. Keep tx_nsec and rx_nsec in the header in both cases: one layout at a fixed offset, and no buffer length check to read them. BREAKING CHANGE: without CONFIG_RPMSG_PORT_RETX the port header grows from 8 to 24 bytes and the timestamps move from the tail of the buffer into it. Both ends of an rpmsg_port link (SPI or UART) must run the same layout; update them together. The payload size of a buffer is unchanged. Signed-off-by: Bowen Wang <[email protected]> --- drivers/rpmsg/rpmsg_port.c | 44 +++----------------------------------------- drivers/rpmsg/rpmsg_port.h | 2 +- 2 files changed, 4 insertions(+), 42 deletions(-) diff --git a/drivers/rpmsg/rpmsg_port.c b/drivers/rpmsg/rpmsg_port.c index 51cdfe7b79e..25cee48da71 100644 --- a/drivers/rpmsg/rpmsg_port.c +++ b/drivers/rpmsg/rpmsg_port.c @@ -42,14 +42,6 @@ #define RPMSG_PORT_TIMEOUT_MS 15000 -/* Without RETX the timestamps are kept at the tail of the buffer */ - -#ifdef CONFIG_RPMSG_PORT_RETX -# define RPMSG_PORT_TAIL_SIZE 0 -#else -# define RPMSG_PORT_TAIL_SIZE sizeof(struct rpmsg_timestamp_s) -#endif - #define rpmsg_port_from_rdev(d) container_of(d, struct rpmsg_port_s, rdev) #define rpmsg_port_hdr_from_buf(r) \ container_of(r, struct rpmsg_port_header_s, buf) @@ -273,7 +265,7 @@ rpmsg_port_get_tx_payload_buffer(FAR struct rpmsg_device *rdev, } *len = hdr->len - sizeof(struct rpmsg_port_header_s) - - sizeof(struct rpmsg_hdr) - RPMSG_PORT_TAIL_SIZE; + sizeof(struct rpmsg_hdr); return RPMSG_LOCATE_DATA(hdr->buf); } @@ -393,7 +385,7 @@ static int rpmsg_port_get_tx_buffer_size(FAR struct rpmsg_device *rdev) FAR struct rpmsg_port_s *port = rpmsg_port_from_rdev(rdev); return port->txq.len - sizeof(struct rpmsg_port_header_s) - - sizeof(struct rpmsg_hdr) - RPMSG_PORT_TAIL_SIZE; + sizeof(struct rpmsg_hdr); } /**************************************************************************** @@ -405,7 +397,7 @@ static int rpmsg_port_get_rx_buffer_size(FAR struct rpmsg_device *rdev) FAR struct rpmsg_port_s *port = rpmsg_port_from_rdev(rdev); return port->rxq.len - sizeof(struct rpmsg_port_header_s) - - sizeof(struct rpmsg_hdr) - RPMSG_PORT_TAIL_SIZE; + sizeof(struct rpmsg_hdr); } /**************************************************************************** @@ -418,23 +410,9 @@ static int rpmsg_port_get_timestamp(FAR struct rpmsg_s *rpmsg, { FAR const struct rpmsg_hdr *rphdr = RPMSG_LOCATE_HDR(data); FAR const struct rpmsg_port_header_s *hdr = rpmsg_port_hdr_from_buf(rphdr); -#ifndef CONFIG_RPMSG_PORT_RETX - FAR struct rpmsg_port_s *port = (FAR struct rpmsg_port_s *)rpmsg; - FAR const struct rpmsg_timestamp_s *rpts = - (FAR const struct rpmsg_timestamp_s *)((uint8_t *)hdr + port->rxq.len - - sizeof(struct rpmsg_timestamp_s)); - if (hdr->len > port->rxq.len - sizeof(struct rpmsg_timestamp_s)) - { - return -EINVAL; - } - - ts->tx_nsec = rpts->tx_nsec; - ts->rx_nsec = rpts->rx_nsec; -#else ts->tx_nsec = hdr->tx_nsec; ts->rx_nsec = hdr->rx_nsec; -#endif return RPMSG_SUCCESS; } @@ -714,21 +692,6 @@ void rpmsg_port_update_timestamp(FAR struct rpmsg_port_queue_s *queue, { struct timespec ts; -#ifndef CONFIG_RPMSG_PORT_RETX - FAR struct rpmsg_timestamp_s *rpts = - (FAR struct rpmsg_timestamp_s *)((uint8_t *)hdr + queue->len - - sizeof(struct rpmsg_timestamp_s)); - - clock_gettime(CLOCK_MONOTONIC, &ts); - if (tx) - { - rpts->tx_nsec = 1000000000ull * ts.tv_sec + ts.tv_nsec; - } - else if (hdr->len <= queue->len - sizeof(struct rpmsg_timestamp_s)) - { - rpts->rx_nsec = 1000000000ull * ts.tv_sec + ts.tv_nsec; - } -#else clock_gettime(CLOCK_MONOTONIC, &ts); if (tx) { @@ -738,7 +701,6 @@ void rpmsg_port_update_timestamp(FAR struct rpmsg_port_queue_s *queue, { hdr->rx_nsec = 1000000000ull * ts.tv_sec + ts.tv_nsec; } -#endif } /**************************************************************************** diff --git a/drivers/rpmsg/rpmsg_port.h b/drivers/rpmsg/rpmsg_port.h index 01b134997cb..6e81ab9d09a 100644 --- a/drivers/rpmsg/rpmsg_port.h +++ b/drivers/rpmsg/rpmsg_port.h @@ -65,9 +65,9 @@ begin_packed_struct struct rpmsg_port_header_s uint16_t cmd; /* Reserved for uart/spi port driver */ uint16_t avail; /* Available rx buffer of peer side */ uint16_t len; /* Data frame length */ -#ifdef CONFIG_RPMSG_PORT_RETX uint64_t tx_nsec; /* TX timestamp in nanoseconds */ uint64_t rx_nsec; /* RX timestamp in nanoseconds */ +#ifdef CONFIG_RPMSG_PORT_RETX uint16_t seqno; uint16_t ackno; uint16_t min_seq;
