sam7x_emac.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554
  1. #include <rthw.h>
  2. #include <rtthread.h>
  3. #include <netif/ethernetif.h>
  4. #include "sam7x_emac.h"
  5. #include "AT91SAM7X256.h"
  6. #include "lwipopts.h"
  7. #define MAX_ADDR_LEN 6
  8. #define EMAC_PIO_CFG (AT91C_PB0_ETXCK_EREFCK | \
  9. AT91C_PB1_ETXEN | \
  10. AT91C_PB2_ETX0 | \
  11. AT91C_PB3_ETX1 | \
  12. AT91C_PB4_ECRS | \
  13. AT91C_PB5_ERX0 | \
  14. AT91C_PB6_ERX1 | \
  15. AT91C_PB7_ERXER | \
  16. AT91C_PB8_EMDC | \
  17. AT91C_PB9_EMDIO | \
  18. AT91C_PB10_ETX2 | \
  19. AT91C_PB11_ETX3 | \
  20. AT91C_PB10_ETX2 | \
  21. AT91C_PB13_ERX2 | \
  22. AT91C_PB14_ERX3 | \
  23. AT91C_PB15_ERXDV_ECRSDV| \
  24. AT91C_PB16_ECOL | \
  25. AT91C_PB17_ERXCK)
  26. #define RB_BUFFER_SIZE 8 /* max number of receive buffers */
  27. #define ETH_RX_BUF_SIZE 128
  28. #define TB_BUFFER_SIZE 4
  29. #define ETH_TX_BUF_SIZE (PBUF_POOL_BUFSIZE)
  30. struct rbf_t
  31. {
  32. rt_uint32_t addr;
  33. rt_uint32_t status;
  34. };
  35. static rt_uint32_t current_rb_index; /* current receive buffer index */
  36. static volatile struct rbf_t rb_descriptors[RB_BUFFER_SIZE];
  37. static volatile struct rbf_t tb_descriptors[TB_BUFFER_SIZE];
  38. static rt_uint8_t rx_buf[RB_BUFFER_SIZE][ETH_RX_BUF_SIZE] __attribute__ ((aligned (8)));
  39. static rt_uint8_t tx_buf[TB_BUFFER_SIZE][ETH_TX_BUF_SIZE] __attribute__ ((aligned (8)));
  40. static struct rt_semaphore tx_sem;
  41. struct net_device
  42. {
  43. /* inherit from ethernet device */
  44. struct eth_device parent;
  45. /* interface address info. */
  46. rt_uint8_t dev_addr[MAX_ADDR_LEN]; /* hw address */
  47. };
  48. static struct net_device sam7x_dev_entry;
  49. static struct net_device *sam7x_dev =&sam7x_dev_entry;
  50. AT91PS_EMAC pEmac = AT91C_BASE_EMAC;
  51. rt_inline void write_phy(rt_uint8_t addr, rt_uint32_t value)
  52. {
  53. AT91C_BASE_EMAC->EMAC_MAN = ((0x01<<30) | (2 << 16) | (1 << 28) |
  54. (AT91C_PHY_ADDR << 23) | (addr << 18)) | value;
  55. /* Wait until IDLE bit in Network Status register is cleared */
  56. while (!(AT91C_BASE_EMAC->EMAC_NSR & AT91C_EMAC_IDLE));
  57. }
  58. rt_inline rt_uint32_t read_phy(rt_uint8_t addr)
  59. {
  60. AT91C_BASE_EMAC->EMAC_MAN = (0x01<<30) | (0x02 << 16) | (0x02 << 28) |
  61. (AT91C_PHY_ADDR << 23) | (addr << 18);
  62. /* Wait until IDLE bit in Network Status register is cleared */
  63. while (!(AT91C_BASE_EMAC->EMAC_NSR & AT91C_EMAC_IDLE));
  64. return (AT91C_BASE_EMAC->EMAC_MAN & 0x0000ffff);
  65. }
  66. rt_inline void sam7xether_reset_tx_desc(void)
  67. {
  68. static rt_uint32_t index = 0;
  69. if(tb_descriptors[index].status & TxDESC_STATUS_USED)
  70. {
  71. while(!tb_descriptors[index].status & TxDESC_STATUS_LAST_BUF)
  72. {
  73. index ++;
  74. if(index >= TB_BUFFER_SIZE)index = 0;
  75. tb_descriptors[index].status |= TxDESC_STATUS_USED;
  76. }
  77. index ++;
  78. if(index >= TB_BUFFER_SIZE)index = 0;
  79. }
  80. }
  81. /* interrupt service routing */
  82. static void sam7xether_isr(int irq)
  83. {
  84. /* Variable definitions can be made now. */
  85. volatile rt_uint32_t isr, rsr;
  86. /* get status */
  87. isr = AT91C_BASE_EMAC->EMAC_ISR;
  88. rsr = AT91C_BASE_EMAC->EMAC_RSR;
  89. if( ( isr & AT91C_EMAC_RCOMP ) || ( rsr & AT91C_EMAC_REC ) )
  90. {
  91. rt_err_t result;
  92. /* a frame has been received */
  93. result = eth_device_ready((struct eth_device*)&(sam7x_dev->parent));
  94. RT_ASSERT(result == RT_EOK);
  95. AT91C_BASE_EMAC->EMAC_RSR = AT91C_EMAC_REC;
  96. }
  97. if( isr & AT91C_EMAC_TCOMP )
  98. {
  99. /* A frame has been transmitted. Mark all the buffers as free */
  100. sam7xether_reset_tx_desc();
  101. AT91C_BASE_EMAC->EMAC_TSR = AT91C_EMAC_COMP;
  102. }
  103. }
  104. rt_inline void linksetup(void)
  105. {
  106. rt_uint32_t value;
  107. /* Check if this is a RTL8201 PHY. */
  108. rt_uint16_t id1 = read_phy(PHY_REG_PHYID1);
  109. rt_uint16_t id2 = read_phy(PHY_REG_PHYID2);
  110. if (((id2 << 16) | (id1 & 0xfff0)) == MII_RTL8201_ID)
  111. {
  112. rt_uint32_t tout;
  113. /* Configure the PHY device */
  114. /* Use autonegotiation about the link speed. */
  115. write_phy (PHY_REG_BMCR, PHY_AUTO_NEG);
  116. /* Wait to complete Auto_Negotiation. */
  117. for (tout = 0; tout < 0x100000; tout++)
  118. {
  119. value = read_phy (PHY_REG_BMSR);
  120. if (value & BMSR_ANEGCOMPLETE) break; /* autonegotiation finished. */
  121. }
  122. /* Check the link status. */
  123. for (tout = 0; tout < 0x10000; tout++)
  124. {
  125. value = read_phy (PHY_REG_BMSR);
  126. if (value & BMSR_LINKST) break; /* Link is on. */
  127. }
  128. }
  129. value = read_phy (PHY_REG_ANLPAR);
  130. /* Update the MAC register NCFGR. */
  131. AT91C_BASE_EMAC->EMAC_NCFGR &= ~(AT91C_EMAC_SPD | AT91C_EMAC_FD);
  132. /* set full duplex . */
  133. if (value & 0xA000) AT91C_BASE_EMAC->EMAC_NCFGR |= AT91C_EMAC_FD;
  134. /* set speed */
  135. if (value & 0xC000) AT91C_BASE_EMAC->EMAC_NCFGR |= AT91C_EMAC_SPD;
  136. }
  137. /*
  138. * Set the MAC address.
  139. */
  140. rt_inline void update_mac_address(struct net_device* device)
  141. {
  142. AT91C_BASE_EMAC->EMAC_SA1L = (device->dev_addr[3] << 24) |
  143. (device->dev_addr[2] << 16) |
  144. (device->dev_addr[1] << 8) |
  145. device->dev_addr[0];
  146. AT91C_BASE_EMAC->EMAC_SA1H = (device->dev_addr[5] << 8) |
  147. device->dev_addr[4];
  148. }
  149. rt_inline void sam7xether_desc_init()
  150. {
  151. rt_uint32_t i;
  152. /* Rx Buffer Descriptor initialization */
  153. current_rb_index = 0;
  154. for (i = 0; i < RB_BUFFER_SIZE; i++)
  155. {
  156. rb_descriptors[i].addr = (rt_uint32_t)&(rx_buf[i][0]);
  157. rb_descriptors[i].status = 0;
  158. }
  159. /* Set the WRAP bit at the end of the list descriptor. */
  160. rb_descriptors[RB_BUFFER_SIZE-1].addr |= 0x02;
  161. /* Set Rx Queue pointer to descriptor list. */
  162. AT91C_BASE_EMAC->EMAC_RBQP = (unsigned int)&(rb_descriptors[0]);
  163. /* Tx Buffer Descriptor initialization */
  164. for (i = 0; i < TB_BUFFER_SIZE; i++)
  165. {
  166. tb_descriptors[i].addr = (rt_uint32_t)&(tx_buf[i][0]);
  167. tb_descriptors[i].status = TxDESC_STATUS_USED;
  168. }
  169. /* Set the WRAP bit at the end of the list descriptor. */
  170. tb_descriptors[TB_BUFFER_SIZE-1].status |= TxDESC_STATUS_WRAP;
  171. /* Set Tx Queue pointer to descriptor list. */
  172. AT91C_BASE_EMAC->EMAC_TBQP = (unsigned int)&(tb_descriptors[0]);
  173. }
  174. /* RT-Thread Device Interface */
  175. /* initialize the interface */
  176. rt_err_t sam7xether_init(rt_device_t dev)
  177. {
  178. /* enable peripheral clock for EMAC and PIO B */
  179. AT91C_BASE_PMC->PMC_PCER = 1 << AT91C_ID_PIOB | 1 << AT91C_ID_EMAC;
  180. /* Disable pull up on RXDV => PHY normal mode (not in test mode), */
  181. /* and set MII mode. PHY has internal pull down. */
  182. AT91C_BASE_PIOB->PIO_PPUDR = (1<<16) | (1 << 15);
  183. /* Clear PB18 <=> PHY powerdown */
  184. AT91C_BASE_PIOB->PIO_PER = 1<<18;
  185. AT91C_BASE_PIOB->PIO_OER = 1<<18;
  186. AT91C_BASE_PIOB->PIO_CODR = 1<<18;
  187. /* EMAC IO init for EMAC-PHY communication. */
  188. AT91C_BASE_PIOB->PIO_ASR = EMAC_PIO_CFG;
  189. AT91C_BASE_PIOB->PIO_PDR = EMAC_PIO_CFG; // Set in Periph mode
  190. /* Enable communication between EMAC-PHY. */
  191. AT91C_BASE_EMAC->EMAC_NCR |= AT91C_EMAC_MPE;
  192. /* MDC = MCK/32 */
  193. AT91C_BASE_EMAC->EMAC_NCFGR |= 2<<10;
  194. /* Reset PHY */
  195. AT91C_BASE_PIOB->PIO_PPUDR = AT91C_PB7_ERXER;
  196. AT91C_BASE_RSTC->RSTC_RMR = 0xA5000000 | (0x08 << 8) ;
  197. AT91C_BASE_RSTC->RSTC_RCR = 0xA5000000 | AT91C_RSTC_EXTRST;
  198. while(!(AT91C_BASE_RSTC->RSTC_RSR & AT91C_RSTC_NRSTL));
  199. linksetup();
  200. /* Disable management port in MAC control register. */
  201. AT91C_BASE_EMAC->EMAC_NCR &= ~AT91C_EMAC_MPE;
  202. /* Enable EMAC in MII mode, enable clock ERXCK and ETXCK */
  203. AT91C_BASE_EMAC->EMAC_USRIO= AT91C_EMAC_CLKEN;
  204. /* Transmit and Receive disable. */
  205. AT91C_BASE_EMAC->EMAC_NCR &= ~(AT91C_EMAC_RE | AT91C_EMAC_TE);
  206. /* init descriptor */
  207. sam7xether_desc_init();
  208. /* Clear receive and transmit status registers. */
  209. AT91C_BASE_EMAC->EMAC_RSR = (AT91C_EMAC_OVR | AT91C_EMAC_REC | AT91C_EMAC_BNA);
  210. AT91C_BASE_EMAC->EMAC_TSR = (AT91C_EMAC_UND | AT91C_EMAC_COMP| AT91C_EMAC_BEX |
  211. AT91C_EMAC_RLES| AT91C_EMAC_COL | AT91C_EMAC_UBR);
  212. /* Configure EMAC operation mode. */
  213. AT91C_BASE_EMAC->EMAC_NCFGR |= (AT91C_EMAC_BIG | AT91C_EMAC_DRFCS);
  214. AT91C_BASE_EMAC->EMAC_NCR |= (AT91C_EMAC_TE | AT91C_EMAC_RE | AT91C_EMAC_WESTAT);
  215. /* update MAC address */
  216. update_mac_address(sam7x_dev);
  217. /* enable interrupt */
  218. AT91C_BASE_EMAC->EMAC_IER = AT91C_EMAC_RCOMP | AT91C_EMAC_TCOMP;
  219. /* setup interrupt */
  220. rt_hw_interrupt_install(AT91C_ID_EMAC, sam7xether_isr, RT_NULL);
  221. *(volatile unsigned int*)(0xFFFFF000 + AT91C_ID_EMAC * 4) = AT91C_AIC_SRCTYPE_INT_HIGH_LEVEL | 5;
  222. // AT91C_AIC_SMR(AT91C_ID_EMAC) = AT91C_AIC_SRCTYPE_INT_HIGH_LEVEL | 5;
  223. rt_hw_interrupt_umask(AT91C_ID_EMAC);
  224. return RT_EOK;
  225. }
  226. /* control the interface */
  227. rt_err_t sam7xether_control(rt_device_t dev, rt_uint8_t cmd, void *args)
  228. {
  229. switch(cmd)
  230. {
  231. case NIOCTL_GADDR:
  232. /* get mac address */
  233. if(args) rt_memcpy(args, sam7x_dev_entry.dev_addr, 6);
  234. else return -RT_ERROR;
  235. break;
  236. default :
  237. break;
  238. }
  239. return RT_EOK;
  240. }
  241. /* Open the ethernet interface */
  242. rt_err_t sam7xether_open(rt_device_t dev, rt_uint16_t oflags)
  243. {
  244. return RT_EOK;
  245. }
  246. /* Close the interface */
  247. rt_err_t sam7xether_close(rt_device_t dev)
  248. {
  249. return RT_EOK;
  250. }
  251. /* Read */
  252. rt_size_t sam7xether_read(rt_device_t dev, rt_off_t pos, void* buffer, rt_size_t size)
  253. {
  254. rt_set_errno(-RT_ENOSYS);
  255. return 0;
  256. }
  257. /* Write */
  258. rt_size_t sam7xether_write(rt_device_t dev, rt_off_t pos, const void* buffer, rt_size_t size)
  259. {
  260. rt_set_errno(-RT_ENOSYS);
  261. return 0;
  262. }
  263. /* See the header file for descriptions of public functions. */
  264. void sam7xether_write_frame(rt_uint8_t *ptr, rt_uint32_t length, rt_bool_t eof)
  265. {
  266. rt_uint8_t *buf_ptr;
  267. static rt_uint32_t current_tb_index = 0;
  268. rt_uint32_t is_last, tx_offset = 0, remain, pdu_length;
  269. while(tx_offset < length)
  270. {
  271. /* check whether buffer is available */
  272. while(!(tb_descriptors[current_tb_index].status & TxDESC_STATUS_USED))
  273. {
  274. /* no buffer */
  275. rt_thread_delay(5);
  276. }
  277. /* Get the address of the buffer from the descriptor, then copy
  278. the data into the buffer. */
  279. buf_ptr = (rt_uint8_t *)tb_descriptors[current_tb_index].addr;
  280. /* How much can we write to the buffer? */
  281. remain = length - tx_offset;
  282. pdu_length = (remain <= ETH_TX_BUF_SIZE)? remain : ETH_TX_BUF_SIZE;
  283. /* Copy the data into the buffer. */
  284. rt_memcpy(buf_ptr, &ptr[tx_offset], pdu_length );
  285. tx_offset += pdu_length;
  286. /* Is this the last data for the frame? */
  287. if((eof == RT_TRUE) && ( tx_offset >= length )) is_last = TxDESC_STATUS_LAST_BUF;
  288. else is_last = 0;
  289. /* Fill out the necessary in the descriptor to get the data sent,
  290. then move to the next descriptor, wrapping if necessary. */
  291. if(current_tb_index >= (TB_BUFFER_SIZE - 1))
  292. {
  293. tb_descriptors[current_tb_index].status = ( pdu_length & TxDESC_STATUS_BUF_SIZE )
  294. | is_last
  295. | TxDESC_STATUS_WRAP;
  296. current_tb_index = 0;
  297. }
  298. else
  299. {
  300. tb_descriptors[current_tb_index].status = ( pdu_length & TxDESC_STATUS_BUF_SIZE )
  301. | is_last;
  302. current_tb_index++;
  303. }
  304. /* If this is the last buffer to be sent for this frame we can
  305. start the transmission. */
  306. if(is_last)
  307. {
  308. AT91C_BASE_EMAC->EMAC_NCR |= AT91C_EMAC_TSTART;
  309. }
  310. }
  311. }
  312. /* ethernet device interface */
  313. /*
  314. * Transmit packet.
  315. */
  316. rt_err_t sam7xether_tx( rt_device_t dev, struct pbuf* p)
  317. {
  318. struct pbuf* q;
  319. /* lock tx operation */
  320. rt_sem_take(&tx_sem, RT_WAITING_FOREVER);
  321. for (q = p; q != NULL; q = q->next)
  322. {
  323. if (q->next == RT_NULL) sam7xether_write_frame(q->payload, q->len, RT_TRUE);
  324. else sam7xether_write_frame(q->payload, q->len, RT_FALSE);
  325. }
  326. rt_sem_release(&tx_sem);
  327. return 0;
  328. }
  329. void sam7xether_read_frame(rt_uint8_t* ptr, rt_uint32_t section_length, rt_uint32_t total)
  330. {
  331. static rt_uint8_t* src_ptr;
  332. register rt_uint32_t buf_remain, section_remain;
  333. static rt_uint32_t section_read = 0, buf_offset = 0, frame_read = 0;
  334. if(ptr == RT_NULL)
  335. {
  336. /* Reset our state variables ready for the next read from this buffer. */
  337. src_ptr = (rt_uint8_t *)(rb_descriptors[current_rb_index].addr & RxDESC_FLAG_ADDR_MASK);
  338. frame_read = (rt_uint32_t)0;
  339. buf_offset = (rt_uint32_t)0;
  340. }
  341. else
  342. {
  343. /* Loop until we have obtained the required amount of data. */
  344. section_read = 0;
  345. while( section_read < section_length )
  346. {
  347. buf_remain = (ETH_RX_BUF_SIZE - buf_offset);
  348. section_remain = section_length - section_read;
  349. if( section_remain > buf_remain )
  350. {
  351. /* more data on section than buffer size */
  352. rt_memcpy(&ptr[ section_read ], &src_ptr[buf_offset], buf_remain);
  353. section_read += buf_remain;
  354. frame_read += buf_remain;
  355. /* free buffer */
  356. rb_descriptors[current_rb_index].addr &= ~RxDESC_FLAG_OWNSHIP;
  357. /* move to the next frame. */
  358. current_rb_index++;
  359. if(current_rb_index >= RB_BUFFER_SIZE) current_rb_index = 0;
  360. /* Reset the variables for the new buffer. */
  361. src_ptr = (rt_uint8_t *)(rb_descriptors[current_rb_index].addr & RxDESC_FLAG_ADDR_MASK);
  362. buf_offset = 0;
  363. }
  364. else
  365. {
  366. /* more data on buffer than section size */
  367. rt_memcpy(&ptr[section_read], &src_ptr[buf_offset], section_remain);
  368. buf_offset += section_remain;
  369. section_read += section_remain;
  370. frame_read += section_remain;
  371. /* finish this read */
  372. if((buf_offset >= ETH_RX_BUF_SIZE) || (frame_read >= total))
  373. {
  374. /* free buffer */
  375. rb_descriptors[current_rb_index].addr &= ~(RxDESC_FLAG_OWNSHIP);
  376. /* move to the next frame. */
  377. current_rb_index++;
  378. if( current_rb_index >= RB_BUFFER_SIZE ) current_rb_index = 0;
  379. src_ptr = (rt_uint8_t*)(rb_descriptors[current_rb_index].addr & RxDESC_FLAG_ADDR_MASK);
  380. buf_offset = 0;
  381. }
  382. }
  383. }
  384. }
  385. }
  386. struct pbuf *sam7xether_rx(rt_device_t dev)
  387. {
  388. struct pbuf *p = RT_NULL;
  389. /* skip fragment frame */
  390. while((rb_descriptors[current_rb_index].addr & RxDESC_FLAG_OWNSHIP)
  391. && !(rb_descriptors[current_rb_index].status & RxDESC_STATUS_FRAME_START))
  392. {
  393. rb_descriptors[current_rb_index].addr &= (~RxDESC_FLAG_OWNSHIP);
  394. current_rb_index++;
  395. if(current_rb_index >= RB_BUFFER_SIZE) current_rb_index = 0;
  396. }
  397. if ((rb_descriptors[current_rb_index].addr & RxDESC_FLAG_OWNSHIP))
  398. {
  399. struct pbuf* q;
  400. rt_uint32_t index, pkt_len = 0;
  401. /* first of all, find the frame length */
  402. index = current_rb_index;
  403. while (rb_descriptors[index].addr & RxDESC_FLAG_OWNSHIP)
  404. {
  405. pkt_len = rb_descriptors[index].status & RxDESC_STATUS_BUF_SIZE;
  406. if (pkt_len > 0) break;
  407. index ++;
  408. if (index > RB_BUFFER_SIZE) index = 0;
  409. }
  410. if (pkt_len)
  411. {
  412. p = pbuf_alloc(PBUF_LINK, pkt_len, PBUF_RAM);
  413. if(p != RT_NULL)
  414. {
  415. sam7xether_read_frame(RT_NULL, 0, pkt_len);
  416. for(q = p; q != RT_NULL; q= q->next)
  417. sam7xether_read_frame(q->payload, q->len, pkt_len);
  418. }
  419. else
  420. {
  421. rt_kprintf("no memory in pbuf\n");
  422. }
  423. }
  424. }
  425. /* enable interrupt */
  426. AT91C_BASE_EMAC->EMAC_IER = AT91C_EMAC_RCOMP;
  427. return p;
  428. }
  429. int sam7xether_register(char *name)
  430. {
  431. rt_err_t result;
  432. /* init rt-thread device interface */
  433. sam7x_dev_entry.parent.parent.init = sam7xether_init;
  434. sam7x_dev_entry.parent.parent.open = sam7xether_open;
  435. sam7x_dev_entry.parent.parent.close = sam7xether_close;
  436. sam7x_dev_entry.parent.parent.read = sam7xether_read;
  437. sam7x_dev_entry.parent.parent.write = sam7xether_write;
  438. sam7x_dev_entry.parent.parent.control = sam7xether_control;
  439. sam7x_dev_entry.parent.eth_rx = sam7xether_rx;
  440. sam7x_dev_entry.parent.eth_tx = sam7xether_tx;
  441. /* Update MAC address */
  442. sam7x_dev_entry.dev_addr[0] = 0x1e;
  443. sam7x_dev_entry.dev_addr[1] = 0x30;
  444. sam7x_dev_entry.dev_addr[2] = 0x6c;
  445. sam7x_dev_entry.dev_addr[3] = 0xa2;
  446. sam7x_dev_entry.dev_addr[4] = 0x45;
  447. sam7x_dev_entry.dev_addr[5] = 0x5e;
  448. /* update mac address */
  449. update_mac_address(sam7x_dev);
  450. rt_sem_init(&tx_sem, "emac", 1, RT_IPC_FLAG_FIFO);
  451. result = eth_device_init(&(sam7x_dev->parent), (char*)name);
  452. RT_ASSERT(result == RT_EOK);
  453. return RT_EOK;
  454. }