Stefan Schuermans commited on 2012-03-06 18:59:32
Showing 3 changed files, with 49 additions and 6 deletions.
... | ... |
@@ -74,3 +74,16 @@ int eth_rx(void **pptr, unsigned int *psz) |
74 | 74 |
return 0; |
75 | 75 |
} |
76 | 76 |
|
77 |
+/** |
|
78 |
+ * @brief transmit packet |
|
79 |
+ * @param[out] ptr pointer to packet data |
|
80 |
+ * @param[out] sz size of packet |
|
81 |
+ */ |
|
82 |
+void eth_tx(void *ptr, unsigned int sz) |
|
83 |
+{ |
|
84 |
+ eth_ptr[8] = (unsigned int)ptr; /* start */ |
|
85 |
+ eth_ptr[9] = (unsigned int)ptr + sz; /* end */ |
|
86 |
+ eth_ptr[10] = 1; /* set flag */ |
|
87 |
+ while (eth_ptr[10] == 1); /* wait until processed */ |
|
88 |
+} |
|
89 |
+ |
... | ... |
@@ -12,5 +12,12 @@ void eth_rx_init(void); |
12 | 12 |
*/ |
13 | 13 |
int eth_rx(void **pptr, unsigned int *psz); |
14 | 14 |
|
15 |
+/** |
|
16 |
+ * @brief transmit packet |
|
17 |
+ * @param[out] ptr pointer to packet data |
|
18 |
+ * @param[out] sz size of packet |
|
19 |
+ */ |
|
20 |
+void eth_tx(void *ptr, unsigned int sz); |
|
21 |
+ |
|
15 | 22 |
#endif /* #ifndef ETH_H */ |
16 | 23 |
|
... | ... |
@@ -7,7 +7,8 @@ |
7 | 7 |
|
8 | 8 |
//#define CFG_SIMULATION |
9 | 9 |
|
10 |
-#define CFG_ETH |
|
10 |
+#define CFG_ETH_RX |
|
11 |
+#define CFG_ETH_TX |
|
11 | 12 |
#define CFG_UART |
12 | 13 |
#ifdef CFG_SIMULATION |
13 | 14 |
# define CFG_UART_CHK |
... | ... |
@@ -50,14 +51,33 @@ void switches(void) |
50 | 51 |
void delay(void) |
51 | 52 |
{ |
52 | 53 |
unsigned int i; |
53 |
-#ifdef CFG_ETH |
|
54 |
- unsigned int sz; |
|
54 |
+#ifdef CFG_ETH_RX |
|
55 |
+ void *vptr; |
|
55 | 56 |
unsigned char *ptr; |
57 |
+ unsigned int sz; |
|
58 |
+#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 |
+ }; |
|
56 | 74 |
#endif |
75 |
+ |
|
57 | 76 |
for (i = 0; i < 10; ++i) { |
58 | 77 |
switches(); |
59 |
-#ifdef CFG_ETH |
|
60 |
- while (eth_rx(&ptr, &sz)) { |
|
78 |
+#ifdef CFG_ETH_RX |
|
79 |
+ while (eth_rx(&vptr, &sz)) { |
|
80 |
+ ptr = vptr; |
|
61 | 81 |
#ifdef CFG_UART |
62 | 82 |
for ( ; sz > 0; ptr++, sz--) |
63 | 83 |
uart_tx(*ptr); |
... | ... |
@@ -68,6 +88,9 @@ void delay(void) |
68 | 88 |
cyc_cnt_delay_ms(20); |
69 | 89 |
#endif |
70 | 90 |
} |
91 |
+#ifdef CFG_ETH_TX |
|
92 |
+ eth_tx(example_packet, sizeof(example_packet)); |
|
93 |
+#endif |
|
71 | 94 |
} |
72 | 95 |
|
73 | 96 |
int main() |
... | ... |
@@ -83,7 +106,7 @@ int main() |
83 | 106 |
|
84 | 107 |
leds_set_state(0x02); |
85 | 108 |
|
86 |
-#ifdef CFG_ETH |
|
109 |
+#ifdef CFG_ETH_RX |
|
87 | 110 |
eth_rx_init(); |
88 | 111 |
#endif |
89 | 112 |
|
90 | 113 |