Skip to content
Snippets Groups Projects
Commit a3301a70 authored by patacongo's avatar patacongo
Browse files

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
parent ac307ce7
No related branches found
No related tags found
No related merge requests found
...@@ -57,6 +57,12 @@ ...@@ -57,6 +57,12 @@
* Pre-processor Definitions * Pre-processor Definitions
****************************************************************************/ ****************************************************************************/
#ifdef CONFIG_CAN_EXTID
# define MAX_ID (1 << 29)
#else
# define MAX_ID (1 << 11)
#endif
#ifdef CONFIG_NSH_BUILTIN_APPS #ifdef CONFIG_NSH_BUILTIN_APPS
# define MAIN_NAME can_main # define MAIN_NAME can_main
# define MAIN_STRING "can_main: " # define MAIN_STRING "can_main: "
...@@ -99,12 +105,16 @@ int MAIN_NAME(int argc, char *argv[]) ...@@ -99,12 +105,16 @@ int MAIN_NAME(int argc, char *argv[])
struct can_msg_s rxmsg; struct can_msg_s rxmsg;
size_t msgsize; size_t msgsize;
ssize_t nbytes; ssize_t nbytes;
#ifdef CONFIG_CAN_EXTID
uint32_t msgid;
#else
uint16_t msgid;
#endif
uint8_t msgdata; uint8_t msgdata;
#if defined(CONFIG_NSH_BUILTIN_APPS) || defined(CONFIG_EXAMPLES_CAN_NMSGS) #if defined(CONFIG_NSH_BUILTIN_APPS) || defined(CONFIG_EXAMPLES_CAN_NMSGS)
long nmsgs; long nmsgs;
#endif #endif
int msgdlc; int msgdlc;
int msgid;
int fd; int fd;
int errval = 0; int errval = 0;
int ret; int ret;
...@@ -174,7 +184,13 @@ int MAIN_NAME(int argc, char *argv[]) ...@@ -174,7 +184,13 @@ int MAIN_NAME(int argc, char *argv[])
/* Construct the next TX message */ /* Construct the next TX message */
txmsg.cm_hdr = CAN_HDR(msgid, 0, msgdlc); txmsg.cm_hdr.ch_id = msgid;
txmsg.cm_hdr.ch_rtr = false;
txmsg.cm_hdr.ch_dlc = msgdlc;
#ifdef CONFIG_CAN_EXTID
txmsg.cm_hdr.ch_extid = true;
#endif
for (i = 0; i < msgdlc; i++) for (i = 0; i < msgdlc; i++)
{ {
txmsg.cm_data[i] = msgdata + i; txmsg.cm_data[i] = msgdata + i;
...@@ -182,7 +198,7 @@ int MAIN_NAME(int argc, char *argv[]) ...@@ -182,7 +198,7 @@ int MAIN_NAME(int argc, char *argv[])
/* Send the TX message */ /* Send the TX message */
msgsize = CAN_MSGLEN(txmsg.cm_hdr); msgsize = CAN_MSGLEN(msgdlc);
nbytes = write(fd, &txmsg, msgsize); nbytes = write(fd, &txmsg, msgsize);
if (nbytes != msgsize) if (nbytes != msgsize)
{ {
...@@ -204,16 +220,20 @@ int MAIN_NAME(int argc, char *argv[]) ...@@ -204,16 +220,20 @@ int MAIN_NAME(int argc, char *argv[])
/* Verify that the received messages are the same */ /* Verify that the received messages are the same */
if (txmsg.cm_hdr != rxmsg.cm_hdr) if (memcmp(&txmsg.cm_hdr, &rxmsg.cm_hdr, sizeof(struct can_hdr_s)) != 0)
{ {
message("ERROR: Sent header %04x; received header %04x\n", txmsg.cm_hdr, rxmsg.cm_hdr); message("ERROR: Sent header does not match received header:\n");
lib_dumpbuffer("Sent header", (FAR const uint8_t*)&txmsg.cm_hdr,
sizeof(struct can_hdr_s));
lib_dumpbuffer("Received header", (FAR const uint8_t*)&rxmsg.cm_hdr,
sizeof(struct can_hdr_s));
errval = 4; errval = 4;
goto errout_with_dev; goto errout_with_dev;
} }
if (memcmp(txmsg.cm_data, rxmsg.cm_data, msgdlc) != 0) if (memcmp(txmsg.cm_data, rxmsg.cm_data, msgdlc) != 0)
{ {
message("ERROR: Data does not match. DLC=%d\n", msgdlc); message("ERROR: Data does not match. DLC=%d\n", msgdlc);
for (i = 0; i < msgdlc; i++) for (i = 0; i < msgdlc; i++)
{ {
message(" %d: TX %02x RX %02x\n", i, txmsg.cm_data[i], rxmsg.cm_data[i]); message(" %d: TX %02x RX %02x\n", i, txmsg.cm_data[i], rxmsg.cm_data[i]);
...@@ -230,7 +250,7 @@ int MAIN_NAME(int argc, char *argv[]) ...@@ -230,7 +250,7 @@ int MAIN_NAME(int argc, char *argv[])
msgdata += msgdlc; msgdata += msgdlc;
if (++msgid >= 2048) if (++msgid >= MAX_ID)
{ {
msgid = 1; msgid = 1;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment