1 /* mbed Microcontroller Library - Ethernet
2 * Copyright (c) 2009-2011 ARM Limited. All rights reserved.
5 #ifndef MBED_ETHERNET_H
6 #define MBED_ETHERNET_H
17 * An ethernet interface, to use with the ethernet pins.
20 * > // Read destination and source from every ethernet packet
30 * > int size = eth.receive();
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]);
44 class Ethernet
: public Base
{
48 /* Constructor: Ethernet
49 * Initialise the ethernet interface.
53 /* Destructor: Ethernet
54 * Powers the hardware down.
67 * Writes into an outgoing ethernet packet.
69 * It will append size bytes of data to the previously written bytes.
72 * data - An array to write.
73 * size - The size of data.
76 * The number of written bytes.
78 int write(const char *data
, int size
);
81 * Send an outgoing ethernet packet.
83 * After filling in the data in an ethernet packet it must be send.
84 * Send will provide a new packet to write to.
87 * 0 - If the sending was failed.
88 * 1 - If the package is successfully sent.
93 * Recevies an arrived ethernet packet.
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.
100 * 0 - If no ethernet packet is arrived.
101 * The size of the arrived packet.
106 * Read from an recevied ethernet packet.
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.
112 * It is possible to use read multible times.
113 * Each time read will start reading after the last read byte before.
116 * The number of byte read.
118 int read(char *data
, int size
);
121 * Gives the ethernet address of the mbed.
124 * mac - Must be a pointer to a 6 byte char array to copy the ethernet address in.
126 void address(char *mac
);
129 * Returns if an ethernet link is pressent or not. It takes a wile after Ethernet initializion to show up.
132 * 0 - If no ethernet link is pressent.
133 * 1 - If an ethernet link is pressent.
136 * > // Using the Ethernet link function
137 * > #include "mbed.h"
142 * > wait(1); // Needed after startup.
144 * > printf("online\n");
146 * > printf("offline\n");
153 /* Function: set_link
154 * Sets the speed and duplex parameters of an ethernet link
157 * mode - the speed and duplex mode to set the link to:
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
165 void set_link(Mode mode
);