svn / mbed / trunk / Ethernet.h

Revision 29, 4.4 kB (checked in by emilmont, 6 months ago)

New Libraries 11.11

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