I2C_EEPROM

Committer:
jhon309
Date:
Thu Aug 13 00:23:16 2015 +0000
Revision:
0:ac8863619623
I2C

Who changed what in which revision?

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