diff options
author | Jukka Rissanen <jukka.rissanen@linux.intel.com> | 2016-02-02 17:54:54 +0200 |
---|---|---|
committer | Anas Nashif <anas.nashif@intel.com> | 2016-02-05 20:25:32 -0500 |
commit | 9e79aa6f9d6e808c60aa201d0c25fc18057bb5c1 (patch) | |
tree | 3ce12c215ec0683d42f9163c1ed586391356b1d8 /samples | |
parent | 40bef01a5fb5d7bb89d71f36dba7980971d1fd45 (diff) |
net: apps: echo-server refactoring to work in microkernel
The echo-server uses only one code base for both microkernel
and nanokernel.
Change-Id: I7abdf76dc13c31e4f91d0fd9d3b870ffe20ac71b
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Diffstat (limited to 'samples')
-rw-r--r-- | samples/microkernel/apps/net/echo_server/prj.mdef | 4 | ||||
-rw-r--r-- | samples/net/echo_server/src/echo-server.c | 78 |
2 files changed, 44 insertions, 38 deletions
diff --git a/samples/microkernel/apps/net/echo_server/prj.mdef b/samples/microkernel/apps/net/echo_server/prj.mdef index d14a3c083..970ed645d 100644 --- a/samples/microkernel/apps/net/echo_server/prj.mdef +++ b/samples/microkernel/apps/net/echo_server/prj.mdef @@ -1,5 +1,5 @@ -% Application : Network echo server +% Application : echo server % TASK NAME PRIO ENTRY STACK GROUPS % ================================== - TASK TASKA 7 task_receive 2048 [EXE] + TASK MAIN 7 main 2048 [EXE] diff --git a/samples/net/echo_server/src/echo-server.c b/samples/net/echo_server/src/echo-server.c index 88618e5f4..64a6717eb 100644 --- a/samples/net/echo_server/src/echo-server.c +++ b/samples/net/echo_server/src/echo-server.c @@ -16,12 +16,6 @@ * limitations under the License. */ -/* - * Note that both the nano and microkernel images in this example - * have a dummy fiber/task that does nothing. This is just here to - * simulate a multi application scenario. - */ - #if defined(CONFIG_STDOUT_CONSOLE) #include <stdio.h> #define PRINT printf @@ -31,11 +25,16 @@ #endif #include <zephyr.h> +#include <sections.h> #include <net/ip_buf.h> #include <net/net_core.h> #include <net/net_socket.h> +#include <contiki/ipv6/uip-ds6-route.h> +#include <contiki/ip/uip.h> +#include <contiki/ipv6/uip-ds6.h> + #ifndef CONFIG_ETHERNET /* The peer is the client in our case. Just invent a mac * address for it because lower parts of the stack cannot set it @@ -51,9 +50,13 @@ static uint8_t my_mac[] = { 0x0a, 0xbe, 0xef, 0x15, 0xf0, 0x0d }; #ifdef CONFIG_NETWORKING_WITH_IPV6 /* The 2001:db8::/32 is the private address space for documentation RFC 3849 */ #define MY_IPADDR { { { 0x20,0x01,0x0d,0xb8,0,0,0,0,0,0,0,0,0,0,0,0x1 } } } +#define PEER_IPADDR { { { 0x20,0x01,0x0d,0xb8,0,0,0,0,0,0,0,0,0,0,0,0x2 } } } /* admin-local, dynamically allocated multicast address */ #define MCAST_IPADDR { { { 0xff,0x84,0,0,0,0,0,0,0,0,0,0,0,0,0,0x2 } } } + +static const struct in6_addr in6addr_peer = PEER_IPADDR; +static struct in6_addr in6addr_my = MY_IPADDR; #else /* The 192.0.2.0/24 is the private address space for documentation RFC 5737 */ #define MY_IPADDR { { { 192,0,2,2 } } } @@ -77,6 +80,30 @@ static inline void init_server() uip_ipaddr(&addr, 192,0,2,2); uip_sethostaddr(&addr); } +#else /* IPv6 */ + { + uip_ipaddr_t *addr; + +#ifdef CONFIG_NETWORKING_IPV6_NO_ND + /* Set the routes and neighbor cache only if we do not have + * neighbor discovery enabled. This setting should only be + * used if running in qemu and using slip (tun device). + */ + const uip_lladdr_t *lladdr = (const uip_lladdr_t *)&peer_mac; + + addr = (uip_ipaddr_t *)&in6addr_peer; + uip_ds6_defrt_add(addr, 0); + + /* We cannot send to peer unless it is in neighbor + * cache. Neighbor cache should be populated automatically + * but do it here so that test works from first packet. + */ + uip_ds6_nbr_add(addr, lladdr, 0, NBR_REACHABLE); +#endif + + addr = (uip_ipaddr_t *)&in6addr_my; + uip_ds6_addr_add(addr, 0, ADDR_MANUAL); + } #endif } @@ -160,7 +187,6 @@ static inline bool get_context(struct net_context **recv, #ifdef CONFIG_NETWORKING_WITH_IPV6 static const struct in6_addr in6addr_any = IN6ADDR_ANY_INIT; static const struct in6_addr in6addr_mcast = MCAST_IPADDR; - static struct in6_addr in6addr_my = MY_IPADDR; mcast_addr.in6_addr = in6addr_mcast; mcast_addr.family = AF_INET6; @@ -205,34 +231,12 @@ static inline bool get_context(struct net_context **recv, return true; } -#ifdef CONFIG_MICROKERNEL - -void task_receive(void) -{ - static struct net_context *recv; - static struct net_context *mcast_recv; - - net_init(); - - init_server(); - - if (!get_context(&recv, &mcast_recv)) { - PRINT("%s: Cannot get network contexts\n", __func__); - return; - } - - while (1) { - receive_and_reply(__func__, recv, mcast_recv); - } -} - -#else /* CONFIG_NANOKERNEL */ - +#ifdef CONFIG_NANOKERNEL #define STACKSIZE 2000 +char __noinit __stack fiberStack[STACKSIZE]; +#endif -char fiberStack[STACKSIZE]; - -void fiber_receive(void) +void receive(void) { static struct net_context *recv; static struct net_context *mcast_recv; @@ -253,8 +257,10 @@ void main(void) init_server(); +#ifdef CONFIG_MICROKERNEL + receive(); +#else task_fiber_start (&fiberStack[0], STACKSIZE, - (nano_fiber_entry_t)fiber_receive, 0, 0, 7, 0); + (nano_fiber_entry_t)receive, 0, 0, 7, 0); +#endif } - -#endif /* CONFIG_MICROKERNEL || CONFIG_NANOKERNEL */ |