Skip to content

Commit

Permalink
timer driver:support poll.
Browse files Browse the repository at this point in the history
Signed-off-by: yangguangcai <[email protected]>
  • Loading branch information
yangguangcai1 committed Aug 28, 2024
1 parent ab92b7d commit 5ce407f
Showing 1 changed file with 50 additions and 1 deletion.
51 changes: 50 additions & 1 deletion drivers/timers/timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include <nuttx/fs/fs.h>
#include <nuttx/mutex.h>
#include <nuttx/timers/timer.h>
#include <sys/poll.h>

#ifdef CONFIG_TIMER

Expand All @@ -53,6 +54,7 @@ struct timer_upperhalf_s
mutex_t lock; /* Supports mutual exclusion */
uint8_t crefs; /* The number of times the device has been opened */
FAR char *path; /* Registration path */
FAR struct pollfd *fds;

/* The contained signal info */

Expand All @@ -77,6 +79,8 @@ static ssize_t timer_write(FAR struct file *filep, FAR const char *buffer,
size_t buflen);
static int timer_ioctl(FAR struct file *filep, int cmd,
unsigned long arg);
static int timer_poll(FAR struct file *filep,
FAR struct pollfd *fds, bool setup);

/****************************************************************************
* Private Data
Expand All @@ -90,6 +94,9 @@ static const struct file_operations g_timerops =
timer_write, /* write */
NULL, /* seek */
timer_ioctl, /* ioctl */
NULL, /* mmap */
NULL, /* truncate */
timer_poll, /* poll */
};

/****************************************************************************
Expand All @@ -115,6 +122,8 @@ static bool timer_notifier(FAR uint32_t *next_interval_us, FAR void *arg)

/* Signal the waiter.. if there is one */

poll_notify(&upper->fds, 1, POLLIN);

nxsig_notification(notify->pid, &notify->event, SI_QUEUE, &upper->work);

return notify->periodic;
Expand Down Expand Up @@ -396,6 +405,46 @@ static int timer_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
return ret;
}

/****************************************************************************
* Name: timer_poll
****************************************************************************/

static int timer_poll(FAR struct file *filep,
FAR struct pollfd *fds, bool setup)
{
FAR struct inode *inode = filep->f_inode;
FAR struct timer_upperhalf_s *upper = inode->i_private;
irqstate_t flags;
int ret = OK;

if (upper == NULL || fds == NULL)
{
return -EINVAL;
}

flags = enter_critical_section();

if (setup)
{
if (upper->fds)
{
ret = -EBUSY;
goto errout;
}

upper->fds = fds;
}
else
{
upper->fds = NULL;
}

errout:
leave_critical_section(flags);

return ret;
}

/****************************************************************************
* Public Functions
****************************************************************************/
Expand Down Expand Up @@ -560,7 +609,7 @@ int timer_setcallback(FAR void *handle, tccb_t callback, FAR void *arg)

/* Check if the lower half driver supports the setcallback method */

if (lower->ops->setcallback != NULL) /* Optional */
if (lower->ops->setcallback != NULL)
{
/* Yes.. Defer the handler attachment to the lower half driver */

Expand Down

0 comments on commit 5ce407f

Please sign in to comment.