diff --git a/Documentation/NuttxPortingGuide.html b/Documentation/NuttxPortingGuide.html index 12850ed495..339f64f306 100644 --- a/Documentation/NuttxPortingGuide.html +++ b/Documentation/NuttxPortingGuide.html @@ -12,7 +12,7 @@
Last Updated: May 20, 2017
+Last Updated: August 30, 2017
@@ -4999,6 +4999,45 @@ void iob_dump(FAR const char *msg, FAR struct iob_s *iob, unsigned int len, Platform-specific CAN drivers reside inarch/
<architecture>/src/
<chip> directory for the specific processor <architecture> and for the specific <chip> CAN peripheral devices.
++ Usage Note: + When reading from the the CAN multiple messages may be returned, depending on (1) the size the returned can messages, and (2) the size of the buffer provided to receive CAN messages. + Never assume that a single message will be returned... if you do this, you will lose CAN data under conditions where your read buffer can hold more than one small message. + Below is an example about how you should think of the CAN read operation: +
++#define BUFLEN 128 + +FAR struct can_msg_s *msg; +char rxbuffer[BUFLEN]; +ssize_t nread; +int nbytes; +int msglen +int i; + +/* Read messages into the RX buffer */ + +nread = read(fd, rxbuffer, BUFLEN); + +/* Check for read errors */ +... + +/* Process each message in the RX buffer */ + +for (i = 0; i <= nread - CAN_MSGLEN(0); i += msglen) +{ + /* Get the next message from the RX buffer */ + + msg = (FAR struct can_msg_s *)&rxbuffer[i]; + nbytes = can_dlc2bytes(msg->cm_hdr.ch_dlc); + msglen = CAN_MSGLEN(nbytes); + + DEBUGASSERT(i + msglen < BUFLEN); + + /* Process the next CAN message */ + ... +} +