Compare commits
14 commits
Author | SHA1 | Date | |
---|---|---|---|
|
6c63efc84e | ||
|
0d797cf90a | ||
|
fab42e0d67 | ||
|
7d63a0f487 | ||
|
d78269ffc1 | ||
|
b87ba1f526 | ||
|
cb1e085ebf | ||
|
b9fc6a8324 | ||
|
d7e6935ec2 | ||
|
0232e6c9dc | ||
|
c043a00bb4 | ||
|
08fb461f43 | ||
|
c49d4a0b36 | ||
|
57959a53f6 |
|
@ -545,6 +545,9 @@ send_packet(mac_callback_t mac_callback, void *mac_callback_ptr,
|
||||||
int strobes;
|
int strobes;
|
||||||
uint8_t got_strobe_ack = 0;
|
uint8_t got_strobe_ack = 0;
|
||||||
uint8_t is_broadcast = 0;
|
uint8_t is_broadcast = 0;
|
||||||
|
#if WITH_PHASE_OPTIMIZATION
|
||||||
|
uint8_t is_known_receiver = 0;
|
||||||
|
#endif
|
||||||
uint8_t collisions;
|
uint8_t collisions;
|
||||||
int transmit_len;
|
int transmit_len;
|
||||||
int ret;
|
int ret;
|
||||||
|
@ -1067,7 +1070,7 @@ turn_off(int keep_radio_on)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
static unsigned short
|
static clock_time_t
|
||||||
duty_cycle(void)
|
duty_cycle(void)
|
||||||
{
|
{
|
||||||
return (1ul * CLOCK_SECOND * CYCLE_TIME) / RTIMER_ARCH_SECOND;
|
return (1ul * CLOCK_SECOND * CYCLE_TIME) / RTIMER_ARCH_SECOND;
|
||||||
|
|
|
@ -918,7 +918,7 @@ turn_off(int keep_radio_on)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
static unsigned short
|
static clock_time_t
|
||||||
channel_check_interval(void)
|
channel_check_interval(void)
|
||||||
{
|
{
|
||||||
return (1ul * CLOCK_SECOND * DEFAULT_PERIOD) / RTIMER_ARCH_SECOND;
|
return (1ul * CLOCK_SECOND * DEFAULT_PERIOD) / RTIMER_ARCH_SECOND;
|
||||||
|
|
|
@ -70,7 +70,7 @@ off(int keep_radio_on)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
static unsigned short
|
static clock_time_t
|
||||||
channel_check_interval(void)
|
channel_check_interval(void)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -87,7 +87,7 @@ off(int keep_radio_on)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
static unsigned short
|
static clock_time_t
|
||||||
channel_check_interval(void)
|
channel_check_interval(void)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -343,7 +343,7 @@ off(int keep_radio_on)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
static unsigned short
|
static clock_time_t
|
||||||
channel_check_interval(void)
|
channel_check_interval(void)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -87,7 +87,7 @@ struct rdc_driver {
|
||||||
int (* off)(int keep_radio_on);
|
int (* off)(int keep_radio_on);
|
||||||
|
|
||||||
/** Returns the channel check interval, expressed in clock_time_t ticks. */
|
/** Returns the channel check interval, expressed in clock_time_t ticks. */
|
||||||
unsigned short (* channel_check_interval)(void);
|
clock_time_t (* channel_check_interval)(void);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* RDC_H_ */
|
#endif /* RDC_H_ */
|
||||||
|
|
|
@ -251,7 +251,7 @@ init(void)
|
||||||
NETSTACK_RADIO.on();
|
NETSTACK_RADIO.on();
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
static unsigned short
|
static clock_time_t
|
||||||
channel_check_interval(void)
|
channel_check_interval(void)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
|
|
77
cpu/pico-rv32/Makefile.pico-rv32
Normal file
77
cpu/pico-rv32/Makefile.pico-rv32
Normal 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 irq.c spi.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 -march=RV32IXcustom -g \
|
||||||
|
-I$(CONTIKI)/platform/$(TARGET) \
|
||||||
|
-I. -I$(CONTIKI_CPU) -I$(CONTIKI)/core -fno-strict-aliasing
|
||||||
|
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
184
cpu/pico-rv32/dev/clock.c
Normal 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. We use the same in the
|
||||||
|
* timer interrupt: 1/128 second ticks, this can be changed by modifying
|
||||||
|
* CLOCK_TIMER_PERIOD below.
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
* We directly use the 64-bit cycle counter provided by the CPU.
|
||||||
|
*/
|
||||||
|
#include "sys/clock.h"
|
||||||
|
#include "sys/etimer.h"
|
||||||
|
#include "icosoc.h"
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
// 1/128 second ticks
|
||||||
|
#define CLOCK_TIMER_PERIOD (F_CPU >> 7)
|
||||||
|
|
||||||
|
unsigned long offset;
|
||||||
|
|
||||||
|
/** \brief irq handler
|
||||||
|
* for running interrupts every 1/128 second.
|
||||||
|
*/
|
||||||
|
|
||||||
|
void
|
||||||
|
clock_irq_handler (void)
|
||||||
|
{
|
||||||
|
// FIXME: Want to call rtimer_run_next();
|
||||||
|
icosoc_timer(CLOCK_TIMER_PERIOD);
|
||||||
|
if(etimer_pending()) {
|
||||||
|
etimer_request_poll();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
/**
|
||||||
|
* Initialize interrupt handler
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
clock_init(void)
|
||||||
|
{
|
||||||
|
register_irq (TIMER_IRQ, clock_irq_handler);
|
||||||
|
enable_irq (TIMER_IRQ);
|
||||||
|
icosoc_timer(CLOCK_TIMER_PERIOD);
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
/**
|
||||||
|
* Return the tick counter. We use the full 64bit counter which makes
|
||||||
|
* computation of seconds etc. easier later.
|
||||||
|
*/
|
||||||
|
clock_time_t
|
||||||
|
clock_time(void)
|
||||||
|
{
|
||||||
|
volatile uint32_t low, high;
|
||||||
|
asm ("1: rdcycleh %1\n"
|
||||||
|
"rdcycle %0\n"
|
||||||
|
"rdcycleh t0\n"
|
||||||
|
"bne %1,t0,1b\n"
|
||||||
|
: "=r" (low), "=r" (high)
|
||||||
|
:
|
||||||
|
: "t0"
|
||||||
|
);
|
||||||
|
return ((clock_time_t)high) << 32 | low;
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
/**
|
||||||
|
* Return seconds, default is time since startup.
|
||||||
|
*/
|
||||||
|
unsigned long
|
||||||
|
clock_seconds(void)
|
||||||
|
{
|
||||||
|
return (unsigned long)(clock_time () / CLOCK_CONF_SECOND) + offset;
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
/**
|
||||||
|
* Set seconds, e.g. to a standard epoch for an absolute date/time.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
clock_set_seconds(unsigned long sec)
|
||||||
|
{
|
||||||
|
offset = sec - (unsigned long)(clock_time () / CLOCK_CONF_SECOND);
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
/*
|
||||||
|
* Wait for a number of clock ticks.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
clock_wait(clock_time_t t)
|
||||||
|
{
|
||||||
|
clock_time_t endticks = clock_time() + t;
|
||||||
|
while (clock_time () < endticks)
|
||||||
|
{;}
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
void
|
||||||
|
clock_delay_usec(uint16_t dt)
|
||||||
|
{
|
||||||
|
clock_wait (CLOCK_SECOND * dt / 1000000ULL);
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
/**
|
||||||
|
* Legacy delay. The original clock_delay for the msp430 used a granularity
|
||||||
|
* of 2.83 usec. This approximates that delay for values up to 1456 usec.
|
||||||
|
* (The largest core call in leds.c uses 400).
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
clock_delay(unsigned int howlong)
|
||||||
|
{
|
||||||
|
clock_delay_usec((45*howlong)>>4);
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
/**
|
||||||
|
* 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)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @} */
|
||||||
|
/** @} */
|
2
cpu/pico-rv32/dev/spi.c
Normal file
2
cpu/pico-rv32/dev/spi.c
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
#include "spi.h"
|
||||||
|
uint8_t spi_rxbuf = 0;
|
85
cpu/pico-rv32/dev/spi.h
Normal file
85
cpu/pico-rv32/dev/spi.h
Normal file
|
@ -0,0 +1,85 @@
|
||||||
|
/*
|
||||||
|
* 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
|
||||||
|
* SPI routines
|
||||||
|
*
|
||||||
|
* \author Ralf Schlatterbeck <rsc@runtux.com>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
/** \addtogroup picorv32
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* \file
|
||||||
|
* SPI macros
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef SPI_H_
|
||||||
|
#define SPI_H_
|
||||||
|
|
||||||
|
#include "icosoc.h"
|
||||||
|
|
||||||
|
#define SPI_RXBUF spi_rxbuf
|
||||||
|
|
||||||
|
extern uint8_t spi_rxbuf;
|
||||||
|
|
||||||
|
/* Write one character to SPI */
|
||||||
|
#define SPI_WRITE(data) (spi_rxbuf = icosoc_cc2520_spi_xfer(data))
|
||||||
|
/* Currently no fast writing without waiting for transmission to
|
||||||
|
* terminate
|
||||||
|
*/
|
||||||
|
#define SPI_WRITE_FAST(data) SPI_WRITE(data)
|
||||||
|
|
||||||
|
/* Read one character from SPI */
|
||||||
|
#define SPI_READ(data) (data = spi_rxbuf = icosoc_cc2520_spi_xfer(0))
|
||||||
|
|
||||||
|
/* No async operation, therefore no flush */
|
||||||
|
#define SPI_FLUSH()
|
||||||
|
|
||||||
|
#define SPI_WAITFORTx_BEFORE()
|
||||||
|
#define SPI_WAITFORTx_AFTER() SPI_WAITFOREOTx()
|
||||||
|
#define SPI_WAITFORTx_ENDED()
|
||||||
|
#define SPI_WAITFORTxREADY()
|
||||||
|
|
||||||
|
#define BV(x) (1<<x)
|
||||||
|
|
||||||
|
/* Used by cc2520_init probably for disabling interrupts, don't need
|
||||||
|
* that here.
|
||||||
|
*/
|
||||||
|
#define splhigh() 1
|
||||||
|
#define splx(x) ((void)(x))
|
||||||
|
|
||||||
|
#endif /* SPI_H_ */
|
||||||
|
|
||||||
|
/** @} */
|
133
cpu/pico-rv32/irq.c
Normal file
133
cpu/pico-rv32/irq.c
Normal file
|
@ -0,0 +1,133 @@
|
||||||
|
/*
|
||||||
|
* 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
|
||||||
|
* Interrupt handling for Timer and other interrupts
|
||||||
|
*
|
||||||
|
* \author Ralf Schlatterbeck <rsc@runtux.com>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
/** \addtogroup picorv32
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* \defgroup picorv32 irq implementation
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* \file
|
||||||
|
* This file contains PicoRV32-specific code to implement
|
||||||
|
* Interrupt handling for Timer and other interrupts
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#include "irq.h"
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <assert.h>
|
||||||
|
|
||||||
|
/* Initially allow bus-error and illegal instruction / sbreak */
|
||||||
|
static uint32_t irqmask = ~0x6;
|
||||||
|
|
||||||
|
/* Interrupt table, for convenience we waste some memory for the lower 3
|
||||||
|
* callbacks
|
||||||
|
*/
|
||||||
|
static void (*irq_callback_functions [MAXIRQ + 1])(void);
|
||||||
|
|
||||||
|
/** \brief irq handler
|
||||||
|
*/
|
||||||
|
|
||||||
|
void
|
||||||
|
irq_handler(uint32_t irq_mask, uint32_t *regs)
|
||||||
|
{
|
||||||
|
// Other interrupts
|
||||||
|
if (irq_mask & (((1 << (MAXIRQ + 2)) - 1) & ~0x6)) {
|
||||||
|
int i;
|
||||||
|
for (i=0; i<=MAXIRQ; i++) {
|
||||||
|
if (irq_mask & (1<<i)) {
|
||||||
|
if (irq_callback_functions [i] == NULL) {
|
||||||
|
printf ("Ooops: IRQ without callback: %d\n", i);
|
||||||
|
} else {
|
||||||
|
irq_callback_functions [i] ();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// SBREAK, ILLINS or BUSERROR
|
||||||
|
if (irq_mask & 6) {
|
||||||
|
if (irq_mask & 4) {
|
||||||
|
if (irq_callback_functions [2]) {
|
||||||
|
irq_callback_functions [2] ();
|
||||||
|
} else {
|
||||||
|
printf("Bus Error!\n");
|
||||||
|
icosoc_sbreak();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (irq_mask & 2) {
|
||||||
|
if (irq_callback_functions [1]) {
|
||||||
|
irq_callback_functions [1] ();
|
||||||
|
} else {
|
||||||
|
printf("Illegal Instruction or SBREAK!\n");
|
||||||
|
icosoc_sbreak();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void irq_init(void)
|
||||||
|
{
|
||||||
|
icosoc_irq(irq_handler);
|
||||||
|
icosoc_maskirq(irqmask);
|
||||||
|
}
|
||||||
|
|
||||||
|
void register_irq (int irq, void (*callback)(void))
|
||||||
|
{
|
||||||
|
assert (irq <= MAXIRQ);
|
||||||
|
irq_callback_functions [irq] = callback;
|
||||||
|
}
|
||||||
|
|
||||||
|
void enable_irq (int irq)
|
||||||
|
{
|
||||||
|
assert (irq <= MAXIRQ);
|
||||||
|
if (irq_callback_functions [irq] != NULL) {
|
||||||
|
irqmask &= (~(1<<irq));
|
||||||
|
icosoc_maskirq(irqmask);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void disable_irq (int irq)
|
||||||
|
{
|
||||||
|
assert (irq <= MAXIRQ);
|
||||||
|
irqmask |= (1<<irq);
|
||||||
|
icosoc_maskirq(irqmask);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @} */
|
||||||
|
/** @} */
|
67
cpu/pico-rv32/irq.h
Normal file
67
cpu/pico-rv32/irq.h
Normal file
|
@ -0,0 +1,67 @@
|
||||||
|
/*
|
||||||
|
* 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
|
||||||
|
* Interrupt handling for Timer and other interrupts
|
||||||
|
*
|
||||||
|
* \author Ralf Schlatterbeck <rsc@runtux.com>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
/** \addtogroup picorv32
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* \file
|
||||||
|
* Interrupt handling for Timer and other interrupts
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef IRQ_H_
|
||||||
|
#define IRQ_H_
|
||||||
|
|
||||||
|
#include "icosoc.h"
|
||||||
|
|
||||||
|
/* Want to set this higher if we have more than two external interrupts
|
||||||
|
* See used interrupts in icosoc.cfg. Don't set lower than 2 (2 is the
|
||||||
|
* bus-error interrupt)
|
||||||
|
*/
|
||||||
|
#define MAXIRQ 4
|
||||||
|
#define TIMER_IRQ 0
|
||||||
|
|
||||||
|
void irq_init (void);
|
||||||
|
void register_irq (int irq, void (*callback)(void));
|
||||||
|
void enable_irq (int irq);
|
||||||
|
void disable_irq (int irq);
|
||||||
|
|
||||||
|
#endif /* IRQ_H_ */
|
||||||
|
|
||||||
|
/** @} */
|
174
cpu/pico-rv32/mtarch.c
Normal file
174
cpu/pico-rv32/mtarch.c
Normal file
|
@ -0,0 +1,174 @@
|
||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
printf ("mtarch_start called\n");
|
||||||
|
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
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* 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 struct mtarch_thread *running;
|
||||||
|
|
||||||
|
static void
|
||||||
|
sw(void)
|
||||||
|
{
|
||||||
|
printf ("sw called\n");
|
||||||
|
/* FIXME: Disable interrupts while we perform the context switch */
|
||||||
|
/* Needs to be in separate asm statement, we don't want to be
|
||||||
|
* interrupted while the C-Compiler-generated wrapper-code pushes
|
||||||
|
* registers on the stack.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Need to save ra, s0/fp, s1-s11, we make the C-compiler do it by
|
||||||
|
* specifying these registers as clobber.
|
||||||
|
* For now we leave MT threads alone -- the stack management is too
|
||||||
|
* unstable in the currently-used gcc port, in our example for storing
|
||||||
|
* 13 4-byte variables on the stack the compiler allocates 64 bytes on
|
||||||
|
* the stack (52 would be ok, 64 is not even explained if the stack is
|
||||||
|
* kept 8-byte aligned (maybe 16?)). Also the normal function wrapper
|
||||||
|
* code is not called if we have a single asm statement in a function
|
||||||
|
* (the normal wrapper code already saves ra, s0/fp on the stack).
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Switch stack pointer */
|
||||||
|
asm (
|
||||||
|
"mv t0, sp\n"
|
||||||
|
"mv sp, %0\n"
|
||||||
|
"mv %0, t0\n"
|
||||||
|
: "+r" (running->sp)
|
||||||
|
:
|
||||||
|
: "t0","ra","s0","s1","s2","s3","s4","s5","s6","s7","s8","s9","s10","s11"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
/*--------------------------------------------------------------------------*/
|
||||||
|
void
|
||||||
|
mtarch_exec(struct mtarch_thread *t)
|
||||||
|
{
|
||||||
|
printf ("mtarch_exec called\n");
|
||||||
|
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
56
cpu/pico-rv32/mtarch.h
Normal 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 1024
|
||||||
|
#endif
|
||||||
|
|
||||||
|
struct mtarch_thread {
|
||||||
|
unsigned char stack[MTARCH_STACKSIZE];
|
||||||
|
unsigned char *sp;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* MTARCH_H_ */
|
55
cpu/pico-rv32/rtimer-arch.c
Normal file
55
cpu/pico-rv32/rtimer-arch.c
Normal file
|
@ -0,0 +1,55 @@
|
||||||
|
/*
|
||||||
|
* 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)
|
||||||
|
{
|
||||||
|
printf ("rtimer_arch_init called\n");
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
void
|
||||||
|
rtimer_arch_schedule(rtimer_clock_t t)
|
||||||
|
{
|
||||||
|
printf ("Scheduling timer: %d\n", t);
|
||||||
|
}
|
41
cpu/pico-rv32/rtimer-arch.h
Normal file
41
cpu/pico-rv32/rtimer-arch.h
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
/*
|
||||||
|
* 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>
|
||||||
|
|
||||||
|
#define RTIMER_ARCH_SECOND 65536L
|
||||||
|
|
||||||
|
#define rtimer_arch_now() ((rtimer_clock_t)(clock_time () * 65536 / F_CPU))
|
||||||
|
#endif /* RTIMER_ARCH_H_ */
|
51
cpu/pico-rv32/rv32def.h
Normal file
51
cpu/pico-rv32/rv32def.h
Normal 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
62
cpu/pico-rv32/watchdog.c
Normal 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)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
|
@ -215,12 +215,17 @@ static void
|
||||||
flushrx(void)
|
flushrx(void)
|
||||||
{
|
{
|
||||||
uint8_t dummy;
|
uint8_t dummy;
|
||||||
|
uint8_t tmp [2] = {0, 0};
|
||||||
|
|
||||||
|
/* This read may cause an RX-fifo underflow which is cleared below */
|
||||||
CC2520_READ_FIFO_BYTE(dummy);
|
CC2520_READ_FIFO_BYTE(dummy);
|
||||||
/* read and discard dummy to avoid "variable set but not used" warning */
|
/* read and discard dummy to avoid "variable set but not used" warning */
|
||||||
(void)dummy;
|
(void)dummy;
|
||||||
|
/* Read twice, see errata */
|
||||||
CC2520_STROBE(CC2520_INS_SFLUSHRX);
|
CC2520_STROBE(CC2520_INS_SFLUSHRX);
|
||||||
CC2520_STROBE(CC2520_INS_SFLUSHRX);
|
CC2520_STROBE(CC2520_INS_SFLUSHRX);
|
||||||
|
/* Reset exception flags for next round incl RX-fifo underflow */
|
||||||
|
CC2520_WRITE_RAM(&tmp, CC2520_EXCFLAG0, 2);
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
static void
|
static void
|
||||||
|
@ -429,7 +434,16 @@ cc2520_transmit(unsigned short payload_len)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if WITH_SEND_CCA
|
#if WITH_SEND_CCA
|
||||||
strobe(CC2520_INS_SRXON);
|
/* Errata says to flush after SRXON to prevent erroneous reception
|
||||||
|
* We turn receiver on only if RXENMASK[15] (RXENABLE1 & 0x80) is
|
||||||
|
* *not* set.
|
||||||
|
*/
|
||||||
|
if (!(getreg (CC2520_RXENABLE1) & 0x80)) {
|
||||||
|
strobe(CC2520_INS_SRXON);
|
||||||
|
printf ("send: enabling receiver\n");
|
||||||
|
flushrx();
|
||||||
|
}
|
||||||
|
/* Wait for valid RSSI to get correct CCA */
|
||||||
BUSYWAIT_UNTIL(status() & BV(CC2520_RSSI_VALID) , RTIMER_SECOND / 10);
|
BUSYWAIT_UNTIL(status() & BV(CC2520_RSSI_VALID) , RTIMER_SECOND / 10);
|
||||||
strobe(CC2520_INS_STXONCCA);
|
strobe(CC2520_INS_STXONCCA);
|
||||||
#else /* WITH_SEND_CCA */
|
#else /* WITH_SEND_CCA */
|
||||||
|
@ -756,6 +770,7 @@ cc2520_read(void *buf, unsigned short bufsize)
|
||||||
/* Clean up in case of FIFO overflow! This happens for every
|
/* Clean up in case of FIFO overflow! This happens for every
|
||||||
* full length frame and is signaled by FIFOP = 1 and FIFO =
|
* full length frame and is signaled by FIFOP = 1 and FIFO =
|
||||||
* 0. */
|
* 0. */
|
||||||
|
printf ("ovl\n");
|
||||||
flushrx();
|
flushrx();
|
||||||
} else {
|
} else {
|
||||||
/* Another packet has been received and needs attention. */
|
/* Another packet has been received and needs attention. */
|
||||||
|
|
|
@ -76,7 +76,7 @@ off(int keep_radio_on)
|
||||||
return keep_radio_on;
|
return keep_radio_on;
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
static unsigned short
|
static clock_time_t
|
||||||
cca(void)
|
cca(void)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -72,7 +72,7 @@ off(int keep_radio_on)
|
||||||
return keep_radio_on;
|
return keep_radio_on;
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
static unsigned short
|
static clock_time_t
|
||||||
cca(void)
|
cca(void)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -170,7 +170,7 @@ off(int keep_radio_on)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
static unsigned short
|
static clock_time_t
|
||||||
channel_check_interval(void)
|
channel_check_interval(void)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
|
|
12
examples/osd/ico-wallclock-time/.gitignore
vendored
Normal file
12
examples/osd/ico-wallclock-time/.gitignore
vendored
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
icosoc.asc
|
||||||
|
icosoc.blif
|
||||||
|
icosoc.mk
|
||||||
|
icosoc.pcf
|
||||||
|
icosoc.v
|
||||||
|
icosoc.ys
|
||||||
|
icosoc.rpt
|
||||||
|
wallclock.co
|
||||||
|
wallclock.pico-rv32-icoboard
|
||||||
|
icosoc.c
|
||||||
|
icosoc.h
|
||||||
|
testbench.v
|
47
examples/osd/ico-wallclock-time/Makefile
Normal file
47
examples/osd/ico-wallclock-time/Makefile
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
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\"
|
||||||
|
# Use this if running from flash, this needs flashpmem in icosoc.cfg
|
||||||
|
#LDFLAGS += -T riscv_flash.ld
|
||||||
|
|
||||||
|
PROJECTDIRS += $(REST_RESOURCES_DIR) $(REST_RESOURCES_DIR_COMMON)
|
||||||
|
PROJECT_SOURCEFILES += $(REST_RESOURCES_FILES)
|
||||||
|
PROJECT_SOURCEFILES += icosoc.c
|
||||||
|
|
||||||
|
# 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
|
||||||
|
|
||||||
|
flash-run: reset_boot
|
||||||
|
|
||||||
|
flash: prog_flash
|
7
examples/osd/ico-wallclock-time/README.md
Normal file
7
examples/osd/ico-wallclock-time/README.md
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
# Raspberry pi must reachable over dhcp with the name raspi
|
||||||
|
|
||||||
|
make TARGET=pico-rv32-icoboard
|
||||||
|
|
||||||
|
make TARGET=pico-rv32-icoboard run
|
||||||
|
|
||||||
|
|
45
examples/osd/ico-wallclock-time/icosoc.cfg
Normal file
45
examples/osd/ico-wallclock-time/icosoc.cfg
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
# Board
|
||||||
|
board icoboard_gamma
|
||||||
|
|
||||||
|
# Don't load application from flash after timeout, makes it work for
|
||||||
|
# long ssh connection times
|
||||||
|
noflashboot
|
||||||
|
|
||||||
|
# enable compressed ISA support
|
||||||
|
compressed_isa
|
||||||
|
|
||||||
|
# (don't) enable code in flash
|
||||||
|
#flashpmem
|
||||||
|
|
||||||
|
# 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
|
||||||
|
|
||||||
|
# Texas cc2520 RF module connected via SPI
|
||||||
|
mod spi cc2520_spi
|
||||||
|
address 2
|
||||||
|
connect CS pmod1_1
|
||||||
|
connect miso pmod1_3
|
||||||
|
connect mosi pmod1_2
|
||||||
|
connect sclk pmod1_4
|
||||||
|
|
||||||
|
mod extirq cc2520_fifop
|
||||||
|
address 3
|
||||||
|
interrupt 3
|
||||||
|
connect pin pmod1_7
|
||||||
|
|
||||||
|
# pmod1_10 sfd
|
||||||
|
mod extirq cc2520_sfd
|
||||||
|
address 4
|
||||||
|
interrupt 4
|
||||||
|
connect pin pmod1_10
|
||||||
|
|
||||||
|
# pmod1_8 Reset: *Output*
|
||||||
|
# pmod1_9 cca
|
||||||
|
mod gpio cc2520_io
|
||||||
|
address 5
|
||||||
|
connect IO pmod1_9 pmod1_8
|
101
examples/osd/ico-wallclock-time/project-conf.h
Normal file
101
examples/osd/ico-wallclock-time/project-conf.h
Normal 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_ */
|
236
examples/osd/ico-wallclock-time/riscv_flash.ld
Normal file
236
examples/osd/ico-wallclock-time/riscv_flash.ld
Normal file
|
@ -0,0 +1,236 @@
|
||||||
|
/*======================================================================*/
|
||||||
|
/* Default maven linker script */
|
||||||
|
/*======================================================================*/
|
||||||
|
/* This is the default linker script for maven. It is based off of the
|
||||||
|
mips idt32.ld linker script. I have added many more comments and
|
||||||
|
tried to clean things up a bit. For more information about standard
|
||||||
|
MIPS sections see Section 9.5 of "See MIPS Run Linux" by Dominic
|
||||||
|
Sweetman. For more generic information about the init, fini, ctors,
|
||||||
|
and dtors sections see the paper titled "ELF From the Programmers
|
||||||
|
Perspective" by Hongiu Lu. */
|
||||||
|
|
||||||
|
/*----------------------------------------------------------------------*/
|
||||||
|
/* Setup */
|
||||||
|
/*----------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
/* The OUTPUT_ARCH command specifies the machine architecture where the
|
||||||
|
argument is one of the names used in the BFD library. More
|
||||||
|
specifically one of the entires in bfd/cpu-mips.c */
|
||||||
|
|
||||||
|
OUTPUT_ARCH( "riscv" )
|
||||||
|
|
||||||
|
/* The ENTRY command specifies the entry point (ie. first instruction to
|
||||||
|
execute). The symbol _start is defined in crt0.S */
|
||||||
|
|
||||||
|
ENTRY( _start )
|
||||||
|
|
||||||
|
/* The GROUP command is special since the listed archives will be
|
||||||
|
searched repeatedly until there are no new undefined references. We
|
||||||
|
need this since -lc depends on -lgloss and -lgloss depends on -lc. I
|
||||||
|
thought gcc would automatically include -lgcc when needed, but
|
||||||
|
idt32.ld includes it explicitly here and I was seeing link errors
|
||||||
|
without it. */
|
||||||
|
|
||||||
|
GROUP( -lc -lgloss -lgcc )
|
||||||
|
|
||||||
|
/*----------------------------------------------------------------------*/
|
||||||
|
/* Sections */
|
||||||
|
/*----------------------------------------------------------------------*/
|
||||||
|
/* This is where we specify how the input sections map to output
|
||||||
|
sections. The .= commands set the location counter, and the
|
||||||
|
sections are inserted in increasing address order according to the
|
||||||
|
location counter. The following statement will take all of the .bar
|
||||||
|
input sections and reloate them into the .foo output section which
|
||||||
|
starts at address 0x1000.
|
||||||
|
|
||||||
|
. = 0.x1000;
|
||||||
|
.foo : { *(.bar) }
|
||||||
|
|
||||||
|
If we wrap an input specification with a KEEP command then it
|
||||||
|
prevents it from being eliminted during "link-time garbage
|
||||||
|
collection". I'm not sure what this is, so I just followed what was
|
||||||
|
done in idt32.ld.
|
||||||
|
|
||||||
|
We can also set a global external symbol to a specific address in the
|
||||||
|
output binary with this syntax:
|
||||||
|
|
||||||
|
_etext = .;
|
||||||
|
PROVIDE( etext = . );
|
||||||
|
|
||||||
|
This will set the global symbol _ftext to the current location. If we
|
||||||
|
wrap this in a PROVIDE commad, the symbol will only be set if it is
|
||||||
|
not defined. We do this with symbols which don't begin with an
|
||||||
|
underscore since technically in ansi C someone might have a function
|
||||||
|
with the same name (eg. etext).
|
||||||
|
|
||||||
|
If we need to label the beginning of a section we need to make sure
|
||||||
|
that the linker doesn't insert an orphan section inbetween where we
|
||||||
|
set the symbol and the actual begining of the section. We can do that
|
||||||
|
by assigning the location dot to itself.
|
||||||
|
|
||||||
|
. = .
|
||||||
|
_ftext = .;
|
||||||
|
.text :
|
||||||
|
{ }
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
SECTIONS
|
||||||
|
{
|
||||||
|
/* Stuff in .text.sram is located in SRAM */
|
||||||
|
. = 0x00010000;
|
||||||
|
.text.sram : {
|
||||||
|
*(.text.sram)
|
||||||
|
}
|
||||||
|
text_sram_end = .;
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------*/
|
||||||
|
/* Code and read-only segment */
|
||||||
|
/*--------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
/* Begining of code and text segment */
|
||||||
|
/* In "flashpmem" mode everything above 1MB in the flash is */
|
||||||
|
/* mapped directly into the processor address space */
|
||||||
|
. = 0x00100000;
|
||||||
|
_ftext = .;
|
||||||
|
PROVIDE( eprol = . );
|
||||||
|
|
||||||
|
/* text: Program code section */
|
||||||
|
.text :
|
||||||
|
{
|
||||||
|
*(.text)
|
||||||
|
*(.text.*)
|
||||||
|
*(.gnu.linkonce.t.*)
|
||||||
|
}
|
||||||
|
|
||||||
|
/* init: Code to execute before main (called by crt0.S) */
|
||||||
|
.init :
|
||||||
|
{
|
||||||
|
KEEP( *(.init) )
|
||||||
|
}
|
||||||
|
|
||||||
|
/* fini: Code to execute after main (called by crt0.S) */
|
||||||
|
.fini :
|
||||||
|
{
|
||||||
|
KEEP( *(.fini) )
|
||||||
|
}
|
||||||
|
|
||||||
|
/* rodata: Read-only data */
|
||||||
|
.rodata :
|
||||||
|
{
|
||||||
|
*(.rdata)
|
||||||
|
*(.rodata)
|
||||||
|
*(.rodata.*)
|
||||||
|
*(.gnu.linkonce.r.*)
|
||||||
|
}
|
||||||
|
|
||||||
|
/* End of code and read-only segment */
|
||||||
|
PROVIDE( etext = . );
|
||||||
|
_etext = .;
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------*/
|
||||||
|
/* Global constructor/destructor segement */
|
||||||
|
/*--------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
.preinit_array :
|
||||||
|
{
|
||||||
|
PROVIDE_HIDDEN (__preinit_array_start = .);
|
||||||
|
KEEP (*(.preinit_array))
|
||||||
|
PROVIDE_HIDDEN (__preinit_array_end = .);
|
||||||
|
}
|
||||||
|
|
||||||
|
.init_array :
|
||||||
|
{
|
||||||
|
PROVIDE_HIDDEN (__init_array_start = .);
|
||||||
|
KEEP (*(SORT(.init_array.*)))
|
||||||
|
KEEP (*(.init_array ))
|
||||||
|
PROVIDE_HIDDEN (__init_array_end = .);
|
||||||
|
}
|
||||||
|
|
||||||
|
.fini_array :
|
||||||
|
{
|
||||||
|
PROVIDE_HIDDEN (__fini_array_start = .);
|
||||||
|
KEEP (*(SORT(.fini_array.*)))
|
||||||
|
KEEP (*(.fini_array ))
|
||||||
|
PROVIDE_HIDDEN (__fini_array_end = .);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------*/
|
||||||
|
/* Other misc gcc segments (this was in idt32.ld) */
|
||||||
|
/*--------------------------------------------------------------------*/
|
||||||
|
/* I am not quite sure about these sections but it seems they are for
|
||||||
|
C++ exception handling. I think .jcr is for "Java Class
|
||||||
|
Registration" but it seems to end up in C++ binaries as well. */
|
||||||
|
|
||||||
|
.eh_frame_hdr : { *(.eh_frame_hdr) }
|
||||||
|
.eh_frame : { KEEP( *(.eh_frame) ) }
|
||||||
|
.gcc_except_table : { *(.gcc_except_table) }
|
||||||
|
.jcr : { KEEP (*(.jcr)) }
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------*/
|
||||||
|
/* Initialized data segment */
|
||||||
|
/*--------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
/* everything below is goind to be in SRAM */
|
||||||
|
. = text_sram_end;
|
||||||
|
|
||||||
|
/* Start of initialized data segment */
|
||||||
|
. = ALIGN(16);
|
||||||
|
_fdata = .;
|
||||||
|
|
||||||
|
/* data: Writable data */
|
||||||
|
.data :
|
||||||
|
{
|
||||||
|
*(.data)
|
||||||
|
*(.data.*)
|
||||||
|
*(.gnu.linkonce.d.*)
|
||||||
|
}
|
||||||
|
|
||||||
|
/* End of initialized data segment */
|
||||||
|
PROVIDE( edata = . );
|
||||||
|
_edata = .;
|
||||||
|
|
||||||
|
/* Have _gp point to middle of sdata/sbss to maximize displacement range */
|
||||||
|
. = ALIGN(16);
|
||||||
|
_gp = . + 0x800;
|
||||||
|
|
||||||
|
/* Writable small data segment */
|
||||||
|
.sdata :
|
||||||
|
{
|
||||||
|
*(.sdata)
|
||||||
|
*(.sdata.*)
|
||||||
|
*(.srodata.*)
|
||||||
|
*(.gnu.linkonce.s.*)
|
||||||
|
}
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------*/
|
||||||
|
/* Uninitialized data segment */
|
||||||
|
/*--------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
/* Start of uninitialized data segment */
|
||||||
|
. = ALIGN(8);
|
||||||
|
_fbss = .;
|
||||||
|
|
||||||
|
/* Writable uninitialized small data segment */
|
||||||
|
.sbss :
|
||||||
|
{
|
||||||
|
*(.sbss)
|
||||||
|
*(.sbss.*)
|
||||||
|
*(.gnu.linkonce.sb.*)
|
||||||
|
}
|
||||||
|
|
||||||
|
/* bss: Uninitialized writeable data section */
|
||||||
|
. = .;
|
||||||
|
_bss_start = .;
|
||||||
|
.bss :
|
||||||
|
{
|
||||||
|
*(.bss)
|
||||||
|
*(.bss.*)
|
||||||
|
*(.gnu.linkonce.b.*)
|
||||||
|
*(COMMON)
|
||||||
|
}
|
||||||
|
|
||||||
|
/* End of uninitialized data segment (used by syscalls.c for heap) */
|
||||||
|
PROVIDE( end = . );
|
||||||
|
_end = ALIGN(8);
|
||||||
|
}
|
141
examples/osd/ico-wallclock-time/wallclock.c
Normal file
141
examples/osd/ico-wallclock-time/wallclock.c
Normal file
|
@ -0,0 +1,141 @@
|
||||||
|
/*
|
||||||
|
* 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 "params.h"
|
||||||
|
#include "contiki-net.h"
|
||||||
|
#include "er-coap-engine.h"
|
||||||
|
#include "xtime.h"
|
||||||
|
#include "cron.h"
|
||||||
|
#include "time_resource.h"
|
||||||
|
#include "jsonparse.h"
|
||||||
|
#include "icosoc.h"
|
||||||
|
|
||||||
|
#define DEBUG 1
|
||||||
|
#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)
|
||||||
|
#define LOOP_INTERVAL (5 * 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 CHANNEL_802_15_4
|
||||||
|
PRINTF("RF channel: %u\n", CHANNEL_802_15_4);
|
||||||
|
#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)
|
||||||
|
*/
|
||||||
|
printf ("Loop-interval: %ld\n", (uint32_t)LOOP_INTERVAL);
|
||||||
|
etimer_set (&loop_periodic_timer, LOOP_INTERVAL);
|
||||||
|
while (1) {
|
||||||
|
clock_time_t cl = clock_time ();
|
||||||
|
printf ("In while loop: %08lx%08lx\n", (uint32_t)(cl>>32), (uint32_t)cl);
|
||||||
|
PROCESS_WAIT_EVENT();
|
||||||
|
if (etimer_expired (&loop_periodic_timer)) {
|
||||||
|
cron ();
|
||||||
|
etimer_reset (&loop_periodic_timer);
|
||||||
|
}
|
||||||
|
} /* while (1) */
|
||||||
|
|
||||||
|
PROCESS_END();
|
||||||
|
}
|
|
@ -170,7 +170,7 @@ off(int keep_radio_on)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
static unsigned short
|
static clock_time_t
|
||||||
channel_check_interval(void)
|
channel_check_interval(void)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
|
|
17
platform/pico-rv32-icoboard/Makefile.pico-rv32-icoboard
Normal file
17
platform/pico-rv32-icoboard/Makefile.pico-rv32-icoboard
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
CONTIKI_TARGET_DIRS = . dev apps net
|
||||||
|
|
||||||
|
CONTIKI_CORE=contiki-main
|
||||||
|
CONTIKI_TARGET_MAIN = ${CONTIKI_CORE}.o
|
||||||
|
CONTIKI_TARGET_SOURCEFILES += contiki-main.c params.c \
|
||||||
|
cc2520.c cc2520-arch.c cc2520-arch-sfd.c
|
||||||
|
|
||||||
|
CONTIKIPICORV32=$(CONTIKI)/cpu/pico-rv32
|
||||||
|
CONTIKIBOARD=.
|
||||||
|
|
||||||
|
CONTIKI_PLAT_DEFS = -DAUTO_CRC_PADDING=2
|
||||||
|
|
||||||
|
MCU=pico-rv32
|
||||||
|
|
||||||
|
include $(CONTIKIPICORV32)/Makefile.pico-rv32
|
||||||
|
MODULES += core/net/mac core/net core/net/mac/sicslowmac \
|
||||||
|
core/net/mac/contikimac dev/cc2520
|
62
platform/pico-rv32-icoboard/cc2520-arch-sfd.c
Normal file
62
platform/pico-rv32-icoboard/cc2520-arch-sfd.c
Normal file
|
@ -0,0 +1,62 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2011, Swedish Institute of Computer Science
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "contiki.h"
|
||||||
|
#include "dev/spi.h"
|
||||||
|
#include "dev/cc2520/cc2520.h"
|
||||||
|
#include "irq.h"
|
||||||
|
|
||||||
|
extern volatile uint8_t cc2520_sfd_counter;
|
||||||
|
extern volatile uint16_t cc2520_sfd_start_time;
|
||||||
|
extern volatile uint16_t cc2520_sfd_end_time;
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
/* SFD interrupt for timestamping radio packets */
|
||||||
|
void cc2520_timerb1_interrupt (void)
|
||||||
|
{
|
||||||
|
ENERGEST_ON(ENERGEST_TYPE_IRQ);
|
||||||
|
/* This timer needs 32768 ticks per second */
|
||||||
|
if(CC2520_SFD_IS_1) {
|
||||||
|
cc2520_sfd_counter++;
|
||||||
|
cc2520_sfd_start_time = (uint16_t)(clock_time() * 32768 / F_CPU);
|
||||||
|
} else {
|
||||||
|
cc2520_sfd_counter = 0;
|
||||||
|
cc2520_sfd_end_time = (uint16_t)(clock_time() * 32768 / F_CPU);
|
||||||
|
}
|
||||||
|
ENERGEST_OFF(ENERGEST_TYPE_IRQ);
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
void
|
||||||
|
cc2520_arch_sfd_init(void)
|
||||||
|
{
|
||||||
|
register_irq (4, cc2520_arch_sfd_init);
|
||||||
|
enable_irq (4);
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
38
platform/pico-rv32-icoboard/cc2520-arch-sfd.h
Normal file
38
platform/pico-rv32-icoboard/cc2520-arch-sfd.h
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2011, 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 CC2520_ARCH_SFD_H
|
||||||
|
#define CC2520_ARCH_SFD_H
|
||||||
|
|
||||||
|
extern volatile uint8_t cc2520_arch_sfd_counter;
|
||||||
|
extern volatile uint16_t cc2520_arch_sfd_start_time;
|
||||||
|
extern volatile uint16_t cc2520_arch_sfd_end_time;
|
||||||
|
|
||||||
|
void cc2520_arch_sfd_init(void);
|
||||||
|
|
||||||
|
#endif /* CC2520_ARCH_SFD_H */
|
86
platform/pico-rv32-icoboard/cc2520-arch.c
Normal file
86
platform/pico-rv32-icoboard/cc2520-arch.c
Normal file
|
@ -0,0 +1,86 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2011, Swedish Institute of Computer Science
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "contiki.h"
|
||||||
|
#include "contiki-net.h"
|
||||||
|
|
||||||
|
#include "icosoc.h"
|
||||||
|
#include "cc2520-arch.h"
|
||||||
|
#include "dev/cc2520/cc2520.h"
|
||||||
|
|
||||||
|
#ifdef CC2520_CONF_SFD_TIMESTAMPS
|
||||||
|
#define CONF_SFD_TIMESTAMPS CC2520_CONF_SFD_TIMESTAMPS
|
||||||
|
#endif /* CC2520_CONF_SFD_TIMESTAMPS */
|
||||||
|
|
||||||
|
#ifndef CONF_SFD_TIMESTAMPS
|
||||||
|
#define CONF_SFD_TIMESTAMPS 0
|
||||||
|
#endif /* CONF_SFD_TIMESTAMPS */
|
||||||
|
|
||||||
|
#ifdef CONF_SFD_TIMESTAMPS
|
||||||
|
#include "cc2520-arch-sfd.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
void icosoc_cc2520_fifop_irq (void)
|
||||||
|
{
|
||||||
|
ENERGEST_ON(ENERGEST_TYPE_IRQ);
|
||||||
|
|
||||||
|
/* See Errata 1.2.2 */
|
||||||
|
if (!CC2520_FIFOP_IS_1) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!CC2520_FIFOP_IS_1) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
cc2520_interrupt();
|
||||||
|
|
||||||
|
ENERGEST_OFF(ENERGEST_TYPE_IRQ);
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
void
|
||||||
|
cc2520_arch_init(void)
|
||||||
|
{
|
||||||
|
// All inputs except for RESET pin which is an output
|
||||||
|
icosoc_cc2520_io_dir (BV(CC2520_RESET_SHIFT));
|
||||||
|
|
||||||
|
// Prescaler set to F_CPU / 4MHz will result in <= 4MHz
|
||||||
|
// rate, chip should perform up to 8MHz)
|
||||||
|
icosoc_cc2520_spi_prescale (F_CPU / 4000000);
|
||||||
|
|
||||||
|
// SPI mode cpol, cpha
|
||||||
|
icosoc_cc2520_spi_mode (0, 0);
|
||||||
|
|
||||||
|
#if CONF_SFD_TIMESTAMPS
|
||||||
|
cc2520_arch_sfd_init();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
CC2520_SPI_DISABLE(); /* Unselect radio. */
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
107
platform/pico-rv32-icoboard/cc2520-arch.h
Normal file
107
platform/pico-rv32-icoboard/cc2520-arch.h
Normal file
|
@ -0,0 +1,107 @@
|
||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \file
|
||||||
|
* Platform configuration for the pico-rv32-icoboard
|
||||||
|
* Definitions for the radio hardware access
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef RADIO_CONF_H_
|
||||||
|
#define RADIO_CONF_H_
|
||||||
|
|
||||||
|
#include "icosoc.h"
|
||||||
|
|
||||||
|
extern void icosoc_cc2520_fifop_irq (void);
|
||||||
|
|
||||||
|
/* the low-level radio driver */
|
||||||
|
#define NETSTACK_CONF_RADIO cc2520_driver
|
||||||
|
|
||||||
|
/*
|
||||||
|
* SPI bus - CC2520 pin configuration.
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Two instructions loop at F_CPU for 326us
|
||||||
|
#define CC2520_CONF_SYMBOL_LOOP_COUNT (F_CPU / (3067 * 2))
|
||||||
|
|
||||||
|
#define CC2520_RESET_SHIFT 0
|
||||||
|
#define CC2520_CCA_SHIFT 1
|
||||||
|
|
||||||
|
/* Pin status.CC2520 */
|
||||||
|
/* This implementation doesn't have enough pins for CC2520_FIFO_IS_1
|
||||||
|
* on a separate pin. So we need to explicitly check for FIFO in
|
||||||
|
* register with a SPI command, this is bit 7 in FSMSTAT1, see p.119 of
|
||||||
|
* spec.
|
||||||
|
*/
|
||||||
|
#define CC2520_FIFOP_IS_1 (!!(icosoc_cc2520_fifop_read()))
|
||||||
|
#define CC2520_FIFO_IS_1 (!!(getreg(CC2520_FSMSTAT1) & BV(7)))
|
||||||
|
#define CC2520_SFD_IS_1 (!!(icosoc_cc2520_sfd_read()))
|
||||||
|
#define CC2520_CCA_IS_1 (!!(icosoc_cc2520_io_get() & (1<<CC2520_CCA_SHIFT)))
|
||||||
|
|
||||||
|
/* The CC2520 reset pin. */
|
||||||
|
#define SET_RESET_INACTIVE() \
|
||||||
|
(icosoc_cc2520_io_set(icosoc_cc2520_io_get() | (1<<CC2520_RESET_SHIFT)))
|
||||||
|
#define SET_RESET_ACTIVE() \
|
||||||
|
(icosoc_cc2520_io_set(icosoc_cc2520_io_get() & (~(1<<CC2520_RESET_SHIFT))))
|
||||||
|
|
||||||
|
/* CC2520 voltage regulator enable pin: direct connection to VCC,
|
||||||
|
we don't have enough pins to turn power on/off and the fpga will
|
||||||
|
always need full power anyway
|
||||||
|
*/
|
||||||
|
#define SET_VREG_ACTIVE()
|
||||||
|
#define SET_VREG_INACTIVE()
|
||||||
|
|
||||||
|
/* CC2520 rising edge trigger for external interrupt 3 (FIFOP). */
|
||||||
|
#define CC2520_FIFOP_INT_INIT() \
|
||||||
|
( register_irq(3, icosoc_cc2520_fifop_irq) \
|
||||||
|
, icosoc_cc2520_fifop_set_config (icosoc_cc2520_fifop_trigger_re) \
|
||||||
|
, icosoc_cc2520_fifop_read() \
|
||||||
|
)
|
||||||
|
|
||||||
|
/* FIFOP on external interrupt 3. */
|
||||||
|
#define CC2520_ENABLE_FIFOP_INT() (enable_irq(3))
|
||||||
|
#define CC2520_DISABLE_FIFOP_INT() (disable_irq(3))
|
||||||
|
#define CC2520_CLEAR_FIFOP_INT() (icosoc_cc2520_fifop_read())
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Enables/disables CC2520 access to the SPI bus (Chip Select)
|
||||||
|
*/
|
||||||
|
|
||||||
|
// ENABLE CSn (active low)
|
||||||
|
#define CC2520_SPI_ENABLE() icosoc_cc2520_spi_cs(0)
|
||||||
|
// DISABLE CSn (active low)
|
||||||
|
#define CC2520_SPI_DISABLE() icosoc_cc2520_spi_cs(1)
|
||||||
|
#define CC2520_SPI_IS_ENABLED() icosoc_cc2520_spi_getcs()
|
||||||
|
|
||||||
|
#if TIMESYNCH_CONF_ENABLED
|
||||||
|
#undef CC2520_CONF_SFD_TIMESTAMPS
|
||||||
|
#define CC2520_CONF_SFD_TIMESTAMPS 1
|
||||||
|
#endif /* TIMESYNCH_CONF_ENABLED */
|
||||||
|
|
||||||
|
#endif /* RADIO_CONF_H_ */
|
194
platform/pico-rv32-icoboard/contiki-conf.h
Normal file
194
platform/pico-rv32-icoboard/contiki-conf.h
Normal file
|
@ -0,0 +1,194 @@
|
||||||
|
/*
|
||||||
|
* 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"
|
||||||
|
#include "icosoc.h"
|
||||||
|
#include "irq.h"
|
||||||
|
#include "cc2520-arch.h"
|
||||||
|
|
||||||
|
/* Platform name, type, and MCU clock rate */
|
||||||
|
#define PLATFORM_NAME "PicoRV32-icoboard"
|
||||||
|
#define PLATFORM_TYPE PICORV32
|
||||||
|
#ifndef F_CPU
|
||||||
|
#define F_CPU (ICOSOC_CLOCK_FREQ_HZ)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Clock ticks per second, our timer runs with cpu freq */
|
||||||
|
#define CLOCK_CONF_SECOND ((long long)F_CPU)
|
||||||
|
|
||||||
|
typedef uint64_t clock_time_t;
|
||||||
|
#define CLOCK_LT(a,b) ((a)<(b))
|
||||||
|
|
||||||
|
/* RADIOSTATS is used in 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 CC2520_CONF_AUTOACK 1
|
||||||
|
#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_ */
|
373
platform/pico-rv32-icoboard/contiki-main.c
Normal file
373
platform/pico-rv32-icoboard/contiki-main.c
Normal file
|
@ -0,0 +1,373 @@
|
||||||
|
/*
|
||||||
|
* 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 "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/cc2520/cc2520.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
|
||||||
|
irq_init();
|
||||||
|
clock_init();
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
cc2520_set_pan_addr(params_get_panid(),params_get_panaddr(),(uint8_t *)&addr.u8);
|
||||||
|
cc2520_set_channel(params_get_channel());
|
||||||
|
// set in init to 1dBm, needs special encoding!
|
||||||
|
//cc2520_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
|
||||||
|
PRINTA ( "%s %s, channel %u , check rate %u Hz tx power %u\n"
|
||||||
|
, NETSTACK_MAC.name
|
||||||
|
, NETSTACK_RDC.name
|
||||||
|
, cc2520_get_channel()
|
||||||
|
, (uint16_t)(CLOCK_SECOND
|
||||||
|
/ (NETSTACK_RDC.channel_check_interval() == 0
|
||||||
|
? 1
|
||||||
|
: NETSTACK_RDC.channel_check_interval()
|
||||||
|
)
|
||||||
|
)
|
||||||
|
, cc2520_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
|
||||||
|
|
||||||
|
/* 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)
|
||||||
|
{
|
||||||
|
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 = 0, j = 1;
|
||||||
|
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);
|
||||||
|
}
|
81
platform/pico-rv32-icoboard/params.c
Normal file
81
platform/pico-rv32-icoboard/params.c
Normal 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
|
||||||
|
}
|
70
platform/pico-rv32-icoboard/params.h
Normal file
70
platform/pico-rv32-icoboard/params.h
Normal file
|
@ -0,0 +1,70 @@
|
||||||
|
#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
|
||||||
|
|
||||||
|
#define CHANNEL_802_15_4 25 // default frequency (11-26)
|
||||||
|
|
||||||
|
#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_ */
|
Loading…
Reference in a new issue