Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
EthernetXpresso.h@0:b4bf563e9741, 2012-05-06 (annotated)
- Committer:
- moccos
- Date:
- Sun May 06 10:11:53 2012 +0000
- Revision:
- 0:b4bf563e9741
- Child:
- 1:95a4c234aaf6
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
moccos | 0:b4bf563e9741 | 1 | #ifndef ETHERNET_XPRESSO_H |
moccos | 0:b4bf563e9741 | 2 | #define ETHERNET_XPRESSO_H |
moccos | 0:b4bf563e9741 | 3 | #include <stdint.h> |
moccos | 0:b4bf563e9741 | 4 | #include "LPC1769Emac.h" |
moccos | 0:b4bf563e9741 | 5 | |
moccos | 0:b4bf563e9741 | 6 | class EthernetXpresso { |
moccos | 0:b4bf563e9741 | 7 | public: |
moccos | 0:b4bf563e9741 | 8 | EthernetXpresso(); |
moccos | 0:b4bf563e9741 | 9 | virtual ~EthernetXpresso(); |
moccos | 0:b4bf563e9741 | 10 | |
moccos | 0:b4bf563e9741 | 11 | // same as mbed's |
moccos | 0:b4bf563e9741 | 12 | enum Mode { |
moccos | 0:b4bf563e9741 | 13 | AutoNegotiate |
moccos | 0:b4bf563e9741 | 14 | , HalfDuplex10 |
moccos | 0:b4bf563e9741 | 15 | , FullDuplex10 |
moccos | 0:b4bf563e9741 | 16 | , HalfDuplex100 |
moccos | 0:b4bf563e9741 | 17 | , FullDuplex100 |
moccos | 0:b4bf563e9741 | 18 | }; |
moccos | 0:b4bf563e9741 | 19 | /* Function: write |
moccos | 0:b4bf563e9741 | 20 | * Writes into an outgoing ethernet packet. |
moccos | 0:b4bf563e9741 | 21 | * |
moccos | 0:b4bf563e9741 | 22 | * It will append size bytes of data to the previously written bytes. |
moccos | 0:b4bf563e9741 | 23 | * |
moccos | 0:b4bf563e9741 | 24 | * Variables: |
moccos | 0:b4bf563e9741 | 25 | * data - An array to write. |
moccos | 0:b4bf563e9741 | 26 | * size - The size of data. |
moccos | 0:b4bf563e9741 | 27 | * |
moccos | 0:b4bf563e9741 | 28 | * Returns: |
moccos | 0:b4bf563e9741 | 29 | * The number of written bytes. |
moccos | 0:b4bf563e9741 | 30 | */ |
moccos | 0:b4bf563e9741 | 31 | int write(const char *data, int size) { return emac_.Write((void*)data, size); } |
moccos | 0:b4bf563e9741 | 32 | |
moccos | 0:b4bf563e9741 | 33 | /* Function: send |
moccos | 0:b4bf563e9741 | 34 | * Send an outgoing ethernet packet. |
moccos | 0:b4bf563e9741 | 35 | * |
moccos | 0:b4bf563e9741 | 36 | * After filling in the data in an ethernet packet it must be send. |
moccos | 0:b4bf563e9741 | 37 | * Send will provide a new packet to write to. |
moccos | 0:b4bf563e9741 | 38 | * |
moccos | 0:b4bf563e9741 | 39 | * Returns: |
moccos | 0:b4bf563e9741 | 40 | * 0 - If the sending was failed. |
moccos | 0:b4bf563e9741 | 41 | * 1 - If the package is successfully sent. |
moccos | 0:b4bf563e9741 | 42 | */ |
moccos | 0:b4bf563e9741 | 43 | int send() { return emac_.Send() ? 1 : 0; } |
moccos | 0:b4bf563e9741 | 44 | |
moccos | 0:b4bf563e9741 | 45 | /* Function: receive |
moccos | 0:b4bf563e9741 | 46 | * Recevies an arrived ethernet packet. |
moccos | 0:b4bf563e9741 | 47 | * |
moccos | 0:b4bf563e9741 | 48 | * Receiving an ethernet packet will drop the last received ethernet packet |
moccos | 0:b4bf563e9741 | 49 | * and make a new ethernet packet ready to read. |
moccos | 0:b4bf563e9741 | 50 | * If no ethernet packet is arrived it will return 0. |
moccos | 0:b4bf563e9741 | 51 | * |
moccos | 0:b4bf563e9741 | 52 | * Returns: |
moccos | 0:b4bf563e9741 | 53 | * 0 - If no ethernet packet is arrived. |
moccos | 0:b4bf563e9741 | 54 | * The size of the arrived packet. |
moccos | 0:b4bf563e9741 | 55 | */ |
moccos | 0:b4bf563e9741 | 56 | int receive() { return emac_.ReadyToReceive(); } |
moccos | 0:b4bf563e9741 | 57 | |
moccos | 0:b4bf563e9741 | 58 | /* Function: read |
moccos | 0:b4bf563e9741 | 59 | * Read from an recevied ethernet packet. |
moccos | 0:b4bf563e9741 | 60 | * |
moccos | 0:b4bf563e9741 | 61 | * After receive returnd a number bigger than 0it is |
moccos | 0:b4bf563e9741 | 62 | * possible to read bytes from this packet. |
moccos | 0:b4bf563e9741 | 63 | * Read will write up to size bytes into data. |
moccos | 0:b4bf563e9741 | 64 | * |
moccos | 0:b4bf563e9741 | 65 | * It is possible to use read multible times. |
moccos | 0:b4bf563e9741 | 66 | * Each time read will start reading after the last read byte before. |
moccos | 0:b4bf563e9741 | 67 | * |
moccos | 0:b4bf563e9741 | 68 | * Returns: |
moccos | 0:b4bf563e9741 | 69 | * The number of byte read. |
moccos | 0:b4bf563e9741 | 70 | */ |
moccos | 0:b4bf563e9741 | 71 | int read(char *data, int size) { return emac_.Recv((void*)data, size); } |
moccos | 0:b4bf563e9741 | 72 | |
moccos | 0:b4bf563e9741 | 73 | /* Function: address |
moccos | 0:b4bf563e9741 | 74 | * Gives the ethernet address of the mbed. |
moccos | 0:b4bf563e9741 | 75 | * |
moccos | 0:b4bf563e9741 | 76 | * Variables: |
moccos | 0:b4bf563e9741 | 77 | * mac - Must be a pointer to a 6 byte char array to copy the ethernet address in. |
moccos | 0:b4bf563e9741 | 78 | */ |
moccos | 0:b4bf563e9741 | 79 | void address(char *mac) { |
moccos | 0:b4bf563e9741 | 80 | emac_.SetAddress(mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); |
moccos | 0:b4bf563e9741 | 81 | ResetEmac_(); |
moccos | 0:b4bf563e9741 | 82 | } |
moccos | 0:b4bf563e9741 | 83 | |
moccos | 0:b4bf563e9741 | 84 | /* Function: link |
moccos | 0:b4bf563e9741 | 85 | * Returns if an ethernet link is pressent or not. It takes a wile after Ethernet initializion to show up. |
moccos | 0:b4bf563e9741 | 86 | * |
moccos | 0:b4bf563e9741 | 87 | * Returns: |
moccos | 0:b4bf563e9741 | 88 | * 0 - If no ethernet link is pressent. |
moccos | 0:b4bf563e9741 | 89 | * 1 - If an ethernet link is pressent. |
moccos | 0:b4bf563e9741 | 90 | */ |
moccos | 0:b4bf563e9741 | 91 | int link() { return emac_.Link() ? 1 : 0; } |
moccos | 0:b4bf563e9741 | 92 | |
moccos | 0:b4bf563e9741 | 93 | /* Function: set_link |
moccos | 0:b4bf563e9741 | 94 | * Sets the speed and duplex parameters of an ethernet link |
moccos | 0:b4bf563e9741 | 95 | * |
moccos | 0:b4bf563e9741 | 96 | * Variables: |
moccos | 0:b4bf563e9741 | 97 | * mode - the speed and duplex mode to set the link to: |
moccos | 0:b4bf563e9741 | 98 | */ |
moccos | 0:b4bf563e9741 | 99 | // currently auto-neg only |
moccos | 0:b4bf563e9741 | 100 | void set_link(Mode mode); |
moccos | 0:b4bf563e9741 | 101 | |
moccos | 0:b4bf563e9741 | 102 | const char* getHwAddr() { return emac_.getHwAddr(); } |
moccos | 0:b4bf563e9741 | 103 | |
moccos | 0:b4bf563e9741 | 104 | private: |
moccos | 0:b4bf563e9741 | 105 | LPC1769Emac emac_; |
moccos | 0:b4bf563e9741 | 106 | |
moccos | 0:b4bf563e9741 | 107 | private: |
moccos | 0:b4bf563e9741 | 108 | bool ResetEmac_(); |
moccos | 0:b4bf563e9741 | 109 | }; |
moccos | 0:b4bf563e9741 | 110 | |
moccos | 0:b4bf563e9741 | 111 | #endif |