diff options
author | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2011-08-30 19:48:47 +0000 |
---|---|---|
committer | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2011-08-30 19:48:47 +0000 |
commit | 0fb1d700e376c74efab18ea5f70a88eabececde1 (patch) | |
tree | 496df0236d9a88fabc2f7c5e5a2e0d685e99598d /apps | |
parent | 7b01904121be6cb88d28005a77da9c1815593925 (diff) | |
download | px4-nuttx-0fb1d700e376c74efab18ea5f70a88eabececde1.tar.gz px4-nuttx-0fb1d700e376c74efab18ea5f70a88eabececde1.tar.bz2 px4-nuttx-0fb1d700e376c74efab18ea5f70a88eabececde1.zip |
I2C tool no longer hangs on dev command
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@3930 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'apps')
-rw-r--r-- | apps/system/i2c/i2c_dev.c | 1 | ||||
-rw-r--r-- | apps/system/i2c/i2c_main.c | 31 | ||||
-rw-r--r-- | apps/system/i2c/i2ctool.h | 2 |
3 files changed, 24 insertions, 10 deletions
diff --git a/apps/system/i2c/i2c_dev.c b/apps/system/i2c/i2c_dev.c index a8340f0d8..2d9946be0 100644 --- a/apps/system/i2c/i2c_dev.c +++ b/apps/system/i2c/i2c_dev.c @@ -227,6 +227,7 @@ int cmd_dev(FAR struct i2ctool_s *i2ctool, int argc, char **argv) } } i2ctool_printf(i2ctool, "\n"); + i2ctool_flush(i2ctool); } (void)up_i2cuninitialize(dev); diff --git a/apps/system/i2c/i2c_main.c b/apps/system/i2c/i2c_main.c index 768054671..85ad90365 100644 --- a/apps/system/i2c/i2c_main.c +++ b/apps/system/i2c/i2c_main.c @@ -297,13 +297,13 @@ int i2c_parse(FAR struct i2ctool_s *i2ctool, int argc, char *argv[]) * Name: i2c_setup ****************************************************************************/ -static inline int i2c_setup(void) +static inline int i2c_setup(FAR struct i2ctool_s *i2ctool) { /* Initialize the output stream */ #ifdef CONFIG_I2CTOOL_OUTDEV - g_i2ctool.ss_outfd = open(CONFIG_I2CTOOL_OUTDEV, O_WRONLY); - if (g_i2ctool.ss_outfd < 0) + i2ctool->ss_outfd = open(CONFIG_I2CTOOL_OUTDEV, O_WRONLY); + if (i2ctool->ss_outfd < 0) { fprintf(stderr, g_i2ccmdfailed, "open", errno); return ERROR; @@ -311,8 +311,8 @@ static inline int i2c_setup(void) /* Create a standard C stream on the console device */ - g_i2ctool.ss_outstream = fdopen(g_i2ctool.ss_outfd, "w"); - if (!g_i2ctool.ss_outstream) + i2ctool->ss_outstream = fdopen(i2ctool->ss_outfd, "w"); + if (!i2ctool->ss_outstream) { fprintf(stderr, g_i2ccmdfailed, "fdopen", errno); return ERROR; @@ -330,12 +330,12 @@ static inline int i2c_setup(void) * ****************************************************************************/ -static void i2c_teardown(void) +static void i2c_teardown(FAR struct i2ctool_s *i2ctool) { fflush(OUTSTREAM(&g_i2ctool)); #ifdef CONFIG_I2CTOOL_OUTDEV - fclose(g_i2ctool.ss_outstream); + fclose(i2ctool->ss_outstream); #endif } @@ -386,10 +386,11 @@ int MAIN_NAME(int argc, char *argv[]) /* Parse process the command line */ - i2c_setup(); + i2c_setup(&g_i2ctool); (void)i2c_parse(&g_i2ctool, argc, argv); - i2c_teardown(); + i2ctool_flush(&g_i2ctool); + i2c_teardown(&g_i2ctool); return OK; } @@ -435,3 +436,15 @@ ssize_t i2ctool_write(FAR struct i2ctool_s *i2ctool, FAR const void *buffer, siz return ret; } +/**************************************************************************** + * Name: i2ctool_flush + * + * Description: + * Flush buffered I/O to the currently selected stream. + * + ****************************************************************************/ + +void i2ctool_flush(FAR struct i2ctool_s *i2ctool) +{ + fflush(OUTSTREAM(i2ctool)); +} diff --git a/apps/system/i2c/i2ctool.h b/apps/system/i2c/i2ctool.h index 962600f43..5abd731aa 100644 --- a/apps/system/i2c/i2ctool.h +++ b/apps/system/i2c/i2ctool.h @@ -179,12 +179,12 @@ extern const char g_i2cxfrerror[]; ssize_t i2ctool_write(FAR struct i2ctool_s *i2ctool, FAR const void *buffer, size_t nbytes); int i2ctool_printf(FAR struct i2ctool_s *i2ctool, const char *fmt, ...); +void i2ctool_flush(FAR struct i2ctool_s *i2ctool); /* Command handlers */ int cmd_bus(FAR struct i2ctool_s *i2ctool, int argc, FAR char **argv); int cmd_dev(FAR struct i2ctool_s *i2ctool, int argc, FAR char **argv); -int cmd_dump(FAR struct i2ctool_s *i2ctool, int argc, FAR char **argv); int cmd_get(FAR struct i2ctool_s *i2ctool, int argc, FAR char **argv); int cmd_set(FAR struct i2ctool_s *i2ctool, int argc, FAR char **argv); |