1 /* mbed Microcontroller Library
2 * Copyright (c) 2006-2013 ARM Limited
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 #ifndef MBED_ETHERNET_H
17 #define MBED_ETHERNET_H
25 /** An ethernet interface, to use with the ethernet pins.
29 * // Read destination and source from every ethernet packet
39 * int size = eth.receive();
41 * eth.read(buf, size);
42 * printf("Destination: %02X:%02X:%02X:%02X:%02X:%02X\n",
43 * buf[0], buf[1], buf[2], buf[3], buf[4], buf[5]);
44 * printf("Source: %02X:%02X:%02X:%02X:%02X:%02X\n",
45 * buf[6], buf[7], buf[8], buf[9], buf[10], buf[11]);
57 /** Initialise the ethernet interface.
61 /** Powers the hardware down.
73 /** Writes into an outgoing ethernet packet.
75 * It will append size bytes of data to the previously written bytes.
77 * @param data An array to write.
78 * @param size The size of data.
81 * The number of written bytes.
83 int write(const char *data, int size);
85 /** Send an outgoing ethernet packet.
87 * After filling in the data in an ethernet packet it must be send.
88 * Send will provide a new packet to write to.
91 * 0 if the sending was failed,
92 * or the size of the packet successfully sent.
96 /** Recevies an arrived ethernet packet.
98 * Receiving an ethernet packet will drop the last received ethernet packet
99 * and make a new ethernet packet ready to read.
100 * If no ethernet packet is arrived it will return 0.
103 * 0 if no ethernet packet is arrived,
104 * or the size of the arrived packet.
108 /** Read from an recevied ethernet packet.
110 * After receive returnd a number bigger than 0it is
111 * possible to read bytes from this packet.
112 * Read will write up to size bytes into data.
114 * It is possible to use read multible times.
115 * Each time read will start reading after the last read byte before.
118 * The number of byte read.
120 int read(char *data, int size);
122 /** Gives the ethernet address of the mbed.
124 * @param mac Must be a pointer to a 6 byte char array to copy the ethernet address in.
126 void address(char *mac);
128 /** Returns if an ethernet link is pressent or not. It takes a wile after Ethernet initializion to show up.
131 * 0 if no ethernet link is pressent,
132 * 1 if an ethernet link is pressent.
136 * // Using the Ethernet link function
142 * wait(1); // Needed after startup.
144 * printf("online\n");
146 * printf("offline\n");
153 /** Sets the speed and duplex parameters of an ethernet link
155 * - AutoNegotiate Auto negotiate speed and duplex
156 * - HalfDuplex10 10 Mbit, half duplex
157 * - FullDuplex10 10 Mbit, full duplex
158 * - HalfDuplex100 100 Mbit, half duplex
159 * - FullDuplex100 100 Mbit, full duplex
161 * @param mode the speed and duplex mode to set the link to:
163 void set_link(Mode mode);