This is an automated email from the ASF dual-hosted git repository.
xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
The following commit(s) were added to refs/heads/master by this push:
new 20e5ad95f5b drivers/can/ctucanfd: Fix 29-bit extended CAN identifiers.
20e5ad95f5b is described below
commit 20e5ad95f5b756d58eaa558e871354d4b47fd055
Author: raiden00pl <[email protected]>
AuthorDate: Tue Oct 13 19:47:26 2026 +0200
drivers/can/ctucanfd: Fix 29-bit extended CAN identifiers.
The frame ID word holds a 29-bit identifier in bits 28..0: the upper
11 bits in the base identifier field, the lower 18 bits in the
extension field. The driver used only the extension field, so the
upper 11 bits were lost on TX and RX in both the socket and character
driver paths.
Assisted-by: Claude:claude-opus-5-5
Signed-off-by: raiden00pl <[email protected]>
---
drivers/can/ctucanfd.h | 6 +++++-
drivers/can/ctucanfd_pci.c | 21 ++++++++++++---------
2 files changed, 17 insertions(+), 10 deletions(-)
diff --git a/drivers/can/ctucanfd.h b/drivers/can/ctucanfd.h
index 84b040b308b..04b1690ec67 100644
--- a/drivers/can/ctucanfd.h
+++ b/drivers/can/ctucanfd.h
@@ -223,7 +223,11 @@ union ctucanfd_frame_fmt_u
uint32_t u32;
};
-/* CAN FD frame ID */
+/* CAN FD frame ID. A 29-bit identifier takes bits 28..0: its upper
+ * 11 bits are the base identifier, its lower 18 bits the extension.
+ */
+
+#define CTUCANFD_ID_EXT_BITS (18)
begin_packed_struct struct ctucanfd_frame_id_s
{
diff --git a/drivers/can/ctucanfd_pci.c b/drivers/can/ctucanfd_pci.c
index 80d515b8a62..18be3272874 100644
--- a/drivers/can/ctucanfd_pci.c
+++ b/drivers/can/ctucanfd_pci.c
@@ -610,8 +610,8 @@ static int ctucanfd_chrdev_send(FAR struct can_dev_s *dev,
#ifdef CONFIG_CAN_EXTID
if (msg->cm_hdr.ch_extid)
{
- fmt.s.ide = 1;
- id.s.id_ext = msg->cm_hdr.ch_id;
+ fmt.s.ide = 1;
+ id.u32 = msg->cm_hdr.ch_id & CAN_MAX_EXTMSGID;
}
else
#endif
@@ -793,7 +793,8 @@ static void ctucanfd_chardev_receive(FAR struct
ctucanfd_can_s *priv)
if (hdr.ch_extid)
{
- hdr.ch_id = frame->id.id_ext;
+ hdr.ch_id = ((uint32_t)frame->id.id << CTUCANFD_ID_EXT_BITS) |
+ frame->id.id_ext;
}
else
{
@@ -1126,8 +1127,8 @@ static int ctucanfd_sock_transmit(FAR struct
netdev_lowerhalf_s *dev,
#ifdef CONFIG_NET_CAN_EXTID
if (frame->can_id & CAN_EFF_FLAG)
{
- fmt.s.ide = 1;
- id.s.id_ext = (frame->can_id & 0x1ffffff);
+ fmt.s.ide = 1;
+ id.u32 = frame->can_id & CAN_EFF_MASK;
}
else
#endif
@@ -1172,8 +1173,8 @@ static int ctucanfd_sock_transmit(FAR struct
netdev_lowerhalf_s *dev,
#ifdef CONFIG_NET_CAN_EXTID
if (frame->can_id & CAN_EFF_FLAG)
{
- fmt.s.ide = 1;
- id.s.id_ext = (frame->can_id & 0x1ffffff);
+ fmt.s.ide = 1;
+ id.u32 = frame->can_id & CAN_EFF_MASK;
}
else
#endif
@@ -1295,7 +1296,8 @@ static FAR netpkt_t *ctucanfd_sock_recv(FAR struct
netdev_lowerhalf_s *dev)
if (rxframe->fmt.ide)
{
- frame->can_id = rxframe->id.id_ext;
+ frame->can_id = ((uint32_t)rxframe->id.id <<
+ CTUCANFD_ID_EXT_BITS) | rxframe->id.id_ext;
frame->can_id |= CAN_EFF_FLAG;
}
else
@@ -1360,7 +1362,8 @@ static FAR netpkt_t *ctucanfd_sock_recv(FAR struct
netdev_lowerhalf_s *dev)
if (rxframe->fmt.ide)
{
- frame->can_id = rxframe->id.id_ext;
+ frame->can_id = ((uint32_t)rxframe->id.id <<
+ CTUCANFD_ID_EXT_BITS) | rxframe->id.id_ext;
frame->can_id |= CAN_EFF_FLAG;
}
else