dhgdh

Dependencies:   MAX44000 PWM_Tone_Library nexpaq_mdk

Fork of LED_Demo by joey shelton

Committer:
cyberjoey
Date:
Sat Oct 22 01:31:58 2016 +0000
Revision:
9:6bb35cef007d
Parent:
1:55a6170b404f
WORKING

Who changed what in which revision?

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