5.2.1 - Updated I2C files

Dependents:   mbed-TFT-example-NCS36510 mbed-Accelerometer-example-NCS36510 mbed-Accelerometer-example-NCS36510

Committer:
group-onsemi
Date:
Wed Jan 25 20:34:15 2017 +0000
Revision:
0:098463de4c5d
Initial commit

Who changed what in which revision?

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