summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpatacongo <patacongo@7fd9a85b-ad96-42d3-883c-3090e2eb8679>2012-03-14 01:19:27 +0000
committerpatacongo <patacongo@7fd9a85b-ad96-42d3-883c-3090e2eb8679>2012-03-14 01:19:27 +0000
commit61b72c1e27b7a6db56dfcd9a6c34fbb59c8ec8f4 (patch)
tree66d8c405ea691ef7b061d7f6d830eba7a6382045
parentce815a7d35f0dfdddf54337d5aed718d141e1d69 (diff)
Extend examples/can so that it can be used in other contexts
git-svn-id: https://nuttx.svn.sourceforge.net/svnroot/nuttx/trunk@4489 7fd9a85b-ad96-42d3-883c-3090e2eb8679
-rwxr-xr-xapps/ChangeLog.txt4
-rw-r--r--apps/examples/README.txt7
-rw-r--r--apps/examples/can/can.h2
-rw-r--r--apps/examples/can/can_main.c48
-rw-r--r--nuttx/configs/pic32-starterkit/README.txt4
5 files changed, 59 insertions, 6 deletions
diff --git a/apps/ChangeLog.txt b/apps/ChangeLog.txt
index eb8cab8617..ae4e5ec546 100755
--- a/apps/ChangeLog.txt
+++ b/apps/ChangeLog.txt
@@ -204,3 +204,7 @@
allows NSH to be used on boards that have USB but no serial connectors.
6.17 2012-xx-xx Gregory Nutt <gnutt@nuttx.org>
+
+ * apps/examples/can: Add conditional compilation so that the test can be
+ configured to only send messages or to only receive messages. This will
+ let the test work in other modes than simple loopback testing.
diff --git a/apps/examples/README.txt b/apps/examples/README.txt
index 86edc6e339..54cbec978b 100644
--- a/apps/examples/README.txt
+++ b/apps/examples/README.txt
@@ -110,6 +110,13 @@ examples/can
built-in, the default is 32. Otherwise messages are sent and received
indefinitely.
+ The default behavior assumes loopback mode. Messages are sent, then read
+ and verified. The behavior can be altered for other kinds of testing where
+ the test only sends or received (but does not verify) can messages.
+
+ CONFIG_EXAMPLES_CAN_READONLY - Only receive messages
+ CONFIG_EXAMPLES_CAN_WRITEONLY - Only send messages
+
examples/cdcacm
^^^^^^^^^^^^^^^
diff --git a/apps/examples/can/can.h b/apps/examples/can/can.h
index 0b781c6692..53a6b63ea0 100644
--- a/apps/examples/can/can.h
+++ b/apps/examples/can/can.h
@@ -65,6 +65,8 @@
* collected and the program terminates. Default: If built as an NSH
* built-in, the default is 32. Otherwise messages are sent and received
* indefinitely.
+ * CONFIG_EXAMPLES_CAN_READONLY - Only receive messages
+ * CONFIG_EXAMPLES_CAN_WRITEONLY - Only send messages
*/
#ifndef CONFIG_CAN
diff --git a/apps/examples/can/can_main.c b/apps/examples/can/can_main.c
index 27e19b1564..c7b0859ba5 100644
--- a/apps/examples/can/can_main.c
+++ b/apps/examples/can/can_main.c
@@ -57,6 +57,19 @@
* Pre-processor Definitions
****************************************************************************/
+#if defined(CONFIG_EXAMPLES_CAN_READONLY)
+# undef CONFIG_EXAMPLES_CAN_WRITEONLY
+# undef CONFIG_EXAMPLES_CAN_READWRITE
+# define CAN_OFLAGS O_RDONLY
+#elif defined(CONFIG_EXAMPLES_CAN_WRITEONLY)
+# undef CONFIG_EXAMPLES_CAN_READWRITE
+# define CAN_OFLAGS O_WRONLY
+#else
+# undef CONFIG_EXAMPLES_CAN_READWRITE
+# define CONFIG_EXAMPLES_CAN_READWRITE 1
+# define CAN_OFLAGS O_RDWR
+#endif
+
#ifdef CONFIG_CAN_EXTID
# define MAX_ID (1 << 29)
#else
@@ -101,20 +114,27 @@
int MAIN_NAME(int argc, char *argv[])
{
+#ifndef CONFIG_EXAMPLES_CAN_READONLY
struct can_msg_s txmsg;
- struct can_msg_s rxmsg;
- size_t msgsize;
- ssize_t nbytes;
#ifdef CONFIG_CAN_EXTID
uint32_t msgid;
#else
uint16_t msgid;
#endif
+ int msgdlc;
uint8_t msgdata;
+#endif
+
+#ifndef CONFIG_EXAMPLES_CAN_WRITEONLY
+ struct can_msg_s rxmsg;
+#endif
+
+ size_t msgsize;
+ ssize_t nbytes;
#if defined(CONFIG_NSH_BUILTIN_APPS) || defined(CONFIG_EXAMPLES_CAN_NMSGS)
long nmsgs;
#endif
- int msgdlc;
+
int fd;
int errval = 0;
int ret;
@@ -151,7 +171,7 @@ int MAIN_NAME(int argc, char *argv[])
/* Open the CAN device for reading */
message(MAIN_STRING "Hardware initialized. Opening the CAN device\n");
- fd = open(CONFIG_EXAMPLES_CAN_DEVPATH, O_RDWR);
+ fd = open(CONFIG_EXAMPLES_CAN_DEVPATH, CAN_OFLAGS);
if (fd < 0)
{
message(MAIN_STRING "open %s failed: %d\n",
@@ -164,9 +184,11 @@ int MAIN_NAME(int argc, char *argv[])
* on each pass.
*/
+#ifndef CONFIG_EXAMPLES_CAN_READONLY
msgdlc = 1;
msgid = 1;
msgdata = 0;
+#endif
#if defined(CONFIG_NSH_BUILTIN_APPS)
for (; nmsgs > 0; nmsgs--)
@@ -184,6 +206,7 @@ int MAIN_NAME(int argc, char *argv[])
/* Construct the next TX message */
+#ifndef CONFIG_EXAMPLES_CAN_READONLY
txmsg.cm_hdr.ch_id = msgid;
txmsg.cm_hdr.ch_rtr = false;
txmsg.cm_hdr.ch_dlc = msgdlc;
@@ -207,8 +230,14 @@ int MAIN_NAME(int argc, char *argv[])
goto errout_with_dev;
}
+#ifndef CONFIG_EXAMPLES_CAN_READWRITE
+ message(" ID: %4d DLC: %d\n", msgid, msgdlc);
+#endif
+#endif
+
/* Read the RX message */
+#ifndef CONFIG_EXAMPLES_CAN_WRITEONLY
msgsize = sizeof(struct can_msg_s);
nbytes = read(fd, &rxmsg, msgsize);
if (nbytes < CAN_MSGLEN(0) || nbytes > msgsize)
@@ -218,8 +247,14 @@ int MAIN_NAME(int argc, char *argv[])
goto errout_with_dev;
}
+#ifndef CONFIG_EXAMPLES_CAN_READWRITE
+ message(" ID: %4d DLC: %d\n", rxmsg.cm_hdr.id, rxmsg.cm_hdr.dlc);
+#endif
+#endif
+
/* Verify that the received messages are the same */
+#ifdef CONFIG_EXAMPLES_CAN_READWRITE
if (memcmp(&txmsg.cm_hdr, &rxmsg.cm_hdr, sizeof(struct can_hdr_s)) != 0)
{
message("ERROR: Sent header does not match received header:\n");
@@ -245,9 +280,11 @@ int MAIN_NAME(int argc, char *argv[])
/* Report success */
message(" ID: %4d DLC: %d -- OK\n", msgid, msgdlc);
+#endif
/* Set up for the next pass */
+#ifndef CONFIG_EXAMPLES_CAN_READONLY
msgdata += msgdlc;
if (++msgid >= MAX_ID)
@@ -259,6 +296,7 @@ int MAIN_NAME(int argc, char *argv[])
{
msgdlc = 1;
}
+#endif
}
errout_with_dev:
diff --git a/nuttx/configs/pic32-starterkit/README.txt b/nuttx/configs/pic32-starterkit/README.txt
index ffbffde783..5b71bc1525 100644
--- a/nuttx/configs/pic32-starterkit/README.txt
+++ b/nuttx/configs/pic32-starterkit/README.txt
@@ -1168,6 +1168,8 @@ Where <subdir> is one of the following:
nsh> msconn
NOTE: This modification is experimental and does not yet
- work properly! However, the configuration is worth remembering
+ work properly! My hunch is that the USB device driver won't
+ support MSC -- probably because the required MSC stall
+ handling. However, this configuration is worth remembering
for future USB MSC testing.