Implement etimer callback

This commit is contained in:
Ralf Schlatterbeck 2016-05-05 16:18:21 +02:00
parent c043a00bb4
commit 0232e6c9dc
8 changed files with 47 additions and 11 deletions

View file

@ -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

View file

@ -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 <stdio.h> // 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();
}
}
/** @} */
/** @} */

View file

@ -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);
}

View file

@ -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_ */

View file

@ -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

View file

@ -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

View file

@ -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 */

View file

@ -114,6 +114,7 @@ uint16_t *p=&__bss_end;
} while (p<SP-10); //don't overwrite our own stack
}
#endif
clock_init();
PRINTA("\n*******Booting %s*******\n",CONTIKI_VERSION_STRING);