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.
LPC1769Emac.h@3:7ba8ebe32420, 2012-05-06 (annotated)
- Committer:
- moccos
- Date:
- Sun May 06 11:14:17 2012 +0000
- Revision:
- 3:7ba8ebe32420
- Parent:
- 1:95a4c234aaf6
- Child:
- 4:7c859e671f9c
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
moccos | 0:b4bf563e9741 | 1 | #ifndef LPC1769EMAC_H |
moccos | 0:b4bf563e9741 | 2 | #define LPC1769EMAC_H |
moccos | 0:b4bf563e9741 | 3 | #include <stdint.h> |
moccos | 0:b4bf563e9741 | 4 | #include "Frame.h" |
moccos | 0:b4bf563e9741 | 5 | |
moccos | 1:95a4c234aaf6 | 6 | /** |
moccos | 1:95a4c234aaf6 | 7 | * LPCXpresso LPC1769 ethernet library. |
moccos | 1:95a4c234aaf6 | 8 | * @author @moccos |
moccos | 1:95a4c234aaf6 | 9 | */ |
moccos | 0:b4bf563e9741 | 10 | class LPC1769Emac { |
moccos | 0:b4bf563e9741 | 11 | public: |
moccos | 1:95a4c234aaf6 | 12 | // same as mbed |
moccos | 0:b4bf563e9741 | 13 | enum LinkMode { |
moccos | 0:b4bf563e9741 | 14 | AutoNegotiate, |
moccos | 0:b4bf563e9741 | 15 | HalfDuplex10, |
moccos | 0:b4bf563e9741 | 16 | FullDuplex10, |
moccos | 0:b4bf563e9741 | 17 | HalfDuplex100, |
moccos | 0:b4bf563e9741 | 18 | FullDuplex100 |
moccos | 0:b4bf563e9741 | 19 | }; |
moccos | 0:b4bf563e9741 | 20 | |
moccos | 0:b4bf563e9741 | 21 | public: |
moccos | 1:95a4c234aaf6 | 22 | /** |
moccos | 1:95a4c234aaf6 | 23 | * Enable LPC1769 ethernet block. |
moccos | 1:95a4c234aaf6 | 24 | */ |
moccos | 0:b4bf563e9741 | 25 | LPC1769Emac(); |
moccos | 1:95a4c234aaf6 | 26 | |
moccos | 1:95a4c234aaf6 | 27 | /** |
moccos | 1:95a4c234aaf6 | 28 | * Disable LPC1769 ethernet block. |
moccos | 1:95a4c234aaf6 | 29 | */ |
moccos | 0:b4bf563e9741 | 30 | ~LPC1769Emac(); |
moccos | 1:95a4c234aaf6 | 31 | |
moccos | 1:95a4c234aaf6 | 32 | /** |
moccos | 1:95a4c234aaf6 | 33 | * Write 16-bit value to PHY register. |
moccos | 1:95a4c234aaf6 | 34 | * @param reg register index. See LAN8710AReg.h. |
moccos | 1:95a4c234aaf6 | 35 | * @param value |
moccos | 1:95a4c234aaf6 | 36 | */ |
moccos | 0:b4bf563e9741 | 37 | bool PhyWrite(uint8_t reg, uint16_t value); |
moccos | 1:95a4c234aaf6 | 38 | |
moccos | 1:95a4c234aaf6 | 39 | /** |
moccos | 1:95a4c234aaf6 | 40 | * Read 16-bit value from PHY register. |
moccos | 1:95a4c234aaf6 | 41 | * @param reg register index. See LAN8710AReg.h. |
moccos | 1:95a4c234aaf6 | 42 | */ |
moccos | 1:95a4c234aaf6 | 43 | uint16_t PhyRead(uint8_t reg); |
moccos | 1:95a4c234aaf6 | 44 | |
moccos | 1:95a4c234aaf6 | 45 | /** |
moccos | 1:95a4c234aaf6 | 46 | * Set ethernet address before initialization for debug. |
moccos | 1:95a4c234aaf6 | 47 | */ |
moccos | 0:b4bf563e9741 | 48 | static void SetAddress(uint8_t a5, uint8_t a4, uint8_t a3, uint8_t a2, uint8_t a1, uint8_t a0); |
moccos | 1:95a4c234aaf6 | 49 | |
moccos | 1:95a4c234aaf6 | 50 | /** |
moccos | 1:95a4c234aaf6 | 51 | * Update ethernet address. |
moccos | 1:95a4c234aaf6 | 52 | */ |
moccos | 1:95a4c234aaf6 | 53 | void UpdateAddress(uint8_t a5, uint8_t a4, uint8_t a3, uint8_t a2, uint8_t a1, uint8_t a0); |
moccos | 1:95a4c234aaf6 | 54 | |
moccos | 1:95a4c234aaf6 | 55 | /** |
moccos | 1:95a4c234aaf6 | 56 | * Enable RX flags. |
moccos | 1:95a4c234aaf6 | 57 | */ |
moccos | 0:b4bf563e9741 | 58 | void StartRx(); |
moccos | 1:95a4c234aaf6 | 59 | |
moccos | 1:95a4c234aaf6 | 60 | /** |
moccos | 1:95a4c234aaf6 | 61 | * Enable TX flags. |
moccos | 1:95a4c234aaf6 | 62 | */ |
moccos | 0:b4bf563e9741 | 63 | void StartTx(); |
moccos | 1:95a4c234aaf6 | 64 | |
moccos | 1:95a4c234aaf6 | 65 | /** |
moccos | 1:95a4c234aaf6 | 66 | * Disable RX flags. |
moccos | 1:95a4c234aaf6 | 67 | */ |
moccos | 0:b4bf563e9741 | 68 | void StopRx(); |
moccos | 1:95a4c234aaf6 | 69 | |
moccos | 1:95a4c234aaf6 | 70 | /** |
moccos | 1:95a4c234aaf6 | 71 | * Disable TX flags. |
moccos | 1:95a4c234aaf6 | 72 | */ |
moccos | 0:b4bf563e9741 | 73 | void StopTx(); |
moccos | 1:95a4c234aaf6 | 74 | |
moccos | 1:95a4c234aaf6 | 75 | /** |
moccos | 1:95a4c234aaf6 | 76 | * Check link status. |
moccos | 1:95a4c234aaf6 | 77 | * @return true if the link is up |
moccos | 1:95a4c234aaf6 | 78 | */ |
moccos | 0:b4bf563e9741 | 79 | bool Link(); |
moccos | 1:95a4c234aaf6 | 80 | |
moccos | 1:95a4c234aaf6 | 81 | /** |
moccos | 1:95a4c234aaf6 | 82 | * Read data from received packet. |
moccos | 1:95a4c234aaf6 | 83 | * @param buf destination buffer |
moccos | 1:95a4c234aaf6 | 84 | * @param max_size |
moccos | 1:95a4c234aaf6 | 85 | */ |
moccos | 1:95a4c234aaf6 | 86 | uint16_t Read(void *buf, uint16_t max_size); |
moccos | 1:95a4c234aaf6 | 87 | |
moccos | 1:95a4c234aaf6 | 88 | /** |
moccos | 1:95a4c234aaf6 | 89 | * Check received packet. |
moccos | 1:95a4c234aaf6 | 90 | * @return The size of readabe data |
moccos | 1:95a4c234aaf6 | 91 | */ |
moccos | 0:b4bf563e9741 | 92 | uint16_t ReadyToReceive(); |
moccos | 1:95a4c234aaf6 | 93 | |
moccos | 1:95a4c234aaf6 | 94 | /** |
moccos | 1:95a4c234aaf6 | 95 | * Write data to the TX buffer. |
moccos | 1:95a4c234aaf6 | 96 | * @param buf data |
moccos | 1:95a4c234aaf6 | 97 | * @size |
moccos | 1:95a4c234aaf6 | 98 | */ |
moccos | 0:b4bf563e9741 | 99 | uint16_t Write(void *buf, uint16_t size); |
moccos | 1:95a4c234aaf6 | 100 | |
moccos | 1:95a4c234aaf6 | 101 | /** |
moccos | 1:95a4c234aaf6 | 102 | * Send data from the TX buffer to the network. |
moccos | 1:95a4c234aaf6 | 103 | */ |
moccos | 0:b4bf563e9741 | 104 | bool Send(); |
moccos | 1:95a4c234aaf6 | 105 | |
moccos | 1:95a4c234aaf6 | 106 | /** |
moccos | 1:95a4c234aaf6 | 107 | * Send data from the user buffer to the network. |
moccos | 1:95a4c234aaf6 | 108 | * Current TX buffer is overwritten. |
moccos | 1:95a4c234aaf6 | 109 | * @param buf data |
moccos | 1:95a4c234aaf6 | 110 | * @size |
moccos | 1:95a4c234aaf6 | 111 | */ |
moccos | 0:b4bf563e9741 | 112 | bool Send(void *buf, uint16_t size); |
moccos | 1:95a4c234aaf6 | 113 | |
moccos | 1:95a4c234aaf6 | 114 | /** |
moccos | 1:95a4c234aaf6 | 115 | * Reset ethernet registers and PHY registers. |
moccos | 1:95a4c234aaf6 | 116 | * @param Linkmode select auto-negotiation or fixed link speed and duplex |
moccos | 1:95a4c234aaf6 | 117 | */ |
moccos | 0:b4bf563e9741 | 118 | bool Reset(LinkMode mode=AutoNegotiate); |
moccos | 1:95a4c234aaf6 | 119 | |
moccos | 1:95a4c234aaf6 | 120 | /** |
moccos | 1:95a4c234aaf6 | 121 | * Gets ethernet address. |
moccos | 1:95a4c234aaf6 | 122 | * @return ethernet address |
moccos | 1:95a4c234aaf6 | 123 | */ |
moccos | 0:b4bf563e9741 | 124 | static const char* getHwAddr() { return (const char*)mac_; } |
moccos | 0:b4bf563e9741 | 125 | |
moccos | 0:b4bf563e9741 | 126 | private: |
moccos | 3:7ba8ebe32420 | 127 | // The number of RX resources |
moccos | 0:b4bf563e9741 | 128 | static const uint8_t N_RX_BUF = 5; |
moccos | 3:7ba8ebe32420 | 129 | // The number of TX resources |
moccos | 0:b4bf563e9741 | 130 | static const uint8_t N_TX_BUF = 3; |
moccos | 0:b4bf563e9741 | 131 | static const uint16_t PHY_ADDR = 0x0100; |
moccos | 0:b4bf563e9741 | 132 | static uint8_t mac_[6]; |
moccos | 0:b4bf563e9741 | 133 | static Descriptor rx_desc_[N_RX_BUF]; |
moccos | 0:b4bf563e9741 | 134 | static Descriptor tx_desc_[N_TX_BUF]; |
moccos | 0:b4bf563e9741 | 135 | static StatusRx rx_status_[N_RX_BUF]; |
moccos | 0:b4bf563e9741 | 136 | static StatusTx tx_status_[N_TX_BUF]; |
moccos | 0:b4bf563e9741 | 137 | static Frame rx_frame_[N_RX_BUF]; |
moccos | 0:b4bf563e9741 | 138 | static Frame tx_frame_[N_TX_BUF]; |
moccos | 0:b4bf563e9741 | 139 | uint8_t *write_next_; |
moccos | 0:b4bf563e9741 | 140 | uint8_t *read_next_; |
moccos | 0:b4bf563e9741 | 141 | uint16_t write_size_; |
moccos | 0:b4bf563e9741 | 142 | uint16_t read_size_; |
moccos | 0:b4bf563e9741 | 143 | |
moccos | 0:b4bf563e9741 | 144 | private: |
moccos | 0:b4bf563e9741 | 145 | void WriteAddress_(); |
moccos | 0:b4bf563e9741 | 146 | bool CheckAutoNeg_(); |
moccos | 0:b4bf563e9741 | 147 | void InitRxBuffer_(); |
moccos | 0:b4bf563e9741 | 148 | void InitTxBuffer_(); |
moccos | 0:b4bf563e9741 | 149 | }; |
moccos | 0:b4bf563e9741 | 150 | |
moccos | 0:b4bf563e9741 | 151 | #endif |