Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sensor:Fixed the problem of user information lag in cross-core communication "stublist". #13538

Merged
merged 1 commit into from
Sep 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading