Initial commit

Dependencies:   FastPWM

Committer:
lypinator
Date:
Wed Sep 16 01:11:49 2020 +0000
Revision:
0:bb348c97df44
Added PWM

Who changed what in which revision?

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