Erste version der Software für der Prototyp

Committer:
borlanic
Date:
Fri Mar 30 14:07:05 2018 +0000
Revision:
4:75df35ef4fb6
Parent:
0:380207fcb5c1
commentar

Who changed what in which revision?

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