i2c_slave: add poll waiters array
Signed-off-by: Shoukui Zhang <zhangshoukui@xiaomi.com>
This commit is contained in:
parent
f94160095e
commit
75fa94af02
|
@ -46,6 +46,13 @@ config I2C_SLAVE_WRITEBUFSIZE
|
|||
---help---
|
||||
I2C Slave write buffer size
|
||||
|
||||
config I2C_SLAVE_NPOLLWAITERS
|
||||
int "Number of i2c slave poll waiters"
|
||||
default 1
|
||||
depends on I2C_SLAVE_DRIVER
|
||||
---help---
|
||||
Number of waiters to i2c slave poll
|
||||
|
||||
endmenu # I2C Slave Support
|
||||
|
||||
config I2C_POLLED
|
||||
|
|
|
@ -101,7 +101,7 @@ struct i2c_slave_driver_s
|
|||
|
||||
/* The poll waiter */
|
||||
|
||||
FAR struct pollfd *fds;
|
||||
FAR struct pollfd *fds[CONFIG_I2C_SLAVE_NPOLLWAITERS];
|
||||
|
||||
/* Number of open references */
|
||||
|
||||
|
@ -381,6 +381,7 @@ static int i2c_slave_poll(FAR struct file *filep, FAR struct pollfd *fds,
|
|||
{
|
||||
FAR struct i2c_slave_driver_s *priv;
|
||||
int ret = OK;
|
||||
int i;
|
||||
|
||||
DEBUGASSERT(filep->f_inode->i_private != NULL);
|
||||
|
||||
|
@ -395,12 +396,17 @@ static int i2c_slave_poll(FAR struct file *filep, FAR struct pollfd *fds,
|
|||
{
|
||||
pollevent_t eventset = 0;
|
||||
|
||||
if (priv->fds == NULL)
|
||||
for (i = 0; i < CONFIG_I2C_SLAVE_NPOLLWAITERS; i++)
|
||||
{
|
||||
priv->fds = fds;
|
||||
fds->priv = &priv->fds;
|
||||
if (!priv->fds[i])
|
||||
{
|
||||
priv->fds[i] = fds;
|
||||
fds->priv = &priv->fds[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
if (i == CONFIG_I2C_SLAVE_NPOLLWAITERS)
|
||||
{
|
||||
ret = -EBUSY;
|
||||
goto out;
|
||||
|
@ -416,11 +422,12 @@ static int i2c_slave_poll(FAR struct file *filep, FAR struct pollfd *fds,
|
|||
eventset |= POLLOUT;
|
||||
}
|
||||
|
||||
poll_notify(&priv->fds, 1, eventset);
|
||||
poll_notify(priv->fds, CONFIG_I2C_SLAVE_NPOLLWAITERS, eventset);
|
||||
}
|
||||
else if (fds->priv != NULL)
|
||||
{
|
||||
priv->fds = NULL;
|
||||
struct pollfd **slot = fds->priv;
|
||||
*slot = NULL;
|
||||
fds->priv = NULL;
|
||||
}
|
||||
|
||||
|
@ -507,7 +514,7 @@ static int i2c_slave_callback(FAR void *arg, i2c_slave_complete_t status,
|
|||
}
|
||||
|
||||
nxmutex_unlock(&priv->lock);
|
||||
poll_notify(&priv->fds, 1, events);
|
||||
poll_notify(priv->fds, CONFIG_I2C_SLAVE_NPOLLWAITERS, events);
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue