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