This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

[参考译文] TMDSCNCD28388D:以太网 TRASMIT -接收问题

Guru**** 2387830 points
Other Parts Discussed in Thread: TMS320F28388D, C2000WARE
请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/microcontrollers/c2000-microcontrollers-group/c2000/f/c2000-microcontrollers-forum/1027251/tmdscncd28388d-ethernet-trasmit---receive-issue

器件型号:TMDSCNCD28388D
主题中讨论的其他器件:TMS320F28388DC2000WARE

大家好、

我们公司正在开发 TMS320f28388d 微控制器上的以太网模块。 我们正在尝试使用 Enet lwip 模块在 PC 中的控制器和应用程序之间发送和接收数据。 以下是迄今为止在该过程中采取的步骤:-

步骤1. 我们已经执行了两个示例项目:- ethernet_c28_config 项目和 enet_lwip 项目。

步骤2. 我们首先调试 cm_common_config 文件、然后调试另一个文件。

步骤3. 通过使用 cmd Window 和 Hercules.exe 工具、我们能够 ping 并建立连接。

步骤4. 也可以使用 http webserver 来验证这一点。

步骤5. 现在我们要发送和接收数据,但我们不知道可以从哪个缓冲区写入或读取数据。 此外、我们可以看到一些随机数据出现在 EtherNet_Rx_buffer 的观察窗口中。

步骤6. 为了尝试通信、我们尝试在 cm_common_config 文件中使用 IPC SEND 命令并尝试与 EtherNet_IPC_ex1_basic_cm 进行通信、会提出传递标志变量、确认 IPC 正在应答、但我们无法在观察窗口和 Hercules 应用中看到我们发送的任何数据。

请纠正问题并指导我们如何在控制器和应用程序之间开始数据传输、我们需要修改哪些缓冲区、以及如何在观察窗口中查看数据。

另请告诉我们,如何通过 enet_lwip 进行套接字编程。

谢谢、此致

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好!

    我  还 尝试 在 不使用 IPC 的情况下将 lwipperf.c 文件中给出的 TCP 函数合并到 lwip 文件中,存在一个我  无法理解的论点,即 void * arg。 请说明这两种方法中的哪一种正确地通过互联网实现 TCP IP 协议栈发送和接收、并提供所涉及的步骤

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好!  

    下周初、我们将了解一下这一点、并对您作出回应。

    此致

    Siddharth

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好,Siddharth,  

    非常感谢   您的回复, 到目前为止,我们 已经尝试 了以下方法:-

    1.testpcb = tcp_new();

    2.err=tcp_bind (testpcb、&src、LocalIPPort);
    3.tcp_arg (testpcb、&data);

    4.tcp_listen_with_backlog (testpcb、0xff);//0xff
    // tcp_accept (testpcb、accept);

     按照以下步骤 在  lwip 堆栈示例中实现 TCP 服务器。 我们无法跟踪 在 tcp_accept 中传递的第二个参数。  请指导我们如何跟踪功能以及如何进一步传输和接收数据。

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好、Udita、  

    tcp_accept 的第二个参数是回调函数、当 侦听 TCP PCB 的新连接到达时调用该函数。   接受传入连接时 ,将调用使用 tcp_accept ()函数指定的函数。

    您可以参考以下链接。

    https://github.com/MCUapps/lwip-gnu/blob/master/STM32F4DIS-BB/tcp_echo_server/src/tcp_echoserver.c

    此致

    Siddharth

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好 Siddharth、

    感谢您的回复,我们正在处理 f28388d 模块。 该回调 函数是否适用于该功能、以及 F28388微控制器是否未提供服务器示例。

    谢谢、 此致

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好 Siddharth、

    我们已经在 F28388D 上测试了 TCP 回显服务器功能,它运行良好,但请告诉我们如何从侧面发送数据。现在,我们能够将数据从 Hercules 发送到服务器,并将其回显到 Hercules。

    谢谢、此致  

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好、Udita、  

    从我们的一方发送数据意味着什么? 请澄清。   

    此外、Hercules 的意思 是 https://www.hw-group.com/software/hercules-setup-utility 工具吗?

    此致

    Siddharth

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好,Siddharth,  

    是的,Hercules 的意思是说只有完全相同的实用工具。  

    我们作为一个服务器工作,现在,Hercules 正在发送一些数据,我们是通过回显进行响应,而不是通过包含数据的缓冲区进行响应。请指导我们。

    谢谢、此致

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好、Udita、  

    您是否正在使用 tcpEchoF2838X 示例? 如果是这样,您可以更新  tcpworker 函数 并使用其自己的数据缓冲区更新 send()命令。  

    此致

    Siddharth

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好,Siddharth ,

    实际上 ,我们 使用 的是 enet_lwip.c,我们已将 tcpechoserver 示例嵌入其中,它可以很好地回显数据。 我们是否可以采取任何措施来共享我们的数据、而不是将接收到的数据回显

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    Udita、  

    您是否可以共享更新的代码? 我可以看一下它、让您知道需要执行的更改。

    此致

    Siddharth

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好 Siddharth、

    请查找更新的代码。

    //###########################################################################
    //
    // FILE:   enet_lwip.c
    //
    // TITLE:  lwIP based Ethernet Example.
    //
    //###########################################################################
    // $TI Release: $
    // $Release Date: $
    // $Copyright: $
    //###########################################################################
    
    #include <string.h>
    
    #include "inc/hw_ints.h"
    #include "inc/hw_memmap.h"
    #include "inc/hw_nvic.h"
    #include "inc/hw_types.h"
    #include "inc/hw_sysctl.h"
    #include "inc/hw_emac.h"
    #define lwiperf_report_type LWIPERF_TCP_DONE_SERVER
    #define Port 5001
    #define LWIP_CALLBACK_API               1
    //#define  TCP_LISTEN_BACKLOG 1
    void tcp_echoserver_init(void);
    //void tcp_echoserver_send(struct tcp_pcb *tpcb, struct tcp_echoserver_struct *es);
    struct tcp_pcb *tcp_echoserver_pcb;
    int LocalIPPort=Port;
    int ServerPort ;
    int err,pcb,ret_val;
    
    
    
    #include "driverlib_cm/ethernet.h"
    #include "driverlib_cm/gpio.h"
    #include "driverlib_cm/interrupt.h"
    
    #include "driverlib_cm/sysctl.h"
    #include "driverlib_cm/systick.h"
    
    #include "utils/lwiplib.h"
    #include "board_drivers/pinout.h"
    
    #include "lwip/apps/httpd.h"
    //*****************************************************************************
    //
    //! \addtogroup master_example_list
    //! <h1>Ethernet with lwIP (enet_lwip)</h1>
    //!
    //! This example application demonstrates the operation of the F2838x
    //! microcontroller Ethernet controller using the lwIP TCP/IP Stack. Once
    //! programmed, the device sits endlessly waiting for ICMP ping requests. It
    //! has a static IP address. To ping the device, the sender has to be in the
    //! same network. The stack also supports ARP.
    //!
    //! For additional details on lwIP, refer to the lwIP web page at:
    //! savannah.nongnu.org/.../
    //
    //*****************************************************************************
    
    // These are defined by the linker (see device linker command file)
    extern unsigned long RamfuncsLoadStart;
    extern unsigned long RamfuncsLoadSize;
    extern unsigned long RamfuncsRunStart;
    ip4_addr_t src;
    //*****************************************************************************
    //
    // Driver specific initialization code and macro.
    //
    //*****************************************************************************
    #define ETHERNET_NO_OF_RX_PACKETS   8U
    #define ETHERNET_MAX_PACKET_LENGTH 500
    #define NUM_PACKET_DESC_RX_APPLICATION 8
    
    Ethernet_Handle emac_handle;
    Ethernet_InitConfig *pInitCfg;
    uint32_t Ethernet_numRxCallbackCustom = 0;
    uint32_t releaseTxCount = 0;
    
    uint32_t systickPeriodValue = 15000000;
    Ethernet_Pkt_Desc  pktDescriptorRXCustom[NUM_PACKET_DESC_RX_APPLICATION];
    extern uint32_t Ethernet_numGetPacketBufferCallback;
    extern Ethernet_Device Ethernet_device_struct;
    uint8_t Ethernet_rxBuffer[ETHERNET_NO_OF_RX_PACKETS *
                              ETHERNET_MAX_PACKET_LENGTH];
    
    extern Ethernet_Pkt_Desc*
    lwIPEthernetIntHandler(Ethernet_Pkt_Desc *pPacket);
    
    //*****************************************************************************
    //
    // HTTP Webserver related callbacks and definitions.
    //
    //*****************************************************************************
    //
    // Currently, this implemented as a pointer to function which is called when
    // corresponding query is received by the HTTP webserver daemon. When more
    // features are needed to be added, it should be implemented as a separate
    // interface.
    //
    void httpLEDToggle(void);
    void(*ledtoggleFuncPtr)(void) = &httpLEDToggle;
    
    //*****************************************************************************
    //
    // The interrupt handler for the SysTick interrupt.
    //
    //*****************************************************************************
    void
    SysTickIntHandler(void)
    {
        //
        // Call the lwIP timer handler.
        //
        lwIPTimer(systickPeriodValue);
    }
    
    
    //callback function for accept
    
    
    //*****************************************************************************
    //
    //  This function is a callback function called by the example to
    //  get a Packet Buffer. Has to return a ETHERNET_Pkt_Desc Structure.
    //  Rewrite this API for custom use case.
    //
    //*****************************************************************************
    Ethernet_Pkt_Desc* Ethernet_getPacketBufferCustom(void)
    {
        //
        // Get the next packet descriptor from the descriptor pool
        //
        uint32_t shortIndex = (Ethernet_numGetPacketBufferCallback + 3)
                    % NUM_PACKET_DESC_RX_APPLICATION;
    
        //
        // Increment the book-keeping pointer which acts as a head pointer
        // to the circular array of packet descriptor pool.
        //
        Ethernet_numGetPacketBufferCallback++;
    
        //
        // Update buffer length information to the newly procured packet
        // descriptor.
        //
        pktDescriptorRXCustom[shortIndex].bufferLength =
                                      ETHERNET_MAX_PACKET_LENGTH;
    
        //
        // Update the receive buffer address in the packer descriptor.
        //
        pktDescriptorRXCustom[shortIndex].dataBuffer =
                                          &Ethernet_device_struct.rxBuffer [ \
                   (ETHERNET_MAX_PACKET_LENGTH*Ethernet_device_struct.rxBuffIndex)];
    
        //
        // Update the receive buffer pool index.
        //
        Ethernet_device_struct.rxBuffIndex += 1U;
        Ethernet_device_struct.rxBuffIndex  = \
        (Ethernet_device_struct.rxBuffIndex%ETHERNET_NO_OF_RX_PACKETS);
    
        //
        // Receive buffer is usable from Address 0
        //
        pktDescriptorRXCustom[shortIndex].dataOffset = 0U;
    
        //
        // Return this new descriptor to the driver.
        //
        return (&(pktDescriptorRXCustom[shortIndex]));
    }
    
    //*****************************************************************************
    //
    //  This is a hook function and called by the driver when it receives a
    //  packet. Application is expected to replenish the buffer after consuming it.
    //  Has to return a ETHERNET_Pkt_Desc Structure.
    //  Rewrite this API for custom use case.
    //
    //*****************************************************************************
    Ethernet_Pkt_Desc* Ethernet_receivePacketCallbackCustom(
            Ethernet_Handle handleApplication,
            Ethernet_Pkt_Desc *pPacket)
    {
        //
        // Book-keeping to maintain number of callbacks received.
        //
    #ifdef ETHERNET_DEBUG
        Ethernet_numRxCallbackCustom++;
    #endif
    
        //
        // This is a placeholder for Application specific handling
        // We are replenishing the buffer received with another buffer
        //
        return lwIPEthernetIntHandler(pPacket);
    }
    
    void Ethernet_releaseTxPacketBufferCustom(
            Ethernet_Handle handleApplication,
            Ethernet_Pkt_Desc *pPacket)
    {
        //
        // Once the packet is sent, reuse the packet memory to avoid
        // memory leaks. Call this interrupt handler function which will take care
        // of freeing the memory used by the packet descriptor.
        //
        lwIPEthernetIntHandler(pPacket);
    
        //
        // Increment the book-keeping counter.
        //
    #ifdef ETHERNET_DEBUG
        releaseTxCount++;
    #endif
    }
    
    void
    Ethernet_init(const unsigned char *mac)
    {
        Ethernet_InitInterfaceConfig initInterfaceConfig;
        uint32_t macLower;
        uint32_t macHigher;
        uint8_t *temp;
    
        initInterfaceConfig.ssbase = EMAC_SS_BASE;
        initInterfaceConfig.eqos_base = EMAC_BASE;
        initInterfaceConfig.phyMode = ETHERNET_SS_PHY_INTF_SEL_MII;
    
        //
        // Assign SoC specific functions for Enabling,Disabling interrupts
        // and for enabling the Peripheral at system level
        //
        initInterfaceConfig.ptrPlatformInterruptDisable =
                                                        &Platform_disableInterrupt;
        initInterfaceConfig.ptrPlatformInterruptEnable =
                                                         &Platform_enableInterrupt;
        initInterfaceConfig.ptrPlatformPeripheralEnable =
                                                        &Platform_enablePeripheral;
        initInterfaceConfig.ptrPlatformPeripheralReset =
                                                         &Platform_resetPeripheral;
    
        //
        // Assign the peripheral number at the SoC
        //
        initInterfaceConfig.peripheralNum = SYSCTL_PERIPH_CLK_ENET;
    
        //
        // Assign the default SoC specific interrupt numbers of Ethernet interrupts
        //
        initInterfaceConfig.interruptNum[0] = INT_EMAC;
        initInterfaceConfig.interruptNum[1] = INT_EMAC_TX0;
        initInterfaceConfig.interruptNum[2] = INT_EMAC_TX1;
        initInterfaceConfig.interruptNum[3] = INT_EMAC_RX0;
        initInterfaceConfig.interruptNum[4] = INT_EMAC_RX1;
    
        pInitCfg = Ethernet_initInterface(initInterfaceConfig);
    
        Ethernet_getInitConfig(pInitCfg);
        pInitCfg->dmaMode.InterruptMode = ETHERNET_DMA_MODE_INTM_MODE2;
    
        //
        // Assign the callbacks for Getting packet buffer when needed
        // Releasing the TxPacketBuffer on Transmit interrupt callbacks
        // Receive packet callback on Receive packet completion interrupt
        //
        pInitCfg->pfcbRxPacket = &Ethernet_receivePacketCallbackCustom;
        pInitCfg->pfcbGetPacket = &Ethernet_getPacketBufferCustom;
        pInitCfg->pfcbFreePacket = &Ethernet_releaseTxPacketBufferCustom;
    
        //
        //Assign the Buffer to be used by the Low level driver for receiving
        //Packets. This should be accessible by the Ethernet DMA
        //
        pInitCfg->rxBuffer = Ethernet_rxBuffer;
    
        //
        // The Application handle is not used by this application
        // Hence using a dummy value of 1
        //
        Ethernet_getHandle((Ethernet_Handle)1, pInitCfg , &emac_handle);
    
        //
        //Do global Interrupt Enable
        //
        (void)Interrupt_enableInProcessor();
    
        //
        //Assign default ISRs
        //
        Interrupt_registerHandler(INT_EMAC_TX0, Ethernet_transmitISR);
        Interrupt_registerHandler(INT_EMAC_RX0, Ethernet_receiveISR);
    
        //
        //Enable the default interrupt handlers
        //
        Interrupt_enable(INT_EMAC_TX0);
        Interrupt_enable(INT_EMAC_RX0);
    
        //
        // Convert the mac address string into the 32/16 split variables format
        // that is required by the driver to program into hardware registers.
        // Note: This step is done after the Ethernet_getHandle function because
        //       a dummy MAC address is programmed in that function.
        //
        temp = (uint8_t *)&macLower;
        temp[0] = mac[0];
        temp[1] = mac[1];
        temp[2] = mac[2];
        temp[3] = mac[3];
    
        temp = (uint8_t *)&macHigher;
        temp[0] = mac[4];
        temp[1] = mac[5];
    
        //
        // Program the unicast mac address.
        //
        Ethernet_setMACAddr(EMAC_BASE,
                            0,
                            macHigher,
                            macLower,
                            ETHERNET_CHANNEL_0);
    }
    
    void acceptcallback(void)
    {
        //tcprecved();
    }
    
    //*****************************************************************************
    //
    // This example demonstrates the use of the Ethernet Controller.
    //
    //*****************************************************************************
    int
    main(void)
    {//buffer->arr[0]=50;
        unsigned long ulUser0, ulUser1;
        unsigned char pucMACArray[8];
        //uint32_t data=0xdeadbeef;
    
        src.addr=IP4_ADDR(&src,4,0,168,192);
        //
        // User specific IP Address Configuration.
        // Current implementation works with Static IP address only.
        //
        unsigned long IPAddr = 0xC0A80004;
        unsigned long NetMask = 0xFFFFFF00;
        unsigned long GWAddr = 0x00000000;
    
        SYSTICK_setPeriod(systickPeriodValue);
        SYSTICK_enableCounter();
        SYSTICK_registerInterruptHandler(SysTickIntHandler);
        SYSTICK_enableInterrupt();
    
        //
        // Enable processor interrupts.
        //
        Interrupt_enableInProcessor();
            
        // Set user/company specific MAC octets
        // (for this code we are using A8-63-F2-00-00-80)
        // 0x00 MACOCT3 MACOCT2 MACOCT1
        ulUser0 = 0x00F263A8;
    
        // 0x00 MACOCT6 MACOCT5 MACOCT4
        ulUser1 = 0x00800000;
    
        //
        // Convert the 24/24 split MAC address from NV ram into a 32/16 split MAC
        // address needed to program the hardware registers, then program the MAC
        // address into the Ethernet Controller registers.
        //
        pucMACArray[0] = ((ulUser0 >>  0) & 0xff);
        pucMACArray[1] = ((ulUser0 >>  8) & 0xff);
        pucMACArray[2] = ((ulUser0 >> 16) & 0xff);
        pucMACArray[3] = ((ulUser1 >>  0) & 0xff);
        pucMACArray[4] = ((ulUser1 >>  8) & 0xff);
        pucMACArray[5] = ((ulUser1 >> 16) & 0xff);
    
        //
        // Initialize ethernet module.
        //
        Ethernet_init(pucMACArray);
    
        //
        // Initialze the lwIP library, using DHCP.
        //
        lwIPInit(0, pucMACArray, IPAddr, NetMask, GWAddr, IPADDR_USE_STATIC);
    
        //
        // Initialize the HTTP webserver daemon.Da
        //
        //httpd_init();
    
        tcp_echoserver_init();
    
        //tcp_echoserver_send(tcp_echoserver_pcb,buffer);
    
        //testpcb = tcp_new();
    
        // err=tcp_bind(testpcb, &src, LocalIPPort);
       //tcp_arg(testpcb,&data);
    
        //tcp_listen_with_backlog(testpcb,0xff);//0xff
        //tcp_echoserver_accept(NULL,testpcb,err);
    
    
        //void *lwiperf_start_tcp_server_default(lwiperf_report_fn report_fn, void *report_arg);
    
       // lwiperf_tcp_accept(void *arg, struct tcp_pcb *newpcb, err_t err);
       // lwiperf_tcp_recv(void *arg, struct tcp_pcb *tpcb, struct pbuf *p, err_t err);
       // err_t  lwiperf_tx_start_impl(const ip_addr_t *remote_ip, u16_t remote_port, lwiperf_settings_t *settings, lwiperf_report_fn report_fn,
                              ///void *report_arg, lwiperf_state_base_t *related_master_state, lwiperf_state_tcp_t **new_conn);
    
    
        //
        // Loop forever. All the work is done in interrupt handlers.
        //
        while(1);
    }
    
    //*****************************************************************************
    //
    // Called by lwIP Library. Toggles the led when a command is received by the
    // HTTP webserver.
    //
    //*****************************************************************************
    void httpLEDToggle(void)
    {
        //
        // Toggle the LED D1 on the control card.
        //
        GPIO_togglePin(DEVICE_GPIO_PIN_LED1);
    }
    
    
    //*****************************************************************************
    //
    // Called by lwIP Library. Could be used for periodic custom tasks.
    //
    //*****************************************************************************
    void lwIPHostTimerHandler(void)
    {
    
    }
    

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    Udita、  

    您可以参阅文件 C:\ti\c2000\C2000Ware_3_04_00_00\libraries\communications\ethernet/third_parti\lwip-2.1.2\src\core\tcp.c,其中提到了用于设置 TCP 连接、发送和接收 TCP 数据的函数。  

    您必须创建 TCP PCB 并实施回调函数、 以使用 tcp_write 和 tcp_send 函数发送数据。

    我将尝试创建此类示例并与您分享。

    此致

    Siddharth

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好 Siddharth、

    非常感谢您的回复。 我们已经解决了这个问题,现在我们可以通过 TCP IP 服务器发送和接收 。    我们 面临的新问题是,我们希望构建一个独立的应用程序,并且无法在 任何其他工作区中复制 enet_lwip 项目。 我们每次都必须导入它并进行必要的更改。 请仔细研究该问题。

    谢谢、此致

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    Udita、  

    很高兴您能正常工作。  

    通过独立的应用程序,您是否意味着要创建一个新的 CCS 项目,该项目可以共享并构建而不进行任何更改?

    如果是、您可以参考以下链接

    https://software-dl.ti.com/ccs/esd/documents/ccs_sharing-projects.html

    如果您有任何其他相关问题、请告诉我。

    此致

    Siddharth