]> oss.titaniummirror.com Git - tinyos-2.x.git/commitdiff
switch to failure handlers written in nesC
authorregehr <regehr>
Sat, 6 Sep 2008 21:22:33 +0000 (21:22 +0000)
committerregehr <regehr>
Sat, 6 Sep 2008 21:22:33 +0000 (21:22 +0000)
support/make/avr/avr.rules
support/make/msp/msp.rules
tos/lib/safe/SafeFailureHandlerC.nc [new file with mode: 0644]
tos/lib/safe/SafeFailureHandlerP.nc [new file with mode: 0644]
tos/lib/safe/avr/fail.c [deleted file]
tos/lib/safe/include/deputy/checks.h
tos/lib/safe/msp430/fail.c [deleted file]
tos/system/MainC.nc

index 03b089ffd7157892e2ff36c8fee23c6cdf1c9fbf..708a4ab621592aab57d7f6401c6482988089dddb 100644 (file)
@@ -24,7 +24,7 @@ endef
 HELP += $(AVR_HELP)
 
 ifdef MAKE_DEPUTY_FLAG
-        NCC_SAFE_TINYOS_FLAGS = -DSAFE_TINYOS -fnesc-deputy -fnesc-deputy-args='-I$(TOSDIR)/lib/safe/include --FLIDs=build/$(PLATFORM)/flids.txt --envmachine -DSAFE_TINYOS --nolib ' $(TOSDIR)/lib/safe/avr/fail.c 
+        NCC_SAFE_TINYOS_FLAGS = -DSAFE_TINYOS -I$(TOSDIR)/lib/safe -fnesc-deputy -fnesc-deputy-args='-I$(TOSDIR)/lib/safe/include --FLIDs=build/$(PLATFORM)/flids.txt --envmachine -DSAFE_TINYOS --nolib '
 else
         NCC_SAFE_TINYOS_FLAGS =
 endif
index 04b090774595bfa8d43ec605c9fa1f56297ce2fb..18d9affd470cb638f741bf53828c7d2e640137ee 100644 (file)
@@ -23,7 +23,7 @@ endef
 HELP += $(MSP_HELP)
 
 ifdef MAKE_DEPUTY_FLAG
-        NCC_SAFE_TINYOS_FLAGS = -DSAFE_TINYOS -fnesc-deputy -fnesc-deputy-args='-I$(TOSDIR)/lib/safe/include --FLIDs=build/$(PLATFORM)/flids.txt --envmachine -DSAFE_TINYOS --nolib ' $(TOSDIR)/lib/safe/msp430/fail.c 
+        NCC_SAFE_TINYOS_FLAGS = -DSAFE_TINYOS -I$(TOSDIR)/lib/safe -fnesc-deputy -fnesc-deputy-args='-I$(TOSDIR)/lib/safe/include --FLIDs=build/$(PLATFORM)/flids.txt --envmachine -DSAFE_TINYOS --nolib '
 else
         NCC_SAFE_TINYOS_FLAGS =
 endif
diff --git a/tos/lib/safe/SafeFailureHandlerC.nc b/tos/lib/safe/SafeFailureHandlerC.nc
new file mode 100644 (file)
index 0000000..ea8dd85
--- /dev/null
@@ -0,0 +1,13 @@
+
+#include "Timer.h"
+
+configuration SafeFailureHandlerC {
+}
+implementation {
+  components LedsC;
+  components SafeFailureHandlerP;
+  components BusyWaitMicroC as Wait;
+
+  SafeFailureHandlerP.Leds -> LedsC;
+  SafeFailureHandlerP.BusyWait -> Wait;
+}
diff --git a/tos/lib/safe/SafeFailureHandlerP.nc b/tos/lib/safe/SafeFailureHandlerP.nc
new file mode 100644 (file)
index 0000000..74d6892
--- /dev/null
@@ -0,0 +1,140 @@
+
+#include "Timer.h"
+
+module SafeFailureHandlerP {
+  uses {
+    interface Leds;
+    interface BusyWait<TMicro, uint16_t>;
+  }
+}
+implementation {
+
+  #ifndef asmlinkage
+    #define asmlinkage
+  #endif
+
+  #ifndef noreturn
+    #define noreturn __attribute__((noreturn))
+  #endif
+
+  void delay (int len) 
+  {
+    volatile int x;
+    for (x=0; x<len; x++) { 
+      call BusyWait.wait(2000);
+    }
+  }
+
+  void v_short_delay (void) { delay (10); }
+
+  void short_delay (void) { delay (80); }
+
+  void long_delay (void) { delay (800); }
+
+  void flicker (void)
+  {
+    int i;
+    for (i=0; i<20; i++) {
+       delay (20);
+       call Leds.led0Off();
+       call Leds.led1Off();
+       call Leds.led2Off();
+       delay (20);
+       call Leds.led0On();
+       call Leds.led1On();
+       call Leds.led2On();
+    }
+    call Leds.led0Off();
+    call Leds.led1Off();
+    call Leds.led2Off();
+  }
+
+  void roll (void)
+  {
+    int i;
+    for (i=0; i<10; i++) {
+       delay (30);
+       call Leds.led0On();
+       call Leds.led2Off();
+       delay (30);
+       call Leds.led1On();
+       call Leds.led0Off();
+       delay (30);
+       call Leds.led2On();
+       call Leds.led1Off();
+    }
+    call Leds.led2Off();
+  }
+           
+  void separator (void)
+  {
+    call Leds.led0Off();
+    call Leds.led1Off();
+    call Leds.led2Off();
+    short_delay ();
+    call Leds.led0On();
+    call Leds.led1On();
+    call Leds.led2On();
+    v_short_delay ();
+    call Leds.led0Off();
+    call Leds.led1Off();
+    call Leds.led2Off();
+    short_delay ();
+  }
+
+  void display_b4 (int c) 
+  {
+    switch (c) {
+    case 3:
+      call Leds.led2On();
+    case 2:
+      call Leds.led1On();
+    case 1:
+      call Leds.led0On();
+    case 0:
+      long_delay ();
+      break;
+    default:
+      flicker ();
+    }
+    separator ();
+  }
+
+  void display_int (const unsigned int x)
+  {
+    int i = 14;
+    do {
+      display_b4 (0x3 & (x >> i));
+      i -= 2;
+    } while (i >= 0);
+  }
+
+  void display_int_flid (const unsigned int x)
+  {
+    roll ();
+    display_int (x);
+    roll ();
+  }
+
+  asmlinkage noreturn 
+  void deputy_fail_noreturn_fast (int flid) @C() @spontaneous()
+  {
+    atomic {
+      while(1) {
+        display_int_flid(flid);
+      }
+    }
+  }
+
+  asmlinkage 
+  void deputy_fail_mayreturn(int flid) @C() @spontaneous()
+  {
+    deputy_fail_noreturn_fast(flid);
+  }
+
+  asmlinkage noreturn 
+  void deputy_fail_noreturn(int flid) @C() @spontaneous()
+  {
+    deputy_fail_noreturn_fast(flid);
+  }
+}
diff --git a/tos/lib/safe/avr/fail.c b/tos/lib/safe/avr/fail.c
deleted file mode 100644 (file)
index 32e5786..0000000
+++ /dev/null
@@ -1,184 +0,0 @@
-#undef SAFE_TINYOS
-
-#include <stdint.h>
-#include <avr/io.h>
-
-// #define SIMPLE_FAIL
-
-#ifndef SIMPLE_FAIL
-
-static void led_off_0 (void) 
-{ 
-  *(volatile unsigned char *)59U |= 1 << 0;
-}
-
-static void led_off_1 (void)  { 
-  *(volatile unsigned char *)59U |= 1 << 1;
-}
-
-static void led_off_2 (void)  {
-  *(volatile unsigned char *)59U |= 1 << 2;
-}
-
-static void led_on_0 (void) { 
-  *(volatile unsigned char *)59U &= ~(1 << 0);
-}
-
-static void led_on_1 (void) { 
-  *(volatile unsigned char *)59U &= ~(1 << 1);
-}
-
-static void led_on_2 (void) { 
-  *(volatile unsigned char *)59U &= ~(1 << 2);
-}
-
-static void delay (int len) 
-{
-  volatile int x, y;
-  for (x=0; x<len; x++) { 
-    for (y=0; y<1000; y++) { }
-  }
-}
-
-static void v_short_delay (void) { delay (10); }
-
-static void short_delay (void) { delay (80); }
-
-static void long_delay (void) { delay (800); }
-
-static void flicker (void)
-{
-    int i;
-    for (i=0; i<20; i++) {
-       delay (20);
-       led_off_0 ();
-       led_off_1 ();
-       led_off_2 ();
-       delay (20);
-       led_on_0 ();
-       led_on_1 ();
-       led_on_2 ();
-    }
-    led_off_0 ();
-    led_off_1 ();
-    led_off_2 ();
-}
-
-static void roll (void)
-{
-    int i;
-    for (i=0; i<10; i++) {
-       delay (30);
-       led_on_0 ();
-       led_off_2 ();
-       delay (30);
-       led_on_1 ();
-       led_off_0 ();
-       delay (30);
-       led_on_2 ();
-       led_off_1 ();
-    }
-    led_off_2 ();
-}
-           
-static void separator (void)
-{
-    led_off_0 ();
-    led_off_1 ();
-    led_off_2 ();
-    short_delay ();
-    led_on_0 ();
-    led_on_1 ();
-    led_on_2 ();
-    v_short_delay ();
-    led_off_0 ();
-    led_off_1 ();
-    led_off_2 ();
-    short_delay ();
-}
-
-static void display_b4 (int c) 
-{
-  switch (c) {
-  case 3:
-    led_on_2 ();
-  case 2:
-    led_on_1 ();
-  case 1:
-    led_on_0 ();
-  case 0:
-    long_delay ();
-    break;
-  default:
-    flicker ();
-  }
-  separator ();
-}
-
-static void display_int (const unsigned int x)
-{
-  int i = 14;
-  do {
-    display_b4 (0x3 & (x >> i));
-    i -= 2;
-  } while (i >= 0);
-}
-
-static void display_int_flid (const unsigned int x)
-{
-  roll ();
-  display_int (x);
-  roll ();
-}
-
-#endif // ndef SIMPLE_FAIL
-
-static inline void load_to_z_and_break (int value)
-{
-  asm volatile ("movw %0, %1" "\n\t"
-               "break"       "\n\t"
-               : "=z"(value)  : "r" (value));
-}
-
-void deputy_fail_noreturn_fast (int flid)
-{
-  asm volatile ("cli");
-  load_to_z_and_break (flid);
-  PORTA |= 7;
-
-#ifdef SIMPLE_FAIL
-
-  while (1) {
-    int i;
-    PORTA ^= 7;
-    for (i = 0; i < 10; i++) {
-      uint16_t dt = 50000;
-      /* loop takes 8 cycles. this is 1uS if running on an internal 8MHz
-        clock, and 1.09uS if running on the external crystal. */
-      asm volatile (
-                   "1: sbiw    %0,1\n"
-                   "   adiw    %0,1\n"
-                   "   sbiw    %0,1\n"
-                   "   brne    1b" : "+w" (dt));
-    }
-  }
-
-#else
-
-  while (1) {
-    display_int_flid (flid);
-  }
-
-#endif
-
-}
-
-void deputy_fail_mayreturn(int flid)
-{
-    deputy_fail_noreturn_fast(flid);
-}
-
-void deputy_fail_noreturn(int flid)
-{
-    deputy_fail_noreturn_fast(flid);
-}
index 61f935d936418072afa0386d24da6295396b54f7..f0582b8642264bd12bed9f6d64dc79fd3d041c97 100644 (file)
@@ -50,7 +50,7 @@ extern asmlinkage noreturn
 void deputy_fail_noreturn(__LOCATION__FORMALS);
 
 extern asmlinkage noreturn
-void deputy_fail_noreturn_fast(void);
+void deputy_fail_noreturn_fast(__LOCATION__FORMALS);
 
 /* Search for a NULL starting at e and return its index */
 extern asmlinkage
diff --git a/tos/lib/safe/msp430/fail.c b/tos/lib/safe/msp430/fail.c
deleted file mode 100644 (file)
index a1125c9..0000000
+++ /dev/null
@@ -1,152 +0,0 @@
-#undef SAFE_TINYOS
-
-static void led_off_0 (void) {
-    __asm__ volatile ("bis.b #16, &0x0031"); // telos
-    __asm__ volatile ("bis.b #1, &0x001D"); // shimmer
-}
-
-static void led_off_1 (void)  { 
-    __asm__ volatile ("bis.b #32, &0x0031"); // telos
-    __asm__ volatile ("bis.b #2, &0x001D"); // shimmer
-}
-
-static void led_off_2 (void)  {
-    __asm__ volatile ("bis.b #64, &0x0031"); // telos
-    __asm__ volatile ("bis.b #4, &0x001D"); // shimmer
-}
-
-static void led_on_0 (void) { 
-    __asm__ volatile ("bic.b #16, &0x0031"); // telos
-    __asm__ volatile ("bic.b #1, &0x001D"); // shimmer
-}
-
-static void led_on_1 (void) { 
-    __asm__ volatile ("bic.b #32, &0x0031"); // telos
-    __asm__ volatile ("bic.b #2, &0x001D"); // shimmer
-}
-
-static void led_on_2 (void) { 
-    __asm__ volatile ("bic.b #64, &0x0031"); // telos
-    __asm__ volatile ("bic.b #4, &0x001D"); // shimmer
-}
-
-static void delay (int len) 
-{
-  volatile int x, y;
-  for (x=0; x<len; x++) { 
-    for (y=0; y<1000; y++) { }
-  }
-}
-
-static void v_short_delay (void) { delay (10); }
-
-static void short_delay (void) { delay (80); }
-
-static void long_delay (void) { delay (800); }
-
-static void flicker (void)
-{
-    int i;
-    for (i=0; i<20; i++) {
-       delay (20);
-       led_off_0 ();
-       led_off_1 ();
-       led_off_2 ();
-       delay (20);
-       led_on_0 ();
-       led_on_1 ();
-       led_on_2 ();
-    }
-    led_off_0 ();
-    led_off_1 ();
-    led_off_2 ();
-}
-
-static void roll (void)
-{
-    int i;
-    for (i=0; i<10; i++) {
-       delay (30);
-       led_on_0 ();
-       led_off_2 ();
-       delay (30);
-       led_on_1 ();
-       led_off_0 ();
-       delay (30);
-       led_on_2 ();
-       led_off_1 ();
-    }
-    led_off_2 ();
-}
-           
-static void separator (void)
-{
-    led_off_0 ();
-    led_off_1 ();
-    led_off_2 ();
-    short_delay ();
-    led_on_0 ();
-    led_on_1 ();
-    led_on_2 ();
-    v_short_delay ();
-    led_off_0 ();
-    led_off_1 ();
-    led_off_2 ();
-    short_delay ();
-}
-
-static void display_b4 (int c) 
-{
-  switch (c) {
-  case 3:
-    led_on_2 ();
-  case 2:
-    led_on_1 ();
-  case 1:
-    led_on_0 ();
-  case 0:
-    long_delay ();
-    break;
-  default:
-    flicker ();
-  }
-  separator ();
-}
-
-static void display_int (const unsigned int x)
-{
-  int i = 14;
-  do {
-    display_b4 (0x3 & (x >> i));
-    i -= 2;
-  } while (i >= 0);
-}
-
-static void display_int_flid (const unsigned int x)
-{
-  roll ();
-  display_int (x);
-  roll ();
-}
-
-// Not sure how to do this in Telosb without looking it up
-void deputy_fail_noreturn_fast (int flid)
-{
-  // disable interrupts
-  // set LEDS to output
-
-  while (1) {
-    display_int_flid (flid);
-  }
-
-}
-
-void deputy_fail_mayreturn(int flid)
-{
-    deputy_fail_noreturn_fast(flid);
-}
-
-void deputy_fail_noreturn(int flid)
-{
-    deputy_fail_noreturn_fast(flid);
-}
index 9f61d0ecebf6891495ba7da4ff1c5c95ee76a736..a6caac44772021d385d0103ff47695a6ca50073f 100644 (file)
@@ -49,6 +49,10 @@ configuration MainC {
 implementation {
   components PlatformC, RealMainP, TinySchedulerC;
 
+#ifdef SAFE_TINYOS
+  components SafeFailureHandlerC;
+#endif
+
   RealMainP.Scheduler -> TinySchedulerC;
   RealMainP.PlatformInit -> PlatformC;