你好
我将 lwIP 协议与 EMAC 模块结合使用以进行数据传输和接收。 发送数据的过程非常顺利、但是 EMAC 模块在接收数据时遇到了问题。 在特定时间段内接收数据后、EMAC 模块无法进入接收中断。 我正在寻求有关如何解决此问题并确保 EMAC 模块能够连续不间断地接收数据的帮助。 谢谢!
我的 lwIP 初始化如下:
void EMAC_LwIP_init (uint8_t * macAddress) { unsigned int ipAddr; uint32 emacCtrlBase = 0xFCF78800U; uint32 emacBase = 0xFCF78000U; EMACInit(emacCtrlBase,emacBase); IntMasterIRQEnable();//中断 /* for static IP address. Change address as required, and uncomment the previous statement. */ uint8 ip_addr[4] = { 172, 22, 1, 1 }; uint8 netmask[4] = { 255, 255, 255, 0 }; uint8 gateway[4] = { 172, 22, 1, 1 }; ipAddr = lwIPInit(0, macAddress, *((uint32_t *)ip_addr), *((uint32_t *)netmask), *((uint32_t *)gateway), IPADDR_USE_STATIC ); }
我的 EMAC 模块的接收中断如下所示。 测试过程中、我注意到接收中断在 R0 (接收空闲缓冲区计数寄存器)接收到值0xCD 后停止(此时、寄存器不会改变、除非我重新初始化)。 我怀疑我的中断函数中的尾部处理可能存在问题。 下面是我的中断函数:
#pragma INTERRUPT(EMACCore0RxIsr, IRQ) uint32 countrxisr = 0; void EMACCore0RxIsr(void) { char* tmpptr; uint32_t tmp = 0; uint32_t CurFinishCP = HWREG(EMAC_BASE + EMAC_RXCP(0)); /* Pointer to the buffer that has completed data reception */ EMACDesc_t* RXCP = EMAC_SL_CurRXCP; /* Pointer to the current processing receive buffer */ MACFrame_t* MacFramePtr = NULL; ECTRL_C0RXEN = 0U; /* Disable interrupts before processing data */ HWREG(EMAC_BASE + EMAC_RXCP(0)) = CurFinishCP; /* Confirm the current processed CP (Complete Pointer) */ HWREG(EMAC_BASE + EMAC_MACEOIVECTOR) = 1U; /* Acknowledge the completion of receive interrupt */ if (countrxisr == 0U) // First frame { HWREG(EMAC_BASE + EMAC_RXHDP(0)) = CurFinishCP; EMAC_SL_CurRXCP = (EMACDesc_t*)CurFinishCP; RXCP = (EMACDesc_t*)CurFinishCP; countrxisr = 1; } /* When the current receive queue reaches the end, reassign the receive buffer pointer to the first position */ else if (HWREG(EMAC_BASE + EMAC_RXHDP(0)) == 0U) { HWREG(EMAC_BASE + EMAC_RXHDP(0)) = CurFinishCP; EMAC_SL_CurRXCP = (EMACDesc_t*)CurFinishCP; RXCP = (EMACDesc_t*)CurFinishCP; // Original } /* When the current receive queue reaches the end, reassign the receive buffer pointer to the first position */ else { EMAC_SL_CurRXCP = ((EMACDesc_t*)(CurFinishCP)) + 1U; EMAC_SL_CurRXCP = (EMACDesc_t*)((char*)EMAC_SL_CurRXCP + 4); /* Appear 4 bytes more data than 3137, so add this offset */ } /* Update the last processed CP */ while ((uint32_t)(RXCP) <= CurFinishCP) { /*1============================================================================1*/ /* Only process single packet data, discard fragmented data packets */ if ((RXCP->EOP == 1U) && (RXCP->SOP == 1U)) { MacFramePtr = (MACFrame_t*)EMACSwizzleData((uint32)RXCP->BufferPtr); /* Pointer to MAC layer data frame information */ switch (MacFramePtr->FrameType) { case IPV4_DT_ARP_FRAME: { if (EMACSwizzleData16(RXCP->Length) <= sizeof EMAC_SL_RXBuffer.Data[0].Buffer) { memcpy(EMAC_SL_RXBuffer.Data[EMAC_SL_RXBuffer.Tail.Cnt].Buffer, EMACSwizzleData(RXCP->BufferPtr), EMACSwizzleData16(RXCP->Length)); EMAC_SL_RXBuffer.Tail.Cnt++; } break; } /* Received ARP data frame, store the data in the receive buffer for later processing */ case IPV4_DT_IP_FRAME: { IPHeader_t* IPHeaderPtr = (IPHeader_t*)(EMACSwizzleData(RXCP->BufferPtr) + 14U); /* IP header information of the current data packet */ if ((IPHeaderPtr->SrcIP == REMOTE_IP_ADDR) && ((IPHeaderPtr->DstIP == LOCAL_IP_ADDR) || (IPHeaderPtr->DstIP == BROADCAST_IP_ADDR)) && (IPHeaderPtr->Protol == IP_PROTO_UDP)) { EMAC_SL_IsRXRemoteUDPData = TRUE; if (EMACSwizzleData16(RXCP->Length) <= sizeof EMAC_SL_RXBuffer.Data[0].Buffer) { memcpy(EMAC_SL_RXBuffer.Data[EMAC_SL_RXBuffer.Tail.Cnt].Buffer, EMACSwizzleData(RXCP->BufferPtr), EMACSwizzleData16(RXCP->Length)); EMAC_SL_RXBuffer.Tail.Cnt++; } } /* Received IP address matches the local IP address and data type is UDP, then process the data frame */ break; } /* Received IP data frame, store the data in the receive buffer for later processing */ default: { break; } } } /*1============================================================================1*/ RXCP->Length = RX_BUFFER_SIZE; RXCP->OWNER = 1U; RXCP++; RXCP = (char*)RXCP + 4; /* Here, don't know why data in buffer is 32 * 5 bytes while 3137 is 32 * 4 bytes, perhaps because of the lwIP protocol */ } ECTRL_C0RXEN = 1U; /* Reactivate interrupts */ }
您能帮助我分析问题可能发生的位置吗? 谢谢你。