Skip to content

Commit

Permalink
sensor: Fixed the problem of user information lag in cross-core commu…
Browse files Browse the repository at this point in the history
…nication "stublist".

When its remote core publishes a message, all subscribed cores will receive the message,
but the local core "stublist" does not update the user's "generation" and "bufferpos" parameters.

Signed-off-by: likun17 <[email protected]>
  • Loading branch information
Otpvondoiats committed Sep 21, 2024
1 parent b5c5e4b commit aeeffc0
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 11 deletions.
50 changes: 39 additions & 11 deletions drivers/sensors/sensor.c
Original file line number Diff line number Diff line change
Expand Up @@ -456,9 +456,17 @@ static ssize_t sensor_do_samples(FAR struct sensor_upperhalf_s *upper,

if (user->state.interval == UINT32_MAX)
{
ret = circbuf_peekat(&upper->buffer,
user->bufferpos * upper->state.esize,
buffer, len);
if (buffer != NULL)
{
ret = circbuf_peekat(&upper->buffer,
user->bufferpos * upper->state.esize,
buffer, len);
}
else
{
ret = len;
}

user->bufferpos += nums;
circbuf_peekat(&upper->timing,
(user->bufferpos - 1) * TIMING_BUF_ESIZE,
Expand Down Expand Up @@ -506,9 +514,17 @@ static ssize_t sensor_do_samples(FAR struct sensor_upperhalf_s *upper,
((user->state.generation + user->state.interval) << 1);
if (delta >= 0)
{
ret += circbuf_peekat(&upper->buffer,
(pos - 1) * upper->state.esize,
buffer + ret, upper->state.esize);
if (buffer != NULL)
{
ret += circbuf_peekat(&upper->buffer,
(pos - 1) * upper->state.esize,
buffer + ret, upper->state.esize);
}
else
{
ret += upper->state.esize;
}

user->bufferpos = pos;
user->state.generation += user->state.interval;
if (ret >= len)
Expand Down Expand Up @@ -701,14 +717,19 @@ static ssize_t sensor_read(FAR struct file *filep, FAR char *buffer,
FAR struct sensor_user_s *user = filep->f_priv;
ssize_t ret;

if (!buffer || !len)
if (!len)
{
return -EINVAL;
}

nxrmutex_lock(&upper->lock);
if (lower->ops->fetch)
{
if (buffer == NULL)
{
return -EINVAL;
}

if (!(filep->f_oflags & O_NONBLOCK))
{
nxrmutex_unlock(&upper->lock);
Expand Down Expand Up @@ -738,11 +759,18 @@ static ssize_t sensor_read(FAR struct file *filep, FAR char *buffer,
}
else if (lower->persist)
{
/* Persistent device can get latest old data if not updated. */
if (buffer == NULL)
{
ret = upper->state.esize;
}
else
{
/* Persistent device can get latest old data if not updated. */

ret = circbuf_peekat(&upper->buffer,
(user->bufferpos - 1) * upper->state.esize,
buffer, upper->state.esize);
ret = circbuf_peekat(&upper->buffer,
(user->bufferpos - 1) * upper->state.esize,
buffer, upper->state.esize);
}
}
else
{
Expand Down
18 changes: 18 additions & 0 deletions drivers/sensors/sensor_rpmsg.c
Original file line number Diff line number Diff line change
Expand Up @@ -1132,6 +1132,8 @@ static int sensor_rpmsg_publish_handler(FAR struct rpmsg_endpoint *ept,
{
FAR struct sensor_rpmsg_data_s *msg = data;
FAR struct sensor_rpmsg_cell_s *cell;
FAR struct sensor_rpmsg_stub_s *stub;
FAR struct sensor_rpmsg_stub_s *stmp;
FAR struct sensor_rpmsg_dev_s *dev;
size_t written = sizeof(*msg);

Expand All @@ -1154,6 +1156,22 @@ static int sensor_rpmsg_publish_handler(FAR struct rpmsg_endpoint *ept,
}

dev->push_event(dev->upper, cell->data, cell->len);

/* When the remote core publishes a message, the subscribed cores will
* receive the message. When the subscribed core publishes a new
* message, it will take away the message published by the remote core,
* so all stublist information needs to be updated.
*/

sensor_rpmsg_lock(dev);
list_for_every_entry_safe(&dev->stublist, stub, stmp,
struct sensor_rpmsg_stub_s, node)
{
file_read(&stub->file, NULL, cell->len);
}

sensor_rpmsg_unlock(dev);

written += sizeof(*cell) + cell->len + 0x7;
written &= ~0x7;
}
Expand Down

0 comments on commit aeeffc0

Please sign in to comment.