Home Alert System

Dependencies:   PWM_Tone_Library DHT

Committer:
aziz111
Date:
Fri Mar 08 17:15:02 2019 +0000
Revision:
5:569a4894abc1
Parent:
3:78f223d34f36
Final

Who changed what in which revision?

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