├── .gitignore
├── CHANGELOG.rst
├── LICENSE.txt
├── Makefile
├── README.rst
├── app_simple_webserver
├── .cproject
├── .project
├── .xproject
├── Makefile
├── README.rst
├── doc_quickstart
│ ├── Makefile
│ ├── images
│ │ ├── hardware_setup-wide.jpg
│ │ └── hardware_setup.jpg
│ └── quickstart.rst
└── src
│ ├── httpd.c
│ ├── httpd.h
│ ├── main.xc
│ ├── xhttpd.h
│ └── xhttpd.xc
├── app_udp_demo
├── .cproject
├── .project
├── .xproject
├── Makefile
├── README.rst
├── src
│ └── main.xc
└── test_udp.py
├── app_webserver_separate_mac
├── .cproject
├── .project
├── .xproject
├── Makefile
└── src
│ ├── httpd.c
│ ├── httpd.h
│ ├── main.xc
│ ├── xhttpd.h
│ ├── xhttpd.xc
│ └── xtcp_conf.h
├── doc
└── slicekit_quickstart
│ ├── Makefile
│ ├── images
│ └── slicekit_eth_setup.jpg
│ └── quickstart.rst
├── experimental
├── app_buffered_protocol_demo
│ ├── .cproject
│ ├── .project
│ ├── .xproject
│ ├── Makefile
│ ├── src
│ │ ├── demo_protocol.c
│ │ ├── demo_protocol.h
│ │ ├── demo_protocol_transport.c
│ │ ├── demo_protocold.h
│ │ ├── demo_protocold.xc
│ │ ├── main.xc
│ │ └── xtcp_client_conf.h
│ └── test
│ │ └── test_demo_protocol.py
├── app_buffered_protocol_demo_2
│ ├── .cproject
│ ├── .project
│ ├── .xproject
│ ├── Makefile
│ └── src
│ │ ├── demo_protocol.c
│ │ ├── demo_protocol.h
│ │ ├── demo_protocold.xc
│ │ ├── main.xc
│ │ └── xtcp_client_conf.h
├── app_pip_bootloader
│ ├── .cproject
│ ├── .project
│ ├── .xproject
│ ├── Makefile
│ └── src
│ │ ├── XP-ETHERNET-TEST.xn
│ │ ├── main.xc
│ │ └── pip_conf.h
├── app_pip_test
│ ├── .cproject
│ ├── .project
│ ├── .xproject
│ ├── Makefile
│ └── src
│ │ ├── XP-DSC-BLDC.xn
│ │ ├── XP-MC-CTRL-L2.xn
│ │ ├── main.xc
│ │ └── pip_conf.h
├── doc_pip
│ ├── pip-api.rst
│ ├── pip-developer.rst
│ └── pip.rst
└── module_pip
│ ├── .cproject
│ ├── .makefile
│ ├── .project
│ ├── .xproject
│ ├── module_build_info
│ └── src
│ ├── arp.h
│ ├── arp.xc
│ ├── c.c
│ ├── checksum.h
│ ├── checksum.xc
│ ├── config.h
│ ├── dhcp.h
│ ├── dhcp.xc
│ ├── ethernet.xc
│ ├── icmp.h
│ ├── icmp.xc
│ ├── igmp.h
│ ├── ipv4.h
│ ├── ipv4.xc
│ ├── linklocal.h
│ ├── linklocal.xc
│ ├── pipServer.h
│ ├── pip_ethernet.h
│ ├── rx.h
│ ├── rx.xc
│ ├── tcp.h
│ ├── tcp.xc
│ ├── tcpApplication.h
│ ├── tftp.h
│ ├── tftp.xc
│ ├── timer.h
│ ├── timer.xc
│ ├── toplevel.xc
│ ├── tx.h
│ ├── tx.xc
│ ├── udp.h
│ ├── udp.xc
│ └── udpApplication.h
├── module_tftp
├── .cproject
├── .makefile
├── .project
├── .xproject
├── README.rst
├── module_build_info
└── src
│ ├── tftp.h
│ ├── tftp.xc
│ ├── tftp_app.h
│ ├── tftp_conf.h
│ └── tftp_support.c
├── module_xtcp
├── .cproject
├── .makefile
├── .project
├── .xproject
├── README.rst
├── doc
│ ├── Makefile
│ ├── api.rst
│ ├── hw.rst
│ ├── images
│ │ ├── events-crop.pdf
│ │ ├── events-crop.png
│ │ ├── events.odg
│ │ ├── events.pdf
│ │ ├── xtcp_arch-crop.pdf
│ │ ├── xtcp_arch-crop.png
│ │ ├── xtcp_arch.odg
│ │ └── xtcp_arch.pdf
│ ├── index.rst
│ ├── overview.rst
│ ├── programming.rst
│ └── system.rst
├── module_build_info
├── module_xtcp.metainfo
├── src
│ ├── ethernet_xtcp_server.h
│ ├── ethernet_xtcp_server.xc
│ ├── standalone_xtcp_server.h
│ ├── xtcp.h
│ ├── xtcp_blocking_client.h
│ ├── xtcp_blocking_client.xc
│ ├── xtcp_buffered_client.c
│ ├── xtcp_buffered_client.h
│ ├── xtcp_bufinfo.h
│ ├── xtcp_client.h
│ ├── xtcp_client.xc
│ ├── xtcp_cmd.h
│ ├── xtcp_conf_derived.h
│ ├── xtcp_mac_filter.h
│ ├── xtcp_mac_filter.xc
│ ├── xtcp_server.h
│ ├── xtcp_server.xc
│ ├── xtcp_server_impl.h
│ ├── xtcp_uip
│ │ ├── README
│ │ ├── autoip
│ │ │ ├── autoip.c
│ │ │ └── autoip.h
│ │ ├── clock-arch.h
│ │ ├── clock-arch.xc
│ │ ├── clock.h
│ │ ├── dhcpc
│ │ │ ├── Makefile.dhcpc
│ │ │ ├── dhcpc.c
│ │ │ └── dhcpc.h
│ │ ├── igmp
│ │ │ ├── igmp.c
│ │ │ └── igmp.h
│ │ ├── lc-addrlabels.h
│ │ ├── lc-switch.h
│ │ ├── lc.h
│ │ ├── psock.c
│ │ ├── psock.h
│ │ ├── pt.h
│ │ ├── timer.c
│ │ ├── timer.h
│ │ ├── uip-conf.h
│ │ ├── uip-fw.c
│ │ ├── uip-fw.h
│ │ ├── uip-neighbor.c
│ │ ├── uip-neighbor.h
│ │ ├── uip-split.c
│ │ ├── uip-split.h
│ │ ├── uip.c
│ │ ├── uip.h
│ │ ├── uip_arch.h
│ │ ├── uip_arp.c
│ │ ├── uip_arp.h
│ │ ├── uip_server.c
│ │ ├── uip_server.h
│ │ ├── uip_server_support.c
│ │ ├── uip_single_server.h
│ │ ├── uip_single_server.xc
│ │ ├── uip_xtcp.c
│ │ ├── uip_xtcp.h
│ │ ├── uip_xtcpd.h
│ │ ├── uiplib.c
│ │ ├── uiplib.h
│ │ ├── uipopt.h
│ │ ├── xcoredev.h
│ │ ├── xcoredev.xc
│ │ └── xtcp_server_conf.h
│ └── xtcp_uip6
│ │ ├── README
│ │ ├── contiki
│ │ ├── contiki-net.h
│ │ ├── contiki.h
│ │ ├── lib
│ │ │ ├── list.c
│ │ │ ├── list.h
│ │ │ ├── memb.c
│ │ │ ├── memb.h
│ │ │ ├── random.c
│ │ │ └── random.h
│ │ ├── net
│ │ │ ├── nbr-table.c
│ │ │ ├── nbr-table.h
│ │ │ ├── packetbuf.c
│ │ │ ├── packetbuf.h
│ │ │ ├── packetbuf_d.h
│ │ │ ├── packetubf_d.c
│ │ │ ├── psock.c
│ │ │ ├── psock.h
│ │ │ ├── rime
│ │ │ │ ├── rimeaddr.c
│ │ │ │ └── rimeaddr.h
│ │ │ ├── rpl
│ │ │ │ ├── rpl-conf.h
│ │ │ │ ├── rpl-dag.c
│ │ │ │ ├── rpl-ext-header.c
│ │ │ │ ├── rpl-icmp6.c
│ │ │ │ ├── rpl-mrhof.c
│ │ │ │ ├── rpl-of0.c
│ │ │ │ ├── rpl-private.h
│ │ │ │ ├── rpl-timers.c
│ │ │ │ ├── rpl.c
│ │ │ │ └── rpl.h
│ │ │ ├── tcpip.c
│ │ │ ├── tcpip.h
│ │ │ ├── uip-debug.c
│ │ │ ├── uip-debug.h
│ │ │ ├── uip-ds6-nbr.c
│ │ │ ├── uip-ds6-nbr.h
│ │ │ ├── uip-ds6-route.c
│ │ │ ├── uip-ds6-route.h
│ │ │ ├── uip-ds6.c
│ │ │ ├── uip-ds6.h
│ │ │ ├── uip-icmp6.c
│ │ │ ├── uip-icmp6.h
│ │ │ ├── uip-nd6.c
│ │ │ ├── uip-nd6.h
│ │ │ ├── uip-packetqueue.c
│ │ │ ├── uip-packetqueue.h
│ │ │ ├── uip-split.c
│ │ │ ├── uip-split.h
│ │ │ ├── uip.c_
│ │ │ ├── uip.h
│ │ │ ├── uip6.c
│ │ │ ├── uip_arp.c
│ │ │ ├── uip_arp.h
│ │ │ └── uipopt.h
│ │ └── sys
│ │ │ ├── arg.c
│ │ │ ├── arg.h
│ │ │ ├── cc.h
│ │ │ ├── clock.h
│ │ │ ├── ctimer.c
│ │ │ ├── ctimer.h
│ │ │ ├── etimer.c
│ │ │ ├── etimer.h
│ │ │ ├── lc-addrlabels.h
│ │ │ ├── lc-switch.h
│ │ │ ├── lc.h
│ │ │ ├── process.c
│ │ │ ├── process.h
│ │ │ ├── pt.h
│ │ │ ├── stimer.c
│ │ │ ├── stimer.h
│ │ │ ├── timer.c
│ │ │ └── timer.h
│ │ ├── uip-conf.h
│ │ ├── uip_arch
│ │ ├── clock-arch.h
│ │ ├── clock-arch.xc
│ │ ├── uip_arch.c
│ │ └── uip_arch.h
│ │ ├── uip_server.c
│ │ ├── uip_server.h
│ │ ├── uip_server_support.c
│ │ ├── uip_server_support.h
│ │ ├── uip_single_server.h
│ │ ├── uip_single_server.xc
│ │ ├── uip_xtcp.c
│ │ ├── uip_xtcp.h
│ │ ├── xcoredev.h
│ │ ├── xcoredev.xc
│ │ └── xtcp_server_conf.h
└── xtcp_conf_example.h
├── module_zeroconf
├── .cproject
├── .makefile
├── .project
├── .xproject
├── README.rst
├── mdns
│ ├── mdns.c
│ ├── mdns.h
│ ├── mdns_protocol.h
│ ├── mdns_support.xc
│ └── netbios_protocol.h
└── module_build_info
├── tests
├── scripts
│ ├── stream
│ │ └── stream_out.c
│ ├── test_tcp_receive.py
│ ├── test_tcp_send.py
│ ├── test_udp_multiple_open_send.py
│ ├── test_udp_receive.py
│ ├── test_udp_send.py
│ └── test_udp_slow_send.pl
├── test_multi_client
│ ├── .cproject
│ ├── .project
│ ├── .xproject
│ ├── Makefile
│ ├── src
│ │ ├── XR-AVB-LC-BRD.xn
│ │ └── main.xc
│ └── test_udp.py
├── test_regression
│ ├── .cproject
│ ├── .project
│ ├── .xproject
│ ├── Makefile
│ ├── src
│ │ ├── ethernet_conf.h
│ │ ├── main.xc
│ │ └── xtcp_client_conf.h
│ ├── tcpip_test.py
│ └── test.sh
└── test_tx_performance
│ ├── .cproject
│ ├── .project
│ ├── .xproject
│ ├── Makefile
│ └── src
│ ├── XP-MC-CTRL-L2.xn
│ ├── ethernet_conf.h
│ ├── main.xc
│ └── xtcp_client_conf.h
└── xpd.xml
/.gitignore:
--------------------------------------------------------------------------------
1 | *.build*
2 | */bin/*
3 | experimental/*/bin/*
4 | tests/*/bin/*
5 | *_build*
6 | *.zip
7 | __generated*
8 |
--------------------------------------------------------------------------------
/CHANGELOG.rst:
--------------------------------------------------------------------------------
1 | sc_xtcp Change Log
2 | ==================
3 |
4 | 3.2.1
5 | -----
6 |
7 | * Changes to dependencies:
8 |
9 | - sc_ethernet: 2.2.7rc1 -> 2.3.1rc0
10 |
11 | + Fix invalid inter-frame gaps.
12 | + Adds AVB-DC support to sc_ethernet
13 |
14 | 3.2.0
15 | -----
16 | * Added IPv6 support
17 |
18 | 3.1.5
19 | -----
20 | * Fixed channel protocol bug that caused crash when xCONNECT is
21 | heavily loaded
22 | * Various documentation updates
23 | * Fixes to avoid warning in xTIMEcomposer studio version 13.0.0
24 | or later
25 |
26 | * Changes to dependencies:
27 |
28 | - sc_ethernet: 2.2.5rc2 -> 2.2.7rc1
29 |
30 | + Fix buffering bug on full implementation that caused crash under
31 | + Various documentation updates
32 |
33 | 3.1.4
34 | -----
35 | * Updated ethernet dependency to version 2.2.5
36 |
37 | 3.1.3
38 | -----
39 | * Updated ethernet dependency to version 2.2.4
40 | * Fixed corner case errors/improved robustness in DHCP protocol handling
41 |
42 | 3.1.2
43 | -----
44 | * Fixed auto-ip bug for 2-core xtcp server
45 |
46 | 3.1.1
47 | -----
48 | * Minor code demo app fixes (port structures should be declared on
49 | specific tiles)
50 |
51 | 3.1.0
52 | -----
53 | * Compatible with 2.2 module_ethernet
54 | * Updated to new intializer api and integrated ethernet server
55 |
56 | 3.0.1
57 | -----
58 |
59 | * Updated to use latest sc_ethernet package
60 |
61 | 3.0.0
62 | -----
63 | * Fixed bugs in DHCP and multicast UDP
64 | * Updated packaging, makefiles and documentation
65 | * Updated to use latest sc_ethernet package
66 |
67 | 2.0.1
68 | -----
69 |
70 | * Further memory improvements
71 | * Additional conditional compilation
72 | * Fix to zeroconf with netbios option enabled
73 |
74 | 2.0.0
75 | -----
76 |
77 | * Memory improvements
78 | * Fix error whereby UDP packets with broadcast destination were not received
79 | * An initial implementation of a TFTP server
80 |
81 | 1.3.1
82 | -----
83 |
84 | * Initial implementation
85 |
86 |
--------------------------------------------------------------------------------
/LICENSE.txt:
--------------------------------------------------------------------------------
1 | Software License Agreement
2 |
3 | Copyright (c) 2011, XMOS Ltd., All rights reserved.
4 |
5 | The copyright holders hereby grant to any person obtaining a copy of this software (the "Software") and/or its associated
6 | documentation files (the Documentation), the perpetual, irrevocable (except in the case of breach of this license) no-cost,
7 | royalty free, sublicensable rights to use, copy, modify, merge, publish, display, publicly perform, distribute, and/or
8 | sell copies of the Software and the Documentation, together or separately, and to permit persons to whom the Software and/or
9 | Documentation is furnished to do so, subject to the following conditions:
10 |
11 | . Redistributions of the Software in source code must retain the above copyright notice, this list of conditions and the
12 | following disclaimers.
13 |
14 | . Redistributions of the Software in binary form must reproduce the above copyright notice, this list of conditions and
15 | the following disclaimers in the documentation and/or other materials provided with the distribution.
16 |
17 | . Redistributions of the Documentation must retain the above copyright notice, this list of conditions and the following
18 | disclaimers.
19 |
20 | Neither the name of XMOS, nor the names of its contributors may be used to endorse or promote products derived from this
21 | Software or the Documentation without specific prior written permission of the copyright holder.
22 |
23 | THE SOFTWARE AND DOCUMENTATION ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
24 | LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25 | CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
26 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR DOCUMENTATION OR THE USE OF OR OTHER
27 | DEALINGS WITH THE SOFTWARE OR DOCUMENTATION.
28 |
--------------------------------------------------------------------------------
/Makefile:
--------------------------------------------------------------------------------
1 | # This variable should contain a space separated list of all
2 | # the directories containing buildable applications (usually
3 | # prefixed with the app_ prefix)
4 | #
5 | # If the variable is set to "all" then all directories that start with app_
6 | # are built.
7 | BUILD_SUBDIRS = $(wildcard app_*) $(wildcard tests/test_*) $(wildcard experimental/app_*)
8 |
9 | XMOS_MAKE_PATH ?= ..
10 | include $(XMOS_MAKE_PATH)/xcommon/module_xcommon/build/Makefile.toplevel
11 |
--------------------------------------------------------------------------------
/README.rst:
--------------------------------------------------------------------------------
1 | XCORE.com xTcp SOFTWARE COMPONENT
2 | .................................
3 |
4 | :Latest release: 3.2.1rc1
5 | :Maintainer: davidn@xmos.com
6 | :Description: Implementation of uIP TCP/IP stack for XMOS devices. Runs in a single thread.
7 |
8 |
9 | Key Features
10 | ============
11 |
12 | * TCP + UDP connections
13 | * ICMP
14 | * DHCP
15 | * mDNS
16 | * Example of HTTP server and Telnet
17 | * TFTP server
18 |
19 | Firmware Overview
20 | =================
21 |
22 | Multiple threads are used to process IP packets and forward them through a channel to upper layer handlers.
23 |
24 | Documentation can be found at http://github.xcore.com/sc_xtcp/index.html
25 |
26 | Known Issues
27 | ============
28 |
29 | none
30 |
31 | Support
32 | =======
33 |
34 | Issues may be submitted via the Issues tab in this github repo. Response to any issues submitted as at the discretion of the maintainer for this line.
35 |
36 | Required software (dependencies)
37 | ================================
38 |
39 | * sc_util (git@github.com:xcore/sc_util)
40 | * sc_slicekit_support (git@github.com:xcore/sc_slicekit_support)
41 | * sc_otp (git@github.com:xcore/sc_otp)
42 | * sc_ethernet (git@github.com:xcore/sc_ethernet.git)
43 |
44 |
--------------------------------------------------------------------------------
/app_simple_webserver/.xproject:
--------------------------------------------------------------------------------
1 | sc_xtcpXM-001955-SM3.2.1rc0
--------------------------------------------------------------------------------
/app_simple_webserver/Makefile:
--------------------------------------------------------------------------------
1 | # The TARGET variable determines what target system the application is
2 | # compiled for. It either refers to an XN file in the source directories
3 | # or a valid argument for the --target option when compiling.
4 |
5 | TARGET = SLICEKIT-L2
6 |
7 | # The APP_NAME variable determines the name of the final .xe file. It should
8 | # not include the .xe postfix. If left blank the name will default to
9 | # the project name
10 |
11 | APP_NAME =
12 |
13 | # The flags passed to xcc when building the application
14 | # You can also set the following to override flags for a particular language:
15 | #
16 | # XCC_XC_FLAGS, XCC_C_FLAGS, XCC_ASM_FLAGS, XCC_CPP_FLAGS
17 | #
18 | # If the variable XCC_MAP_FLAGS is set it overrides the flags passed to
19 | # xcc for the final link (mapping) stage.
20 |
21 | XCC_FLAGS_IPV6 = -O2 -save-temps -g -report -Xmapper --map -Xmapper MAPFILE -DIPV6=1
22 | XCC_FLAGS_IPV4 = -O2 -save-temps -g -report -Xmapper --map -Xmapper MAPFILE -DIPV6=0
23 |
24 | # The USED_MODULES variable lists other module used by the application.
25 | USED_MODULES = module_xtcp module_ethernet_board_support
26 |
27 |
28 | #=============================================================================
29 | # The following part of the Makefile includes the common build infrastructure
30 | # for compiling XMOS applications. You should not need to edit below here.
31 |
32 | XMOS_MAKE_PATH ?= ../..
33 | include $(XMOS_MAKE_PATH)/xcommon/module_xcommon/build/Makefile.common
34 |
--------------------------------------------------------------------------------
/app_simple_webserver/README.rst:
--------------------------------------------------------------------------------
1 | Simple HTTP Demo
2 | ================
3 |
4 | :scope: Example
5 | :description: A demo of the TCP/IP stack that provides a simple webserver
6 | :keywords: ethernet, tcp/ip, webserver, http
7 |
8 | Description
9 | -----------
10 |
11 | This application uses the tcp/ip stack to produce a simple
12 | webserver. It is here as an illustration on how to use the xtcp stack.
13 |
14 |
--------------------------------------------------------------------------------
/app_simple_webserver/doc_quickstart/Makefile:
--------------------------------------------------------------------------------
1 | all: html
2 |
3 | SPHINX_PROJECT_NAME = Simple Webserver Demo Quickstart Guide
4 | VERSION = 1.0
5 | SOURCE_INCLUDE_DIRS = ../../app_simple_webserver
6 | XDOC_DIR ?= ../../../xdoc
7 | include $(XDOC_DIR)/Makefile.inc
8 |
--------------------------------------------------------------------------------
/app_simple_webserver/doc_quickstart/images/hardware_setup-wide.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xcore/sc_xtcp/2ceb8e2d4734652b12f7871d7d3cc389ed96a31b/app_simple_webserver/doc_quickstart/images/hardware_setup-wide.jpg
--------------------------------------------------------------------------------
/app_simple_webserver/doc_quickstart/images/hardware_setup.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xcore/sc_xtcp/2ceb8e2d4734652b12f7871d7d3cc389ed96a31b/app_simple_webserver/doc_quickstart/images/hardware_setup.jpg
--------------------------------------------------------------------------------
/app_simple_webserver/src/httpd.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2011, XMOS Ltd, All rights reserved
2 | // This software is freely distributable under a derivative of the
3 | // University of Illinois/NCSA Open Source License posted in
4 | // LICENSE.txt and at
5 |
6 | #ifndef _httpd_h_
7 | #define _httpd_h_
8 |
9 | #include "xtcp_client.h"
10 |
11 | void httpd_init(chanend tcp_svr);
12 | void httpd_handle_event(chanend tcp_svr, REFERENCE_PARAM(xtcp_connection_t, conn));
13 |
14 | #endif // _httpd_h_
15 |
--------------------------------------------------------------------------------
/app_simple_webserver/src/main.xc:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2011, XMOS Ltd, All rights reserved
2 | // This software is freely distributable under a derivative of the
3 | // University of Illinois/NCSA Open Source License posted in
4 | // LICENSE.txt and at
5 |
6 | #include
7 | #include "xtcp.h"
8 | #include "ethernet_board_support.h"
9 | #include "xhttpd.h"
10 |
11 | // These intializers are taken from the ethernet_board_support.h header for
12 | // XMOS dev boards. If you are using a different board you will need to
13 | // supply explicit port structure intializers for these values
14 | ethernet_xtcp_ports_t xtcp_ports =
15 | {on ETHERNET_DEFAULT_TILE: OTP_PORTS_INITIALIZER,
16 | ETHERNET_DEFAULT_SMI_INIT,
17 | ETHERNET_DEFAULT_MII_INIT_lite,
18 | ETHERNET_DEFAULT_RESET_INTERFACE_INIT};
19 |
20 | #if IPV6
21 | xtcp_ipconfig_t ipconfig = {
22 | 0,
23 | {{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}},
24 | {{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}},
25 | {{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}},
26 | };
27 | #else
28 | // IP Config - change this to suit your network. Leave with all
29 | // 0 values to use DHCP
30 | xtcp_ipconfig_t ipconfig = {
31 | { 0, 0, 0, 0 }, // ip address (eg 192,168,0,2)
32 | { 0, 0, 0, 0 }, // netmask (eg 255,255,255,0)
33 | { 0, 0, 0, 0 } // gateway (eg 192,168,0,1)
34 | };
35 | #endif
36 |
37 | // Program entry point
38 | int main(void) {
39 | chan c_xtcp[1];
40 |
41 | par
42 | {
43 | // The main ethernet/tcp server
44 | on ETHERNET_DEFAULT_TILE:
45 | ethernet_xtcp_server(xtcp_ports,
46 | ipconfig,
47 | c_xtcp,
48 | 1);
49 |
50 |
51 | // The webserver
52 | on tile[0]: xhttpd(c_xtcp[0]);
53 |
54 | }
55 | return 0;
56 | }
57 |
--------------------------------------------------------------------------------
/app_simple_webserver/src/xhttpd.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2011, XMOS Ltd, All rights reserved
2 | // This software is freely distributable under a derivative of the
3 | // University of Illinois/NCSA Open Source License posted in
4 | // LICENSE.txt and at
5 |
6 | #ifndef _xhttpd_h_
7 | #define _xhttpd_h_
8 |
9 | void xhttpd(chanend tcp_svr);
10 |
11 | #endif // _xhttpd_h_
12 |
--------------------------------------------------------------------------------
/app_simple_webserver/src/xhttpd.xc:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2011, XMOS Ltd, All rights reserved
2 | // This software is freely distributable under a derivative of the
3 | // University of Illinois/NCSA Open Source License posted in
4 | // LICENSE.txt and at
5 |
6 | #include
7 | #include
8 | #include "httpd.h"
9 | #include "xtcp_client.h"
10 |
11 | // The main webserver thread
12 | void xhttpd(chanend tcp_svr)
13 | {
14 | xtcp_connection_t conn;
15 | printstrln("**WELCOME TO THE SIMPLE WEBSERVER DEMO**");
16 | // Initiate the HTTP state
17 | httpd_init(tcp_svr);
18 |
19 | // Loop forever processing TCP events
20 | while(1)
21 | {
22 | select
23 | {
24 | case xtcp_event(tcp_svr, conn):
25 | httpd_handle_event(tcp_svr, conn);
26 | break;
27 | }
28 |
29 | }
30 | }
31 |
32 |
--------------------------------------------------------------------------------
/app_udp_demo/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | app_udp_demo
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.cdt.managedbuilder.core.genmakebuilder
10 | clean,full,incremental,
11 |
12 |
13 | ?children?
14 | ?name?=outputEntries\|?children?=?name?=entry\\\\|\\|\||
15 |
16 |
17 | ?name?
18 |
19 |
20 |
21 | org.eclipse.cdt.make.core.append_environment
22 | true
23 |
24 |
25 | org.eclipse.cdt.make.core.buildArguments
26 | CONFIG=Debug
27 |
28 |
29 | org.eclipse.cdt.make.core.buildCommand
30 | xmake
31 |
32 |
33 | org.eclipse.cdt.make.core.cleanBuildTarget
34 | clean
35 |
36 |
37 | org.eclipse.cdt.make.core.contents
38 | org.eclipse.cdt.make.core.activeConfigSettings
39 |
40 |
41 | org.eclipse.cdt.make.core.enableAutoBuild
42 | false
43 |
44 |
45 | org.eclipse.cdt.make.core.enableCleanBuild
46 | true
47 |
48 |
49 | org.eclipse.cdt.make.core.enableFullBuild
50 | true
51 |
52 |
53 | org.eclipse.cdt.make.core.stopOnError
54 | true
55 |
56 |
57 | org.eclipse.cdt.make.core.useDefaultBuildCmd
58 | false
59 |
60 |
61 |
62 |
63 | org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder
64 | full,incremental,
65 |
66 |
67 |
68 |
69 |
70 | org.eclipse.cdt.core.cnature
71 | org.eclipse.cdt.managedbuilder.core.managedBuildNature
72 | org.eclipse.cdt.managedbuilder.core.ScannerConfigNature
73 | com.xmos.cdt.core.XdeProjectNature
74 |
75 |
76 |
77 |
--------------------------------------------------------------------------------
/app_udp_demo/.xproject:
--------------------------------------------------------------------------------
1 | sc_xtcpXM-001955-SM3.2.1rc0
--------------------------------------------------------------------------------
/app_udp_demo/Makefile:
--------------------------------------------------------------------------------
1 | # The TARGET variable determines what target system the application is
2 | # compiled for. It either refers to an XN file in the source directories
3 | # or a valid argument for the --target option when compiling
4 | TARGET = XC-2
5 |
6 | # The APP_NAME variable determines the name of the final .xe file. It should
7 | # not include the .xe postfix. If left blank the name will default to
8 | # the project name
9 | APP_NAME =
10 |
11 | # The USED_MODULES variable lists other module used by the application.
12 | USED_MODULES = module_xtcp module_ethernet_board_support
13 |
14 | # The flags passed to xcc when building the application
15 | # You can also set the following to override flags for a particular language:
16 | # XCC_XC_FLAGS, XCC_C_FLAGS, XCC_ASM_FLAGS, XCC_CPP_FLAGS
17 | # If the variable XCC_MAP_FLAGS is set it overrides the flags passed to
18 | # xcc for the final link (mapping) stage.
19 | XCC_FLAGS = -g -O3 -save-temps
20 |
21 | # The VERBOSE variable, if set to 1, enables verbose output from the make
22 | # system.
23 | VERBOSE = 0
24 |
25 | #=============================================================================
26 | # The following part of the Makefile includes the common build infrastructure
27 | # for compiling XMOS applications. You should not need to edit below here.
28 |
29 | XMOS_MAKE_PATH ?= ../..
30 | include $(XMOS_MAKE_PATH)/xcommon/module_xcommon/build/Makefile.common
31 |
--------------------------------------------------------------------------------
/app_udp_demo/README.rst:
--------------------------------------------------------------------------------
1 | Simple UDP Demo
2 | ================
3 |
4 | :scope: Example
5 | :description: A simple example using the UDP protocol
6 | :keywords: ethernet, udp, tcp, ip
7 |
8 | This is a simple example that reflects a particular type of UDP
9 | messages using the TCP/IP stack component.
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app_udp_demo/test_udp.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/python
2 | import socket,sys
3 |
4 | # This simple script sends a UDP packet to port 15533 at the
5 | # IP address given as the first argument to the script
6 | # This is to test the simple UDP example XC program
7 |
8 | sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
9 |
10 | print "Connecting.."
11 | sock.connect((sys.argv[1], 15533))
12 | print "Connected"
13 |
14 | msg = "hello world"
15 | print "Sending message: " + msg
16 | sock.send(msg)
17 |
18 | print "Closing..."
19 | sock.close()
20 | print "Closed"
21 |
--------------------------------------------------------------------------------
/app_webserver_separate_mac/.xproject:
--------------------------------------------------------------------------------
1 | sc_xtcpXM-001955-SM3.2.1rc0
--------------------------------------------------------------------------------
/app_webserver_separate_mac/Makefile:
--------------------------------------------------------------------------------
1 | # The TARGET variable determines what target system the application is
2 | # compiled for. It either refers to an XN file in the source directories
3 | # or a valid argument for the --target option when compiling.
4 |
5 | TARGET = SLICEKIT-L2
6 |
7 | # The APP_NAME variable determines the name of the final .xe file. It should
8 | # not include the .xe postfix. If left blank the name will default to
9 | # the project name
10 |
11 | APP_NAME =
12 |
13 | # The flags passed to xcc when building the application
14 | # You can also set the following to override flags for a particular language:
15 | #
16 | # XCC_XC_FLAGS, XCC_C_FLAGS, XCC_ASM_FLAGS, XCC_CPP_FLAGS
17 | #
18 | # If the variable XCC_MAP_FLAGS is set it overrides the flags passed to
19 | # xcc for the final link (mapping) stage.
20 |
21 | XCC_FLAGS = -O2 -save-temps -g -report -Xmapper --map -Xmapper MAPFILE
22 |
23 | # The USED_MODULES variable lists other module used by the application.
24 | USED_MODULES = module_xtcp module_ethernet_board_support
25 |
26 |
27 | #=============================================================================
28 | # The following part of the Makefile includes the common build infrastructure
29 | # for compiling XMOS applications. You should not need to edit below here.
30 |
31 | XMOS_MAKE_PATH ?= ../..
32 | include $(XMOS_MAKE_PATH)/xcommon/module_xcommon/build/Makefile.common
33 |
--------------------------------------------------------------------------------
/app_webserver_separate_mac/src/httpd.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2011, XMOS Ltd, All rights reserved
2 | // This software is freely distributable under a derivative of the
3 | // University of Illinois/NCSA Open Source License posted in
4 | // LICENSE.txt and at
5 |
6 | #ifndef _httpd_h_
7 | #define _httpd_h_
8 |
9 | #include "xtcp_client.h"
10 |
11 | void httpd_init(chanend tcp_svr);
12 | void httpd_handle_event(chanend tcp_svr, REFERENCE_PARAM(xtcp_connection_t, conn));
13 |
14 | #endif // _httpd_h_
15 |
--------------------------------------------------------------------------------
/app_webserver_separate_mac/src/main.xc:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2011, XMOS Ltd, All rights reserved
2 | // This software is freely distributable under a derivative of the
3 | // University of Illinois/NCSA Open Source License posted in
4 | // LICENSE.txt and at
5 |
6 | #include
7 | #include "xtcp.h"
8 | #include "ethernet_board_support.h"
9 | #include "xhttpd.h"
10 |
11 | // IP Config - change this to suit your network. Leave with all
12 | // 0 values to use DHCP
13 | xtcp_ipconfig_t ipconfig = {
14 | { 0, 0, 0, 0 }, // ip address (eg 192,168,0,2)
15 | { 0, 0, 0, 0 }, // netmask (eg 255,255,255,0)
16 | { 0, 0, 0, 0 } // gateway (eg 192,168,0,1)
17 | };
18 |
19 |
20 | // Port Definitions
21 |
22 | // These ports are for accessing the OTP memory
23 | on ETHERNET_DEFAULT_TILE: otp_ports_t otp_ports = OTP_PORTS_INITIALIZER;
24 |
25 | // Here are the port definitions required by ethernet
26 | // The intializers are taken from the ethernet_board_support.h header for
27 | // XMOS dev boards. If you are using a different board you will need to
28 | // supply explicit port structure intializers for these values
29 | smi_interface_t smi = ETHERNET_DEFAULT_SMI_INIT;
30 | mii_interface_t mii = ETHERNET_DEFAULT_MII_INIT;
31 | ethernet_reset_interface_t eth_rst = ETHERNET_DEFAULT_RESET_INTERFACE_INIT;
32 |
33 |
34 | // Program entry point
35 | int main(void) {
36 | chan c_xtcp[1];
37 | chan c_mac_rx[1];
38 | chan c_mac_tx[1];
39 | par
40 | {
41 |
42 | on ETHERNET_DEFAULT_TILE:
43 | {
44 | char mac_address[6];
45 | otp_board_info_get_mac(otp_ports, 0, mac_address);
46 | eth_phy_reset(eth_rst);
47 | smi_init(smi);
48 | eth_phy_config(1, smi);
49 | ethernet_server(mii,
50 | null,
51 | mac_address,
52 | c_mac_rx, 1,
53 | c_mac_tx, 1);
54 | }
55 |
56 | // The tcp server
57 | on ETHERNET_DEFAULT_TILE:
58 | xtcp_server_uip(c_mac_rx[0],
59 | c_mac_tx[0],
60 | c_xtcp,
61 | 1,
62 | ipconfig);
63 |
64 |
65 | // The webserver
66 | on tile[0]: xhttpd(c_xtcp[0]);
67 |
68 | }
69 | return 0;
70 | }
71 |
--------------------------------------------------------------------------------
/app_webserver_separate_mac/src/xhttpd.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2011, XMOS Ltd, All rights reserved
2 | // This software is freely distributable under a derivative of the
3 | // University of Illinois/NCSA Open Source License posted in
4 | // LICENSE.txt and at
5 |
6 | #ifndef _xhttpd_h_
7 | #define _xhttpd_h_
8 |
9 | void xhttpd(chanend tcp_svr);
10 |
11 | #endif // _xhttpd_h_
12 |
--------------------------------------------------------------------------------
/app_webserver_separate_mac/src/xhttpd.xc:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2011, XMOS Ltd, All rights reserved
2 | // This software is freely distributable under a derivative of the
3 | // University of Illinois/NCSA Open Source License posted in
4 | // LICENSE.txt and at
5 |
6 | #include
7 | #include
8 | #include "httpd.h"
9 | #include "xtcp_client.h"
10 |
11 | // The main webserver thread
12 | void xhttpd(chanend tcp_svr)
13 | {
14 | xtcp_connection_t conn;
15 | printstrln("**WELCOME TO THE SIMPLE WEBSERVER DEMO**");
16 | // Initiate the HTTP state
17 | httpd_init(tcp_svr);
18 |
19 | // Loop forever processing TCP events
20 | while(1)
21 | {
22 | select
23 | {
24 | case xtcp_event(tcp_svr, conn):
25 | httpd_handle_event(tcp_svr, conn);
26 | break;
27 | }
28 |
29 | }
30 | }
31 |
32 |
--------------------------------------------------------------------------------
/app_webserver_separate_mac/src/xtcp_conf.h:
--------------------------------------------------------------------------------
1 | #define XTCP_SEPARATE_MAC 1
2 |
--------------------------------------------------------------------------------
/doc/slicekit_quickstart/Makefile:
--------------------------------------------------------------------------------
1 | all: html
2 |
3 | VERSION = 0.1
4 | XDOC_DIR ?= ../../../xdoc
5 | SOURCE_INCLUDE_DIRS=../../../sc_xtcp
6 | include $(XDOC_DIR)/Makefile.inc
7 |
--------------------------------------------------------------------------------
/doc/slicekit_quickstart/images/slicekit_eth_setup.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xcore/sc_xtcp/2ceb8e2d4734652b12f7871d7d3cc389ed96a31b/doc/slicekit_quickstart/images/slicekit_eth_setup.jpg
--------------------------------------------------------------------------------
/experimental/app_buffered_protocol_demo/.project:
--------------------------------------------------------------------------------
1 | app_buffered_protocol_demo com.xmos.cdt.core.ModulePathBuilder org.eclipse.cdt.managedbuilder.core.genmakebuilder clean,full,incremental, ?children? ?name?=outputEntries\|?children?=?name?=entry\\\\|\\|\|| ?name? org.eclipse.cdt.make.core.append_environment true org.eclipse.cdt.make.core.buildArguments CONFIG=Debug org.eclipse.cdt.make.core.buildCommand xmake org.eclipse.cdt.make.core.cleanBuildTarget clean org.eclipse.cdt.make.core.contents org.eclipse.cdt.make.core.activeConfigSettings org.eclipse.cdt.make.core.enableAutoBuild false org.eclipse.cdt.make.core.enableCleanBuild true org.eclipse.cdt.make.core.enableFullBuild true org.eclipse.cdt.make.core.stopOnError true org.eclipse.cdt.make.core.useDefaultBuildCmd false org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder full,incremental, org.eclipse.cdt.core.cnature org.eclipse.cdt.managedbuilder.core.managedBuildNature org.eclipse.cdt.managedbuilder.core.ScannerConfigNature com.xmos.cdt.core.XdeProjectNature
--------------------------------------------------------------------------------
/experimental/app_buffered_protocol_demo/.xproject:
--------------------------------------------------------------------------------
1 | sc_xtcpXM-000074-SW3.0.0rc1
--------------------------------------------------------------------------------
/experimental/app_buffered_protocol_demo/Makefile:
--------------------------------------------------------------------------------
1 | # The TARGET variable determines what target system the application is
2 | # compiled for. It either refers to an XN file in the source directories
3 | # or a valid argument for the --target option when compiling.
4 |
5 | TARGET = SLICEKIT-L2
6 |
7 | # The APP_NAME variable determines the name of the final .xe file. It should
8 | # not include the .xe postfix. If left blank the name will default to
9 | # the project name
10 |
11 | APP_NAME =
12 |
13 | # The flags passed to xcc when building the application
14 | # You can also set the following to override flags for a particular language:
15 | #
16 | # XCC_XC_FLAGS, XCC_C_FLAGS, XCC_ASM_FLAGS, XCC_CPP_FLAGS
17 | #
18 | # If the variable XCC_MAP_FLAGS is set it overrides the flags passed to
19 | # xcc for the final link (mapping) stage.
20 |
21 | XCC_FLAGS = -g -O3
22 |
23 | # The USED_MODULES variable lists other module used by the application.
24 |
25 | USED_MODULES = module_xtcp module_ethernet_board_support
26 |
27 | ifeq ($(notdir $(abspath ..)),experimental)
28 | PATHSEP = $(if $(findstring Windows, $(OS))$(findstring WINDOWS,$(OS)),;,:)
29 | XMOS_MODULE_PATH := $(XMOS_MODULE_PATH)$(PATHSEP)../../..
30 | endif
31 |
32 | #=============================================================================
33 | # The following part of the Makefile includes the common build infrastructure
34 | # for compiling XMOS applications. You should not need to edit below here.
35 |
36 | XMOS_MAKE_PATH ?= ../..
37 | include $(XMOS_MAKE_PATH)/xcommon/module_xcommon/build/Makefile.common
38 |
--------------------------------------------------------------------------------
/experimental/app_buffered_protocol_demo/src/demo_protocol.c:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2011, XMOS Ltd, All rights reserved
2 | // This software is freely distributable under a derivative of the
3 | // University of Illinois/NCSA Open Source License posted in
4 | // LICENSE.txt and at
5 |
6 | #include "xtcp_client.h"
7 | #include "xtcp_buffered_client.h"
8 | #include "demo_protocol.h"
9 | #include "print.h"
10 |
11 | // This method is called to process the header. It returns the size, which is the
12 | // first byte of the header
13 | int decode_demo_protocol_header(char *hdr) {
14 | return *hdr;
15 | }
16 |
17 | // This method is called by the protocol RX function when a full message is received
18 | void demo_protocol_process_message(chanend tcp_svr, xtcp_connection_t *conn,
19 | demo_protocol_state_t *st, char *msg) {
20 | char reply[7] = { 0, 1, 2, 3, 4, 5, 6 };
21 | int success;
22 |
23 | // Print the received message to the console
24 | printstrln(&msg[1]);
25 |
26 | // Send a reply, which is a 7 byte message
27 | success = xtcp_buffered_send(tcp_svr, conn, &st->bufinfo, reply, 7);
28 |
29 | if (!success)
30 | printstr("send buffer overflow\n");
31 |
32 | return;
33 | }
34 |
35 |
--------------------------------------------------------------------------------
/experimental/app_buffered_protocol_demo/src/demo_protocol.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2011, XMOS Ltd, All rights reserved
2 | // This software is freely distributable under a derivative of the
3 | // University of Illinois/NCSA Open Source License posted in
4 | // LICENSE.txt and at
5 |
6 | #ifndef __demo_protocol_h__
7 | #define __demo_protocol_h__
8 |
9 | #include "xtcp_client.h"
10 | #include "xtcp_buffered_client.h"
11 |
12 | #define DEMO_PROTOCOL_PORT 15533
13 | #define DEMO_PROTOCOL_HDR_SIZE 1
14 | #define DEMO_PROTOCOL_MAX_MSG_SIZE 100
15 | #define DEMO_PROTOCOL_RXBUF_LEN 2048
16 | #define DEMO_PROTOCOL_TXBUF_LEN 1024
17 |
18 | #define DEMO_PROTOCOL_CONN_TIMEOUT_MS (500) // timeout due to inactivity
19 | //every 500 ms
20 |
21 |
22 | #ifndef __XC__
23 |
24 | typedef struct demo_protocol_state_t
25 | {
26 | int active;
27 | int got_header;
28 | int len;
29 | int last_used;
30 | int conn_id;
31 | xtcp_bufinfo_t bufinfo;
32 | char inbuf[DEMO_PROTOCOL_RXBUF_LEN];
33 | char outbuf[DEMO_PROTOCOL_TXBUF_LEN];
34 | } demo_protocol_state_t;
35 |
36 | #endif
37 |
38 |
39 | void demo_protocol_process_message(chanend tcp_svr,
40 | xtcp_connection_t *conn,
41 | demo_protocol_state_t *st,
42 | char *msg);
43 |
44 | int decode_demo_protocol_header(char *hdr);
45 |
46 | #endif //__demo_protocol_h__
47 |
--------------------------------------------------------------------------------
/experimental/app_buffered_protocol_demo/src/demo_protocold.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2011, XMOS Ltd, All rights reserved
2 | // This software is freely distributable under a derivative of the
3 | // University of Illinois/NCSA Open Source License posted in
4 | // LICENSE.txt and at
5 |
6 | #ifndef _demo_protocold_h_
7 | #define _demo_protocold_h_
8 | #include "xccompat.h"
9 | #include "xtcp_client.h"
10 |
11 | void demo_protocold(chanend tcp_svr);
12 |
13 | // Used internally to the server
14 | void demo_protocol_init(chanend tcp_svr);
15 |
16 | void demo_protocol_periodic(chanend tcp_svr, int t);
17 |
18 | void demo_protocol_handle_event(chanend tcp_svr,
19 | REFERENCE_PARAM(xtcp_connection_t, conn),
20 | int timestamp);
21 |
22 |
23 |
24 | #endif // _demo_protocold_h_
25 |
--------------------------------------------------------------------------------
/experimental/app_buffered_protocol_demo/src/demo_protocold.xc:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2011, XMOS Ltd, All rights reserved
2 | // This software is freely distributable under a derivative of the
3 | // University of Illinois/NCSA Open Source License posted in
4 | // LICENSE.txt and at
5 |
6 | #include
7 | #include
8 | #include "demo_protocold.h"
9 | #include "xtcp_client.h"
10 |
11 | #define DEMO_PROTOCOL_PERIOD_MS (200) // every 200 ms
12 | #define DEMO_PROTOCOL_PERIOD_TIMER_TICKS (DEMO_PROTOCOL_PERIOD_MS * XS1_TIMER_KHZ)
13 |
14 | // The main service thread
15 | void demo_protocold(chanend tcp_svr) {
16 | xtcp_connection_t conn;
17 | timer tmr;
18 | int t, timestamp;
19 |
20 | // Initiate the protocol state
21 | demo_protocol_init(tcp_svr);
22 |
23 | tmr :> t;
24 |
25 | // Loop forever processing TCP events
26 | while(1)
27 | {
28 | select
29 | {
30 | case xtcp_event(tcp_svr, conn):
31 | {
32 | // Send the event to the protocol handler for processing
33 | tmr :> timestamp;
34 | demo_protocol_handle_event(tcp_svr, conn, timestamp);
35 | }
36 | break;
37 |
38 |
39 | case tmr when timerafter(t) :> void:
40 | {
41 | // Send a periodic event to the protocol
42 | demo_protocol_periodic(tcp_svr, t);
43 | t += DEMO_PROTOCOL_PERIOD_TIMER_TICKS;
44 | }
45 | break;
46 | }
47 | }
48 | }
49 |
50 |
51 |
52 |
53 |
--------------------------------------------------------------------------------
/experimental/app_buffered_protocol_demo/src/main.xc:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2011, XMOS Ltd, All rights reserved
2 | // This software is freely distributable under a derivative of the
3 | // University of Illinois/NCSA Open Source License posted in
4 | // LICENSE.txt and at
5 |
6 | #include
7 | #include "xtcp.h"
8 | #include "ethernet_board_support.h"
9 | #include "demo_protocold.h"
10 |
11 | // These intializers are taken from the ethernet_board_support.h header for
12 | // XMOS dev boards. If you are using a different board you will need to
13 | // supply explicit port structure intializers for these values
14 | ethernet_xtcp_ports_t xtcp_ports =
15 | {on ETHERNET_DEFAULT_TILE: OTP_PORTS_INITIALIZER,
16 | ETHERNET_DEFAULT_SMI_INIT,
17 | ETHERNET_DEFAULT_MII_INIT_lite,
18 | ETHERNET_DEFAULT_RESET_INTERFACE_INIT};
19 |
20 | xtcp_ipconfig_t ipconfig = {{0,0,0,0},{0,0,0,0},{0,0,0,0}};
21 |
22 | // Program entry point
23 | int main(void)
24 | {
25 | chan c_xtcp[1];
26 |
27 | par
28 | {
29 | on ETHERNET_DEFAULT_TILE: ethernet_xtcp_server(xtcp_ports,
30 | ipconfig,
31 | c_xtcp,
32 | 1);
33 |
34 | // The server thread
35 | on stdcore[0]: demo_protocold(c_xtcp[0]);
36 |
37 |
38 | }
39 | return 0;
40 | }
41 |
--------------------------------------------------------------------------------
/experimental/app_buffered_protocol_demo/src/xtcp_client_conf.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2011, XMOS Ltd, All rights reserved
2 | // This software is freely distributable under a derivative of the
3 | // University of Illinois/NCSA Open Source License posted in
4 | // LICENSE.txt and at
5 |
6 | #define XTCP_BUFFERED_API 1
7 |
--------------------------------------------------------------------------------
/experimental/app_buffered_protocol_demo/test/test_demo_protocol.py:
--------------------------------------------------------------------------------
1 | import socket,sys
2 |
3 | sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
4 | #sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
5 |
6 | print "Connecting.."
7 | sock.connect((sys.argv[1], 15533))
8 | print "Connected"
9 |
10 |
11 | for i in range(0,10):
12 |
13 | msg = "\0hello world "
14 | for j in range(i):
15 | msg = msg + str(j)
16 |
17 | msg = msg + '\0'
18 | msg = chr(len(msg)) + msg
19 |
20 | msg = msg + msg
21 |
22 | print "Sending message: " + msg[1:-1]
23 | sock.send(msg[0:2])
24 | sock.send(msg[2:])
25 | reply = sock.recv(14)
26 | print "Reply: " + str([ord(x) for x in list(reply)])
27 |
28 | print "Closing..."
29 | sock.close()
30 | print "Closed"
31 |
--------------------------------------------------------------------------------
/experimental/app_buffered_protocol_demo_2/.project:
--------------------------------------------------------------------------------
1 | app_buffered_protocol_demo_2 com.xmos.cdt.core.ModulePathBuilder org.eclipse.cdt.managedbuilder.core.genmakebuilder clean,full,incremental, ?children? ?name?=outputEntries\|?children?=?name?=entry\\\\|\\|\|| ?name? org.eclipse.cdt.make.core.append_environment true org.eclipse.cdt.make.core.buildArguments CONFIG=Debug org.eclipse.cdt.make.core.buildCommand xmake org.eclipse.cdt.make.core.cleanBuildTarget clean org.eclipse.cdt.make.core.contents org.eclipse.cdt.make.core.activeConfigSettings org.eclipse.cdt.make.core.enableAutoBuild false org.eclipse.cdt.make.core.enableCleanBuild true org.eclipse.cdt.make.core.enableFullBuild true org.eclipse.cdt.make.core.stopOnError true org.eclipse.cdt.make.core.useDefaultBuildCmd false org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder full,incremental, org.eclipse.cdt.core.cnature org.eclipse.cdt.managedbuilder.core.managedBuildNature org.eclipse.cdt.managedbuilder.core.ScannerConfigNature com.xmos.cdt.core.XdeProjectNature
--------------------------------------------------------------------------------
/experimental/app_buffered_protocol_demo_2/.xproject:
--------------------------------------------------------------------------------
1 | sc_xtcpXM-000074-SW3.0.0rc1
--------------------------------------------------------------------------------
/experimental/app_buffered_protocol_demo_2/Makefile:
--------------------------------------------------------------------------------
1 | # The TARGET variable determines what target system the application is
2 | # compiled for. It either refers to an XN file in the source directories
3 | # or a valid argument for the --target option when compiling.
4 |
5 | TARGET = SLICEKIT-L2
6 |
7 | # The APP_NAME variable determines the name of the final .xe file. It should
8 | # not include the .xe postfix. If left blank the name will default to
9 | # the project name
10 |
11 | APP_NAME =
12 |
13 | # The flags passed to xcc when building the application
14 | # You can also set the following to override flags for a particular language:
15 | #
16 | # XCC_XC_FLAGS, XCC_C_FLAGS, XCC_ASM_FLAGS, XCC_CPP_FLAGS
17 | #
18 | # If the variable XCC_MAP_FLAGS is set it overrides the flags passed to
19 | # xcc for the final link (mapping) stage.
20 |
21 | XCC_FLAGS = -g -O3
22 |
23 | # The USED_MODULES variable lists other module used by the application.
24 |
25 | USED_MODULES = module_xtcp module_ethernet_board_support
26 |
27 | ifeq ($(notdir $(abspath ..)),experimental)
28 | PATHSEP = $(if $(findstring Windows, $(OS))$(findstring WINDOWS,$(OS)),;,:)
29 | XMOS_MODULE_PATH := $(XMOS_MODULE_PATH)$(PATHSEP)../../..
30 | endif
31 |
32 | #=============================================================================
33 | # The following part of the Makefile includes the common build infrastructure
34 | # for compiling XMOS applications. You should not need to edit below here.
35 |
36 | XMOS_MAKE_PATH ?= ../..
37 | include $(XMOS_MAKE_PATH)/xcommon/module_xcommon/build/Makefile.common
38 |
--------------------------------------------------------------------------------
/experimental/app_buffered_protocol_demo_2/src/demo_protocol.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2011, XMOS Ltd, All rights reserved
2 | // This software is freely distributable under a derivative of the
3 | // University of Illinois/NCSA Open Source License posted in
4 | // LICENSE.txt and at
5 |
6 | #ifndef __demo_protocol_h__
7 | #define __demo_protocol_h__
8 |
9 | #include "xtcp_client.h"
10 | #include "xtcp_buffered_client.h"
11 |
12 | #define DEMO_PROTOCOL_PORT 15533
13 | #define DEMO_PROTOCOL_MAX_MSG_SIZE 100
14 | #define DEMO_PROTOCOL_RXBUF_LEN 2048
15 | #define DEMO_PROTOCOL_TXBUF_LEN 1024
16 |
17 | #define DEMO_PROTOCOL_CONN_TIMEOUT_MS (60000) // timeout due to inactivity after 1 minute
18 |
19 |
20 | #ifndef __XC__
21 |
22 | typedef struct demo_protocol_state_t
23 | {
24 | int active;
25 | int len;
26 | int last_used;
27 | int conn_id;
28 | xtcp_bufinfo_t bufinfo;
29 | char inbuf[DEMO_PROTOCOL_RXBUF_LEN];
30 | char outbuf[DEMO_PROTOCOL_TXBUF_LEN];
31 | } demo_protocol_state_t;
32 |
33 | #endif
34 |
35 | void demo_protocold(chanend tcp_svr);
36 |
37 | // Used internally to the server
38 | void demo_protocol_init(chanend tcp_svr);
39 |
40 | void demo_protocol_periodic(chanend tcp_svr, int t);
41 |
42 | void demo_protocol_handle_event(chanend tcp_svr,
43 | REFERENCE_PARAM(xtcp_connection_t, conn),
44 | int timestamp);
45 |
46 |
47 | #endif //__demo_protocol_h__
48 |
--------------------------------------------------------------------------------
/experimental/app_buffered_protocol_demo_2/src/demo_protocold.xc:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2011, XMOS Ltd, All rights reserved
2 | // This software is freely distributable under a derivative of the
3 | // University of Illinois/NCSA Open Source License posted in
4 | // LICENSE.txt and at
5 |
6 | #include
7 | #include
8 | #include "demo_protocol.h"
9 | #include "xtcp_client.h"
10 |
11 | #define DEMO_PROTOCOL_PERIOD_MS (200) // every 200 ms
12 | #define DEMO_PROTOCOL_PERIOD_TIMER_TICKS (DEMO_PROTOCOL_PERIOD_MS * XS1_TIMER_KHZ)
13 |
14 | // The main service thread
15 | void demo_protocold(chanend tcp_svr) {
16 | xtcp_connection_t conn;
17 | timer tmr;
18 | int t, timestamp;
19 |
20 | // Initiate the protocol state
21 | demo_protocol_init(tcp_svr);
22 |
23 | tmr :> t;
24 |
25 | // Loop forever processing TCP events
26 | while(1)
27 | {
28 | select
29 | {
30 | case xtcp_event(tcp_svr, conn):
31 | {
32 | // Send the event to the protocol handler for processing
33 | tmr :> timestamp;
34 | demo_protocol_handle_event(tcp_svr, conn, timestamp);
35 | }
36 | break;
37 |
38 |
39 | case tmr when timerafter(t) :> void:
40 | {
41 | // Send a periodic event to the protocol
42 | demo_protocol_periodic(tcp_svr, t);
43 | t += DEMO_PROTOCOL_PERIOD_TIMER_TICKS;
44 | }
45 | break;
46 | }
47 | }
48 | }
49 |
50 |
51 |
52 |
53 |
--------------------------------------------------------------------------------
/experimental/app_buffered_protocol_demo_2/src/main.xc:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2011, XMOS Ltd, All rights reserved
2 | // This software is freely distributable under a derivative of the
3 | // University of Illinois/NCSA Open Source License posted in
4 | // LICENSE.txt and at
5 |
6 | #include
7 | #include "xtcp.h"
8 | #include "ethernet_board_support.h"
9 | #include "demo_protocol.h"
10 |
11 | // These intializers are taken from the ethernet_board_support.h header for
12 | // XMOS dev boards. If you are using a different board you will need to
13 | // supply explicit port structure intializers for these values
14 | ethernet_xtcp_ports_t xtcp_ports =
15 | {on ETHERNET_DEFAULT_TILE: OTP_PORTS_INITIALIZER,
16 | ETHERNET_DEFAULT_SMI_INIT,
17 | ETHERNET_DEFAULT_MII_INIT_lite,
18 | ETHERNET_DEFAULT_RESET_INTERFACE_INIT};
19 |
20 |
21 | #if 1
22 | // Static IP Config - change this to suit your network (current is link local address)
23 | xtcp_ipconfig_t ipconfig =
24 | {
25 | {169,254,3,2}, // ip address
26 | {255,255,0,0}, // netmask
27 | {0,0,0,0} // gateway
28 | };
29 | #else
30 | // Use dynamic addressing DHCP
31 | xtcp_ipconfig_t ipconfig = {{0,0,0,0},{0,0,0,0},{0,0,0,0}};
32 | #endif
33 |
34 | // Program entry point
35 | int main(void)
36 | {
37 | chan c_xtcp[1];
38 |
39 | par
40 | {
41 | on ETHERNET_DEFAULT_TILE: ethernet_xtcp_server(xtcp_ports,
42 | ipconfig,
43 | c_xtcp,
44 | 1);
45 |
46 |
47 | // The server thread
48 | on stdcore[0]: demo_protocold(c_xtcp[0]);
49 |
50 |
51 | }
52 | return 0;
53 | }
54 |
--------------------------------------------------------------------------------
/experimental/app_buffered_protocol_demo_2/src/xtcp_client_conf.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2011, XMOS Ltd, All rights reserved
2 | // This software is freely distributable under a derivative of the
3 | // University of Illinois/NCSA Open Source License posted in
4 | // LICENSE.txt and at
5 |
6 | #define XTCP_BUFFERED_API 1
7 |
--------------------------------------------------------------------------------
/experimental/app_pip_bootloader/.project:
--------------------------------------------------------------------------------
1 | app_pip_bootloader com.xmos.cdt.core.ModulePathBuilder org.eclipse.cdt.managedbuilder.core.genmakebuilder clean,full,incremental, ?children? ?name?=outputEntries\|?children?=?name?=entry\\\\|\\|\|| ?name? org.eclipse.cdt.make.core.append_environment true org.eclipse.cdt.make.core.buildArguments CONFIG=Debug org.eclipse.cdt.make.core.buildCommand xmake org.eclipse.cdt.make.core.cleanBuildTarget clean org.eclipse.cdt.make.core.contents org.eclipse.cdt.make.core.activeConfigSettings org.eclipse.cdt.make.core.enableAutoBuild false org.eclipse.cdt.make.core.enableCleanBuild true org.eclipse.cdt.make.core.enableFullBuild true org.eclipse.cdt.make.core.stopOnError true org.eclipse.cdt.make.core.useDefaultBuildCmd false org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder full,incremental, org.eclipse.cdt.core.cnature org.eclipse.cdt.managedbuilder.core.managedBuildNature org.eclipse.cdt.managedbuilder.core.ScannerConfigNature com.xmos.cdt.core.XdeProjectNature
--------------------------------------------------------------------------------
/experimental/app_pip_bootloader/.xproject:
--------------------------------------------------------------------------------
1 | sc_xtcpXM-000074-SW3.0.0rc1
--------------------------------------------------------------------------------
/experimental/app_pip_bootloader/Makefile:
--------------------------------------------------------------------------------
1 | TARGET = XP-ETHERNET-TEST
2 | APP_NAME =
3 | XCC_FLAGS = -Os -g -report
4 | USED_MODULES = module_pip module_ethernet module_otp_board_info module_ethernet_board_support
5 |
6 | # This change to the module path is so that this application can be in the
7 | # tests sub-directory in it's git repo
8 | ifeq ($(notdir $(abspath ..)),experimental)
9 | PATHSEP = $(if $(findstring Windows, $(OS))$(findstring WINDOWS,$(OS)),;,:)
10 | XMOS_MODULE_PATH := $(XMOS_MODULE_PATH)$(PATHSEP)../../..
11 | endif
12 |
13 | #=============================================================================
14 | # The following part of the Makefile includes the common build infrastructure
15 | # for compiling XMOS applications. You should not need to edit below here.
16 |
17 | XMOS_MAKE_PATH ?= ../..
18 | include $(XMOS_MAKE_PATH)/xcommon/module_xcommon/build/Makefile.common
19 |
--------------------------------------------------------------------------------
/experimental/app_pip_bootloader/src/XP-ETHERNET-TEST.xn:
--------------------------------------------------------------------------------
1 |
2 |
5 | Device
6 | XP-ETHERNET-TEST
7 |
8 |
9 | core stdcore[1]
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
--------------------------------------------------------------------------------
/experimental/app_pip_bootloader/src/main.xc:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2011, XMOS Ltd, All rights reserved
2 | // This software is freely distributable under a derivative of the
3 | // University of Illinois/NCSA Open Source License posted in
4 | // LICENSE.txt and at
5 |
6 | #include
7 | #include
8 | #include "smi.h"
9 | #include "mii_driver.h"
10 | #include "mii.h"
11 | #include "pipServer.h"
12 | #include "tcpApplication.h"
13 |
14 | #define PORT_ETH_FAKE XS1_PORT_8C
15 |
16 | #define PORT_ETH_RST_N XS1_PORT_4C
17 |
18 | mii_interface_t mii =
19 | {
20 | XS1_CLKBLK_1,
21 | XS1_CLKBLK_2,
22 |
23 | PORT_ETH_RXCLK,
24 | PORT_ETH_RXER,
25 | PORT_ETH_RXD,
26 | PORT_ETH_RXDV,
27 |
28 | PORT_ETH_TXCLK,
29 | PORT_ETH_TXEN,
30 | PORT_ETH_TXD,
31 |
32 | PORT_ETH_FAKE,
33 | };
34 |
35 | #ifdef PORT_ETH_RST_N
36 | out port p_mii_resetn = PORT_ETH_RST_N;
37 | smi_interface_t smi = { 0x1F, PORT_ETH_MDIO, PORT_ETH_MDC };
38 | #else
39 | smi_interface_t smi = { 0x1F, PORT_ETH_RST_N_MDIO, PORT_ETH_MDC };
40 | #endif
41 |
42 | clock clk_smi = XS1_CLKBLK_5;
43 |
44 | int main(void) {
45 | streaming chan tcpApps[1];
46 | streaming chan udpApps[1];
47 |
48 | pipServer(clk_smi, p_mii_resetn, smi, mii, tcpApps, udpApps);
49 | return 0;
50 | }
51 |
--------------------------------------------------------------------------------
/experimental/app_pip_bootloader/src/pip_conf.h:
--------------------------------------------------------------------------------
1 | #define PIP_DHCP_DONT_WAIT
2 | #define PIP_TFTP
3 |
4 | #define PIP_ETHRX_WORDS 800
5 | #define PIP_ETHTX_WORDS 200
6 |
--------------------------------------------------------------------------------
/experimental/app_pip_test/.project:
--------------------------------------------------------------------------------
1 | app_pip_test com.xmos.cdt.core.ModulePathBuilder org.eclipse.cdt.managedbuilder.core.genmakebuilder clean,full,incremental, ?children? ?name?=outputEntries\|?children?=?name?=entry\\\\|\\|\|| ?name? org.eclipse.cdt.make.core.append_environment true org.eclipse.cdt.make.core.buildArguments CONFIG=Debug org.eclipse.cdt.make.core.buildCommand xmake org.eclipse.cdt.make.core.cleanBuildTarget clean org.eclipse.cdt.make.core.contents org.eclipse.cdt.make.core.activeConfigSettings org.eclipse.cdt.make.core.enableAutoBuild false org.eclipse.cdt.make.core.enableCleanBuild true org.eclipse.cdt.make.core.enableFullBuild true org.eclipse.cdt.make.core.stopOnError true org.eclipse.cdt.make.core.useDefaultBuildCmd false org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder full,incremental, org.eclipse.cdt.core.cnature org.eclipse.cdt.managedbuilder.core.managedBuildNature org.eclipse.cdt.managedbuilder.core.ScannerConfigNature com.xmos.cdt.core.XdeProjectNature
--------------------------------------------------------------------------------
/experimental/app_pip_test/.xproject:
--------------------------------------------------------------------------------
1 | sc_xtcpXM-000074-SW3.0.0rc1
--------------------------------------------------------------------------------
/experimental/app_pip_test/Makefile:
--------------------------------------------------------------------------------
1 | TARGET = XP-DSC-BLDC
2 | # TARGET = XP-MC-CTRL-L2
3 |
4 | APP_NAME =
5 | XCC_FLAGS = -Os -g -report -save-temps -lxscope
6 | USED_MODULES = module_pip module_ethernet module_otp_board_info module_ethernet_board_support
7 |
8 | # This change to the module path is so that this application can be in the
9 | # tests sub-directory in it's git repo
10 | ifeq ($(notdir $(abspath ..)),experimental)
11 | PATHSEP = $(if $(findstring Windows, $(OS))$(findstring WINDOWS,$(OS)),;,:)
12 | XMOS_MODULE_PATH := $(XMOS_MODULE_PATH)$(PATHSEP)../../..
13 | endif
14 |
15 |
16 | #=============================================================================
17 | # The following part of the Makefile includes the common build infrastructure
18 | # for compiling XMOS applications. You should not need to edit below here.
19 |
20 | XMOS_MAKE_PATH ?= ../..
21 | include $(XMOS_MAKE_PATH)/xcommon/module_xcommon/build/Makefile.common
22 |
--------------------------------------------------------------------------------
/experimental/app_pip_test/src/pip_conf.h:
--------------------------------------------------------------------------------
1 | #define PIP_DHCP_DONT_WAIT
2 | #define PIP_ICMP
3 | #define PIP_GATEWAY
4 | #define PIP_LINK_LOCAL
5 | #define PIP_TCP_CONNECT 2 // Two connections for testing.
6 | #define PIP_DEBUG_TCP 10
7 | #define PIP_DEBUG_TIMER
8 |
9 | #define PIP_TCP_CHANNELS 1 // At most one application
10 | #define PIP_UDP_CHANNELS 1 // At most one application
11 |
--------------------------------------------------------------------------------
/experimental/module_pip/.makefile:
--------------------------------------------------------------------------------
1 | all:
2 | @echo "** Module only - only builds as part of application **"
3 |
4 |
5 | clean:
6 | @echo "** Module only - only builds as part of application **"
7 |
8 |
9 |
--------------------------------------------------------------------------------
/experimental/module_pip/.project:
--------------------------------------------------------------------------------
1 | module_pip com.xmos.cdt.core.ModulePathBuilder org.eclipse.cdt.managedbuilder.core.genmakebuilder clean,full,incremental, ?children? ?name?=outputEntries\|?children?=?name?=entry\\\\|\\|\|| ?name? org.eclipse.cdt.make.core.append_environment true org.eclipse.cdt.make.core.buildArguments CONFIG=Debug org.eclipse.cdt.make.core.buildCommand xmake org.eclipse.cdt.make.core.cleanBuildTarget clean org.eclipse.cdt.make.core.contents org.eclipse.cdt.make.core.activeConfigSettings org.eclipse.cdt.make.core.enableAutoBuild false org.eclipse.cdt.make.core.enableCleanBuild true org.eclipse.cdt.make.core.enableFullBuild true org.eclipse.cdt.make.core.stopOnError true org.eclipse.cdt.make.core.useDefaultBuildCmd false org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder full,incremental, org.eclipse.cdt.core.cnature org.eclipse.cdt.managedbuilder.core.managedBuildNature org.eclipse.cdt.managedbuilder.core.ScannerConfigNature com.xmos.cdt.core.XdeProjectNature
--------------------------------------------------------------------------------
/experimental/module_pip/.xproject:
--------------------------------------------------------------------------------
1 | sc_xtcpXM-000074-SW3.0.0rc1
--------------------------------------------------------------------------------
/experimental/module_pip/module_build_info:
--------------------------------------------------------------------------------
1 | OPTIONAL_HEADERS += pip_conf.h
2 |
3 | MODULE_XCC_FLAGS = $(XCC_FLAGS) -Os -Wall -g
4 | XCC_FLAGS_toplevel.xc = $(XCC_FLAGS) -O0 -Wall -g
5 |
--------------------------------------------------------------------------------
/experimental/module_pip/src/arp.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2011, XMOS Ltd, All rights reserved
2 | // This software is freely distributable under a derivative of the
3 | // University of Illinois/NCSA Open Source License posted in
4 | // LICENSE.txt and at
5 |
6 | #define ARPENTRIES 10
7 |
8 | struct arp {
9 | unsigned int ipAddress;
10 | unsigned char macAddr[8]; // last two bytes are flags
11 | };
12 |
13 | extern struct arp pipArpTable[ARPENTRIES];
14 |
15 |
16 | /** Function to innitialise ARP. To be called prior to any of the above
17 | * functions. Typically called from toplevel.
18 | */
19 | void pipInitARP();
20 |
21 | /** Function that deals with an incoming ARP packet.
22 | *
23 | * \param packet contains the packet data.
24 | *
25 | * \param offset points to the ARP header in the packet.
26 | */
27 | void pipIncomingARP(unsigned short packet[], unsigned offset);
28 |
29 | /** Function that is called to signal a timeout on ARP - typically to
30 | * remove some ARP entries. Called from timer.xc, set by pipInitARP() and
31 | * pipTimeOutARP().
32 | */
33 | void pipTimeOutARP();
34 |
35 | /** Function that creates an ARP packet.
36 | *
37 | * \param reply whether to generate a reply or request message.
38 | * Set to 0 for generating an ARP request.
39 | *
40 | * \param ipAddress IP address to which the ARP is targetted
41 | *
42 | * \param macAddress Ignored for a request, set to known hardware
43 | * address for a request.
44 | *
45 | * \param offset start index of address inside the macAddress
46 | * array
47 | */
48 | void pipCreateARP(unsigned reply, unsigned ipAddress, unsigned char macAddress[], unsigned offset);
49 |
50 | /** Function that stores an arp entry
51 | *
52 | * \param ipAddress IP address to which the ARP is targetted
53 | *
54 | * \param macAddress Ignored for a request, set to known hardware
55 | * address for a request.
56 | *
57 | * \param offset start index of address inside the macAddress
58 | * array
59 | */
60 | void pipARPStoreEntry(unsigned ipAddress, unsigned char macAddress[], unsigned offset);
61 |
--------------------------------------------------------------------------------
/experimental/module_pip/src/c.c:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2011, XMOS Ltd, All rights reserved
2 | // This software is freely distributable under a derivative of the
3 | // University of Illinois/NCSA Open Source License posted in
4 | // LICENSE.txt and at
5 |
6 | extern void pipIncomingEthernet(unsigned short[]);
7 |
8 | void pipIncomingEthernetC(int a) {
9 | pipIncomingEthernet((unsigned short *) a);
10 | }
11 |
--------------------------------------------------------------------------------
/experimental/module_pip/src/checksum.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2011, XMOS Ltd, All rights reserved
2 | // This software is freely distributable under a derivative of the
3 | // University of Illinois/NCSA Open Source License posted in
4 | // LICENSE.txt and at
5 |
6 | /** Function that computes a one's completement checksum over two 32-bit
7 | * values. Both values are assumed to be in host order (not network order).
8 | *
9 | * \param x first 32-bit value
10 | *
11 | * \param y second 32-bit value
12 | *
13 | * \returns a 16-bit value which is the ones complement checksum, suitable
14 | * for passing to onesChecksum(). This is a value in host-order.
15 | */
16 | unsigned int onesAdd(unsigned int x, unsigned int y);
17 |
18 | /** Function that computes a one's complement checksum over a section of data.
19 | *
20 | * \param sum initial checksum, typically zero or the checksum value of a
21 | * pseudo header (TCP & UDP). The sum may be a 32-bit value,
22 | * but must be in host-order.
23 | *
24 | * \param data array of data over which to compute the checksum. The data array
25 | * is assumed to be in network order.
26 | *
27 | * \param begin index of first entry of array.
28 | *
29 | * \param lengthInBytes Number of bytes over which to compute checksum.
30 | *
31 | * \returns the checksum in network order, xored with 0xffff. Possible
32 | * values are in the range 0x0001-0xffff (0x0000 is reserved for no checksum)
33 | */
34 | unsigned int onesChecksum(unsigned int sum, unsigned short data[], int begin, int lengthInBytes);
35 |
--------------------------------------------------------------------------------
/experimental/module_pip/src/checksum.xc:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2011, XMOS Ltd, All rights reserved
2 | // This software is freely distributable under a derivative of the
3 | // University of Illinois/NCSA Open Source License posted in
4 | // LICENSE.txt and at
5 |
6 | #include
7 | #include
8 | #include
9 | #include "config.h"
10 | #include "checksum.h"
11 |
12 | static int onesReduce(unsigned int sum, int carry) {
13 | sum = (sum & 0xffff) + (sum >> 16) + carry;
14 | return (sum & 0xffff) + (sum >> 16);
15 | }
16 |
17 | unsigned onesAdd(unsigned int x, unsigned int y) {
18 | unsigned int carry, sum;
19 | asm("ladd %0,%1,%2,%3,%4" : "=r" (carry), "=r" (sum) : "r" (x), "r" (y), "r" (0));
20 | return onesReduce(sum, carry);
21 | }
22 |
23 | unsigned onesChecksum(unsigned int sum, unsigned short data[], int begin, int lengthInBytes) {
24 | int i;
25 | for(i = begin; i < begin + (lengthInBytes>>1); i++) {
26 | sum += byterev(data[i]) >> 16;
27 | }
28 | if (lengthInBytes & 1) {
29 | sum += (data, unsigned char[])[2*i] << 8;
30 | }
31 | sum = onesReduce(sum, 0);
32 | return byterev((~sum) & 0xffff) >> 16;
33 | }
34 |
--------------------------------------------------------------------------------
/experimental/module_pip/src/config.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2011, XMOS Ltd, All rights reserved
2 | // This software is freely distributable under a derivative of the
3 | // University of Illinois/NCSA Open Source License posted in
4 | // LICENSE.txt and at
5 |
6 | /*
7 | * This include file should contain the dependencies between all defines
8 | * (for example DHCP requires UDP requires IPV4 requires ARP), and the
9 | * defaults for undefined defines for all defines.
10 | */
11 |
12 | #ifdef __pip_conf_h_exists__
13 | #include "pip_conf.h"
14 | #endif
15 |
16 | #ifdef PIP_DEBUG_TCP
17 | #ifndef PIP_ICMP
18 | #define PIP_ICMP 1
19 | #endif
20 | #endif
21 |
22 | // Application level
23 |
24 | #ifdef PIP_TFTP
25 | #define PIP_UDP 1
26 | #endif
27 |
28 | #ifdef PIP_DHCP_DONT_WAIT
29 | #define PIP_DHCP 1
30 | #endif
31 |
32 | #ifdef PIP_DHCP
33 | #define PIP_UDP 1
34 | #endif
35 |
36 | #ifdef PIP_LINK_LOCAL
37 | #define PIP_ARP 1
38 | #endif
39 |
40 |
41 |
42 | // TCP/UDP Level
43 |
44 | #ifdef PIP_TCP_CONNECT
45 | #define PIP_TCP PIP_TCP_CONNECT
46 | #endif
47 |
48 | #ifdef PIP_TCP
49 | #define PIP_IPV4 1
50 | #endif
51 |
52 | #ifdef PIP_UDP
53 | #define PIP_IPV4 1
54 | #endif
55 |
56 | #ifdef PIP_ICMP
57 | #define PIP_IPV4 1
58 | #endif
59 |
60 |
61 |
62 | // IP level
63 |
64 | #ifdef PIP_IPV4
65 | #define PIP_ARP 1
66 | #endif
67 |
68 |
69 |
70 | #ifndef PIP_TCP_BUFSIZE_RX
71 | #define PIP_TCP_BUFSIZE_RX 512
72 | #endif
73 |
74 | #ifndef PIP_TCP_BUFSIZE_TX
75 | #define PIP_TCP_BUFSIZE_TX 512
76 | #endif
77 |
78 | #if (PIP_TCP_BUFSIZE_RX & (PIP_TCP_BUFSIZE_RX - 1)) != 0
79 | #error "PIP_TCP_BUFSIZE_RX must be a power of 2"
80 | #endif
81 |
82 | #if (PIP_TCP_BUFSIZE_TX & (PIP_TCP_BUFSIZE_TX - 1)) != 0
83 | #error "PIP_TCP_BUFSIZE_TX must be a power of 2"
84 | #endif
85 |
86 | #ifndef PIP_UDP_CHANNELS
87 | #define PIP_UDP_CHANNELS 0
88 | #endif
89 |
90 |
91 | #ifndef PIP_ETHTX_WORDS
92 | #define PIP_ETHTX_WORDS 200
93 | #endif
94 |
95 | #ifndef PIP_ETHRX_WORDS
96 | #define PIP_ETHRX_WORDS 3200
97 | #endif
98 |
99 |
100 | #ifdef PIP_ARP
101 | #if PIP_ETHTX_WORDS < 22
102 | #define PIP_ETHTX_WORDS 22
103 | #warning "Warning, PIP_ETHTX_WORDS increased to 22 to fit ARP"
104 | #endif
105 | #endif
106 |
107 | #ifdef PIP_DHCP
108 | #if PIP_ETHTX_WORDS < 64
109 | #define PIP_ETHTX_WORDS 64
110 | #warning "Warning, PIP_ETHTX_WORDS increased to 64 to fit DHCP"
111 | #endif
112 | #endif
113 |
114 | #ifdef PIP_DHCP
115 | #if PIP_ETHTX_WORDS < ((62+PIP_TCP_BUFSIZE_TX)/4)
116 | #define PIP_ETHTX_WORDS ((62+PIP_TCP_BUFSIZE_TX)/4)
117 | #warning "Warning, PIP_ETHTX_WORDS increased to fit TCP"
118 | #endif
119 | #endif
120 |
--------------------------------------------------------------------------------
/experimental/module_pip/src/dhcp.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2011, XMOS Ltd, All rights reserved
2 | // This software is freely distributable under a derivative of the
3 | // University of Illinois/NCSA Open Source License posted in
4 | // LICENSE.txt and at
5 |
6 | /** Function that initialises the DHCP client. To be called prior to any
7 | * other function. Usually called from toplevel.
8 | */
9 | void pipInitDHCP();
10 |
11 | /** Function that processes an incoming DHCP packet. May trigger an
12 | * outgoing packet. Normally called from IPv4 layer.
13 | *
14 | * \param packet packet data.
15 | *
16 | * \param srcIP source IP address according to IP header.
17 | *
18 | * \param dstIP destination IP address according to IP header.
19 | *
20 | * \param offset index in packet array where the first byte of the
21 | * DHCP packet resides.
22 | *
23 | * \param length length of the total packet in bytes.
24 | */
25 | void pipIncomingDHCP(unsigned short packet[], unsigned srcIP, unsigned dstIP, int offset, int length);
26 |
27 | /** Function that creates a DHCP message.
28 | *
29 | * \param firstMessage flag to indicate that this is the first DHCP message
30 | * (DHCP-DISCOVER), set to 0 to indicate that it is a
31 | * DHCP-REQUEST.
32 | *
33 | * \param proposedIP The suggested IP address - set to 0 if no IP address
34 | * is suggested.
35 | *
36 | * \param serverIP The server IP address - set to 0 if not known.
37 | */
38 | void pipCreateDHCP(int firstMessage,
39 | unsigned proposedIP,
40 | unsigned serverIP);
41 |
42 | /** Function that is called to signal a timeout on DHCP timer T2. Called
43 | * from timer.xc, set by init and incoming.
44 | */
45 | void pipTimeOutDHCPT1();
46 |
47 | /** Function that is called to signal a timeout on DHCP timer T2. Called
48 | * from timer.xc, set by init and incoming.
49 | */
50 | void pipTimeOutDHCPT2();
51 |
--------------------------------------------------------------------------------
/experimental/module_pip/src/ethernet.xc:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2011, XMOS Ltd, All rights reserved
2 | // This software is freely distributable under a derivative of the
3 | // University of Illinois/NCSA Open Source License posted in
4 | // LICENSE.txt and at
5 |
6 | #include
7 | #include "config.h"
8 | #include "pip_ethernet.h"
9 | #include "ipv4.h"
10 | #include "arp.h"
11 | #include "tx.h"
12 |
13 | unsigned char myMacAddress[6] = {0x00, 0x7F, 0xD3, 0x11, 0x22, 0x33};
14 |
15 | void pipIncomingEthernet(unsigned short packet[]) {
16 | int offset = 6;
17 | int ethType;
18 |
19 | do {
20 | ethType = packet[offset]; // Ethernet type in network order - swapped
21 | offset++;
22 | } while (ethType == 0x0081);
23 |
24 | #if defined(PIP_IPV4)
25 | if (ethType == PIP_ETHTYPE_IPV4_REV) {
26 | pipIncomingIPv4(packet, offset);
27 | return;
28 | }
29 | #endif
30 |
31 | #if defined(PIP_ARP)
32 | if (ethType == PIP_ETHTYPE_ARP_REV) {
33 | pipIncomingARP(packet, offset);
34 | return;
35 | }
36 | #endif
37 |
38 | }
39 |
40 | void pipOutgoingEthernet(unsigned char macDest[], int offset, int revType) {
41 | txData(0, macDest, offset, 6); // Set ETH mac dst
42 | txData(3, myMacAddress, 0, 6); // Set ETH mac src
43 | txShort(6, revType); // Fill in type.
44 | }
45 |
--------------------------------------------------------------------------------
/experimental/module_pip/src/icmp.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2011, XMOS Ltd, All rights reserved
2 | // This software is freely distributable under a derivative of the
3 | // University of Illinois/NCSA Open Source License posted in
4 | // LICENSE.txt and at
5 |
6 | /** Function that processes an incoming ICMP packet. The ICMP header starts
7 | * at the given offset in the packet.
8 | *
9 | * \param packet packetdata.
10 | *
11 | * \param ipOffset Index of first element in the array that contains the IP header.
12 | *
13 | * \param icmpOffset Index of first element in the array that contains the ICMP header.
14 | *
15 | * \param srcIP Source IP address from IP header, in host order.
16 | *
17 | * \param dstIP Destination IP address from IP header (the address of this
18 | * host if all is well, or some sort of multicast address), in host order.
19 | *
20 | * \param length Number of bytes in ICMP part of packet.
21 | */
22 | void pipIncomingICMP(unsigned short packet[], int ipOffset, int icmpOffset, int srcIP, int dstIP, int length);
23 |
24 | /** Function that generates a ping.
25 | *
26 | * \param dstIP Destination IP address to send the PING to.
27 | *
28 | * \param sequence Sequence number of the ping, top 16 bits are ID.
29 | */
30 | void pipOutgoingICMPPing(unsigned dstIP, int sequence);
31 |
--------------------------------------------------------------------------------
/experimental/module_pip/src/icmp.xc:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2011, XMOS Ltd, All rights reserved
2 | // This software is freely distributable under a derivative of the
3 | // University of Illinois/NCSA Open Source License posted in
4 | // LICENSE.txt and at
5 |
6 | #include
7 | #include
8 | #include "config.h"
9 | #include "icmp.h"
10 | #include "pip_ethernet.h"
11 | #include "tx.h"
12 | #include "tcp.h"
13 | #include "ipv4.h"
14 | #include "checksum.h"
15 | #include "timer.h"
16 |
17 |
18 | // RFC 0792
19 |
20 | void pipIncomingICMP(unsigned short packet[], int ipOffset, int icmpOffset, int srcIP, int dstIP, int length) {
21 | int type = (packet, unsigned char[])[icmpOffset * 2];
22 | if (myIP != 0 && type == 8) { // Echo request (PING).
23 | // bounce message back with type = 0 (PONG), everything else is identical.
24 | // And swap srcIP and dstIP.
25 | txData(17, (packet, unsigned char[]), 34, length); // Copy contents of old packet
26 | txByte(icmpOffset*2, 0); // Set type to 'reply'.
27 | txShort(18, 0); // This could be simplified by patching old checksum rather than computing a new one.
28 | txShort(18, onesChecksum(0, (txbuf, unsigned short[]), 17, length));
29 | pipOutgoingIPv4(PIP_IPTYPE_ICMP, srcIP, length);
30 | #ifdef PIP_DEBUG_TCP
31 | pipDebugTCPPrint();
32 | #endif
33 | #ifdef PIP_DEBUG_TIMER
34 | pipPrintTimeOuts();
35 | #endif
36 | }
37 | }
38 |
39 | void pipOutgoingICMPPing(unsigned dstIP, int sequence) {
40 | int offset = 17;
41 | int length = 32 - offset;
42 | txShort(offset, 8); // Type 8: echo request; code 0.
43 | txShort(offset+1, 0); // Initial checksum
44 | txInt(offset + 2, byterev(sequence));
45 | for(int i = offset+4; i < offset + length; i++) {
46 | txShort(i, i);
47 | }
48 | txShort(offset + 1, onesChecksum(0, (txbuf, unsigned short[]), 17, length<<1));
49 | pipOutgoingIPv4(PIP_IPTYPE_ICMP, dstIP, length<<1);
50 | }
51 |
--------------------------------------------------------------------------------
/experimental/module_pip/src/igmp.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2011, XMOS Ltd, All rights reserved
2 | // This software is freely distributable under a derivative of the
3 | // University of Illinois/NCSA Open Source License posted in
4 | // LICENSE.txt and at
5 |
6 |
--------------------------------------------------------------------------------
/experimental/module_pip/src/ipv4.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2011, XMOS Ltd, All rights reserved
2 | // This software is freely distributable under a derivative of the
3 | // University of Illinois/NCSA Open Source License posted in
4 | // LICENSE.txt and at
5 |
6 | #define PIP_IPTYPE_TCP 0x06
7 | #define PIP_IPTYPE_UDP 0x11
8 | #define PIP_IPTYPE_ICMP 0x01
9 | #define PIP_IPTYPE_IGMP 0x02
10 |
11 | /** Function that deals with an incoming IPv4 packet. Normally called from the Ethernet layer.
12 | *
13 | * \param packet contains the packet data.
14 | *
15 | * \param offset points to the IPv4 header in the packet.
16 | */
17 |
18 | void pipIncomingIPv4(unsigned short packet[], int offset);
19 |
20 | /** Function that adds an IPv4 header to the outgoing packet. It needs the
21 | * ipType (one of the above defines), destination address and a length of
22 | * the datagram. Note that if no ARP entry is available for this packet,
23 | * then the packet shall be discarded and a ARP request shall be send
24 | * instead.
25 | *
26 | * \param ipType type of the IP packet to be transmitted. One of the
27 | * defines above.
28 | *
29 | * \param ipDst IP address of the destination, in normal order, i.e.
30 | * 192.168.1.1 is represented as 0xC0A80101
31 | *
32 | * \param length Number of bytes in the datagram.
33 | */
34 | void pipOutgoingIPv4(int ipType, unsigned ipDst, int length);
35 |
36 | /** Function that sets our IP address - called by dhcp.xc and linklocal.xc
37 | * to set the IP address once one has been established. Set router to 0 if
38 | * no router is available.
39 | *
40 | * \param proposedIP new IP address
41 | *
42 | * \param subnet new subnet mask
43 | *
44 | * \param router new gateway IP for traffic outside our subnet.
45 | */
46 | void pipAssignIPv4(unsigned proposedIP, unsigned subnet, unsigned router);
47 |
48 | /** Function that unsets our IP address - called by dhcp.xc when the lease
49 | * expires and the lease could not be renewed.
50 | */
51 | void pipUnassignIPv4();
52 |
53 | /** Variable that holds the current IP address; 0 if this node does not
54 | * have an IP address at present.
55 | */
56 | extern unsigned myIP;
57 |
58 | /** Variable that holds the current IP subnet.
59 | */
60 | extern unsigned mySubnetIP;
61 |
62 | /** Variable that holds the current gateway for traffic to other subnets; 0
63 | * if this node does not have a router.
64 | */
65 | extern unsigned myRouterIP;
66 |
--------------------------------------------------------------------------------
/experimental/module_pip/src/linklocal.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2011, XMOS Ltd, All rights reserved
2 | // This software is freely distributable under a derivative of the
3 | // University of Illinois/NCSA Open Source License posted in
4 | // LICENSE.txt and at
5 |
6 | /** Function that initialises the Link Local client. To be called prior to
7 | * any other function. Usually called from dhcp or toplevel (depending on
8 | * whether DHCP is enabled)
9 | */
10 | void pipInitLinkLocal();
11 |
12 | /** Function that is called to signal a timeout on the Link Local timer. Called
13 | * from timer.xc, set by init and incoming.
14 | */
15 | void pipTimeOutLinkLocal();
16 |
17 | /** Function that is called to determine whether an incoming ARP packet is
18 | * for the link local protocol. This function returns 1 if it is, and
19 | * should act on it, and 0 if it is not.
20 | *
21 | * \param oper either 256 (request) or 512 (reply)
22 | *
23 | * \param ipAddress the address in the ARP packet.
24 | *
25 | * \param macAddress the mac address in the ARP packet
26 | *
27 | * \param offset the index in the mac address array where the mac address is stored
28 | *
29 | * \returns a boolean stating that this ARP packet was for the link local layer.
30 | */
31 | int pipIncomingLinkLocalARP(int oper, int ipAddress, unsigned char macAddress[], int offset);
32 |
33 | /** Function that disables the Link Local client.
34 | */
35 | void pipDisableLinkLocal();
36 |
37 |
--------------------------------------------------------------------------------
/experimental/module_pip/src/pipServer.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2011, XMOS Ltd, All rights reserved
2 | // This software is freely distributable under a derivative of the
3 | // University of Illinois/NCSA Open Source License posted in
4 | // LICENSE.txt and at
5 |
6 | /** Function that is called to start both the TCP/UDP/IP stack and the
7 | * two-thread Ethernet stack. This function requires two threads: one for
8 | * MII handling, and the other one for TCP/UDP/IP.
9 | *
10 | * \param clk_smi clock block for the SMI port
11 | *
12 | * \param p_mii_resetn port for resetting
13 | *
14 | * \param smi description of SMI ports
15 | *
16 | * \param mii description of MII ports
17 | *
18 | * \param tcpApps array of channels to each TCP application. This array
19 | * must have PIP_TCP_CHANNELS entries.
20 | *
21 | * \param udpApps array of channels to each UDP application. This array
22 | * must have PIP_UDP_CHANNELS entries.
23 | */
24 | void pipServer(clock clk_smi,
25 | out port ?p_mii_resetn,
26 | smi_interface_t &smi,
27 | mii_interface_t &mii,
28 | streaming chanend tcpApps[],
29 | streaming chanend udpApps[]
30 | );
31 |
32 | extern unsigned char myMacAddress[6];
33 |
--------------------------------------------------------------------------------
/experimental/module_pip/src/pip_ethernet.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2011, XMOS Ltd, All rights reserved
2 | // This software is freely distributable under a derivative of the
3 | // University of Illinois/NCSA Open Source License posted in
4 | // LICENSE.txt and at
5 |
6 | /** The 16-bit value that represents the ethernet type for an IPV4 packet,
7 | * in reverse byte order.
8 | */
9 | #define PIP_ETHTYPE_IPV4_REV 0x0008
10 |
11 | /** The 16-bit value that represents the ethernet type for an ARP packet,
12 | * in reverse byte order.
13 | */
14 | #define PIP_ETHTYPE_ARP_REV 0x0608
15 |
16 | /** Function that processes an incoming Ethernet packet.
17 | *
18 | * \param packet packetdata.
19 | */
20 | void pipIncomingEthernet(unsigned short packet[]);
21 | void pipIncomingEthernetC(int a);
22 |
23 |
24 |
25 | /** Function that completes the outgoing packet ready to go onto the Ethernet cable.
26 | * It sets the source and destination mac addresses, and the type of the packet.
27 | *
28 | * \param macDest array containing the destination mac address.
29 | *
30 | * \param offset the index in the array where the mac address resides.
31 | *
32 | * \param revType the type of the packet, in reverse byte order. Use one of
33 | * the predefined types above.
34 | */
35 | void pipOutgoingEthernet(unsigned char macDest[], int offset, int revType);
36 |
37 |
38 | extern unsigned char myMacAddress[6];
39 |
--------------------------------------------------------------------------------
/experimental/module_pip/src/rx.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2011, XMOS Ltd, All rights reserved
2 | // This software is freely distributable under a derivative of the
3 | // University of Illinois/NCSA Open Source License posted in
4 | // LICENSE.txt and at
5 |
6 | /** Function that gets an integer from a byte location in a packet. Can
7 | * have any alignment.
8 | */
9 | extern unsigned getIntUnaligned(unsigned short packet[], int offset);
10 |
--------------------------------------------------------------------------------
/experimental/module_pip/src/rx.xc:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2011, XMOS Ltd, All rights reserved
2 | // This software is freely distributable under a derivative of the
3 | // University of Illinois/NCSA Open Source License posted in
4 | // LICENSE.txt and at
5 |
6 | #include "rx.h"
7 | #include "config.h"
8 |
9 | unsigned getIntUnaligned(unsigned short packet[], int offset) {
10 | unsigned x = (packet, unsigned char[])[offset] << 24 |
11 | (packet, unsigned char[])[offset+1] << 16 |
12 | (packet, unsigned char[])[offset+2] << 8 |
13 | (packet, unsigned char[])[offset+3] << 0;
14 | return x;
15 | }
16 |
--------------------------------------------------------------------------------
/experimental/module_pip/src/tcpApplication.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2011, XMOS Ltd, All rights reserved
2 | // This software is freely distributable under a derivative of the
3 | // University of Illinois/NCSA Open Source License posted in
4 | // LICENSE.txt and at
5 |
6 | /** Function that an application can call to wait and accept a connection
7 | * on a TCP stream. The streams are pre-allocated and numbered.
8 | *
9 | * \param stack Channel that connects to the TCP server.
10 | *
11 | * \param connection Number of the connection to accept on.
12 | *
13 | */
14 | int pipApplicationAccept(streaming chanend stack, unsigned connection);
15 |
16 | /** Function that an application can call to wait and open a connection
17 | * on a TCP stream. The streams are pre-allocated and numbered.
18 | *
19 | * \param stack Channel that connects to the TCP server.
20 | *
21 | * \param connection Number to place the open connection in.
22 | *
23 | * \param remoteIP IP address of host as an integer in host format eg,
24 | * 192.168.1.3 is 0xC0A80103
25 | *
26 | * \param remotePort Port number to connect to (0..65535)
27 | *
28 | * \param localPort Port number to use locally.
29 | *
30 | */
31 | int pipApplicationConnect(streaming chanend stack, unsigned connection, int remoteIP, int remotePort, int localPort);
32 |
33 |
34 | /** Function that an application can call close a TCP stream. The streams
35 | * are pre-allocated and numbered.
36 | *
37 | * \param stack Channel that connects to the TCP server.
38 | *
39 | * \param connection Number of the connection to close.
40 | *
41 | */
42 | void pipApplicationClose(streaming chanend stack, unsigned connection);
43 |
44 | /** Function that an application can call to read from a TCP stream. The streams
45 | * are pre-allocated and numbered. The function blocks if there is no data available,
46 | * otherwise up to the maximum number of bytes are returned.
47 | *
48 | * \param stack Channel that connects to the TCP server.
49 | *
50 | * \param connection Number of the connection to read from.
51 | *
52 | * \param buffer Place to store the received data.
53 | *
54 | * \param maxBytes Maximum number of bytes to read.
55 | *
56 | */
57 | int pipApplicationRead(streaming chanend stack, unsigned connection,
58 | unsigned char buffer[], unsigned maxBytes);
59 |
60 | /** Function that an application can call to write to a TCP stream. The
61 | * streams are pre-allocated and numbered. The function blocks until either
62 | * all data is submitted for transmission, or until the link is shutdown.
63 | *
64 | * \param stack Channel that connects to the TCP server.
65 | *
66 | * \param connection Number of the connection to write to.
67 | *
68 | * \param buffer Array that holds the data to be transmitted.
69 | *
70 | * \param nBytes Number of bytes to write.
71 | *
72 | * \returns The number of bytes transmitted. Normally nBytes, unless the
73 | * TCP stream was prematurely closed, in which case a partial number is returned.
74 | */
75 | int pipApplicationWrite(streaming chanend stack, unsigned connection,
76 | unsigned char buffer[], unsigned nBytes);
77 |
78 |
79 |
--------------------------------------------------------------------------------
/experimental/module_pip/src/tftp.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2011, XMOS Ltd, All rights reserved
2 | // This software is freely distributable under a derivative of the
3 | // University of Illinois/NCSA Open Source License posted in
4 | // LICENSE.txt and at
5 |
6 | /** Function that initialises the TFTP client. To be called prior to any
7 | * other function. Usually called from toplevel.
8 | */
9 | void pipInitTFTP();
10 |
11 | /** Function that processes an incoming TFTP packet. May trigger an
12 | * outgoing packet. Normally called from IPv4 layer.
13 | *
14 | * \param packet packet data.
15 | *
16 | * \param srcIP source IP address according to IP header.
17 | *
18 | * \param dstIP destination IP address according to IP header.
19 | *
20 | * \param srcPort source port according to IP header.
21 | *
22 | * \param dstPort destination port according to IP header.
23 | *
24 | * \param offset index in packet array where the first byte of the
25 | * TFTP packet resides.
26 | *
27 | * \param length length of the total packet in bytes.
28 | */
29 | void pipIncomingTFTP(unsigned short packet[], unsigned srcIP, unsigned dstIP, unsigned srcPort, int offset, int length);
30 |
31 | /** Function that is called to signal a timeout on TFTP timer. Called
32 | * from timer.xc, set by init and incoming.
33 | */
34 | void pipTimeOutTFTP();
35 |
36 | extern unsigned pipPortTFTP;
37 | extern unsigned pipIpTFTP;
38 |
39 | #define TFTP_SERVER_PORT 69
40 |
--------------------------------------------------------------------------------
/experimental/module_pip/src/timer.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2011, XMOS Ltd, All rights reserved
2 | // This software is freely distributable under a derivative of the
3 | // University of Illinois/NCSA Open Source License posted in
4 | // LICENSE.txt and at
5 |
6 |
7 | #define PIP_DHCP_TIMER_T1 0
8 | #define PIP_DHCP_TIMER_T2 1
9 | #define PIP_ARP_TIMER 2
10 | #define PIP_TCP_TIMER_TIMEWAIT 3
11 | #define PIP_TFTP_TIMER 4
12 | #define PIP_LINK_LOCAL_TIMER 5
13 |
14 | #define PIP_FUZZ_NONE 0
15 | #define PIP_FUZZ_1MS 0x0001FFFF
16 | #define PIP_FUZZ_10MS 0x000FFFFF
17 | #define PIP_FUZZ_100MS 0x007FFFFF
18 | #define PIP_FUZZ_1S 0x07FFFFFF
19 | #define PIP_FUZZ_10S 0x3FFFFFFF
20 |
21 | /** Select function to be called in the main top level select loop. It
22 | * implements timers for all other modules, and calls time-out functions
23 | * for DHCP, TCP, ARP, etc.
24 | *
25 | * \param t timer on which to implement the main time out.
26 | */
27 | select pipTimeOut(timer t);
28 |
29 | /** Function to set a timeout. The timerNumber must be one of the
30 | * preallocated timer values defined above. Delay is given in secs and in
31 | * 100 Mhz reference ticks. Maximum time out is 40 years; maximum up time
32 | * of a product is 1500 years.
33 | *
34 | * \param timerNumber integer constant denoting which time out to set.
35 | * The function to call is hardcoded in the timer.
36 | *
37 | * \param secsDelay Number of seconds until timer expires.
38 | *
39 | * \param tenNSDelay Number of 10 ns ticks until timer expires
40 | * (should be less than 100000000).
41 | *
42 | * \param fuzz Random delay to be added. Set to zero for no random delay,
43 | * otherwise should be a bit mask. For each '1' in the
44 | * bit mask a random delay will be added in the
45 | * corresponding bit position on tenNSDelay. Use one of
46 | * the preset bit masks PIP_FUZZ_... defined earlier
47 | * for random delays of 1ms to 10s.
48 | */
49 | void pipSetTimeOut(int timerNumber, int secsDelay, int tenNSdelay, int fuzz);
50 |
51 | /** Function to reset a timeout. The timerNumber must be one of the
52 | * preallocated timer values defined above.
53 | *
54 | * \param timerNumber integer constant denoting which time out to reset.
55 | * The function to call is hardcoded in the timer.
56 | */
57 | void pipResetTimeOut(int timerNumber);
58 |
59 | void pipPrintTimeOuts();
60 |
--------------------------------------------------------------------------------
/experimental/module_pip/src/tx.xc:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2011, XMOS Ltd, All rights reserved
2 | // This software is freely distributable under a derivative of the
3 | // University of Illinois/NCSA Open Source License posted in
4 | // LICENSE.txt and at
5 |
6 |
7 | #include
8 | #include
9 | #include
10 | #include "config.h"
11 | #include "mii_driver.h"
12 | #include "mii.h"
13 | #include "mii_client.h"
14 | #include "tx.h"
15 |
16 | short txbuf[PIP_ETHTX_WORDS*2];
17 | static int txbufLength = 0;
18 |
19 | void doTx(chanend cOut) {
20 | if (txbufLength != 0) {
21 | if (txbufLength < 64) {
22 | txbufLength = 64;
23 | }
24 | mii_out_packet(cOut, (txbuf, int[]), 0, txbufLength);
25 | mii_out_packet_done(cOut);
26 | txbufLength = 0;
27 | }
28 | }
29 |
30 | void adjustBufLength(int offset) {
31 | if (offset > txbufLength) {
32 | txbufLength = offset;
33 | }
34 | }
35 |
36 | void txInt(int offset, int x) {
37 | txbuf[offset] = x;
38 | txbuf[offset+1] = x >> 16;
39 | adjustBufLength(offset * 2 + 4);
40 | }
41 |
42 | void txShort(int offset, int x) {
43 | txbuf[offset] = x;
44 | adjustBufLength(offset * 2 + 2);
45 | }
46 |
47 | void txShortRev(int offset, int x) {
48 | txShort(offset, ((unsigned)byterev(x))>>16);
49 | }
50 |
51 | void txByte(int offset, int x) {
52 | (txbuf, unsigned char[])[offset] = x;
53 | adjustBufLength(offset + 1);
54 | }
55 |
56 | void txData(int offset, char data[], int dataOffset, int n) {
57 | for(int i = 0; i < n; i++) {
58 | (txbuf, unsigned char[])[i+offset*2] = data[i+dataOffset];
59 | }
60 | adjustBufLength(offset * 2 + n);
61 | }
62 |
63 | void txShortZeroes(int offset, int len) {
64 | for(int i = 0; i < len; i++) {
65 | txbuf[offset+i] = 0;
66 | }
67 | adjustBufLength((offset + len) * 2);
68 | }
69 |
70 | void txClear() {
71 | txbufLength = 0;
72 | }
73 |
74 | void txPrint() {
75 | for(int i = 0; i < txbufLength; i++) {
76 | printhex((txbuf, unsigned char[])[i]);
77 | printstr(" ");
78 | if ((i & 15) == 15) {
79 | printstr("\n");
80 | }
81 | }
82 | printstr("\n");
83 | }
84 |
85 |
--------------------------------------------------------------------------------
/experimental/module_pip/src/udp.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2011, XMOS Ltd, All rights reserved
2 | // This software is freely distributable under a derivative of the
3 | // University of Illinois/NCSA Open Source License posted in
4 | // LICENSE.txt and at
5 |
6 | /** Function that processes an incoming UDP packet. The UDP header starts
7 | * at the given offset in the packet. The source and destination IP
8 | * addresses are passed to enable the checksum computation and for
9 | * application level software.
10 | *
11 | * \param packet packetdata.
12 | *
13 | * \param offset Index of first element in the array that contains the UDP header.
14 | *
15 | * \param srcIP Source IP address from IP header, in host order.
16 | *
17 | * \param dstIP Destination IP address from IP header (the address of this
18 | * host if all is well, or some sort of multicast address), in host order.
19 | */
20 | void pipIncomingUDP(unsigned short packet[], unsigned offset, unsigned srcIP, unsigned dstIP);
21 |
22 | /** Function that prepends a UDP header in front of the current packet. The
23 | * UDP header will transmit to the given IP address and port, from the
24 | * given source port. The UDP packet contains length data bytes (note this
25 | * excludes the header, so pass 0 for an empty datagram). Note that if no
26 | * ARP entry is present, the current packet id destroyed and an ARP packet
27 | * is sent instead.
28 | *
29 | * \param dstIP Destination IP address, in host order.
30 | *
31 | * \param srcPort Port number where the data came from
32 | *
33 | * \param dstPort Port number where the data goes to
34 | *
35 | * \param length number of bytes in the datagram
36 | */
37 | void pipOutgoingUDP(unsigned dstIP, unsigned srcPort, unsigned dstPort, unsigned length);
38 |
39 | /** Function to be called to process an application request to the UDP
40 | * stack. The streaming channel end connects to the application. This
41 | * function is to be called when a word has been input from the channel.
42 | *
43 | * \param app streaming channel that connects to the application program. A
44 | * two way protocol over this channel implements operations such
45 | * as read and write.
46 | *
47 | * \param cmd the word input from the channel.
48 | *
49 | * \param cOut channel to MII for transmitting packet.
50 | */
51 | void pipApplicationUDP(streaming chanend app, int cmd, chanend cOut);
52 |
53 | /** Value to send over the application channel to indicate a READ command;
54 | * to be followed by the local port number (a word), and the maximum number of
55 | * bytes (a word). Then input the actual number of bytes (a word) and then
56 | * input a stream of bytes as a series of data tokens.
57 | */
58 | #define PIP_UDP_READ 0
59 | /** Value to send over the application channel to indicate a WRITE command;
60 | * to be followed by the local port number (a word), the number of bytes to
61 | * be written (a word) and then a stream of bytes as a series of data
62 | * tokens.
63 | */
64 | #define PIP_UDP_WRITE 1
65 |
66 |
--------------------------------------------------------------------------------
/experimental/module_pip/src/udpApplication.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2011, XMOS Ltd, All rights reserved
2 | // This software is freely distributable under a derivative of the
3 | // University of Illinois/NCSA Open Source License posted in
4 | // LICENSE.txt and at
5 |
6 | /** Function to be called to read a UDP packet. There is no input buffering
7 | * on UDP when this interface is used - and when this function is not
8 | * called UDP traffic on this port will be lost.
9 | *
10 | * \param stack channel to the UDP stack
11 | *
12 | * \param buffer array to store the packet in
13 | *
14 | * \param start first location in the buffer to write into
15 | *
16 | * \param maxBytes maximum number of bytes to write into the buffer
17 | *
18 | * \param remoteIP the remote IP address is returned in this argument
19 | *
20 | * \param remotePort the remote port number is returned in this argument
21 | *
22 | * \param localPort the localPort to listen on.
23 | */
24 | int pipApplicationReadUDP(streaming chanend stack,
25 | unsigned char buffer[], unsigned start,
26 | unsigned maxBytes,
27 | unsigned int &remoteIP, unsigned int &remotePort,
28 | unsigned int localPort);
29 |
30 | /** Function to be called to write a UDP packet. Packets always originate
31 | * from the current IP address.
32 | *
33 | * \param stack channel to the UDP stack
34 | *
35 | * \param buffer array to read the packet from
36 | *
37 | * \param start first location in the buffer to read from
38 | *
39 | * \param maxBytes number of bytes to write into the packet. Note that this parameter must be less than the maximum outgoing packet size minus 42.
40 | *
41 | * \param remoteIP the remote IP address to send to
42 | *
43 | * \param remotePort the remote port number to send to
44 | *
45 | * \param localPort the localPort to supply to the other end
46 | */
47 | void pipApplicationWriteUDP(streaming chanend stack,
48 | unsigned char buffer[], unsigned start,
49 | unsigned maxBytes,
50 | unsigned int remoteIP, unsigned int remotePort,
51 | unsigned int localPort);
52 |
--------------------------------------------------------------------------------
/module_tftp/.makefile:
--------------------------------------------------------------------------------
1 | all:
2 | @echo "** Module only - only builds as part of application **"
3 |
4 |
5 | clean:
6 | @echo "** Module only - only builds as part of application **"
7 |
8 |
9 |
--------------------------------------------------------------------------------
/module_tftp/.xproject:
--------------------------------------------------------------------------------
1 | sc_xtcpXM-001955-SM3.2.1rc0
--------------------------------------------------------------------------------
/module_tftp/README.rst:
--------------------------------------------------------------------------------
1 |
2 | ================
3 |
4 | :scope:
5 | :description:
6 | :keywords:
7 | :boards:
8 |
9 | Basic TFTP (RFC 1350) Implementation
10 |
11 | This module implements a basic TFTP server that accepts a single Write Request
12 | connection only. It does not support any of the Option Extensions.
13 |
14 | It may be extended to cover a more general (non firmware upgrade) use-case.
15 |
--------------------------------------------------------------------------------
/module_tftp/module_build_info:
--------------------------------------------------------------------------------
1 | # You can set flags specifically for your module by using the MODULE_XCC_FLAGS
2 | # variable. So the following
3 | #
4 | # MODULE_XCC_FLAGS = $(XCC_FLAGS) -O3
5 | #
6 | # specifies that everything in the modules should have the application
7 | # build flags with -O3 appended (so the files will build at
8 | # optimization level -O3).
9 | #
10 | # You can also set MODULE_XCC_C_FLAGS, MODULE_XCC_XC_FLAGS etc..
11 |
12 | MODULE_XCC_C_FLAGS = $(XCC_FLAGS) -Os
13 |
14 |
--------------------------------------------------------------------------------
/module_tftp/src/tftp_app.h:
--------------------------------------------------------------------------------
1 | /** Defines a high level interface to module_tftp from the application.
2 | *
3 | * The following functions must be implemented, even if they are left blank.
4 | *
5 | **/
6 | #ifndef TFTP_APP_H_
7 | #define TFTP_APP_H_
8 |
9 | #include
10 |
11 | /** This is called at the beginning of a new TFTP connection and allows the
12 | * application layer to perform any necessary initialisation tasks before it
13 | * is ready to receive data.
14 | *
15 | * On return, the application should expect to receive multiple calls to
16 | * tftp_app_process_data_block(), followed by a final call to
17 | * tftp_app_transfer_complete(), to signal that the last block of data has
18 | * been received and the TFTP transfer is complete.
19 | *
20 | * \return 0 on success, non-zero if the application is not ready to
21 | * receive a new connection or an error occurred.
22 | **/
23 | int tftp_app_transfer_begin(void);
24 |
25 | /** This function is called from TFTP every time a valid TFTP DATA packet is received
26 | * via the protocol. TFTP only passes unique data blocks to the application i.e.
27 | * duplicate data received due to problems with the protocol will NOT trigger this
28 | * function.
29 | *
30 | * It allows the application to process or store the data as needed.
31 | *
32 | * NOTE: TFTP will not ACK the DATA packet associated with this data block until
33 | * this function returns success. Hence, the processing delay associated with
34 | * this function should be taken into consideration, to ensure that the source
35 | * does not timeout.
36 | *
37 | * \param data A pointer to the received data (excluding any TFTP headers)
38 | * \param num_bytes The number of bytes in the data array
39 | * \return 0 if success, non-zero if the application wishes to
40 | * signal a critical error to TFTP that signals a premature
41 | * termination of the TFTP transfer and closes the connection.
42 | *
43 | **/
44 | int tftp_app_process_data_block(REFERENCE_PARAM(unsigned char, data), int num_bytes);
45 |
46 | /** This function is called once the last block of data has been received and
47 | * ACKed by TFTP. The application should perform any housekeeping to de-initialise
48 | * any process that was initialised in tftp_app_transfer_begin().
49 | *
50 | * On return, the active TFTP connection is closed.
51 | *
52 | */
53 | void tftp_app_transfer_complete(void);
54 |
55 | /** This function is called when an error in the TFTP protocol has occurred that
56 | * will cause premature termination of the active connection.
57 | *
58 | * The application should expect the TFTP connection to close on return from this
59 | * function, and hence should perform any housekeeping to safely terminate any
60 | * process that was started in tftp_app_transfer_begin(). There will be no further
61 | * calls to tftp_app_process_data_block() from TFTP for this connection.
62 | *
63 | **/
64 | void tftp_app_transfer_error(void);
65 |
66 |
67 | #endif /* TFTP_APP_H_ */
68 |
--------------------------------------------------------------------------------
/module_tftp/src/tftp_conf.h:
--------------------------------------------------------------------------------
1 | #ifndef TFTP_CONF_H_
2 | #define TFTP_CONF_H_
3 |
4 | #ifndef TFTP_DEBUG_PRINT
5 | #define TFTP_DEBUG_PRINT 0
6 | #endif
7 |
8 | #ifndef TFTP_DEFAULT_PORT
9 | #define TFTP_DEFAULT_PORT 69
10 | #endif
11 |
12 | #ifndef TFTP_BLOCK_SIZE
13 | #define TFTP_BLOCK_SIZE 512 /* 512 bytes */
14 | #endif
15 | #ifndef TFTP_MAX_FILE_SIZE
16 | #define TFTP_MAX_FILE_SIZE (128 * 1024) /* 128 KB */
17 | #endif
18 |
19 | // The number of seconds after which the connection will close if no new data is received
20 | #ifndef TFTP_TIMEOUT_SECONDS
21 | #define TFTP_TIMEOUT_SECONDS 3
22 | #endif
23 |
24 | // The maximum length in bytes of the custom messages in error packets.
25 | // Should always be >= the length of the longest error message.
26 | #ifndef TFTP_ERROR_MSG_MAX_LENGTH
27 | #define TFTP_ERROR_MSG_MAX_LENGTH 25
28 | #endif
29 |
30 | // By default, the TFTP client only accepts an image with the filename TFTP_IMAGE_FILENAME.
31 | // Setting TFTP_ACCEPT_ANY_FILENAME to non-zero allows the client to accept any filename
32 | #ifndef TFTP_ACCEPT_ANY_FILENAME
33 | #define TFTP_ACCEPT_ANY_FILENAME 0
34 | #endif
35 |
36 | #if !TFTP_ACCEPT_ANY_FILENAME
37 | #ifndef TFTP_IMAGE_FILENAME
38 | #define TFTP_IMAGE_FILENAME "upgrade.bin" /* Don't forget quotes around the string */
39 | #endif
40 | #endif
41 |
42 | #endif /* TFTP_CONF_H_ */
43 |
--------------------------------------------------------------------------------
/module_xtcp/.makefile:
--------------------------------------------------------------------------------
1 | all:
2 | @echo "** Module only - only builds as part of application **"
3 |
4 |
5 | clean:
6 | @echo "** Module only - only builds as part of application **"
7 |
8 |
9 |
--------------------------------------------------------------------------------
/module_xtcp/.xproject:
--------------------------------------------------------------------------------
1 | sc_xtcpXM-001955-SM3.2.1rc0
--------------------------------------------------------------------------------
/module_xtcp/README.rst:
--------------------------------------------------------------------------------
1 | Ethernet/TCP Module
2 | ===================
3 |
4 | :scope: General Use
5 | :description: An ethernet stack with TCP/IP
6 | :keywords: ethernet, TCP/IP, mac, mii, IP, UDP, ICMP, UDP
7 |
8 | This module provides an ethernet stack with IP/UDP/TCP protocols. It
9 | can run as a standalone server that takes two cores and connects to an
10 | MII interface or it can connect to a separate low level ethernet mac.
11 |
--------------------------------------------------------------------------------
/module_xtcp/doc/Makefile:
--------------------------------------------------------------------------------
1 | SPHINX_PROJECT_NAME=XTCP TCP/IP Stack
2 | VERSION=2v0
3 | DOXYGEN_DIRS=../../module_xtcp
4 | SOURCE_INCLUDE_DIRS=../../../sc_xtcp
5 | XDOC_DIR ?= ../../../xdoc
6 | include $(XDOC_DIR)/Makefile.inc
7 |
--------------------------------------------------------------------------------
/module_xtcp/doc/hw.rst:
--------------------------------------------------------------------------------
1 | H/W Development Platforms
2 | =========================
3 |
4 | For initial development of ethernet applications the following XMOS
5 | development platforms can be used:
6 |
7 | * XK-AVB-LC-SYS AVB Audio Endpoint
8 | * XP-SKC-L16 (sliceKIT L16 Core Board) plus XA-SK-AUDIO plus XA-SK-XTAG2 (sliceKIT xTAG adaptor) plus xTAG2 (debug adaptor)
9 |
10 | For developing an application specific board with ethernet please
11 | refer to the hardware guides for the above boards with example
12 | schematics, BOMs, design guidelines etc.
13 |
14 | Note that the 2 logical core version of the stack relies on the single thread MII ethernet component, which requires 62.5MIPS to run correctly. Consequently, the 2 logical core version of the stack will not run on a 400MHz device.
15 |
16 |
--------------------------------------------------------------------------------
/module_xtcp/doc/images/events-crop.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xcore/sc_xtcp/2ceb8e2d4734652b12f7871d7d3cc389ed96a31b/module_xtcp/doc/images/events-crop.pdf
--------------------------------------------------------------------------------
/module_xtcp/doc/images/events-crop.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xcore/sc_xtcp/2ceb8e2d4734652b12f7871d7d3cc389ed96a31b/module_xtcp/doc/images/events-crop.png
--------------------------------------------------------------------------------
/module_xtcp/doc/images/events.odg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xcore/sc_xtcp/2ceb8e2d4734652b12f7871d7d3cc389ed96a31b/module_xtcp/doc/images/events.odg
--------------------------------------------------------------------------------
/module_xtcp/doc/images/events.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xcore/sc_xtcp/2ceb8e2d4734652b12f7871d7d3cc389ed96a31b/module_xtcp/doc/images/events.pdf
--------------------------------------------------------------------------------
/module_xtcp/doc/images/xtcp_arch-crop.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xcore/sc_xtcp/2ceb8e2d4734652b12f7871d7d3cc389ed96a31b/module_xtcp/doc/images/xtcp_arch-crop.pdf
--------------------------------------------------------------------------------
/module_xtcp/doc/images/xtcp_arch-crop.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xcore/sc_xtcp/2ceb8e2d4734652b12f7871d7d3cc389ed96a31b/module_xtcp/doc/images/xtcp_arch-crop.png
--------------------------------------------------------------------------------
/module_xtcp/doc/images/xtcp_arch.odg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xcore/sc_xtcp/2ceb8e2d4734652b12f7871d7d3cc389ed96a31b/module_xtcp/doc/images/xtcp_arch.odg
--------------------------------------------------------------------------------
/module_xtcp/doc/images/xtcp_arch.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xcore/sc_xtcp/2ceb8e2d4734652b12f7871d7d3cc389ed96a31b/module_xtcp/doc/images/xtcp_arch.pdf
--------------------------------------------------------------------------------
/module_xtcp/doc/index.rst:
--------------------------------------------------------------------------------
1 | Ethernet TCP/IP component programming guide
2 | ===========================================
3 |
4 | .. toctree::
5 |
6 | overview
7 | system
8 | api
9 | programming
10 |
--------------------------------------------------------------------------------
/module_xtcp/doc/overview.rst:
--------------------------------------------------------------------------------
1 | Overview
2 | ========
3 |
4 | The XMOS TCP/IP component provides a IP/UDP/TCP stack that connects to
5 | the XMOS ethernet component. It enables several
6 | clients to connect to it and send and receive on multiple TCP or UDP
7 | connections. The stack has been designed for a low memory
8 | embedded programming environment and despite its low memory footprint
9 | provides a complete stack including ARP, IPv4, IPv6, UDP, TCP, DHCP, IPv4LL,
10 | ICMP and IGMP protocols.
11 |
12 | .. note:: Please contact XMOS support for IPv6.
13 |
14 | The stack is based on the open-source stack uIP with modifications to
15 | work efficiently on the XMOS architecture and communicate between tasks
16 | using xC channels.
17 |
18 | The TCP stack can either interface to a separate ethernet MAC or work
19 | with an integrated MAC taking only 2 logical cores.
20 |
21 | Seperate MAC + TCP/IP stack properties
22 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++
23 |
24 | * Layer 2 packets can be sent and received independently of layer 3
25 | * Integrated support for high priority Qtagged packets
26 | * Integrated support for 802.1 Qav rate control
27 | * Packet filtering in an independent logical core
28 | * Works on a 400 MHz part
29 |
30 | Two core ethernet plus integrated TCP/IP stack properties
31 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
32 |
33 | * Uses only 2 logical cores
34 | * High throughput
35 | * Uses lower memory footprint
36 | * Only TCP/IP sourced packets can be transmitted
37 | * 500 MHz parts only (MII core requires 62.5 MIPS)
38 |
39 | Component Summary
40 | +++++++++++++++++
41 |
42 | +-------------------------------------------------------------------+
43 | | **Functionality** |
44 | +-------------------------------------------------------------------+
45 | | Provides a lightweight IP/UDP/TCP stack |
46 | +-------------------------------------------------------------------+
47 | | **Supported Standards** |
48 | +-------------------------------------------------------------------+
49 | | IPv4, IPv6, UDP, TCP, DHCP, IPv4LL, ICMP, IGMP |
50 | +-------------------------------------------------------------------+
51 | | **Supported Devices** |
52 | +------------------------------+------------------------------------+
53 | | | XMOS Devices | | XS1-G4 |
54 | | | | XS1-L2 |
55 | | | | XS1-L1 |
56 | +------------------------------+------------------------------------+
57 | | **Requirements** |
58 | +------------------------------+------------------------------------+
59 | | XMOS Desktop Tools | v12.0 or later |
60 | +------------------------------+------------------------------------+
61 | | XMOS Ethernet Component | 2.2.0 or later |
62 | +------------------------------+------------------------------------+
63 |
64 |
--------------------------------------------------------------------------------
/module_xtcp/doc/programming.rst:
--------------------------------------------------------------------------------
1 | Programming Guide
2 | =================
3 |
4 | Installation
5 | ------------
6 |
7 | The xtcp component can be installed via the xSOFTip browser in the
8 | xTIMEcomposer. Just drag the "Ethernet TCP/IP Component" into your
9 | project explorer window.
10 |
11 | Source code structure
12 | ---------------------
13 |
14 | All the files for the stack are contained in the ``module_xtcp``
15 | directory. The important header files that are used by applications
16 | are:
17 |
18 | .. list-table::
19 | :header-rows: 1
20 |
21 | * - File
22 | - Description
23 | * - ``xtcp.h``
24 | - Header file containing prototypes for the functions found in :ref:`sec_client_api`.
25 |
26 | Usage Example
27 | -------------
28 |
29 | See the quickstart guide for the ``Simple HTTP Demo`` demo application, which contains a detailed walkthough of an example application using this module.
30 |
--------------------------------------------------------------------------------
/module_xtcp/module_build_info:
--------------------------------------------------------------------------------
1 | DEPENDENT_MODULES = module_ethernet module_otp_board_info
2 |
3 | ifeq ($(CONFIG),IPV6)
4 | XTCP_SOURCE_DIRS = src src/xtcp_uip6/*
5 | EXCLUDE_FILES += uip_arp.c autoip.c dhcp.c igmp.c rpl.c rpl-dag.c rpl-ext-header.c \
6 | rpl-icmp6.c rpl-mrhof.c rpl-of0.c rpl-timers.c
7 | else
8 | XTCP_SOURCE_DIRS = src src/xtcp_uip/*
9 | EXCLUDE_FILES += uip-fw.c uip-neighbor.c
10 | endif
11 |
12 | SOURCE_DIRS += $(XTCP_SOURCE_DIRS)
13 |
14 | INCLUDE_DIRS += $(XTCP_SOURCE_DIRS)
15 | OPTIONAL_HEADERS += xtcp_client_conf.h xtcp_conf.h
16 | MODULE_XCC_FLAGS = $(XCC_FLAGS)
17 |
18 | ifeq ($(USE_XTCP_MAC_CUSTOM_FILTER),1)
19 | INCLUDE_DIRS += src/mac_custom_filter
20 | SOURCE_DIRS += src/mac_custom_filter
21 | endif
22 |
23 | $(call SET_XCC_XC_FLAGS, $(XTCP_SOURCE_DIRS), $(XCC_FLAGS) -g -Os)
24 | $(call SET_XCC_C_FLAGS, $(XTCP_SOURCE_DIRS), $(XCC_FLAGS) -Os)
25 |
26 | XCC_FLAGS_xcoredev.xc = $(XCC_FLAGS) -fsubword-select
27 | XCC_FLAGS_xtcp_server.xc = $(XCC_FLAGS) -fsubword-select
28 | XCC_FLAGS_uip_xtcp_support.xc = $(XCC_FLAGS) -fsubword-select
29 |
30 | XCC_FLAGS_uip_single_server.xc = $(XCC_FLAGS) -fsubword-select
31 |
32 | # Uncomment for debugging
33 | # $(warning ****Building parts of xtcp at -O0 to help debugging****** )
34 | # XCC_FLAGS_uip_xtcp.c = $(XCC_FLAGS) -O0 -g
35 | # XCC_FLAGS_uip.c = $(XCC_FLAGS) -O0 -g
36 |
37 |
--------------------------------------------------------------------------------
/module_xtcp/src/ethernet_xtcp_server.h:
--------------------------------------------------------------------------------
1 | #ifndef __ethernet_xtcp_server_h__
2 | #define __ethernet_xtcp_server_h__
3 | #include "uip_server.h"
4 | #include
5 | #include "otp_board_info.h"
6 | #include "ethernet.h"
7 |
8 | typedef struct ethernet_xtcp_ports_s {
9 | otp_ports_t otp_ports;
10 | smi_interface_t smi;
11 | mii_interface_lite_t mii;
12 | ethernet_reset_interface_t eth_rst;
13 | } ethernet_xtcp_ports_t;
14 |
15 | void ethernet_xtcp_server(REFERENCE_PARAM(ethernet_xtcp_ports_t, ports),
16 | REFERENCE_PARAM(xtcp_ipconfig_t, ipconfig),
17 | chanend xtcp[],
18 | int num_clients);
19 |
20 | #endif // __ethernet_xtcp_server_h__
21 |
--------------------------------------------------------------------------------
/module_xtcp/src/ethernet_xtcp_server.xc:
--------------------------------------------------------------------------------
1 | #include "ethernet_xtcp_server.h"
2 | #include "uip_single_server.h"
3 | #include "xtcp_conf_derived.h"
4 | #if !XTCP_SEPARATE_MAC
5 |
6 | void ethernet_xtcp_server(ethernet_xtcp_ports_t &ports,
7 | xtcp_ipconfig_t &ipconfig,
8 | chanend c_xtcp[],
9 | int num_clients)
10 | {
11 | char mac_address[6];
12 | otp_board_info_get_mac(ports.otp_ports, 0, mac_address);
13 | // Start server
14 | eth_phy_reset(ports.eth_rst);
15 | uip_single_server(null, ports.smi, ports.mii, c_xtcp, num_clients,
16 | ipconfig, mac_address);
17 | }
18 |
19 | #endif
20 |
--------------------------------------------------------------------------------
/module_xtcp/src/standalone_xtcp_server.h:
--------------------------------------------------------------------------------
1 | #ifndef __standalone_xtcp_server_h__
2 | #define __standalone_xtcp_server_h__
3 |
4 | #include "xccompat.h"
5 | #include "uip_server.h"
6 | /** xtcp TCP/IP server.
7 | *
8 | * \param mac_rx Rx channel connected to ethernet server
9 | * \param mac_tx Tx channel connected to ethernet server
10 | * \param xtcp Client channel array
11 | * \param num_xtcp_clients The number of clients connected to the server
12 | * \param ipconfig An data structure representing the IP config
13 | * (ip address, netmask and gateway) of the device.
14 | * Leave NULL for automatic address allocation.
15 | * \param connect_status This chanend needs to be connected to the connect
16 | * status output of the ethernet mac.
17 | *
18 | * This function implements an xtcp tcp/ip server in a logical core.
19 | * It uses a port of the uIP stack which is then interfaces over the
20 | * xtcp channel array.
21 | *
22 | * The IP setup is based on the ipconfig parameter. If this
23 | * parameter is NULL then an automatic IP address is found (using dhcp or
24 | * ipv4 link local addressing if no dhcp server is present). Otherwise
25 | * it uses the ipconfig structure to allocate a static ip address.
26 | *
27 | * The clients can communicate with the server using the API found
28 | * in xtcp_client.h
29 | *
30 | * \sa xtcp_event()
31 | **/
32 | void
33 | xtcp_server(chanend mac_rx,
34 | chanend mac_tx,
35 | chanend xtcp[],
36 | int num_xtcp_clients,
37 | NULLABLE_REFERENCE_PARAM(xtcp_ipconfig_t, ipconfig));
38 |
39 | #define xtcp_server xtcp_server_uip
40 |
41 | #endif // __standalone_xtcp_server_h__
42 |
--------------------------------------------------------------------------------
/module_xtcp/src/xtcp.h:
--------------------------------------------------------------------------------
1 | #ifndef __xtcp_h__
2 | #define __xtcp_h__
3 |
4 | #include "ethernet_xtcp_server.h"
5 | #include "standalone_xtcp_server.h"
6 | #include "xtcp_client.h"
7 |
8 | #endif // __xtcp_h__
9 |
10 |
--------------------------------------------------------------------------------
/module_xtcp/src/xtcp_blocking_client.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2011, XMOS Ltd, All rights reserved
2 | // This software is freely distributable under a derivative of the
3 | // University of Illinois/NCSA Open Source License posted in
4 | // LICENSE.txt and at
5 |
6 | #ifndef _xtcp_blocking_client_h_
7 | #define _xtcp_blocking_client_h_
8 |
9 | /** \file xtcp_blocking_client.h
10 | * \brief Contains the write and read functions for a blocking TCP client
11 | */
12 |
13 | /** \brief block until the xtcp interface has come up
14 | *
15 | * This means, amongst other things, that it has acquired an
16 | * IP address using whatever scheme was necessary
17 | */
18 | void xtcp_wait_for_ifup(chanend tcp_svr);
19 |
20 | /** \brief Block until a connection attempt to is made
21 | */
22 | xtcp_connection_t xtcp_wait_for_connection(chanend tcp_svr);
23 |
24 | //!@{
25 | //! \name Blocking client API
26 |
27 | /** \brief Write a buffer of data to a TCP connection
28 | *
29 | * This is a blocking write of data to the given xtcp connection
30 | *
31 | * \return 1 for success, 0 for failure
32 | * \param tcp_svr The xtcp control channel
33 | * \param conn The xtcp server connection structure
34 | * \param buf The buffer to write
35 | * \param len The length of data to send
36 | */
37 | int xtcp_write(chanend tcp_svr,
38 | REFERENCE_PARAM(xtcp_connection_t, conn),
39 | unsigned char buf[],
40 | int len);
41 |
42 | /** \brief Receive data from xtcp connection
43 | *
44 | * This is a blocking read from the xtcp stack
45 | *
46 | * \return The number of bytes received
47 | * \param tcp_svr The xtcp control channel
48 | * \param conn The xtcp server connection structure
49 | * \param buf The buffer to read into
50 | * \param minlen The minimim length of data to receive
51 | */
52 | int xtcp_read(chanend tcp_svr,
53 | REFERENCE_PARAM(xtcp_connection_t, conn),
54 | unsigned char buf[],
55 | int minlen);
56 |
57 | //!@}
58 |
59 | #endif
60 |
--------------------------------------------------------------------------------
/module_xtcp/src/xtcp_bufinfo.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2011, XMOS Ltd, All rights reserved
2 | // This software is freely distributable under a derivative of the
3 | // University of Illinois/NCSA Open Source License posted in
4 | // LICENSE.txt and at
5 |
6 | #ifndef __xtcp_bufinfo_h__
7 | #define __xtcp_bufinfo_h__
8 |
9 | #ifndef __XC__
10 | typedef struct xtcp_bufinfo_t {
11 |
12 | int rx_new_event;
13 | char *rx_buf;
14 | char *rx_end;
15 | char *rx_wrptr;
16 | char *rx_rdptr;
17 |
18 | char *tx_buf;
19 | char *tx_end;
20 | char *tx_wrptr;
21 | char *tx_rdptr;
22 | char *tx_prev_rdptr;
23 | int tx_lowmark;
24 |
25 | } xtcp_bufinfo_t;
26 | #endif
27 |
28 | #define SIZEOF_BUFINFO (11*4)
29 |
30 | #endif //__xtcp_bufinfo_h__
31 |
--------------------------------------------------------------------------------
/module_xtcp/src/xtcp_cmd.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2011, XMOS Ltd, All rights reserved
2 | // This software is freely distributable under a derivative of the
3 | // University of Illinois/NCSA Open Source License posted in
4 | // LICENSE.txt and at
5 |
6 | #ifndef _xtcp_cmd_h_
7 | #define _xtcp_cmd_h_
8 |
9 | #define XTCP_CMD_TOKEN 128
10 |
11 | typedef enum xtcp_cmd_t {
12 | XTCP_CMD_LISTEN,
13 | XTCP_CMD_UNLISTEN,
14 | XTCP_CMD_CONNECT,
15 | XTCP_CMD_BIND_LOCAL,
16 | XTCP_CMD_BIND_REMOTE,
17 | XTCP_CMD_INIT_SEND,
18 | XTCP_CMD_SET_APPSTATE,
19 | XTCP_CMD_CLOSE,
20 | XTCP_CMD_ABORT,
21 | XTCP_CMD_TIMED_OUT,
22 | XTCP_CMD_SET_POLL_INTERVAL,
23 | XTCP_CMD_JOIN_GROUP,
24 | XTCP_CMD_LEAVE_GROUP,
25 | XTCP_CMD_GET_MAC_ADDRESS,
26 | XTCP_CMD_GET_IPCONFIG,
27 | XTCP_CMD_ACK_RECV,
28 | XTCP_CMD_ACK_RECV_MODE,
29 | XTCP_CMD_PAUSE,
30 | XTCP_CMD_UNPAUSE,
31 | XTCP_CMD_UPDATE_BUFINFO,
32 | XTCP_CMD_ACCEPT_PARTIAL_ACK
33 | } xtcp_cmd_t;
34 |
35 | #endif // _xtcp_cmd_h_
36 |
--------------------------------------------------------------------------------
/module_xtcp/src/xtcp_conf_derived.h:
--------------------------------------------------------------------------------
1 | #ifndef __xtcp_conf_derived_h__
2 | #define __xtcp_conf_derived_h__
3 |
4 | #ifdef __xtcp_conf_h_exists__
5 | #include "xtcp_conf.h"
6 | #endif
7 |
8 | #ifdef __xtcp_client_conf_h_exists__
9 | #include "xtcp_client_conf.h"
10 | #endif
11 |
12 | #ifndef XTCP_SEPARATE_MAC
13 | #define XTCP_SEPARATE_MAC 0
14 | #endif
15 |
16 | #if XTCP_SEPARATE_MAC
17 | #define ETHERNET_DEFAULT_IMPLEMENTATION full
18 | #endif
19 |
20 | #ifndef ETHERNET_USE_XTCP_FILTER
21 | #define ETHERNET_USE_XTCP_FILTER 1
22 | #endif
23 |
24 | #if ETHERNET_USE_XTCP_FILTER
25 | #define ETHERNET_CUSTOM_FILTER_HEADER "xtcp_mac_filter.h"
26 | #endif
27 |
28 | #ifndef XTCP_ENABLE_PUSH_FLAG_NOTIFICATION
29 | #define XTCP_ENABLE_PUSH_FLAG_NOTIFICATION 0
30 | #endif
31 |
32 | #endif // __xtcp_conf_derived_h__
33 |
--------------------------------------------------------------------------------
/module_xtcp/src/xtcp_mac_filter.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2011, XMOS Ltd, All rights reserved
2 | // This software is freely distributable under a derivative of the
3 | // University of Illinois/NCSA Open Source License posted in
4 | // LICENSE.txt and at
5 |
6 | #ifndef _mac_cusom_filter_h_
7 | #define _mac_cusom_filter_h_
8 | #include "xtcp_conf_derived.h"
9 |
10 | #if ETHERNET_USE_XTCP_FILTER
11 | #define MAC_FILTER_ARPIP 0x1
12 |
13 | inline int mac_custom_filter(unsigned int buf[])
14 | {
15 | int result = 0;
16 | unsigned short etype = (unsigned short) buf[3];
17 | int qhdr = (etype == 0x0081);
18 |
19 | if (qhdr) {
20 | // has a 802.1q tag - read etype from next word
21 | etype = (unsigned short) buf[4];
22 | }
23 |
24 | switch (etype) {
25 | case 0x0608:
26 | case 0x0008:
27 | result = MAC_FILTER_ARPIP;
28 | break;
29 | default:
30 | break;
31 | }
32 |
33 | return result;
34 | }
35 | #endif
36 | #endif
37 |
--------------------------------------------------------------------------------
/module_xtcp/src/xtcp_mac_filter.xc:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2011, XMOS Ltd, All rights reserved
2 | // This software is freely distributable under a derivative of the
3 | // University of Illinois/NCSA Open Source License posted in
4 | // LICENSE.txt and at
5 |
6 | #include "xtcp_mac_filter.h"
7 | #if ETHERNET_USE_XTCP_FILTER
8 | extern int mac_custom_filter(unsigned int buf[]);
9 | #endif
10 |
--------------------------------------------------------------------------------
/module_xtcp/src/xtcp_server.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2011, XMOS Ltd, All rights reserved
2 | // This software is freely distributable under a derivative of the
3 | // University of Illinois/NCSA Open Source License posted in
4 | // LICENSE.txt and at
5 |
6 | #ifndef __xtcp_server_h__
7 | #define __xtcp_server_h__
8 | #include
9 | #include "xtcp_client.h"
10 | #include "xtcp_server_conf.h"
11 |
12 | #if UIP_CONF_IPV6
13 | #include "process.h"
14 | #include "uip-conf.h"
15 | #endif
16 |
17 | #define MAX_XTCP_CLIENTS 10
18 |
19 | typedef struct xtcpd_state_t {
20 | unsigned int linknum;
21 | xtcp_connection_t conn;
22 | xtcp_server_state_t s;
23 | } xtcpd_state_t;
24 |
25 |
26 | void xtcpd_init(chanend xtcp[], int num_xtcp);
27 |
28 | void xtcpd_send_event(chanend c, xtcp_event_type_t event,
29 | REFERENCE_PARAM(xtcpd_state_t, s));
30 |
31 | void xtcpd_send_null_event(chanend c);
32 |
33 | void xtcpd_service_clients(chanend xtcp[], int num_xtcp);
34 | void xtcpd_service_clients_until_ready(int waiting_link,
35 | chanend xtcp[],
36 | int num_xtcp);
37 |
38 | void xtcpd_recv(chanend xtcp[],
39 | int linknum,
40 | int num_xtcp,
41 | REFERENCE_PARAM(xtcpd_state_t, s),
42 | unsigned char data[],
43 | int datalen);
44 |
45 | int xtcpd_send(chanend c,
46 | xtcp_event_type_t event,
47 | REFERENCE_PARAM(xtcpd_state_t, s),
48 | unsigned char data[],
49 | int mss);
50 |
51 | void xtcpd_get_mac_address(unsigned char []);
52 |
53 | void xtcpd_server_init(void);
54 |
55 | void xtcpd_queue_event(chanend c, int linknum, int event);
56 | #endif
57 |
--------------------------------------------------------------------------------
/module_xtcp/src/xtcp_server_impl.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2011, XMOS Ltd, All rights reserved
2 | // This software is freely distributable under a derivative of the
3 | // University of Illinois/NCSA Open Source License posted in
4 | // LICENSE.txt and at
5 |
6 | // These functions need to be supplied by the IP stack to
7 | // implement an xtcp server
8 |
9 | #ifndef _xtcp_server_impl_h_
10 | #define _xtcp_server_impl_h_
11 | #include
12 |
13 | void xtcpd_ask(int linknum);
14 | void xtcpd_listen(int linknum, int port_number, xtcp_protocol_t p);
15 | void xtcpd_unlisten(int linknum, int port_number);
16 | void xtcpd_connect(int linknum, int port_number, xtcp_ipaddr_t addr,
17 | xtcp_protocol_t p);
18 | void xtcpd_bind_local(int linknum, int conn_id, int port_number);
19 | void xtcpd_bind_remote(int linknum,
20 | int conn_id,
21 | xtcp_ipaddr_t addr,
22 | int port_number);
23 |
24 | void xtcpd_init_send(int linknum, int conn_id);
25 | void xtcpd_set_appstate(int linknum, int conn_id, xtcp_appstate_t appstate);
26 | void xtcpd_abort(int linknum, int conn_id);
27 |
28 | void xtcpd_request_null_event(int linknum, int requested_linknum);
29 |
30 | void xtcpd_close(int linknum, int conn_id);
31 |
32 | void xtcpd_ask_config(int linknum);
33 |
34 | void xtcpd_set_poll_interval(int linknum, int conn_id, int poll_interval);
35 |
36 | void xtcpd_join_group(xtcp_ipaddr_t addr);
37 | void xtcpd_leave_group(xtcp_ipaddr_t addr);
38 | void xtcpd_get_mac_addr(unsigned char mac_addr[]);
39 | void xtcpd_get_ipconfig(REFERENCE_PARAM(xtcp_ipconfig_t, ipconfig));
40 |
41 | void xtcpd_ack_recv(int conn_id);
42 | void xtcpd_ack_recv_mode(int conn_id);
43 |
44 | void xtcpd_pause(int conn_id);
45 | void xtcpd_unpause(int conn_id);
46 | void xtcpd_accept_partial_ack(int conn_id);
47 |
48 | #endif
49 |
--------------------------------------------------------------------------------
/module_xtcp/src/xtcp_uip/README:
--------------------------------------------------------------------------------
1 | This implementation of an XTCP server is based on uIP v1.0.
2 |
3 | uIP is a very small implementation of the TCP/IP stack that is written
4 | by Adam Dunkels . More information can be obtained
5 | at the uIP homepage at http://www.sics.se/~adam/uip/.
6 |
--------------------------------------------------------------------------------
/module_xtcp/src/xtcp_uip/autoip/autoip.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2011, XMOS Ltd, All rights reserved
2 | // This software is freely distributable under a derivative of the
3 | // University of Illinois/NCSA Open Source License posted in
4 | // LICENSE.txt and at
5 |
6 | #ifndef _autoip_h_
7 | #define _autoip_h_
8 |
9 | void autoip_init(int seed);
10 | void autoip_arp_in();
11 | void autoip_start();
12 | void autoip_stop();
13 | void autoip_configured(uip_ipaddr_t ipaddr);
14 | void autoip_periodic();
15 | #endif //_autoip_h_
16 |
--------------------------------------------------------------------------------
/module_xtcp/src/xtcp_uip/clock-arch.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2011, XMOS Ltd, All rights reserved
2 | // This software is freely distributable under a derivative of the
3 | // University of Illinois/NCSA Open Source License posted in
4 | // LICENSE.txt and at
5 |
6 | /*
7 | * Copyright (c) 2006, Swedish Institute of Computer Science.
8 | * All rights reserved.
9 | *
10 | * Redistribution and use in source and binary forms, with or without
11 | * modification, are permitted provided that the following conditions
12 | * are met:
13 | * 1. Redistributions of source code must retain the above copyright
14 | * notice, this list of conditions and the following disclaimer.
15 | * 2. Redistributions in binary form must reproduce the above copyright
16 | * notice, this list of conditions and the following disclaimer in the
17 | * documentation and/or other materials provided with the distribution.
18 | * 3. Neither the name of the Institute nor the names of its contributors
19 | * may be used to endorse or promote products derived from this software
20 | * without specific prior written permission.
21 | *
22 | * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
23 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
26 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 | * SUCH DAMAGE.
33 | *
34 | * This file is part of the uIP TCP/IP stack
35 | *
36 | * $Id: clock-arch.h,v 1.2 2006/06/12 08:00:31 adam Exp $
37 | */
38 |
39 | #ifndef __CLOCK_ARCH_H__
40 | #define __CLOCK_ARCH_H__
41 |
42 | typedef int clock_time_t;
43 | #define CLOCK_CONF_SECOND 1000
44 |
45 | #endif /* __CLOCK_ARCH_H__ */
46 |
--------------------------------------------------------------------------------
/module_xtcp/src/xtcp_uip/clock-arch.xc:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2011, XMOS Ltd, All rights reserved
2 | // This software is freely distributable under a derivative of the
3 | // University of Illinois/NCSA Open Source License posted in
4 | // LICENSE.txt and at
5 |
6 | /*
7 | * Copyright (c) 2006, Swedish Institute of Computer Science.
8 | * All rights reserved.
9 | *
10 | * Redistribution and use in source and binary forms, with or without
11 | * modification, are permitted provided that the following conditions
12 | * are met:
13 | * 1. Redistributions of source code must retain the above copyright
14 | * notice, this list of conditions and the following disclaimer.
15 | * 2. Redistributions in binary form must reproduce the above copyright
16 | * notice, this list of conditions and the following disclaimer in the
17 | * documentation and/or other materials provided with the distribution.
18 | * 3. Neither the name of the Institute nor the names of its contributors
19 | * may be used to endorse or promote products derived from this software
20 | * without specific prior written permission.
21 | *
22 | * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
23 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
26 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 | * SUCH DAMAGE.
33 | *
34 | * This file is part of the uIP TCP/IP stack
35 | *
36 | * $Id: clock-arch.c,v 1.2 2006/06/12 08:00:31 adam Exp $
37 | */
38 |
39 | /**
40 | * \file
41 | * Implementation of architecture-specific clock functionality
42 | * \author
43 | * Adam Dunkels
44 | */
45 |
46 | #include "clock-arch.h"
47 | #include
48 |
49 | /* This assumes that this is called within 10s periods */
50 |
51 | static int time = 0;
52 |
53 | static unsigned int prev_timestamp = 0;
54 |
55 | static int init = 1;
56 |
57 | /*---------------------------------------------------------------------------*/
58 | clock_time_t
59 | clock_time(void)
60 | {
61 | timer tmr;
62 | unsigned t;
63 |
64 | tmr :> t;
65 | t = t - (t % 100000);
66 |
67 | if (init) {
68 | time = 0;
69 | init = 0;
70 | }
71 | else {
72 | unsigned diff = (signed) t - (signed) prev_timestamp;
73 | time += diff/100000;
74 | }
75 |
76 | prev_timestamp = t;
77 | return time;
78 |
79 | #if 0
80 | struct timeval tv;
81 | struct timezone tz;
82 |
83 | gettimeofday(&tv, &tz);
84 |
85 | return tv.tv_sec * 1000 + tv.tv_usec / 1000;
86 | #endif
87 | }
88 | /*---------------------------------------------------------------------------*/
89 |
--------------------------------------------------------------------------------
/module_xtcp/src/xtcp_uip/dhcpc/Makefile.dhcpc:
--------------------------------------------------------------------------------
1 | APP_SOURCES += dhcpc.c timer.c
2 |
--------------------------------------------------------------------------------
/module_xtcp/src/xtcp_uip/dhcpc/dhcpc.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2011, XMOS Ltd, All rights reserved
2 | // This software is freely distributable under a derivative of the
3 | // University of Illinois/NCSA Open Source License posted in
4 | // LICENSE.txt and at
5 |
6 |
7 | /*
8 | * Copyright (c) 2005, Swedish Institute of Computer Science
9 | * All rights reserved.
10 | *
11 | * Redistribution and use in source and binary forms, with or without
12 | * modification, are permitted provided that the following conditions
13 | * are met:
14 | * 1. Redistributions of source code must retain the above copyright
15 | * notice, this list of conditions and the following disclaimer.
16 | * 2. Redistributions in binary form must reproduce the above copyright
17 | * notice, this list of conditions and the following disclaimer in the
18 | * documentation and/or other materials provided with the distribution.
19 | * 3. Neither the name of the Institute nor the names of its contributors
20 | * may be used to endorse or promote products derived from this software
21 | * without specific prior written permission.
22 | *
23 | * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
24 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 | * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
27 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 | * SUCH DAMAGE.
34 | *
35 | * This file is part of the uIP TCP/IP stack
36 | *
37 | * @(#)$Id: dhcpc.h,v 1.3 2006/06/11 21:46:37 adam Exp $
38 | */
39 | #ifndef __DHCPC_H__
40 | #define __DHCPC_H__
41 |
42 | #include "timer.h"
43 | #include "pt.h"
44 |
45 | struct dhcpc_state {
46 | struct pt pt;
47 | char state;
48 | struct uip_udp_conn *conn;
49 | struct uip_timer timer;
50 | unsigned int ticks;
51 | const void *mac_addr;
52 | int mac_len;
53 |
54 | u8_t serverid[4];
55 |
56 | u16_t lease_time[2];
57 | u16_t ipaddr[2];
58 | u16_t netmask[2];
59 | u16_t dnsaddr[2];
60 | u16_t default_router[2];
61 | };
62 |
63 | void dhcpc_init(const void *mac_addr, int mac_len);
64 | void dhcpc_request(void);
65 |
66 | void dhcpc_appcall(void);
67 |
68 | void dhcpc_configured(const struct dhcpc_state *s);
69 | void dhcpc_start();
70 | void dhcpc_stop();
71 | //typedef struct dhcpc_state uip_udp_appstate_t;
72 |
73 | #ifndef UIP_UDP_APPCALL
74 | #define UIP_UDP_APPCALL dhcpc_appcall
75 | #endif
76 |
77 | #endif /* __DHCPC_H__ */
78 |
--------------------------------------------------------------------------------
/module_xtcp/src/xtcp_uip/igmp/igmp.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2011, XMOS Ltd, All rights reserved
2 | // This software is freely distributable under a derivative of the
3 | // University of Illinois/NCSA Open Source License posted in
4 | // LICENSE.txt and at
5 |
6 | #ifndef _igmp_h_
7 | #define _igmp_h_
8 |
9 | void igmp_init();
10 |
11 | void igmp_periodic();
12 | void igmp_in();
13 | void igmp_join_group(uip_ipaddr_t addr);
14 | void igmp_leave_group(uip_ipaddr_t addr);
15 | int igmp_check_addr(uip_ipaddr_t addr);
16 | #endif // _igmp_h_
17 |
--------------------------------------------------------------------------------
/module_xtcp/src/xtcp_uip/uip-neighbor.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2011, XMOS Ltd, All rights reserved
2 | // This software is freely distributable under a derivative of the
3 | // University of Illinois/NCSA Open Source License posted in
4 | // LICENSE.txt and at
5 |
6 |
7 | /*
8 | * Copyright (c) 2006, Swedish Institute of Computer Science.
9 | * All rights reserved.
10 | *
11 | * Redistribution and use in source and binary forms, with or without
12 | * modification, are permitted provided that the following conditions
13 | * are met:
14 | * 1. Redistributions of source code must retain the above copyright
15 | * notice, this list of conditions and the following disclaimer.
16 | * 2. Redistributions in binary form must reproduce the above copyright
17 | * notice, this list of conditions and the following disclaimer in the
18 | * documentation and/or other materials provided with the distribution.
19 | * 3. Neither the name of the Institute nor the names of its contributors
20 | * may be used to endorse or promote products derived from this software
21 | * without specific prior written permission.
22 | *
23 | * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
24 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 | * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
27 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 | * SUCH DAMAGE.
34 | *
35 | * This file is part of the uIP TCP/IP stack
36 | *
37 | * $Id: uip-neighbor.h,v 1.2 2006/06/12 08:00:30 adam Exp $
38 | */
39 |
40 | /**
41 | * \file
42 | * Header file for database of link-local neighbors, used by
43 | * IPv6 code and to be used by future ARP code.
44 | * \author
45 | * Adam Dunkels
46 | */
47 |
48 | #ifndef __UIP_NEIGHBOR_H__
49 | #define __UIP_NEIGHBOR_H__
50 |
51 | #include "uip.h"
52 |
53 | struct uip_neighbor_addr {
54 | #if UIP_NEIGHBOR_CONF_ADDRTYPE
55 | UIP_NEIGHBOR_CONF_ADDRTYPE addr;
56 | #else
57 | struct uip_eth_addr addr;
58 | #endif
59 | };
60 |
61 | void uip_neighbor_init(void);
62 | void uip_neighbor_add(uip_ipaddr_t ipaddr, struct uip_neighbor_addr *addr);
63 | void uip_neighbor_update(uip_ipaddr_t ipaddr);
64 | struct uip_neighbor_addr *uip_neighbor_lookup(uip_ipaddr_t ipaddr);
65 | void uip_neighbor_periodic(void);
66 |
67 | #endif /* __UIP-NEIGHBOR_H__ */
68 |
--------------------------------------------------------------------------------
/module_xtcp/src/xtcp_uip/uip_server.c:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2011, XMOS Ltd, All rights reserved
2 | // This software is freely distributable under a derivative of the
3 | // University of Illinois/NCSA Open Source License posted in
4 | // LICENSE.txt and at
5 |
6 | #include
7 | #include
8 | #include
9 |
10 | #include "xtcp_conf_derived.h"
11 |
12 | #ifndef UIP_USE_SINGLE_THREADED_ETHERNET
13 |
14 | #include "uip.h"
15 | #include "uip_arp.h"
16 | #include "xcoredev.h"
17 | #include "xtcp_server.h"
18 | #include "timer.h"
19 | #include "uip_server.h"
20 | #include "ethernet_rx_client.h"
21 | #include "ethernet_tx_client.h"
22 | #include "uip_xtcp.h"
23 | #include "autoip.h"
24 | #include "igmp.h"
25 |
26 | // Functions from the uip_server_support file
27 | extern void uip_printip4(const uip_ipaddr_t ip4);
28 | extern void uip_server_init(chanend xtcp[], int num_xtcp, xtcp_ipconfig_t* ipconfig, unsigned char mac_address[6]);
29 | extern void xtcpd_check_connection_poll(chanend mac_tx);
30 | extern void xtcp_tx_buffer(chanend mac_tx);
31 | extern void xtcp_process_incoming_packet(chanend mac_tx, int length);
32 | extern void xtcp_process_udp_acks(chanend mac_tx);
33 | extern void xtcp_process_periodic_timer(chanend mac_tx);
34 |
35 |
36 | // Global variables from the uip_server_support file
37 | extern int uip_static_ip;
38 | extern xtcp_ipconfig_t uip_static_ipconfig;
39 |
40 | #if XTCP_SEPARATE_MAC
41 |
42 | void xtcp_server_uip(chanend mac_rx, chanend mac_tx, chanend xtcp[], int num_xtcp,
43 | xtcp_ipconfig_t *ipconfig) {
44 |
45 | struct uip_timer periodic_timer, arp_timer, autoip_timer;
46 | unsigned char hwaddr[6];
47 |
48 | timer_set(&periodic_timer, CLOCK_SECOND / 10);
49 | timer_set(&autoip_timer, CLOCK_SECOND / 2);
50 | timer_set(&arp_timer, CLOCK_SECOND * 10);
51 |
52 | xcoredev_init(mac_rx, mac_tx);
53 |
54 | mac_get_macaddr(mac_tx, hwaddr);
55 |
56 | uip_server_init(xtcp, num_xtcp, ipconfig, hwaddr);
57 |
58 | // Main uIP service loop
59 | while (1)
60 | {
61 | xtcpd_service_clients(xtcp, num_xtcp);
62 |
63 | xtcpd_check_connection_poll(mac_tx);
64 |
65 | uip_xtcp_checkstate();
66 | uip_len = xcoredev_read(mac_rx, UIP_CONF_BUFFER_SIZE);
67 | if (uip_len > 0) {
68 | xtcp_process_incoming_packet(mac_tx, uip_len);
69 | }
70 |
71 | xtcp_process_udp_acks(mac_tx);
72 |
73 |
74 | if (timer_expired(&arp_timer)) {
75 | timer_reset(&arp_timer);
76 | uip_arp_timer();
77 | }
78 |
79 | #if UIP_USE_AUTOIP
80 | if (timer_expired(&autoip_timer)) {
81 | timer_reset(&autoip_timer);
82 | autoip_periodic();
83 | if (uip_len > 0) {
84 | xtcp_tx_buffer(mac_tx);
85 | }
86 | }
87 | #endif
88 |
89 | if (timer_expired(&periodic_timer)) {
90 |
91 | xtcp_process_periodic_timer(mac_tx);
92 |
93 | timer_reset(&periodic_timer);
94 | }
95 |
96 | }
97 | return;
98 | }
99 |
100 | #endif // XTCP_SEPARATE_MAC
101 |
102 | #endif
103 |
--------------------------------------------------------------------------------
/module_xtcp/src/xtcp_uip/uip_server.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2011, XMOS Ltd, All rights reserved
2 | // This software is freely distributable under a derivative of the
3 | // University of Illinois/NCSA Open Source License posted in
4 | // LICENSE.txt and at
5 |
6 | #ifndef _uip_server_h_
7 | #define _uip_server_h_
8 | #include "xtcp_client.h"
9 |
10 | /** uIP based xtcp server.
11 | *
12 | * \param mac_rx Rx channel connected to ethernet server
13 | * \param mac_tx Tx channel connected to ethernet server
14 | * \param xtcp Client channel array
15 | * \param num_xtcp_clients The number of clients connected to the server
16 | * \param ipconfig An data structure representing the IP config
17 | * (ip address, netmask and gateway) of the device.
18 | * Leave NULL for automatic address allocation.
19 | *
20 | * This function implements an xtcp tcp/ip server in a logical core.
21 | * It uses a port of the uIP stack which is then interfaces over the
22 | * xtcp channel array.
23 | *
24 | * The IP setup is based on the ipconfig parameter. If this
25 | * parameter is NULL then an automatic IP address is found (using dhcp or
26 | * ipv4 link local addressing if no dhcp server is present). Otherwise
27 | * it uses the ipconfig structure to allocate a static ip address.
28 | *
29 | * The clients can communicate with the server using the API found
30 | * in xtcp_client.h
31 | *
32 | * \sa xtcp_event()
33 | **/
34 | #ifdef __XC__
35 | void
36 | xtcp_server_uip(chanend mac_rx,
37 | chanend mac_tx,
38 | chanend xtcp[],
39 | int num_xtcp_clients,
40 | xtcp_ipconfig_t &?ipconfig);
41 | #else
42 | void xtcp_server_uip(chanend mac_rx,
43 | chanend mac_tx,
44 | chanend xtcp[],
45 | int num_xtcp_clients,
46 | xtcp_ipconfig_t *ipconfig);
47 | #endif
48 |
49 | #define uip_server xtcp_server_uip
50 |
51 | #endif // _uip_server_h_
52 |
--------------------------------------------------------------------------------
/module_xtcp/src/xtcp_uip/uip_single_server.h:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | #include "mii.h"
4 | #include "smi.h"
5 | #include "xtcp_client.h"
6 |
7 | /**
8 | * The top level thread function for a single threaded XTCP server, interfacing
9 | * to a single thread ethernet MII.
10 | * *
11 | * \note This function should be used in a top level 'par' in the main function.
12 | * It will internally create the single MII thread.
13 | *
14 | * \param p_mii_resetn Optional port which resets the PHY
15 | * \param smi Structure describing the SMI ports
16 | * \param mii Structure describing the MII ports
17 | * \param xtcp Array of client comms channels
18 | * \param num_xtcp The number of TCP client channels
19 | * \param ipconfig The configuration structure for the IP address
20 | * \param mac_address The unicast MAC address for this device
21 | *
22 | */
23 | void uip_single_server(out port ?p_mii_resetn,
24 | smi_interface_t &smi,
25 | mii_interface_lite_t &mii,
26 | chanend xtcp[], int num_xtcp,
27 | xtcp_ipconfig_t& ipconfig,
28 | char mac_address[6]);
29 |
--------------------------------------------------------------------------------
/module_xtcp/src/xtcp_uip/uip_xtcp.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2011, XMOS Ltd, All rights reserved
2 | // This software is freely distributable under a derivative of the
3 | // University of Illinois/NCSA Open Source License posted in
4 | // LICENSE.txt and at
5 |
6 | #ifndef _UIP_XTCP_H_
7 | #define _UIP_XTCP_H_
8 |
9 | void uip_xtcp_checkstate();
10 | void uip_xtcp_up();
11 | void uip_xtcp_down();
12 | void uip_xtcp_checklink(chanend connect_status);
13 | int get_uip_xtcp_ifstate();
14 | void uip_linkdown();
15 | void uip_linkup();
16 | void uip_xtcp_null_events();
17 | #endif // _UIP_XTCP_H_
18 |
--------------------------------------------------------------------------------
/module_xtcp/src/xtcp_uip/uip_xtcpd.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2011, XMOS Ltd, All rights reserved
2 | // This software is freely distributable under a derivative of the
3 | // University of Illinois/NCSA Open Source License posted in
4 | // LICENSE.txt and at
5 |
6 |
--------------------------------------------------------------------------------
/module_xtcp/src/xtcp_uip/uiplib.c:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2011, XMOS Ltd, All rights reserved
2 | // This software is freely distributable under a derivative of the
3 | // University of Illinois/NCSA Open Source License posted in
4 | // LICENSE.txt and at
5 |
6 |
7 | /*
8 | * Copyright (c) 2004, Adam Dunkels and the Swedish Institute of
9 | * Computer Science.
10 | * All rights reserved.
11 | *
12 | * Redistribution and use in source and binary forms, with or without
13 | * modification, are permitted provided that the following conditions
14 | * are met:
15 | * 1. Redistributions of source code must retain the above copyright
16 | * notice, this list of conditions and the following disclaimer.
17 | * 2. Redistributions in binary form must reproduce the above copyright
18 | * notice, this list of conditions and the following disclaimer in the
19 | * documentation and/or other materials provided with the distribution.
20 | * 3. The name of the author may not be used to endorse or promote
21 | * products derived from this software without specific prior
22 | * written permission.
23 | *
24 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
25 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
26 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
28 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
30 | * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
32 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
33 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
34 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 | *
36 | * This file is part of the uIP TCP/IP stack
37 | *
38 | * $Id: uiplib.c,v 1.2 2006/06/12 08:00:31 adam Exp $
39 | *
40 | */
41 |
42 |
43 | #include "uip.h"
44 | #include "uiplib.h"
45 |
46 |
47 | /*-----------------------------------------------------------------------------------*/
48 | unsigned char
49 | uiplib_ipaddrconv(char *addrstr, unsigned char *ipaddr)
50 | {
51 | unsigned char tmp;
52 | char c;
53 | unsigned char i, j;
54 |
55 | tmp = 0;
56 |
57 | for(i = 0; i < 4; ++i) {
58 | j = 0;
59 | do {
60 | c = *addrstr;
61 | ++j;
62 | if(j > 4) {
63 | return 0;
64 | }
65 | if(c == '.' || c == 0) {
66 | *ipaddr = tmp;
67 | ++ipaddr;
68 | tmp = 0;
69 | } else if(c >= '0' && c <= '9') {
70 | tmp = (tmp * 10) + (c - '0');
71 | } else {
72 | return 0;
73 | }
74 | ++addrstr;
75 | } while(c != '.' && c != 0);
76 | }
77 | return 1;
78 | }
79 |
80 | /*-----------------------------------------------------------------------------------*/
81 |
--------------------------------------------------------------------------------
/module_xtcp/src/xtcp_uip/uiplib.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2011, XMOS Ltd, All rights reserved
2 | // This software is freely distributable under a derivative of the
3 | // University of Illinois/NCSA Open Source License posted in
4 | // LICENSE.txt and at
5 |
6 |
7 | /**
8 | * \file
9 | * Various uIP library functions.
10 | * \author
11 | * Adam Dunkels
12 | *
13 | */
14 |
15 | /*
16 | * Copyright (c) 2002, Adam Dunkels.
17 | * All rights reserved.
18 | *
19 | * Redistribution and use in source and binary forms, with or without
20 | * modification, are permitted provided that the following conditions
21 | * are met:
22 | * 1. Redistributions of source code must retain the above copyright
23 | * notice, this list of conditions and the following disclaimer.
24 | * 2. Redistributions in binary form must reproduce the above
25 | * copyright notice, this list of conditions and the following
26 | * disclaimer in the documentation and/or other materials provided
27 | * with the distribution.
28 | * 3. The name of the author may not be used to endorse or promote
29 | * products derived from this software without specific prior
30 | * written permission.
31 | *
32 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
33 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
34 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
35 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
36 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
38 | * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
39 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
40 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
41 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
42 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
43 | *
44 | * This file is part of the uIP TCP/IP stack
45 | *
46 | * $Id: uiplib.h,v 1.1 2006/06/07 09:15:19 adam Exp $
47 | *
48 | */
49 | #ifndef __UIPLIB_H__
50 | #define __UIPLIB_H__
51 |
52 | /**
53 | * \addtogroup uipconvfunc
54 | * @{
55 | */
56 |
57 | /**
58 | * Convert a textual representation of an IP address to a numerical representation.
59 | *
60 | * This function takes a textual representation of an IP address in
61 | * the form a.b.c.d and converts it into a 4-byte array that can be
62 | * used by other uIP functions.
63 | *
64 | * \param addrstr A pointer to a string containing the IP address in
65 | * textual form.
66 | *
67 | * \param addr A pointer to a 4-byte array that will be filled in with
68 | * the numerical representation of the address.
69 | *
70 | * \retval 0 If the IP address could not be parsed.
71 | * \retval Non-zero If the IP address was parsed.
72 | */
73 | unsigned char uiplib_ipaddrconv(char *addrstr, unsigned char *addr);
74 |
75 | /** @} */
76 |
77 | #endif /* __UIPLIB_H__ */
78 |
--------------------------------------------------------------------------------
/module_xtcp/src/xtcp_uip/xcoredev.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2011, XMOS Ltd, All rights reserved
2 | // This software is freely distributable under a derivative of the
3 | // University of Illinois/NCSA Open Source License posted in
4 | // LICENSE.txt and at
5 |
6 | #ifndef __XCOREDEV_H__
7 | #define __XCOREDEV_H__
8 |
9 | #include
10 |
11 | void xcoredev_init(chanend mac_rx, chanend mac_tx);
12 | unsigned int xcoredev_read(chanend mac_rx, int n);
13 | void xcoredev_send(chanend mac_tx);
14 |
15 | #endif /* __XCOREDEV_H__ */
16 |
--------------------------------------------------------------------------------
/module_xtcp/src/xtcp_uip/xcoredev.xc:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2011, XMOS Ltd, All rights reserved
2 | // This software is freely distributable under a derivative of the
3 | // University of Illinois/NCSA Open Source License posted in
4 | // LICENSE.txt and at
5 |
6 | #include
7 | #include
8 | #include "uip_xtcp.h"
9 | #include "xtcp_conf_derived.h"
10 |
11 | #if XTCP_SEPARATE_MAC
12 |
13 | #include "ethernet_rx_client.h"
14 | #include "ethernet_tx_client.h"
15 | #include "mac_filter.h"
16 |
17 | extern unsigned short uip_len;
18 | extern unsigned int uip_buf32[];
19 |
20 | /*---------------------------------------------------------------------------*/
21 | void
22 | xcoredev_init(chanend rx, chanend tx)
23 | {
24 | // Configure the mac link to send the server anything
25 | // arp or ip
26 | mac_set_custom_filter(rx, MAC_FILTER_ARPIP);
27 | mac_request_status_packets(rx);
28 | }
29 |
30 | /*---------------------------------------------------------------------------*/
31 | #pragma unsafe arrays
32 | unsigned int
33 | xcoredev_read(chanend rx, int n)
34 | {
35 | unsigned int len = 0;
36 | unsigned int src_port;
37 | select
38 | {
39 | case safe_mac_rx(rx, (uip_buf32, unsigned char[]), len, src_port, n):
40 | if (len == STATUS_PACKET_LEN) {
41 | if ((uip_buf32, unsigned char[])[0]) {
42 | uip_linkup();
43 | }
44 | else {
45 | uip_linkdown();
46 | }
47 | return 0;
48 | }
49 | break;
50 | default:
51 | break;
52 | }
53 | return len <= n ? len : 0;
54 | }
55 |
56 | /*---------------------------------------------------------------------------*/
57 | void
58 | xcoredev_send(chanend tx)
59 | {
60 | int len = uip_len;
61 | if (len != 0) {
62 | if (len < 64) {
63 | for (int i=len;i<64;i++)
64 | (uip_buf32, unsigned char[])[i] = 0;
65 | len=64;
66 | }
67 |
68 | mac_tx(tx, uip_buf32, len, -1);
69 | }
70 | }
71 | /*---------------------------------------------------------------------------*/
72 |
73 | #endif
74 |
75 |
--------------------------------------------------------------------------------
/module_xtcp/src/xtcp_uip/xtcp_server_conf.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2011, XMOS Ltd, All rights reserved
2 | // This software is freely distributable under a derivative of the
3 | // University of Illinois/NCSA Open Source License posted in
4 | // LICENSE.txt and at
5 |
6 | #include "timer.h"
7 | #include "xtcp_client.h"
8 |
9 | typedef struct xtcp_server_state_t {
10 | int send_request;
11 | int abort_request;
12 | int close_request;
13 | int poll_interval;
14 | int connect_request;
15 | int ack_request;
16 | int closed;
17 | struct uip_timer tmr;
18 | int uip_conn;
19 | int ack_recv_mode;
20 | #ifdef XTCP_ENABLE_PARTIAL_PACKET_ACK
21 | int accepts_partial_ack;
22 | #endif
23 | } xtcp_server_state_t;
24 |
--------------------------------------------------------------------------------
/module_xtcp/src/xtcp_uip6/README:
--------------------------------------------------------------------------------
1 | This implementation of an XTCP server is based on uIP v1.0.
2 |
3 | uIP is a very small implementation of the TCP/IP stack that is written
4 | by Adam Dunkels . More information can be obtained
5 | at the uIP homepage at http://www.sics.se/~adam/uip/.
6 |
--------------------------------------------------------------------------------
/module_xtcp/src/xtcp_uip6/contiki/contiki-net.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2005, Swedish Institute of Computer Science.
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without
6 | * modification, are permitted provided that the following conditions
7 | * are met:
8 | * 1. Redistributions of source code must retain the above copyright
9 | * notice, this list of conditions and the following disclaimer.
10 | * 2. Redistributions in binary form must reproduce the above copyright
11 | * notice, this list of conditions and the following disclaimer in the
12 | * documentation and/or other materials provided with the distribution.
13 | * 3. Neither the name of the Institute nor the names of its contributors
14 | * may be used to endorse or promote products derived from this software
15 | * without specific prior written permission.
16 | *
17 | * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 | * SUCH DAMAGE.
28 | *
29 | * This file is part of the Contiki operating system.
30 | *
31 | * Author: Adam Dunkels
32 | *
33 | */
34 | #ifndef __CONTIKI_NET_H__
35 | #define __CONTIKI_NET_H__
36 |
37 | #include "contiki.h"
38 |
39 | #include "net/tcpip.h"
40 | #include "net/uip.h"
41 | #if NO_XMOS_PROJECT
42 | #include "net/uip-fw.h"
43 | #include "net/uip-fw-drv.h"
44 | #endif /* NO_XMOS_PROJECT */
45 | #include "net/uip_arp.h"
46 | #if NO_XMOS_PROJECT
47 | #include "net/uiplib.h"
48 | #include "net/uip-udp-packet.h"
49 | #include "net/simple-udp.h"
50 | #endif /* NO_XMOS_PROJECT */
51 |
52 | #if UIP_CONF_IPV6
53 | #include "net/uip-icmp6.h"
54 | #include "net/uip-ds6.h"
55 | #endif /* UIP_CONF_IPV6 */
56 |
57 | #if NO_XMOS_PROJECT
58 | #include "net/resolv.h"
59 | #endif /* NO_XMOS_PROJECT */
60 |
61 | #include "net/psock.h"
62 |
63 | #if NO_XMOS_PROJECT
64 | #include "net/rime.h"
65 | #endif /* NO_XMOS_PROJECT */
66 |
67 | #if NO_XMOS_PROJECT
68 | #include "net/netstack.h"
69 | #endif /* NO_XMOS_PROJECT */
70 |
71 | #endif /* __CONTIKI_NET_H__ */
72 |
--------------------------------------------------------------------------------
/module_xtcp/src/xtcp_uip6/contiki/contiki.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2004, Swedish Institute of Computer Science.
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without
6 | * modification, are permitted provided that the following conditions
7 | * are met:
8 | * 1. Redistributions of source code must retain the above copyright
9 | * notice, this list of conditions and the following disclaimer.
10 | * 2. Redistributions in binary form must reproduce the above copyright
11 | * notice, this list of conditions and the following disclaimer in the
12 | * documentation and/or other materials provided with the distribution.
13 | * 3. Neither the name of the Institute nor the names of its contributors
14 | * may be used to endorse or promote products derived from this software
15 | * without specific prior written permission.
16 | *
17 | * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 | * SUCH DAMAGE.
28 | *
29 | * This file is part of the Contiki operating system.
30 | *
31 | * Author: Adam Dunkels
32 | *
33 | */
34 | #ifndef __CONTIKI_H__
35 | #define __CONTIKI_H__
36 |
37 | #if NO_XMOS_PROJECT
38 | #include "contiki-version.h"
39 | #include "contiki-conf.h"
40 | #include "contiki-default-conf.h"
41 | #endif NO_XMOS_PROJECT
42 |
43 | #include "sys/process.h"
44 | #if NO_XMOS_PROJECT
45 | #include "sys/autostart.h"
46 | #endif NO_XMOS_PROJECT
47 |
48 | #include "sys/timer.h"
49 | #include "sys/ctimer.h"
50 | #include "sys/etimer.h"
51 | #if NO_XMOS_PROJECT
52 | #include "sys/rtimer.h"
53 | #endif NO_XMOS_PROJECT
54 |
55 | #include "sys/pt.h"
56 |
57 |
58 | #if NO_XMOS_PROJECT
59 | #include "sys/procinit.h"
60 | #endif NO_XMOS_PROJECT
61 |
62 | #if NO_XMOS_PROJECT
63 | #include "sys/loader.h"
64 | #endif NO_XMOS_PROJECT
65 | #include "sys/clock.h"
66 |
67 | #if NO_XMOS_PROJECT
68 | #include "sys/energest.h"
69 | #endif NO_XMOS_PROJECT
70 |
71 | #endif /* __CONTIKI_H__ */
72 |
--------------------------------------------------------------------------------
/module_xtcp/src/xtcp_uip6/contiki/lib/random.c:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2005, Swedish Institute of Computer Science
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without
6 | * modification, are permitted provided that the following conditions
7 | * are met:
8 | * 1. Redistributions of source code must retain the above copyright
9 | * notice, this list of conditions and the following disclaimer.
10 | * 2. Redistributions in binary form must reproduce the above copyright
11 | * notice, this list of conditions and the following disclaimer in the
12 | * documentation and/or other materials provided with the distribution.
13 | * 3. Neither the name of the Institute nor the names of its contributors
14 | * may be used to endorse or promote products derived from this software
15 | * without specific prior written permission.
16 | *
17 | * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 | * SUCH DAMAGE.
28 | *
29 | * This file is part of the Contiki operating system.
30 | *
31 | */
32 |
33 |
34 | #include "lib/random.h"
35 |
36 | #include
37 |
38 | /*---------------------------------------------------------------------------*/
39 | void
40 | random_init(unsigned short seed)
41 | {
42 | srand(seed);
43 | }
44 | /*---------------------------------------------------------------------------*/
45 | unsigned short
46 | random_rand(void)
47 | {
48 | /* In gcc int rand() uses RAND_MAX and long random() uses RANDOM_MAX=0x7FFFFFFF */
49 | /* RAND_MAX varies depending on the architecture */
50 |
51 | return (unsigned short)rand();
52 | }
53 | /*---------------------------------------------------------------------------*/
54 |
--------------------------------------------------------------------------------
/module_xtcp/src/xtcp_uip6/contiki/lib/random.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2005, Swedish Institute of Computer Science
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without
6 | * modification, are permitted provided that the following conditions
7 | * are met:
8 | * 1. Redistributions of source code must retain the above copyright
9 | * notice, this list of conditions and the following disclaimer.
10 | * 2. Redistributions in binary form must reproduce the above copyright
11 | * notice, this list of conditions and the following disclaimer in the
12 | * documentation and/or other materials provided with the distribution.
13 | * 3. Neither the name of the Institute nor the names of its contributors
14 | * may be used to endorse or promote products derived from this software
15 | * without specific prior written permission.
16 | *
17 | * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 | * SUCH DAMAGE.
28 | *
29 | * This file is part of the Contiki operating system.
30 | *
31 | */
32 | #ifndef __RANDOM_H__
33 | #define __RANDOM_H__
34 |
35 | /*
36 | * Initialize the pseudo-random generator.
37 | *
38 | */
39 | void random_init(unsigned short seed);
40 |
41 | /*
42 | * Calculate a pseudo random number between 0 and 65535.
43 | *
44 | * \return A pseudo-random number between 0 and 65535.
45 | */
46 | unsigned short random_rand(void);
47 |
48 | /* In gcc int rand() uses RAND_MAX and long random() uses RANDOM_MAX */
49 | /* Since random_rand casts to unsigned short, we'll use this maxmimum */
50 | #define RANDOM_RAND_MAX 65535U
51 |
52 | #endif /* __RANDOM_H__ */
53 |
--------------------------------------------------------------------------------
/module_xtcp/src/xtcp_uip6/contiki/net/packetbuf_d.h:
--------------------------------------------------------------------------------
1 | /*****************************************************************************
2 | *
3 | * Filename: packetbuf_d.h
4 | * Author: Christian Schlittler
5 | * Version: 1.0
6 | * Creation date: 18.11.2013
7 | *
8 | * Copyright: Christian Schlittler, christian.schlittler@gmx.ch
9 | *
10 | * Project: XMOS and 6LoWPAN
11 | * Target: XMOS sliceKIT with RFSlice extension
12 | * Compiler:
13 | *
14 | * -----------------------------------------------------------------------------
15 | *
16 | * History:
17 | *
18 | * -----------------------------------------------------------------------------
19 | *
20 | * Usage:
21 | *
22 | **************************************************************************** */
23 |
24 | #ifndef PACKETBUF_D_H_
25 | #define PACKETBUF_D_H_
26 |
27 | #include
28 | #include
29 | #include "net/rime/rimeaddr.h"
30 |
31 | enum{
32 | PACKETBUF_D_ADDR_SENDER,
33 | };
34 |
35 | int packetbuf_d_set_addr(uint8_t type, NULLABLE_ARRAY_OF(const rimeaddr_t, addr));
36 | #if !__XC__
37 | const rimeaddr_t *packetbuf_d_addr(uint8_t type);
38 | #endif /* __XC__ */
39 | #endif /* PACKETBUF_D_H_ */
40 |
--------------------------------------------------------------------------------
/module_xtcp/src/xtcp_uip6/contiki/net/packetubf_d.c:
--------------------------------------------------------------------------------
1 | /*****************************************************************************
2 | *
3 | * Filename: packetubf_d.c
4 | * Author: Christian Schlittler
5 | * Version: 1.0
6 | * Creation date: 18.11.2013
7 | *
8 | * Copyright: Christian Schlittler, christian.schlittler@gmx.ch
9 | *
10 | * Project: XMOS and 6LoWPAN
11 | * Target: XMOS sliceKIT with RFSlice extension
12 | * Compiler:
13 | *
14 | * -----------------------------------------------------------------------------
15 | *
16 | * History:
17 | *
18 | * The package buffer is based on the sources of contiki-os. The problem was, that
19 | * contiki-os runs on a single core, shared memory cpu. But, for the XMOS implementation
20 | * this is not true. The MAC and the IPv6 stack could be on different tiles with
21 | * no shared memory.
22 | * The RPL alogrithm needs access to the sender MAC address and normally this is
23 | * done by the shared packet buffer. So, here we need to copy the address in a
24 | * dummy packet buffer.
25 | *
26 | * -----------------------------------------------------------------------------
27 | *
28 | * Usage:
29 | *
30 | **************************************************************************** */
31 |
32 | #include
33 | #include "net/packetbuf_d.h"
34 |
35 | static rimeaddr_t packetbuf_d_addr_sender;
36 |
37 | int packetbuf_d_set_addr(uint8_t type, const rimeaddr_t *addr){
38 |
39 | switch(type){
40 | case PACKETBUF_D_ADDR_SENDER:
41 | memcpy(&packetbuf_d_addr_sender, addr, sizeof(rimeaddr_t));
42 | return 1;
43 | break;
44 |
45 | default:
46 | return 0;
47 | break;
48 | }
49 |
50 | }
51 |
52 | /*----------------------------------------------------------------------------*/
53 | const rimeaddr_t *packetbuf_d_addr(uint8_t type){
54 | if(type == PACKETBUF_D_ADDR_SENDER){
55 | return &packetbuf_d_addr_sender;
56 | } else {
57 | return NULL;
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/module_xtcp/src/xtcp_uip6/contiki/net/rime/rimeaddr.c:
--------------------------------------------------------------------------------
1 | /**
2 | * \addtogroup rimeaddr
3 | * @{
4 | */
5 |
6 | /*
7 | * Copyright (c) 2007, Swedish Institute of Computer Science.
8 | * All rights reserved.
9 | *
10 | * Redistribution and use in source and binary forms, with or without
11 | * modification, are permitted provided that the following conditions
12 | * are met:
13 | * 1. Redistributions of source code must retain the above copyright
14 | * notice, this list of conditions and the following disclaimer.
15 | * 2. Redistributions in binary form must reproduce the above copyright
16 | * notice, this list of conditions and the following disclaimer in the
17 | * documentation and/or other materials provided with the distribution.
18 | * 3. Neither the name of the Institute nor the names of its contributors
19 | * may be used to endorse or promote products derived from this software
20 | * without specific prior written permission.
21 | *
22 | * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
23 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
26 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 | * SUCH DAMAGE.
33 | *
34 | * This file is part of the Contiki operating system.
35 | *
36 | */
37 |
38 | /**
39 | * \file
40 | * Functions for manipulating Rime addresses
41 | * \author
42 | * Adam Dunkels
43 | */
44 |
45 | #include "net/rime/rimeaddr.h"
46 | #include
47 |
48 | rimeaddr_t rimeaddr_node_addr;
49 | #if RIMEADDR_SIZE == 2
50 | const rimeaddr_t rimeaddr_null = { { 0, 0 } };
51 | #else /*RIMEADDR_SIZE == 2*/
52 | #if RIMEADDR_SIZE == 8
53 | const rimeaddr_t rimeaddr_null = { { 0, 0, 0, 0, 0, 0, 0, 0 } };
54 | #endif /*RIMEADDR_SIZE == 8*/
55 | #endif /*RIMEADDR_SIZE == 2*/
56 |
57 |
58 | /*---------------------------------------------------------------------------*/
59 | void
60 | rimeaddr_copy(rimeaddr_t *dest, const rimeaddr_t *src)
61 | {
62 | memcpy(dest, src, RIMEADDR_SIZE);
63 | }
64 | /*---------------------------------------------------------------------------*/
65 | int
66 | rimeaddr_cmp(const rimeaddr_t *addr1, const rimeaddr_t *addr2)
67 | {
68 | return (memcmp(addr1, addr2, RIMEADDR_SIZE) == 0);
69 | }
70 | /*---------------------------------------------------------------------------*/
71 | void
72 | rimeaddr_set_node_addr(rimeaddr_t *t)
73 | {
74 | rimeaddr_copy(&rimeaddr_node_addr, t);
75 | }
76 | /*---------------------------------------------------------------------------*/
77 | /** @} */
78 |
--------------------------------------------------------------------------------
/module_xtcp/src/xtcp_uip6/contiki/net/uip-packetqueue.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | #include "net/uip.h"
4 |
5 | #include "lib/memb.h"
6 |
7 | #include "net/uip-packetqueue.h"
8 |
9 | #define MAX_NUM_QUEUED_PACKETS 2
10 | MEMB(packets_memb, struct uip_packetqueue_packet, MAX_NUM_QUEUED_PACKETS);
11 |
12 | #define DEBUG 0
13 | #if DEBUG
14 | #include
15 | #define PRINTF(...) printf(__VA_ARGS__)
16 | #else
17 | #define PRINTF(...)
18 | #endif
19 |
20 | /*---------------------------------------------------------------------------*/
21 | static void
22 | packet_timedout(void *ptr)
23 | {
24 | struct uip_packetqueue_handle *h = ptr;
25 |
26 | PRINTF("uip_packetqueue_free timed out %p\n", h);
27 | memb_free(&packets_memb, h->packet);
28 | h->packet = NULL;
29 | }
30 | /*---------------------------------------------------------------------------*/
31 | void
32 | uip_packetqueue_new(struct uip_packetqueue_handle *handle)
33 | {
34 | PRINTF("uip_packetqueue_new %p\n", handle);
35 | handle->packet = NULL;
36 | }
37 | /*---------------------------------------------------------------------------*/
38 | struct uip_packetqueue_packet *
39 | uip_packetqueue_alloc(struct uip_packetqueue_handle *handle, clock_time_t lifetime)
40 | {
41 | PRINTF("uip_packetqueue_alloc %p\n", handle);
42 | if(handle->packet != NULL) {
43 | PRINTF("alloced\n");
44 | return NULL;
45 | }
46 | handle->packet = memb_alloc(&packets_memb);
47 | if(handle->packet != NULL) {
48 | ctimer_set(&handle->packet->lifetimer, lifetime,
49 | packet_timedout, handle);
50 | } else {
51 | PRINTF("uip_packetqueue_alloc failed\n");
52 | }
53 | return handle->packet;
54 | }
55 | /*---------------------------------------------------------------------------*/
56 | void
57 | uip_packetqueue_free(struct uip_packetqueue_handle *handle)
58 | {
59 | PRINTF("uip_packetqueue_free %p\n", handle);
60 | if(handle->packet != NULL) {
61 | ctimer_stop(&handle->packet->lifetimer);
62 | memb_free(&packets_memb, handle->packet);
63 | handle->packet = NULL;
64 | }
65 | }
66 | /*---------------------------------------------------------------------------*/
67 | uint8_t *
68 | uip_packetqueue_buf(struct uip_packetqueue_handle *h)
69 | {
70 | return h->packet != NULL? h->packet->queue_buf: NULL;
71 | }
72 | /*---------------------------------------------------------------------------*/
73 | uint16_t
74 | uip_packetqueue_buflen(struct uip_packetqueue_handle *h)
75 | {
76 | return h->packet != NULL? h->packet->queue_buf_len: 0;
77 | }
78 | /*---------------------------------------------------------------------------*/
79 | void
80 | uip_packetqueue_set_buflen(struct uip_packetqueue_handle *h, uint16_t len)
81 | {
82 | if(h->packet != NULL) {
83 | h->packet->queue_buf_len = len;
84 | }
85 | }
86 | /*---------------------------------------------------------------------------*/
87 |
--------------------------------------------------------------------------------
/module_xtcp/src/xtcp_uip6/contiki/net/uip-packetqueue.h:
--------------------------------------------------------------------------------
1 | #ifndef UIP_PACKETQUEUE_H
2 | #define UIP_PACKETQUEUE_H
3 |
4 | #include "sys/ctimer.h"
5 |
6 | struct uip_packetqueue_handle;
7 |
8 | struct uip_packetqueue_packet {
9 | struct uip_ds6_queued_packet *next;
10 | uint8_t queue_buf[UIP_BUFSIZE - UIP_LLH_LEN];
11 | uint16_t queue_buf_len;
12 | struct ctimer lifetimer;
13 | struct uip_packetqueue_handle *handle;
14 | };
15 |
16 | struct uip_packetqueue_handle {
17 | struct uip_packetqueue_packet *packet;
18 | };
19 |
20 | void uip_packetqueue_new(struct uip_packetqueue_handle *handle);
21 |
22 |
23 | struct uip_packetqueue_packet *
24 | uip_packetqueue_alloc(struct uip_packetqueue_handle *handle, clock_time_t lifetime);
25 |
26 |
27 | void
28 | uip_packetqueue_free(struct uip_packetqueue_handle *handle);
29 |
30 | uint8_t *uip_packetqueue_buf(struct uip_packetqueue_handle *h);
31 | uint16_t uip_packetqueue_buflen(struct uip_packetqueue_handle *h);
32 | void uip_packetqueue_set_buflen(struct uip_packetqueue_handle *h, uint16_t len);
33 |
34 |
35 | #endif /* UIP_PACKETQUEUE_H */
36 |
--------------------------------------------------------------------------------
/module_xtcp/src/xtcp_uip6/contiki/sys/arg.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2003, Adam Dunkels.
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without
6 | * modification, are permitted provided that the following conditions
7 | * are met:
8 | * 1. Redistributions of source code must retain the above copyright
9 | * notice, this list of conditions and the following disclaimer.
10 | * 2. Redistributions in binary form must reproduce the above
11 | * copyright notice, this list of conditions and the following
12 | * disclaimer in the documentation and/or other materials provided
13 | * with the distribution.
14 | * 3. The name of the author may not be used to endorse or promote
15 | * products derived from this software without specific prior
16 | * written permission.
17 | *
18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
19 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
22 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
24 | * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | *
30 | * This file is part of the Contiki desktop OS
31 | *
32 | *
33 | */
34 | #ifndef __ARG_H__
35 | #define __ARG_H__
36 |
37 | void arg_init(void);
38 |
39 | char *arg_alloc(char size);
40 | void arg_free(char *arg);
41 |
42 | #endif /* __ARG_H__ */
43 |
--------------------------------------------------------------------------------
/module_xtcp/src/xtcp_uip6/uip_arch/clock-arch.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2011, XMOS Ltd, All rights reserved
2 | // This software is freely distributable under a derivative of the
3 | // University of Illinois/NCSA Open Source License posted in
4 | // LICENSE.txt and at
5 |
6 | /*
7 | * Copyright (c) 2006, Swedish Institute of Computer Science.
8 | * All rights reserved.
9 | *
10 | * Redistribution and use in source and binary forms, with or without
11 | * modification, are permitted provided that the following conditions
12 | * are met:
13 | * 1. Redistributions of source code must retain the above copyright
14 | * notice, this list of conditions and the following disclaimer.
15 | * 2. Redistributions in binary form must reproduce the above copyright
16 | * notice, this list of conditions and the following disclaimer in the
17 | * documentation and/or other materials provided with the distribution.
18 | * 3. Neither the name of the Institute nor the names of its contributors
19 | * may be used to endorse or promote products derived from this software
20 | * without specific prior written permission.
21 | *
22 | * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
23 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
26 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 | * SUCH DAMAGE.
33 | *
34 | * This file is part of the uIP TCP/IP stack
35 | *
36 | * $Id: clock-arch.h,v 1.2 2006/06/12 08:00:31 adam Exp $
37 | */
38 |
39 | #ifndef __CLOCK_ARCH_H__
40 | #define __CLOCK_ARCH_H__
41 |
42 | typedef int clock_time_t;
43 | #define CLOCK_CONF_SECOND 1000
44 |
45 | #endif /* __CLOCK_ARCH_H__ */
46 |
--------------------------------------------------------------------------------
/module_xtcp/src/xtcp_uip6/uip_server.c:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2011, XMOS Ltd, All rights reserved
2 | // This software is freely distributable under a derivative of the
3 | // University of Illinois/NCSA Open Source License posted in
4 | // LICENSE.txt and at
5 |
6 | #include
7 | #include
8 | #include
9 |
10 | #include "xtcp_conf_derived.h"
11 |
12 | #ifndef UIP_USE_SINGLE_THREADED_ETHERNET
13 |
14 | #include "uip.h"
15 | #include "uip_arp.h"
16 | #include "xcoredev.h"
17 | #include "xtcp_server.h"
18 | #include "timer.h"
19 | #include "uip_server.h"
20 | #include "ethernet_rx_client.h"
21 | #include "ethernet_tx_client.h"
22 | #include "uip_xtcp.h"
23 |
24 | // Functions from the uip_server_support file
25 | extern void uip_printip4(const uip_ipaddr_t ip4);
26 | extern void uip_server_init(chanend xtcp[], int num_xtcp, xtcp_ipconfig_t* ipconfig, unsigned char mac_address[6]);
27 | extern void xtcpd_check_connection_poll(chanend mac_tx);
28 | extern void xtcp_tx_buffer(chanend mac_tx);
29 | extern void xtcp_process_incoming_packet(chanend mac_tx);
30 | extern void xtcp_process_udp_acks(chanend mac_tx);
31 | extern void xtcp_process_periodic_timer(chanend mac_tx);
32 |
33 |
34 | // Global variables from the uip_server_support file
35 | extern int uip_static_ip;
36 | extern xtcp_ipconfig_t uip_static_ipconfig;
37 |
38 | #if XTCP_SEPARATE_MAC
39 |
40 | void xtcp_server_uip(chanend mac_rx, chanend mac_tx, chanend xtcp[], int num_xtcp,
41 | xtcp_ipconfig_t *ipconfig) {
42 |
43 | struct uip_timer periodic_timer, arp_timer, autoip_timer;
44 | unsigned char hwaddr[6];
45 |
46 | timer_set(&periodic_timer, CLOCK_SECOND / 10);
47 | timer_set(&autoip_timer, CLOCK_SECOND / 2);
48 | timer_set(&arp_timer, CLOCK_SECOND * 10);
49 |
50 | xcoredev_init(mac_rx, mac_tx);
51 |
52 | mac_get_macaddr(mac_tx, hwaddr);
53 |
54 | uip_server_init(xtcp, num_xtcp, ipconfig, hwaddr);
55 |
56 | // Main uIP service loop
57 | while (1)
58 | {
59 | xtcpd_service_clients(xtcp, num_xtcp);
60 |
61 | xtcpd_check_connection_poll(mac_tx);
62 |
63 | xtcpd_uip_checkstate();
64 | uip_len = xcoredev_read(mac_rx, UIP_CONF_BUFFER_SIZE);
65 | if (uip_len > 0) {
66 | xtcp_process_incoming_packet(mac_tx);
67 | }
68 |
69 | xtcp_process_udp_acks(mac_tx);
70 |
71 |
72 | if (timer_expired(&arp_timer)) {
73 | timer_reset(&arp_timer);
74 | uip_arp_timer();
75 | }
76 |
77 | #if UIP_USE_AUTOIP
78 | if (timer_expired(&autoip_timer)) {
79 | timer_reset(&autoip_timer);
80 | autoip_periodic();
81 | if (uip_len > 0) {
82 | xtcp_tx_buffer(mac_tx);
83 | }
84 | }
85 | #endif
86 |
87 | if (timer_expired(&periodic_timer)) {
88 |
89 | xtcp_process_periodic_timer(mac_tx);
90 |
91 | timer_reset(&periodic_timer);
92 | }
93 |
94 | }
95 | return;
96 | }
97 |
98 | #endif // XTCP_SEPARATE_MAC
99 |
100 | #endif
101 |
--------------------------------------------------------------------------------
/module_xtcp/src/xtcp_uip6/uip_server.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2011, XMOS Ltd, All rights reserved
2 | // This software is freely distributable under a derivative of the
3 | // University of Illinois/NCSA Open Source License posted in
4 | // LICENSE.txt and at
5 |
6 | #ifndef _uip_server_h_
7 | #define _uip_server_h_
8 | #include
9 | #include "xtcp_client.h"
10 |
11 | /** uIP based xtcp server.
12 | *
13 | * \param mac_rx Rx channel connected to ethernet server
14 | * \param mac_tx Tx channel connected to ethernet server
15 | * \param xtcp Client channel array
16 | * \param num_xtcp_clients The number of clients connected to the server
17 | * \param ipconfig An data structure representing the IP config
18 | * (ip address, netmask and gateway) of the device.
19 | * Leave NULL for automatic address allocation.
20 | *
21 | * This function implements an xtcp tcp/ip server in a logical core.
22 | * It uses a port of the uIP stack which is then interfaces over the
23 | * xtcp channel array.
24 | *
25 | * The IP setup is based on the ipconfig parameter. If this
26 | * parameter is NULL then an automatic IP address is found (using dhcp or
27 | * ipv4 link local addressing if no dhcp server is present). Otherwise
28 | * it uses the ipconfig structure to allocate a static ip address.
29 | *
30 | * The clients can communicate with the server using the API found
31 | * in xtcp_client.h
32 | *
33 | * \sa xtcp_event()
34 | **/
35 | void
36 | xtcp_server_uip(chanend mac_rx,
37 | chanend mac_tx,
38 | chanend xtcp[],
39 | int num_xtcp_clients,
40 | NULLABLE_REFERENCE_PARAM(xtcp_ipconfig_t,ipconfig));
41 |
42 | #define uip_server xtcp_server_uip
43 |
44 | #endif // _uip_server_h_
45 |
--------------------------------------------------------------------------------
/module_xtcp/src/xtcp_uip6/uip_server_support.h:
--------------------------------------------------------------------------------
1 | /*****************************************************************************
2 | *
3 | * Filename: uip_server_support.h
4 | * Author: Christian Schlittler
5 | * Version: 1.0
6 | * Creation date: 25.10.2013
7 | *
8 | * Copyright: Christian Schlittler, christian.schlittler@gmx.ch
9 | *
10 | * Project: XMOS and 6LoWPAN
11 | * Target: XMOS sliceKIT with RFSlice extension
12 | * Compiler:
13 | *
14 | * -----------------------------------------------------------------------------
15 | *
16 | * History:
17 | *
18 | * -----------------------------------------------------------------------------
19 | *
20 | * Usage:
21 | *
22 | **************************************************************************** */
23 |
24 | #ifndef UIP_SERVER_SUPPORT_H_
25 | #define UIP_SERVER_SUPPORT_H_
26 |
27 | #include
28 | #include
29 |
30 | typedef enum xtcp_tmr_event_type_t {
31 | XTCP_TMR_PERIODIC,
32 | } xtcp_tmr_event_type_t;
33 |
34 | void uip_server_init(chanend xtcp[], int num_xtcp,
35 | REFERENCE_PARAM(xtcp_ipconfig_t, ipconfig),
36 | unsigned char mac_address[6]);
37 | void xtcpd_check_connection_poll(chanend mac_tx);
38 | void xtcp_tx_buffer(chanend mac_tx);
39 | void xtcp_process_incoming_packet(chanend mac_tx);
40 | void xtcp_process_udp_acks(chanend mac_tx);
41 | void xtcp_process_timer(chanend mac_tx, xtcp_tmr_event_type_t event);
42 |
43 | void xtcpip_input(chanend mac_tx);
44 | void xtcpip_ipv6_output(chanend mac_tx);
45 |
46 |
47 | #endif /* UIP_SERVER_SUPPORT_H_ */
48 |
--------------------------------------------------------------------------------
/module_xtcp/src/xtcp_uip6/uip_single_server.h:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | #include "mii.h"
4 | #include "smi.h"
5 | #include "xtcp_client.h"
6 |
7 | /**
8 | * The top level thread function for a single threaded XTCP server, interfacing
9 | * to a single thread ethernet MII.
10 | * *
11 | * \note This function should be used in a top level 'par' in the main function.
12 | * It will internally create the single MII thread.
13 | *
14 | * \param p_mii_resetn Optional port which resets the PHY
15 | * \param smi Structure describing the SMI ports
16 | * \param mii Structure describing the MII ports
17 | * \param xtcp Array of client comms channels
18 | * \param num_xtcp The number of TCP client channels
19 | * \param ipconfig The configuration structure for the IP address
20 | * \param mac_address The unicast MAC address for this device
21 | *
22 | */
23 | void uip_single_server(out port ?p_mii_resetn,
24 | smi_interface_t &smi,
25 | mii_interface_lite_t &mii,
26 | chanend xtcp[], int num_xtcp,
27 | xtcp_ipconfig_t& ipconfig,
28 | char mac_address[6]);
29 |
--------------------------------------------------------------------------------
/module_xtcp/src/xtcp_uip6/uip_xtcp.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2011, XMOS Ltd, All rights reserved
2 | // This software is freely distributable under a derivative of the
3 | // University of Illinois/NCSA Open Source License posted in
4 | // LICENSE.txt and at
5 |
6 | #ifndef _UIP_XTCP_H_
7 | #define _UIP_XTCP_H_
8 |
9 | #include
10 | #include
11 |
12 | void xtcpd_uip_checkstate(void);
13 | void uip_xtcp_up(void);
14 | void uip_xtcp_down(void);
15 | void uip_xtcp_checklink(chanend connect_status);
16 | int uip_xtcp_get_ifstate(void);
17 | void uip_linkdown(void);
18 | void uip_linkup(void);
19 | void uip_xtcp_null_events(void);
20 |
21 | /**
22 | * \brief Output packet to layer 2
23 | * The eventual parameter is the MAC address of the destination.
24 | */
25 | #if UIP_CONF_IPV6
26 | uint8_t xtcpip_output(uip_lladdr_t *, chanend mac_tx);
27 | #else
28 | uint8_t xtcpip_output(chanend mac_tx);
29 | #endif
30 |
31 | /**
32 | * \brief This function does address resolution and then calls tcpip_output
33 | */
34 | #if UIP_CONF_IPV6
35 | void xtcpip_ipv6_output(chanend mac_tx);
36 | #endif
37 |
38 | #endif // _UIP_XTCP_H_
39 |
--------------------------------------------------------------------------------
/module_xtcp/src/xtcp_uip6/xcoredev.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2011, XMOS Ltd, All rights reserved
2 | // This software is freely distributable under a derivative of the
3 | // University of Illinois/NCSA Open Source License posted in
4 | // LICENSE.txt and at
5 |
6 | #ifndef __XCOREDEV_H__
7 | #define __XCOREDEV_H__
8 |
9 | #include
10 |
11 | void xcoredev_init(chanend mac_rx, chanend mac_tx);
12 | unsigned int xcoredev_read(chanend mac_rx, int n);
13 | void xcoredev_send(chanend mac_tx);
14 |
15 | #endif /* __XCOREDEV_H__ */
16 |
--------------------------------------------------------------------------------
/module_xtcp/src/xtcp_uip6/xtcp_server_conf.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2011, XMOS Ltd, All rights reserved
2 | // This software is freely distributable under a derivative of the
3 | // University of Illinois/NCSA Open Source License posted in
4 | // LICENSE.txt and at
5 |
6 | #include "timer.h"
7 | #include "xtcp_client.h"
8 |
9 | typedef struct xtcp_server_state_t {
10 | int send_request;
11 | int abort_request;
12 | int close_request;
13 | int poll_interval;
14 | int connect_request;
15 | int ack_request;
16 | int closed;
17 | struct uip_timer tmr;
18 | int uip_conn;
19 | int ack_recv_mode;
20 | #ifdef XTCP_ENABLE_PARTIAL_PACKET_ACK
21 | int accepts_partial_ack;
22 | #endif
23 | } xtcp_server_state_t;
24 |
--------------------------------------------------------------------------------
/module_xtcp/xtcp_conf_example.h:
--------------------------------------------------------------------------------
1 | //Define this to be true if you want to connect the tcp task
2 | //to a separate ethernet mac
3 | #define XTCP_SEPARATE_MAC 0
4 |
--------------------------------------------------------------------------------
/module_zeroconf/.makefile:
--------------------------------------------------------------------------------
1 | all:
2 | @echo "** Module only - only builds as part of application **"
3 |
4 |
5 | clean:
6 | @echo "** Module only - only builds as part of application **"
7 |
8 |
9 |
--------------------------------------------------------------------------------
/module_zeroconf/.xproject:
--------------------------------------------------------------------------------
1 | sc_xtcpXM-001955-SM3.2.1rc0
--------------------------------------------------------------------------------
/module_zeroconf/README.rst:
--------------------------------------------------------------------------------
1 |
2 | ================
3 |
4 | :scope:
5 | :description:
6 | :keywords:
7 | :boards:
8 |
9 |
10 | This module provides multicast DNS and DNS-SD protocol implementations
11 | to enable zero configuration networking.
12 |
--------------------------------------------------------------------------------
/module_zeroconf/mdns/mdns_support.xc:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2011, XMOS Ltd, All rights reserved
2 | // This software is freely distributable under a derivative of the
3 | // University of Illinois/NCSA Open Source License posted in
4 | // LICENSE.txt and at
5 |
6 | #include "mdns.h"
7 |
8 | mdns_event mdns_handle_event(chanend tcp_svr,
9 | xtcp_connection_t &conn,
10 | unsigned int t);
11 |
12 | mdns_event mdns_xtcp_handler(chanend tcp_svr,
13 | xtcp_connection_t &conn)
14 | {
15 | timer tmr;
16 | unsigned t;
17 | tmr :> t;
18 | return mdns_handle_event(tcp_svr, conn, t);
19 | }
20 |
21 |
22 |
--------------------------------------------------------------------------------
/module_zeroconf/module_build_info:
--------------------------------------------------------------------------------
1 | # This file describes how this module will affect the application
2 | # using it. The file is included in the Makefile of the main application.
3 | #
4 | # The module contributes to the build of the application by extending
5 | # the following variables:
6 | #
7 | # SOURCE_DIRS - directories with source files to be included in the build
8 | # INCLUDE_DIRS - directories to be added to the include path during the build
9 | # LIB_DIRS - directories containing libraries to be linked into the build
10 | #
11 | # Note that all the source files in each directory in SOURCE_DIRS
12 | # will be compiled (you do not need to name the files individually).
13 | #
14 |
15 | MODULE_DIRS = mdns
16 |
17 | SOURCE_DIRS += $(MODULE_DIRS)
18 | INCLUDE_DIRS += $(MODULE_DIRS)
19 |
20 | # You can change the flags of a set of files using the SET_XCC_[lang]_FLAGS
21 | # functions. The first argument is a list of directories and the
22 | # second argument is the value to set the compile flags to. e.g.
23 | #
24 | # $(call SET_XCC_C_FLAGS, mydir1 mydir2, $(XCC_FLAGS) -g -O3)
25 |
26 | $(call SET_XCC_C_FLAGS, $(MODULE_DIRS), $(XCC_FLAGS) -g -Os)
27 |
28 | # You can change the flags of an individual file by setting the
29 | # XCC_FLAGS_[filename] variable. e.g.
30 | #
31 | # XCC_FLAGS_myfile.xc = $(XCC_FLAGS) -fsubword-select
32 |
33 |
34 | # You can exclude particular files from the build even if they occur
35 | # within SOURCE_DIRS by adding the file name (with no path) to the
36 | # EXCLUDE_FILES variable e..g
37 | #
38 | # EXCLUDE_FILES += myfile.xc
39 | #
40 |
--------------------------------------------------------------------------------
/tests/scripts/stream/stream_out.c:
--------------------------------------------------------------------------------
1 | /*
2 | To build this on Windows, open a visual studio (express) C++ command prompt and type:
3 |
4 | cl -D__WIN32__ stream_out.c
5 | */
6 |
7 |
8 | #ifndef __WIN32__
9 |
10 | #include
11 | #include
12 | #include
13 | #include
14 |
15 | #define SOCKET int
16 | #define INVALID_SOCKET -1
17 |
18 | #else
19 |
20 | #define WIN32_LEAN_AND_MEAN
21 | #include
22 | #pragma comment(lib, "ws2_32.lib")
23 |
24 | #endif
25 |
26 | int data[1460/4];
27 |
28 | int main(int argc, char *argv[]) {
29 | unsigned long addr;
30 | SOCKET s;
31 | struct sockaddr_in sa;
32 | int i;
33 |
34 | #ifdef __WIN32__
35 | {
36 | WSADATA wsa;
37 | WSAStartup(MAKEWORD(2,2), &wsa);
38 | }
39 | #endif
40 |
41 | if (argc < 3) {
42 | puts("Please provide IP address in dotted decimal form");
43 | exit(0);
44 | }
45 |
46 | sa.sin_family = AF_INET;
47 | sa.sin_port = htons(atoi(argv[2]));
48 | sa.sin_addr.s_addr = inet_addr(argv[1]);
49 | if (sa.sin_addr.s_addr == INADDR_NONE) {
50 | puts("Invalid IP address");
51 | exit(0);
52 | }
53 |
54 | // Open a socket
55 | //s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
56 | s = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
57 | if (s == INVALID_SOCKET) {
58 | puts("Unable to open socket");
59 | exit(0);
60 | }
61 |
62 | if (connect(s, (struct sockaddr*)&sa, sizeof(struct sockaddr_in)) != 0) {
63 | puts("Unable to connect");
64 | exit(0);
65 | }
66 |
67 | for (i=0; i<1000000; ++i) {
68 | data[0] = i;
69 | send(s, data, sizeof(data), 0);
70 | }
71 |
72 | return 0;
73 | }
74 |
--------------------------------------------------------------------------------
/tests/scripts/test_tcp_receive.py:
--------------------------------------------------------------------------------
1 | import socket,sys,time,random,struct
2 |
3 | sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
4 | sock.connect((sys.argv[1], 101))
5 |
6 | print "Connected"
7 |
8 | msg = "Start"
9 | sock.send(msg[0:])
10 |
11 | while (True) :
12 | msg = sock.recv(4096)
13 |
14 | print "Done"
15 | sock.close()
16 |
--------------------------------------------------------------------------------
/tests/scripts/test_tcp_send.py:
--------------------------------------------------------------------------------
1 | import socket,sys,time,random,struct
2 |
3 | sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
4 | sock.connect((sys.argv[1], 102))
5 |
6 | print "Connected"
7 |
8 | n = 0
9 |
10 | for i in range(0,99999):
11 | msg = struct.pack('I', n)
12 |
13 | for j in range(0,300):
14 | msg = msg + 'xx'
15 |
16 | sock.send(msg[0:])
17 |
18 | n = n + 1
19 | #time.sleep(2.0)
20 |
21 | print "Done"
22 | sock.close()
23 |
--------------------------------------------------------------------------------
/tests/scripts/test_udp_multiple_open_send.py:
--------------------------------------------------------------------------------
1 | import socket,sys,time,random,struct
2 |
3 | n = 0
4 |
5 | for i in range(0,99999):
6 | sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
7 | sock.connect((sys.argv[1], 101))
8 |
9 | msg = struct.pack('I', n)
10 |
11 | for j in range(0,300):
12 | msg = msg + 'xx'
13 |
14 | sock.send(msg[0:])
15 |
16 | n = n + 1
17 | #time.sleep(2.0)
18 |
19 | print "Done"
20 | sock.close()
21 |
--------------------------------------------------------------------------------
/tests/scripts/test_udp_receive.py:
--------------------------------------------------------------------------------
1 | import socket,sys,time,random,struct
2 |
3 | sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
4 | sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
5 | sock.connect((sys.argv[1], 100))
6 |
7 | print "Connected"
8 |
9 | msg = "Start"
10 | sock.send(msg[0:])
11 |
12 | time.sleep(100)
13 |
14 | print "Done"
15 | sock.close()
16 |
--------------------------------------------------------------------------------
/tests/scripts/test_udp_send.py:
--------------------------------------------------------------------------------
1 | import socket,sys,time,random,struct
2 |
3 | sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
4 | sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
5 | sock.connect((sys.argv[1], 100))
6 |
7 | print "Connected"
8 |
9 | n = 0
10 |
11 | for i in range(0,99999):
12 | msg = struct.pack('I', n)
13 |
14 | for j in range(0,300):
15 | msg = msg + 'xx'
16 |
17 | sock.send(msg[0:])
18 |
19 | n = n + 1
20 | #time.sleep(2.0)
21 |
22 | print "Done"
23 | sock.close()
24 |
--------------------------------------------------------------------------------
/tests/scripts/test_udp_slow_send.pl:
--------------------------------------------------------------------------------
1 | import socket,sys,time,random,struct
2 |
3 | sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
4 | sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
5 | sock.connect((sys.argv[1], 100))
6 |
7 | print "Connected"
8 |
9 | n = 0
10 |
11 | for i in range(0,99999):
12 | msg = struct.pack('I', n)
13 |
14 | for j in range(0,300):
15 | msg = msg + 'xx'
16 |
17 | sock.send(msg[0:])
18 |
19 | n = n + 1
20 | time.sleep(2.0)
21 |
22 | print "Done"
23 | sock.close()
24 |
--------------------------------------------------------------------------------
/tests/test_multi_client/.project:
--------------------------------------------------------------------------------
1 | test_multi_client com.xmos.cdt.core.ModulePathBuilder org.eclipse.cdt.managedbuilder.core.genmakebuilder clean,full,incremental, ?children? ?name?=outputEntries\|?children?=?name?=entry\\\\|\\|\|| ?name? org.eclipse.cdt.make.core.append_environment true org.eclipse.cdt.make.core.buildArguments CONFIG=Debug org.eclipse.cdt.make.core.buildCommand xmake org.eclipse.cdt.make.core.cleanBuildTarget clean org.eclipse.cdt.make.core.contents org.eclipse.cdt.make.core.activeConfigSettings org.eclipse.cdt.make.core.enableAutoBuild false org.eclipse.cdt.make.core.enableCleanBuild true org.eclipse.cdt.make.core.enableFullBuild true org.eclipse.cdt.make.core.stopOnError true org.eclipse.cdt.make.core.useDefaultBuildCmd false org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder full,incremental, org.eclipse.cdt.core.cnature org.eclipse.cdt.managedbuilder.core.managedBuildNature org.eclipse.cdt.managedbuilder.core.ScannerConfigNature com.xmos.cdt.core.XdeProjectNature
2 |
--------------------------------------------------------------------------------
/tests/test_multi_client/.xproject:
--------------------------------------------------------------------------------
1 | sc_xtcpXM-000074-SW3.0.0rc1
--------------------------------------------------------------------------------
/tests/test_multi_client/Makefile:
--------------------------------------------------------------------------------
1 | # The TARGET variable determines what target system the application is
2 | # compiled for. It either refers to an XN file in the source directories
3 | # or a valid argument for the --target option when compiling
4 | TARGET = XR-AVB-LC-BRD
5 |
6 | # The APP_NAME variable determines the name of the final .xe file. It should
7 | # not include the .xe postfix. If left blank the name will default to
8 | # the project name
9 | APP_NAME =
10 |
11 | # The USED_MODULES variable lists other module used by the application.
12 | USED_MODULES = module_xtcp module_ethernet_board_support
13 |
14 | # The flags passed to xcc when building the application
15 | # You can also set the following to override flags for a particular language:
16 | # XCC_XC_FLAGS, XCC_C_FLAGS, XCC_ASM_FLAGS, XCC_CPP_FLAGS
17 | # If the variable XCC_MAP_FLAGS is set it overrides the flags passed to
18 | # xcc for the final link (mapping) stage.
19 | XCC_FLAGS = -g -O2 -save-temps
20 |
21 | # The VERBOSE variable, if set to 1, enables verbose output from the make
22 | # system.
23 | VERBOSE = 0
24 |
25 | # This change to the module path is so that this application can be in the
26 | # tests sub-directory in it's git repo
27 | ifeq ($(notdir $(abspath ..)),tests)
28 | PATHSEP = $(if $(findstring Windows, $(OS))$(findstring WINDOWS,$(OS)),;,:)
29 | XMOS_MODULE_PATH := $(XMOS_MODULE_PATH)$(PATHSEP)../../..
30 | endif
31 |
32 |
33 | #=============================================================================
34 | # The following part of the Makefile includes the common build infrastructure
35 | # for compiling XMOS applications. You should not need to edit below here.
36 |
37 | XMOS_MAKE_PATH ?= ../..
38 | include $(XMOS_MAKE_PATH)/xcommon/module_xcommon/build/Makefile.common
39 |
--------------------------------------------------------------------------------
/tests/test_multi_client/test_udp.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/python
2 | import socket,sys
3 |
4 | # This simple script sends a UDP packet to port 15533 at the
5 | # IP address given as the first argument to the script
6 | # This is to test the simple UDP example XC program
7 |
8 | sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
9 |
10 | print "Connecting.."
11 | sock.connect((sys.argv[1], 15533))
12 | print "Connected"
13 |
14 | msg = "hello world"
15 | print "Sending message: " + msg
16 | sock.send(msg)
17 |
18 | print "Closing..."
19 | sock.close()
20 | print "Closed"
21 |
--------------------------------------------------------------------------------
/tests/test_regression/.project:
--------------------------------------------------------------------------------
1 | app_xtcp_tests com.xmos.cdt.core.ModulePathBuilder org.eclipse.cdt.managedbuilder.core.genmakebuilder clean,full,incremental, ?children? ?name?=outputEntries\|?children?=?name?=entry\\\\|\\|\|| ?name? org.eclipse.cdt.make.core.append_environment true org.eclipse.cdt.make.core.buildArguments CONFIG=Debug org.eclipse.cdt.make.core.buildCommand xmake org.eclipse.cdt.make.core.cleanBuildTarget clean org.eclipse.cdt.make.core.contents org.eclipse.cdt.make.core.activeConfigSettings org.eclipse.cdt.make.core.enableAutoBuild false org.eclipse.cdt.make.core.enableCleanBuild true org.eclipse.cdt.make.core.enableFullBuild true org.eclipse.cdt.make.core.stopOnError true org.eclipse.cdt.make.core.useDefaultBuildCmd false org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder full,incremental, org.eclipse.cdt.core.cnature org.eclipse.cdt.managedbuilder.core.managedBuildNature org.eclipse.cdt.managedbuilder.core.ScannerConfigNature com.xmos.cdt.core.XdeProjectNature
--------------------------------------------------------------------------------
/tests/test_regression/.xproject:
--------------------------------------------------------------------------------
1 | sc_xtcpXM-000074-SW3.0.0rc1
--------------------------------------------------------------------------------
/tests/test_regression/Makefile:
--------------------------------------------------------------------------------
1 | # The TARGET variable determines what target system the application is
2 | # compiled for. It either refers to an XN file in the source directories
3 | # or a valid argument for the --target option when compiling.
4 |
5 | TARGET = SLICEKIT-L2
6 |
7 | # The APP_NAME variable determines the name of the final .xe file. It should
8 | # not include the .xe postfix. If left blank the name will default to
9 | # the project name
10 |
11 | APP_NAME =
12 |
13 | # The flags passed to xcc when building the application
14 | # You can also set the following to override flags for a particular language:
15 | #
16 | # XCC_XC_FLAGS, XCC_C_FLAGS, XCC_ASM_FLAGS, XCC_CPP_FLAGS
17 | #
18 | # If the variable XCC_MAP_FLAGS is set it overrides the flags passed to
19 | # xcc for the final link (mapping) stage.
20 |
21 | XCC_FLAGS = -O3 -save-temps -g -report -Xmapper --map -Xmapper MAPFILE
22 |
23 | # The USED_MODULES variable lists other module used by the application.
24 | USED_MODULES = module_xtcp module_ethernet_board_support
25 |
26 | # This change to the module path is so that this application can be in the
27 | # tests sub-directory in it's git repo
28 | ifeq ($(notdir $(abspath ..)),tests)
29 | PATHSEP = $(if $(findstring Windows, $(OS))$(findstring WINDOWS,$(OS)),;,:)
30 | XMOS_MODULE_PATH := $(XMOS_MODULE_PATH)$(PATHSEP)../../..
31 | endif
32 |
33 |
34 |
35 | #=============================================================================
36 | # The following part of the Makefile includes the common build infrastructure
37 | # for compiling XMOS applications. You should not need to edit below here.
38 |
39 | XMOS_MAKE_PATH ?= ../..
40 | include $(XMOS_MAKE_PATH)/xcommon/module_xcommon/build/Makefile.common
41 |
--------------------------------------------------------------------------------
/tests/test_regression/src/ethernet_conf.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2011, XMOS Ltd, All rights reserved
2 | // This software is freely distributable under a derivative of the
3 | // University of Illinois/NCSA Open Source License posted in
4 | // LICENSE.txt and at
5 |
6 | // The maximum ip payload size we can use is 500 bytes, so
7 | // there is no point accepted larger packets, this allows
8 | // us to have more buffers in total
9 | #define MAX_ETHERNET_PACKET_SIZE (1514)
10 |
11 | #define NUM_MII_RX_BUF 6
12 | #define NUM_MII_TX_BUF 4
13 |
14 | #define MAX_ETHERNET_CLIENTS (1)
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/tests/test_regression/src/xtcp_client_conf.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2011, XMOS Ltd, All rights reserved
2 | // This software is freely distributable under a derivative of the
3 | // University of Illinois/NCSA Open Source License posted in
4 | // LICENSE.txt and at
5 |
6 |
7 | #define XTCP_CLIENT_BUF_SIZE (1500)
8 |
9 | #define XTCP_VERBOSE_DEBUG (1)
10 |
11 |
--------------------------------------------------------------------------------
/tests/test_regression/test.sh:
--------------------------------------------------------------------------------
1 | # TCP/IP component test script
2 |
3 | BINARY=$1
4 | FAILED=false
5 | DIR=`pwd`
6 |
7 | if [ "$BINARY" = "" ]; then
8 | echo "Usage: $0 [test binary]"
9 | exit
10 | fi
11 |
12 | # Start device
13 | exe=$BINARY libpath=$LD_LIBRARY_PATH xterm -hold -ls -e 'export LD_LIBRARY_PATH=$libpath; xrun --io $exe 2>&1 | tee xrun.out' &
14 |
15 | # Run host 2 test
16 | xterm -hold -e "ssh colin 'cd $DIR; ./tcpip_test.py 2'" &
17 |
18 | # Run host 1 test
19 | sleep 10; ./tcpip_test.py 2>&1 | tee host.out
20 |
21 | while lsof xrun.out; do
22 | echo waiting
23 | sleep 1
24 | done
25 |
26 | FAILURES=`grep -n -B 5 FAILED host.out xrun.out`
27 | if [ "$FAILURES" != "" ]; then
28 | FAILED=true
29 | echo output: $FAILURES
30 | fi
31 |
32 | PASSES=`grep -ch PASSED xrun.out`
33 | if [ "$PASSES" != "8" ]; then
34 | FAILED=true
35 | echo $PASSES tests passed.
36 | fi
37 |
38 | if $FAILED; then
39 | echo FAILED
40 | else
41 | echo PASSED
42 | fi
43 |
44 |
45 | echo $FAILURES
46 |
--------------------------------------------------------------------------------
/tests/test_tx_performance/.project:
--------------------------------------------------------------------------------
1 | test_2_thread_tx_perf com.xmos.cdt.core.ModulePathBuilder org.eclipse.cdt.managedbuilder.core.genmakebuilder clean,full,incremental, ?children? ?name?=outputEntries\|?children?=?name?=entry\\\\|\\|\|| ?name? org.eclipse.cdt.make.core.append_environment true org.eclipse.cdt.make.core.buildArguments CONFIG=Debug org.eclipse.cdt.make.core.buildCommand xmake org.eclipse.cdt.make.core.cleanBuildTarget clean org.eclipse.cdt.make.core.contents org.eclipse.cdt.make.core.activeConfigSettings org.eclipse.cdt.make.core.enableAutoBuild false org.eclipse.cdt.make.core.enableCleanBuild true org.eclipse.cdt.make.core.enableFullBuild true org.eclipse.cdt.make.core.stopOnError true org.eclipse.cdt.make.core.useDefaultBuildCmd false org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder full,incremental, org.eclipse.cdt.core.cnature org.eclipse.cdt.managedbuilder.core.managedBuildNature org.eclipse.cdt.managedbuilder.core.ScannerConfigNature com.xmos.cdt.core.XdeProjectNature
--------------------------------------------------------------------------------
/tests/test_tx_performance/.xproject:
--------------------------------------------------------------------------------
1 | sc_xtcpXM-000074-SW3.0.0rc1
--------------------------------------------------------------------------------
/tests/test_tx_performance/Makefile:
--------------------------------------------------------------------------------
1 | TARGET ?= SLICEKIT-L2
2 | APP_NAME =
3 | XCC_FLAGS = -g -O3 -lxscope
4 | USED_MODULES = module_xtcp module_ethernet_board_support
5 |
6 | ifeq ($(notdir $(abspath ..)),tests)
7 | PATHSEP = $(if $(findstring Windows, $(OS))$(findstring WINDOWS,$(OS)),;,:)
8 | XMOS_MODULE_PATH := $(XMOS_MODULE_PATH)$(PATHSEP)../../..
9 | endif
10 |
11 |
12 |
13 | #=============================================================================
14 | # The following part of the Makefile includes the common build infrastructure
15 | # for compiling XMOS applications. You should not need to edit below here.
16 |
17 | XMOS_MAKE_PATH ?= ../..
18 | include $(XMOS_MAKE_PATH)/xcommon/module_xcommon/build/Makefile.common
19 |
--------------------------------------------------------------------------------
/tests/test_tx_performance/src/ethernet_conf.h:
--------------------------------------------------------------------------------
1 | #define MII_NO_RESET
2 |
--------------------------------------------------------------------------------
/tests/test_tx_performance/src/xtcp_client_conf.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2011, XMOS Ltd, All rights reserved
2 | // This software is freely distributable under a derivative of the
3 | // University of Illinois/NCSA Open Source License posted in
4 | // LICENSE.txt and at
5 |
6 | #define XTCP_BUFFERED_API 1
7 | #define UIP_USE_SINGLE_THREADED_ETHERNET
8 | #define XTCP_VERBOSE_DEBUG
9 |
10 | #define UIP_USE_AUTOIP 1
11 | #define UIP_USE_DHCP 0
12 |
13 | #define XTCP_EXCLUDE_UNLISTEN
14 | #define XTCP_EXCLUDE_CONNECT
15 | #define XTCP_EXCLUDE_BIND_REMOTE
16 | #define XTCP_EXCLUDE_BIND_LOCAL
17 | #define XTCP_EXCLUDE_SET_APPSTATE
18 | #define XTCP_EXCLUDE_ABORT
19 | #define XTCP_EXCLUDE_SET_POLL_INTERVAL
20 | #define XTCP_EXCLUDE_JOIN_GROUP
21 | #define XTCP_EXCLUDE_LEAVE_GROUP
22 | #define XTCP_EXCLUDE_GET_MAC_ADDRESS
23 | #define XTCP_EXCLUDE_GET_IPCONFIG
24 | #define XTCP_EXCLUDE_ACK_RECV
25 | #define XTCP_EXCLUDE_ACK_RECV_MODE
26 | #define XTCP_EXCLUDE_PAUSE
27 | #define XTCP_EXCLUDE_UNPAUSE
28 |
29 |
--------------------------------------------------------------------------------