OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [freertos-6.1.1/] [Demo/] [lwIP_AVR32_UC3/] [DRIVERS/] [MACB/] [macb.h] - Blame information for rev 600

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 583 jeremybenn
/*This file has been prepared for Doxygen automatic documentation generation.*/
2
/*! \file *********************************************************************
3
 *
4
 * \brief MACB example driver for EVK1100 board.
5
 *
6
 * This file defines a useful set of functions for the MACB interface on
7
 * AVR32 devices.
8
 *
9
 * - Compiler:           IAR EWAVR32 and GNU GCC for AVR32
10
 * - Supported devices:  All AVR32 devices with a MACB module can be used.
11
 * - AppNote:
12
 *
13
 * \author               Atmel Corporation: http://www.atmel.com \n
14
 *                       Support and FAQ: http://support.atmel.no/
15
 *
16
 *****************************************************************************/
17
 
18
/* Copyright (c) 2007, Atmel Corporation All rights reserved.
19
 *
20
 * Redistribution and use in source and binary forms, with or without
21
 * modification, are permitted provided that the following conditions are met:
22
 *
23
 * 1. Redistributions of source code must retain the above copyright notice,
24
 * this list of conditions and the following disclaimer.
25
 *
26
 * 2. Redistributions in binary form must reproduce the above copyright notice,
27
 * this list of conditions and the following disclaimer in the documentation
28
 * and/or other materials provided with the distribution.
29
 *
30
 * 3. The name of ATMEL may not be used to endorse or promote products derived
31
 * from this software without specific prior written permission.
32
 *
33
 * THIS SOFTWARE IS PROVIDED BY ATMEL ``AS IS'' AND ANY EXPRESS OR IMPLIED
34
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
35
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE EXPRESSLY AND
36
 * SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT,
37
 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
38
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
39
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
40
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
41
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
42
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
43
 */
44
 
45
 
46
#ifndef AVR32_MACB_H
47
#define AVR32_MACB_H
48
 
49
#include <avr32/io.h>
50
 
51
#ifdef FREERTOS_USED
52
#include <arch/sys_arch.h>
53
#endif
54
 
55
#include "conf_eth.h"
56
 
57
/*! \name Rx Ring descriptor flags
58
 */
59
//! @{
60
#define AVR32_MACB_RX_USED_OFFSET       0
61
#define AVR32_MACB_RX_USED_SIZE         1
62
#define AVR32_MACB_RX_WRAP_OFFSET       1
63
#define AVR32_MACB_RX_WRAP_SIZE         1
64
#define AVR32_MACB_RX_LEN_OFFSET        0
65
#define AVR32_MACB_RX_LEN_SIZE         12
66
#define AVR32_MACB_RX_OFFSET_OFFSET    12
67
#define AVR32_MACB_RX_OFFSET_SIZE       2
68
#define AVR32_MACB_RX_SOF_OFFSET       14
69
#define AVR32_MACB_RX_SOF_SIZE          1
70
#define AVR32_MACB_RX_EOF_OFFSET       15
71
#define AVR32_MACB_RX_EOF_SIZE          1
72
#define AVR32_MACB_RX_CFI_OFFSET       16
73
#define AVR32_MACB_RX_CFI_SIZE          1
74
//! @}
75
 
76
/*! \name Tx Ring descriptor flags
77
 */
78
//! @{
79
#define AVR32_MACB_TX_LEN_OFFSET        0
80
#define AVR32_MACB_TX_LEN_SIZE         11
81
#define AVR32_MACB_TX_EOF_OFFSET       15
82
#define AVR32_MACB_TX_EOF_SIZE          1
83
#define AVR32_MACB_TX_NOCRC_OFFSET     16
84
#define AVR32_MACB_TX_NOCRC_SIZE        1
85
#define AVR32_MACB_TX_EMF_OFFSET       27
86
#define AVR32_MACB_TX_EMF_SIZE          1
87
#define AVR32_MACB_TX_UNR_OFFSET       28
88
#define AVR32_MACB_TX_UNR_SIZE          1
89
#define AVR32_MACB_TX_MAXRETRY_OFFSET  29
90
#define AVR32_MACB_TX_MAXRETRY_SIZE     1
91
#define AVR32_MACB_TX_WRAP_OFFSET      30
92
#define AVR32_MACB_TX_WRAP_SIZE         1
93
#define AVR32_MACB_TX_USED_OFFSET      31
94
#define AVR32_MACB_TX_USED_SIZE         1
95
//! @}
96
 
97
/*! \name Generic MII registers.
98
 */
99
//! @{
100
#define PHY_BMCR            0x00        //!< Basic mode control register
101
#define PHY_BMSR            0x01        //!< Basic mode status register
102
#define PHY_PHYSID1         0x02        //!< PHYS ID 1
103
#define PHY_PHYSID2         0x03        //!< PHYS ID 2
104
#define PHY_ADVERTISE       0x04        //!< Advertisement control reg
105
#define PHY_LPA             0x05        //!< Link partner ability reg
106
//! @}
107
 
108
#if BOARD == EVK1100
109
/*! \name Extended registers for DP83848
110
 */
111
//! @{
112
#define PHY_RBR             0x17        //!< RMII Bypass reg
113
#define PHY_MICR            0x11        //!< Interrupt Control reg
114
#define PHY_MISR            0x12        //!< Interrupt Status reg
115
#define PHY_PHYCR           0x19        //!< Phy CTRL reg
116
//! @}
117
#endif
118
 
119
 
120
/*! \name Basic mode control register.
121
 */
122
//! @{
123
#define BMCR_RESV               0x007f  //!< Unused...
124
#define BMCR_CTST               0x0080  //!< Collision test
125
#define BMCR_FULLDPLX           0x0100  //!< Full duplex
126
#define BMCR_ANRESTART          0x0200  //!< Auto negotiation restart
127
#define BMCR_ISOLATE            0x0400  //!< Disconnect PHY from MII
128
#define BMCR_PDOWN              0x0800  //!< Powerdown the PHY
129
#define BMCR_ANENABLE           0x1000  //!< Enable auto negotiation
130
#define BMCR_SPEED100           0x2000  //!< Select 100Mbps
131
#define BMCR_LOOPBACK           0x4000  //!< TXD loopback bits
132
#define BMCR_RESET              0x8000  //!< Reset the PHY
133
//! @}
134
 
135
/*! \name Basic mode status register.
136
 */
137
//! @{
138
#define BMSR_ERCAP              0x0001  //!< Ext-reg capability
139
#define BMSR_JCD                0x0002  //!< Jabber detected
140
#define BMSR_LSTATUS            0x0004  //!< Link status
141
#define BMSR_ANEGCAPABLE        0x0008  //!< Able to do auto-negotiation
142
#define BMSR_RFAULT             0x0010  //!< Remote fault detected
143
#define BMSR_ANEGCOMPLETE       0x0020  //!< Auto-negotiation complete
144
#define BMSR_RESV               0x00c0  //!< Unused...
145
#define BMSR_ESTATEN            0x0100  //!< Extended Status in R15
146
#define BMSR_100FULL2           0x0200  //!< Can do 100BASE-T2 HDX
147
#define BMSR_100HALF2           0x0400  //!< Can do 100BASE-T2 FDX
148
#define BMSR_10HALF             0x0800  //!< Can do 10mbps, half-duplex
149
#define BMSR_10FULL             0x1000  //!< Can do 10mbps, full-duplex
150
#define BMSR_100HALF            0x2000  //!< Can do 100mbps, half-duplex
151
#define BMSR_100FULL            0x4000  //!< Can do 100mbps, full-duplex
152
#define BMSR_100BASE4           0x8000  //!< Can do 100mbps, 4k packets
153
//! @}
154
 
155
/*! \name Advertisement control register.
156
 */
157
//! @{
158
#define ADVERTISE_SLCT          0x001f  //!< Selector bits
159
#define ADVERTISE_CSMA          0x0001  //!< Only selector supported
160
#define ADVERTISE_10HALF        0x0020  //!< Try for 10mbps half-duplex
161
#define ADVERTISE_1000XFULL     0x0020  //!< Try for 1000BASE-X full-duplex
162
#define ADVERTISE_10FULL        0x0040  //!< Try for 10mbps full-duplex
163
#define ADVERTISE_1000XHALF     0x0040  //!< Try for 1000BASE-X half-duplex
164
#define ADVERTISE_100HALF       0x0080  //!< Try for 100mbps half-duplex
165
#define ADVERTISE_1000XPAUSE    0x0080  //!< Try for 1000BASE-X pause
166
#define ADVERTISE_100FULL       0x0100  //!< Try for 100mbps full-duplex
167
#define ADVERTISE_1000XPSE_ASYM 0x0100  //!< Try for 1000BASE-X asym pause
168
#define ADVERTISE_100BASE4      0x0200  //!< Try for 100mbps 4k packets
169
#define ADVERTISE_PAUSE_CAP     0x0400  //!< Try for pause
170
#define ADVERTISE_PAUSE_ASYM    0x0800  //!< Try for asymetric pause
171
#define ADVERTISE_RESV          0x1000  //!< Unused...
172
#define ADVERTISE_RFAULT        0x2000  //!< Say we can detect faults
173
#define ADVERTISE_LPACK         0x4000  //!< Ack link partners response
174
#define ADVERTISE_NPAGE         0x8000  //!< Next page bit
175
//! @}
176
 
177
#define ADVERTISE_FULL (ADVERTISE_100FULL | ADVERTISE_10FULL | ADVERTISE_CSMA)
178
#define ADVERTISE_ALL (ADVERTISE_10HALF | ADVERTISE_10FULL | \
179
                       ADVERTISE_100HALF | ADVERTISE_100FULL)
180
 
181
/*! \name Link partner ability register.
182
 */
183
//! @{
184
#define LPA_SLCT                0x001f  //!< Same as advertise selector
185
#define LPA_10HALF              0x0020  //!< Can do 10mbps half-duplex
186
#define LPA_1000XFULL           0x0020  //!< Can do 1000BASE-X full-duplex
187
#define LPA_10FULL              0x0040  //!< Can do 10mbps full-duplex
188
#define LPA_1000XHALF           0x0040  //!< Can do 1000BASE-X half-duplex
189
#define LPA_100HALF             0x0080  //!< Can do 100mbps half-duplex
190
#define LPA_1000XPAUSE          0x0080  //!< Can do 1000BASE-X pause
191
#define LPA_100FULL             0x0100  //!< Can do 100mbps full-duplex
192
#define LPA_1000XPAUSE_ASYM     0x0100  //!< Can do 1000BASE-X pause asym
193
#define LPA_100BASE4            0x0200  //!< Can do 100mbps 4k packets
194
#define LPA_PAUSE_CAP           0x0400  //!< Can pause
195
#define LPA_PAUSE_ASYM          0x0800  //!< Can pause asymetrically
196
#define LPA_RESV                0x1000  //!< Unused...
197
#define LPA_RFAULT              0x2000  //!< Link partner faulted
198
#define LPA_LPACK               0x4000  //!< Link partner acked us
199
#define LPA_NPAGE               0x8000  //!< Next page bit
200
 
201
#define LPA_DUPLEX    (LPA_10FULL | LPA_100FULL)
202
#define LPA_100       (LPA_100FULL | LPA_100HALF | LPA_100BASE4)
203
//! @}
204
 
205
#if BOARD == EVK1100
206
/*! RMII Bypass Register */
207
#define RBR_RMII                 0x0020  //!< RMII Mode
208
/*! \name Interrupt Ctrl Register.
209
 */
210
//! @{
211
#define MICR_INTEN               0x0002  //!< Enable interrupts
212
#define MICR_INTOE               0x0001  //!< Enable INT output
213
//! @}
214
 
215
/*! \name Interrupt Status Register.
216
 */
217
//! @{
218
#define MISR_ED_INT_EN           0x0040  //!< Energy Detect enabled
219
#define MISR_LINK_INT_EN         0x0020  //!< Link status change enabled
220
#define MISR_SPD_INT_EN          0x0010  //!< Speed change enabled
221
#define MISR_DP_INT_EN           0x0008  //!< Duplex mode change enabled
222
#define MISR_ANC_INT_EN          0x0004  //!< Auto-Neg complete enabled
223
#define MISR_FHF_INT_EN          0x0002  //!< False Carrier enabled
224
#define MISR_RHF_INT_EN          0x0001  //!< Receive Error enabled
225
#define MISR_ED_INT              0x4000  //!< Energy Detect
226
#define MISR_LINK_INT            0x2000  //!< Link status change
227
#define MISR_SPD_INT             0x1000  //!< Speed change
228
#define MISR_DP_INT              0x0800  //!< Duplex mode change
229
#define MISR_ANC_INT             0x0400  //!< Auto-Neg complete
230
#define MISR_FHF_INT             0x0200  //!< False Carrier
231
#define MISR_RHF_INT             0x0100  //!< Receive Error
232
//! @}
233
 
234
/*! \name Phy Ctrl Register.
235
 */
236
//! @{
237
#define PHYCR_MDIX_EN            0x8000  //!< Enable Auto MDIX
238
#define PHYCR_MDIX_FORCE         0x4000  //!< Force MDIX crossed
239
//! @}
240
#endif
241
 
242
/*! Packet structure.
243
 */
244
//! @{
245
typedef struct
246
{
247
  char *data;
248
  unsigned int len;
249
} macb_packet_t;
250
//! @}
251
 
252
/*! Receive Transfer descriptor structure.
253
 */
254
//! @{
255
typedef struct  _AVR32_RxTdDescriptor {
256
  unsigned int addr;
257
  union
258
  {
259
    unsigned int status;
260
    struct {
261
      unsigned int BroadCast:1;
262
      unsigned int MultiCast:1;
263
      unsigned int UniCast:1;
264
      unsigned int ExternalAdd:1;
265
      unsigned int Res1:1;
266
      unsigned int Sa1Match:1;
267
      unsigned int Sa2Match:1;
268
      unsigned int Sa3Match:1;
269
      unsigned int Sa4Match:1;
270
      unsigned int TypeID:1;
271
      unsigned int VlanTag:1;
272
      unsigned int PriorityTag:1;
273
      unsigned int VlanPriority:3;
274
      unsigned int Cfi:1;
275
      unsigned int EndOfFrame:1;
276
      unsigned int StartOfFrame:1;
277
      unsigned int Rxbuf_off:2;
278
      unsigned int Res0:1;
279
      unsigned int Length:11;
280
    }S_Status;
281
  }U_Status;
282
}AVR32_RxTdDescriptor, *AVR32P_RxTdDescriptor;
283
//! @}
284
 
285
/*! Transmit Transfer descriptor structure.
286
 */
287
//! @{
288
typedef struct _AVR32_TxTdDescriptor {
289
  unsigned int addr;
290
  union
291
  {
292
    unsigned int status;
293
    struct {
294
      unsigned int BuffUsed:1;
295
      unsigned int Wrap:1;
296
      unsigned int TransmitError:1;
297
      unsigned int TransmitUnderrun:1;
298
      unsigned int BufExhausted:1;
299
      unsigned int Res1:10;
300
      unsigned int NoCrc:1;
301
      unsigned int LastBuff:1;
302
      unsigned int Res0:4;
303
      unsigned int Length:11;
304
    }S_Status;
305
  }U_Status;
306
}AVR32_TxTdDescriptor, *AVR32P_TxTdDescriptor;
307
//! @}
308
 
309
/*! Mask for frame used. */
310
#define AVR32_OWNERSHIP_BIT   0x00000001
311
 
312
/*! Receive status defintion.
313
 */
314
//! @{
315
#define AVR32_BROADCAST_ADDR  ((unsigned int) (1 << 31))  //* Broadcat address detected
316
#define AVR32_MULTICAST_HASH  ((unsigned int) (1 << 30))  //* MultiCast hash match
317
#define AVR32_UNICAST_HASH    ((unsigned int) (1 << 29))  //* UniCast hash match
318
#define AVR32_EXTERNAL_ADDR   ((unsigned int) (1 << 28))  //* External Address match
319
#define AVR32_SA1_ADDR        ((unsigned int) (1 << 26))  //* Specific address 1 match
320
#define AVR32_SA2_ADDR        ((unsigned int) (1 << 25))  //* Specific address 2 match
321
#define AVR32_SA3_ADDR        ((unsigned int) (1 << 24))  //* Specific address 3 match
322
#define AVR32_SA4_ADDR        ((unsigned int) (1 << 23))  //* Specific address 4 match
323
#define AVR32_TYPE_ID         ((unsigned int) (1 << 22))  //* Type ID match
324
#define AVR32_VLAN_TAG        ((unsigned int) (1 << 21))  //* VLAN tag detected
325
#define AVR32_PRIORITY_TAG    ((unsigned int) (1 << 20))  //* PRIORITY tag detected
326
#define AVR32_VLAN_PRIORITY   ((unsigned int) (7 << 17))  //* PRIORITY Mask
327
#define AVR32_CFI_IND         ((unsigned int) (1 << 16))  //* CFI indicator
328
#define AVR32_EOF             ((unsigned int) (1 << 15))  //* EOF
329
#define AVR32_SOF             ((unsigned int) (1 << 14))  //* SOF
330
#define AVR32_RBF_OFFSET      ((unsigned int) (3 << 12))  //* Receive Buffer Offset Mask
331
#define AVR32_LENGTH_FRAME    ((unsigned int) 0x0FFF)     //* Length of frame
332
//! @}
333
 
334
/* Transmit Status definition */
335
//! @{
336
#define AVR32_TRANSMIT_OK     ((unsigned int) (1 << 31))  //*
337
#define AVR32_TRANSMIT_WRAP   ((unsigned int) (1 << 30))  //* Wrap bit: mark the last descriptor
338
#define AVR32_TRANSMIT_ERR    ((unsigned int) (1 << 29))  //* RLE:transmit error
339
#define AVR32_TRANSMIT_UND    ((unsigned int) (1 << 28))  //* Transmit Underrun
340
#define AVR32_BUF_EX          ((unsigned int) (1 << 27))  //* Buffers exhausted in mid frame
341
#define AVR32_TRANSMIT_NO_CRC ((unsigned int) (1 << 16))  //* No CRC will be appended to the current frame
342
#define AVR32_LAST_BUFFER     ((unsigned int) (1 << 15))  //*
343
//! @}
344
 
345
/**
346
 * \brief Initialise the MACB driver.
347
 *
348
 * \param *macb Base address of the MACB
349
 *
350
 * \return TRUE if success, FALSE otherwise.
351
 */
352
Bool xMACBInit( volatile avr32_macb_t * macb );
353
 
354
/**
355
 * \brief Send ulLength bytes from pcFrom. This copies the buffer to one of the
356
 * MACB Tx buffers, then indicates to the MACB that the buffer is ready.
357
 * If lEndOfFrame is true then the data being copied is the end of the frame
358
 * and the frame can be transmitted.
359
 *
360
 * \param *macb        Base address of the MACB
361
 * \param *pcFrom      Address of the data buffer
362
 * \param ulLength     Length of the frame
363
 * \param lEndOfFrame  Flag for End Of Frame
364
 *
365
 * \return length sent.
366
 */
367
long lMACBSend(volatile avr32_macb_t * macb, char *pcFrom, unsigned long ulLength, long lEndOfFrame );
368
 
369
 
370
/**
371
 * \brief Frames can be read from the MACB in multiple sections.
372
 * Read ulSectionLength bytes from the MACB receive buffers to pcTo.
373
 * ulTotalFrameLength is the size of the entire frame.  Generally vMACBRead
374
 * will be repetedly called until the sum of all the ulSectionLenths totals
375
 * the value of ulTotalFrameLength.
376
 *
377
 * \param *pcTo               Address of the buffer
378
 * \param ulSectionLength     Length of the buffer
379
 * \param ulTotalFrameLength  Length of the frame
380
 */
381
void vMACBRead( char *pcTo, unsigned long ulSectionLength, unsigned long ulTotalFrameLength );
382
 
383
/**
384
 * \brief Called by the Tx interrupt, this function traverses the buffers used to
385
 * hold the frame that has just completed transmission and marks each as
386
 * free again.
387
 */
388
void vClearMACBTxBuffer( void );
389
 
390
/**
391
 * \brief Suspend on a semaphore waiting either for the semaphore to be obtained
392
 * or a timeout.  The semaphore is used by the MACB ISR to indicate that
393
 * data has been received and is ready for processing.
394
 *
395
 * \param ulTimeOut    time to wait for an input
396
 *
397
 */
398
void vMACBWaitForInput( unsigned long ulTimeOut );
399
 
400
/**
401
 * \brief Function to get length of the next frame in the receive buffers
402
 *
403
 * \return the length of the next frame in the receive buffers.
404
 */
405
unsigned long ulMACBInputLength( void );
406
 
407
/**
408
 * \brief Set the MACB Physical address (SA1B & SA1T registers).
409
 *
410
 * \param *MACAddress the MAC address to set.
411
 */
412
void vMACBSetMACAddress(const char * MACAddress);
413
 
414
/**
415
 * \brief Disable MACB operations (Tx and Rx).
416
 *
417
 * \param *macb        Base address of the MACB
418
 */
419
void vDisableMACBOperations(volatile avr32_macb_t * macb);
420
 
421
#endif
422
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.