examples/udp: Change build so that both server and client can be on a target, rather than one on the target one on the host PC.
This commit is contained in:
parent
bb95584aed
commit
d1fb6dec09
@ -35,6 +35,37 @@ config EXAMPLES_UDP_STACKSIZE1
|
||||
int "Target1 stack size"
|
||||
default 2048
|
||||
|
||||
config EXAMPLES_UDP_TARGET2
|
||||
bool "Second endpoint is a target"
|
||||
default n
|
||||
---help---
|
||||
By default, the host PC is configured as the second endpoint of the
|
||||
UDP test. If this option is selected, then the second endpoint
|
||||
will be built into the FLASH image as well. This means that you
|
||||
can use two target boards to run the test with not host PC
|
||||
involvement.
|
||||
|
||||
if EXAMPLES_UDP_TARGET2
|
||||
|
||||
config EXAMPLES_UDP_PROGNAME2
|
||||
string "Target2 program name"
|
||||
default "udpserver" if !EXAMPLES_UDP_SERVER2
|
||||
default "udpclient" if EXAMPLES_UDP_SERVER2
|
||||
depends on BUILD_KERNEL
|
||||
---help---
|
||||
This is the name of the Target2 program that will be use when the
|
||||
NSH ELF program is installed.
|
||||
|
||||
config EXAMPLES_UDP_PRIORITY2
|
||||
int "Target2 task priority"
|
||||
default 100
|
||||
|
||||
config EXAMPLES_UDP_STACKSIZE2
|
||||
int "Target2 stack size"
|
||||
default 2048
|
||||
|
||||
endif # EXAMPLES_UDP_TARGET2
|
||||
|
||||
config EXAMPLES_UDP_DEVNAME
|
||||
string "Network device"
|
||||
default "eth0"
|
||||
|
@ -39,29 +39,92 @@ include $(APPDIR)/Make.defs
|
||||
|
||||
# UDP Test
|
||||
|
||||
TARG_ASRCS =
|
||||
|
||||
TARG_CSRCS =
|
||||
ifeq ($(CONFIG_EXAMPLES_UDP_SERVER1),y)
|
||||
TARG_CSRCS += udp_server.c
|
||||
else
|
||||
TARG_CSRCS += udp_client.c
|
||||
endif
|
||||
TARGCMN_CRCS =
|
||||
ifeq ($(CONFIG_EXAMPLES_UDP_NETINIT),y)
|
||||
TARG_CSRCS += target_netinit.c
|
||||
TARGCMN_CRCS += target_netinit.c
|
||||
endif
|
||||
|
||||
TARG_MAINSRC = target1.c
|
||||
# Target 1
|
||||
|
||||
TARG_AOBJS = $(TARG_ASRCS:.S=$(OBJEXT))
|
||||
TARG_COBJS = $(TARG_CSRCS:.c=$(OBJEXT))
|
||||
TARG_MAINOBJ = $(TARG_MAINSRC:.c=$(OBJEXT))
|
||||
TARG1_CRCS =
|
||||
ifeq ($(CONFIG_EXAMPLES_UDP_SERVER1),y)
|
||||
TARG1_CRCS += udp_server.c
|
||||
else
|
||||
TARG1_CRCS += udp_client.c
|
||||
endif
|
||||
TARG1_MAINSRC = target1.c
|
||||
|
||||
TARG_SRCS = $(TARG_ASRCS) $(TARG_CSRCS) $(TARG_MAINSRC)
|
||||
TARG_OBJS = $(TARG_AOBJS) $(TARG_COBJS)
|
||||
TARG1_COBJS = $(TARG1_CRCS:.c=$(OBJEXT))
|
||||
TARG1_MAINOBJ = $(TARG1_MAINSRC:.c=$(OBJEXT))
|
||||
|
||||
ifeq ($(CONFIG_EXAMPLES_UDP_SERVER1),y)
|
||||
CONFIG_EXAMPLES_UDP_PROGNAME1 ?= udpserver
|
||||
APPNAME1 = udpserver
|
||||
else
|
||||
CONFIG_EXAMPLES_UDP_PROGNAME1 ?= udpclient
|
||||
APPNAME1 = udpclient
|
||||
endif
|
||||
CONFIG_EXAMPLES_UDP_PRIORITY1 ?= 100
|
||||
CONFIG_EXAMPLES_UDP_STACKSIZE1 ?= 2048
|
||||
|
||||
PROGNAME1 = $(CONFIG_EXAMPLES_UDP_PROGNAME1)
|
||||
PRIORITY1 = $(CONFIG_EXAMPLES_UDP_PRIORITY1)
|
||||
STACKSIZE1 = $(CONFIG_EXAMPLES_UDP_STACKSIZE1)
|
||||
|
||||
# Target 2
|
||||
|
||||
ifeq ($(CONFIG_EXAMPLES_UDP_TARGET2),y)
|
||||
|
||||
TARG2_CRCS =
|
||||
ifeq ($(CONFIG_EXAMPLES_UDP_SERVER1),y)
|
||||
TARG2_CRCS += udp_client.c
|
||||
else
|
||||
TARG2_CRCS += udp_server.c
|
||||
endif
|
||||
TARG2_MAINSRC = target2.c
|
||||
|
||||
TARG2_COBJS = $(TARG2_CRCS:.c=$(OBJEXT))
|
||||
TARG2_MAINOBJ = $(TARG2_MAINSRC:.c=$(OBJEXT))
|
||||
|
||||
ifeq ($(CONFIG_EXAMPLES_UDP_SERVER1),y)
|
||||
CONFIG_EXAMPLES_UDP_PROGNAME2 ?= udpclient
|
||||
APPNAME2 = udpclient
|
||||
else
|
||||
CONFIG_EXAMPLES_UDP_PROGNAME2 ?= udpserver
|
||||
APPNAME2 = udpserver
|
||||
endif
|
||||
CONFIG_EXAMPLES_UDP_PRIORITY2 ?= 100
|
||||
CONFIG_EXAMPLES_UDP_STACKSIZE2 ?= 2048
|
||||
|
||||
PROGNAME2 = $(CONFIG_EXAMPLES_UDP_PROGNAME2)
|
||||
PRIORITY2 = $(CONFIG_EXAMPLES_UDP_PRIORITY2)
|
||||
STACKSIZE2 = $(CONFIG_EXAMPLES_UDP_STACKSIZE2)
|
||||
|
||||
endif
|
||||
|
||||
TARG_SRCS = $(TARG1_CRCS) $(TARG1_MAINSRC) $(TARG2_CRCS) $(TARG2_MAINSRC)
|
||||
TARG_OBJS = $(TARG1_COBJS) $(TARG2_COBJS)
|
||||
|
||||
ifneq ($(CONFIG_BUILD_KERNEL),y)
|
||||
TARG_OBJS += $(TARG_MAINOBJ)
|
||||
TARG_OBJS += $(TARG1_MAINOBJ) $(TARG2_MAINOBJ)
|
||||
endif
|
||||
|
||||
# Host
|
||||
|
||||
ifneq ($(CONFIG_EXAMPLES_UDP_TARGET2),y)
|
||||
|
||||
HOSTCFLAGS += -DEXAMPLES_UDP_HOST=1
|
||||
|
||||
HOST_SRCS = host.c
|
||||
ifeq ($(CONFIG_EXAMPLES_UDP_SERVER1),y)
|
||||
HOST_SRCS += udp_client.c
|
||||
else
|
||||
HOST_SRCS += udp_server.c
|
||||
endif
|
||||
|
||||
HOST_OBJS = $(HOST_SRCS:.c=.o)
|
||||
HOST_BIN = host$(EXEEXT)
|
||||
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_WINDOWS_NATIVE),y)
|
||||
@ -74,44 +137,19 @@ else
|
||||
endif
|
||||
endif
|
||||
|
||||
HOSTCFLAGS += -DEXAMPLES_UDP_HOST=1
|
||||
|
||||
HOST_SRCS = host.c
|
||||
ifeq ($(CONFIG_EXAMPLES_UDP_SERVER1),y)
|
||||
HOST_SRCS += udp_client.c
|
||||
ifeq ($(CONFIG_EXAMPLES_UDP_TARGET2),y)
|
||||
MAINNAME1 = udp1_main
|
||||
MAINNAME2 = udp2_main
|
||||
else
|
||||
HOST_SRCS += udp_server.c
|
||||
MAINNAME1 = udp_main
|
||||
endif
|
||||
|
||||
HOST_OBJS = $(HOST_SRCS:.c=.o)
|
||||
HOST_BIN = host
|
||||
|
||||
ifeq ($(WINTOOL),y)
|
||||
INSTALL_DIR = "${shell cygpath -w $(BIN_DIR)}"
|
||||
else
|
||||
INSTALL_DIR = $(BIN_DIR)
|
||||
endif
|
||||
|
||||
ifeq ($(EXAMPLES_UDP_SERVER1),y)
|
||||
CONFIG_EXAMPLES_UDP_PROGNAME1 ?= udpserver$(EXEEXT)
|
||||
APPNAME1 = udpserver
|
||||
else
|
||||
CONFIG_EXAMPLES_UDP_PROGNAME1 ?= udpclient$(EXEEXT)
|
||||
APPNAME1 = udpclient
|
||||
endif
|
||||
CONFIG_EXAMPLES_UDP_PRIORITY1 ?= 100
|
||||
CONFIG_EXAMPLES_UDP_STACKSIZE1 ?= 2048
|
||||
|
||||
PROGNAME1 = $(CONFIG_EXAMPLES_UDP_PROGNAME1)
|
||||
PRIORITY1 = $(CONFIG_EXAMPLES_UDP_PRIORITY1)
|
||||
STACKSIZE1 = $(CONFIG_EXAMPLES_UDP_STACKSIZE1)
|
||||
|
||||
ifeq ($(EXAMPLES_UDP_TARGET2),y)
|
||||
MAINNAME1 = udp1_main
|
||||
else
|
||||
MAINNAME1 = udp_main
|
||||
endif
|
||||
|
||||
ROOTDEPPATH = --dep-path .
|
||||
|
||||
# Common build
|
||||
@ -119,35 +157,36 @@ ROOTDEPPATH = --dep-path .
|
||||
VPATH =
|
||||
|
||||
all: .built
|
||||
.PHONY: clean depend distclean
|
||||
.PHONY: clean depend distclean preconfig
|
||||
|
||||
$(TARG_AOBJS): %$(OBJEXT): %.S
|
||||
$(call ASSEMBLE, $<, $@)
|
||||
|
||||
$(TARG_COBJS) $(TARG_MAINOBJ): %$(OBJEXT): %.c
|
||||
$(TARG1_COBJS) $(TARG1_MAINOBJ)$(TARG2_COBJS) $(TARG2_MAINOBJ): %$(OBJEXT): %.c
|
||||
$(call COMPILE, $<, $@)
|
||||
|
||||
$(TARG_BIN): $(TARG_OBJS) $(HOST_BIN)
|
||||
$(call ARCHIVE, $@, $(TARG_OBJS))
|
||||
|
||||
ifneq ($(CONFIG_EXAMPLES_UDP_TARGET2),y)
|
||||
$(HOST_OBJS): %.o: %.c
|
||||
@echo "CC: $<"
|
||||
$(Q) $(HOSTCC) -c $(HOSTCFLAGS) $< -o $@
|
||||
endif
|
||||
|
||||
config.h: $(TOPDIR)/include/nuttx/config.h
|
||||
@echo "CP: $<"
|
||||
$(Q) cp $< $@
|
||||
|
||||
ifneq ($(CONFIG_EXAMPLES_UDP_TARGET2),y)
|
||||
$(HOST_BIN): config.h $(HOST_OBJS)
|
||||
$(Q) $(HOSTCC) $(HOSTLDFLAGS) $(HOST_OBJS) -o $@
|
||||
endif
|
||||
|
||||
.built: config.h $(TARG_BIN) $(HOST_BIN)
|
||||
$(Q) touch .built
|
||||
|
||||
ifeq ($(CONFIG_BUILD_KERNEL),y)
|
||||
$(BIN_DIR)$(DELIM)$(PROGNAME1): $(OBJS) $(TARG_MAINOBJ)
|
||||
$(BIN_DIR)$(DELIM)$(PROGNAME1): $(OBJS) $(TARG1_MAINOBJ)
|
||||
@echo "LD: $(PROGNAME1)"
|
||||
$(Q) $(LD) $(LDELFFLAGS) $(LDLIBPATH) -o $(INSTALL_DIR)$(DELIM)$(PROGNAME1) $(ARCHCRT0OBJ) $(TARG_MAINOBJ) $(LDLIBS)
|
||||
$(Q) $(LD) $(LDELFFLAGS) $(LDLIBPATH) -o $(INSTALL_DIR)$(DELIM)$(PROGNAME1) $(ARCHCRT0OBJ) $(TARG1_MAINOBJ) $(LDLIBS)
|
||||
$(Q) $(NM) -u $(INSTALL_DIR)$(DELIM)$(PROGNAME1)
|
||||
|
||||
install: $(BIN_DIR)$(DELIM)$(PROGNAME1)
|
||||
@ -161,7 +200,15 @@ ifeq ($(CONFIG_NSH_BUILTIN_APPS),y)
|
||||
$(BUILTIN_REGISTRY)$(DELIM)$(APPNAME1)_main.bdat: $(DEPCONFIG) Makefile
|
||||
$(call REGISTER,$(APPNAME1),$(PRIORITY1),$(STACKSIZE1),$(MAINNAME1))
|
||||
|
||||
ifeq ($(CONFIG_EXAMPLES_UDP_TARGET2),y)
|
||||
$(BUILTIN_REGISTRY)$(DELIM)$(APPNAME2)_main.bdat: $(DEPCONFIG) Makefile
|
||||
$(call REGISTER,$(APPNAME2),$(PRIORITY2),$(STACKSIZE2),$(MAINNAME2))
|
||||
|
||||
context: $(BUILTIN_REGISTRY)$(DELIM)$(APPNAME1)_main.bdat \
|
||||
$(BUILTIN_REGISTRY)$(DELIM)$(APPNAME2)_main.bdat
|
||||
else
|
||||
context: $(BUILTIN_REGISTRY)$(DELIM)$(APPNAME1)_main.bdat
|
||||
endif
|
||||
else
|
||||
context:
|
||||
endif
|
||||
@ -174,8 +221,10 @@ depend: .depend
|
||||
|
||||
clean:
|
||||
$(call DELFILE, .built)
|
||||
$(call DELFILE, $(TARG_BIN))
|
||||
#$(call DELFILE, $(TARG_BIN))
|
||||
ifneq ($(CONFIG_EXAMPLES_UDP_TARGET2),y)
|
||||
$(call DELFILE, $(HOST_BIN))
|
||||
endif
|
||||
$(call DELFILE, *.dSYM)
|
||||
$(call DELFILE, config.h)
|
||||
$(call CLEAN)
|
||||
@ -184,7 +233,6 @@ distclean: clean
|
||||
$(call DELFILE, Make.dep)
|
||||
$(call DELFILE, .depend)
|
||||
|
||||
-include Make.dep
|
||||
|
||||
.PHONY: preconfig
|
||||
preconfig:
|
||||
|
||||
-include Make.dep
|
||||
|
72
examples/udp/target2.c
Normal file
72
examples/udp/target2.c
Normal file
@ -0,0 +1,72 @@
|
||||
/****************************************************************************
|
||||
* examples/udp/target2.c
|
||||
*
|
||||
* Copyright (C) 2017 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include "config.h"
|
||||
#include "udp.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* udp2_main
|
||||
****************************************************************************/
|
||||
|
||||
#if defined(CONFIG_BUILD_KERNEL)
|
||||
int main(int argc, FAR char *argv[])
|
||||
#else
|
||||
int udp2_main(int argc, char *argv[])
|
||||
#endif
|
||||
{
|
||||
#ifdef CONFIG_EXAMPLES_UDP_NETINIT
|
||||
/* Initialize the network */
|
||||
|
||||
(void)target_netinit();
|
||||
#endif
|
||||
|
||||
/* Run the server or client, depending upon how target1 was configured */
|
||||
|
||||
#ifdef CONFIG_EXAMPLES_UDP_SERVER1
|
||||
send_client();
|
||||
#else
|
||||
recv_server();
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user