File: SafeFailureHandlerP.nc

package info (click to toggle)
tinyos 2.1.2%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: buster, jessie, jessie-kfreebsd, stretch
  • size: 47,476 kB
  • ctags: 36,607
  • sloc: ansic: 63,646; cpp: 14,974; java: 10,358; python: 5,215; makefile: 1,724; sh: 902; asm: 597; xml: 392; perl: 74; awk: 46
file content (143 lines) | stat: -rw-r--r-- 2,418 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143

#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 {
#if defined(__AVR_ARCH__)
      asm volatile ("break");
#endif
      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);
  }
}