apps/examples/can: Extend test to report an errors reported by the CAN driver

This commit is contained in:
Gregory Nutt 2015-08-18 08:50:14 -06:00
parent 546450cc92
commit cb25507a06

View File

@ -320,10 +320,11 @@ int can_main(int argc, char *argv[])
txmsg.cm_hdr.ch_id = msgid;
txmsg.cm_hdr.ch_rtr = false;
txmsg.cm_hdr.ch_dlc = msgdlc;
txmsg.cm_hdr.ch_error = 0;
#ifdef CONFIG_CAN_EXTID
txmsg.cm_hdr.ch_extid = extended;
txmsg.cm_hdr.ch_unused = 0;
#endif
txmsg.cm_hdr.ch_unused = 0;
for (i = 0; i < msgdlc; i++)
{
@ -336,7 +337,8 @@ int can_main(int argc, char *argv[])
nbytes = write(fd, &txmsg, msgsize);
if (nbytes != msgsize)
{
printf("ERROR: write(%ld) returned %ld\n", (long)msgsize, (long)nbytes);
printf("ERROR: write(%ld) returned %ld\n",
(long)msgsize, (long)nbytes);
errval = 3;
goto errout_with_dev;
}
@ -353,16 +355,81 @@ int can_main(int argc, char *argv[])
nbytes = read(fd, &rxmsg, msgsize);
if (nbytes < CAN_MSGLEN(0) || nbytes > msgsize)
{
printf("ERROR: read(%ld) returned %ld\n", (long)msgsize, (long)nbytes);
printf("ERROR: read(%ld) returned %ld\n",
(long)msgsize, (long)nbytes);
errval = 4;
goto errout_with_dev;
}
#endif
#ifndef CONFIG_EXAMPLES_CAN_READONLY
printf(" ID: %4u DLC: %u\n", rxmsg.cm_hdr.ch_id, rxmsg.cm_hdr.ch_dlc);
printf(" ID: %4u DLC: %u\n",
rxmsg.cm_hdr.ch_id, rxmsg.cm_hdr.ch_dlc);
#endif
/* Check for error reports */
#ifndef CONFIG_EXAMPLES_CAN_WRITEONLY
if (rxmsg.cm_hdr.ch_error != 0)
{
printf("ERROR: CAN error report: [%04x]\n", rxmsg.cm_hdr.ch_id);
if ((rxmsg.cm_hdr.ch_id & CAN_ERROR_SYSTEM) != 0)
{
printf(" Driver internal error\n");
}
if ((rxmsg.cm_hdr.ch_id & CAN_ERROR_RXLOST) != 0)
{
printf(" RX Message Lost\n");
}
if ((rxmsg.cm_hdr.ch_id & CAN_ERROR_TXLOST) != 0)
{
printf(" TX Message Lost\n");
}
if ((rxmsg.cm_hdr.ch_id & CAN_ERROR_ACCESS) != 0)
{
printf(" RAM Access Failure\n");
}
if ((rxmsg.cm_hdr.ch_id & CAN_ERROR_TIMEOUT) != 0)
{
printf(" Timeout Occurred\n");
}
if ((rxmsg.cm_hdr.ch_id & CAN_ERROR_PASSIVE) != 0)
{
printf(" Error Passive\n");
}
if ((rxmsg.cm_hdr.ch_id & CAN_ERROR_CRC) != 0)
{
printf(" RX CRC Error\n");
}
if ((rxmsg.cm_hdr.ch_id & CAN_ERROR_BIT) != 0)
{
printf(" Bit Error\n");
}
if ((rxmsg.cm_hdr.ch_id & CAN_ERROR_ACK) != 0)
{
printf(" Acknowledge Error\n");
}
if ((rxmsg.cm_hdr.ch_id & CAN_ERROR_FORMAT) != 0)
{
printf(" Format Error\n");
}
if ((rxmsg.cm_hdr.ch_id & CAN_ERROR_STUFF) != 0)
{
printf(" Stuff Error\n");
}
}
else
{
/* Verify that the received messages are the same */
#ifdef CONFIG_EXAMPLES_CAN_READWRITE
@ -382,11 +449,14 @@ int can_main(int argc, char *argv[])
printf("ERROR: Data does not match. DLC=%d\n", msgdlc);
for (i = 0; i < msgdlc; i++)
{
printf(" %d: TX %02x RX %02x\n", i, txmsg.cm_data[i], rxmsg.cm_data[i]);
printf(" %d: TX %02x RX %02x\n",
i, txmsg.cm_data[i], rxmsg.cm_data[i]);
errval = 5;
goto errout_with_dev;
}
}
}
#endif
/* Report success */