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---
|
---help---
|
||||||
I2C Slave write buffer size
|
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
|
endmenu # I2C Slave Support
|
||||||
|
|
||||||
config I2C_POLLED
|
config I2C_POLLED
|
||||||
|
@ -101,7 +101,7 @@ struct i2c_slave_driver_s
|
|||||||
|
|
||||||
/* The poll waiter */
|
/* The poll waiter */
|
||||||
|
|
||||||
FAR struct pollfd *fds;
|
FAR struct pollfd *fds[CONFIG_I2C_SLAVE_NPOLLWAITERS];
|
||||||
|
|
||||||
/* Number of open references */
|
/* 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;
|
FAR struct i2c_slave_driver_s *priv;
|
||||||
int ret = OK;
|
int ret = OK;
|
||||||
|
int i;
|
||||||
|
|
||||||
DEBUGASSERT(filep->f_inode->i_private != NULL);
|
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;
|
pollevent_t eventset = 0;
|
||||||
|
|
||||||
if (priv->fds == NULL)
|
for (i = 0; i < CONFIG_I2C_SLAVE_NPOLLWAITERS; i++)
|
||||||
{
|
{
|
||||||
priv->fds = fds;
|
if (!priv->fds[i])
|
||||||
fds->priv = &priv->fds;
|
{
|
||||||
|
priv->fds[i] = fds;
|
||||||
|
fds->priv = &priv->fds[i];
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
|
if (i == CONFIG_I2C_SLAVE_NPOLLWAITERS)
|
||||||
{
|
{
|
||||||
ret = -EBUSY;
|
ret = -EBUSY;
|
||||||
goto out;
|
goto out;
|
||||||
@ -416,11 +422,12 @@ static int i2c_slave_poll(FAR struct file *filep, FAR struct pollfd *fds,
|
|||||||
eventset |= POLLOUT;
|
eventset |= POLLOUT;
|
||||||
}
|
}
|
||||||
|
|
||||||
poll_notify(&priv->fds, 1, eventset);
|
poll_notify(priv->fds, CONFIG_I2C_SLAVE_NPOLLWAITERS, eventset);
|
||||||
}
|
}
|
||||||
else if (fds->priv != NULL)
|
else if (fds->priv != NULL)
|
||||||
{
|
{
|
||||||
priv->fds = NULL;
|
struct pollfd **slot = fds->priv;
|
||||||
|
*slot = NULL;
|
||||||
fds->priv = 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);
|
nxmutex_unlock(&priv->lock);
|
||||||
poll_notify(&priv->fds, 1, events);
|
poll_notify(priv->fds, CONFIG_I2C_SLAVE_NPOLLWAITERS, events);
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user