CV-Bowen opened a new pull request, #22352:
URL: https://github.com/apache/nuttx/pull/22352

   ## Summary
   
   `uart_ram` carried a serial upper half over a shared ring, so every byte was
   copied into a local xmit/recv buffer on its way to the ring and a watchdog
   moved it in interrupt context.
   
   Register it as a `file_operations` character device on the rings instead:
   
   - `read()` and `write()` copy between the caller's buffer and the ring;
     a mutex per direction keeps each ring single-producer/single-consumer.
   - The watchdog only binds the slave side, wakes waiters and reports poll
     events; it no longer moves data.
   - `FIONREAD` and `TIOCVHANGUP` are kept for `rpmsg_port_uart`.
   - `RAM_UART_NPOLLWAITERS` is added for the poll waiters, and
     `RAM_UART_BUFSIZE` is now the capacity of one direction of the ring.
   
   ## Impact
   
   - **The shared memory layout changes.** `struct uart_rambuf_s` (a buffer and
     two offsets) becomes a `ring_blob_t` array, so both ends of a link must be
     updated together. `uart_ram_register()` takes the new type; the in-tree
     caller, `arch/sim/src/sim/sim_uart.c`, is updated in this commit.
   - `RAM_UART` no longer selects `SERIAL_RXDMA`/`SERIAL_TXDMA`, since the 
driver
     no longer sits under the serial upper half. A configuration that opened the
     device through the serial layer (`/dev/ttyVS0` as a `uart_dev_s`) now gets 
a
     plain character device with the same path.
   - The device keeps its name; `read()`/`write()`/`poll()`/`ioctl()` behaviour
     is unchanged for callers.
   
   ## Testing
   
   Host: Ubuntu 22.04.5 LTS x86_64; gcc 13.1.0.
   
   **Two `sim` instances** sharing `/dev/ttyVS0` through the host shm
   (`sim_uartram_register()`), one master and one slave, exchange data both
   ways. `hello w <text>` writes, `hello r <n>` polls then reads:
   
   ```
   note   both shells up
   master wrote 8 of 8
   slave  poll=1 revents=0x1
   slave  read 8 [PING1234]
   slave  wrote 8 of 8
   master poll=1 revents=0x1
   master read 8 [PONG5678]
   ```
   
   The same run against master has no character device to open: the device is a
   `uart_dev_s` and the calls go through the serial upper half, so the new
   interface cannot be exercised there.
   
   **Builds**, 0 warnings each:
   
   | config | what it covers |
   |---|---|
   | `sim:nsh` + `SIM_RAM_UART0`, master and slave | host shm registration, 
`uart_ram_register()` |
   | `sim:nsh` + `RAM_UART0` + `RAM_UART1` | the static buffer path in 
`ram_serialinit()` |
   
   <details><summary>Test program (not part of this PR)</summary>
   
   ```c
   #include <nuttx/config.h>
   #include <stdio.h>
   #include <stdlib.h>
   #include <string.h>
   #include <fcntl.h>
   #include <unistd.h>
   #include <poll.h>
   
   #define PATH "/dev/ttyVS0"
   
   int main(int argc, FAR char *argv[])
   {
     struct pollfd pfd;
     char buf[64];
     ssize_t n;
     int ret;
     int fd;
   
     fd = open(PATH, O_RDWR);
     if (fd < 0)
       {
         printf("open %s failed: %d\n", PATH, fd);
         return 1;
       }
   
     if (argc >= 3 && strcmp(argv[1], "w") == 0)
       {
         n = write(fd, argv[2], strlen(argv[2]));
         printf("wrote %ld of %zu\n", (long)n, strlen(argv[2]));
       }
     else if (argc >= 2 && strcmp(argv[1], "r") == 0)
       {
         int len = argc >= 3 ? atoi(argv[2]) : 8;
   
         pfd.fd = fd;
         pfd.events = POLLIN;
         pfd.revents = 0;
         ret = poll(&pfd, 1, 3000);
         printf("poll=%d revents=0x%x\n", ret, pfd.revents);
   
         n = read(fd, buf, len);
         buf[n > 0 ? n : 0] = '\0';
         printf("read %ld [%s]\n", (long)n, buf);
       }
   
     close(fd);
     return 0;
   }
   ```
   
   </details>
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to