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/12/22 09:26:45 UTC

[GitHub] [nuttx] CV-Bowen commented on a diff in pull request #7954: power/relay: add relay driver framework for NuttX

CV-Bowen commented on code in PR #7954:
URL: https://github.com/apache/nuttx/pull/7954#discussion_r1055257337


##########
drivers/power/relay/relay.c:
##########
@@ -0,0 +1,168 @@
+/****************************************************************************
+ * drivers/power/relay/relay.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/types.h>
+
+#include <errno.h>
+
+#include <nuttx/mutex.h>
+#include <nuttx/power/relay.h>
+#include <nuttx/fs/fs.h>
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+static ssize_t relay_read(FAR struct file *filep, FAR char *buffer,
+                          size_t buflen);
+static ssize_t relay_write(FAR struct file *filep, FAR const char *buffer,
+                           size_t buflen);
+static int     relay_ioctl(FAR struct file *filep, int cmd,
+                           unsigned long arg);
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static const struct file_operations g_relay_ops =
+{
+  NULL,         /* open */
+  NULL,         /* close */
+  relay_read,   /* read */
+  relay_write,  /* write */
+  NULL,         /* seek */
+  relay_ioctl,  /* ioctl */
+  NULL          /* poll */
+#ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS
+  , NULL        /* unlink */
+#endif
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+static ssize_t relay_read(FAR struct file *filep, FAR char *buffer,
+                          size_t buflen)
+{
+  return 0;
+}
+
+static ssize_t relay_write(FAR struct file *filep, FAR const char *buffer,
+                           size_t buflen)
+{
+  return 0;
+}
+
+static int relay_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
+{
+  FAR struct relay_dev_s *dev;
+  FAR struct inode *inode;
+  int ret;
+
+  DEBUGASSERT(filep != NULL && filep->f_inode != NULL);
+  inode = filep->f_inode;
+  DEBUGASSERT(inode->i_private != NULL);
+  dev = inode->i_private;
+
+  ret = nxmutex_lock(&dev->lock);
+  if (ret < 0)
+    {
+      return ret;
+    }
+
+  switch (cmd)
+    {
+      case RELAYIOC_SET:
+        {
+          FAR bool *enable = (FAR bool *)((uintptr_t)arg);
+          DEBUGASSERT(enable != NULL);
+          ret = dev->ops->set(dev, *enable);
+        }
+        break;
+
+      case RELAYIOC_GET:
+        {
+          DEBUGASSERT(arg != 0);
+          ret = dev->ops->get(dev, (FAR bool *)((uintptr_t)arg));
+        }

Review Comment:
   Done



##########
drivers/power/relay/relay.c:
##########
@@ -0,0 +1,168 @@
+/****************************************************************************
+ * drivers/power/relay/relay.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/types.h>
+
+#include <errno.h>
+
+#include <nuttx/mutex.h>
+#include <nuttx/power/relay.h>
+#include <nuttx/fs/fs.h>
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+static ssize_t relay_read(FAR struct file *filep, FAR char *buffer,
+                          size_t buflen);
+static ssize_t relay_write(FAR struct file *filep, FAR const char *buffer,
+                           size_t buflen);
+static int     relay_ioctl(FAR struct file *filep, int cmd,
+                           unsigned long arg);
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static const struct file_operations g_relay_ops =
+{
+  NULL,         /* open */
+  NULL,         /* close */
+  relay_read,   /* read */
+  relay_write,  /* write */
+  NULL,         /* seek */
+  relay_ioctl,  /* ioctl */
+  NULL          /* poll */
+#ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS
+  , NULL        /* unlink */
+#endif
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+static ssize_t relay_read(FAR struct file *filep, FAR char *buffer,
+                          size_t buflen)
+{
+  return 0;
+}
+
+static ssize_t relay_write(FAR struct file *filep, FAR const char *buffer,
+                           size_t buflen)
+{
+  return 0;
+}
+
+static int relay_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
+{
+  FAR struct relay_dev_s *dev;
+  FAR struct inode *inode;
+  int ret;
+
+  DEBUGASSERT(filep != NULL && filep->f_inode != NULL);
+  inode = filep->f_inode;
+  DEBUGASSERT(inode->i_private != NULL);
+  dev = inode->i_private;
+
+  ret = nxmutex_lock(&dev->lock);
+  if (ret < 0)
+    {
+      return ret;
+    }
+
+  switch (cmd)
+    {
+      case RELAYIOC_SET:
+        {
+          FAR bool *enable = (FAR bool *)((uintptr_t)arg);
+          DEBUGASSERT(enable != NULL);
+          ret = dev->ops->set(dev, *enable);
+        }
+        break;
+
+      case RELAYIOC_GET:
+        {
+          DEBUGASSERT(arg != 0);
+          ret = dev->ops->get(dev, (FAR bool *)((uintptr_t)arg));
+        }
+        break;
+
+      default:
+        {
+          if (dev->ops->ioctl != NULL)
+            {
+              ret = dev->ops->ioctl(dev, cmd, arg);
+            }
+          else
+            {
+              ret = -ENOTSUP;
+            }
+        }
+        break;

Review Comment:
   Done



##########
drivers/power/relay/relay_gpio.c:
##########
@@ -0,0 +1,148 @@
+/****************************************************************************
+ * drivers/power/relay/relay_gpio.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 <errno.h>
+
+#include <nuttx/ioexpander/ioexpander.h>
+#include <nuttx/kmalloc.h>
+#include <nuttx/power/relay.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+struct relay_gpio_priv
+{
+  FAR struct relay_dev_s       dev;

Review Comment:
   Done



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

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