From ca16bf1bd294d63f3ebbe982803379fe7a38c89b Mon Sep 17 00:00:00 2001 From: Laurent Deru Date: Thu, 7 Dec 2017 16:20:53 +0100 Subject: [PATCH 1/5] Make select timeout user configurable for native platform --- arch/platform/native/platform.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/arch/platform/native/platform.c b/arch/platform/native/platform.c index 02fad921c..a63ecd396 100644 --- a/arch/platform/native/platform.c +++ b/arch/platform/native/platform.c @@ -76,6 +76,12 @@ #define SELECT_MAX 8 #endif +#ifdef SELECT_CONF_TIMEOUT +#define SELECT_TIMEOUT SELECT_CONF_TIMEOUT +#else +#define SELECT_TIMEOUT 1000 +#endif + static const struct select_callback *select_callback[SELECT_MAX]; static int select_max = 0; @@ -252,7 +258,7 @@ platform_main_loop() retval = process_run(); tv.tv_sec = 0; - tv.tv_usec = retval ? 1 : 1000; + tv.tv_usec = retval ? 1 : SELECT_TIMEOUT; FD_ZERO(&fdr); FD_ZERO(&fdw); From 9fe252d1071c6467969a2f6f766925edf7792621 Mon Sep 17 00:00:00 2001 From: Laurent Deru Date: Mon, 11 Dec 2017 09:21:12 +0100 Subject: [PATCH 2/5] Make stdin select callback configurable --- arch/platform/native/platform.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/arch/platform/native/platform.c b/arch/platform/native/platform.c index a63ecd396..e12641414 100644 --- a/arch/platform/native/platform.c +++ b/arch/platform/native/platform.c @@ -82,6 +82,12 @@ #define SELECT_TIMEOUT 1000 #endif +#ifdef SELECT_CONF_STDIN +#define SELECT_STDIN SELECT_CONF_STDIN +#else +#define SELECT_STDIN 1 +#endif + static const struct select_callback *select_callback[SELECT_MAX]; static int select_max = 0; @@ -122,6 +128,7 @@ select_set_callback(int fd, const struct select_callback *callback) return 0; } /*---------------------------------------------------------------------------*/ +#if SELECT_STDIN static int stdin_set_fd(fd_set *rset, fd_set *wset) { @@ -141,6 +148,7 @@ stdin_handle_fd(fd_set *rset, fd_set *wset) const static struct select_callback stdin_fd = { stdin_set_fd, stdin_handle_fd }; +#endif /* SELECT_STDIN */ /*---------------------------------------------------------------------------*/ static void set_lladdr(void) @@ -246,7 +254,9 @@ platform_init_stage_three() void platform_main_loop() { +#if SELECT_STDIN select_set_callback(STDIN_FILENO, &stdin_fd); +#endif /* SELECT_STDIN */ while(1) { fd_set fdr; fd_set fdw; From d0ca150a384b0f5e0f23b61e78b91b0fe3394bb4 Mon Sep 17 00:00:00 2001 From: Laurent Deru Date: Fri, 22 Dec 2017 11:22:38 +0100 Subject: [PATCH 3/5] Document new native platform defines --- arch/platform/native/platform.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/arch/platform/native/platform.c b/arch/platform/native/platform.c index e12641414..4d1a1421c 100644 --- a/arch/platform/native/platform.c +++ b/arch/platform/native/platform.c @@ -70,23 +70,43 @@ #define LOG_MODULE "Native" #define LOG_LEVEL LOG_LEVEL_MAIN +/*---------------------------------------------------------------------------*/ +/** + * \name Native Platform Configuration + * + * @{ + */ + +/* + * Defines the maximum number of file descriptors monitored by the platform + * main loop. + */ #ifdef SELECT_CONF_MAX #define SELECT_MAX SELECT_CONF_MAX #else #define SELECT_MAX 8 #endif +/* + * Defines the timeout (in msec) of the select operation if no monitored file + * descriptors becomes ready. + */ #ifdef SELECT_CONF_TIMEOUT #define SELECT_TIMEOUT SELECT_CONF_TIMEOUT #else #define SELECT_TIMEOUT 1000 #endif +/* + * Adds the STDIN file descriptor to the list of monitored file descriptors. + */ #ifdef SELECT_CONF_STDIN #define SELECT_STDIN SELECT_CONF_STDIN #else #define SELECT_STDIN 1 #endif +/** @} */ +/*---------------------------------------------------------------------------*/ static const struct select_callback *select_callback[SELECT_MAX]; static int select_max = 0; From acbe590b52cbd840ab730dfcd0208d3d17644a6a Mon Sep 17 00:00:00 2001 From: Laurent Deru Date: Fri, 8 Dec 2017 13:14:22 +0100 Subject: [PATCH 4/5] Don't override UIP_CONF_BYTE_ORDER in contiki-conf.h for native platform --- arch/platform/native/contiki-conf.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/arch/platform/native/contiki-conf.h b/arch/platform/native/contiki-conf.h index c315b8e18..5e45a6053 100644 --- a/arch/platform/native/contiki-conf.h +++ b/arch/platform/native/contiki-conf.h @@ -69,7 +69,9 @@ typedef int32_t s32_t; typedef unsigned short uip_stats_t; +#ifndef UIP_CONF_BYTE_ORDER #define UIP_CONF_BYTE_ORDER UIP_LITTLE_ENDIAN +#endif #if NETSTACK_CONF_WITH_IPV6 From 511497b3b6b90376ebde3f3bf6e5d699f74b50f1 Mon Sep 17 00:00:00 2001 From: Laurent Deru Date: Fri, 8 Dec 2017 13:13:59 +0100 Subject: [PATCH 5/5] Make uip_stats_t int instead of short for native --- arch/platform/native/contiki-conf.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/platform/native/contiki-conf.h b/arch/platform/native/contiki-conf.h index 5e45a6053..3a0329a82 100644 --- a/arch/platform/native/contiki-conf.h +++ b/arch/platform/native/contiki-conf.h @@ -67,7 +67,7 @@ typedef uint16_t u16_t; typedef uint32_t u32_t; typedef int32_t s32_t; -typedef unsigned short uip_stats_t; +typedef unsigned int uip_stats_t; #ifndef UIP_CONF_BYTE_ORDER #define UIP_CONF_BYTE_ORDER UIP_LITTLE_ENDIAN