导航: 老古网老古论坛XMOS公共讨论区XMOS开源项目区单片机程序设计嵌入式系统广告区域
→发表看法:[ido211314]求教大侠们关于一点关于串口以太网的问题,



No.18564
作者:ido211314
邮件:zkb251314@163.com
ID:100823
登陆:1次
文章数:1篇
最后登陆IP:202.198.16.219
最后登陆:2008/4/16 11:24:50
注册:2008/1/18 16:53:59
财富:105
发帖时间:2008/1/18 17:03:57
发贴者IP:202.98.18.55
标题:ido211314:求教大侠们关于一点关于串口以太网的问题,小弟十分感谢!
摘要:No.18564求教大侠们关于一点关于串口以太网的问题,小弟十分感谢! 我用的是MOTOROLA的MC9S12NE64,功能是串口转以太网。以前是把IP和物理地址固化进去的,现在想把程序改成可以通过串口精灵之类的界面给板子设定IP,可是总是无法成功,附上程序,真诚的希望可以可以得到大家的帮助,谢谢啊!
*****************************************************************************
 *                      (c) Freescale  Inc. 2004 All rights reserved       
 *   
 * File Name     : debug.c                                              
 *                                                                           
 * PURPOSE: Diagnostics output through SCI                                   
 *                                                                           
 *                                                                           
 * DESCRIPTION: Implementation of the diagnostics output - enabled when
 *              ETH_DEBUG keyword is defined (-DETH_DEBUG) 
 *              _SCI_BASE must be set to SCI0 or SCI1
 *              (see compiler command line arguments)
 *
 * Version : 2.1
 * Date    : 02/04/04 
 *
 *****************************************************************************/

//#include   <stdio.h>  
#include "ne64debug.h"
#include "MC9S12NE64.h"
#include "eeprom.h"

/*************shell fun used sci0*******************/
extern tU08 hard_addr[6];
extern tU08 prot_addr[4];
extern tU08 netw_mask[4];
extern tU08 dfgw_addr[4];
extern tU08 brcs_addr[4];
extern tU08 DEMO_RMTHOST_IP[4];
extern tU16 DEMO_LOCAL_PORT;
extern tU16 DEMO_RMTHOST_PRT;

tU08 TCPIP_MODE=0;
tU32 SCI_BAUD;
tU16 SCI_BASE;
tU08 SCI_MODE;
tU08 SCI_BAUDtemp; 
tU08 prot_addrf,netw_maskf,dfgw_addrf,DEMO_RMTHOST_IPf,
     DEMO_LOCAL_PORTf,DEMO_RMTHOST_PRTf,mac_addf,
     sci_modef,set_baudf,tcp_modef;
/******************************/

#ifdef ETH_DEBUG

#define _BASE 0x0000  /**  < Base on register map */

#define ECLK 25000000 /**  < this is BUSCLK */

#define reg(x)  *((volatile tU08 *)(_BASE+x))
#define regw(x)  *((volatile tU16 *)(_BASE+x))

//#define _SCI_BASE   SCI0

//#ifndef _SCI_BASE
//#error _SCI_BASE not defined, use SCI0 or SCI1
//#endif

#define SCI0    0x00c8
#define SCI1    0x00d0
#define SCIBD  regw(SCI_BASE+0x00)
#define SCICR1 reg(SCI_BASE+0x02)
#define SCICR2 reg(SCI_BASE+0x03)
#define SCISR1 reg(SCI_BASE+0x04)
#define SCIDRL reg(SCI_BASE+0x07)

//===================================================
void InitDebug(void)
{

#define BAUD_RATE    9600
  
#define BAUD_DIV     ECLK/16/BAUD_RATE
 
  SCI_BASE  = SCI0;
  SCIBD= BAUD_DIV;
  SCICR1= 0;
  //SCICR2= SCI1CR2_TE_MASK | SCI1CR2_RE_MASK | SCI1CR2_RWU_MASK ;
  SCICR2 = 0x2C;
}

//===================================================
/* send string via SCI */
//===================================================
void Debugt(tS08 * s)
{
  while (*s != 0)
  {
    while (!(SCISR1 & 0x80));
    SCIDRL=*s;
    s++;
  }
}
//===================================================
/* send string via SCI for protocol display*/
//===================================================
void Debugs(tU08  s)
{

    while (!(SCISR1 & 0x80));
    SCIDRL=s;

}
  


//===================================================
/* convert 8bit number to 2 hexadecimal ascii characters */
//===================================================
tS08 cvt[16]={ '0','1','2','3','4','5','6','7','8','9',
                      'A','B','C','D','E','F' };

//===================================================
void Ctoh (tS08 * s, tU08 c)
{
  *s= cvt[c / 16];
  s++;
  *s= cvt[c % 16];
}


//===================================================
/* send 16bit number in hexa via SCI */
//===================================================
void Debugi(tU16 i)
{
  tS08 s[6];
  s[0]=' ';
  Ctoh(s+1,(tU08)(i / 256));
  Ctoh(s+3,i % 256);
  s[5]=0;
  Debugt(s);
}

//===================================================
/* send 8bit number in hexa via SCI */
//===================================================
void Debugc(tU08 c)
{
  tS08 s[4];
  s[0]=' ';
  Ctoh(s+1,c);
  s[3]=0;
  Debugt(s);
}

//===================================================
/* send newline and return characters via SCI */
//===================================================
void Debugnl(void)
{
  Debugt("\r\n");
}
/*********************shell function**************************/

//===================================================
/* shell write data to IPADDRESS/NET MASK/ROUTE RECEIVE buffer */
//===================================================
tU08 shell_recedata(tU08 *p)
{
  tU08 dataok=0,s;
   tU08 i,j=0;
  tU08 bufftemp[3];
   for(i=0;i  <4;)
   {
      while(!(SCISR1 & 0x20));
      s = SCIDRL;
      if((s !='.')&&(s !=0x0D)){
        
         if(('0'  <= s)&&(s   <='9')){
            if(j==3){
               Debugs(0x07);
              // dataok=1;
             // break;
            } else{            
               Debugs(s);
               s = s&0x0f;
               bufftemp[j]=s;
               j++;
            }
         } else if(s==0x08)
         {              
            if(j!=0){
              Debugs(0x08);
              j--;
            } else {
              Debugs(0x07);
            }
         } else{
          
            Debugs(0x07); 
            //dataok = 1;
            //break;
         }
        // bufftemp[j]=s;
        // j++;
      } else 
      {
        if((s=='.')&&(i!=3)&&(j!=0))
        {
           Debugt(".");
           if(j==1)p[i]=bufftemp[0];
           if(j==2)p[i]=bufftemp[1]+bufftemp[0]*10;
           if((j==3)&&(bufftemp[0]  <3))p[i]=bufftemp[2]+bufftemp[1]*10+bufftemp[0]*100;
      else if((j==3)&&(bufftemp[0]>  3))dataok=1;
           i++;
           j=0;
           
        }else if((s==0x0D)&&(i==3)&&(j!=0)) 
        {
           if(j==1)p[i]=bufftemp[0];
           if(j==2)p[i]=bufftemp[1]+bufftemp[0]*10;
           if((j==3)&&(bufftemp[0]  <3))p[i]=bufftemp[2]+bufftemp[1]*10+bufftemp[0]*100;
      else if((j==3)&&(bufftemp[0]>  3))dataok=1;
           i++;
           j=0;
        } else if((s==0x0D)&&(i==0)&&(j==0)){
            dataok=1;
            return(dataok);
        } else {          
           Debugs(0x07); 
          // dataok = 1;
        }
      }
   }
   return(dataok);
}
//===================================================
/* shell MAC ADDRESS STR TO NUM funciton select via SCI */
//===================================================
tU08 strTOnum(tU08 s) 
{

     if(('0'  <= s)&&(s   <='9')){
        s = s&0x0f;       
     } 
     else if(('A'  <= s)&&(s   <='F')){
        s=s&0x0f;
        s+=9;        
     }
     else if(('a'  <= s)&&(s   <='f')){
        s=s&0x0f;
        s+=9;        
     } 
     else if(s==0x08){
        //Debugs(0x08);
        return(128);
     }
     else return(255);
     
     return(s);
}
//===================================================
/* shell  configration SCI BAUD_RATE process via SCI */
//===================================================
void shell_scibaud(void) 
{
   tU08 i,ss;
   set_baudf=0;
   for(i=0;i  <1;)
   {
     while(!(SCISR1 & 0x20));
     ss = SCIDRL;
     if(ss==0x0D) {
        set_baudf=1;
        break;
     }
   SCI_BAUDtemp= strTOnum(ss);
     if(SCI_BAUDtemp!=255)
     {
          Debugs(ss);
          i++;
     }
     else{
        Debugs(0x07);
     }
  }
}
//===================================================
/* SET SCI BAUD_RATE process via SCI */
//===================================================
 void set_scibaud(void) {
  
  switch(SCI_BAUDtemp) 
  {
    case 1:
       SCI_BAUD=300;
       break;
    case 2:
       SCI_BAUD=600;
       break;
    case 3:
       SCI_BAUD=1200;
       break;
    case 4:
       SCI_BAUD=2400;
       break;
    case 5:
       SCI_BAUD=4800;
       break;
    case 6:
       SCI_BAUD=9600;
       break;
    case 7:
       SCI_BAUD=19200;
       break;
    case 8:
       SCI_BAUD=38400;
       break;
    case 9:
       SCI_BAUD=57600;
       break;
    case 10:
       SCI_BAUD=115200;
       break;
    case 11:
       SCI_BAUD=230400;
       break;
    case 12:
       SCI_BAUD=460800;
       break;
    default:
       break;
  }
}
//===================================================
/* shell  configration remote port and local port process via SCI */
//===================================================
tU08 shell_cofigport(tU16 *port) 
{
   tU08 s,i;
  tU08 bufftemp[5];
  tU08 dataok=0;
  for(i=0;i  <5;i++){
     bufftemp[i]=0;
  }
   for(i=0;i  <6;)
   {
      while(!(SCISR1 & 0x20));
      s = SCIDRL;
      if(s !=0x0D){
        
         if(('0'  <= s)&&(s   <='9')&&(i  <5)){
           
               Debugs(s);
               s = s&0x0f;
               bufftemp[i]=s;
               i++;
            
         } else if(s==0x08)
         {              
            if(i!=0){
              Debugs(0x08);
              i--;
            } else {
              Debugs(0x07);
            }
         } else{           
            Debugs(0x07); 
         }

      } else 
      {
         if(i==4){
           *port=bufftemp[0]*1000;
         *port+=bufftemp[1]*100;
         *port+=bufftemp[2]*10;
          *port+=bufftemp[3]; 
          if((*port)  <1024) {
             Debugs(0x07);
          } else return(0);
         } else if(i==5)
         {
            *port=bufftemp[0]*10000;
         *port+=bufftemp[1]*1000;
         *port+=bufftemp[2]*100;
         *port+=bufftemp[3]*10;
          *port+=bufftemp[4]; 
          if((bufftemp[0]>  6)&&((*port)  <1024)) {
            //i=5;
              Debugs(0x07);
            } else return(0);             
         } else if(i==0){
             dataok=1;
              return (dataok);
         }else Debugs(0x07);
         

      }
   }
 
}
//===================================================
/* shell funciton configration process via SCI */
//===================================================
void shell_func(void) 
{
   tU08 i,ss;
   //tU08 hard_addrf,prot_addrf;
  // tU08 netw_maskf,dfgw_addrf;
   tU08 hard_addrtemp[12];

   //help ifo
   Debugnl();
   Debugt("            HELP INFORMATION,\r\n");
   Debugt("The Follow Is The Info Should Be Configed\r\n");
   Debugt("MAC ADDRESS By      0x00-0xFF\r\n");
   Debugt("IP  ADDRESS By      0-255\r\n");
   Debugt("NET MASK By         0-255\r\n");
   Debugt("DEFAULT ROUTE By    0-255\r\n");
   Debugt("DEMO_RMTHOST_IP By  0-255\r\n");
   Debugt("TCPIP_MODE By       0,1,2\r\n");
   Debugt("REMOTE HOST PORT By 1024-50000\r\n");
   Debugt("LOCAL HOST PORT By  1024-50000\r\n"); 
   Debugt("SCI_MODE SELECT By  0,1\r\n");
   Debugt("SCI BAUD_RATE       1-C\r\n"); 

 /*  Debugt("You Can Choose The Figure To Confige The Parameter Separately\r\n"); 
   Debugt("Or Input 'S' To Confige The Patameter Step by Step\r\n");   
   while(!(SCISR1 & 0x20));
      s = SCIDRL;
      s = s&0x0f;*/
   
   //MAC ADDRESS configration
  // Debugnl();
   Debugnl();
   Debugt("MAC ADDRESS (000000000000):");
   mac_addf=0;
  for(i=0;i  <12;)
   {
     while(!(SCISR1 & 0x20));
     ss = SCIDRL;
     if((ss==0x0D)&&(i==0)) {
        mac_addf=1;
        break;
     }
   hard_addrtemp[i]= strTOnum(ss);
     if(hard_addrtemp[i]!=255)
     {

        if(hard_addrtemp[i]==128){
          if((i!=0)&&(i%2)){
            Debugs(0x08);
            i--;
          } else{
            Debugs(0x07);
          }
        }else {
          Debugs(ss);
          i++;
          if((i!=0)&&(i!=12)){
            if(!(i%2))
            Debugt("-");
          } 
        }
       
     
     } else{
        Debugs(0x07);
        //hard_addrf = 1;
     }
  }
  // if(hard_addrf==0){
     for(i=0;i  <6;i++){
        hard_addr[i]=hard_addrtemp[i*2]*16+ hard_addrtemp[i*2+1];
     }
  // }
   
   //IP address configration
   Debugnl();
   Debugt("IP ADDRESS       (0.0.0.0):");
   prot_addrf=shell_recedata(prot_addr);

  
   //NET MASK configration
   Debugnl();
   Debugt("NET MASK         (0.0.0.0):");
  netw_maskf=shell_recedata(netw_mask);
  
  //DEFAULT ROUTE configration
   Debugnl(); ......

>>返回讨论的主题



  发表回复
用户名   *您没有注册?
密码   *
验证码   * .
标题   *
心情
随便说说    我回答你    最新发现    得意的笑   
气死我了    真是没劲    坚决同意    表示反对   
大家过来    好奇怪哟    懒得理它    大家小心   
文件上传
内容


字体:      字体大小:    颜色:
粗体 斜体 下划线 居中 超级连接 Email连接 图片 Flash图片 Shockwave文件 realplay视频文件 Media Player视频文件 QuickTime视频文件 引用 飞行字 移动字 发光字 阴影字 查看更多的心情图标 背景音乐
点击加入表情
                         
选项
有回复时用短消息通知您?

   




老古网执行:78毫秒 最大:734毫秒 查询6次