1 /* ----------------------------------------------------------------------------
\r
2 * SAM Software Package License
\r
3 * ----------------------------------------------------------------------------
\r
4 * Copyright (c) 2012, Atmel Corporation
\r
6 * All rights reserved.
\r
8 * Redistribution and use in source and binary forms, with or without
\r
9 * modification, are permitted provided that the following conditions are met:
\r
11 * - Redistributions of source code must retain the above copyright notice,
\r
12 * this list of conditions and the disclaimer below.
\r
14 * Atmel's name may not be used to endorse or promote products derived from
\r
15 * this software without specific prior written permission.
\r
17 * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
\r
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
\r
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
\r
20 * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
\r
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
\r
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
\r
23 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
\r
24 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
\r
25 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
\r
26 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\r
27 * ----------------------------------------------------------------------------
\r
32 /** \addtogroup gmacd_module
\r
34 * Implement GMAC data transfer and PHY management functions.
\r
37 * -# Implement GMAC interrupt handler, which must invoke GMACD_Handler()
\r
38 * to handle GMAC interrupt events.
\r
39 * -# Implement struct _gmacd instance in application.
\r
40 * -# Initialize the instance with GMACD_Init() and GMACD_InitTransfer(),
\r
41 * so that GMAC data can be transmitted/received.
\r
42 * -# Some management callbacks can be set by GMACD_SetRxCallback()
\r
43 * and GMACD_SetTxWakeupCallback().
\r
44 * -# Send ethernet packets using GMACD_Send(), GMACD_TxLoad() is used
\r
45 * to check the free space in TX queue.
\r
46 * -# Check and obtain received ethernet packets via GMACD_Poll().
\r
48 * \sa \ref gmacb_module, \ref gmac_module
\r
54 * \defgroup gmacd_defines GMAC Driver Defines
\r
55 * \defgroup gmacd_types GMAC Driver Types
\r
56 * \defgroup gmacd_functions GMAC Driver Functions
\r
63 /*---------------------------------------------------------------------------
\r
65 *---------------------------------------------------------------------------*/
\r
67 #include "peripherals/gmac.h"
\r
70 /*---------------------------------------------------------------------------
\r
72 *---------------------------------------------------------------------------*/
\r
73 /** \addtogroup gmacd_defines
\r
76 /** \addtogroup gmacd_buf_size GMACD Default Buffer Size
\r
78 #define GMAC_RX_UNITSIZE 128 /**< RX buffer size, must be 128 */
\r
79 #define GMAC_TX_UNITSIZE 1536 /**< TX buffer size, must be multiple
\r
80 of 32 (cache line) */
\r
83 /** \addtogroup gmacd_rc GMACD Return Codes
\r
85 #define GMACD_OK 0 /**< Operation OK */
\r
86 #define GMACD_TX_BUSY 1 /**< TX in progress */
\r
87 #define GMACD_RX_NULL 1 /**< No data received */
\r
88 /** Buffer size not enough */
\r
89 #define GMACD_SIZE_TOO_SMALL 2
\r
90 /** Parameter error, TX packet invalid or RX size too small */
\r
91 #define GMACD_PARAM 3
\r
92 /** Transter is not initialized */
\r
93 #define GMACD_NOT_INITIALIZED 4
\r
98 /*---------------------------------------------------------------------------
\r
100 *---------------------------------------------------------------------------*/
\r
101 /** \addtogroup gmacd_types
\r
104 /** RX/TX callback */
\r
105 typedef void (*gmacd_callback_t)(uint8_t queue, uint32_t status);
\r
107 /** TX Wakeup callback */
\r
108 typedef void (*gmacd_wakeup_cb_t)(uint8_t queue);
\r
110 /** GMAC scatter-gather entry */
\r
114 struct _gmac_sg *next;
\r
117 /** GMAC scatter-gather list */
\r
118 struct _gmac_sg_list {
\r
120 struct _gmac_sg *entries;
\r
123 struct _gmacd_queue {
\r
124 uint8_t *rx_buffer;
\r
125 struct _gmac_desc *rx_desc;
\r
128 gmacd_callback_t rx_callback;
\r
130 uint8_t *tx_buffer;
\r
131 struct _gmac_desc *tx_desc;
\r
135 gmacd_callback_t *tx_callbacks;
\r
137 gmacd_wakeup_cb_t tx_wakeup_callback;
\r
138 uint16_t tx_wakeup_threshold;
\r
142 * GMAC driver struct.
\r
145 Gmac* gmac; /**< GMAC instance */
\r
146 struct _gmacd_queue queues[GMAC_NUM_QUEUES];
\r
151 /** \addtogroup gmacd_functions
\r
154 /*---------------------------------------------------------------------------
\r
155 * GMAC Exported functions
\r
156 *---------------------------------------------------------------------------*/
\r
158 extern void gmacd_configure(struct _gmacd* gmacd, Gmac *pHw, uint8_t enableCAF, uint8_t enableNBC);
\r
160 extern uint8_t gmacd_setup_queue(struct _gmacd* gmacd, uint8_t queue,
\r
161 uint16_t rx_size, uint8_t* rx_buffer, struct _gmac_desc* rx_desc,
\r
162 uint16_t tx_size, uint8_t* tx_buffer, struct _gmac_desc* tx_desc,
\r
163 gmacd_callback_t *tx_callbacks);
\r
165 extern void gmacd_start(struct _gmacd* gmacd);
\r
167 extern void gmacd_reset(struct _gmacd* gmacd);
\r
169 extern uint8_t gmacd_send_sg(struct _gmacd* gmacd, uint8_t queue,
\r
170 const struct _gmac_sg_list* sgl, gmacd_callback_t callback);
\r
172 extern uint8_t gmacd_send(struct _gmacd* gmacd, uint8_t queue, void *buffer,
\r
173 uint32_t size, gmacd_callback_t callback);
\r
175 extern uint32_t gmacd_get_tx_load(struct _gmacd* gmacd, uint8_t queue);
\r
177 extern uint8_t gmacd_poll(struct _gmacd* gmacd, uint8_t queue,
\r
178 uint8_t* buffer, uint32_t buffer_size, uint32_t* recv_size);
\r
180 extern void gmacd_set_rx_callback(struct _gmacd *gmacd, uint8_t queue,
\r
181 gmacd_callback_t callback);
\r
183 extern uint8_t gmacd_set_tx_wakeup_callback(struct _gmacd *gmacd,
\r
184 uint8_t queue, gmacd_wakeup_cb_t wakeup_callback,
\r
185 uint16_t threshold);
\r
189 #endif /* _GMACD_H_ */
\r