drv_eth.c 59 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430
  1. /*
  2. * File : application.c
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2006, RT-Thread Development Team
  5. *
  6. * The license and distribution terms for this file may be
  7. * found in the file LICENSE in this distribution or at
  8. * http://www.rt-thread.org/license/LICENSE
  9. *
  10. * Change Logs:
  11. * Date Author Notes
  12. * 2017-06-08 tanek first implementation
  13. */
  14. #include <rtthread.h>
  15. #include "board.h"
  16. #include <rtdevice.h>
  17. #ifdef RT_USING_FINSH
  18. #include <finsh.h>
  19. #endif
  20. #include "fsl_enet.h"
  21. #include "fsl_gpio.h"
  22. #include "fsl_iomuxc.h"
  23. #include "fsl_phy.h"
  24. #include "fsl_cache.h"
  25. #ifdef RT_USING_LWIP
  26. #include <netif/ethernetif.h>
  27. #include "lwipopts.h"
  28. #ifdef BOARD_RT1050_ATK
  29. #include "drv_pcf8574.h"
  30. #endif
  31. #define ENET_RXBD_NUM (4)
  32. #define ENET_TXBD_NUM (4)
  33. #define ENET_RXBUFF_SIZE (ENET_FRAME_MAX_FRAMELEN)
  34. #define ENET_TXBUFF_SIZE (ENET_FRAME_MAX_FRAMELEN)
  35. #if defined(BOARD_RT1050_FIRE) || defined(BOARD_RT1050_ATK)
  36. #define PHY_ADDRESS 0x00u
  37. #endif
  38. #if defined(BOARD_RT1050_EVK)
  39. #define PHY_ADDRESS 0x02u
  40. #endif
  41. /* debug option */
  42. //#define ETH_RX_DUMP
  43. //#define ETH_TX_DUMP
  44. #define DBG_ENABLE
  45. #define DBG_SECTION_NAME "ETH"
  46. #define DBG_COLOR
  47. #define DBG_LEVEL DBG_INFO
  48. #include <rtdbg.h>
  49. #define MAX_ADDR_LEN 6
  50. struct rt_imxrt_eth
  51. {
  52. /* inherit from ethernet device */
  53. struct eth_device parent;
  54. enet_handle_t enet_handle;
  55. ENET_Type *enet_base;
  56. enet_data_error_stats_t error_statistic;
  57. rt_uint8_t dev_addr[MAX_ADDR_LEN]; /* hw address */
  58. rt_bool_t tx_is_waiting;
  59. struct rt_semaphore tx_wait;
  60. enet_mii_speed_t speed;
  61. enet_mii_duplex_t duplex;
  62. };
  63. ALIGN(ENET_BUFF_ALIGNMENT) enet_tx_bd_struct_t g_txBuffDescrip[ENET_TXBD_NUM] SECTION("NonCacheable");
  64. ALIGN(ENET_BUFF_ALIGNMENT) rt_uint8_t g_txDataBuff[ENET_TXBD_NUM][RT_ALIGN(ENET_TXBUFF_SIZE, ENET_BUFF_ALIGNMENT)];
  65. ALIGN(ENET_BUFF_ALIGNMENT) enet_rx_bd_struct_t g_rxBuffDescrip[ENET_RXBD_NUM] SECTION("NonCacheable");
  66. ALIGN(ENET_BUFF_ALIGNMENT) rt_uint8_t g_rxDataBuff[ENET_RXBD_NUM][RT_ALIGN(ENET_RXBUFF_SIZE, ENET_BUFF_ALIGNMENT)];
  67. static struct rt_imxrt_eth imxrt_eth_device;
  68. void _enet_rx_callback(struct rt_imxrt_eth *eth)
  69. {
  70. rt_err_t result;
  71. ENET_DisableInterrupts(eth->enet_base, kENET_RxFrameInterrupt);
  72. result = eth_device_ready(&(eth->parent));
  73. if (result != RT_EOK)
  74. rt_kprintf("RX err =%d\n", result);
  75. }
  76. void _enet_tx_callback(struct rt_imxrt_eth *eth)
  77. {
  78. if (eth->tx_is_waiting == RT_TRUE)
  79. {
  80. eth->tx_is_waiting = RT_FALSE;
  81. rt_sem_release(&eth->tx_wait);
  82. }
  83. }
  84. void _enet_callback(ENET_Type *base, enet_handle_t *handle, enet_event_t event, void *userData)
  85. {
  86. switch (event)
  87. {
  88. case kENET_RxEvent:
  89. _enet_rx_callback((struct rt_imxrt_eth *)userData);
  90. break;
  91. case kENET_TxEvent:
  92. _enet_tx_callback((struct rt_imxrt_eth *)userData);
  93. break;
  94. case kENET_ErrEvent:
  95. //rt_kprintf("kENET_ErrEvent\n");
  96. break;
  97. case kENET_WakeUpEvent:
  98. //rt_kprintf("kENET_WakeUpEvent\n");
  99. break;
  100. case kENET_TimeStampEvent:
  101. //rt_kprintf("kENET_TimeStampEvent\n");
  102. break;
  103. case kENET_TimeStampAvailEvent:
  104. //rt_kprintf("kENET_TimeStampAvailEvent \n");
  105. break;
  106. default:
  107. //rt_kprintf("unknow error\n");
  108. break;
  109. }
  110. }
  111. #if defined(BOARD_RT1050_EVK)
  112. static void evk_enet_io_init(void)
  113. {
  114. CLOCK_EnableClock(kCLOCK_Iomuxc); /* iomuxc clock (iomuxc_clk_enable): 0x03u */
  115. IOMUXC_SetPinMux(
  116. IOMUXC_GPIO_AD_B0_09_GPIO1_IO09, /* GPIO_AD_B0_09 is configured as GPIO1_IO09 */
  117. 0U); /* Software Input On Field: Input Path is determined by functionality */
  118. IOMUXC_SetPinMux(
  119. IOMUXC_GPIO_AD_B0_10_GPIO1_IO10, /* GPIO_AD_B0_10 is configured as GPIO1_IO10 */
  120. 0U); /* Software Input On Field: Input Path is determined by functionality */
  121. IOMUXC_SetPinMux(
  122. IOMUXC_GPIO_AD_B0_12_LPUART1_TX, /* GPIO_AD_B0_12 is configured as LPUART1_TX */
  123. 0U); /* Software Input On Field: Input Path is determined by functionality */
  124. IOMUXC_SetPinMux(
  125. IOMUXC_GPIO_AD_B0_13_LPUART1_RX, /* GPIO_AD_B0_13 is configured as LPUART1_RX */
  126. 0U); /* Software Input On Field: Input Path is determined by functionality */
  127. IOMUXC_SetPinMux(
  128. IOMUXC_GPIO_B1_04_ENET_RX_DATA00, /* GPIO_B1_04 is configured as ENET_RX_DATA00 */
  129. 0U); /* Software Input On Field: Input Path is determined by functionality */
  130. IOMUXC_SetPinMux(
  131. IOMUXC_GPIO_B1_05_ENET_RX_DATA01, /* GPIO_B1_05 is configured as ENET_RX_DATA01 */
  132. 0U); /* Software Input On Field: Input Path is determined by functionality */
  133. IOMUXC_SetPinMux(
  134. IOMUXC_GPIO_B1_06_ENET_RX_EN, /* GPIO_B1_06 is configured as ENET_RX_EN */
  135. 0U); /* Software Input On Field: Input Path is determined by functionality */
  136. IOMUXC_SetPinMux(
  137. IOMUXC_GPIO_B1_07_ENET_TX_DATA00, /* GPIO_B1_07 is configured as ENET_TX_DATA00 */
  138. 0U); /* Software Input On Field: Input Path is determined by functionality */
  139. IOMUXC_SetPinMux(
  140. IOMUXC_GPIO_B1_08_ENET_TX_DATA01, /* GPIO_B1_08 is configured as ENET_TX_DATA01 */
  141. 0U); /* Software Input On Field: Input Path is determined by functionality */
  142. IOMUXC_SetPinMux(
  143. IOMUXC_GPIO_B1_09_ENET_TX_EN, /* GPIO_B1_09 is configured as ENET_TX_EN */
  144. 0U); /* Software Input On Field: Input Path is determined by functionality */
  145. IOMUXC_SetPinMux(
  146. IOMUXC_GPIO_B1_10_ENET_REF_CLK, /* GPIO_B1_10 is configured as ENET_REF_CLK */
  147. 1U); /* Software Input On Field: Force input path of pad GPIO_B1_10 */
  148. IOMUXC_SetPinMux(
  149. IOMUXC_GPIO_B1_11_ENET_RX_ER, /* GPIO_B1_11 is configured as ENET_RX_ER */
  150. 0U); /* Software Input On Field: Input Path is determined by functionality */
  151. IOMUXC_SetPinMux(
  152. IOMUXC_GPIO_EMC_40_ENET_MDC, /* GPIO_EMC_40 is configured as ENET_MDC */
  153. 0U); /* Software Input On Field: Input Path is determined by functionality */
  154. IOMUXC_SetPinMux(
  155. IOMUXC_GPIO_EMC_41_ENET_MDIO, /* GPIO_EMC_41 is configured as ENET_MDIO */
  156. 0U); /* Software Input On Field: Input Path is determined by functionality */
  157. IOMUXC_SetPinConfig(
  158. IOMUXC_GPIO_AD_B0_09_GPIO1_IO09, /* GPIO_AD_B0_09 PAD functional properties : */
  159. 0xB0A9u); /* Slew Rate Field: Fast Slew Rate
  160. Drive Strength Field: R0/5
  161. Speed Field: medium(100MHz)
  162. Open Drain Enable Field: Open Drain Disabled
  163. Pull / Keep Enable Field: Pull/Keeper Enabled
  164. Pull / Keep Select Field: Pull
  165. Pull Up / Down Config. Field: 100K Ohm Pull Up
  166. Hyst. Enable Field: Hysteresis Disabled */
  167. IOMUXC_SetPinConfig(
  168. IOMUXC_GPIO_AD_B0_10_GPIO1_IO10, /* GPIO_AD_B0_10 PAD functional properties : */
  169. 0xB0A9u); /* Slew Rate Field: Fast Slew Rate
  170. Drive Strength Field: R0/5
  171. Speed Field: medium(100MHz)
  172. Open Drain Enable Field: Open Drain Disabled
  173. Pull / Keep Enable Field: Pull/Keeper Enabled
  174. Pull / Keep Select Field: Pull
  175. Pull Up / Down Config. Field: 100K Ohm Pull Up
  176. Hyst. Enable Field: Hysteresis Disabled */
  177. IOMUXC_SetPinConfig(
  178. IOMUXC_GPIO_AD_B0_12_LPUART1_TX, /* GPIO_AD_B0_12 PAD functional properties : */
  179. 0x10B0u); /* Slew Rate Field: Slow Slew Rate
  180. Drive Strength Field: R0/6
  181. Speed Field: medium(100MHz)
  182. Open Drain Enable Field: Open Drain Disabled
  183. Pull / Keep Enable Field: Pull/Keeper Enabled
  184. Pull / Keep Select Field: Keeper
  185. Pull Up / Down Config. Field: 100K Ohm Pull Down
  186. Hyst. Enable Field: Hysteresis Disabled */
  187. IOMUXC_SetPinConfig(
  188. IOMUXC_GPIO_AD_B0_13_LPUART1_RX, /* GPIO_AD_B0_13 PAD functional properties : */
  189. 0x10B0u); /* Slew Rate Field: Slow Slew Rate
  190. Drive Strength Field: R0/6
  191. Speed Field: medium(100MHz)
  192. Open Drain Enable Field: Open Drain Disabled
  193. Pull / Keep Enable Field: Pull/Keeper Enabled
  194. Pull / Keep Select Field: Keeper
  195. Pull Up / Down Config. Field: 100K Ohm Pull Down
  196. Hyst. Enable Field: Hysteresis Disabled */
  197. IOMUXC_SetPinConfig(
  198. IOMUXC_GPIO_B1_04_ENET_RX_DATA00, /* GPIO_B1_04 PAD functional properties : */
  199. 0xB0E9u); /* Slew Rate Field: Fast Slew Rate
  200. Drive Strength Field: R0/5
  201. Speed Field: max(200MHz)
  202. Open Drain Enable Field: Open Drain Disabled
  203. Pull / Keep Enable Field: Pull/Keeper Enabled
  204. Pull / Keep Select Field: Pull
  205. Pull Up / Down Config. Field: 100K Ohm Pull Up
  206. Hyst. Enable Field: Hysteresis Disabled */
  207. IOMUXC_SetPinConfig(
  208. IOMUXC_GPIO_B1_05_ENET_RX_DATA01, /* GPIO_B1_05 PAD functional properties : */
  209. 0xB0E9u); /* Slew Rate Field: Fast Slew Rate
  210. Drive Strength Field: R0/5
  211. Speed Field: max(200MHz)
  212. Open Drain Enable Field: Open Drain Disabled
  213. Pull / Keep Enable Field: Pull/Keeper Enabled
  214. Pull / Keep Select Field: Pull
  215. Pull Up / Down Config. Field: 100K Ohm Pull Up
  216. Hyst. Enable Field: Hysteresis Disabled */
  217. IOMUXC_SetPinConfig(
  218. IOMUXC_GPIO_B1_06_ENET_RX_EN, /* GPIO_B1_06 PAD functional properties : */
  219. 0xB0E9u); /* Slew Rate Field: Fast Slew Rate
  220. Drive Strength Field: R0/5
  221. Speed Field: max(200MHz)
  222. Open Drain Enable Field: Open Drain Disabled
  223. Pull / Keep Enable Field: Pull/Keeper Enabled
  224. Pull / Keep Select Field: Pull
  225. Pull Up / Down Config. Field: 100K Ohm Pull Up
  226. Hyst. Enable Field: Hysteresis Disabled */
  227. IOMUXC_SetPinConfig(
  228. IOMUXC_GPIO_B1_07_ENET_TX_DATA00, /* GPIO_B1_07 PAD functional properties : */
  229. 0xB0E9u); /* Slew Rate Field: Fast Slew Rate
  230. Drive Strength Field: R0/5
  231. Speed Field: max(200MHz)
  232. Open Drain Enable Field: Open Drain Disabled
  233. Pull / Keep Enable Field: Pull/Keeper Enabled
  234. Pull / Keep Select Field: Pull
  235. Pull Up / Down Config. Field: 100K Ohm Pull Up
  236. Hyst. Enable Field: Hysteresis Disabled */
  237. IOMUXC_SetPinConfig(
  238. IOMUXC_GPIO_B1_08_ENET_TX_DATA01, /* GPIO_B1_08 PAD functional properties : */
  239. 0xB0E9u); /* Slew Rate Field: Fast Slew Rate
  240. Drive Strength Field: R0/5
  241. Speed Field: max(200MHz)
  242. Open Drain Enable Field: Open Drain Disabled
  243. Pull / Keep Enable Field: Pull/Keeper Enabled
  244. Pull / Keep Select Field: Pull
  245. Pull Up / Down Config. Field: 100K Ohm Pull Up
  246. Hyst. Enable Field: Hysteresis Disabled */
  247. IOMUXC_SetPinConfig(
  248. IOMUXC_GPIO_B1_09_ENET_TX_EN, /* GPIO_B1_09 PAD functional properties : */
  249. 0xB0E9u); /* Slew Rate Field: Fast Slew Rate
  250. Drive Strength Field: R0/5
  251. Speed Field: max(200MHz)
  252. Open Drain Enable Field: Open Drain Disabled
  253. Pull / Keep Enable Field: Pull/Keeper Enabled
  254. Pull / Keep Select Field: Pull
  255. Pull Up / Down Config. Field: 100K Ohm Pull Up
  256. Hyst. Enable Field: Hysteresis Disabled */
  257. IOMUXC_SetPinConfig(
  258. IOMUXC_GPIO_B1_10_ENET_REF_CLK, /* GPIO_B1_10 PAD functional properties : */
  259. 0x31u); /* Slew Rate Field: Fast Slew Rate
  260. Drive Strength Field: R0/6
  261. Speed Field: low(50MHz)
  262. Open Drain Enable Field: Open Drain Disabled
  263. Pull / Keep Enable Field: Pull/Keeper Disabled
  264. Pull / Keep Select Field: Keeper
  265. Pull Up / Down Config. Field: 100K Ohm Pull Down
  266. Hyst. Enable Field: Hysteresis Disabled */
  267. IOMUXC_SetPinConfig(
  268. IOMUXC_GPIO_B1_11_ENET_RX_ER, /* GPIO_B1_11 PAD functional properties : */
  269. 0xB0E9u); /* Slew Rate Field: Fast Slew Rate
  270. Drive Strength Field: R0/5
  271. Speed Field: max(200MHz)
  272. Open Drain Enable Field: Open Drain Disabled
  273. Pull / Keep Enable Field: Pull/Keeper Enabled
  274. Pull / Keep Select Field: Pull
  275. Pull Up / Down Config. Field: 100K Ohm Pull Up
  276. Hyst. Enable Field: Hysteresis Disabled */
  277. IOMUXC_SetPinConfig(
  278. IOMUXC_GPIO_EMC_40_ENET_MDC, /* GPIO_EMC_40 PAD functional properties : */
  279. 0xB0E9u); /* Slew Rate Field: Fast Slew Rate
  280. Drive Strength Field: R0/5
  281. Speed Field: max(200MHz)
  282. Open Drain Enable Field: Open Drain Disabled
  283. Pull / Keep Enable Field: Pull/Keeper Enabled
  284. Pull / Keep Select Field: Pull
  285. Pull Up / Down Config. Field: 100K Ohm Pull Up
  286. Hyst. Enable Field: Hysteresis Disabled */
  287. IOMUXC_SetPinConfig(
  288. IOMUXC_GPIO_EMC_41_ENET_MDIO, /* GPIO_EMC_41 PAD functional properties : */
  289. 0xB829u); /* Slew Rate Field: Fast Slew Rate
  290. Drive Strength Field: R0/5
  291. Speed Field: low(50MHz)
  292. Open Drain Enable Field: Open Drain Enabled
  293. Pull / Keep Enable Field: Pull/Keeper Enabled
  294. Pull / Keep Select Field: Pull
  295. Pull Up / Down Config. Field: 100K Ohm Pull Up
  296. Hyst. Enable Field: Hysteresis Disabled */
  297. }
  298. #endif
  299. #ifdef BOARD_RT1050_ATK
  300. static void atk_enet_io_init(void)
  301. {
  302. CLOCK_EnableClock(kCLOCK_Iomuxc); /* iomuxc clock (iomuxc_clk_enable): 0x03u */
  303. IOMUXC_SetPinMux(
  304. IOMUXC_GPIO_B1_04_ENET_RX_DATA00, /* GPIO_B1_04 is configured as ENET_RX_DATA00 */
  305. 0U); /* Software Input On Field: Input Path is determined by functionality */
  306. IOMUXC_SetPinMux(
  307. IOMUXC_GPIO_B1_05_ENET_RX_DATA01, /* GPIO_B1_05 is configured as ENET_RX_DATA01 */
  308. 0U); /* Software Input On Field: Input Path is determined by functionality */
  309. IOMUXC_SetPinMux(
  310. IOMUXC_GPIO_B1_06_ENET_RX_EN, /* GPIO_B1_06 is configured as ENET_RX_EN */
  311. 0U); /* Software Input On Field: Input Path is determined by functionality */
  312. IOMUXC_SetPinMux(
  313. IOMUXC_GPIO_B1_07_ENET_TX_DATA00, /* GPIO_B1_07 is configured as ENET_TX_DATA00 */
  314. 0U); /* Software Input On Field: Input Path is determined by functionality */
  315. IOMUXC_SetPinMux(
  316. IOMUXC_GPIO_B1_08_ENET_TX_DATA01, /* GPIO_B1_08 is configured as ENET_TX_DATA01 */
  317. 0U); /* Software Input On Field: Input Path is determined by functionality */
  318. IOMUXC_SetPinMux(
  319. IOMUXC_GPIO_B1_09_ENET_TX_EN, /* GPIO_B1_09 is configured as ENET_TX_EN */
  320. 0U); /* Software Input On Field: Input Path is determined by functionality */
  321. IOMUXC_SetPinMux(
  322. IOMUXC_GPIO_B1_10_ENET_REF_CLK, /* GPIO_B1_10 is configured as ENET_REF_CLK */
  323. 1U); /* Software Input On Field: Force input path of pad GPIO_B1_10 */
  324. IOMUXC_SetPinMux(
  325. IOMUXC_GPIO_B1_14_ENET_MDC, /* GPIO_EMC_40 is configured as ENET_MDC */
  326. 0); /* Software Input On Field: Input Path is determined by functionality */
  327. IOMUXC_SetPinMux(
  328. IOMUXC_GPIO_B1_15_ENET_MDIO, /* GPIO_EMC_41 is configured as ENET_MDIO */
  329. 0); /* Software Input On Field: Input Path is determined by functionality */
  330. IOMUXC_SetPinConfig(
  331. IOMUXC_GPIO_B1_04_ENET_RX_DATA00, /* GPIO_B1_04 PAD functional properties : */
  332. 0x110F9);
  333. IOMUXC_SetPinConfig(
  334. IOMUXC_GPIO_B1_05_ENET_RX_DATA01, /* GPIO_B1_05 PAD functional properties : */
  335. 0x110F9);
  336. IOMUXC_SetPinConfig(
  337. IOMUXC_GPIO_B1_06_ENET_RX_EN, /* GPIO_B1_06 PAD functional properties : */
  338. 0x110F9);
  339. IOMUXC_SetPinConfig(
  340. IOMUXC_GPIO_B1_07_ENET_TX_DATA00, /* GPIO_B1_07 PAD functional properties : */
  341. 0x110F9);
  342. IOMUXC_SetPinConfig(
  343. IOMUXC_GPIO_B1_08_ENET_TX_DATA01, /* GPIO_B1_08 PAD functional properties : */
  344. 0x110F9);
  345. IOMUXC_SetPinConfig(
  346. IOMUXC_GPIO_B1_09_ENET_TX_EN, /* GPIO_B1_09 PAD functional properties : */
  347. 0x110F9);
  348. IOMUXC_SetPinConfig(
  349. IOMUXC_GPIO_B1_10_ENET_REF_CLK, /* GPIO_B1_10 PAD functional properties : */
  350. 0x110F9);
  351. IOMUXC_SetPinConfig(
  352. IOMUXC_GPIO_B1_14_ENET_MDC,
  353. 0x110F9);
  354. IOMUXC_SetPinConfig(
  355. IOMUXC_GPIO_B1_15_ENET_MDIO,
  356. 0x110F9);
  357. IOMUXC_EnableMode(IOMUXC_GPR, kIOMUXC_GPR_ENET1TxClkOutputDir, true);
  358. IOMUXC_GPR->GPR1 |= 1 << 23;
  359. }
  360. #endif
  361. #ifdef BOARD_RT1050_FIRE
  362. static void fire_enet_io_init(void)
  363. {
  364. CLOCK_EnableClock(kCLOCK_Iomuxc); /* iomuxc clock (iomuxc_clk_enable): 0x03u */
  365. IOMUXC_SetPinMux(
  366. IOMUXC_GPIO_AD_B0_09_GPIO1_IO09, /* GPIO_AD_B0_09 is configured as GPIO1_IO09 */
  367. 0U); /* Software Input On Field: Input Path is determined by functionality */
  368. IOMUXC_SetPinMux(
  369. IOMUXC_GPIO_AD_B0_10_GPIO1_IO10, /* GPIO_AD_B0_10 is configured as GPIO1_IO10 */
  370. 0U); /* Software Input On Field: Input Path is determined by functionality */
  371. IOMUXC_SetPinMux(
  372. IOMUXC_GPIO_AD_B0_12_LPUART1_TX, /* GPIO_AD_B0_12 is configured as LPUART1_TX */
  373. 0U); /* Software Input On Field: Input Path is determined by functionality */
  374. IOMUXC_SetPinMux(
  375. IOMUXC_GPIO_AD_B0_13_LPUART1_RX, /* GPIO_AD_B0_13 is configured as LPUART1_RX */
  376. 0U); /* Software Input On Field: Input Path is determined by functionality */
  377. IOMUXC_SetPinMux(
  378. IOMUXC_GPIO_B1_11_ENET_RX_ER, /* GPIO_B1_11 is configured as ENET_RX_ER */
  379. 0U); /* Software Input On Field: Input Path is determined by functionality */
  380. IOMUXC_SetPinMux(
  381. IOMUXC_GPIO_B1_04_ENET_RX_DATA00, /* GPIO_B1_04 is configured as ENET_RX_DATA00 */
  382. 0U); /* Software Input On Field: Input Path is determined by functionality */
  383. IOMUXC_SetPinMux(
  384. IOMUXC_GPIO_B1_05_ENET_RX_DATA01, /* GPIO_B1_05 is configured as ENET_RX_DATA01 */
  385. 0U); /* Software Input On Field: Input Path is determined by functionality */
  386. IOMUXC_SetPinMux(
  387. IOMUXC_GPIO_B1_06_ENET_RX_EN, /* GPIO_B1_06 is configured as ENET_RX_EN */
  388. 0U); /* Software Input On Field: Input Path is determined by functionality */
  389. IOMUXC_SetPinMux(
  390. IOMUXC_GPIO_B1_07_ENET_TX_DATA00, /* GPIO_B1_07 is configured as ENET_TX_DATA00 */
  391. 0U); /* Software Input On Field: Input Path is determined by functionality */
  392. IOMUXC_SetPinMux(
  393. IOMUXC_GPIO_B1_08_ENET_TX_DATA01, /* GPIO_B1_08 is configured as ENET_TX_DATA01 */
  394. 0U); /* Software Input On Field: Input Path is determined by functionality */
  395. IOMUXC_SetPinMux(
  396. IOMUXC_GPIO_B1_09_ENET_TX_EN, /* GPIO_B1_09 is configured as ENET_TX_EN */
  397. 0U); /* Software Input On Field: Input Path is determined by functionality */
  398. IOMUXC_SetPinMux(
  399. IOMUXC_GPIO_B1_10_ENET_REF_CLK, /* GPIO_B1_10 is configured as ENET_REF_CLK */
  400. 1U); /* Software Input On Field: Force input path of pad GPIO_B1_10 */
  401. IOMUXC_SetPinMux(
  402. IOMUXC_GPIO_AD_B1_04_ENET_MDC, /* GPIO_EMC_40 is configured as ENET_MDC */
  403. 0U); /* Software Input On Field: Input Path is determined by functionality */
  404. IOMUXC_SetPinMux(
  405. IOMUXC_GPIO_B1_15_ENET_MDIO, /* GPIO_EMC_41 is configured as ENET_MDIO */
  406. 0U); /* Software Input On Field: Input Path is determined by functionality */
  407. IOMUXC_SetPinConfig(
  408. IOMUXC_GPIO_AD_B0_09_GPIO1_IO09, /* GPIO_AD_B0_09 PAD functional properties : */
  409. 0xB0A9u); /* Slew Rate Field: Fast Slew Rate
  410. Drive Strength Field: R0/5
  411. Speed Field: medium(100MHz)
  412. Open Drain Enable Field: Open Drain Disabled
  413. Pull / Keep Enable Field: Pull/Keeper Enabled
  414. Pull / Keep Select Field: Pull
  415. Pull Up / Down Config. Field: 100K Ohm Pull Up
  416. Hyst. Enable Field: Hysteresis Disabled */
  417. IOMUXC_SetPinConfig(
  418. IOMUXC_GPIO_AD_B0_10_GPIO1_IO10, /* GPIO_AD_B0_10 PAD functional properties : */
  419. 0xB0A9u); /* Slew Rate Field: Fast Slew Rate
  420. Drive Strength Field: R0/5
  421. Speed Field: medium(100MHz)
  422. Open Drain Enable Field: Open Drain Disabled
  423. Pull / Keep Enable Field: Pull/Keeper Enabled
  424. Pull / Keep Select Field: Pull
  425. Pull Up / Down Config. Field: 100K Ohm Pull Up
  426. Hyst. Enable Field: Hysteresis Disabled */
  427. IOMUXC_SetPinConfig(
  428. IOMUXC_GPIO_AD_B0_12_LPUART1_TX, /* GPIO_AD_B0_12 PAD functional properties : */
  429. 0x10B0u); /* Slew Rate Field: Slow Slew Rate
  430. Drive Strength Field: R0/6
  431. Speed Field: medium(100MHz)
  432. Open Drain Enable Field: Open Drain Disabled
  433. Pull / Keep Enable Field: Pull/Keeper Enabled
  434. Pull / Keep Select Field: Keeper
  435. Pull Up / Down Config. Field: 100K Ohm Pull Down
  436. Hyst. Enable Field: Hysteresis Disabled */
  437. IOMUXC_SetPinConfig(
  438. IOMUXC_GPIO_AD_B0_13_LPUART1_RX, /* GPIO_AD_B0_13 PAD functional properties : */
  439. 0x10B0u); /* Slew Rate Field: Slow Slew Rate
  440. Drive Strength Field: R0/6
  441. Speed Field: medium(100MHz)
  442. Open Drain Enable Field: Open Drain Disabled
  443. Pull / Keep Enable Field: Pull/Keeper Enabled
  444. Pull / Keep Select Field: Keeper
  445. Pull Up / Down Config. Field: 100K Ohm Pull Down
  446. Hyst. Enable Field: Hysteresis Disabled */
  447. IOMUXC_SetPinConfig(
  448. IOMUXC_GPIO_B1_04_ENET_RX_DATA00, /* GPIO_B1_04 PAD functional properties : */
  449. 0xB0E9u); /* Slew Rate Field: Fast Slew Rate
  450. Drive Strength Field: R0/5
  451. Speed Field: max(200MHz)
  452. Open Drain Enable Field: Open Drain Disabled
  453. Pull / Keep Enable Field: Pull/Keeper Enabled
  454. Pull / Keep Select Field: Pull
  455. Pull Up / Down Config. Field: 100K Ohm Pull Up
  456. Hyst. Enable Field: Hysteresis Disabled */
  457. IOMUXC_SetPinConfig(
  458. IOMUXC_GPIO_B1_05_ENET_RX_DATA01, /* GPIO_B1_05 PAD functional properties : */
  459. 0xB0E9u); /* Slew Rate Field: Fast Slew Rate
  460. Drive Strength Field: R0/5
  461. Speed Field: max(200MHz)
  462. Open Drain Enable Field: Open Drain Disabled
  463. Pull / Keep Enable Field: Pull/Keeper Enabled
  464. Pull / Keep Select Field: Pull
  465. Pull Up / Down Config. Field: 100K Ohm Pull Up
  466. Hyst. Enable Field: Hysteresis Disabled */
  467. IOMUXC_SetPinConfig(
  468. IOMUXC_GPIO_B1_06_ENET_RX_EN, /* GPIO_B1_06 PAD functional properties : */
  469. 0xB0E9u);
  470. /* Slew Rate Field: Fast Slew Rate
  471. Drive Strength Field: R0/5
  472. Speed Field: max(200MHz)
  473. Open Drain Enable Field: Open Drain Disabled
  474. Pull / Keep Enable Field: Pull/Keeper Enabled
  475. Pull / Keep Select Field: Pull
  476. Pull Up / Down Config. Field: 100K Ohm Pull Up
  477. Hyst. Enable Field: Hysteresis Disabled */
  478. IOMUXC_SetPinConfig(
  479. IOMUXC_GPIO_B1_07_ENET_TX_DATA00, /* GPIO_B1_07 PAD functional properties : */
  480. 0xB0E9u); /* Slew Rate Field: Fast Slew Rate
  481. Drive Strength Field: R0/5
  482. Speed Field: max(200MHz)
  483. Open Drain Enable Field: Open Drain Disabled
  484. Pull / Keep Enable Field: Pull/Keeper Enabled
  485. Pull / Keep Select Field: Pull
  486. Pull Up / Down Config. Field: 100K Ohm Pull Up
  487. Hyst. Enable Field: Hysteresis Disabled */
  488. IOMUXC_SetPinConfig(
  489. IOMUXC_GPIO_B1_08_ENET_TX_DATA01, /* GPIO_B1_08 PAD functional properties : */
  490. 0xB0E9u); /* Slew Rate Field: Fast Slew Rate
  491. Drive Strength Field: R0/5
  492. Speed Field: max(200MHz)
  493. Open Drain Enable Field: Open Drain Disabled
  494. Pull / Keep Enable Field: Pull/Keeper Enabled
  495. Pull / Keep Select Field: Pull
  496. Pull Up / Down Config. Field: 100K Ohm Pull Up
  497. Hyst. Enable Field: Hysteresis Disabled */
  498. IOMUXC_SetPinConfig(
  499. IOMUXC_GPIO_B1_09_ENET_TX_EN, /* GPIO_B1_09 PAD functional properties : */
  500. 0xB0E9u); /* Slew Rate Field: Fast Slew Rate
  501. Drive Strength Field: R0/5
  502. Speed Field: max(200MHz)
  503. Open Drain Enable Field: Open Drain Disabled
  504. Pull / Keep Enable Field: Pull/Keeper Enabled
  505. Pull / Keep Select Field: Pull
  506. Pull Up / Down Config. Field: 100K Ohm Pull Up
  507. Hyst. Enable Field: Hysteresis Disabled */
  508. IOMUXC_SetPinConfig(
  509. IOMUXC_GPIO_B1_10_ENET_REF_CLK, /* GPIO_B1_10 PAD functional properties : */
  510. 0x31u); /* Slew Rate Field: Fast Slew Rate
  511. Drive Strength Field: R0/6
  512. Speed Field: low(50MHz)
  513. Open Drain Enable Field: Open Drain Disabled
  514. Pull / Keep Enable Field: Pull/Keeper Disabled
  515. Pull / Keep Select Field: Keeper
  516. Pull Up / Down Config. Field: 100K Ohm Pull Down
  517. Hyst. Enable Field: Hysteresis Disabled */
  518. IOMUXC_SetPinConfig(
  519. IOMUXC_GPIO_B1_11_ENET_RX_ER, /* GPIO_B1_11 PAD functional properties : */
  520. 0xB0E9u); /* Slew Rate Field: Fast Slew Rate
  521. Drive Strength Field: R0/5
  522. Speed Field: max(200MHz)
  523. Open Drain Enable Field: Open Drain Disabled
  524. Pull / Keep Enable Field: Pull/Keeper Enabled
  525. Pull / Keep Select Field: Pull
  526. Pull Up / Down Config. Field: 100K Ohm Pull Up
  527. Hyst. Enable Field: Hysteresis Disabled */
  528. IOMUXC_SetPinConfig(
  529. IOMUXC_GPIO_AD_B1_04_ENET_MDC,
  530. 0xB0E9u); /* Slew Rate Field: Fast Slew Rate
  531. Drive Strength Field: R0/5
  532. Speed Field: max(200MHz)
  533. Open Drain Enable Field: Open Drain Disabled
  534. Pull / Keep Enable Field: Pull/Keeper Enabled
  535. Pull / Keep Select Field: Pull
  536. Pull Up / Down Config. Field: 100K Ohm Pull Up
  537. Hyst. Enable Field: Hysteresis Disabled */
  538. IOMUXC_SetPinConfig(
  539. IOMUXC_GPIO_B1_15_ENET_MDIO,
  540. 0xB829u); /* Slew Rate Field: Fast Slew Rate
  541. Drive Strength Field: R0/5
  542. Speed Field: low(50MHz)
  543. Open Drain Enable Field: Open Drain Enabled
  544. Pull / Keep Enable Field: Pull/Keeper Enabled
  545. Pull / Keep Select Field: Pull
  546. Pull Up / Down Config. Field: 100K Ohm Pull Up
  547. Hyst. Enable Field: Hysteresis Disabled */
  548. }
  549. #endif
  550. static void _enet_clk_init(void)
  551. {
  552. const clock_enet_pll_config_t config = {true, false, 1};
  553. CLOCK_InitEnetPll(&config);
  554. IOMUXC_EnableMode(IOMUXC_GPR, kIOMUXC_GPR_ENET1TxClkOutputDir, true);
  555. }
  556. static void _delay(void)
  557. {
  558. volatile int i = 1000000;
  559. while (i--)
  560. i = i;
  561. }
  562. static void _enet_phy_reset_by_gpio(void)
  563. {
  564. gpio_pin_config_t gpio_config = {kGPIO_DigitalOutput, 0, kGPIO_NoIntmode};
  565. #ifndef BOARD_RT1050_ATK
  566. GPIO_PinInit(GPIO1, 9, &gpio_config);
  567. #endif
  568. GPIO_PinInit(GPIO1, 10, &gpio_config);
  569. /* pull up the ENET_INT before RESET. */
  570. GPIO_WritePinOutput(GPIO1, 10, 1);
  571. #ifdef BOARD_RT1050_ATK
  572. pcf8574_write_bit(7, 1);
  573. _delay();
  574. pcf8574_write_bit(7, 0);
  575. #else
  576. GPIO_WritePinOutput(GPIO1, 9, 0);
  577. _delay();
  578. GPIO_WritePinOutput(GPIO1, 9, 1);
  579. #endif
  580. }
  581. static void _enet_config(void)
  582. {
  583. enet_config_t config;
  584. uint32_t sysClock;
  585. /* prepare the buffer configuration. */
  586. enet_buffer_config_t buffConfig =
  587. {
  588. ENET_RXBD_NUM,
  589. ENET_TXBD_NUM,
  590. SDK_SIZEALIGN(ENET_RXBUFF_SIZE, ENET_BUFF_ALIGNMENT),
  591. SDK_SIZEALIGN(ENET_TXBUFF_SIZE, ENET_BUFF_ALIGNMENT),
  592. &g_rxBuffDescrip[0],
  593. &g_txBuffDescrip[0],
  594. &g_rxDataBuff[0][0],
  595. &g_txDataBuff[0][0],
  596. };
  597. /* Get default configuration. */
  598. /*
  599. * config.miiMode = kENET_RmiiMode;
  600. * config.miiSpeed = kENET_MiiSpeed100M;
  601. * config.miiDuplex = kENET_MiiFullDuplex;
  602. * config.rxMaxFrameLen = ENET_FRAME_MAX_FRAMELEN;
  603. */
  604. ENET_GetDefaultConfig(&config);
  605. config.interrupt = kENET_TxFrameInterrupt | kENET_RxFrameInterrupt;
  606. //config.interrupt = 0xFFFFFFFF;
  607. config.miiSpeed = imxrt_eth_device.speed;
  608. config.miiDuplex = imxrt_eth_device.duplex;
  609. /* Set SMI to get PHY link status. */
  610. sysClock = CLOCK_GetFreq(kCLOCK_AhbClk);
  611. dbg_log(DBG_LOG, "deinit\n");
  612. ENET_Deinit(imxrt_eth_device.enet_base);
  613. dbg_log(DBG_LOG, "init\n");
  614. ENET_Init(imxrt_eth_device.enet_base, &imxrt_eth_device.enet_handle, &config, &buffConfig, &imxrt_eth_device.dev_addr[0], sysClock);
  615. dbg_log(DBG_LOG, "set call back\n");
  616. ENET_SetCallback(&imxrt_eth_device.enet_handle, _enet_callback, &imxrt_eth_device);
  617. dbg_log(DBG_LOG, "active read\n");
  618. ENET_ActiveRead(imxrt_eth_device.enet_base);
  619. }
  620. #if defined(ETH_RX_DUMP) || defined(ETH_TX_DUMP)
  621. static void packet_dump(const char *msg, const struct pbuf *p)
  622. {
  623. const struct pbuf *q;
  624. rt_uint32_t i, j;
  625. rt_uint8_t *ptr;
  626. rt_kprintf("%s %d byte\n", msg, p->tot_len);
  627. i = 0;
  628. for (q = p; q != RT_NULL; q = q->next)
  629. {
  630. ptr = q->payload;
  631. for (j = 0; j < q->len; j++)
  632. {
  633. if ((i % 8) == 0)
  634. {
  635. rt_kprintf(" ");
  636. }
  637. if ((i % 16) == 0)
  638. {
  639. rt_kprintf("\r\n");
  640. }
  641. rt_kprintf("%02x ", *ptr);
  642. i++;
  643. ptr++;
  644. }
  645. }
  646. rt_kprintf("\n\n");
  647. }
  648. #else
  649. #define packet_dump(...)
  650. #endif /* dump */
  651. /* initialize the interface */
  652. static rt_err_t rt_imxrt_eth_init(rt_device_t dev)
  653. {
  654. dbg_log(DBG_LOG, "rt_imxrt_eth_init...\n");
  655. _enet_config();
  656. return RT_EOK;
  657. }
  658. static rt_err_t rt_imxrt_eth_open(rt_device_t dev, rt_uint16_t oflag)
  659. {
  660. dbg_log(DBG_LOG, "rt_imxrt_eth_open...\n");
  661. return RT_EOK;
  662. }
  663. static rt_err_t rt_imxrt_eth_close(rt_device_t dev)
  664. {
  665. dbg_log(DBG_LOG, "rt_imxrt_eth_close...\n");
  666. return RT_EOK;
  667. }
  668. static rt_size_t rt_imxrt_eth_read(rt_device_t dev, rt_off_t pos, void *buffer, rt_size_t size)
  669. {
  670. dbg_log(DBG_LOG, "rt_imxrt_eth_read...\n");
  671. rt_set_errno(-RT_ENOSYS);
  672. return 0;
  673. }
  674. static rt_size_t rt_imxrt_eth_write(rt_device_t dev, rt_off_t pos, const void *buffer, rt_size_t size)
  675. {
  676. dbg_log(DBG_LOG, "rt_imxrt_eth_write...\n");
  677. rt_set_errno(-RT_ENOSYS);
  678. return 0;
  679. }
  680. static rt_err_t rt_imxrt_eth_control(rt_device_t dev, int cmd, void *args)
  681. {
  682. dbg_log(DBG_LOG, "rt_imxrt_eth_control...\n");
  683. switch (cmd)
  684. {
  685. case NIOCTL_GADDR:
  686. /* get mac address */
  687. if (args) rt_memcpy(args, imxrt_eth_device.dev_addr, 6);
  688. else return -RT_ERROR;
  689. break;
  690. default :
  691. break;
  692. }
  693. return RT_EOK;
  694. }
  695. static void _ENET_ActiveSend(ENET_Type *base, uint32_t ringId)
  696. {
  697. assert(ringId < FSL_FEATURE_ENET_QUEUE);
  698. switch (ringId)
  699. {
  700. case 0:
  701. base->TDAR = ENET_TDAR_TDAR_MASK;
  702. break;
  703. #if FSL_FEATURE_ENET_QUEUE > 1
  704. case kENET_Ring1:
  705. base->TDAR1 = ENET_TDAR1_TDAR_MASK;
  706. break;
  707. case kENET_Ring2:
  708. base->TDAR2 = ENET_TDAR2_TDAR_MASK;
  709. break;
  710. #endif /* FSL_FEATURE_ENET_QUEUE > 1 */
  711. default:
  712. base->TDAR = ENET_TDAR_TDAR_MASK;
  713. break;
  714. }
  715. }
  716. static status_t _ENET_SendFrame(ENET_Type *base, enet_handle_t *handle, const uint8_t *data, uint32_t length)
  717. {
  718. assert(handle);
  719. assert(data);
  720. volatile enet_tx_bd_struct_t *curBuffDescrip;
  721. uint32_t len = 0;
  722. uint32_t sizeleft = 0;
  723. uint32_t address;
  724. /* Check the frame length. */
  725. if (length > ENET_FRAME_MAX_FRAMELEN)
  726. {
  727. return kStatus_ENET_TxFrameOverLen;
  728. }
  729. /* Check if the transmit buffer is ready. */
  730. curBuffDescrip = handle->txBdCurrent[0];
  731. if (curBuffDescrip->control & ENET_BUFFDESCRIPTOR_TX_READY_MASK)
  732. {
  733. return kStatus_ENET_TxFrameBusy;
  734. }
  735. #ifdef ENET_ENHANCEDBUFFERDESCRIPTOR_MODE
  736. bool isPtpEventMessage = false;
  737. /* Check PTP message with the PTP header. */
  738. isPtpEventMessage = ENET_Ptp1588ParseFrame(data, NULL, true);
  739. #endif /* ENET_ENHANCEDBUFFERDESCRIPTOR_MODE */
  740. /* One transmit buffer is enough for one frame. */
  741. if (handle->txBuffSizeAlign[0] >= length)
  742. {
  743. /* Copy data to the buffer for uDMA transfer. */
  744. #if defined(FSL_FEATURE_MEMORY_HAS_ADDRESS_OFFSET) && FSL_FEATURE_MEMORY_HAS_ADDRESS_OFFSET
  745. address = MEMORY_ConvertMemoryMapAddress((uint32_t)curBuffDescrip->buffer,kMEMORY_DMA2Local);
  746. #else
  747. address = (uint32_t)curBuffDescrip->buffer;
  748. #endif /* FSL_FEATURE_MEMORY_HAS_ADDRESS_OFFSET */
  749. pbuf_copy_partial((const struct pbuf *)data, (void *)address, length, 0);
  750. /* Set data length. */
  751. curBuffDescrip->length = length;
  752. #ifdef ENET_ENHANCEDBUFFERDESCRIPTOR_MODE
  753. /* For enable the timestamp. */
  754. if (isPtpEventMessage)
  755. {
  756. curBuffDescrip->controlExtend1 |= ENET_BUFFDESCRIPTOR_TX_TIMESTAMP_MASK;
  757. }
  758. else
  759. {
  760. curBuffDescrip->controlExtend1 &= ~ENET_BUFFDESCRIPTOR_TX_TIMESTAMP_MASK;
  761. }
  762. #endif /* ENET_ENHANCEDBUFFERDESCRIPTOR_MODE */
  763. curBuffDescrip->control |= (ENET_BUFFDESCRIPTOR_TX_READY_MASK | ENET_BUFFDESCRIPTOR_TX_LAST_MASK);
  764. /* Increase the buffer descriptor address. */
  765. if (curBuffDescrip->control & ENET_BUFFDESCRIPTOR_TX_WRAP_MASK)
  766. {
  767. handle->txBdCurrent[0] = handle->txBdBase[0];
  768. }
  769. else
  770. {
  771. handle->txBdCurrent[0]++;
  772. }
  773. #if defined(FSL_SDK_ENABLE_DRIVER_CACHE_CONTROL) && FSL_SDK_ENABLE_DRIVER_CACHE_CONTROL
  774. /* Add the cache clean maintain. */
  775. #if defined(FSL_FEATURE_MEMORY_HAS_ADDRESS_OFFSET) && FSL_FEATURE_MEMORY_HAS_ADDRESS_OFFSET
  776. address = MEMORY_ConvertMemoryMapAddress((uint32_t)curBuffDescrip->buffer,kMEMORY_DMA2Local);
  777. #else
  778. address = (uint32_t)curBuffDescrip->buffer;
  779. #endif /* FSL_FEATURE_MEMORY_HAS_ADDRESS_OFFSET */
  780. DCACHE_CleanByRange(address, length);
  781. #endif /* FSL_SDK_ENABLE_DRIVER_CACHE_CONTROL */
  782. /* Active the transmit buffer descriptor. */
  783. _ENET_ActiveSend(base, 0);
  784. return kStatus_Success;
  785. }
  786. else
  787. {
  788. /* One frame requires more than one transmit buffers. */
  789. do
  790. {
  791. #ifdef ENET_ENHANCEDBUFFERDESCRIPTOR_MODE
  792. /* For enable the timestamp. */
  793. if (isPtpEventMessage)
  794. {
  795. curBuffDescrip->controlExtend1 |= ENET_BUFFDESCRIPTOR_TX_TIMESTAMP_MASK;
  796. }
  797. else
  798. {
  799. curBuffDescrip->controlExtend1 &= ~ENET_BUFFDESCRIPTOR_TX_TIMESTAMP_MASK;
  800. }
  801. #endif /* ENET_ENHANCEDBUFFERDESCRIPTOR_MODE */
  802. /* Increase the buffer descriptor address. */
  803. if (curBuffDescrip->control & ENET_BUFFDESCRIPTOR_TX_WRAP_MASK)
  804. {
  805. handle->txBdCurrent[0] = handle->txBdBase[0];
  806. }
  807. else
  808. {
  809. handle->txBdCurrent[0]++;
  810. }
  811. /* update the size left to be transmit. */
  812. sizeleft = length - len;
  813. if (sizeleft > handle->txBuffSizeAlign[0])
  814. {
  815. /* Data copy. */
  816. #if defined(FSL_FEATURE_MEMORY_HAS_ADDRESS_OFFSET) && FSL_FEATURE_MEMORY_HAS_ADDRESS_OFFSET
  817. address = MEMORY_ConvertMemoryMapAddress((uint32_t)curBuffDescrip->buffer,kMEMORY_DMA2Local);
  818. #else
  819. address = (uint32_t)curBuffDescrip->buffer;
  820. #endif /* FSL_FEATURE_MEMORY_HAS_ADDRESS_OFFSET */
  821. memcpy((void *)address, data + len, handle->txBuffSizeAlign[0]);
  822. /* Data length update. */
  823. curBuffDescrip->length = handle->txBuffSizeAlign[0];
  824. len += handle->txBuffSizeAlign[0];
  825. /* Sets the control flag. */
  826. curBuffDescrip->control &= ~ENET_BUFFDESCRIPTOR_TX_LAST_MASK;
  827. curBuffDescrip->control |= ENET_BUFFDESCRIPTOR_TX_READY_MASK;
  828. /* Active the transmit buffer descriptor*/
  829. _ENET_ActiveSend(base, 0);
  830. }
  831. else
  832. {
  833. #if defined(FSL_FEATURE_MEMORY_HAS_ADDRESS_OFFSET) && FSL_FEATURE_MEMORY_HAS_ADDRESS_OFFSET
  834. address = MEMORY_ConvertMemoryMapAddress((uint32_t)curBuffDescrip->buffer,kMEMORY_DMA2Local);
  835. #else
  836. address = (uint32_t)curBuffDescrip->buffer;
  837. #endif /* FSL_FEATURE_MEMORY_HAS_ADDRESS_OFFSET */
  838. memcpy((void *)address, data + len, sizeleft);
  839. curBuffDescrip->length = sizeleft;
  840. /* Set Last buffer wrap flag. */
  841. curBuffDescrip->control |= ENET_BUFFDESCRIPTOR_TX_READY_MASK | ENET_BUFFDESCRIPTOR_TX_LAST_MASK;
  842. #if defined(FSL_SDK_ENABLE_DRIVER_CACHE_CONTROL) && FSL_SDK_ENABLE_DRIVER_CACHE_CONTROL
  843. /* Add the cache clean maintain. */
  844. #if defined(FSL_FEATURE_MEMORY_HAS_ADDRESS_OFFSET) && FSL_FEATURE_MEMORY_HAS_ADDRESS_OFFSET
  845. address = MEMORY_ConvertMemoryMapAddress((uint32_t)curBuffDescrip->buffer,kMEMORY_DMA2Local);
  846. #else
  847. address = (uint32_t)curBuffDescrip->buffer;
  848. #endif /* FSL_FEATURE_MEMORY_HAS_ADDRESS_OFFSET */
  849. DCACHE_CleanByRange(address, handle->txBuffSizeAlign[0]);
  850. #endif /* FSL_SDK_ENABLE_DRIVER_CACHE_CONTROL */
  851. /* Active the transmit buffer descriptor. */
  852. _ENET_ActiveSend(base, 0);
  853. return kStatus_Success;
  854. }
  855. /* Get the current buffer descriptor address. */
  856. curBuffDescrip = handle->txBdCurrent[0];
  857. }
  858. while (!(curBuffDescrip->control & ENET_BUFFDESCRIPTOR_TX_READY_MASK));
  859. return kStatus_ENET_TxFrameBusy;
  860. }
  861. }
  862. /* ethernet device interface */
  863. /* transmit packet. */
  864. rt_err_t rt_imxrt_eth_tx(rt_device_t dev, struct pbuf *p)
  865. {
  866. rt_err_t result = RT_EOK;
  867. enet_handle_t * enet_handle = &imxrt_eth_device.enet_handle;
  868. RT_ASSERT(p != NULL);
  869. RT_ASSERT(enet_handle != RT_NULL);
  870. dbg_log(DBG_LOG, "rt_imxrt_eth_tx: %d\n", p->len);
  871. #ifdef ETH_TX_DUMP
  872. packet_dump("send", p);
  873. #endif
  874. do
  875. {
  876. result = _ENET_SendFrame(imxrt_eth_device.enet_base, enet_handle, (const uint8_t *)p, p->tot_len);
  877. if (result == kStatus_ENET_TxFrameBusy)
  878. {
  879. imxrt_eth_device.tx_is_waiting = RT_TRUE;
  880. rt_sem_take(&imxrt_eth_device.tx_wait, RT_WAITING_FOREVER);
  881. }
  882. }
  883. while (result == kStatus_ENET_TxFrameBusy);
  884. return RT_EOK;
  885. }
  886. /* reception packet. */
  887. struct pbuf *rt_imxrt_eth_rx(rt_device_t dev)
  888. {
  889. uint32_t length = 0;
  890. status_t status;
  891. struct pbuf *p = RT_NULL;
  892. enet_handle_t *enet_handle = &imxrt_eth_device.enet_handle;
  893. ENET_Type *enet_base = imxrt_eth_device.enet_base;
  894. enet_data_error_stats_t *error_statistic = &imxrt_eth_device.error_statistic;
  895. /* Get the Frame size */
  896. status = ENET_GetRxFrameSize(enet_handle, &length);
  897. /* Call ENET_ReadFrame when there is a received frame. */
  898. if (length != 0)
  899. {
  900. /* Received valid frame. Deliver the rx buffer with the size equal to length. */
  901. p = pbuf_alloc(PBUF_RAW, length, PBUF_POOL);
  902. if (p != NULL)
  903. {
  904. status = ENET_ReadFrame(enet_base, enet_handle, p->payload, length);
  905. if (status == kStatus_Success)
  906. {
  907. #ifdef ETH_RX_DUMP
  908. packet_dump("recv", p);
  909. #endif
  910. return p;
  911. }
  912. else
  913. {
  914. dbg_log(DBG_LOG, " A frame read failed\n");
  915. pbuf_free(p);
  916. }
  917. }
  918. else
  919. {
  920. dbg_log(DBG_LOG, " pbuf_alloc faild\n");
  921. }
  922. }
  923. else if (status == kStatus_ENET_RxFrameError)
  924. {
  925. dbg_log(DBG_WARNING, "ENET_GetRxFrameSize: kStatus_ENET_RxFrameError\n");
  926. /* Update the received buffer when error happened. */
  927. /* Get the error information of the received g_frame. */
  928. ENET_GetRxErrBeforeReadFrame(enet_handle, error_statistic);
  929. /* update the receive buffer. */
  930. ENET_ReadFrame(enet_base, enet_handle, NULL, 0);
  931. }
  932. ENET_EnableInterrupts(enet_base, kENET_RxFrameInterrupt);
  933. return NULL;
  934. }
  935. static void phy_monitor_thread_entry(void *parameter)
  936. {
  937. phy_speed_t speed;
  938. phy_duplex_t duplex;
  939. bool link = false;
  940. _enet_phy_reset_by_gpio();
  941. PHY_Init(imxrt_eth_device.enet_base, PHY_ADDRESS, CLOCK_GetFreq(kCLOCK_AhbClk));
  942. while (1)
  943. {
  944. bool new_link = false;
  945. status_t status = PHY_GetLinkStatus(imxrt_eth_device.enet_base, PHY_ADDRESS, &new_link);
  946. if ((status == kStatus_Success) && (link != new_link))
  947. {
  948. link = new_link;
  949. if (link) // link up
  950. {
  951. PHY_GetLinkSpeedDuplex(imxrt_eth_device.enet_base,
  952. PHY_ADDRESS, &speed, &duplex);
  953. if (kPHY_Speed10M == speed)
  954. {
  955. dbg_log(DBG_LOG, "10M\n");
  956. }
  957. else
  958. {
  959. dbg_log(DBG_LOG, "100M\n");
  960. }
  961. if (kPHY_HalfDuplex == duplex)
  962. {
  963. dbg_log(DBG_LOG, "half dumplex\n");
  964. }
  965. else
  966. {
  967. dbg_log(DBG_LOG, "full dumplex\n");
  968. }
  969. if ((imxrt_eth_device.speed != (enet_mii_speed_t)speed)
  970. || (imxrt_eth_device.duplex != (enet_mii_duplex_t)duplex))
  971. {
  972. imxrt_eth_device.speed = (enet_mii_speed_t)speed;
  973. imxrt_eth_device.duplex = (enet_mii_duplex_t)duplex;
  974. dbg_log(DBG_LOG, "link up, and update eth mode.\n");
  975. rt_imxrt_eth_init((rt_device_t)&imxrt_eth_device);
  976. }
  977. else
  978. {
  979. dbg_log(DBG_LOG, "link up, eth not need re-config.\n");
  980. }
  981. dbg_log(DBG_LOG, "link up.\n");
  982. eth_device_linkchange(&imxrt_eth_device.parent, RT_TRUE);
  983. }
  984. else // link down
  985. {
  986. dbg_log(DBG_LOG, "link down.\n");
  987. eth_device_linkchange(&imxrt_eth_device.parent, RT_FALSE);
  988. }
  989. }
  990. rt_thread_delay(RT_TICK_PER_SECOND * 2);
  991. }
  992. }
  993. static int rt_hw_imxrt_eth_init(void)
  994. {
  995. rt_err_t state;
  996. #ifdef BOARD_RT1050_ATK
  997. atk_enet_io_init();
  998. #endif
  999. #ifdef BOARD_RT1050_FIRE
  1000. fire_enet_io_init();
  1001. #endif
  1002. #if defined(BOARD_RT1050_EVK)
  1003. evk_enet_io_init();
  1004. #endif
  1005. _enet_clk_init();
  1006. /* OUI 00-80-E1 STMICROELECTRONICS. */
  1007. imxrt_eth_device.dev_addr[0] = 0x00;
  1008. imxrt_eth_device.dev_addr[1] = 0x04;
  1009. imxrt_eth_device.dev_addr[2] = 0x9F;
  1010. /* generate MAC addr from 96bit unique ID (only for test). */
  1011. imxrt_eth_device.dev_addr[3] = 0x08;
  1012. imxrt_eth_device.dev_addr[4] = 0x43;
  1013. imxrt_eth_device.dev_addr[5] = 0x75;
  1014. imxrt_eth_device.speed = kENET_MiiSpeed100M;
  1015. imxrt_eth_device.duplex = kENET_MiiFullDuplex;
  1016. imxrt_eth_device.enet_base = ENET;
  1017. imxrt_eth_device.parent.parent.init = rt_imxrt_eth_init;
  1018. imxrt_eth_device.parent.parent.open = rt_imxrt_eth_open;
  1019. imxrt_eth_device.parent.parent.close = rt_imxrt_eth_close;
  1020. imxrt_eth_device.parent.parent.read = rt_imxrt_eth_read;
  1021. imxrt_eth_device.parent.parent.write = rt_imxrt_eth_write;
  1022. imxrt_eth_device.parent.parent.control = rt_imxrt_eth_control;
  1023. imxrt_eth_device.parent.parent.user_data = RT_NULL;
  1024. imxrt_eth_device.parent.eth_rx = rt_imxrt_eth_rx;
  1025. imxrt_eth_device.parent.eth_tx = rt_imxrt_eth_tx;
  1026. dbg_log(DBG_LOG, "sem init: tx_wait\r\n");
  1027. /* init tx semaphore */
  1028. rt_sem_init(&imxrt_eth_device.tx_wait, "tx_wait", 0, RT_IPC_FLAG_FIFO);
  1029. /* register eth device */
  1030. dbg_log(DBG_LOG, "eth_device_init start\r\n");
  1031. state = eth_device_init(&(imxrt_eth_device.parent), "e0");
  1032. if (RT_EOK == state)
  1033. {
  1034. dbg_log(DBG_LOG, "eth_device_init success\r\n");
  1035. }
  1036. else
  1037. {
  1038. dbg_log(DBG_LOG, "eth_device_init faild: %d\r\n", state);
  1039. }
  1040. eth_device_linkchange(&imxrt_eth_device.parent, RT_FALSE);
  1041. /* start phy monitor */
  1042. {
  1043. rt_thread_t tid;
  1044. tid = rt_thread_create("phy",
  1045. phy_monitor_thread_entry,
  1046. RT_NULL,
  1047. 512,
  1048. RT_THREAD_PRIORITY_MAX - 2,
  1049. 2);
  1050. if (tid != RT_NULL)
  1051. rt_thread_startup(tid);
  1052. }
  1053. return state;
  1054. }
  1055. #ifdef BOARD_RT1050_ATK
  1056. INIT_ENV_EXPORT(rt_hw_imxrt_eth_init);
  1057. #else
  1058. INIT_DEVICE_EXPORT(rt_hw_imxrt_eth_init);
  1059. #endif
  1060. #endif
  1061. #ifdef RT_USING_FINSH
  1062. #include <finsh.h>
  1063. void phy_read(uint32_t phyReg)
  1064. {
  1065. uint32_t data;
  1066. status_t status;
  1067. status = PHY_Read(imxrt_eth_device.enet_base, PHY_ADDRESS, phyReg, &data);
  1068. if (kStatus_Success == status)
  1069. {
  1070. rt_kprintf("PHY_Read: %02X --> %08X", phyReg, data);
  1071. }
  1072. else
  1073. {
  1074. rt_kprintf("PHY_Read: %02X --> faild", phyReg);
  1075. }
  1076. }
  1077. void phy_write(uint32_t phyReg, uint32_t data)
  1078. {
  1079. status_t status;
  1080. status = PHY_Write(imxrt_eth_device.enet_base, PHY_ADDRESS, phyReg, data);
  1081. if (kStatus_Success == status)
  1082. {
  1083. rt_kprintf("PHY_Write: %02X --> %08X\n", phyReg, data);
  1084. }
  1085. else
  1086. {
  1087. rt_kprintf("PHY_Write: %02X --> faild\n", phyReg);
  1088. }
  1089. }
  1090. void phy_dump(void)
  1091. {
  1092. uint32_t data;
  1093. status_t status;
  1094. int i;
  1095. for (i = 0; i < 32; i++)
  1096. {
  1097. status = PHY_Read(imxrt_eth_device.enet_base, PHY_ADDRESS, i, &data);
  1098. if (kStatus_Success != status)
  1099. {
  1100. rt_kprintf("phy_dump: %02X --> faild", i);
  1101. break;
  1102. }
  1103. if (i % 8 == 7)
  1104. {
  1105. rt_kprintf("%02X --> %08X ", i, data);
  1106. }
  1107. else
  1108. {
  1109. rt_kprintf("%02X --> %08X\n", i, data);
  1110. }
  1111. }
  1112. }
  1113. void enet_reg_dump(void)
  1114. {
  1115. ENET_Type *enet_base = imxrt_eth_device.enet_base;
  1116. #define DUMP_REG(__REG) \
  1117. rt_kprintf("%s(%08X): %08X\n", #__REG, (uint32_t)&enet_base->__REG, enet_base->__REG)
  1118. DUMP_REG(EIR);
  1119. DUMP_REG(EIMR);
  1120. DUMP_REG(RDAR);
  1121. DUMP_REG(TDAR);
  1122. DUMP_REG(ECR);
  1123. DUMP_REG(MMFR);
  1124. DUMP_REG(MSCR);
  1125. DUMP_REG(MIBC);
  1126. DUMP_REG(RCR);
  1127. DUMP_REG(TCR);
  1128. DUMP_REG(PALR);
  1129. DUMP_REG(PAUR);
  1130. DUMP_REG(OPD);
  1131. DUMP_REG(TXIC);
  1132. DUMP_REG(RXIC);
  1133. DUMP_REG(IAUR);
  1134. DUMP_REG(IALR);
  1135. DUMP_REG(GAUR);
  1136. DUMP_REG(GALR);
  1137. DUMP_REG(TFWR);
  1138. DUMP_REG(RDSR);
  1139. DUMP_REG(TDSR);
  1140. DUMP_REG(MRBR);
  1141. DUMP_REG(RSFL);
  1142. DUMP_REG(RSEM);
  1143. DUMP_REG(RAEM);
  1144. DUMP_REG(RAFL);
  1145. DUMP_REG(TSEM);
  1146. DUMP_REG(TAEM);
  1147. DUMP_REG(TAFL);
  1148. DUMP_REG(TIPG);
  1149. DUMP_REG(FTRL);
  1150. DUMP_REG(TACC);
  1151. DUMP_REG(RACC);
  1152. DUMP_REG(RMON_T_DROP);
  1153. DUMP_REG(RMON_T_PACKETS);
  1154. DUMP_REG(RMON_T_BC_PKT);
  1155. DUMP_REG(RMON_T_MC_PKT);
  1156. DUMP_REG(RMON_T_CRC_ALIGN);
  1157. DUMP_REG(RMON_T_UNDERSIZE);
  1158. DUMP_REG(RMON_T_OVERSIZE);
  1159. DUMP_REG(RMON_T_FRAG);
  1160. DUMP_REG(RMON_T_JAB);
  1161. DUMP_REG(RMON_T_COL);
  1162. DUMP_REG(RMON_T_P64);
  1163. DUMP_REG(RMON_T_P65TO127);
  1164. DUMP_REG(RMON_T_P128TO255);
  1165. DUMP_REG(RMON_T_P256TO511);
  1166. DUMP_REG(RMON_T_P512TO1023);
  1167. DUMP_REG(RMON_T_P1024TO2047);
  1168. DUMP_REG(RMON_T_P_GTE2048);
  1169. DUMP_REG(RMON_T_OCTETS);
  1170. DUMP_REG(IEEE_T_DROP);
  1171. DUMP_REG(IEEE_T_FRAME_OK);
  1172. DUMP_REG(IEEE_T_1COL);
  1173. DUMP_REG(IEEE_T_MCOL);
  1174. DUMP_REG(IEEE_T_DEF);
  1175. DUMP_REG(IEEE_T_LCOL);
  1176. DUMP_REG(IEEE_T_EXCOL);
  1177. DUMP_REG(IEEE_T_MACERR);
  1178. DUMP_REG(IEEE_T_CSERR);
  1179. DUMP_REG(IEEE_T_SQE);
  1180. DUMP_REG(IEEE_T_FDXFC);
  1181. DUMP_REG(IEEE_T_OCTETS_OK);
  1182. DUMP_REG(RMON_R_PACKETS);
  1183. DUMP_REG(RMON_R_BC_PKT);
  1184. DUMP_REG(RMON_R_MC_PKT);
  1185. DUMP_REG(RMON_R_CRC_ALIGN);
  1186. DUMP_REG(RMON_R_UNDERSIZE);
  1187. DUMP_REG(RMON_R_OVERSIZE);
  1188. DUMP_REG(RMON_R_FRAG);
  1189. DUMP_REG(RMON_R_JAB);
  1190. DUMP_REG(RMON_R_RESVD_0);
  1191. DUMP_REG(RMON_R_P64);
  1192. DUMP_REG(RMON_R_P65TO127);
  1193. DUMP_REG(RMON_R_P128TO255);
  1194. DUMP_REG(RMON_R_P256TO511);
  1195. DUMP_REG(RMON_R_P512TO1023);
  1196. DUMP_REG(RMON_R_P1024TO2047);
  1197. DUMP_REG(RMON_R_P_GTE2048);
  1198. DUMP_REG(RMON_R_OCTETS);
  1199. DUMP_REG(IEEE_R_DROP);
  1200. DUMP_REG(IEEE_R_FRAME_OK);
  1201. DUMP_REG(IEEE_R_CRC);
  1202. DUMP_REG(IEEE_R_ALIGN);
  1203. DUMP_REG(IEEE_R_MACERR);
  1204. DUMP_REG(IEEE_R_FDXFC);
  1205. DUMP_REG(IEEE_R_OCTETS_OK);
  1206. DUMP_REG(ATCR);
  1207. DUMP_REG(ATVR);
  1208. DUMP_REG(ATOFF);
  1209. DUMP_REG(ATPER);
  1210. DUMP_REG(ATCOR);
  1211. DUMP_REG(ATINC);
  1212. DUMP_REG(ATSTMP);
  1213. DUMP_REG(TGSR);
  1214. }
  1215. void enet_nvic_tog(void)
  1216. {
  1217. NVIC_SetPendingIRQ(ENET_IRQn);
  1218. }
  1219. void enet_rx_stat(void)
  1220. {
  1221. enet_data_error_stats_t *error_statistic = &imxrt_eth_device.error_statistic;
  1222. #define DUMP_STAT(__VAR) \
  1223. rt_kprintf("%-25s: %08X\n", #__VAR, error_statistic->__VAR);
  1224. DUMP_STAT(statsRxLenGreaterErr);
  1225. DUMP_STAT(statsRxAlignErr);
  1226. DUMP_STAT(statsRxFcsErr);
  1227. DUMP_STAT(statsRxOverRunErr);
  1228. DUMP_STAT(statsRxTruncateErr);
  1229. #ifdef ENET_ENHANCEDBUFFERDESCRIPTOR_MODE
  1230. DUMP_STAT(statsRxProtocolChecksumErr);
  1231. DUMP_STAT(statsRxIpHeadChecksumErr);
  1232. DUMP_STAT(statsRxMacErr);
  1233. DUMP_STAT(statsRxPhyErr);
  1234. DUMP_STAT(statsRxCollisionErr);
  1235. DUMP_STAT(statsTxErr);
  1236. DUMP_STAT(statsTxFrameErr);
  1237. DUMP_STAT(statsTxOverFlowErr);
  1238. DUMP_STAT(statsTxLateCollisionErr);
  1239. DUMP_STAT(statsTxExcessCollisionErr);
  1240. DUMP_STAT(statsTxUnderFlowErr);
  1241. DUMP_STAT(statsTxTsErr);
  1242. #endif
  1243. }
  1244. void enet_buf_info(void)
  1245. {
  1246. int i = 0;
  1247. for (i = 0; i < ENET_RXBD_NUM; i++)
  1248. {
  1249. rt_kprintf("%d: length: %-8d, control: %04X, buffer:%p\n",
  1250. i,
  1251. g_rxBuffDescrip[i].length,
  1252. g_rxBuffDescrip[i].control,
  1253. g_rxBuffDescrip[i].buffer);
  1254. }
  1255. for (i = 0; i < ENET_TXBD_NUM; i++)
  1256. {
  1257. rt_kprintf("%d: length: %-8d, control: %04X, buffer:%p\n",
  1258. i,
  1259. g_txBuffDescrip[i].length,
  1260. g_txBuffDescrip[i].control,
  1261. g_txBuffDescrip[i].buffer);
  1262. }
  1263. }
  1264. FINSH_FUNCTION_EXPORT(phy_read, read phy register);
  1265. FINSH_FUNCTION_EXPORT(phy_write, write phy register);
  1266. FINSH_FUNCTION_EXPORT(phy_dump, dump phy registers);
  1267. FINSH_FUNCTION_EXPORT(enet_reg_dump, dump enet registers);
  1268. FINSH_FUNCTION_EXPORT(enet_nvic_tog, toggle enet nvic pendding bit);
  1269. FINSH_FUNCTION_EXPORT(enet_rx_stat, dump enet rx statistic);
  1270. FINSH_FUNCTION_EXPORT(enet_buf_info, dump enet tx and tx buffer descripter);
  1271. #endif