Gary-Hobson commented on code in PR #7554: URL: https://github.com/apache/nuttx/pull/7554#discussion_r1035257133
########## drivers/segger/serial_rtt.c: ########## @@ -0,0 +1,374 @@ +/**************************************************************************** + * drivers/segger/serial_rtt.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <assert.h> +#include <debug.h> +#include <errno.h> +#include <stdbool.h> +#include <stddef.h> +#include <stdint.h> + +#include <nuttx/kmalloc.h> +#include <nuttx/kthread.h> +#include <nuttx/list.h> +#include <nuttx/serial/serial.h> +#include <nuttx/signal.h> + +#include <SEGGER_RTT.h> + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +struct serial_rtt_dev_s +{ + struct list_node node; + struct uart_dev_s uart; + int channel; +}; + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +static int serial_rtt_setup(FAR struct uart_dev_s *dev); +static void serial_rtt_shutdown(FAR struct uart_dev_s *dev); +static int serial_rtt_attach(FAR struct uart_dev_s *dev); +static void serial_rtt_detach(FAR struct uart_dev_s *dev); +static int serial_rtt_ioctl(FAR struct file *filep, int cmd, + unsigned long arg); +static int serial_rtt_receive(FAR struct uart_dev_s *dev, + FAR unsigned int *status); +static void serial_rtt_rxint(FAR struct uart_dev_s *dev, bool enable); +static bool serial_rtt_rxavailable(FAR struct uart_dev_s *dev); +static void serial_rtt_dmasend(FAR struct uart_dev_s *dev); +static void serial_rtt_dmareceive(FAR struct uart_dev_s *dev); +static void serial_rtt_dmarxfree(FAR struct uart_dev_s *dev); +static void serial_rtt_dmatxavail(FAR struct uart_dev_s *dev); +static void serial_rtt_send(FAR struct uart_dev_s *dev, int ch); +static void serial_rtt_txint(FAR struct uart_dev_s *dev, bool enable); +static bool serial_rtt_txready(FAR struct uart_dev_s *dev); +static bool serial_rtt_txempty(FAR struct uart_dev_s *dev); + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +struct list_node g_serial_rtt_list = LIST_INITIAL_VALUE(g_serial_rtt_list); + +static const struct uart_ops_s g_serial_rtt_ops = +{ + serial_rtt_setup, + serial_rtt_shutdown, + serial_rtt_attach, + serial_rtt_detach, + serial_rtt_ioctl, + serial_rtt_receive, + serial_rtt_rxint, + serial_rtt_rxavailable, +#ifdef CONFIG_SERIAL_IFLOWCONTROL + NULL, +#endif + serial_rtt_dmasend, + serial_rtt_dmareceive, + serial_rtt_dmarxfree, + serial_rtt_dmatxavail, + serial_rtt_send, + serial_rtt_txint, + serial_rtt_txready, + serial_rtt_txempty, +}; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: serial_rtt_setup + ****************************************************************************/ + +static int serial_rtt_setup(FAR struct uart_dev_s *dev) +{ + return OK; +} + +/**************************************************************************** + * Name: serial_rtt_shutdown + ****************************************************************************/ + +static void serial_rtt_shutdown(FAR struct uart_dev_s *dev) +{ +} + +/**************************************************************************** + * Name: serial_rtt_attach + ****************************************************************************/ + +static int serial_rtt_attach(FAR struct uart_dev_s *dev) +{ + return OK; +} + +/**************************************************************************** + * Name: serial_rtt_detach + ****************************************************************************/ + +static void serial_rtt_detach(FAR struct uart_dev_s *dev) +{ +} + +/**************************************************************************** + * Name: serial_rtt_ioctl + ****************************************************************************/ + +static int serial_rtt_ioctl(FAR struct file *filep, int cmd, + unsigned long arg) +{ + return -ENOTTY; +} + +/**************************************************************************** + * Name: serial_rtt_receive + ****************************************************************************/ + +static int serial_rtt_receive(FAR struct uart_dev_s *dev, + FAR unsigned int *status) +{ + return -ENOSYS; +} + +/**************************************************************************** + * Name: serial_rtt_rxint + ****************************************************************************/ + +static void serial_rtt_rxint(FAR struct uart_dev_s *dev, bool enable) +{ +} + +/**************************************************************************** + * Name: serial_rtt_rxavailable + ****************************************************************************/ + +static bool serial_rtt_rxavailable(FAR struct uart_dev_s *dev) +{ + FAR struct serial_rtt_dev_s *rtt = + (FAR struct serial_rtt_dev_s *)dev->priv; + return SEGGER_RTT_HasData(rtt->channel) != 0; +} + +/**************************************************************************** + * Name: serial_rtt_dmasend + ****************************************************************************/ + +static void serial_rtt_dmasend(FAR struct uart_dev_s *dev) +{ + FAR struct serial_rtt_dev_s *rtt = + (FAR struct serial_rtt_dev_s *)dev->priv; + FAR SEGGER_RTT_BUFFER_UP *ring = (SEGGER_RTT_BUFFER_UP *)((FAR char *) + &_SEGGER_RTT.aUp[rtt->channel] + SEGGER_RTT_UNCACHED_OFF); + FAR struct uart_dmaxfer_s *xfer = &dev->dmatx; + size_t len = xfer->length + xfer->nlength; + + if (rtt->channel) + { + ring->WrOff = (ring->WrOff + len) % dev->xmit.size; + } + else + { + SEGGER_RTT_Write(rtt->channel, xfer->buffer, xfer->length); Review Comment: done -- 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: commits-unsubscr...@nuttx.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org