temp

Dependencies:   mbed SDFileSystem MS5607 ADXL345_I2C FATFileSystem

Committer:
IKobayashi
Date:
Mon Mar 16 23:37:42 2020 +0900
Revision:
0:c88c3b616c00
copy

Who changed what in which revision?

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