Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions NanodeUIP.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "NanodeUIP.h"

#include <avr/pgmspace.h>
#include <stdio.h>
#include <inttypes.h>

#include "uip.h"
Expand All @@ -8,12 +10,15 @@
#include "dhcpc.h"
#include "resolv.h"

void nanode_log(char *msg);

void nanode_log(char *msg) {
Serial.println(msg);
}

void nanode_log_P(PGM_P msg) {
printf_P(PSTR("%lu: %S\r\n"),millis(),msg);
}

void dhcpc_configured(const struct dhcpc_state *s) {
uip_sethostaddr(s->ipaddr);
uip_setnetmask(s->netmask);
Expand Down Expand Up @@ -93,14 +98,14 @@ void NanodeUIP::set_nameserver_addr(byte a, byte b, byte c, byte d) {

// Requires a buffer of at least 18 bytes to format into
void NanodeUIP::get_mac_str(char *buf) {
sprintf(buf,"%02X:%02X:%02X:%02X:%02X:%02X",
sprintf_P(buf,PSTR("%02X:%02X:%02X:%02X:%02X:%02X"),
uip_ethaddr.addr[0], uip_ethaddr.addr[1], uip_ethaddr.addr[2],
uip_ethaddr.addr[3], uip_ethaddr.addr[4], uip_ethaddr.addr[5]);
}

// Requires a buffer of at least 16 bytes to format into
void NanodeUIP::format_ipaddr(char *buf,uint16_t *addr) {
sprintf(buf,"%d.%d.%d.%d",addr[0]&0xff,addr[0]>>8,
sprintf_P(buf,PSTR("%d.%d.%d.%d"),addr[0]&0xff,addr[0]>>8,
addr[1]&0xff,addr[1]>>8);
}

Expand Down
3 changes: 3 additions & 0 deletions NanodeUIP.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@
#else
#include <WProgram.h> // Arduino 0022
#endif
#include <avr/pgmspace.h>

#include "uip.h"
#include "timer.h"

extern void resolv_conf(const uint16_t *dnsserver);
extern void nanode_log(char *msg);
extern void nanode_log_P(PGM_P msg);

#define DHCP_STATUS_OK 1
#define DHCP_STATUS_DOWN 0
Expand Down
224 changes: 224 additions & 0 deletions examples/telnet_server/Jamfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,224 @@
# (1) Project Information

PROJECT_LIBS = SPI NanodeUIP NanodeUNIO ;
PROJECT_DIRS = $(PWD) ;

# (2) Board Information

UPLOAD_PROTOCOL ?= arduino ;
UPLOAD_SPEED ?= 57600 ;
MCU ?= atmega328p ;
F_CPU ?= 16000000 ;
CORE ?= arduino ;
VARIANT ?= standard ;
ARDUINO_VERSION ?= 100 ;

# (3) USB Ports

PORTS = p4 p6 p9 u0 u1 u2 ;
PORT_p6 = /dev/tty.usbserial-A600eHIs ;
PORT_p4 = /dev/tty.usbserial-A40081RP ;
PORT_p9 = /dev/tty.usbserial-A9007LmI ;
PORT_u0 = /dev/ttyUSB0 ;
PORT_u1 = /dev/ttyUSB1 ;
PORT_u2 = /dev/ttyUSB2 ;

# (4) Location of AVR tools
#
# This configuration assumes using avr-tools that were obtained separate from the Arduino
# distribution.

if $(OS) = MACOSX
{
AVR_BIN = /usr/local/avrtools/bin ;
AVR_ETC = /usr/local/avrtools/etc ;
AVR_INCLUDE = /usr/local/avrtools/include ;
}
else
{
AVR_BIN = /usr/bin ;
AVR_INCLUDE = /usr/lib/avr/include ;
AVR_ETC = /etc ;
}

# (5) Directories where Arduino core and libraries are located

ARDUINO_DIR ?= /opt/Arduino ;
ARDUINO_CORE = $(ARDUINO_DIR)/hardware/arduino/cores/$(CORE) $(ARDUINO_DIR)/hardware/arduino/variants/$(VARIANT) ;
ARDUINO_LIB = $(ARDUINO_DIR)/libraries ;
SKETCH_LIB = $(HOME)/Source/Arduino/libraries ;

#
# --------------------------------------------------
# Below this line usually never needs to be modified
#

# Tool locations

CC = $(AVR_BIN)/avr-gcc ;
C++ = $(AVR_BIN)/avr-g++ ;
LINK = $(AVR_BIN)/avr-gcc ;
AR = $(AVR_BIN)/avr-ar rcs ;
RANLIB = ;
OBJCOPY = $(AVR_BIN)/avr-objcopy ;
AVRDUDE = $(AVR_BIN)/avrdude ;

# Flags

DEFINES += F_CPU=$(F_CPU)L ARDUINO=$(ARDUINO_VERSION) VERSION_H ;
OPTIM = -Os ;
CCFLAGS = -Wall -Wextra -Wno-strict-aliasing -mmcu=$(MCU) -ffunction-sections -fdata-sections ;
C++FLAGS = $(CCFLAGS) -fno-exceptions -fno-strict-aliasing ;
LINKFLAGS = $(OPTIM) -lm -Wl,--gc-sections -mmcu=$(MCU) ;
AVRDUDEFLAGS = -V -F -D -C $(AVR_ETC)/avrdude.conf -p $(MCU) -c $(UPLOAD_PROTOCOL) -b $(UPLOAD_SPEED) ;

# Search everywhere for headers

HDRS = $(PROJECT_DIRS) $(AVR_INCLUDE) $(ARDUINO_CORE) $(ARDUINO_LIB)/$(PROJECT_LIBS) $(ARDUINO_LIB)/$(PROJECT_LIBS)/utility $(SKETCH_LIB)/$(PROJECT_LIBS) ;

# Output locations

LOCATE_TARGET = $(F_CPU) ;
LOCATE_SOURCE = $(F_CPU) ;

#
# Custom rules
#

rule GitVersion
{
Always $(<) ;
Depends all : $(<) ;
}

actions GitVersion
{
echo "const char program_version[] = \"\\" > $(<)
git log -1 --pretty=format:%h >> $(<)
echo "\";" >> $(<)
}

GitVersion version.h ;

rule Pde
{
Depends $(<) : $(>) ;
MakeLocate $(<) : $(LOCATE_SOURCE) ;
Clean clean : $(<) ;
}

if ( $(ARDUINO_VERSION) < 100 )
{
ARDUINO_H = WProgram.h ;
}
else
{
ARDUINO_H = Arduino.h ;
}

actions Pde
{
echo "#include <$(ARDUINO_H)>" > $(<)
echo "#line 1 \"$(>)\"" >> $(<)
cat $(>) >> $(<)
}

rule C++Pde
{
local _CPP = $(>:B).cpp ;
Pde $(_CPP) : $(>) ;
C++ $(<) : $(_CPP) ;
}

rule UserObject
{
switch $(>:S)
{
case .ino : C++Pde $(<) : $(>) ;
case .pde : C++Pde $(<) : $(>) ;
}
}

rule Objects
{
local _i ;

for _i in [ FGristFiles $(<) ]
{
local _b = $(_i:B)$(SUFOBJ) ;
local _o = $(_b:G=$(SOURCE_GRIST:E)) ;
Object $(_o) : $(_i) ;
Depends obj : $(_o) ;
}
}

actions Link bind NEEDLIBS
{
$(LINK) $(LINKFLAGS) -o $(<) $(UNDEFS) $(NEEDLIBS) $(LINKLIBS) $(>)
}

rule Library
{
LibraryFromObjects $(<) : $(>:B)$(SUFOBJ) ;
Objects $(>) ;
}

rule Main
{
MainFromObjects $(<) : $(>:B)$(SUFOBJ) ;
Objects $(>) ;
}

rule Hex
{
Depends $(<) : $(>) ;
MakeLocate $(<) : $(LOCATE_TARGET) ;
Depends hex : $(<) ;
Clean clean : $(<) ;
}

actions Hex
{
$(OBJCOPY) -O ihex -R .eeprom $(>) $(<)
}

rule Upload
{
Depends $(1) : $(2) ;
Depends $(2) : $(3) ;
NotFile $(1) ;
Always $(1) ;
Always $(2) ;
UploadAction $(2) : $(3) ;
}

actions UploadAction
{
$(AVRDUDE) $(AVRDUDEFLAGS) -P $(<) $(AVRDUDE_WRITE_FLASH) -U flash:w:$(>):i
}

rule Arduino
{
LINKFLAGS on $(<) = $(LINKFLAGS) -Wl,-Map=$(LOCATE_TARGET)/$(<:B).map ;
#LinkLibraries $(<) : core libs ;
Main $(<) : $(>) ;
Hex $(<:B).hex : $(<) ;
for _p in $(PORTS)
{
Upload $(_p) : $(PORT_$(_p)) : $(<:B).hex ;
}
}

#
# Targets
#

# Grab everything from the core directory
#Library core : [ GLOB $(ARDUINO_CORE) : *.c *.cpp ] ;

# Grab everything from libraries. To avoid this "grab everything" behaviour, you
# can specify specific modules to pick up in PROJECT_MODULES
#Library libs : [ GLOB $(ARDUINO_LIB)/$(PROJECT_LIBS) $(ARDUINO_LIB)/$(PROJECT_LIBS)/utility $(SKETCH_LIB)/$(PROJECT_LIBS) : *.cpp *.c ] ;

# Main output executable
Arduino $(PWD:B).elf : $(PROJECT_MODULES) [ GLOB $(ARDUINO_CORE) : *.c *.cpp ] [ GLOB $(ARDUINO_LIB)/$(PROJECT_LIBS) $(ARDUINO_LIB)/$(PROJECT_LIBS)/utility $(SKETCH_LIB)/$(PROJECT_LIBS) : *.cpp *.c ] [ GLOB $(PROJECT_DIRS) : *.c *.cpp *.pde *.ino ] ;
104 changes: 104 additions & 0 deletions examples/telnet_server/memb.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/*
* Copyright (c) 2004, Swedish Institute of Computer Science.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. 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 uIP TCP/IP stack
*
* Author: Adam Dunkels <adam@sics.se>
*
* $Id: memb.c,v 1.1 2006/06/12 08:21:43 adam Exp $
*/

/**
* \addtogroup memb
* @{
*/

/**
* \file
* Memory block allocation routines.
* \author Adam Dunkels <adam@sics.se>
*/
#include <string.h>

#include "memb.h"

/*---------------------------------------------------------------------------*/
void
memb_init(struct memb_blocks *m)
{
memset(m->count, 0, m->num);
memset(m->mem, 0, m->size * m->num);
}
/*---------------------------------------------------------------------------*/
void *
memb_alloc(struct memb_blocks *m)
{
int i;

for(i = 0; i < m->num; ++i) {
if(m->count[i] == 0) {
/* If this block was unused, we increase the reference count to
indicate that it now is used and return a pointer to the
memory block. */
++(m->count[i]);
return (void *)((char *)m->mem + (i * m->size));
}
}

/* No free block was found, so we return NULL to indicate failure to
allocate block. */
return NULL;
}
/*---------------------------------------------------------------------------*/
char
memb_free(struct memb_blocks *m, void *ptr)
{
int i;
char *ptr2;

/* Walk through the list of blocks and try to find the block to
which the pointer "ptr" points to. */
ptr2 = (char *)m->mem;
for(i = 0; i < m->num; ++i) {

if(ptr2 == (char *)ptr) {
/* We've found to block to which "ptr" points so we decrease the
reference count and return the new value of it. */
if(m->count[i] > 0) {
/* Make sure that we don't deallocate free memory. */
--(m->count[i]);
}
return m->count[i];
}
ptr2 += m->size;
}
return -1;
}
/*---------------------------------------------------------------------------*/

/** @} */
Loading