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