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

📄 sbc.c

📁 atmel at89c51snd1c mp3芯片方案源码
💻 C
字号:
//sbc_operation


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

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

bdata   bit     no_data_phase;
Uint32 data     media_sector;
Uint16 data     media_data_length;
extern data     Uint32 dCBWDataTransferLength;
extern xdata    Uint32 total_capacity;

INT8U code sbc_vendor[8]   = SBC_VENDOR_ID;
INT8U code sbc_product[16] = SBC_PRODUCT_ID;
INT8U code sbc_revision[4] = SBC_REVISION_ID;



////////////////////////////////////////////////////////////////////////////////////////
void Sbc_chip_init (void) 
{ 
//  Hard_install();
}



////////////////////////////////////////////////////////////////////////////////////////
void scsi_command_iquiry(void)
{
   uchar inquiry_allocation_length;
   uchar i;
   INT8U *p;

   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);

   p = sbc_vendor;
   for (i=0; i<8; i++)
   {
     Usb_write_byte(*p ++);
   }

   p = sbc_product;
   for (i=0; i<16; i++)
   {
 	 Usb_write_byte(*p ++);
   }

   p = sbc_revision;
   for (i=0; i<4; i++)
   {
 	 Usb_write_byte(*p ++); 
   }

   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(((Byte*)&total_capacity)[3]);
   Usb_write_byte(((Byte*)&total_capacity)[2]);
   Usb_write_byte(((Byte*)&total_capacity)[1]);
   Usb_write_byte(((Byte*)&total_capacity)[0]);
   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 scsi_command_read(void)
{
   INT8U i, u8Sectors;

   ACC = Usb_read_byte();
   ((Byte*)&media_sector)[0] = Usb_read_byte();
   ((Byte*)&media_sector)[1] = Usb_read_byte();
   ((Byte*)&media_sector)[2] = Usb_read_byte();
   ((Byte*)&media_sector)[3] = Usb_read_byte();
   ACC = Usb_read_byte();
   ((Byte*)&media_data_length)[0] = Usb_read_byte();
   ((Byte*)&media_data_length)[1] = Usb_read_byte();
 
   u8Sectors = media_data_length; 
   Usb_clear_RXOUT_PP();

   for(i=0; i<u8Sectors; i++)
   {
      if(Hard_read_one_sector(media_sector + i))
      {
        dCBWDataTransferLength = 0;
        status = 0;
      }
      else 
      {
        status = 1;
        break;
	  }
   } 
}


/////////////////////////////////////////////////////////////////////////
void scsi_command_write(void)
{
    INT8U i, u8Sectors;

    ACC = Usb_read_byte();
    ((Byte*)&media_sector)[0] = Usb_read_byte();
	((Byte*)&media_sector)[1] = Usb_read_byte();
	((Byte*)&media_sector)[2] = Usb_read_byte();
	((Byte*)&media_sector)[3] = Usb_read_byte();
    ACC = Usb_read_byte();
    ((Byte*)&media_data_length)[0] = Usb_read_byte();
    ((Byte*)&media_data_length)[1] = Usb_read_byte();

    u8Sectors = media_data_length; 
    Usb_clear_RXOUT_PP();

    for(i=0; i<u8Sectors; i++)
    { 
	   if (Hard_write_one_sector(media_sector + i))
	   {
	      dCBWDataTransferLength = 0;
          status = 0;
	   }
       else 
       {
         status = 1;
         break;
	   }
	}	     
}


/////////////////////////////////////////////////////////////////////////
void Sbc_command_chip(void)
{
   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:
           scsi_command_read();
           break;

      case SCSI_WRITE:	    
           scsi_command_write();
           break;

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

⌨️ 快捷键说明

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