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