help :(

Dependencies:   FFT

Committer:
dimitryjl23
Date:
Fri Dec 04 18:01:22 2020 +0000
Revision:
11:951bbb0385aa
Parent:
0:d6c9b09b4042
Final :)

Who changed what in which revision?

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