Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of mbed-src by
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.h" 00020 00021 #if DEVICE_ETHERNET 00022 00023 namespace mbed { 00024 00025 /** An ethernet interface, to use with the ethernet pins. 00026 * 00027 * Example: 00028 * @code 00029 * // Read destination and source from every ethernet packet 00030 * 00031 * #include "mbed.h" 00032 * 00033 * Ethernet eth; 00034 * 00035 * int main() { 00036 * char buf[0x600]; 00037 * 00038 * while(1) { 00039 * int size = eth.receive(); 00040 * if(size > 0) { 00041 * eth.read(buf, size); 00042 * printf("Destination: %02X:%02X:%02X:%02X:%02X:%02X\n", 00043 * buf[0], buf[1], buf[2], buf[3], buf[4], buf[5]); 00044 * printf("Source: %02X:%02X:%02X:%02X:%02X:%02X\n", 00045 * buf[6], buf[7], buf[8], buf[9], buf[10], buf[11]); 00046 * } 00047 * 00048 * wait(1); 00049 * } 00050 * } 00051 * @endcode 00052 */ 00053 class Ethernet { 00054 00055 public: 00056 00057 /** Initialise the ethernet interface. 00058 */ 00059 Ethernet(); 00060 00061 /** Powers the hardware down. 00062 */ 00063 virtual ~Ethernet(); 00064 00065 enum Mode { 00066 AutoNegotiate, 00067 HalfDuplex10, 00068 FullDuplex10, 00069 HalfDuplex100, 00070 FullDuplex100 00071 }; 00072 00073 /** Writes into an outgoing ethernet packet. 00074 * 00075 * It will append size bytes of data to the previously written bytes. 00076 * 00077 * @param data An array to write. 00078 * @param size The size of data. 00079 * 00080 * @returns 00081 * The number of written bytes. 00082 */ 00083 int write(const char *data, int size); 00084 00085 /** Send an outgoing ethernet packet. 00086 * 00087 * After filling in the data in an ethernet packet it must be send. 00088 * Send will provide a new packet to write to. 00089 * 00090 * @returns 00091 * 0 if the sending was failed, 00092 * or the size of the packet successfully sent. 00093 */ 00094 int send(); 00095 00096 /** Recevies an arrived ethernet packet. 00097 * 00098 * Receiving an ethernet packet will drop the last received ethernet packet 00099 * and make a new ethernet packet ready to read. 00100 * If no ethernet packet is arrived it will return 0. 00101 * 00102 * @returns 00103 * 0 if no ethernet packet is arrived, 00104 * or the size of the arrived packet. 00105 */ 00106 int receive(); 00107 00108 /** Read from an recevied ethernet packet. 00109 * 00110 * After receive returnd a number bigger than 0it is 00111 * possible to read bytes from this packet. 00112 * Read will write up to size bytes into data. 00113 * 00114 * It is possible to use read multible times. 00115 * Each time read will start reading after the last read byte before. 00116 * 00117 * @returns 00118 * The number of byte read. 00119 */ 00120 int read(char *data, int size); 00121 00122 /** Gives the ethernet address of the mbed. 00123 * 00124 * @param 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 /** Returns if an ethernet link is pressent or not. It takes a wile after Ethernet initializion to show up. 00129 * 00130 * @returns 00131 * 0 if no ethernet link is pressent, 00132 * 1 if an ethernet link is pressent. 00133 * 00134 * Example: 00135 * @code 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 * @endcode 00150 */ 00151 int link(); 00152 00153 /** Sets the speed and duplex parameters of an ethernet link 00154 * 00155 * - AutoNegotiate Auto negotiate speed and duplex 00156 * - HalfDuplex10 10 Mbit, half duplex 00157 * - FullDuplex10 10 Mbit, full duplex 00158 * - HalfDuplex100 100 Mbit, half duplex 00159 * - FullDuplex100 100 Mbit, full duplex 00160 * 00161 * @param mode the speed and duplex mode to set the link to: 00162 */ 00163 void set_link(Mode mode); 00164 }; 00165 00166 } // namespace mbed 00167 00168 #endif 00169 00170 #endif
Generated on Tue Jul 12 2022 21:21:33 by
