summaryrefslogtreecommitdiff
path: root/apps/nshlib/nsh_netinit.c
diff options
context:
space:
mode:
authorGregory Nutt <gnutt@nuttx.org>2014-08-06 11:59:41 -0600
committerGregory Nutt <gnutt@nuttx.org>2014-08-06 11:59:41 -0600
commit35c00972da41e12f4fb0590f4b4d45be91a31bfa (patch)
treec108e3dc1ce6c65c0111cd5a5adbff2521728ac9 /apps/nshlib/nsh_netinit.c
parent0b7ec28d62b4499189c474ee5cf29ec1212ff57a (diff)
downloadpx4-nuttx-35c00972da41e12f4fb0590f4b4d45be91a31bfa.tar.gz
px4-nuttx-35c00972da41e12f4fb0590f4b4d45be91a31bfa.tar.bz2
px4-nuttx-35c00972da41e12f4fb0590f4b4d45be91a31bfa.zip
NSH networking: There is now a configuration option that will bring up the network on an separate thread. Since the network bring-up is asynchronous, there are not serial console start-up delays due to the network negotiation time.
Diffstat (limited to 'apps/nshlib/nsh_netinit.c')
-rw-r--r--apps/nshlib/nsh_netinit.c69
1 files changed, 63 insertions, 6 deletions
diff --git a/apps/nshlib/nsh_netinit.c b/apps/nshlib/nsh_netinit.c
index c4e83d7e6..187a0bb2f 100644
--- a/apps/nshlib/nsh_netinit.c
+++ b/apps/nshlib/nsh_netinit.c
@@ -42,6 +42,7 @@
#include <nuttx/config.h>
+#include <pthread.h>
#include <debug.h>
#include <net/if.h>
@@ -95,18 +96,14 @@
****************************************************************************/
/****************************************************************************
- * Public Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Name: nsh_netinit
+ * Name: nsh_netinit_thread
*
* Description:
* Initialize the network per the selected NuttX configuration
*
****************************************************************************/
-int nsh_netinit(void)
+pthread_addr_t nsh_netinit_thread(pthread_addr_t arg)
{
struct in_addr addr;
#if defined(CONFIG_NSH_DHCPC)
@@ -116,6 +113,8 @@ int nsh_netinit(void)
uint8_t mac[IFHWADDRLEN];
#endif
+ nvdbg("Entry\n");
+
/* Many embedded network interfaces must have a software assigned MAC */
#if defined(CONFIG_NSH_NOMAC) && !defined(CONFIG_NET_SLIP)
@@ -207,7 +206,65 @@ int nsh_netinit(void)
}
#endif
+ nvdbg("Exit\n");
return OK;
}
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: nsh_netinit
+ *
+ * Description:
+ * Initialize the network per the selected NuttX configuration
+ *
+ ****************************************************************************/
+
+int nsh_netinit(void)
+{
+#ifdef CONFIG_NSH_NETINIT_THREAD
+ struct sched_param sparam;
+ pthread_attr_t attr;
+ pthread_t tid;
+ void *value;
+ int ret;
+
+ /* Start the network initialization thread to perform the network bring-up
+ * asynchronously.
+ */
+
+ pthread_attr_init(&attr);
+ sparam.sched_priority = CONFIG_NSH_NETINIT_THREAD_PRIORITY;
+ (void)pthread_attr_setschedparam(&attr, &sparam);
+ (void)pthread_attr_setstacksize(&attr, CONFIG_NSH_NETINIT_THREAD_STACKSIZE);
+
+ nvdbg("Starting netinit thread\n");
+ ret = pthread_create(&tid, &attr, nsh_netinit_thread, NULL);
+ if (ret != OK)
+ {
+ ndbg("ERROR: Failed to create netinit thread: %d\n", ret);
+ (void)nsh_netinit_thread(NULL);
+ }
+ else
+ {
+ /* Detach the thread because we will not be joining to it */
+
+ (void)pthread_detach(tid);
+
+ /* Name the thread */
+
+ pthread_setname_np(tid, "netinit");
+ }
+
+ return OK;
+
+#else
+ /* Perform network initialization sequentially */
+
+ (void)nsh_netinit_thread(NULL);
+#endif
+}
+
#endif /* CONFIG_NET */