Skip to content

Commit

Permalink
net/can: fix timestamp
Browse files Browse the repository at this point in the history
Fix timestamp in socket CAN. Right now the timestamp is only generated
if there is no reader and the frame is stored in the read ahead list.
This is solved by moving the timestamp generation before the code flow
branch.

Signed-off-by: Javier Casas <[email protected]>
  • Loading branch information
occam25 committed Mar 7, 2025
1 parent e15f7b1 commit 12396a2
Showing 1 changed file with 16 additions and 21 deletions.
37 changes: 16 additions & 21 deletions net/can/can_callback.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,20 +119,6 @@ uint16_t can_callback(FAR struct net_driver_s *dev,

if (conn)
{
/* Try to lock the network when successful send data to the listener */

if (net_trylock() == OK)
{
flags = devif_conn_event(dev, flags, conn->sconn.list);
net_unlock();
}

/* Either we did not get the lock or there is no application listening
* If we did not get a lock we store the frame in the read-ahead buffer
*/

if ((flags & CAN_NEWDATA) != 0)
{
#ifdef CONFIG_NET_TIMESTAMP
/* TIMESTAMP sockopt is activated,
* create timestamp and copy to iob
Expand All @@ -150,18 +136,27 @@ uint16_t can_callback(FAR struct net_driver_s *dev,
len = iob_trycopyin(dev->d_iob, (FAR uint8_t *)&tv,
sizeof(struct timeval),
-CONFIG_NET_LL_GUARDSIZE, false);
if (len != sizeof(struct timeval))
{
dev->d_len = 0;
return flags & ~CAN_NEWDATA;
}
else
if (len == sizeof(struct timeval))
{
dev->d_len += len;
}
}

#endif

/* Try to lock the network when successful send data to the listener */

if (net_trylock() == OK)
{
flags = devif_conn_event(dev, flags, conn->sconn.list);
net_unlock();
}

/* Either we did not get the lock or there is no application listening
* If we did not get a lock we store the frame in the read-ahead buffer
*/

if ((flags & CAN_NEWDATA) != 0)
{
/* Data was not handled.. dispose of it appropriately */

flags = can_data_event(dev, conn, flags);
Expand Down

0 comments on commit 12396a2

Please sign in to comment.