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