?? application.c
字號:
/*
* File : app.c
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006, RT-Thread Development Team
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://openlab.rt-thread.com/license/LICENSE
*
* Change Logs:
* Date Author Notes
* 2007-11-20 Yi.Qiu add rtgui application
* 2008-6-28 Bernard no rtgui init
*/
/**
* @addtogroup s3ceb2410
*/
/*@{*/
#include <rtthread.h>
#ifdef RT_USING_LWIP
#include "lwip/sys.h"
#include "lwip/api.h"
void thread_tcpecho(void *parameter)
{
struct netconn *conn, *newconn;
err_t err;
/* Create a new connection identifier. */
conn = netconn_new(NETCONN_TCP);
/* Bind connection to well known port number 7. */
netconn_bind(conn, NULL, 7);
/* Tell connection to go into listening mode. */
netconn_listen(conn);
while(1)
{
/* Grab new connection. */
newconn = netconn_accept(conn);
/* Process the new connection. */
if(newconn != NULL)
{
struct netbuf *buf;
void *data;
u16_t len;
while((buf = netconn_recv(newconn)) != NULL)
{
do
{
netbuf_data(buf, &data, &len);
err = netconn_write(newconn, data, len, NETCONN_COPY);
if(err != ERR_OK)
{
rt_kprintf("echo write error %d\n", err);
break;
}
} while(netbuf_next(buf) >= 0);
netbuf_delete(buf);
}
/* Close connection and discard connection identifier. */
netconn_delete(newconn);
}
}
}
void lwip_init_entry(void* parameter)
{
/* init lwip system */
lwip_sys_init();
rt_kprintf("TCP/IP initialized!\n");
}
#endif
/**
* This function will be invoked to initalize user application when system startup.
*/
void rt_application_init()
{
#ifdef RT_USING_LWIP
rt_thread_t lwip_init;
rt_thread_t echo;
lwip_init = rt_thread_create("lw0",
lwip_init_entry, RT_NULL,
1024, 100,20);
rt_thread_startup(lwip_init);
echo = rt_thread_create("echo",
thread_tcpecho, RT_NULL,
1024, 200,20);
rt_thread_startup(echo);
#endif
}
/*@}*/
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -