1 /* mbed Microcontroller Library - Ethernet
2 * Copyright (c) 2009 ARM Limited. All rights reserved.
6 #ifndef MBED_ETHERNET_H
7 #define MBED_ETHERNET_H
14 * An ethernet interface, to use with the ethernet pins.
17 * > // Read destination and source from every ethernet packet
27 * > int size = eth.receive();
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]);
41 class Ethernet : public Base {
45 /* Constructor: Ethernet
46 * Initialise the ethernet interface.
50 /* Destructor: Ethernet
51 * Powers the hardware down.
64 * Writes into an outgoing ethernet packet.
66 * It will append size bytes of data to the previously written bytes.
69 * data - An array to write.
70 * size - The size of data.
73 * The number of written bytes.
75 int write(const char *data, int size);
78 * Send an outgoing ethernet packet.
80 * After filling in the data in an ethernet packet it must be send.
81 * Send will provide a new packet to write to.
84 * 0 - If the sending was failed.
85 * 1 - If the package is successfully sent.
90 * Recevies an arrived ethernet packet.
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.
97 * 0 - If no ethernet packet is arrived.
98 * The size of the arrived packet.
103 * Read from an recevied ethernet packet.
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.
109 * It is possible to use read multible times.
110 * Each time read will start reading after the last read byte before.
113 * The number of byte read.
115 int read(char *data, int size);
118 * Gives the ethernet address of the mbed.
121 * mac - Must be a pointer to a 6 byte char array to copy the ethernet address in.
123 void address(char *mac);
126 * Returns if an ethernet link is pressent or not. It takes a wile after Ethernet initializion to show up.
129 * 0 - If no ethernet link is pressent.
130 * 1 - If an ethernet link is pressent.
133 * > // Using the Ethernet link function
134 * > #include "mbed.h"
139 * > wait(1); // Needed after startup.
141 * > printf("online\n");
143 * > printf("offline\n");
150 /* Function: set_link
151 * Sets the speed and duplex parameters of an ethernet link
154 * mode - the speed and duplex mode to set the link to:
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
162 void set_link(Mode mode);