diff --git a/cpu/pico-rv32/Makefile.pico-rv32 b/cpu/pico-rv32/Makefile.pico-rv32 index cf6e55dd6..0f20936e5 100644 --- a/cpu/pico-rv32/Makefile.pico-rv32 +++ b/cpu/pico-rv32/Makefile.pico-rv32 @@ -22,7 +22,7 @@ STRIP = riscv32-unknown-elf-strip ifdef WERROR CFLAGSWERROR=-Werror endif -CFLAGSNO = -Wall -g \ +CFLAGSNO = -Wall -march=RV32IXcustom -g \ -I$(CONTIKI)/platform/$(TARGET) \ -I. -I$(CONTIKI)/core -I$(CONTIKI_CPU) CFLAGS += $(CFLAGSNO) -Os diff --git a/cpu/pico-rv32/dev/clock.c b/cpu/pico-rv32/dev/clock.c index 58e131ec7..af4374710 100644 --- a/cpu/pico-rv32/dev/clock.c +++ b/cpu/pico-rv32/dev/clock.c @@ -55,29 +55,40 @@ * 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. + * 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 // FIXME +// 1/128 second ticks +#define CLOCK_TIMER_PERIOD (F_CPU >> 7) + static volatile clock_time_t count; unsigned long offset; -long sleepseconds; + +void irq_handler(uint32_t irq_mask, uint32_t *regs); /*---------------------------------------------------------------------------*/ /** - * No need to init + * Initialize interrupt handler */ void clock_init(void) { + icosoc_irq(irq_handler); + icosoc_maskirq(0); + icosoc_timer(CLOCK_TIMER_PERIOD); } /*---------------------------------------------------------------------------*/ /** @@ -147,5 +158,29 @@ clock_adjust_ticks(clock_time_t howmany) { } +/** \brief irq handler + * for running interrupts every 1/128 second. + */ + +void +irq_handler(uint32_t irq_mask, uint32_t *regs) +{ + // timer interrupt + if (irq_mask & 1) { + // FIXME: Want to call rtimer_run_next(); + icosoc_timer(CLOCK_TIMER_PERIOD); + if(etimer_pending()) { + etimer_request_poll(); + } + } + // SBREAK, ILLINS or BUSERROR + if (irq_mask & 4) { + printf("Bus Error!\n"); + } + // Can we distinguish ILLINS and SBREAK? + if (irq_mask & 2) { + icosoc_sbreak(); + } +} /** @} */ /** @} */ diff --git a/cpu/pico-rv32/rtimer-arch.c b/cpu/pico-rv32/rtimer-arch.c index dee4481b8..d47585429 100644 --- a/cpu/pico-rv32/rtimer-arch.c +++ b/cpu/pico-rv32/rtimer-arch.c @@ -45,9 +45,11 @@ 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); } diff --git a/cpu/pico-rv32/rtimer-arch.h b/cpu/pico-rv32/rtimer-arch.h index 272dece0c..311200746 100644 --- a/cpu/pico-rv32/rtimer-arch.h +++ b/cpu/pico-rv32/rtimer-arch.h @@ -38,6 +38,4 @@ #define RTIMER_ARCH_SECOND F_CPU #define rtimer_arch_now() (clock_time ()) - -void rtimer_arch_sleep(rtimer_clock_t howlong); #endif /* RTIMER_ARCH_H_ */ diff --git a/examples/osd/ico-wallclock-time/.gitignore b/examples/osd/ico-wallclock-time/.gitignore index de3098d4b..64ebf92f8 100644 --- a/examples/osd/ico-wallclock-time/.gitignore +++ b/examples/osd/ico-wallclock-time/.gitignore @@ -4,7 +4,9 @@ icosoc.mk icosoc.pcf icosoc.v icosoc.ys +icosoc.rpt wallclock.co wallclock.pico-rv32-icoboard icosoc.c icosoc.h +testbench.v diff --git a/examples/osd/ico-wallclock-time/wallclock.c b/examples/osd/ico-wallclock-time/wallclock.c index f2b57b4cd..9c63bf65a 100644 --- a/examples/osd/ico-wallclock-time/wallclock.c +++ b/examples/osd/ico-wallclock-time/wallclock.c @@ -73,10 +73,7 @@ PROCESS (wallclock, "Wallclock Example Server"); AUTOSTART_PROCESSES(&wallclock); //#define LOOP_INTERVAL (30 * CLOCK_SECOND) -//#define LOOP_INTERVAL (3 * CLOCK_SECOND) -// one more than this will currently hang, probably due to -// non-implemented etimer callback. -#define LOOP_INTERVAL (25461) +#define LOOP_INTERVAL (5 * CLOCK_SECOND) /* * Set led to on or off, we abuse the given pointer to simply carry the diff --git a/platform/pico-rv32-icoboard/contiki-conf.h b/platform/pico-rv32-icoboard/contiki-conf.h index 170e0dac7..1d1baa1cf 100644 --- a/platform/pico-rv32-icoboard/contiki-conf.h +++ b/platform/pico-rv32-icoboard/contiki-conf.h @@ -42,12 +42,13 @@ #define CONTIKI_CONF_H_ #include "rv32def.h" +#include "icosoc.h" /* Platform name, type, and MCU clock rate */ #define PLATFORM_NAME "PicoRV32-icoboard" #define PLATFORM_TYPE PICORV32 #ifndef F_CPU -#define F_CPU 2000000ULL +#define F_CPU (ICOSOC_CLOCK_FREQ_HZ) #endif /* Clock ticks per second, our timer runs with cpu freq */ diff --git a/platform/pico-rv32-icoboard/contiki-main.c b/platform/pico-rv32-icoboard/contiki-main.c index 42cee88f6..85efabfc2 100644 --- a/platform/pico-rv32-icoboard/contiki-main.c +++ b/platform/pico-rv32-icoboard/contiki-main.c @@ -114,6 +114,7 @@ uint16_t *p=&__bss_end; } while (p