api / mbed / trunk / Ethernet
Ethernet
class Ethernet : public Base
An ethernet interface, to use with the ethernet pins.
Example
// Read destination and source from every ethernet packet
#include "mbed.h"
Ethernet eth;
int main() {
char buf[0x600];
while(1) {
int size = eth.receive();
if(size > 0) {
eth.read(buf, size);
printf("Destination: %02X:%02X:%02X:%02X:%02X:%02X\n",
buf[0], buf[1], buf[2], buf[3], buf[4], buf[5]);
printf("Source: %02X:%02X:%02X:%02X:%02X:%02X\n",
buf[6], buf[7], buf[8], buf[9], buf[10], buf[11]);
}
wait(1);
}
}| Ethernet | An ethernet interface, to use with the ethernet pins. |
| Functions | |
| Ethernet | Initialise the ethernet interface. |
| Ethernet | Powers the hardware down. |
| write | Writes into an outgoing ethernet packet. |
| send | Send an outgoing ethernet packet. |
| receive | Recevies an arrived ethernet packet. |
| read | Read from an recevied ethernet packet. |
| address | Gives the ethernet address of the mbed. |
| link | Returns if an ethernet link is pressent or not. |
| set_link | Sets the speed and duplex parameters of an ethernet link |
read
int read( char * data, int size )
Read from an recevied ethernet packet.
After receive returnd a number bigger than 0it is possible to read bytes from this packet. Read will write up to size bytes into data.
It is possible to use read multible times. Each time read will start reading after the last read byte before.
Returns
The number of byte read.
link
int link()
Returns if an ethernet link is pressent or not. It takes a wile after Ethernet initializion to show up.
Returns
| 0 | If no ethernet link is pressent. |
| 1 | If an ethernet link is pressent. |
Example
// Using the Ethernet link function
#include "mbed.h"
Ethernet eth;
int main() {
wait(1); // Needed after startup.
if(eth.link()) {
printf("online\n");
} else {
printf("offline\n");
}
}set_link
void set_link( Mode mode )
Sets the speed and duplex parameters of an ethernet link
Variables
| mode | the speed and duplex mode to set the link to: |
AutoNegotiate Auto negotiate speed and duplex HalfDuplex10 10 Mbit, half duplex FullDuplex10 10 Mbit, full duplex HalfDuplex100 100 Mbit, half duplex FullDuplex100 100 Mbit, full duplex
An ethernet interface, to use with the ethernet pins.
class Ethernet : public Base
Initialise the ethernet interface.
Ethernet()
Writes into an outgoing ethernet packet.
int write( const char * data, int size )
Send an outgoing ethernet packet.
int send()
Recevies an arrived ethernet packet.
int receive()
Read from an recevied ethernet packet.
int read( char * data, int size )
Gives the ethernet address of the mbed.
void address( char * mac )
Returns if an ethernet link is pressent or not.
int link()
Sets the speed and duplex parameters of an ethernet link
void set_link( Mode mode )
