ethernetif.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598
  1. /**
  2. * @file
  3. * Ethernet Interface Skeleton
  4. *
  5. */
  6. /*
  7. * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
  8. * All rights reserved.
  9. *
  10. * Redistribution and use in source and binary forms, with or without modification,
  11. * are permitted provided that the following conditions are met:
  12. *
  13. * 1. Redistributions of source code must retain the above copyright notice,
  14. * this list of conditions and the following disclaimer.
  15. * 2. Redistributions in binary form must reproduce the above copyright notice,
  16. * this list of conditions and the following disclaimer in the documentation
  17. * and/or other materials provided with the distribution.
  18. * 3. The name of the author may not be used to endorse or promote products
  19. * derived from this software without specific prior written permission.
  20. *
  21. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
  22. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  23. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
  24. * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  25. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
  26. * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  27. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  28. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  29. * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
  30. * OF SUCH DAMAGE.
  31. *
  32. * This file is part of the lwIP TCP/IP stack.
  33. *
  34. * Author: Adam Dunkels <adam@sics.se>
  35. *
  36. */
  37. /*
  38. * This file is a skeleton for developing Ethernet network interface
  39. * drivers for lwIP. Add code to the low_level functions and do a
  40. * search-and-replace for the word "ethernetif" to replace it with
  41. * something that better describes your network interface.
  42. */
  43. #include "lwip/opt.h"
  44. #include "lwip/def.h"
  45. #include "lwip/mem.h"
  46. #include "lwip/pbuf.h"
  47. #include "lwip/sys.h"
  48. #include <lwip/stats.h>
  49. #include <lwip/snmp.h>
  50. #include "netif/etharp.h"
  51. #include "netif/ppp/pppoe.h"
  52. #include "err.h"
  53. #include "ethernetif.h"
  54. #include "at32f403a_407_emac.h"
  55. #include <string.h>
  56. /* TCP and ARP timeouts */
  57. volatile int tcp_end_time, arp_end_time;
  58. /* Define those to better describe your network interface. */
  59. #define IFNAME0 'a'
  60. #define IFNAME1 't'
  61. #define EMAC_DMARxDesc_FrameLengthShift 16
  62. /**
  63. * Helper struct to hold private data used to operate your ethernet interface.
  64. * Keeping the ethernet address of the MAC in this struct is not necessary
  65. * as it is already kept in the struct netif.
  66. * But this is only an example, anyway...
  67. */
  68. struct ethernetif
  69. {
  70. struct eth_addr *ethaddr;
  71. /* Add whatever per-interface state that is needed here. */
  72. int unused;
  73. };
  74. /* Forward declarations. */
  75. err_t ethernetif_input(struct netif *netif);
  76. #define EMAC_RXBUFNB 6
  77. #define EMAC_TXBUFNB 4
  78. uint8_t MACaddr[6];
  79. emac_dma_desc_type DMARxDscrTab[EMAC_RXBUFNB], DMATxDscrTab[EMAC_TXBUFNB];/* Ethernet Rx & Tx DMA Descriptors */
  80. uint8_t Rx_Buff[EMAC_RXBUFNB][EMAC_MAX_PACKET_LENGTH], Tx_Buff[EMAC_TXBUFNB][EMAC_MAX_PACKET_LENGTH];/* Ethernet buffers */
  81. extern emac_dma_desc_type *dma_tx_desc_to_set;
  82. extern emac_dma_desc_type *dma_rx_desc_to_get;
  83. typedef struct{
  84. u32 length;
  85. u32 buffer;
  86. emac_dma_desc_type *descriptor;
  87. emac_dma_desc_type *rx_fs_desc;
  88. emac_dma_desc_type *rx_ls_desc;
  89. uint32_t g_seg_count;
  90. }FrameTypeDef;
  91. FrameTypeDef rx_frame;
  92. error_status emac_rxpkt_chainmode(void);
  93. u32 emac_getcurrenttxbuffer(void);
  94. error_status emac_txpkt_chainmode(uint32_t FrameLength);
  95. /**
  96. * Setting the MAC address.
  97. *
  98. * @param netif the already initialized lwip network interface structure
  99. * for this ethernetif
  100. */
  101. void lwip_set_mac_address(uint8_t* macadd)
  102. {
  103. MACaddr[0] = macadd[0];
  104. MACaddr[1] = macadd[1];
  105. MACaddr[2] = macadd[2];
  106. MACaddr[3] = macadd[3];
  107. MACaddr[4] = macadd[4];
  108. MACaddr[5] = macadd[5];
  109. emac_local_address_set(macadd);
  110. }
  111. /**
  112. * In this function, the hardware should be initialized.
  113. * Called from ethernetif_init().
  114. *
  115. * @param netif the already initialized lwip network interface structure
  116. * for this ethernetif
  117. */
  118. static void
  119. low_level_init(struct netif *netif)
  120. {
  121. uint32_t index = 0;
  122. /* set MAC hardware address length */
  123. netif->hwaddr_len = ETHARP_HWADDR_LEN;
  124. /* set MAC hardware address */
  125. netif->hwaddr[0] = MACaddr[0];
  126. netif->hwaddr[1] = MACaddr[1];
  127. netif->hwaddr[2] = MACaddr[2];
  128. netif->hwaddr[3] = MACaddr[3];
  129. netif->hwaddr[4] = MACaddr[4];
  130. netif->hwaddr[5] = MACaddr[5];
  131. /* maximum transfer unit */
  132. netif->mtu = 1500;
  133. /* device capabilities */
  134. /* don't set NETIF_FLAG_ETHARP if this device is not an ethernet one */
  135. netif->flags |= NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP | NETIF_FLAG_LINK_UP;
  136. /* Initialize Tx Descriptors list: Chain Mode */
  137. emac_dma_descriptor_list_address_set(EMAC_DMA_TRANSMIT, DMATxDscrTab, &Tx_Buff[0][0], EMAC_TXBUFNB);
  138. /* Initialize Rx Descriptors list: Chain Mode */
  139. emac_dma_descriptor_list_address_set(EMAC_DMA_RECEIVE, DMARxDscrTab, &Rx_Buff[0][0], EMAC_RXBUFNB);
  140. /* Enable Ethernet Rx interrrupt */
  141. for(index = 0; index < EMAC_RXBUFNB; index ++)
  142. {
  143. emac_dma_rx_desc_interrupt_config(&DMARxDscrTab[index], TRUE);
  144. }
  145. #ifdef CHECKSUM_BY_HARDWARE
  146. for(index = 0; index < EMAC_TXBUFNB; index ++)
  147. {
  148. DMATxDscrTab[index].status |= EMAC_DMATXDESC_CIC_TUI_FULL;
  149. }
  150. #endif
  151. rx_frame.g_seg_count = 0;
  152. /* Enable MAC and DMA transmission and reception */
  153. emac_start();
  154. }
  155. /**
  156. * This function should do the actual transmission of the packet. The packet is
  157. * contained in the pbuf that is passed to the function. This pbuf
  158. * might be chained.
  159. *
  160. * @param netif the lwip network interface structure for this ethernetif
  161. * @param p the MAC packet to send (e.g. IP packet including MAC addresses and type)
  162. * @return ERR_OK if the packet could be sent
  163. * an err_t value if the packet couldn't be sent
  164. *
  165. * @note Returning ERR_MEM here if a DMA queue of your MAC is full can lead to
  166. * strange results. You might consider waiting for space in the DMA queue
  167. * to become availale since the stack doesn't retry to send a packet
  168. * dropped because of memory failure (except for the TCP timers).
  169. */
  170. static err_t
  171. low_level_output(struct netif *netif, struct pbuf *p)
  172. {
  173. struct pbuf *q;
  174. err_t errno;
  175. emac_dma_desc_type *dma_tx_desc;
  176. uint8_t *buffer;
  177. uint32_t length = 0;
  178. uint32_t buffer_offset = 0, payload_offset = 0, copy_count = 0;
  179. dma_tx_desc = dma_tx_desc_to_set;
  180. buffer = (uint8_t *)emac_getcurrenttxbuffer();
  181. /* copy data to buffer */
  182. for(q = p; q != NULL; q = q->next)
  183. {
  184. if((dma_tx_desc->status & EMAC_DMATXDESC_OWN) != RESET)
  185. {
  186. errno = ERR_USE;
  187. goto out_error;
  188. }
  189. copy_count = q->len;
  190. payload_offset = 0;
  191. while((copy_count + buffer_offset) > EMAC_MAX_PACKET_LENGTH)
  192. {
  193. memcpy(buffer + buffer_offset, (uint8_t *)q->payload + payload_offset, (EMAC_MAX_PACKET_LENGTH - buffer_offset));
  194. dma_tx_desc = (emac_dma_desc_type*)dma_tx_desc->buf2nextdescaddr;
  195. if((dma_tx_desc->status & EMAC_DMATXDESC_OWN) != RESET)
  196. {
  197. errno = ERR_USE;
  198. goto out_error;
  199. }
  200. buffer = (uint8_t *)dma_tx_desc->buf1addr;
  201. copy_count = copy_count - (EMAC_MAX_PACKET_LENGTH - buffer_offset);
  202. payload_offset = payload_offset + (EMAC_MAX_PACKET_LENGTH - buffer_offset);
  203. length = length + (EMAC_MAX_PACKET_LENGTH - buffer_offset);
  204. buffer_offset = 0;
  205. }
  206. memcpy(buffer + buffer_offset, (uint8_t *)q->payload + payload_offset, copy_count);
  207. buffer_offset = buffer_offset + copy_count;
  208. length = length + copy_count;
  209. }
  210. emac_txpkt_chainmode(length);
  211. errno = ERR_OK;
  212. out_error:
  213. /* When Tx Buffer unavailable flag is set: clear it and resume transmission */
  214. if(emac_dma_flag_get(EMAC_DMA_TBU_FLAG))
  215. {
  216. /* Clear TBUS ETHERNET DMA flag */
  217. emac_dma_flag_clear(EMAC_DMA_TBU_FLAG);
  218. /* Resume DMA transmission*/
  219. EMAC_DMA->tpd_bit.tpd = 0;
  220. }
  221. return errno;
  222. }
  223. /**
  224. * Should allocate a pbuf and transfer the bytes of the incoming
  225. * packet from the interface into the pbuf.
  226. *
  227. * @param netif the lwip network interface structure for this ethernetif
  228. * @return a pbuf filled with the received packet (including MAC header)
  229. * NULL on memory error
  230. */
  231. static struct pbuf *
  232. low_level_input(struct netif *netif)
  233. {
  234. struct pbuf *p, *q;
  235. uint32_t len = 0;
  236. emac_dma_desc_type *dma_rx_desc;
  237. uint8_t *buffer;
  238. uint32_t buffer_offset, payload_offset = 0, copy_count = 0;
  239. uint32_t index = 0;
  240. p = NULL;
  241. if(emac_rxpkt_chainmode() != SUCCESS)
  242. {
  243. return NULL;
  244. }
  245. /* Obtain the size of the packet and put it into the "len"
  246. variable. */
  247. len = rx_frame.length;
  248. buffer = (uint8_t *)rx_frame.buffer;
  249. /* We allocate a pbuf chain of pbufs from the pool. */
  250. if(len > 0)
  251. {
  252. p = pbuf_alloc(PBUF_RAW, len, PBUF_POOL);
  253. }
  254. if(p != NULL)
  255. {
  256. dma_rx_desc = rx_frame.rx_fs_desc;
  257. buffer_offset = 0;
  258. for (q = p; q != NULL; q = q->next)
  259. {
  260. copy_count = q->len;
  261. payload_offset = 0;
  262. while( (copy_count + buffer_offset) > EMAC_MAX_PACKET_LENGTH )
  263. {
  264. /* copy data to pbuf */
  265. memcpy((uint8_t*)q->payload + payload_offset, buffer + buffer_offset, (EMAC_MAX_PACKET_LENGTH - buffer_offset));
  266. /* point to next descriptor */
  267. dma_rx_desc = (emac_dma_desc_type *)(dma_rx_desc->buf2nextdescaddr);
  268. buffer = (uint8_t *)(dma_rx_desc->buf1addr);
  269. copy_count = copy_count - (EMAC_MAX_PACKET_LENGTH - buffer_offset);
  270. payload_offset = payload_offset + (EMAC_MAX_PACKET_LENGTH - buffer_offset);
  271. buffer_offset = 0;
  272. }
  273. memcpy((uint8_t*)q->payload + payload_offset, (uint8_t*)buffer + buffer_offset, copy_count);
  274. buffer_offset = buffer_offset + copy_count;
  275. }
  276. }
  277. dma_rx_desc = rx_frame.rx_fs_desc;
  278. for(index = 0; index < rx_frame.g_seg_count; index ++)
  279. {
  280. dma_rx_desc->status |= EMAC_DMARXDESC_OWN;
  281. dma_rx_desc = (emac_dma_desc_type*) (dma_rx_desc->buf2nextdescaddr);
  282. }
  283. rx_frame.g_seg_count = 0;
  284. /* When Rx Buffer unavailable flag is set: clear it and resume reception */
  285. if(emac_dma_flag_get(EMAC_DMA_RBU_FLAG))
  286. {
  287. /* Clear RBUS ETHERNET DMA flag */
  288. emac_dma_flag_clear(EMAC_DMA_RBU_FLAG);
  289. /* Resume DMA reception */
  290. EMAC_DMA->rpd_bit.rpd = FALSE;
  291. }
  292. return p;
  293. }
  294. /**
  295. * This function should be called when a packet is ready to be read
  296. * from the interface. It uses the function low_level_input() that
  297. * should handle the actual reception of bytes from the network
  298. * interface. Then the type of the received packet is determined and
  299. * the appropriate input function is called.
  300. *
  301. * @param netif the lwip network interface structure for this ethernetif
  302. */
  303. err_t
  304. ethernetif_input(struct netif *netif)
  305. {
  306. err_t err;
  307. struct pbuf *p;
  308. /* move received packet into a new pbuf */
  309. p = low_level_input(netif);
  310. /* no packet could be read, silently ignore this */
  311. if (p == NULL) return ERR_MEM;
  312. err = netif->input(p, netif);
  313. if (err != ERR_OK)
  314. {
  315. LWIP_DEBUGF(NETIF_DEBUG, ("ethernetif_input: IP input error\n"));
  316. pbuf_free(p);
  317. p = NULL;
  318. }
  319. return err;
  320. }
  321. /**
  322. * Should be called at the beginning of the program to set up the
  323. * network interface. It calls the function low_level_init() to do the
  324. * actual setup of the hardware.
  325. *
  326. * This function should be passed as a parameter to netif_add().
  327. *
  328. * @param netif the lwip network interface structure for this ethernetif
  329. * @return ERR_OK if the loopif is initialized
  330. * ERR_MEM if private data couldn't be allocated
  331. * any other err_t on error
  332. */
  333. err_t
  334. ethernetif_init(struct netif *netif)
  335. {
  336. struct ethernetif *ethernetif;
  337. LWIP_ASSERT("netif != NULL", (netif != NULL));
  338. ethernetif = mem_malloc(sizeof(struct ethernetif));
  339. if (ethernetif == NULL)
  340. {
  341. LWIP_DEBUGF(NETIF_DEBUG, ("ethernetif_init: out of memory\n"));
  342. return ERR_MEM;
  343. }
  344. #if LWIP_NETIF_HOSTNAME
  345. /* Initialize interface hostname */
  346. netif->hostname = "lwip";
  347. #endif /* LWIP_NETIF_HOSTNAME */
  348. /*
  349. * Initialize the snmp variables and counters inside the struct netif.
  350. * The last argument should be replaced with your link speed, in units
  351. * of bits per second.
  352. */
  353. NETIF_INIT_SNMP(netif, snmp_ifType_ethernet_csmacd, 100000000);
  354. netif->state = ethernetif;
  355. netif->name[0] = IFNAME0;
  356. netif->name[1] = IFNAME1;
  357. /* We directly use etharp_output() here to save a function call.
  358. * You can instead declare your own function an call etharp_output()
  359. * from it if you have to do some checks before sending (e.g. if link
  360. * is available...) */
  361. netif->output = etharp_output;
  362. netif->linkoutput = low_level_output;
  363. ethernetif->ethaddr = (struct eth_addr *)&(netif->hwaddr[0]);
  364. /* initialize the hardware */
  365. low_level_init(netif);
  366. return ERR_OK;
  367. }
  368. /*******************************************************************************
  369. * Function Name : emac_rxpkt_chainmode
  370. * Description : Receives a packet.
  371. * Input : None
  372. * Output : None
  373. * Return : ERROR: in case of Tx desc owned by DMA
  374. * SUCCESS: for correct transmission
  375. *******************************************************************************/
  376. error_status emac_rxpkt_chainmode(void)
  377. {
  378. /* Check if the descriptor is owned by the ETHERNET DMA (when set) or CPU (when reset) */
  379. if((dma_rx_desc_to_get->status & EMAC_DMARXDESC_OWN) != (u32)RESET)
  380. {
  381. /* return error: own bit set */
  382. return ERROR;
  383. }
  384. if((dma_rx_desc_to_get->status & EMAC_DMARXDESC_LS) != (u32)RESET)
  385. {
  386. rx_frame.g_seg_count ++;
  387. if(rx_frame.g_seg_count == 1)
  388. {
  389. rx_frame.rx_fs_desc = dma_rx_desc_to_get;
  390. }
  391. rx_frame.rx_ls_desc = dma_rx_desc_to_get;
  392. rx_frame.length = ((dma_rx_desc_to_get->status & EMAC_DMARXDESC_FL) >> EMAC_DMARxDesc_FrameLengthShift) - 4;
  393. rx_frame.buffer = rx_frame.rx_fs_desc->buf1addr;
  394. /* Selects the next DMA Rx descriptor list for next buffer to read */
  395. dma_rx_desc_to_get = (emac_dma_desc_type*) (dma_rx_desc_to_get->buf2nextdescaddr);
  396. return SUCCESS;
  397. }
  398. else if((dma_rx_desc_to_get->status & EMAC_DMARXDESC_FS) != (u32)RESET)
  399. {
  400. rx_frame.g_seg_count = 1;
  401. rx_frame.rx_fs_desc = dma_rx_desc_to_get;
  402. rx_frame.rx_ls_desc = NULL;
  403. dma_rx_desc_to_get = (emac_dma_desc_type*) (dma_rx_desc_to_get->buf2nextdescaddr);
  404. }
  405. else
  406. {
  407. rx_frame.g_seg_count ++;
  408. dma_rx_desc_to_get = (emac_dma_desc_type*) (dma_rx_desc_to_get->buf2nextdescaddr);
  409. }
  410. return ERROR;
  411. }
  412. /*******************************************************************************
  413. * Function Name : emac_txpkt_chainmode
  414. * Description : Transmits a packet, from application buffer, pointed by ppkt.
  415. * Input : - FrameLength: Tx Packet size.
  416. * Output : None
  417. * Return : ERROR: in case of Tx desc owned by DMA
  418. * SUCCESS: for correct transmission
  419. *******************************************************************************/
  420. error_status emac_txpkt_chainmode(uint32_t FrameLength)
  421. {
  422. uint32_t buf_cnt = 0, index = 0;
  423. /* Check if the descriptor is owned by the ETHERNET DMA (when set) or CPU (when reset) */
  424. if((dma_tx_desc_to_set->status & EMAC_DMATXDESC_OWN) != (u32)RESET)
  425. {
  426. /* Return ERROR: OWN bit set */
  427. return ERROR;
  428. }
  429. if(FrameLength == 0)
  430. {
  431. return ERROR;
  432. }
  433. if(FrameLength > EMAC_MAX_PACKET_LENGTH)
  434. {
  435. buf_cnt = FrameLength / EMAC_MAX_PACKET_LENGTH;
  436. if(FrameLength % EMAC_MAX_PACKET_LENGTH)
  437. {
  438. buf_cnt += 1;
  439. }
  440. }
  441. else
  442. {
  443. buf_cnt = 1;
  444. }
  445. if(buf_cnt == 1)
  446. {
  447. /* Setting the last segment and first segment bits (in this case a frame is transmitted in one descriptor) */
  448. dma_tx_desc_to_set->status |= EMAC_DMATXDESC_LS | EMAC_DMATXDESC_FS;
  449. /* Setting the Frame Length: bits[12:0] */
  450. dma_tx_desc_to_set->controlsize = (FrameLength & EMAC_DMATXDESC_TBS1);
  451. /* Set Own bit of the Tx descriptor Status: gives the buffer back to ETHERNET DMA */
  452. dma_tx_desc_to_set->status |= EMAC_DMATXDESC_OWN;
  453. /* Selects the next DMA Tx descriptor list for next buffer to send */
  454. dma_tx_desc_to_set = (emac_dma_desc_type*) (dma_tx_desc_to_set->buf2nextdescaddr);
  455. }
  456. else
  457. {
  458. for(index = 0; index < buf_cnt; index ++)
  459. {
  460. /* clear first and last segments */
  461. dma_tx_desc_to_set->status &= ~(EMAC_DMATXDESC_LS | EMAC_DMATXDESC_FS);
  462. /* set first segments */
  463. if(index == 0)
  464. {
  465. dma_tx_desc_to_set->status |= EMAC_DMATXDESC_FS;
  466. }
  467. /* set size */
  468. dma_tx_desc_to_set->controlsize = (EMAC_MAX_PACKET_LENGTH & EMAC_DMATXDESC_TBS1);
  469. /* set last segments */
  470. if(index == (buf_cnt - 1))
  471. {
  472. dma_tx_desc_to_set->status |= EMAC_DMATXDESC_LS;
  473. dma_tx_desc_to_set->controlsize = ((FrameLength - ((buf_cnt-1) * EMAC_MAX_PACKET_LENGTH)) & EMAC_DMATXDESC_TBS1);
  474. }
  475. /* Set Own bit of the Tx descriptor Status: gives the buffer back to ETHERNET DMA */
  476. dma_tx_desc_to_set->status |= EMAC_DMATXDESC_OWN;
  477. /* Selects the next DMA Tx descriptor list for next buffer to send */
  478. dma_tx_desc_to_set = (emac_dma_desc_type*) (dma_tx_desc_to_set->buf2nextdescaddr);
  479. }
  480. }
  481. /* When Tx Buffer unavailable flag is set: clear it and resume transmission */
  482. if(emac_dma_flag_get(EMAC_DMA_TBU_FLAG))
  483. {
  484. /* Clear TBUS ETHERNET DMA flag */
  485. emac_dma_flag_clear(EMAC_DMA_TBU_FLAG);
  486. /* Resume DMA transmission*/
  487. EMAC_DMA->tpd_bit.tpd = 0;
  488. }
  489. return SUCCESS;
  490. }
  491. /*******************************************************************************
  492. * Function Name : emac_getcurrenttxbuffer
  493. * Description : Return the address of the buffer pointed by the current descritor.
  494. * Input : None
  495. * Output : None
  496. * Return : Buffer address
  497. *******************************************************************************/
  498. u32 emac_getcurrenttxbuffer(void)
  499. {
  500. /* Return Buffer address */
  501. return (dma_tx_desc_to_set->buf1addr);
  502. }