Initial PicoRV32 target

This commit is contained in:
Ralf Schlatterbeck 2016-03-31 12:47:05 +02:00
parent 743245e230
commit 57959a53f6
17 changed files with 1714 additions and 0 deletions

View file

@ -0,0 +1,77 @@
CONTIKI_CPU_DIRS = . dev
### Define the CPU directory of the AVR port
CONTIKI_CPU=$(CONTIKI)/cpu/pico-rv32
PICORV32_SOURCES = mtarch.c rtimer-arch.c clock.c watchdog.c
CONTIKI_TARGET_SOURCEFILES += $(PICORV32_SOURCES) $(SENSORS) $(SYSAPPS) \
nullsec.c
CONTIKI_SOURCEFILES += $(CONTIKI_TARGET_SOURCEFILES)
### Compiler definitions
CC = riscv32-unknown-elf-gcc
CXX = riscv32-unknown-elf-g++
LD = riscv32-unknown-elf-gcc
AS = riscv32-unknown-elf-as
AR = riscv32-unknown-elf-ar
ELF_SIZE = riscv32-unknown-elf-size
NM = riscv32-unknown-elf-nm
OBJCOPY = riscv32-unknown-elf-objcopy
STRIP = riscv32-unknown-elf-strip
ifdef WERROR
CFLAGSWERROR=-Werror
endif
CFLAGSNO = -Wall -g \
-I$(CONTIKI)/platform/$(TARGET) \
-I. -I$(CONTIKI)/core -I$(CONTIKI_CPU)
CFLAGS += $(CFLAGSNO) -Os
ifeq ($(HOST_OS),Darwin)
AROPTS = -r
LDFLAGS += -Wl,-flat_namespace
CFLAGS += -DHAVE_SNPRINTF=1 -U__ASSERT_USE_STDERR
else
ifeq ($(HOST_OS),Linux)
LDFLAGS += -Wl,-Map=contiki-$(TARGET).map,-export-dynamic
endif
endif
### Setup directory search path for source files
CONTIKI_TARGET_DIRS_CONCAT = ${addprefix $(CONTIKI)/platform/$(TARGET)/, \
$(CONTIKI_TARGET_DIRS)}
### Compilation rules
# Vertical bar | symbol denotes an order-only dependency: Timestamp is
# ignored on the directory (otherwise everything would be rebuilt
# everytime)
$(OBJECTDIR)/%.o: %.c | $(OBJECTDIR)
$(CC) $(CFLAGS) -c $< -o $@
%.o: %.c
$(CC) $(CFLAGS) -c $< -o $@
$(OBJECTDIR)/%.o: %.cpp | $(OBJECTDIR)
$(CXX) $(CFLAGS) -c $< -o $@
%.o: %.cpp
$(CXX) $(CFLAGS) -c $< -o $@
%.ko: %.o
$(STRIP) -K _init -K _fini --strip-unneeded -g -x $< -o $@
%.elf: %.co $(PROJECT_OBJECTFILES) contiki-$(TARGET).a symbols.o
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(filter-out %.a,$^) \
$(filter %.a,$^) $(LDLIBS)
%.hex: %.$(TARGET)
$(OBJCOPY) $^ -j .text -j .data -O ihex $@
%.ihex: %.$(TARGET)
$(OBJCOPY) $^ -O ihex $@
%-stripped.o: %.o
$(STRIP) --strip-unneeded -g -x -o $@ $<

184
cpu/pico-rv32/dev/clock.c Normal file
View file

@ -0,0 +1,184 @@
/*
* Copyright (c) 2016, Dr. Ralf Schlatterbeck Open Source Consulting
* 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.
*
*/
/**
* \brief This module contains PicoRV32-specific code to implement
* the Contiki core clock functions.
*
* \author Ralf Schlatterbeck <rsc@runtux.com>.
*
*/
/** \addtogroup picorv32
* @{
*/
/**
* \defgroup picorv32clock PicoRV32 clock implementation
* @{
*/
/**
* \file
* This file contains PicoRV32-specific code to implement the Contiki
* core clock functions.
*
*/
/**
* These routines define the PicoRV32-specific calls declared in
* /core/sys/clock.h CLOCK_SECOND is the number of ticks per second.
* It is defined through CONF_CLOCK_SECOND in the contiki-conf.h for
* each platform.
* The usual AVR defaults are 128 or 125 ticks per second, counting a
* prescaled CPU clock using the 8 bit timer0.
*
* clock_time_t is usually declared by the platform as an unsigned 16
* bit data type, thus intervals up to 512 or 524 seconds can be
* measured with ~8 millisecond precision.
* For longer intervals the 32 bit clock_seconds() is available.
*/
#include "sys/clock.h"
#include "sys/etimer.h"
static volatile clock_time_t count;
volatile unsigned long seconds;
long sleepseconds;
/*---------------------------------------------------------------------------*/
/**
* Start the clock by enabling the timer comparison interrupts.
*/
void
clock_init(void)
{
//cli ();
//OCRSetup();
//sei ();
}
/*---------------------------------------------------------------------------*/
/**
* Return the tick counter. When 16 bit it typically wraps every 10 minutes.
* The comparison avoids the need to disable clock interrupts for an atomic
* read of the multi-byte variable.
*/
clock_time_t
clock_time(void)
{
static clock_time_t counter = 0;
return counter++;
}
/*---------------------------------------------------------------------------*/
/**
* Return seconds, default is time since startup.
* The comparison avoids the need to disable clock interrupts for an atomic
* read of the four-byte variable.
*/
unsigned long
clock_seconds(void)
{
unsigned long tmp;
do {
tmp = seconds;
} while(tmp != seconds);
return tmp;
}
/*---------------------------------------------------------------------------*/
/**
* Set seconds, e.g. to a standard epoch for an absolute date/time.
*/
void
clock_set_seconds(unsigned long sec)
{
seconds = sec;
}
/*---------------------------------------------------------------------------*/
/*
* Wait for a number of clock ticks.
*/
void
clock_wait(clock_time_t t)
{
clock_time_t endticks = clock_time() + t;
if (sizeof(clock_time_t) == 1) {
while ((signed char )(clock_time() - endticks) < 0) {;}
} else if (sizeof(clock_time_t) == 2) {
while ((signed short)(clock_time() - endticks) < 0) {;}
} else {
while ((signed long )(clock_time() - endticks) < 0) {;}
}
}
/*---------------------------------------------------------------------------*/
void
clock_delay_usec(uint16_t dt)
{
}
/*---------------------------------------------------------------------------*/
/**
* Delay up to 65535 milliseconds.
* \param howlong How many milliseconds to delay.
*
* Neither interrupts nor the watchdog timer is disabled over the delay.
* Platforms are not required to implement this call.
* \note This will break for CPUs clocked above 260 MHz.
*/
void
clock_delay_msec(uint16_t howlong)
{
#if F_CPU>=16000000
while(howlong--) clock_delay_usec(1000);
#elif F_CPU>=8000000
uint16_t i=996;
while(howlong--) {clock_delay_usec(i);i=999;}
#elif F_CPU>=4000000
uint16_t i=992;
while(howlong--) {clock_delay_usec(i);i=999;}
#elif F_CPU>=2000000
uint16_t i=989;
while(howlong--) {clock_delay_usec(i);i=999;}
#else
uint16_t i=983;
while(howlong--) {clock_delay_usec(i);i=999;}
#endif
}
/*---------------------------------------------------------------------------*/
/**
* Adjust the system current clock time.
* \param howmany How many ticks to add
*
* Typically used to add ticks after an MCU sleep
* clock_seconds will increment if necessary to reflect the tick addition.
* Leap ticks or seconds can (rarely) be introduced if the ISR is not blocked.
*/
void
clock_adjust_ticks(clock_time_t howmany)
{
}
/** @} */
/** @} */

159
cpu/pico-rv32/mtarch.c Normal file
View file

@ -0,0 +1,159 @@
/*
* Copyright (c) 2016, Dr. Ralf Schlatterbeck Open Source Consulting
* 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.
*
* \file PicoRV32 specific implementation of multithreading architecture
*
* \author Ralf Schlatterbeck <rsc@runtux.com>
*
*/
#include <stdio.h>
#include "sys/mt.h"
/*--------------------------------------------------------------------------*/
void
mtarch_init(void)
{
}
/*--------------------------------------------------------------------------*/
void
mtarch_start(struct mtarch_thread *t,
void (*function)(void *), void *data)
{
/* Initialize stack with number sequence (used for
* measuring stack usage */
uint8_t i;
for(i = 0; i < MTARCH_STACKSIZE; ++i) {
t->stack[i] = i;
}
/*
* Push pointer to mt_exit and the thread onto our stack:
* Caveats:
* - The stack is defined as an array of bytes, but pointers are 32 bit wide
* - Function pointers are 32-bit addresses in flash ROM
*/
/* Initialize stack. This is done in reverse order ("pushing") the
* pre-allocated array */
/* mt_exit function that is to be invoked if the thread dies
* function is the thread handler. Invoked when RET is called in mtarch_exec
*/
*((uint32_t *)(t->stack + MTARCH_STACKSIZE - 4)) = (uint32_t)mt_exit;
*((uint32_t *)(t->stack + MTARCH_STACKSIZE - 8)) = (uint32_t)function;
/* FIXME: Push args to function and saved registers, check calling
* conventions
*/
/* Initialize stack pointer: Space for 2 2-byte-addresses and 32 registers,
* post-decrement POP / pre-increment PUSH scheme
* FIXME: Need to calculate correct address here
*/
t->sp = &t->stack[MTARCH_STACKSIZE - 1 - 4 - 32];
}
/*--------------------------------------------------------------------------*/
static unsigned char *sptmp;
static struct mtarch_thread *running;
static void
sw(void)
{
/* Disable interrupts while we perform the context switch */
//cli ();
/* Push 32 general purpuse registers */
/* Switch stack pointer */
sptmp = running->sp;
//running->sp = (unsigned char*)SP;
//SP = (unsigned short)sptmp;
/* Pop 32 general purpose registers */
/* Renable interrupts */
//sei ();
}
/*--------------------------------------------------------------------------*/
void
mtarch_exec(struct mtarch_thread *t)
{
running = t;
sw();
running = NULL;
}
/*--------------------------------------------------------------------------*/
void
mtarch_remove(void)
{
}
/*--------------------------------------------------------------------------*/
void
mtarch_yield(void)
{
sw();
}
/*--------------------------------------------------------------------------*/
void
mtarch_pstop(void)
{
}
/*--------------------------------------------------------------------------*/
void
mtarch_pstart(void)
{
}
/*--------------------------------------------------------------------------*/
void
mtarch_stop(struct mtarch_thread *t)
{
}
/*--------------------------------------------------------------------------*/
int
mtarch_stack_usage(struct mt_thread *t)
{
uint8_t i;
for(i = 0; i < MTARCH_STACKSIZE; ++i) {
if(t->thread.stack[i] != i) {
break;
}
}
return MTARCH_STACKSIZE - i;
}
/*--------------------------------------------------------------------------*/

56
cpu/pico-rv32/mtarch.h Normal file
View file

@ -0,0 +1,56 @@
/*
* Copyright (c) 2016, Dr. Ralf Schlatterbeck Open Source Consulting
* 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.
*/
/**
* \file
* PicoRV32 specific implementation of multithreading architecture
* \author
* Ralf Schlatterbeck <rsc@runtux.com>
*
*/
#ifndef MTARCH_H_
#define MTARCH_H_
#include "contiki-conf.h"
#ifdef MTARCH_CONF_STACKSIZE
#define MTARCH_STACKSIZE MTARCH_CONF_STACKSIZE
#else
#define MTARCH_STACKSIZE 512
#endif
struct mtarch_thread {
unsigned char stack[MTARCH_STACKSIZE];
unsigned char *sp;
};
#endif /* MTARCH_H_ */

View file

@ -0,0 +1,53 @@
/*
* Copyright (c) 2016, Dr. Ralf Schlatterbeck Open Source Consulting
* 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.
*
*/
/**
* \file
* PicoRV32-specific rtimer code
* \author
* Ralf Schlatterbeck <rsc@runtux.com>
*/
#include <stdio.h>
#include "sys/rtimer.h"
#include "rtimer-arch.h"
void
rtimer_arch_init(void)
{
}
/*---------------------------------------------------------------------------*/
void
rtimer_arch_schedule(rtimer_clock_t t)
{
}

View file

@ -0,0 +1,44 @@
/*
* Copyright (c) 2016, Dr. Ralf Schlatterbeck Open Source Consulting
* 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.
*
*/
#ifndef RTIMER_ARCH_H_
#define RTIMER_ARCH_H_
#include <sys/clock.h>
// FIXME
#define RTIMER_ARCH_SECOND 23
#define rtimer_arch_now() (clock_time ())
void rtimer_arch_sleep(rtimer_clock_t howlong);
#endif /* RTIMER_ARCH_H_ */

51
cpu/pico-rv32/rv32def.h Normal file
View file

@ -0,0 +1,51 @@
/*
* Copyright (c) 2016, Dr. Ralf Schlatterbeck Open Source Consulting
* 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.
*
*/
#ifndef RV32DEF_H
#define RV32DEF_H
typedef unsigned char uint8_t;
typedef unsigned short uint16_t;
typedef unsigned long uint32_t;
typedef unsigned long long uint64_t;
typedef signed char int8_t;
typedef short int16_t;
typedef long int32_t;
typedef long long int64_t;
//void cpu_init(void);
//void *sbrk(int);
//typedef unsigned char spl_t;
//static inline void splx(spl_t s) { SREG = s; }
//static inline spl_t splhigh(void) { spl_t s = SREG; cli(); return s; }
#endif /* RV32DEF_H */

62
cpu/pico-rv32/watchdog.c Normal file
View file

@ -0,0 +1,62 @@
/*
* Copyright (c) 2016, Dr. Ralf Schlatterbeck Open Source Consulting
* 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.
*
*/
/* Dummy Watchdog routines for the PicoRV32 */
#include "dev/watchdog.h"
/*---------------------------------------------------------------------------*/
void
watchdog_init(void)
{
}
/*---------------------------------------------------------------------------*/
void
watchdog_start(void)
{
}
/*---------------------------------------------------------------------------*/
void
watchdog_periodic(void)
{
}
/*---------------------------------------------------------------------------*/
void
watchdog_stop(void)
{
}
/*---------------------------------------------------------------------------*/
void
watchdog_reboot(void)
{
}
/*---------------------------------------------------------------------------*/

View file

@ -0,0 +1,40 @@
ifeq ($(TARGET), osd-merkur)
PLATFORM_FILES= avr-size wallclock.osd-merkur.hex \
wallclock.osd-merkur.eep
endif
ifeq ($(TARGET), pico-rv32-icoboard)
PLATFORM_FILES= appimage.hex
endif
ifeq ($(ICOTOOLS),)
ICOTOOLS=/usr/local/src/unpacked/icotools
endif
all: wallclock.$(TARGET) $(PLATFORM_FILES)
# use target "er-plugtest-server" explicitly when requried
CONTIKI=../../..
CFLAGS += -DPROJECT_CONF_H=\"project-conf.h\"
PROJECTDIRS += $(REST_RESOURCES_DIR) $(REST_RESOURCES_DIR_COMMON)
PROJECT_SOURCEFILES += $(REST_RESOURCES_FILES)
# REST Engine shall use Erbium CoAP implementation
APPS += er-coap
APPS += rest-engine
APPS += json json-resource time
CONTIKI_WITH_IPV6 = 1
include $(CONTIKI)/Makefile.include
appimage.hex: wallclock.pico-rv32-icoboard
riscv32-unknown-elf-objcopy -O verilog wallclock.pico-rv32-icoboard \
appimage.hex
icosoc.mk: icosoc.cfg
$(ICOTOOLS)/icosoc/icosoc.py -c
include icosoc.mk
CLEAN += appimage.hex wallclock.$(TARGET)
-include *.d

View file

@ -0,0 +1,15 @@
# hello world example
# Digilent PmodUSBUART on PMOD3
# http://store.digilentinc.com/pmodusbuart-usb-to-uart-interface/
mod rs232 ser0
address 1
param BAUD_RATE 115200
connect rx pmod3_3
connect tx pmod3_2
# Digilent Pmod8LD in PMOD1 and PMOD2
mod gpio leds
address 2
connect IO pmod2 pmod1

View file

@ -0,0 +1,101 @@
/*
* 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.
*
*
*/
#ifndef PROJECT_RPL_WEB_CONF_H_
#define PROJECT_RPL_WEB_CONF_H_
#define PLATFORM_HAS_LEDS 1
//#define PLATFORM_HAS_BUTTON 1
#define PLATFORM_HAS_BATTERY 1
#define SICSLOWPAN_CONF_FRAG 1
/* For Debug: Dont allow MCU sleeping between channel checks */
#undef RDC_CONF_MCU_SLEEP
#define RDC_CONF_MCU_SLEEP 0
/* Disabling RDC for demo purposes. Core updates often require more memory. */
/* For projects, optimize memory and enable RDC again. */
// #undef NETSTACK_CONF_RDC
//#define NETSTACK_CONF_RDC nullrdc_driver
/* Increase rpl-border-router IP-buffer when using more than 64. */
#undef REST_MAX_CHUNK_SIZE
#define REST_MAX_CHUNK_SIZE 64
/* Estimate your header size, especially when using Proxy-Uri. */
/*
#undef COAP_MAX_HEADER_SIZE
#define COAP_MAX_HEADER_SIZE 70
*/
/* The IP buffer size must fit all other hops, in particular the border router. */
#undef UIP_CONF_BUFFER_SIZE
#define UIP_CONF_BUFFER_SIZE 256
/* Multiplies with chunk size, be aware of memory constraints. */
#undef COAP_MAX_OPEN_TRANSACTIONS
#define COAP_MAX_OPEN_TRANSACTIONS 4
/* Must be <= open transaction number, default is COAP_MAX_OPEN_TRANSACTIONS-1. */
/*
#undef COAP_MAX_OBSERVERS
#define COAP_MAX_OBSERVERS 2
*/
/* Filtering .well-known/core per query can be disabled to save space. */
/*
#undef COAP_LINK_FORMAT_FILTERING
#define COAP_LINK_FORMAT_FILTERING 0
*/
/* Save some memory for the sky platform. */
/*
#undef NBR_TABLE_CONF_MAX_NEIGHBORS
#define NBR_TABLE_CONF_MAX_NEIGHBORS 10
#undef UIP_CONF_MAX_ROUTES
#define UIP_CONF_MAX_ROUTES 10
*/
/* Reduce 802.15.4 frame queue to save RAM. */
/*
#undef QUEUEBUF_CONF_NUM
#define QUEUEBUF_CONF_NUM 4
*/
/*
#undef SICSLOWPAN_CONF_FRAG
#define SICSLOWPAN_CONF_FRAG 1
*/
#endif /* PROJECT_RPL_WEB_CONF_H_ */

View file

@ -0,0 +1,136 @@
/*
* Copyright (C) 2016, Ralf Schlatterbeck and other contributors.
* 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.
*/
/**
* \file
* Erbium (Er) Wallclock REST Engine example (with CoAP-specific code)
* \author
* Matthias Kovatsch <kovatsch@inf.ethz.ch>
* Ralf Schlatterbeck <rsc@runtux.com>
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "contiki.h"
#include "contiki-net.h"
#include "er-coap-engine.h"
#include "time.h"
#include "cron.h"
#include "time_resource.h"
#include "jsonparse.h"
#include "icosoc.h"
#define DEBUG 0
#if DEBUG
#include <stdio.h>
#define PRINTF(...) printf(__VA_ARGS__)
#define PRINT6ADDR(addr) PRINTF("[%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x]", ((uint8_t *)addr)[0], ((uint8_t *)addr)[1], ((uint8_t *)addr)[2], ((uint8_t *)addr)[3], ((uint8_t *)addr)[4], ((uint8_t *)addr)[5], ((uint8_t *)addr)[6], ((uint8_t *)addr)[7], ((uint8_t *)addr)[8], ((uint8_t *)addr)[9], ((uint8_t *)addr)[10], ((uint8_t *)addr)[11], ((uint8_t *)addr)[12], ((uint8_t *)addr)[13], ((uint8_t *)addr)[14], ((uint8_t *)addr)[15])
#define PRINTLLADDR(lladdr) PRINTF("[%02x:%02x:%02x:%02x:%02x:%02x]", (lladdr)->addr[0], (lladdr)->addr[1], (lladdr)->addr[2], (lladdr)->addr[3], (lladdr)->addr[4], (lladdr)->addr[5])
#else
#define PRINTF(...)
#define PRINT6ADDR(addr)
#define PRINTLLADDR(addr)
#endif
void
hw_init ()
{
icosoc_leds_dir (0xFFFF);
icosoc_leds_set (0);
}
PROCESS (wallclock, "Wallclock Example Server");
AUTOSTART_PROCESSES(&wallclock);
#define LOOP_INTERVAL (30 * CLOCK_SECOND)
/*
* Set led to on or off, we abuse the given pointer to simply carry the
* on/off flag.
*/
void led_set (void *onoff)
{
int status = (int)onoff;
icosoc_leds_set (0xFF * status);
}
PROCESS_THREAD(wallclock, ev, data)
{
static struct etimer loop_periodic_timer;
PROCESS_BEGIN();
PRINTF("Starting Wallclock Example\n");
#ifdef RF_CHANNEL
PRINTF("RF channel: %u\n", RF_CHANNEL);
#endif
#ifdef IEEE802154_PANID
PRINTF("PAN ID: 0x%04X\n", IEEE802154_PANID);
#endif
PRINTF("uIP buffer: %u\n", UIP_BUFSIZE);
PRINTF("LL header: %u\n", UIP_LLH_LEN);
PRINTF("IP+UDP header: %u\n", UIP_IPUDPH_LEN);
PRINTF("REST max chunk: %u\n", REST_MAX_CHUNK_SIZE);
/* Initialize the Hardware. */
hw_init ();
/* Initialize the REST engine. */
rest_init_engine ();
rest_activate_resource (&res_timestamp, "clock/timestamp");
rest_activate_resource (&res_timezone, "clock/timezone");
rest_activate_resource (&res_localtime, "clock/localtime");
rest_activate_resource (&res_utc, "clock/utc");
/* Register callback function(s) */
cron_register_command ("led_on", led_set, (void *)1);
cron_register_command ("led_off", led_set, (void *)0);
/* Allocate all cron entries and the necessary resources */
activate_cron_resources ();
/* Define application-specific events here.
* We need to call cron every 30 seconds or so (at least once a
* minute)
*/
etimer_set (&loop_periodic_timer, LOOP_INTERVAL);
while (1) {
PROCESS_WAIT_EVENT();
if (etimer_expired (&loop_periodic_timer)) {
cron ();
etimer_reset (&loop_periodic_timer);
}
} /* while (1) */
PROCESS_END();
}

View file

@ -0,0 +1,16 @@
CONTIKI_TARGET_DIRS = . apps net loader
CONTIKI_CORE=contiki-main
CONTIKI_TARGET_MAIN = ${CONTIKI_CORE}.o
CONTIKI_TARGET_SOURCEFILES += contiki-main.c params.c
CONTIKIPICORV32=$(CONTIKI)/cpu/pico-rv32
CONTIKIBOARD=.
CONTIKI_PLAT_DEFS = -DF_CPU=8000000UL -DAUTO_CRC_PADDING=2
MCU=pico-rv32
include $(CONTIKIPICORV32)/Makefile.pico-rv32
#include $(CONTIKIPICORV32)/radio/Makefile.radio
MODULES += core/net/mac core/net core/net/mac/sicslowmac core/net/mac/contikimac

View file

@ -0,0 +1,204 @@
/*
* Copyright (c) 2016, Dr. Ralf Schlatterbeck Open Source Consulting
* 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.
*
* @(#)$$
*/
/**
* \file
* Configuration for PicoRV32 on icoboard
* \author
* Ralf Schlatterbeck <rsc@runtux.com>
*/
#ifndef CONTIKI_CONF_H_
#define CONTIKI_CONF_H_
#include "rv32def.h"
/* Platform name, type, and MCU clock rate */
#define PLATFORM_NAME "PicoRV32-icoboard"
#define PLATFORM_TYPE PICORV32
#ifndef F_CPU
#define F_CPU 8000000UL
#endif
/* The AVR tick interrupt usually is done with an 8 bit counter around 128 Hz.
* 125 Hz needs slightly more overhead during the interrupt, as does a 32 bit
* clock_time_t.
*/
/* Clock ticks per second */
#define CLOCK_CONF_SECOND 128
typedef uint32_t clock_time_t;
#define CLOCK_LT(a,b) ((int32_t)((a)-(b)) < 0)
/* RADIOSTATS is used in rf230bb, clock.c and the webserver cgi to report radio usage */
/* It has less overhead than ENERGEST */
#define RADIOSTATS 1
/* More extensive stats, via main loop printfs or webserver status pages */
#define ENERGEST_CONF_ON 1
/* Packet statistics */
typedef unsigned short uip_stats_t;
#define UIP_STATISTICS 0
/* Network setup */
/* TX routine passes the cca/ack result in the return parameter */
#define RDC_CONF_HARDWARE_ACK 1
/* TX routine does automatic cca and optional backoffs */
#define RDC_CONF_HARDWARE_CSMA 1
/* Allow MCU sleeping between channel checks */
#define RDC_CONF_MCU_SLEEP 1
#if NETSTACK_CONF_WITH_IPV6
#define LINKADDR_CONF_SIZE 8
#define UIP_CONF_ICMP6 1
#define UIP_CONF_UDP 1
#define UIP_CONF_TCP 1
#define NETSTACK_CONF_NETWORK sicslowpan_driver
#define SICSLOWPAN_CONF_COMPRESSION SICSLOWPAN_COMPRESSION_HC06
#else
/* ip4 should build but is largely untested */
#define LINKADDR_CONF_SIZE 2
#define NETSTACK_CONF_NETWORK rime_driver
#endif
#define UIP_CONF_LL_802154 1
#define UIP_CONF_LLH_LEN 0
/* 10 bytes per stateful address context - see sicslowpan.c */
/* Default is 1 context with prefix aaaa::/64 */
/* These must agree with all the other nodes or there will be a failure to communicate! */
#define SICSLOWPAN_CONF_MAX_ADDR_CONTEXTS 1
#define SICSLOWPAN_CONF_ADDR_CONTEXT_0 {addr_contexts[0].prefix[0]=0xaa;addr_contexts[0].prefix[1]=0xaa;}
#define SICSLOWPAN_CONF_ADDR_CONTEXT_1 {addr_contexts[1].prefix[0]=0xbb;addr_contexts[1].prefix[1]=0xbb;}
#define SICSLOWPAN_CONF_ADDR_CONTEXT_2 {addr_contexts[2].prefix[0]=0x20;addr_contexts[2].prefix[1]=0x01;addr_contexts[2].prefix[2]=0x49;addr_contexts[2].prefix[3]=0x78,addr_contexts[2].prefix[4]=0x1d;addr_contexts[2].prefix[5]=0xb1;}
/* Take the default TCP maximum segment size for efficiency and simpler wireshark captures */
/* Use this to prevent 6LowPAN fragmentation (whether or not fragmentation is enabled) */
//#define UIP_CONF_TCP_MSS 48
#define UIP_CONF_IP_FORWARD 0
#define UIP_CONF_FWCACHE_SIZE 0
#define UIP_CONF_IPV6_CHECKS 1
#define UIP_CONF_IPV6_QUEUE_PKT 1
#define UIP_CONF_IPV6_REASSEMBLY 0
#define UIP_CONF_UDP_CHECKSUMS 1
#define UIP_CONF_TCP_SPLIT 1
#define UIP_CONF_DHCP_LIGHT 1
#if 1 /* No radio cycling */
#define NETSTACK_CONF_MAC nullmac_driver
#define NETSTACK_CONF_RDC sicslowmac_driver
#define NETSTACK_CONF_FRAMER framer_802154
//#define NETSTACK_CONF_RADIO rf230_driver
#define CHANNEL_802_15_4 26
/* AUTOACK receive mode gives better rssi measurements, even if ACK is never requested */
#define RF230_CONF_AUTOACK 1
/* 1 + Number of auto retry attempts 0-15 (0 implies don't use extended TX_ARET_ON mode) */
#define RF230_CONF_FRAME_RETRIES 2
/* Number of csma retry attempts 0-5 in extended tx mode (7 does immediate tx with no csma) */
#define RF230_CONF_CSMA_RETRIES 5
/* Default is one RAM buffer for received packets. More than one may benefit multiple TCP connections or ports */
#define RF230_CONF_RX_BUFFERS 3
#define SICSLOWPAN_CONF_FRAG 1
/* Most browsers reissue GETs after 3 seconds which stops fragment reassembly so a longer MAXAGE does no good */
#define SICSLOWPAN_CONF_MAXAGE 3
/* How long to wait before terminating an idle TCP connection. Smaller to allow faster sleep. Default is 120 seconds */
/* If wait is too short the connection can be reset as a result of multiple fragment reassembly timeouts */
#define UIP_CONF_WAIT_TIMEOUT 20
/* 211 bytes per queue buffer */
#define QUEUEBUF_CONF_NUM 8
/* 54 bytes per queue ref buffer */
#define QUEUEBUF_CONF_REF_NUM 2
/* Allocate remaining RAM as desired */
/* 30 bytes per TCP connection */
/* 6LoWPAN does not do well with concurrent TCP streams, as new browser GETs collide with packets coming */
/* from previous GETs, causing decreased throughput, retransmissions, and timeouts. Increase to study this. */
/* ACKs to other ports become interleaved with computation-intensive GETs, so ACKs are particularly missed. */
/* Increasing the number of packet receive buffers in RAM helps to keep ACKs from being lost */
#define UIP_CONF_MAX_CONNECTIONS 4
/* 2 bytes per TCP listening port */
#define UIP_CONF_MAX_LISTENPORTS 4
/* 25 bytes per UDP connection */
#define UIP_CONF_UDP_CONNS 10
/* See uip-ds6.h */
#define NBR_TABLE_CONF_MAX_NEIGHBORS 20
#define UIP_CONF_DS6_DEFRT_NBU 2
#define UIP_CONF_DS6_PREFIX_NBU 3
#define UIP_CONF_MAX_ROUTES 20
#define UIP_CONF_DS6_ADDR_NBU 3
#define UIP_CONF_DS6_MADDR_NBU 0
#define UIP_CONF_DS6_AADDR_NBU 0
#else
#error Network configuration not specified!
#endif /* Network setup */
/* ************************************************************************** */
//#pragma mark RPL Settings
/* ************************************************************************** */
#if UIP_CONF_IPV6_RPL
#define UIP_CONF_ROUTER 1
#define UIP_CONF_ND6_SEND_RA 0
#define UIP_CONF_ND6_REACHABLE_TIME 600000
#define UIP_CONF_ND6_RETRANS_TIMER 10000
/* For slow slip connections, to prevent buffer overruns */
//#define UIP_CONF_RECEIVE_WINDOW 300
#undef UIP_CONF_FWCACHE_SIZE
#define UIP_CONF_FWCACHE_SIZE 30
#define UIP_CONF_BROADCAST 1
#define UIP_ARCH_IPCHKSUM 1
#define UIP_CONF_PINGADDRCONF 0
#define UIP_CONF_LOGGING 0
#endif /* RPL */
#define CCIF
#define CLIF
#ifndef CC_CONF_INLINE
#define CC_CONF_INLINE inline
#endif
/* include the project config */
/* PROJECT_CONF_H might be defined in the project Makefile */
#ifdef PROJECT_CONF_H
#include PROJECT_CONF_H
#endif
#endif /* CONTIKI_CONF_H_ */

View file

@ -0,0 +1,367 @@
/*
* Copyright (c) 2016, Dr. Ralf Schlatterbeck Open Source Consulting
* 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.
*
*/
#define printf_P printf
#define PSTR(x) (x)
#define PRINTF(FORMAT,args...) printf_P(PSTR(FORMAT),##args)
#define ANNOUNCE_BOOT 1
#if ANNOUNCE_BOOT
#define PRINTA(FORMAT,args...) printf_P(PSTR(FORMAT),##args)
#else
#define PRINTA(...)
#endif
#define DEBUG 0
#if DEBUG
#define PRINTD(FORMAT,args...) printf_P(PSTR(FORMAT),##args)
#else
#define PRINTD(...)
#endif
#include <stdio.h>
#include <string.h>
#include "params.h"
//#include "radio/rf230bb/rf230bb.h"
#include "net/mac/frame802154.h"
#include "net/mac/framer-802154.h"
#include "net/ipv6/sicslowpan.h"
#include "contiki.h"
#include "contiki-net.h"
#include "contiki-lib.h"
//#include "dev/rs232.h"
//#include "dev/serial-line.h"
//#include "dev/slip.h"
#include "net/rime/rime.h"
/* Track interrupt flow through mac, rdc and radio driver */
//#define DEBUGFLOWSIZE 32
#if DEBUGFLOWSIZE
uint8_t debugflowsize,debugflow[DEBUGFLOWSIZE];
#define DEBUGFLOW(c) if (debugflowsize<(DEBUGFLOWSIZE-1)) debugflow[debugflowsize++]=c
#else
#define DEBUGFLOW(c)
#endif
/* Get periodic prints from idle loop, from clock seconds or rtimer interrupts */
/* Use of rtimer will conflict with other rtimer interrupts such as contikimac radio cycling */
/* STAMPS will print ENERGEST outputs if that is enabled. */
#define PERIODICPRINTS 1
#if PERIODICPRINTS
//#define PINGS 64
#define ROUTES 600
#define STAMPS 60
#define STACKMONITOR 1024
uint32_t clocktime;
#define TESTRTIMER 0
#if TESTRTIMER
uint8_t rtimerflag=1;
struct rtimer rt;
void rtimercycle(void) {rtimerflag=1;}
#endif
#endif
uint16_t ledtimer;
/*-------------------------Low level initialization------------------------*/
/*------Done in a subroutine to keep main routine stack usage small--------*/
void initialize(void)
{
#if 0 && STACKMONITOR
/* Simple stack pointer highwater monitor. Checks for magic numbers in the main
* loop. In conjuction with PERIODICPRINTS, never-used stack will be printed
* every STACKMONITOR seconds.
*/
{
extern uint16_t __bss_end;
uint16_t *p=&__bss_end;
do {
*p = 0x4242;
p+=5;
} while (p<SP-10); //don't overwrite our own stack
}
#endif
PRINTA("\n*******Booting %s*******\n",CONTIKI_VERSION_STRING);
/* rtimers needed for radio cycling */
rtimer_init();
/* Initialize process subsystem */
process_init();
/* etimers must be started before ctimer_init */
process_start(&etimer_process, NULL);
ctimer_init();
/* Start radio and radio receive process */
NETSTACK_RADIO.init();
/* Get a random seed for the 802.15.4 packet sequence number.
* Some layers will ignore duplicates found in a history (e.g. Contikimac)
* causing the initial packets to be ignored after a short-cycle restart.
*/
//random_init(rng_get_uint8());
/* Set addresses BEFORE starting tcpip process */
linkaddr_t addr;
if (params_get_eui64(addr.u8)) {
PRINTA("Random EUI64 address generated\n");
}
#if NETSTACK_CONF_WITH_IPV6
memcpy(&uip_lladdr.addr, &addr.u8, sizeof(linkaddr_t));
#elif WITH_NODE_ID
node_id=get_panaddr_from_eeprom();
addr.u8[1]=node_id&0xff;
addr.u8[0]=(node_id&0xff00)>>8;
PRINTA("Node ID from eeprom: %X\n",node_id);
#endif
linkaddr_set_node_addr(&addr);
// FIXME undefined
//rf230_set_pan_addr(params_get_panid(),params_get_panaddr(),(uint8_t *)&addr.u8);
//rf230_set_channel(params_get_channel());
//rf230_set_txpower(params_get_txpower());
#if NETSTACK_CONF_WITH_IPV6
PRINTA("EUI-64 MAC: %x-%x-%x-%x-%x-%x-%x-%x\n",addr.u8[0],addr.u8[1],addr.u8[2],addr.u8[3],addr.u8[4],addr.u8[5],addr.u8[6],addr.u8[7]);
#else
PRINTA("MAC address ");
uint8_t i;
for (i=sizeof(linkaddr_t); i>0; i--){
PRINTA("%x:",addr.u8[i-1]);
}
PRINTA("\n");
#endif
/* Initialize stack protocols */
queuebuf_init();
NETSTACK_RDC.init();
NETSTACK_MAC.init();
NETSTACK_NETWORK.init();
#if ANNOUNCE_BOOT
//FIXME: undefined
//PRINTA("%s %s, channel %u , check rate %u Hz tx power %u\n",NETSTACK_MAC.name, NETSTACK_RDC.name, rf230_get_channel(),
// CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval() == 0 ? 1:NETSTACK_RDC.channel_check_interval()),
// rf230_get_txpower());
#if UIP_CONF_IPV6_RPL
PRINTA("RPL Enabled\n");
#endif
#if UIP_CONF_ROUTER
PRINTA("Routing Enabled\n");
#endif
#endif /* ANNOUNCE_BOOT */
#if NETSTACK_CONF_WITH_IPV6 || NETSTACK_CONF_WITH_IPV4
process_start(&tcpip_process, NULL);
#endif
#ifdef RAVEN_LCD_INTERFACE
process_start(&raven_lcd_process, NULL);
#endif
/* Autostart other processes */
autostart_start(autostart_processes);
/* Add addresses for testing */
#if 0
{
uip_ip6addr_t ipaddr;
uip_ip6addr(&ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 0);
uip_ds6_addr_add(&ipaddr, 0, ADDR_AUTOCONF);
// uip_ds6_prefix_add(&ipaddr,64,0);
}
#endif
/*--------------------------Announce the configuration---------------------*/
#if ANNOUNCE_BOOT
PRINTA("Online\n");
#endif /* ANNOUNCE_BOOT */
}
#if ROUTES && NETSTACK_CONF_WITH_IPV6
static void
ipaddr_add(const uip_ipaddr_t *addr)
{
uint16_t a;
int8_t i, f;
for(i = 0, f = 0; i < sizeof(uip_ipaddr_t); i += 2) {
a = (addr->u8[i] << 8) + addr->u8[i + 1];
if(a == 0 && f >= 0) {
if(f++ == 0) PRINTF("::");
} else {
if(f > 0) {
f = -1;
} else if(i > 0) {
PRINTF(":");
}
PRINTF("%x",a);
}
}
}
#endif
/*-------------------------------------------------------------------------*/
/*------------------------- Main Scheduler loop----------------------------*/
/*-------------------------------------------------------------------------*/
int
main(void)
{
puts ("Hello world!\n");
printf ("Hello world!\n");
#if NETSTACK_CONF_WITH_IPV6
uip_ds6_nbr_t *nbr;
#endif /* NETSTACK_CONF_WITH_IPV6 */
initialize();
while(1) {
process_run();
#if PERIODICPRINTS
#if TESTRTIMER
/* Timeout can be increased up to 8 seconds maximum.
* A one second cycle is convenient for triggering the various debug printouts.
* The triggers are staggered to avoid printing everything at once.
*/
if (rtimerflag) {
rtimer_set(&rt, RTIMER_NOW()+ RTIMER_ARCH_SECOND*1UL, 1,(void *) rtimercycle, NULL);
rtimerflag=0;
#else
if (clocktime!=clock_seconds()) {
clocktime=clock_seconds();
#endif
#if STAMPS
if ((clocktime%STAMPS)==0) {
PRINTF("%lus\n",clocktime);
}
#endif
#if ROUTES && NETSTACK_CONF_WITH_IPV6
if ((clocktime%ROUTES)==2) {
extern uip_ds6_netif_t uip_ds6_if;
uint8_t i,j;
PRINTF("\nAddresses [%u max]\n",UIP_DS6_ADDR_NB);
for (i=0;i<UIP_DS6_ADDR_NB;i++) {
if (uip_ds6_if.addr_list[i].isused) {
ipaddr_add(&uip_ds6_if.addr_list[i].ipaddr);
PRINTF("\n");
}
}
PRINTF("\nNeighbors [%u max]\n",NBR_TABLE_MAX_NEIGHBORS);
for(nbr = nbr_table_head(ds6_neighbors);
nbr != NULL;
nbr = nbr_table_next(ds6_neighbors, nbr)) {
ipaddr_add(&nbr->ipaddr);
PRINTF("\n");
j=0;
}
if (j) PRINTF(" <none>");
PRINTF("\nRoutes [%u max]\n",UIP_DS6_ROUTE_NB);
{
uip_ds6_route_t *r;
PRINTF("\nRoutes [%u max]\n",UIP_DS6_ROUTE_NB);
j = 1;
for(r = uip_ds6_route_head();
r != NULL;
r = uip_ds6_route_next(r)) {
ipaddr_add(&r->ipaddr);
PRINTF("/%u (via ", r->length);
ipaddr_add(uip_ds6_route_nexthop(r));
PRINTF(") %lus\n", r->state.lifetime);
j = 0;
}
}
if (j) PRINTF(" <none>");
PRINTF("\n---------\n");
}
#endif
#if 0 && STACKMONITOR
if ((clocktime%STACKMONITOR)==3) {
extern uint16_t __bss_end;
uint16_t *p=&__bss_end;
do {
if (*p != 0x4242) {
PRINTF("Never-used stack > %d bytes\n",((char*)p) - ((char*)&__bss_end));
break;
}
p+=5;
} while (p<RAMEND-10);
}
#endif
}
#endif /* PERIODICPRINTS */
#if 0
#if RF230BB&&0
extern uint8_t rf230processflag;
if (rf230processflag) {
PRINTF("rf230p%d",rf230processflag);
rf230processflag=0;
}
#endif
#if RF230BB&&0
extern uint8_t rf230_interrupt_flag;
if (rf230_interrupt_flag) {
// if (rf230_interrupt_flag!=11) {
PRINTF("**RI%u",rf230_interrupt_flag);
// }
rf230_interrupt_flag=0;
}
#endif
#endif /* 0 */
}
return 0;
}
/*---------------------------------------------------------------------------*/
void log_message(char *m1, char *m2)
{
PRINTF("%s%s\n", m1, m2);
}

View file

@ -0,0 +1,81 @@
/*
* Copyright (c) 2016, Dr. Ralf Schlatterbeck Open Source Consulting
* 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.
*
*/
#define PRINTF(FORMAT,args...) printf_P(PSTR(FORMAT),##args)
#define DEBUG 1
#if DEBUG
#define PRINTD(FORMAT,args...) printf_P(PSTR(FORMAT),##args)
#else
#define PRINTD(...)
#endif
#include "contiki.h"
#include <stdio.h>
#include <string.h>
#include "contiki-net.h"
#include "params.h"
#if CONTIKI_CONF_RANDOM_MAC
extern uint8_t rng_get_uint8(void);
static void
generate_new_eui64(uint8_t eui64[8]) {
eui64[0] = 0x02;
eui64[1] = rng_get_uint8();
eui64[2] = rng_get_uint8();
eui64[3] = 0xFF;
eui64[4] = 0xFE;
eui64[5] = rng_get_uint8();
eui64[6] = rng_get_uint8();
eui64[7] = rng_get_uint8();
}
#endif
const uint8_t default_mac_address[8] =
{0x02, 0x00, 0x00, 0xff, 0xfe, 0x00, 0x00, 0x01};
/* Hard coded parameters. */
uint8_t
params_get_eui64(uint8_t *eui64) {
#if CONTIKI_CONF_RANDOM_MAC
PRINTD("Generating random EUI64 MAC\n");
generate_new_eui64(eui64);
return 1;
#else
uint8_t i;
for (i=0;i<sizeof(default_mac_address);i++) {
eui64[i] = default_mac_address [i];
}
return 0;
#endif
}

View file

@ -0,0 +1,68 @@
#ifndef PARAMS_H_
#define PARAMS_H_
/* Include settings.h, then dummy out the write routines */
#include "settings.h"
#if PARAMETER_STORAGE==2
#define settings_add(...) 0
#define settings_add_uint8(...) 0
#define settings_add_uint16(...) 0
#endif
#ifdef SERVER_NAME
#define PARAMS_SERVERNAME SERVER_NAME
#else
#define PARAMS_SERVERNAME "PicoRV32"
#endif
#ifdef DOMAIN_NAME
#define PARAMS_DOMAINNAME DOMAIN_NAME
#else
#define PARAMS_DOMAINNAME "localhost"
#endif
#ifdef NODE_ID
#define PARAMS_NODEID NODE_ID
#else
#define PARAMS_NODEID 0
#endif
#ifdef CHANNEL_802_15_4
#define PARAMS_CHANNEL CHANNEL_802_15_4
#else
#define PARAMS_CHANNEL 26
#endif
#ifdef IEEE802154_PANID
#define PARAMS_PANID IEEE802154_PANID
#else
#define PARAMS_PANID 0xABCD
#endif
#ifdef IEEE802154_PANADDR
#define PARAMS_PANADDR IEEE802154_PANADDR
#else
#define PARAMS_PANADDR 0
#endif
#ifdef RF230_MAX_TX_POWER
#define PARAMS_TXPOWER RF230_MAX_TX_POWER
#else
#define PARAMS_TXPOWER 0
#endif
#ifdef EUI64_ADDRESS
#define PARAMS_EUI64ADDR EUI64_ADDRESS
#else
/* This form of of EUI64 mac allows full 6LoWPAN header compression from mac address */
#if UIP_CONF_LL_802154
#define PARAMS_EUI64ADDR {0x02, 0x00, 0x00, 0xff, 0xfe, 0x00, 0x00, 0x01}
#else
#define PARAMS_EUI64ADDR {0x00, 0x00, 0x00, 0xff, 0xfe, 0x00, 0x00, 0x01}
#endif
/* This form of of EUI64 mac allows 16 bit 6LoWPAN header compression on multihops */
#endif
uint8_t params_get_eui64(uint8_t *eui64);
/* Hard coded program flash parameters */
#define params_get_servername(...)
#define params_get_nodeid(...) PARAMS_NODEID
#define params_get_channel(...) PARAMS_CHANNEL
#define params_get_panid(...) PARAMS_PANID
#define params_get_panaddr(...) PARAMS_PANADDR
#define params_get_txpower(...) PARAMS_TXPOWER
#endif /* PARAMS_H_ */