Commit ccc44b31 authored by Matthias Wenzl's avatar Matthias Wenzl
Browse files

added udp functionality, added udp server example and blank example

parent 80ffcf1c
......@@ -124,10 +124,10 @@
</toolChain>
</folderInfo>
<sourceEntries>
<entry excluding="src|blinkit.c|tm4c1294ncpdt.cmd|TM4C1294XL|uip|uip_hw-adapted|lib" flags="VALUE_WORKSPACE_PATH" kind="sourcePath" name=""/>
<entry flags="VALUE_WORKSPACE_PATH" kind="sourcePath" name="TM4C1294XL"/>
<entry flags="VALUE_WORKSPACE_PATH" kind="sourcePath" name="uip"/>
<entry flags="VALUE_WORKSPACE_PATH" kind="sourcePath" name="uip_hw-adapted"/>
<entry excluding="src|blinkit.c|tm4c1294ncpdt.cmd|TM4C1294XL|uip|uip_hw-adapted|lib" flags="VALUE_WORKSPACE_PATH" kind="sourcePath" name=""/>
</sourceEntries>
</configuration>
</storageModule>
......
......@@ -10,24 +10,40 @@
#ifndef CONFIG_H_
#define CONFIG_H_
#define ETH_FRAME_LEN 1526 //worst case ethernet frame
#define ETH_H_LEN 14 // 3.5 words; 2 octets missing
#define IP_H_LEN 20 // 5 words
#define TCP_H_LEN 20 // 5 words
#define UDP_H_LEN 8 // 2 words
#define TCP_PAYLOAD_LEN ETH_FRAME_LEN - ETH_H_LEN - IP_H_LEN - TCP_H_LEN
#define UDP_PAYLOAD_LEN ETH_FRAME_LEN - ETH_H_LEN - IP_H_LEN - UDP_H_LEN
/*!
* \def BUILD_EXAMPLES
*
* Set to 1 to build the examples, set to 0 to clean the project for your implementation
*
*/
#define BUILD_EXAMPLES 0
#define BUILD_EXAMPLES 1
#if !BUILD_EXAMPLES
/* uip_tcp_appstate_t structure is mandatory in EVERY uip tcp enabled project */
typedef struct app_state {
/*arbitrary state information*/
char inputbuffer[80];/*local input buffer*/
} uip_tcp_appstate_t;
char iobuffer[UDP_PAYLOAD_LEN];/*local input buffer - use udp len since it is longer*/
} uip_tcp_appstate_t, uip_udp_appstate_t;
#define UIP_APPCALL your_appcall
#ifndef UIP_APPCALL
#define UIP_APPCALL your_appcall
#endif
#ifndef UIP_UDP_APPCALL
#define UIP_UDP_APPCALL your_appcall
#endif
#endif
......@@ -40,6 +56,12 @@ typedef struct app_state {
*/
#define IS_SERVER 1
/*!
\def HAS_UDP_SERVER
Set to 1 if the example udp echo server shall be integrated
*/
#define HAS_UDP_SERVER 1
/*!
\def HAS_WEBSERVER
Set to 1 if the example webserver shall be integrated
......@@ -62,18 +84,18 @@ typedef struct app_state {
#error "Either IS_CLIENT XOR IS_SERVER must be set"
#endif
#if IS_CLIENT && (HAS_WEBSERVER || HAS_LED_SERVER)
#if IS_CLIENT && (HAS_WEBSERVER || HAS_LED_SERVER || HAS_UDP_SERVER)
#error "A client cannot cannot act as a server."
#endif
#if IS_SERVER && !IS_CLIENT && (!HAS_WEBSERVER && !HAS_LED_SERVER)
#error "A server must be either a led or a webserver"
#if IS_SERVER && !IS_CLIENT && (!HAS_WEBSERVER && !HAS_LED_SERVER && !HAS_UDP_SERVER)
#error "A server must be either a led, web, or a udp server"
#endif
/*!
\def UIP_APPCALL
Defines the network application to call within the uip stack
Defines the network application to call within the uip stack for tcp connections
*/
#ifndef UIP_APPCALL
#if IS_SERVER
......@@ -84,6 +106,16 @@ typedef struct app_state {
#endif /* UIP_APPCALL */
/*!
\def UIP_UDP_APPCALL
Defines the network application to call within the uip stack for udp connections
*/
#ifndef UIP_UDP_APPCALL
#if IS_SERVER
#define UIP_UDP_APPCALL server_appcall
#endif
#endif
/*! \enum led_server_state
* Internal state of the LED server
......@@ -126,7 +158,7 @@ enum led_client_state{CLIENT_WAIT_S,CLIENT_RUNNING_S};
#if IS_CLIENT
typedef struct client_state {
/*arbitrary state information*/
char inputbuffer[80];/*input buffer associated with this connection*/
char inputbuffer[TCP_PAYLOAD_LEN];/*input buffer associated with this connection*/
enum led_client_state state;
} uip_tcp_appstate_t;
#endif
......@@ -139,19 +171,31 @@ typedef struct client_state {
of our application. the memory required for this state is
allocated together with each TCP connection. One application state
for each TCP connection.
The same is true for uip_udp_appstate_t considering UDP connections.
*/
#if IS_SERVER
typedef struct server_state {
/*arbitrary state information*/
char inputbuffer[80];/*input buffer associated with this connection*/
char inputbuffer[UDP_PAYLOAD_LEN];/*input buffer associated with this connection - udp packets are longer*/
#if HAS_LED_SERVER
enum led_server_state state;
#endif
#if HAS_WEBSERVER
httpd_state_t http_state;
#endif
} uip_tcp_appstate_t;
#if HAS_UDP_SERVER
volatile u16_t len;
#endif
} uip_tcp_appstate_t
#if HAS_UDP_SERVER
, uip_udp_appstate_t
#endif
;
#endif /*IS_SERVER*/
#endif /* BUILD_EXAMPLES */
......
......@@ -13,6 +13,7 @@
#if IS_SERVER
#include <udp_server.h>
#include <led_server.h>
#include <httpd.h>
......
/*! \file udp_server.h
\brief UDP server application header
\author Katharina Ewers
*/
#ifndef UDP_SERVER_H_
#define UDP_SERVER_H_
#include <uip-conf.h>/*application configuration*/
#if IS_SERVER && HAS_UDP_SERVER
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <uip.h>
#include <xdc/runtime/System.h>
#define UDP_HDR ((struct uip_udpip_hdr *)&uip_buf[UIP_LLH_LEN]) // UDP header of the last received packet
/**
* Initialize UDP server.
*
*/
void udp_server_init(uint16_t port);
/**
* Periodically check for new UDP packets and timeout.
*
*/
void udp_server(void);
#endif
#endif /* UDP_SERVER_H_ */
......@@ -20,6 +20,10 @@ void server_init(void) {
#if HAS_WEBSERVER
httpd_init();
#endif
#if HAS_UDP_SERVER
udp_server_init(5000);
#endif
}
/*called by uip networking stack - eventually calls this function*/
......@@ -34,6 +38,12 @@ void server_appcall(void) {
if(uip_conn->lport == HTONS(1024))
led_server();
#endif
#if HAS_UDP_SERVER
if(uip_udp_conn->lport == HTONS(5000))
udp_server();
#endif
}
#endif
......
#
# This file was generated based on the configuration script:
# /home/wenzl/git/connected_launchpad_rtos_uip/application.cfg
# /home/wenzl/git/rtos_uip/application.cfg
#
# This makefile may be included in other makefiles that need to build
# the libraries containing the compiled source files generated as
......@@ -14,7 +14,7 @@
#
# The absolute path to the generated source directory (at the time the
# sources were generated) is:
# /home/wenzl/git/connected_launchpad_rtos_uip/src
# /home/wenzl/git/rtos_uip/src
#
GEN_SRC_DIR ?= ../src
......
XOPTS = -I"/home/matthias/ti/xdctools_3_31_01_33_core/packages/" -Dxdc_target_types__=/home/matthias/ti/tirtos_tivac_2_14_00_10/products/bios_6_42_01_20/packages/ti/targets/arm/elf/std.h -Dxdc_target_name__=M4F
XOPTS = -I"/home/wenzl/usr/ti_ccs/xdctools_3_32_00_06_core/packages/" -Dxdc_target_types__=/home/wenzl/usr/ti_ccs/tirtos_tivac_2_16_01_14/products/bios_6_45_02_31/packages/ti/targets/arm/elf/std.h -Dxdc_target_name__=M4F
vpath % /home/matthias/ti/tirtos_tivac_2_14_00_10/products/bios_6_42_01_20/packages/ti/sysbios/
vpath %.c /home/matthias/ti/xdctools_3_31_01_33_core/packages/
vpath % /home/wenzl/usr/ti_ccs/tirtos_tivac_2_16_01_14/products/bios_6_45_02_31/packages/ti/sysbios/
vpath %.c /home/wenzl/usr/ti_ccs/xdctools_3_32_00_06_core/packages/
CCOPTS = --endian=little -mv7M4 --abi=eabi --float_support=fpv4spd16 -q -ms --opt_for_speed=2 --program_level_compile -o3 -g --optimize_with_debug -Dti_sysbios_family_arm_m3_Hwi_enableException__D=TRUE -Dti_sysbios_family_arm_m3_Hwi_disablePriority__D=32U -Dti_sysbios_family_arm_m3_Hwi_numSparseInterrupts__D=0U
CCOPTS = --endian=little -mv7M4 --abi=eabi --float_support=fpv4spd16 -q -ms --opt_for_speed=2 --program_level_compile -o3 -g --optimize_with_debug -Dti_sysbios_knl_Task_minimizeLatency__D=FALSE -Dti_sysbios_knl_Clock_stopCheckNext__D=FALSE -Dti_sysbios_family_arm_m3_Hwi_enableException__D=TRUE -Dti_sysbios_family_arm_m3_Hwi_disablePriority__D=32U -Dti_sysbios_family_arm_m3_Hwi_numSparseInterrupts__D=0U
XDC_ROOT = /home/matthias/ti/xdctools_3_31_01_33_core/packages/
XDC_ROOT = /home/wenzl/usr/ti_ccs/xdctools_3_32_00_06_core/packages/
BIOS_ROOT = /home/matthias/ti/tirtos_tivac_2_14_00_10/products/bios_6_42_01_20/packages/ti/sysbios/
BIOS_ROOT = /home/wenzl/usr/ti_ccs/tirtos_tivac_2_16_01_14/products/bios_6_45_02_31/packages/ti/sysbios/
BIOS_DEFS = -Dti_sysbios_BIOS_swiEnabled__D=TRUE -Dti_sysbios_BIOS_taskEnabled__D=TRUE -Dti_sysbios_BIOS_clockEnabled__D=TRUE -Dti_sysbios_BIOS_runtimeCreatesEnabled__D=TRUE -Dti_sysbios_hal_Hwi_DISABLE_ALL_HOOKS -Dti_sysbios_knl_Swi_DISABLE_ALL_HOOKS -Dti_sysbios_knl_Task_DISABLE_ALL_HOOKS -Dti_sysbios_BIOS_smpEnabled__D=FALSE -Dti_sysbios_Build_useHwiMacros -Dti_sysbios_knl_Swi_numPriorities__D=16 -Dti_sysbios_knl_Task_deleteTerminatedTasks__D=FALSE -Dti_sysbios_knl_Task_numPriorities__D=16 -Dti_sysbios_knl_Task_checkStackFlag__D=TRUE -Dti_sysbios_knl_Clock_TICK_SOURCE=ti_sysbios_knl_Clock_TickSource_TIMER -Dti_sysbios_knl_Clock_TICK_MODE=ti_sysbios_knl_Clock_TickMode_PERIODIC -Dti_sysbios_hal_Core_delegate_getId=ti_sysbios_hal_CoreNull_getId__E -Dti_sysbios_hal_Core_delegate_interruptCore=ti_sysbios_hal_CoreNull_interruptCore__E -Dti_sysbios_hal_Core_delegate_lock=ti_sysbios_hal_CoreNull_lock__E -Dti_sysbios_hal_Core_delegate_unlock=ti_sysbios_hal_CoreNull_unlock__E -Dti_sysbios_hal_Core_numCores__D=1 -Dti_sysbios_hal_CoreNull_numCores__D=1 -Dti_sysbios_utils_Load_taskEnabled__D=TRUE -Dti_sysbios_utils_Load_swiEnabled__D=FALSE -Dti_sysbios_utils_Load_hwiEnabled__D=FALSE -Dti_sysbios_family_arm_m3_Hwi_dispatcherSwiSupport__D=TRUE -Dti_sysbios_family_arm_m3_Hwi_dispatcherTaskSupport__D=TRUE -Dti_sysbios_family_arm_m3_Hwi_dispatcherAutoNestingSupport__D=TRUE -Dti_sysbios_family_arm_m3_Hwi_dispatcherIrpTrackingSupport__D=TRUE -Dti_sysbios_knl_Semaphore_supportsEvents__D=FALSE -Dti_sysbios_knl_Semaphore_supportsPriority__D=TRUE
BIOS_DEFS = -Dti_sysbios_BIOS_swiEnabled__D=TRUE -Dti_sysbios_BIOS_taskEnabled__D=TRUE -Dti_sysbios_BIOS_clockEnabled__D=TRUE -Dti_sysbios_BIOS_runtimeCreatesEnabled__D=TRUE -Dti_sysbios_hal_Hwi_DISABLE_ALL_HOOKS -Dti_sysbios_knl_Swi_DISABLE_ALL_HOOKS -Dti_sysbios_BIOS_smpEnabled__D=FALSE -Dti_sysbios_Build_useHwiMacros -Dti_sysbios_knl_Swi_numPriorities__D=16 -Dti_sysbios_knl_Task_deleteTerminatedTasks__D=FALSE -Dti_sysbios_knl_Task_numPriorities__D=16 -Dti_sysbios_knl_Task_checkStackFlag__D=TRUE -Dti_sysbios_knl_Task_initStackFlag__D=TRUE -Dti_sysbios_knl_Task_DISABLE_ALL_HOOKS -Dti_sysbios_knl_Clock_TICK_SOURCE=ti_sysbios_knl_Clock_TickSource_TIMER -Dti_sysbios_knl_Clock_TICK_MODE=ti_sysbios_knl_Clock_TickMode_PERIODIC -Dti_sysbios_hal_Core_delegate_getId=ti_sysbios_hal_CoreNull_getId__E -Dti_sysbios_hal_Core_delegate_interruptCore=ti_sysbios_hal_CoreNull_interruptCore__E -Dti_sysbios_hal_Core_delegate_lock=ti_sysbios_hal_CoreNull_lock__E -Dti_sysbios_hal_Core_delegate_unlock=ti_sysbios_hal_CoreNull_unlock__E -Dti_sysbios_hal_Core_numCores__D=1 -Dti_sysbios_hal_CoreNull_numCores__D=1 -Dti_sysbios_utils_Load_taskEnabled__D=TRUE -Dti_sysbios_utils_Load_swiEnabled__D=FALSE -Dti_sysbios_utils_Load_hwiEnabled__D=FALSE -Dti_sysbios_family_arm_m3_Hwi_dispatcherSwiSupport__D=TRUE -Dti_sysbios_family_arm_m3_Hwi_dispatcherTaskSupport__D=TRUE -Dti_sysbios_family_arm_m3_Hwi_dispatcherAutoNestingSupport__D=TRUE -Dti_sysbios_family_arm_m3_Hwi_dispatcherIrpTrackingSupport__D=TRUE -Dti_sysbios_knl_Semaphore_supportsEvents__D=FALSE -Dti_sysbios_knl_Semaphore_supportsPriority__D=TRUE -Dxdc_runtime_Assert_DISABLE_ALL -Dxdc_runtime_Log_DISABLE_ALL
BIOS_INC = -I"/home/matthias/ti/tirtos_tivac_2_14_00_10/products/bios_6_42_01_20/packages/"
BIOS_INC = -I"/home/wenzl/usr/ti_ccs/tirtos_tivac_2_16_01_14/products/bios_6_45_02_31/packages/"
TARGET_INC = -I"/home/matthias/ti/tirtos_tivac_2_14_00_10/products/bios_6_42_01_20/packages/"
TARGET_INC = -I"/home/wenzl/usr/ti_ccs/tirtos_tivac_2_16_01_14/products/bios_6_45_02_31/packages/"
INCS = $(BIOS_INC) $(TARGET_INC)
CC = /home/matthias/ti/ccsv6/tools/compiler/ti-cgt-arm_5.2.2/bin/armcl -c $(CCOPTS) -I /home/matthias/ti/ccsv6/tools/compiler/ti-cgt-arm_5.2.2/include
ASM = /home/matthias/ti/ccsv6/tools/compiler/ti-cgt-arm_5.2.2/bin/armcl -c $(CCOPTS) -I /home/matthias/ti/ccsv6/tools/compiler/ti-cgt-arm_5.2.2/include
AR = /home/matthias/ti/ccsv6/tools/compiler/ti-cgt-arm_5.2.2/bin/armar rq
CC = /home/wenzl/usr/ti_ccs/ccsv6/tools/compiler/ti-cgt-arm_15.12.1.LTS/bin/armcl -c $(CCOPTS) -I /home/wenzl/usr/ti_ccs/ccsv6/tools/compiler/ti-cgt-arm_15.12.1.LTS/include
ASM = /home/wenzl/usr/ti_ccs/ccsv6/tools/compiler/ti-cgt-arm_15.12.1.LTS/bin/armcl -c $(CCOPTS) -I /home/wenzl/usr/ti_ccs/ccsv6/tools/compiler/ti-cgt-arm_15.12.1.LTS/include
AR = /home/wenzl/usr/ti_ccs/ccsv6/tools/compiler/ti-cgt-arm_15.12.1.LTS/bin/armar rq
DEL = rm -f
CP = cp -f
......@@ -87,9 +87,5 @@ sysbios.aem4f: BIOS.obj m3_Hwi_asm.obj m3_Hwi_asm_switch.obj m3_IntrinsicsSuppor
clean:
@-$(call RM, sysbios.aem4f)
@-$(call RM, BIOS.obj)
@-$(call RM, m3_Hwi_asm.obj)
@-$(call RM, m3_Hwi_asm_switch.obj)
@-$(call RM, m3_IntrinsicsSupport_asm.obj)
@-$(call RM, m3_TaskSupport_asm.obj)
@$(DEL) ../makefile.libs
@-$(call RM, *)
/*! \file udp_server.h
\brief UDP server application source file
\author ewers
*/
#include <uip-conf.h>/*application configuration*/
#if IS_SERVER && HAS_UDP_SERVER
#include <udp_server.h>
void udp_server_init(uint16_t port) {
struct server_state *s = NULL;
uint16_t *len = NULL;
uip_udp_conn = uip_udp_new(NULL, HTONS(0));
s = &(uip_udp_conn->appstate);
len = (uint16_t*)&(s->len);
*len = 0;
if(uip_udp_conn != NULL) {
uip_udp_bind(uip_udp_conn, HTONS(port));
}
}
void udp_server(void) {
struct server_state *s = &(uip_udp_conn->appstate);
uint16_t *len = (uint16_t*)&(s->len); // Length of received data
uint16_t outlen = 0; // Length of outgoing data
char *buf = s->inputbuffer; // UDP server's buffer
uip_ipaddr_t *ipaddr = (uip_ipaddr_t*)&(uip_udp_conn->ripaddr);
if(uip_poll()) {
if(uip_arp_lookup(*ipaddr) == NULL) {
/*skip until lookup was successfull*/
}
else {
outlen = *len;
if (outlen > 0) {
uip_udp_send(outlen);
}
}
}
if(uip_newdata()) {
/* Copy received data into the local buffer */
*len = uip_datalen();
memcpy(buf, uip_appdata, *len);
/* Copy IP address and port number from the UDP header of the received packet */
uip_ipaddr_copy(&uip_udp_conn->ripaddr, &UDP_HDR->srcipaddr); // IP address
uip_udp_conn->rport = UDP_HDR->srcport; // UDP port
outlen = *len;
if (outlen > 0) {
uip_udp_send(outlen);
}
}
}
#endif
......@@ -53,7 +53,7 @@ typedef unsigned short uip_stats_t;
//
// UDP support on or off
//
#define UIP_CONF_UDP 0
#define UIP_CONF_UDP 1
//
// UDP checksums on or off
......
......@@ -153,6 +153,36 @@ uip_arp_timer(void)
}
}
/*-----------------------------------------------------------------------------------*/
struct arp_entry *
uip_arp_lookup(u16_t *ipaddr)
{
register struct arp_entry *tabptr;
/* Walk through the ARP mapping table and try to find an entry to
update. If none is found, the IP -> MAC address mapping is
inserted in the ARP table. */
for(i = 0; i < UIP_ARPTAB_SIZE; ++i) {
tabptr = &arp_table[i];
/* Only check those entries that are actually in use. */
if(tabptr->ipaddr[0] != 0 &&
tabptr->ipaddr[1] != 0) {
/* Check if the source IP address of the incoming packet matches
the IP address in this ARP table entry. */
if(ipaddr[0] == tabptr->ipaddr[0] &&
ipaddr[1] == tabptr->ipaddr[1]) {
return tabptr;
}
}
}
return NULL;
}
/*-----------------------------------------------------------------------------------*/
static void
uip_arp_update(u16_t *ipaddr, struct uip_eth_addr *ethaddr)
......
......@@ -107,6 +107,11 @@ void uip_arp_out(void);
is responsible for flushing old entries in the ARP table. */
void uip_arp_timer(void);
/* The uip_arp_lookup(u16_t *ipaddr) function searches the ARP table to
* see if an entry for ipaddr already exists. It returns either the ARP
* entry for the given IP address or NULL, if no entry was found. */
struct arp_entry *uip_arp_lookup(u16_t *ipaddr);
/** @} */
/**
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment