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