re-enabling serial
[clinton/Smoothieware.git] / gcc4mbed / external / mbed / .svn / text-base / Ethernet.h.svn-base
1 /* mbed Microcontroller Library - Ethernet
2 * Copyright (c) 2009 ARM Limited. All rights reserved.
3 * sford, rmeyer
4 */
5
6 #ifndef MBED_ETHERNET_H
7 #define MBED_ETHERNET_H
8
9 #include "Base.h"
10
11 namespace mbed {
12
13 /* Class: Ethernet
14 * An ethernet interface, to use with the ethernet pins.
15 *
16 * Example:
17 * > // Read destination and source from every ethernet packet
18 * >
19 * > #include "mbed.h"
20 * >
21 * > Ethernet eth;
22 * >
23 * > int main() {
24 * > char buf[0x600];
25 * >
26 * > while(1) {
27 * > int size = eth.receive();
28 * > if(size > 0) {
29 * > eth.read(buf, size);
30 * > printf("Destination: %02X:%02X:%02X:%02X:%02X:%02X\n",
31 * > buf[0], buf[1], buf[2], buf[3], buf[4], buf[5]);
32 * > printf("Source: %02X:%02X:%02X:%02X:%02X:%02X\n",
33 * > buf[6], buf[7], buf[8], buf[9], buf[10], buf[11]);
34 * > }
35 * >
36 * > wait(1);
37 * > }
38 * > }
39 *
40 */
41 class Ethernet : public Base {
42
43 public:
44
45 /* Constructor: Ethernet
46 * Initialise the ethernet interface.
47 */
48 Ethernet();
49
50 /* Destructor: Ethernet
51 * Powers the hardware down.
52 */
53 virtual ~Ethernet();
54
55 enum Mode {
56 AutoNegotiate
57 , HalfDuplex10
58 , FullDuplex10
59 , HalfDuplex100
60 , FullDuplex100
61 };
62
63 /* Function: write
64 * Writes into an outgoing ethernet packet.
65 *
66 * It will append size bytes of data to the previously written bytes.
67 *
68 * Variables:
69 * data - An array to write.
70 * size - The size of data.
71 *
72 * Returns:
73 * The number of written bytes.
74 */
75 int write(const char *data, int size);
76
77 /* Function: send
78 * Send an outgoing ethernet packet.
79 *
80 * After filling in the data in an ethernet packet it must be send.
81 * Send will provide a new packet to write to.
82 *
83 * Returns:
84 * 0 - If the sending was failed.
85 * 1 - If the package is successfully sent.
86 */
87 int send();
88
89 /* Function: receive
90 * Recevies an arrived ethernet packet.
91 *
92 * Receiving an ethernet packet will drop the last received ethernet packet
93 * and make a new ethernet packet ready to read.
94 * If no ethernet packet is arrived it will return 0.
95 *
96 * Returns:
97 * 0 - If no ethernet packet is arrived.
98 * The size of the arrived packet.
99 */
100 int receive();
101
102 /* Function: read
103 * Read from an recevied ethernet packet.
104 *
105 * After receive returnd a number bigger than 0it is
106 * possible to read bytes from this packet.
107 * Read will write up to size bytes into data.
108 *
109 * It is possible to use read multible times.
110 * Each time read will start reading after the last read byte before.
111 *
112 * Returns:
113 * The number of byte read.
114 */
115 int read(char *data, int size);
116
117 /* Function: address
118 * Gives the ethernet address of the mbed.
119 *
120 * Variables:
121 * mac - Must be a pointer to a 6 byte char array to copy the ethernet address in.
122 */
123 void address(char *mac);
124
125 /* Function: link
126 * Returns if an ethernet link is pressent or not. It takes a wile after Ethernet initializion to show up.
127 *
128 * Returns:
129 * 0 - If no ethernet link is pressent.
130 * 1 - If an ethernet link is pressent.
131 *
132 * Example:
133 * > // Using the Ethernet link function
134 * > #include "mbed.h"
135 * >
136 * > Ethernet eth;
137 * >
138 * > int main() {
139 * > wait(1); // Needed after startup.
140 * > if(eth.link()) {
141 * > printf("online\n");
142 * > } else {
143 * > printf("offline\n");
144 * > }
145 * > }
146 *
147 */
148 int link();
149
150 /* Function: set_link
151 * Sets the speed and duplex parameters of an ethernet link
152 *
153 * Variables:
154 * mode - the speed and duplex mode to set the link to:
155 *
156 * > AutoNegotiate Auto negotiate speed and duplex
157 * > HalfDuplex10 10 Mbit, half duplex
158 * > FullDuplex10 10 Mbit, full duplex
159 * > HalfDuplex100 100 Mbit, half duplex
160 * > FullDuplex100 100 Mbit, full duplex
161 */
162 void set_link(Mode mode);
163
164 };
165
166 } // namespace mbed
167
168 #endif