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

📄 usb.c

📁 Embest EudKit-II教学系统配Samsung S3C44B0处理器的部分测试程序。
💻 C
📖 第 1 页 / 共 3 页
字号:
        clrfeature();
        break;
  	case GET_CONFIGURATION:   //8
        write_usb(TXD0,usb_cfg);        /*load the config val     */
        break;
  	case GET_DESCRIPTOR:      //6      //6次
        getdescriptor();
        break;
  	case GET_STATUS:          //0
        getstatus();
        break;
  	case SET_ADDRESS:         //5      //1次
        write_usb(EPC0,DEF);
    	write_usb(FAR,usb_buf[2]|AD_EN);
        break;
  	case SET_CONFIGURATION:   //9      //1次
        setconfiguration();
        break;
  	case SET_FEATURE:         //3
        setfeature();
        break;
        case GET_INTERFACE:       //10
        write_usb(TXD0,0);
        break;
        case SET_INTERFACE:       //11
        if(usb_buf[2])          /*if the requested intf!=0*/
        bitset(EPC0,STALL);     /*stall the endpoint      */
        break;
  	default:
    	break;
   }
   else
   {
   }
   write_usb(TXC0,TX_TOGL+TX_EN);
   dtapid_TGL0PID=0;
 }
 else
 {
  if(status_GETDESC)
   {
     if((rxstat&0x5F)!=0x10)
     {
     }
   status_GETDESC=0;
   FLUSHTX0;
  }
  write_usb(RXC0,RX_EN);
 }
}
/***************************************************************************
【功能说明】This subroutine handles RX events for FIFO1 (endpoint 2)
****************************************************************************/
void rxevent_1(void)
{
  rxstat=read_usb(RXS1);		/*get receiver status     */
}
/***************************************************************************
【功能说明】This subroutine handles RX events for FIFO2 (endpoint 4)
****************************************************************************/
void rxevent_2(void)
{
  rxstat=read_usb(RXS2);              /*get receiver status */
}
/***************************************************************************
【功能说明】This subroutine handles RX events for FIFO3 (endpoint 6)
****************************************************************************/
void rxevent_3(void)
{
  U8 i,bytes_count;
//  U8 j = 0;
  rxstat=read_usb(RXS3);		/*get receiver status     */
  if(rxstat&SETUP_R)
  {
  }
  else if(rxstat&RX_ERR)
  {
    FLUSHRX3;                 /*flush RX2 and disable  */
    write_usb(RXC3,RX_EN);    /*re-enable the receiver */
  }
  else
  {
  /*
    do{
         bytes_count = read_usb(RXS3)&0x0f;
         (*(volatile unsigned char *)0x02000002)=RXD3;
         for(i = 0; i< bytes_count; i++)
         {
            COMbuf[j++] = (*(volatile unsigned char *)0x02000000); 
      	    COMlen++;
         }
      }while(bytes_count == 0x0f);
     */
     do{
         bytes_count = read_usb(RXS3)&0x0f;
         (*(volatile unsigned char *)0x02000002)=RXD3;
         for(i = 0; i< bytes_count; i++)
         {
            COMbuf[2][COMfront[2]++] = (*(volatile unsigned char *)0x02000000); 
      	    if(COMfront[2] > 64)
      	    {
      	    	COMfront[2] = 0;
      	    	if(COMfront[2] == COMtail[2])
      	    	{
      	    		COMtail[2]++;
      	    		if(COMtail[2] > 64)
      	    			COMtail[2] = 0;
      	    	}
      	    }
         }
      }while(bytes_count == 0x0f);

/*  	
    while(read_usb(RXS3)&0x0f)
    {
     *Rev_COMptr=read_usb(RXD3);
     Rev_COMptr++;
     Rev_COMlen++;
    }
*/
    FLUSHRX3;                 /*flush RX2 and disable  */
    write_usb(RXC3,RX_EN);    /*re-enable the receiver */
  }
}
/***************************************************************************
【功能说明】This subroutine handles TX events for FIFO0 (endpoint 0)
****************************************************************************/
void txevent_0(void)
{
  U8 lim;
  txstat=read_usb(TXS0);            /*get transmitter status*/
  if((txstat&ACK_STAT)&&(txstat&TX_DONE))
  {
    FLUSHTX0;
    if(status_GETDESC)
    {
      lim=desc_idx+8;
      for(;((desc_idx<lim)&&(desc_idx<desc_sze));desc_idx++)
 	  get_desc();
      TXEN0_PID;
    }
  }
  else
  write_usb(RXC0,RX_EN);          /*re-enable the receiver  */
}
/***************************************************************************
【功能说明】This subroutine handles TX events for FIFO1 (endpoint 1)
****************************************************************************/
void txevent_1(void)
{
  txstat=read_usb(TXS1);              /*get transmitter status  */
}
/***************************************************************************
【功能说明】This subroutine handles TX events for FIFO2 (endpoint 3)
****************************************************************************/
void txevent_2(void)
{
  txstat=read_usb(TXS2);         /*get transmitter status  */
}
/***************************************************************************
【功能说明】This subroutine handles TX events for FIFO3 (endpoint 5)
****************************************************************************/
void txevent_3(void)
{
  txstat=read_usb(TXS3);         /*get transmitter status  */
  //Uart_Printf(0,"\n txstat=%x",txstat);
  if (txstat & ACK_STAT)
 {	
   /*-----------------------------------------------------------------------
    * previous data packet from current ep was received successfully by host
    *-----------------------------------------------------------------------*/
    FLUSHTX3;
    //Flag = TRUE;
  }
  else 
  {
    /*------------------------------------
     * there is no ACK
     * retransmit the previous data packet
     *------------------------------------*/
     if(dtapid_TGL3PID) 
        write_usb(TXC3,TX_TOGL+TX_LAST+TX_EN+RFF);
     else write_usb(TXC3,TX_LAST+TX_EN+RFF);
     dtapid_TGL3PID=!dtapid_TGL3PID;
//     write_usb(TXC3,TX_LAST+TX_EN+RFF);
  }
}
/***************************************************************************
【功能说明】9603写控制,根据具体硬件结构修改 
****************************************************************************/
void write_usb(unsigned char addr,unsigned char dat)
{
	(*(volatile unsigned char *)0x02000002)=addr;
	(*(volatile unsigned char *)0x02000000)=dat;
}
/***************************************************************************
【功能说明】9603读控制,根据具体硬件结构修改
****************************************************************************/
unsigned char read_usb(unsigned char addr)
{
	(*(volatile unsigned char *)0x02000002)=addr;
	return (*(volatile unsigned char *)0x02000000);
}

void bitset(unsigned char addr, unsigned char mask)
{
   write_usb(addr,(read_usb(addr)|(mask)));   /*set the bit (RMW)  */
}

void bitclr(unsigned char addr, unsigned char mask)
{
   write_usb(addr,(read_usb(addr)&(~mask)));  /*clr the bit (RMW)  */
}
/***************************************************************************
【功能说明】取描述符 
****************************************************************************/
void getdescriptor(void)
{
  status_GETDESC=1;                  /*enter GETDESC mode      */
  desc_typ=usb_buf[3];               /*store the type requested*/
  /*select descriptor size and starting index  */
  if(desc_typ==DEVICE)
    desc_sze=DEV_DESC_SIZE;          /*DEV_DESC_SIZE=18        */
  else if(desc_typ==CONFIGURATION)
    desc_sze=CFG_DESC_SIZE;          /*DEV_DESC_SIZE=18        */
  if (desc_sze>usb_buf[6])
    desc_sze=usb_buf[6];
  for(desc_idx=0;((desc_idx<8)&&(desc_idx<desc_sze));desc_idx++)
    get_desc();
}

void get_desc(void)
{
  U8 desc_dta;
  if(desc_typ==DEVICE)
  {
    desc_dta=DEV_DESC[desc_idx];
  }
  else if(desc_typ==CONFIGURATION)
    desc_dta=CFG_DESC[desc_idx];
    write_usb(TXD0,desc_dta);
}
/***************************************************************************
【功能说明】取状态
****************************************************************************/
void getstatus(void)
{
	switch(usb_buf[0]&0x03)            /*find request target     */
	{
		case 0:                    /*DEVICE                  */
		write_usb(TXD0,0);         /*first  byte is reserved */
	    break;

	    case 1:                        /*INTERFACE               */
	    write_usb(TXD0,0);             /*first  byte is reserved */
	    break;

	    case 2:                        /*ENDPOINT                */
	    switch(usb_buf[4]&0x0f)        /*find specific endpoint  */
		{                          /*  (strip off dir. bit)  */
			case 0:
			if(stall0)write_usb(TXD0,1);else write_usb(TXD0,0);
			break;

			case 1:
			if(stall1)write_usb(TXD0,1);else write_usb(TXD0,0);
			break;

			case 2:
			if(stall2)write_usb(TXD0,1);else write_usb(TXD0,0);
			break;

			case 3:
			if(stall3)write_usb(TXD0,1);else write_usb(TXD0,0);
			break;

			case 4:
			if(stall4)write_usb(TXD0,1);else write_usb(TXD0,0);
			break;

			case 5:
			if(stall5)write_usb(TXD0,1);else write_usb(TXD0,0);
			break;

			case 6:
			if(stall6)write_usb(TXD0,1);
			else write_usb(TXD0,0); /*first  byte is reserved */
			break;

			default:
			break;
		}
		default:
		break;
	}
	write_usb(TXD0,0);             /*second byte is reserved */
}
/***************************************************************************
【功能说明】清除特性
****************************************************************************/
void clrfeature(void)
{
	switch(usb_buf[0]&0x03)  /*find request target*/
	{
		case 0:              /*DEVICE             */
	    break;

	    case 1:              /*INTERFACE          */
	    break;

	    case 2:              /*ENDPOINT           */
	    switch(usb_buf[4]&0x0f)/*find specific endpoint*/
		{
			case 0:
		    	stall0=0;
		    	break;

		  	case 1:
		    	stall1=0;
		    	break;

		  	case 2:
		    	stall2=0;
		    	break;

		  	case 3:

⌨️ 快捷键说明

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