drivers/gpio: tidy up a bit
authorHeesub Shin <heesub.shin@samsung.com>
Mon, 10 Apr 2017 02:12:03 +0000 (11:12 +0900)
committerHeesub Shin <heesub.shin@samsung.com>
Tue, 18 Apr 2017 03:02:13 +0000 (12:02 +0900)
Fixes trivial coding styles.

Change-Id: I1fc80dce0cea0aa8f92ebff8bf79e5a2fef5bf11
Signed-off-by: Heesub Shin <heesub.shin@samsung.com>
os/drivers/gpio/gpio.c
os/include/tinyara/gpio.h

index 31fb11e..4fb9ee5 100644 (file)
  *
  ****************************************************************************/
 
-/*******************************************************************************
+/****************************************************************************
  * Included Files
- ******************************************************************************/
+ ****************************************************************************/
+#include <tinyara/config.h>
 
 #include <stdio.h>
 #include <string.h>
 
 #include <tinyara/gpio.h>
 
-/*******************************************************************************
+/****************************************************************************
  * Pre-processor Definitions
- ******************************************************************************/
+ ****************************************************************************/
 #define GPIO_PREVENT_MULTIPLE_OPEN   0
 
-/******************************************************************************
+/****************************************************************************
  * Private Types
- ******************************************************************************/
+ ****************************************************************************/
 
-/******************************************************************************
+/****************************************************************************
  * Private Function Prototypes
- ******************************************************************************/
-
-static int gpio_fopen(FAR struct file *filep);
-static int gpio_fclose(FAR struct file *filep);
-static ssize_t gpio_read(FAR struct file *filep, FAR char *buffer, size_t buflen);
-static ssize_t gpio_write(FAR struct file *filep, FAR const char *buffer, size_t buflen);
-static int gpio_ioctl(FAR struct file *filep, int cmd, unsigned long arg);
+ ****************************************************************************/
+static int     gpio_fopen(FAR struct file *filep);
+static int     gpio_fclose(FAR struct file *filep);
+static ssize_t gpio_read(FAR struct file *filep, FAR char *buffer,
+                        size_t buflen);
+static ssize_t gpio_write(FAR struct file *filep, FAR const char *buffer,
+                         size_t buflen);
+static int     gpio_ioctl(FAR struct file *filep, int cmd,
+                         unsigned long arg);
 #ifndef CONFIG_DISABLE_POLL
-static int gpio_poll(FAR struct file *filep, FAR struct pollfd *fds, bool setup);
+static int     gpio_poll(FAR struct file *filep, FAR struct pollfd *fds,
+                        bool setup);
 #endif
 
-/******************************************************************************
+/****************************************************************************
  * Private Variables
- ******************************************************************************/
-
+ ****************************************************************************/
 static const struct file_operations g_gpioops = {
-       gpio_fopen,                                     /* open  */
-       gpio_fclose,                            /* close */
-       gpio_read,                                      /* read  */
-       gpio_write,                                     /* write */
-       NULL,                                           /* seek  */
-       gpio_ioctl,                                     /* ioctl */
+       gpio_fopen,     /* open  */
+       gpio_fclose,    /* close */
+       gpio_read,      /* read  */
+       gpio_write,     /* write */
+       NULL,           /* seek  */
+       gpio_ioctl,     /* ioctl */
 #ifndef CONFIG_DISABLE_POLL
-       gpio_poll                                       /* poll  */
+       gpio_poll       /* poll  */
 #endif
 };
 
-/******************************************************************************
+/****************************************************************************
  * Private Functions
- ******************************************************************************/
+ ****************************************************************************/
 
-/******************************************************************************
+/****************************************************************************
  * Name: sem_reinit
  *
  * Description:
  *    Reinitialize semaphore
  *
- ******************************************************************************/
-
+ ****************************************************************************/
 #ifndef CONFIG_DISABLE_POLL
 static int sem_reinit(FAR sem_t *sem, int pshared, unsigned int value)
 {
        sem_destroy(sem);
+
        return sem_init(sem, pshared, value);
 }
 #endif
 
-/*******************************************************************************
+/****************************************************************************
  * Name: gpio_takesem
  *
  * Description:
  *    Take the lock, waiting as necessary
  *
- ******************************************************************************/
-
+ ****************************************************************************/
 static int gpio_takesem(FAR sem_t *sem, bool errout)
 {
-       /* Loop, ignoring interrupts, until we have successfully acquired the lock */
+       /*
+        * Loop, ignoring interrupts, until we have successfully acquired
+        * the lock
+        */
 
        while (sem_wait(sem) != OK) {
-               /* The only case that an error should occur here is if the wait
-                * was awakened by a signal.
+               /*
+                * The only case that an error should occur here is if the
+                * wait was awakened by a signal.
                 */
-
                ASSERT(get_errno() == EINTR);
 
-               /* When the signal is received, should we errout? Or should we just
-                * continue waiting until we have the semaphore?
+               /*
+                * When the signal is received, should we errout? Or should
+                * we just continue waiting until we have the semaphore?
                 */
-
                if (errout) {
                        return -EINTR;
                }
@@ -118,31 +123,30 @@ static int gpio_takesem(FAR sem_t *sem, bool errout)
        return OK;
 }
 
-/*******************************************************************************
+/****************************************************************************
  * Name: gpio_givesem
  *
  * Description:
  *    release the lock
  *
- ******************************************************************************/
-
+ ****************************************************************************/
 static inline void gpio_givesem(sem_t *sem)
 {
        sem_post(sem);
 }
 
-/*******************************************************************************
+/****************************************************************************
  * Name: gpio_pollnotify
  *
  * Description:
  *    notify file descriptor. It is necessary to handle async I/O.
  *
- ******************************************************************************/
-
+ ****************************************************************************/
 #ifndef CONFIG_DISABLE_POLL
 static void gpio_pollnotify(FAR struct gpio_dev_s *dev, pollevent_t eventset)
 {
        int i;
+
        for (i = 0; i < CONFIG_GPIO_NPOLLWAITERS; i++) {
                struct pollfd *fds = dev->fds[i];
                if (fds) {
@@ -159,16 +163,16 @@ static void gpio_pollnotify(FAR struct gpio_dev_s *dev, pollevent_t eventset)
 #define gpio_pollnotify(dev, event)
 #endif
 
-/*******************************************************************************
+/****************************************************************************
  * Name: gpio_write
  *
  * Description:
  *    This function is called when you handle the write() API in
  *    File system.
  *
- ******************************************************************************/
-
-static ssize_t gpio_write(FAR struct file *filep, FAR const char *buffer, size_t buflen)
+ ****************************************************************************/
+static ssize_t gpio_write(FAR struct file *filep, FAR const char *buffer,
+                         size_t buflen)
 {
        int32_t value;
        FAR struct inode *inode = filep->f_inode;
@@ -181,28 +185,27 @@ static ssize_t gpio_write(FAR struct file *filep, FAR const char *buffer, size_t
 
 }
 
-/*******************************************************************************
+/****************************************************************************
  * Name: gpio_read
  *
  * Description:
  *    This function is automatically called when you handle the read() API in
  *    File system.
  *
- ******************************************************************************/
-
-static ssize_t gpio_read(FAR struct file *filep, FAR char *buffer, size_t buflen)
+ ****************************************************************************/
+static ssize_t gpio_read(FAR struct file *filep, FAR char *buffer,
+                        size_t buflen)
 {
        FAR struct inode *inode = filep->f_inode;
        FAR struct gpio_dev_s *dev = inode->i_private;
        int ret;
        int value;
 
-       /* if you read gpio with 'cat', you have to return 0,
-        * Otherwise cat will be cleaned up properly.
-        * So If it is the first time, then return size, and resize fpos.
-        * next time return zero.
+       /*
+        * if you read gpio with 'cat', you have to return 0, Otherwise cat
+        * will be cleaned up properly. So If it is the first time, then
+        * return size, and resize fpos. next time return zero.
         */
-
        if (filep->f_pos == 0) {
                value = gpio_get(dev);
 
@@ -219,14 +222,13 @@ static ssize_t gpio_read(FAR struct file *filep, FAR char *buffer, size_t buflen
 
 }
 
-/*******************************************************************************
+/****************************************************************************
  * Name: gpio_ioctl
  *
  * Description:
  *    This function is allow you to control the event.
  *
- ******************************************************************************/
-
+ ****************************************************************************/
 static int gpio_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
 {
        int ret;
@@ -238,17 +240,17 @@ static int gpio_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
        return ret;
 }
 
-/******************************************************************************
+/****************************************************************************
  * Name: gpio_poll
  *
  * Description:
  *    This function is called when you want to wait for events.
  *    You don't know when the event will be occured.
  *
- ******************************************************************************/
-
+ ****************************************************************************/
 #ifndef CONFIG_DISABLE_POLL
-static int gpio_poll(FAR struct file *filep, FAR struct pollfd *fds, bool setup)
+static int gpio_poll(FAR struct file *filep, FAR struct pollfd *fds,
+                    bool setup)
 {
        FAR struct inode *inode = filep->f_inode;
        FAR struct gpio_dev_s *dev = inode->i_private;
@@ -256,33 +258,29 @@ static int gpio_poll(FAR struct file *filep, FAR struct pollfd *fds, bool setup)
        int i;
 
        /* Some sanity checking */
-
        if (!dev || !fds) {
                return -ENODEV;
        }
 
        /* Are we setting up the poll?  Or tearing it down? */
-
        ret = gpio_takesem(&dev->pollsem, true);
        if (ret < 0) {
-               /* A signal received while waiting for access to the poll data
+               /*
+                * A signal received while waiting for access to the poll data
                 * will abort the operation.
                 */
-
                return ret;
        }
 
        if (setup) {
-               /* This is a request to set up the poll.  Find an available
+               /*
+                * This is a request to set up the poll.  Find an available
                 * slot for the poll structure reference
                 */
-
                for (i = 0; i < CONFIG_GPIO_NPOLLWAITERS; i++) {
                        /* Find an available slot */
-
                        if (!dev->fds[i]) {
                                /* Bind the poll structure and this slot */
-
                                dev->fds[i] = fds;
                                fds->priv = &dev->fds[i];
                                break;
@@ -296,7 +294,6 @@ static int gpio_poll(FAR struct file *filep, FAR struct pollfd *fds, bool setup)
                }
        } else if (fds->priv) {
                /* This is a request to tear down the poll. */
-
                struct pollfd **slot = (struct pollfd **)fds->priv;
 
                if (!slot) {
@@ -305,7 +302,6 @@ static int gpio_poll(FAR struct file *filep, FAR struct pollfd *fds, bool setup)
                }
 
                /* Remove all memory of the poll setup */
-
                *slot = NULL;
                fds->priv = NULL;
        }
@@ -314,16 +310,15 @@ errout:
        gpio_givesem(&dev->pollsem);
        return ret;
 }
-#endif                                                 /* CONFIG_DISABLE_POLL */
+#endif /* CONFIG_DISABLE_POLL */
 
-/*******************************************************************************
+/****************************************************************************
  * Name: gpio_fclose
  *
  * Description:
  *   This routine is called when the gpio gets closed.
  *
- ******************************************************************************/
-
+ ****************************************************************************/
 static int gpio_fclose(FAR struct file *filep)
 {
        FAR struct inode *inode = filep->f_inode;
@@ -349,14 +344,13 @@ static int gpio_fclose(FAR struct file *filep)
        return OK;
 }
 
-/*******************************************************************************
+/*****************************************************************************
  * Name: gpio_fopen
  *
  * Description:
  *   This routine is called whenever gpio is opened.
  *
- ******************************************************************************/
-
+ ****************************************************************************/
 static int gpio_fopen(FAR struct file *filep)
 {
        int ret;
@@ -364,12 +358,17 @@ static int gpio_fopen(FAR struct file *filep)
        FAR struct gpio_dev_s *dev = inode->i_private;
        uint8_t tmp;
 
-       /* If the port is the middle of closing, wait until the close is finished.
-        * If a signal is received while we are waiting, then return EINTR.
+       /*
+        * If the port is the middle of closing, wait until the close is
+        * finished. If a signal is received while we are waiting, then
+        * return EINTR.
         */
        ret = gpio_takesem(&dev->closesem, true);
        if (ret < 0) {
-               /* A signal received while waiting for the last close operation. */
+               /*
+                * A signal received while waiting for the last close
+                * operation.
+                */
                return ret;
        }
 
@@ -402,15 +401,14 @@ errout_with_sem:
        return ret;
 }
 
-/*******************************************************************************
+/*****************************************************************************
  * Name: gpio_notify
  *
  * Description:
  *   This routine is called from irq handler. If you want to handle with
  *   async call or event, you have to register your fd with poll().
  *
- ******************************************************************************/
-
+ ****************************************************************************/
 void gpio_notify(FAR struct gpio_dev_s *dev)
 {
        gpio_pollnotify(dev, POLLIN);
@@ -418,18 +416,17 @@ void gpio_notify(FAR struct gpio_dev_s *dev)
        return;
 }
 
-/******************************************************************************
+/****************************************************************************
  * Public Functions
- ******************************************************************************/
+ ****************************************************************************/
 
-/******************************************************************************
+/****************************************************************************
  * Name: gpio_register
  *
  * Description:
  *   Register GPIO device.
  *
- ******************************************************************************/
-
+ ****************************************************************************/
 int gpio_register(FAR const char *path, FAR struct gpio_dev_s *dev)
 {
        sem_init(&dev->closesem, 0, 1);
@@ -441,14 +438,13 @@ int gpio_register(FAR const char *path, FAR struct gpio_dev_s *dev)
        return register_driver(path, &g_gpioops, 0666, dev);
 }
 
-/******************************************************************************
+/****************************************************************************
  * Name: gpio_unregister
  *
  * Description:
  *   unregister GPIO device.
  *
- ******************************************************************************/
-
+ ****************************************************************************/
 int gpio_unregister(FAR const char *path)
 {
        return unregister_driver(path);
index 6ea68ea..56e1bf3 100644 (file)
@@ -15,7 +15,7 @@
  * language governing permissions and limitations under the License.
  *
  ****************************************************************************/
-/************************************************************************************
+/****************************************************************************
  * include/tinyara/gpio.h
  *
  *   Copyright (C) 2016 SAMSUNG ELECTRONICS CO., LTD. All rights reserved.
  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  * POSSIBILITY OF SUCH DAMAGE.
  *
- ******************************************************************************/
+ ****************************************************************************/
 
 #ifndef __INCLUDE_TINYARA_GPIO_H
 #define __INCLUDE_TINYARA_GPIO_H
 
-/******************************************************************************
+/****************************************************************************
  * Included Files
- ******************************************************************************/
+ ****************************************************************************/
 
 #include <tinyara/config.h>
+
 #include <stdint.h>
 #include <semaphore.h>
+
 #include <tinyara/wdog.h>
 #include <tinyara/wqueue.h>
 
 #ifndef CONFIG_DISABLE_POLL
-#include<tinyara/serial/serial.h>
+#include <tinyara/serial/serial.h>
 #endif
-/******************************************************************************
+
+/****************************************************************************
  * Pre-processor Definitions
- ******************************************************************************/
+ ****************************************************************************/
 
 /* Maximum number of threads than can be waiting for POLL events */
 
 #define gpio_set(dev, s)        dev->ops->set(dev, s)
 #define gpio_ctrl(dev, s, v)    dev->ops->ctrl(dev, s, v)
 
-/******************************************************************************
+/****************************************************************************
  * Public Types
- ******************************************************************************/
+ ****************************************************************************/
 typedef void (*GPIO_CB_FUNC)(void);
 
 typedef enum {
-       GPIO_EDGE_NONE,                         /* No interrupt on GPIO */
-       GPIO_EDGE_BOTH,                         /* Interrupt occures on rising and falling edge */
-       GPIO_EDGE_RISING,                       /* Interrupt occurs on rising edge */
-       GPIO_EDGE_FALLING,                      /* Interrupt occurs on falling edge */
+       GPIO_EDGE_NONE,         /* No interrupt on GPIO */
+       GPIO_EDGE_BOTH,         /* Interrupt occures on rising and falling edge */
+       GPIO_EDGE_RISING,       /* Interrupt occurs on rising edge */
+       GPIO_EDGE_FALLING,      /* Interrupt occurs on falling edge */
 
-       GPIO_LEVEL_LOW,                         /* Not support in SystemIO */
-       GPIO_LEVEL_HIGH,                        /* Not support in SystemIO */
+       GPIO_LEVEL_LOW,         /* Not support in SystemIO */
+       GPIO_LEVEL_HIGH,        /* Not support in SystemIO */
 } gpio_edge_t;
 
 typedef enum {
@@ -152,9 +155,9 @@ struct gpio_dev_s {
 #endif
 };
 
-/******************************************************************************
+/****************************************************************************
  * Public Data
- ******************************************************************************/
+ ****************************************************************************/
 
 #undef EXTERN
 #if defined(__cplusplus)
@@ -164,73 +167,73 @@ extern "C" {
 #define EXTERN extern
 #endif
 
-/******************************************************************************
+/****************************************************************************
  * Public Functions
- ******************************************************************************/
+ ****************************************************************************/
 
-/*******************************************************************************
+/****************************************************************************
  * Name: gpio_notify
  *
  * Description:
  *   This routine is called from irq handler. If you want to handle with
  *   async call or event, you have to register your fd with poll().
  *
- ******************************************************************************/
+ ****************************************************************************/
 
 void gpio_notify(FAR struct gpio_dev_s *dev);
 
-/******************************************************************************
+/****************************************************************************
  * Name: gpio_register
  *
  * Description:
  *   Register GPIO device.
  *
- ******************************************************************************/
+ ****************************************************************************/
 
 int gpio_register(FAR const char *path, FAR struct gpio_dev_s *dev);
 
-/******************************************************************************
+/****************************************************************************
  * Name: gpio_export_init
  *
  * Description:
  *   register export-file in filesystem
  *
- ******************************************************************************/
+ ****************************************************************************/
 
 #ifdef CONFIG_GPIO_EXPORT
 int gpio_export_init();
 #endif
 
-/******************************************************************************
+/****************************************************************************
  * Name: gpio_unexport_init
  *
  * Description:
  *   register unexport-file in filesystem
  *
- ******************************************************************************/
+ ****************************************************************************/
 
 #ifdef CONFIG_GPIO_EXPORT
 int gpio_unexport_init();
 #endif
 
-/*******************************************************************************
+/****************************************************************************
  * Name: up_destroy_gpio
  *
  * Description:
- *  Destroy device.
+ *   Destroy device.
  *
- ******************************************************************************/
+ ****************************************************************************/
 
 int up_destroy_gpio(int32_t idx);
 
-/*******************************************************************************
+/****************************************************************************
  * Name: up_create_gpio
  *
  * Description:
- * Create device. Userspace may ask the kernel to export control of
- * a GPIO to userspace by writing its number to file (gpio_export).
+ *   Create device. Userspace may ask the kernel to export control of
+ *   a GPIO to userspace by writing its number to file (gpio_export).
  *
- ******************************************************************************/
+ ****************************************************************************/
 
 int up_create_gpio(int32_t idx);
 
@@ -239,4 +242,4 @@ int up_create_gpio(int32_t idx);
 }
 #endif
 
-#endif                                                 /* __INCLUDE_TINYARA_GPIO_H */
+#endif /* __INCLUDE_TINYARA_GPIO_H */