mbed library sources. Supersedes mbed-src.

Fork of mbed-dev by mbed official

Committer:
sivasuren
Date:
Fri Nov 25 07:57:40 2016 +0000
Revision:
150:da61ba4e9755
Parent:
149:156823d33999
surendar changes

Who changed what in which revision?

UserRevisionLine numberNew contents of line
<> 149:156823d33999 1 /* mbed Microcontroller Library
<> 149:156823d33999 2 * Copyright (c) 2006-2013 ARM Limited
<> 149:156823d33999 3 *
<> 149:156823d33999 4 * Licensed under the Apache License, Version 2.0 (the "License");
<> 149:156823d33999 5 * you may not use this file except in compliance with the License.
<> 149:156823d33999 6 * You may obtain a copy of the License at
<> 149:156823d33999 7 *
<> 149:156823d33999 8 * http://www.apache.org/licenses/LICENSE-2.0
<> 149:156823d33999 9 *
<> 149:156823d33999 10 * Unless required by applicable law or agreed to in writing, software
<> 149:156823d33999 11 * distributed under the License is distributed on an "AS IS" BASIS,
<> 149:156823d33999 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<> 149:156823d33999 13 * See the License for the specific language governing permissions and
<> 149:156823d33999 14 * limitations under the License.
<> 149:156823d33999 15 */
<> 149:156823d33999 16 #ifndef MBED_ETHERNET_H
<> 149:156823d33999 17 #define MBED_ETHERNET_H
<> 149:156823d33999 18
<> 149:156823d33999 19 #include "platform/platform.h"
<> 149:156823d33999 20
<> 149:156823d33999 21 #if DEVICE_ETHERNET
<> 149:156823d33999 22
<> 149:156823d33999 23 namespace mbed {
<> 149:156823d33999 24 /** \addtogroup drivers */
<> 149:156823d33999 25 /** @{*/
<> 149:156823d33999 26
<> 149:156823d33999 27 /** An ethernet interface, to use with the ethernet pins.
<> 149:156823d33999 28 *
<> 149:156823d33999 29 * @Note Synchronization level: Not protected
<> 149:156823d33999 30 *
<> 149:156823d33999 31 * Example:
<> 149:156823d33999 32 * @code
<> 149:156823d33999 33 * // Read destination and source from every ethernet packet
<> 149:156823d33999 34 *
<> 149:156823d33999 35 * #include "mbed.h"
<> 149:156823d33999 36 *
<> 149:156823d33999 37 * Ethernet eth;
<> 149:156823d33999 38 *
<> 149:156823d33999 39 * int main() {
<> 149:156823d33999 40 * char buf[0x600];
<> 149:156823d33999 41 *
<> 149:156823d33999 42 * while(1) {
<> 149:156823d33999 43 * int size = eth.receive();
<> 149:156823d33999 44 * if(size > 0) {
<> 149:156823d33999 45 * eth.read(buf, size);
<> 149:156823d33999 46 * printf("Destination: %02X:%02X:%02X:%02X:%02X:%02X\n",
<> 149:156823d33999 47 * buf[0], buf[1], buf[2], buf[3], buf[4], buf[5]);
<> 149:156823d33999 48 * printf("Source: %02X:%02X:%02X:%02X:%02X:%02X\n",
<> 149:156823d33999 49 * buf[6], buf[7], buf[8], buf[9], buf[10], buf[11]);
<> 149:156823d33999 50 * }
<> 149:156823d33999 51 *
<> 149:156823d33999 52 * wait(1);
<> 149:156823d33999 53 * }
<> 149:156823d33999 54 * }
<> 149:156823d33999 55 * @endcode
<> 149:156823d33999 56 */
<> 149:156823d33999 57 class Ethernet {
<> 149:156823d33999 58
<> 149:156823d33999 59 public:
<> 149:156823d33999 60
<> 149:156823d33999 61 /** Initialise the ethernet interface.
<> 149:156823d33999 62 */
<> 149:156823d33999 63 Ethernet();
<> 149:156823d33999 64
<> 149:156823d33999 65 /** Powers the hardware down.
<> 149:156823d33999 66 */
<> 149:156823d33999 67 virtual ~Ethernet();
<> 149:156823d33999 68
<> 149:156823d33999 69 enum Mode {
<> 149:156823d33999 70 AutoNegotiate,
<> 149:156823d33999 71 HalfDuplex10,
<> 149:156823d33999 72 FullDuplex10,
<> 149:156823d33999 73 HalfDuplex100,
<> 149:156823d33999 74 FullDuplex100
<> 149:156823d33999 75 };
<> 149:156823d33999 76
<> 149:156823d33999 77 /** Writes into an outgoing ethernet packet.
<> 149:156823d33999 78 *
<> 149:156823d33999 79 * It will append size bytes of data to the previously written bytes.
<> 149:156823d33999 80 *
<> 149:156823d33999 81 * @param data An array to write.
<> 149:156823d33999 82 * @param size The size of data.
<> 149:156823d33999 83 *
<> 149:156823d33999 84 * @returns
<> 149:156823d33999 85 * The number of written bytes.
<> 149:156823d33999 86 */
<> 149:156823d33999 87 int write(const char *data, int size);
<> 149:156823d33999 88
<> 149:156823d33999 89 /** Send an outgoing ethernet packet.
<> 149:156823d33999 90 *
<> 149:156823d33999 91 * After filling in the data in an ethernet packet it must be send.
<> 149:156823d33999 92 * Send will provide a new packet to write to.
<> 149:156823d33999 93 *
<> 149:156823d33999 94 * @returns
<> 149:156823d33999 95 * 0 if the sending was failed,
<> 149:156823d33999 96 * or the size of the packet successfully sent.
<> 149:156823d33999 97 */
<> 149:156823d33999 98 int send();
<> 149:156823d33999 99
<> 149:156823d33999 100 /** Recevies an arrived ethernet packet.
<> 149:156823d33999 101 *
<> 149:156823d33999 102 * Receiving an ethernet packet will drop the last received ethernet packet
<> 149:156823d33999 103 * and make a new ethernet packet ready to read.
<> 149:156823d33999 104 * If no ethernet packet is arrived it will return 0.
<> 149:156823d33999 105 *
<> 149:156823d33999 106 * @returns
<> 149:156823d33999 107 * 0 if no ethernet packet is arrived,
<> 149:156823d33999 108 * or the size of the arrived packet.
<> 149:156823d33999 109 */
<> 149:156823d33999 110 int receive();
<> 149:156823d33999 111
<> 149:156823d33999 112 /** Read from an recevied ethernet packet.
<> 149:156823d33999 113 *
<> 149:156823d33999 114 * After receive returnd a number bigger than 0it is
<> 149:156823d33999 115 * possible to read bytes from this packet.
<> 149:156823d33999 116 * Read will write up to size bytes into data.
<> 149:156823d33999 117 *
<> 149:156823d33999 118 * It is possible to use read multible times.
<> 149:156823d33999 119 * Each time read will start reading after the last read byte before.
<> 149:156823d33999 120 *
<> 149:156823d33999 121 * @returns
<> 149:156823d33999 122 * The number of byte read.
<> 149:156823d33999 123 */
<> 149:156823d33999 124 int read(char *data, int size);
<> 149:156823d33999 125
<> 149:156823d33999 126 /** Gives the ethernet address of the mbed.
<> 149:156823d33999 127 *
<> 149:156823d33999 128 * @param mac Must be a pointer to a 6 byte char array to copy the ethernet address in.
<> 149:156823d33999 129 */
<> 149:156823d33999 130 void address(char *mac);
<> 149:156823d33999 131
<> 149:156823d33999 132 /** Returns if an ethernet link is pressent or not. It takes a wile after Ethernet initializion to show up.
<> 149:156823d33999 133 *
<> 149:156823d33999 134 * @returns
<> 149:156823d33999 135 * 0 if no ethernet link is pressent,
<> 149:156823d33999 136 * 1 if an ethernet link is pressent.
<> 149:156823d33999 137 *
<> 149:156823d33999 138 * Example:
<> 149:156823d33999 139 * @code
<> 149:156823d33999 140 * // Using the Ethernet link function
<> 149:156823d33999 141 * #include "mbed.h"
<> 149:156823d33999 142 *
<> 149:156823d33999 143 * Ethernet eth;
<> 149:156823d33999 144 *
<> 149:156823d33999 145 * int main() {
<> 149:156823d33999 146 * wait(1); // Needed after startup.
<> 149:156823d33999 147 * if (eth.link()) {
<> 149:156823d33999 148 * printf("online\n");
<> 149:156823d33999 149 * } else {
<> 149:156823d33999 150 * printf("offline\n");
<> 149:156823d33999 151 * }
<> 149:156823d33999 152 * }
<> 149:156823d33999 153 * @endcode
<> 149:156823d33999 154 */
<> 149:156823d33999 155 int link();
<> 149:156823d33999 156
<> 149:156823d33999 157 /** Sets the speed and duplex parameters of an ethernet link
<> 149:156823d33999 158 *
<> 149:156823d33999 159 * - AutoNegotiate Auto negotiate speed and duplex
<> 149:156823d33999 160 * - HalfDuplex10 10 Mbit, half duplex
<> 149:156823d33999 161 * - FullDuplex10 10 Mbit, full duplex
<> 149:156823d33999 162 * - HalfDuplex100 100 Mbit, half duplex
<> 149:156823d33999 163 * - FullDuplex100 100 Mbit, full duplex
<> 149:156823d33999 164 *
<> 149:156823d33999 165 * @param mode the speed and duplex mode to set the link to:
<> 149:156823d33999 166 */
<> 149:156823d33999 167 void set_link(Mode mode);
<> 149:156823d33999 168 };
<> 149:156823d33999 169
<> 149:156823d33999 170 } // namespace mbed
<> 149:156823d33999 171
<> 149:156823d33999 172 #endif
<> 149:156823d33999 173
<> 149:156823d33999 174 #endif
<> 149:156823d33999 175
<> 149:156823d33999 176 /** @}*/