]> git.gir.st - tmk_keyboard.git/blob - tool/mbed/mbed-sdk/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/TARGET_KPSDK_CODE/drivers/enet/fsl_enet_rtcs_adapter.h
Squashed 'tmk_core/' changes from 7967731..b9e0ea0
[tmk_keyboard.git] / tool / mbed / mbed-sdk / libraries / mbed / targets / hal / TARGET_Freescale / TARGET_KPSDK_MCUS / TARGET_KPSDK_CODE / drivers / enet / fsl_enet_rtcs_adapter.h
1 /*
2 * Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without modification,
6 * are permitted provided that the following conditions are met:
7 *
8 * o Redistributions of source code must retain the above copyright notice, this list
9 * of conditions and the following disclaimer.
10 *
11 * o Redistributions in binary form must reproduce the above copyright notice, this
12 * list of conditions and the following disclaimer in the documentation and/or
13 * other materials provided with the distribution.
14 *
15 * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
16 * contributors may be used to endorse or promote products derived from this
17 * software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31 #ifndef __FSL_ENET_RTCS_ADAPTOR_H__
32 #define __FSL_ENET_RTCS_ADAPTOR_H__
33
34 #include "fsl_enet_hal.h"
35
36 #ifndef MBED_NO_ENET
37
38 #ifdef FSL_RTOS_MQX
39 #include "rtcs.h"
40 #include "pcb.h"
41 #endif
42 /*!
43 * @addtogroup enet_rtcs_adaptor
44 * @{
45 */
46
47 /*******************************************************************************
48 * Definitions
49 ******************************************************************************/
50 /*! @brief Definitions of the task parameter*/
51 #ifndef FSL_RTOS_MQX
52 extern unsigned long _RTCSTASK_priority;
53 #endif
54 #define ENET_RECEIVE_TASK_PRIO (1)
55 #define ENET_TASK_STACK_SIZE (800)
56 #define ENET_PCB_NUM (16)
57
58 /*! @brief Definitions of the configuration parameter*/
59 #define ENET_RXBD_NUM (8)
60 #define ENET_TXBD_NUM (4)
61 #define ENET_EXTRXBD_NUM (4)
62 #define ENET_RXBuff_SIZE (kEnetMaxFrameSize)
63 #define ENET_TXBuff_SIZE (kEnetMaxFrameSize)
64 #define ENET_RXRTCSBUFF_NUM (8)
65 #define ENET_RX_BUFFER_ALIGNMENT (16)
66 #define ENET_TX_BUFFER_ALIGNMENT (16)
67 #define ENET_BD_ALIGNMENT (16)
68 #define ENET_RXBuffSizeAlign(n) ENET_ALIGN(n, ENET_RX_BUFFER_ALIGNMENT)
69 #define ENET_TXBuffSizeAlign(n) ENET_ALIGN(n, ENET_TX_BUFFER_ALIGNMENT)
70 #define ENET_MII_CLOCK (2500000L)
71 #if FSL_FEATURE_ENET_SUPPORT_PTP
72 #define ENET_PTP_TXTS_RING_LEN (25)
73 #define ENET_PTP_RXTS_RING_LEN (25)
74 #endif
75
76 /*! @brief Definitions of the error codes */
77 #define ENET_OK (0)
78 #define ENET_ERROR (0xff) /* General ENET error */
79
80 #define ENETERR_INVALID_DEVICE (kStatus_ENET_InvalidDevice) /* Device number out of range */
81 #define ENETERR_INIT_DEVICE (kStatus_ENET_Initialized) /* Device already initialized */
82
83 /*! @brief Definitions of the ENET protocol parameter*/
84 #define ENETPROT_IP 0x0800
85 #define ENETPROT_ARP 0x0806
86 #define ENETPROT_8021Q 0x8100
87 #define ENETPROT_IP6 0x86DD
88 #define ENETPROT_ETHERNET 0x88F7
89 #define ENET_OPT_8023 0x0001
90 #define ENET_OPT_8021QTAG 0x0002
91 #define ENET_SETOPT_8021QPRIO(p) (ENET_OPT_8021QTAG | (((uint_32)(p) & 0x7) << 2))
92 #define ENET_GETOPT_8021QPRIO(f) ((((unsigned int)f) >> 2) & 0x7)
93
94 /*! @brief Definitions of the ENET option macro*/
95 #define ENET_OPTION_HW_TX_IP_CHECKSUM 0x00001000
96 #define ENET_OPTION_HW_TX_PROTOCOL_CHECKSUM 0x00002000
97 #define ENET_OPTION_HW_RX_IP_CHECKSUM 0x00004000
98 #define ENET_OPTION_HW_RX_PROTOCOL_CHECKSUM 0x00008000
99 #define ENET_OPTION_HW_RX_MAC_ERR 0x00010000
100
101 /*! @brief Definitions of the ENET default Mac*/
102 #define ENET_DEFAULT_MAC_ADD { 0x00, 0x00, 0x5E, 0, 0, 0 }
103 #define PCB_MINIMUM_SIZE (sizeof(PCB2))
104 #define PCB_free(pcb_ptr) ((pcb_ptr)->FREE(pcb_ptr))
105
106 /*! @brief Definitions of the macro for byte-swap*/
107 #if SYSTEM_LITTLE_ENDIAN
108 #define RTCS_HTONS(n) BSWAP_16(n)
109 #define RTCS_HTONL(n) BSWAP_32(n)
110 #define RTCS_NTOHS(n) BSWAP_16(n)
111 #define RTCS_NTOHL(n) BSWAP_32(n)
112 #else
113 #define RTCS_HTONS(n) (n)
114 #define RTCS_HTONL(n) (n)
115 #define RTCS_NTOHS(n) (n)
116 #define RTCS_NTOHL(n) (n)
117 #endif
118
119 #ifndef FSL_RTOS_MQX
120 #define htonl(p,x) (((uint_8_ptr)(p))[0] = ((x) >> 24) & 0xFF, \
121 ((uint_8_ptr)(p))[1] = ((x) >> 16) & 0xFF, \
122 ((uint_8_ptr)(p))[2] = ((x) >> 8) & 0xFF, \
123 ((uint_8_ptr)(p))[3] = (x) & 0xFF, \
124 (x))
125
126 #define htons(p,x) (((uint_8_ptr)(p))[0] = ((x) >> 8) & 0xFF, \
127 ((uint_8_ptr)(p))[1] = (x) & 0xFF, \
128 (x))
129
130 #define htonc(p,x) (((uint_8_ptr)(p))[0] = (x) & 0xFF, \
131 (x))
132
133 #define ntohl(p) (\
134 (((uint_32)(((uint_8_ptr)(p))[0])) << 24) | \
135 (((uint_32)(((uint_8_ptr)(p))[1])) << 16) | \
136 (((uint_32)(((uint_8_ptr)(p))[2])) << 8) | \
137 ( (uint_32)(((uint_8_ptr)(p))[3])) \
138 )
139
140 #define ntohs(p) (\
141 (((uint_16)(((uint_8_ptr)(p))[0])) << 8) | \
142 ( (uint_16)(((uint_8_ptr)(p))[1])) \
143 )
144
145 #define ntohc(p) ((uint_8)(((uint_8_ptr)(p))[0]))
146 #endif
147 #define htone(p,x) ((p)[0] = (x)[0], \
148 (p)[1] = (x)[1], \
149 (p)[2] = (x)[2], \
150 (p)[3] = (x)[3], \
151 (p)[4] = (x)[4], \
152 (p)[5] = (x)[5] \
153 )
154
155 #define ntohe(p,x) ((x)[0] = (p)[0] & 0xFF, \
156 (x)[1] = (p)[1] & 0xFF, \
157 (x)[2] = (p)[2] & 0xFF, \
158 (x)[3] = (p)[3] & 0xFF, \
159 (x)[4] = (p)[4] & 0xFF, \
160 (x)[5] = (p)[5] & 0xFF \
161 )
162
163 /*! @brief Definitions of the add to queue*/
164 #define QUEUEADD(head,tail,pcb) \
165 if ((head) == NULL) { \
166 (head) = (pcb); \
167 } else { \
168 (tail)->PRIVATE = (pcb); \
169 } \
170 (tail) = (pcb); \
171 (pcb)->PRIVATE = NULL
172
173 /*! @brief Definitions of the get from queue*/
174 #define QUEUEGET(head,tail,pcb) \
175 (pcb) = (head); \
176 if (head) { \
177 (head) = (head)->PRIVATE; \
178 if ((head) == NULL) { \
179 (tail) = NULL; \
180 } \
181 }
182
183 /*! @brief Definition for ENET six-byte Mac type*/
184 typedef unsigned char _enet_address[6];
185
186 /*! @brief Definition of the IPCFG structure*/
187 typedef void * _enet_handle;
188
189 #ifndef FSL_RTOS_MQX
190 struct pcb;
191 typedef void (* PCB_FREE_FPTR)(struct pcb *);
192 #endif
193
194 /*! @brief Definition of the Ethernet packet header structure*/
195 typedef struct enet_header
196 {
197 _enet_address DEST; /*!< destination Mac address*/
198 _enet_address SOURCE; /*!< source Mac address*/
199 unsigned char TYPE[2]; /*!< protocol type*/
200 } ENET_HEADER, * ENET_HEADER_PTR;
201
202 #ifndef FSL_RTOS_MQX
203
204 /*! @brief Definition of the fragment PCB structure*/
205 typedef struct pcb_fragment
206 {
207 uint32_t LENGTH; /*!< Packet fragment length*/
208 unsigned char *FRAGMENT; /*!< brief Pointer to fragment*/
209 } PCB_FRAGMENT, * PCB_FRAGMENT_PTR;
210
211 /*! @brief Definition of the PCB structure for the RTCS adaptor*/
212 typedef struct pcb
213 {
214 PCB_FREE_FPTR FREE; /*!< Function that frees PCB*/
215 void *PRIVATE; /*!< Private PCB information*/
216 PCB_FRAGMENT FRAG[1]; /*!< Pointer to PCB fragment*/
217 } PCB, * PCB_PTR;
218
219 /*! @brief Definition of the two fragment PCB structure*/
220 typedef struct pcb2
221 {
222 PCB_FREE_FPTR FREE; /*!< Function that frees PCB*/
223 void *PRIVATE; /*!< Private PCB information*/
224 PCB_FRAGMENT FRAG[2]; /*!< Pointers to two PCB fragments*/
225 } PCB2, *PCB2_PTR;
226
227 #endif
228
229 /*! @brief Definition of the two fragment PCB structure*/
230 typedef struct pcb_queue
231 {
232 PCB *pcbHead; /*!< PCB buffer head*/
233 PCB *pcbTail; /*!< PCB buffer tail*/
234 }pcb_queue;
235
236 /*! @brief Definition of the ECB structure, which contains the protocol type and it's related service function*/
237 typedef struct ENETEcbStruct
238 {
239 uint16_t TYPE;
240 void (* SERVICE)(PCB_PTR, void *);
241 void *PRIVATE;
242 struct ENETEcbStruct *NEXT;
243 } enet_ecb_struct_t;
244
245 /*! @brief Definition of the 8022 header*/
246 typedef struct enet_8022_header
247 {
248 uint8_t dsap[1]; /*!< DSAP region*/
249 uint8_t ssap[1]; /*!< SSAP region*/
250 uint8_t command[1]; /*!< Command region*/
251 uint8_t oui[3]; /*!< OUI region*/
252 uint16_t type; /*!< type region*/
253 }enet_8022_header_t, *enet_8022_header_ptr;
254
255 /*! @brief Definition of the common status structure*/
256 typedef struct enet_commom_stats_struct {
257 uint32_t ST_RX_TOTAL; /*!< Total number of received packets*/
258 uint32_t ST_RX_MISSED; /*!< Number of missed packets*/
259 uint32_t ST_RX_DISCARDED; /*!< Discarded a protocol that was not recognized*/
260 uint32_t ST_RX_ERRORS; /*!< Discarded error during reception*/
261 uint32_t ST_TX_TOTAL; /*!< Total number of transmitted packets*/
262 uint32_t ST_TX_MISSED; /*!< Discarded transmit ring full*/
263 uint32_t ST_TX_DISCARDED; /*!< Discarded bad packet*/
264 uint32_t ST_TX_ERRORS; /*!< Error during transmission*/
265 } ENET_COMMON_STATS_STRUCT, * ENET_COMMON_STATS_STRUCT_PTR;
266
267 typedef struct enet_stats {
268 ENET_COMMON_STATS_STRUCT COMMON; /*!< Common status structure*/
269 uint32_t ST_RX_ALIGN; /*!< Frame Alignment error*/
270 uint32_t ST_RX_FCS; /*!< CRC error */
271 uint32_t ST_RX_RUNT; /*!< Runt packet received */
272 uint32_t ST_RX_GIANT; /*!< Giant packet received*/
273 uint32_t ST_RX_LATECOLL; /*!< Late collision */
274 uint32_t ST_RX_OVERRUN; /*!< DMA overrun*/
275 uint32_t ST_TX_SQE; /*!< Heartbeat lost*/
276 uint32_t ST_TX_DEFERRED; /*!< Transmission deferred*/
277 uint32_t ST_TX_LATECOLL; /*!< Late collision*/
278 uint32_t ST_TX_EXCESSCOLL; /*!< Excessive collisions*/
279 uint32_t ST_TX_CARRIER; /*!< Carrier sense lost*/
280 uint32_t ST_TX_UNDERRUN; /*!< DMA underrun*/
281 /* Following stats are collected by the Ethernet driver */
282 uint32_t ST_RX_COPY_SMALL; /*!< Driver had to copy packet */
283 uint32_t ST_RX_COPY_LARGE; /*!< Driver had to copy packet */
284 uint32_t ST_TX_COPY_SMALL; /*!< Driver had to copy packet */
285 uint32_t ST_TX_COPY_LARGE; /*!< Driver had to copy packet */
286 uint32_t RX_FRAGS_EXCEEDED;
287 uint32_t RX_PCBS_EXHAUSTED;
288 uint32_t RX_LARGE_BUFFERS_EXHAUSTED;
289 uint32_t TX_ALIGNED;
290 uint32_t TX_ALL_ALIGNED;
291 #if BSPCFG_ENABLE_ENET_HISTOGRAM
292 uint32_t RX_HISTOGRAM[ENET_HISTOGRAM_ENTRIES];
293 uint32_t TX_HISTOGRAM[ENET_HISTOGRAM_ENTRIES];
294 #endif
295
296 } ENET_STATS, * ENET_STATS_PTR;
297
298 /*******************************************************************************
299 * API
300 ******************************************************************************/
301
302 #if defined(__cplusplus)
303 extern "C" {
304 #endif
305
306 /*!
307 * @name ENET RTCS ADAPTOR
308 * @{
309 */
310
311 /*!
312 * @brief Initializes the ENET device.
313 *
314 * @param device The ENET device number.
315 * @param address The hardware address.
316 * @param flag The flag for upper layer.
317 * @param handle The address pointer for ENET device structure.
318 * @return The execution status.
319 */
320 uint32_t ENET_initialize(uint32_t device, _enet_address address,uint32_t flag, _enet_handle *handle);
321
322 /*!
323 * @brief Opens the ENET device.
324 *
325 * @param handle The address pointer for ENET device structure.
326 * @param type The ENET protocol type.
327 * @param service The service function for type.
328 * @param private The private data for ENET device.
329 * @return The execution status.
330 */
331 uint32_t ENET_open(_enet_handle handle, uint16_t type, void (* service)(PCB_PTR, void *), void *private);
332
333 /*!
334 * @brief Shuts down the ENET device.
335 *
336 * @param handle The address pointer for ENET device structure.
337 * @return The execution status.
338 */
339 uint32_t ENET_shutdown(_enet_handle handle);
340 #if !ENET_RECEIVE_ALL_INTERRUPT
341 /*!
342 * @brief ENET frame receive.
343 *
344 * @param enetIfPtr The address pointer for ENET device structure.
345 */
346 static void ENET_receive(task_param_t param);
347 #endif
348 /*!
349 * @brief ENET frame transmit.
350 *
351 * @param handle The address pointer for ENET device structure.
352 * @param packet The ENET packet buffer.
353 * @param type The ENET protocol type.
354 * @param dest The destination hardware address.
355 * @param flag The flag for upper layer.
356 * @return The execution status.
357 */
358 uint32_t ENET_send(_enet_handle handle, PCB_PTR packet, uint32_t type, _enet_address dest, uint32_t flags) ;
359
360 /*!
361 * @brief The ENET gets the address with the initialized device.
362 *
363 * @param handle The address pointer for ENET device structure.
364 * @param address The destination hardware address.
365 * @return The execution status.
366 */
367 uint32_t ENET_get_address(_enet_handle handle, _enet_address address);
368
369 /*!
370 * @brief The ENET gets the address with an uninitialized device.
371 *
372 * @param handle The address pointer for ENET device structure.
373 * @param value The value to change the last three bytes of hardware.
374 * @param address The destination hardware address.
375 * @return True if the execution status is success else false.
376 */
377 uint32_t ENET_get_mac_address(uint32_t device, uint32_t value, _enet_address address);
378 /*!
379 * @brief The ENET joins a multicast group address.
380 *
381 * @param handle The address pointer for ENET device structure.
382 * @param type The ENET protocol type.
383 * @param address The destination hardware address.
384 * @return The execution status.
385 */
386 uint32_t ENET_join(_enet_handle handle, uint16_t type, _enet_address address);
387
388 /*!
389 * @brief The ENET leaves a multicast group address.
390 *
391 * @param handle The address pointer for ENET device structure.
392 * @param type The ENET protocol type.
393 * @param address The destination hardware address.
394 * @return The execution status.
395 */
396 uint32_t ENET_leave(_enet_handle handle, uint16_t type, _enet_address address);
397 #if BSPCFG_ENABLE_ENET_STATS
398 /*!
399 * @brief The ENET gets the packet statistic.
400 *
401 * @param handle The address pointer for ENET device structure.
402 * @return The statistic.
403 */
404 ENET_STATS_PTR ENET_get_stats(_enet_handle handle);
405 #endif
406 /*!
407 * @brief The ENET gets the link status.
408 *
409 * @param handle The address pointer for ENET device structure.
410 * @return The link status.
411 */
412 bool ENET_link_status(_enet_handle handle);
413
414 /*!
415 * @brief The ENET gets the link speed.
416 *
417 * @param handle The address pointer for ENET device structure.
418 * @return The link speed.
419 */
420 uint32_t ENET_get_speed(_enet_handle handle);
421
422 /*!
423 * @brief The ENET gets the MTU.
424 *
425 * @param handle The address pointer for ENET device structure.
426 * @return The link MTU
427 */
428 uint32_t ENET_get_MTU(_enet_handle handle);
429
430 /*!
431 * @brief Gets the ENET PHY registers.
432 *
433 * @param handle The address pointer for ENET device structure.
434 * @param numRegs The number of registers.
435 * @param regPtr The buffer for data read from PHY registers.
436 * @return True if all numRegs registers are read succeed else false.
437 */
438 bool ENET_phy_registers(_enet_handle handle, uint32_t numRegs, uint32_t *regPtr);
439
440 /*!
441 * @brief Gets ENET options.
442 *
443 * @param handle The address pointer for ENET device structure.
444 * @return ENET options.
445 */
446 uint32_t ENET_get_options(_enet_handle handle);
447
448 /*!
449 * @brief Unregisters a protocol type on an Ethernet channel.
450 *
451 * @param handle The address pointer for ENET device structure.
452 * @return ENET options.
453 */
454 uint32_t ENET_close(_enet_handle handle, uint16_t type);
455
456 /*!
457 * @brief ENET mediactl.
458 *
459 * @param handle The address pointer for ENET device structure.
460 * @param The command ID.
461 * @param The buffer for input or output parameters.
462 * @return ENET options.
463 */
464 uint32_t ENET_mediactl(_enet_handle handle, uint32_t commandId, void *inOutParam);
465
466 /*!
467 * @brief Gets the next ENET device handle address.
468 *
469 * @param handle The address pointer for ENET device structure.
470 * @return The address of next ENET device handle.
471 */
472 _enet_handle ENET_get_next_device_handle(_enet_handle handle);
473
474 /*!
475 * @brief ENET free.
476 *
477 * @param packet The buffer address.
478 */
479 void ENET_free(PCB_PTR packet);
480
481 /*!
482 * @brief ENET error description.
483 *
484 * @param error The ENET error code.
485 * @return The error string.
486 */
487 const char * ENET_strerror(uint32_t error);
488
489
490
491 /* @} */
492
493 #if defined(__cplusplus)
494 }
495 #endif
496
497 /*! @}*/
498
499 #endif /* MBED_NO_ENET */
500
501 #endif /* __FSL_ENET_RTCS_ADAPTOR_H__ */
502 /*******************************************************************************
503 * EOF
504 ******************************************************************************/
505
506
507
508
509
510
511
512
513
Imprint / Impressum