send ethernet packet on center button press
Stefan Schuermans

Stefan Schuermans commited on 2012-03-07 21:52:08
Showing 1 changed files, with 28 additions and 19 deletions.

... ...
@@ -15,6 +15,7 @@
15 15
 #else
16 16
 # define CFG_DELAY
17 17
 # define CFG_LCD
18
+# define CFG_SWITCHES
18 19
 #endif
19 20
 
20 21
 const int myconst = 0x12345678;
... ...
@@ -23,9 +24,27 @@ int myvar = 0x11223344;
23 24
 
24 25
 volatile int data[100];
25 26
 
27
+#ifdef CFG_ETH_TX
28
+  static const unsigned char example_packet[] = {
29
+    0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, /* destination MAC */
30
+    0x02, 0x03, 0x04, 0x05, 0x06, 0x07, /* source MAC */
31
+    0x08, 0x00, /* ethertype: IP */
32
+    0x45, 0x00, 0x00, 0x36, /* IP header: ..., len */
33
+    0x12, 0x34, 0x00, 0x00, /* IP header: ..., not fragmented */
34
+    0x40, 0x11, 0x00, 0x00, /* IP header: ..., UDP, ... */
35
+    0x7F, 0x00, 0x00, 0x01, /* source IP */
36
+    0xFF, 0xFF, 0xFF, 0xFF, /* destination IP */
37
+    0x00, 0x01, 0x00, 0x01, /* UDP: source port, destination port */
38
+    0x00, 0x22, 0x00, 0x00, /* UDP: len, ... */
39
+    'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
40
+    'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'
41
+  };
42
+#endif
43
+
26 44
 void switches(void)
27 45
 {
28 46
 #ifdef CFG_LCD
47
+#ifdef CFG_SWITCHES
29 48
   lcd_chr(1, 0, switches_get_state(sw_0) ? '0' : ' ');
30 49
   lcd_chr(1, 1, switches_get_state(sw_1) ? '1' : ' ');
31 50
   lcd_chr(1, 2, switches_get_state(sw_2) ? '2' : ' ');
... ...
@@ -38,14 +57,17 @@ void switches(void)
38 57
   lcd_chr(1, 9, switches_get_state(sw_rot_a) ? 'a' : ' ');
39 58
   lcd_chr(1, 10, switches_get_state(sw_rot_b) ? 'b' : ' ');
40 59
 #endif
60
+#endif
41 61
 
42 62
 #ifdef CFG_LCD
63
+#ifdef CFG_SWITCHES
43 64
   unsigned int cnt = switches_get_rot_cnt();
44 65
   lcd_chr(1, 12, '0' + (cnt >> 9 & 0x7));
45 66
   lcd_chr(1, 13, '0' + (cnt >> 6 & 0x7));
46 67
   lcd_chr(1, 14, '0' + (cnt >> 3 & 0x7));
47 68
   lcd_chr(1, 15, '0' + (cnt & 0x7));
48 69
 #endif
70
+#endif
49 71
 }
50 72
 
51 73
 void delay(void)
... ...
@@ -56,22 +78,6 @@ void delay(void)
56 78
   unsigned char *ptr;
57 79
   unsigned int sz;
58 80
 #endif
59
-#ifdef CFG_ETH_TX
60
-  static const unsigned char example_packet[] = {
61
-    0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, /* destination MAC */
62
-    0x02, 0x03, 0x04, 0x05, 0x06, 0x07, /* source MAC */
63
-    0x08, 0x00, /* ethertype: IP */
64
-    0x45, 0x00, 0x00, 0x36, /* IP header: ..., len */
65
-    0x12, 0x34, 0x00, 0x00, /* IP header: ..., not fragmented */
66
-    0x40, 0x11, 0x00, 0x00, /* IP header: ..., UDP, ... */
67
-    0x7F, 0x00, 0x00, 0x01, /* source IP */
68
-    0xFF, 0xFF, 0xFF, 0xFF, /* destination IP */
69
-    0x00, 0x01, 0x00, 0x01, /* UDP: source port, destination port */
70
-    0x00, 0x22, 0x00, 0x00, /* UDP: len, ... */
71
-    'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
72
-    'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'
73
-  };
74
-#endif
75 81
 
76 82
   for (i = 0; i < 10; ++i) {
77 83
     switches();
... ...
@@ -88,9 +94,6 @@ void delay(void)
88 94
     cyc_cnt_delay_ms(20);
89 95
 #endif
90 96
   }
91
-#ifdef CFG_ETH_TX
92
-  eth_tx(example_packet, sizeof(example_packet));
93
-#endif
94 97
 }
95 98
 
96 99
 int main()
... ...
@@ -160,6 +163,12 @@ int main()
160 163
     leds_set_state(leds);
161 164
     leds = leds << 1 | leds >> 7;
162 165
     delay();
166
+#ifdef CFG_ETH_TX
167
+#ifdef CFG_SWITCHES
168
+    if (switches_get_state(sw_center))
169
+#endif
170
+      eth_tx(example_packet, sizeof(example_packet));
171
+#endif
163 172
   }
164 173
 
165 174
   return 0;
166 175