IOTIO

Dependencies:   Nucleo_BLE_API_IOTIO Nucleo_BLE_BlueNRG Nucleo_BLE_DemoApp Nucleo_Sensor_Shield mbed

Dependents:   Nucleo_BLE_Demo_IOTIO

Fork of Nucleo_BLE_Demo by Cortex Challenge Team

Committer:
16038618
Date:
Wed Mar 08 10:24:56 2017 +0000
Revision:
2:c69117fc79da
Parent:
1:4bdfa7d7e8bf
IOTIO

Who changed what in which revision?

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