Commit de2aacb1 authored by Lucas Russo's avatar Lucas Russo

Merge branch 'lwip-port' into ebone-hw-support

parents 120334e2 79766d58
......@@ -3,3 +3,4 @@
*.ram
*.elf
*.bin
*.d
# choose your board here.
# Autodependencies generatation by Scott McPeak, November 2001,
# from article "Autodependencies with GNU make"
# Choose your board here.
BOARD = ml605
# some configurations
# Some configurations
CONFIG_PPRINTF =? 1
#ifeq ($(CONFIG_PPRINTF),1)
......@@ -12,7 +15,7 @@ CONFIG_ETHERBONE =? 1
CONFIG_FMC150 ?= 0
CONFIG_FMC516 ?= 0
# and don't touch the rest unless you know what you're doing.
# Don't touch the rest unless you know what you're doing.
CROSS_COMPILE ?= lm32-elf-
CC = $(CROSS_COMPILE)gcc
......@@ -20,19 +23,19 @@ LD = $(CROSS_COMPILE)ld
OBJDUMP = $(CROSS_COMPILE)objdump
OBJCOPY = $(CROSS_COMPILE)objcopy
SIZE = $(CROSS_COMPILE)size
AR = $(CROSS_COMPILE)ar
-include $(CURDIR)/.config
OBJS_DBE = dbe_main.o
TOPDIR=.
OBJS_DBE = dbe_lwip.o
#OBJS_DBE = dbe_main.o
#OBJS_DBE = dbe_main_test.o
INCLUDE_DIRS = -Iinclude \
-Iinclude/memmgr \
-Iinclude/fmc/fmc150 \
-Iinclude/fmc/fmc516 \
-I$(CURDIR)/pp_printf \
-I$(CURDIR)/lib \
-I$(CURDIR)/lib/ethmac
-Ipp_printf \
-Ilib
CFLAGS = -Wall
#-include $(CURDIR)/include/generated/autoconf.h
......@@ -41,12 +44,18 @@ CFLAGS_MEMMGR = -DDEBUG_MEMMGR_FATAL=1 \
-DDEBUG_MEMMGR_SUPPORT_STATS=1 \
-DPOOL_SIZE=2048
CFLAGS_DEBUG = -DDBE_DBG=1
CFLAGS_DEBUG = -DDBE_DBG=1 -DLWIP_DEBUG=1
CFLAGS_PLATFORM = -mmultiply-enabled -mbarrel-shift-enabled
#LDFLAGS_PLATFORM = -mmultiply-enabled -mbarrel-shift-enabled \
# -nostdlib -T arch/lm32/ram.ld
LDFLAGS_PLATFORM = -mmultiply-enabled -mbarrel-shift-enabled \
-nostdlib -T arch/lm32/ram.ld
#LIBS = -llwip4
#LIB_DIRS = lib/lwip
#LFLAGS = $(addprefix -L,$(LIB_DIRS))
OBJS_PLATFORM = arch/lm32/crt0.o arch/lm32/irq.o arch/lm32/debug.o
include lib/lib.mk
......@@ -56,8 +65,8 @@ include boards/boards.mk
include fmc/fmc.mk
CFLAGS += $(CFLAGS_PLATFORM) $(CFLAGS_EB) $(INCLUDE_DIRS) \
$(CFLAGS_MEMMGR) $(CFLAGS_DEBUG) -ffunction-sections -fdata-sections \
-Os
$(CFLAGS_MEMMGR) $(CFLAGS_DEBUG) $(CFLAGS_LWIP) -ffunction-sections \
-fdata-sections -Os
LDFLAGS = $(LDFLAGS_PLATFORM) \
-ffunction-sections -fdata-sections -Wl,--gc-sections -Os -Iinclude
......@@ -66,7 +75,8 @@ OBJS = $(OBJS_PLATFORM) $(OBJS_DBE) \
$(OBJS_SHELL) $(OBJS_TESTS) $(OBJS_LIB) \
$(OBJS_DEV) $(OBJS_BOARD) $(OBJS_FMC)
OUTPUT = dbe
OUTPUT = dbe_lwip
#OUTPUT = dbe
#OUTPUT = dbe_test
REVISION=$(shell git describe --dirty --always)
......@@ -76,9 +86,10 @@ all: tools $(OUTPUT).ram $(OUTPUT).vhd
.PHONY: all tools clean
$(OUTPUT).elf: $(OBJS)
#$(MAKE) -C $(LIB_DIRS) all
$(CC) $(CFLAGS) -DGIT_REVISION=\"$(REVISION)\" -c revision.c
$(SIZE) -t $(OBJS)
${CC} -o $@ revision.o $(OBJS) $(LDFLAGS)
${CC} $(LFLAGS) -o $@ revision.o $(OBJS) $(LDFLAGS) $(LIBS)
${OBJDUMP} -d $(OUTPUT).elf > $(OUTPUT)_disasm.S
$(SIZE) $@
......@@ -98,10 +109,37 @@ include/board.h:
clean:
rm -f $(OBJS) $(OUTPUT).elf $(OUTPUT).bin $(OUTPUT).ram $(OUTPUT)_disasm.S $(OUTPUT).vhd include/board.h
# Bad...
find . -iname "*.d" -exec rm '{}' \;
make clean -C tools
# Pull in dependency info for *existing* .o files and don't complain if the
# corresponding .d file is not found
-include $(OBJS:.o=.d)
# Compile and generate dependency info;
%.o: %.c
${CC} $(CFLAGS) $(INCLUDE_DIRS) $(LIB_DIR) -c $*.c -o $@
# create the dependency files "target: pre-requisites"
${CC} -MM $(CFLAGS) $*.c > $*.d
# Workaround to make objects in different folders have
# the correct target path. e.g., "dir/bar.o: dir/bar.c dir/foo.h"
# instead of "bar.o: dir/bar.c dir/foo.h"
@mv -f $*.d $*.d.tmp
@sed -e 's|.*:|$*.o:|' < $*.d.tmp > $*.d
# All prereqs listed will also become command-less,
# prereq-less targets. In this way, the prereq file will be
# treated as changed and the target will be rebuilt
# sed: strip the target (everything before colon)
# sed: remove any continuation backslashes
# fmt -1: list words one per line
# sed: strip leading spaces
# sed: add trailing colons
@sed -e 's/.*://' -e 's/\\$$//' < $*.d.tmp | fmt -1 | \
sed -e 's/^ *//' -e 's/$$/:/' >> $*.d
@rm -f $*.d.tmp
tools:
$(MAKE) -C tools
This diff is collapsed.
#include "gpio.h" // GPIO device funtions
#include "i2c.h" // I2V device functions
#include "onewire.h" // Onewire device functions
#include "dma.h" // DMA device functions
#include "uart.h" // UART device functions
#include "timer.h" // timer device functions
#include "memmgr.h" // memory pool functions
#include "board.h" // board definitions
#include "int.h" // LM32 interruption definitions
#include "pp-printf.h" // printf-like function
#include "ethmac.h" // ethmac headers
#include "eth-phy-mii.h"
#include "ethmac_adapt.h"
//#include "icmp.h"
//#include "ipv4.h"
//#include "arp.h"
#include "util.h" // util functions like memcmp and memcpy
#include "debug_print.h"
#include "debug_subsys.h"
/* lwIP includes */
#include "ethernet_config.h" /* Application Ethernet Configuration File */
#include "lwip/memp.h"
#include "netif/etharp.h"
#include "lwip/ip.h"
#include "lwip/netif.h"
#include "lwip/sys.h"
#include "netif/ethernetif.h"
/* Each loop iteration takes 4 cycles.
* It runs at 100MHz.
* Sleep 0.2 second.
*/
#define LED_DELAY (100000000/4/5)
// 1s delay
#define FMC150_DELAY (100000000/4)
#define NUM_LEDS 8
#define NUM_LED_ITER 4
//#define NUM_FMC150_TRIES 5
#define NUM_BUTTONS 8
#define TEST_BUTTONS_MASK 0x00000003
#define TEST_BUTTONS_TRIES 10
#define TEST_BUTTONS_ITER 2
#define TEST_BUTTONS_DELAY (100000000/4/5)
/* Placeholder for IRQ vector */
//void _irq_entry(void){}
static void button(void* arg)
{
pp_printf("> button pushed!\n");
}
int dbe_init(void)
{
// Initialize memory pool
memmgr_init();
// Fill SDB device structures
sdb_find_devices();
// Initialize specific components
if(uart_init() == -1){
return -1;
}
/* Output memory layout */
sdb_print_devices();
if(dma_init() == -1){
pp_printf("> error initializing DMA! Exiting...\n");
return -1;
}
if(gpio_init() == -1){
pp_printf("> error initializing GPIO! Exiting...\n");
return -1;
}
if(timer_init() == -1){
pp_printf("> error initializing TIMER! Exiting...\n");
return -1;
}
/* Initialized within lwIP functions */
// Ethernet MAC Initialization
//if(ethmac_init() == -1){
// pp_printf("> error initializing Ethernet MAC! Exiting...\n");
// return -1;
//}
// Ethernet adapter initilization
if(ethmac_adapt_init() == -1){
pp_printf("> error initializing Ethernet MAC adapter! Exiting...\n");
return -1;
}
// Initialize LM32 Interrupts
if(int_init() == -1){
pp_printf("> error initializing Interrupts! Exiting...\n");
return -1;
}
return 0;
}
int dbe_exit()
{
gpio_exit();
uart_exit();
timer_exit();
ethmac_exit();
//always succeeds
return 0;
}
void print_header(void)
{
pp_printf("-------------------------------------------\n");
pp_printf("| DBE EXAMPLE APPLICATION |\n");
pp_printf("| |\n");
pp_printf("| This application aims to demostrate |\n");
pp_printf("| the capabilities of the DBE project |\n");
pp_printf("-------------------------------------------\n\n");
}
void print_end_header(void)
{
pp_printf("-------------------------------------------\n");
pp_printf("| END OF TEST APPLICATION |\n");
pp_printf("-------------------------------------------\n\n");
}
void memmgr_test(void)
{
/* Simple Memory Pool Test */
char *p = (char *)memmgr_alloc(100*sizeof(char));
pp_printf("-------------------------------------------\n");
pp_printf("| Memory pool test |\n");
pp_printf("-------------------------------------------\n\n");
pp_printf("memmgr_test:\n");
if(p){
strcpy(p, "> dynamic allocated string with memory pool\n\n");
pp_printf(p);
pp_printf("> test passed!\n");
}
else
pp_printf("> test failed. Could not allocate memory!\n");
memmgr_print_stats();
memmgr_free(p);
}
void leds_test(void)
{
/* Simple LEDs test */
int i, j;
pp_printf("-------------------------------------------\n");
pp_printf("| Leds test |\n");
pp_printf("-------------------------------------------\n\n");
pp_printf("leds_test:\n");
pp_printf("> blinking leds\n");
/* Rotate the LEDs */
for ( j = 0; j < NUM_LED_ITER; ++j)
for (i = 0; i < NUM_LEDS; ++i){
// Set led at position i
gpio_out(0, i, 1);
/* Each loop iteration takes 4 cycles.
* It runs at 100MHz.
* Sleep 0.2 second.
*/
delay(LED_DELAY);
// Clear led at position i
gpio_out(0, i, 0);
}
// End test with 4 leds set
gpio_out(0, 0, 1);
gpio_out(0, 2, 1);
gpio_out(0, 4, 1);
gpio_out(0, 6, 1);
pp_printf("> test passed!\n");
}
void button_test()
{
int i, j;
unsigned int button_pressed = 0;
pp_printf("-------------------------------------------\n");
pp_printf("| Button test |\n");
pp_printf("-------------------------------------------\n\n");
pp_printf("buttons_test:\n");
pp_printf("> press (switch) buttons ");
for (i = 0; i < TEST_BUTTONS_ITER-1; ++i)
pp_printf("%d, ", i);
pp_printf("%d\n", TEST_BUTTONS_ITER);
for (i = 0; i < TEST_BUTTONS_TRIES; ++i) {
for (j = 0; j < TEST_BUTTONS_ITER; ++j) {
if ((!(button_pressed & (0x1 << j))) & gpio_in(1, j)) {
button_pressed |= 1 << j;
pp_printf("button%d pressed!\n", j);
}
}
if (button_pressed == TEST_BUTTONS_MASK) {
pp_printf("> test passed!\n");
return;
}
pp_printf("> remaining time to press buttons: %ds\n", (TEST_BUTTONS_TRIES-i));
delay(TEST_BUTTONS_DELAY);
}
pp_printf("> test failed!\n");
}
struct netif netif;
static int init_netifs(void)
{
struct ip_addr ipaddr, netmask, gw;
#if PPP_SUPPORT
pppInit();
#if PPP_PTY_TEST
ppp_sio = sio_open(2);
#else
ppp_sio = sio_open(0);
#endif
if(!ppp_sio)
{
perror("Error opening device: ");
exit(1);
}
#ifdef LWIP_PPP_CHAP_TEST
pppSetAuth(PPPAUTHTYPE_CHAP, "lwip", "mysecret");
#endif
pppOpen(ppp_sio, pppLinkStatusCallback, NULL);
#endif /* PPP_SUPPORT */
DBE_DEBUG(DBG_GENERIC | DBE_DBG_TRACE, "> initializing lwip netifs...\n");
#if LWIP_DHCP
DBE_DEBUG(DBG_GENERIC | DBE_DBG_TRACE, "> using dynamic (DHCP) ip address\n");
IP4_ADDR(&gw, 0,0,0,0);
IP4_ADDR(&ipaddr, 0,0,0,0);
IP4_ADDR(&netmask, 0,0,0,0);
netif_add(&netif, &ipaddr, &netmask, &gw, NULL, tapif_init,
tcpip_input);
netif_set_default(&netif);
dhcp_start(&netif);
#else
DBE_DEBUG(DBG_GENERIC | DBE_DBG_TRACE, "> using static ip address\n");
/* Not using DHCP, so fix IP addresses */
/* host */
IP4_ADDR( &ipaddr,
HST_IP_ADDR_0,
HST_IP_ADDR_1,
HST_IP_ADDR_2,
HST_IP_ADDR_3 );
/* gateway */
IP4_ADDR( &gw,
GW_IP_ADDR_0,
GW_IP_ADDR_1,
GW_IP_ADDR_2,
GW_IP_ADDR_3 );
/* subnet mask */
IP4_ADDR( &netmask,
SUBNET_MASK_0,
SUBNET_MASK_1,
SUBNET_MASK_2,
SUBNET_MASK_3 );
netif_add(&netif, &ipaddr, &netmask, &gw, 0, ethernetif_init, ethernet_input);
/* declare this netif as the default interface */
netif_set_default(&netif);
/* ask lwIP to setup the network interface */
netif_set_up(&netif);
#endif
#if LWIP_TCP
/*tcpecho_init();
shell_init();
httpd_init();*/
#endif
#if LWIP_UDP
/*udpecho_init();*/
#endif
/* sys_timeout(5000, tcp_debug_timeout, NULL);*/
return 0;
}
int main(void)
{
// Board initialization
if(board_init() == -1)
return -1;
// General initialization
if(dbe_init() == -1){
pp_printf("> error initializing DBE Board! Exiting...\n");
return -1;
}
// lwIP initilization
lwip_init();
/* lwIP netif initilization */
if(init_netifs() == -1){
pp_printf("> error initializing lwIP netif! Exiting...\n");
return -1;
}
/* Testing functions */
print_header();
/* Test memory pool */
memmgr_test();
/* Test leds */
leds_test();
/* Test button */
button_test();
print_end_header();
/* Install ethernet interrupt handler, it is enabled here too */
int_add(ETH0_IRQ, oeth_interrupt, &netif);
int_add(2, &button, 0);
//ethmac_setup(ETH0_PHY, ETH0_BUF); /* Configure MAC, TX/RX BDs and enable RX and TX in MODER */
//ethmac_setup(ETH0_PHY); /* Configure MAC, TX/RX BDs and enable RX and TX in MODER */
/* clear tx_done, the tx interrupt handler will set it when it's been transmitted */
/* Configure EB DMA */
//ethmac_adapt_set_base(0, (unsigned int)hisBody, (unsigned int)hisBody);
//int_add(4, &set_eb_done, 0);
/* Enable interrupts */
//enable_irq();
DBE_DEBUG(DBG_GENERIC | DBE_DBG_TRACE, "> begin main lwip loop\n");
// Main loop
while (1) {
/* lwIP checkfor timeouts */
sys_check_timeouts();
}
dbe_exit();
return 0;
}
......@@ -5,5 +5,6 @@ OBJS_DEV = dev/dma.o \
dev/ethmac_adapt.o \
dev/spi.o \
dev/i2c.o \
dev/onewire.o
dev/onewire.o \
dev/timer.o \
/*
* This work is part of the White Rabbit project
*
* Copyright (C) 2011 CERN (www.cern.ch)
* Author: Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
* Author: Lucas Russo <lucas.russo@lnls.br>
*
* Released according to the GNU GPL, version 2 or any later version.
*/
#include "board.h"
#include "timer.h"
#include "memmgr.h"
#include "debug_print.h"
// Global TICS handler.
tics_t **tics;
int timer_init()
{
int i;
struct dev_node *dev_p = 0;
if (!tics_devl->devices)
return -1;
// get all base addresses
tics = (tics_t **) memmgr_alloc(sizeof(tics_t *)*tics_devl->size);
for (i = 0, dev_p = tics_devl->devices; i < tics_devl->size;
++i, dev_p = dev_p->next) {
tics[i] = (tics_t *) dev_p->base;
DBE_DEBUG(DBG_GENERIC | DBE_DBG_INFO,"> timer addr[%d]: %08X\n", i, dev_p->base);
}
DBE_DEBUG(DBG_GENERIC | DBE_DBG_INFO, "> timer size: %d\n", tics_devl->size);
return 0;
}
int timer_exit(void)
{
memmgr_free(tics);
return 0;
}
uint32_t timer_get_tics(void)
{
return tics[TICS_ID]->TICS_REG;
}
/* Alias for lwIP timers */
uint32_t sys_now(void) __attribute__((alias("timer_get_tics")));
void timer_delay(uint32_t how_long)
{
uint32_t t_start;
t_start = timer_get_tics();
while (t_start + how_long > timer_get_tics()) ;
}
......@@ -57,8 +57,16 @@ void uart_write_string(unsigned int id, char *s)
uart_write_byte(id, *(s++));
}
void uart_write(unsigned int id, const char *s, int nbytes)
{
int i;
for(i = 0; i < nbytes; ++i)
uart_write_byte(DEFAULT_UART, *(s++));
}
// Only for use with puts
void uart_default_write_string(char *s)
static void uart_default_write_string(char *s)
{
while (*s)
uart_write_byte(DEFAULT_UART, *(s++));
......
ifeq ($(CONFIG_FMC150),1)
OBJS_FMC150 += fmc/fmc150/fmc150.o
INCLUDE_DIRS += -I$(TOPDIR)/include/fmc/fmc150
endif
ifeq ($(CONFIG_FMC516),1)
OBJS_FMC516 += fmc/fmc516/lmk02000.o fmc/fmc516/isla216p25.o fmc/fmc516/fmc516.o
INCLUDE_DIRS += -I$(TOPDIR)/include/fmc/fmc516
endif
OBJS_FMC += $(OBJS_FMC150) $(OBJS_FMC516)
......
../boards/ml605/board.h
\ No newline at end of file
/*
* This file defines constants that control
* application-configuration
*/
#ifndef _ETHERNET_CONFIG_H_
#define _ETHERNET_CONFIG_H_
#include "lwip/opt.h"
/* PHY Number */
#define PHY_NUM 7
/*
* MAC Address (Software configured)
* (e.g. 00-01-02-03-04-05)
*/
#define MAC_CFG_MAC_ADDR_UPPER_16 (0x000A)
#define MAC_CFG_MAC_ADDR_LOWER_32 (0x3502532D)
/*
* IP Addresses when not using DHCP
*/
#if !LWIP_DHCP
/* Host ip-address: 10.0.18.148 */
#define HST_IP_ADDR_0 (10)
#define HST_IP_ADDR_1 (0)
#define HST_IP_ADDR_2 (18)
#define HST_IP_ADDR_3 (148)
/* Gateway IP Address: 10.0.18.1 */
#define GW_IP_ADDR_0 (10)
#define GW_IP_ADDR_1 (0)
#define GW_IP_ADDR_2 (18)
#define GW_IP_ADDR_3 (1)
/* Subnet: 255.255.255.0 */
#define SUBNET_MASK_0 (255)
#define SUBNET_MASK_1 (255)
#define SUBNET_MASK_2 (255)
#define SUBNET_MASK_3 (0)
#endif
#endif /*ETHERNET_CONFIG_H_*/
This diff is collapsed.
......@@ -2,7 +2,7 @@
// Statically-allocated memory manager
//
// by Eli Bendersky (eliben@gmail.com)
//
//
// This code is in the public domain.
//----------------------------------------------------------------
// Modified by Lucas Russo <lucas.russo@lnls.br>
......@@ -13,66 +13,66 @@
#include "inttypes.h"
//
// Memory manager: dynamically allocates memory from
// Memory manager: dynamically allocates memory from
// a fixed pool that is allocated statically at link-time.
//
// Usage: after calling memmgr_init() in your
//
// Usage: after calling memmgr_init() in your
// initialization routine, just use memmgr_alloc() instead
// of malloc() and memmgr_free() instead of free().
// Naturally, you can use the preprocessor to define
// malloc() and free() as aliases to memmgr_alloc() and
// memmgr_free(). This way the manager will be a drop-in
// Naturally, you can use the preprocessor to define
// malloc() and free() as aliases to memmgr_alloc() and
// memmgr_free(). This way the manager will be a drop-in
// replacement for the standard C library allocators, and can
// be useful for debugging memory allocation problems and
// be useful for debugging memory allocation problems and
// leaks.
//
// Preprocessor flags you can define to customize the
// Preprocessor flags you can define to customize the
// memory manager:
//
// DEBUG_MEMMGR_FATAL
// Allow printing out a message when allocations fail
// Allow printing out a message when allocations fail
//
// DEBUG_MEMMGR_SUPPORT_STATS
// Allow printing out of stats in function
// memmgr_print_stats When this is disabled,
// memmgr_print_stats does nothing.
// Allow printing out of stats in function
// memmgr_print_stats When this is disabled,
// memmgr_print_stats does nothing.
//
// Note that in production code on an embedded system
// Note that in production code on an embedded system
// you'll probably want to keep those undefined, because
// they cause printf to be called.
//
// POOL_SIZE
// Size of the pool for new allocations. This is
// effectively the heap size of the application, and can
// be changed in accordance with the available memory
// resources.
// Size of the pool for new allocations. This is
// effectively the heap size of the application, and can
// be changed in accordance with the available memory
// resources.
//
// MIN_POOL_ALLOC_QUANTAS
// Internally, the memory manager allocates memory in
// quantas roughly the size of two ulong objects. To
// minimize pool fragmentation in case of multiple allocations
// and deallocations, it is advisable to not allocate
// blocks that are too small.
// This flag sets the minimal ammount of quantas for
// an allocation. If the size of a ulong is 4 and you
// set this flag to 16, the minimal size of an allocation
// will be 4 * 2 * 16 = 128 bytes
// If you have a lot of small allocations, keep this value
// low to conserve memory. If you have mostly large
// allocations, it is best to make it higher, to avoid
// fragmentation.
// Internally, the memory manager allocates memory in
// quantas roughly the size of two ulong objects. To
// minimize pool fragmentation in case of multiple allocations
// and deallocations, it is advisable to not allocate
// blocks that are too small.
// This flag sets the minimal ammount of quantas for
// an allocation. If the size of a ulong is 4 and you
// set this flag to 16, the minimal size of an allocation
// will be 4 * 2 * 16 = 128 bytes
// If you have a lot of small allocations, keep this value
// low to conserve memory. If you have mostly large
// allocations, it is best to make it higher, to avoid
// fragmentation.
//
// Notes:
// 1. This memory manager is *not thread safe*. Use it only
// for single thread/task applications.
//
// for single thread/task applications.
//
//#ifndef DEBUG_MEMMGR_FATAL
// #define DEBUG_MEMMGR_FATAL 1
// #define DEBUG_MEMMGR_FATAL 1
//#endif
//#ifndef DEBUG_MEMMGR_SUPPORT_STATS
// #define DEBUG_MEMMGR_SUPPORT_STATS 1
// #define DEBUG_MEMMGR_SUPPORT_STATS 1
//#endif
#ifndef POOL_SIZE
......
#ifndef _TIMER_H_
#define _TIMER_H_
#include "inttypes.h"
#define TICS_PER_SECOND 1000
struct TICS_WB
{
uint32_t TICS_REG;
};
typedef volatile struct TICS_WB tics_t;
int timer_init();
int timer_exit();
uint32_t timer_get_tics();
void timer_delay(uint32_t how_long);
#endif
......@@ -17,6 +17,7 @@ int uart_init(void);
int uart_exit(void);
void uart_write_byte(unsigned int id, int b);
void uart_write_string(unsigned int id, char *s);
void uart_write(unsigned int id, const char *s, int nbytes);
int puts(const char *s);
int uart_poll(unsigned int id);
int uart_read_byte(unsigned int id);
......
/*
* Copyright (C) 2012 LNLS (www.lnls.br)
* Author: Lucas Russo <lucas.russo@lnls.br>
* Parts taken from lwIP debug system
*
* Released according to the GNU GPL, version 2 or any later version.
*/
......
This diff is collapsed.
......@@ -179,6 +179,12 @@ typedef volatile unsigned long ethmac_buf_t;
#define OETH_CTRLMODER_RXFLOW 0x00000002 /* Receive Control Flow Enable */
#define OETH_CTRLMODER_TXFLOW 0x00000004 /* Transmit Control Flow Enable */
/* Packet Length Register */
#define OETH_PKTLEN_MINFL 0x00000040 /* Minimum frame length = 64B */
#define OETH_PKTLEN_DEFAULT_ETH 0x000005F0 /* Default maximum ethernet frame length = 1518B */
#define OETH_PKTLEN_EXTRA 0x00000010 /* Extra frame length space = 16B*/
#define OETH_PKTLEN_MAXFL (OETH_PKTLEN_DEFAULT_ETH+OETH_PKTLEN_EXTRA) /* Maximum frame length = 1536B */
/* MII Mode Register */
#define OETH_MIIMODER_CLKDIV 0x000000FF /* Clock Divider */
#define OETH_MIIMODER_NOPRE 0x00000100 /* No Preamble */
......@@ -198,17 +204,29 @@ typedef volatile unsigned long ethmac_buf_t;
#define OETH_MIISTATUS_BUSY 0x00000002 /* MII Busy */
#define OETH_MIISTATUS_NVALID 0x00000004 /* Data in MII Status Register is invalid */
/* ETHMAC init */
int ethmac_init(void);
void ethmac_exit(void);
void ethmac_setup(int phynum);
void eth_mii_write(char phynum, short regnum, short data);
short eth_mii_read(char phynum, short regnum);
//void ethmac_setup(int phynum, unsigned int buf);
void ethmac_setup(int phynum);
void ethphy_set_10mbit(int phynum);
void ethphy_set_100mbit(int phynum);
void oeth_disable_tx(void);
void oeth_disable_rx(void);
int num_tx_ready_bd(void);
int all_tx_bd_clear(void);
void wait_for_tx_bd_clear(int num_tx_clear);
void ethmac_halt(void);
void oeth_interrupt(void* arg);
void tx_packet(void* data, int length);
void rx_packet(void* data, int length);
void user_recv(unsigned char* data, int length);
/* ETHMAC init */
int ethmac_init(void);
int oeth_check_rx_bd();
void oeth_drop_rx_bd();
#endif
OBJS_LIB += lib/ethmac/ethmac.o
INCLUDE_DIRS += -I$(TOPDIR)/lib/ethmac
#lib/ethmac/ethmac-int.o
include lib/memmgr/memmgr.mk
include lib/ethmac/ethmac.mk
include lib/lwip/lwip.mk
ifeq ($(CONFIG_PPRINTF),0)
OBJS_LIB += lib/mprintf.o
endif
OBJS_LIB += lib/util.o lib/int.o lib/arp.o lib/icmp.o lib/ipv4.o lib/debug_print.o
#OBJS_LIB += lib/util.o lib/int.o lib/debug_print.o
OBJS_LIB += lib/util.o lib/int.o lib/debug_print.o
#OBJS_LIB += lib/util.o lib/int.o lib/arp.o lib/icmp.o lib/ipv4.o lib/debug_print.o
ifdef CONFIG_ETHERBONE
#OBJS_LIB += lib/bootp.o
endif
OBJS_LIB += lib/minimal_newlibc.o
This source diff could not be displayed because it is too large. You can view the blob instead.
/*
* Copyright (c) 2001, 2002 Swedish Institute of Computer Science.
* 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. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
*
* This file is part of the lwIP TCP/IP stack.
*
* Author: Adam Dunkels <adam@sics.se>
*
*/
src/ - The source code for the lwIP TCP/IP stack.
doc/ - The documentation for lwIP.
See also the FILES file in each subdirectory.
# Based on the reference lwIP makefile available at
# http://lwip.wikia.com/wiki/Porting_For_Bare_Metal
CROSS_COMPILE ?= lm32-elf-
CC = $(CROSS_COMPILE)gcc
LD = $(CROSS_COMPILE)ld
OBJDUMP = $(CROSS_COMPILE)objdump
OBJCOPY = $(CROSS_COMPILE)objcopy
SIZE = $(CROSS_COMPILE)size
AR = $(CROSS_COMPILE)ar
ARFLAGS=rs
TOPDIR=../..
TARGETDIR=$(TOPDIR)/lib
CONTRIBDIR=$(TOPDIR)/lib/lwip/contrib
CONFIGDIR=$(TOPDIR)/lib/lwip/config
LWIPDIR=$(TOPDIR)/lib/lwip/src
INCDIR=$(TOPDIR)/include
PP_PRINTFINCDIR=$(TOPDIR)/pp_printf
LWIPARCH=$(CONTRIBDIR)/ports/lm32
LWIPDRVDIR=$(CONTRIBDIR)/ports/ethmac10100-drv
CFLAGS_LWIP += $(CPPFLAGS) -I$(LWIPDIR)/include -I. \
-I$(LWIPARCH)/include -I$(LWIPARCH)/include/arch \
-I$(LWIPDIR)/include/ipv4 -I$(CONFIGDIR) \
-I$(LWIPDRVDIR) -I$(LWIPDRVDIR)/netif \
-I$(INCDIR) -I$(PP_PRINTFINCDIR)
# COREOBJS, CORE4OBJS: The minimum set of files needed for lwIP.
COREOBJS=$(LWIPDIR)/core/mem.o \
$(LWIPDIR)/core/memp.o \
$(LWIPDIR)/core/netif.o \
$(LWIPDIR)/core/pbuf.o \
$(LWIPDIR)/core/raw.o \
$(LWIPDIR)/core/stats.o \
$(LWIPDIR)/core/sys.o \
$(LWIPDIR)/core/tcp.o \
$(LWIPDIR)/core/tcp_in.o \
$(LWIPDIR)/core/tcp_out.o \
$(LWIPDIR)/core/udp.o \
$(LWIPDIR)/core/dhcp.o \
$(LWIPDIR)/core/init.o
CORE4OBJS=$(LWIPDIR)/core/ipv4/icmp.o \
$(LWIPDIR)/core/ipv4/ip.o \
$(LWIPDIR)/core/ipv4/inet.o \
$(LWIPDIR)/core/ipv4/ip_addr.o \
$(LWIPDIR)/core/ipv4/ip_frag.o \
$(LWIPDIR)/core/ipv4/inet_chksum.o
# NETIFOBJS: Files implementing various generic network interface functions.'
NETIFOBJS=$(LWIPDIR)/netif/etharp.o \
$(LWIPDRVDIR)/netif/ethernetif.o
# LWIPOBJS: All the above.
LWIPOBJS=$(COREOBJS) $(CORE4OBJS) $(NETIFOBJS)
LWIPLIB=liblwip4.a
all compile: $(LWIPLIB)
mkdir -p $(TARGETDIR)
install $(LWIPLIB) $(TARGETDIR)
.PHONY: all depend compile clean
# Pull in dependency info for *existing* .o files and don't complain if the
# corresponding .d file is not found
-include $(LWIPOBJS:.o=.d)
# Compile and generate dependency info;
%.o: %.c
${CC} $(CFLAGS_LWIP) -c $*.c -o $@
# create the dependency files "target: pre-requisites"
${CC} -MM $(CFLAGS_LWIP) $*.c > $*.d
# Workaround to make objects in different folders have
# the correct target path. e.g., "dir/bar.o: dir/bar.c dir/foo.h"
# instead of "bar.o: dir/bar.c dir/foo.h"
@mv -f $*.d $*.d.tmp
@sed -e 's|.*:|$*.o:|' < $*.d.tmp > $*.d
# All prereqs listed will also become command-less,
# prereq-less targets. In this way, the prereq file will be
# treated as changed and the target will be rebuilt
# sed: strip the target (everything before colon)
# sed: remove any continuation backslashes
# fmt -1: list words one per line
# sed: strip leading spaces
# sed: add trailing colons
@sed -e 's/.*://' -e 's/\\$$//' < $*.d.tmp | fmt -1 | \
sed -e 's/^ *//' -e 's/$$/:/' >> $*.d
@rm -f $*.d.tmp
clean:
rm -f *.o $(LWIPLIB)
$(LWIPLIB): $(LWIPOBJS)
$(AR) $(ARFLAGS) $(LWIPLIB) $?
INTRODUCTION
lwIP is a small independent implementation of the TCP/IP protocol
suite that has been developed by Adam Dunkels at the Computer and
Networks Architectures (CNA) lab at the Swedish Institute of Computer
Science (SICS).
The focus of the lwIP TCP/IP implementation is to reduce the RAM usage
while still having a full scale TCP. This making lwIP suitable for use
in embedded systems with tens of kilobytes of free RAM and room for
around 40 kilobytes of code ROM.
FEATURES
* IP (Internet Protocol) including packet forwarding over multiple network
interfaces
* ICMP (Internet Control Message Protocol) for network maintenance and debugging
* IGMP (Internet Group Management Protocol) for multicast traffic management
* UDP (User Datagram Protocol) including experimental UDP-lite extensions
* TCP (Transmission Control Protocol) with congestion control, RTT estimation
and fast recovery/fast retransmit
* Specialized raw/native API for enhanced performance
* Optional Berkeley-like socket API
* DNS (Domain names resolver)
* SNMP (Simple Network Management Protocol)
* DHCP (Dynamic Host Configuration Protocol)
* AUTOIP (for IPv4, conform with RFC 3927)
* PPP (Point-to-Point Protocol)
* ARP (Address Resolution Protocol) for Ethernet
LICENSE
lwIP is freely available under a BSD license.
DEVELOPMENT
lwIP has grown into an excellent TCP/IP stack for embedded devices,
and developers using the stack often submit bug fixes, improvements,
and additions to the stack to further increase its usefulness.
Development of lwIP is hosted on Savannah, a central point for
software development, maintenance and distribution. Everyone can
help improve lwIP by use of Savannah's interface, CVS and the
mailing list. A core team of developers will commit changes to the
CVS source tree.
The lwIP TCP/IP stack is maintained in the 'lwip' CVS module and
contributions (such as platform ports) are in the 'contrib' module.
See doc/savannah.txt for details on CVS server access for users and
developers.
Last night's CVS tar ball can be downloaded from:
http://savannah.gnu.org/cvs.backups/lwip.tar.gz [CHANGED - NEEDS FIXING]
The current CVS trees are web-browsable:
http://savannah.nongnu.org/cgi-bin/viewcvs/lwip/lwip/
http://savannah.nongnu.org/cgi-bin/viewcvs/lwip/contrib/
Submit patches and bugs via the lwIP project page:
http://savannah.nongnu.org/projects/lwip/
DOCUMENTATION
The original out-dated homepage of lwIP and Adam Dunkels' papers on
lwIP are at the official lwIP home page:
http://www.sics.se/~adam/lwip/
Self documentation of the source code is regularly extracted from the
current CVS sources and is available from this web page:
http://www.nongnu.org/lwip/
There is now a constantly growin wiki about lwIP at
http://lwip.wikia.com/wiki/LwIP_Wiki
Also, there are mailing lists you can subscribe at
http://savannah.nongnu.org/mail/?group=lwip
plus searchable archives:
http://lists.nongnu.org/archive/html/lwip-users/
http://lists.nongnu.org/archive/html/lwip-devel/
Reading Adam's papers, the files in docs/, browsing the source code
documentation and browsing the mailing list archives is a good way to
become familiar with the design of lwIP.
Adam Dunkels <adam@sics.se>
Leon Woestenberg <leon.woestenberg@gmx.net>
This file lists major changes between release versions that require
ports or applications to be changed. Use it to update a port or an
application written for an older version of lwIP to correctly work
with newer versions.
(CVS HEAD)
* [Enter new changes just after this line - do not remove this line]
++ Application changes:
* Replaced struct ip_addr by typedef ip_addr_t (struct ip_addr is kept for
compatibility to old applications, but will be removed in the future).
* Renamed mem_realloc() to mem_trim() to prevent confusion with realloc()
+++ Raw API:
* Changed the semantics of tcp_close() (since it was rather a
shutdown before): Now the application does *NOT* get any calls to the recv
callback (aside from NULL/closed) after calling tcp_close()
* When calling tcp_abort() from a raw API TCP callback function,
make sure you return ERR_ABRT to prevent accessing unallocated memory.
(ERR_ABRT now means the applicaiton has called tcp_abort!)
+++ Netconn API:
* Changed netconn_receive() and netconn_accept() to return
err_t, not a pointer to new data/netconn.
+++ Socket API:
* LWIP_SO_RCVTIMEO: when accept() or recv() time out, they
now set errno to EWOULDBLOCK/EAGAIN, not ETIMEDOUT.
* Added a minimal version of posix fctl() to have a
standardised way to set O_NONBLOCK for nonblocking sockets.
+++ all APIs:
* correctly implemented SO(F)_REUSEADDR
++ Port changes
+++ new files:
* Added 4 new files: def.c, timers.c, timers.h, tcp_impl.h:
* Moved stack-internal parts of tcp.h to tcp_impl.h, tcp.h now only contains
the actual application programmer's API
* Separated timer implementation from sys.h/.c, moved to timers.h/.c;
Added timer implementation for NO_SYS==1, set NO_SYS_NO_TIMERS==1 if you
still want to use your own timer implementation for NO_SYS==0 (as before).
+++ sys layer:
* Converted mbox- and semaphore-functions to take pointers to sys_mbox_t/
sys_sem_t;
* Converted sys_mbox_new/sys_sem_new to take pointers and return err_t;
* Added Mutex concept in sys_arch (define LWIP_COMPAT_MUTEX to let sys.h use
binary semaphores instead of mutexes - as before)
+++ new options:
* Don't waste memory when chaining segments, added option TCP_OVERSIZE to
prevent creating many small pbufs when calling tcp_write with many small
blocks of data. Instead, pbufs are allocated larger than needed and the
space is used for later calls to tcp_write.
* Added LWIP_NETIF_TX_SINGLE_PBUF to always copy to try to create single pbufs
in tcp_write/udp_send.
* Added an additional option LWIP_ETHERNET to support ethernet without ARP
(necessary for pure PPPoE)
* Add MEMP_SEPARATE_POOLS to place memory pools in separate arrays. This may
be used to place these pools into user-defined memory by using external
declaration.
* Added TCP_SNDQUEUELOWAT corresponding to TCP_SNDLOWAT
+++ new pools:
* Netdb uses a memp pool for allocating memory when getaddrinfo() is called,
so MEMP_NUM_NETDB has to be set accordingly.
* DNS_LOCAL_HOSTLIST_IS_DYNAMIC uses a memp pool instead of the heap, so
MEMP_NUM_LOCALHOSTLIST has to be set accordingly.
* Snmp-agent uses a memp pools instead of the heap, so MEMP_NUM_SNMP_* have
to be set accordingly.
* PPPoE uses a MEMP pool instead of the heap, so MEMP_NUM_PPPOE_INTERFACES
has to be set accordingly
* Integrated loopif into netif.c - loopif does not have to be created by the
port any more, just define LWIP_HAVE_LOOPIF to 1.
* Added define LWIP_RAND() for lwip-wide randomization (needs to be defined
in cc.h, e.g. used by igmp)
* Added printf-formatter X8_F to printf u8_t as hex
* The heap now may be moved to user-defined memory by defining
LWIP_RAM_HEAP_POINTER as a void pointer to that memory's address
* added autoip_set_struct() and dhcp_set_struct() to let autoip and dhcp work
with user-allocated structs instead of calling mem_malloc
* Added const char* name to mem- and memp-stats for easier debugging.
* Calculate the TCP/UDP checksum while copying to only fetch data once:
Define LWIP_CHKSUM_COPY to a memcpy-like function that returns the checksum
* Added SO_REUSE_RXTOALL to pass received UDP broadcast/multicast packets to
more than one pcb.
* Changed the semantics of ARP_QUEUEING==0: ARP_QUEUEING now cannot be turned
off any more, if this is set to 0, only one packet (the most recent one) is
queued (like demanded by RFC 1122).
++ Major bugfixes/improvements
* Implemented tcp_shutdown() to only shut down one end of a connection
* Implemented shutdown() at socket- and netconn-level
* Added errorset support to select() + improved select speed overhead
* Merged pppd to v2.3.11 (including some backported bugfixes from 2.4.x)
* Added timer implementation for NO_SYS==1 (may be disabled with NO_SYS_NO_TIMERS==1
* Use macros defined in ip_addr.h to work with IP addresses
* Implemented many nonblocking socket/netconn functions
* Fixed ARP input processing: only add a new entry if a request was directed as us
* mem_realloc() to mem_trim() to prevent confusion with realloc()
* Some improvements for AutoIP (don't route/forward link-local addresses, don't break
existing connections when assigning a routable address)
* Correctly handle remote side overrunning our rcv_wnd in ooseq case
* Removed packing from ip_addr_t, the packed version is now only used in protocol headers
* Corrected PBUF_POOL_BUFSIZE for ports where ETH_PAD_SIZE > 0
* Added support for static ARP table entries
(STABLE-1.3.2)
* initial version of this file
#ifndef _ETHMAC_CONFIG_H_
#define _ETHMAC_CONFIG_H_
/* include user-provided file that
* will override definitions in this
* standard include file.
*/
#include "ethernet_config.h"
/* NOTE:
* ethernet_config.h is a user-supplied file
* that can be blank if the defaults specified
* in this file are acceptable.
*/
/* Interface PHY number */
#ifndef PHY_NUM
#define PHY_NUM 0
#endif
/*
* MAC Address (Software configurable)
* (e.g. 00-0A-35-02-53-2D)
*/
#ifndef MAC_CFG_MAC_ADDR_UPPER_16
#define MAC_CFG_MAC_ADDR_UPPER_16 (0x0001)
#endif
#ifndef MAC_CFG_MAC_ADDR_LOWER_32
#define MAC_CFG_MAC_ADDR_LOWER_32 (0x02030405)
#endif
#endif /*_ETHMAC_CONFIG_H_*/
#ifndef _ETHERNETIF_H_
#define _ETHERNETIF_H_
/*
* user-defined structure for containing
* ethernet information
*/
struct ethernetif {
struct eth_addr *ethaddr;
unsigned int gigabit_mode_enabled; /* 0 => 10/100mbps, 1 => 1000mbps */
};
/* Ethernet interface initialization function */
err_t ethernetif_init(struct netif *netif);
#endif /*ETHERNETIF_H_*/
/*
* Copyright (c) 2001-2003 Swedish Institute of Computer Science.
* 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. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
*
* This file is part of the lwIP TCP/IP stack.
*
* NOTE: Modified for LatticeMico32 (Lattice Semiconductor)
*/
#ifndef __ARCH_CC_H__
#define __ARCH_CC_H__
/* Include some files for defining library routines */
#include <string.h>
/* LatticeMicoc32 is big-endian */
#define BYTE_ORDER BIG_ENDIAN
/* Define generic types used in lwIP */
typedef unsigned char u8_t;
typedef signed char s8_t;
typedef unsigned short u16_t;
typedef signed short s16_t;
typedef unsigned long u32_t;
typedef signed long s32_t;
typedef u32_t mem_ptr_t;
/* Define (sn)printf formatters for these lwIP types */
#define U8_F "c"
#define S8_F "c"
#define X8_F "x"
#define U16_F "u"
#define S16_F "d"
#define X16_F "x"
#define U32_F "u"
#define S32_F "d"
#define X32_F "x"
/* Compiler hints for packing structures */
#define PACK_STRUCT_FIELD(x) x __attribute__((packed))
#define PACK_STRUCT_STRUCT __attribute__((packed))
#define PACK_STRUCT_BEGIN
#define PACK_STRUCT_END
/* prototypes for printf() and abort() */
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
/* Our printf function */
#include "pp-printf.h"
/* Definitions for ASSERT/DIAG */
#ifdef LWIP_NOASSERT
#define LWIP_PLATFORM_ASSERT(x)
#else
#define LWIP_PLATFORM_ASSERT(x) do {pp_printf("Assertion \"%s\" failed at line %d in %s\n", \
x, __LINE__, __FILE__); fflush(NULL); _exit(1);} while(0)
#endif
#ifndef LWIP_DEBUG
#define LWIP_PLATFORM_DIAG(x)
#else
#define LWIP_PLATFORM_DIAG(x) do {pp_printf x;} while(0)
#endif
#endif /* __ARCH_CC_H__ */
/*
* Copyright (c) 2001-2003 Swedish Institute of Computer Science.
* 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. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
*
* This file is part of the lwIP TCP/IP stack.
*
* Author: Adam Dunkels <adam@sics.se>
*
*/
#ifndef __ARCH_PERF_H__
#define __ARCH_PERF_H__
#define PERF_START /* null definition */
#define PERF_STOP(x) /* null definition */
#endif /* __ARCH_PERF_H__ */
/*
* Copyright (c) 2001-2003 Swedish Institute of Computer Science.
* 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. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
*
* This file is part of the lwIP TCP/IP stack.
*
* Author: Adam Dunkels <adam@sics.se>
*
*/
#ifndef __ARCH_SYS_ARCH_H__
#define __ARCH_SYS_ARCH_H__
/*#include <errno.h>*/
/*#include <sys/time.h>*/
#define SYS_MBOX_NULL NULL
#define SYS_SEM_NULL NULL
/*typedef u32_t sys_prot_t;
struct sys_sem;
typedef struct sys_sem * sys_sem_t;
struct sys_mbox;
typedef struct sys_mbox *sys_mbox_t;
struct sys_thread;
typedef struct sys_thread * sys_thread_t;*/
typedef void * sys_prot_t;
typedef void * sys_sem_t;
typedef void * sys_mbox_t;
typedef void * sys_thread_t;
#endif /* __ARCH_SYS_ARCH_H__ */
savannah.txt - How to obtain the current development source code.
contrib.txt - How to contribute to lwIP as a developer.
rawapi.txt - The documentation for the core API of lwIP.
Also provides an overview about the other APIs and multithreading.
snmp_agent.txt - The documentation for the lwIP SNMP agent.
sys_arch.txt - The documentation for a system abstraction layer of lwIP.
1 Introduction
This document describes some guidelines for people participating
in lwIP development.
2 How to contribute to lwIP
Here is a short list of suggestions to anybody working with lwIP and
trying to contribute bug reports, fixes, enhancements, platform ports etc.
First of all as you may already know lwIP is a volunteer project so feedback
to fixes or questions might often come late. Hopefully the bug and patch tracking
features of Savannah help us not lose users' input.
2.1 Source code style:
1. do not use tabs.
2. indentation is two spaces per level (i.e. per tab).
3. end debug messages with a trailing newline (\n).
4. one space between keyword and opening bracket.
5. no space between function and opening bracket.
6. one space and no newline before opening curly braces of a block.
7. closing curly brace on a single line.
8. spaces surrounding assignment and comparisons.
9. don't initialize static and/or global variables to zero, the compiler takes care of that.
10. use current source code style as further reference.
2.2 Source code documentation style:
1. JavaDoc compliant and Doxygen compatible.
2. Function documentation above functions in .c files, not .h files.
(This forces you to synchronize documentation and implementation.)
3. Use current documentation style as further reference.
2.3 Bug reports and patches:
1. Make sure you are reporting bugs or send patches against the latest
sources. (From the latest release and/or the current CVS sources.)
2. If you think you found a bug make sure it's not already filed in the
bugtracker at Savannah.
3. If you have a fix put the patch on Savannah. If it is a patch that affects
both core and arch specific stuff please separate them so that the core can
be applied separately while leaving the other patch 'open'. The prefered way
is to NOT touch archs you can't test and let maintainers take care of them.
This is a good way to see if they are used at all - the same goes for unix
netifs except tapif.
4. Do not file a bug and post a fix to it to the patch area. Either a bug report
or a patch will be enough.
If you correct an existing bug then attach the patch to the bug rather than creating a new entry in the patch area.
5. Trivial patches (compiler warning, indentation and spelling fixes or anything obvious which takes a line or two)
can go to the lwip-users list. This is still the fastest way of interaction and the list is not so crowded
as to allow for loss of fixes. Putting bugs on Savannah and subsequently closing them is too much an overhead
for reporting a compiler warning fix.
6. Patches should be specific to a single change or to related changes.Do not mix bugfixes with spelling and other
trivial fixes unless the bugfix is trivial too.Do not reorganize code and rename identifiers in the same patch you
change behaviour if not necessary.A patch is easier to read and understand if it's to the point and short than
if it's not to the point and long :) so the chances for it to be applied are greater.
2.4 Platform porters:
1. If you have ported lwIP to a platform (an OS, a uC/processor or a combination of these) and
you think it could benefit others[1] you might want discuss this on the mailing list. You
can also ask for CVS access to submit and maintain your port in the contrib CVS module.
\ No newline at end of file
This diff is collapsed.
Daily Use Guide for using Savannah for lwIP
Table of Contents:
1 - Obtaining lwIP from the CVS repository
2 - Committers/developers CVS access using SSH (to be written)
3 - Merging from DEVEL branch to main trunk (stable branch)
4 - How to release lwIP
1 Obtaining lwIP from the CVS repository
----------------------------------------
To perform an anonymous CVS checkout of the main trunk (this is where
bug fixes and incremental enhancements occur), do this:
cvs -z3 -d:pserver:anonymous@cvs.sv.gnu.org:/sources/lwip checkout lwip
Or, obtain a stable branch (updated with bug fixes only) as follows:
cvs -z3 -d:pserver:anonymous@cvs.sv.gnu.org:/sources/lwip checkout \
-r STABLE-0_7 -d lwip-0.7 lwip
Or, obtain a specific (fixed) release as follows:
cvs -z3 -d:pserver:anonymous@cvs.sv.gnu.org:/sources/lwip checkout \
-r STABLE-0_7_0 -d lwip-0.7.0 lwip
3 Committers/developers CVS access using SSH
--------------------------------------------
The Savannah server uses SSH (Secure Shell) protocol 2 authentication and encryption.
As such, CVS commits to the server occur through a SSH tunnel for project members.
To create a SSH2 key pair in UNIX-like environments, do this:
ssh-keygen -t dsa
Under Windows, a recommended SSH client is "PuTTY", freely available with good
documentation and a graphic user interface. Use its key generator.
Now paste the id_dsa.pub contents into your Savannah account public key list. Wait
a while so that Savannah can update its configuration (This can take minutes).
Try to login using SSH:
ssh -v your_login@cvs.sv.gnu.org
If it tells you:
Authenticating with public key "your_key_name"...
Server refused to allocate pty
then you could login; Savannah refuses to give you a shell - which is OK, as we
are allowed to use SSH for CVS only. Now, you should be able to do this:
export CVS_RSH=ssh
cvs -z3 -d:ext:your_login@cvs.sv.gnu.org:/sources/lwip co lwip
after which you can edit your local files with bug fixes or new features and
commit them. Make sure you know what you are doing when using CVS to make
changes on the repository. If in doubt, ask on the lwip-members mailing list.
(If SSH asks about authenticity of the host, you can check the key
fingerprint against http://savannah.nongnu.org/cvs/?group=lwip)
3 Merging from DEVEL branch to main trunk (stable)
--------------------------------------------------
Merging is a delicate process in CVS and requires the
following disciplined steps in order to prevent conflicts
in the future. Conflicts can be hard to solve!
Merging from branch A to branch B requires that the A branch
has a tag indicating the previous merger. This tag is called
'merged_from_A_to_B'. After merging, the tag is moved in the
A branch to remember this merger for future merge actions.
IMPORTANT: AFTER COMMITTING A SUCCESFUL MERGE IN THE
REPOSITORY, THE TAG MUST BE SET ON THE SOURCE BRANCH OF THE
MERGE ACTION (REPLACING EXISTING TAGS WITH THE SAME NAME).
Merge all changes in DEVEL since our last merge to main:
In the working copy of the main trunk:
cvs update -P -jmerged_from_DEVEL_to_main -jDEVEL
(This will apply the changes between 'merged_from_DEVEL_to_main'
and 'DEVEL' to your work set of files)
We can now commit the merge result.
cvs commit -R -m "Merged from DEVEL to main."
If this worked out OK, we now move the tag in the DEVEL branch
to this merge point, so we can use this point for future merges:
cvs rtag -F -r DEVEL merged_from_DEVEL_to_main lwip
4 How to release lwIP
---------------------
First, checkout a clean copy of the branch to be released. Tag this set with
tag name "STABLE-0_6_3". (I use release number 0.6.3 throughout this example).
Login CVS using pserver authentication, then export a clean copy of the
tagged tree. Export is similar to a checkout, except that the CVS metadata
is not created locally.
export CVS_RSH=ssh
cvs -z3 -d:pserver:anonymous@cvs.sv.gnu.org:/sources/lwip checkout \
-r STABLE-0_6_3 -d lwip-0.6.3 lwip
Archive this directory using tar, gzip'd, bzip2'd and zip'd.
tar czvf lwip-0.6.3.tar.gz lwip-0.6.3
tar cjvf lwip-0.6.3.tar.bz2 lwip-0.6.3
zip -r lwip-0.6.3.zip lwip-0.6.3
Now, sign the archives with a detached GPG binary signature as follows:
gpg -b lwip-0.6.3.tar.gz
gpg -b lwip-0.6.3.tar.bz2
gpg -b lwip-0.6.3.zip
Upload these files using anonymous FTP:
ncftp ftp://savannah.gnu.org/incoming/savannah/lwip
ncftp>mput *0.6.3.*
Additionally, you may post a news item on Savannah, like this:
A new 0.6.3 release is now available here:
http://savannah.nongnu.org/files/?group=lwip&highlight=0.6.3
You will have to submit this via the user News interface, then approve
this via the Administrator News interface.
\ No newline at end of file
SNMPv1 agent for lwIP
Author: Christiaan Simons
This is a brief introduction how to use and configure the SNMP agent.
Note the agent uses the raw-API UDP interface so you may also want to
read rawapi.txt to gain a better understanding of the SNMP message handling.
0 Agent Capabilities
====================
SNMPv1 per RFC1157
This is an old(er) standard but is still widely supported.
For SNMPv2c and v3 have a greater complexity and need many
more lines of code. IMHO this breaks the idea of "lightweight IP".
Note the S in SNMP stands for "Simple". Note that "Simple" is
relative. SNMP is simple compared to the complex ISO network
management protocols CMIP (Common Management Information Protocol)
and CMOT (CMip Over Tcp).
MIB II per RFC1213
The standard lwIP stack management information base.
This is a required MIB, so this is always enabled.
When builing lwIP without TCP, the mib-2.tcp group is omitted.
The groups EGP, CMOT and transmission are disabled by default.
Most mib-2 objects are not writable except:
sysName, sysLocation, sysContact, snmpEnableAuthenTraps.
Writing to or changing the ARP and IP address and route
tables is not possible.
Note lwIP has a very limited notion of IP routing. It currently
doen't have a route table and doesn't have a notion of the U,G,H flags.
Instead lwIP uses the interface list with only one default interface
acting as a single gateway interface (G) for the default route.
The agent returns a "virtual table" with the default route 0.0.0.0
for the default interface and network routes (no H) for each
network interface in the netif_list.
All routes are considered to be up (U).
Loading additional MIBs
MIBs can only be added in compile-time, not in run-time.
There is no MIB compiler thus additional MIBs must be hand coded.
Large SNMP message support
The packet decoding and encoding routines are designed
to use pbuf-chains. Larger payloads than the minimum
SNMP requirement of 484 octets are supported if the
PBUF_POOL_SIZE and IP_REASS_BUFSIZE are set to match your
local requirement.
1 Building the Agent
====================
First of all you'll need to add the following define
to your local lwipopts.h:
#define LWIP_SNMP 1
and add the source files in lwip/src/core/snmp
and some snmp headers in lwip/src/include/lwip to your makefile.
Note you'll might need to adapt you network driver to update
the mib2 variables for your interface.
2 Running the Agent
===================
The following function calls must be made in your program to
actually get the SNMP agent running.
Before starting the agent you should supply pointers
to non-volatile memory for sysContact, sysLocation,
and snmpEnableAuthenTraps. You can do this by calling
snmp_set_syscontact()
snmp_set_syslocation()
snmp_set_snmpenableauthentraps()
Additionally you may want to set
snmp_set_sysdescr()
snmp_set_sysobjid() (if you have a private MIB)
snmp_set_sysname()
Also before starting the agent you need to setup
one or more trap destinations using these calls:
snmp_trap_dst_enable();
snmp_trap_dst_ip_set();
In the lwIP initialisation sequence call snmp_init() just after
the call to udp_init().
Exactly every 10 msec the SNMP uptime timestamp must be updated with
snmp_inc_sysuptime(). You should call this from a timer interrupt
or a timer signal handler depending on your runtime environment.
An alternative way to update the SNMP uptime timestamp is to do a call like
snmp_add_sysuptime(100) each 1000ms (which is bigger "step", but call to
a lower frequency). Another one is to not call snmp_inc_sysuptime() or
snmp_add_sysuptime(), and to define the SNMP_GET_SYSUPTIME(sysuptime) macro.
This one is undefined by default in mib2.c. SNMP_GET_SYSUPTIME is called inside
snmp_get_sysuptime(u32_t *value), and enable to change "sysuptime" value only
when it's queried (any function which need "sysuptime" have to call
snmp_get_sysuptime).
3 Private MIBs
==============
If want to extend the agent with your own private MIB you'll need to
add the following define to your local lwipopts.h:
#define SNMP_PRIVATE_MIB 1
You must provide the private_mib.h and associated files yourself.
Note we don't have a "MIB compiler" that generates C source from a MIB,
so you're required to do some serious coding if you enable this!
Note the lwIP enterprise ID (26381) is assigned to the lwIP project,
ALL OBJECT IDENTIFIERS LIVING UNDER THIS ID ARE ASSIGNED BY THE lwIP
MAINTAINERS!
If you need to create your own private MIB you'll need
to apply for your own enterprise ID with IANA: http://www.iana.org/numbers.html
You can set it by passing a struct snmp_obj_id to the agent
using snmp_set_sysobjid(&my_object_id), just before snmp_init().
Note the object identifiers for thes MIB-2 and your private MIB
tree must be kept in sorted ascending (lexicographical) order.
This to ensure correct getnext operation.
An example for a private MIB is part of the "minimal Unix" project:
contrib/ports/unix/proj/minimal/lwip_prvmib.c
The next chapter gives a more detailed description of the
MIB-2 tree and the optional private MIB.
4 The Gory Details
==================
4.0 Object identifiers and the MIB tree.
We have three distinct parts for all object identifiers:
The prefix
.iso.org.dod.internet
the middle part
.mgmt.mib-2.ip.ipNetToMediaTable.ipNetToMediaEntry.ipNetToMediaPhysAddress
and the index part
.1.192.168.0.1
Objects located above the .internet hierarchy aren't supported.
Currently only the .mgmt sub-tree is available and
when the SNMP_PRIVATE_MIB is enabled the .private tree
becomes available too.
Object identifiers from incoming requests are checked
for a matching prefix, middle part and index part
or are expanded(*) for GetNext requests with short
or inexisting names in the request.
(* we call this "expansion" but this also
resembles the "auto-completion" operation)
The middle part is usually located in ROM (const)
to preserve precious RAM on small microcontrollers.
However RAM location is possible for a dynamically
changing private tree.
The index part is handled by functions which in
turn use dynamically allocated index trees from RAM.
These trees are updated by e.g. the etharp code
when new entries are made or removed form the ARP cache.
/** @todo more gory details */
This diff is collapsed.
TARGETDIR=lib
CONTRIBDIR=lib/lwip/contrib
LWIPDIR=lib/lwip/src
LWIPARCH=$(CONTRIBDIR)/ports/lm32
LWIPDRVDIR=$(CONTRIBDIR)/ports/ethmac10100-drv
CFLAGS_LWIP += $(CPPFLAGS) -I$(LWIPDIR)/include -I. \
-I$(LWIPARCH)/include -I$(LWIPARCH)/include/arch \
-I$(LWIPDIR)/include/ipv4 -I$(LWIPDRVDIR) \
-I$(LWIPDRVDIR)/netif -I$(INCDIR)
# COREOBJS, CORE4OBJS: The minimum set of files needed for lwIP.
COREOBJS=$(LWIPDIR)/core/mem.o \
$(LWIPDIR)/core/memp.o \
$(LWIPDIR)/core/netif.o \
$(LWIPDIR)/core/pbuf.o \
$(LWIPDIR)/core/raw.o \
$(LWIPDIR)/core/stats.o \
$(LWIPDIR)/core/sys.o \
$(LWIPDIR)/core/timers.o \
$(LWIPDIR)/core/tcp.o \
$(LWIPDIR)/core/tcp_in.o \
$(LWIPDIR)/core/tcp_out.o \
$(LWIPDIR)/core/udp.o \
$(LWIPDIR)/core/dhcp.o \
$(LWIPDIR)/core/init.o
CORE4OBJS=$(LWIPDIR)/core/ipv4/icmp.o \
$(LWIPDIR)/core/ipv4/ip.o \
$(LWIPDIR)/core/ipv4/inet.o \
$(LWIPDIR)/core/ipv4/ip_addr.o \
$(LWIPDIR)/core/ipv4/ip_frag.o \
$(LWIPDIR)/core/ipv4/inet_chksum.o
# NETIFOBJS: Files implementing various generic network interface functions.'
NETIFOBJS=$(LWIPDIR)/netif/etharp.o \
$(LWIPDRVDIR)/netif/ethernetif.o
# LWIPOBJS: All the above.
LWIPOBJS=$(COREOBJS) $(CORE4OBJS) $(NETIFOBJS)
OBJS_LIB+=$(LWIPOBJS)
CFLAGS_LWIP = -I$(LWIPDIR)/include -I. \
-I$(LWIPARCH)/include -I$(LWIPARCH)/include/arch \
-I$(LWIPDIR)/include/ipv4 -I$(LWIPDRVDIR) \
-I$(LWIPDRVDIR)/netif
$(LWIPLIB): $(LWIPOBJS)
$(AR) $(ARFLAGS) $(LWIPLIB) $?
api/ - The code for the high-level wrapper API. Not needed if
you use the lowel-level call-back/raw API.
core/ - The core of the TPC/IP stack; protocol implementations,
memory and buffer management, and the low-level raw API.
include/ - lwIP include files.
netif/ - Generic network interface device drivers are kept here,
as well as the ARP module.
For more information on the various subdirectories, check the FILES
file in each directory.
This diff is collapsed.
This diff is collapsed.
/**
* @file
* Error Management module
*
*/
/*
* Copyright (c) 2001-2004 Swedish Institute of Computer Science.
* 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. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
*
* This file is part of the lwIP TCP/IP stack.
*
* Author: Adam Dunkels <adam@sics.se>
*
*/
#include "lwip/err.h"
#ifdef LWIP_DEBUG
static const char *err_strerr[] = {
"Ok.", /* ERR_OK 0 */
"Out of memory error.", /* ERR_MEM -1 */
"Buffer error.", /* ERR_BUF -2 */
"Timeout.", /* ERR_TIMEOUT -3 */
"Routing problem.", /* ERR_RTE -4 */
"Operation in progress.", /* ERR_INPROGRESS -5 */
"Illegal value.", /* ERR_VAL -6 */
"Operation would block.", /* ERR_WOULDBLOCK -7 */
"Address in use.", /* ERR_USE -8 */
"Already connected.", /* ERR_ISCONN -9 */
"Connection aborted.", /* ERR_ABRT -10 */
"Connection reset.", /* ERR_RST -11 */
"Connection closed.", /* ERR_CLSD -12 */
"Not connected.", /* ERR_CONN -13 */
"Illegal argument.", /* ERR_ARG -14 */
"Low-level netif error.", /* ERR_IF -15 */
};
/**
* Convert an lwip internal error to a string representation.
*
* @param err an lwip internal err_t
* @return a string representation for err
*/
const char *
lwip_strerr(err_t err)
{
return err_strerr[-err];
}
#endif /* LWIP_DEBUG */
/**
* @file
* Network buffer management
*
*/
/*
* Copyright (c) 2001-2004 Swedish Institute of Computer Science.
* 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. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
*
* This file is part of the lwIP TCP/IP stack.
*
* Author: Adam Dunkels <adam@sics.se>
*
*/
#include "lwip/opt.h"
#if LWIP_NETCONN /* don't build if not configured for use in lwipopts.h */
#include "lwip/netbuf.h"
#include "lwip/memp.h"
#include <string.h>
/**
* Create (allocate) and initialize a new netbuf.
* The netbuf doesn't yet contain a packet buffer!
*
* @return a pointer to a new netbuf
* NULL on lack of memory
*/
struct
netbuf *netbuf_new(void)
{
struct netbuf *buf;
buf = (struct netbuf *)memp_malloc(MEMP_NETBUF);
if (buf != NULL) {
buf->p = NULL;
buf->ptr = NULL;
ip_addr_set_any(&buf->addr);
buf->port = 0;
#if LWIP_NETBUF_RECVINFO || LWIP_CHECKSUM_ON_COPY
#if LWIP_CHECKSUM_ON_COPY
buf->flags = 0;
#endif /* LWIP_CHECKSUM_ON_COPY */
buf->toport_chksum = 0;
#if LWIP_NETBUF_RECVINFO
ip_addr_set_any(&buf->toaddr);
#endif /* LWIP_NETBUF_RECVINFO */
#endif /* LWIP_NETBUF_RECVINFO || LWIP_CHECKSUM_ON_COPY */
return buf;
} else {
return NULL;
}
}
/**
* Deallocate a netbuf allocated by netbuf_new().
*
* @param buf pointer to a netbuf allocated by netbuf_new()
*/
void
netbuf_delete(struct netbuf *buf)
{
if (buf != NULL) {
if (buf->p != NULL) {
pbuf_free(buf->p);
buf->p = buf->ptr = NULL;
}
memp_free(MEMP_NETBUF, buf);
}
}
/**
* Allocate memory for a packet buffer for a given netbuf.
*
* @param buf the netbuf for which to allocate a packet buffer
* @param size the size of the packet buffer to allocate
* @return pointer to the allocated memory
* NULL if no memory could be allocated
*/
void *
netbuf_alloc(struct netbuf *buf, u16_t size)
{
LWIP_ERROR("netbuf_alloc: invalid buf", (buf != NULL), return NULL;);
/* Deallocate any previously allocated memory. */
if (buf->p != NULL) {
pbuf_free(buf->p);
}
buf->p = pbuf_alloc(PBUF_TRANSPORT, size, PBUF_RAM);
if (buf->p == NULL) {
return NULL;
}
LWIP_ASSERT("check that first pbuf can hold size",
(buf->p->len >= size));
buf->ptr = buf->p;
return buf->p->payload;
}
/**
* Free the packet buffer included in a netbuf
*
* @param buf pointer to the netbuf which contains the packet buffer to free
*/
void
netbuf_free(struct netbuf *buf)
{
LWIP_ERROR("netbuf_free: invalid buf", (buf != NULL), return;);
if (buf->p != NULL) {
pbuf_free(buf->p);
}
buf->p = buf->ptr = NULL;
}
/**
* Let a netbuf reference existing (non-volatile) data.
*
* @param buf netbuf which should reference the data
* @param dataptr pointer to the data to reference
* @param size size of the data
* @return ERR_OK if data is referenced
* ERR_MEM if data couldn't be referenced due to lack of memory
*/
err_t
netbuf_ref(struct netbuf *buf, const void *dataptr, u16_t size)
{
LWIP_ERROR("netbuf_ref: invalid buf", (buf != NULL), return ERR_ARG;);
if (buf->p != NULL) {
pbuf_free(buf->p);
}
buf->p = pbuf_alloc(PBUF_TRANSPORT, 0, PBUF_REF);
if (buf->p == NULL) {
buf->ptr = NULL;
return ERR_MEM;
}
buf->p->payload = (void*)dataptr;
buf->p->len = buf->p->tot_len = size;
buf->ptr = buf->p;
return ERR_OK;
}
/**
* Chain one netbuf to another (@see pbuf_chain)
*
* @param head the first netbuf
* @param tail netbuf to chain after head, freed by this function, may not be reference after returning
*/
void
netbuf_chain(struct netbuf *head, struct netbuf *tail)
{
LWIP_ERROR("netbuf_ref: invalid head", (head != NULL), return;);
LWIP_ERROR("netbuf_chain: invalid tail", (tail != NULL), return;);
pbuf_cat(head->p, tail->p);
head->ptr = head->p;
memp_free(MEMP_NETBUF, tail);
}
/**
* Get the data pointer and length of the data inside a netbuf.
*
* @param buf netbuf to get the data from
* @param dataptr pointer to a void pointer where to store the data pointer
* @param len pointer to an u16_t where the length of the data is stored
* @return ERR_OK if the information was retreived,
* ERR_BUF on error.
*/
err_t
netbuf_data(struct netbuf *buf, void **dataptr, u16_t *len)
{
LWIP_ERROR("netbuf_data: invalid buf", (buf != NULL), return ERR_ARG;);
LWIP_ERROR("netbuf_data: invalid dataptr", (dataptr != NULL), return ERR_ARG;);
LWIP_ERROR("netbuf_data: invalid len", (len != NULL), return ERR_ARG;);
if (buf->ptr == NULL) {
return ERR_BUF;
}
*dataptr = buf->ptr->payload;
*len = buf->ptr->len;
return ERR_OK;
}
/**
* Move the current data pointer of a packet buffer contained in a netbuf
* to the next part.
* The packet buffer itself is not modified.
*
* @param buf the netbuf to modify
* @return -1 if there is no next part
* 1 if moved to the next part but now there is no next part
* 0 if moved to the next part and there are still more parts
*/
s8_t
netbuf_next(struct netbuf *buf)
{
LWIP_ERROR("netbuf_free: invalid buf", (buf != NULL), return -1;);
if (buf->ptr->next == NULL) {
return -1;
}
buf->ptr = buf->ptr->next;
if (buf->ptr->next == NULL) {
return 1;
}
return 0;
}
/**
* Move the current data pointer of a packet buffer contained in a netbuf
* to the beginning of the packet.
* The packet buffer itself is not modified.
*
* @param buf the netbuf to modify
*/
void
netbuf_first(struct netbuf *buf)
{
LWIP_ERROR("netbuf_free: invalid buf", (buf != NULL), return;);
buf->ptr = buf->p;
}
#endif /* LWIP_NETCONN */
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
IPv6 support in lwIP is very experimental.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
dsp-cores @ 6063bc95
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment