19001579 发表于 2010-8-5 19:05:15

LWIP网络问题LM3S8962

#include <stdio.h>
#include <string.h>
#include "http_webs.h"
                               
/* 这是实际的web页面数据。大部分的编译器会将这些数据放在ROM里*/
const static char index_html[] ={
   "<html>\r\n"
   "<head>\r\n"
   "   <meta http-equiv=\"X-UA-Compatible\" content=\"IE=7\">\r\n"
   "    <meta http-equiv=\"content-type\" content=\"text/html;charset=gb2312\">\r\n"
   "   <title>CORTEX-M3 LM3S8962 HTML 测试程序</title>\r\n"
   "</head>\r\n"
   "<body >\r\n"
   "   <form name=\"loginForm\" method=\"post\" action=\"hello.htm\">\r\n"
   "      <table>\r\n"
   "       <tr><td><div align=\"right\">用户名:</div></td>\r\n"
   "             <td><input type=\"text\" name=\"username\"></td>\r\n"
   "          </tr>\r\n"
   "          <tr><td><div align=\"right\">口令:</div></td>\r\n"
   "            <td><input type=\"password\" name=\"password\"></td>\r\n"
   "          </tr>\r\n"
   "          <tr><td></td>\r\n"
   "            <td><input type=\"submit\" name=\"submit\" value=\"submit\"></td>\r\n"
   "          </tr>\r\n"
   "      </table>\r\n"
   "    </form>\r\n"
   "\r\n"
   "\"poto1.jpg\"\r\n"
   "</body>\r\n"
   "</html>\r\n"
   "\r\n"
};
const static char http_html_hdr[] = "HTTP/1.1 200 OK\r\nContent-type: text/html\r\n\r\n";

/* 线程入口*/
void rt_webserver_thread(void* paramter)
{

    struct netconn *conn, *newconn;
    struct netbuf        *TCPNetbuf=NULL;
   
        char *rq;
        char *uri;
        unsigned int i;
        unsigned short len;

        int fd,size=1;
        char file_data_buffer;

    conn = netconn_new(NETCONN_TCP);      /* 创建TCP连接*/
   
    netconn_bind(conn,NULL,80);         /* 绑定本地地址和监听的端口号 */
   
    netconn_listen(conn);               /* 进入监听状态 */
    while(1)
    {
      newconn = netconn_accept(conn);    /*阻塞当前进程到有数据接收 */
      if(newconn != NULL)
      {   
              TCPNetbuf = netconn_recv(newconn);
            if(TCPNetbuf != NULL)
               {
                                  netbuf_data( TCPNetbuf,(void *)&rq,&len);
                                  uri=&rq;//请求内容,前四字节是请求类型,GET与POST 后面为用户请求
                                  if (strncmp(rq, "GET ", 4) == 0)
                                         {
                                             
                                                /*************************GET 用户请求********************************/
                                               for(i = 4; i < (len - 5); i++)       /*提取用户请求以HTTP为界*/
                                                  {
                                                  if ((rq == ' ')&&(rq == 'H') &&(rq == 'T') && (rq == 'T') &&(rq == 'P'))
                                                              {
                                                                    rq = 0;
                                                                   break;
                                                         }
                           }
                                      if(i == (len - 5))/*提取用户请求失败*/
                                                        {
                                                                   netbuf_delete(TCPNetbuf);
                                                                   netconn_close(newconn);       /* 关闭连接   */   
                                                         while(netconn_delete(newconn) != ERR_OK);
                                                continue;/*结束本次处理,如果是在函数里面就使用返回*/
                                                        }
                                          /*************************GET 请求********************************/
                                        rt_kprintf("\n");
                                        rt_kprintf((void *)uri);
                                  rt_kprintf("\n");

                                        if((uri=='/')&&(uri==0))         //默认打开的页面
                                       {
                                              netconn_write(newconn,http_html_hdr,sizeof(http_html_hdr),NETCONN_NOCOPY);
                                        /* 发送头部数据*/
                                       netconn_write(newconn,index_html,sizeof(index_html),NETCONN_NOCOPY);
                                           /* 发送实际的WEB页面 */

                                       }//END IF URI
                                       else                    /*其它文件请求处理*/
                                          {
                                                   rt_kprintf("send head string...\n");
                                                   netconn_write(newconn,g_psHTTPHeaderStrings,sizeof(g_psHTTPHeaderStrings),NETCONN_NOCOPY);
                                                     netconn_write(newconn,g_psHTTPHeaderStrings,sizeof(g_psHTTPHeaderStrings),NETCONN_NOCOPY);
                                                        rt_kprintf("open file...\n");                                               
                                                       fd = open("/DCIM/100MEDIA/IMG_001.JPG", O_RDONLY,0);
                                                          
                                                           if (fd >= 0)
                                                                        {
                                                                                rt_kprintf("send file...wait !\n");
                                                                                while (1)
                                                                                {
                                                                                        size=read(fd,file_data_buffer, sizeof(file_data_buffer));
                                                                                        if(!size){ close(fd);break;}
                                                                                        //rt_kprintf("%d\n",size);
                                                                                        netconn_write(newconn,file_data_buffer,size,NETCONN_NOCOPY);                                                                                                                                                
                                                                                       
                                                                               }
                                                                               
                                                                       }
                                                                               
                                  
                                                     }
                                  
                                   }                                                   /*请求信息*/
                                  
                                  rt_kprintf("clear TCPNetbuf conn..\n");
                netbuf_delete(TCPNetbuf);
                                  rt_kprintf("close conn..\n");
            }

         netconn_close(newconn);       /* 关闭连接   */       
         rt_kprintf("delete conn..\n");
          while(netconn_delete(newconn) != ERR_OK);
       
      }
    }

       
}

错误如下
/poto1.jpg
send head string...
open file...
send file...wait !
100
psr: 0x61000000
pc: 0x0000126c
lr: 0x000011c5
r12: 0x00000000
r03: 0xffffffff
r02: 0x20000998
r01: 0x00000004
r00: 0x00000004
hard fault on thread: etx
threadpristatus      sp   stack size max used   left tickerror
-------- ---- ------- ---------- ---------- ---------- ---------- ---
twebsrv0x13 suspend 0x00000130 0x00001000 0x00000278 0x00000011 000
tcpip    0x16 suspend 0x00000230 0x00000400 0x00000278 0x00000002 000
tidle    0x1f ready   0x00000050 0x00000100 0x00000050 0x00000012 000
tshell   0x14 suspend 0x00000230 0x00000800 0x00000230 0x00000064 000
led      0x19 suspend 0x00000078 0x00000200 0x00000078 0x00000009 -02
led      0x19 suspend 0x00000078 0x00000200 0x00000078 0x00000008 -02
led_stat 0x15 suspend 0x00000080 0x00000400 0x00000080 0x0000000f -02
etx      0x17 ready   0x00000078 0x00000200 0x00000090 0x00000010 000
erx      0x17 suspend 0x00000090 0x00000200 0x000000d0 0x00000010 000

问题:
每次促使要一运行到这里LWIP就挂在这里故障
//rt_kprintf("%d\n",size);
netconn_write(newconn,file_data_buffer,size,NETCONN_NOCOPY);       
前面的发送又没有问题,奇怪了       
是LWIP有问题还是MILBOX有问题,真的是难查出来呀。又不能单步DEBUG。FFXZ希望你能看看。谢谢了

shaolin 发表于 2010-8-6 07:20:21

感觉是数据要求4字节对齐有点关系,你可以试下将netconn_write中的NETCONN_NOCOPY改成COPY,看看什么情况

另外你可以跟踪 下lr: 0x000011c5 这个地址在执行什么代码?

ffxz 发表于 2010-8-6 08:04:57

如shaolin说的,改成COPY试试。

19001579 发表于 2010-8-6 09:37:50

真的是字节对齐问题。在发送头的时候就已经没有对齐了。只是ROM数据好像就没事,谢谢版主。问题解决
页: [1]
查看完整版本: LWIP网络问题LM3S8962