summaryrefslogtreecommitdiff
path: root/apps/examples/i2schar/i2schar_main.c
diff options
context:
space:
mode:
authorGregory Nutt <gnutt@nuttx.org>2013-11-12 10:21:16 -0600
committerGregory Nutt <gnutt@nuttx.org>2013-11-12 10:21:16 -0600
commitb406d3ac1676184453a6e1fcb669b2c352ce06f9 (patch)
treee5bf59f83c957e4488609f240d1a1c903e8e47b3 /apps/examples/i2schar/i2schar_main.c
parent94d06bff175b59ff5fd25a46d0cf6bc5a7b3bacc (diff)
downloadnuttx-b406d3ac1676184453a6e1fcb669b2c352ce06f9.tar.gz
nuttx-b406d3ac1676184453a6e1fcb669b2c352ce06f9.tar.bz2
nuttx-b406d3ac1676184453a6e1fcb669b2c352ce06f9.zip
apps/examples/i2schar: Raise priority of the receiver thread. In a loopback test, catching the returned data is higher priority than sending new data
Diffstat (limited to 'apps/examples/i2schar/i2schar_main.c')
-rw-r--r--apps/examples/i2schar/i2schar_main.c59
1 files changed, 41 insertions, 18 deletions
diff --git a/apps/examples/i2schar/i2schar_main.c b/apps/examples/i2schar/i2schar_main.c
index 524a27550..01ca7fd15 100644
--- a/apps/examples/i2schar/i2schar_main.c
+++ b/apps/examples/i2schar/i2schar_main.c
@@ -246,6 +246,9 @@ int i2schar_main(int argc, char *argv[])
#ifdef CONFIG_EXAMPLES_I2SCHAR_RX
pthread_t receiver;
#endif
+#if defined(CONFIG_EXAMPLES_I2SCHAR_RX) & defined(CONFIG_EXAMPLES_I2SCHAR_TX)
+ struct sched_param param;
+#endif
int ret;
/* Check if we have initialized */
@@ -286,46 +289,66 @@ int i2schar_main(int argc, char *argv[])
#endif
sched_lock();
+#ifdef CONFIG_EXAMPLES_I2SCHAR_RX
+ /* Start the receiver thread */
+
+ message("i2schar_main: Start receiver thread\n");
+ pthread_attr_init(&attr);
+
#ifdef CONFIG_EXAMPLES_I2SCHAR_TX
- /* Start the transmitter thread */
+ /* Bump the receiver priority from the default so that it will be above
+ * the priority of transmitter. This is important if a loopback test is
+ * being performed; it improves the changes that a receiving audio buffer
+ * is in place for each transmission.
+ */
+
+ (void)pthread_attr_getschedparam(&attr, &param);
+ param.sched_priority++;
+ (void)pthread_attr_setschedparam(&attr, &param);
+#endif
- message("i2schar_main: Start transmitter thread\n");
+ /* Set the receiver stack size */
- pthread_attr_init(&attr);
- (void)pthread_attr_setstacksize(&attr, CONFIG_EXAMPLES_I2SCHAR_TXSTACKSIZE);
+ (void)pthread_attr_setstacksize(&attr, CONFIG_EXAMPLES_I2SCHAR_RXSTACKSIZE);
- ret = pthread_create(&transmitter, &attr, i2schar_transmitter, NULL);
+ /* Start the receiver */
+
+ ret = pthread_create(&receiver, &attr, i2schar_receiver, NULL);
if (ret != OK)
{
sched_unlock();
- message("i2schar_main: ERROR: failed to Start transmitter thread: %d\n", ret);
+ message("i2schar_main: ERROR: failed to Start receiver thread: %d\n", ret);
return EXIT_FAILURE;
}
- pthread_setname_np(transmitter, "transmitter");
+ pthread_setname_np(receiver, "receiver");
#endif
-#ifdef CONFIG_EXAMPLES_I2SCHAR_RX
- /* Start the receiver thread */
-
- message("i2schar_main: Start receiver thread\n");
+#ifdef CONFIG_EXAMPLES_I2SCHAR_TX
+ /* Start the transmitter thread */
+ message("i2schar_main: Start transmitter thread\n");
pthread_attr_init(&attr);
- (void)pthread_attr_setstacksize(&attr, CONFIG_EXAMPLES_I2SCHAR_RXSTACKSIZE);
- ret = pthread_create(&receiver, &attr, i2schar_receiver, NULL);
+ /* Set the transmitter stack size */
+
+ (void)pthread_attr_setstacksize(&attr, CONFIG_EXAMPLES_I2SCHAR_TXSTACKSIZE);
+
+ /* Start the transmitter */
+
+ ret = pthread_create(&transmitter, &attr, i2schar_transmitter, NULL);
if (ret != OK)
{
sched_unlock();
- message("i2schar_main: ERROR: failed to Start receiver thread: %d\n", ret);
-#ifdef CONFIG_EXAMPLES_I2SCHAR_TX
- message("i2schar_main: Waiting for the transmitter thread\n");
- (void)pthread_join(transmitter, &result);
+ message("i2schar_main: ERROR: failed to Start transmitter thread: %d\n", ret);
+#ifdef CONFIG_EXAMPLES_I2SCHAR_RX
+ message("i2schar_main: Waiting for the receiver thread\n");
+ (void)pthread_join(receiver, &result);
#endif
return EXIT_FAILURE;
}
- pthread_setname_np(transmitter, "receiver");
+ pthread_setname_np(transmitter, "transmitter");
#endif
sched_unlock();