You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by GitBox <gi...@apache.org> on 2022/11/28 15:08:43 UTC

[GitHub] [nuttx] pkarashchenko commented on a diff in pull request #7554: drivers/segger: add rtt console support

pkarashchenko commented on code in PR #7554:
URL: https://github.com/apache/nuttx/pull/7554#discussion_r1033661042


##########
drivers/segger/serial_rtt.c:
##########
@@ -0,0 +1,368 @@
+/****************************************************************************
+ * 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 <SEGGER_RTT.h>
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+struct rtt_dev_s
+{
+  int channel;
+  FAR char *txbuf;
+  FAR char *rxbuf;
+  struct list_node node;
+  struct uart_dev_s uart;
+};
+
+/****************************************************************************
+ * 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,
+                              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_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);
+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);
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+struct list_node g_rtt_dev_list = LIST_INITIAL_VALUE(g_rtt_dev_list);
+
+static const struct uart_ops_s g_serial_rtt_ops =
+{
+  .setup = serial_rtt_setup,
+  .shutdown = serial_rtt_shutdown,
+  .attach = serial_rtt_attach,
+  .detach = serial_rtt_detach,
+  .ioctl = serial_rtt_ioctl,
+  .receive = serial_rtt_receive,
+  .rxint = serial_rtt_rxint,
+  .dmasend = serial_rtt_dmasend,
+  .dmareceive = serial_rtt_dmareceive,
+  .dmarxfree = serial_rtt_dmarxfree,
+  .dmatxavail = serial_rtt_dmatxavail,
+  .rxavailable = serial_rtt_rxavailable,
+  .send = serial_rtt_send,
+  .txint = serial_rtt_txint,
+  .txready = serial_rtt_txready,
+  .txempty = 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_rxint
+ ****************************************************************************/
+
+static void serial_rtt_rxint(FAR struct uart_dev_s *dev, bool enable)
+{
+}
+
+/****************************************************************************
+ * Name: serial_rtt_receive
+ ****************************************************************************/
+
+static int serial_rtt_receive(FAR struct uart_dev_s *dev,
+                              unsigned int *status)
+{
+  return -1;
+}
+
+/****************************************************************************
+ * Name: serial_rtt_dmarxfree
+ ****************************************************************************/
+
+static void serial_rtt_dmarxfree(FAR struct uart_dev_s *dev)
+{
+}
+
+/****************************************************************************
+ * Name: serial_rtt_txint
+ ****************************************************************************/
+
+static void serial_rtt_txint(FAR struct uart_dev_s *dev, bool enable)
+{
+}
+
+/****************************************************************************
+ * Name: serial_rtt_txready
+ ****************************************************************************/
+
+static bool serial_rtt_txready(FAR struct uart_dev_s *dev)
+{
+  return true;
+}
+
+/****************************************************************************
+ * Name: serial_rtt_send
+ ****************************************************************************/
+
+static void serial_rtt_send(FAR struct uart_dev_s *dev, int ch)
+{
+}
+
+/****************************************************************************
+ * Name: serial_rtt_txempty
+ ****************************************************************************/
+
+static bool serial_rtt_txempty(FAR struct uart_dev_s *dev)
+{
+  return true;
+}
+
+/****************************************************************************
+ * Name: serial_rtt_dmasend
+ ****************************************************************************/
+
+static void serial_rtt_dmasend(FAR struct uart_dev_s *dev)
+{
+  SEGGER_RTT_BUFFER_UP *pRing;

Review Comment:
   ```suggestion
     FAR SEGGER_RTT_BUFFER_UP *pRing;
   ```
   



##########
drivers/segger/serial_rtt.c:
##########
@@ -0,0 +1,368 @@
+/****************************************************************************
+ * 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 <SEGGER_RTT.h>
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+struct rtt_dev_s
+{
+  int channel;
+  FAR char *txbuf;
+  FAR char *rxbuf;
+  struct list_node node;
+  struct uart_dev_s uart;
+};
+
+/****************************************************************************
+ * 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,
+                              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_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);
+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);
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+struct list_node g_rtt_dev_list = LIST_INITIAL_VALUE(g_rtt_dev_list);
+
+static const struct uart_ops_s g_serial_rtt_ops =
+{
+  .setup = serial_rtt_setup,
+  .shutdown = serial_rtt_shutdown,
+  .attach = serial_rtt_attach,
+  .detach = serial_rtt_detach,
+  .ioctl = serial_rtt_ioctl,
+  .receive = serial_rtt_receive,
+  .rxint = serial_rtt_rxint,
+  .dmasend = serial_rtt_dmasend,
+  .dmareceive = serial_rtt_dmareceive,
+  .dmarxfree = serial_rtt_dmarxfree,
+  .dmatxavail = serial_rtt_dmatxavail,
+  .rxavailable = serial_rtt_rxavailable,
+  .send = serial_rtt_send,
+  .txint = serial_rtt_txint,
+  .txready = serial_rtt_txready,
+  .txempty = 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_rxint
+ ****************************************************************************/
+
+static void serial_rtt_rxint(FAR struct uart_dev_s *dev, bool enable)
+{
+}
+
+/****************************************************************************
+ * Name: serial_rtt_receive
+ ****************************************************************************/
+
+static int serial_rtt_receive(FAR struct uart_dev_s *dev,
+                              unsigned int *status)
+{
+  return -1;
+}
+
+/****************************************************************************
+ * Name: serial_rtt_dmarxfree
+ ****************************************************************************/
+
+static void serial_rtt_dmarxfree(FAR struct uart_dev_s *dev)
+{
+}
+
+/****************************************************************************
+ * Name: serial_rtt_txint
+ ****************************************************************************/
+
+static void serial_rtt_txint(FAR struct uart_dev_s *dev, bool enable)
+{
+}
+
+/****************************************************************************
+ * Name: serial_rtt_txready
+ ****************************************************************************/
+
+static bool serial_rtt_txready(FAR struct uart_dev_s *dev)
+{
+  return true;
+}
+
+/****************************************************************************
+ * Name: serial_rtt_send
+ ****************************************************************************/
+
+static void serial_rtt_send(FAR struct uart_dev_s *dev, int ch)
+{
+}
+
+/****************************************************************************
+ * Name: serial_rtt_txempty
+ ****************************************************************************/
+
+static bool serial_rtt_txempty(FAR struct uart_dev_s *dev)
+{
+  return true;
+}
+
+/****************************************************************************
+ * Name: serial_rtt_dmasend
+ ****************************************************************************/
+
+static void serial_rtt_dmasend(FAR struct uart_dev_s *dev)
+{
+  SEGGER_RTT_BUFFER_UP *pRing;
+  FAR struct rtt_dev_s *rtt = (FAR struct rtt_dev_s *)dev->priv;
+  FAR struct uart_dmaxfer_s *xfer = &dev->dmatx;
+  size_t len = xfer->length + xfer->nlength;
+  pRing = (SEGGER_RTT_BUFFER_UP *)((char *)&_SEGGER_RTT.aUp[rtt->channel]

Review Comment:
   ```suggestion
     pRing = (FAR SEGGER_RTT_BUFFER_UP *)((FAR char *)&_SEGGER_RTT.aUp[rtt->channel]
   ```
   



##########
drivers/segger/serial_rtt.c:
##########
@@ -0,0 +1,368 @@
+/****************************************************************************
+ * 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 <SEGGER_RTT.h>
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+struct rtt_dev_s
+{
+  int channel;
+  FAR char *txbuf;
+  FAR char *rxbuf;
+  struct list_node node;
+  struct uart_dev_s uart;
+};
+
+/****************************************************************************
+ * 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,
+                              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_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);
+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);
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+struct list_node g_rtt_dev_list = LIST_INITIAL_VALUE(g_rtt_dev_list);
+
+static const struct uart_ops_s g_serial_rtt_ops =
+{
+  .setup = serial_rtt_setup,

Review Comment:
   Can we use C89 compatible struct init?



-- 
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-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org