Fix RZ/A1H target issues

Fork of mbed-src by mbed official

Committer:
emilmont
Date:
Fri Jun 14 17:49:17 2013 +0100
Revision:
10:3bc89ef62ce7
Parent:
9:0ce32e54c9a7
Child:
13:0645d8841f51
Unify mbed library sources

Who changed what in which revision?

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