From 7ce2688d84e01114f77abf403b9c181aadae2bdb Mon Sep 17 00:00:00 2001 From: Jelmer Tiete Date: Wed, 23 Jan 2013 22:56:43 +0100 Subject: [PATCH 01/34] Added support for motelist and uploading to Z1 motes under Mac OSX --- platform/z1/Makefile.common | 39 +++++++++++++------ tools/z1/motelist-z1-macos | 75 +++++++++++++++++++++++++++++++++++++ 2 files changed, 102 insertions(+), 12 deletions(-) create mode 100755 tools/z1/motelist-z1-macos diff --git a/platform/z1/Makefile.common b/platform/z1/Makefile.common index 28f1f8f8a..fb065c657 100644 --- a/platform/z1/Makefile.common +++ b/platform/z1/Makefile.common @@ -1,4 +1,4 @@ -# $Id: Makefile.z1,v 1.5 2011/02/26 enricmcalvo Exp $ +# $Id: Makefile.z1,v 1.6 2013/01/23 enricmcalvo,JelmerTiete Exp $ ifdef GCC CFLAGS+=-Os -g @@ -53,19 +53,34 @@ contiki-$(TARGET).a: ${addprefix $(OBJECTDIR)/,symbols.o} NUMPAR=20 IHEXFILE=tmpimage.ihex -# If we are not running under Windows, we assume Linux -ifndef MOTELIST - USBDEVPREFIX= - SERIALDUMP = $(CONTIKI)/tools/sky/serialdump-linux - MOTELIST = $(CONTIKI)/tools/z1/motelist-z1 - BSL = $(CONTIKI)/tools/z1/z1-bsl-nopic --z1 - BSL_FILETYPE = -I - MOTES = $(shell $(MOTELIST) -c 2>&- | \ - cut -f 2 -d , | \ - perl -ne 'print $$1 . " " if(m-(/dev/\w+)-);') - CMOTES=$(MOTES) +ifeq ($(HOST_OS),Darwin) + ifndef MOTELIST + USBDEVPREFIX= + SERIALDUMP = $(CONTIKI)/tools/sky/serialdump-linux + MOTELIST = $(CONTIKI)/tools/z1/motelist-z1-macos + BSL = $(CONTIKI)/tools/z1/z1-bsl-nopic --z1 + BSL_FILETYPE = -I + MOTES = $(shell $(MOTELIST) -c 2>&- | \ + cut -f 2 -d ,) + CMOTES=$(MOTES) + endif +else + # If we are not running under Mac, we assume Linux + ifndef MOTELIST + USBDEVPREFIX= + SERIALDUMP = $(CONTIKI)/tools/sky/serialdump-linux + MOTELIST = $(CONTIKI)/tools/z1/motelist-z1 + BSL = $(CONTIKI)/tools/z1/z1-bsl-nopic --z1 + BSL_FILETYPE = -I + MOTES = $(shell $(MOTELIST) -c 2>&- | \ + cut -f 2 -d , | \ + perl -ne 'print $$1 . " " if(m-(/dev/\w+)-);') + CMOTES=$(MOTES) + endif endif + + motelist: z1-motelist z1-motelist: diff --git a/tools/z1/motelist-z1-macos b/tools/z1/motelist-z1-macos new file mode 100755 index 000000000..526b4887e --- /dev/null +++ b/tools/z1/motelist-z1-macos @@ -0,0 +1,75 @@ +#!/usr/bin/perl -w +use strict; + +my $help = <<'EOF'; +usage: motelist [options] + +options: + -h display this help + -c compact format, not pretty but easier for parsing +EOF + +my %Opt = ( + compact => 0, + dev_prefix => [ "/dev/tty.SLAB" ], +); + +while (@ARGV) { + last unless $ARGV[0] =~ /^-/; + my $opt = shift @ARGV; + if( $opt eq "-h" ) { print "$help\n"; exit 0; } + elsif( $opt eq "-c" ) { $Opt{compact} = 1; } + else { print STDERR "$help\nerror, unknown command line option $opt\n"; exit 1; } +} + +print_motelist( scan_dev() ); + +# +# Scan /dev for tty.SLAB* +# +sub scan_dev { + my @devs; + foreach (`ls /dev/tty.SLAB* 2>&1`) { + my($dev, $serial) = /(\/dev\/tty.SLAB(\S+))/; + if ($serial ne "*:") { + my $d; + $d->{"InfoSerial"} = $serial; + $d->{"SerialDevName"} = $dev; + push(@devs, $d); + } + } + return @devs; +} + + +# +# Print motelist +# +sub print_motelist { + my @devs = @_; + + # If none were found, quit + if( @devs == 0 ) { + #print "No devices found.\n"; + return; + } + + # Print a header + if( !$Opt{compact} ) { + print << "EOF" unless $Opt{compact}; +Reference Device Description +---------- --------------------------- --------------------------------------- +EOF + } + + # Print the usb information + for my $dev (@devs) { + my $desc = "(none)"; + my @output = ( $dev->{"InfoSerial"}, $dev->{"SerialDevName"}, $desc ); + if( $Opt{compact} ) { + print join(",",@output) . "\n"; + } else { + printf( "%-10s %-27s %s\n", @output ); + } + } +} From 2cf4e30b1116ecef0114639aa71e1d861ebc7b1f Mon Sep 17 00:00:00 2001 From: Antonio Lignan Date: Tue, 29 Jan 2013 12:23:23 +0100 Subject: [PATCH 02/34] Baudrate now is configured taking into account the MCU frequency, instead of using fixed values for 8MHz freq --- cpu/msp430/f2xxx/uart0.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cpu/msp430/f2xxx/uart0.c b/cpu/msp430/f2xxx/uart0.c index 938fe9c4c..0a17636fb 100644 --- a/cpu/msp430/f2xxx/uart0.c +++ b/cpu/msp430/f2xxx/uart0.c @@ -114,7 +114,7 @@ uart0_init(unsigned long ubr) UCA0CTL1 |= UCSWRST; /* Hold peripheral in reset state */ UCA0CTL1 |= UCSSEL_2; /* CLK = SMCLK */ - UCA0BR0 = 0x45; /* 8MHz/115200 = 69 = 0x45 */ + UCA0BR0 = ubr; /* 8MHz/115200 = 69 = 0x45 */ UCA0BR1 = 0x00; UCA0MCTL = UCBRS_3; /* Modulation UCBRSx = 3 */ From edf4e3609477122eac6d9be8f7497a5eb2965bbc Mon Sep 17 00:00:00 2001 From: Jelmer Tiete Date: Wed, 30 Jan 2013 11:13:19 +0100 Subject: [PATCH 03/34] removed tag from z1 Makefile.common --- platform/z1/Makefile.common | 2 -- 1 file changed, 2 deletions(-) diff --git a/platform/z1/Makefile.common b/platform/z1/Makefile.common index fb065c657..72a1270d6 100644 --- a/platform/z1/Makefile.common +++ b/platform/z1/Makefile.common @@ -1,5 +1,3 @@ -# $Id: Makefile.z1,v 1.6 2013/01/23 enricmcalvo,JelmerTiete Exp $ - ifdef GCC CFLAGS+=-Os -g endif From 12dd138915f56214a3aa464da6b239d1c792b451 Mon Sep 17 00:00:00 2001 From: Jelmer Tiete Date: Wed, 30 Jan 2013 14:15:16 +0100 Subject: [PATCH 04/34] fixed z1 i2c bug where 2 extra bytes were read with every i2c-receive --- platform/z1/dev/i2cmaster.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/platform/z1/dev/i2cmaster.c b/platform/z1/dev/i2cmaster.c index 2da89ef7b..d1d9ccbf2 100644 --- a/platform/z1/dev/i2cmaster.c +++ b/platform/z1/dev/i2cmaster.c @@ -214,6 +214,7 @@ ISR(USCIAB1TX, i2c_tx_interrupt) { // TX Part if (UC1IFG & UCB1TXIFG) { // TX int. condition + PRINTFDEBUG("!!! TX int\n"); if (tx_byte_ctr == 0) { UCB1CTL1 |= UCTXSTP; // I2C stop condition UC1IFG &= ~UCB1TXIFG; // Clear USCI_B1 TX int flag @@ -226,16 +227,13 @@ ISR(USCIAB1TX, i2c_tx_interrupt) // RX Part #if I2C_RX_WITH_INTERRUPT else if (UC1IFG & UCB1RXIFG){ // RX int. condition - if (rx_byte_ctr == 0){ + rx_buf_ptr[rx_byte_tot - rx_byte_ctr] = UCB1RXBUF; + rx_byte_ctr--; + if (rx_byte_ctr == 1){ //stop condition should be set before receiving last byte // Only for 1-byte transmissions, STOP is handled in receive_n_int if (rx_byte_tot != 1) UCB1CTL1 |= UCTXSTP; // I2C stop condition - - UC1IFG &= ~UCB1RXIFG; // Clear USCI_B1 RX int flag. XXX Just in case, check if necessary - } - else { - rx_buf_ptr[rx_byte_tot - rx_byte_ctr] = UCB1RXBUF; - rx_byte_ctr--; + UC1IFG &= ~UCB1RXIFG; // Clear USCI_B1 RX int flag. XXX Just in case, check if necessary } } #endif From f4976140fc1c1856e3fa6eb661441e2d0eb46062 Mon Sep 17 00:00:00 2001 From: Jelmer Tiete Date: Wed, 30 Jan 2013 14:23:07 +0100 Subject: [PATCH 05/34] fixed z1 i2c bug where 2 extra bytes were read with every i2c-receive --- platform/z1/dev/i2cmaster.c | 1 - 1 file changed, 1 deletion(-) diff --git a/platform/z1/dev/i2cmaster.c b/platform/z1/dev/i2cmaster.c index d1d9ccbf2..c3765f5cf 100644 --- a/platform/z1/dev/i2cmaster.c +++ b/platform/z1/dev/i2cmaster.c @@ -214,7 +214,6 @@ ISR(USCIAB1TX, i2c_tx_interrupt) { // TX Part if (UC1IFG & UCB1TXIFG) { // TX int. condition - PRINTFDEBUG("!!! TX int\n"); if (tx_byte_ctr == 0) { UCB1CTL1 |= UCTXSTP; // I2C stop condition UC1IFG &= ~UCB1TXIFG; // Clear USCI_B1 TX int flag From 5c6018f0e2ced379526582a3204ec700c48af804 Mon Sep 17 00:00:00 2001 From: Jeff Ciesielski Date: Wed, 6 Feb 2013 15:41:50 -0800 Subject: [PATCH 06/34] stm32f1x_cl: Add initial support for STM32F1x connectivity line This currently supports the stm32f107, but support will be added for the F105 shortly (missing a linker script and I can't properly test without a devkit). --- cpu/arm/stm32f1x_cl/Makefile.stm32f1x_cl | 169 +++++++++++++++++++++++ cpu/arm/stm32f1x_cl/STM32F107VCT.ld | 54 ++++++++ cpu/arm/stm32f1x_cl/clock.c | 78 +++++++++++ cpu/arm/stm32f1x_cl/mtarch.h | 13 ++ cpu/arm/stm32f1x_cl/rtimer-arch.c | 16 +++ cpu/arm/stm32f1x_cl/rtimer-arch.h | 22 +++ cpu/arm/stm32f1x_cl/uip-log.c | 7 + cpu/arm/stm32f1x_cl/util.c | 12 ++ cpu/arm/stm32f1x_cl/util.h | 5 + 9 files changed, 376 insertions(+) create mode 100644 cpu/arm/stm32f1x_cl/Makefile.stm32f1x_cl create mode 100644 cpu/arm/stm32f1x_cl/STM32F107VCT.ld create mode 100644 cpu/arm/stm32f1x_cl/clock.c create mode 100644 cpu/arm/stm32f1x_cl/mtarch.h create mode 100644 cpu/arm/stm32f1x_cl/rtimer-arch.c create mode 100644 cpu/arm/stm32f1x_cl/rtimer-arch.h create mode 100644 cpu/arm/stm32f1x_cl/uip-log.c create mode 100644 cpu/arm/stm32f1x_cl/util.c create mode 100644 cpu/arm/stm32f1x_cl/util.h diff --git a/cpu/arm/stm32f1x_cl/Makefile.stm32f1x_cl b/cpu/arm/stm32f1x_cl/Makefile.stm32f1x_cl new file mode 100644 index 000000000..c816ea40e --- /dev/null +++ b/cpu/arm/stm32f1x_cl/Makefile.stm32f1x_cl @@ -0,0 +1,169 @@ +# Adapted from Makefile.stm32f103 + +# Default to STM32F107VCT7 +ifndef SUBTARGET +$(warning SUBTARGET not defined, defaulting to STM32F107VCT) +SUBTARGET = 7VCT +endif + +### libopencm3 specifics +OPENCM3_BASE= +OPENCM3_FAMILY=STM32F1 +OPENCM3_LIB=opencm3_stm32f1 + +ifndef OPENCM3_BASE +$(error OPENCM3_BASE not defined. Please set definition to root of libopencm3) +endif +### Code common for all ARM CPUs + +CONTIKI_CPU_ARM=$(CONTIKI)/cpu/arm +CONTIKI_CPU_ARM_COMMON=$(CONTIKI_CPU_ARM)/common + +### Define the CPU directory +CONTIKI_CPU=$(CONTIKI_CPU_ARM)/stm32f1x_cl + +### Define the source files we have in the STM32F1x_cl port + +CONTIKI_CPU_DIRS = . + +STM32F1x = clock.c util.c uip-log.c symbols.c + +#Using the opencm3 usb library for now +#include $(CONTIKI_CPU_ARM_COMMON)/usb/Makefile.usb + +#No SD support for now...This is a TODO +#include $(CONTIKI_CPU_ARM_COMMON)/SD-card/Makefile.sdcard + +TARGETLIBS = random.c + +CONTIKI_TARGET_SOURCEFILES += $(STM32F1x) $(TARGETLIBS) + +CONTIKI_SOURCEFILES += $(CONTIKI_TARGET_SOURCEFILES) + +PREFIX = arm-none-eabi + +### Compiler definitions +CC = $(PREFIX)-gcc +LD = $(PREFIX)-ld +AS = $(PREFIX)-as +AR = $(PREFIX)-ar +NM = $(PREFIX)-nm +OBJCOPY = $(PREFIX)-objcopy +STRIP = $(PREFIX)-strip + +XSLTPROC=xsltproc + +PROJECT_OBJECTFILES += ${addprefix $(OBJECTDIR)/,$(CONTIKI_TARGET_MAIN:.c=.o)} + +LINKERSCRIPT = $(CONTIKI_CPU)/STM32F10$(SUBTARGET).ld + +# DFU-UTIL program upload +DFU_UTIL=dfu-util +DFU_UTIL_OFFSET=0x08000000 + +# Use dfu-util by default +PROG=dfuutil + +ARCH_FLAGS= -mcpu=cortex-m3 -mthumb + +#CONTIKI_CFLAGS = -DWITH_UIP -DWITH_ASCII + +CFLAGSNO = -I. -I$(CONTIKI)/core -I$(CONTIKI_CPU) \ + -I$(OPENCM3_BASE)/include \ + -I$(CONTIKI)/platform/$(TARGET) \ + ${addprefix -I,$(APPDIRS)} \ + -DMCK=$(MCK) -DSUBTARGET=$(SUBTARGET) \ + -Wall $(ARCH_FLAGS) -g -DSTM32F1 -MD + +CFLAGS += $(CONTIKI_CFLAGS) $(CFLAGSNO) -Os + +LDFLAGS += -L $(CONTIKI_CPU) -T $(LINKERSCRIPT) \ + -Wl,--start-group -lc -lgcc -Wl,--end-group\ + -nostartfiles -Wl,--gc-sections $(ARCH_FLAGS) + +EXTERN_LIBS += -L $(OPENCM3_BASE)/lib -l$(OPENCM3_LIB) + +CDEPFLAGS = $(CFLAGS) -D __MAKING_DEPS__ + +### Setup directory search path for source files + +CUSTOM_RULE_C_TO_OBJECTDIR_O=yes +CUSTOM_RULE_C_TO_O=yes + +%.o: %.c + $(CC) $(CFLAGS) $< -c + +$(OBJECTDIR)/%.o: %.c + $(CC) $(CFLAGS) -c $< -o $@ + + +CUSTOM_RULE_S_TO_OBJECTDIR_O = yes +%.o: %.S + $(CC) $(CFLAGS) $< -c + +$(OBJECTDIR)/%.o: %.S + $(CC) $(CFLAGS) $< -c -o $@ + + +CUSTOM_RULE_C_TO_CO=yes + +%.co: %.c + $(CC) $(CFLAGS) $< -c -o $@ + +CUSTOM_RULE_C_TO_CE=yes + +%.ce: %.o + $(LD) $(LDFLAGS) --relocatable -T $(CONTIKI_CPU)/merge-rodata.ld $< -o $@ + $(STRIP) -K _init -K _fini --strip-unneeded -g -x $@ + +CUSTOM_RULE_LINK=yes + +%-stripped.o: %.c + $(CC) $(CFLAGS) -c $< -o $@ + $(STRIP) --strip-unneeded -g -x $@ + +%-stripped.o: %.o + $(STRIP) --strip-unneeded -g -x -o $@ $< + +%.o: ${CONTIKI_TARGET}/loader/%.S + $(AS) -o $(notdir $(<:.S=.o)) $< + +%-nosyms.$(TARGET): %.co $(PROJECT_OBJECTFILES) contiki-$(TARGET).a # $(OBJECTDIR)/empty-symbols.o + $(CC) $(LDFLAGS) $(CFLAGS) -nostartfiles -o $@ $(filter-out %.a,$^) $(filter %.a,$^) -lc $(filter %.a,$^) $(EXTERN_LIBS) + + +%.ihex: %.$(TARGET) + $(OBJCOPY) $^ -O ihex $@ + +%.bin: %.$(TARGET) + $(OBJCOPY) -O binary $< $@ + +.PHONY: symbols.c +ifdef CORE +%.$(TARGET): %.co $(PROJECT_OBJECTFILES) contiki-$(TARGET).a $(STARTUP) $(OBJECTDIR)/symbols.o + $(CC) $(LDFLAGS) $(CFLAGS) -nostartfiles -o $@ $(filter-out %.a,$^) $(filter %.a,$^) -lc $(filter %.a,$^) + +symbols.c: $(CORE) + $(NM) $< | awk -f $(CONTIKI_CPU)/builtins.awk -f ../../tools/mknmlist > symbols.c + +else +%.$(TARGET): %-nosyms.$(TARGET) + ln -sf $< $@ +endif + +empty-symbols.c: + cp ${CONTIKI}/tools/empty-symbols.c symbols.c + cp ${CONTIKI}/tools/empty-symbols.h symbols.h + +# Don't use core/loader/elfloader.c, use elfloader-otf.c instead +$(OBJECTDIR)/elfloader.o: + echo -n >$@ + +clean: clean_cpu + +.PHONY: stm32test_clean + +clean_cpu: + -rm -rf $(BUILTSRCDIR) + +.PRECIOUS: %-nosyms.$(TARGET) diff --git a/cpu/arm/stm32f1x_cl/STM32F107VCT.ld b/cpu/arm/stm32f1x_cl/STM32F107VCT.ld new file mode 100644 index 000000000..5d60e4979 --- /dev/null +++ b/cpu/arm/stm32f1x_cl/STM32F107VCT.ld @@ -0,0 +1,54 @@ +MEMORY +{ + CODE (rx) : ORIGIN = 0x08000000, LENGTH = 256K + DATA (xrw) : ORIGIN = 0x20000000, LENGTH = 64K +} + +/* Section Definitions */ + +EXTERN (vector_table) +ENTRY(reset_handler) +SECTIONS +{ + +/* Make sure the vector table is at address 0 */ + + .text : { + *(.vectors) + *(.text*) + . = ALIGN(4); + *(.rodata*) + . = ALIGN(4); + } >CODE + + . = ALIGN(4); + _etext = . ; + PROVIDE (etext = .); + + .data : + { + _data = . ; + *(.data) + . = ALIGN(4); + _edata = . ; + PROVIDE (_edata = .); + } >DATA AT >CODE + _data_loadaddr = LOADADDR(.data); + +/* .bss section which is used for uninitialized data */ + + .bss : + { + __bss_start = . ; + __bss_start__ = . ; + *(.bss) + *(COMMON) + . = ALIGN(4); + _ebss = . ; + } >DATA + . = ALIGN(4); + + _end = .; + PROVIDE (_end = .); +} +PROVIDE(_stack = ORIGIN(DATA) + LENGTH(DATA)); diff --git a/cpu/arm/stm32f1x_cl/clock.c b/cpu/arm/stm32f1x_cl/clock.c new file mode 100644 index 000000000..9efaf3e05 --- /dev/null +++ b/cpu/arm/stm32f1x_cl/clock.c @@ -0,0 +1,78 @@ +#include +#include +#include +#include + +#include + +static volatile clock_time_t current_clock = 0; +static volatile unsigned long current_seconds = 0; +static unsigned int second_countdown = CLOCK_SECOND; + +void sys_tick_handler(void) __attribute__ ((interrupt)); + +void +sys_tick_handler(void) +{ + current_clock++; + if(etimer_pending() && etimer_next_expiration_time() <= current_clock) { + etimer_request_poll(); + /* printf("%d,%d\n", clock_time(),etimer_next_expiration_time ()); */ + } + + if(--second_countdown == 0) { + current_seconds++; + second_countdown = CLOCK_SECOND; + } +} + + +void +clock_init() +{ + systick_set_clocksource(STK_CTRL_CLKSOURCE_AHB_DIV8); + + /*72mhz / 8 / 1000 */ + systick_set_reload(MCK / 8 / CLOCK_SECOND); + + systick_interrupt_enable(); + systick_counter_enable(); +} + +clock_time_t +clock_time(void) +{ + return current_clock; +} + +unsigned long +clock_seconds(void) +{ + return current_seconds; +} + +/* TODO: This code needs to be evaluated for the stm32f107 and + * implemented + */ +#if 0 +/* The inner loop takes 4 cycles. The outer 5+SPIN_COUNT*4. */ + +#define SPIN_TIME 2 /* us */ +#define SPIN_COUNT (((MCK*SPIN_TIME/1000000)-5)/4) + +#ifndef __MAKING_DEPS__ + +void +clock_delay(unsigned int t) +{ +#ifdef __THUMBEL__ + asm + volatile + ("1: mov r1,%2\n2:\tsub r1,#1\n\tbne 2b\n\tsub %0,#1\n\tbne 1b\n":"=l" + (t):"0"(t), "l"(SPIN_COUNT)); +#else +#error Must be compiled in thumb mode +#endif +} +#endif +#endif /* __MAKING_DEPS__ */ diff --git a/cpu/arm/stm32f1x_cl/mtarch.h b/cpu/arm/stm32f1x_cl/mtarch.h new file mode 100644 index 000000000..a61c7be97 --- /dev/null +++ b/cpu/arm/stm32f1x_cl/mtarch.h @@ -0,0 +1,13 @@ +/* + * Implementation of multithreading in ARM Cortex-M3. To be done. + */ + + +#ifndef __MTARCH_H__ +#define __MTARCH_H__ + +struct mtarch_thread { + short mt_thread; +}; + +#endif /* __MTARCH_H__ */ \ No newline at end of file diff --git a/cpu/arm/stm32f1x_cl/rtimer-arch.c b/cpu/arm/stm32f1x_cl/rtimer-arch.c new file mode 100644 index 000000000..351ca3afc --- /dev/null +++ b/cpu/arm/stm32f1x_cl/rtimer-arch.c @@ -0,0 +1,16 @@ + +void +rtimer_arch_init(void) +{ +} + +void +rtimer_arch_set(rtimer_clock_t t) +{ +} + +rtimer_clock_t +rtimer_arch_now(void) +{ + return 0; +} diff --git a/cpu/arm/stm32f1x_cl/rtimer-arch.h b/cpu/arm/stm32f1x_cl/rtimer-arch.h new file mode 100644 index 000000000..58a9e22c5 --- /dev/null +++ b/cpu/arm/stm32f1x_cl/rtimer-arch.h @@ -0,0 +1,22 @@ +/** + * \file + * Header file for the STM32F107-specific rtimer code + * \author + * Jeff Ciesielski + * Adapted from stm32f103 example + */ + +#ifndef __RTIMER_ARCH_H__ +#define __RTIMER_ARCH_H__ + +#include "sys/rtimer.h" + +#define RTIMER_ARCH_SECOND (MCK/1024) + +void rtimer_arch_init(void); + +void rtimer_arch_set(rtimer_clock_t t); + +rtimer_clock_t rtimer_arch_now(void); + +#endif /* __RTIMER_ARCH_H__ */ diff --git a/cpu/arm/stm32f1x_cl/uip-log.c b/cpu/arm/stm32f1x_cl/uip-log.c new file mode 100644 index 000000000..52dbd1d29 --- /dev/null +++ b/cpu/arm/stm32f1x_cl/uip-log.c @@ -0,0 +1,7 @@ +#include + +void +uip_log(char *msg) +{ + printf("uip: %s\n", msg); +} diff --git a/cpu/arm/stm32f1x_cl/util.c b/cpu/arm/stm32f1x_cl/util.c new file mode 100644 index 000000000..5c4d49c25 --- /dev/null +++ b/cpu/arm/stm32f1x_cl/util.c @@ -0,0 +1,12 @@ +#include + +uint32_t retval; + +uint32_t +get_msp(void) +{ + asm("ldr r1, =retval"); + asm("mrs r0, msp"); + asm("str r0, [r1]"); + return retval; +} diff --git a/cpu/arm/stm32f1x_cl/util.h b/cpu/arm/stm32f1x_cl/util.h new file mode 100644 index 000000000..114f7c15f --- /dev/null +++ b/cpu/arm/stm32f1x_cl/util.h @@ -0,0 +1,5 @@ +#ifndef _UTIL_H_ +#define _UTIL_H_ +#include +uint32_t get_msp(void); +#endif /*_UTIL_H_*/ From 222f93f023d40a884b91c120420102b63aa5fa14 Mon Sep 17 00:00:00 2001 From: Jeff Ciesielski Date: Wed, 6 Feb 2013 15:43:25 -0800 Subject: [PATCH 07/34] stm32f107_basic: Add support for a simple stm32f107 platform This platform is a basic waveshare stm32f107 devkit which contains a USART, USB device port, some buttons and some LEDs. Unfortunately not enough to bring up networking, but enough to test building and a simple contiki shell --- platform/stm32f107_basic/Makefile | 26 +++ .../stm32f107_basic/Makefile.stm32f107_basic | 20 ++ platform/stm32f107_basic/contiki-conf.h | 46 ++++ platform/stm32f107_basic/contiki-main.c | 44 ++++ platform/stm32f107_basic/dev/debug-uart.c | 95 +++++++++ platform/stm32f107_basic/dev/debug-uart.h | 14 ++ platform/stm32f107_basic/gqueue.c | 38 ++++ platform/stm32f107_basic/gqueue.h | 73 +++++++ platform/stm32f107_basic/newlib.c | 199 ++++++++++++++++++ platform/stm32f107_basic/structgen_opts.gen.h | 2 + 10 files changed, 557 insertions(+) create mode 100644 platform/stm32f107_basic/Makefile create mode 100644 platform/stm32f107_basic/Makefile.stm32f107_basic create mode 100644 platform/stm32f107_basic/contiki-conf.h create mode 100644 platform/stm32f107_basic/contiki-main.c create mode 100644 platform/stm32f107_basic/dev/debug-uart.c create mode 100644 platform/stm32f107_basic/dev/debug-uart.h create mode 100644 platform/stm32f107_basic/gqueue.c create mode 100644 platform/stm32f107_basic/gqueue.h create mode 100644 platform/stm32f107_basic/newlib.c create mode 100644 platform/stm32f107_basic/structgen_opts.gen.h diff --git a/platform/stm32f107_basic/Makefile b/platform/stm32f107_basic/Makefile new file mode 100644 index 000000000..625c667f3 --- /dev/null +++ b/platform/stm32f107_basic/Makefile @@ -0,0 +1,26 @@ +TARGET=stm32f107_basic + +all: stm32f107_basic + + +CONTIKI=../.. + +CONTIKI_TARGET_MAIN=contiki-main.c + +PROJECT_SOURCEFILES = parity.c + + +randgen: randgen.c + gcc -DNDEBUG -I $(CONTIKI)/cpu/arm/stm32f107/ -I . -I $(CONTIKI)/core randgen.c -o randgen + +randcheck: randcheck.c + gcc -DNDEBUG -I $(CONTIKI)/cpu/arm/stm32f107/ -I . -I $(CONTIKI)/core randcheck.c -o randcheck + +clean: stm32test_clean + +.PHONY: stm32test_clean + +stm32test_clean: + +include $(CONTIKI)/Makefile.include + diff --git a/platform/stm32f107_basic/Makefile.stm32f107_basic b/platform/stm32f107_basic/Makefile.stm32f107_basic new file mode 100644 index 000000000..f7a9cfd8b --- /dev/null +++ b/platform/stm32f107_basic/Makefile.stm32f107_basic @@ -0,0 +1,20 @@ +CONTIKI_TARGET_DIRS = . dev +# Master clock frequency +MCK=72000000 +CFLAGS+=-DAUTOSTART_ENABLE + +ifndef CONTIKI_TARGET_MAIN +CONTIKI_TARGET_MAIN = contiki-main.c +endif + +CONTIKI_TARGET_SOURCEFILES += $(CONTIKI_TARGET_MAIN) +CONTIKI_TARGET_SOURCEFILES += debug-uart.c newlib.c gqueue.c + +include $(CONTIKI)/cpu/arm/stm32f1x_cl/Makefile.stm32f1x_cl + +contiki-$(TARGET).a: ${addprefix $(OBJECTDIR)/,symbols.o} + +ifndef BASE_IP +BASE_IP := 172.16.1.1 +endif + diff --git a/platform/stm32f107_basic/contiki-conf.h b/platform/stm32f107_basic/contiki-conf.h new file mode 100644 index 000000000..883ebf4fe --- /dev/null +++ b/platform/stm32f107_basic/contiki-conf.h @@ -0,0 +1,46 @@ +#ifndef __CONTIKI_CONF_H__CDBB4VIH3I__ +#define __CONTIKI_CONF_H__CDBB4VIH3I__ + +#include + +#define CCIF +#define CLIF + +#define WITH_UIP 1 +#define WITH_ASCII 1 + +#define CLOCK_CONF_SECOND 1000 + +/* These names are deprecated, use C99 names. */ +typedef uint8_t u8_t; +typedef uint16_t u16_t; +typedef uint32_t u32_t; +typedef int8_t s8_t; +typedef int16_t s16_t; +typedef int32_t s32_t; + +typedef unsigned int clock_time_t; +typedef unsigned int uip_stats_t; + +#ifndef BV +#define BV(x) (1<<(x)) +#endif + +/* uIP configuration */ +#define UIP_CONF_LLH_LEN 0 +#define UIP_CONF_BROADCAST 1 +#define UIP_CONF_LOGGING 1 +#define UIP_CONF_BUFFER_SIZE 116 + +#define UIP_CONF_TCP_FORWARD 1 + +/* Prefix for relocation sections in ELF files */ +#define REL_SECT_PREFIX ".rel" + +#define CC_BYTE_ALIGNED __attribute__ ((packed, aligned(1))) + +#define USB_EP1_SIZE 64 +#define USB_EP2_SIZE 64 + +#define RAND_MAX 0x7fff +#endif /* __CONTIKI_CONF_H__CDBB4VIH3I__ */ diff --git a/platform/stm32f107_basic/contiki-main.c b/platform/stm32f107_basic/contiki-main.c new file mode 100644 index 000000000..6508f42a5 --- /dev/null +++ b/platform/stm32f107_basic/contiki-main.c @@ -0,0 +1,44 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +#include +unsigned int idle_count = 0; + +static void +configure_mcu_clocks(void) +{ + rcc_clock_setup_in_hse_25mhz_out_72mhz(); + + /* GPIO Clocks */ + rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPAEN); + rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_AFIOEN); + + /* USART 1 */ + rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_USART1EN); +} + +int +main() +{ + configure_mcu_clocks(); + uart_init(115200); + printf("Initialising\n"); + + clock_init(); + process_init(); + process_start(&etimer_process, NULL); + autostart_start(autostart_processes); + printf("Processes running\n"); + while(1) { + do { + } while(process_run() > 0); + idle_count++; + } + return 0; +} diff --git a/platform/stm32f107_basic/dev/debug-uart.c b/platform/stm32f107_basic/dev/debug-uart.c new file mode 100644 index 000000000..381241f29 --- /dev/null +++ b/platform/stm32f107_basic/dev/debug-uart.c @@ -0,0 +1,95 @@ +#include +#include +#include + +#include +#include +#include +#include + +DECLARE_QUEUE(char, uart_tx_buf, 256); +DECLARE_QUEUE(char, uart_rx_buf, 256); + +static void uart_init_gpio(void) +{ + gpio_set_mode(GPIOA, + GPIO_MODE_OUTPUT_50_MHZ, + GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, + GPIO9); + + gpio_set_mode(GPIOA, + GPIO_MODE_INPUT, + GPIO_CNF_INPUT_FLOAT, + GPIO10); + + /* USART lines should idle high */ + gpio_set(GPIOA, GPIO9); + gpio_set(GPIOA, GPIO10); +} + +void uart_init(int baud) +{ + uart_init_gpio(); + + nvic_enable_irq(NVIC_USART1_IRQ); + nvic_set_priority(NVIC_USART1_IRQ, 2); + + usart_set_baudrate(USART1, baud); + usart_set_databits(USART1, 8); + usart_set_parity(USART1, USART_PARITY_NONE); + usart_set_flow_control(USART1, USART_FLOWCONTROL_NONE); + usart_set_stopbits(USART1, USART_CR2_STOPBITS_1); + usart_set_mode(USART1, USART_MODE_TX_RX); + usart_enable_rx_interrupt(USART1); + usart_enable(USART1); + + /* This ensures stdio doesn't use its own buffers */ + setvbuf(stdin, NULL, _IONBF, 0); + setvbuf(stdout, NULL, _IONBF, 0); +} + +int uart_putchar(char c) +{ + if( c == '\n') + uart_putchar('\r'); + if(!queue_is_full(&uart_tx_buf)) { + queue_enqueue(&uart_tx_buf, &c); + } else { + return -ENOMEM; + } + + usart_enable_tx_interrupt(USART1); + + return 0; +} + +int uart_getchar(char *c) +{ + if(!queue_is_empty(&uart_rx_buf)) { + queue_dequeue(&uart_rx_buf, c); + return 0; + } else { + return -ENODATA; + } +} + +void usart1_isr(void) +{ + char c; + if (usart_get_flag(USART1, USART_SR_TXE)) { + if (!queue_is_empty(&uart_tx_buf)) { + queue_dequeue(&uart_tx_buf, &c); + usart_send(USART1, (uint16_t)c); + } else { + usart_disable_tx_interrupt(USART1); + } + } + + + if (usart_get_flag(USART1, USART_SR_RXNE)) { + if (!queue_is_full(&uart_rx_buf)) { + c = usart_recv(USART1); + queue_enqueue(&uart_rx_buf, &c); + } + } +} diff --git a/platform/stm32f107_basic/dev/debug-uart.h b/platform/stm32f107_basic/dev/debug-uart.h new file mode 100644 index 000000000..1808880a9 --- /dev/null +++ b/platform/stm32f107_basic/dev/debug-uart.h @@ -0,0 +1,14 @@ +/** + * USART driver for STM32F1xx w/ libopencm3 peripherl lib + * (c) 2012 Blessed Contraptions + * Jeff Ciesielski + */ + +#ifndef _UART_H_ +#define _UART_H_ + +int uart_putchar(char c); +int uart_getchar(char *c); +void uart_init(int baud); + +#endif diff --git a/platform/stm32f107_basic/gqueue.c b/platform/stm32f107_basic/gqueue.c new file mode 100644 index 000000000..1f7e29a47 --- /dev/null +++ b/platform/stm32f107_basic/gqueue.c @@ -0,0 +1,38 @@ +#include + +void +queue_enqueue(volatile void *q, const void *elt) +{ + volatile struct generic_queue *gq = q; + + if(gq->len == 0) { + gq->head = gq->memory; + gq->tail = gq->memory; + } else { + if(gq->tail == gq->memory + (gq->max_capacity - 1) * gq->item_size) + /* FIXME: Should something be done about + * queue length? Substact one, maybe?*/ + gq->tail = gq->memory; + else + gq->tail = (uint8_t *) gq->tail + gq->item_size; + } + + memcpy((void *)gq->tail, elt, gq->item_size); + gq->len++; +} + +void +queue_dequeue(volatile void *q, void *elt) +{ + volatile struct generic_queue *gq = q; + + memcpy(elt, (void *)gq->head, gq->item_size); + + if(gq->head == gq->memory + (gq->max_capacity - 1) * gq->item_size) + /* FIXME: Should something be done about + * queue length? Substact one, maybe?*/ + gq->head = gq->memory; + else if(gq->len > 1) + gq->head = (uint8_t *) gq->head + gq->item_size; + gq->len--; +} diff --git a/platform/stm32f107_basic/gqueue.h b/platform/stm32f107_basic/gqueue.h new file mode 100644 index 000000000..8efef6c14 --- /dev/null +++ b/platform/stm32f107_basic/gqueue.h @@ -0,0 +1,73 @@ +/************************************************************************************/ +/* The MIT License (MIT) */ +/* */ +/* Copyright (c) 2012 Jeff Ciesielski */ +/* Andrey Smirnov */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining a copy of */ +/* this software and associated documentation files (the "Software"), to deal in */ +/* the Software without restriction, including without limitation the rights to */ +/* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies */ +/* of the Software, and to permit persons to whom the Software is furnished to do */ +/* so, subject to the following conditions: */ +/* */ +/* -The above copyright notice and this permission notice shall be included in all */ +/* copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR */ +/* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS */ +/* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR */ +/* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER */ +/* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN */ +/* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/************************************************************************************/ + +#ifndef _QUEUE_H_ +#define _QUEUE_H_ + +#include +#include +#include + +struct generic_queue { + volatile void *head; + volatile void *tail; + size_t item_size; + size_t len; + size_t max_capacity; + volatile uint8_t memory[0]; +}; + +#define DECLARE_QUEUE(element_type, name, max_size) \ + struct name { \ + struct generic_queue gq; \ + element_type __elements[max_size]; \ + } name = { \ + .gq={ \ + .len = 0, \ + .item_size = sizeof(element_type), \ + .max_capacity = max_size, \ + }, \ + } + + +static inline bool queue_is_empty(volatile void *q) +{ + volatile struct generic_queue *gq = q; + + return (gq->len == 0); +} +static inline int queue_get_len(volatile void *q) +{ + volatile struct generic_queue *gq = q; + return gq->len; +} +static inline bool queue_is_full(volatile void *q) +{ + volatile struct generic_queue *gq = q; + return (gq->len >= gq->max_capacity); +} +void queue_enqueue(volatile void *q, const void *elt) __attribute__((nonnull)); +void queue_dequeue(volatile void *q, void *elt) __attribute__((nonnull)); + +#endif diff --git a/platform/stm32f107_basic/newlib.c b/platform/stm32f107_basic/newlib.c new file mode 100644 index 000000000..0edbd64c1 --- /dev/null +++ b/platform/stm32f107_basic/newlib.c @@ -0,0 +1,199 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define STDOUT_USART USART1 +#define STDERR_USART USART1 +#define STDIN_USART USART1 +#undef errno +extern int errno; + +char *__env[1] = { 0 }; +char **environ = __env; + +int _write(int file, char *ptr, int len); + +void +_exit(int status) +{ + while(1); +} + +int +_close(int file) +{ + return -1; +} + +int +_execve(char *name, char **argv, char **env) +{ + errno = ENOMEM; + return -1; +} + +int +_fork() +{ + errno = EAGAIN; + return -1; +} + +int +_fstat(int file, struct stat *st) +{ + st->st_mode = S_IFCHR; + return 0; +} + +int +_getpid() +{ + return 1; +} + +int +_gettimeofday(struct timeval *tv, struct timezone *tz) +{ + tv->tv_sec = rtc_get_counter_val(); + tv->tv_usec = 0; + return 0; +} + +int +_isatty(int file) +{ + switch (file) { + case STDOUT_FILENO: + case STDERR_FILENO: + case STDIN_FILENO: + return 1; + default: + //errno = ENOTTY; + errno = EBADF; + return 0; + } +} + +int +_kill(int pid, int sig) +{ + errno = EINVAL; + return (-1); +} + +int +_link(char *old, char *new) +{ + errno = EMLINK; + return -1; +} + +int +_lseek(int file, int ptr, int dir) +{ + return 0; +} + +caddr_t +_sbrk(int incr) +{ + extern char _ebss; + static char *heap_end; + char *prev_heap_end; + + if(heap_end == 0) { + heap_end = &_ebss; + } + prev_heap_end = heap_end; + + char *stack = (char *)get_msp(); + + if(heap_end + incr > stack) { + _write(STDERR_FILENO, "Heap and stack collision", 25); + errno = ENOMEM; + return (caddr_t) - 1; + //abort (); + } + + heap_end += incr; + return (caddr_t) prev_heap_end; + +} + +int +_read(int file, char *ptr, int len) +{ + char c = 0x00; + + switch (file) { + case STDIN_FILENO: + uart_getchar(&c); + *ptr++ = c; + return 1; + break; + default: + errno = EBADF; + return -1; + } +} + +int +_stat(const char *filepath, struct stat *st) +{ + st->st_mode = S_IFCHR; + return 0; +} + +clock_t +_times(struct tms * buf) +{ + return -1; +} + +int +_unlink(char *name) +{ + errno = ENOENT; + return -1; +} + +int +_wait(int *status) +{ + errno = ECHILD; + return -1; +} + +int +_write(int file, char *ptr, int len) +{ + int n; + char c; + + switch (file) { + case STDOUT_FILENO: /*stdout */ + for(n = 0; n < len; n++) { + c = (uint8_t) * ptr++; + uart_putchar(c); + } + break; + case STDERR_FILENO: /* stderr */ + for(n = 0; n < len; n++) { + c = (uint8_t) * ptr++; + uart_putchar(c); + } + break; + default: + errno = EBADF; + return -1; + } + return len; +} diff --git a/platform/stm32f107_basic/structgen_opts.gen.h b/platform/stm32f107_basic/structgen_opts.gen.h new file mode 100644 index 000000000..f0a459008 --- /dev/null +++ b/platform/stm32f107_basic/structgen_opts.gen.h @@ -0,0 +1,2 @@ +#pragma target_endian little +#pragma max_target_int_bytes 8 From 1895d3a959982e6a9b1bcae177a4135e4244f71a Mon Sep 17 00:00:00 2001 From: Oliver Schmidt Date: Sat, 9 Feb 2013 22:22:31 +0100 Subject: [PATCH 08/34] Fixed severe bug in PSOCK_READTO (?) Either I found and fixed a severe bug in PSOCK_READTO() or I misunderstood something completely. To me PSOCK_READTO() is supposed to return if either the supplied character was read or if the user supplied buffer is exhausted - sor far so good. However if the latter occurs up to now PSOCK_READTO() was continuing to process characters already read from the network (aka present in the uIP buffer) in order to check if the supplied character was found there and adjust the return value accordingly. But this means that the character processed this way were lost forever for the caller as the next call to PSOCK_READTO() would continue to read past the characters processed this way. Therefore I removed that character processing altogether. So now if the user supplied buffer is exhausted before the supplied character is found the next call to PSOCK_READTO() starts exactly where previous call left off. --- core/net/psock.c | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/core/net/psock.c b/core/net/psock.c index fa488f724..47893a5de 100644 --- a/core/net/psock.c +++ b/core/net/psock.c @@ -124,16 +124,6 @@ buf_bufto(CC_REGISTER_ARG struct psock_buf *buf, uint8_t endmarker, return BUF_NOT_FOUND; } - while(*datalen > 0) { - c = **dataptr; - --*datalen; - ++*dataptr; - - if(c == endmarker) { - return BUF_FOUND | BUF_FULL; - } - } - return BUF_FULL; } /*---------------------------------------------------------------------------*/ @@ -274,9 +264,9 @@ PT_THREAD(psock_readto(CC_REGISTER_ARG struct psock *psock, unsigned char c)) psock->readptr = (uint8_t *)uip_appdata; psock->readlen = uip_datalen(); } - } while((buf_bufto(&psock->buf, c, - &psock->readptr, - &psock->readlen) & BUF_FOUND) == 0); + } while(buf_bufto(&psock->buf, c, + &psock->readptr, + &psock->readlen) == BUF_NOT_FOUND); if(psock_datalen(psock) == 0) { psock->state = STATE_NONE; From 6b97fa838235b5f19a1baff9a94409a189dacc2d Mon Sep 17 00:00:00 2001 From: Jeff Ciesielski Date: Sat, 9 Feb 2013 23:54:14 -0800 Subject: [PATCH 09/34] stm32f1x_cl: Fix stm32f107 linker script This is a critical fix which adds inclusion of the entire data/bss section to the output ELF file. Without it, the BSS section will not be zeroed out --- cpu/arm/stm32f1x_cl/STM32F107VCT.ld | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cpu/arm/stm32f1x_cl/STM32F107VCT.ld b/cpu/arm/stm32f1x_cl/STM32F107VCT.ld index 5d60e4979..40c396780 100644 --- a/cpu/arm/stm32f1x_cl/STM32F107VCT.ld +++ b/cpu/arm/stm32f1x_cl/STM32F107VCT.ld @@ -28,7 +28,7 @@ SECTIONS .data : { _data = . ; - *(.data) + *(.data*) . = ALIGN(4); _edata = . ; PROVIDE (_edata = .); @@ -41,7 +41,7 @@ SECTIONS { __bss_start = . ; __bss_start__ = . ; - *(.bss) + *(.bss*) *(COMMON) . = ALIGN(4); _ebss = . ; From 1eda821a756a8fc1ca256d14bbe259b38113b258 Mon Sep 17 00:00:00 2001 From: Oliver Schmidt Date: Sat, 9 Feb 2013 22:22:31 +0100 Subject: [PATCH 10/34] Fixed severe bug in PSOCK_READTO (?) Either I found and fixed a severe bug in PSOCK_READTO() or I misunderstood something completely. To me PSOCK_READTO() is supposed to return if either the supplied character was read or if the user supplied buffer is exhausted - sor far so good. However if the latter occurs up to now PSOCK_READTO() was continuing to process characters already read from the network (aka present in the uIP buffer) in order to check if the supplied character was found there and adjust the return value accordingly. But this means that the character processed this way were lost forever for the caller as the next call to PSOCK_READTO() would continue to read past the characters processed this way. Therefore I removed that character processing altogether. So now if the user supplied buffer is exhausted before the supplied character is found the next call to PSOCK_READTO() starts exactly where previous call left off. --- core/net/psock.c | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/core/net/psock.c b/core/net/psock.c index fa488f724..47893a5de 100644 --- a/core/net/psock.c +++ b/core/net/psock.c @@ -124,16 +124,6 @@ buf_bufto(CC_REGISTER_ARG struct psock_buf *buf, uint8_t endmarker, return BUF_NOT_FOUND; } - while(*datalen > 0) { - c = **dataptr; - --*datalen; - ++*dataptr; - - if(c == endmarker) { - return BUF_FOUND | BUF_FULL; - } - } - return BUF_FULL; } /*---------------------------------------------------------------------------*/ @@ -274,9 +264,9 @@ PT_THREAD(psock_readto(CC_REGISTER_ARG struct psock *psock, unsigned char c)) psock->readptr = (uint8_t *)uip_appdata; psock->readlen = uip_datalen(); } - } while((buf_bufto(&psock->buf, c, - &psock->readptr, - &psock->readlen) & BUF_FOUND) == 0); + } while(buf_bufto(&psock->buf, c, + &psock->readptr, + &psock->readlen) == BUF_NOT_FOUND); if(psock_datalen(psock) == 0) { psock->state = STATE_NONE; From ea4fac679fd65a66e05095c0e656e0c73abf093b Mon Sep 17 00:00:00 2001 From: Oliver Schmidt Date: Mon, 11 Feb 2013 00:24:51 +0100 Subject: [PATCH 11/34] Allow user to read the result of wget. Several retro targets clear the screen after program termination so allow user to read the result. --- examples/wget/wget.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/examples/wget/wget.c b/examples/wget/wget.c index 00bc6439b..5cac9b885 100644 --- a/examples/wget/wget.c +++ b/examples/wget/wget.c @@ -142,6 +142,8 @@ app_quit(void) if(file != -1) { cfs_close(file); } + puts("Press any key to continue..."); + getchar(); process_exit(&wget_process); LOADER_UNLOAD(); } From c385dd13937facdd618addac72f306eb9b1ac27a Mon Sep 17 00:00:00 2001 From: Oliver Schmidt Date: Mon, 11 Feb 2013 00:28:31 +0100 Subject: [PATCH 12/34] Be consistent with tab chars in Makefiles. --- Makefile.include | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Makefile.include b/Makefile.include index fa3c9d65a..b0e294b5e 100644 --- a/Makefile.include +++ b/Makefile.include @@ -1,7 +1,7 @@ # -*- makefile -*- ifndef CONTIKI - ${error CONTIKI not defined! You must specify where CONTIKI resides} + ${error CONTIKI not defined! You must specify where Contiki resides} endif ifeq ($(TARGET),) @@ -105,8 +105,8 @@ PROJECT_OBJECTFILES = ${addprefix $(OBJECTDIR)/,${call oname, $(PROJECT_SOURCEFI ifdef APPS APPDIRS += ${wildcard ${addprefix $(CONTIKI)/apps/, $(APPS)} \ - ${addprefix $(CONTIKI)/platform/$(TARGET)/apps/, $(APPS)} \ - $(APPS)} + ${addprefix $(CONTIKI)/platform/$(TARGET)/apps/, $(APPS)} \ + $(APPS)} APPINCLUDES = ${foreach APP, $(APPS), ${wildcard ${foreach DIR, $(APPDIRS), $(DIR)/Makefile.$(APP)}}} -include $(APPINCLUDES) APP_SOURCES = ${foreach APP, $(APPS), $($(APP)_src)} @@ -163,7 +163,7 @@ endif ifneq ($(MAKECMDGOALS),clean) -include ${addprefix $(OBJECTDIR)/,$(CONTIKI_SOURCEFILES:.c=.d) \ - $(PROJECT_SOURCEFILES:.c=.d)} + $(PROJECT_SOURCEFILES:.c=.d)} endif ### See http://make.paulandlesley.org/autodep.html#advanced @@ -178,8 +178,8 @@ endef clean: rm -f *~ *core core *.srec \ *.lst *.map \ - *.cprg *.bin *.data contiki*.a *.firmware core-labels.S *.ihex *.ini \ - *.ce *.co $(CLEAN) + *.cprg *.bin *.data contiki*.a *.firmware core-labels.S *.ihex *.ini \ + *.ce *.co $(CLEAN) -rm -rf $(OBJECTDIR) ifndef CUSTOM_RULE_C_TO_CE From 98060c1eab2abf45d11a6bb2195c59aacdb259b9 Mon Sep 17 00:00:00 2001 From: Oliver Schmidt Date: Thu, 14 Feb 2013 15:42:43 +0100 Subject: [PATCH 13/34] Moved from last cc65 release (2.13.3) to recent cc65 snapshot (2.13.9). Relevant cc65 changes... General: - The compiler generates "extended" dependency info (like gcc) so there's no need for postprocessing whatsoever :-) - The linker is very pernickety regarding the ordering of cmdline options so a custom linker rule is necessary :-( Apple2: - The various memory usage scenarios aren't specified anymore via separate linker configs but via defines overriding default values in the builtin linker config. Atari: - The builtin linker config allows to override the start addr so there no more need for a custom linker config. - The C library comes with POSIX directory access. So there's no more need for for a custom coding. CBM: - The C library comes with POSIX directory access. So there's no more need for for a custom coding. --- cpu/6502/Makefile.6502 | 32 ++---- platform/apple2enh/Makefile.apple2enh | 12 +- platform/atari/Makefile.atari | 21 ++-- platform/atari/lib/posixdirent.S | 159 -------------------------- platform/c128/Makefile.c128 | 5 +- platform/c128/cfs/cfs-cbm-dir.c | 69 ----------- platform/c128/lib/pfs.S | 4 +- platform/c64/Makefile.c64 | 5 +- platform/c64/cfs/cfs-cbm-dir.c | 69 ----------- platform/c64/lib/pfs.S | 4 +- 10 files changed, 35 insertions(+), 345 deletions(-) delete mode 100644 platform/atari/lib/posixdirent.S delete mode 100644 platform/c128/cfs/cfs-cbm-dir.c delete mode 100644 platform/c64/cfs/cfs-cbm-dir.c diff --git a/cpu/6502/Makefile.6502 b/cpu/6502/Makefile.6502 index f67f77692..4d5c53a35 100644 --- a/cpu/6502/Makefile.6502 +++ b/cpu/6502/Makefile.6502 @@ -39,7 +39,7 @@ endif all: cs8900a.eth lan91c96.eth -CONTIKI_TARGET_DIRS = . lib sys cfs +CONTIKI_TARGET_DIRS = . lib sys CONTIKI_CPU_DIRS = . lib sys ctk net CONTIKI_TARGET_SOURCEFILES += contiki-main.c @@ -47,10 +47,8 @@ CONTIKI_CPU_SOURCEFILES += log.c error.c unload.c config.c ctk-mouse.c \ clock.c mtarch.c mtarch-asm.S lc-asm.S \ uip_arch.c ethernet-drv.c ethernet.c -CONTIKI_SOURCEFILES += $(CTK) ctk-conio.c petsciiconv.c \ +CONTIKI_SOURCEFILES += $(CTK) ctk-conio.c petsciiconv.c cfs-posix-dir.c \ $(CONTIKI_TARGET_SOURCEFILES) $(CONTIKI_CPU_SOURCEFILES) - -TARGET_LIBFILES = $(TARGET).lib ifdef ETHERNET CONTIKI_SOURCEFILES += $(ETHERNET)-eth.S @@ -60,7 +58,7 @@ endif ### Compiler definitions AS = ca65 -CC = cc65 +CC = cl65 LD = ld65 AR = ar65 @@ -69,35 +67,29 @@ AR = ar65 ASFLAGS = -t $(TARGET) CFLAGS += -t $(TARGET) -Or -LDFLAGS = -D __STACKSIZE__=0x200 -u _main -m contiki-$(TARGET).map +LDFLAGS = $(STARTADDR_FLAG) -t $(TARGET) -m contiki-$(TARGET).map -D __STACKSIZE__=0x200 AROPTS = a ### Compilation rules .SUFFIXES: -CMD.EXE := $(shell echo) - CUSTOM_RULE_C_TO_OBJECTDIR_O = 1 $(OBJECTDIR)/%.o: %.c - $(CC) $(CFLAGS) --create-dep $< -o $(@:.o=.s) - @$(AS) $(ASFLAGS) $(@:.o=.s) -o $@ - @sed -e "s!.s:!.o:!" -e "s!\t! !" < $(@:.o=.u) > $(@:.o=.d) - @rm -f $(@:.o=.s) $(@:.o=.u) -ifndef CMD.EXE - @$(FINALIZE_DEPENDENCY) -endif + $(CC) -c -o $@ $(CFLAGS) --create-dep $(@:.o=.d) $< CUSTOM_RULE_C_TO_CO = 1 %.co: %.c - $(CC) $(CFLAGS) -DAUTOSTART_ENABLE $< -o $(@:.co=.s) - @$(AS) $(ASFLAGS) $(@:.co=.s) -o $@ - @rm -f $(@:.co=.s) + $(CC) -c -o $@ $(CFLAGS) -DAUTOSTART_ENABLE --create-dep $(@:.o=.d) $< + +CUSTOM_RULE_LINK = 1 +%.$(TARGET): %.co contiki-$(TARGET).a + $(LD) -o $@ $(LDFLAGS) -u _main $^ $(TARGET).lib %.eth: $(OBJECTDIR)/%.o - $(LD) -t module -m $@.map $< -o $@ + $(LD) -o $@ -t module -m $@.map $< ifdef ETHERNET $(ETHERNET)-eth.S: $(ETHERNET).eth - co65 --code-label _$(ETHERNET) -o $@ $< + co65 -o $@ --code-label _$(ETHERNET) $< endif diff --git a/platform/apple2enh/Makefile.apple2enh b/platform/apple2enh/Makefile.apple2enh index 6e318b904..5add9a8e9 100644 --- a/platform/apple2enh/Makefile.apple2enh +++ b/platform/apple2enh/Makefile.apple2enh @@ -33,22 +33,22 @@ # $Id: Makefile.apple2enh,v 1.19 2010/10/23 08:17:45 oliverschmidt Exp $ # -CONTIKI_SOURCEFILES += cfs-posix-dir.c CONTIKI_TARGET_SOURCEFILES += pfs.S CONTIKI_CPU = $(CONTIKI)/cpu/6502 include $(CONTIKI_CPU)/Makefile.6502 +LDFLAGS += -D __HIMEM__=0xBF00 + ifeq ($(findstring WITH_REBOOT,$(DEFINES)),WITH_REBOOT) - HIGHCODE_SOURCEFILES = process.c etimer.c uip_arp.c - LDFLAGS += -C apple2enh-reboot.cfg + LC_SOURCEFILES = process.c etimer.c uip_arp.c + LDFLAGS += -D __LCADDR__=0xD000 -D __LCSIZE__=0x1000 else - HIGHCODE_SOURCEFILES = process.c etimer.c ethernet.c - LDFLAGS += -C apple2enh-loader.cfg + LC_SOURCEFILES = process.c etimer.c ethernet.c endif # Set a target-specific variable value -${addprefix $(OBJECTDIR)/,${call oname, $(HIGHCODE_SOURCEFILES)}}: CFLAGS += --code-name HIGHCODE +${addprefix $(OBJECTDIR)/,${call oname, $(LC_SOURCEFILES)}}: CFLAGS += --code-name LC ifeq ($(MAKECMDGOALS),disk) ifndef AC diff --git a/platform/atari/Makefile.atari b/platform/atari/Makefile.atari index c8377655a..b795367b4 100644 --- a/platform/atari/Makefile.atari +++ b/platform/atari/Makefile.atari @@ -35,13 +35,10 @@ ETHERNET = cs8900a -CONTIKI_SOURCEFILES += cfs-posix-dir.c -CONTIKI_TARGET_SOURCEFILES += posixdirent.S - CONTIKI_CPU = $(CONTIKI)/cpu/6502 include $(CONTIKI_CPU)/Makefile.6502 -LDFLAGS += -C $(CONTIKI)/platform/$(TARGET)/$(TARGET).cfg -S 0x2000 +STARTADDR_FLAG = -S 0x2000 ifeq ($(MAKECMDGOALS),disk) ifndef DIR2ATR @@ -51,15 +48,15 @@ endif disk: all mkdir atr - cp $(CONTIKI)/tools/$(TARGET)/dos.sys atr/dos.sys - cp $(CONTIKI)/tools/$(TARGET)/dup.sys atr/dup.sys - cp $(CONTIKI_PROJECT).$(TARGET) atr/autorun.sys - cp $(CONTIKI)/tools/$(TARGET)/sample.cfg atr/contiki.cfg + cp $(CONTIKI)/tools/$(TARGET)/dos25/dos.sys atr/dos.sys + cp $(CONTIKI)/tools/$(TARGET)/dos25/dup.sys atr/dup.sys + cp $(CONTIKI_PROJECT).$(TARGET) atr/autorun.sys + cp $(CONTIKI)/tools/$(TARGET)/sample.cfg atr/contiki.cfg ifeq ($(HTTPD-CFS),1) - cp httpd-cfs/index.htm atr/index.htm - cp httpd-cfs/backgrnd.gif atr/backgrnd.gif - cp httpd-cfs/contiki.gif atr/contiki.gif - cp httpd-cfs/notfound.htm atr/notfound.htm + cp httpd-cfs/index.htm atr/index.htm + cp httpd-cfs/backgrnd.gif atr/backgrnd.gif + cp httpd-cfs/contiki.gif atr/contiki.gif + cp httpd-cfs/notfound.htm atr/notfound.htm endif $(DIR2ATR) -b Dos25 1040 contiki.atr atr rm -r atr diff --git a/platform/atari/lib/posixdirent.S b/platform/atari/lib/posixdirent.S deleted file mode 100644 index f33a7f04f..000000000 --- a/platform/atari/lib/posixdirent.S +++ /dev/null @@ -1,159 +0,0 @@ -; Native: Shawn Jefferson, December 2005 -; POSIX: Stefan Haubenthal, April 2008 - - .include "atari.inc" - .export _opendir, _readdir, _closedir - .import findfreeiocb, clriocb - .import __oserror, return0, __do_oserror - .importzp ptr1, tmp1 -.ifdef DEFAULT_DEVICE - .import __defdev -.endif - - -.proc _opendir - sta ptr1 - stx ptr1+1 - jsr findfreeiocb - beq @iocbok - bne cioerr -@iocbok: stx diriocb - jsr clriocb - ldx diriocb - ldy #0 ; '.' -> "D:*.*" - lda (ptr1),y - cmp #'.' - bne @use_parm - -; "." was given as parameter, use default device/dir - -.ifdef DEFAULT_DEVICE - ; construct a "Dn:*.*" like string from the default drive - lda __defdev+1 - sta dddefdev+1 ; copy drive number (overwrite 2nd 'D') - lda #dddefdev - sta ICBAH,x - bne @cont -.else - lda #defdev - sta ICBAH,x - bne @cont -.endif - -@use_parm: lda ptr1 - sta ICBAL,x - lda ptr1+1 - sta ICBAH,x - -@cont: lda #OPEN - sta ICCOM,x - lda #OPNIN|DIRECT - sta ICAX1,x - jsr CIOV - bmi cioerr - lda #0 - sta __oserror - tax - lda diriocb - rts -.endproc - -cioerr: sty __oserror - jmp return0 - -.proc _readdir - tax - lda #GETREC - sta ICCOM,x - lda #entry - sta ICBAH,x - sta ptr1+1 - lda #DSCTSZ - sta ICBLL,x - lda #0 - sta ICBLH,x - jsr CIOV - bmi cioerr - ldy #0 ; FREE SECTORS - lda (ptr1),y - cmp #'0' - bcs cioerr - dey -@next: iny ; remove trailing spaces - iny - iny - lda (ptr1),y - dey - dey - sta (ptr1),y - cpy #9 - bcs @break - cmp #' ' - bne @next - -@break: lda #'.' ; extension dot - sta (ptr1),y - iny ; copy extension - sty tmp1 - ldy #10 - lda (ptr1),y - cmp #' ' - bne @hasext - -; no extension present: remove the trailing dot and be done - ldy tmp1 - dey - bne @done - -@hasext: jsr copychar - ldy #11 - jsr copychar - ldy #12 - jsr copychar - -@done: lda #0 ; end of string - sta (ptr1),y - lda ptr1 - ldx ptr1+1 - rts - - -copychar: lda (ptr1),y ; src=y dest=tmp1 - ldy tmp1 - cmp #' ' - beq @break - sta (ptr1),y - iny - sty tmp1 -@break: rts -.endproc - -.proc _closedir - tax - lda #CLOSE - sta ICCOM,x - jsr CIOV - bmi @cioerr - ldx #0 - stx __oserror ; clear system specific error code - txa - rts -@cioerr: jmp __do_oserror -.endproc - - .data -.ifdef DEFAULT_DEVICE -dddefdev: .byte "D" -.endif -defdev: .asciiz "D:*.*" - - .bss -diriocb: .res 1 -entry: .res DSCTSZ diff --git a/platform/c128/Makefile.c128 b/platform/c128/Makefile.c128 index 70273bba4..f2cf2b6ef 100644 --- a/platform/c128/Makefile.c128 +++ b/platform/c128/Makefile.c128 @@ -33,13 +33,12 @@ # $Id: Makefile.c128,v 1.15 2010/10/23 13:48:06 oliverschmidt Exp $ # -CONTIKI_TARGET_SOURCEFILES += cfs-cbm-dir.c pfs.S pfs_write.S +CONTIKI_TARGET_SOURCEFILES += pfs.S pfs_write.S CONTIKI_CPU = $(CONTIKI)/cpu/6502 include $(CONTIKI_CPU)/Makefile.6502 -CFLAGS += -DWITH_PETSCII -LDFLAGS += -t $(TARGET) +CFLAGS += -DWITH_PETSCII ifeq ($(MAKECMDGOALS),disk) ifndef C1541 diff --git a/platform/c128/cfs/cfs-cbm-dir.c b/platform/c128/cfs/cfs-cbm-dir.c deleted file mode 100644 index 7ea8079d4..000000000 --- a/platform/c128/cfs/cfs-cbm-dir.c +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright (c) 2010, 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. Neither the name of the Institute 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 INSTITUTE 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 INSTITUTE 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. - * - * This file is part of the Contiki operating system. - * - * Author: Oliver Schmidt - * - */ - -#include -#include - -#include "contiki.h" - -#include "cfs/cfs.h" - -/*---------------------------------------------------------------------------*/ -int -cfs_opendir(struct cfs_dir *p, const char *n) -{ - return cbm_opendir(12, _curunit); -} -/*---------------------------------------------------------------------------*/ -int -cfs_readdir(struct cfs_dir *p, struct cfs_dirent *e) -{ - struct cbm_dirent dirent; - - do { - if(cbm_readdir(12, &dirent)) { - return -1; - } - } while(dirent.type == CBM_T_HEADER); - strcpy(e->name, dirent.name); - e->size = dirent.size; - return 0; -} -/*---------------------------------------------------------------------------*/ -void -cfs_closedir(struct cfs_dir *p) -{ - cbm_closedir(12); -} -/*---------------------------------------------------------------------------*/ diff --git a/platform/c128/lib/pfs.S b/platform/c128/lib/pfs.S index 07cf0cb69..e82a1cb7c 100644 --- a/platform/c128/lib/pfs.S +++ b/platform/c128/lib/pfs.S @@ -36,7 +36,7 @@ .constructor init_pfs .destructor done_pfs .importzp ptr1, ptr2, ptr3, sp - .import __curunit, __filetype, popax, addysp, subysp + .import curunit, __filetype, popax, addysp, subysp .export pfs_rwcommon, pfs_rwsetflags, pfs_rwcommonend .if F_IDE64 .export ide64_rwprepare, ide64_rwfinish @@ -178,7 +178,7 @@ next: inc ptr2 ;next file number stx ptr2+1 nextsa: inc ptr2+1 ;next channel retr: lda ptr2 ;file number - ldx __curunit + ldx curunit ldy ptr2+1 ;secondary address jsr SETLFS jsr OPEN ;open diff --git a/platform/c64/Makefile.c64 b/platform/c64/Makefile.c64 index a7011892d..72dfc9144 100644 --- a/platform/c64/Makefile.c64 +++ b/platform/c64/Makefile.c64 @@ -33,13 +33,12 @@ # $Id: Makefile.c64,v 1.17 2010/10/23 13:48:06 oliverschmidt Exp $ # -CONTIKI_TARGET_SOURCEFILES += cfs-cbm-dir.c pfs.S pfs_write.S +CONTIKI_TARGET_SOURCEFILES += pfs.S pfs_write.S CONTIKI_CPU = $(CONTIKI)/cpu/6502 include $(CONTIKI_CPU)/Makefile.6502 -CFLAGS += -DWITH_PETSCII -LDFLAGS += -t $(TARGET) +CFLAGS += -DWITH_PETSCII ifeq ($(MAKECMDGOALS),disk) ifndef C1541 diff --git a/platform/c64/cfs/cfs-cbm-dir.c b/platform/c64/cfs/cfs-cbm-dir.c deleted file mode 100644 index 7ea8079d4..000000000 --- a/platform/c64/cfs/cfs-cbm-dir.c +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright (c) 2010, 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. Neither the name of the Institute 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 INSTITUTE 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 INSTITUTE 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. - * - * This file is part of the Contiki operating system. - * - * Author: Oliver Schmidt - * - */ - -#include -#include - -#include "contiki.h" - -#include "cfs/cfs.h" - -/*---------------------------------------------------------------------------*/ -int -cfs_opendir(struct cfs_dir *p, const char *n) -{ - return cbm_opendir(12, _curunit); -} -/*---------------------------------------------------------------------------*/ -int -cfs_readdir(struct cfs_dir *p, struct cfs_dirent *e) -{ - struct cbm_dirent dirent; - - do { - if(cbm_readdir(12, &dirent)) { - return -1; - } - } while(dirent.type == CBM_T_HEADER); - strcpy(e->name, dirent.name); - e->size = dirent.size; - return 0; -} -/*---------------------------------------------------------------------------*/ -void -cfs_closedir(struct cfs_dir *p) -{ - cbm_closedir(12); -} -/*---------------------------------------------------------------------------*/ diff --git a/platform/c64/lib/pfs.S b/platform/c64/lib/pfs.S index 0ebe24a07..89eb03ae0 100644 --- a/platform/c64/lib/pfs.S +++ b/platform/c64/lib/pfs.S @@ -36,7 +36,7 @@ .constructor init_pfs .destructor done_pfs .importzp ptr1, ptr2, ptr3, sp - .import __curunit, __filetype, popax, addysp, subysp + .import curunit, __filetype, popax, addysp, subysp .export pfs_rwcommon, pfs_rwsetflags, pfs_rwcommonend .if F_IDE64 .export ide64_rwprepare, ide64_rwfinish @@ -178,7 +178,7 @@ next: inc ptr2 ;next file number stx ptr2+1 nextsa: inc ptr2+1 ;next channel retr: lda ptr2 ;file number - ldx __curunit + ldx curunit ldy ptr2+1 ;secondary address jsr SETLFS jsr OPEN ;open From 107b79c0193c604b8c47ef1593493ed999b7172d Mon Sep 17 00:00:00 2001 From: Oliver Schmidt Date: Thu, 14 Feb 2013 15:45:33 +0100 Subject: [PATCH 14/34] The recent cc65 snapshot yields somewhat small programs so we can move back to the MTU size used before. --- examples/webbrowser/Makefile.atari.defines | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/webbrowser/Makefile.atari.defines b/examples/webbrowser/Makefile.atari.defines index 7713f7f1e..54380b38d 100644 --- a/examples/webbrowser/Makefile.atari.defines +++ b/examples/webbrowser/Makefile.atari.defines @@ -1 +1 @@ -DEFINES = WITH_CLIENT,WITH_DNS,WITH_GUI,MTU_SIZE=900 +DEFINES = WITH_CLIENT,WITH_DNS,WITH_GUI,MTU_SIZE=1000 From 9040f83fd42d45c7a591bdc45a17676ff2deb888 Mon Sep 17 00:00:00 2001 From: Oliver Schmidt Date: Thu, 14 Feb 2013 15:51:09 +0100 Subject: [PATCH 15/34] Reduced program size. On the C128 the custom PFS code doesn't add functionality (as it does with IDE64 support on the C64) but is "only" smaller than the POSIX file i/o code in the C library. But the POSIX directory access code in the C library relies on the POSIX file i/o code anyway so there no point in additionally adding the PFS code to the FTP program. --- examples/ftp/Makefile.c128.defines | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/ftp/Makefile.c128.defines b/examples/ftp/Makefile.c128.defines index 688d85113..7f438d1d1 100644 --- a/examples/ftp/Makefile.c128.defines +++ b/examples/ftp/Makefile.c128.defines @@ -1 +1 @@ -DEFINES = WITH_CLIENT,WITH_DNS,WITH_GUI,WITH_PFS +DEFINES = WITH_CLIENT,WITH_DNS,WITH_GUI From c22838b9d3deea7d8f8001a41a06af6b2ecc8a7a Mon Sep 17 00:00:00 2001 From: Ivan Delamer Date: Fri, 15 Feb 2013 16:08:37 -0700 Subject: [PATCH 16/34] Enable Timer1 on Raven so that interrupts coming from radio, which are connected to input capture, fire again. --- cpu/avr/radio/rf230bb/hal.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cpu/avr/radio/rf230bb/hal.h b/cpu/avr/radio/rf230bb/hal.h index 4b4753471..443a44190 100644 --- a/cpu/avr/radio/rf230bb/hal.h +++ b/cpu/avr/radio/rf230bb/hal.h @@ -293,7 +293,7 @@ #else #define RADIO_VECT TIMER1_CAPT_vect // Raven and Jackdaw -#define HAL_ENABLE_RADIO_INTERRUPT( ) ( TIMSK1 |= ( 1 << ICIE1 ) ) +#define HAL_ENABLE_RADIO_INTERRUPT( ) { TCCR1B = ( 1 << ICES1 ) | ( 1 << CS10 ); TIFR1 |= (1 << ICF1); TIMSK1 |= ( 1 << ICIE1 ) ; } #define HAL_DISABLE_RADIO_INTERRUPT( ) ( TIMSK1 &= ~( 1 << ICIE1 ) ) #endif From 61b90c0126bdce67624713119c13bff86c4a4477 Mon Sep 17 00:00:00 2001 From: Oliver Schmidt Date: Sat, 16 Feb 2013 22:57:50 +0100 Subject: [PATCH 17/34] We actually need PROJECT_OBJECTFILES and PROJECT_LIBRARIES for retro builds too. --- cpu/6502/Makefile.6502 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cpu/6502/Makefile.6502 b/cpu/6502/Makefile.6502 index 4d5c53a35..fc185c2a5 100644 --- a/cpu/6502/Makefile.6502 +++ b/cpu/6502/Makefile.6502 @@ -83,7 +83,7 @@ CUSTOM_RULE_C_TO_CO = 1 $(CC) -c -o $@ $(CFLAGS) -DAUTOSTART_ENABLE --create-dep $(@:.o=.d) $< CUSTOM_RULE_LINK = 1 -%.$(TARGET): %.co contiki-$(TARGET).a +%.$(TARGET): %.co $(PROJECT_OBJECTFILES) $(PROJECT_LIBRARIES) contiki-$(TARGET).a $(LD) -o $@ $(LDFLAGS) -u _main $^ $(TARGET).lib %.eth: $(OBJECTDIR)/%.o From d4433a749855643db7e3823fd6313220ce4d49b2 Mon Sep 17 00:00:00 2001 From: Oliver Schmidt Date: Sat, 16 Feb 2013 23:04:55 +0100 Subject: [PATCH 18/34] Replaced 10.1.1.1/8 with 192.168.0.0/24. --- tools/apple2enh/sample.cfg | Bin 29 -> 29 bytes tools/atari/sample.cfg | Bin 29 -> 29 bytes tools/c128/sample.cfg | Bin 29 -> 29 bytes tools/c64/sample.cfg | Bin 29 -> 29 bytes 4 files changed, 0 insertions(+), 0 deletions(-) diff --git a/tools/apple2enh/sample.cfg b/tools/apple2enh/sample.cfg index 50f8ef4a29a4aec01e4b003346c3c74d6f91538a..43ca5486ffd6f65513847c19df0f6d44a9c225d1 100644 GIT binary patch literal 29 icmX@Gf+7F^|NjgJRxmJv@P-4)#TJ$Z28nv9B^dzKb_|XH literal 29 icmd;LWMur$z`(%8$e04c8xABFTUZ(xBWB>q8v Date: Sun, 17 Feb 2013 00:30:55 +0100 Subject: [PATCH 19/34] loader.system is now official part of the cc65 Apple II support. --- platform/apple2enh/Makefile.apple2enh | 2 +- tools/6502/Makefile | 42 +++++++++++++------------- tools/apple2enh/loader.system | Bin 397 -> 0 bytes 3 files changed, 22 insertions(+), 22 deletions(-) delete mode 100644 tools/apple2enh/loader.system diff --git a/platform/apple2enh/Makefile.apple2enh b/platform/apple2enh/Makefile.apple2enh index 5add9a8e9..48e063107 100644 --- a/platform/apple2enh/Makefile.apple2enh +++ b/platform/apple2enh/Makefile.apple2enh @@ -58,7 +58,7 @@ endif disk: all cp $(CONTIKI)/tools/$(TARGET)/prodos.dsk contiki.dsk - java -jar $(AC) -p contiki.dsk contiki.system sys 0 < $(CONTIKI)/tools/$(TARGET)/loader.system + java -jar $(AC) -p contiki.dsk contiki.system sys 0 < $(CC65_HOME)/targetutil/loader.system java -jar $(AC) -cc65 contiki.dsk contiki bin < $(CONTIKI_PROJECT).$(TARGET) java -jar $(AC) -p contiki.dsk contiki.cfg bin 0 < $(CONTIKI)/tools/$(TARGET)/sample.cfg java -jar $(AC) -p contiki.dsk cs8900a.eth rel 0 < cs8900a.eth diff --git a/tools/6502/Makefile b/tools/6502/Makefile index ff1c59e2b..47cf44f5b 100644 --- a/tools/6502/Makefile +++ b/tools/6502/Makefile @@ -76,11 +76,11 @@ contiki-apple2-1.dsk: apple2enh-makes cp ../apple2enh/prodos.dsk $@ java -jar $(AC) -p $@ contiki.cfg bin 0 < ../apple2enh/default.cfg java -jar $(AC) -p $@ menu.system sys 0 < ../apple2enh/menu.system - java -jar $(AC) -p $@ ipconfig.system sys 0 < ../apple2enh/loader.system + java -jar $(AC) -p $@ ipconfig.system sys 0 < $(CC65_HOME)/targetutil/loader.system java -jar $(AC) -cc65 $@ ipconfig bin 0 < ../../cpu/6502/ipconfig/ipconfig.apple2enh - java -jar $(AC) -p $@ webbrows.system sys 0 < ../apple2enh/loader.system + java -jar $(AC) -p $@ webbrows.system sys 0 < $(CC65_HOME)/targetutil/loader.system java -jar $(AC) -cc65 $@ webbrows bin < ../../examples/webbrowser/webbrowser.apple2enh - java -jar $(AC) -p $@ wget.system sys 0 < ../apple2enh/loader.system + java -jar $(AC) -p $@ wget.system sys 0 < $(CC65_HOME)/targetutil/loader.system java -jar $(AC) -cc65 $@ wget bin < ../../examples/wget/wget.apple2enh java -jar $(AC) -p $@ cs8900a.eth rel 0 < ../../cpu/6502/ipconfig/cs8900a.eth java -jar $(AC) -p $@ lan91c96.eth rel 0 < ../../cpu/6502/ipconfig/lan91c96.eth @@ -90,11 +90,11 @@ contiki-apple2-2.dsk: apple2enh-makes cp ../apple2enh/prodos.dsk $@ java -jar $(AC) -p $@ contiki.cfg bin 0 < ../apple2enh/default.cfg java -jar $(AC) -p $@ menu.system sys 0 < ../apple2enh/menu.system - java -jar $(AC) -p $@ ipconfig.system sys 0 < ../apple2enh/loader.system + java -jar $(AC) -p $@ ipconfig.system sys 0 < $(CC65_HOME)/targetutil/loader.system java -jar $(AC) -cc65 $@ ipconfig bin 0 < ../../cpu/6502/ipconfig/ipconfig.apple2enh - java -jar $(AC) -p $@ irc.system sys 0 < ../apple2enh/loader.system + java -jar $(AC) -p $@ irc.system sys 0 < $(CC65_HOME)/targetutil/loader.system java -jar $(AC) -cc65 $@ irc bin < ../../examples/irc/irc-client.apple2enh - java -jar $(AC) -p $@ breadbox.system sys 0 < ../apple2enh/loader.system + java -jar $(AC) -p $@ breadbox.system sys 0 < $(CC65_HOME)/targetutil/loader.system java -jar $(AC) -cc65 $@ breadbox bin < ../../../contikiprojects/vandenbrande.com/twitter/platform/apple2enh/breadbox64.apple2enh java -jar $(AC) -p $@ cs8900a.eth rel 0 < ../../cpu/6502/ipconfig/cs8900a.eth java -jar $(AC) -p $@ lan91c96.eth rel 0 < ../../cpu/6502/ipconfig/lan91c96.eth @@ -104,11 +104,11 @@ contiki-apple2-3.dsk: apple2enh-makes cp ../apple2enh/prodos.dsk $@ java -jar $(AC) -p $@ contiki.cfg bin 0 < ../apple2enh/default.cfg java -jar $(AC) -p $@ menu.system sys 0 < ../apple2enh/menu.system - java -jar $(AC) -p $@ ipconfig.system sys 0 < ../apple2enh/loader.system + java -jar $(AC) -p $@ ipconfig.system sys 0 < $(CC65_HOME)/targetutil/loader.system java -jar $(AC) -cc65 $@ ipconfig bin 0 < ../../cpu/6502/ipconfig/ipconfig.apple2enh - java -jar $(AC) -p $@ email.system sys 0 < ../apple2enh/loader.system + java -jar $(AC) -p $@ email.system sys 0 < $(CC65_HOME)/targetutil/loader.system java -jar $(AC) -cc65 $@ email bin < ../../examples/email/email-client.apple2enh - java -jar $(AC) -p $@ ftp.system sys 0 < ../apple2enh/loader.system + java -jar $(AC) -p $@ ftp.system sys 0 < $(CC65_HOME)/targetutil/loader.system java -jar $(AC) -cc65 $@ ftp bin < ../../examples/ftp/ftp-client.apple2enh java -jar $(AC) -p $@ cs8900a.eth rel 0 < ../../cpu/6502/ipconfig/cs8900a.eth java -jar $(AC) -p $@ lan91c96.eth rel 0 < ../../cpu/6502/ipconfig/lan91c96.eth @@ -118,11 +118,11 @@ contiki-apple2-4.dsk: apple2enh-makes cp ../apple2enh/prodos.dsk $@ java -jar $(AC) -p $@ contiki.cfg bin 0 < ../apple2enh/default.cfg java -jar $(AC) -p $@ menu.system sys 0 < ../apple2enh/menu.system - java -jar $(AC) -p $@ ipconfig.system sys 0 < ../apple2enh/loader.system + java -jar $(AC) -p $@ ipconfig.system sys 0 < $(CC65_HOME)/targetutil/loader.system java -jar $(AC) -cc65 $@ ipconfig bin 0 < ../../cpu/6502/ipconfig/ipconfig.apple2enh - java -jar $(AC) -p $@ webserv.system sys 0 < ../apple2enh/loader.system + java -jar $(AC) -p $@ webserv.system sys 0 < $(CC65_HOME)/targetutil/loader.system java -jar $(AC) -cc65 $@ webserv bin < ../../examples/webserver/webserver-example.apple2enh - java -jar $(AC) -p $@ telnetd.system sys 0 < ../apple2enh/loader.system + java -jar $(AC) -p $@ telnetd.system sys 0 < $(CC65_HOME)/targetutil/loader.system java -jar $(AC) -cc65 $@ telnetd bin < ../../examples/telnet-server/telnet-server.apple2enh java -jar $(AC) -p $@ cs8900a.eth rel 0 < ../../cpu/6502/ipconfig/cs8900a.eth java -jar $(AC) -p $@ lan91c96.eth rel 0 < ../../cpu/6502/ipconfig/lan91c96.eth @@ -136,23 +136,23 @@ contiki-apple2.2mg: apple2enh-makes cp ../apple2enh/prodos.2mg $@ java -jar $(AC) -p $@ contiki.cfg bin 0 < ../apple2enh/default.cfg java -jar $(AC) -p $@ menu.system sys 0 < ../apple2enh/menu.system - java -jar $(AC) -p $@ ipconfig.system sys 0 < ../apple2enh/loader.system + java -jar $(AC) -p $@ ipconfig.system sys 0 < $(CC65_HOME)/targetutil/loader.system java -jar $(AC) -cc65 $@ ipconfig bin 0 < ../../cpu/6502/ipconfig/ipconfig.apple2enh - java -jar $(AC) -p $@ webbrows.system sys 0 < ../apple2enh/loader.system + java -jar $(AC) -p $@ webbrows.system sys 0 < $(CC65_HOME)/targetutil/loader.system java -jar $(AC) -cc65 $@ webbrows bin < ../../examples/webbrowser/webbrowser.apple2enh - java -jar $(AC) -p $@ wget.system sys 0 < ../apple2enh/loader.system + java -jar $(AC) -p $@ wget.system sys 0 < $(CC65_HOME)/targetutil/loader.system java -jar $(AC) -cc65 $@ wget bin < ../../examples/wget/wget.apple2enh - java -jar $(AC) -p $@ irc.system sys 0 < ../apple2enh/loader.system + java -jar $(AC) -p $@ irc.system sys 0 < $(CC65_HOME)/targetutil/loader.system java -jar $(AC) -cc65 $@ irc bin < ../../examples/irc/irc-client.apple2enh - java -jar $(AC) -p $@ breadbox.system sys 0 < ../apple2enh/loader.system + java -jar $(AC) -p $@ breadbox.system sys 0 < $(CC65_HOME)/targetutil/loader.system java -jar $(AC) -cc65 $@ breadbox bin < ../../../contikiprojects/vandenbrande.com/twitter/platform/apple2enh/breadbox64.apple2enh - java -jar $(AC) -p $@ email.system sys 0 < ../apple2enh/loader.system + java -jar $(AC) -p $@ email.system sys 0 < $(CC65_HOME)/targetutil/loader.system java -jar $(AC) -cc65 $@ email bin < ../../examples/email/email-client.apple2enh - java -jar $(AC) -p $@ ftp.system sys 0 < ../apple2enh/loader.system + java -jar $(AC) -p $@ ftp.system sys 0 < $(CC65_HOME)/targetutil/loader.system java -jar $(AC) -cc65 $@ ftp bin < ../../examples/ftp/ftp-client.apple2enh - java -jar $(AC) -p $@ webserv.system sys 0 < ../apple2enh/loader.system + java -jar $(AC) -p $@ webserv.system sys 0 < $(CC65_HOME)/targetutil/loader.system java -jar $(AC) -cc65 $@ webserv bin < ../../examples/webserver/webserver-example.apple2enh - java -jar $(AC) -p $@ telnetd.system sys 0 < ../apple2enh/loader.system + java -jar $(AC) -p $@ telnetd.system sys 0 < $(CC65_HOME)/targetutil/loader.system java -jar $(AC) -cc65 $@ telnetd bin < ../../examples/telnet-server/telnet-server.apple2enh java -jar $(AC) -p $@ cs8900a.eth rel 0 < ../../cpu/6502/ipconfig/cs8900a.eth java -jar $(AC) -p $@ lan91c96.eth rel 0 < ../../cpu/6502/ipconfig/lan91c96.eth diff --git a/tools/apple2enh/loader.system b/tools/apple2enh/loader.system deleted file mode 100644 index a463c2a6269c114cf6afc238816fbc0f824436e4..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 397 zcmeZqS9tf%k%3aM=>M!mYxmw)nERjU)P?VB8<;F!viCMHty;-2w~=Wbo5D(l56pYn z73MN9o)Y-J^86wN1tsQ{jfT3oE)m{+Obom#2D008~dauNUl From 9970a3631ae9da0a57f12ea9658a84198d479fe4 Mon Sep 17 00:00:00 2001 From: Oliver Schmidt Date: Sun, 17 Feb 2013 01:03:51 +0100 Subject: [PATCH 20/34] The new POSIX directory access in the CBM C library comes with a d_blocks field too. --- core/cfs/cfs-posix-dir.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/cfs/cfs-posix-dir.c b/core/cfs/cfs-posix-dir.c index 3423167d9..4512f5786 100644 --- a/core/cfs/cfs-posix-dir.c +++ b/core/cfs/cfs-posix-dir.c @@ -66,11 +66,11 @@ cfs_readdir(struct cfs_dir *p, struct cfs_dirent *e) return -1; } strncpy(e->name, res->d_name, sizeof(e->name)); -#if defined(__APPLE2__) || defined(__APPLE2ENH__) +#if defined(__APPLE2__) || defined(__APPLE2ENH__) || defined(__CBM__) e->size = res->d_blocks; -#else /* __APPLE2__ || __APPLE2ENH__ */ +#else /* __APPLE2__ || __APPLE2ENH__ || __CBM__ */ e->size = 0; -#endif /* __APPLE2__ || __APPLE2ENH__ */ +#endif /* __APPLE2__ || __APPLE2ENH__ || __CBM__ */ return 0; } /*---------------------------------------------------------------------------*/ From 15fb63ba9a2f504041c5c1ee2e13c9fac029c81c Mon Sep 17 00:00:00 2001 From: Oliver Schmidt Date: Mon, 18 Feb 2013 23:08:05 +0100 Subject: [PATCH 21/34] Harmonized ststus texts and and added status on wrong MIME type. --- apps/webbrowser/www.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/apps/webbrowser/www.c b/apps/webbrowser/www.c index 279f882bc..1b8b27ea3 100644 --- a/apps/webbrowser/www.c +++ b/apps/webbrowser/www.c @@ -325,7 +325,7 @@ open_url(void) /* The hostname we present in the hostname table, so we send out the initial GET request. */ if(webclient_get(host, 80, file) == 0) { - show_statustext("Out of memory error."); + show_statustext("Out of memory error"); } else { show_statustext("Connecting..."); } @@ -534,7 +534,7 @@ PROCESS_THREAD(www_process, ev, data) resolv_lookup((char *)data) != NULL) { open_url(); } else { - show_statustext("Host not found."); + show_statustext("Host not found"); } #endif /* UIP_UDP */ } else if(ev == ctk_signal_window_close || @@ -602,7 +602,7 @@ webclient_timedout(void) void webclient_closed(void) { - show_statustext("Stopped."); + show_statustext("Stopped"); petsciiconv_topetscii(webpageptr - x, x); CTK_WIDGET_FOCUS(&mainwindow, &downbutton); redraw_window(); @@ -644,6 +644,7 @@ webclient_datahandler(char *data, uint16_t len) htmlparser_parse(data, len); redraw_window(); } else { + show_statustext("Cannot display web page"); uip_abort(); #if WWW_CONF_WITH_WGET ctk_dialog_open(&wgetdialog); @@ -656,7 +657,7 @@ webclient_datahandler(char *data, uint16_t len) if(data == NULL) { loading = 0; - show_statustext("Done."); + show_statustext("Done"); petsciiconv_topetscii(webpageptr - x, x); CTK_WIDGET_FOCUS(&mainwindow, &urlentry); redraw_window(); From 4938877dd9fc87c16b04248000cf1d6bb70b3446 Mon Sep 17 00:00:00 2001 From: Oliver Schmidt Date: Tue, 19 Feb 2013 00:25:36 +0100 Subject: [PATCH 22/34] Lifted restrictions on accepted MIME type. The "normal" web is moving forward quickly reducing the interoperability of the Contiki web browser to nearly zero. The Mobile Web fits the capabilities of the Contiki web browser much better. Modern smartphones don't need the Mobile Web anymore but there are large areas in world with rather low end mobile phones and limited mobile bandwidth where the Mobile Web will be necessary for quite some time. From that perspective it is reasonable to increase the Contiki web browser's interoperability with the Mobie Web - namely WAP 2.0 aka XHTML MP. XHTML MP is delivered as MIME types 'application/vnd.wap.xhtml+xml' or 'application/xhtml+xml'. Therefore we (try to) parse the document if the MIME type contains the substring 'html' (which is true 'text/html' too). --- apps/webbrowser/http-strings | 3 +-- apps/webbrowser/http-strings.c | 7 ++----- apps/webbrowser/http-strings.h | 1 - apps/webbrowser/www.c | 2 +- apps/webserver/http-strings | 3 +-- apps/webserver/http-strings.c | 7 ++----- apps/webserver/http-strings.h | 1 - 7 files changed, 7 insertions(+), 17 deletions(-) diff --git a/apps/webbrowser/http-strings b/apps/webbrowser/http-strings index ea5ebc1e0..2bba32dc8 100644 --- a/apps/webbrowser/http-strings +++ b/apps/webbrowser/http-strings @@ -6,9 +6,8 @@ http_get "GET " http_10 "HTTP/1.0" http_11 "HTTP/1.1" http_content_type "content-type: " -http_texthtml "text/html" http_location "location: " -http_host "host: " +http_host "Host: " http_crnl "\r\n" http_index_html "/index.html" http_404_html "/404.html" diff --git a/apps/webbrowser/http-strings.c b/apps/webbrowser/http-strings.c index 968a71851..3407105c3 100644 --- a/apps/webbrowser/http-strings.c +++ b/apps/webbrowser/http-strings.c @@ -22,15 +22,12 @@ const char http_11[9] = const char http_content_type[15] = /* "content-type: " */ {0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x2d, 0x74, 0x79, 0x70, 0x65, 0x3a, 0x20, }; -const char http_texthtml[10] = -/* "text/html" */ -{0x74, 0x65, 0x78, 0x74, 0x2f, 0x68, 0x74, 0x6d, 0x6c, }; const char http_location[11] = /* "location: " */ {0x6c, 0x6f, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x3a, 0x20, }; const char http_host[7] = -/* "host: " */ -{0x68, 0x6f, 0x73, 0x74, 0x3a, 0x20, }; +/* "Host: " */ +{0x48, 0x6f, 0x73, 0x74, 0x3a, 0x20, }; const char http_crnl[3] = /* "\r\n" */ {0xd, 0xa, }; diff --git a/apps/webbrowser/http-strings.h b/apps/webbrowser/http-strings.h index f197bba2b..5c2cf9396 100644 --- a/apps/webbrowser/http-strings.h +++ b/apps/webbrowser/http-strings.h @@ -6,7 +6,6 @@ extern const char http_get[5]; extern const char http_10[9]; extern const char http_11[9]; extern const char http_content_type[15]; -extern const char http_texthtml[10]; extern const char http_location[11]; extern const char http_host[7]; extern const char http_crnl[3]; diff --git a/apps/webbrowser/www.c b/apps/webbrowser/www.c index 1b8b27ea3..06726e90a 100644 --- a/apps/webbrowser/www.c +++ b/apps/webbrowser/www.c @@ -638,7 +638,7 @@ void webclient_datahandler(char *data, uint16_t len) { if(len > 0) { - if(strcmp(webclient_mimetype(), http_texthtml) == 0) { + if(strstr(webclient_mimetype(), http_html + 1) != 0) { count = (count + 1) & 3; show_statustext(receivingmsgs[count]); htmlparser_parse(data, len); diff --git a/apps/webserver/http-strings b/apps/webserver/http-strings index 579faee74..7a3d51c03 100644 --- a/apps/webserver/http-strings +++ b/apps/webserver/http-strings @@ -6,9 +6,8 @@ http_get "GET " http_10 "HTTP/1.0" http_11 "HTTP/1.1" http_content_type "content-type: " -http_texthtml "text/html" http_location "location: " -http_host "host: " +http_host "Host: " http_crnl "\r\n" http_index_htm "/index.htm" http_index_html "/index.html" diff --git a/apps/webserver/http-strings.c b/apps/webserver/http-strings.c index 4e22787ea..5c02fedef 100644 --- a/apps/webserver/http-strings.c +++ b/apps/webserver/http-strings.c @@ -22,15 +22,12 @@ const char http_11[9] = const char http_content_type[15] = /* "content-type: " */ {0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x2d, 0x74, 0x79, 0x70, 0x65, 0x3a, 0x20, }; -const char http_texthtml[10] = -/* "text/html" */ -{0x74, 0x65, 0x78, 0x74, 0x2f, 0x68, 0x74, 0x6d, 0x6c, }; const char http_location[11] = /* "location: " */ {0x6c, 0x6f, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x3a, 0x20, }; const char http_host[7] = -/* "host: " */ -{0x68, 0x6f, 0x73, 0x74, 0x3a, 0x20, }; +/* "Host: " */ +{0x48, 0x6f, 0x73, 0x74, 0x3a, 0x20, }; const char http_crnl[3] = /* "\r\n" */ {0xd, 0xa, }; diff --git a/apps/webserver/http-strings.h b/apps/webserver/http-strings.h index 35af562d4..01fc8cd9d 100644 --- a/apps/webserver/http-strings.h +++ b/apps/webserver/http-strings.h @@ -6,7 +6,6 @@ extern const char http_get[5]; extern const char http_10[9]; extern const char http_11[9]; extern const char http_content_type[15]; -extern const char http_texthtml[10]; extern const char http_location[11]; extern const char http_host[7]; extern const char http_crnl[3]; From 374c89be0194109edc5a081f5651d15d34838621 Mon Sep 17 00:00:00 2001 From: Oliver Schmidt Date: Tue, 19 Feb 2013 00:43:16 +0100 Subject: [PATCH 23/34] Added newline on . The tag
(in contrast to the tag ) is normally used to denote content placed on a line by its own. So it makes sense to trigger a newline when
is processed. --- apps/webbrowser/html-strings | 1 + apps/webbrowser/html-strings.c | 3 ++ apps/webbrowser/html-strings.h | 1 + apps/webbrowser/htmlparser.c | 51 ++++++++++++++++++---------------- 4 files changed, 32 insertions(+), 24 deletions(-) diff --git a/apps/webbrowser/html-strings b/apps/webbrowser/html-strings index e3c43c93b..5e10d41d4 100644 --- a/apps/webbrowser/html-strings +++ b/apps/webbrowser/html-strings @@ -1,5 +1,6 @@ html_slasha "/a\0" html_slashcenter "/center\0" +html_slashdiv "/div\0" html_slashform "/form\0" html_slashh "/h\0" html_slashscript "/script\0" diff --git a/apps/webbrowser/html-strings.c b/apps/webbrowser/html-strings.c index 6292280e6..cb4b05629 100644 --- a/apps/webbrowser/html-strings.c +++ b/apps/webbrowser/html-strings.c @@ -4,6 +4,9 @@ const char html_slasha[4] = const char html_slashcenter[9] = /* "/center\0" */ {0x2f, 0x63, 0x65, 0x6e, 0x74, 0x65, 0x72, 00, }; +const char html_slashdiv[6] = +/* "/div\0" */ +{0x2f, 0x64, 0x69, 0x76, 00, }; const char html_slashform[7] = /* "/form\0" */ {0x2f, 0x66, 0x6f, 0x72, 0x6d, 00, }; diff --git a/apps/webbrowser/html-strings.h b/apps/webbrowser/html-strings.h index 21c6c129d..b10a78c59 100644 --- a/apps/webbrowser/html-strings.h +++ b/apps/webbrowser/html-strings.h @@ -1,5 +1,6 @@ extern const char html_slasha[4]; extern const char html_slashcenter[9]; +extern const char html_slashdiv[6]; extern const char html_slashform[7]; extern const char html_slashh[4]; extern const char html_slashscript[9]; diff --git a/apps/webbrowser/htmlparser.c b/apps/webbrowser/htmlparser.c index c33640191..20d74deeb 100644 --- a/apps/webbrowser/htmlparser.c +++ b/apps/webbrowser/htmlparser.c @@ -179,53 +179,55 @@ static const char *tags[] = { html_slasha, #define TAG_SLASHCENTER 1 html_slashcenter, -#define TAG_SLASHFORM 2 +#define TAG_SLASHDIV 2 + html_slashdiv, +#define TAG_SLASHFORM 3 html_slashform, -#define TAG_SLASHH 3 +#define TAG_SLASHH 4 html_slashh, -#define TAG_SLASHSCRIPT 4 +#define TAG_SLASHSCRIPT 5 html_slashscript, -#define TAG_SLASHSELECT 5 +#define TAG_SLASHSELECT 6 html_slashselect, -#define TAG_SLASHSTYLE 6 +#define TAG_SLASHSTYLE 7 html_slashstyle, -#define TAG_A 7 +#define TAG_A 8 html_a, -#define TAG_BODY 8 +#define TAG_BODY 9 html_body, -#define TAG_BR 9 +#define TAG_BR 10 html_br, -#define TAG_CENTER 10 +#define TAG_CENTER 11 html_center, -#define TAG_FORM 11 +#define TAG_FORM 12 html_form, -#define TAG_FRAME 12 +#define TAG_FRAME 13 html_frame, -#define TAG_H1 13 +#define TAG_H1 14 html_h1, -#define TAG_H2 14 +#define TAG_H2 15 html_h2, -#define TAG_H3 15 +#define TAG_H3 16 html_h3, -#define TAG_H4 16 +#define TAG_H4 17 html_h4, -#define TAG_IMG 17 +#define TAG_IMG 18 html_img, -#define TAG_INPUT 18 +#define TAG_INPUT 19 html_input, -#define TAG_LI 19 +#define TAG_LI 20 html_li, -#define TAG_P 20 +#define TAG_P 21 html_p, -#define TAG_SCRIPT 21 +#define TAG_SCRIPT 22 html_script, -#define TAG_SELECT 22 +#define TAG_SELECT 23 html_select, -#define TAG_STYLE 23 +#define TAG_STYLE 24 html_style, -#define TAG_TR 24 +#define TAG_TR 25 html_tr, -#define TAG_LAST 25 +#define TAG_LAST 26 last, }; @@ -376,6 +378,7 @@ parse_tag(void) /* FALLTHROUGH */ case TAG_BR: case TAG_TR: + case TAG_SLASHDIV: case TAG_SLASHH: /* parse_char(ISO_nl);*/ dummy = 0; From d5d646528e30f64901b9a0797228f5f30d046add Mon Sep 17 00:00:00 2001 From: Oliver Schmidt Date: Tue, 19 Feb 2013 00:49:01 +0100 Subject: [PATCH 24/34] Added support for self closing tags. XHTML requires self closing tags to be used for empty tags, so we need to recognize them. --- apps/webbrowser/htmlparser.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/webbrowser/htmlparser.c b/apps/webbrowser/htmlparser.c index 20d74deeb..dc0914cb6 100644 --- a/apps/webbrowser/htmlparser.c +++ b/apps/webbrowser/htmlparser.c @@ -327,7 +327,7 @@ find_tag(char *tag) do { tagc = tag[i]; - if(tagc == 0 && + if((tagc == 0 || tagc == ISO_slash) && tags[first][i] == 0) { return first; } From d71ce70c540653d928234e45a121ae9940af6784 Mon Sep 17 00:00:00 2001 From: Oliver Schmidt Date: Tue, 19 Feb 2013 21:40:21 +0100 Subject: [PATCH 25/34] Made sure that HTML form values get initialized properly. --- apps/webbrowser/htmlparser.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/apps/webbrowser/htmlparser.c b/apps/webbrowser/htmlparser.c index dc0914cb6..79e2724c6 100644 --- a/apps/webbrowser/htmlparser.c +++ b/apps/webbrowser/htmlparser.c @@ -241,12 +241,25 @@ iswhitespace(char c) c == ISO_ht); } /*-----------------------------------------------------------------------------------*/ +#if WWW_CONF_FORMS +static void +init_input(void) +{ + s.inputtype = HTMLPARSER_INPUTTYPE_NONE; + s.inputname[0] = s.inputvalue[0] = 0; + s.inputvaluesize = 20; /* De facto default size */ +} +#endif /* WWW_CONF_FORMS */ +/*-----------------------------------------------------------------------------------*/ void htmlparser_init(void) { s.majorstate = s.lastmajorstate = MAJORSTATE_DISCARD; s.minorstate = MINORSTATE_TEXT; s.lastchar = 0; +#if WWW_CONF_FORMS + s.formaction[0] = s.formname[0] = 0; +#endif /* WWW_CONF_FORMS */ } /*-----------------------------------------------------------------------------------*/ static char CC_FASTCALL @@ -460,7 +473,7 @@ parse_tag(void) PRINTF(("Form name '%s'\n", s.tagattrparam)); strncpy(s.formname, s.tagattrparam, WWW_CONF_MAX_FORMNAMELEN - 1); } - s.inputname[0] = s.inputvalue[0] = 0; + init_input(); break; case TAG_SLASHFORM: switch_majorstate(MAJORSTATE_BODY); @@ -486,7 +499,7 @@ parse_tag(void) s.formname, s.formaction); break; } - s.inputtype = HTMLPARSER_INPUTTYPE_NONE; + init_input(); } else { PRINTF(("Input '%s' '%s'\n", s.tagattr, s.tagattrparam)); if(strncmp(s.tagattr, html_type, sizeof(html_type)) == 0) { From 955fbc3c5adbfd3b2c4c5803c6273f27a0c3bb08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Moritz=20=27Morty=27=20Str=C3=BCbe?= Date: Wed, 20 Feb 2013 19:50:29 +0100 Subject: [PATCH 26/34] Add missing brace in sky Makefile --- platform/sky/Makefile.common | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform/sky/Makefile.common b/platform/sky/Makefile.common index 10c9ff8d3..212f95554 100644 --- a/platform/sky/Makefile.common +++ b/platform/sky/Makefile.common @@ -97,7 +97,7 @@ else ifdef MOTEIDS MOTES = $(foreach MOTEID, $(MOTEIDS), $(shell $(MOTELIST) 2>&- | grep $(MOTEID) | \ cut -f 4 -d \ | \ - perl -ne 'print $$1 . " " if(m-(/dev/[\w+\.\-]+)-);') + perl -ne 'print $$1 . " " if(m-(/dev/[\w+\.\-]+)-);')) else MOTES = $(shell $(MOTELIST) 2>&- | grep USB | \ cut -f 4 -d \ | \ From 67a39618eb5920aea3bf67b58a0952c87c2703a6 Mon Sep 17 00:00:00 2001 From: Robert Quattlebaum Date: Thu, 17 May 2012 10:27:31 -0700 Subject: [PATCH 27/34] cpu/avr: Make sure that GCC removes all unused symbols. This magic comes from the `--gc-sections` linker flag, which turns on garbage collection for unused input sections. The compiler flags `-ffunction-sections` and `-fdata-sections` make sure that each function and each static data definition have their own section. The result is that GCC can prune away all unused symbols, reducing the size of the resulting executable. These optimizations may be disabled by setting the Makefile variable `SMALL` to zero. --- cpu/avr/Makefile.avr | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/cpu/avr/Makefile.avr b/cpu/avr/Makefile.avr index 5325cef6d..264408066 100644 --- a/cpu/avr/Makefile.avr +++ b/cpu/avr/Makefile.avr @@ -106,6 +106,15 @@ endif LDFLAGS += -mmcu=$(MCU) -Wl,-Map=contiki-$(TARGET).map \ -Wl,--section-start=.bootloader=$(BOOTLOADER_START) +SMALL ?= 1 + +### These flags help significantly reduce the code size +ifeq ($(SMALL),1) +CFLAGS += -ffunction-sections +CFLAGS += -fdata-sections +LDFLAGS += -Wl,--gc-sections +endif # SMALL + ### Setup directory search path for source files CONTIKI_TARGET_DIRS_CONCAT = ${addprefix $(CONTIKI)/platform/$(TARGET)/, \ From ab8fe95864f6c5c7f61dbbc9fd23fbc436e0a83c Mon Sep 17 00:00:00 2001 From: Mariano Alvira Date: Sat, 2 Mar 2013 08:11:28 -0500 Subject: [PATCH 28/34] Revert "Merge pull request #120 from Jeff-Ciesielski/stm32_cl" This reverts commit 029bc0ee276cdc0d265a0b3312492159bea5e29e, reversing changes made to a7b3e99644b69faa87d5cf98a24571f7d060d7ec. This uses LGPL libopencm3. While the patch doesn't include the code, the resulting binary would force the release of all code as LGPL. --- cpu/arm/stm32f1x_cl/Makefile.stm32f1x_cl | 169 --------------- cpu/arm/stm32f1x_cl/STM32F107VCT.ld | 54 ----- cpu/arm/stm32f1x_cl/clock.c | 78 ------- cpu/arm/stm32f1x_cl/mtarch.h | 13 -- cpu/arm/stm32f1x_cl/rtimer-arch.c | 16 -- cpu/arm/stm32f1x_cl/rtimer-arch.h | 22 -- cpu/arm/stm32f1x_cl/uip-log.c | 7 - cpu/arm/stm32f1x_cl/util.c | 12 -- cpu/arm/stm32f1x_cl/util.h | 5 - platform/stm32f107_basic/Makefile | 26 --- .../stm32f107_basic/Makefile.stm32f107_basic | 20 -- platform/stm32f107_basic/contiki-conf.h | 46 ---- platform/stm32f107_basic/contiki-main.c | 44 ---- platform/stm32f107_basic/dev/debug-uart.c | 95 --------- platform/stm32f107_basic/dev/debug-uart.h | 14 -- platform/stm32f107_basic/gqueue.c | 38 ---- platform/stm32f107_basic/gqueue.h | 73 ------- platform/stm32f107_basic/newlib.c | 199 ------------------ platform/stm32f107_basic/structgen_opts.gen.h | 2 - 19 files changed, 933 deletions(-) delete mode 100644 cpu/arm/stm32f1x_cl/Makefile.stm32f1x_cl delete mode 100644 cpu/arm/stm32f1x_cl/STM32F107VCT.ld delete mode 100644 cpu/arm/stm32f1x_cl/clock.c delete mode 100644 cpu/arm/stm32f1x_cl/mtarch.h delete mode 100644 cpu/arm/stm32f1x_cl/rtimer-arch.c delete mode 100644 cpu/arm/stm32f1x_cl/rtimer-arch.h delete mode 100644 cpu/arm/stm32f1x_cl/uip-log.c delete mode 100644 cpu/arm/stm32f1x_cl/util.c delete mode 100644 cpu/arm/stm32f1x_cl/util.h delete mode 100644 platform/stm32f107_basic/Makefile delete mode 100644 platform/stm32f107_basic/Makefile.stm32f107_basic delete mode 100644 platform/stm32f107_basic/contiki-conf.h delete mode 100644 platform/stm32f107_basic/contiki-main.c delete mode 100644 platform/stm32f107_basic/dev/debug-uart.c delete mode 100644 platform/stm32f107_basic/dev/debug-uart.h delete mode 100644 platform/stm32f107_basic/gqueue.c delete mode 100644 platform/stm32f107_basic/gqueue.h delete mode 100644 platform/stm32f107_basic/newlib.c delete mode 100644 platform/stm32f107_basic/structgen_opts.gen.h diff --git a/cpu/arm/stm32f1x_cl/Makefile.stm32f1x_cl b/cpu/arm/stm32f1x_cl/Makefile.stm32f1x_cl deleted file mode 100644 index c816ea40e..000000000 --- a/cpu/arm/stm32f1x_cl/Makefile.stm32f1x_cl +++ /dev/null @@ -1,169 +0,0 @@ -# Adapted from Makefile.stm32f103 - -# Default to STM32F107VCT7 -ifndef SUBTARGET -$(warning SUBTARGET not defined, defaulting to STM32F107VCT) -SUBTARGET = 7VCT -endif - -### libopencm3 specifics -OPENCM3_BASE= -OPENCM3_FAMILY=STM32F1 -OPENCM3_LIB=opencm3_stm32f1 - -ifndef OPENCM3_BASE -$(error OPENCM3_BASE not defined. Please set definition to root of libopencm3) -endif -### Code common for all ARM CPUs - -CONTIKI_CPU_ARM=$(CONTIKI)/cpu/arm -CONTIKI_CPU_ARM_COMMON=$(CONTIKI_CPU_ARM)/common - -### Define the CPU directory -CONTIKI_CPU=$(CONTIKI_CPU_ARM)/stm32f1x_cl - -### Define the source files we have in the STM32F1x_cl port - -CONTIKI_CPU_DIRS = . - -STM32F1x = clock.c util.c uip-log.c symbols.c - -#Using the opencm3 usb library for now -#include $(CONTIKI_CPU_ARM_COMMON)/usb/Makefile.usb - -#No SD support for now...This is a TODO -#include $(CONTIKI_CPU_ARM_COMMON)/SD-card/Makefile.sdcard - -TARGETLIBS = random.c - -CONTIKI_TARGET_SOURCEFILES += $(STM32F1x) $(TARGETLIBS) - -CONTIKI_SOURCEFILES += $(CONTIKI_TARGET_SOURCEFILES) - -PREFIX = arm-none-eabi - -### Compiler definitions -CC = $(PREFIX)-gcc -LD = $(PREFIX)-ld -AS = $(PREFIX)-as -AR = $(PREFIX)-ar -NM = $(PREFIX)-nm -OBJCOPY = $(PREFIX)-objcopy -STRIP = $(PREFIX)-strip - -XSLTPROC=xsltproc - -PROJECT_OBJECTFILES += ${addprefix $(OBJECTDIR)/,$(CONTIKI_TARGET_MAIN:.c=.o)} - -LINKERSCRIPT = $(CONTIKI_CPU)/STM32F10$(SUBTARGET).ld - -# DFU-UTIL program upload -DFU_UTIL=dfu-util -DFU_UTIL_OFFSET=0x08000000 - -# Use dfu-util by default -PROG=dfuutil - -ARCH_FLAGS= -mcpu=cortex-m3 -mthumb - -#CONTIKI_CFLAGS = -DWITH_UIP -DWITH_ASCII - -CFLAGSNO = -I. -I$(CONTIKI)/core -I$(CONTIKI_CPU) \ - -I$(OPENCM3_BASE)/include \ - -I$(CONTIKI)/platform/$(TARGET) \ - ${addprefix -I,$(APPDIRS)} \ - -DMCK=$(MCK) -DSUBTARGET=$(SUBTARGET) \ - -Wall $(ARCH_FLAGS) -g -DSTM32F1 -MD - -CFLAGS += $(CONTIKI_CFLAGS) $(CFLAGSNO) -Os - -LDFLAGS += -L $(CONTIKI_CPU) -T $(LINKERSCRIPT) \ - -Wl,--start-group -lc -lgcc -Wl,--end-group\ - -nostartfiles -Wl,--gc-sections $(ARCH_FLAGS) - -EXTERN_LIBS += -L $(OPENCM3_BASE)/lib -l$(OPENCM3_LIB) - -CDEPFLAGS = $(CFLAGS) -D __MAKING_DEPS__ - -### Setup directory search path for source files - -CUSTOM_RULE_C_TO_OBJECTDIR_O=yes -CUSTOM_RULE_C_TO_O=yes - -%.o: %.c - $(CC) $(CFLAGS) $< -c - -$(OBJECTDIR)/%.o: %.c - $(CC) $(CFLAGS) -c $< -o $@ - - -CUSTOM_RULE_S_TO_OBJECTDIR_O = yes -%.o: %.S - $(CC) $(CFLAGS) $< -c - -$(OBJECTDIR)/%.o: %.S - $(CC) $(CFLAGS) $< -c -o $@ - - -CUSTOM_RULE_C_TO_CO=yes - -%.co: %.c - $(CC) $(CFLAGS) $< -c -o $@ - -CUSTOM_RULE_C_TO_CE=yes - -%.ce: %.o - $(LD) $(LDFLAGS) --relocatable -T $(CONTIKI_CPU)/merge-rodata.ld $< -o $@ - $(STRIP) -K _init -K _fini --strip-unneeded -g -x $@ - -CUSTOM_RULE_LINK=yes - -%-stripped.o: %.c - $(CC) $(CFLAGS) -c $< -o $@ - $(STRIP) --strip-unneeded -g -x $@ - -%-stripped.o: %.o - $(STRIP) --strip-unneeded -g -x -o $@ $< - -%.o: ${CONTIKI_TARGET}/loader/%.S - $(AS) -o $(notdir $(<:.S=.o)) $< - -%-nosyms.$(TARGET): %.co $(PROJECT_OBJECTFILES) contiki-$(TARGET).a # $(OBJECTDIR)/empty-symbols.o - $(CC) $(LDFLAGS) $(CFLAGS) -nostartfiles -o $@ $(filter-out %.a,$^) $(filter %.a,$^) -lc $(filter %.a,$^) $(EXTERN_LIBS) - - -%.ihex: %.$(TARGET) - $(OBJCOPY) $^ -O ihex $@ - -%.bin: %.$(TARGET) - $(OBJCOPY) -O binary $< $@ - -.PHONY: symbols.c -ifdef CORE -%.$(TARGET): %.co $(PROJECT_OBJECTFILES) contiki-$(TARGET).a $(STARTUP) $(OBJECTDIR)/symbols.o - $(CC) $(LDFLAGS) $(CFLAGS) -nostartfiles -o $@ $(filter-out %.a,$^) $(filter %.a,$^) -lc $(filter %.a,$^) - -symbols.c: $(CORE) - $(NM) $< | awk -f $(CONTIKI_CPU)/builtins.awk -f ../../tools/mknmlist > symbols.c - -else -%.$(TARGET): %-nosyms.$(TARGET) - ln -sf $< $@ -endif - -empty-symbols.c: - cp ${CONTIKI}/tools/empty-symbols.c symbols.c - cp ${CONTIKI}/tools/empty-symbols.h symbols.h - -# Don't use core/loader/elfloader.c, use elfloader-otf.c instead -$(OBJECTDIR)/elfloader.o: - echo -n >$@ - -clean: clean_cpu - -.PHONY: stm32test_clean - -clean_cpu: - -rm -rf $(BUILTSRCDIR) - -.PRECIOUS: %-nosyms.$(TARGET) diff --git a/cpu/arm/stm32f1x_cl/STM32F107VCT.ld b/cpu/arm/stm32f1x_cl/STM32F107VCT.ld deleted file mode 100644 index 40c396780..000000000 --- a/cpu/arm/stm32f1x_cl/STM32F107VCT.ld +++ /dev/null @@ -1,54 +0,0 @@ -MEMORY -{ - CODE (rx) : ORIGIN = 0x08000000, LENGTH = 256K - DATA (xrw) : ORIGIN = 0x20000000, LENGTH = 64K -} - -/* Section Definitions */ - -EXTERN (vector_table) -ENTRY(reset_handler) -SECTIONS -{ - -/* Make sure the vector table is at address 0 */ - - .text : { - *(.vectors) - *(.text*) - . = ALIGN(4); - *(.rodata*) - . = ALIGN(4); - } >CODE - - . = ALIGN(4); - _etext = . ; - PROVIDE (etext = .); - - .data : - { - _data = . ; - *(.data*) - . = ALIGN(4); - _edata = . ; - PROVIDE (_edata = .); - } >DATA AT >CODE - _data_loadaddr = LOADADDR(.data); - -/* .bss section which is used for uninitialized data */ - - .bss : - { - __bss_start = . ; - __bss_start__ = . ; - *(.bss*) - *(COMMON) - . = ALIGN(4); - _ebss = . ; - } >DATA - . = ALIGN(4); - - _end = .; - PROVIDE (_end = .); -} -PROVIDE(_stack = ORIGIN(DATA) + LENGTH(DATA)); diff --git a/cpu/arm/stm32f1x_cl/clock.c b/cpu/arm/stm32f1x_cl/clock.c deleted file mode 100644 index 9efaf3e05..000000000 --- a/cpu/arm/stm32f1x_cl/clock.c +++ /dev/null @@ -1,78 +0,0 @@ -#include -#include -#include -#include - -#include - -static volatile clock_time_t current_clock = 0; -static volatile unsigned long current_seconds = 0; -static unsigned int second_countdown = CLOCK_SECOND; - -void sys_tick_handler(void) __attribute__ ((interrupt)); - -void -sys_tick_handler(void) -{ - current_clock++; - if(etimer_pending() && etimer_next_expiration_time() <= current_clock) { - etimer_request_poll(); - /* printf("%d,%d\n", clock_time(),etimer_next_expiration_time ()); */ - } - - if(--second_countdown == 0) { - current_seconds++; - second_countdown = CLOCK_SECOND; - } -} - - -void -clock_init() -{ - systick_set_clocksource(STK_CTRL_CLKSOURCE_AHB_DIV8); - - /*72mhz / 8 / 1000 */ - systick_set_reload(MCK / 8 / CLOCK_SECOND); - - systick_interrupt_enable(); - systick_counter_enable(); -} - -clock_time_t -clock_time(void) -{ - return current_clock; -} - -unsigned long -clock_seconds(void) -{ - return current_seconds; -} - -/* TODO: This code needs to be evaluated for the stm32f107 and - * implemented - */ -#if 0 -/* The inner loop takes 4 cycles. The outer 5+SPIN_COUNT*4. */ - -#define SPIN_TIME 2 /* us */ -#define SPIN_COUNT (((MCK*SPIN_TIME/1000000)-5)/4) - -#ifndef __MAKING_DEPS__ - -void -clock_delay(unsigned int t) -{ -#ifdef __THUMBEL__ - asm - volatile - ("1: mov r1,%2\n2:\tsub r1,#1\n\tbne 2b\n\tsub %0,#1\n\tbne 1b\n":"=l" - (t):"0"(t), "l"(SPIN_COUNT)); -#else -#error Must be compiled in thumb mode -#endif -} -#endif -#endif /* __MAKING_DEPS__ */ diff --git a/cpu/arm/stm32f1x_cl/mtarch.h b/cpu/arm/stm32f1x_cl/mtarch.h deleted file mode 100644 index a61c7be97..000000000 --- a/cpu/arm/stm32f1x_cl/mtarch.h +++ /dev/null @@ -1,13 +0,0 @@ -/* - * Implementation of multithreading in ARM Cortex-M3. To be done. - */ - - -#ifndef __MTARCH_H__ -#define __MTARCH_H__ - -struct mtarch_thread { - short mt_thread; -}; - -#endif /* __MTARCH_H__ */ \ No newline at end of file diff --git a/cpu/arm/stm32f1x_cl/rtimer-arch.c b/cpu/arm/stm32f1x_cl/rtimer-arch.c deleted file mode 100644 index 351ca3afc..000000000 --- a/cpu/arm/stm32f1x_cl/rtimer-arch.c +++ /dev/null @@ -1,16 +0,0 @@ - -void -rtimer_arch_init(void) -{ -} - -void -rtimer_arch_set(rtimer_clock_t t) -{ -} - -rtimer_clock_t -rtimer_arch_now(void) -{ - return 0; -} diff --git a/cpu/arm/stm32f1x_cl/rtimer-arch.h b/cpu/arm/stm32f1x_cl/rtimer-arch.h deleted file mode 100644 index 58a9e22c5..000000000 --- a/cpu/arm/stm32f1x_cl/rtimer-arch.h +++ /dev/null @@ -1,22 +0,0 @@ -/** - * \file - * Header file for the STM32F107-specific rtimer code - * \author - * Jeff Ciesielski - * Adapted from stm32f103 example - */ - -#ifndef __RTIMER_ARCH_H__ -#define __RTIMER_ARCH_H__ - -#include "sys/rtimer.h" - -#define RTIMER_ARCH_SECOND (MCK/1024) - -void rtimer_arch_init(void); - -void rtimer_arch_set(rtimer_clock_t t); - -rtimer_clock_t rtimer_arch_now(void); - -#endif /* __RTIMER_ARCH_H__ */ diff --git a/cpu/arm/stm32f1x_cl/uip-log.c b/cpu/arm/stm32f1x_cl/uip-log.c deleted file mode 100644 index 52dbd1d29..000000000 --- a/cpu/arm/stm32f1x_cl/uip-log.c +++ /dev/null @@ -1,7 +0,0 @@ -#include - -void -uip_log(char *msg) -{ - printf("uip: %s\n", msg); -} diff --git a/cpu/arm/stm32f1x_cl/util.c b/cpu/arm/stm32f1x_cl/util.c deleted file mode 100644 index 5c4d49c25..000000000 --- a/cpu/arm/stm32f1x_cl/util.c +++ /dev/null @@ -1,12 +0,0 @@ -#include - -uint32_t retval; - -uint32_t -get_msp(void) -{ - asm("ldr r1, =retval"); - asm("mrs r0, msp"); - asm("str r0, [r1]"); - return retval; -} diff --git a/cpu/arm/stm32f1x_cl/util.h b/cpu/arm/stm32f1x_cl/util.h deleted file mode 100644 index 114f7c15f..000000000 --- a/cpu/arm/stm32f1x_cl/util.h +++ /dev/null @@ -1,5 +0,0 @@ -#ifndef _UTIL_H_ -#define _UTIL_H_ -#include -uint32_t get_msp(void); -#endif /*_UTIL_H_*/ diff --git a/platform/stm32f107_basic/Makefile b/platform/stm32f107_basic/Makefile deleted file mode 100644 index 625c667f3..000000000 --- a/platform/stm32f107_basic/Makefile +++ /dev/null @@ -1,26 +0,0 @@ -TARGET=stm32f107_basic - -all: stm32f107_basic - - -CONTIKI=../.. - -CONTIKI_TARGET_MAIN=contiki-main.c - -PROJECT_SOURCEFILES = parity.c - - -randgen: randgen.c - gcc -DNDEBUG -I $(CONTIKI)/cpu/arm/stm32f107/ -I . -I $(CONTIKI)/core randgen.c -o randgen - -randcheck: randcheck.c - gcc -DNDEBUG -I $(CONTIKI)/cpu/arm/stm32f107/ -I . -I $(CONTIKI)/core randcheck.c -o randcheck - -clean: stm32test_clean - -.PHONY: stm32test_clean - -stm32test_clean: - -include $(CONTIKI)/Makefile.include - diff --git a/platform/stm32f107_basic/Makefile.stm32f107_basic b/platform/stm32f107_basic/Makefile.stm32f107_basic deleted file mode 100644 index f7a9cfd8b..000000000 --- a/platform/stm32f107_basic/Makefile.stm32f107_basic +++ /dev/null @@ -1,20 +0,0 @@ -CONTIKI_TARGET_DIRS = . dev -# Master clock frequency -MCK=72000000 -CFLAGS+=-DAUTOSTART_ENABLE - -ifndef CONTIKI_TARGET_MAIN -CONTIKI_TARGET_MAIN = contiki-main.c -endif - -CONTIKI_TARGET_SOURCEFILES += $(CONTIKI_TARGET_MAIN) -CONTIKI_TARGET_SOURCEFILES += debug-uart.c newlib.c gqueue.c - -include $(CONTIKI)/cpu/arm/stm32f1x_cl/Makefile.stm32f1x_cl - -contiki-$(TARGET).a: ${addprefix $(OBJECTDIR)/,symbols.o} - -ifndef BASE_IP -BASE_IP := 172.16.1.1 -endif - diff --git a/platform/stm32f107_basic/contiki-conf.h b/platform/stm32f107_basic/contiki-conf.h deleted file mode 100644 index 883ebf4fe..000000000 --- a/platform/stm32f107_basic/contiki-conf.h +++ /dev/null @@ -1,46 +0,0 @@ -#ifndef __CONTIKI_CONF_H__CDBB4VIH3I__ -#define __CONTIKI_CONF_H__CDBB4VIH3I__ - -#include - -#define CCIF -#define CLIF - -#define WITH_UIP 1 -#define WITH_ASCII 1 - -#define CLOCK_CONF_SECOND 1000 - -/* These names are deprecated, use C99 names. */ -typedef uint8_t u8_t; -typedef uint16_t u16_t; -typedef uint32_t u32_t; -typedef int8_t s8_t; -typedef int16_t s16_t; -typedef int32_t s32_t; - -typedef unsigned int clock_time_t; -typedef unsigned int uip_stats_t; - -#ifndef BV -#define BV(x) (1<<(x)) -#endif - -/* uIP configuration */ -#define UIP_CONF_LLH_LEN 0 -#define UIP_CONF_BROADCAST 1 -#define UIP_CONF_LOGGING 1 -#define UIP_CONF_BUFFER_SIZE 116 - -#define UIP_CONF_TCP_FORWARD 1 - -/* Prefix for relocation sections in ELF files */ -#define REL_SECT_PREFIX ".rel" - -#define CC_BYTE_ALIGNED __attribute__ ((packed, aligned(1))) - -#define USB_EP1_SIZE 64 -#define USB_EP2_SIZE 64 - -#define RAND_MAX 0x7fff -#endif /* __CONTIKI_CONF_H__CDBB4VIH3I__ */ diff --git a/platform/stm32f107_basic/contiki-main.c b/platform/stm32f107_basic/contiki-main.c deleted file mode 100644 index 6508f42a5..000000000 --- a/platform/stm32f107_basic/contiki-main.c +++ /dev/null @@ -1,44 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include - -#include -unsigned int idle_count = 0; - -static void -configure_mcu_clocks(void) -{ - rcc_clock_setup_in_hse_25mhz_out_72mhz(); - - /* GPIO Clocks */ - rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPAEN); - rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_AFIOEN); - - /* USART 1 */ - rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_USART1EN); -} - -int -main() -{ - configure_mcu_clocks(); - uart_init(115200); - printf("Initialising\n"); - - clock_init(); - process_init(); - process_start(&etimer_process, NULL); - autostart_start(autostart_processes); - printf("Processes running\n"); - while(1) { - do { - } while(process_run() > 0); - idle_count++; - } - return 0; -} diff --git a/platform/stm32f107_basic/dev/debug-uart.c b/platform/stm32f107_basic/dev/debug-uart.c deleted file mode 100644 index 381241f29..000000000 --- a/platform/stm32f107_basic/dev/debug-uart.c +++ /dev/null @@ -1,95 +0,0 @@ -#include -#include -#include - -#include -#include -#include -#include - -DECLARE_QUEUE(char, uart_tx_buf, 256); -DECLARE_QUEUE(char, uart_rx_buf, 256); - -static void uart_init_gpio(void) -{ - gpio_set_mode(GPIOA, - GPIO_MODE_OUTPUT_50_MHZ, - GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, - GPIO9); - - gpio_set_mode(GPIOA, - GPIO_MODE_INPUT, - GPIO_CNF_INPUT_FLOAT, - GPIO10); - - /* USART lines should idle high */ - gpio_set(GPIOA, GPIO9); - gpio_set(GPIOA, GPIO10); -} - -void uart_init(int baud) -{ - uart_init_gpio(); - - nvic_enable_irq(NVIC_USART1_IRQ); - nvic_set_priority(NVIC_USART1_IRQ, 2); - - usart_set_baudrate(USART1, baud); - usart_set_databits(USART1, 8); - usart_set_parity(USART1, USART_PARITY_NONE); - usart_set_flow_control(USART1, USART_FLOWCONTROL_NONE); - usart_set_stopbits(USART1, USART_CR2_STOPBITS_1); - usart_set_mode(USART1, USART_MODE_TX_RX); - usart_enable_rx_interrupt(USART1); - usart_enable(USART1); - - /* This ensures stdio doesn't use its own buffers */ - setvbuf(stdin, NULL, _IONBF, 0); - setvbuf(stdout, NULL, _IONBF, 0); -} - -int uart_putchar(char c) -{ - if( c == '\n') - uart_putchar('\r'); - if(!queue_is_full(&uart_tx_buf)) { - queue_enqueue(&uart_tx_buf, &c); - } else { - return -ENOMEM; - } - - usart_enable_tx_interrupt(USART1); - - return 0; -} - -int uart_getchar(char *c) -{ - if(!queue_is_empty(&uart_rx_buf)) { - queue_dequeue(&uart_rx_buf, c); - return 0; - } else { - return -ENODATA; - } -} - -void usart1_isr(void) -{ - char c; - if (usart_get_flag(USART1, USART_SR_TXE)) { - if (!queue_is_empty(&uart_tx_buf)) { - queue_dequeue(&uart_tx_buf, &c); - usart_send(USART1, (uint16_t)c); - } else { - usart_disable_tx_interrupt(USART1); - } - } - - - if (usart_get_flag(USART1, USART_SR_RXNE)) { - if (!queue_is_full(&uart_rx_buf)) { - c = usart_recv(USART1); - queue_enqueue(&uart_rx_buf, &c); - } - } -} diff --git a/platform/stm32f107_basic/dev/debug-uart.h b/platform/stm32f107_basic/dev/debug-uart.h deleted file mode 100644 index 1808880a9..000000000 --- a/platform/stm32f107_basic/dev/debug-uart.h +++ /dev/null @@ -1,14 +0,0 @@ -/** - * USART driver for STM32F1xx w/ libopencm3 peripherl lib - * (c) 2012 Blessed Contraptions - * Jeff Ciesielski - */ - -#ifndef _UART_H_ -#define _UART_H_ - -int uart_putchar(char c); -int uart_getchar(char *c); -void uart_init(int baud); - -#endif diff --git a/platform/stm32f107_basic/gqueue.c b/platform/stm32f107_basic/gqueue.c deleted file mode 100644 index 1f7e29a47..000000000 --- a/platform/stm32f107_basic/gqueue.c +++ /dev/null @@ -1,38 +0,0 @@ -#include - -void -queue_enqueue(volatile void *q, const void *elt) -{ - volatile struct generic_queue *gq = q; - - if(gq->len == 0) { - gq->head = gq->memory; - gq->tail = gq->memory; - } else { - if(gq->tail == gq->memory + (gq->max_capacity - 1) * gq->item_size) - /* FIXME: Should something be done about - * queue length? Substact one, maybe?*/ - gq->tail = gq->memory; - else - gq->tail = (uint8_t *) gq->tail + gq->item_size; - } - - memcpy((void *)gq->tail, elt, gq->item_size); - gq->len++; -} - -void -queue_dequeue(volatile void *q, void *elt) -{ - volatile struct generic_queue *gq = q; - - memcpy(elt, (void *)gq->head, gq->item_size); - - if(gq->head == gq->memory + (gq->max_capacity - 1) * gq->item_size) - /* FIXME: Should something be done about - * queue length? Substact one, maybe?*/ - gq->head = gq->memory; - else if(gq->len > 1) - gq->head = (uint8_t *) gq->head + gq->item_size; - gq->len--; -} diff --git a/platform/stm32f107_basic/gqueue.h b/platform/stm32f107_basic/gqueue.h deleted file mode 100644 index 8efef6c14..000000000 --- a/platform/stm32f107_basic/gqueue.h +++ /dev/null @@ -1,73 +0,0 @@ -/************************************************************************************/ -/* The MIT License (MIT) */ -/* */ -/* Copyright (c) 2012 Jeff Ciesielski */ -/* Andrey Smirnov */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining a copy of */ -/* this software and associated documentation files (the "Software"), to deal in */ -/* the Software without restriction, including without limitation the rights to */ -/* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies */ -/* of the Software, and to permit persons to whom the Software is furnished to do */ -/* so, subject to the following conditions: */ -/* */ -/* -The above copyright notice and this permission notice shall be included in all */ -/* copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR */ -/* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS */ -/* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR */ -/* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER */ -/* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN */ -/* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/************************************************************************************/ - -#ifndef _QUEUE_H_ -#define _QUEUE_H_ - -#include -#include -#include - -struct generic_queue { - volatile void *head; - volatile void *tail; - size_t item_size; - size_t len; - size_t max_capacity; - volatile uint8_t memory[0]; -}; - -#define DECLARE_QUEUE(element_type, name, max_size) \ - struct name { \ - struct generic_queue gq; \ - element_type __elements[max_size]; \ - } name = { \ - .gq={ \ - .len = 0, \ - .item_size = sizeof(element_type), \ - .max_capacity = max_size, \ - }, \ - } - - -static inline bool queue_is_empty(volatile void *q) -{ - volatile struct generic_queue *gq = q; - - return (gq->len == 0); -} -static inline int queue_get_len(volatile void *q) -{ - volatile struct generic_queue *gq = q; - return gq->len; -} -static inline bool queue_is_full(volatile void *q) -{ - volatile struct generic_queue *gq = q; - return (gq->len >= gq->max_capacity); -} -void queue_enqueue(volatile void *q, const void *elt) __attribute__((nonnull)); -void queue_dequeue(volatile void *q, void *elt) __attribute__((nonnull)); - -#endif diff --git a/platform/stm32f107_basic/newlib.c b/platform/stm32f107_basic/newlib.c deleted file mode 100644 index 0edbd64c1..000000000 --- a/platform/stm32f107_basic/newlib.c +++ /dev/null @@ -1,199 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define STDOUT_USART USART1 -#define STDERR_USART USART1 -#define STDIN_USART USART1 -#undef errno -extern int errno; - -char *__env[1] = { 0 }; -char **environ = __env; - -int _write(int file, char *ptr, int len); - -void -_exit(int status) -{ - while(1); -} - -int -_close(int file) -{ - return -1; -} - -int -_execve(char *name, char **argv, char **env) -{ - errno = ENOMEM; - return -1; -} - -int -_fork() -{ - errno = EAGAIN; - return -1; -} - -int -_fstat(int file, struct stat *st) -{ - st->st_mode = S_IFCHR; - return 0; -} - -int -_getpid() -{ - return 1; -} - -int -_gettimeofday(struct timeval *tv, struct timezone *tz) -{ - tv->tv_sec = rtc_get_counter_val(); - tv->tv_usec = 0; - return 0; -} - -int -_isatty(int file) -{ - switch (file) { - case STDOUT_FILENO: - case STDERR_FILENO: - case STDIN_FILENO: - return 1; - default: - //errno = ENOTTY; - errno = EBADF; - return 0; - } -} - -int -_kill(int pid, int sig) -{ - errno = EINVAL; - return (-1); -} - -int -_link(char *old, char *new) -{ - errno = EMLINK; - return -1; -} - -int -_lseek(int file, int ptr, int dir) -{ - return 0; -} - -caddr_t -_sbrk(int incr) -{ - extern char _ebss; - static char *heap_end; - char *prev_heap_end; - - if(heap_end == 0) { - heap_end = &_ebss; - } - prev_heap_end = heap_end; - - char *stack = (char *)get_msp(); - - if(heap_end + incr > stack) { - _write(STDERR_FILENO, "Heap and stack collision", 25); - errno = ENOMEM; - return (caddr_t) - 1; - //abort (); - } - - heap_end += incr; - return (caddr_t) prev_heap_end; - -} - -int -_read(int file, char *ptr, int len) -{ - char c = 0x00; - - switch (file) { - case STDIN_FILENO: - uart_getchar(&c); - *ptr++ = c; - return 1; - break; - default: - errno = EBADF; - return -1; - } -} - -int -_stat(const char *filepath, struct stat *st) -{ - st->st_mode = S_IFCHR; - return 0; -} - -clock_t -_times(struct tms * buf) -{ - return -1; -} - -int -_unlink(char *name) -{ - errno = ENOENT; - return -1; -} - -int -_wait(int *status) -{ - errno = ECHILD; - return -1; -} - -int -_write(int file, char *ptr, int len) -{ - int n; - char c; - - switch (file) { - case STDOUT_FILENO: /*stdout */ - for(n = 0; n < len; n++) { - c = (uint8_t) * ptr++; - uart_putchar(c); - } - break; - case STDERR_FILENO: /* stderr */ - for(n = 0; n < len; n++) { - c = (uint8_t) * ptr++; - uart_putchar(c); - } - break; - default: - errno = EBADF; - return -1; - } - return len; -} diff --git a/platform/stm32f107_basic/structgen_opts.gen.h b/platform/stm32f107_basic/structgen_opts.gen.h deleted file mode 100644 index f0a459008..000000000 --- a/platform/stm32f107_basic/structgen_opts.gen.h +++ /dev/null @@ -1,2 +0,0 @@ -#pragma target_endian little -#pragma max_target_int_bytes 8 From 4d4b796abbf83c771a836dc8d85df51d7733ceaa Mon Sep 17 00:00:00 2001 From: Oliver Schmidt Date: Wed, 6 Mar 2013 14:32:36 +0100 Subject: [PATCH 29/34] Removed useless register keywords. Modern compilers (especially GCC) ignore the register keyword anyway and the latest cc65 snapshot generates actually larger code with the register keyword at the locations in question. --- core/net/tcpip.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/core/net/tcpip.c b/core/net/tcpip.c index 4b178a1db..fc6db0ad2 100644 --- a/core/net/tcpip.c +++ b/core/net/tcpip.c @@ -284,7 +284,7 @@ void tcp_attach(struct uip_conn *conn, void *appstate) { - register uip_tcp_appstate_t *s; + uip_tcp_appstate_t *s; s = &conn->appstate; s->p = PROCESS_CURRENT(); @@ -298,7 +298,7 @@ void udp_attach(struct uip_udp_conn *conn, void *appstate) { - register uip_udp_appstate_t *s; + uip_udp_appstate_t *s; s = &conn->appstate; s->p = PROCESS_CURRENT(); @@ -394,7 +394,7 @@ eventhandler(process_event_t ev, process_data_t data) } { - register struct uip_conn *cptr; + struct uip_conn *cptr; for(cptr = &uip_conns[0]; cptr < &uip_conns[UIP_CONNS]; ++cptr) { if(cptr->appstate.p == p) { @@ -406,7 +406,7 @@ eventhandler(process_event_t ev, process_data_t data) #endif /* UIP_TCP */ #if UIP_UDP { - register struct uip_udp_conn *cptr; + struct uip_udp_conn *cptr; for(cptr = &uip_udp_conns[0]; cptr < &uip_udp_conns[UIP_UDP_CONNS]; ++cptr) { @@ -697,7 +697,7 @@ tcpip_poll_tcp(struct uip_conn *conn) void tcpip_uipcall(void) { - register uip_udp_appstate_t *ts; + uip_udp_appstate_t *ts; #if UIP_UDP if(uip_conn != NULL) { @@ -712,7 +712,7 @@ tcpip_uipcall(void) #if UIP_TCP { static unsigned char i; - register struct listenport *l; + struct listenport *l; /* If this is a connection request for a listening port, we must mark the connection with the right process ID. */ From 49ca10d54029a5b1b443aa3681f9d72fe262478b Mon Sep 17 00:00:00 2001 From: Oliver Schmidt Date: Wed, 6 Mar 2013 14:50:51 +0100 Subject: [PATCH 30/34] Removed PFS code from C128 WGET. On the C128 the custom PFS code doesn't add functionality (as it does with IDE64 support on the C64) but is "only" smaller than the POSIX file i/o code in the C library. But the stdio code in the C library (used in WGET for screen i/o) relies on the POSIX file i/o code anyway so there no point in additionally adding the PFS code to the WGET program. --- examples/wget/Makefile.c128.defines | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/wget/Makefile.c128.defines b/examples/wget/Makefile.c128.defines index 3dbfd3e2f..405794c09 100644 --- a/examples/wget/Makefile.c128.defines +++ b/examples/wget/Makefile.c128.defines @@ -1 +1 @@ -DEFINES = WITH_LOGGING,WITH_CLIENT,WITH_DNS,WITH_PFS +DEFINES = WITH_LOGGING,WITH_CLIENT,WITH_DNS From 65ad87422f83ac121be2b59d305ccf6375945510 Mon Sep 17 00:00:00 2001 From: Oliver Schmidt Date: Wed, 6 Mar 2013 14:57:24 +0100 Subject: [PATCH 31/34] Finetuned Language Card usage. Both the source code and the cc65 compiler have changed. So it made sense to review which object files are to be compiled for placement in the Language Card. --- platform/apple2enh/Makefile.apple2enh | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/platform/apple2enh/Makefile.apple2enh b/platform/apple2enh/Makefile.apple2enh index 48e063107..d5b9ab244 100644 --- a/platform/apple2enh/Makefile.apple2enh +++ b/platform/apple2enh/Makefile.apple2enh @@ -39,12 +39,11 @@ CONTIKI_CPU = $(CONTIKI)/cpu/6502 include $(CONTIKI_CPU)/Makefile.6502 LDFLAGS += -D __HIMEM__=0xBF00 +LC_SOURCEFILES = process.c tcpip.c ifeq ($(findstring WITH_REBOOT,$(DEFINES)),WITH_REBOOT) - LC_SOURCEFILES = process.c etimer.c uip_arp.c LDFLAGS += -D __LCADDR__=0xD000 -D __LCSIZE__=0x1000 -else - LC_SOURCEFILES = process.c etimer.c ethernet.c + LC_SOURCEFILES += etimer.c endif # Set a target-specific variable value From 65a4472a0d0ad273286b13236ddaf0e37638f026 Mon Sep 17 00:00:00 2001 From: Oliver Schmidt Date: Wed, 6 Mar 2013 15:12:02 +0100 Subject: [PATCH 32/34] Limit content of web browser version of http-strings to web browser. In general it seems a bad idea to have two http-strings.c files as this precludes to have them both in the Contiki library. However as it stands it seems most reasonable to have one http-strings.c file be a clean superset of all usecases in order to allow them to run together in a single binary. As webserver/http-strings.c already contained strings not present in webbrowser/http-strings.c it seems reasonable to consider webserver/http-strings.c as the superset described. From that perspective it is appropriate to remove all strings from webbrowser/http-strings.c which are not used by the web browser in order to save memory otherwise wasted. --- apps/webbrowser/http-strings | 21 ------------ apps/webbrowser/http-strings.c | 60 ---------------------------------- apps/webbrowser/http-strings.h | 20 ------------ 3 files changed, 101 deletions(-) diff --git a/apps/webbrowser/http-strings b/apps/webbrowser/http-strings index 2bba32dc8..24ddb4f90 100644 --- a/apps/webbrowser/http-strings +++ b/apps/webbrowser/http-strings @@ -9,25 +9,4 @@ http_content_type "content-type: " http_location "location: " http_host "Host: " http_crnl "\r\n" -http_index_html "/index.html" -http_404_html "/404.html" -http_referer "Referer:" -http_header_200 "HTTP/1.0 200 OK\r\nServer: Contiki/2.6 http://www.contiki-os.org/\r\nConnection: close\r\n" -http_header_404 "HTTP/1.0 404 Not found\r\nServer: Contiki/2.6 http://www.contiki-os.org/\r\nConnection: close\r\n" -http_content_type_plain "Content-type: text/plain\r\n\r\n" -http_content_type_html "Content-type: text/html\r\n\r\n" -http_content_type_css "Content-type: text/css\r\n\r\n" -http_content_type_text "Content-type: text/text\r\n\r\n" -http_content_type_png "Content-type: image/png\r\n\r\n" -http_content_type_gif "Content-type: image/gif\r\n\r\n" -http_content_type_jpg "Content-type: image/jpeg\r\n\r\n" -http_content_type_binary "Content-type: application/octet-stream\r\n\r\n" http_html ".html" -http_htm ".htm" -http_css ".css" -http_png ".png" -http_gif ".gif" -http_jpg ".jpg" -http_text ".text" -http_txt ".txt" - diff --git a/apps/webbrowser/http-strings.c b/apps/webbrowser/http-strings.c index 3407105c3..aa4d45ece 100644 --- a/apps/webbrowser/http-strings.c +++ b/apps/webbrowser/http-strings.c @@ -31,66 +31,6 @@ const char http_host[7] = const char http_crnl[3] = /* "\r\n" */ {0xd, 0xa, }; -const char http_index_html[12] = -/* "/index.html" */ -{0x2f, 0x69, 0x6e, 0x64, 0x65, 0x78, 0x2e, 0x68, 0x74, 0x6d, 0x6c, }; -const char http_404_html[10] = -/* "/404.html" */ -{0x2f, 0x34, 0x30, 0x34, 0x2e, 0x68, 0x74, 0x6d, 0x6c, }; -const char http_referer[9] = -/* "Referer:" */ -{0x52, 0x65, 0x66, 0x65, 0x72, 0x65, 0x72, 0x3a, }; -const char http_header_200[85] = -/* "HTTP/1.0 200 OK\r\nServer: Contiki/2.6 http://www.contiki-os.org/\r\nConnection: close\r\n" */ -{0x48, 0x54, 0x54, 0x50, 0x2f, 0x31, 0x2e, 0x30, 0x20, 0x32, 0x30, 0x30, 0x20, 0x4f, 0x4b, 0xd, 0xa, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x3a, 0x20, 0x43, 0x6f, 0x6e, 0x74, 0x69, 0x6b, 0x69, 0x2f, 0x32, 0x2e, 0x36, 0x20, 0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, 0x77, 0x77, 0x77, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x69, 0x6b, 0x69, 0x2d, 0x6f, 0x73, 0x2e, 0x6f, 0x72, 0x67, 0x2f, 0xd, 0xa, 0x43, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x3a, 0x20, 0x63, 0x6c, 0x6f, 0x73, 0x65, 0xd, 0xa, }; -const char http_header_404[92] = -/* "HTTP/1.0 404 Not found\r\nServer: Contiki/2.6 http://www.contiki-os.org/\r\nConnection: close\r\n" */ -{0x48, 0x54, 0x54, 0x50, 0x2f, 0x31, 0x2e, 0x30, 0x20, 0x34, 0x30, 0x34, 0x20, 0x4e, 0x6f, 0x74, 0x20, 0x66, 0x6f, 0x75, 0x6e, 0x64, 0xd, 0xa, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x3a, 0x20, 0x43, 0x6f, 0x6e, 0x74, 0x69, 0x6b, 0x69, 0x2f, 0x32, 0x2e, 0x36, 0x20, 0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, 0x77, 0x77, 0x77, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x69, 0x6b, 0x69, 0x2d, 0x6f, 0x73, 0x2e, 0x6f, 0x72, 0x67, 0x2f, 0xd, 0xa, 0x43, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x3a, 0x20, 0x63, 0x6c, 0x6f, 0x73, 0x65, 0xd, 0xa, }; -const char http_content_type_plain[29] = -/* "Content-type: text/plain\r\n\r\n" */ -{0x43, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x2d, 0x74, 0x79, 0x70, 0x65, 0x3a, 0x20, 0x74, 0x65, 0x78, 0x74, 0x2f, 0x70, 0x6c, 0x61, 0x69, 0x6e, 0xd, 0xa, 0xd, 0xa, }; -const char http_content_type_html[28] = -/* "Content-type: text/html\r\n\r\n" */ -{0x43, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x2d, 0x74, 0x79, 0x70, 0x65, 0x3a, 0x20, 0x74, 0x65, 0x78, 0x74, 0x2f, 0x68, 0x74, 0x6d, 0x6c, 0xd, 0xa, 0xd, 0xa, }; -const char http_content_type_css [27] = -/* "Content-type: text/css\r\n\r\n" */ -{0x43, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x2d, 0x74, 0x79, 0x70, 0x65, 0x3a, 0x20, 0x74, 0x65, 0x78, 0x74, 0x2f, 0x63, 0x73, 0x73, 0xd, 0xa, 0xd, 0xa, }; -const char http_content_type_text[28] = -/* "Content-type: text/text\r\n\r\n" */ -{0x43, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x2d, 0x74, 0x79, 0x70, 0x65, 0x3a, 0x20, 0x74, 0x65, 0x78, 0x74, 0x2f, 0x74, 0x65, 0x78, 0x74, 0xd, 0xa, 0xd, 0xa, }; -const char http_content_type_png [28] = -/* "Content-type: image/png\r\n\r\n" */ -{0x43, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x2d, 0x74, 0x79, 0x70, 0x65, 0x3a, 0x20, 0x69, 0x6d, 0x61, 0x67, 0x65, 0x2f, 0x70, 0x6e, 0x67, 0xd, 0xa, 0xd, 0xa, }; -const char http_content_type_gif [28] = -/* "Content-type: image/gif\r\n\r\n" */ -{0x43, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x2d, 0x74, 0x79, 0x70, 0x65, 0x3a, 0x20, 0x69, 0x6d, 0x61, 0x67, 0x65, 0x2f, 0x67, 0x69, 0x66, 0xd, 0xa, 0xd, 0xa, }; -const char http_content_type_jpg [29] = -/* "Content-type: image/jpeg\r\n\r\n" */ -{0x43, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x2d, 0x74, 0x79, 0x70, 0x65, 0x3a, 0x20, 0x69, 0x6d, 0x61, 0x67, 0x65, 0x2f, 0x6a, 0x70, 0x65, 0x67, 0xd, 0xa, 0xd, 0xa, }; -const char http_content_type_binary[43] = -/* "Content-type: application/octet-stream\r\n\r\n" */ -{0x43, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x2d, 0x74, 0x79, 0x70, 0x65, 0x3a, 0x20, 0x61, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2f, 0x6f, 0x63, 0x74, 0x65, 0x74, 0x2d, 0x73, 0x74, 0x72, 0x65, 0x61, 0x6d, 0xd, 0xa, 0xd, 0xa, }; const char http_html[6] = /* ".html" */ {0x2e, 0x68, 0x74, 0x6d, 0x6c, }; -const char http_htm[5] = -/* ".htm" */ -{0x2e, 0x68, 0x74, 0x6d, }; -const char http_css[5] = -/* ".css" */ -{0x2e, 0x63, 0x73, 0x73, }; -const char http_png[5] = -/* ".png" */ -{0x2e, 0x70, 0x6e, 0x67, }; -const char http_gif[5] = -/* ".gif" */ -{0x2e, 0x67, 0x69, 0x66, }; -const char http_jpg[5] = -/* ".jpg" */ -{0x2e, 0x6a, 0x70, 0x67, }; -const char http_text[6] = -/* ".text" */ -{0x2e, 0x74, 0x65, 0x78, 0x74, }; -const char http_txt[5] = -/* ".txt" */ -{0x2e, 0x74, 0x78, 0x74, }; diff --git a/apps/webbrowser/http-strings.h b/apps/webbrowser/http-strings.h index 5c2cf9396..8b9bee66e 100644 --- a/apps/webbrowser/http-strings.h +++ b/apps/webbrowser/http-strings.h @@ -9,24 +9,4 @@ extern const char http_content_type[15]; extern const char http_location[11]; extern const char http_host[7]; extern const char http_crnl[3]; -extern const char http_index_html[12]; -extern const char http_404_html[10]; -extern const char http_referer[9]; -extern const char http_header_200[85]; -extern const char http_header_404[92]; -extern const char http_content_type_plain[29]; -extern const char http_content_type_html[28]; -extern const char http_content_type_css [27]; -extern const char http_content_type_text[28]; -extern const char http_content_type_png [28]; -extern const char http_content_type_gif [28]; -extern const char http_content_type_jpg [29]; -extern const char http_content_type_binary[43]; extern const char http_html[6]; -extern const char http_htm[5]; -extern const char http_css[5]; -extern const char http_png[5]; -extern const char http_gif[5]; -extern const char http_jpg[5]; -extern const char http_text[6]; -extern const char http_txt[5]; From cdb16c02fa3df10e59fbec092deff7ac5e389566 Mon Sep 17 00:00:00 2001 From: Oliver Schmidt Date: Wed, 6 Mar 2013 15:17:39 +0100 Subject: [PATCH 33/34] Removed web browser settings that aren't actually different from the defaults. --- platform/pc-6001/contiki-conf.h | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/platform/pc-6001/contiki-conf.h b/platform/pc-6001/contiki-conf.h index d0760d9c3..8f20e2c5e 100644 --- a/platform/pc-6001/contiki-conf.h +++ b/platform/pc-6001/contiki-conf.h @@ -175,15 +175,5 @@ typedef unsigned long clock_time_t; #define WWW_CONF_WEBPAGE_WIDTH 76 #define WWW_CONF_WEBPAGE_HEIGHT 30 -#define WWW_CONF_HISTORY_SIZE 40 -#define WWW_CONF_MAX_URLLEN 200 -#define WWW_CONF_MAX_NUMPAGEWIDGETS 80 -#define WWW_CONF_RENDERSTATE 1 -#define WWW_CONF_FORMS 1 -#define WWW_CONF_MAX_FORMACTIONLEN 200 -#define WWW_CONF_MAX_FORMNAMELEN 200 -#define WWW_CONF_MAX_INPUTNAMELEN 200 -#define WWW_CONF_MAX_INPUTVALUELEN 240 -#define WWW_CONF_PAGEVIEW 1 #endif /* __CONTIKI_CONF_H__ */ From c7b8bac0065f1292ecd1701fc7e2bbb121556f5e Mon Sep 17 00:00:00 2001 From: Oliver Schmidt Date: Wed, 6 Mar 2013 16:29:36 +0100 Subject: [PATCH 34/34] Reorganized web page attribute data handling. - Up to now the web browser used several fixed size arrays to hold the various types attribute data of the web page. This turned out to be way to inflexible for any non-trivial web page. Therefore now all attribute data is stored in a single buffer one after the other as they arrive from the parser only occupying the memory actually needed. This allows for pages with many links with rather short URLs as well as pages with few link with long URLs as well as pages with several simple forms as well as pages with one form with many form inputs. - Using the actual web page buffer to hold the text buffers of text entry fields was in general a cool idea but in reality it is often necessary to enter text longer than the size of the text entry field. Therefore the text buffer is now stored in the new unified attribute data buffer. - Splitting up the process of canonicalizing a link URL and actually navigating to the resulting URL allowed to get rid of the 'tmpurl' buffer used during form submit. Now the form action is canonicalized like a usual link, then the form input name/value pairs are written right into the 'url' buffer and afterwards the navigation is triggered. - Support for the 'render states' was completely removed. The only actually supported render state was centered output. The new unified attribute buffer would have complicated enumerating all widgets added to the page in order to adjust their position. Therefore I decided to drop the whole feature as the
tag is barely used anymore and newer center attributes are to hard to parse. --- apps/webbrowser/html-strings | 2 - apps/webbrowser/html-strings.c | 6 - apps/webbrowser/html-strings.h | 2 - apps/webbrowser/htmlparser.c | 207 +++++-------- apps/webbrowser/htmlparser.h | 20 +- apps/webbrowser/www.c | 493 ++++++++++++++---------------- apps/webbrowser/www.h | 20 +- platform/apple2enh/contiki-conf.h | 2 - platform/atari/contiki-conf.h | 5 - platform/c128/contiki-conf.h | 5 - platform/c64/contiki-conf.h | 2 - 11 files changed, 313 insertions(+), 451 deletions(-) diff --git a/apps/webbrowser/html-strings b/apps/webbrowser/html-strings index 5e10d41d4..0c9a7c99f 100644 --- a/apps/webbrowser/html-strings +++ b/apps/webbrowser/html-strings @@ -1,5 +1,4 @@ html_slasha "/a\0" -html_slashcenter "/center\0" html_slashdiv "/div\0" html_slashform "/form\0" html_slashh "/h\0" @@ -9,7 +8,6 @@ html_slashstyle "/style\0" html_a "a\0" html_body "body\0" html_br "br\0" -html_center "center\0" html_form "form\0" html_frame "frame\0" html_h1 "h1\0" diff --git a/apps/webbrowser/html-strings.c b/apps/webbrowser/html-strings.c index cb4b05629..567d9ce4a 100644 --- a/apps/webbrowser/html-strings.c +++ b/apps/webbrowser/html-strings.c @@ -1,9 +1,6 @@ const char html_slasha[4] = /* "/a\0" */ {0x2f, 0x61, 00, }; -const char html_slashcenter[9] = -/* "/center\0" */ -{0x2f, 0x63, 0x65, 0x6e, 0x74, 0x65, 0x72, 00, }; const char html_slashdiv[6] = /* "/div\0" */ {0x2f, 0x64, 0x69, 0x76, 00, }; @@ -31,9 +28,6 @@ const char html_body[6] = const char html_br[4] = /* "br\0" */ {0x62, 0x72, 00, }; -const char html_center[8] = -/* "center\0" */ -{0x63, 0x65, 0x6e, 0x74, 0x65, 0x72, 00, }; const char html_form[6] = /* "form\0" */ {0x66, 0x6f, 0x72, 0x6d, 00, }; diff --git a/apps/webbrowser/html-strings.h b/apps/webbrowser/html-strings.h index b10a78c59..ec8587997 100644 --- a/apps/webbrowser/html-strings.h +++ b/apps/webbrowser/html-strings.h @@ -1,5 +1,4 @@ extern const char html_slasha[4]; -extern const char html_slashcenter[9]; extern const char html_slashdiv[6]; extern const char html_slashform[7]; extern const char html_slashh[4]; @@ -9,7 +8,6 @@ extern const char html_slashstyle[8]; extern const char html_a[3]; extern const char html_body[6]; extern const char html_br[4]; -extern const char html_center[8]; extern const char html_form[6]; extern const char html_frame[7]; extern const char html_h1[4]; diff --git a/apps/webbrowser/htmlparser.c b/apps/webbrowser/htmlparser.c index 79e2724c6..2e2727993 100644 --- a/apps/webbrowser/htmlparser.c +++ b/apps/webbrowser/htmlparser.c @@ -160,7 +160,6 @@ struct htmlparser_state { #if WWW_CONF_FORMS char formaction[WWW_CONF_MAX_FORMACTIONLEN]; - char formname[WWW_CONF_MAX_FORMNAMELEN]; unsigned char inputtype; char inputname[WWW_CONF_MAX_INPUTNAMELEN]; char inputvalue[WWW_CONF_MAX_INPUTVALUELEN]; @@ -177,57 +176,53 @@ static const char *tags[] = { #define TAG_FIRST 0 #define TAG_SLASHA 0 html_slasha, -#define TAG_SLASHCENTER 1 - html_slashcenter, -#define TAG_SLASHDIV 2 +#define TAG_SLASHDIV 1 html_slashdiv, -#define TAG_SLASHFORM 3 +#define TAG_SLASHFORM 2 html_slashform, -#define TAG_SLASHH 4 +#define TAG_SLASHH 3 html_slashh, -#define TAG_SLASHSCRIPT 5 +#define TAG_SLASHSCRIPT 4 html_slashscript, -#define TAG_SLASHSELECT 6 +#define TAG_SLASHSELECT 5 html_slashselect, -#define TAG_SLASHSTYLE 7 +#define TAG_SLASHSTYLE 6 html_slashstyle, -#define TAG_A 8 +#define TAG_A 7 html_a, -#define TAG_BODY 9 +#define TAG_BODY 8 html_body, -#define TAG_BR 10 +#define TAG_BR 9 html_br, -#define TAG_CENTER 11 - html_center, -#define TAG_FORM 12 +#define TAG_FORM 10 html_form, -#define TAG_FRAME 13 +#define TAG_FRAME 11 html_frame, -#define TAG_H1 14 +#define TAG_H1 12 html_h1, -#define TAG_H2 15 +#define TAG_H2 13 html_h2, -#define TAG_H3 16 +#define TAG_H3 14 html_h3, -#define TAG_H4 17 +#define TAG_H4 15 html_h4, -#define TAG_IMG 18 +#define TAG_IMG 16 html_img, -#define TAG_INPUT 19 +#define TAG_INPUT 17 html_input, -#define TAG_LI 20 +#define TAG_LI 18 html_li, -#define TAG_P 21 +#define TAG_P 19 html_p, -#define TAG_SCRIPT 22 +#define TAG_SCRIPT 20 html_script, -#define TAG_SELECT 23 +#define TAG_SELECT 21 html_select, -#define TAG_STYLE 24 +#define TAG_STYLE 22 html_style, -#define TAG_TR 25 +#define TAG_TR 23 html_tr, -#define TAG_LAST 26 +#define TAG_LAST 24 last, }; @@ -258,7 +253,7 @@ htmlparser_init(void) s.minorstate = MINORSTATE_TEXT; s.lastchar = 0; #if WWW_CONF_FORMS - s.formaction[0] = s.formname[0] = 0; + s.formaction[0] = 0; #endif /* WWW_CONF_FORMS */ } /*-----------------------------------------------------------------------------------*/ @@ -336,31 +331,28 @@ find_tag(char *tag) first = TAG_FIRST; last = TAG_LAST; i = 0; - + do { tagc = tag[i]; - if((tagc == 0 || tagc == ISO_slash) && - tags[first][i] == 0) { + if((tagc == 0 || tagc == ISO_slash) && tags[first][i] == 0) { return first; } tabi = first; - + /* First, find first matching tag from table. */ - while(tagc > (tags[tabi])[i] && - tabi < last) { + while(tagc > (tags[tabi])[i] && tabi < last) { ++tabi; } first = tabi; - + /* Second, find last matching tag from table. */ - while(tagc == (tags[tabi])[i] && - tabi < last) { + while(tagc == (tags[tabi])[i] && tabi < last) { ++tabi; } last = tabi; - + /* If first and last matching tags are equal, we have a non-match and return. Else we continue with the next character. */ ++i; @@ -377,8 +369,7 @@ parse_tag(void) static char dummy; - PRINTF(("Parsing tag '%s' '%s' '%s'\n", - s.tag, s.tagattr, s.tagattrparam)); + PRINTF(("Parsing tag '%s' '%s' '%s'\n", s.tag, s.tagattr, s.tagattrparam)); switch(find_tag(s.tag)) { case TAG_P: @@ -386,14 +377,12 @@ parse_tag(void) case TAG_H2: case TAG_H3: case TAG_H4: - /* parse_char(ISO_nl);*/ newline(); /* FALLTHROUGH */ case TAG_BR: case TAG_TR: case TAG_SLASHDIV: case TAG_SLASHH: - /* parse_char(ISO_nl);*/ dummy = 0; newline(); break; @@ -417,8 +406,7 @@ parse_tag(void) s.majorstate = s.lastmajorstate = MAJORSTATE_BODY; break; case TAG_FRAME: - if(strncmp(s.tagattr, html_src, sizeof(html_src)) == 0 && - s.tagattrparam[0] != 0) { + if(strncmp(s.tagattr, html_src, sizeof(html_src)) == 0 && s.tagattrparam[0] != 0) { switch_majorstate(MAJORSTATE_BODY); newline(); add_char(ISO_rbrack); @@ -430,25 +418,20 @@ parse_tag(void) } break; case TAG_IMG: - if(strncmp(s.tagattr, html_alt, sizeof(html_alt)) == 0 && - s.tagattrparam[0] != 0) { - /* parse_char(ISO_lt);*/ + if(strncmp(s.tagattr, html_alt, sizeof(html_alt)) == 0 && s.tagattrparam[0] != 0) { add_char(ISO_lt); tagattrparam = &s.tagattrparam[0]; while(*tagattrparam) { - /* parse_char(*tagattrparam);*/ add_char(*tagattrparam); ++tagattrparam; } - /* parse_char(ISO_gt);*/ add_char(ISO_gt); do_word(); } break; case TAG_A: PRINTF(("A %s %s\n", s.tagattr, s.tagattrparam)); - if(strncmp(s.tagattr, html_href, sizeof(html_href)) == 0 && - s.tagattrparam[0] != 0) { + if(strncmp(s.tagattr, html_href, sizeof(html_href)) == 0 && s.tagattrparam[0] != 0) { strcpy(s.linkurl, s.tagattrparam); do_word(); switch_majorstate(MAJORSTATE_LINK); @@ -464,72 +447,62 @@ parse_tag(void) break; #if WWW_CONF_FORMS case TAG_FORM: - PRINTF(("Form tag\n")); - switch_majorstate(MAJORSTATE_FORM); - if(strncmp(s.tagattr, html_action, sizeof(html_action)) == 0) { - PRINTF(("Form action '%s'\n", s.tagattrparam)); - strncpy(s.formaction, s.tagattrparam, WWW_CONF_MAX_FORMACTIONLEN - 1); - } else if(strncmp(s.tagattr, html_name, sizeof(html_name)) == 0) { - PRINTF(("Form name '%s'\n", s.tagattrparam)); - strncpy(s.formname, s.tagattrparam, WWW_CONF_MAX_FORMNAMELEN - 1); + /* First check if we are called at the end of a form tag. If + so, we should propagate the form action. */ + if(s.tagattr[0] == 0 && s.formaction[0] != 0) { + htmlparser_form(s.formaction); + init_input(); + } else { + PRINTF(("Form tag\n")); + switch_majorstate(MAJORSTATE_FORM); + if(strncmp(s.tagattr, html_action, sizeof(html_action)) == 0) { + PRINTF(("Form action '%s'\n", s.tagattrparam)); + strncpy(s.formaction, s.tagattrparam, WWW_CONF_MAX_FORMACTIONLEN - 1); + } } - init_input(); break; case TAG_SLASHFORM: switch_majorstate(MAJORSTATE_BODY); - s.formaction[0] = s.formname[0] = 0; + s.formaction[0] = 0; break; case TAG_INPUT: if(s.majorstate == MAJORSTATE_FORM) { /* First check if we are called at the end of an input tag. If so, we should render the input widget. */ - if(s.tagattr[0] == 0 && - s.inputname[0] != 0) { + if(s.tagattr[0] == 0 && s.inputname[0] != 0) { PRINTF(("Render input type %d\n", s.inputtype)); switch(s.inputtype) { case HTMLPARSER_INPUTTYPE_NONE: case HTMLPARSER_INPUTTYPE_TEXT: s.inputvalue[s.inputvaluesize] = 0; - htmlparser_inputfield(s.inputvaluesize, s.inputvalue, s.inputname, - s.formname, s.formaction); + htmlparser_inputfield(s.inputvaluesize, s.inputvalue, s.inputname); break; case HTMLPARSER_INPUTTYPE_SUBMIT: case HTMLPARSER_INPUTTYPE_IMAGE: - htmlparser_submitbutton(s.inputvalue, s.inputname, - s.formname, s.formaction); + htmlparser_submitbutton(s.inputvalue, s.inputname); break; } init_input(); } else { PRINTF(("Input '%s' '%s'\n", s.tagattr, s.tagattrparam)); if(strncmp(s.tagattr, html_type, sizeof(html_type)) == 0) { - if(strncmp(s.tagattrparam, html_submit, - sizeof(html_submit)) == 0) { + if(strncmp(s.tagattrparam, html_submit, sizeof(html_submit)) == 0) { s.inputtype = HTMLPARSER_INPUTTYPE_SUBMIT; - } else if(strncmp(s.tagattrparam, html_image, - sizeof(html_image)) == 0) { + } else if(strncmp(s.tagattrparam, html_image, sizeof(html_image)) == 0) { s.inputtype = HTMLPARSER_INPUTTYPE_IMAGE; - } else if(strncmp(s.tagattrparam, html_text, - sizeof(html_text)) == 0) { + } else if(strncmp(s.tagattrparam, html_text, sizeof(html_text)) == 0) { s.inputtype = HTMLPARSER_INPUTTYPE_TEXT; } else { s.inputtype = HTMLPARSER_INPUTTYPE_OTHER; } - } else if(strncmp(s.tagattr, html_name, - sizeof(html_name)) == 0) { - strncpy(s.inputname, s.tagattrparam, - WWW_CONF_MAX_INPUTNAMELEN); - } else if(strncmp(s.tagattr, html_alt, - sizeof(html_alt)) == 0 && + } else if(strncmp(s.tagattr, html_name, sizeof(html_name)) == 0) { + strncpy(s.inputname, s.tagattrparam, WWW_CONF_MAX_INPUTNAMELEN); + } else if(strncmp(s.tagattr, html_alt, sizeof(html_alt)) == 0 && s.inputtype == HTMLPARSER_INPUTTYPE_IMAGE) { - strncpy(s.inputvalue, s.tagattrparam, - WWW_CONF_MAX_INPUTVALUELEN); - } else if(strncmp(s.tagattr, html_value, - sizeof(html_value)) == 0) { - strncpy(s.inputvalue, s.tagattrparam, - WWW_CONF_MAX_INPUTVALUELEN); - } else if(strncmp(s.tagattr, html_size, - sizeof(html_size)) == 0) { + strncpy(s.inputvalue, s.tagattrparam, WWW_CONF_MAX_INPUTVALUELEN); + } else if(strncmp(s.tagattr, html_value, sizeof(html_value)) == 0) { + strncpy(s.inputvalue, s.tagattrparam, WWW_CONF_MAX_INPUTVALUELEN); + } else if(strncmp(s.tagattr, html_size, sizeof(html_size)) == 0) { size = 0; if(s.tagattrparam[0] >= '0' && s.tagattrparam[0] <= '9') { @@ -543,32 +516,15 @@ parse_tag(void) size = WWW_CONF_MAX_INPUTVALUELEN - 1; } s.inputvaluesize = size; - /* strncpy(s.inputvalue, s.tagattrparam, - WWW_CONF_MAX_INPUTVALUELEN);*/ } } - } break; -#endif /* WWW_CONF_FORMS */ -#if WWW_CONF_RENDERSTATE - case TAG_CENTER: - /* parse_char(ISO_nl); */ - newline(); - htmlparser_renderstate(HTMLPARSER_RENDERSTATE_BEGIN | - HTMLPARSER_RENDERSTATE_CENTER); - break; - case TAG_SLASHCENTER: - /* parse_char(ISO_nl);*/ - newline(); - htmlparser_renderstate(HTMLPARSER_RENDERSTATE_END | - HTMLPARSER_RENDERSTATE_CENTER); - break; -#endif /* WWW_CONF_RENDERSTATE */ +#endif /* WWW_CONF_FORMS */ } } /*-----------------------------------------------------------------------------------*/ -static uint16_t +static uint16_t CC_FASTCALL parse_word(char *data, uint8_t dlen) { static uint8_t i; @@ -586,7 +542,6 @@ parse_word(char *data, uint8_t dlen) } else if(c == ISO_lt) { s.minorstate = MINORSTATE_TAG; s.tagptr = 0; - /* do_word();*/ break; } else if(c == ISO_ampersand) { s.minorstate = MINORSTATE_EXTCHAR; @@ -599,11 +554,11 @@ parse_word(char *data, uint8_t dlen) case MINORSTATE_EXTCHAR: for(i = 0; i < len; ++i) { c = data[i]; - if(c == ISO_semicolon) { + if(c == ISO_semicolon) { s.minorstate = MINORSTATE_TEXT; add_char(' '); break; - } else if(iswhitespace(c)) { + } else if(iswhitespace(c)) { s.minorstate = MINORSTATE_TEXT; add_char('&'); add_char(' '); @@ -622,7 +577,7 @@ parse_word(char *data, uint8_t dlen) /* Full tag found. We continue parsing regular text. */ s.minorstate = MINORSTATE_TEXT; s.tagattrptr = s.tagattrparamptr = 0; - endtagfound(); + endtagfound(); parse_tag(); break; } else if(iswhitespace(c)) { @@ -635,7 +590,6 @@ parse_word(char *data, uint8_t dlen) } else { /* Keep track of the name of the tag, but convert it to lower case. */ - s.tag[s.tagptr] = lowercase(c); ++s.tagptr; /* Check if the ->tag field is full. If so, we just eat up @@ -645,7 +599,7 @@ parse_word(char *data, uint8_t dlen) break; } } - + /* Check for HTML comment, indicated by