The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.

Dependents:   hello SerialTestv11 SerialTestv12 Sierpinski ... more

mbed 2

This is the mbed 2 library. If you'd like to learn about Mbed OS please see the mbed-os docs.

Committer:
<>
Date:
Mon Jan 16 12:05:23 2017 +0000
Revision:
134:ad3be0349dc5
Parent:
128:9bcdf88f62b0
Child:
145:64910690c574
Release 134 of the mbed library

Ports for Upcoming Targets


Fixes and Changes

3488: Dev stm i2c v2 unitary functions https://github.com/ARMmbed/mbed-os/pull/3488
3492: Fix #3463 CAN read() return value https://github.com/ARMmbed/mbed-os/pull/3492
3503: [LPC15xx] Ensure that PWM=1 is resolved correctly https://github.com/ARMmbed/mbed-os/pull/3503
3504: [LPC15xx] CAN implementation improvements https://github.com/ARMmbed/mbed-os/pull/3504
3539: NUCLEO_F412ZG - Add support of TRNG peripheral https://github.com/ARMmbed/mbed-os/pull/3539
3540: STM: SPI: Initialize Rx in spi_master_write https://github.com/ARMmbed/mbed-os/pull/3540
3438: K64F: Add support for SERIAL ASYNCH API https://github.com/ARMmbed/mbed-os/pull/3438
3519: MCUXpresso: Fix ENET driver to enable interrupts after interrupt handler is set https://github.com/ARMmbed/mbed-os/pull/3519
3544: STM32L4 deepsleep improvement https://github.com/ARMmbed/mbed-os/pull/3544
3546: NUCLEO-F412ZG - Add CAN peripheral https://github.com/ARMmbed/mbed-os/pull/3546
3551: Fix I2C driver for RZ/A1H https://github.com/ARMmbed/mbed-os/pull/3551
3558: K64F UART Asynch API: Fix synchronization issue https://github.com/ARMmbed/mbed-os/pull/3558
3563: LPC4088 - Fix vector checksum https://github.com/ARMmbed/mbed-os/pull/3563
3567: Dev stm32 F0 v1.7.0 https://github.com/ARMmbed/mbed-os/pull/3567
3577: Fixes linking errors when building with debug profile https://github.com/ARMmbed/mbed-os/pull/3577

Who changed what in which revision?

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