]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_A5_SAMA5D2x_Xplained_IAR/AtmelFiles/drivers/peripherals/gmacd.h
Add SAMA5D2 Xplained IAR demo.
[freertos] / FreeRTOS / Demo / CORTEX_A5_SAMA5D2x_Xplained_IAR / AtmelFiles / drivers / peripherals / gmacd.h
1 /* ----------------------------------------------------------------------------\r
2  *         SAM Software Package License\r
3  * ----------------------------------------------------------------------------\r
4  * Copyright (c) 2012, Atmel Corporation\r
5  *\r
6  * All rights reserved.\r
7  *\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
10  *\r
11  * - Redistributions of source code must retain the above copyright notice,\r
12  * this list of conditions and the disclaimer below.\r
13  *\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
16  *\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
28  */\r
29 \r
30 /** \file */\r
31 \r
32 /** \addtogroup gmacd_module\r
33  * @{\r
34  * Implement GMAC data transfer and PHY management functions.\r
35  *\r
36  * \section Usage\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
47  *\r
48  * \sa \ref gmacb_module, \ref gmac_module\r
49  *\r
50  * Related files:\n\r
51  * \ref gmacd.c\n\r
52  * \ref gmacd.h.\n\r
53  *\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
57  */\r
58 /**@}*/\r
59 \r
60 #ifndef _GMACD_H_\r
61 #define _GMACD_H_\r
62 \r
63 /*---------------------------------------------------------------------------\r
64  *         Headers\r
65  *---------------------------------------------------------------------------*/\r
66 \r
67 #include "peripherals/gmac.h"\r
68 #include <stdint.h>\r
69 \r
70 /*---------------------------------------------------------------------------\r
71  *         Definitions\r
72  *---------------------------------------------------------------------------*/\r
73 /** \addtogroup gmacd_defines\r
74     @{*/\r
75 \r
76 /** \addtogroup gmacd_buf_size GMACD Default Buffer Size\r
77         @{*/\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
81 /**     @}*/\r
82 \r
83 /** \addtogroup gmacd_rc GMACD Return Codes\r
84         @{*/\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
94 /**     @}*/\r
95 \r
96 /** @}*/\r
97 \r
98 /*---------------------------------------------------------------------------\r
99  *         Types\r
100  *---------------------------------------------------------------------------*/\r
101 /** \addtogroup gmacd_types\r
102     @{*/\r
103 \r
104 /** RX/TX callback */\r
105 typedef void (*gmacd_callback_t)(uint8_t queue, uint32_t status);\r
106 \r
107 /** TX Wakeup callback */\r
108 typedef void (*gmacd_wakeup_cb_t)(uint8_t queue);\r
109 \r
110 /** GMAC scatter-gather entry */\r
111 struct _gmac_sg {\r
112         uint32_t         size;\r
113         void            *buffer;\r
114         struct _gmac_sg *next;\r
115 };\r
116 \r
117 /** GMAC scatter-gather list */\r
118 struct _gmac_sg_list {\r
119         uint32_t         size;\r
120         struct _gmac_sg *entries;\r
121 };\r
122 \r
123 struct _gmacd_queue {\r
124         uint8_t           *rx_buffer;\r
125         struct _gmac_desc *rx_desc;\r
126         uint16_t           rx_size;\r
127         uint16_t           rx_head;\r
128         gmacd_callback_t   rx_callback;\r
129 \r
130         uint8_t           *tx_buffer;\r
131         struct _gmac_desc *tx_desc;\r
132         uint16_t           tx_size;\r
133         uint16_t           tx_head;\r
134         uint16_t           tx_tail;\r
135         gmacd_callback_t  *tx_callbacks;\r
136 \r
137         gmacd_wakeup_cb_t  tx_wakeup_callback;\r
138         uint16_t           tx_wakeup_threshold;\r
139 };\r
140 \r
141 /**\r
142  * GMAC driver struct.\r
143  */\r
144 struct _gmacd {\r
145         Gmac* gmac; /**< GMAC instance */\r
146         struct _gmacd_queue queues[GMAC_NUM_QUEUES];\r
147 };\r
148 \r
149 /** @}*/\r
150 \r
151 /** \addtogroup gmacd_functions\r
152     @{*/\r
153 \r
154 /*---------------------------------------------------------------------------\r
155  *         GMAC Exported functions\r
156  *---------------------------------------------------------------------------*/\r
157 \r
158 extern void gmacd_configure(struct _gmacd* gmacd, Gmac *pHw, uint8_t enableCAF, uint8_t enableNBC);\r
159 \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
164 \r
165 extern void gmacd_start(struct _gmacd* gmacd);\r
166 \r
167 extern void gmacd_reset(struct _gmacd* gmacd);\r
168 \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
171 \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
174 \r
175 extern uint32_t gmacd_get_tx_load(struct _gmacd* gmacd, uint8_t queue);\r
176 \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
179 \r
180 extern void gmacd_set_rx_callback(struct _gmacd *gmacd, uint8_t queue,\r
181                 gmacd_callback_t callback);\r
182 \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
186 \r
187 /** @}*/\r
188 \r
189 #endif /* _GMACD_H_ */\r