Merge branch 'master' of ssh://contiki.git.sourceforge.net/gitroot/contiki/contiki

This commit is contained in:
nvt 2012-04-05 18:23:31 +02:00
commit 38e66571ce
15 changed files with 230 additions and 232 deletions

View file

@ -52,31 +52,19 @@ typedef unsigned short clock_time_t;
#define CCIF #define CCIF
#define CLIF #define CLIF
/* Single asm instruction without messing up syntax highlighting */
#if defined(__SDCC_mcs51) || defined(SDCC_mcs51)
#define ASM(x) __asm \
x \
__endasm
#else
#define ASM(x)
#endif
/* Critical section management */ /* Critical section management */
#define DISABLE_INTERRUPTS() do {EA = 0;} while(0) #define DISABLE_INTERRUPTS() do {EA = 0;} while(0)
#define ENABLE_INTERRUPTS() do {EA = 1;} while(0) #define ENABLE_INTERRUPTS() do {EA = 1;} while(0)
#define ENTER_CRITICAL() \
{ \
__asm \
push ACC \
push IE \
__endasm; \
} \
EA = 0;
#define EXIT_CRITICAL() \
{ \
__asm \
pop ACC \
__endasm; \
ACC &= 0x80; \
IE |= ACC; \
__asm \
pop ACC \
__endasm; \
}
/* Macro for a soft reset. */ /* Macro for a soft reset. */
#define SOFT_RESET() do {((void (__code *) (void)) 0x0000) ();} while(0) #define SOFT_RESET() do {((void (__code *) (void)) 0x0000) ();} while(0)

View file

@ -27,57 +27,46 @@
* SUCH DAMAGE. * SUCH DAMAGE.
* *
* This file is part of the Contiki operating system. * This file is part of the Contiki operating system.
*
* $Id: clock.c,v 1.1 2009/09/08 20:07:35 zdshelby Exp $
*/ */
/** /**
* \file * \file
* Implementation of the clock functions for the 8051 CPU * Implementation of the clock functions for the cc243x
* \author * \author
* Zach Shelby (zach@sensinode.com) * Zach Shelby (zach@sensinode.com) - original
* George Oikonomou - <oikonomou@users.sourceforge.net>
*/ */
/**
* TODO: Implement clock_fine() and clock_fine_max_ticks() using another timer?
*/
#include <stdio.h> /*for debug printf*/
#include "sys/clock.h" #include "sys/clock.h"
#include "sys/etimer.h" #include "sys/etimer.h"
#include "cc2430_sfr.h" #include "cc2430_sfr.h"
#include "sys/energest.h" #include "sys/energest.h"
/*Sleep timer runs on the 32k RC osc. */ /* Sleep timer runs on the 32k RC osc. */
/* One clock tick is 7.8 ms */ /* One clock tick is 7.8 ms */
#define TICK_VAL (32768/128) /* 256 */ #define TICK_VAL (32768/128) /* 256 */
/*---------------------------------------------------------------------------*/
#if CLOCK_CONF_STACK_FRIENDLY
volatile __bit sleep_flag;
#else
#endif
/*---------------------------------------------------------------------------*/
/* Used in sleep timer interrupt for calculating the next interrupt time */ /* Used in sleep timer interrupt for calculating the next interrupt time */
static unsigned long timer_value; static unsigned long timer_value;
/*starts calculating the ticks right after reset*/ static volatile __data clock_time_t count = 0; /* Uptime in ticks */
#if CLOCK_CONF_ACCURATE static volatile __data clock_time_t seconds = 0; /* Uptime in secs */
static volatile __data clock_time_t count = 0;
#else
volatile __data clock_time_t count = 0;
/* accurate clock is stack hungry */
volatile __bit sleep_flag;
#endif
/*calculates seconds*/
static volatile __data clock_time_t seconds = 0;
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
/** /**
* One delay is about 0.6 us, so this function delays for len * 0.6 us * Each iteration is ~1.0xy usec, so this function delays for roughly len usec
*/ */
void void
clock_delay(unsigned int len) clock_delay(unsigned int len)
{ {
unsigned int i; DISABLE_INTERRUPTS();
for(i = 0; i< len; i++) { while(len--) {
__asm ASM(nop); ASM(nop); ASM(nop);
nop ASM(nop); ASM(nop);
__endasm;
} }
ENABLE_INTERRUPTS();
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
/** /**
@ -92,7 +81,7 @@ clock_wait(int i)
while(clock_time() - start < (clock_time_t)i); while(clock_time() - start < (clock_time_t)i);
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
clock_time_t CCIF clock_time_t
clock_time(void) clock_time(void)
{ {
return count; return count;
@ -107,24 +96,24 @@ clock_seconds(void)
void void
clock_init(void) clock_init(void)
{ {
CLKCON = OSC32K | TICKSPD2|TICKSPD1; /*tickspeed 500 kHz for timers[1-4]*/ CLKCON = OSC32K | TICKSPD2 | TICKSPD1; /* tickspeed 500 kHz for timers[1-4] */
/*Initialize tick value*/ /* Initialize tick value */
timer_value = ST0; /*sleep timer 0. low bits [7:0]*/ timer_value = ST0; /* ST low bits [7:0] */
timer_value += ((unsigned long int)ST1) << 8; /*middle bits [15:8]*/ timer_value += ((unsigned long int) ST1) << 8; /* middle bits [15:8] */
timer_value += ((unsigned long int)ST2) << 16; /*high bits [23:16]*/ timer_value += ((unsigned long int) ST2) << 16; /* high bits [23:16] */
timer_value += TICK_VAL; /*init value 256*/ timer_value += TICK_VAL; /* Init value 256 */
ST2 = (unsigned char) (timer_value >> 16); ST2 = (unsigned char) (timer_value >> 16);
ST1 = (unsigned char) (timer_value >> 8); ST1 = (unsigned char) (timer_value >> 8);
ST0 = (unsigned char) timer_value; ST0 = (unsigned char) timer_value;
IEN0 |= STIE; /*interrupt enable for sleep timers. STIE=Interrupt mask, CPU. */ IEN0_STIE = 1; /* IEN0.STIE acknowledge Sleep Timer Interrupt */
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
void void
clock_ISR( void ) __interrupt (ST_VECTOR) clock_ISR(void) __interrupt(ST_VECTOR)
{ {
IEN0_EA = 0; /*interrupt disable*/ DISABLE_INTERRUPTS();
ENERGEST_ON(ENERGEST_TYPE_IRQ); ENERGEST_ON(ENERGEST_TYPE_IRQ);
/* /*
@ -134,14 +123,13 @@ clock_ISR( void ) __interrupt (ST_VECTOR)
*/ */
SLEEP &= 0xFC; SLEEP &= 0xFC;
/* When using the cooperative scheduler the timer 2 ISR is only /*
required to increment the RTOS tick count. */ * Read value of the ST0:ST1:ST2, add TICK_VAL and write it back.
* Next interrupt occurs after the current time + TICK_VAL
/*Read value of the ST0,ST1,ST2 and then add TICK_VAL and write it back. */
Next interrupt occurs after the current time + TICK_VAL*/
timer_value = ST0; timer_value = ST0;
timer_value += ((unsigned long int)ST1) << 8; timer_value += ((unsigned long int) ST1) << 8;
timer_value += ((unsigned long int)ST2) << 16; timer_value += ((unsigned long int) ST2) << 16;
timer_value += TICK_VAL; timer_value += TICK_VAL;
ST2 = (unsigned char) (timer_value >> 16); ST2 = (unsigned char) (timer_value >> 16);
ST1 = (unsigned char) (timer_value >> 8); ST1 = (unsigned char) (timer_value >> 8);
@ -161,17 +149,17 @@ clock_ISR( void ) __interrupt (ST_VECTOR)
++seconds; ++seconds;
} }
#if CLOCK_CONF_ACCURATE #if CLOCK_CONF_STACK_FRIENDLY
if(etimer_pending() && sleep_flag = 1;
(etimer_next_expiration_time() - count - 1) > MAX_TICKS) { /*core/sys/etimer.c*/ #else
if(etimer_pending()
&& (etimer_next_expiration_time() - count - 1) > MAX_TICKS) {
etimer_request_poll(); etimer_request_poll();
} }
#else
sleep_flag = 1;
#endif #endif
IRCON &= ~STIF; /*IRCON.STIF=Sleep timer interrupt flag. This flag called this interrupt func, now reset it*/ IRCON_STIF = 0;
ENERGEST_OFF(ENERGEST_TYPE_IRQ); ENERGEST_OFF(ENERGEST_TYPE_IRQ);
IEN0_EA = 1; /*interrupt enable*/ ENABLE_INTERRUPTS();
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/

View file

@ -27,15 +27,14 @@
* SUCH DAMAGE. * SUCH DAMAGE.
* *
* This file is part of the Contiki operating system. * This file is part of the Contiki operating system.
*
* $Id: clock.c,v 1.1 2009/09/08 20:07:35 zdshelby Exp $
*/ */
/** /**
* \file * \file
* Implementation of the clock functions for the 8051 CPU * Implementation of the clock functions for the cc253x.
* Ported over from the cc243x original.
* \author * \author
* Zach Shelby (zach@sensinode.com) - original * Zach Shelby (zach@sensinode.com) - original (cc243x)
* George Oikonomou - <oikonomou@users.sourceforge.net> - cc2530 port * George Oikonomou - <oikonomou@users.sourceforge.net> - cc2530 port
*/ */
#include "sfr-bits.h" #include "sfr-bits.h"
@ -47,8 +46,11 @@
/* Sleep timer runs on the 32k RC osc. */ /* Sleep timer runs on the 32k RC osc. */
/* One clock tick is 7.8 ms */ /* One clock tick is 7.8 ms */
#define TICK_VAL (32768/128) /* 256 */ #define TICK_VAL (32768/128) /* 256 */
/*---------------------------------------------------------------------------*/
#define MAX_TICKS (~((clock_time_t)0) / 2) #if CLOCK_CONF_STACK_FRIENDLY
volatile __bit sleep_flag;
#else
#endif
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
/* Do NOT remove the absolute address and do NOT remove the initialiser here */ /* Do NOT remove the absolute address and do NOT remove the initialiser here */
__xdata __at(0x0000) static unsigned long timer_value = 0; __xdata __at(0x0000) static unsigned long timer_value = 0;
@ -57,15 +59,16 @@ static volatile __data clock_time_t count = 0; /* Uptime in ticks */
static volatile __data clock_time_t seconds = 0; /* Uptime in secs */ static volatile __data clock_time_t seconds = 0; /* Uptime in secs */
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
/** /**
* One delay is about 0.6 us, so this function delays for len * 0.6 us * Each iteration is ~1.0xy usec, so this function delays for roughly len usec
*/ */
void void
clock_delay(unsigned int len) clock_delay(unsigned int len)
{ {
unsigned int i; DISABLE_INTERRUPTS();
for(i = 0; i< len; i++) { while(len--) {
ASM(nop); ASM(nop);
} }
ENABLE_INTERRUPTS();
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
/** /**
@ -117,7 +120,7 @@ clock_init(void)
CLKCONCMD |= CLKCONCMD_TICKSPD2 | CLKCONCMD_TICKSPD1; CLKCONCMD |= CLKCONCMD_TICKSPD2 | CLKCONCMD_TICKSPD1;
while(CLKCONSTA != CLKCONCMD); while(CLKCONSTA != CLKCONCMD);
/*Initialize tick value*/ /* Initialize tick value */
timer_value = ST0; timer_value = ST0;
timer_value += ((unsigned long int) ST1) << 8; timer_value += ((unsigned long int) ST1) << 8;
timer_value += ((unsigned long int) ST2) << 16; timer_value += ((unsigned long int) ST2) << 16;
@ -135,15 +138,6 @@ clock_isr(void) __interrupt(ST_VECTOR)
DISABLE_INTERRUPTS(); DISABLE_INTERRUPTS();
ENERGEST_ON(ENERGEST_TYPE_IRQ); ENERGEST_ON(ENERGEST_TYPE_IRQ);
/*
* If the Sleep timer throws an interrupt while we are powering down to
* PM1, we need to abort the power down. Clear SLEEP.MODE, this will signal
* main() to abort the PM1 transition
*
* On cc2430 this would be:
* SLEEPCMD &= 0xFC;
*/
/* /*
* Read value of the ST0:ST1:ST2, add TICK_VAL and write it back. * Read value of the ST0:ST1:ST2, add TICK_VAL and write it back.
* Next interrupt occurs after the current time + TICK_VAL * Next interrupt occurs after the current time + TICK_VAL
@ -170,10 +164,14 @@ clock_isr(void) __interrupt(ST_VECTOR)
++seconds; ++seconds;
} }
#if CLOCK_CONF_STACK_FRIENDLY
sleep_flag = 1;
#else
if(etimer_pending() if(etimer_pending()
&& (etimer_next_expiration_time() - count - 1) > MAX_TICKS) { && (etimer_next_expiration_time() - count - 1) > MAX_TICKS) {
etimer_request_poll(); etimer_request_poll();
} }
#endif
STIF = 0; /* IRCON.STIF */ STIF = 0; /* IRCON.STIF */
ENERGEST_OFF(ENERGEST_TYPE_IRQ); ENERGEST_OFF(ENERGEST_TYPE_IRQ);

View file

@ -60,7 +60,6 @@ uart0_init()
UART0_RX_EN(); UART0_RX_EN();
UART0_RX_INT(1); UART0_RX_INT(1);
U0DBUF = 0;
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
/* Write one byte over the UART. */ /* Write one byte over the UART. */

View file

@ -23,7 +23,7 @@ CONTIKI_CPU_DIRS = . dev hal simplemac hal/micro/cortexm3 hal/micro/cortexm3/stm
STM32W_C = leds-arch.c leds.c clock.c watchdog.c uart1.c uart1-putchar.c slip_uart1.c slip.c\ STM32W_C = leds-arch.c leds.c clock.c watchdog.c uart1.c uart1-putchar.c slip_uart1.c slip.c\
stm32w-radio.c stm32w_systick.c uip_arch.c rtimer-arch.c adc.c micro.c sleep.c \ stm32w-radio.c stm32w_systick.c uip_arch.c rtimer-arch.c adc.c micro.c sleep.c \
micro-common.c micro-common-internal.c clocks.c mfg-token.c nvm.c flash.c rand.c system-timer.c mpu.c micro-common.c micro-common-internal.c clocks.c mfg-token.c nvm.c flash.c rand.c system-timer.c
STM32W_S = spmr.s79 context-switch.s79 STM32W_S = spmr.s79 context-switch.s79
@ -297,3 +297,12 @@ else
login: login:
$(SERIALDUMP) -b115200 -d10000 $(USBDEVPREFIX)$(firstword $(MOTES)) $(SERIALDUMP) -b115200 -d10000 $(USBDEVPREFIX)$(firstword $(MOTES))
endif endif
# a target that gives a user-friendly memory profile, taking into account the RAM
# that is statically occupied by the stack as defined in cpu/stm32w108/gnu.ld
RAM_SIZE = 8192
FLASH_SIZE = 128*1024
STACK_SIZE = 1280
%.size: %.$(TARGET)
@size -A $< | egrep "data|bss" | awk '{s+=$$2} END {s=s+$(STACK_SIZE); f=$(RAM_SIZE)-s; printf "[RAM] used %6d, free %6d\n",s,f;}'
@size -A $< | egrep "text|isr_vector" | awk '{s+=$$2} END {f=$(FLASH_SIZE)-s; printf "[Flash] used %6d, free %6d\n",s,f;}'

View file

@ -1,9 +1,7 @@
/** /**
* \file * \file
* Tests related to clocks and timers * Tests related to clocks and timers
* * This is based on clock_test.c from the original sensinode port
* This is clock_test.c plus a small addition by George Oikonomou
* (Loughborough University) in order to test the rtimer
* *
* \author * \author
* Zach Shelby <zach@sensinode.com> (Original) * Zach Shelby <zach@sensinode.com> (Original)
@ -17,7 +15,6 @@
#include "dev/leds.h" #include "dev/leds.h"
#include <stdio.h> #include <stdio.h>
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
#define TEST_CLOCK_DELAY 1 #define TEST_CLOCK_DELAY 1
#define TEST_RTIMER 1 #define TEST_RTIMER 1
@ -27,7 +24,7 @@
static struct etimer et; static struct etimer et;
#if TEST_CLOCK_DELAY #if TEST_CLOCK_DELAY
static clock_time_t start_count, end_count, diff; static rtimer_clock_t start_count, end_count, diff;
#endif #endif
#if TEST_CLOCK_SECONDS #if TEST_CLOCK_SECONDS
@ -70,12 +67,13 @@ PROCESS_THREAD(clock_test_process, ev, data)
#if TEST_CLOCK_DELAY #if TEST_CLOCK_DELAY
printf("Clock delay test, (10,000 x i) cycles:\n"); printf("Clock delay test, (10,000 x i) cycles:\n");
i = 1; i = 1;
while(i < 6) { while(i < 7) {
start_count = clock_time(); start_count = RTIMER_NOW();
clock_delay(10000 * i); clock_delay(10000 * i);
end_count = clock_time(); end_count = RTIMER_NOW();
diff = end_count - start_count; diff = end_count - start_count;
printf("Delayed %u = %u ticks = ~%u ms\n", 10000 * i, diff, diff * 8); printf("Delayed %u = %u rtimer ticks = ~%u us\n", 10000 * i, diff,
diff * 64);
i++; i++;
} }
#endif #endif

View file

@ -1,67 +0,0 @@
/**
* \file
* Tests related to clocks and timers
* \author
* Zach Shelby <zach@sensinode.com>
*/
#include "contiki.h"
#include "sys/clock.h"
#include "dev/bus.h"
#include "dev/leds.h"
#include <stdio.h> /* For printf() */
/*---------------------------------------------------------------------------*/
PROCESS(clock_test_process, "Clock test process");
AUTOSTART_PROCESSES(&clock_test_process);
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(clock_test_process, ev, data)
{
static struct etimer et;
static clock_time_t count, start_count, end_count, diff;
static unsigned long sec;
static uint8_t i;
PROCESS_BEGIN();
printf("Clock delay test (10 x (10,000xi) cycles):\n");
i = 1;
while(i < 6) {
start_count = clock_time();
clock_delay(10000*i);
end_count = clock_time();
diff = end_count-start_count;
printf("Delayed %u = %u ticks = ~%u ms\n", 10000*i, diff, diff*8 );
i++;
}
printf("Clock tick and etimer test (10 x 1s):\n");
i = 0;
while(i < 10) {
etimer_set(&et, CLOCK_SECOND);
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
etimer_reset(&et);
count = clock_time();
printf("%u ticks\n", count);
leds_toggle(LEDS_RED);
i++;
}
printf("Clock seconds test (10 x 5s):\n");
i = 0;
while(i < 10) {
etimer_set(&et, 5 * CLOCK_SECOND);
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
etimer_reset(&et);
sec = clock_seconds();
printf("%u seconds\n", (uint16_t) sec);
leds_toggle(LEDS_GREEN);
i++;
}
PROCESS_END();
}
/*---------------------------------------------------------------------------*/

View file

@ -1,9 +1,7 @@
/** /**
* \file * \file
* Tests related to clocks and timers * Tests related to clocks and timers
* * This is based on clock_test.c from the original sensinode port
* This is clock_test.c plus a small addition by George Oikonomou
* (Loughborough University)in order to test the rtimer
* *
* \author * \author
* Zach Shelby <zach@sensinode.com> (Original) * Zach Shelby <zach@sensinode.com> (Original)
@ -23,59 +21,73 @@
#define TEST_ETIMER 1 #define TEST_ETIMER 1
#define TEST_CLOCK_SECONDS 1 #define TEST_CLOCK_SECONDS 1
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
static struct etimer et;
#if TEST_CLOCK_DELAY
static rtimer_clock_t start_count, end_count, diff;
#endif
#if TEST_CLOCK_SECONDS
static unsigned long sec;
#endif
#if TEST_ETIMER
static clock_time_t count;
#endif
#if TEST_RTIMER
static struct rtimer rt;
rtimer_clock_t rt_now, rt_for;
static clock_time_t ct;
#endif
static uint8_t i;
/*---------------------------------------------------------------------------*/
PROCESS(clock_test_process, "Clock test process"); PROCESS(clock_test_process, "Clock test process");
AUTOSTART_PROCESSES(&clock_test_process); AUTOSTART_PROCESSES(&clock_test_process);
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
#if TEST_RTIMER #if TEST_RTIMER
void void
rt_callback(struct rtimer *t, void *ptr) { rt_callback(struct rtimer *t, void *ptr) {
printf("Task called at %u\n", RTIMER_NOW()); rt_now = RTIMER_NOW();
ct = clock_time();
printf("Task called at %u (clock = %u)\n", rt_now, ct);
} }
#endif #endif
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
PROCESS_THREAD(clock_test_process, ev, data) PROCESS_THREAD(clock_test_process, ev, data)
{ {
static struct etimer et;
#if TEST_CLOCK_DELAY
static clock_time_t start_count, end_count, diff;
#endif
#if TEST_CLOCK_SECONDS
static unsigned long sec;
#endif
#if TEST_ETIMER
static clock_time_t count;
#endif
#if TEST_RTIMER
uint16_t rt_now, rt_for;
static struct rtimer rt;
#endif
static uint8_t i;
PROCESS_BEGIN(); PROCESS_BEGIN();
etimer_set(&et, 2 * CLOCK_SECOND);
PROCESS_YIELD();
#if TEST_CLOCK_DELAY #if TEST_CLOCK_DELAY
printf("Clock delay test (10 x (10,000xi) cycles):\n"); printf("Clock delay test, (10,000 x i) cycles:\n");
i = 1; i = 1;
while(i < 6) { while(i < 7) {
start_count = clock_time(); start_count = RTIMER_NOW();
clock_delay(10000 * i); clock_delay(10000 * i);
end_count = clock_time(); end_count = RTIMER_NOW();
diff = end_count - start_count; diff = end_count - start_count;
printf("Delayed %u = %u ticks = ~%u ms\n", 10000 * i, diff, diff * 8); printf("Delayed %u = %u rtimer ticks = ~%u us\n", 10000 * i, diff,
diff * 64);
i++; i++;
} }
#endif #endif
#if TEST_RTIMER #if TEST_RTIMER
printf("Rtimer Test (10 x 1s):\n"); printf("Rtimer Test, 1 sec (%u rtimer ticks):\n", RTIMER_SECOND);
i = 0; i = 0;
while(i < 10) { while(i < 5) {
etimer_set(&et, 2*CLOCK_SECOND); etimer_set(&et, 2*CLOCK_SECOND);
puts("======================="); printf("=======================\n");
ct = clock_time();
rt_now = RTIMER_NOW(); rt_now = RTIMER_NOW();
rt_for = rt_now + RTIMER_SECOND; rt_for = rt_now + RTIMER_SECOND;
printf("%Now=%u - For=%u\n", rt_now, rt_for); printf("Now=%u (clock = %u) - For=%u\n", rt_now, ct, rt_for);
if (rtimer_set(&rt, rt_for, 1, if (rtimer_set(&rt, rt_for, 1,
(void (*)(struct rtimer *, void *))rt_callback, NULL) != RTIMER_OK) { (void (*)(struct rtimer *, void *))rt_callback, NULL) != RTIMER_OK) {
printf("Error setting\n"); printf("Error setting\n");
@ -87,7 +99,7 @@ PROCESS_THREAD(clock_test_process, ev, data)
#endif #endif
#if TEST_ETIMER #if TEST_ETIMER
printf("Clock tick and etimer test (10 x 1s):\n"); printf("Clock tick and etimer test, 1 sec (%u clock ticks):\n", CLOCK_SECOND);
i = 0; i = 0;
while(i < 10) { while(i < 10) {
etimer_set(&et, CLOCK_SECOND); etimer_set(&et, CLOCK_SECOND);
@ -103,7 +115,7 @@ PROCESS_THREAD(clock_test_process, ev, data)
#endif #endif
#if TEST_CLOCK_SECONDS #if TEST_CLOCK_SECONDS
printf("Clock seconds test (10 x 5s):\n"); printf("Clock seconds test (5s):\n");
i = 0; i = 0;
while(i < 10) { while(i < 10) {
etimer_set(&et, 5 * CLOCK_SECOND); etimer_set(&et, 5 * CLOCK_SECOND);
@ -111,13 +123,15 @@ PROCESS_THREAD(clock_test_process, ev, data)
etimer_reset(&et); etimer_reset(&et);
sec = clock_seconds(); sec = clock_seconds();
printf("%u seconds\n", (uint16_t) sec); printf("%lu seconds\n", sec);
leds_toggle(LEDS_GREEN); leds_toggle(LEDS_GREEN);
i++; i++;
} }
#endif #endif
printf("Done!\n");
PROCESS_END(); PROCESS_END();
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/

View file

@ -10,6 +10,14 @@
#include "project-conf.h" #include "project-conf.h"
#endif /* PROJECT_CONF_H */ #endif /* PROJECT_CONF_H */
/*
* Define this as 1 to poll the etimer process from within main instead of from
* the clock ISR. This reduces the ISR's stack usage and may prevent crashes.
*/
#ifndef CLOCK_CONF_STACK_FRIENDLY
#define CLOCK_CONF_STACK_FRIENDLY 1
#endif
/* Energest Module */ /* Energest Module */
#ifndef ENERGEST_CONF_ON #ifndef ENERGEST_CONF_ON
#define ENERGEST_CONF_ON 0 #define ENERGEST_CONF_ON 0

View file

@ -45,6 +45,10 @@ PROCESS_NAME(viztool_process);
#define PUTCHAR(...) do {} while(0) #define PUTCHAR(...) do {} while(0)
#endif #endif
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
#if CLOCK_CONF_STACK_FRIENDLY
extern volatile __bit sleep_flag;
#endif
/*---------------------------------------------------------------------------*/
extern rimeaddr_t rimeaddr_node_addr; extern rimeaddr_t rimeaddr_node_addr;
static __data int r; static __data int r;
static __data int len; static __data int len;
@ -252,6 +256,16 @@ main(void)
do { do {
/* Reset watchdog and handle polls and events */ /* Reset watchdog and handle polls and events */
watchdog_periodic(); watchdog_periodic();
#if CLOCK_CONF_STACK_FRIENDLY
if(sleep_flag) {
if(etimer_pending() &&
(etimer_next_expiration_time() - clock_time() - 1) > MAX_TICKS) {
etimer_request_poll();
}
sleep_flag = 0;
}
#endif
r = process_run(); r = process_run();
} while(r > 0); } while(r > 0);
len = NETSTACK_RADIO.pending_packet(); len = NETSTACK_RADIO.pending_packet();

View file

@ -96,9 +96,16 @@
#define XMAC_CONF_ANNOUNCEMENTS 0 #define XMAC_CONF_ANNOUNCEMENTS 0
#define XMAC_CONF_COMPOWER 1 #define XMAC_CONF_COMPOWER 1
/* Other */ /* Other (RAM saving) */
#define ENERGEST_CONF_ON 0 #define ENERGEST_CONF_ON 0
#define QUEUEBUF_CONF_NUM 2 #define QUEUEBUF_CONF_NUM 2
#define QUEUEBUF_CONF_REF_NUM 0
#define UIP_CONF_DS6_NBR_NBU 4
#define UIP_CONF_DS6_ROUTE_NBU 4
#define RPL_CONF_MAX_PARENTS_PER_DAG 4
#define RPL_CONF_MAX_INSTANCES 1
#define RPL_CONF_MAX_DAG_PER_INSTANCE 1
#define PROCESS_CONF_NUMEVENTS 16
#if WITH_UIP6 #if WITH_UIP6
@ -129,11 +136,16 @@
#define UIP_CONF_MAX_LISTENPORTS 8 #define UIP_CONF_MAX_LISTENPORTS 8
#define UIP_CONF_UDP_CONNS 4 #define UIP_CONF_UDP_CONNS 4
#include "net/sicslowpan.h" #define SICSLOWPAN_CONF_COMPRESSION SICSLOWPAN_COMPRESSION_HC06
#define SICSLOWPAN_CONF_COMPRESSION SICSLOWPAN_CONF_COMPRESSION_HC06 #ifndef SICSLOWPAN_CONF_FRAG
#define SICSLOWPAN_CONF_FRAG 1 #define SICSLOWPAN_CONF_FRAG 1
#endif /* SICSLOWPAN_CONF_FRAG */
#ifndef SICSLOWPAN_CONF_MAX_ADDR_CONTEXTS
#define SICSLOWPAN_CONF_MAX_ADDR_CONTEXTS 2 #define SICSLOWPAN_CONF_MAX_ADDR_CONTEXTS 2
#endif /* SICSLOWPAN_CONF_MAX_ADDR_CONTEXTS */
#ifndef SICSLOWPAN_CONF_MAXAGE
#define SICSLOWPAN_CONF_MAXAGE 2 #define SICSLOWPAN_CONF_MAXAGE 2
#endif /* SICSLOWPAN_CONF_MAXAGE */
#else /* WITH_UIP6 */ #else /* WITH_UIP6 */

View file

@ -68,6 +68,9 @@
#include "net/rime/rime-udp.h" #include "net/rime/rime-udp.h"
#include "net/uip.h" #include "net/uip.h"
#if WITH_UIP6
#include "net/uip-ds6.h"
#endif /* WITH_UIP6 */
#define DEBUG 1 #define DEBUG 1
#if DEBUG #if DEBUG
@ -100,8 +103,6 @@ set_rime_addr(void)
uint8_t u8[8]; uint8_t u8[8];
}eui64; }eui64;
//rimeaddr_t lladdr;
int8u *stm32w_eui64 = ST_RadioGetEui64(); int8u *stm32w_eui64 = ST_RadioGetEui64();
{ {
int8u c; int8u c;
@ -186,6 +187,32 @@ main(void)
autostart_start(autostart_processes); autostart_start(autostart_processes);
printf("Tentative link-local IPv6 address ");
{
uip_ds6_addr_t *lladdr;
int i;
lladdr = uip_ds6_get_link_local(-1);
for(i = 0; i < 7; ++i) {
printf("%02x%02x:", lladdr->ipaddr.u8[i * 2],
lladdr->ipaddr.u8[i * 2 + 1]);
}
printf("%02x%02x\n", lladdr->ipaddr.u8[14], lladdr->ipaddr.u8[15]);
}
if(!UIP_CONF_IPV6_RPL) {
uip_ipaddr_t ipaddr;
int i;
uip_ip6addr(&ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 0);
uip_ds6_set_addr_iid(&ipaddr, &uip_lladdr);
uip_ds6_addr_add(&ipaddr, 0, ADDR_TENTATIVE);
printf("Tentative global IPv6 address ");
for(i = 0; i < 7; ++i) {
printf("%02x%02x:",
ipaddr.u8[i * 2], ipaddr.u8[i * 2 + 1]);
}
printf("%02x%02x\n",
ipaddr.u8[7 * 2], ipaddr.u8[7 * 2 + 1]);
}
watchdog_start(); watchdog_start();
@ -262,11 +289,11 @@ void UsageFault_Handler(){
errcode = 7; errcode = 7;
//leds_on(LEDS_RED); //leds_on(LEDS_RED);
//halReboot(); //halReboot();
}*/ }
void Default_Handler() void Default_Handler()
{ {
//errcode = 8; //errcode = 8;
leds_on(LEDS_RED); leds_on(LEDS_RED);
halReboot(); halReboot();
} }*/

View file

@ -96,9 +96,16 @@
#define XMAC_CONF_ANNOUNCEMENTS 0 #define XMAC_CONF_ANNOUNCEMENTS 0
#define XMAC_CONF_COMPOWER 1 #define XMAC_CONF_COMPOWER 1
/* Other */ /* Other (RAM saving) */
#define ENERGEST_CONF_ON 0 #define ENERGEST_CONF_ON 0
#define QUEUEBUF_CONF_NUM 2 #define QUEUEBUF_CONF_NUM 2
#define QUEUEBUF_CONF_REF_NUM 0
#define UIP_CONF_DS6_NBR_NBU 4
#define UIP_CONF_DS6_ROUTE_NBU 4
#define RPL_CONF_MAX_PARENTS_PER_DAG 4
#define RPL_CONF_MAX_INSTANCES 1
#define RPL_CONF_MAX_DAG_PER_INSTANCE 1
#define PROCESS_CONF_NUMEVENTS 16
#if WITH_UIP6 #if WITH_UIP6
@ -129,11 +136,16 @@
#define UIP_CONF_MAX_LISTENPORTS 8 #define UIP_CONF_MAX_LISTENPORTS 8
#define UIP_CONF_UDP_CONNS 4 #define UIP_CONF_UDP_CONNS 4
#include "net/sicslowpan.h" #define SICSLOWPAN_CONF_COMPRESSION SICSLOWPAN_COMPRESSION_HC06
#define SICSLOWPAN_CONF_COMPRESSION SICSLOWPAN_CONF_COMPRESSION_HC06 #ifndef SICSLOWPAN_CONF_FRAG
#define SICSLOWPAN_CONF_FRAG 1 #define SICSLOWPAN_CONF_FRAG 1
#endif /* SICSLOWPAN_CONF_FRAG */
#ifndef SICSLOWPAN_CONF_MAX_ADDR_CONTEXTS
#define SICSLOWPAN_CONF_MAX_ADDR_CONTEXTS 2 #define SICSLOWPAN_CONF_MAX_ADDR_CONTEXTS 2
#endif /* SICSLOWPAN_CONF_MAX_ADDR_CONTEXTS */
#ifndef SICSLOWPAN_CONF_MAXAGE
#define SICSLOWPAN_CONF_MAXAGE 2 #define SICSLOWPAN_CONF_MAXAGE 2
#endif /* SICSLOWPAN_CONF_MAXAGE */
#else /* WITH_UIP6 */ #else /* WITH_UIP6 */

View file

@ -10,10 +10,12 @@
#include "project-conf.h" #include "project-conf.h"
#endif /* PROJECT_CONF_H */ #endif /* PROJECT_CONF_H */
/* The clock ISR is stack-hungry and may cause crashes. /*
* Define this as 0 if you are suffering from frequent stack overflows */ * Define this as 1 to poll the etimer process from within main instead of from
#ifndef CLOCK_CONF_ACCURATE * the clock ISR. This reduces the ISR's stack usage and may prevent crashes.
#define CLOCK_CONF_ACCURATE 1 */
#ifndef CLOCK_CONF_STACK_FRIENDLY
#define CLOCK_CONF_STACK_FRIENDLY 1
#endif #endif
/* Memory filesystem RAM size. */ /* Memory filesystem RAM size. */
@ -27,7 +29,7 @@
#define ENERGEST_CONF_ON 0 #define ENERGEST_CONF_ON 0
#endif #endif
/* Verbose Startup? Turning this off saves 700+ bytes of CODE in HOME */ /* Verbose Startup? Turning this off reduces our footprint a fair bit */
#define STARTUP_CONF_VERBOSE 0 #define STARTUP_CONF_VERBOSE 0
/* More CODE space savings by turning off process names */ /* More CODE space savings by turning off process names */
@ -35,9 +37,9 @@
/* /*
* UARTs: 1=>Enabled, 0=>Disabled. Default: Both Disabled (see uart.h) * UARTs: 1=>Enabled, 0=>Disabled. Default: Both Disabled (see uart.h)
* Disabling UART0 saves ~200 bytes of CODE. * Disabling UARTs reduces our CODE footprint
* Disabling UART1 saves ~500 bytes of CODE but also disables all debugging * Disabling UART1 also disables all debugging output.
* output. Should be used when nodes are meant to run on batteries * Should be used when nodes are meant to run on batteries
* *
* On N740, by enabling UART1, you are also enabling an ugly hack which aims * On N740, by enabling UART1, you are also enabling an ugly hack which aims
* to detect the USB connection during execution. It will then turn on/off * to detect the USB connection during execution. It will then turn on/off

View file

@ -54,10 +54,7 @@ static __data int len;
#define PUTCHAR(...) do {} while(0) #define PUTCHAR(...) do {} while(0)
#endif #endif
#if CLOCK_CONF_STACK_FRIENDLY
#if !CLOCK_CONF_ACCURATE
extern volatile __data clock_time_t count;
/* accurate clock is stack hungry */
extern volatile __bit sleep_flag; extern volatile __bit sleep_flag;
#endif #endif
@ -294,11 +291,10 @@ main(void)
/* Reset watchdog and handle polls and events */ /* Reset watchdog and handle polls and events */
watchdog_periodic(); watchdog_periodic();
/**/ #if CLOCK_CONF_STACK_FRIENDLY
#if !CLOCK_CONF_ACCURATE
if(sleep_flag) { if(sleep_flag) {
if(etimer_pending() && if(etimer_pending() &&
(etimer_next_expiration_time() - count - 1) > MAX_TICKS) { /*core/sys/etimer.c*/ (etimer_next_expiration_time() - clock_time() - 1) > MAX_TICKS) {
etimer_request_poll(); etimer_request_poll();
} }
sleep_flag = 0; sleep_flag = 0;