Commit | Line | Data |
---|---|---|
618e6b09 MM |
1 | #ifndef _LPC17XX_ETHERNET_H |
2 | #define _LPC17XX_ETHERNET_H | |
3 | ||
4 | #include "lpc17xx_emac.h" | |
5 | ||
6 | #include "Module.h" | |
7 | #include "net_util.h" | |
8 | ||
9 | #define EMAC_SMSC_8720A 0x0007C0F0 | |
10 | ||
11 | // SMSC 8720A special control/status register | |
12 | #define EMAC_PHY_REG_SCSR 0x1F | |
13 | ||
14 | #define LPC17XX_MAX_PACKET 1536 | |
15 | #define LPC17XX_TXBUFS 5 | |
16 | #define LPC17XX_RXBUFS 5 | |
17 | ||
18 | typedef struct { | |
19 | void* packet; | |
20 | uint32_t control; | |
21 | } packet_desc; | |
22 | ||
23 | typedef struct { | |
24 | uint8_t buf[LPC17XX_RXBUFS][LPC17XX_MAX_PACKET]; | |
25 | RX_Stat rxstat[LPC17XX_RXBUFS]; | |
26 | packet_desc rxdesc[LPC17XX_RXBUFS]; | |
27 | } _rxbuf_t; | |
28 | ||
29 | typedef struct { | |
30 | uint8_t buf[LPC17XX_TXBUFS][LPC17XX_MAX_PACKET]; | |
31 | TX_Stat txstat[LPC17XX_TXBUFS]; | |
32 | packet_desc txdesc[LPC17XX_TXBUFS]; | |
33 | } _txbuf_t; | |
34 | ||
35 | class LPC17XX_Ethernet; | |
36 | ||
37 | class LPC17XX_Ethernet : public Module, public NetworkInterface | |
38 | { | |
39 | public: | |
40 | LPC17XX_Ethernet(); | |
41 | ||
42 | void on_module_loaded(); | |
43 | void on_idle(void*); | |
44 | void on_second_tick(void*); | |
45 | ||
46 | void emac_init(void) __attribute__ ((optimize("O0"))); | |
47 | ||
48 | void set_mac(uint8_t*); | |
49 | ||
50 | void irq(void); | |
51 | ||
52 | void _receive_frame(void); | |
53 | ||
54 | // NetworkInterface methods | |
55 | // void provide_net(netcore* n); | |
56 | bool can_read_packet(void); | |
57 | int read_packet(uint8_t**); | |
58 | void release_read_packet(uint8_t*); | |
59 | void periodical(int); | |
60 | ||
61 | bool can_write_packet(void); | |
62 | int write_packet(uint8_t *, int); | |
63 | ||
64 | void* request_packet_buffer(void); | |
65 | ||
66 | // Encapsulator methods | |
67 | int receive(NetworkInterface* ni, NET_PACKET, int); | |
68 | int construct(NetworkInterface* ni, NET_PACKET, int); | |
69 | NET_PACKET get_new_packet_buffer(NetworkInterface*); | |
70 | NET_PAYLOAD get_payload_buffer(NET_PACKET); | |
71 | void set_payload_length(NET_PACKET, int); | |
72 | ||
73 | static LPC17XX_Ethernet* instance; | |
74 | ||
75 | static _rxbuf_t rxbuf; | |
76 | static _txbuf_t txbuf; | |
77 | }; | |
78 | ||
79 | #endif /* _LPC17XX_ETHERNET_H */ |