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 2021/06/18 21:26:47 UTC

[GitHub] [incubator-nuttx-apps] saramonteiro opened a new pull request #784: examples: Adds Timer gpout example

saramonteiro opened a new pull request #784:
URL: https://github.com/apache/incubator-nuttx-apps/pull/784


   ## Summary
   
   This PR adds one example.
   This example uses the timer interrupt to periodically
   change the state of a digital output.
   The digital output may be a relay, a led or anything else.
   This example can be very useful to validate timer drivers
   by using a logic analyzer connected to the digital output.
   This example, mainly differs from the timer example because it
   waits on a sigwaitinfo() instead of using a signal handler.
   This approach ensures a deterministic wake-up time when
   the signal occurs.
   
   ## Impact
   N/A
   
   ## Testing
   Tested and published a video in NuttX Brasil channel running this example with a LA:
   https://youtu.be/v4bSGF3b3v4
   
   
   


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

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



[GitHub] [incubator-nuttx-apps] patacongo merged pull request #784: examples: Adds Timer gpout example

Posted by GitBox <gi...@apache.org>.
patacongo merged pull request #784:
URL: https://github.com/apache/incubator-nuttx-apps/pull/784


   


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

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



[GitHub] [incubator-nuttx-apps] patacongo commented on pull request #784: examples: Adds Timer gpout example

Posted by GitBox <gi...@apache.org>.
patacongo commented on pull request #784:
URL: https://github.com/apache/incubator-nuttx-apps/pull/784#issuecomment-864345849


   > The driver really should handle multiple clients like most other drivers. That should be a requirement of all drivers, if possible, so I would personally consider that limitation a bug in this case.
   
   Ha ha... looks like I wrote the driver/timer/timer.c driver way back in 2012.  So I guess if it is a bug, it is my bug.


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

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



[GitHub] [incubator-nuttx-apps] patacongo edited a comment on pull request #784: examples: Adds Timer gpout example

Posted by GitBox <gi...@apache.org>.
patacongo edited a comment on pull request #784:
URL: https://github.com/apache/incubator-nuttx-apps/pull/784#issuecomment-864336869


   The driver really should handle multiple clients like all other drivers.  That should be a requirement of all drivers so I would personally consider that limitation a bug.
   
   For a single timer, this would be handled by keeping a list of relative timer delays.  This is done, for example, for the wdog dog timers.  See https://github.com/apache/incubator-nuttx/blob/master/sched/wdog/wd_start.c#L226 . The wdog timers can handle an unlimited number of clients with a single timer and with NO additional overhead (at least after the relative delay is calculated).


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

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



[GitHub] [incubator-nuttx-apps] saramonteiro commented on pull request #784: examples: Adds Timer gpout example

Posted by GitBox <gi...@apache.org>.
saramonteiro commented on pull request #784:
URL: https://github.com/apache/incubator-nuttx-apps/pull/784#issuecomment-864054654


   @patacongo I fixed the found issues. PTAL.
   Note: I'll squash the commits once it's approved.
   Do not merge without it.


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

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



[GitHub] [incubator-nuttx-apps] saramonteiro commented on pull request #784: examples: Adds Timer gpout example

Posted by GitBox <gi...@apache.org>.
saramonteiro commented on pull request #784:
URL: https://github.com/apache/incubator-nuttx-apps/pull/784#issuecomment-864298365


   > A question. This is not essential to the PR, but is it really necessary to limit the number of daemons waiting for the signal? Is that a limitation of the timer? What would happen if you removed g_timer_gpout_daemon_started so that there could be multiple active timers?
   
   This a good question. Although I haven't tested, I infer that we can't have multiple deamons with one timer. Because each time one daemon was launched it would rewrite the `timer_notify_s` structure which is used within the timer callback to send a signal for a specific process id (task).  As a consequence, I believe we should see the priors daemons starve. To achieve this purpose, I believe we would have to create a Task Group and set up signaling for Multi-threaded Task Group. (What's is actually a good idea for a next example...).
   But I see no reasons we shouldn't have multiple daemons (each one associated with a specific timer).
   I'll perform both test and I come back here to tell you.


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

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



[GitHub] [incubator-nuttx-apps] patacongo edited a comment on pull request #784: examples: Adds Timer gpout example

Posted by GitBox <gi...@apache.org>.
patacongo edited a comment on pull request #784:
URL: https://github.com/apache/incubator-nuttx-apps/pull/784#issuecomment-864336869


   The driver really should handle multiple clients like most other drivers.  That should be a requirement of all drivers, if possible, so I would personally consider that limitation a bug in this case.
   
   For a single timer, this could be handled by keeping a list of relative timer delays.  This is done, for example, for the wdog timers.  See https://github.com/apache/incubator-nuttx/blob/master/sched/wdog/wd_start.c#L226 . The wdog timers can handle an unlimited number of clients with a single timer and with NO additional overhead (at least after the relative delay is calculated).
   
   For example, if there are two active timers, one to expire in 1.0 seconds and on in 1.5 seconds.  The delay on the first would be 1.0 seconds and the relative delay on the second would be 0.5 seconds.  After the first timer expires and the signal is sent, an additional 0.5 second delay would be required for the 1.5 second delay.


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

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



[GitHub] [incubator-nuttx-apps] patacongo commented on pull request #784: examples: Adds Timer gpout example

Posted by GitBox <gi...@apache.org>.
patacongo commented on pull request #784:
URL: https://github.com/apache/incubator-nuttx-apps/pull/784#issuecomment-864336869


   The driver really should handle multiple clients like all other drivers.  That should be a requirement of all drivers so I would personally consider that limitation a bug.
   
   For a single timer, this would be handled by keeping a list of relative timer delays.  This is done, for example, for the wdog dog timers.  See https://github.com/apache/incubator-nuttx/blob/master/sched/wdog/wd_start.c#L226


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

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



[GitHub] [incubator-nuttx-apps] saramonteiro commented on a change in pull request #784: examples: Adds Timer gpout example

Posted by GitBox <gi...@apache.org>.
saramonteiro commented on a change in pull request #784:
URL: https://github.com/apache/incubator-nuttx-apps/pull/784#discussion_r654446443



##########
File path: examples/timer_gpout/Make.defs
##########
@@ -0,0 +1,39 @@
+############################################################################
+# apps/examples/timer_gpout/Make.defs
+# Adds selected applications to apps/ build
+#
+#   Copyright (C) 2015 Gregory Nutt. All rights reserved.
+#   Author: Gregory Nutt <gn...@nuttx.org>
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in
+#    the documentation and/or other materials provided with the
+#    distribution.
+# 3. Neither the name NuttX nor the names of its contributors may be
+#    used to endorse or promote products derived from this software
+#    without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+############################################################################

Review comment:
       Yes.
   Solved.
   Thanks.

##########
File path: examples/timer_gpout/Makefile
##########
@@ -0,0 +1,49 @@
+############################################################################
+# apps/examples/timer_gpout/Makefile
+#
+#   Copyright (C) 2015 Gregory Nutt. All rights reserved.
+#   Author: Gregory Nutt <gn...@nuttx.org>
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in
+#    the documentation and/or other materials provided with the
+#    distribution.
+# 3. Neither the name NuttX nor the names of its contributors may be
+#    used to endorse or promote products derived from this software
+#    without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+############################################################################
+

Review comment:
       Yes.
   Solved.
   Thanks.

##########
File path: examples/timer_gpout/timer_gpout_main.c
##########
@@ -0,0 +1,306 @@
+/****************************************************************************
+ * apps/examples/timer_gpout/timer_gpout_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 <sys/ioctl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <fcntl.h>
+#include <signal.h>
+#include <errno.h>
+#include <string.h>
+#include <nuttx/timers/timer.h>
+#include <nuttx/ioexpander/gpio.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define DEVNAME_SIZE 16
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static char devtim_g[DEVNAME_SIZE];
+static char devgpout_g[DEVNAME_SIZE];
+static bool timer_gpout_daemon_started_g = false;

Review comment:
       I inverted. Fixed.

##########
File path: examples/timer_gpout/timer_gpout_main.c
##########
@@ -0,0 +1,306 @@
+/****************************************************************************
+ * apps/examples/timer_gpout/timer_gpout_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 <sys/ioctl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <fcntl.h>
+#include <signal.h>
+#include <errno.h>
+#include <string.h>
+#include <nuttx/timers/timer.h>
+#include <nuttx/ioexpander/gpio.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define DEVNAME_SIZE 16
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static char devtim_g[DEVNAME_SIZE];
+static char devgpout_g[DEVNAME_SIZE];
+static bool timer_gpout_daemon_started_g = false;
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: timer_status
+ *
+ * Description:
+ *   Auxiliar function to get the timer status and print it.
+ *
+ * Parameters:
+ *   fd           - Timer file descriptor to access the timer.
+ *
+ ****************************************************************************/
+
+static void timer_status(int fd)
+{
+  struct timer_status_s status;
+  int ret;
+
+  /* Get timer status */
+
+  ret = ioctl(fd, TCIOC_GETSTATUS, (unsigned long)((uintptr_t)&status));
+  if (ret < 0)
+    {
+      fprintf(stderr, "ERROR: Failed to get timer status: %d\n", errno);
+      close(fd);
+      exit(EXIT_FAILURE);
+    }
+
+  /* Print the timer status */
+
+  printf("  flags: %08lx timeout: %lu timeleft: %lu\n",
+         (unsigned long)status.flags, (unsigned long)status.timeout,
+         (unsigned long)status.timeleft);
+}
+
+/****************************************************************************
+ * Name: timer_gpout_daemon
+ *
+ * Description:
+ *   Deamon that will be active waiting on a signal to change the digital
+ *   output state.
+ *
+ ****************************************************************************/
+
+static int timer_gpout_daemon(int argc, char *argv[])
+{
+  struct timer_notify_s notify;
+  sigset_t set;
+  struct siginfo value;
+  int fd_timer;
+  int fd_gpout;
+  int ret;
+  bool state = false;
+
+  /* Indicate that the deamon is running */
+
+  timer_gpout_daemon_started_g = true;
+  printf("timer_gpout_daemon: timer_gpout_daemon started\n");
+
+  /* Open the timer device */
+
+  printf("Open %s\n", devtim_g);
+
+  fd_timer = open(devtim_g, O_RDONLY);
+  if (fd_timer < 0)
+    {
+      int errcode = errno;
+      printf("timer_gpout_daemon: Failed to open %s: %d\n",
+              devtim_g, errcode);
+      return EXIT_FAILURE;
+    }
+
+  /* Open the GPIO driver */
+
+  printf("Open %s\n", devgpout_g);
+
+  fd_gpout = open(devgpout_g, O_RDWR);
+  if (fd_gpout < 0)
+    {
+      int errcode = errno;
+      printf("timer_gpout_daemon: Failed to open %s: %d\n",
+              devgpout_g, errcode);
+      close(fd_timer);
+      return EXIT_FAILURE;
+    }
+
+  /* Show the timer status before setting the timer interval */
+
+  timer_status(fd_timer);
+
+  /* Set the timer interval */
+
+  printf("Set timer interval to %lu\n",
+         (unsigned long)CONFIG_EXAMPLES_TIMER_GPOUT_INTERVAL);
+
+  ret = ioctl(fd_timer, TCIOC_SETTIMEOUT,
+              CONFIG_EXAMPLES_TIMER_GPOUT_INTERVAL);
+  if (ret < 0)
+    {
+      int errcode = errno;
+      printf("timer_gpout_daemon: Failed to set the timer interval: %d\n",
+             errcode);
+      goto errout;
+    }
+
+  /* Show the timer status before attaching the timer handler */
+
+  timer_status(fd_timer);
+
+  /* Configure the signal set for this task */
+
+  sigemptyset(&set);
+  sigaddset(&set, CONFIG_EXAMPLES_TIMER_GPOUT_SIGNO);
+
+  /* Configure the timer notifier to receive a signal when timeout occurs.
+   * Inform the PID of the process that will be notified by the internal
+   * timer callback, and configure the event to describe the way this
+   * task will be notified. In this case, through a signal.
+   */
+
+  printf("Configure the timer notification.\n");
+
+  notify.pid   = getpid();
+  notify.event.sigev_notify = SIGEV_SIGNAL;
+  notify.event.sigev_signo  = CONFIG_EXAMPLES_TIMER_GPOUT_SIGNO;
+  notify.event.sigev_value.sival_ptr = NULL;
+
+  ret = ioctl(fd_timer, TCIOC_NOTIFICATION,
+              (unsigned long)((uintptr_t)&notify));
+  if (ret < 0)
+    {
+      int errcode = errno;
+      printf("timer_gpout_daemon: Failed to set the timer handler: %d\n",
+             errcode);
+      goto errout;
+    }
+
+  /* Start the timer */
+
+  printf("Start the timer\n");
+
+  ret = ioctl(fd_timer, TCIOC_START, 0);
+  if (ret < 0)
+    {
+      int errcode = errno;
+      printf("timer_gpout_daemon: Failed to start the timer: %d\n", errcode);
+      goto errout;
+    }
+
+  while (1)
+    {
+      ret = sigwaitinfo(&set, &value);
+      if (ret < 0)
+        {
+          int errcode = errno;
+          printf("timer_gpout_daemon: ERROR: sigwaitinfo() failed: %d\n",
+                 errcode);
+          goto errout;
+        }
+
+      /* Change the gpout state */
+
+      state = ~state;

Review comment:
       Ok.
   Fixed.




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

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



[GitHub] [incubator-nuttx-apps] saramonteiro commented on pull request #784: examples: Adds Timer gpout example

Posted by GitBox <gi...@apache.org>.
saramonteiro commented on pull request #784:
URL: https://github.com/apache/incubator-nuttx-apps/pull/784#issuecomment-890568819


   @patacongo I performed some tests and here are the tests with the results:
   
   **1st Test:**
   Simply removed the part that checks for `g_timer_gpout_daemon_started`.
   Result:
   Simply doesn't work, because when it calls the timer start ioctl, it returns EBUSY.
   
   **2nd Test**
   Kept the changes from the 1st test, but after opening timer driver, I called the status ioctl to use the status flags and check the TCFLAGS_ACTIVE. Then I checked If the timer was running, in case it was, I set it to perform only the notification ioctl and not to perform settimeout and start.
   Result:
   It works, but as I expected, `timer_notify_s` structure was subscribed and the previous daemon starved. Take a look:
   ![image](https://user-images.githubusercontent.com/33546913/127781510-b3cc2949-0651-49bd-bbf6-763976799d63.png)
   Conclusion for this: For one timer, we should have only one daemon.
   
   **3rd Test**
   I kept _only_ the changes from the 1st test and ran multiple daemons. Each one using one timer and a specific gpout. Ex:
   `timer_gpout -t /dev/timer0 -g /dev/gpout0`
   `timer_gpout -t /dev/timer1 -g /dev/gpout1`
   Result:
   It works perfectly: 
   ![image](https://user-images.githubusercontent.com/33546913/127782028-5fe7efdf-d3a5-42a2-ae52-94c70f31314e.png)
   
   
   
   
   
    


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



[GitHub] [incubator-nuttx-apps] patacongo commented on a change in pull request #784: examples: Adds Timer gpout example

Posted by GitBox <gi...@apache.org>.
patacongo commented on a change in pull request #784:
URL: https://github.com/apache/incubator-nuttx-apps/pull/784#discussion_r654070882



##########
File path: examples/timer_gpout/Makefile
##########
@@ -0,0 +1,49 @@
+############################################################################
+# apps/examples/timer_gpout/Makefile
+#
+#   Copyright (C) 2015 Gregory Nutt. All rights reserved.
+#   Author: Gregory Nutt <gn...@nuttx.org>
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in
+#    the documentation and/or other materials provided with the
+#    distribution.
+# 3. Neither the name NuttX nor the names of its contributors may be
+#    used to endorse or promote products derived from this software
+#    without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+############################################################################
+

Review comment:
       Shouldn't this be an ASF Apache 2.0 header? 

##########
File path: examples/timer_gpout/Make.defs
##########
@@ -0,0 +1,39 @@
+############################################################################
+# apps/examples/timer_gpout/Make.defs
+# Adds selected applications to apps/ build
+#
+#   Copyright (C) 2015 Gregory Nutt. All rights reserved.
+#   Author: Gregory Nutt <gn...@nuttx.org>
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in
+#    the documentation and/or other materials provided with the
+#    distribution.
+# 3. Neither the name NuttX nor the names of its contributors may be
+#    used to endorse or promote products derived from this software
+#    without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+############################################################################

Review comment:
       Shouldn't this be an ASF Apache 2.0 header? 

##########
File path: examples/timer_gpout/timer_gpout_main.c
##########
@@ -0,0 +1,306 @@
+/****************************************************************************
+ * apps/examples/timer_gpout/timer_gpout_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 <sys/ioctl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <fcntl.h>
+#include <signal.h>
+#include <errno.h>
+#include <string.h>
+#include <nuttx/timers/timer.h>
+#include <nuttx/ioexpander/gpio.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define DEVNAME_SIZE 16
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static char devtim_g[DEVNAME_SIZE];
+static char devgpout_g[DEVNAME_SIZE];
+static bool timer_gpout_daemon_started_g = false;

Review comment:
       The NuttX coding standard requires that all variables defined at global scope must begin with g_.  Putting _g at the end violates the coding standard.  These need to be changed to g_devtim, g_devgpout, and g_timer_gpout_daemon_started.

##########
File path: examples/timer_gpout/timer_gpout_main.c
##########
@@ -0,0 +1,306 @@
+/****************************************************************************
+ * apps/examples/timer_gpout/timer_gpout_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 <sys/ioctl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <fcntl.h>
+#include <signal.h>
+#include <errno.h>
+#include <string.h>
+#include <nuttx/timers/timer.h>
+#include <nuttx/ioexpander/gpio.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define DEVNAME_SIZE 16
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static char devtim_g[DEVNAME_SIZE];
+static char devgpout_g[DEVNAME_SIZE];
+static bool timer_gpout_daemon_started_g = false;
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: timer_status
+ *
+ * Description:
+ *   Auxiliar function to get the timer status and print it.
+ *
+ * Parameters:
+ *   fd           - Timer file descriptor to access the timer.
+ *
+ ****************************************************************************/
+
+static void timer_status(int fd)
+{
+  struct timer_status_s status;
+  int ret;
+
+  /* Get timer status */
+
+  ret = ioctl(fd, TCIOC_GETSTATUS, (unsigned long)((uintptr_t)&status));
+  if (ret < 0)
+    {
+      fprintf(stderr, "ERROR: Failed to get timer status: %d\n", errno);
+      close(fd);
+      exit(EXIT_FAILURE);
+    }
+
+  /* Print the timer status */
+
+  printf("  flags: %08lx timeout: %lu timeleft: %lu\n",
+         (unsigned long)status.flags, (unsigned long)status.timeout,
+         (unsigned long)status.timeleft);
+}
+
+/****************************************************************************
+ * Name: timer_gpout_daemon
+ *
+ * Description:
+ *   Deamon that will be active waiting on a signal to change the digital
+ *   output state.
+ *
+ ****************************************************************************/
+
+static int timer_gpout_daemon(int argc, char *argv[])
+{
+  struct timer_notify_s notify;
+  sigset_t set;
+  struct siginfo value;
+  int fd_timer;
+  int fd_gpout;
+  int ret;
+  bool state = false;
+
+  /* Indicate that the deamon is running */
+
+  timer_gpout_daemon_started_g = true;
+  printf("timer_gpout_daemon: timer_gpout_daemon started\n");
+
+  /* Open the timer device */
+
+  printf("Open %s\n", devtim_g);
+
+  fd_timer = open(devtim_g, O_RDONLY);
+  if (fd_timer < 0)
+    {
+      int errcode = errno;
+      printf("timer_gpout_daemon: Failed to open %s: %d\n",
+              devtim_g, errcode);
+      return EXIT_FAILURE;
+    }
+
+  /* Open the GPIO driver */
+
+  printf("Open %s\n", devgpout_g);
+
+  fd_gpout = open(devgpout_g, O_RDWR);
+  if (fd_gpout < 0)
+    {
+      int errcode = errno;
+      printf("timer_gpout_daemon: Failed to open %s: %d\n",
+              devgpout_g, errcode);
+      close(fd_timer);
+      return EXIT_FAILURE;
+    }
+
+  /* Show the timer status before setting the timer interval */
+
+  timer_status(fd_timer);
+
+  /* Set the timer interval */
+
+  printf("Set timer interval to %lu\n",
+         (unsigned long)CONFIG_EXAMPLES_TIMER_GPOUT_INTERVAL);
+
+  ret = ioctl(fd_timer, TCIOC_SETTIMEOUT,
+              CONFIG_EXAMPLES_TIMER_GPOUT_INTERVAL);
+  if (ret < 0)
+    {
+      int errcode = errno;
+      printf("timer_gpout_daemon: Failed to set the timer interval: %d\n",
+             errcode);
+      goto errout;
+    }
+
+  /* Show the timer status before attaching the timer handler */
+
+  timer_status(fd_timer);
+
+  /* Configure the signal set for this task */
+
+  sigemptyset(&set);
+  sigaddset(&set, CONFIG_EXAMPLES_TIMER_GPOUT_SIGNO);
+
+  /* Configure the timer notifier to receive a signal when timeout occurs.
+   * Inform the PID of the process that will be notified by the internal
+   * timer callback, and configure the event to describe the way this
+   * task will be notified. In this case, through a signal.
+   */
+
+  printf("Configure the timer notification.\n");
+
+  notify.pid   = getpid();
+  notify.event.sigev_notify = SIGEV_SIGNAL;
+  notify.event.sigev_signo  = CONFIG_EXAMPLES_TIMER_GPOUT_SIGNO;
+  notify.event.sigev_value.sival_ptr = NULL;
+
+  ret = ioctl(fd_timer, TCIOC_NOTIFICATION,
+              (unsigned long)((uintptr_t)&notify));
+  if (ret < 0)
+    {
+      int errcode = errno;
+      printf("timer_gpout_daemon: Failed to set the timer handler: %d\n",
+             errcode);
+      goto errout;
+    }
+
+  /* Start the timer */
+
+  printf("Start the timer\n");
+
+  ret = ioctl(fd_timer, TCIOC_START, 0);
+  if (ret < 0)
+    {
+      int errcode = errno;
+      printf("timer_gpout_daemon: Failed to start the timer: %d\n", errcode);
+      goto errout;
+    }
+
+  while (1)
+    {
+      ret = sigwaitinfo(&set, &value);
+      if (ret < 0)
+        {
+          int errcode = errno;
+          printf("timer_gpout_daemon: ERROR: sigwaitinfo() failed: %d\n",
+                 errcode);
+          goto errout;
+        }
+
+      /* Change the gpout state */
+
+      state = ~state;

Review comment:
       ```suggestion
         state = !state;
   ```
   The tilde is a bit operation of a boolean value.  It will toggle from 0 (false) and 0xffffffff (invalid boolean value).  The exclamation point is the correct operator for a boolean and will toggle from 0 (false) to 1 (true).
   

##########
File path: examples/timer_gpout/timer_gpout_main.c
##########
@@ -0,0 +1,306 @@
+/****************************************************************************
+ * apps/examples/timer_gpout/timer_gpout_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 <sys/ioctl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <fcntl.h>
+#include <signal.h>
+#include <errno.h>
+#include <string.h>
+#include <nuttx/timers/timer.h>
+#include <nuttx/ioexpander/gpio.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define DEVNAME_SIZE 16
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static char devtim_g[DEVNAME_SIZE];
+static char devgpout_g[DEVNAME_SIZE];
+static bool timer_gpout_daemon_started_g = false;

Review comment:
       The NuttX coding standard requires that all variables defined at global scope must begin with g_.  Putting _g at the end violates the coding standard.  These need to be changed to g_devtim, g_devgpout, and g_timer_gpout_daemon_started to be compliant with the coding standard.

##########
File path: examples/timer_gpout/timer_gpout_main.c
##########
@@ -0,0 +1,306 @@
+/****************************************************************************
+ * apps/examples/timer_gpout/timer_gpout_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 <sys/ioctl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <fcntl.h>
+#include <signal.h>
+#include <errno.h>
+#include <string.h>
+#include <nuttx/timers/timer.h>
+#include <nuttx/ioexpander/gpio.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define DEVNAME_SIZE 16
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static char devtim_g[DEVNAME_SIZE];
+static char devgpout_g[DEVNAME_SIZE];
+static bool timer_gpout_daemon_started_g = false;

Review comment:
       The NuttX coding standard requires that all variables defined at global scope must begin with g_.  Putting _g at the end violates the coding standard.  These need to be changed to g_devtim, g_devgpout, and g_timer_gpout_daemon_started to be compliant with the coding standard.
   
   https://cwiki.apache.org/confluence/display/NUTTX/Coding+Standard#globalvariable

##########
File path: examples/timer_gpout/timer_gpout_main.c
##########
@@ -0,0 +1,306 @@
+/****************************************************************************
+ * apps/examples/timer_gpout/timer_gpout_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 <sys/ioctl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <fcntl.h>
+#include <signal.h>
+#include <errno.h>
+#include <string.h>
+#include <nuttx/timers/timer.h>
+#include <nuttx/ioexpander/gpio.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define DEVNAME_SIZE 16
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static char devtim_g[DEVNAME_SIZE];
+static char devgpout_g[DEVNAME_SIZE];
+static bool timer_gpout_daemon_started_g = false;

Review comment:
       The NuttX coding standard requires that all variables defined at global scope must begin with g_.  Putting _g at the end violates the coding standard.  These need to be changed to g_devtim, g_devgpout, and g_timer_gpout_daemon_started to be compliant with the coding standard.
   
   https://cwiki.apache.org/confluence/display/NUTTX/Coding+Standard#globalvariable
   
   This error is not detected by nxstyle.  This is a known issue that will get fixed someday: https://github.com/apache/incubator-nuttx/issues/901

##########
File path: examples/timer_gpout/timer_gpout_main.c
##########
@@ -0,0 +1,306 @@
+/****************************************************************************
+ * apps/examples/timer_gpout/timer_gpout_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 <sys/ioctl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <fcntl.h>
+#include <signal.h>
+#include <errno.h>
+#include <string.h>
+#include <nuttx/timers/timer.h>
+#include <nuttx/ioexpander/gpio.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define DEVNAME_SIZE 16
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static char devtim_g[DEVNAME_SIZE];
+static char devgpout_g[DEVNAME_SIZE];
+static bool timer_gpout_daemon_started_g = false;
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: timer_status
+ *
+ * Description:
+ *   Auxiliar function to get the timer status and print it.
+ *
+ * Parameters:
+ *   fd           - Timer file descriptor to access the timer.
+ *
+ ****************************************************************************/
+
+static void timer_status(int fd)
+{
+  struct timer_status_s status;
+  int ret;
+
+  /* Get timer status */
+
+  ret = ioctl(fd, TCIOC_GETSTATUS, (unsigned long)((uintptr_t)&status));
+  if (ret < 0)
+    {
+      fprintf(stderr, "ERROR: Failed to get timer status: %d\n", errno);
+      close(fd);
+      exit(EXIT_FAILURE);
+    }
+
+  /* Print the timer status */
+
+  printf("  flags: %08lx timeout: %lu timeleft: %lu\n",
+         (unsigned long)status.flags, (unsigned long)status.timeout,
+         (unsigned long)status.timeleft);
+}
+
+/****************************************************************************
+ * Name: timer_gpout_daemon
+ *
+ * Description:
+ *   Deamon that will be active waiting on a signal to change the digital
+ *   output state.
+ *
+ ****************************************************************************/
+
+static int timer_gpout_daemon(int argc, char *argv[])
+{
+  struct timer_notify_s notify;
+  sigset_t set;
+  struct siginfo value;
+  int fd_timer;
+  int fd_gpout;
+  int ret;
+  bool state = false;
+
+  /* Indicate that the deamon is running */
+
+  timer_gpout_daemon_started_g = true;
+  printf("timer_gpout_daemon: timer_gpout_daemon started\n");
+
+  /* Open the timer device */
+
+  printf("Open %s\n", devtim_g);
+
+  fd_timer = open(devtim_g, O_RDONLY);
+  if (fd_timer < 0)
+    {
+      int errcode = errno;
+      printf("timer_gpout_daemon: Failed to open %s: %d\n",
+              devtim_g, errcode);
+      return EXIT_FAILURE;
+    }
+
+  /* Open the GPIO driver */
+
+  printf("Open %s\n", devgpout_g);
+
+  fd_gpout = open(devgpout_g, O_RDWR);
+  if (fd_gpout < 0)
+    {
+      int errcode = errno;
+      printf("timer_gpout_daemon: Failed to open %s: %d\n",
+              devgpout_g, errcode);
+      close(fd_timer);
+      return EXIT_FAILURE;
+    }
+
+  /* Show the timer status before setting the timer interval */
+
+  timer_status(fd_timer);
+
+  /* Set the timer interval */
+
+  printf("Set timer interval to %lu\n",
+         (unsigned long)CONFIG_EXAMPLES_TIMER_GPOUT_INTERVAL);
+
+  ret = ioctl(fd_timer, TCIOC_SETTIMEOUT,
+              CONFIG_EXAMPLES_TIMER_GPOUT_INTERVAL);
+  if (ret < 0)
+    {
+      int errcode = errno;
+      printf("timer_gpout_daemon: Failed to set the timer interval: %d\n",
+             errcode);
+      goto errout;
+    }
+
+  /* Show the timer status before attaching the timer handler */
+
+  timer_status(fd_timer);
+
+  /* Configure the signal set for this task */
+
+  sigemptyset(&set);
+  sigaddset(&set, CONFIG_EXAMPLES_TIMER_GPOUT_SIGNO);
+
+  /* Configure the timer notifier to receive a signal when timeout occurs.
+   * Inform the PID of the process that will be notified by the internal
+   * timer callback, and configure the event to describe the way this
+   * task will be notified. In this case, through a signal.
+   */
+
+  printf("Configure the timer notification.\n");
+
+  notify.pid   = getpid();
+  notify.event.sigev_notify = SIGEV_SIGNAL;
+  notify.event.sigev_signo  = CONFIG_EXAMPLES_TIMER_GPOUT_SIGNO;
+  notify.event.sigev_value.sival_ptr = NULL;
+
+  ret = ioctl(fd_timer, TCIOC_NOTIFICATION,
+              (unsigned long)((uintptr_t)&notify));
+  if (ret < 0)
+    {
+      int errcode = errno;
+      printf("timer_gpout_daemon: Failed to set the timer handler: %d\n",
+             errcode);
+      goto errout;
+    }
+
+  /* Start the timer */
+
+  printf("Start the timer\n");
+
+  ret = ioctl(fd_timer, TCIOC_START, 0);
+  if (ret < 0)
+    {
+      int errcode = errno;
+      printf("timer_gpout_daemon: Failed to start the timer: %d\n", errcode);
+      goto errout;
+    }
+
+  while (1)
+    {
+      ret = sigwaitinfo(&set, &value);
+      if (ret < 0)
+        {
+          int errcode = errno;
+          printf("timer_gpout_daemon: ERROR: sigwaitinfo() failed: %d\n",
+                 errcode);
+          goto errout;
+        }
+
+      /* Change the gpout state */
+
+      state = ~state;

Review comment:
       ```suggestion
         state = !state;
   ```
   The tilde is a bit operation and probably not appropriate for a boolean value.  It will toggle from 0 (false) and 0xffffffff (invalid boolean value).  The exclamation point is the correct operator for a boolean and will toggle from 0 (false) to 1 (true).
   




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

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



[GitHub] [incubator-nuttx-apps] patacongo commented on pull request #784: examples: Adds Timer gpout example

Posted by GitBox <gi...@apache.org>.
patacongo commented on pull request #784:
URL: https://github.com/apache/incubator-nuttx-apps/pull/784#issuecomment-864179521


   A question.  This is not essential to the PR, but is it really necessary to limit the number of daemons waiting for the signal?  Is that a limitation of the timer? What would happen if you removed g_timer_gpout_daemon_started so that there could be multiple active timers?
   


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

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



[GitHub] [incubator-nuttx-apps] patacongo edited a comment on pull request #784: examples: Adds Timer gpout example

Posted by GitBox <gi...@apache.org>.
patacongo edited a comment on pull request #784:
URL: https://github.com/apache/incubator-nuttx-apps/pull/784#issuecomment-864336869


   The driver really should handle multiple clients like most other drivers.  That should be a requirement of all drivers, if possible, so I would personally consider that limitation a bug.
   
   For a single timer, this could be handled by keeping a list of relative timer delays.  This is done, for example, for the wdog timers.  See https://github.com/apache/incubator-nuttx/blob/master/sched/wdog/wd_start.c#L226 . The wdog timers can handle an unlimited number of clients with a single timer and with NO additional overhead (at least after the relative delay is calculated).


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

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



[GitHub] [incubator-nuttx-apps] patacongo commented on pull request #784: examples: Adds Timer gpout example

Posted by GitBox <gi...@apache.org>.
patacongo commented on pull request #784:
URL: https://github.com/apache/incubator-nuttx-apps/pull/784#issuecomment-864308193


   I think I should go ahead a merge this version.  It would be a good extension to testing to prove that there is no issue with multiple concurrent timers.  It would be a bug in the driver if it could not support more than one client task.
   
   But, I think you can extend this testing in any way that you wish in the future.  Let's merge this well verified PR as it is now.


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

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



[GitHub] [incubator-nuttx-apps] patacongo edited a comment on pull request #784: examples: Adds Timer gpout example

Posted by GitBox <gi...@apache.org>.
patacongo edited a comment on pull request #784:
URL: https://github.com/apache/incubator-nuttx-apps/pull/784#issuecomment-864336869


   The driver really should handle multiple clients like most other drivers.  That should be a requirement of all drivers, if possible, so I would personally consider that limitation a bug in this case.
   
   For a single timer, this could be handled by keeping a list of relative timer delays.  This is done, for example, for the wdog timers.  See https://github.com/apache/incubator-nuttx/blob/master/sched/wdog/wd_start.c#L226 . The wdog timers can handle an unlimited number of clients with a single timer and with NO additional overhead (at least after the relative delay is calculated).


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

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