mbed library sources. Supersedes mbed-src.

Dependents:   Nucleo_Hello_Encoder BLE_iBeaconScan AM1805_DEMO DISCO-F429ZI_ExportTemplate1 ... more

Committer:
AnnaBridge
Date:
Wed Feb 20 22:31:08 2019 +0000
Revision:
189:f392fc9709a3
Parent:
188:bcfe06ba3d64
mbed library release version 165

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