1 |
583 |
jeremybenn |
//*----------------------------------------------------------------------------
|
2 |
|
|
//* ATMEL Microcontroller Software Support - ROUSSET -
|
3 |
|
|
//*----------------------------------------------------------------------------
|
4 |
|
|
//* The software is delivered "AS IS" without warranty or condition of any
|
5 |
|
|
//* kind, either express, implied or statutory. This includes without
|
6 |
|
|
//* limitation any warranty or condition with respect to merchantability or
|
7 |
|
|
//* fitness for any particular purpose, or against the infringements of
|
8 |
|
|
//* intellectual property rights of others.
|
9 |
|
|
//*----------------------------------------------------------------------------
|
10 |
|
|
//* File Name : Emac.h
|
11 |
|
|
//* Object : Emac header file
|
12 |
|
|
//* Creation : Hi 11/18/2002
|
13 |
|
|
//*
|
14 |
|
|
//*----------------------------------------------------------------------------
|
15 |
|
|
#ifndef AT91C_EMAC_H
|
16 |
|
|
#define AT91C_EMAC_H
|
17 |
|
|
|
18 |
|
|
|
19 |
|
|
//* Allows to display all IP header in the main.c
|
20 |
|
|
//* If not defined, only ICMP packets are displayed
|
21 |
|
|
#define AT91C_DISPLAY_ALL_IPHEADER 0
|
22 |
|
|
|
23 |
|
|
#define NB_RX_BUFFERS 25 //* Number of receive buffers
|
24 |
|
|
#define ETH_RX_BUFFER_SIZE 128 //*
|
25 |
|
|
|
26 |
|
|
#define NB_TX_BUFFERS 2 //* Number of Transmit buffers
|
27 |
|
|
#define ETH_TX_BUFFER_SIZE UIP_BUFSIZE //*
|
28 |
|
|
|
29 |
|
|
#define AT91C_NO_IPPACKET 0
|
30 |
|
|
#define AT91C_IPPACKET 1
|
31 |
|
|
|
32 |
|
|
#define ARP_REQUEST 0x0001
|
33 |
|
|
#define ARP_REPLY 0x0002
|
34 |
|
|
#define PROT_ARP 0x0806
|
35 |
|
|
#define PROT_IP 0x0800
|
36 |
|
|
#define PROT_ICMP 0x01
|
37 |
|
|
#define ICMP_ECHO_REQUEST 0x08
|
38 |
|
|
#define ICMP_ECHO_REPLY 0x00
|
39 |
|
|
|
40 |
|
|
#define AT91C_EMAC_CLKEN 0x2
|
41 |
|
|
#define SWAP16(x) (((x & 0xff) << 8) | (x >> 8))
|
42 |
|
|
|
43 |
|
|
#if 0
|
44 |
|
|
//* Transfer descriptor structure
|
45 |
|
|
typedef struct _AT91S_TdDescriptor {
|
46 |
|
|
unsigned int addr;
|
47 |
|
|
unsigned int status;
|
48 |
|
|
}AT91S_TdDescriptor, *AT91PS_TdDescriptor;
|
49 |
|
|
#endif
|
50 |
|
|
|
51 |
|
|
//* Receive Transfer descriptor structure
|
52 |
|
|
typedef struct _AT91S_RxTdDescriptor {
|
53 |
|
|
unsigned int addr;
|
54 |
|
|
union
|
55 |
|
|
{
|
56 |
|
|
unsigned int status;
|
57 |
|
|
struct {
|
58 |
|
|
unsigned int Length:11;
|
59 |
|
|
unsigned int Res0:1;
|
60 |
|
|
unsigned int Rxbuf_off:2;
|
61 |
|
|
unsigned int StartOfFrame:1;
|
62 |
|
|
unsigned int EndOfFrame:1;
|
63 |
|
|
unsigned int Cfi:1;
|
64 |
|
|
unsigned int VlanPriority:3;
|
65 |
|
|
unsigned int PriorityTag:1;
|
66 |
|
|
unsigned int VlanTag:1;
|
67 |
|
|
unsigned int TypeID:1;
|
68 |
|
|
unsigned int Sa4Match:1;
|
69 |
|
|
unsigned int Sa3Match:1;
|
70 |
|
|
unsigned int Sa2Match:1;
|
71 |
|
|
unsigned int Sa1Match:1;
|
72 |
|
|
unsigned int Res1:1;
|
73 |
|
|
unsigned int ExternalAdd:1;
|
74 |
|
|
unsigned int UniCast:1;
|
75 |
|
|
unsigned int MultiCast:1;
|
76 |
|
|
unsigned int BroadCast:1;
|
77 |
|
|
}S_Status;
|
78 |
|
|
}U_Status;
|
79 |
|
|
}AT91S_RxTdDescriptor, *AT91PS_RxTdDescriptor;
|
80 |
|
|
|
81 |
|
|
|
82 |
|
|
//* Transmit Transfer descriptor structure
|
83 |
|
|
typedef struct _AT91S_TxTdDescriptor {
|
84 |
|
|
unsigned int addr;
|
85 |
|
|
union
|
86 |
|
|
{
|
87 |
|
|
unsigned int status;
|
88 |
|
|
struct {
|
89 |
|
|
unsigned int Length:11;
|
90 |
|
|
unsigned int Res0:4;
|
91 |
|
|
unsigned int LastBuff:1;
|
92 |
|
|
unsigned int NoCrc:1;
|
93 |
|
|
unsigned int Res1:10;
|
94 |
|
|
unsigned int BufExhausted:1;
|
95 |
|
|
unsigned int TransmitUnderrun:1;
|
96 |
|
|
unsigned int TransmitError:1;
|
97 |
|
|
unsigned int Wrap:1;
|
98 |
|
|
unsigned int BuffUsed:1;
|
99 |
|
|
}S_Status;
|
100 |
|
|
}U_Status;
|
101 |
|
|
}AT91S_TxTdDescriptor, *AT91PS_TxTdDescriptor;
|
102 |
|
|
|
103 |
|
|
#define AT91C_OWNERSHIP_BIT 0x00000001
|
104 |
|
|
|
105 |
|
|
/* Receive status defintion */
|
106 |
|
|
#define AT91C_BROADCAST_ADDR ((unsigned int) (1 << 31)) //* Broadcat address detected
|
107 |
|
|
#define AT91C_MULTICAST_HASH ((unsigned int) (1 << 30)) //* MultiCast hash match
|
108 |
|
|
#define AT91C_UNICAST_HASH ((unsigned int) (1 << 29)) //* UniCast hash match
|
109 |
|
|
#define AT91C_EXTERNAL_ADDR ((unsigned int) (1 << 28)) //* External Address match
|
110 |
|
|
#define AT91C_SA1_ADDR ((unsigned int) (1 << 26)) //* Specific address 1 match
|
111 |
|
|
#define AT91C_SA2_ADDR ((unsigned int) (1 << 25)) //* Specific address 2 match
|
112 |
|
|
#define AT91C_SA3_ADDR ((unsigned int) (1 << 24)) //* Specific address 3 match
|
113 |
|
|
#define AT91C_SA4_ADDR ((unsigned int) (1 << 23)) //* Specific address 4 match
|
114 |
|
|
#define AT91C_TYPE_ID ((unsigned int) (1 << 22)) //* Type ID match
|
115 |
|
|
#define AT91C_VLAN_TAG ((unsigned int) (1 << 21)) //* VLAN tag detected
|
116 |
|
|
#define AT91C_PRIORITY_TAG ((unsigned int) (1 << 20)) //* PRIORITY tag detected
|
117 |
|
|
#define AT91C_VLAN_PRIORITY ((unsigned int) (7 << 17)) //* PRIORITY Mask
|
118 |
|
|
#define AT91C_CFI_IND ((unsigned int) (1 << 16)) //* CFI indicator
|
119 |
|
|
#define AT91C_EOF ((unsigned int) (1 << 15)) //* EOF
|
120 |
|
|
#define AT91C_SOF ((unsigned int) (1 << 14)) //* SOF
|
121 |
|
|
#define AT91C_RBF_OFFSET ((unsigned int) (3 << 12)) //* Receive Buffer Offset Mask
|
122 |
|
|
#define AT91C_LENGTH_FRAME ((unsigned int) 0x07FF) //* Length of frame
|
123 |
|
|
|
124 |
|
|
/* Transmit Status definition */
|
125 |
|
|
#define AT91C_TRANSMIT_OK ((unsigned int) (1 << 31)) //*
|
126 |
|
|
#define AT91C_TRANSMIT_WRAP ((unsigned int) (1 << 30)) //* Wrap bit: mark the last descriptor
|
127 |
|
|
#define AT91C_TRANSMIT_ERR ((unsigned int) (1 << 29)) //* RLE:transmit error
|
128 |
|
|
#define AT91C_TRANSMIT_UND ((unsigned int) (1 << 28)) //* Transmit Underrun
|
129 |
|
|
#define AT91C_BUF_EX ((unsigned int) (1 << 27)) //* Buffers exhausted in mid frame
|
130 |
|
|
#define AT91C_TRANSMIT_NO_CRC ((unsigned int) (1 << 16)) //* No CRC will be appended to the current frame
|
131 |
|
|
#define AT91C_LAST_BUFFER ((unsigned int) (1 << 15)) //*
|
132 |
|
|
|
133 |
|
|
#define ARP_ETHER 1 /* Ethernet hardware address */
|
134 |
|
|
#define ARPOP_REQUEST 1 /* Request to resolve address */
|
135 |
|
|
#define ARPOP_REPLY 2 /* Response to previous request */
|
136 |
|
|
#define RARPOP_REQUEST 3 /* Request to resolve address */
|
137 |
|
|
#define RARPOP_REPLY 4 /* Response to previous request */
|
138 |
|
|
|
139 |
|
|
|
140 |
|
|
typedef struct _AT91S_EthHdr
|
141 |
|
|
{
|
142 |
|
|
unsigned char et_dest[6]; /* Destination node */
|
143 |
|
|
unsigned char et_src[6]; /* Source node */
|
144 |
|
|
unsigned short et_protlen; /* Protocol or length */
|
145 |
|
|
} AT91S_EthHdr, *AT91PS_EthHdr;
|
146 |
|
|
|
147 |
|
|
typedef struct _AT91S_ArpHdr
|
148 |
|
|
{
|
149 |
|
|
unsigned short ar_hrd; /* Format of hardware address */
|
150 |
|
|
unsigned short ar_pro; /* Format of protocol address */
|
151 |
|
|
unsigned char ar_hln; /* Length of hardware address */
|
152 |
|
|
unsigned char ar_pln; /* Length of protocol address */
|
153 |
|
|
unsigned short ar_op; /* Operation */
|
154 |
|
|
unsigned char ar_sha[6]; /* Sender hardware address */
|
155 |
|
|
unsigned char ar_spa[4]; /* Sender protocol address */
|
156 |
|
|
unsigned char ar_tha[6]; /* Target hardware address */
|
157 |
|
|
unsigned char ar_tpa[4]; /* Target protocol address */
|
158 |
|
|
} AT91S_ArpHdr, *AT91PS_ArpHdr;
|
159 |
|
|
|
160 |
|
|
//* IP Header structure
|
161 |
|
|
typedef struct _AT91S_IPheader {
|
162 |
|
|
unsigned char ip_hl_v; /* header length and version */
|
163 |
|
|
unsigned char ip_tos; /* type of service */
|
164 |
|
|
unsigned short ip_len; /* total length */
|
165 |
|
|
unsigned short ip_id; /* identification */
|
166 |
|
|
unsigned short ip_off; /* fragment offset field */
|
167 |
|
|
unsigned char ip_ttl; /* time to live */
|
168 |
|
|
unsigned char ip_p; /* protocol */
|
169 |
|
|
unsigned short ip_sum; /* checksum */
|
170 |
|
|
unsigned char ip_src[4]; /* Source IP address */
|
171 |
|
|
unsigned char ip_dst[4]; /* Destination IP address */
|
172 |
|
|
unsigned short udp_src; /* UDP source port */
|
173 |
|
|
unsigned short udp_dst; /* UDP destination port */
|
174 |
|
|
unsigned short udp_len; /* Length of UDP packet */
|
175 |
|
|
unsigned short udp_xsum; /* Checksum */
|
176 |
|
|
} AT91S_IPheader, *AT91PS_IPheader;
|
177 |
|
|
|
178 |
|
|
//* ICMP echo header structure
|
179 |
|
|
typedef struct _AT91S_IcmpEchoHdr {
|
180 |
|
|
unsigned char type; /* type of message */
|
181 |
|
|
unsigned char code; /* type subcode */
|
182 |
|
|
unsigned short cksum; /* ones complement cksum of struct */
|
183 |
|
|
unsigned short id; /* identifier */
|
184 |
|
|
unsigned short seq; /* sequence number */
|
185 |
|
|
}AT91S_IcmpEchoHdr, *AT91PS_IcmpEchoHdr;
|
186 |
|
|
|
187 |
|
|
|
188 |
|
|
typedef struct _AT91S_EthPack
|
189 |
|
|
{
|
190 |
|
|
AT91S_EthHdr EthHdr;
|
191 |
|
|
AT91S_ArpHdr ArpHdr;
|
192 |
|
|
} AT91S_EthPack, *AT91PS_EthPack;
|
193 |
|
|
|
194 |
|
|
|
195 |
|
|
#endif //* AT91C_EMAC_H
|