This is the final version of Mini Gateway for Automation and Security desgined for Renesas GR Peach Design Contest

Dependencies:   GR-PEACH_video GraphicsFramework HTTPServer R_BSP mbed-rpc mbed-rtos Socket lwip-eth lwip-sys lwip FATFileSystem

Fork of mbed-os-example-mbed5-blinky by mbed-os-examples

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Ethernet.h Source File

Ethernet.h

00001 /* mbed Microcontroller Library
00002  * Copyright (c) 2006-2013 ARM Limited
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *     http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 #ifndef MBED_ETHERNET_H
00017 #define MBED_ETHERNET_H
00018 
00019 #include "platform/platform.h"
00020 
00021 #if DEVICE_ETHERNET
00022 
00023 namespace mbed {
00024 /** \addtogroup drivers */
00025 /** @{*/
00026 
00027 /** An ethernet interface, to use with the ethernet pins.
00028  *
00029  * @Note Synchronization level: Not protected
00030  *
00031  * Example:
00032  * @code
00033  * // Read destination and source from every ethernet packet
00034  *
00035  * #include "mbed.h"
00036  *
00037  * Ethernet eth;
00038  *
00039  * int main() {
00040  *     char buf[0x600];
00041  *
00042  *     while(1) {
00043  *         int size = eth.receive();
00044  *         if(size > 0) {
00045  *             eth.read(buf, size);
00046  *             printf("Destination:  %02X:%02X:%02X:%02X:%02X:%02X\n",
00047  *                     buf[0], buf[1], buf[2], buf[3], buf[4], buf[5]);
00048  *             printf("Source: %02X:%02X:%02X:%02X:%02X:%02X\n",
00049  *                     buf[6], buf[7], buf[8], buf[9], buf[10], buf[11]);
00050  *         }
00051  *
00052  *         wait(1);
00053  *     }
00054  * }
00055  * @endcode
00056  */
00057 class Ethernet {
00058 
00059 public:
00060 
00061     /** Initialise the ethernet interface.
00062      */
00063     Ethernet();
00064 
00065     /** Powers the hardware down.
00066      */
00067     virtual ~Ethernet();
00068 
00069     enum Mode {
00070         AutoNegotiate,
00071         HalfDuplex10,
00072         FullDuplex10,
00073         HalfDuplex100,
00074         FullDuplex100
00075     };
00076 
00077     /** Writes into an outgoing ethernet packet.
00078      *
00079      *  It will append size bytes of data to the previously written bytes.
00080      *
00081      *  @param data An array to write.
00082      *  @param size The size of data.
00083      *
00084      *  @returns
00085      *   The number of written bytes.
00086      */
00087     int write(const char *data, int size);
00088 
00089     /** Send an outgoing ethernet packet.
00090      *
00091      *  After filling in the data in an ethernet packet it must be send.
00092      *  Send will provide a new packet to write to.
00093      *
00094      *  @returns
00095      *    0 if the sending was failed,
00096      *    or the size of the packet successfully sent.
00097      */
00098     int send();
00099 
00100     /** Recevies an arrived ethernet packet.
00101      *
00102      *  Receiving an ethernet packet will drop the last received ethernet packet
00103      *  and make a new ethernet packet ready to read.
00104      *  If no ethernet packet is arrived it will return 0.
00105      *
00106      *  @returns
00107      *    0 if no ethernet packet is arrived,
00108      *    or the size of the arrived packet.
00109      */
00110     int receive();
00111 
00112     /** Read from an recevied ethernet packet.
00113      *
00114      *  After receive returnd a number bigger than 0it is
00115      *  possible to read bytes from this packet.
00116      *  Read will write up to size bytes into data.
00117      *
00118      *  It is possible to use read multible times.
00119      *  Each time read will start reading after the last read byte before.
00120      *
00121      *  @returns
00122      *  The number of byte read.
00123      */
00124     int read(char *data, int size);
00125 
00126     /** Gives the ethernet address of the mbed.
00127      *
00128      *  @param mac Must be a pointer to a 6 byte char array to copy the ethernet address in.
00129      */
00130     void address(char *mac);
00131 
00132     /** Returns if an ethernet link is pressent or not. It takes a wile after Ethernet initializion to show up.
00133      *
00134      *  @returns
00135      *   0 if no ethernet link is pressent,
00136      *   1 if an ethernet link is pressent.
00137      *
00138      * Example:
00139      * @code
00140      * // Using the Ethernet link function
00141      * #include "mbed.h"
00142      *
00143      * Ethernet eth;
00144      *
00145      * int main() {
00146      *     wait(1); // Needed after startup.
00147      *     if (eth.link()) {
00148      *          printf("online\n");
00149      *     } else {
00150      *          printf("offline\n");
00151      *     }
00152      * }
00153      * @endcode
00154      */
00155     int link();
00156 
00157     /** Sets the speed and duplex parameters of an ethernet link
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      *  @param mode the speed and duplex mode to set the link to:
00166      */
00167     void set_link(Mode mode);
00168 };
00169 
00170 } // namespace mbed
00171 
00172 #endif
00173 
00174 #endif
00175 
00176 /** @}*/