You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2021/03/22 16:47:15 UTC

[incubator-nuttx-apps] branch master updated (4c256e7 -> 3bf2f31)

This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx-apps.git.


    from 4c256e7  netutils/dhcpd: handshake the dhcpd message with server port.
     new 8e3eca1  apps/examples: Adds termios example
     new 577598d  Apply 2 suggestion(s) to 1 file(s)
     new afad97d  Apply 2 suggestion(s) to 2 file(s)
     new 3bf2f31  fixed coding style issue

The 4 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 examples/README.md                            |   9 ++
 examples/termios/Kconfig                      |  24 +++++
 {fsutils/ipcfg => examples/termios}/Make.defs |   6 +-
 examples/{i2sloop => termios}/Makefile        |  16 ++--
 examples/termios/termios_main.c               | 129 ++++++++++++++++++++++++++
 5 files changed, 173 insertions(+), 11 deletions(-)
 create mode 100644 examples/termios/Kconfig
 copy {fsutils/ipcfg => examples/termios}/Make.defs (89%)
 copy examples/{i2sloop => termios}/Makefile (78%)
 create mode 100644 examples/termios/termios_main.c

[incubator-nuttx-apps] 04/04: fixed coding style issue

Posted by xi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx-apps.git

commit 3bf2f317169f07bcd6f83022e46fc18b01aec9be
Author: Sara Souza <sa...@espressif.com>
AuthorDate: Mon Mar 22 10:09:24 2021 -0300

    fixed coding style issue
---
 examples/termios/termios_main.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/examples/termios/termios_main.c b/examples/termios/termios_main.c
index 44512af..d34cce5 100644
--- a/examples/termios/termios_main.c
+++ b/examples/termios/termios_main.c
@@ -123,6 +123,7 @@ int main(int argc, FAR char *argv[])
             "Expected error code: 0. Current code: %d\n", error);
       sleep(1);
     }
+
   return 0;
 }
 

[incubator-nuttx-apps] 02/04: Apply 2 suggestion(s) to 1 file(s)

Posted by xi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx-apps.git

commit 577598d2dfc6cfc582d2a7dbdef6b445d152b7e4
Author: Sara Souza <sa...@espressif.com>
AuthorDate: Fri Mar 12 01:05:15 2021 +0800

    Apply 2 suggestion(s) to 1 file(s)
---
 examples/termios/termios_main.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/examples/termios/termios_main.c b/examples/termios/termios_main.c
index 7af7689..44512af 100644
--- a/examples/termios/termios_main.c
+++ b/examples/termios/termios_main.c
@@ -36,7 +36,7 @@
  * main
  ****************************************************************************/
 
-void main(int argc, FAR char *argv[])
+int main(int argc, FAR char *argv[])
 {
   int fd;
   int ret;
@@ -123,5 +123,6 @@ void main(int argc, FAR char *argv[])
             "Expected error code: 0. Current code: %d\n", error);
       sleep(1);
     }
+  return 0;
 }
 

[incubator-nuttx-apps] 03/04: Apply 2 suggestion(s) to 2 file(s)

Posted by xi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx-apps.git

commit afad97d9f8c28cb853aa0fe4a6c32a8a354f4b75
Author: Sara Souza <sa...@espressif.com>
AuthorDate: Sat Mar 13 01:57:14 2021 +0800

    Apply 2 suggestion(s) to 2 file(s)
---
 examples/termios/Kconfig  | 2 +-
 examples/termios/Makefile | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/examples/termios/Kconfig b/examples/termios/Kconfig
index e322f70..1e0e673 100644
--- a/examples/termios/Kconfig
+++ b/examples/termios/Kconfig
@@ -9,7 +9,7 @@ config EXAMPLES_TERMIOS
 	---help---
 		Enable the Termios example. This example
 		shows how to change serial parameters like baud rate,
-		stop bits, data lenght and parity using the termios interface.
+		stop bits, data length and parity using the termios interface.
 
 if EXAMPLES_TERMIOS
 
diff --git a/examples/termios/Makefile b/examples/termios/Makefile
index 9c038ac..c24adcb 100644
--- a/examples/termios/Makefile
+++ b/examples/termios/Makefile
@@ -20,7 +20,7 @@
 
 include $(APPDIR)/Make.defs
 
-# Termios Example! built-in application info
+# Termios example built-in application info
 
 PROGNAME  = termios
 PRIORITY  = $(CONFIG_EXAMPLES_TERMIOS_PRIORITY)

[incubator-nuttx-apps] 01/04: apps/examples: Adds termios example

Posted by xi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx-apps.git

commit 8e3eca1836d7dabecb6e69ed11b8ac4c54cb56c0
Author: Sara Souza <sa...@espressif.com>
AuthorDate: Wed Mar 10 15:25:34 2021 -0300

    apps/examples: Adds termios example
---
 examples/README.md              |   9 +++
 examples/termios/Kconfig        |  24 ++++++++
 examples/termios/Make.defs      |  23 ++++++++
 examples/termios/Makefile       |  34 +++++++++++
 examples/termios/termios_main.c | 127 ++++++++++++++++++++++++++++++++++++++++
 5 files changed, 217 insertions(+)

diff --git a/examples/README.md b/examples/README.md
index 4449a99..6dd601d 100644
--- a/examples/README.md
+++ b/examples/README.md
@@ -1651,6 +1651,15 @@ character per TCP transfer):
 - `CONFIG_STDIO_BUFFER_SIZE` – Some value `>= 64`
 - `CONFIG_STDIO_LINEBUFFER=y`
 
+## `termios` Simple Termios interface test
+
+This directory contains a simple application that uses the termios interface
+to change serial parameters. Just import a `nsh` config and enable the
+following symbols:
+
+- `CONFIG_SERIAL_TERMIOS`   – Enable the termios support.
+- `CONFIG_EXAMPLES_TERMIOS` – Enable the example itself.
+
 ## `thttpd` THTTPD server
 
 An example that builds `netutils/thttpd` with some simple NXFLAT CGI programs.
diff --git a/examples/termios/Kconfig b/examples/termios/Kconfig
new file mode 100644
index 0000000..e322f70
--- /dev/null
+++ b/examples/termios/Kconfig
@@ -0,0 +1,24 @@
+#
+# For a description of the syntax of this configuration file,
+# see the file kconfig-language.txt in the NuttX tools repository.
+#
+
+config EXAMPLES_TERMIOS
+	tristate "Termios example"
+	default n
+	---help---
+		Enable the Termios example. This example
+		shows how to change serial parameters like baud rate,
+		stop bits, data lenght and parity using the termios interface.
+
+if EXAMPLES_TERMIOS
+
+config EXAMPLES_TERMIOS_PRIORITY
+	int "Termios task priority"
+	default 100
+
+config EXAMPLES_TERMIOS_STACKSIZE
+	int "Termios stack size"
+	default DEFAULT_TASK_STACKSIZE
+
+endif
diff --git a/examples/termios/Make.defs b/examples/termios/Make.defs
new file mode 100644
index 0000000..06ac9be
--- /dev/null
+++ b/examples/termios/Make.defs
@@ -0,0 +1,23 @@
+############################################################################
+# apps/examples/termios/Make.defs
+#
+# 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.
+#
+############################################################################
+
+ifneq ($(CONFIG_EXAMPLES_TERMIOS),)
+CONFIGURED_APPS += $(APPDIR)/examples/termios
+endif
diff --git a/examples/termios/Makefile b/examples/termios/Makefile
new file mode 100644
index 0000000..9c038ac
--- /dev/null
+++ b/examples/termios/Makefile
@@ -0,0 +1,34 @@
+############################################################################
+# examples/termios/Make.defs
+#
+# 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.
+#
+############################################################################
+
+include $(APPDIR)/Make.defs
+
+# Termios Example! built-in application info
+
+PROGNAME  = termios
+PRIORITY  = $(CONFIG_EXAMPLES_TERMIOS_PRIORITY)
+STACKSIZE = $(CONFIG_EXAMPLES_TERMIOS_STACKSIZE)
+MODULE    = $(CONFIG_EXAMPLES_TERMIOS)
+
+# Termios Example
+
+MAINSRC = termios_main.c
+
+include $(APPDIR)/Application.mk
diff --git a/examples/termios/termios_main.c b/examples/termios/termios_main.c
new file mode 100644
index 0000000..7af7689
--- /dev/null
+++ b/examples/termios/termios_main.c
@@ -0,0 +1,127 @@
+/****************************************************************************
+ * apps/examples/termios/termios_main.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 <nuttx/config.h>
+#include <stdio.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <termios.h>
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * main
+ ****************************************************************************/
+
+void main(int argc, FAR char *argv[])
+{
+  int fd;
+  int ret;
+  int error = OK;
+  struct termios tio;
+
+  printf("Termios example\n");
+
+  fd = open("/dev/ttyS0", O_RDONLY);
+  if (fd < 0)
+    {
+      error = errno;
+      printf("Error opening serial: %d\n", error);
+    }
+
+  /* Fill the termios struct with the current values. */
+
+  ret = tcgetattr(fd, &tio);
+  if (ret < 0)
+    {
+      error = errno;
+      printf("Error getting attributes: %d\n", error);
+    }
+
+  /* Configure a baud rate.
+   * NuttX doesn't support different baud rates for RX and TX.
+   * So, both cfisetospeed() and cfisetispeed() are overwritten
+   * by cfsetspeed.
+   */
+
+  ret = cfsetspeed(&tio, B57600);
+  if (ret < 0)
+    {
+      error = errno;
+      printf("Error setting baud rate: %d\n", error);
+    }
+
+  /* Configure 2 stop bits. */
+
+  tio.c_cflag |= CSTOPB;
+
+  /* Enable parity and configure odd parity. */
+
+  tio.c_cflag |= PARENB | PARODD;
+
+  /* Change the data size to 7 bits */
+
+  tio.c_cflag &= ~CSIZE; /* Clean the bits */
+  tio.c_cflag |= CS7;    /* 7 bits */
+
+  printf("Please, reopen the terminal with the new attributes,"
+         " otherwise you will have garbage.\n"
+         "You may try: picocom /dev/ttyUSB0 --baud 57600"
+         " --parity o --databits 5 --stopbits 2\n\n");
+  fflush(stdout); /* Clean stdout buffer */
+
+  /* Wait to empty the hardware buffer, otherwise the above message
+   * will not be seen because the following command will take effect
+   * before the hardware buffer gets empty. A small delay is enough.
+   */
+
+  usleep(100);
+
+  /* Change the attributes now. */
+
+  ret = tcsetattr(fd, TCSANOW, &tio);
+  if (ret < 0)
+    {
+      error = errno;
+      /* Print the error code in the loop because at this
+       * moment the serial attributes already changed
+       */
+    }
+
+  (void)close(fd);
+
+  /* Now, we should reopen the terminal with the new
+   * attributes to see if they took effect;
+   */
+
+  while (1)
+    {
+      printf("If you can read this message, the changes took effect.\n"
+            "Expected error code: 0. Current code: %d\n", error);
+      sleep(1);
+    }
+}
+