diff options
author | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2012-01-20 21:52:35 +0000 |
---|---|---|
committer | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2012-01-20 21:52:35 +0000 |
commit | 1a0b77740ae6317e7a9a512489bc74cecb4a5fdf (patch) | |
tree | 82926d6798d4193b9d1c0421d0b496acced412ae /nuttx/drivers/can.c | |
parent | 49c358953f0d1462456a666cdf141346884d655d (diff) | |
download | px4-nuttx-1a0b77740ae6317e7a9a512489bc74cecb4a5fdf.tar.gz px4-nuttx-1a0b77740ae6317e7a9a512489bc74cecb4a5fdf.tar.bz2 px4-nuttx-1a0b77740ae6317e7a9a512489bc74cecb4a5fdf.zip |
Add support for extended (29-bit) CAN IDs
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@4319 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/drivers/can.c')
-rw-r--r-- | nuttx/drivers/can.c | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/nuttx/drivers/can.c b/nuttx/drivers/can.c index ec61fef17..3c9ea28fc 100644 --- a/nuttx/drivers/can.c +++ b/nuttx/drivers/can.c @@ -325,7 +325,7 @@ static ssize_t can_read(FAR struct file *filep, FAR char *buffer, size_t buflen) /* Will the next message in the FIFO fit into the user buffer? */ FAR struct can_msg_s *msg = &dev->cd_recv.rx_buffer[dev->cd_recv.rx_head]; - int msglen = CAN_MSGLEN(msg->cm_hdr); + int msglen = CAN_MSGLEN(msg->cm_hdr.ch_dlc); if (nread + msglen > buflen) { @@ -532,7 +532,7 @@ static ssize_t can_write(FAR struct file *filep, FAR const char *buffer, size_t */ msg = (FAR struct can_msg_s *)&buffer[nsent]; - msglen = CAN_MSGLEN(msg->cm_hdr); + msglen = CAN_MSGLEN(msg->cm_hdr.ch_dlc); memcpy(&fifo->tx_buffer[fifo->tx_tail], msg, msglen); /* Increment the tail of the circular buffer */ @@ -706,7 +706,7 @@ int can_register(FAR const char *path, FAR struct can_dev_s *dev) * ************************************************************************************/ -int can_receive(FAR struct can_dev_s *dev, uint16_t hdr, FAR uint8_t *data) +int can_receive(FAR struct can_dev_s *dev, FAR struct can_hdr_s *hdr, FAR uint8_t *data) { FAR struct can_rxfifo_s *fifo = &dev->cd_recv; FAR uint8_t *dest; @@ -714,7 +714,7 @@ int can_receive(FAR struct can_dev_s *dev, uint16_t hdr, FAR uint8_t *data) int err = -ENOMEM; int i; - canllvdbg("ID: %d DLC: %d\n", CAN_ID(hdr), CAN_DLC(hdr)); + canllvdbg("ID: %d DLC: %d\n", hdr->ch_id, hdr->ch_dlc); /* Check if adding this new message would over-run the drivers ability to enqueue * read data. @@ -743,12 +743,12 @@ int can_receive(FAR struct can_dev_s *dev, uint16_t hdr, FAR uint8_t *data) * a non-NULL receiving address */ - if (msg && CAN_ID(hdr) == rtr->cr_id) + if (msg && hdr->ch_id == rtr->cr_id) { /* We have the response... copy the data to the user's buffer */ - msg->cm_hdr = hdr; - for (i = 0, dest = msg->cm_data; i < CAN_DLC(hdr); i++) + memcpy(&msg->cm_hdr, hdr, sizeof(struct can_hdr_s)); + for (i = 0, dest = msg->cm_data; i < hdr->ch_dlc; i++) { *dest++ = *data++; } @@ -770,8 +770,8 @@ int can_receive(FAR struct can_dev_s *dev, uint16_t hdr, FAR uint8_t *data) { /* Add the new, decoded CAN message at the tail of the FIFO */ - fifo->rx_buffer[fifo->rx_tail].cm_hdr = hdr; - for (i = 0, dest = fifo->rx_buffer[fifo->rx_tail].cm_data; i < CAN_DLC(hdr); i++) + memcpy(&fifo->rx_buffer[fifo->rx_tail].cm_hdr, hdr, sizeof(struct can_hdr_s)); + for (i = 0, dest = fifo->rx_buffer[fifo->rx_tail].cm_data; i < hdr->ch_dlc; i++) { *dest++ = *data++; } |