xiaoxiang781216 commented on code in PR #7678:
URL: https://github.com/apache/nuttx/pull/7678#discussion_r1032546737


##########
drivers/segger/rtt_stream.c:
##########
@@ -0,0 +1,126 @@
+/****************************************************************************
+ * drivers/segger/rtt_stream.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 <nuttx/config.h>
+#include <nuttx/kmalloc.h>
+#include <nuttx/streams.h>
+#include <nuttx/segger/rtt.h>
+
+#include <SEGGER_RTT.h>
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: rttstream_putc
+ ****************************************************************************/
+
+static void rttstream_putc(FAR struct lib_outstream_s *this, int ch)
+{
+  FAR struct lib_rttoutstream_s *stream = this;
+  stream->public.nput += SEGGER_RTT_PutChar(stream->channel, ch);
+}
+
+/****************************************************************************
+ * Name: rttstream_puts
+ ****************************************************************************/
+
+static int rttstream_puts(FAR struct lib_outstream_s *this,
+                          FAR const void *buf, int len)
+{
+  int ret;
+  FAR struct lib_rttoutstream_s *stream = this;
+  ret = SEGGER_RTT_Write(stream->channel, buf, len);
+  stream->public.nput += ret;
+  return ret;
+}
+
+/****************************************************************************
+ * Name: rttstream_getc
+ ****************************************************************************/
+
+static int rttstream_getc(FAR struct lib_instream_s *this)
+{
+  int ch;
+  FAR struct lib_rttinstream_s *stream = this;
+
+  DEBUGASSERT(stream);
+  stream->public.nget++;
+  SEGGER_RTT_Read(stream->channel, &ch, 1);
+  return ch;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: lib_rttoutstream
+ *
+ * Description:
+ *   Initializes a stream for use with the configured RTT interface.
+ *
+ * Input Parameters:
+ *   stream - User allocated, uninitialized instance of struct
+ *            lib_rttoutstream_s to be initialized.
+ *   channel - SEGGER RTT channel number
+ *
+ * Returned Value:
+ *   None (User allocated instance initialized).
+ *
+ ****************************************************************************/
+
+void lib_rttoutstream(FAR struct lib_rttoutstream_s *stream, int channel)
+{
+  DEBUGASSERT(stream != NULL);
+  stream->public.put = rttstream_putc;
+  stream->public.puts = rttstream_puts;
+  stream->public.flush = lib_noflush;
+  stream->public.nput = 0;
+  stream->channel = channel;
+}
+
+/****************************************************************************
+ * Name: lib_rttinstream
+ *
+ * Description:
+ *   Initializes output stream for use with the configured RTT interface.
+ *
+ * Input Parameters:
+ *   stream - User allocated, uninitialized instance of struct
+ *            lib_rttinstream_s to be initialized.
+ *   channel - SEGGER RTT channel number
+ *
+ ****************************************************************************/
+
+void lib_rttinstream(FAR struct lib_rttinstream_s *stream, int channel)

Review Comment:
   need call SEGGER_RTT_AllocDownBuffer when channel isn't equal zero



##########
drivers/segger/rtt_stream.c:
##########
@@ -0,0 +1,126 @@
+/****************************************************************************
+ * drivers/segger/rtt_stream.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 <nuttx/config.h>
+#include <nuttx/kmalloc.h>
+#include <nuttx/streams.h>
+#include <nuttx/segger/rtt.h>
+
+#include <SEGGER_RTT.h>
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: rttstream_putc
+ ****************************************************************************/
+
+static void rttstream_putc(FAR struct lib_outstream_s *this, int ch)
+{
+  FAR struct lib_rttoutstream_s *stream = this;
+  stream->public.nput += SEGGER_RTT_PutChar(stream->channel, ch);
+}
+
+/****************************************************************************
+ * Name: rttstream_puts
+ ****************************************************************************/
+
+static int rttstream_puts(FAR struct lib_outstream_s *this,
+                          FAR const void *buf, int len)
+{
+  int ret;
+  FAR struct lib_rttoutstream_s *stream = this;
+  ret = SEGGER_RTT_Write(stream->channel, buf, len);
+  stream->public.nput += ret;
+  return ret;
+}
+
+/****************************************************************************
+ * Name: rttstream_getc
+ ****************************************************************************/
+
+static int rttstream_getc(FAR struct lib_instream_s *this)
+{
+  int ch;
+  FAR struct lib_rttinstream_s *stream = this;
+
+  DEBUGASSERT(stream);
+  stream->public.nget++;
+  SEGGER_RTT_Read(stream->channel, &ch, 1);
+  return ch;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: lib_rttoutstream
+ *
+ * Description:
+ *   Initializes a stream for use with the configured RTT interface.
+ *
+ * Input Parameters:
+ *   stream - User allocated, uninitialized instance of struct
+ *            lib_rttoutstream_s to be initialized.
+ *   channel - SEGGER RTT channel number
+ *
+ * Returned Value:
+ *   None (User allocated instance initialized).
+ *
+ ****************************************************************************/
+
+void lib_rttoutstream(FAR struct lib_rttoutstream_s *stream, int channel)
+{
+  DEBUGASSERT(stream != NULL);

Review Comment:
   need call SEGGER_RTT_AllocUpBuffer when channel isn't equal zero



##########
drivers/segger/rtt_stream.c:
##########
@@ -0,0 +1,126 @@
+/****************************************************************************
+ * drivers/segger/rtt_stream.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 <nuttx/config.h>
+#include <nuttx/kmalloc.h>
+#include <nuttx/streams.h>
+#include <nuttx/segger/rtt.h>
+
+#include <SEGGER_RTT.h>
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: rttstream_putc
+ ****************************************************************************/
+
+static void rttstream_putc(FAR struct lib_outstream_s *this, int ch)
+{
+  FAR struct lib_rttoutstream_s *stream = this;
+  stream->public.nput += SEGGER_RTT_PutChar(stream->channel, ch);
+}
+
+/****************************************************************************
+ * Name: rttstream_puts
+ ****************************************************************************/
+
+static int rttstream_puts(FAR struct lib_outstream_s *this,
+                          FAR const void *buf, int len)
+{
+  int ret;
+  FAR struct lib_rttoutstream_s *stream = this;
+  ret = SEGGER_RTT_Write(stream->channel, buf, len);

Review Comment:
   merge with the next line



##########
drivers/segger/rtt_stream.c:
##########
@@ -0,0 +1,126 @@
+/****************************************************************************
+ * drivers/segger/rtt_stream.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 <nuttx/config.h>
+#include <nuttx/kmalloc.h>
+#include <nuttx/streams.h>
+#include <nuttx/segger/rtt.h>
+
+#include <SEGGER_RTT.h>
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: rttstream_putc
+ ****************************************************************************/
+
+static void rttstream_putc(FAR struct lib_outstream_s *this, int ch)
+{
+  FAR struct lib_rttoutstream_s *stream = this;
+  stream->public.nput += SEGGER_RTT_PutChar(stream->channel, ch);
+}
+
+/****************************************************************************
+ * Name: rttstream_puts
+ ****************************************************************************/
+
+static int rttstream_puts(FAR struct lib_outstream_s *this,
+                          FAR const void *buf, int len)
+{
+  int ret;
+  FAR struct lib_rttoutstream_s *stream = this;

Review Comment:
   need cast



##########
drivers/segger/rtt_stream.c:
##########
@@ -0,0 +1,126 @@
+/****************************************************************************
+ * drivers/segger/rtt_stream.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 <nuttx/config.h>
+#include <nuttx/kmalloc.h>
+#include <nuttx/streams.h>
+#include <nuttx/segger/rtt.h>
+
+#include <SEGGER_RTT.h>
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: rttstream_putc
+ ****************************************************************************/
+
+static void rttstream_putc(FAR struct lib_outstream_s *this, int ch)
+{
+  FAR struct lib_rttoutstream_s *stream = this;

Review Comment:
   need cast



##########
drivers/segger/rtt_stream.c:
##########
@@ -0,0 +1,126 @@
+/****************************************************************************
+ * drivers/segger/rtt_stream.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 <nuttx/config.h>
+#include <nuttx/kmalloc.h>
+#include <nuttx/streams.h>
+#include <nuttx/segger/rtt.h>
+
+#include <SEGGER_RTT.h>
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: rttstream_putc
+ ****************************************************************************/
+
+static void rttstream_putc(FAR struct lib_outstream_s *this, int ch)
+{
+  FAR struct lib_rttoutstream_s *stream = this;
+  stream->public.nput += SEGGER_RTT_PutChar(stream->channel, ch);
+}
+
+/****************************************************************************
+ * Name: rttstream_puts
+ ****************************************************************************/
+
+static int rttstream_puts(FAR struct lib_outstream_s *this,
+                          FAR const void *buf, int len)
+{
+  int ret;
+  FAR struct lib_rttoutstream_s *stream = this;
+  ret = SEGGER_RTT_Write(stream->channel, buf, len);
+  stream->public.nput += ret;
+  return ret;
+}
+
+/****************************************************************************
+ * Name: rttstream_getc
+ ****************************************************************************/
+
+static int rttstream_getc(FAR struct lib_instream_s *this)
+{
+  int ch;
+  FAR struct lib_rttinstream_s *stream = this;
+
+  DEBUGASSERT(stream);
+  stream->public.nget++;
+  SEGGER_RTT_Read(stream->channel, &ch, 1);
+  return ch;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: lib_rttoutstream
+ *
+ * Description:
+ *   Initializes a stream for use with the configured RTT interface.
+ *
+ * Input Parameters:
+ *   stream - User allocated, uninitialized instance of struct
+ *            lib_rttoutstream_s to be initialized.
+ *   channel - SEGGER RTT channel number
+ *
+ * Returned Value:
+ *   None (User allocated instance initialized).
+ *
+ ****************************************************************************/
+
+void lib_rttoutstream(FAR struct lib_rttoutstream_s *stream, int channel)
+{
+  DEBUGASSERT(stream != NULL);
+  stream->public.put = rttstream_putc;
+  stream->public.puts = rttstream_puts;
+  stream->public.flush = lib_noflush;
+  stream->public.nput = 0;
+  stream->channel = channel;
+}
+
+/****************************************************************************
+ * Name: lib_rttinstream
+ *
+ * Description:
+ *   Initializes output stream for use with the configured RTT interface.
+ *
+ * Input Parameters:
+ *   stream - User allocated, uninitialized instance of struct
+ *            lib_rttinstream_s to be initialized.
+ *   channel - SEGGER RTT channel number
+ *
+ ****************************************************************************/
+
+void lib_rttinstream(FAR struct lib_rttinstream_s *stream, int channel)
+{
+  DEBUGASSERT(stream != NULL);
+  stream->public.get = rttstream_getc;

Review Comment:
   let's implement gets too



-- 
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

Reply via email to