Programme d'utilisation des AX12 avec rajout de l'MX12

Fork of test_carteAToutFaire_PR by CRAC Team

Committer:
ClementBreteau
Date:
Thu May 11 11:49:50 2017 +0000
Revision:
1:f3f702086a30
test de la carte ? tout faire du petit robot

Who changed what in which revision?

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