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
- Committer:
- moccos
- Date:
- 2012-05-06
- Revision:
- 1:95a4c234aaf6
- Parent:
- 0:b4bf563e9741
- Child:
- 4:7c859e671f9c
File content as of revision 1:95a4c234aaf6:
#ifndef ETHERNET_XPRESSO_H #define ETHERNET_XPRESSO_H #include <stdint.h> #include "LPC1769Emac.h" /** * mbed-like wrapper class for LPCXpresso LPC1769. * @author @moccos */ class EthernetXpresso { public: EthernetXpresso(); virtual ~EthernetXpresso(); // same as mbed enum Mode { AutoNegotiate , HalfDuplex10 , FullDuplex10 , HalfDuplex100 , FullDuplex100 }; /** * Writes into an outgoing ethernet packet. * It will append size bytes of data to the previously written bytes. * * @param data An array to write. * @param size The size of data. * @return The number of written bytes. */ int write(const char *data, int size) { return emac_.Write((void*)data, size); } /** * 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. * * @retval 0 If the sending was failed. * @retval 1 If the package is successfully sent. */ int send() { return emac_.Send() ? 1 : 0; } /** * 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. * * @return The size of the arrived packet. */ int receive() { return emac_.ReadyToReceive(); } /** * Read from an recevied ethernet packet. * * After receive returnd a number bigger than 0, it 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. * * @return The number of byte read. */ int read(char *data, int size) { return emac_.Read((void*)data, size); } /** * Gives the ethernet address. * * @param mac Must be a pointer to a 6 byte char array to copy the ethernet address in. */ void address(char *mac) { emac_.UpdateAddress(mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); } /** * Returns if an ethernet link is pressent or not. It takes a wile after Ethernet initializion to show up. * * @retval 0 If no ethernet link is pressent. * @retval 1 If an ethernet link is pressent. */ int link() { return emac_.Link() ? 1 : 0; } /** * Sets the speed and duplex parameters of an ethernet link * * note: currently auto-neg only * @param mode the speed and duplex mode to set the link to: */ void set_link(Mode mode); /** * Gets the ethernet address. */ const char* getHwAddr() { return emac_.getHwAddr(); } private: LPC1769Emac emac_; private: bool ResetEmac_(); }; #endif