Add clock_delay_us and clock_set_seconds to clock.h. Modify clock_wait to use clock_time_t.

Remove the troublesome avr/dev/delay.* files.
Add PLATFORM_NAME and combine the confusing *_REVISION defines into a single PLATFORM_TYPE
This commit is contained in:
David Kopf 2012-04-09 15:49:53 -04:00
parent ea667cef2d
commit cac4e9a222
39 changed files with 810 additions and 481 deletions

View file

@ -6,17 +6,28 @@
* \defgroup clock Clock library
*
* The clock library is the interface between Contiki and the platform
* specific clock functionality. The clock library performs a single
* function: measuring time. Additionally, the clock library provides
* a macro, CLOCK_SECOND, which corresponds to one second of system
* time.
* specific clock functionality. The clock library defines a macro,
* CLOCK_SECOND, to convert seconds into the tick resolution of the platform.
* Typically this is 1-10 milliseconds, e.g. 4*CLOCK_SECOND could be 512.
* A 16 bit counter would thus overflow every 1-10 minutes.
* Platforms use the tick interrupt to maintain a long term count
* of seconds since startup.
*
* Platforms may also implement rtimers for greater time resolution
* and for real-time interrupts, These use a corresponding RTIMER_SECOND.
*
* \note These timers do not necessarily have a common divisor or are phase locked.
* One may be crystal controlled and the other may not. Low power operation
* or sleep will often use one for wake and disable the other, then give
* it a tick correction after wakeup.
*
* \note The clock library need in many cases not be used
* directly. Rather, the \ref timer "timer library" or the \ref etimer
* "event timers" should be used.
* directly. Rather, the \ref timer "timer library", \ref etimer
* "event timers", or \ref trimer "rtimer library" should be used.
*
* \sa \ref timer "Timer library"
* \sa \ref etimer "Event timers"
* \sa \ref rtimer "Realtime library"
*
* @{
*/
@ -53,24 +64,22 @@
*
* Author: Adam Dunkels <adam@sics.se>
*
* $Id: clock.h,v 1.11 2009/01/24 15:20:11 adamdunkels Exp $
*/
#ifndef __CLOCK_H__
#define __CLOCK_H__
#include "contiki-conf.h"
#if 0 /* XXX problems with signedness and use in timer_expired(). #if:ed it out for now. */
/**
* Check if a clock time value is less than another clock time value.
*
* This macro checks if a clock time value is less than another clock
* time value. This macro is needed to correctly handle wrap-around of
* clock time values.
* A second, measured in system clock time.
*
* \hideinitializer
*/
#define CLOCK_LT(a, b) ((clock_time_t)((a) - (b)) < ((clock_time_t)(~((clock_time_t)0)) >> 1))
#endif /* 0 */
#ifdef CLOCK_CONF_SECOND
#define CLOCK_SECOND CLOCK_CONF_SECOND
#else
#define CLOCK_SECOND (clock_time_t)32
#endif
/**
* Initialize the clock library.
@ -90,24 +99,45 @@ void clock_init(void);
*/
CCIF clock_time_t clock_time(void);
void clock_delay(unsigned int);
/**
* A second, measured in system clock time.
* Get the current value of the platform seconds.
*
* \hideinitializer
* This could be the number of seconds since startup, or
* since a standard epoch.
*
* \return The value.
*/
#ifdef CLOCK_CONF_SECOND
#define CLOCK_SECOND CLOCK_CONF_SECOND
#else
#define CLOCK_SECOND (clock_time_t)32
#endif
int clock_fine_max(void);
unsigned short clock_fine(void);
CCIF unsigned long clock_seconds(void);
/**
* Set the value of the platform seconds.
* \param sec The value to set.
*
*/
void clock_set_seconds(unsigned long sec);
/**
* Wait for a given number of ticks.
* \param t How many ticks.
*
*/
void clock_wait(clock_time_t t);
/**
* Delay a given number of microseconds.
* \param dt How many microseconds to delay.
*
* \note Interrupts could increase the delay by a variable amount.
*/
void clock_delay_usec(uint16_t dt);
/**
* Deprecated platform-specific routines.
*
*/
int clock_fine_max(void);
unsigned short clock_fine(void);
void clock_delay(unsigned int delay);
#endif /* __CLOCK_H__ */

View file

@ -1,4 +1,69 @@
/*
* Copyright (c) 2012, 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.
*
* This file is part of the Contiki operating system.
*
*/
/**
* \brief This module contains AVR-specific code to implement
* the Contiki core clock functions.
*
* \author David Kopf <dak664@embarqmail.com> and others.
*
*/
/** \addtogroup avr
* @{
*/
/**
* \defgroup avrclock AVR clock implementation
* @{
*/
/**
* \file
* This file contains AVR-specific code to implement the Contiki core clock functions.
*
*/
/**
* These routines define the AVR-specific calls declared in /core/sys/clock.h
* CLOCK_SECOND is the number of ticks per second.
* It is defined through CONF_CLOCK_SECOND in the contiki-conf.h for each platform.
* The usual AVR defaults are 128 or 125 ticks per second, counting a prescaled CPU clock
* using the 8 bit timer0.
*
* clock_time_t is usually declared by the platform as an unsigned 16 bit data type,
* thus intervals up to 512 or 524 seconds can be measured with ~8 millisecond precision.
* For longer intervals the 32 bit clock_seconds() is available.
*
* Since a carry to a higer byte can occur during an interrupt, declaring them non-static
* for direct examination can cause occasional time reversals!
*
* clock-avr.h contains the specific setup code for each mcu.
*/
#include "sys/clock.h"
#include "dev/clock-avr.h"
#include "sys/etimer.h"
@ -6,25 +71,18 @@
#include <avr/io.h>
#include <avr/interrupt.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.
As clock_time_t is an unsigned 16 bit data type, intervals up to 512 or 524 seconds
can be measured with ~8 millisecond precision.
For longer intervals a 32 bit global is incremented every second.
clock-avr.h contains the specific setup code for each mcu.
/* Two tick counters avoid a software divide when CLOCK_SECOND is not a power of two. */
#if CLOCK_SECOND && (CLOCK_SECOND - 1)
#define TWO_COUNTERS 1
#endif
*/
/* count is a 16 bit tick counter that wraps every ~10 minutes, returned by clock_time() */
/* count is usually a 16 bit variable, although the platform can declare it otherwise */
static volatile clock_time_t count;
#if TWO_COUNTERS
/* scount is the 8 bit counter that counts ticks modulo CLOCK_SECONDS */
static volatile uint8_t scount;
/* seconds is the number of seconds since startup, returned by clock_seconds() */
#endif
/* seconds is available globally but non-atomic update during interrupt can cause time reversals */
volatile unsigned long seconds;
/* sleepseconds is the number of seconds sleeping since startup, available globally */
long sleepseconds;
@ -50,99 +108,243 @@ extern volatile uint8_t rf230_calibrate;
static uint8_t calibrate_interval;
#endif
/*---------------------------------------------------------------------------*/
/**
* Start the clock by enabling the timer comparison interrupts.
*/
void
clock_init(void)
{
cli ();
OCRSetup();
sei ();
}
/*---------------------------------------------------------------------------*/
/**
* Return the tick counter. When 16 bit it typically wraps every 10 minutes.
* The comparison avoids the need to disable clock interrupts for an atomic
* read of the multi-byte variable.
*/
clock_time_t
clock_time(void)
{
clock_time_t tmp;
do {
tmp = count;
} while(tmp != count);
return tmp;
}
/*---------------------------------------------------------------------------*/
/**
* Return seconds, default is time since startup.
* The comparison avoids the need to disable clock interrupts for an atomic
* read of the four-byte variable.
*/
unsigned long
clock_seconds(void)
{
unsigned long tmp;
do {
tmp = seconds;
} while(tmp != seconds);
return tmp;
}
/*---------------------------------------------------------------------------*/
/**
* Set seconds, e.g. to a standard epoch for an absolute date/time.
*/
void
clock_set_seconds(unsigned long sec)
{
seconds = sec;
}
/*---------------------------------------------------------------------------*/
/**
* Wait for a number of clock ticks.
*/
void
clock_wait(clock_time_t t)
{
clock_time_t endticks = clock_time() + t;
if (sizeof(clock_time_t) == 1) {
while ((signed char )(clock_time() - endticks) < 0) {;}
} else if (sizeof(clock_time_t) == 2) {
while ((signed short)(clock_time() - endticks) < 0) {;}
} else {
while ((signed long )(clock_time() - endticks) < 0) {;}
}
}
/*---------------------------------------------------------------------------*/
/**
* Delay the CPU for up to 65535*(4000000/F_CPU) microseconds.
* Copied from _delay_loop_2 in AVR library delay_basic.h, 4 clocks per loop.
* For accurate short delays, inline _delay_loop_2 in the caller, use a constant
* value for the delay, and disable interrupts if necessary.
*/
static inline void my_delay_loop_2(uint16_t __count) __attribute__((always_inline));
void
my_delay_loop_2(uint16_t __count)
{
__asm__ volatile (
"1: sbiw %0,1" "\n\t"
"brne 1b"
: "=w" (__count)
: "0" (__count)
);
}
void
clock_delay_usec(uint16_t howlong)
{
#if 0
/* Accurate delay at any frequency, but introduces a 64 bit intermediate
* and has a 279 clock overhead.
*/
if(howlong<=(uint16_t)(279000000UL/F_CPU)) return;
howlong-=(uint16_t) (279000000UL/F_CPU);
my_delay_loop_2(((uint64_t)(howlong) * (uint64_t) F_CPU) / 4000000ULL);
/* Remaining numbers tweaked for the breakpoint CPU frequencies */
/* Add other frequencies as necessary */
#elif F_CPU>=16000000UL
if(howlong<1) return;
my_delay_loop_2((howlong*(uint16_t)(F_CPU/3250000)));
#elif F_CPU >= 12000000UL
if(howlong<2) return;
howlong-=(uint16_t) (3*12000000/F_CPU);
my_delay_loop_2((howlong*(uint16_t)(F_CPU/3250000)));
#elif F_CPU >= 8000000UL
if(howlong<4) return;
howlong-=(uint16_t) (3*8000000/F_CPU);
my_delay_loop_2((howlong*(uint16_t)(F_CPU/2000000))/2);
#elif F_CPU >= 4000000UL
if(howlong<5) return;
howlong-=(uint16_t) (4*4000000/F_CPU);
my_delay_loop_2((howlong*(uint16_t)(F_CPU/2000000))/2);
#elif F_CPU >= 2000000UL
if(howlong<11) return;
howlong-=(uint16_t) (10*2000000/F_CPU);
my_delay_loop_2((howlong*(uint16_t)(F_CPU/1000000))/4);
#elif F_CPU >= 1000000UL
if(howlong<=17) return;
howlong-=(uint16_t) (17*1000000/F_CPU);
my_delay_loop_2((howlong*(uint16_t)(F_CPU/1000000))/4);
#else
howlong >> 5;
if (howlong < 1) return;
my_delay_loop_2(howlong);
#endif
}
#if 0
/*---------------------------------------------------------------------------*/
/* This routine can be called to add seconds to the clock after a sleep
* of an integral number of seconds.
/**
* 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_adjust_seconds(uint8_t howmany) {
seconds += howmany;
sleepseconds +=howmany;
count += howmany * CLOCK_SECOND;
#if RADIOSTATS
if (RF230_receive_on) radioontime += howmany;
#endif
void
clock_delay(unsigned int howlong)
{
if(howlong<2) return;
clock_delay_usec((45*howlong)>>4);
}
#endif
/*---------------------------------------------------------------------------*/
/**
* Delay up to 65535 milliseconds.
* \param dt How many milliseconds to delay.
*
* Neither interrupts nor the watchdog timer is disabled over the delay.
* Platforms are not required to implement this call.
* \note This will break for CPUs clocked above 260 MHz.
*/
void
clock_delay_msec(uint16_t howlong)
{
/*---------------------------------------------------------------------------*/
/* This routine can be called to add ticks to the clock after a sleep.
* Leap ticks or seconds can (rarely) be introduced if the ISR is not blocked.
*/
void clock_adjust_ticks(uint16_t howmany) {
// uint8_t sreg = SREG;cli();
count += howmany;
howmany+= scount;
while(howmany >= CLOCK_SECOND) {
howmany -= CLOCK_SECOND;
seconds++;
sleepseconds++;
#if RADIOSTATS
if (RF230_receive_on) radioontime += 1;
#if F_CPU>=16000000
while(howlong--) clock_delay_usec(1000);
#elif F_CPU>=8000000
uint16_t i=996;
while(howlong--) {clock_delay_usec(i);i=999;}
#elif F_CPU>=4000000
uint16_t i=992;
while(howlong--) {clock_delay_usec(i);i=999;}
#elif F_CPU>=2000000
uint16_t i=989;
while(howlong--) {clock_delay_usec(i);i=999;}
#else
uint16_t i=983;
while(howlong--) {clock_delay_usec(i);i=999;}
#endif
}
scount = howmany;
// SREG=sreg;
}
/*---------------------------------------------------------------------------*/
//SIGNAL(SIG_OUTPUT_COMPARE0)
/**
* Adjust the system current clock time.
* \param dt 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)
{
uint8_t sreg = SREG;cli();
count += howmany;
#if TWO_COUNTERS
howmany+= scount;
#endif
while(howmany >= CLOCK_SECOND) {
howmany -= CLOCK_SECOND;
seconds++;
sleepseconds++;
#if RADIOSTATS
if (RF230_receive_on) radioontime += 1;
#endif
}
#if TWO_COUNTERS
scount = howmany;
#endif
SREG=sreg;
}
/*---------------------------------------------------------------------------*/
/* This it the timer comparison match interrupt.
* It maintains the tick counter, clock_seconds, and etimer updates.
*
* If the interrupts derive from an external crystal, the CPU instruction
* clock can optionally be phase locked to it. This allows accurate rtimer
* interrupts for strobe detection during radio duty cycling.
* Phase lock is accomplished by adjusting OSCCAL based on the phase error
* since the last interrupt.
*/
/*---------------------------------------------------------------------------*/
#if defined(DOXYGEN)
/** \brief ISR for the TIMER0 or TIMER2 interrupt as defined in
* clock-avr.h for the particular MCU.
*/
void AVR_OUTPUT_COMPARE_INT(void);
#else
ISR(AVR_OUTPUT_COMPARE_INT)
{
count++;
count++;
#if TWO_COUNTERS
if(++scount >= CLOCK_SECOND) {
scount = 0;
#else
if(count%CLOCK_SECOND==0) {
#endif
seconds++;
}
#if F_CPU == 0x800000 && USE_32K_CRYSTAL
/* Special routine to phase lock CPU to 32768 watch crystal.
We are interrupting 128 times per second.
If RTIMER_ARCH_SECOND is a multiple of 128 we can use the residual modulo
128 to determine whether the clock is too fast or too slow.
E.g. for 8192 the phase should be constant modulo 0x40
OSCCAL is started in the lower range at 90, allowed to stabilize, then
rapidly raised or lowered based on the phase comparison.
It gives less phase noise to do this every tick and doesn't seem to hurt anything.
*/
#include "rtimer-arch.h"
{
volatile static uint8_t lockcount;
volatile static int16_t last_phase;
volatile static uint8_t osccalhigh,osccallow;
if (seconds < 60) { //give a minute to stabilize
if(++lockcount >= 8192UL*128/RTIMER_ARCH_SECOND) {
lockcount=0;
rtimer_phase = TCNT3 & 0x0fff;
if (seconds < 2) OSCCAL=100;
if (last_phase > rtimer_phase) osccalhigh=++OSCCAL; else osccallow=--OSCCAL;
last_phase = rtimer_phase;
}
} else {
#if TICK_MODULO
static uint8_t lock_clock;
if (++lock_clock>=TICK_MODULO) {
lock_clock=0;
#endif
uint8_t error = (TCNT3 - last_phase) & 0x3f;
if (error == 0) {
} else if (error<32) {
OSCCAL=osccallow-1;
} else {
OSCCAL=osccalhigh+1;
}
#if TICK_MODULO
}
#endif
}
}
#endif
#if RADIO_CONF_CALIBRATE_INTERVAL
if (++calibrate_interval==0) {
rf230_calibrate=1;
}
/* Force a radio PLL frequency calibration every 256 seconds */
if (++calibrate_interval==0) {
rf230_calibrate=1;
}
#endif
}
#if RADIOSTATS
/* Sample radio on time. Less accurate than ENERGEST but a smaller footprint */
if (RF230_receive_on) {
if (++rcount >= CLOCK_SECOND) {
rcount=0;
@ -150,6 +352,41 @@ volatile static uint8_t osccalhigh,osccallow;
}
}
#endif
#if F_CPU == 0x800000 && USE_32K_CRYSTAL
/* Special routine to phase lock CPU to 32768 watch crystal.
* We are interrupting 128 times per second.
* If RTIMER_ARCH_SECOND is a multiple of 128 we can use the residual modulo
* 128 to determine whether the clock is too fast or too slow.
* E.g. for 8192 the phase should be constant modulo 0x40
* OSCCAL is started in the lower range at 90, allowed to stabilize, then
* rapidly raised or lowered based on the phase comparison.
* It gives less phase noise to do this every tick and doesn't seem to hurt anything.
*/
#include "rtimer-arch.h"
{
volatile static uint8_t lockcount;
volatile static int16_t last_phase;
volatile static uint8_t osccalhigh,osccallow;
if (seconds < 60) { //give a minute to stabilize
if(++lockcount >= 8192UL*128/RTIMER_ARCH_SECOND) {
lockcount=0;
rtimer_phase = TCNT3 & 0x0fff;
if (seconds < 2) OSCCAL=100;
if (last_phase > rtimer_phase) osccalhigh=++OSCCAL; else osccallow=--OSCCAL;
last_phase = rtimer_phase;
}
} else {
uint8_t error = (TCNT3 - last_phase) & 0x3f;
if (error == 0) {
} else if (error<32) {
OSCCAL=osccallow-1;
} else {
OSCCAL=osccalhigh+1;
}
}
}
#endif
#if 1
/* gcc will save all registers on the stack if an external routine is called */
@ -166,80 +403,17 @@ volatile static uint8_t osccalhigh,osccallow;
#define PROCESS_STATE_CALLED 2
if (timerlist) {
if(etimer_process.state == PROCESS_STATE_RUNNING ||
etimer_process.state == PROCESS_STATE_CALLED) {
if(etimer_process.state == PROCESS_STATE_RUNNING || etimer_process.state == PROCESS_STATE_CALLED) {
etimer_process.needspoll = 1;
poll_requested = 1;
}
}
#endif
}
#endif /* defined(DOXYGEN) */
/*---------------------------------------------------------------------------*/
void
clock_init(void)
{
cli ();
OCRSetup();
//scount = count = 0;
sei ();
}
/* Debugging aids */
/*---------------------------------------------------------------------------*/
clock_time_t
clock_time(void)
{
clock_time_t tmp;
do {
tmp = count;
} while(tmp != count);
return tmp;
}
#if 0
/*---------------------------------------------------------------------------*/
/**
* Delay the CPU for a multiple of TODO
*/
void
clock_delay(unsigned int i)
{
for (; i > 0; i--) { /* Needs fixing XXX */
unsigned j;
for (j = 50; j > 0; j--)
asm volatile("nop");
}
}
/*---------------------------------------------------------------------------*/
/**
* Wait for a number of clock ticks.
*
*/
void
clock_wait(int i)
{
clock_time_t start;
start = clock_time();
while(clock_time() - start < (clock_time_t)i);
}
/*---------------------------------------------------------------------------*/
void
clock_set_seconds(unsigned long sec)
{
seconds = sec;
}
#endif
unsigned long
clock_seconds(void)
{
unsigned long tmp;
do {
tmp = seconds;
} while(tmp != seconds);
return tmp;
}
#ifdef HANDLE_UNSUPPORTED_INTERRUPTS
/* Ignore unsupported interrupts, optionally hang for debugging */
/* BADISR is a gcc weak symbol that matches any undefined interrupt */
@ -334,4 +508,6 @@ ISR( _VECTOR(76)) {while (1) x++;}
ISR( _VECTOR(77)) {while (1) x++;}
ISR( _VECTOR(78)) {while (1) x++;}
ISR( _VECTOR(79)) {while (1) x++;}
#endif
#endif
/** @} */
/** @} */

View file

@ -1,29 +0,0 @@
#include "delay.h"
//----------------------------------------------------------------------------
// Wait for a specific time in 100 uSec
// (15 + t*( ((K_DELAY_100us-1)*6)+5 ))
//----------------------------------------------------------------------------
void Delay_100us(unsigned char t) {
unsigned int i;
if (t==0) return;
while (t--) for(i=0;i<K_DELAY_100us; i++);
}
//----------------------------------------------------------------------------
// Wait for a specific time in 1 mSec
// (15 + t*( ((K_DELAY_1ms-1)*6)+5 ))
//----------------------------------------------------------------------------
void Delay_1ms(unsigned char t) {
unsigned int i;
if (t==0) return;
while (t--) for(i=0;i<K_DELAY_1ms; i++);
}
//----------------------------------------------------------------------------
// Wait for a specific time in 10 mSec
// (15 + t*( ((K_DELAY_10ms-1)*6)+5 ))
//----------------------------------------------------------------------------
void Delay_10ms(unsigned char t) {
unsigned int i;
if (t==0) return;
while (t--) for(i=0;i<K_DELAY_10ms; i++);
}

View file

@ -1,9 +0,0 @@
#define F_CPU 15000000
#define K_DELAY_100us F_CPU/61349
#define K_DELAY_1ms F_CPU/6013
#define K_DELAY_10ms F_CPU/600
void Delay_100us(unsigned char t);
void Delay_1ms(unsigned char t);
void Delay_10ms(unsigned char t);

View file

@ -1,5 +1,4 @@
#include "rtl8019.h"
#include "delay.h"
#include "debug.h"
#include "avr/pgmspace.h"
#include "rtlregs.h"
@ -36,6 +35,8 @@
* Corrected the overrun function - overrun flag was not reset after overrun
* Added support for the Imagecraft Compiler
* Added support to communicate with the NIC using general I/O ports
* March 10, 2012 - David Kopf
* Use contiki clock_delay_usec call.
*
*****************************************************************************/
@ -85,7 +86,25 @@ void writeRTL(unsigned char address, unsigned char data)
#endif
void
delay_msec(uint16_t howlong)
{
#if F_CPU>=16000000
while(howlong--) clock_delay_usec(1000);
#elif F_CPU>=8000000
uint16_t i=996;
while(howlong--) {clock_delay_usec(i);i=999;}
#elif F_CPU>=4000000
uint16_t i=992;
while(howlong--) {clock_delay_usec(i);i=999;}
#elif F_CPU>=2000000
uint16_t i=989;
while(howlong--) {clock_delay_usec(i);i=999;}
#else
uint16_t i=983;
while(howlong--) {clock_delay_usec(i);i=999;}
#endif
}
/*****************************************************************************
* readRTL(RTL_ADDRESS)
* Args: unsigned char RTL_ADDRESS - register offset of RTL register
@ -191,7 +210,7 @@ volatile unsigned char *base = (unsigned char *)0x8300;
* Description: Simply toggles the pin that resets the NIC
*****************************************************************************/
/*#define HARD_RESET_RTL8019() do{ sbi(RTL8019_RESET_PORT, RTL8019_RESET_PIN); \
Delay_10ms(1); \
delay_msec(10); \
cbi(RTL8019_RESET_PORT, RTL8019_RESET_PIN);} \
while(0)*/
@ -503,7 +522,7 @@ void overrun(void)
data_L = readRTL(CR);
writeRTL(CR, 0x21);
Delay_1ms(2);
delay_msec(2);
writeRTL(RBCR0, 0x00);
writeRTL(RBCR1, 0x00);
if(!(data_L & 0x04))
@ -686,7 +705,11 @@ void initRTL8019(void)
*/
nic_write(NIC_PG3_EECR, 0);
/* NutSleep(WAIT500);*/
Delay_10ms(50);
delay_msec(500);
/*
* Switch to register page 0 and set data configuration register
@ -772,7 +795,10 @@ void initRTL8019(void)
nic_write(NIC_PG0_TCR, 0);
/* NutSleep(WAIT500);*/
Delay_10ms(50);
delay_msec(500);
#endif /* 0 */
@ -788,7 +814,8 @@ void initRTL8019(void)
nic_write(NIC_PG3_CONFIG2, NIC_CONFIG2_BSELB);
nic_write(NIC_PG3_EECR, 0);
/* Delay(50000);*/
Delay_10ms(200);
delay_msec(2000);
nic_write(NIC_CR, NIC_CR_STP | NIC_CR_RD2);
nic_write(NIC_PG0_DCR, NIC_DCR_LS | NIC_DCR_FT1);
nic_write(NIC_PG0_RBCR0, 0);
@ -813,7 +840,7 @@ void initRTL8019(void)
nic_write(NIC_CR, NIC_CR_STA | NIC_CR_RD2);
nic_write(NIC_PG0_TCR, 0);
/* Delay(1000000)*/
Delay_10ms(200);
delay_msec(2000);
nic_write(NIC_CR, NIC_CR_STA | NIC_CR_RD2 | NIC_CR_PS0 | NIC_CR_PS1);
@ -874,10 +901,10 @@ void initRTL8019(void)
// do soft reset
writeRTL( ISR, readRTL(ISR) ) ;
Delay_10ms(5);
delay_msec(50);
writeRTL(CR,0x21); // stop the NIC, abort DMA, page 0
Delay_1ms(2); // make sure nothing is coming in or going out
delay_msec(2); // make sure nothing is coming in or going out
writeRTL(DCR, DCR_INIT); // 0x58
writeRTL(RBCR0,0x00);
writeRTL(RBCR1,0x00);
@ -888,7 +915,7 @@ void initRTL8019(void)
writeRTL(BNRY, RXSTART_INIT);
writeRTL(PSTOP, RXSTOP_INIT);
writeRTL(CR, 0x61);
Delay_1ms(2);
delay_msec(2);
writeRTL(CURR, RXSTART_INIT);
writeRTL(PAR0+0, MYMAC_0);

View file

@ -76,16 +76,16 @@
// RCB_B : RZ200 kit from Atmel based on 1281V
// ZIGBIT : Zigbit module from Meshnetics
// IRIS : IRIS Mote from MEMSIC
#define RAVEN_D 4
#define RAVENUSB_C 1
#define RCB_B 2
#define ZIGBIT 3
#define RAVEN_D 1
#define RAVENUSB_C 2
#define RCB_B 3
#define ZIGBIT 4
#define IRIS 5
#if RCB_REVISION == RCB_B
#if PLATFORM_TYPE == RCB_B
/* 1281 rcb */
# define SSPORT B
# define SSPIN (0x00)
@ -104,7 +104,7 @@
# define TICKTIMER 3
# define HAS_SPARE_TIMER
#elif HARWARE_REVISION == ZIGBIT
#elif PLATFORM_TYPE == ZIGBIT
/* 1281V Zigbit */
# define SSPORT B
# define SSPIN (0x00)
@ -170,7 +170,7 @@
# define HAS_CW_MODE
# define HAS_SPARE_TIMER
#elif HARWARE_REVISION == IRIS
#elif PLATFORM_TYPE == IRIS
/* 1281 IRIS */
# define SSPORT B
# define SSPIN (0x00)
@ -296,7 +296,7 @@
#error "Clock speed not supported."
#endif
#if HARWARE_REVISION == ZIGBIT
#if PLATFORM_TYPE == ZIGBIT
// IRQ E5 for Zigbit example
#define RADIO_VECT INT5_vect
#define HAL_ENABLE_RADIO_INTERRUPT( ) { ( EIMSK |= ( 1 << INT5 ) ) ; EICRB |= 0x0C ; PORTE &= ~(1<<PE5); DDRE &= ~(1<<DDE5); }

View file

@ -9,6 +9,7 @@
* Mike Vidales mavida404@gmail.com
* Kevin Brown kbrown3@uccs.edu
* Nate Bohlmann nate@elfwerks.com
* David Kopf dak664@embarqmail.com
*
* All rights reserved.
*
@ -67,25 +68,22 @@
* \brief Change these values to port to other platforms.
* \{
*/
/* Define all possible revisions here */
/* Define all possible platform types/revisions here. */
// Don't use zero, it will match if undefined!
// RAVEN_D : Raven kit with LCD display
// RAVENUSB_C : used for USB key or Raven card
// RAVENUSB_C : used for RZRAVEN USB key
// RCB_B : RZ200 kit from Atmel based on 1281V
// ZIGBIT : Zigbit module from Meshnetics
// ATMEGA128RFA1 : Bare chip with internal radio
// IRIS : IRIS Mote from MEMSIC
#define RAVEN_D 4
#define RAVENUSB_C 1
#define RCB_B 2
#define ZIGBIT 3
#define ATMEGA128RFA1 4
#define RAVENUSB_C 1
#define RAVEN_D 2
#define RCB_B 3
#define ZIGBIT 4
#define IRIS 5
#define ATMEGA128RFA1 6
/* TODO: Move to platform (or CPU specific) */
#if RCB_REVISION == RCB_B
#if PLATFORM_TYPE == RCB_B
/* 1281 rcb */
# define SSPORT B
# define SSPIN (0x00)
@ -104,7 +102,7 @@
# define TICKTIMER 3
# define HAS_SPARE_TIMER
#elif HARWARE_REVISION == ZIGBIT
#elif PLATFORM_TYPE == ZIGBIT
/* 1281V Zigbit */
# define SSPORT B
# define SSPIN (0x00)
@ -126,7 +124,7 @@
//# define HAS_SPARE_TIMER // Not used
#elif RAVEN_REVISION == RAVEN_D
#elif PLATFORM_TYPE == RAVEN_D
/* 1284 raven */
# define SSPORT B
# define SSPIN (0x04)
@ -148,7 +146,7 @@
# define HAS_CW_MODE
# define HAS_SPARE_TIMER
#elif RAVEN_REVISION == RAVENUSB_C
#elif PLATFORM_TYPE == RAVENUSB_C
/* 1287USB raven */
# define SSPORT B
# define SSPIN (0x00)
@ -170,24 +168,8 @@
# define HAS_CW_MODE
# define HAS_SPARE_TIMER
#elif HARWARE_REVISION == ATMEGA128RFA1
#elif PLATFORM_TYPE == ATMEGA128RFA1
/* ATmega1281 with internal AT86RF231 radio */
#if 0
# define SSPORT B
# define SSPIN (0x04)
# define SPIPORT B
# define MOSIPIN (0x05)
# define MISOPIN (0x06)
# define SCKPIN (0x07)
# define RSTPORT B
# define RSTPIN (0x01)
# define IRQPORT D
# define IRQPIN (0x06)
# define SLPTRPORT B
# define SLPTRPIN (0x03)
# define TXCWPORT B
# define TXCWPIN (0x00)
#endif
# define SLPTRPORT TRXPR
# define SLPTRPIN 1
# define USART 1
@ -198,7 +180,6 @@
#elif CONTIKI_TARGET_MULLE
/* mulle 5.2 (TODO: move to platform specific) */
# define SSPORT 3
# define SSPIN 5
# define MOSIPORT 1
@ -215,8 +196,7 @@
# define SLPTRPIN 7
# define HAS_SPARE_TIMER
#elif HARWARE_REVISION == IRIS
#elif PLATFORM_TYPE == IRIS
/* 1281 IRIS */
# define SSPORT B
# define SSPIN (0x00)
@ -238,7 +218,7 @@
//# define HAS_SPARE_TIMER // Not used
#else
#error "Platform undefined in hal.h"
#error "PLATFORM_TYPE undefined in hal.h"
#endif
@ -427,7 +407,7 @@
#error "Clock speed not supported."
#endif
#if HARWARE_REVISION == ZIGBIT
#if PLATFORM_TYPE == ZIGBIT
// IRQ E5 for Zigbit example
#define RADIO_VECT INT5_vect
#define HAL_ENABLE_RADIO_INTERRUPT( ) { ( EIMSK |= ( 1 << INT5 ) ) ; EICRB |= 0x0C ; PORTE &= ~(1<<PE5); DDRE &= ~(1<<DDE5); }

View file

@ -317,7 +317,6 @@ uint32_t longhowlong;
watchdog_start();
/* Adjust clock.c for the time spent sleeping */
extern void clock_adjust_ticks(uint16_t howmany);
longhowlong=CLOCK_CONF_SECOND;
longhowlong*=howlong;
clock_adjust_ticks(longhowlong/RTIMER_ARCH_SECOND);

View file

@ -73,7 +73,7 @@ clock_delay(unsigned int len)
* Wait for a multiple of ~8 ms (a tick)
*/
void
clock_wait(int i)
clock_wait(clock_time_t i)
{
clock_time_t start;

View file

@ -75,7 +75,7 @@ clock_delay(unsigned int len)
* Wait for a multiple of ~8 ms (a tick)
*/
void
clock_wait(int i)
clock_wait(clock_time_t i)
{
clock_time_t start;

View file

@ -78,7 +78,12 @@ clock_init()
*TMR_ENBL = 0xf; /* enable all the timers --- why not? */
enable_irq(TMR);
/* Do startup scan of the ADC */
#if CLOCK_CONF_SAMPLEADC
adc_reading[8]=0;
adc_init();
while (adc_reading[8]==0) adc_service();
#endif
}
void tmr0_isr(void) {
@ -88,9 +93,15 @@ void tmr0_isr(void) {
seconds++;
#if BLINK_SECONDS
leds_toggle(LEDS_GREEN);
#endif
/* ADC can be serviced every tick or every second */
#if CLOCK_CONF_SAMPLEADC > 1
adc_service();
#endif
}
#if CLOCK_CONF_SAMPLEADC == 1
adc_service();
#endif
if(etimer_pending() &&
(etimer_next_expiration_time() - current_clock - 1) > MAX_TICKS) {
etimer_request_poll();
@ -98,9 +109,9 @@ void tmr0_isr(void) {
/* clear the compare flags */
clear_bit(*TMR(0,SCTRL),TCF);
clear_bit(*TMR(0,CSCTRL),TCF1);
clear_bit(*TMR(0,CSCTRL),TCF2);
clear_bit(*TMR(0,SCTRL),TCF);
clear_bit(*TMR(0,CSCTRL),TCF1);
clear_bit(*TMR(0,CSCTRL),TCF2);
return;
} else {
/* this timer didn't create an interrupt condition */
@ -120,13 +131,63 @@ clock_seconds(void)
return seconds;
}
/* clock delay from cc2430 */
/* I don't see any documentation about how this routine is suppose to behave */
void
clock_delay(unsigned int len)
clock_wait(clock_time_t t)
{
unsigned int i;
for(i = 0; i< len; i++) {
asm("nop");
}
clock_time_t endticks = current_clock + t;
while ((signed long)(current_clock - endticks) < 0) {;}
}
/*---------------------------------------------------------------------------*/
/**
* Delay the CPU for up to 65535 microseconds.
* Use the 250KHz MACA clock for longer delays to avoid interrupt effects.
* However that can't be used if the radio is being power cycled!
*/
void
clock_delay_usec(uint16_t howlong)
{
if(howlong<2) return;
#if 0
if(howlong>400) {
volatile register uint32_t i=*MACA_CLK+howlong/4;
while (i > *MACA_CLK) ;
return;
}
#endif
/* These numbers at 25MHz, gcc -Os */
volatile register uint32_t i=4000*howlong/2301;
while(--i);
}
/*---------------------------------------------------------------------------*/
/**
* Delay the CPU for up to 65535 milliseconds. The watchdog is NOT disabled.
*/
void
clock_delay_msec(uint16_t howlong)
{
while(howlong--) clock_delay_usec(1000);
}
/*---------------------------------------------------------------------------*/
/**
* 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)
{
if(howlong--) return;
clock_delay_usec((283*howlong)/100);
}
/*---------------------------------------------------------------------------*/
/**
* Adjust clock ticks after a cpu sleep.
*/
void clock_adjust_ticks(clock_time_t howmany) {
/* Add seconds */
seconds+=howmany/CLOCK_CONF_SECOND;
/* Handle tick overflow */
if(((current_clock % CLOCK_CONF_SECOND) + (howmany % CLOCK_CONF_SECOND)) >= CLOCK_CONF_SECOND) seconds++;
/* Add ticks */
current_clock+=howmany;
}

View file

@ -55,9 +55,4 @@ typedef unsigned short uip_stats_t;
typedef uint32_t clock_time_t;
void clock_delay(unsigned int us2);
void clock_wait(int ms10);
void clock_set_seconds(unsigned long s);
unsigned long clock_seconds(void);
#endif
#endif

View file

@ -186,7 +186,7 @@ clock_delay(unsigned int i)
*
*/
void
clock_wait(int i)
clock_wait(clock_time_t i)
{
clock_time_t start;

View file

@ -183,7 +183,7 @@ clock_delay(unsigned int i)
*
*/
void
clock_wait(int i)
clock_wait(clock_time_t i)
{
clock_time_t start;

View file

@ -46,6 +46,7 @@
#include "dev/stm32w_systick.h"
#include "contiki.h"
#include "sys/clock.h"
#include "uart1.h"
#include "dev/leds.h"
@ -122,7 +123,7 @@ void clock_delay(unsigned int i)
* Wait for a multiple of 1 ms.
*
*/
void clock_wait(int i)
void clock_wait(clock_timt_t i)
{
clock_time_t start;

View file

@ -41,38 +41,36 @@
#ifndef __CONTIKI_CONF_H__
#define __CONTIKI_CONF_H__
/* MCU and clock rate */
#define PLATFORM PLATFORM_AVR
#define HARWARE_REVISION ATMEGA128RFA1
/* Platform name, type, and MCU clock rate */
#define PLATFORM_NAME "RFA1"
#define PLATFORM_TYPE ATMEGA128RFA1
#ifndef F_CPU
#define F_CPU 8000000UL
#endif
#include <stdint.h>
/* These names are deprecated, use C99 names. */
typedef int32_t s32_t;
typedef unsigned char u8_t;
typedef unsigned short u16_t;
typedef unsigned long u32_t;
typedef unsigned short clock_time_t;
typedef unsigned short uip_stats_t;
typedef unsigned long off_t;
void clock_delay(unsigned int us2);
void clock_wait(int ms10);
void clock_set_seconds(unsigned long s);
unsigned long clock_seconds(void);
/* Maximum timer interval for 16 bit clock_time_t */
#define INFINITE_TIME 0xffff
/* Clock ticks per second */
/* The AVR tick interrupt usually is done with an 8 bit counter around 128 Hz.
* 125 Hz needs slightly more overhead during the interrupt, as does a 32 bit
* clock_time_t.
*/
/* Clock ticks per second */
#define CLOCK_CONF_SECOND 128
/* Maximum tick interval is 0xffff/128 = 511 seconds */
#if 1
/* 16 bit counter overflows every ~10 minutes */
typedef unsigned short clock_time_t;
#define CLOCK_LT(a,b) ((signed short)((a)-(b)) < 0)
#define INFINITE_TIME 0xffff
#define RIME_CONF_BROADCAST_ANNOUNCEMENT_MAX_TIME INFINITE_TIME/CLOCK_CONF_SECOND /* Default uses 600 */
#define COLLECT_CONF_BROADCAST_ANNOUNCEMENT_MAX_TIME INFINITE_TIME/CLOCK_CONF_SECOND /* Default uses 600 */
#else
typedef unsigned long clock_time_t;
#define CLOCK_LT(a,b) ((signed long)((a)-(b)) < 0)
#define INFINITE_TIME 0xffffffff
#endif
/* These routines are not part of the contiki core but can be enabled in cpu/avr/clock.c */
void clock_delay_msec(uint16_t howlong);
void clock_adjust_ticks(clock_time_t howmany);
/* Michael Hartman's atmega128rfa1 board has an external 32768Hz crystal connected to TOSC1 and 2 pins similar to the Raven 1284p */
/* and theoretically can use TIMER2 with it to keep time. Else TIMER0 is used. */
@ -94,7 +92,8 @@ unsigned long clock_seconds(void);
/* Default is 4096. Currently used only when elfloader is present. Not tested on Raven */
//#define MMEM_CONF_SIZE 256
/* Starting address for code received via the codeprop facility. Not tested on Raven */
/* Starting address for code received via the codeprop facility. Not tested. */
typedef unsigned long off_t;
//#define EEPROMFS_ADDR_CODEPROP 0x8000
/* Logging adds 200 bytes to program size. RS232 output slows down webserver. */
@ -107,6 +106,10 @@ unsigned long clock_seconds(void);
/* 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
/* Available watchdog timeouts depend on mcu. Default is WDTO_2S. -1 Disables the watchdog. */
/* AVR Studio simulator tends to reboot due to clocking the WD 8 times too fast */
//#define WATCHDOG_CONF_TIMEOUT -1

View file

@ -215,7 +215,6 @@ void micro_sleep(uint8_t howlong)
sleep_mode(); // Sleep
/* Adjust clock.c for the time spent sleeping */
extern void clock_adjust_ticks(uint16_t howmany);
clock_adjust_ticks(howlong * CLOCK_SECOND);
// if (TIMSK2&(1<<OCIE2A)) break; // Exit sleep if not awakened by TIMER2

View file

@ -43,43 +43,40 @@
#ifndef __CONTIKI_CONF_H__
#define __CONTIKI_CONF_H__
/* MCU and clock rate */
#define PLATFORM PLATFORM_AVR
#define RAVEN_REVISION RAVEN_D
/* Platform name, type, and MCU clock rate */
#define PLATFORM_NAME "Raven"
#define PLATFORM_TYPE RAVEN_D
#ifndef F_CPU
#define F_CPU 8000000UL
#endif
/* MCU_CONF_LOW_WEAR will remove the signature and eeprom from the .elf file */
/* This reduces reprogramming wear during development */
#define MCU_CONF_LOW_WEAR 0
//#define MCU_CONF_LOW_WEAR 1
#include <stdint.h>
/* These names are deprecated, use C99 names. */
typedef int32_t s32_t;
typedef unsigned char u8_t;
typedef unsigned short u16_t;
typedef unsigned long u32_t;
typedef unsigned short clock_time_t;
typedef unsigned short uip_stats_t;
typedef unsigned long off_t;
void clock_delay(unsigned int us2);
void clock_wait(int ms10);
void clock_set_seconds(unsigned long s);
unsigned long clock_seconds(void);
/* Maximum timer interval for 16 bit clock_time_t */
#define INFINITE_TIME 0xffff
/* The AVR tick interrupt usually is done with an 8 bit counter around 128 Hz.
* 125 Hz needs slightly more overhead during the interrupt, as does a 32 bit
* clock_time_t.
*/
/* Clock ticks per second */
#define CLOCK_CONF_SECOND 128
/* Maximum tick interval is 0xffff/128 = 511 seconds */
#if 1
/* 16 bit counter overflows every ~10 minutes */
typedef unsigned short clock_time_t;
#define CLOCK_LT(a,b) ((signed short)((a)-(b)) < 0)
#define INFINITE_TIME 0xffff
#define RIME_CONF_BROADCAST_ANNOUNCEMENT_MAX_TIME INFINITE_TIME/CLOCK_CONF_SECOND /* Default uses 600 */
#define COLLECT_CONF_BROADCAST_ANNOUNCEMENT_MAX_TIME INFINITE_TIME/CLOCK_CONF_SECOND /* Default uses 600 */
#else
typedef unsigned long clock_time_t;
#define CLOCK_LT(a,b) ((signed long)((a)-(b)) < 0)
#define INFINITE_TIME 0xffffffff
#endif
/* These routines are not part of the contiki core but can be enabled in cpu/avr/clock.c */
void clock_delay_msec(uint16_t howlong);
void clock_adjust_ticks(clock_time_t howmany);
/* The 1284p can use TIMER2 with the external 32768Hz crystal to keep time. Else TIMER0 is used. */
/* The sleep timer in raven-lcd.c also uses the crystal and adds a TIMER2 interrupt routine if not already define by clock.c */
@ -100,6 +97,7 @@ unsigned long clock_seconds(void);
//#define MMEM_CONF_SIZE 256
/* Starting address for code received via the codeprop facility. Not tested on Raven */
typedef unsigned long off_t;
//#define EEPROMFS_ADDR_CODEPROP 0x8000
/* RADIO_CONF_CALIBRATE_INTERVAL is used in rf230bb and clock.c. If nonzero a 256 second interval is used */
@ -112,6 +110,11 @@ unsigned long clock_seconds(void);
/* More extensive stats */
#define ENERGEST_CONF_ON 1
/* Packet statistics */
typedef unsigned short uip_stats_t;
#define UIP_STATISTICS 0
/* Possible watchdog timeouts depend on mcu. Default is WDTO_2S. -1 Disables the watchdog. */
/* AVR Studio simulator tends to reboot due to clocking the WD 8 times too fast */
//#define WATCHDOG_CONF_TIMEOUT -1
@ -143,7 +146,7 @@ unsigned long clock_seconds(void);
/* TX routine does automatic cca and optional backoff */
#define RDC_CONF_HARDWARE_CSMA 1
/* Allow MCU sleeping between channel checks */
#define RDC_CONF_MCU_SLEEP 1
#define RDC_CONF_MCU_SLEEP 0
#else
#define PACKETBUF_CONF_HDR_SIZE 0 //RF230 combined driver/mac handles headers internally
#endif /*RF230BB */
@ -270,11 +273,11 @@ unsigned long clock_seconds(void);
#define QUEUEBUF_CONF_REF_NUM 2
/* Allocate remaining RAM. Not much left due to queuebuf increase */
#define UIP_CONF_MAX_CONNECTIONS 2
#define UIP_CONF_MAX_LISTENPORTS 4
#define UIP_CONF_UDP_CONNS 5
#define UIP_CONF_DS6_NBR_NBU 4
#define UIP_CONF_MAX_LISTENPORTS 2
#define UIP_CONF_UDP_CONNS 4
#define UIP_CONF_DS6_NBR_NBU 10
#define UIP_CONF_DS6_DEFRT_NBU 2
#define UIP_CONF_DS6_PREFIX_NBU 3
#define UIP_CONF_DS6_PREFIX_NBU 2
#define UIP_CONF_DS6_ROUTE_NBU 4
#define UIP_CONF_DS6_ADDR_NBU 3
#define UIP_CONF_DS6_MADDR_NBU 0

View file

@ -47,40 +47,38 @@
//#pragma mark Basic Configuration
/* ************************************************************************** */
/* MCU and clock rate */
#define PLATFORM PLATFORM_AVR
#define RAVEN_REVISION RAVENUSB_C
/* Platform name, type, and MCU clock rate */
#define PLATFORM_NAME "RAVENUSB"
#define PLATFORM_TYPE RAVENUSB_C
#ifndef F_CPU
#define F_CPU 8000000UL
#define F_CPU 8000000UL
#endif
#include <stdbool.h>
#include <stdint.h>
#include <string.h>
/* These names are deprecated, use C99 names. */
typedef int32_t s32_t;
typedef unsigned char u8_t;
typedef unsigned short u16_t;
typedef unsigned long u32_t;
typedef unsigned short clock_time_t;
typedef unsigned short uip_stats_t;
typedef unsigned long off_t;
void clock_delay(unsigned int us2);
void clock_wait(int ms10);
void clock_set_seconds(unsigned long s);
unsigned long clock_seconds(void);
/* Maximum timer interval for 16 bit clock_time_t */
#define INFINITE_TIME 0xffff
/* Clock ticks per second */
/* The AVR tick interrupt usually is done with an 8 bit counter around 128 Hz.
* 125 Hz needs slightly more overhead during the interrupt, as does a 32 bit
* clock_time_t.
*/
/* Clock ticks per second */
#define CLOCK_CONF_SECOND 125
/* Maximum tick interval is 0xffff/125 = 524 seconds */
#define RIME_CONF_BROADCAST_ANNOUNCEMENT_MAX_TIME CLOCK_CONF_SECOND * 524UL /* Default uses 600UL */
#define COLLECT_CONF_BROADCAST_ANNOUNCEMENT_MAX_TIME CLOCK_CONF_SECOND * 524UL /* Default uses 600UL */
#if 1
/* 16 bit counter overflows every ~10 minutes */
typedef unsigned short clock_time_t;
#define CLOCK_LT(a,b) ((signed short)((a)-(b)) < 0)
#define INFINITE_TIME 0xffff
#define RIME_CONF_BROADCAST_ANNOUNCEMENT_MAX_TIME INFINITE_TIME/CLOCK_CONF_SECOND /* Default uses 600 */
#define COLLECT_CONF_BROADCAST_ANNOUNCEMENT_MAX_TIME INFINITE_TIME/CLOCK_CONF_SECOND /* Default uses 600 */
#else
typedef unsigned long clock_time_t;
#define CLOCK_LT(a,b) ((signed long)((a)-(b)) < 0)
#define INFINITE_TIME 0xffffffff
#endif
/* These routines are not part of the contiki core but can be enabled in cpu/avr/clock.c */
void clock_delay_msec(uint16_t howlong);
void clock_adjust_ticks(clock_time_t howmany);
/* Use EEPROM settings manager, or hard-coded EEPROM reads? */
/* Generate random MAC address on first startup? */
@ -98,6 +96,7 @@ unsigned long clock_seconds(void);
//#define MMEM_CONF_SIZE 256
/* Starting address for code received via the codeprop facility. Not tested on Jackdaw */
typedef unsigned long off_t;
//#define EEPROMFS_ADDR_CODEPROP 0x8000
/* Simple stack monitor. Status is displayed from the USB menu with 'm' command */
@ -265,6 +264,8 @@ extern void mac_log_802_15_4_rx(const uint8_t* buffer, size_t total_len);
#define UIP_CONF_UDP_CHECKSUMS 1
#define UIP_CONF_TCP_SPLIT 0
typedef unsigned short uip_stats_t;
#define UIP_CONF_STATISTICS 1
/* Network setup */

View file

@ -44,17 +44,39 @@
#include <stdint.h>
typedef int32_t s32_t;
//typedef int32_t s32_t;
/*
* MCU and clock rate
*/
#define MCU_MHZ 8
#define PLATFORM PLATFORM_AVR
#define RCB_REVISION RCB_B
/* Platform name, type, and MCU clock rate */
#define PLATFORM_NAME "RCB"
#define PLATFORM_TYPE RCB_B
#ifndef F_CPU
#define F_CPU 8000000UL
#endif
/* The AVR tick interrupt usually is done with an 8 bit counter around 128 Hz.
* 125 Hz needs slightly more overhead during the interrupt, as does a 32 bit
* clock_time_t.
*/
/* Clock ticks per second */
#define CLOCK_CONF_SECOND 125
#if 1
/* 16 bit counter overflows every ~10 minutes */
typedef unsigned short clock_time_t;
#define CLOCK_LT(a,b) ((signed short)((a)-(b)) < 0)
#define INFINITE_TIME 0xffff
#define RIME_CONF_BROADCAST_ANNOUNCEMENT_MAX_TIME INFINITE_TIME/CLOCK_CONF_SECOND /* Default uses 600 */
#define COLLECT_CONF_BROADCAST_ANNOUNCEMENT_MAX_TIME INFINITE_TIME/CLOCK_CONF_SECOND /* Default uses 600 */
#else
typedef unsigned long clock_time_t;
#define CLOCK_LT(a,b) ((signed long)((a)-(b)) < 0)
#define INFINITE_TIME 0xffffffff
#endif
/* These routines are not part of the contiki core but can be enabled in cpu/avr/clock.c */
void clock_delay_msec(uint16_t howlong);
void clock_adjust_ticks(clock_time_t howmany);
/* COM port to be used for SLIP connection */
#define SLIP_PORT RS232_PORT_0
@ -114,18 +136,13 @@ typedef int32_t s32_t;
#define UIP_CONF_TCP_SPLIT 0
typedef unsigned short clock_time_t;
/* These names are deprecated, use C99 names. */
typedef unsigned char u8_t;
/*typedef unsigned char u8_t;
typedef unsigned short u16_t;
typedef unsigned long u32_t;
*/
typedef unsigned short uip_stats_t;
typedef unsigned long off_t;
void clock_delay(unsigned int us2);
void clock_wait(int ms10);
void clock_set_seconds(unsigned long s);
unsigned long clock_seconds(void);
#endif /* __CONTIKI_CONF_H__ */

View file

@ -42,18 +42,36 @@
#ifndef __CONTIKI_CONF_H__
#define __CONTIKI_CONF_H__
/* MCU and clock rate */
#define PLATFORM PLATFORM_AVR
#define HARWARE_REVISION ZIGBIT
/* Platform name, type, and MCU clock rate */
#define PLATFORM_NAME "Zigbit"
#define PLATFORM_TYPE ZIGBIT
#ifndef F_CPU
#define F_CPU 8000000UL
#endif
#include <stdint.h>
/* The AVR tick interrupt usually is done with an 8 bit counter around 128 Hz.
* 125 Hz needs slightly more overhead during the interrupt, as does a 32 bit
* clock_time_t.
*/
/* Clock ticks per second */
#define CLOCK_CONF_SECOND 125
/* Since clock_time_t is 16 bits, maximum interval is 524 seconds */
#define RIME_CONF_BROADCAST_ANNOUNCEMENT_MAX_TIME CLOCK_CONF_SECOND * 524UL /*Default uses 600*/
/* Maximum time interval (used for timers) */
#if 1
/* 16 bit counter overflows every ~10 minutes */
typedef unsigned short clock_time_t;
#define CLOCK_LT(a,b) ((signed short)((a)-(b)) < 0)
#define INFINITE_TIME 0xffff
#define RIME_CONF_BROADCAST_ANNOUNCEMENT_MAX_TIME INFINITE_TIME/CLOCK_CONF_SECOND /* Default uses 600 */
#define COLLECT_CONF_BROADCAST_ANNOUNCEMENT_MAX_TIME INFINITE_TIME/CLOCK_CONF_SECOND /* Default uses 600 */
#else
typedef unsigned long clock_time_t;
#define CLOCK_LT(a,b) ((signed long)((a)-(b)) < 0)
#define INFINITE_TIME 0xffffffff
#endif
/* These routines are not part of the contiki core but can be enabled in cpu/avr/clock.c */
void clock_delay_msec(uint16_t howlong);
void clock_adjust_ticks(clock_time_t howmany);
/* COM port to be used for SLIP connection */
#define SLIP_PORT RS232_PORT_0
@ -143,21 +161,15 @@
#define UIP_CONF_TCP_SPLIT 1
#include <stdint.h>
/* These names are deprecated, use C99 names. */
typedef unsigned short clock_time_t;
/*
typedef unsigned char u8_t;
typedef unsigned short u16_t;
typedef unsigned long u32_t;
typedef int32_t s32_t;
*/
typedef unsigned short uip_stats_t;
typedef unsigned long off_t;
void clock_delay(unsigned int us2);
void clock_wait(int ms10);
void clock_set_seconds(unsigned long s);
unsigned long clock_seconds(void);
#endif /* __CONTIKI_CONF_H__ */

View file

@ -42,8 +42,6 @@
typedef unsigned long clock_time_t;
void clock_wait(int ms10);
#define LOG_CONF_ENABLED 0
#define PACKETBUF_CONF_ATTRS_INLINE 1

View file

@ -33,6 +33,7 @@
#include "contiki.h"
#include "contiki-esb.h"
#include "sys/clock.h"
#define ON 1
#define OFF 0

View file

@ -214,7 +214,7 @@ __delay_cycles(int c)
*
*/
void
clock_wait(int i)
clock_wait(clock_time_t i)
{
clock_time_t start;

View file

@ -188,16 +188,9 @@
#define UIP_CONF_TCP_SPLIT 0
typedef unsigned short clock_time_t;
typedef unsigned short uip_stats_t;
typedef unsigned long off_t;
void clock_delay(unsigned int us2);
void clock_wait(int ms10);
void clock_set_seconds(unsigned long s);
unsigned long clock_seconds(void);
#ifdef PROJECT_CONF_H
#include PROJECT_CONF_H
#endif /* PROJECT_CONF_H */

View file

@ -44,13 +44,34 @@
* Definitions below are dictated by the hardware and not really
* changeable!
*/
#define PLATFORM PLATFORM_AVR
#define HARWARE_REVISION IRIS
/* Platform name, type, and MCU clock rate */
#define PLATFORM_NAME "Iris"
#define PLATFORM_TYPE IRIS
#ifndef F_CPU
#define F_CPU 8000000UL
#endif
/* The AVR tick interrupt usually is done with an 8 bit counter around 128 Hz.
* 125 Hz needs slightly more overhead during the interrupt, as does a 32 bit
* clock_time_t.
*/
/* Clock ticks per second */
#define CLOCK_CONF_SECOND 128
#if 1
/* 16 bit counter overflows every ~10 minutes */
typedef unsigned short clock_time_t;
#define CLOCK_LT(a,b) ((signed short)((a)-(b)) < 0)
#define INFINITE_TIME 0xffff
#define RIME_CONF_BROADCAST_ANNOUNCEMENT_MAX_TIME INFINITE_TIME/CLOCK_CONF_SECOND /* Default uses 600 */
#define COLLECT_CONF_BROADCAST_ANNOUNCEMENT_MAX_TIME INFINITE_TIME/CLOCK_CONF_SECOND /* Default uses 600 */
#else
typedef unsigned long clock_time_t;
#define CLOCK_LT(a,b) ((signed long)((a)-(b)) < 0)
#define INFINITE_TIME 0xffffffff
#endif
/* These routines are not part of the contiki core but can be enabled in cpu/avr/clock.c */
void clock_delay_msec(uint16_t howlong);
void clock_adjust_ticks(clock_time_t howmany);
/* LED ports */
#define LEDS_PxDIR DDRA // port direction register

View file

@ -43,8 +43,7 @@
#include "dev/acc-sensor.h"
#include "mems.h"
void clock_wait(int i);
#include "sys/clock.h"
#define FALSE 0
#define TRUE 1

View file

@ -130,7 +130,7 @@ void clock_delay(unsigned int i)
* Wait for a multiple of 1 ms.
*
*/
void clock_wait(int i)
void clock_wait(clock_time_t i)
{
clock_time_t start;

View file

@ -42,10 +42,9 @@
#include "dev/acc-sensor.h"
#include "sys/clock.h"
#include "mems.h"
void clock_wait(int i);
#define FALSE 0
#define TRUE 1

View file

@ -47,12 +47,17 @@
#include "platform-conf.h"
#if WITH_UIP6
#if UIP_CONF_IPV6
#define WITH_UIP6 1
#endif
#if WITH_UIP6
/* Network setup for IPv6 */
#define NETSTACK_CONF_NETWORK sicslowpan_driver
#define NETSTACK_CONF_MAC csma_driver
#define NETSTACK_CONF_RDC nullrdc_driver
//#define NETSTACK_CONF_MAC csma_driver
#define NETSTACK_CONF_MAC nullmac_driver
//#define NETSTACK_CONF_RDC nullrdc_driver
#define NETSTACK_CONF_RDC sicslowmac_driver
#define NETSTACK_CONF_FRAMER framer_802154
#define CC2420_CONF_AUTOACK 1
@ -66,6 +71,7 @@
#define NETSTACK_CONF_NETWORK rime_driver
#define NETSTACK_CONF_MAC csma_driver
#define NETSTACK_CONF_MAC nullmac_driver
#define NETSTACK_CONF_RDC cxmac_driver
#define NETSTACK_CONF_FRAMER framer_802154
@ -109,8 +115,8 @@
#define UIP_CONF_LL_802154 1
#define UIP_CONF_LLH_LEN 0
#define UIP_CONF_ROUTER 1
#define UIP_CONF_IPV6_RPL 1
#define UIP_CONF_ROUTER 0
#define UIP_CONF_IPV6_RPL 0
/* configure number of neighbors and routes */
#define UIP_CONF_DS6_NBR_NBU 5
@ -188,14 +194,7 @@
#define UIP_CONF_TCP_SPLIT 0
typedef unsigned short clock_time_t;
typedef unsigned short uip_stats_t;
typedef unsigned long off_t;
void clock_delay(unsigned int us2);
void clock_wait(int ms10);
void clock_set_seconds(unsigned long s);
unsigned long clock_seconds(void);
#endif /* __CONTIKI_CONF_H__ */

View file

@ -64,7 +64,8 @@ init_usart(void)
USART_PARITY_NONE | USART_STOP_BITS_1 | USART_DATA_BITS_8);
#if WITH_UIP || WITH_UIP6
slip_arch_init(USART_BAUD_115200);
// slip_arch_init(USART_BAUD_115200);
rs232_redirect_stdout(RS232_PORT_0);
#else
rs232_redirect_stdout(RS232_PORT_0);
#endif /* WITH_UIP */
@ -103,7 +104,7 @@ main(void)
ctimer_init();
leds_on(LEDS_YELLOW);
init_net();
printf_P(PSTR(CONTIKI_VERSION_STRING " started. Node id %u\n"), node_id);

View file

@ -134,12 +134,12 @@ clock_delay(unsigned int i)
*
*/
void
clock_wait(int i)
clock_wait(clock_time_t i)
{
clock_time_t start;
start = clock_time();
while(clock_time() - start < (clock_time_t)i);
while(clock_time() - start < i);
}
/*---------------------------------------------------------------------------*/
void

View file

@ -44,17 +44,34 @@
* Definitions below are dictated by the hardware and not really
* changeable!
*/
#define PLATFORM PLATFORM_AVR
/* Platform name, type, and MCU clock rate */
#define PLATFORM_NAME "MicaZ"
#define PLATFORM_TYPE MICAZ
#ifndef F_CPU
#define F_CPU 7372800UL
#endif
/*
* MCU and clock rate.
* MICAZ runs on 7.3728 MHz clock.
/* The AVR tick interrupt usually is done with an 8 bit counter around 128 Hz.
* 125 Hz needs slightly more overhead during the interrupt, as does a 32 bit
* clock_time_t.
*/
#define MCU_MHZ 7
/* Clock ticks per second */
/* Clock ticks per second */
#define CLOCK_CONF_SECOND 128
#if 1
/* 16 bit counter overflows every ~10 minutes */
typedef unsigned short clock_time_t;
#define CLOCK_LT(a,b) ((signed short)((a)-(b)) < 0)
#define INFINITE_TIME 0xffff
#define RIME_CONF_BROADCAST_ANNOUNCEMENT_MAX_TIME INFINITE_TIME/CLOCK_CONF_SECOND /* Default uses 600 */
#define COLLECT_CONF_BROADCAST_ANNOUNCEMENT_MAX_TIME INFINITE_TIME/CLOCK_CONF_SECOND /* Default uses 600 */
#else
typedef unsigned long clock_time_t;
#define CLOCK_LT(a,b) ((signed long)((a)-(b)) < 0)
#define INFINITE_TIME 0xffffffff
#endif
/* These routines are not part of the contiki core but can be enabled in cpu/avr/clock.c */
void clock_delay_msec(uint16_t howlong);
void clock_adjust_ticks(clock_time_t howmany);
/* LED ports */
#define LEDS_PxDIR DDRA // port direction register

View file

@ -51,6 +51,8 @@
#include <stdint.h>
#define PLATFORM_NAME "Econotag"
#define PLATFORM_TYPE MC1322X
/* mc1322x files */
#include "contiki-mc1322x-conf.h"
/* this is from cpu/mc1322x/board */
@ -62,6 +64,9 @@
/* FIXME setting this will break the sensor button (and other gpio) */
/* since leds_arch hits the entire gpio_data */
#define BLINK_SECONDS 0
/* Set to 1 to sample an ADC channel every second, 9 second refresh */
/* Set >1 to sample an ADC channel every tick, 90 msec refresh */
#define CLOCK_CONF_SAMPLEADC 1
#define CCIF
#define CLIF

View file

@ -3,15 +3,37 @@
#include<stdint.h>
/* Platform name, type, and MCU clock rate */
#define PLATFORM_NAME "STK500"
#define PLATFORM_TYPE STK500
#ifndef F_CPU
#define F_CPU 8000000UL
#endif
#define CCIF
#define CLIF
typedef unsigned short clock_time_t;
/* The AVR tick interrupt usually is done with an 8 bit counter around 128 Hz.
* 125 Hz needs slightly more overhead during the interrupt, as does a 32 bit
* clock_time_t.
*/
/* Clock ticks per second */
#define CLOCK_CONF_SECOND 125
/* Maximum tick interval is 0xffff/125 = 524 seconds */
#define RIME_CONF_BROADCAST_ANNOUNCEMENT_MAX_TIME CLOCK_CONF_SECOND * 524UL /* Default uses 600UL */
#define COLLECT_CONF_BROADCAST_ANNOUNCEMENT_MAX_TIME CLOCK_CONF_SECOND * 524UL /* Default uses 600UL */
#if 1
/* 16 bit counter overflows every ~10 minutes */
typedef unsigned short clock_time_t;
#define CLOCK_LT(a,b) ((signed short)((a)-(b)) < 0)
#define INFINITE_TIME 0xffff
#define RIME_CONF_BROADCAST_ANNOUNCEMENT_MAX_TIME INFINITE_TIME/CLOCK_CONF_SECOND /* Default uses 600 */
#define COLLECT_CONF_BROADCAST_ANNOUNCEMENT_MAX_TIME INFINITE_TIME/CLOCK_CONF_SECOND /* Default uses 600 */
#else
typedef unsigned long clock_time_t;
#define CLOCK_LT(a,b) ((signed long)((a)-(b)) < 0)
#define INFINITE_TIME 0xffffffff
#endif
/* These routines are not part of the contiki core but can be enabled in cpu/avr/clock.c */
void clock_delay_msec(uint16_t howlong);
void clock_adjust_ticks(clock_time_t howmany);
#define SLIP_PORT 0
@ -56,13 +78,6 @@ typedef unsigned short clock_time_t;
#define NETSTACK_CONF_NETWORK rime_driver
#endif /* UIP_CONF_IPV6 */
void clock_delay(unsigned int us2);
void clock_wait(int ms10);
void clock_set_seconds(unsigned long s);
unsigned long clock_seconds(void);
typedef unsigned short uip_stats_t;
/* These names are deprecated, use C99 names. */

View file

@ -45,17 +45,40 @@
/*
* MCU and clock rate. Various MCUs can be inserted in the ZIF socket.
*/
/* Platform name, type, and MCU clock rate */
#define PLATFORM_NAME "STK501"
#define PLATFORM_TYPE STK501
#ifndef MCU
#define MCU atmega128
#endif
#ifndef F_CPU
#define F_CPU 16000000UL
#define F_CPU 16000000UL
#endif
#define PLATFORM PLATFORM_AVR
/* Cock ticks per second */
#define HAVE_STDINT_H
#include "avrdef.h"
/* The AVR tick interrupt usually is done with an 8 bit counter around 128 Hz.
* 125 Hz needs slightly more overhead during the interrupt, as does a 32 bit
* clock_time_t.
*/
/* Clock ticks per second */
#define CLOCK_CONF_SECOND 125
#define RIME_CONF_BROADCAST_ANNOUNCEMENT_MAX_TIME CLOCK_CONF_SECOND * 524UL /*Default uses 600*/
#if 1
/* 16 bit counter overflows every ~10 minutes */
typedef unsigned short clock_time_t;
#define CLOCK_LT(a,b) ((signed short)((a)-(b)) < 0)
#define INFINITE_TIME 0xffff
#define RIME_CONF_BROADCAST_ANNOUNCEMENT_MAX_TIME INFINITE_TIME/CLOCK_CONF_SECOND /* Default uses 600 */
#define COLLECT_CONF_BROADCAST_ANNOUNCEMENT_MAX_TIME INFINITE_TIME/CLOCK_CONF_SECOND /* Default uses 600 */
#else
typedef unsigned long clock_time_t;
#define CLOCK_LT(a,b) ((signed long)((a)-(b)) < 0)
#define INFINITE_TIME 0xffffffff
#endif
/* These routines are not part of the contiki core but can be enabled in cpu/avr/clock.c */
void clock_delay_msec(uint16_t howlong);
void clock_adjust_ticks(clock_time_t howmany);
/* COM port to be used for SLIP connection */
#define SLIP_PORT RS232_PORT_0
@ -83,13 +106,7 @@
#define HAVE_STDINT_H
#include "avrdef.h"
typedef unsigned short clock_time_t;
typedef unsigned short uip_stats_t;
typedef unsigned long off_t;
void clock_delay(unsigned int us2);
void clock_wait(int ms10);
void clock_set_seconds(unsigned long s);
unsigned long clock_seconds(void);
#endif /* __CONTIKI_CONF_H__ */

View file

@ -138,7 +138,7 @@ main(void)
/* Perform rest of initializations */
process_start(&contiki_stk501_main_init_process, NULL);
PRINTF"Initialized.\n");
PRINTF("Initialized.\n");
#ifdef MT_DEMO
mt_start (&threads[0], thread_handler1, &d1);

View file

@ -46,6 +46,7 @@
#include "net/mac/frame802154.h"
#include "dev/button-sensor.h"
#include "dev/adxl345.h"
#include "sys/clock.h"
#if WITH_UIP6
#include "net/uip-ds6.h"
@ -105,7 +106,6 @@ static uint8_t is_gateway;
#endif
void init_platform(void);
void clock_wait(int i);
/*---------------------------------------------------------------------------*/
#if 0

View file

@ -26,7 +26,6 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: uip6-bridge-tap.c,v 1.2 2011/01/19 09:13:06 salvopitru Exp $
*
*/
@ -43,6 +42,7 @@
#include "dev/slip.h"
#include "dev/leds.h"
#include "sicslow_ethernet.h"
#include "sys/clock.h"
#include "net/packetbuf.h"
@ -50,8 +50,6 @@
#include <stdio.h>
#include <string.h>
void clock_wait(int i);
#define UIP_IP_BUF ((struct uip_ip_hdr *)&uip_buf[UIP_LLH_LEN])
PROCESS(uip6_bridge, "IPv6/6lowpan TAP bridge");