|
![](static/image/common/ico_lz.png)
楼主 |
发表于 2014-11-6 13:34:04
|
显示全部楼层
先请教你一个问题:
low_level_output函数调用ethernet_send向网卡发送数据,但是ethernet_send调用的确实EMAC_WritePacketBuffer函数
该函数只是把发发送的数据放到了Tx_Desc缓存中,这个缓存中的数据是谁,在哪里,怎么调用把数据发送到phy上的呢?
谢谢
下面的函数有2个是1788的库函数中的,一个是lwip文件中的。low_level_output的写法参考论坛里一个人的,是用lwip实现AD数据读取的那个帖子。
- void EMAC_WritePacketBuffer(EMAC_PACKETBUF_Type *pDataStruct)
- {
- uint32_t idx,len;
- uint32_t *sp,*dp;
- idx = LPC_EMAC->TxProduceIndex;
- sp = (uint32_t *)pDataStruct->pbDataBuf;
- dp = (uint32_t *)Tx_Desc[idx].Packet;
- /* Copy frame data to EMAC packet buffers. */
- for (len = (pDataStruct->ulDataLen + 3) >> 2; len; len--)
- {
- *dp++ = *sp++;
- }
- Tx_Desc[idx].Ctrl = (pDataStruct->ulDataLen - 1) | (EMAC_TCTRL_INT | EMAC_TCTRL_LAST);//===============这个数据在哪里被发送到phy上了呢?????????
- }
- int8_t ethernet_send(void *pPacket, uint16_t size)
- {
- EMAC_PACKETBUF_Type TxPack;
- /* Check size */
- if(size == 0)
- {
- return 1;
- }
- /* check Tx Slot is available */
- if (EMAC_CheckTransmitIndex() == FALSE)
- {
- return -1;
- }
- size = MIN(size,EMAC_MAX_PACKET_SIZE);
- /* Setup Tx Packet buffer */
- TxPack.ulDataLen = size;
- TxPack.pbDataBuf = (uint32_t *)pPacket;
- EMAC_WritePacketBuffer(&TxPack);
- EMAC_UpdateTxProduceIndex();
- return 0;
- }
- static err_t
- low_level_output(struct netif *netif, struct pbuf *p)
- {
- //struct ethernetif *ethernetif = netif->state;
- struct pbuf *q;
- u32_t len = 0;
- //initiate transfer();
- SYS_ARCH_DECL_PROTECT(sr);
- /* Interrupts are disabled through this whole thing to support multi-threading
- transmit calls. Also this function might be called from an ISR. */
- SYS_ARCH_PROTECT(sr);
- #if ETH_PAD_SIZE
- pbuf_header(p, -ETH_PAD_SIZE); /* drop the padding word */
- #endif
- for(q = p; q != NULL; q = q->next)
- {
- /* Send the data from the pbuf to the interface, one pbuf at a
- time. The size of the data in each pbuf is kept in the ->len
- variable. */
- //send data from(q->payload, q->len);
- memcpy((u8_t*)&gTxBuf[len], q->payload, q->len);
- len = len + q->len;
- }
- //signal that packet should be sent();
- ethernet_send(gTxBuf, len);
- #if ETH_PAD_SIZE
- pbuf_header(p, ETH_PAD_SIZE); /* reclaim the padding word */
- #endif
- LINK_STATS_INC(link.xmit);
- SYS_ARCH_UNPROTECT(sr);
- return ERR_OK;
- }
复制代码 |
|