bjzps
驱动小牛
驱动小牛
  • 注册日期2003-03-06
  • 最后登录2009-04-13
  • 粉丝0
  • 关注0
  • 积分11分
  • 威望22点
  • 贡献值0点
  • 好评度3点
  • 原创分0分
  • 专家分0分
阅读:968回复:0

大虾们帮我看看程序吧,我又卡住了

楼主#
更多 发布于:2003-08-06 15:33
前面枚举,0端口收setup包等都正常。
set config之后,可以用busbound看到pc已经发出inquiry命令了
当时后面就死掉了,显示no respond的。我在回的数据肯定没问题
找了半天也不知道毛病在哪里。大家帮帮忙吧/*---------------------------------------------------------------------------
*
* FILE:  USB_main.c
*
* DESCRIPTION:
*
*  Initial MPC850 and enable usb , complete slave function.
*
* NOTES  <<<IMPORTANT:  PLEASE READ>>>:
*
*     1) Specifically Designed to run on 850 FADS board.
*
*
* REFERENCES:
*
*      1) MPC850 Users Manual
*      2) USB 1.1 Specification
*
* HISTORY:
*
* 7/17/03      zps     Initial 850 Structure Complete , enable usb.
* 7/30 2003    jewel Change structure of the old programs and
*                        accomplish the protocol of USB.
*August 2003   zps     SCSI.
*-----------------------------------------------------------------------------*/



#include \"vxworks.h\"
#include \"vxPpcLib.h\"
#include \"intlib.h\"
#include \"stdio.h\"
#include \"ivppc.h\"
#include \"loglib.h\"
#include \"tasklib.h\"
#include \"memlib.h\"
#include \"msgQLib.h\"
#include \"string.h\"
#include \"usb.h\"
/***********************/
/* Global Declarations */
/***********************/

#define TEST_SLAVE
#define MAX_MESSAGES 1000
#define MAX_MESSAGE_LENGTH 50
#define RxBD_NUM      4

bd *rx[RxBD_NUM * MAX_ENDPOINTS], *tx[MAX_ENDPOINTS];
usbep *endpoint[MAX_ENDPOINTS];
volatile int immr;
MSG_Q_ID mesgQueueId;
unsigned int data_pid;

#ifdef TEST_SLAVE

unsigned volatile int tep,tepreset,tepidle,tepsof,teptxb,teprxb,
                      teptxe0,teptxe1,teptxe2,teptxe3,tepbsy;
 
int num,numidle,numsof,numtxb,numrxb,
    numtxe0,numtxe1,numtxe2,numtxe3;
#endif

/********************************/
/* Internal Function Prototypes */
/********************************/

void init850();
void enable_usb();
void task_handler(void);
void allocate_space();
void extern_handler();
void USB_handler(test_bd *);
void interrupt();
void USB_enumeration(test_bd *,unsigned int);
void USB_SCSI(test_bd *,unsigned int);

#ifdef TEST_SLAVE
int expect_DEV_DESC(test_bd *);
void trans_DEV_DESC(int,unsigned int);
int expect_CFG_DESC(test_bd *);
void trans_CFG_DESC(int,unsigned int);
int expect_SET_ADDR(test_bd *);
void trans_ZERO_DATA(int,unsigned int);
int expect_SET_CONF(test_bd *);
void trans_ZERO_DATA(int,unsigned int);
int expect_CBW(test_bd *);
void trans_0612(int,unsigned int);
#endif


void main_in()
{    
  int i,taskId;

  init850();  /*init 850*/

  #ifdef TEST_SLAVE  /*interrupt number*/
  num=numidle=numsof=numtxb=numrxb=0;
  numtxe0=numtxe1=numtxe2=numtxe3=0;
  #endif

  i=0;
  /*create message queue*/
  if((mesgQueueId = msgQCreate( MAX_MESSAGES,sizeof(test_bd),MSG_Q_FIFO ))
          == NULL )
          logMsg(\"@msgQCreate in failed\\n\",0,0,0,0,0,0);
  i++;
  /*spawn a task*/
  if(( taskId = taskSpawn( \"tUsbTask\",90,0x100,2000,(FUNCPTR)task_handler,0,0,
          0,0,0,0,0,0,0,0 ))==ERROR)
          logMsg(\"@taskSpawn task_handler failed\\n\",0,0,0,0,0,0);

  i++;

  /*Set interrupt*/
  interrupt();
  /*Enable USB*/
  enable_usb();
  while (1);


}


/*-----------------------------------------------------------------------------
*
* FUNCTION NAME:  init850
*
*
* DESCRIPTION:
*
* Initial usb.
*
* EXTERNAL EFFECTS: Initializes MPC850 system for USB slave.
*
* PARAMETERS: None
*
* RETURNS: None
*
*-----------------------------------------------------------------------------*/

void init850()
{
  immr = ( vxImmrGet() & 0xffff0000 );/*Get address of immr*/
  
  usbmr(immr)=0;/*Clear mask register*/
  usber(immr)=0xffff;/*Clear event register*/
  
  /*Set baud rate generator 3 to produce 48MHz reference clock*/
  brgc3(immr) = 0x00010000;

  /*Pin set*/
  /* set usboe , usbrxd */
  papar(immr) |=   0x0003; /*papar[dd14,dd15]=1 */
  padir(immr) &= ~(0x0003);  /* padir[dr14,dr15]=0 */

  pbpar(immr)&=~(0x00008000);
  pbdir(immr)|=0x00008000;
  pbdat(immr)&=~(0x00008000);

  /*fad*/
  pdpar(immr)&=~(0x0400);
  pddir(immr)|= 0x0400;
  pddat(immr)&=~(0x0400);

  /* set usbtxp,usbtxn */
  pcdir(immr) |= 0x0300; /* pcdir[dr6,dr7]=1 */
  pcpar(immr) |= 0x0300; /* pcpar[dd6,dd7]=1 */

  /* set usbrxp,usbrxn */
  pcpar(immr) &= ~(0x0030); /* pcpar[dd10,dd11]=0 */
  pcdir(immr) &= ~(0x0030); /* pcdir[dr10,dr11]=0 */
  pcso(immr)  |= 0x0030;    /* pcso[10,11]=1 */
  
  /*Clear frame number*/
  frame_n(immr) = 0;

  /*Allocate space for BD and Endpiont*/
  allocate_space(immr);  


  /* Set SI clock route register */
  sicr(immr) &= ~(0x00000038);
  sicr(immr) |= 0x00000010;
  
  /*Set USB slave address*/
  /*usbadr(immr) = 0x02;*/
  
  /*Set mode register:Full-speede,Normal operation*/
  usbmod(immr) = 0x00;
  
  /*Clear command register*/
  usbcom(immr) = 0x00;

  /*Set USBEPn:All endpoints are bulk mode;normal handshake.*/
 /* usbep0(immr) = 0x0000;
  usbep1(immr) = 0x1200;
  usbep2(immr) = 0x2200;
  usbep3(immr) = 0x3200;  */

}
/*-----------------------------------------------------------------------------
*
* FUNCTION NAME:  interrupt
*
*
* DESCRIPTION:
*
* Connect the interrupt vector,INTERRUPT_LEVEL,to a specific interrupt
* handler routine,interruptHandler,and pass an argument,i.
*
* EXTERNAL EFFECTS: Interrupt.
*
* PARAMETERS: None
*
* RETURNS: None
*
*-----------------------------------------------------------------------------*/
void interrupt()
{
  int i;
  /*interrupt*/
  if(intConnect(INUM_TO_IVEC(62),(VOIDFUNCPTR)extern_handler,i)==ERROR)
    logMsg(\"@error\\n\",0,0,0,0,0,0);
    else logMsg(\"@no error\\n\",0,0,0,0,0,0);

  /*Mask interrupt*/
  usbmr(immr) = 0x03ff;
  
  /*Set CMP interrupt mask register*/
  cimr(immr) |= (1 << (31 -1));

}


/*-----------------------------------------------------------------------------
*
* FUNCTION NAME:  allocate_space
*
*
* DESCRIPTION:
*
* Allocate space for BD , BD\'s buffer and Endpionts.
*
* EXTERNAL EFFECTS: None
*
* PARAMETERS: None
*
* RETURNS: None
*
*-----------------------------------------------------------------------------*/

void allocate_space()
{

#define BUF     0x2300
#define EP0 0x2800
#define BD0 0x2900


  int i,BD_addr,BUF_addr;
  char TxBuf[18];

  memset((void*)(immr + BUF), 0, 0x600);
  BD_addr=BD0;
  BUF_addr=BUF;
  for (i=0; i<RxBD_NUM*MAX_ENDPOINTS; i++)
  {
       /*Rxbd*/
       rx = (bd*)(immr + BD_addr) ;
       if(( i & 0x3 ) == 0x3)
           rx->bd_cstatus = rxbd_e | rxbd_w | rxbd_i ;        
         else
           rx->bd_cstatus = rxbd_e | rxbd_i ;
      
       rx->bd_length = 0x00 ;
       rx->bd_addr = (char *)(immr + BUF_addr) ;
       BD_addr = BD_addr + 8 ;
       BUF_addr = BUF_addr + 0x40 ;

       /*TxBD*/
       if(( i & 0x3 ) == 0x3)
       {
           tx[i/4] = (bd*)(immr + BD_addr) ;
           tx[i/4]->bd_addr = (char *)(immr + BUF_addr) ;
           BD_addr= BD_addr + 8 ;
           BUF_addr = BUF_addr + 0x40 ;
        }
  }
  
  /*Endpoint*/
  for (i=0; i<4; i++)
  {
    endpoint = (usbep*)(immr + EP0 + i*0x20);
    endpoint->rbase = endpoint->rbptr = rx[i * RxBD_NUM];
    endpoint->tbase = endpoint->tbptr = tx;
    endpoint->rfcr = endpoint->tfcr = 0x18;  
    endpoint->mrblr = 256;
    endpoint->tstate = 0;
  }

  ep0ptr(immr)= endpoint[0];
  ep1ptr(immr)= endpoint[1];
  ep2ptr(immr)= endpoint[2];
  ep3ptr(immr)= endpoint[3];


  


}
/*-----------------------------------------------------------------------------
*
* FUNCTION NAME:  task_handler
*
*
* DESCRIPTION:
*
* Task handler.
*
* EXTERNAL EFFECTS: None
*
* PARAMETERS: None
*
* RETURNS: None
*
*-----------------------------------------------------------------------------*/
void task_handler()
{
  test_bd msgBuf;

  while(1)
  {
     if ( msgQReceive( mesgQueueId,(char *)&msgBuf,sizeof(msgBuf),WAIT_FOREVER)
                  == ERROR )
        logMsg(\"@Receive failed\\n\",0,0,0,0,0,0);
     else
        {    
           /*logMsg(\"@Receive buf:%s\\n\",msgBuf,0,0,0,0,0);*/
           /*USB handler*/
           USB_handler(&msgBuf);
        }
   }




}

/*-----------------------------------------------------------------------------
*
* FUNCTION NAME:  enable_usb
*
*
* DESCRIPTION:
*
* Enable usb.
*
* EXTERNAL EFFECTS: Enables USB operation.
*
* PARAMETERS: None
*
* RETURNS: None
*
*-----------------------------------------------------------------------------*/

void enable_usb()
{

  usbmod(immr) |= 1;  /*enable usb*/
  
}

/*-----------------------------------------------------------------------------
*
* FUNCTION NAME:  extern_handler
*
*
* DESCRIPTION:
*
* This function processes USB Interrupts .
*
* EXTERNAL EFFECTS:  Interrupt related registers.
*
* PARAMETERS: None
*
* RETURNS: None
*
*-----------------------------------------------------------------------------*/

void extern_handler()
{
  unsigned volatile short intno;
  int i;
  test_bd rx_bd;
  num++;
  intno = usber(immr);
  tep = intno;
  usber(immr) = 0x3ff;
  cisr(immr) = 1<<(31-1);
  rx_bd.endpoint = 0;
  rx_bd.bd_addr = 0;
  rx_bd.bd_cstatus = 0;
  rx_bd.bd_length = 0;
  if(intno & reset)
    {
      tepreset=intno;
      rx_bd.flag =0x00;
      if((msgQSend(mesgQueueId,(char *)&rx_bd,sizeof(rx_bd),NO_WAIT,
               MSG_PRI_NORMAL))==ERROR)
               logMsg(\"@msgQsend  RESET failed\\n\",0,0,0,0,0,0);
    }
  if(intno & idle)
    {
      tepidle=intno;
      numidle++;
      
   /* rx_bd.flag =0x01;
      if((msgQSend(mesgQueueId,(char *)rx_bd,sizeof(rx_bd),NO_WAIT,
               MSG_PRI_NORMAL))==ERROR)
               logMsg(\"@msgQsend  RESET failed\\n\",0,0,0,0,0,0);
              logMsg(\"@msgQsend IDLE failed\\n\",0,0,0,0,0,0);
              
    */      
    }
  if(intno & txe3)
    {
      teptxe3=intno;
      numtxe3++;
      rx_bd.flag =0x02;
      if((msgQSend(mesgQueueId,(char *)&rx_bd,sizeof(rx_bd),NO_WAIT,
               MSG_PRI_NORMAL))==ERROR)
               logMsg(\"@msgQsend  RESET failed\\n\",0,0,0,0,0,0);
    }
  if(intno & txe2)
    {
      teptxe2=intno;
      numtxe2++;
      rx_bd.flag =0x03;
      if((msgQSend(mesgQueueId,(char *)&rx_bd,sizeof(rx_bd),NO_WAIT,
               MSG_PRI_NORMAL))==ERROR)
               logMsg(\"@msgQsend  RESET failed\\n\",0,0,0,0,0,0);
    }
  if(intno & txe1)
    {
      teptxe1=intno;
      numtxe1++;
      rx_bd.flag =0x04;
      if((msgQSend(mesgQueueId,(char *)&rx_bd,sizeof(rx_bd),NO_WAIT,
               MSG_PRI_NORMAL))==ERROR)
               logMsg(\"@msgQsend  RESET failed\\n\",0,0,0,0,0,0);
    }
  if(intno & txe0)
    {
      teptxe0=intno;
      numtxe0++;
      rx_bd.flag =0x05;
      if((msgQSend(mesgQueueId,(char *)&rx_bd,sizeof(rx_bd),NO_WAIT,
               MSG_PRI_NORMAL))==ERROR)
               logMsg(\"@msgQsend  RESET failed\\n\",0,0,0,0,0,0);
    }
  if(intno & sof)
    {
      tepsof=intno;
      numsof++;
   /* rx_bd.flag =0x06;
      if((msgQSend(mesgQueueId,(char *)&rx_bd,sizeof(rx_bd),NO_WAIT,
               MSG_PRI_NORMAL))==ERROR)
               logMsg(\"@msgQsend  RESET failed\\n\",0,0,0,0,0,0);
   */
              
    }
  if(intno & bsy)
    {
      tepbsy=intno;
      rx_bd.flag =0x07;
      if((msgQSend(mesgQueueId,(char *)&rx_bd,sizeof(rx_bd),NO_WAIT,
               MSG_PRI_NORMAL))==ERROR)
               logMsg(\"@msgQsend  RESET failed\\n\",0,0,0,0,0,0);
    }
  if(intno & txb)
    {
      teptxb=intno;
      numtxb++;
      rx_bd.flag =0x08;
      if((msgQSend(mesgQueueId,(char *)&rx_bd,sizeof(rx_bd),NO_WAIT,
               MSG_PRI_NORMAL))==ERROR)
               logMsg(\"@msgQsend  RESET failed\\n\",0,0,0,0,0,0);
    }
  if(intno & rxb)
    {
      teprxb=intno;
      numrxb++;
      rx_bd.flag =0x09;
      for(i=0;i<4*MAX_ENDPOINTS;i++)
      {
        
         if((rx->bd_cstatus & rxbd_e) ==0)
         {          
             rx_bd.endpoint = i/4;
             rx_bd.bd_addr = rx->bd_addr;
             rx_bd.bd_cstatus = rx->bd_cstatus;
             rx_bd.bd_length = rx->bd_length;
             if( expect_CBW(&rx_bd)==1)
        { logMsg(\"cbw\\n\",0,0,0,0,0,0);}
             /*Clear RxBD*/
             if((rx->bd_cstatus & rxbd_w) == rxbd_w)
                rx->bd_cstatus = rxbd_e | rxbd_w | rxbd_i ;
             else
                rx->bd_cstatus = rxbd_e | rxbd_i ;
             logMsg(\"@rx_bd.bd_addr:%x\\n\",rx_bd.bd_addr,0,0,0,0,0);
        }
      }
 
      if((msgQSend(mesgQueueId,(char *)&rx_bd,sizeof(rx_bd),NO_WAIT,
               MSG_PRI_NORMAL))==ERROR)
               logMsg(\"@msgQsend  RESET failed\\n\",0,0,0,0,0,0);
      
     }
 

}

/*-----------------------------------------------------------------------------
*
* FUNCTION NAME:  USB_handler
*
*
* DESCRIPTION:
*
* USB handler.
*
* EXTERNAL EFFECTS: None
*
* PARAMETERS: rx_bd
*
* RETURNS: None
*
*-----------------------------------------------------------------------------*/
void USB_handler(test_bd *rx_bd)
{
  int i,tendp;
  unsigned int tx_pid;
  tendp=0;

  logMsg(\"@Interrupt type:%x\\n\",rx_bd->flag,0,0,0,0,0);
  switch(rx_bd->flag)
  {
     case 0x00:break;/*RESET*/
     case 0x01:break;/*IDLE*/
     case 0x02:break;/*TXE3*/
     case 0x03:break;/*TXE2*/
     case 0x04:break;/*TXE1*/
     case 0x05:break;/*TXE0*/
     case 0x06:break;/*SOF*/
     case 0x07:break;/*BSY*/
     case 0x08:/*TXB*/
               {
                   if((tx[tendp]->bd_cstatus &(txbd_nak|txbd_stal|txbd_to|txbd_un))==0)
                      {
                          if(tx_pid==txbd_pid0)
                             data_pid = txbd_pid1;
                          else
                             data_pid = txbd_pid0;
                       }
                   break;
                }
     case 0x09:/*RXB*/
                {
                  logMsg(\"@rx_bd->bd_length:%x\\n\",rx_bd->bd_length,0,0,0,0,0);
                  /*PID*/
                  /*SETUP*/
                  if((rx_bd->bd_cstatus & rxbd_setuppid)== rxbd_setuppid)
                    {
                      tx_pid = txbd_pid1;
                      data_pid = txbd_pid1;
 USB_enumeration(rx_bd,tx_pid);
                    }
 else
  { USB_SCSI(rx_bd,txbd_pid1);
  }
                  /*DATA0*/
           /*       if((rx_bd->bd_cstatus & (rxbd_f |rxbd_data0pid))== (rxbd_f |rxbd_data0pid))
                     { tx_pid = txbd_pid1;
                        USB_SCSI(rx_bd,tx_pid);
    }   */
                  /*DATA1*/
            /*     if((rx_bd->bd_cstatus & (rxbd_f |rxbd_data1pid))== (rxbd_f |rxbd_data1pid))
                     { tx_pid = txbd_pid0;  
                       USB_SCSI(rx_bd,tx_pid);
                   }
            */                
                  break;
               }
     default:logMsg(\"@Interrupt error\\n\",0,0,0,0,0,0);
  }

}
/*-----------------------------------------------------------------------------
*
* FUNCTION NAME:  expect_DEV_DESC
*
*
* DESCRIPTION:
*
* For test. Detect the packet: GET_DESCRIPTOR.
*
* EXTERNAL EFFECTS:None
*
* PARAMETERS: rx_bd
*
* RETURNS: 1:The packet is 80 06 00 01;
*          0:The packet is not 80 06 00 01.
*
*-----------------------------------------------------------------------------*/



int expect_DEV_DESC(test_bd *rx_bd)
{
    if((rx_bd->bd_addr[0]!=0x80)||(rx_bd->bd_addr[1]!=0x06)||
       (rx_bd->bd_addr[2]!=0x00)||(rx_bd->bd_addr[3]!=0x01))
      return 0;
    return 1;
}

/*-----------------------------------------------------------------------------
*
* FUNCTION NAME:  expect_CFG_DESC
*
*
* DESCRIPTION:
*
* For test. Detect the packet: GET_DESCRIPTOR.
*
* EXTERNAL EFFECTS:None
*
* PARAMETERS: rx_bd.
*
* RETURNS:1:The packet is 80 06 00 02;
*          0:The packet is not 80 06 00 02.
*
*-----------------------------------------------------------------------------*/



int expect_CFG_DESC(test_bd *rx_bd)
{
    if((rx_bd->bd_addr[0]!=0x80)||(rx_bd->bd_addr[1]!=0x06)||
       (rx_bd->bd_addr[2]!=0x00)||(rx_bd->bd_addr[3]!=0x02))
      return 0;
    return 1;
}
/*-----------------------------------------------------------------------------
*
* FUNCTION NAME:  expect_SET_ADDR
*
*
* DESCRIPTION:
*
* For test. Detect the packet: SET_ADDRESS.
*
* EXTERNAL EFFECTS:None
*
* PARAMETERS: rx_bd.
*
* RETURNS: None
*
*-----------------------------------------------------------------------------*/



int expect_SET_ADDR(test_bd *rx_bd)
{

    if((rx_bd->bd_addr[0]!=0x00)||(rx_bd->bd_addr[1]!=0x05))
      return 0;
    return 1;
}

/*-----------------------------------------------------------------------------
*
* FUNCTION NAME:  expect_SET_CONF
*
*
* DESCRIPTION:
*
* For test. Detect the packet: SET_CONFIGURATION.
*
* EXTERNAL EFFECTS:None
*
* PARAMETERS: rx_bd
*
* RETURNS: None
*
*-----------------------------------------------------------------------------*/



int expect_SET_CONF(test_bd *rx_bd)
{

    if((rx_bd->bd_addr[0]!=0x00)||(rx_bd->bd_addr[1]!=0x09))
      return 0;
    return 1;
}

int expect_CBW(test_bd *rx_bd)
{  
    if((rx_bd->bd_addr[0]!=0x55)||(rx_bd->bd_addr[1]!=0x53)
  ||(rx_bd->bd_addr[2]!=0x42)||(rx_bd->bd_addr[3]!=0x43))
       return 0;
return 1;
}
/*-----------------------------------------------------------------------------
*
* FUNCTION NAME:  trans_DEV_DESC
*
*
* DESCRIPTION:
*
* For test. Transmit a packet:DEV_DESC.
*
* EXTERNAL EFFECTS:  Transmit a packet:DEV_DESC.
*
* PARAMETERS: None
*
* RETURNS: None
*
*-----------------------------------------------------------------------------*/

void trans_DEV_DESC(int tendp,unsigned int txpid)
{
  memset(0x2202640, 0, 0x20);
  
  tx[tendp]->bd_addr[0] = 0x12;
  tx[tendp]->bd_addr[1] = 0x01;
  tx[tendp]->bd_addr[2] = 0x10;
  tx[tendp]->bd_addr[3] = 0x01;

  tx[tendp]->bd_addr[4] = 0x00;
  tx[tendp]->bd_addr[5] = 0x00;
  tx[tendp]->bd_addr[6] = 0x00;
  tx[tendp]->bd_addr[7] = 0x40;
  
  tx[tendp]->bd_addr[8] = 0x00;
  tx[tendp]->bd_addr[9] = 0x04;
  tx[tendp]->bd_addr[10] = 0x07;
  tx[tendp]->bd_addr[11] = 0x00;

  tx[tendp]->bd_addr[12] = 0x63;
  tx[tendp]->bd_addr[13] = 0x00;
  tx[tendp]->bd_addr[14] = 0x00;
  tx[tendp]->bd_addr[15] = 0x00;

  tx[tendp]->bd_addr[16] = 0x00;
  tx[tendp]->bd_addr[17] = 0x01;
  
  tx[tendp]->bd_cstatus =  txbd_r | txbd_w | txbd_i | txbd_l | txbd_tc | txpid;

  usbcom(immr) = 0x80|tendp;

}

/*-----------------------------------------------------------------------------
*
* FUNCTION NAME:  trans_CFG_DESC
*
*
* DESCRIPTION:
*
* For test. Transmit a packet:CFG_DESC.
*
* EXTERNAL EFFECTS:  Transmit a packet:CFG_DESC.
*
* PARAMETERS: None
*
* RETURNS: None
*
*-----------------------------------------------------------------------------*/

void trans_CFG_DESC(int tendp,unsigned int txpid)
{
  memset(0x2202640, 0, 0x20);
  
  tx[tendp]->bd_addr[0] = 0x09;
  tx[tendp]->bd_addr[1] = 0x02;
  tx[tendp]->bd_addr[2] = 0x20;
  tx[tendp]->bd_addr[3] = 0x00;

  tx[tendp]->bd_addr[4] = 0x01;
  tx[tendp]->bd_addr[5] = 0x01;
  tx[tendp]->bd_addr[6] = 0x00;
  tx[tendp]->bd_addr[7] = 0x40;
  
  tx[tendp]->bd_addr[8] = 0x32;
  /*       */
  tx[tendp]->bd_addr[9] = 0x09;
  tx[tendp]->bd_addr[10] = 0x04;
  tx[tendp]->bd_addr[11] = 0x00;

  tx[tendp]->bd_addr[12] = 0x00;
  tx[tendp]->bd_addr[13] = 0x02;
  tx[tendp]->bd_addr[14] = 0x08;/*MASS*/
  tx[tendp]->bd_addr[15] = 0x06;/*SCSI*/

  tx[tendp]->bd_addr[16] = 0x50;/*BULK*/
  tx[tendp]->bd_addr[17] = 0x00;
  /*PIPE 1*/
  tx[tendp]->bd_addr[18] = 0x07;
  tx[tendp]->bd_addr[19] = 0x05;

  tx[tendp]->bd_addr[20] = 0x81;
  tx[tendp]->bd_addr[21] = 0x02;
  tx[tendp]->bd_addr[22] = 0x40;
  tx[tendp]->bd_addr[23] = 0x00;

  tx[tendp]->bd_addr[24] = 0x00;
  /*PIPE 2*/
  tx[tendp]->bd_addr[25] = 0x07;
  tx[tendp]->bd_addr[26] = 0x05;

  tx[tendp]->bd_addr[27] = 0x02;
  tx[tendp]->bd_addr[28] = 0x02;
  tx[tendp]->bd_addr[29] = 0x40;
  tx[tendp]->bd_addr[30] = 0x00;

  tx[tendp]->bd_addr[31] = 0x00;

  
  tx[tendp]->bd_cstatus =  txbd_r | txbd_w | txbd_i | txbd_l | txbd_tc | txpid;

  usbcom(immr) = 0x80|tendp;

}


/*-----------------------------------------------------------------------------
*
* FUNCTION NAME:  trans_ZERO_DATA
*
*
* DESCRIPTION:
*
* For test. Transmit a packet: zero-length data.
*
* EXTERNAL EFFECTS:  Transmit a packet: zero-length data.
*
* PARAMETERS: None
*
* RETURNS: None
*
*-----------------------------------------------------------------------------*/

void trans_ZERO_DATA(int endp,unsigned int txpid)
{
  memset(0x2202640, 0, 0x20);
  tx[endp]->bd_length = 0;


  tx[endp]->bd_cstatus =  txbd_r | txbd_w | txbd_i | txbd_l | txbd_tc | txpid;


  usbcom(immr) = 0x80|endp;

}
void trans_0612(int tendp,unsigned int txpid)
{ tx[tendp]->bd_length = 0x24;
  tx[tendp]->bd_addr[0] = 0x00;
  tx[tendp]->bd_addr[1] = 0x80;
  tx[tendp]->bd_addr[2] = 0x02;
  tx[tendp]->bd_addr[3] = 0x02;

  tx[tendp]->bd_addr[4] = 0x1f;
  tx[tendp]->bd_addr[5] = 0x00;
  tx[tendp]->bd_addr[6] = 0x00;
  tx[tendp]->bd_addr[7] = 0x00;
  
  tx[tendp]->bd_addr[8] = 0x4c;
  tx[tendp]->bd_addr[9] = 0x41;
  tx[tendp]->bd_addr[10] = 0x4e;
  tx[tendp]->bd_addr[11] = 0x44;

  tx[tendp]->bd_addr[12] = 0x4d;
  tx[tendp]->bd_addr[13] = 0x41;
  tx[tendp]->bd_addr[14] = 0x53;
  tx[tendp]->bd_addr[15] = 0x20;

  tx[tendp]->bd_addr[16] = 0x51;
  tx[tendp]->bd_addr[17] = 0x51;
  tx[tendp]->bd_addr[18] = 0x4d;
  tx[tendp]->bd_addr[19] = 0x43;
  
  tx[tendp]->bd_addr[20] = 0x59;
  tx[tendp]->bd_addr[21] = 0x33;
  tx[tendp]->bd_addr[22] = 0x35;
  tx[tendp]->bd_addr[23] = 0x30;
      
  tx[tendp]->bd_addr[24] = 0x31;
  tx[tendp]->bd_addr[25] = 0x30;
  tx[tendp]->bd_addr[26] = 0x30;
  tx[tendp]->bd_addr[27] = 0x53;
  
  tx[tendp]->bd_addr[28] = 0x20;
  tx[tendp]->bd_addr[29] = 0x20;
  tx[tendp]->bd_addr[30] = 0x20;
  tx[tendp]->bd_addr[31] = 0x20;

  tx[tendp]->bd_addr[32] = 0x31;
  tx[tendp]->bd_addr[33] = 0x2e;
  tx[tendp]->bd_addr[34] = 0x31;
  tx[tendp]->bd_addr[35] = 0x31;
  
  tx[tendp]->bd_cstatus =  txbd_r | txbd_w | txbd_i | txbd_l | txbd_tc | txpid;

  usbcom(immr) = 0x80|tendp;

}
/*-----------------------------------------------------------------------------
*
* FUNCTION NAME:  USB_enumeration
*
*
* DESCRIPTION:
*
* Enumeration.
*
* EXTERNAL EFFECTS: None
*
* PARAMETERS: rx_bd
*
* RETURNS: None
*
*-----------------------------------------------------------------------------*/
void USB_enumeration(test_bd *rx_bd,unsigned int tx_pid)
{
   int tendp;
   tendp=0;
   /*GET_DESCRIPTOR   DEV_DESC */
   if(expect_DEV_DESC(rx_bd)==1)
   {
      
      if(rx_bd->bd_addr[6]==0x40)
           tx[tendp]->bd_length = 8;
      else
           tx[tendp]->bd_length = rx_bd->bd_addr[6];
          
      trans_DEV_DESC(tendp,tx_pid);
      logMsg(\"@Trans data length:0x%x  PID:0x%x\\n\",rx_bd->bd_addr[6],tx_pid,0,0,0,0);
   }

 
   /*GET_DESCRIPTOR   CFG_DESC */
   if(expect_CFG_DESC(rx_bd)==1)
   {
      logMsg(\"@Trans data length:0x%x  PID:0x%x\\n\",rx_bd->bd_addr[6],tx_pid,0,0,0,0);
      if(rx_bd->bd_addr[6]==0xFF)
           tx[tendp]->bd_length = 0x20;
      else
           tx[tendp]->bd_length = rx_bd->bd_addr[6];
      trans_CFG_DESC(tendp,tx_pid);
   }
  
   /*SET_CONFIG*/
   if(expect_SET_CONF(rx_bd)==1)
   {
       usbep1(immr) = 0x1200;
       usbep2(immr) = 0x2200;
       logMsg(\"@Recieve SET_CONFIG\\n\",0,0,0,0,0,0);
       trans_ZERO_DATA(tendp,tx_pid);
   }
  
   /*SET_ADDRESS*/
   if(expect_SET_ADDR(rx_bd)==1)
   {
       trans_ZERO_DATA(tendp,tx_pid);
       logMsg(\"@Set address:0x%x  PID:0x%x\\n\",rx_bd->bd_addr[2],tx_pid,0,0,0,0);
       usbadr(immr) = rx_bd->bd_addr[2];
   }
    if(expect_CBW(rx_bd)==1)
   {  
     logMsg(\"scsi endpoint:0x%x  PID:0x%x\\n\",rx_bd->endpoint,tx_pid,0,0,0,0);
   }
}

void USB_SCSI(test_bd *rx_bd,unsigned int tx_pid)
{  int tendp;
   tendp=2;
   if(expect_CBW(rx_bd)==1)
   {  
     logMsg(\"scsi endpoint:0x%x  PID:0x%x\\n\",rx_bd->endpoint,tx_pid,0,0,0,0);
  trans_0612(tendp,tx_pid);
   }

}
游客

返回顶部