moccos mizuki / EthernetXpresso

Dependents:   XNetServicesMin

Revision:
0:b4bf563e9741
Child:
1:95a4c234aaf6
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/EthernetXpresso.h	Sun May 06 10:11:53 2012 +0000
@@ -0,0 +1,111 @@
+#ifndef ETHERNET_XPRESSO_H
+#define ETHERNET_XPRESSO_H
+#include <stdint.h>
+#include "LPC1769Emac.h"
+
+class EthernetXpresso {
+public:
+    EthernetXpresso();
+    virtual ~EthernetXpresso();
+
+    // same as mbed's
+    enum Mode {
+        AutoNegotiate
+        , HalfDuplex10
+        , FullDuplex10
+        , HalfDuplex100
+        , FullDuplex100
+    };
+    /* Function: write
+     *  Writes into an outgoing ethernet packet.
+     *
+     *  It will append size bytes of data to the previously written bytes.
+     *
+     *  Variables:
+     *   data - An array to write.
+     *   size - The size of data.
+     *
+     *  Returns:
+     *   The number of written bytes.
+     */
+    int write(const char *data, int size) { return emac_.Write((void*)data, size); }
+
+    /* Function: send
+     *  Send an outgoing ethernet packet.
+     *
+     *  After filling in the data in an ethernet packet it must be send.
+     *  Send will provide a new packet to write to.
+     *
+     * Returns:
+     *  0 - If the sending was failed.
+     *  1 - If the package is successfully sent.
+     */
+    int send() { return emac_.Send() ? 1 : 0; }
+
+    /* Function: receive
+     *  Recevies an arrived ethernet packet.
+     *
+     *  Receiving an ethernet packet will drop the last received ethernet packet
+     *  and make a new ethernet packet ready to read.
+     *  If no ethernet packet is arrived it will return 0.
+     *
+     * Returns:
+     *  0 - If no ethernet packet is arrived.
+     *  The size of the arrived packet.
+     */
+    int receive() { return emac_.ReadyToReceive(); }
+
+    /* Function: read
+     *  Read from an recevied ethernet packet.
+     *
+     *  After receive returnd a number bigger than 0it is
+     *  possible to read bytes from this packet.
+     *  Read will write up to size bytes into data.
+     *
+     *  It is possible to use read multible times.
+     *  Each time read will start reading after the last read byte before.
+     *
+     * Returns:
+     *  The number of byte read.
+     */
+    int read(char *data, int size) { return emac_.Recv((void*)data, size); }
+
+    /* Function: address
+     *  Gives the ethernet address of the mbed.
+     *
+     * Variables:
+     *  mac - Must be a pointer to a 6 byte char array to copy the ethernet address in.
+     */
+    void address(char *mac) {
+        emac_.SetAddress(mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
+        ResetEmac_();
+    }
+
+    /* Function: link
+     *  Returns if an ethernet link is pressent or not. It takes a wile after Ethernet initializion to show up.
+     *
+     * Returns:
+     *  0 - If no ethernet link is pressent.
+     *  1 - If an ethernet link is pressent.
+     */
+    int link() { return emac_.Link() ? 1 : 0; }
+
+    /* Function: set_link
+     *  Sets the speed and duplex parameters of an ethernet link
+     *
+     *  Variables:
+     *   mode - the speed and duplex mode to set the link to:
+     */
+     // currently auto-neg only
+    void set_link(Mode mode);
+    
+    const char* getHwAddr() { return emac_.getHwAddr(); }
+
+private:
+    LPC1769Emac emac_;
+
+private:
+    bool ResetEmac_();
+};
+
+#endif
\ No newline at end of file