示例#1
0
/*! \brief create ethernet task, for ethernet management.
 *
 *  \param uxPriority   Input. priority for the task, it should be low
 *
 */
portTASK_FUNCTION(vStartEthernetTask, pvParameters)
{
	/* Setup lwIP. */
	prvlwIPInit();

#if (HTTP_USED == 1)
	/* Create the WEB server task.  This uses the lwIP RTOS abstraction layer. */
	sys_thread_new("WEB", vBasicWEBServer, (void *)NULL,
			lwipBASIC_WEB_SERVER_STACK_SIZE,
			lwipBASIC_WEB_SERVER_PRIORITY);
#endif

#if (TFTP_USED == 1)
  /* Create the TFTP server task.  This uses the lwIP RTOS abstraction layer. */
	sys_thread_new("TFTP", vBasicTFTPServer, (void *)NULL,
			lwipBASIC_TFTP_SERVER_STACK_SIZE,
			lwipBASIC_TFTP_SERVER_PRIORITY);
#endif

#if (SMTP_USED == 1)
  /* Create the SMTP Client task.  This uses the lwIP RTOS abstraction layer. */
	sys_thread_new("SMTP", vBasicSMTPClient, (void *)NULL,
			lwipBASIC_SMTP_CLIENT_STACK_SIZE,
			lwipBASIC_SMTP_CLIENT_PRIORITY);
#endif
	/* Kill this task. */
	vTaskDelete(NULL);
}
示例#2
0
文件: unixif.c 项目: fhauser/lwip-ppf
/*-----------------------------------------------------------------------------------*/
err_t
unixif_init_client(struct netif *netif)
{
  struct unixif *unixif;
  unixif = (struct unixif *)malloc(sizeof(struct unixif));
  if (!unixif) {
    return ERR_MEM;
  }
  netif->state = unixif;
  netif->name[0] = 'u';
  netif->name[1] = 'n';
  netif->output = unixif_output;

  unixif->fd = unix_socket_client("/tmp/lwip-lower");
  if (unixif->fd == -1) {
    perror("unixif_init");
    abort();
  }
  unixif->q = list_new(UNIXIF_QUEUELEN);
  if(sys_sem_new(&unixif->sem, 0) != ERR_OK) {
    LWIP_ASSERT("Failed to create semaphore", 0);
  }
  sys_thread_new("unixif_thread", unixif_thread, netif, DEFAULT_THREAD_STACKSIZE, DEFAULT_THREAD_PRIO);
  sys_thread_new("unixif_thread2", unixif_thread2, netif, DEFAULT_THREAD_STACKSIZE, DEFAULT_THREAD_PRIO);
  return ERR_OK;
}
示例#3
0
文件: simhost.c 项目: aps243/2A-lwIP
/*-----------------------------------------------------------------------------------*/
static void
main_thread(void *arg)
{
  sys_sem_t sem;
  LWIP_UNUSED_ARG(arg);

  if(sys_sem_new(&sem, 0) != ERR_OK) {
    LWIP_ASSERT("Failed to create semaphore", 0);
  }
  tcpip_init(tcpip_init_done, &sem);
  sys_sem_wait(&sem);
  printf("TCP/IP initialized.\n");

#if LWIP_SOCKET
  if(ping_flag) {
    sys_thread_new("ping_thread", ping_thread, NULL, DEFAULT_THREAD_STACKSIZE, DEFAULT_THREAD_PRIO);
  }
#endif

  printf("Applications started.\n");


#ifdef MEM_PERF
  mem_perf_init("/tmp/memstats.client");
#endif /* MEM_PERF */
#if 0
    stats_display();
#endif
  /* Block forever. */
  sys_thread_new("pppos_rx_thread", pppos_rx_thread, NULL, DEFAULT_THREAD_STACKSIZE, DEFAULT_THREAD_PRIO);
  sys_sem_wait(&sem);
}
示例#4
0
void ucos_test(void)
{
	char *str1 = "!";
	char *str2 = "?";

	
   OSInit();
	//mbox = OSQCreate (queue, sizeof(queue)/sizeof(queue[0]));
	//dprintf("OSQCreate return:0x%8x\r\n",mbox);
	
	/*install os timer*/	
	//sys_timer_start();
    //OSTaskCreate(task1,(void *)str1,&task1_stk[1024],11);
    //OSTaskCreate(task2,(void *)str2,&task2_stk[1024],10);
    //OSTaskCreate(task3,(void *)"*",&task3_stk[1024],11);
    //debug_enable = 1;
	sys_thread_new("thread1", task1, str1, 1024, 8);
	sys_thread_new("thread2", task2, str2, 1024, 9);
	sys_thread_new("thread3", task3, str2, 1024, 10);
	sys_mbox_new(&sys_mbox, 30);
	//sys_sem_new(&sys_sem, 0);
	sys_mutex_new(&sys_mutex);
    OSStart();
	
    while(1)
    {
        dprintf("os runtime error");
    }
}
void
launch_app_threads()
{
    /* start webserver thread */
    if (INCLUDE_WEB_SERVER)
        sys_thread_new("httpd", web_application_thread, 0,
                       THREAD_STACKSIZE,
                       DEFAULT_THREAD_PRIO);

    /* start echo server thread */
    if (INCLUDE_ECHO_SERVER)
        sys_thread_new("echod", echo_application_thread, 0,
                       THREAD_STACKSIZE,
                       DEFAULT_THREAD_PRIO);

    /* start tftp server thread */
    if (INCLUDE_TFTP_SERVER)
        sys_thread_new("tftpd", tftpserver_application_thread, 0,
                       THREAD_STACKSIZE,
                       DEFAULT_THREAD_PRIO);

    /* start echo server thread */
    if (INCLUDE_RXPERF_SERVER)
        sys_thread_new("rxperfd", rx_application_thread, 0,
                       THREAD_STACKSIZE,
                       DEFAULT_THREAD_PRIO);

    /* start echo server thread */
    if (INCLUDE_TXPERF_CLIENT)
        sys_thread_new("txperfd", tx_application_thread, 0,
                       THREAD_STACKSIZE,
                       DEFAULT_THREAD_PRIO);
}
示例#6
0
void socket_examples_init(void)
{
#if SOCKET_EXAMPLES_RUN_PARALLEL
  sys_thread_new("sockex_nonblocking_connect", sockex_nonblocking_connect, NULL, 0, 0);
  sys_thread_new("sockex_testrecv", sockex_testrecv, NULL, 0, 0);
  sys_thread_new("sockex_testtwoselects", sockex_testtwoselects, NULL, 0, 0);
#else
  sys_thread_new("socket_example_test", socket_example_test, NULL, 0, 0);
#endif
}
示例#7
0
文件: unixif.c 项目: fhauser/lwip-ppf
/*-----------------------------------------------------------------------------------*/
err_t
unixif_init_server(struct netif *netif)
{
  int fd, fd2;
  struct sockaddr_un addr;
  socklen_t len;
  struct unixif *unixif;

  fd = unix_socket_server("/tmp/lwip-lower");

  if (fd == -1) {
    perror("unixif_server");
    abort();
  }
  LWIP_DEBUGF(UNIXIF_DEBUG, ("unixif_server: fd %d\n", fd));

//
  /* device capabilities */
  /* don't set NETIF_FLAG_ETHARP if this device is not an ethernet one */
  netif->flags |= NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP;
//

  unixif = (struct unixif *)malloc(sizeof(struct unixif));
  if (!unixif) {
    return ERR_MEM;
  }

  // unixif-struct is stored in state-field of the netif-structure
  netif->state = unixif;
  netif->name[0] = 'u';
  netif->name[1] = 'n';
  netif->output = unixif_output;
  unixif->q = list_new(UNIXIF_QUEUELEN);

  len = sizeof(addr);
  fd2 = accept(fd, (struct sockaddr *)&addr, &len);

  if (fd2 == -1) {
    perror("unixif_accept");
    abort();
  }

  LWIP_DEBUGF(UNIXIF_DEBUG, ("unixif_accept: %d\n", fd2));

  unixif->fd = fd2;
  if(sys_sem_new(&unixif->sem, 0) != ERR_OK) {
    LWIP_ASSERT("Failed to create semaphore", 0);
  }
  sys_thread_new("unixif_thread", unixif_thread, netif, DEFAULT_THREAD_STACKSIZE, DEFAULT_THREAD_PRIO);
  sys_thread_new("unixif_thread2", unixif_thread2, netif, DEFAULT_THREAD_STACKSIZE, DEFAULT_THREAD_PRIO);
  return ERR_OK;
}
示例#8
0
err_t eth_arch_enetif_init(struct netif *netif)
{
    ethernet_cfg_t ethcfg;

    /* set MAC hardware address */
#if (MBED_MAC_ADDRESS_SUM != MBED_MAC_ADDR_INTERFACE)
    netif->hwaddr[0] = MBED_MAC_ADDR_0;
    netif->hwaddr[1] = MBED_MAC_ADDR_1;
    netif->hwaddr[2] = MBED_MAC_ADDR_2;
    netif->hwaddr[3] = MBED_MAC_ADDR_3;
    netif->hwaddr[4] = MBED_MAC_ADDR_4;
    netif->hwaddr[5] = MBED_MAC_ADDR_5;
#else
    mbed_mac_address((char *)netif->hwaddr);
#endif
    netif->hwaddr_len = ETHARP_HWADDR_LEN;

    /* maximum transfer unit */
    netif->mtu = 1500;

    /* device capabilities */
    netif->flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP | NETIF_FLAG_ETHERNET | NETIF_FLAG_IGMP;

#if LWIP_NETIF_HOSTNAME
    /* Initialize interface hostname */
    netif->hostname = "lwiprza1";
#endif /* LWIP_NETIF_HOSTNAME */

    netif->name[0] = 'e';
    netif->name[1] = 'n';

    netif->output     = rza1_etharp_output;
    netif->linkoutput = rza1_low_level_output;

    /* Initialize the hardware */
    ethcfg.int_priority = 6;
    ethcfg.recv_cb      = &rza1_recv_callback;
    ethcfg.ether_mac    = (char *)netif->hwaddr;
    ethernetext_init(&ethcfg);

    /* semaphore */
    sys_sem_new(&recv_ready_sem, 0);

    /* task */
    sys_thread_new("rza1_recv_task", rza1_recv_task, netif, DEFAULT_THREAD_STACKSIZE, RECV_TASK_PRI);
    sys_thread_new("rza1_phy_task", rza1_phy_task, netif, DEFAULT_THREAD_STACKSIZE, PHY_TASK_PRI);

    return ERR_OK;
}
示例#9
0
/* ------------------------------------------------------------------------------------------------------
 *									      socket_examples_init()
 *
 * Description : socket initialisation function.
 *
 * Argument(s) : none.
 *
 */
void TaskSocket_Create(void)
{
//	sys_thread_new("sockex_nonblocking_connect", sockex_nonblocking_connect, NULL, 128, 2);
//	sys_thread_new("sockex_testrecv", sockex_testrecv, NULL, 128, 3);
//	sys_thread_new("sockex_app", sockex_app, NULL, 128, 4);
	sys_thread_new("sockex_selects", sockex_selects, NULL, 256, 2);
}
示例#10
0
static void
low_level_init(struct netif *netif)
{
//  struct ethernetif *ethernetif = netif->state;
  unsigned portBASE_TYPE uxPriority;

  /* maximum transfer unit */
  netif->mtu = netifMTU;
  
  /* broadcast capability */
  netif->flags = NETIF_FLAG_BROADCAST;
 
  /* Do whatever else is needed to initialize interface. */  
  xNetIf = netif;

  /* Initialise the MACB.  This routine contains code that polls status bits.
  If the Ethernet cable is not plugged in then this can take a considerable
  time.  To prevent this starving lower priority tasks of processing time we
  lower our priority prior to the call, then raise it back again once the
  initialisation is complete. */
  uxPriority = uxTaskPriorityGet( NULL );
  vTaskPrioritySet( NULL, tskIDLE_PRIORITY );
  while( xMACBInit(&AVR32_MACB) == FALSE )
  {
    __asm__ __volatile__ ( "nop" );
  }
  vTaskPrioritySet( NULL, uxPriority );

  /* Create the task that handles the MACB. */
  // xTaskCreate( ethernetif_input, ( signed portCHAR * ) "ETH_INT", netifINTERFACE_TASK_STACK_SIZE, NULL, netifINTERFACE_TASK_PRIORITY, NULL );
  sys_thread_new( ethernetif_input, NULL, netifINTERFACE_TASK_PRIORITY );
}
示例#11
0
/*
 * Arguments: function, [arguments (any) ...]
 * Returns: [thread_udata]
 */
static int
thread_run (lua_State *L)
{
  struct sys_thread *td, *vmtd = sys_thread_get();

  if (!vmtd) luaL_argerror(L, 0, "Threading not initialized");
  luaL_checktype(L, 1, LUA_TFUNCTION);

  td = sys_thread_new(L, vmtd, NULL, 1);
  if (!td) goto err;

  lua_insert(L, 1);  /* thread_udata */

  /* function and arguments */
  {
    const int n = lua_gettop(L) - 1;
    luaL_checkstack(td->L, n, NULL);
    lua_xmove(L, td->L, n);
  }

  if (!sys_thread_create(td, 0)) {
    return 1;
  }
  sys_thread_del(td);
 err:
  return sys_seterror(L, 0);
}
示例#12
0
/*-----------------------------------------------------------------------------------*/
static void
low_level_init(struct netif *netif)
{
  struct tunif *tunif;
  char buf[100];

  tunif = netif->state;
  
  /* Obtain MAC address from network interface. */

  /* Do whatever else is needed to initialize interface. */
  
  tunif->fd = open("/dev/tun0", O_RDWR);
  DEBUGF(TUNIF_DEBUG, ("tunif_init: fd %d\n", tunif->fd));
  if(tunif->fd == -1) {
    perror("tunif_init");
    exit(1);
  }
  snprintf(buf, sizeof(buf), "ifconfig tun0 inet %d.%d.%d.%d %d.%d.%d.%d",
           ip4_addr1(&(netif->gw)),
           ip4_addr2(&(netif->gw)),
           ip4_addr3(&(netif->gw)),
           ip4_addr4(&(netif->gw)),
           ip4_addr1(&(netif->ip_addr)),
           ip4_addr2(&(netif->ip_addr)),
           ip4_addr3(&(netif->ip_addr)),
           ip4_addr4(&(netif->ip_addr)));
  
  DEBUGF(TUNIF_DEBUG, ("tunif_init: system(\"%s\");\n", buf));
  system(buf);
  sys_thread_new(tunif_thread, netif);

}
示例#13
0
void uip_sys_init(void)
{

    uip_init();         //uip init
    sys_thread_new("uip",uip_tcpip_thread, RT_NULL, RT_LWIP_TCPTHREAD_STACKSIZE, RT_LWIP_TCPTHREAD_PRIORITY);
    hello_world_init(); //
}
示例#14
0
/**
 * SLIP netif initialization
 *
 * Call the arch specific sio_open and remember
 * the opened device in the state field of the netif.
 *
 * @param netif the lwip network interface structure for this slipif
 * @return ERR_OK if serial line could be opened,
 *         ERR_MEM if no memory could be allocated,
 *         ERR_IF is serial line couldn't be opened
 *
 * @note netif->num must contain the number of the serial port to open
 *       (0 by default). If netif->state is != NULL, it is interpreted as an
 *       u8_t pointer pointing to the serial port number instead of netif->num.
 *
 */
err_t
slipif_init(struct netif *netif)
{
  struct slipif_priv *priv;
  u8_t sio_num;

  LWIP_DEBUGF(SLIP_DEBUG, ("slipif_init: netif->num=%"U16_F"\n", (u16_t)netif->num));

  /* Allocate private data */
  priv = (struct slipif_priv *)mem_malloc(sizeof(struct slipif_priv));
  if (!priv) {
    return ERR_MEM;
  }

  netif->name[0] = 's';
  netif->name[1] = 'l';
#if LWIP_IPV4
  netif->output = slipif_output_v4;
#endif /* LWIP_IPV4 */
#if LWIP_IPV6
  netif->output_ip6 = slipif_output_v6;
#endif /* LWIP_IPV6 */
  netif->mtu = SLIP_MAX_SIZE;

  /* netif->state or netif->num contain the port number */
  if (netif->state != NULL) {
    sio_num = *(u8_t*)netif->state;
  } else {
    sio_num = netif->num;
  }
  /* Try to open the serial port. */
  priv->sd = sio_open(sio_num);
  if (!priv->sd) {
    /* Opening the serial port failed. */
    mem_free(priv);
    return ERR_IF;
  }

  /* Initialize private data */
  priv->p = NULL;
  priv->q = NULL;
  priv->state = SLIP_RECV_NORMAL;
  priv->i = 0;
  priv->recved = 0;
#if SLIP_RX_FROM_ISR
  priv->rxpackets = NULL;
#endif

  netif->state = priv;

  /* initialize the snmp variables and counters inside the struct netif */
  MIB2_INIT_NETIF(netif, snmp_ifType_slip, SLIP_SIO_SPEED(priv->sd));

#if SLIP_USE_RX_THREAD
  /* Create a thread to poll the serial line. */
  sys_thread_new(SLIPIF_THREAD_NAME, slipif_loop_thread, netif,
    SLIPIF_THREAD_STACKSIZE, SLIPIF_THREAD_PRIO);
#endif /* SLIP_USE_RX_THREAD */
  return ERR_OK;
}
示例#15
0
/*-----------------------------------------------------------------------------------*/
static void
low_level_init(struct netif *netif)
{
  struct tunif *tunif;
  char buf[sizeof(IFCONFIG_CALL) + 50];

  tunif = (struct tunif *)netif->state;

  /* Obtain MAC address from network interface. */

  /* Do whatever else is needed to initialize interface. */

  tunif->fd = open("/dev/tun0", O_RDWR);
  LWIP_DEBUGF(TUNIF_DEBUG, ("tunif_init: fd %d\n", tunif->fd));
  if (tunif->fd == -1) {
    perror("tunif_init");
    exit(1);
  }
  sprintf(buf, IFCONFIG_CALL,
           ip4_addr1(&(netif->gw)),
           ip4_addr2(&(netif->gw)),
           ip4_addr3(&(netif->gw)),
           ip4_addr4(&(netif->gw)),
           ip4_addr1(&(netif->ip_addr)),
           ip4_addr2(&(netif->ip_addr)),
           ip4_addr3(&(netif->ip_addr)),
           ip4_addr4(&(netif->ip_addr)));

  LWIP_DEBUGF(TUNIF_DEBUG, ("tunif_init: system(\"%s\");\n", buf));
  system(buf);
  sys_thread_new("tunif_thread", tunif_thread, netif, DEFAULT_THREAD_STACKSIZE, DEFAULT_THREAD_PRIO);

}
示例#16
0
/*-----------------------------------------------------------------------------------*/
err_t
delif_init_thread(struct netif *netif)
{
  struct delif *del;

  LWIP_DEBUGF(DELIF_DEBUG, ("delif_init_thread\n"));
  
  del = malloc(sizeof(struct delif));
  if (!del)
      return ERR_MEM;
  netif->state = del;
  netif->name[0] = 'd';
  netif->name[1] = 'e';
  netif->output = delif_output;

  del->netif = malloc(sizeof(struct netif));
  if (!del->netif) {
      free(del);
      return ERR_MEM;
  }
  del->netif->ip_addr = netif->ip_addr;
  del->netif->gw = netif->gw;
  del->netif->netmask = netif->netmask;
  del->input = netif->input;
  del->netif->input = delif_input;
  sys_thread_new("delif_thread", delif_thread, netif, DEFAULT_THREAD_STACKSIZE, DEFAULT_THREAD_PRIO);
  return ERR_OK;
}
示例#17
0
//---------------------------------------------------------------------
int update_ota_cloud(char *repository, char *file_path)
{
	update_cfg_cloud_t *pUpdateCfg;
	
	if(TaskOTA){
		printf("\n\r[%s] Update task has created.", __FUNCTION__);
		return 0;
	}
	pUpdateCfg = update_malloc(sizeof(update_cfg_cloud_t));
	if(pUpdateCfg == NULL){
		printf("\n\r[%s] Alloc update cfg failed.", __FUNCTION__);
		goto exit;
	}
	if(strlen(repository) > (REPOSITORY_LEN-1)){
		printf("\n\r[%s] Repository length is too long.", __FUNCTION__);
		goto exit;
	}
	if(strlen(file_path) > (FILE_PATH_LEN-1)){
		printf("\n\r[%s] File path length is too long.", __FUNCTION__);
		goto exit;
	}
	strcpy((char*)pUpdateCfg->repository, repository);
	strcpy((char*)pUpdateCfg->file_path, file_path);

	TaskOTA = sys_thread_new("OTA_server", update_ota_cloud_task, pUpdateCfg, STACK_SIZE, TASK_PRIORITY);
	if(TaskOTA == NULL){	  	
		printf("\n\r[%s] Create update task failed", __FUNCTION__);
		goto exit;
	}

exit:
	update_free(pUpdateCfg);
	return 0;
}
示例#18
0
void echo_application_thread()
{
	int sock, new_sd;
	struct sockaddr_in address, remote;
	int size;

	if ((sock = lwip_socket(AF_INET, SOCK_STREAM, 0)) < 0)
		return;

	address.sin_family = AF_INET;
	address.sin_port = htons(echo_port);
	address.sin_addr.s_addr = INADDR_ANY;

	if (lwip_bind(sock, (struct sockaddr *)&address, sizeof (address)) < 0)
		return;

	lwip_listen(sock, 0);

	size = sizeof(remote);

	while (1) {
		if ((new_sd = lwip_accept(sock, (struct sockaddr *)&remote, (socklen_t *)&size)) > 0) {
			sys_thread_new("echos", process_echo_request,
				(void*)new_sd,
				THREAD_STACKSIZE,
				DEFAULT_THREAD_PRIO);
		}
	}
}
示例#19
0
/**
 * SLIP netif initialization
 *
 * Call the arch specific sio_open and remember
 * the opened device in the state field of the netif.
 *
 * @param netif the lwip network interface structure for this slipif
 * @return ERR_OK if serial line could be opened,
 *         ERR_IF is serial line couldn't be opened
 *
 * @note netif->num must contain the number of the serial port to open
 *       (0 by default)
 */
err_t
slipif_init(struct netif *netif)
{

  LWIP_DEBUGF(SLIP_DEBUG, ("slipif_init: netif->num=%"U16_F"\n", (u16_t)netif->num));

  netif->name[0] = 's';
  netif->name[1] = 'l';
  netif->output = slipif_output;
  netif->mtu = MAX_SIZE;
  netif->flags = NETIF_FLAG_POINTTOPOINT;

  /* Try to open the serial port (netif->num contains the port number). */
  netif->state = sio_open(netif->num);
  if (!netif->state) {
    /* Opening the serial port failed. */
    return ERR_IF;
  }

  /* initialize the snmp variables and counters inside the struct netif
   * ifSpeed: no assumption can be made without knowing more about the
   * serial line!
   */
  NETIF_INIT_SNMP(netif, snmp_ifType_slip, 0);

  /* Create a thread to poll the serial line. */
  sys_thread_new(SLIPIF_THREAD_NAME, slipif_loop, netif, SLIPIF_THREAD_STACKSIZE, SLIPIF_THREAD_PRIO);
  return ERR_OK;
}
示例#20
0
void cli_local_main( void* pport ) {
    uint16_t port;
    struct sockaddr_in addr;
    struct sockaddr client_addr;
    unsigned sock_len = sizeof(struct sockaddr);
    int bindfd;
    int clientfd;
    cli_client_t* client;

    port = *(uint16_t*)pport;
    free( pport );

    /* create a socket to listen for connections on */
    bindfd = socket( AF_INET, SOCK_STREAM, 0 );
    if( bindfd == -1 ) {
        die( "Error: unable to create a real IPv4 TCP socket" );
    }

    /* allow reuse of the port */
    int reuse = 1;
    if( setsockopt( bindfd, SOL_SOCKET, SO_REUSEADDR, &reuse, sizeof(reuse) ) )
        die( "Error: SO_REUSEADDR failed" );

    /* bind to the requested port */
    addr.sin_port = htons(port);
    addr.sin_addr.s_addr = 0;
    memset(&(addr.sin_zero), 0, sizeof(addr.sin_zero));
    if( bind(bindfd, (struct sockaddr*)&addr, sizeof(struct sockaddr)) ) {
        die( "Error: unable to bind to local port %u", port );
    }

    /* listen for clients */
    listen( bindfd, 10 );

    while( !cli_is_time_to_shutdown() ) {
        /* wait for a new client */
        clientfd = accept(bindfd, &client_addr, &sock_len);
        if( clientfd == - 1 ) {
            if( errno == EINTR ) {
                /* Interrupt received, going back to real accept() */
                continue;
            }

            /* some error */
            fprintf( stderr, "Warrning: real accept() returned an error code (%d)", errno );
            continue;
        }

        /* create a client record */
        client = (cli_client_t*)malloc_or_die( sizeof(cli_client_t) );
        client->fd = -clientfd; /* negative means use the real sockets */
        search_state_init( &client->state, CLI_INIT_BUF, CLI_MAX_BUF );

        /* spawn a new thread to handle the client */
        sys_thread_new( cli_client_handler_main, client );
    }

    exit( 0 );
}
示例#21
0
/*-----------------------------------------------------------------------------------*/
void
tcpip_init(void (* initfunc)(void *), void *arg)
{
  tcpip_init_done = initfunc;
  tcpip_init_done_arg = arg;
  mbox = sys_mbox_new();
  sys_thread_new((void *)tcpip_thread, NULL);
}
示例#22
0
/**
  * @brief  Initialize the HTTP server (start its thread) 
  * @param  None
  * @retval None
  */
void http_init()
{
  nPageHits = 0;
  if(HTTP_Task_Handle == NULL)
  {
    HTTP_Task_Handle = sys_thread_new("HTTP", http_ipcam_thread, NULL, HTTP_THREAD_STACK_SIZE, HTTP_THREAD_PRIO);
  }
}
void
tcpip_init(void (* initfunc)(void *), void *arg)
{
  tcpip_init_done = initfunc;
  tcpip_init_done_arg = arg;
  tcp_mbox = sys_mbox_new();
  sys_thread_new(tcpip_thread, NULL, TCPIP_THREAD_PRIO);
}
/**
 * In this function, the hardware should be initialized.
 * Called from ethernetif_init().
 *
 * @param netif the already initialized lwip network interface structure
 *        for this ethernetif
 */
static void
low_level_init(struct netif *netif)
{
#ifdef FREERTOS_USED
  unsigned portBASE_TYPE uxPriority;
#endif


  /* set MAC hardware address length */
  netif->hwaddr_len = ETHARP_HWADDR_LEN;

  /* set MAC hardware address */
	netif->hwaddr[0] = cMACAddress[0];
	netif->hwaddr[1] = cMACAddress[1];
	netif->hwaddr[2] = cMACAddress[2];
	netif->hwaddr[3] = cMACAddress[3];
	netif->hwaddr[4] = cMACAddress[4];
	netif->hwaddr[5] = cMACAddress[5];

  /* maximum transfer unit */
  netif->mtu = 1500;

  /* device capabilities */
  /* don't set NETIF_FLAG_ETHARP if this device is not an ethernet one */
  netif->flags |= NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP
#if defined(DHCP_USED)
    | NETIF_FLAG_DHCP
#endif
  ;

  /* Do whatever else is needed to initialize interface. */
  /* Initialise the MACB. */
#ifdef FREERTOS_USED
  // NOTE: This routine contains code that polls status bits. If the Ethernet
  // cable is not plugged in then this can take a considerable time.  To prevent
  // this from starving lower priority tasks of processing time we lower our
  // priority prior to the call, then raise it back again once the initialization
  // is complete.

  // Read the priority of the current task.
  uxPriority = uxTaskPriorityGet( NULL );
  // Set the priority of the current task to the lowest possible.
  vTaskPrioritySet( NULL, tskIDLE_PRIORITY );
#endif
  // Init the MACB interface.
  while( xMACBInit(&AVR32_MACB) == false )
  {
    __asm__ __volatile__ ( "nop" );
  }
#ifdef FREERTOS_USED
  // Restore the priority of the current task.
  vTaskPrioritySet( NULL, uxPriority );

  /* Create the task that handles the MACB input packets. */
  sys_thread_new( "ETHINT", ethernetif_input, netif, netifINTERFACE_TASK_STACK_SIZE,
                  netifINTERFACE_TASK_PRIORITY );
#endif
}
示例#25
0
/*! \brief create ethernet task, for ethernet management.
 *
 *  \param uxPriority   Input. priority for the task, it should be low
 *
 */
portTASK_FUNCTION( vStartEthernetTask, pvParameters )
{
   static const gpio_map_t MACB_GPIO_MAP =
   {
      {EXTPHY_MACB_MDC_PIN,     EXTPHY_MACB_MDC_FUNCTION   },
      {EXTPHY_MACB_MDIO_PIN,    EXTPHY_MACB_MDIO_FUNCTION  },
      {EXTPHY_MACB_RXD_0_PIN,   EXTPHY_MACB_RXD_0_FUNCTION },
      {EXTPHY_MACB_TXD_0_PIN,   EXTPHY_MACB_TXD_0_FUNCTION },
      {EXTPHY_MACB_RXD_1_PIN,   EXTPHY_MACB_RXD_1_FUNCTION },
      {EXTPHY_MACB_TXD_1_PIN,   EXTPHY_MACB_TXD_1_FUNCTION },
      {EXTPHY_MACB_TX_EN_PIN,   EXTPHY_MACB_TX_EN_FUNCTION },
      {EXTPHY_MACB_RX_ER_PIN,   EXTPHY_MACB_RX_ER_FUNCTION },
      {EXTPHY_MACB_RX_DV_PIN,   EXTPHY_MACB_RX_DV_FUNCTION },
      {EXTPHY_MACB_TX_CLK_PIN,  EXTPHY_MACB_TX_CLK_FUNCTION}
   };

   // Assign GPIO to MACB
   gpio_enable_module(MACB_GPIO_MAP, sizeof(MACB_GPIO_MAP) / sizeof(MACB_GPIO_MAP[0]));

   /* Setup lwIP. */
   prvlwIPInit();

#if (HTTP_USED == 1)
   /* Create the WEB server task.  This uses the lwIP RTOS abstraction layer.*/
   sys_thread_new( "WEB", vBasicWEBServer, ( void * ) NULL,
                   lwipBASIC_WEB_SERVER_STACK_SIZE,
                   lwipBASIC_WEB_SERVER_PRIORITY );
#endif

#if (TFTP_USED == 1)
   /* Create the TFTP server task.  This uses the lwIP RTOS abstraction layer.*/
   sys_thread_new( "TFTP", vBasicTFTPServer, ( void * ) NULL,
                   lwipBASIC_TFTP_SERVER_STACK_SIZE,
                   lwipBASIC_TFTP_SERVER_PRIORITY );
#endif

#if (SMTP_USED == 1)
   /* Create the SMTP Client task.  This uses the lwIP RTOS abstraction layer.*/
   sys_thread_new( "SMTP", vBasicSMTPClient, ( void * ) NULL,
                   lwipBASIC_SMTP_CLIENT_STACK_SIZE,
                   lwipBASIC_SMTP_CLIENT_PRIORITY );
#endif
  // Kill this task.
  vTaskDelete(NULL);
}
示例#26
0
文件: ping.c 项目: AleksKolkov/lrndis
void
ping_init(void)
{
#if PING_USE_SOCKETS
  sys_thread_new("ping_thread", ping_thread, NULL, DEFAULT_THREAD_STACKSIZE, DEFAULT_THREAD_PRIO);
#else /* PING_USE_SOCKETS */
  ping_raw_init();
#endif /* PING_USE_SOCKETS */
}
示例#27
0
文件: lwIP_Apps.c 项目: Eclo/FreeRTOS
/* Called from the TCP/IP thread. */
void lwIPAppsInit( void *pvArgument )
{
ip_addr_t xIPAddr, xNetMask, xGateway;
extern err_t xemacpsif_init( struct netif *netif );
extern void xemacif_input_thread( void *netif );
static struct netif xNetIf;

	( void ) pvArgument;

	/* Set up the network interface. */
	ip_addr_set_zero( &xGateway );
	ip_addr_set_zero( &xIPAddr );
	ip_addr_set_zero( &xNetMask );

	LWIP_PORT_INIT_GW(&xGateway);
	LWIP_PORT_INIT_IPADDR( &xIPAddr );
	LWIP_PORT_INIT_NETMASK(&xNetMask);

	/* Set mac address */
	xNetIf.hwaddr_len = 6;
	xNetIf.hwaddr[ 0 ] = configMAC_ADDR0;
	xNetIf.hwaddr[ 1 ] = configMAC_ADDR1;
	xNetIf.hwaddr[ 2 ] = configMAC_ADDR2;
	xNetIf.hwaddr[ 3 ] = configMAC_ADDR3;
	xNetIf.hwaddr[ 4 ] = configMAC_ADDR4;
	xNetIf.hwaddr[ 5 ] = configMAC_ADDR5;

	netif_set_default( netif_add( &xNetIf, &xIPAddr, &xNetMask, &xGateway, ( void * ) XPAR_XEMACPS_0_BASEADDR, xemacpsif_init, tcpip_input ) );
	netif_set_status_callback( &xNetIf, vStatusCallback );
	#if LWIP_DHCP
	{
		dhcp_start( &xNetIf );
	}
	#else
	{
		netif_set_up( &xNetIf );
	}
	#endif

	/* Install the server side include handler. */
	http_set_ssi_handler( uslwIPAppsSSIHandler, pccSSITags, sizeof( pccSSITags ) / sizeof( char * ) );

	/* Create the mutex used to ensure mutual exclusive access to the Tx 
	buffer. */
	xTxBufferMutex = xSemaphoreCreateMutex();
	configASSERT( xTxBufferMutex );

	/* Create the httpd server from the standard lwIP code.  This demonstrates
	use of the lwIP raw API. */
	httpd_init();

	sys_thread_new( "lwIP_In", xemacif_input_thread, &xNetIf, configMINIMAL_STACK_SIZE, configMAC_INPUT_TASK_PRIORITY );

	/* Create the FreeRTOS defined basic command server.  This demonstrates use
	of the lwIP sockets API. */
	xTaskCreate( vBasicSocketsCommandInterpreterTask, "CmdInt", configMINIMAL_STACK_SIZE * 5, NULL, configCLI_TASK_PRIORITY, NULL );
}
示例#28
0
/**
 * Add a network interface
 */
void apps_init( void )
{
	vSerialPutString("INIT\n");
	vSerialPutString("...\n");
	if( sys_thread_new( "demo-apps", vDemoAppsTask, NULL, 1024, (tskIDLE_PRIORITY + 1) ) == NULL )
		printf( "apps_init: create task failed!\n");

	vSerialPutString("OK\n");
}
示例#29
0
void
launch_app_threads()
{
    /* start echo server thread */
    if (INCLUDE_ECHO_SERVER)
        sys_thread_new("echod", echo_application_thread, 0,
            THREAD_STACKSIZE,
            DEFAULT_THREAD_PRIO);
}
示例#30
0
/*! \brief create ethernet task, for ethernet management.
 *
 *  \param uxPriority   Input. priority for the task, it should be low
 *
 */
portTASK_FUNCTION(vStartEthernetTask, pvParameters)
{
	/* Setup lwIP. */
	prvlwIPInit();

	/* Create the WEB server task.  This uses the lwIP RTOS abstraction layer. */
	sys_thread_new("WEB", vBasicWEBServer, (void *)NULL,
					lwipBASIC_WEB_SERVER_STACK_SIZE,
					lwipBASIC_WEB_SERVER_PRIORITY);

	/* Create the Socket Server task.  This uses the lwIP RTOS abstraction layer. */
	sys_thread_new("NETS", vNetHandle, (void *)NULL,
					TASK_TCP_SERVER_STACK_SIZE,
					TASK_TCP_SERVER_PRIORITY);

	/* Kill this task. */
	vTaskDelete(NULL);
}