test

Dependents:   robotic_fish_6

Committer:
juansal12
Date:
Fri Dec 03 23:00:34 2021 +0000
Revision:
0:c792b17d9f78
uploaded sofi code ;

Who changed what in which revision?

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