初级会员
- 积分
- 101
- 金钱
- 101
- 注册时间
- 2019-10-24
- 在线时间
- 34 小时
|
用正点原子的扩展程序,网络实验9 NETCONN_TCP服务器,但server建立好后,当有连接的时候,获得IP地址,并创建一个task,发现当task执行完时,系统死机,不知道什么原因,大佬帮忙看下是什么问题。发现在tcp_test执行完后就死机了。
static void tcp_server_thread(void *arg)
{
OS_CPU_SR cpu_sr;
u32 data_len = 0;
struct pbuf *q;
err_t err,recv_err;
u8 remot_addr[4];
struct netconn *conn, *newconn;
static ip_addr_t ipaddr;
static u16_t port;
uint8_t clientnumindex=0;
client_init();
LWIP_UNUSED_ARG(arg);
conn = netconn_new(NETCONN_TCP); //′′½¨ò»¸öTCPá′½ó
netconn_bind(conn,IP_ADDR_ANY,TCP_SERVER_PORT); //°ó¶¨¶Ë¿ú
netconn_listen(conn); //½øèë¼àìyÄ£ê½
conn->recv_timeout = 10; //½ûÖ1×èèûÏß3ì μè′y10ms
//printf("Server is ready\r\n");
while (1)
{
err = netconn_accept(conn,&newconn); //½óêÕᬽóÇëÇó
if(err==ERR_OK) newconn->recv_timeout = 10;
if (err == ERR_OK) //′|àíDÂᬽóμÄêy¾Y
{
if(set_client((void *)&newconn,&clientnumindex) != ERR_OK)
{
netconn_close(newconn);
netconn_delete(newconn);
}
else
{
// printf("clientnumindex=%d\r\n",clientnumindex);
create_task_handle_client(newconn,clientnumindex);
}
}
delay_ms(10);
}
// printf("Server is exit\r\n");
}
static int task_parameter=0;
void create_task_handle_client(struct netconn *newconn,int clientnumindex)
{
OS_CPU_SR cpu_sr;
// uint8_t index=0;
// printf("entry create_task_handle_client %d\r\n",clientnumindex);
clientad.client[clientnumindex]=newconn;
clientad.state[clientnumindex]=1;
task_parameter =clientnumindex;
//index =clientnumindex;
// printf("addr:0x%p",&clientnumindex);
//clientad.client_taskid[clientnumindex] = osThreadCreate(osThread(myTaskClient), (void *)clientnumindex);
OS_ENTER_CRITICAL(); //1ØÖD¶Ï
// clientad.client_taskid[clientnumindex] = OSTaskCreateExt(tcp_server_datahandle_thread,(void*)&clientnumindex,(void*)&clientad.TCPSERVER_HANDLE_TASK_STK[clientnumindex][TCPSERVER_HANDLE_STK_SIZE-1],clientad.prio[clientnumindex],clientad.prio[clientnumindex],(OS_STK*)&clientad.TCPSERVER_HANDLE_TASK_STK[clientnumindex][TCPSERVER_HANDLE_STK_SIZE-1],TCPSERVER_HANDLE_STK_SIZE,NULL,0);
clientad.client_taskid[clientnumindex] =OSTaskCreate(/*tcp_server_datahandle_thread*/tcp_test, (void*)&task_parameter,(OS_STK*)&clientad.TCPSERVER_HANDLE_TASK_STK[clientnumindex][TCPSERVER_HANDLE_STK_SIZE-1],clientad.prio[clientnumindex]); //′′½¨TCP·tÎñÆ÷Ïß3ì
OS_EXIT_CRITICAL(); //¿aÖD¶Ï
if(clientad.client_taskid[clientnumindex]!=0)
{
// printf("Failed to create the recv thread with id: %d\n",clientad.client_taskid[clientnumindex] );
}
else
{
// printf("create the recv thread with id: %x\n",(int)(clientad.client_taskid[clientnumindex]));
}
}
static void tcp_test(void *arg)
{
OS_CPU_SR cpu_sr;
int i=0;
for(i=0;i<100;i++)
{
OSTimeDlyHMSM(0,0,0,100);
}
OS_ENTER_CRITICAL(); //1ØÖD¶Ï
printf("exit tcp test\r\n");
OS_EXIT_CRITICAL(); //¿aÖD¶Ï
OS_Sched();
}
|
|