moccos mizuki / EthernetXpresso

Dependents:   XNetServicesMin

Committer:
moccos
Date:
Sun May 06 10:52:06 2012 +0000
Revision:
1:95a4c234aaf6
Parent:
0:b4bf563e9741
Child:
4:7c859e671f9c

        

Who changed what in which revision?

UserRevisionLine numberNew 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 1:95a4c234aaf6 6 /**
moccos 1:95a4c234aaf6 7 * mbed-like wrapper class for LPCXpresso LPC1769.
moccos 1:95a4c234aaf6 8 * @author @moccos
moccos 1:95a4c234aaf6 9 */
moccos 0:b4bf563e9741 10 class EthernetXpresso {
moccos 0:b4bf563e9741 11 public:
moccos 0:b4bf563e9741 12 EthernetXpresso();
moccos 0:b4bf563e9741 13 virtual ~EthernetXpresso();
moccos 0:b4bf563e9741 14
moccos 1:95a4c234aaf6 15 // same as mbed
moccos 0:b4bf563e9741 16 enum Mode {
moccos 0:b4bf563e9741 17 AutoNegotiate
moccos 0:b4bf563e9741 18 , HalfDuplex10
moccos 0:b4bf563e9741 19 , FullDuplex10
moccos 0:b4bf563e9741 20 , HalfDuplex100
moccos 0:b4bf563e9741 21 , FullDuplex100
moccos 0:b4bf563e9741 22 };
moccos 1:95a4c234aaf6 23 /**
moccos 0:b4bf563e9741 24 * Writes into an outgoing ethernet packet.
moccos 0:b4bf563e9741 25 * It will append size bytes of data to the previously written bytes.
moccos 0:b4bf563e9741 26 *
moccos 1:95a4c234aaf6 27 * @param data An array to write.
moccos 1:95a4c234aaf6 28 * @param size The size of data.
moccos 1:95a4c234aaf6 29 * @return 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 1:95a4c234aaf6 33 /**
moccos 0:b4bf563e9741 34 * Send an outgoing ethernet packet.
moccos 0:b4bf563e9741 35 * After filling in the data in an ethernet packet it must be send.
moccos 0:b4bf563e9741 36 * Send will provide a new packet to write to.
moccos 0:b4bf563e9741 37 *
moccos 1:95a4c234aaf6 38 * @retval 0 If the sending was failed.
moccos 1:95a4c234aaf6 39 * @retval 1 If the package is successfully sent.
moccos 0:b4bf563e9741 40 */
moccos 0:b4bf563e9741 41 int send() { return emac_.Send() ? 1 : 0; }
moccos 0:b4bf563e9741 42
moccos 1:95a4c234aaf6 43 /**
moccos 0:b4bf563e9741 44 * Recevies an arrived ethernet packet.
moccos 0:b4bf563e9741 45 *
moccos 0:b4bf563e9741 46 * Receiving an ethernet packet will drop the last received ethernet packet
moccos 0:b4bf563e9741 47 * and make a new ethernet packet ready to read.
moccos 0:b4bf563e9741 48 * If no ethernet packet is arrived it will return 0.
moccos 0:b4bf563e9741 49 *
moccos 1:95a4c234aaf6 50 * @return The size of the arrived packet.
moccos 0:b4bf563e9741 51 */
moccos 0:b4bf563e9741 52 int receive() { return emac_.ReadyToReceive(); }
moccos 0:b4bf563e9741 53
moccos 1:95a4c234aaf6 54 /**
moccos 0:b4bf563e9741 55 * Read from an recevied ethernet packet.
moccos 0:b4bf563e9741 56 *
moccos 1:95a4c234aaf6 57 * After receive returnd a number bigger than 0, it is
moccos 0:b4bf563e9741 58 * possible to read bytes from this packet.
moccos 0:b4bf563e9741 59 * Read will write up to size bytes into data.
moccos 0:b4bf563e9741 60 *
moccos 0:b4bf563e9741 61 * It is possible to use read multible times.
moccos 0:b4bf563e9741 62 * Each time read will start reading after the last read byte before.
moccos 0:b4bf563e9741 63 *
moccos 1:95a4c234aaf6 64 * @return The number of byte read.
moccos 0:b4bf563e9741 65 */
moccos 1:95a4c234aaf6 66 int read(char *data, int size) { return emac_.Read((void*)data, size); }
moccos 0:b4bf563e9741 67
moccos 1:95a4c234aaf6 68 /**
moccos 1:95a4c234aaf6 69 * Gives the ethernet address.
moccos 0:b4bf563e9741 70 *
moccos 1:95a4c234aaf6 71 * @param mac Must be a pointer to a 6 byte char array to copy the ethernet address in.
moccos 0:b4bf563e9741 72 */
moccos 0:b4bf563e9741 73 void address(char *mac) {
moccos 1:95a4c234aaf6 74 emac_.UpdateAddress(mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
moccos 0:b4bf563e9741 75 }
moccos 0:b4bf563e9741 76
moccos 1:95a4c234aaf6 77 /**
moccos 0:b4bf563e9741 78 * Returns if an ethernet link is pressent or not. It takes a wile after Ethernet initializion to show up.
moccos 0:b4bf563e9741 79 *
moccos 1:95a4c234aaf6 80 * @retval 0 If no ethernet link is pressent.
moccos 1:95a4c234aaf6 81 * @retval 1 If an ethernet link is pressent.
moccos 0:b4bf563e9741 82 */
moccos 0:b4bf563e9741 83 int link() { return emac_.Link() ? 1 : 0; }
moccos 0:b4bf563e9741 84
moccos 1:95a4c234aaf6 85 /**
moccos 0:b4bf563e9741 86 * Sets the speed and duplex parameters of an ethernet link
moccos 0:b4bf563e9741 87 *
moccos 1:95a4c234aaf6 88 * note: currently auto-neg only
moccos 1:95a4c234aaf6 89 * @param mode the speed and duplex mode to set the link to:
moccos 0:b4bf563e9741 90 */
moccos 0:b4bf563e9741 91 void set_link(Mode mode);
moccos 0:b4bf563e9741 92
moccos 1:95a4c234aaf6 93 /**
moccos 1:95a4c234aaf6 94 * Gets the ethernet address.
moccos 1:95a4c234aaf6 95 */
moccos 0:b4bf563e9741 96 const char* getHwAddr() { return emac_.getHwAddr(); }
moccos 0:b4bf563e9741 97
moccos 0:b4bf563e9741 98 private:
moccos 0:b4bf563e9741 99 LPC1769Emac emac_;
moccos 0:b4bf563e9741 100
moccos 0:b4bf563e9741 101 private:
moccos 0:b4bf563e9741 102 bool ResetEmac_();
moccos 0:b4bf563e9741 103 };
moccos 0:b4bf563e9741 104
moccos 0:b4bf563e9741 105 #endif