Other Parts Discussed in Thread: EK-TM4C1294XL
Tool/software:
HI Team
I am trying to send dara value 10 via ethernet tx packet from microcontroller to PC but iam getting following error
code snippet
can you please tell you tcp write not working, but i could able receive the packets from PC but could not transmit the packet to PC
PFB code for your reference please suggest any chnages to be made in the code for TCP_write and tcp_output//*****************************************************************************
//
// Defines for the server IP address and PORT numbers.
//
//*****************************************************************************
#define SERVER_IPADDR "192.168.254.220"
#define SERVER_PORT 1001
//*****************************************************************************
//
// Defines for setting up the system clock.
//
//*****************************************************************************
#define SYSTICKHZ 100
#define SYSTICKMS (1000 / SYSTICKHZ)
#define IPADDR "241.254.168.192"
#define NETMASK "0.255.255.255"
#define GWMASK "0.0.0.255"
#define PORT 1001
//*****************************************************************************
//
// Interrupt priority definitions. The top 3 bits of these values are
// significant with lower values indicating higher priority interrupts.
//
//*****************************************************************************
#define SYSTICK_INT_PRIORITY 0x80
#define ETHERNET_INT_PRIORITY 0x80 //0xC0
//*****************************************************************************
//
// The current IP address.
//
//*****************************************************************************
uint32_t g_ui32IPAddress;
//*****************************************************************************
//
// Global counter to keep track the duration the connection has been idle.
//
//*****************************************************************************
uint32_t g_ui32tcpPollTick = 0;
uint32_t firmware_address = 0;
//*****************************************************************************
//
// Global flag indicating when the IP address is acquired
//
//*****************************************************************************
bool g_bIPAddrValid = 0;
//*****************************************************************************
//
// Global LwIP PCB structure and error variables.
//
//*****************************************************************************
err_t err;
extern bool fw_Upgrade_started;
//*****************************************************************************
//
// The error routine that is called if the driver library encounters an error.
//
//*****************************************************************************
#ifdef DEBUG
void
__error__(char *pcFilename, uint32_t ui32Line)
{
}
#endif
//#define UART_DEBUG_OUT 1
//*****************************************************************************
//
// Display an lwIP type IP Address.
//
//*****************************************************************************
void DisplayIPAddress(uint32_t ui32Addr)
{
char pcBuf[16];
// Convert the IP Address into a string.
usprintf(pcBuf, "%d.%d.%d.%d", ui32Addr & 0xff, (ui32Addr >> 8) & 0xff,
(ui32Addr >> 16) & 0xff, (ui32Addr >> 24) & 0xff);
UARTprintf(pcBuf);
}
//*****************************************************************************
//
// Required by lwIP library to support any host-related timer functions.
//
//*****************************************************************************
void lwIPHostTimerHandler(void)
{
uint32_t ui32NewIPAddress;
//
// Get the current IP address.
//
ui32NewIPAddress = lwIPLocalIPAddrGet();
//
// See if the IP address has changed.
//
if(ui32NewIPAddress != g_ui32IPAddress)
{
//
// See if there is an IP address assigned.
//
if(ui32NewIPAddress == 0xffffffff)
{
//
// Indicate that there is no link.
//
UARTprintf("Waiting for link.\n");
}
else if(ui32NewIPAddress == 0)
{
//
// There is no IP address, so indicate that the DHCP process is
// running.
//
UARTprintf("Waiting for IP address.\n");
}
else
{
g_bIPAddrValid = 1;
//
// Display the new IP address.
//
UARTprintf("IP Address: ");
DisplayIPAddress(ui32NewIPAddress);
}
//
// Save the new IP address.
//
g_ui32IPAddress = ui32NewIPAddress;
}
//
// If there is not an IP address.
//
if((ui32NewIPAddress == 0) || (ui32NewIPAddress == 0xffffffff))
{
//
// Do nothing and keep waiting.
//
UARTprintf("No IP Address: assigned waiting\n");
}
}
//*****************************************************************************
//
// The EchoReceive is a callback function when payload is received from the
// remote host
//
//*****************************************************************************
err_t EchoReceive(void *arg, struct tcp_pcb *tpcb, struct pbuf *p, err_t err)
{
uint32_t i = 0;
//
// Check for null pointer.
//
if (p == NULL)
{
//
// If null pointer has been passed in, close the connection.
//
UARTprintf("The Motion Table closed the connection.\n");
g_bconnect = false;
//allposttest_t.ethernettestflag = 1;
tcp_close(tpcb);
return ERR_ABRT;
}
else
{
tcp_recved(tpcb, p->tot_len);
UARTprintf("\r\nReceive %d bytes from the Termianl.\r\n", p->tot_len);
uint8_t *intReceiveData = p->payload;
uint32_t *int32ReceiveData = (uint32_t)p->payload;
//AESecb128_Decryption(int32ReceiveData, &Localbuff, g_pui32AES128Keytest,(uint32_t)p->tot_len);
fw_to_upgrade_memory(intReceiveData ,int32ReceiveData,(uint32_t)p->tot_len);
//memset(Localbuff,0,400);
SysCtlDelay(20);
//
// Free the packet buffer.
//
pbuf_free(p);
}
return ERR_OK;
}
//*****************************************************************************
//
// Function to send TCP packets to the server
//
//*****************************************************************************
uint32_t TcpSendPacket(EthRspPacket *HHCEthPacket, uint8_t PacketLength)
{
/* if(g_bconnect==false)
ClientInit();*/
// ClientInit();
//
// Queues the data pointed to by string.
//
err = tcp_write(tpcb1, HHCEthPacket, PacketLength, TCP_WRITE_FLAG_COPY);
if (err)
{
UARTprintf("ERROR: Code: %d (TcpSendPacket :: tcp_write)\n", err);
return 1;
}
//
// Transmit the data.
//
err = tcp_output(tpcb1);
//
// Report any error that occurs.
//
if (err)
{
UARTprintf("ERROR: Code: %d (TcpSendPacket :: tcp_output)\n", err);
return 1;
}
UARTprintf("data sent\n");
return 0;
}
//*****************************************************************************
//
// Callback function when the client establishes a successful connection to
// the remote host.
//
//*****************************************************************************
err_t ConnectCallback(void *arg, struct tcp_pcb *tpcb, err_t err)
{
if (err == ERR_OK)
{
UARTprintf("Connection Established.\n");
g_bconnect = true;
// allposttest_t.ethernettestflag = 0;
//
// Register the callback function EchoReceive when
// receiving data
//
tcp_recv(tpcb, EchoReceive);
tcp_sent(tpcb, NULL);
return 0;
}
else
{
UARTprintf("No Connection Established.\n");
return 1;
}
}
//*****************************************************************************
//
// Function to create a LwIP client.
//
//*****************************************************************************
void ClientInit(void)
{
//
// Create IP address structure.
//
struct ip4_addr server_addr;
//
// Create a new TCP control block.
//
tpcb1 = tcp_new();
if (tpcb1 != NULL)
{
//
// Assign destination server IP address.
//
server_addr.addr = inet_addr(SERVER_IPADDR);
//
// Configure destination IP address and port.
//
// err = tcp_connect(tpcb1, &server_addr, SERVER_PORT, ConnectCallback);
err = tcp_bind(tpcb1, INADDR_ANY, 1001);
if (err)
{
UARTprintf("ERROR: Code: %d (tcp_connect)\n", err);
}
tpcb1 = tcp_listen(tpcb1);
tcp_accept(tpcb1, ConnectCallback);
UARTprintf("\nPCB CREATED\n");
}
else
{
memp_free(MEMP_TCP_PCB, tpcb1);
UARTprintf("PCB NOT CREATED\n");
}
}
//*****************************************************************************
//
// This example demonstrates the use of the Ethernet Controller.
//
//*****************************************************************************
int tcpAPI_init(void)
{
uint32_t ui32User0, ui32User1;
uint8_t pui8MACArray[8];
//allposttest_t.ethernettestflag = 1;
//
// Configure the hardware MAC address for Ethernet Controller filtering of
// incoming packets. The MAC address will be stored in the non-volatile
// USER0 and USER1 registers.
//
MAP_FlashUserGet(&ui32User0, &ui32User1);
if((ui32User0 == 0xffffffff) || (ui32User1 == 0xffffffff))
{
//
// We should never get here. This is an error if the MAC address has
// not been programmed into the device. Exit the program.
// Let the user know there is no MAC address
//
UARTprintf("No MAC programmed!\n");
// return 1; //Failure
}
UARTprintf("Waiting for IP.\n");
//
// 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.
//
pui8MACArray[0] = ((ui32User0 >> 0) & 0xff);
pui8MACArray[1] = ((ui32User0 >> 8) & 0xff);
pui8MACArray[2] = ((ui32User0 >> 16) & 0xff);
pui8MACArray[3] = ((ui32User1 >> 0) & 0xff);
pui8MACArray[4] = ((ui32User1 >> 8) & 0xff);
pui8MACArray[5] = ((ui32User1 >> 16) & 0xff);
//
// Initialize the lwIP library, using STATIC.
//
lwIPInit(u32getSysClock(), pui8MACArray,
inet_addr(IPADDR),
inet_addr(NETMASK),
inet_addr(GWMASK),
IPADDR_USE_STATIC);
u8IPConfigCounter = 100; // 100 milliseconds
//TODO timer for ip address
//
// Wait here until a valid IP address is obtained before
// starting the client connection to the server.
//
while ((g_bIPAddrValid == 0) && (u8IPConfigCounter != 0));
//
// Initialize the client.
//
ClientInit();
//
// Set the interrupt priorities. We set the SysTick interrupt to a higher
// priority than the Ethernet interrupt to ensure that the file system
// tick is processed if SysTick occurs while the Ethernet handler is being
// processed. This is very likely since all the TCP/IP and HTTP work is
// done in the context of the Ethernet interrupt.
//
MAP_IntPrioritySet(INT_EMAC0, ETHERNET_INT_PRIORITY);
MAP_IntPrioritySet(FAULT_SYSTICK, SYSTICK_INT_PRIORITY);
return 0; //success
}
please help me to sort this issue