DHT11

Committer:
jhon309
Date:
Thu Aug 13 00:21:57 2015 +0000
Revision:
0:c52df770855b
DHT11

Who changed what in which revision?

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