Dataloger

Committer:
jhon309
Date:
Thu Aug 20 00:37:14 2015 +0000
Revision:
0:666850d06c9f
ok

Who changed what in which revision?

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