From b406d3ac1676184453a6e1fcb669b2c352ce06f9 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 12 Nov 2013 10:21:16 -0600 Subject: apps/examples/i2schar: Raise priority of the receiver thread. In a loopback test, catching the returned data is higher priority than sending new data --- apps/examples/i2schar/i2schar_main.c | 59 +++++++++++++++++++++++++----------- 1 file changed, 41 insertions(+), 18 deletions(-) (limited to 'apps/examples/i2schar/i2schar_main.c') 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 @@ -245,6 +245,9 @@ int i2schar_main(int argc, char *argv[]) #endif #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; @@ -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, ¶m); + param.sched_priority++; + (void)pthread_attr_setschedparam(&attr, ¶m); +#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(); -- cgit v1.2.3