Make Arduino timer stuff work on Contiki

New discovery: Contiki also uses timer 0. With almost the same interface
as Arduino. So we now completely get rid of wiring.c (only the main
file, the other wiring_xxx stay) and implement Arduino timer, delay, etc
in terms of the corresponding Contiki routines. Verified that now delay
works as expected. The LED in examples/osd/arduino-sketch blinks!

Before this, the arduino_init routine in wiring.c destroyed the timer-0
initialization of contiki, making both, contiki timer implementation
*and* contiki timer implementation fail if the arduino_init routine was
called. Now both work.

Squashed with following bug-fix commit.
This commit is contained in:
Ralf Schlatterbeck 2014-06-26 18:37:13 +02:00
parent 08abd8807d
commit c46d6afa39
7 changed files with 61 additions and 273 deletions

View file

@ -48,6 +48,12 @@
*
*/
#ifdef __cplusplus
extern "C"{
#endif
#include "contiki.h"
/*
* The OSD hardware only supports timer 3 for PWM, timer 2 is used by
* contiki for sleep/wakeup timing and is not usable for PWM.
@ -65,9 +71,39 @@
#define arduino_pwm_timer_init() \
(hwtimer_ini (3, HWT_WGM_PWM_PHASE_8_BIT, HWT_CLOCK_PRESCALER_64, 0))
/*
* micros on arduino takes timer overflows into account.
* We put in the seconds counter. To get a consistent seconds / ticks
* value we have to disable interrupts.
*/
static inline uint32_t micros (void)
{
uint32_t ticks;
uint8_t sreg = SREG;
cli ();
ticks = clock_seconds () * 1000000L
+ clock_time () * 1000L / CLOCK_SECOND;
SREG = sreg;
return ticks;
}
/*
* millis counts only internal timer ticks since start, not trying to do
* something about overflows. Note that we don't try to emulate overflow
* behaviour of arduino implementation.
*/
#define millis() (((uint32_t)clock_time())*1000L/CLOCK_SECOND)
#define micros() (clock_seconds()*1000L+
#define delay(ms) clock_delay_msec(ms)
#define delayMicroseconds(us) clock_delay_usec(us)
/*
* VI settings, see coding style
* ex:ts=8:et:sw=2
*/
#ifdef __cplusplus
} // extern "C"
#endif
/** @} */