mbed libraries for KL25Z

Dependents:   FRDM_RGBLED

Committer:
emilmont
Date:
Fri Oct 05 09:16:41 2012 +0000
Revision:
0:8024c367e29f
Child:
2:e9a661555b58
First release of the mbed libraries for KL25Z

Who changed what in which revision?

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