Add support for testing multiple ADC, PWM, and QE devices

git-svn-id: https://nuttx.svn.sourceforge.net/svnroot/nuttx/trunk@4993 7fd9a85b-ad96-42d3-883c-3090e2eb8679
This commit is contained in:
patacongo
2012-07-30 16:51:43 +00:00
parent a4f9a7805d
commit cb77f5961d
9 changed files with 305 additions and 69 deletions
+5 -3
View File
@@ -100,9 +100,11 @@
#ifdef CONFIG_NSH_BUILTIN_APPS
struct qe_example_s
{
bool reset; /* True: set the count back to zero */
unsigned int nloops; /* Collect this number of samples */
unsigned int delay; /* Delay this number of seconds between samples */
bool initialized; /* True: QE devices have been initialized */
bool reset; /* True: set the count back to zero */
FAR char *devpath; /* Path to the QE device */
unsigned int nloops; /* Collect this number of samples */
unsigned int delay; /* Delay this number of seconds between samples */
};
#endif
+55 -17
View File
@@ -45,6 +45,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <fcntl.h>
#include <limits.h>
#include <errno.h>
@@ -90,6 +91,24 @@ struct qe_example_s g_qeexample;
* Private Functions
****************************************************************************/
/****************************************************************************
* Name: qe_devpath
****************************************************************************/
static void qe_devpath(FAR const char *devpath)
{
/* Get rid of any old device path */
if (g_qeexample.devpath)
{
free(g_qeexample.devpath);
}
/* The set-up the new device path by copying the string */
g_qeexample.devpath = strdup(devpath);
}
/****************************************************************************
* Name: qe_help
****************************************************************************/
@@ -99,6 +118,7 @@ static void qe_help(void)
{
message("\nUsage: qe [OPTIONS]\n\n");
message("OPTIONS include:\n");
message(" [-p devpath] QE device path\n");
message(" [-n samples] Number of samples\n");
message(" [-t msec] Delay between samples (msec)\n");
message(" [-r] Reset the position to zero\n");
@@ -152,6 +172,7 @@ static int arg_decimal(FAR char **arg, FAR long *value)
static void parse_args(int argc, FAR char **argv)
{
FAR char *ptr;
FAR char *str;
long value;
int index;
int nargs;
@@ -183,6 +204,12 @@ static void parse_args(int argc, FAR char **argv)
index += nargs;
break;
case 'p':
nargs = arg_string(&argv[index], &str);
qe_devpath(str);
index += nargs;
break;
case 't':
nargs = arg_decimal(&argv[index], &value);
if (value < 0 || value > INT_MAX)
@@ -231,33 +258,44 @@ int MAIN_NAME(int argc, char *argv[])
int nloops;
#endif
/* Check if we have initialized */
if (!g_qeexample.initialized)
{
/* Initialization of the encoder hardware is performed by logic external to
* this test.
*/
message(MAIN_STRING "Initializing external encoder(s)\n");
ret = qe_devinit();
if (ret != OK)
{
message(MAIN_STRING "qe_devinit failed: %d\n", ret);
exitval = EXIT_FAILURE;
goto errout;
}
/* Set the default values */
qe_devpath(CONFIG_EXAMPLES_QENCODER_DEVPATH);
g_qeexample.initialized = true;
}
/* Parse command line arguments */
#ifdef CONFIG_NSH_BUILTIN_APPS
parse_args(argc, argv);
#endif
/* Initialization of the encoder hardware is performed by logic external to
* this test.
*/
message(MAIN_STRING "Initializing external encoder\n");
ret = qe_devinit();
if (ret != OK)
{
message(MAIN_STRING "qe_devinit failed: %d\n", ret);
exitval = EXIT_FAILURE;
goto errout;
}
/* Open the encoder device for reading */
message(MAIN_STRING "Hardware initialized. Opening the encoder device\n");
fd = open(CONFIG_EXAMPLES_QENCODER_DEVPATH, O_RDONLY);
message(MAIN_STRING "Hardware initialized. Opening the encoder device: %s\n",
g_qeexample.devpath);
fd = open(g_qeexample.devpath, O_RDONLY);
if (fd < 0)
{
message(MAIN_STRING "open %s failed: %d\n",
CONFIG_EXAMPLES_QENCODER_DEVPATH, errno);
message(MAIN_STRING "open %s failed: %d\n", g_qeexample.devpath, errno);
exitval = EXIT_FAILURE;
goto errout_with_dev;
}