AnsweredAssumed Answered

Ethernet Communication Problem

Question asked by Utsavi Kalpesh Bharuchwala on Feb 21, 2014
Latest reply on Feb 23, 2014 by Daniel Chen

Hi All,

 

I am using TWR-K60D100M for ethernet communication.I have created new mqx4.0 project and write the following code for that.

 

/****************************************************************************

*

*   This file contains MQX only stationery code.

*

****************************************************************************/

#include "main.h"

#include <rtcs.h>

#include <ipcfg.h>

#include <fio.h>

#include <mqx.h>

#include <bsp.h>

 

#if !BSPCFG_ENABLE_IO_SUBSYSTEM

#error This application requires BSPCFG_ENABLE_IO_SUBSYSTEM defined non-zero in user_config.h. Please recompile BSP with this option.

#endif

 

#ifndef BSP_DEFAULT_IO_CHANNEL_DEFINED

#error This application requires BSP_DEFAULT_IO_CHANNEL to be not NULL. Please set corresponding BSPCFG_ENABLE_TTYx to non-zero in user_config.h and recompile BSP with this option.

#endif

 

uint_32 (_CODE_PTR_ const RTCS_protocol_table[])(void) = {

RTCSPROT_TCP,

NULL

};

 

 

TASK_TEMPLATE_STRUCT MQX_template_list[] =

{

/*  Task number, Entry point, Stack, Pri, String, Auto? */

   {MAIN_TASK,   Main_task,   1500,  9,   "main", MQX_AUTO_START_TASK},

   {0,           0,           0,     0,   0,      0,                 }

};

 

 

/*TASK*-----------------------------------------------------

*

* Task Name    : Main_task

* Comments     :

*    This task prints " Hello World "

*

*END*-----------------------------------------------------*/

 

 

void Main_task(uint_32 initial_data)

{

  IPCFG_IP_ADDRESS_DATA ip_data; _enet_address mac_address;

  uint_32 error;

  uint_32 sock,listensock;

  sockaddr_in addr;

  char str[] = "\n Hello World \n";

  uint_32 value;

  printf("\n Hello World \n");

  _RTCSPCB_init = 4; _RTCS_msgpool_init = 4; _RTCS_socket_part_init = 2; _RTCSTASK_priority = 8;

  error = RTCS_create();

  ip_data.ip = IPADDR(169,254,1,200);

  ip_data.mask = IPADDR(255,255,0,0);

  ip_data.gateway = 0;

  ENET_get_mac_address(BSP_DEFAULT_ENET_DEVICE, ip_data.ip,mac_address);

  ipcfg_init_device(BSP_DEFAULT_ENET_DEVICE, mac_address);

  error = ipcfg_bind_staticip(BSP_DEFAULT_ENET_DEVICE, &ip_data);

  listensock = socket(PF_INET, SOCK_STREAM, 0);

  value = 256;

  setsockopt(listensock,SOL_TCP, OPT_TBSIZE, &value, sizeof(value));

  setsockopt(listensock,SOL_TCP, OPT_RBSIZE, &value, sizeof(value));

  value = 1000;

  setsockopt(listensock,SOL_TCP, OPT_TIMEWAIT_TIMEOUT, &value,sizeof(value));

  /* Bind the socket to the Telnet port */

  addr.sin_family = AF_INET;

  addr.sin_port = IPPORT_TELNET;

  addr.sin_addr.s_addr = INADDR_ANY;

  error = bind(listensock, &addr, sizeof(addr));

  error = listen(listensock, 0);

  while (1) {

  sock= accept(listensock, NULL, NULL);

  if (sock != RTCS_SOCKET_ERROR) {

  send(sock,str, sizeof(str)-1,0);

  shutdown(sock,FLAG_CLOSE_TX);

  }

  }

  // _mqx_exit(0)

}

 

 

/* EOF */

 

but after running it indicate that "Socket is not created"..PLz help me

Outcomes