mouvement AX12 petit robot version 2

Fork of command_AX12_petit_robot by CRAC Team

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Ethernet.h Source File

Ethernet.h

00001 /* mbed Microcontroller Library - Ethernet
00002  * Copyright (c) 2009-2011 ARM Limited. All rights reserved.
00003  */ 
00004  
00005 #ifndef MBED_ETHERNET_H
00006 #define MBED_ETHERNET_H
00007 
00008 #include "device.h"
00009 
00010 #if DEVICE_ETHERNET
00011 
00012 #include "Base.h"
00013 
00014 namespace mbed {
00015 
00016 /* Class: Ethernet
00017  *  An ethernet interface, to use with the ethernet pins.
00018  *
00019  * Example:
00020  * > // Read destination and source from every ethernet packet
00021  * >
00022  * > #include "mbed.h"
00023  * >
00024  * > Ethernet eth;
00025  * > 
00026  * > int main() {
00027  * >     char buf[0x600];
00028  * >     
00029  * >     while(1) {
00030  * >         int size = eth.receive();
00031  * >         if(size > 0) {
00032  * >             eth.read(buf, size);
00033  * >             printf("Destination:  %02X:%02X:%02X:%02X:%02X:%02X\n",
00034  * >                     buf[0], buf[1], buf[2], buf[3], buf[4], buf[5]);
00035  * >             printf("Source: %02X:%02X:%02X:%02X:%02X:%02X\n",
00036  * >                     buf[6], buf[7], buf[8], buf[9], buf[10], buf[11]);
00037  * >         }
00038  * >         
00039  * >         wait(1);
00040  * >     }
00041  * > }
00042  *
00043  */
00044 class Ethernet : public Base {
00045 
00046 public:
00047     
00048     /* Constructor: Ethernet
00049      *  Initialise the ethernet interface.
00050      */
00051     Ethernet();
00052 
00053     /* Destructor: Ethernet
00054      *  Powers the hardware down.
00055      */
00056     virtual ~Ethernet();
00057 
00058     enum Mode {
00059         AutoNegotiate
00060         , HalfDuplex10
00061         , FullDuplex10
00062         , HalfDuplex100
00063         , FullDuplex100
00064     };
00065 
00066     /* Function: write
00067      *  Writes into an outgoing ethernet packet.
00068      *
00069      *  It will append size bytes of data to the previously written bytes.
00070      *  
00071      *  Variables:
00072      *   data - An array to write.
00073      *   size - The size of data.
00074      *
00075      *  Returns:
00076      *   The number of written bytes.
00077      */
00078     int write(const char *data, int size);
00079 
00080     /* Function: send
00081      *  Send an outgoing ethernet packet.
00082      *
00083      *  After filling in the data in an ethernet packet it must be send.
00084      *  Send will provide a new packet to write to.
00085      *
00086      * Returns:
00087      *  0 - If the sending was failed.
00088      *  1 - If the package is successfully sent.
00089      */
00090     int send();
00091 
00092     /* Function: receive
00093      *  Recevies an arrived ethernet packet.
00094      *
00095      *  Receiving an ethernet packet will drop the last received ethernet packet 
00096      *  and make a new ethernet packet ready to read.
00097      *  If no ethernet packet is arrived it will return 0.
00098      *
00099      * Returns:
00100      *  0 - If no ethernet packet is arrived.
00101      *  The size of the arrived packet.
00102      */
00103     int receive();
00104 
00105     /* Function: read
00106      *  Read from an recevied ethernet packet.
00107      *
00108      *  After receive returnd a number bigger than 0it is
00109      *  possible to read bytes from this packet.
00110      *  Read will write up to size bytes into data.
00111      *
00112      *  It is possible to use read multible times. 
00113      *  Each time read will start reading after the last read byte before.
00114      *
00115      * Returns:
00116      *  The number of byte read.
00117      */
00118     int read(char *data, int size);
00119     
00120     /* Function: address
00121      *  Gives the ethernet address of the mbed.
00122      *
00123      * Variables:
00124      *  mac - Must be a pointer to a 6 byte char array to copy the ethernet address in.
00125      */
00126     void address(char *mac);
00127 
00128     /* Function: link
00129      *  Returns if an ethernet link is pressent or not. It takes a wile after Ethernet initializion to show up.
00130      * 
00131      * Returns:
00132      *  0 - If no ethernet link is pressent.
00133      *  1 - If an ethernet link is pressent.
00134      *
00135      * Example:
00136      * > // Using the Ethernet link function
00137      * > #include "mbed.h"
00138      * >
00139      * > Ethernet eth;
00140      * >
00141      * > int main() {
00142      * >     wait(1); // Needed after startup.
00143      * >     if(eth.link()) {
00144      * >         printf("online\n");
00145      * >     } else {
00146      * >          printf("offline\n");
00147      * >     }
00148      * > }
00149      *
00150      */
00151     int link();
00152 
00153     /* Function: set_link
00154      *  Sets the speed and duplex parameters of an ethernet link
00155      *
00156      *  Variables:
00157      *   mode - the speed and duplex mode to set the link to:
00158      *
00159      * > AutoNegotiate      Auto negotiate speed and duplex
00160      * > HalfDuplex10       10 Mbit, half duplex
00161      * > FullDuplex10       10 Mbit, full duplex
00162      * > HalfDuplex100      100 Mbit, half duplex
00163      * > FullDuplex100      100 Mbit, full duplex
00164      */
00165     void set_link(Mode mode);
00166 
00167 };
00168 
00169 } // namespace mbed
00170 
00171 #endif
00172 
00173 #endif