1 #ifndef INCLUDED_LED_H
2 #define INCLUDED_LED_H
3
4 extern long * LED_GREEN, * LED_RED, * LED_AF;
5
6 #ifndef DEFAULT_DELAY
7 #define DEFAULT_DELAY 5000000
8 #endif
9
10 typedef unsigned long ulong;
11
12 void busy_wait(ulong n);
13 void led_on(long * led);
14 void led_off(long * led);
15 void led_flashx(long * led, ulong times, ulong delay);
16 void led_binx(long val, ulong delay);
17 void led_dumpx(long * mem, ulong len, ulong delay);
18
19 void __attribute__((naked,noinline)) led_flash2();
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 #define led_flash(led, times) led_flashx(led, times, DEFAULT_DELAY)
35 #define led_bin(val) led_binx(val, DEFAULT_DELAY)
36 #define led_dump(mem, len) led_dumpx(mem, len, DEFAULT_DELAY)
37
38 #define BUSY_WAIT(delay) do { unsigned long i = (delay); while (--i) asm volatile("nop\n"); } while (0)
39
40 #define LED_ON(led) do { *(long*)(led) = 0x46; } while(0)
41
42 #define LED_OFF(led) do { *(long*)(led) = 0x44; } while(0)
43
44 #define LED_FLASHX(led, times, delay) \
45 do { \
46 long i = (times); \
47 while (i--) { \
48 LED_ON((led)); \
49 BUSY_WAIT((delay)); \
50 LED_OFF((led)); \
51 BUSY_WAIT((delay)); \
52 } \
53 } while (0)
54
55 #define LED_FLASH(led, times) LED_FLASHX((led), (times), DEFAULT_DELAY)
56
57 #endif