⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 net.c

📁 本文件内容为用tms320lf2407 dsp与以太网控制芯片 RTL8019AS通信的实验程序
💻 C
字号:
/*************************************************************
 *Copyright (c) 2005,北京精仪达盛科技有限公司研发部
 *All rights reserved
 *
 *文件名称:net.c
 *文件标示:
 *摘    要:本文件内容为用tms320lf2407 dsp与以太网控制芯片     
 *          RTL8019AS通信的实验程序。
 *
 *当前版本:1.0
 *作    者:王飞
 *完成日期:2005年2月17日
 *
 *取代版本:
 *原作者  :
 *完成日期:
 *************************************************************/

/************************文件预处理***************************/
#include "exp3_2407.h"
/*************************************************************/

/********************全局变量定义与初始化*********************/
ioport unsigned port9300; //RTL8019AS IO address
ioport unsigned port9301;
ioport unsigned port9302;
ioport unsigned port9303;
ioport unsigned port9304;
ioport unsigned port9305;
ioport unsigned port9306;
ioport unsigned port9307;
ioport unsigned port9308;
ioport unsigned port9309;
ioport unsigned port930a;
ioport unsigned port930b;
ioport unsigned port930c;
ioport unsigned port930d;
ioport unsigned port930e;
ioport unsigned port930f;
ioport unsigned port9310;
ioport unsigned port9311;
ioport unsigned port9318;
ioport unsigned port9322;
ioport unsigned port800d;//RTL8019AS reset IO port      

 unsigned int  ram[16],test[16];             //变量数组
 unsigned int  sum=0;
/*************************************************************/

/*******************函数、子程序声明与定义********************/
void sys_ini()               //系统初始化子程序
{
 /*关总中断*/
  asm(" setc INTM");         
 /*抑制符号位扩展*/
  asm(" clrc SXM");          
 /*累加器中结果正常溢出*/
  asm(" clrc OVM");          
 /*禁止看门狗*/
  * WDCR=0x00E8;             
 /*CLKIN=10M,CLKOUT=10*4=40M*/
  * SCSR1=0x0000;   
 /*ram、program都设为1等待io为4等待读写*/       
  WSGR=0x0709;                                   			                                      
 /*清除所有中断标志,"写1清0"*/ 
  * IFR=0xFFFF;                                  
}                                   

void delay()                //延时子程序
{
  unsigned int j;
  for(j=0;j<5000;j++);
}

void rtl8019as_reset()      //复位 RTL8019AS子程序
{
   unsigned int k=0;
   
   port800d = k;   //复位RTL8019AS
   
   delay();        //延时
   
   k = port800d;   //RTL8019AS退出复位状态
   
   delay();        //延时
   
} 
/*************************************************************/

/*****************中断服务子程序声明与定义********************/
interrupt void nothing()     //哑中断子程序
{
  return;         
}
/*************************************************************/

/**************************主程序*****************************/
void main(void)
{ 
  unsigned int temp=0;
  unsigned int i=0;
  unsigned int ramerr1=0;
  unsigned int ramerr2=0;
  unsigned int ramerr3=0;
  unsigned int chipid1=0;
  unsigned int chipid2=0;

  sys_ini();
  rtl8019as_reset();

  for(i=0;i<=15;i++)
    
    {  ram[i]=0; 
       test[i]=0;
    }

      port9300=0x000f;   //写RTL8019AS的00H 寄存器CR
      
      temp=port9300;
      
      asm(" nop ");     //读 寄存器CR ,ONLY FOR TEST
      
      chipid1 = port930a&0x00ff; //读RTL8019AS 的ID1 = 50H (ASCII code of "P")
      
      chipid2 = port930b&0x00ff; //读RTL8019AS 的ID2 = 70H (ASCII code of "p")

//测试SL811HS的内部RAM 4000~7FFF 
 
//--写0~15 再读出比较,连续的写和读用自增模式


//--------------写----------    

     port9300=0x0012;   //写RTL8019AS的00H 寄存器CR ,REMODE WRITE MODE
     port9308 = 0x0000;   //Remote Start Address Registers(RSAR0),08H ,A7~A0
     port9309 = 0x0040;   //Remote Start Address Registers(RSAR1),09H ,A15~A8
                          //设置REMODE 写的地址指针
                        
     port930a = 0x0000;   //Remote Byte Count Registers(RBCR0),0AH, RBC7~0
     port930b = 0x0010;   //Remote Byte Count Registers(RBCR1),0BH, RBC15~8
                          //设置写总数的寄存器                        
     port9300=0x0012;   //写RTL8019AS的00H 寄存器CR ,REMODE WRITE MODE
  
     for(i=0;i<=15;i++)
     
       {
        //for(;;)
        //{ 
        port9310 = i;  // write RTL8019AS ram address 4000~4010 = i
        //}
        ram[i]=i;
        
       }   
      
//-------------读-----------
     port9308 = 0x0000;   //Remote Start Address Registers(RSAR0),08H ,A7~A0
     port9309 = 0x0040;   //Remote Start Address Registers(RSAR1),09H ,A15~A8
                          //设置REMODE 写的地址指针
                        
     port930a = 0x0000;   //Remote Byte Count Registers(RBCR0),0AH, RBC7~0
     port930b = 0x0010;   //Remote Byte Count Registers(RBCR1),0BH, RBC15~8
                          //设置写总数的寄存器 
     port9300=0x000a;     //写RTL8019AS的00H 寄存器CR ,REMODE READ  MODE
                                  
      
     for(i=0;i<=15;i++)  //read RTL8019AS ram address 4000~4010 
     
       {
       
      test[i] = port9310&0x00ff; 
      
       }

//-------------比较---------      
      
     for(i=0;i<=15;i++)
     
     {
     
        sum = ram[i]-test[i];
        
        if(sum!=0)
          ramerr1++;
        
     } 

//--写0 再读出比较,连续的写和读用自增模式 

//--------------写-------------------------- 
     port9300=0x0012;   //写RTL8019AS的00H 寄存器CR ,REMODE WRITE MODE     
     port9308 = 0x0000;   //Remote Start Address Registers(RSAR0),08H ,A7~A0
     port9309 = 0x0040;   //Remote Start Address Registers(RSAR1),09H ,A15~A8
                          //设置REMODE 写的地址指针
                        
     port930a = 0x0000;   //Remote Byte Count Registers(RBCR0),0AH, RBC7~0
     port930b = 0x0010;   //Remote Byte Count Registers(RBCR1),0BH, RBC15~8
                          //设置写总数的寄存器                        
     port9300=0x0012;   //写RTL8019AS的00H 寄存器CR ,REMODE WRITE MODE
     
     for(i=0;i<=15;i++)
     
       { 
         port9310 = 0; // write RTL8019AS ram address 4000~4010 = 0
         ram[i] = 0; 
       }  
//---------------读--------------------------      
     port9308 = 0x0000;   //Remote Start Address Registers(RSAR0),08H ,A7~A0
     port9309 = 0x0040;   //Remote Start Address Registers(RSAR1),09H ,A15~A8
                          //设置REMODE 写的地址指针
                        
     port930a = 0x0000;   //Remote Byte Count Registers(RBCR0),0AH, RBC7~0
     port930b = 0x0010;   //Remote Byte Count Registers(RBCR1),0BH, RBC15~8
                          //设置写总数的寄存器 
     port9300=0x000a;     //写RTL8019AS的00H 寄存器CR ,REMODE READ  MODE
      
     for(i=0;i<=15;i++)  //read RTL8019AS ram address 4000~4010 
      { 
      test[i]=port9310&0x00ff; 
      }
//---------------比较------------------------      
     for(i=0;i<=15;i++)
     {
     
        sum=ram[i]-test[i];
        
        if(sum!=0)
          ramerr2++;
        
     }            
    
//--写FF 再读出比较,连续的写和读用自增模式 
//--------------写-------------------------- 
     
     port9300=0x0012;   //写RTL8019AS的00H 寄存器CR ,REMODE WRITE MODE
     port9308 = 0x0000;   //Remote Start Address Registers(RSAR0),08H ,A7~A0
     port9309 = 0x0040;   //Remote Start Address Registers(RSAR1),09H ,A15~A8
                          //设置REMODE 写的地址指针
                        
     port930a = 0x0000;   //Remote Byte Count Registers(RBCR0),0AH, RBC7~0
     port930b = 0x0010;   //Remote Byte Count Registers(RBCR1),0BH, RBC15~8
                          //设置写总数的寄存器                        
     port9300=0x0012;   //写RTL8019AS的00H 寄存器CR ,REMODE WRITE MODE
     
     for(i=0;i<=15;i++)
       { 
         port9310 = 0xff; // write RTL8019AS ram address 4000~4010 = 0xff
         ram[i] = 0xff; 
       }  
//---------------读--------------------------      
     port9308 = 0x0000;   //Remote Start Address Registers(RSAR0),08H ,A7~A0
     port9309 = 0x0040;   //Remote Start Address Registers(RSAR1),09H ,A15~A8
                          //设置REMODE 写的地址指针
                        
     port930a = 0x0000;   //Remote Byte Count Registers(RBCR0),0AH, RBC7~0
     port930b = 0x0010;   //Remote Byte Count Registers(RBCR1),0BH, RBC15~8
                          //设置写总数的寄存器 
     port9300=0x000a;     //写RTL8019AS的00H 寄存器CR ,REMODE READ  MODE
      
     for(i=0;i<=15;i++)  //read RTL8019AS ram address 4000~4010 
      { 
      test[i]=port9310&0x00ff; 
      }
      
      
//-------------------------------------------
   // }      
//-------------------------------------------

//---------------比较------------------------      
     for(i=0;i<=15;i++)
     {
     
        sum=ram[i]-test[i];
        
        if(sum!=0)
          ramerr3++;
        
     }  
             
     temp=0;
       
     for(;;)
     {
     } 
}
/***************************结束******************************/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -