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

📄 sbc.c

📁 基于uCOS/II制作的MP3
💻 C
字号:
//sbc_operation


#include "config.h"                         /* system configuration */
#include "lib_mcu\usb\usb_drv.h"            /* usb driver definition */
#include "modules\mem\hard.h"               /* low level function definition */
#include "lib_storage\sbc.h"                /* SBC commands definition */
#include "lib_mcu\ide\ideio.h"

//#define Usb_clear_RXOUTB0()  {if(UEPSTAX & 0x42)  UEPSTAX &= 0xbd;}

uchar code  HDD_MANUFACTURER_ID[] = "QUANTUM ";
uchar code  HDD_PRODUCT_ID[] = "HDD_650M_MP3_ST ";
uchar code  HDD_REVITION[] = "1.0 "; 

bdata   bit     no_data_phase;
Uint32 data hdd_sector;
Uint16 data hdd_data_length;
extern data    Uint32 dCBWDataTransferLength;
extern xdata Uint32 fat_bpb_add;        /* address of the first byte of FAT */



extern  void usb_mass_storage_csw (void);



void scsi_command_iquiry(void)
{uchar inquiry_allocation_length;
 uchar i;
   ACC = Usb_read_byte(); //read LUN
   ACC = Usb_read_byte(); //read pagecode
   ACC = Usb_read_byte(); //read Reserved
   inquiry_allocation_length = Usb_read_byte(); //read inquiry_allocation_length
   ACC = Usb_read_byte(); //read control code

  Usb_clear_RXOUT_PP();

  Usb_clear_no_data_phase();
  Usb_clear_status_ready();
  Usb_select_ep(EP_IN);

  Usb_write_byte(0x00); //外设属性
  Usb_write_byte(0x80); //设备可移动
  Usb_write_byte(0x00); 
  Usb_write_byte(0x01); 
  Usb_write_byte(inquiry_allocation_length-5); //以下还有相应的字节数传输
  Usb_write_byte(0x00);
  Usb_write_byte(0x00);
  Usb_write_byte(0x00);

  for (i=0; i<8; i++)
     Usb_write_byte(HDD_MANUFACTURER_ID[i]);

  for (i=0; i<16; i++)
 	 Usb_write_byte(HDD_PRODUCT_ID[i]);

  for (i=0; i<4; i++)
 	 Usb_write_byte(HDD_REVITION[i]);

  Usb_set_TXRDY();
  Usb_select_ep(EP_IN);
  while (!Usb_tx_complete());
  Usb_clear_TXCMPL();
  dCBWDataTransferLength = 0;
  status = 0; 
}


void scsi_command_read_long(void)
{ 
  Usb_clear_RXOUT_PP(); 

  Usb_clear_no_data_phase();
  Usb_clear_status_ready();
  Usb_select_ep(EP_IN);

  Usb_write_byte(0x00);
  Usb_write_byte(0x00);
  Usb_write_byte(0x00);
  Usb_write_byte(0x08);
  Usb_write_byte(0x00);
  Usb_write_byte(0x00);
  Usb_write_byte(0x00);
  Usb_write_byte(0x00);
  Usb_write_byte(0x0c);
  Usb_write_byte(0x00);
  Usb_write_byte(0x02);
  Usb_write_byte(0x00);

  Usb_set_TXRDY();
  Usb_select_ep(EP_IN);
  while (!Usb_tx_complete());
  Usb_clear_TXCMPL();
  dCBWDataTransferLength = 0;
  status = 0;
  }

void scsi_command_read_capacity(void)
{ 
  Usb_clear_RXOUT_PP();
    
  Usb_clear_no_data_phase();
  Usb_clear_status_ready();
  Usb_select_ep(EP_IN);

  Usb_write_byte(0x00);
  Usb_write_byte(0x14);
  Usb_write_byte(0x50);
  Usb_write_byte(0x00);
  Usb_write_byte(0x00);
  Usb_write_byte(0x00);
  Usb_write_byte(0x02);
  Usb_write_byte(0x00);

  Usb_set_TXRDY();
  Usb_select_ep(EP_IN);
  while (!Usb_tx_complete());
  Usb_clear_TXCMPL();
  dCBWDataTransferLength = 0;
  status = 0;
}


void scsi_command_mode_sence(void)
{ Usb_clear_RXOUT_PP();
    
  Usb_clear_no_data_phase();
  Usb_clear_status_ready();
  Usb_select_ep(EP_IN);

  Usb_write_byte(0x03);
  Usb_write_byte(0x00);
  Usb_write_byte(0x00);
  Usb_write_byte(0x00);

  Usb_set_TXRDY();
  Usb_select_ep(EP_IN);
  while (!Usb_tx_complete());
  Usb_clear_TXCMPL();
  dCBWDataTransferLength = 0;
  status = 0;
}

void scsi_command_test_uint_ready(void)
{
 Usb_clear_RXOUT_PP();
 dCBWDataTransferLength = 0;
 status = 0;
}

void Sbc_chip_init (void) 
{ 
  Hard_install();
}


void Sbc_command_chip(void)
{
 uchar rwtime;
 uchar i;
 
 switch(Usb_read_byte()) //read operate code 
  {  
    case SCSI_IQUIRY: 
	      {scsi_command_iquiry();
           break;
           }
    case SCSI_READ_LONG:
          {scsi_command_read_long(); 
           break; 
           }
    case SCSI_READ_CAPACITY:
          {scsi_command_read_capacity();
           break; 
           }
    case SCSI_MODE_SENCE:
	      {  
           scsi_command_mode_sence();
	       break; 
          }

	case SCSI_TEST_UNIT_READY:
	      {
	       scsi_command_test_uint_ready();
	       break;
	      }

	case SCSI_READ:
	   {
	    ACC = Usb_read_byte();
 	    ((Byte*)&hdd_sector)[0] = Usb_read_byte();
		((Byte*)&hdd_sector)[1] = Usb_read_byte();
		((Byte*)&hdd_sector)[2] = Usb_read_byte();
		((Byte*)&hdd_sector)[3] = Usb_read_byte();
        ACC = Usb_read_byte();
        ((Byte*)&hdd_data_length)[0] = Usb_read_byte();
        ((Byte*)&hdd_data_length)[1] = Usb_read_byte();
     
		rwtime = hdd_data_length; 
        Usb_clear_RXOUT_PP();

      for(i = 0; i < rwtime; i++)
		{
		 if (hdd_read_one_sector(hdd_sector+i))
		   {dCBWDataTransferLength = 0;
            status = 0;
		   }
		else 
		   {status = 1;
		    break;
			}
		 }
		break;
	   }

   case SCSI_WRITE:
      {	    
	    ACC = Usb_read_byte();
 	    ((Byte*)&hdd_sector)[0] = Usb_read_byte();
		((Byte*)&hdd_sector)[1] = Usb_read_byte();
		((Byte*)&hdd_sector)[2] = Usb_read_byte();
		((Byte*)&hdd_sector)[3] = Usb_read_byte();
        ACC = Usb_read_byte();
        ((Byte*)&hdd_data_length)[0] = Usb_read_byte();
        ((Byte*)&hdd_data_length)[1] = Usb_read_byte();

        rwtime = hdd_data_length; 
        Usb_clear_RXOUT_PP();

        for(i = 0; i < rwtime; i++)
	    { 
		  if (hdd_write_usb_sector(hdd_sector+i))
		   {
		    dCBWDataTransferLength = 0;
            status = 0;
		    }
		 }

	    break;
	  }


	default :  
	   { 
	    Usb_clear_RXOUT_PP();	
        dCBWDataTransferLength = 0;
        status = 0;
	    break;
	   }

  }
}

⌨️ 快捷键说明

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