galileo: Add Ethernet support

This patch adds support for Ethernet to the Intel Galileo port.  It
uses the Intel Quark X1000 Ethernet driver.  It initializes the first
Ethernet interface and starts some common network services.  By
default, it uses the following addresses:
 - Host: 192.0.2.2
 - Netmask: 255.255.255.0
 - Default gateway: 192.0.2.1
 - DNS server: (same as default gateway)
These settings can be changed by editing eth-conf.c.
This commit is contained in:
Michael LeMay 2015-07-07 16:40:21 -07:00 committed by Jesus Sanchez-Palencia
parent abeed93da5
commit 38206e3980
8 changed files with 292 additions and 3 deletions

View file

@ -3,9 +3,13 @@ LIBC_PATH=$(BSP_PATH)/libc
LIBC=$(LIBC_PATH)/i586-elf LIBC=$(LIBC_PATH)/i586-elf
LIBGCC_PATH = /usr/lib/gcc/$(shell gcc -dumpmachine)/$(shell gcc -dumpversion) LIBGCC_PATH = /usr/lib/gcc/$(shell gcc -dumpmachine)/$(shell gcc -dumpversion)
CONTIKI_TARGET_DIRS = . core/sys/ drivers/ CONTIKI_TARGET_DIRS = . core/sys/ drivers/ net/
CONTIKI_TARGET_MAIN = ${addprefix $(OBJECTDIR)/,contiki-main.o} CONTIKI_TARGET_MAIN = ${addprefix $(OBJECTDIR)/,contiki-main.o}
CONTIKI_SOURCEFILES += contiki-main.c clock.c rtimer-arch.c gpio-pcal9535a.c pwm-pca9685.c galileo-pinmux.c CONTIKI_SOURCEFILES += contiki-main.c clock.c rtimer-arch.c gpio-pcal9535a.c pwm-pca9685.c galileo-pinmux.c eth-proc.c eth-conf.c
ifeq ($(CONTIKI_WITH_IPV6),1)
CONTIKI_SOURCEFILES += nbr-table.c packetbuf.c linkaddr.c
endif
PROJECT_SOURCEFILES += newlib-syscalls.c PROJECT_SOURCEFILES += newlib-syscalls.c

View file

@ -29,6 +29,7 @@ Device drivers:
* Programmable Intergal Timer (PIT) * Programmable Intergal Timer (PIT)
* Real-Time Clock (RTC) * Real-Time Clock (RTC)
* UART * UART
* Ethernet
Contiki APIs: Contiki APIs:
* Clock module * Clock module

View file

@ -31,6 +31,14 @@
#ifndef CONTIKI_CONF_H #ifndef CONTIKI_CONF_H
#define CONTIKI_CONF_H #define CONTIKI_CONF_H
/* Include the default configuration file early here so that this file can
* unconfigure the IP buffer size. That will allow uipopt.h to define a
* default IP buffer size that is larger and more useful.
*/
#include "contiki-default-conf.h"
#undef UIP_CONF_BUFFER_SIZE
#include <inttypes.h> #include <inttypes.h>
#define CLOCK_CONF_SECOND 128 #define CLOCK_CONF_SECOND 128
@ -46,6 +54,10 @@ typedef uint64_t rtimer_clock_t;
#define CCIF #define CCIF
#define CLIF #define CLIF
#define UIP_CONF_LLH_LEN 14
#define LINKADDR_CONF_SIZE 6
typedef unsigned short uip_stats_t; typedef unsigned short uip_stats_t;
#endif /* CONTIKI_CONF_H */ #endif /* CONTIKI_CONF_H */

View file

@ -31,9 +31,18 @@
#include <stdio.h> #include <stdio.h>
#include "contiki.h" #include "contiki.h"
#include "contiki-net.h"
#include "cpu.h" #include "cpu.h"
#include "interrupt.h" #include "interrupt.h"
#include "uart.h" #include "uart.h"
#include "eth-conf.h"
PROCINIT( &etimer_process
, &tcpip_process
#if WITH_DNS
, &resolv_process
#endif
);
int int
main(void) main(void)
@ -49,10 +58,12 @@ main(void)
ENABLE_IRQ(); ENABLE_IRQ();
process_init(); process_init();
process_start(&etimer_process, NULL); procinit_init();
ctimer_init(); ctimer_init();
autostart_start(autostart_processes); autostart_start(autostart_processes);
eth_init();
while(1) { while(1) {
process_run(); process_run();
} }

View file

@ -0,0 +1,75 @@
/*
* Copyright (C) 2015, Intel Corporation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "eth-conf.h"
#include "eth.h"
#include "net/eth-proc.h"
#include "contiki-net.h"
#include "net/linkaddr.h"
#if NETSTACK_CONF_WITH_IPV6
const linkaddr_t linkaddr_null = { { 0, 0, 0, 0, 0, 0 } };
#else
/* 192.0.2.0/24 is a block reserved for documentation by RFC 5737. */
#define SUBNET_IP 192, 0, 2
#define NETMASK_IP 255, 255, 255, 0
#define HOST_IP SUBNET_IP, 2
#define GATEWAY_IP SUBNET_IP, 1
#define NAMESERVER_IP GATEWAY_IP
#endif
void
eth_init(void)
{
#if !NETSTACK_CONF_WITH_IPV6
uip_ipaddr_t ip_addr;
#define SET_IP_ADDR(x) \
uip_ipaddr(&ip_addr, x)
SET_IP_ADDR(HOST_IP);
uip_sethostaddr(&ip_addr);
SET_IP_ADDR(NETMASK_IP);
uip_setnetmask(&ip_addr);
SET_IP_ADDR(GATEWAY_IP);
uip_setdraddr(&ip_addr);
#if WITH_DNS
SET_IP_ADDR(NAMESERVER_IP);
uip_nameserver_update(&ip_addr, UIP_NAMESERVER_INFINITE_LIFETIME);
#endif
#endif
quarkX1000_eth_init();
process_start(&eth_process, NULL);
}

View file

@ -0,0 +1,36 @@
/*
* Copyright (C) 2015, Intel Corporation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef PLATFORM_GALILEO_ETH_CONF_H_
#define PLATFORM_GALILEO_ETH_CONF_H_
void eth_init(void);
#endif /* PLATFORM_GALILEO_ETH_CONF_H_ */

View file

@ -0,0 +1,112 @@
/*
* Copyright (C) 2015, Intel Corporation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdio.h>
#include "contiki-net.h"
#include "net/ipv4/uip-neighbor.h"
#include "net/eth-proc.h"
#include "eth.h"
#define BUF ((struct uip_eth_hdr *)&uip_buf[0])
#define IPBUF ((struct uip_ip_hdr *)&uip_buf[UIP_LLH_LEN])
PROCESS(eth_process, "Ethernet");
/*---------------------------------------------------------------------------*/
#if NETSTACK_CONF_WITH_IPV6
static uint8_t
output(const uip_lladdr_t *dest_mac)
{
if (dest_mac == NULL) {
/* broadcast packet */
memset(&BUF->dest, 0xFF, UIP_LLH_LEN);
} else {
memcpy(&BUF->dest, dest_mac, UIP_LLH_LEN);
}
memcpy(&BUF->src, uip_lladdr.addr, UIP_LLH_LEN);
quarkX1000_eth_send();
return 0;
}
#else
static uint8_t
output(void)
{
uip_arp_out();
quarkX1000_eth_send();
return 0;
}
#endif /* NETSTACK_CONF_WITH_IPV6 */
/*---------------------------------------------------------------------------*/
static void
pollhandler(void)
{
process_poll(&eth_process);
quarkX1000_eth_poll(&uip_len);
if(uip_len > 0) {
#if NETSTACK_CONF_WITH_IPV6
if(BUF->type == uip_htons(UIP_ETHTYPE_IPV6)) {
tcpip_input();
}
#else
if(BUF->type == uip_htons(UIP_ETHTYPE_IP)) {
uip_len -= sizeof(struct uip_eth_hdr);
tcpip_input();
} else if(BUF->type == uip_htons(UIP_ETHTYPE_ARP)) {
uip_arp_arpin();
/* If the above function invocation resulted in data that
should be sent out on the network, the global variable
uip_len is set to a value > 0. */
if(uip_len > 0) {
quarkX1000_eth_send();
}
}
#endif /* NETSTACK_CONF_WITH_IPV6 */
}
}
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(eth_process, ev, data)
{
PROCESS_POLLHANDLER(pollhandler());
PROCESS_BEGIN();
tcpip_set_outputfunc(output);
process_poll(&eth_process);
PROCESS_WAIT_UNTIL(ev == PROCESS_EVENT_EXIT);
PROCESS_END();
}
/*---------------------------------------------------------------------------*/

View file

@ -0,0 +1,38 @@
/*
* Copyright (C) 2015, Intel Corporation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef PLATFORM_GALILEO_NET_ETH_PROC_H_
#define PLATFORM_GALILEO_NET_ETH_PROC_H_
#include "contiki.h"
PROCESS_NAME(eth_process);
#endif /* PLATFORM_GALILEO_NET_ETH_PROC_H_ */