From ad57b3de4d2d50556b5333e2d8f082323fdd1526 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 29 Apr 2019 11:49:15 -0600 Subject: [PATCH] apps/graphics/twm4nx: Add options to initialize the system via boardctl() and to bring up the network using the new apps/netutils/netinit. This latter is only necessary because VNC is being used to provide graphics. --- graphics/twm4nx/Kconfig | 20 +++++++++++++++ graphics/twm4nx/src/ctwm4nx.cxx | 43 +++++++++++++++++++++++++-------- include/netutils/netinit.h | 13 ++++++++++ netutils/netinit/Kconfig | 1 + 4 files changed, 67 insertions(+), 10 deletions(-) diff --git a/graphics/twm4nx/Kconfig b/graphics/twm4nx/Kconfig index 34a915f60..cf8487dba 100644 --- a/graphics/twm4nx/Kconfig +++ b/graphics/twm4nx/Kconfig @@ -41,4 +41,24 @@ config TWM4NX_REVMINOR string "Twm4Nx minor version number" default "0" +config TWM4NX_ARCHINIT + bool "Have architecture-specific initialization" + default n + select LIB_BOARDCTL + depends on !NSH_ARCHINIT + ---help--- + Set if your board provides architecture specific initialization + via the board-interface function boardctl(). The boardctl() + function will be called early in Twm4Nx initialization to allow + board logic to do such things as configure MMC/SD slots. + +config TWM4NX_NETINIT + bool "Network initialization" + default y + depends on NET + select NETUTILS_NETINIT + depends on !NSH_ARCHINIT + ---help--- + This option enables/disables all network initialization in Twm4Nx. + endif # GRAPHICS_TWM4NX diff --git a/graphics/twm4nx/src/ctwm4nx.cxx b/graphics/twm4nx/src/ctwm4nx.cxx index 8fe21ceab..0398e2567 100644 --- a/graphics/twm4nx/src/ctwm4nx.cxx +++ b/graphics/twm4nx/src/ctwm4nx.cxx @@ -64,6 +64,7 @@ #include #include "platform/cxxinitialize.h" +#include "netutils/netinit.h" #include "graphics/twm4nx/twm4nx_config.hxx" #include "graphics/twm4nx/ctwm4nx.hxx" @@ -182,16 +183,6 @@ bool CTwm4Nx::run(void) up_cxxinitialize(); #endif -#if defined(CONFIG_LIB_BOARDCTL) && !defined(CONFIG_BOARD_LATE_INITIALIZE) - // Should we perform board-specific initialization? There are two ways - // that board initialization can occur: 1) automatically via - // board_late_initialize() during bootup if CONFIG_BOARD_LATE_INITIALIZE, or - // 2) here via a call to boardctl() if the interface is enabled - // (CONFIG_LIB_BOARDCTL=y). - - (void)boardctl(BOARDIOC_INIT, 0); -#endif - // Connect to the NX server if (!connect()) @@ -601,6 +592,38 @@ int twm4nx_main(int argc, char *argv[]) return EXIT_FAILURE; } + int ret; + +#if defined(CONFIG_TWM4NX_ARCHINIT) && defined(CONFIG_LIB_BOARDCTL) && \ + !defined(CONFIG_BOARD_LATE_INITIALIZE) + // Should we perform board-specific initialization? There are two ways + // that board initialization can occur: 1) automatically via + // board_late_initialize() during bootup if CONFIG_BOARD_LATE_INITIALIZE, or + // 2) here via a call to boardctl() if the interface is enabled + // (CONFIG_LIB_BOARDCTL=y). board_early_initialize() is also possibility, + // although less likely. + + ret = boardctl(BOARDIOC_INIT, 0); + if (ret < 0) + { + gerr("ERROR: boardctl(BOARDIOC_INIT) failed: %d\n", errno); + return EXIT_FAILURE; + } +#endif + +#ifdef CONFIG_TWM4NX_NETINIT + /* Bring up the network */ + + ret = netinit_bringup(); + if (ret < 0) + { + gerr("ERROR: netinit_bringup() failed: %d\n", ret); + return EXIT_FAILURE; + } +#endif + + UNUSED(ret); + /* Create an instance of CTwm4Nx and and run it */ FAR CTwm4Nx *twm4nx = new CTwm4Nx(display); diff --git a/include/netutils/netinit.h b/include/netutils/netinit.h index 072ccd26a..cb9a4ce79 100644 --- a/include/netutils/netinit.h +++ b/include/netutils/netinit.h @@ -47,6 +47,7 @@ /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ + /* Configuration ************************************************************/ /* Networking support. Make sure that all non-boolean configuration @@ -99,6 +100,14 @@ * Public Function Prototypes ****************************************************************************/ +#ifdef __cplusplus +#define EXTERN extern "C" +extern "C" +{ +#else +#define EXTERN extern +#endif + /**************************************************************************** * Name: netinit_bringup * @@ -117,5 +126,9 @@ int netinit_bringup(void); int netinit_associate(FAR const char *ifname); #endif +#undef EXTERN +#ifdef __cplusplus +} +#endif #endif /* CONFIG_NETUTILS_NETINIT */ #endif /* __APPS_INCLUDE_NETUTILS_NETINIT_H */ diff --git a/netutils/netinit/Kconfig b/netutils/netinit/Kconfig index f67a99887..42318cf5b 100644 --- a/netutils/netinit/Kconfig +++ b/netutils/netinit/Kconfig @@ -8,6 +8,7 @@ menuconfig NETUTILS_NETINIT bool "Network initialization" default n depends on NET + select NETUTILS_NETLIB ---help--- This option enables/disables all support for common network initialization.