...

Dependents:   2doejemplo Labo_TRSE_Drone

Fork of mbed by mbed official

Committer:
emilmont
Date:
Fri Oct 26 17:40:46 2012 +0100
Revision:
43:e2ed12d17f06
Parent:
27:7110ebee3484
Child:
44:24d45a770a51
Update documentation

Who changed what in which revision?

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