mbed library sources for TON Board V1.2

Fork of mbed-dev by mbed official

Committer:
AnnaBridge
Date:
Wed Jun 21 17:46:44 2017 +0100
Revision:
167:e84263d55307
Parent:
149:156823d33999
This updates the lib to the mbed lib v 145

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
AnnaBridge 167:e84263d55307 21 #if defined (DEVICE_ETHERNET) || defined(DOXYGEN_ONLY)
<> 149:156823d33999 22
<> 149:156823d33999 23 namespace mbed {
<> 149:156823d33999 24 /** \addtogroup drivers */
<> 149:156823d33999 25
<> 149:156823d33999 26 /** An ethernet interface, to use with the ethernet pins.
<> 149:156823d33999 27 *
AnnaBridge 167:e84263d55307 28 * @note Synchronization level: Not protected
<> 149:156823d33999 29 *
<> 149:156823d33999 30 * Example:
<> 149:156823d33999 31 * @code
<> 149:156823d33999 32 * // Read destination and source from every ethernet packet
<> 149:156823d33999 33 *
<> 149:156823d33999 34 * #include "mbed.h"
<> 149:156823d33999 35 *
<> 149:156823d33999 36 * Ethernet eth;
<> 149:156823d33999 37 *
<> 149:156823d33999 38 * int main() {
<> 149:156823d33999 39 * char buf[0x600];
<> 149:156823d33999 40 *
<> 149:156823d33999 41 * while(1) {
<> 149:156823d33999 42 * int size = eth.receive();
<> 149:156823d33999 43 * if(size > 0) {
<> 149:156823d33999 44 * eth.read(buf, size);
<> 149:156823d33999 45 * printf("Destination: %02X:%02X:%02X:%02X:%02X:%02X\n",
<> 149:156823d33999 46 * buf[0], buf[1], buf[2], buf[3], buf[4], buf[5]);
<> 149:156823d33999 47 * printf("Source: %02X:%02X:%02X:%02X:%02X:%02X\n",
<> 149:156823d33999 48 * buf[6], buf[7], buf[8], buf[9], buf[10], buf[11]);
<> 149:156823d33999 49 * }
<> 149:156823d33999 50 *
<> 149:156823d33999 51 * wait(1);
<> 149:156823d33999 52 * }
<> 149:156823d33999 53 * }
<> 149:156823d33999 54 * @endcode
AnnaBridge 167:e84263d55307 55 * @ingroup drivers
<> 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 *
AnnaBridge 167:e84263d55307 114 * After receive returned a number bigger than 0 it is
<> 149:156823d33999 115 * possible to read bytes from this packet.
<> 149:156823d33999 116 *
AnnaBridge 167:e84263d55307 117 * @param data Pointer to data packet
AnnaBridge 167:e84263d55307 118 * @param size Size of data to be read.
AnnaBridge 167:e84263d55307 119 * @returns The number of byte read.
AnnaBridge 167:e84263d55307 120 *
AnnaBridge 167:e84263d55307 121 * @note It is possible to use read multiple times.
<> 149:156823d33999 122 * Each time read will start reading after the last read byte before.
<> 149:156823d33999 123 *
<> 149:156823d33999 124 */
<> 149:156823d33999 125 int read(char *data, int size);
<> 149:156823d33999 126
<> 149:156823d33999 127 /** Gives the ethernet address of the mbed.
<> 149:156823d33999 128 *
<> 149:156823d33999 129 * @param mac Must be a pointer to a 6 byte char array to copy the ethernet address in.
<> 149:156823d33999 130 */
<> 149:156823d33999 131 void address(char *mac);
<> 149:156823d33999 132
<> 149:156823d33999 133 /** Returns if an ethernet link is pressent or not. It takes a wile after Ethernet initializion to show up.
<> 149:156823d33999 134 *
<> 149:156823d33999 135 * @returns
<> 149:156823d33999 136 * 0 if no ethernet link is pressent,
<> 149:156823d33999 137 * 1 if an ethernet link is pressent.
<> 149:156823d33999 138 *
<> 149:156823d33999 139 * Example:
<> 149:156823d33999 140 * @code
<> 149:156823d33999 141 * // Using the Ethernet link function
<> 149:156823d33999 142 * #include "mbed.h"
<> 149:156823d33999 143 *
<> 149:156823d33999 144 * Ethernet eth;
<> 149:156823d33999 145 *
<> 149:156823d33999 146 * int main() {
<> 149:156823d33999 147 * wait(1); // Needed after startup.
<> 149:156823d33999 148 * if (eth.link()) {
<> 149:156823d33999 149 * printf("online\n");
<> 149:156823d33999 150 * } else {
<> 149:156823d33999 151 * printf("offline\n");
<> 149:156823d33999 152 * }
<> 149:156823d33999 153 * }
<> 149:156823d33999 154 * @endcode
<> 149:156823d33999 155 */
<> 149:156823d33999 156 int link();
<> 149:156823d33999 157
<> 149:156823d33999 158 /** Sets the speed and duplex parameters of an ethernet link
<> 149:156823d33999 159 *
<> 149:156823d33999 160 * - AutoNegotiate Auto negotiate speed and duplex
<> 149:156823d33999 161 * - HalfDuplex10 10 Mbit, half duplex
<> 149:156823d33999 162 * - FullDuplex10 10 Mbit, full duplex
<> 149:156823d33999 163 * - HalfDuplex100 100 Mbit, half duplex
<> 149:156823d33999 164 * - FullDuplex100 100 Mbit, full duplex
<> 149:156823d33999 165 *
<> 149:156823d33999 166 * @param mode the speed and duplex mode to set the link to:
<> 149:156823d33999 167 */
<> 149:156823d33999 168 void set_link(Mode mode);
<> 149:156823d33999 169 };
<> 149:156823d33999 170
<> 149:156823d33999 171 } // namespace mbed
<> 149:156823d33999 172
<> 149:156823d33999 173 #endif
<> 149:156823d33999 174
<> 149:156823d33999 175 #endif