📄 drv_usb.c
字号:
/*---------------------------------------------------------------
* Developed By Signal Process, synergy Co.,Ltd.
* Copyright (c) 2006-2008 synergy Co.,Ltd.
* All Right Reserved.
*
* $Author Zhaoww (Zhaoww@synergy.com.cn)
* $Version: Alpha
* $Since 2006.4.11
* $Log
*
* DESCRIPTION
* DRV USB File for omp5912 Series
*
*---------------------------------------------------------------*/
#define _DRV_USB_GLOBALS_
#include "includes.h"
#include "drv_usb.h"
/* SCSI Command Codes
* Based on the USB Mass Storage Class - UFI Commands */
#define SCSI_TEST_UNIT_READY 0x00
#define SCSI_INQUIRY 0x12
#define SCSI_MEDIA_REMOVAL 0x1E
#define SCSI_MODE_SENSE 0x1A
#define SCSI_READ_FORMAT_CAPACITY 0x23
#define SCSI_READ_CAPACITY 0x25
#define SCSI_READ 0x28
#define SCSI_WRITE 0x2a
#define SCSI_VERIFY 0x2f
/* Command Block Wrapper Signature */
#define CBW_SIGNATURE 0x43425355
/* Command Status Wrapper Signature */
#define CSW_SIGNATURE 0x53425355
#define CSW_COMMAND_PASS 0
#define CSW_COMMAND_FAIL 1
#define CSW_COMMAND_PHASE_ERROR 2
/* RamDisk Sector Size */
#define SECTOR_SIZE 512
/* ------------------------------------------------------------------------- */
/* SCSI Response */
/* PreDetermined SCSI Response for USB DISK */
/* ------------------------------------------------------------------------- */
INT8U scsi_inquiry[] = {
0x00, /* Peripheral Device Type: [0x00 Direct-access device: floppy] */
0x80, /* Removable Media: [0x80: YES, 0x00: NO] */
0x00, /* Version Info: Set to [0x00 for UFI] */
0x01, /* Response Data Format: [0x01 for UFI] */
0x1f, /* Additional Length: Length of IDs Strings */
0x00, /* Reserved [0x00] */
0x00, /* Reserved [0x00] */
0x00, /* Reserved [0x00] */
'S', 'p', 'e', 'c', 'D', 'i', 'g', ' ', /* Vender ID [8-15] : SpecDig */
'O', 'S', 'K', '5', '9', '1', '2', ' ', /* Product ID [16-31]: OSK5912 */
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
'0', '0', '0', '1' /* Product Revision : 0001 */
};
INT8U scsi_capacity[] = {
0x00, 0x00, 0x01, 0x80, /* Last Logical Block Address */
0x00, 0x00, 0x02, 0x00 /* Block Length in bytes */
};
INT8U scsi_mode_sense[] = {
0x02, 0x00, 0x00, 0x00
};
INT8U scsi_read_fmt_cap[] = {
0x00, /* Reserved [0x00] */
0x00, /* Reserved [0x00] */
0x00, /* Reserved [0x00] */
0x08, /* Capacity List Header */
0x00, 0x01, 0xf4, 0xff, /* Current/Maximum Capacity Descriptor */
0x03, /* Descriptor Code: [0x1 Unformatted Media]
* [0x2 Formatted Media]
* [0x3 No Cartridge in Drive] */
0x00, 0x02, 0x00 /* Block Length in bytes */
};
/* ------------------------------------------------------------------------- */
/* USB Bulk Variables */
/* Bulk In & Bulk Out Variables to implement a Mass Storage Class */
/* ------------------------------------------------------------------------- */
/* For RAM Disk */
INT8U ramDiskBuffer[SECTOR_SIZE];
INT8U* pRamDiskBuffer = 0;
INT32U logicalBlockAddr = 0;
INT16U numLogicalBlocks = 0;
/* For Writing to the RAM Disk */
INT32S sizeToWrite = 0;
INT8S writeInProgress = 0;
/* For Reading from the RAM Disk */
INT32S sizeToRead = 0;
INT8S readInProgress = 0;
/* Command Wrapper Buffers */
INT8U csw[13];
INT8U cbw[31];
INT8S postCSW = 0;
/* Device Descriptor ptr */
INT8U* dev_desc;
/* Configuration Descriptor ptr */
INT8U* cfg_desc;
/* Configuration Descriptor size */
INT16U cfg_desc_size = 0 ;
volatile INT16U last_state=0;
volatile INT16U test_result = 0;
volatile INT16U test_suspend = 0;
volatile INT16U test_detect = 0;
CSL_UsbfObj usbfObj;
UsbStringDesc string_desc_tbl[USB_STRING_INDEX_MAX];
/* USB function Handler */
void(* endpt_func_in[USB_EP_SIZE + 1])(INT8U,INT8U);
void(* endpt_func_out[USB_EP_SIZE + 1])(INT8U,INT8U);
INT8U* ep0_send_ptr = 0; /* Ptr to data to send */
INT16U ep0_send_len = 0; /* Len of data waiting */
INT8U ep0_post_send = 0;
/** usbf handle */
CSL_UsbfHandle hUsbf ;
INT8U ep3_num = 0;
/* String 0 Descriptor */
INT8U usb_string0_desc[] =
{
0x04, /* Desc. Size */
0x03, /* String Desc ( 0x03 )*/
0x09, 0x04 /* Language ID ( 0x0409=English )*/ /* BIG End 0x04, 0x09,*/
};
/* String 1 Descriptor: "USB Storage" */
INT8U usb_string1_desc[] =
{
0x18, /* Desc. Size*/
0x03, /* String Desc ( 0x03 )*/
'U', 0x00, 'S', 0x00, 'B', 0x00, ' ', 0x00, /* BIG End move 0x00 to front*/
'S', 0x00, 't', 0x00, 'o', 0x00, 'r', 0x00, 'a', 0x00, 'g', 0x00, 'e', 0x00
};
/* String 2 Descriptor: "Spectrum Digital Inc." */
INT8U usb_string2_desc[] =
{
0x2C, /* Desc. Size*/
0x03, /* String Desc ( 0x03 )*/
'S', 0x00, 'p', 0x00, 'e', 0x00, 'c', 0x00, 't', 0x00, 'r', 0x00,
'u', 0x00, 'm', 0x00, ' ', 0x00,
'D', 0x00, 'i', 0x00, 'g', 0x00, 'i', 0x00, 't', 0x00, 'a', 0x00,
'l', 0x00, ' ', 0x00,
'I', 0x00, 'n', 0x00, 'c', 0x00, '.', 0x00 /* BIG End move 0x00 to front */
};
/* String 3 Descriptor: "OSK5912" */
INT8U usb_string3_desc[] =
{
0x10, /* Desc. Size*/
0x03, /* String Desc ( 0x03 )*/
'O', 0x00, 'S', 0x00, 'K', 0x00, '5', 0x00, '9', 0x00, '1', 0x00,
'2', 0x00 /* BIG End move 0x00 to front*/
};
/* String 4 Descriptor: "0000000000001" */
INT8U usb_string4_desc[] =
{
0x1C, /* Desc. Size*/
0x03, /* String Desc ( 0x03 )*/
'0', 0x00, '0', 0x00, '0', 0x00, '0', 0x00, '0', 0x00, '0', 0x00,
'0', 0x00, '0', 0x00, '0', 0x00, '0', 0x00, '0', 0x00, '0', 0x00,
'1', 0x00, /* BIG End move 0x00 to front*/
};
#if 0
/* Device Descriptor */
INT8U usb_device_desc[] =
{
0x12, /* Desc. Size ( 18 bytes )*/
0x01, /* Device Desc. ( 0x01 )*/
0x01, 0x01, /* USB Spec ( ver 1.1 ) */ /* BIG End 0x01, 0x10,*/
0x00, /* Class Code*/
0x00, /* SubClass Subclass Code*/
0x00, /* Protocol Code */
0x40, /* Maximum Packet Size {8, 16, 32, or 64} */
0x71, 0x04, /* Vendor ID */ /* BIG End 0x0C, 0x55, */
0x22, 0x02, /* Product ID */ /* BIG End 0x59, 0x10, */
0x13, 0x01, /* Device Release Number */ /* BIG End 0x00, 0x02, */
0x00, /* Manufacturer String Desc Index */
0x00, /* Product String Desc Index */
0x00, /* Serial Number String Desc Index */
0x01 /* Num Configuration( s ) */
};
/* Configuration Descriptor */
INT8U usb_config_desc[] =
{
0x09, /* Desc. Size ( 9 bytes ) */
0x02, /* Configuration Desc. ( 0x02 ) */
0x20, 0x00, /* Total length of Config Tree */ /* BIG End 0x00, 0x20, */
0x01, /* Num Interface( s ) */
0x01, /* Configuration Value */
0x00, /* Index of String Desc. for Config. */
0x80, /* Attributes */
0x32, /* Max Power Consumption ( *2mA ) */
/* Interface 1 Descriptor */
0x09, /* Desc. Size ( 9 bytes ) */
0x04, /* Interface Desc. ( 0x04 ) */
0x00, /* Num Interface( s ) */
0x00, /* Value for alt. settings */
0x02, /* Num Endpoint( s ) on Interface */
0x08, /* Class Code - ( MASS STORAGE CLASS ) */
0x04, /* SubClass Code */
0x50, /* Protocol Code */
0x00, /* Index of String Desc. for Intf. */
/* Endpoint 1 Descriptor */
0x07, /* Desc. Size ( 7 bytes ) */
0x05, /* Endpoint Desc ( 0x05 ) */
0x82, /* Endpoint Address */
0x02, /* Attributes */
0x40, 0x00, /* Max Packet Size */ /* BIG End 0x00, 0x40, */
0x00, /* Polling Interval */
/* Endpoint 2 Descriptor */
0x07, /* Desc. Size ( 7 bytes ) */
0x05, /* Endpoint Desc ( 0x05 ) */
0x02, /* Endpoint Address */
0x02, /* Attributes */
0x40, 0x00, /* Max Packet Size */ /* BIG End 0x00, 0x40, */
0x00 /* Polling Interval */
};
#endif
#if 1
/* Device Descriptor */
INT8U usb_device_desc[] =
{
0x12, /* Desc. Size ( 18 bytes )*/
0x01, /* Device Desc. ( 0x01 )*/
0x01, 0x01, /* USB Spec ( ver 1.1 ) */ /* BIG End 0x01, 0x10,*/
0x00, /* Class Code*/
0x00, /* SubClass Subclass Code*/
0x00, /* Protocol Code */
0x40, /* Maximum Packet Size {8, 16, 32, or 64} */
0x55, 0x0C, /* Vendor ID */ /* BIG End 0x0C, 0x55, */
0x12, 0x59, /* Product ID */ /* BIG End 0x59, 0x10, */
0x02, 0x00, /* Device Release Number */ /* BIG End 0x00, 0x02, */
0x02, /* Manufacturer String Desc Index */
0x03, /* Product String Desc Index */
0x04, /* Serial Number String Desc Index */
0x01 /* Num Configuration( s ) */
};
/* Configuration Descriptor */
INT8U usb_config_desc[] =
{
0x09, /* Desc. Size ( 9 bytes ) */
0x02, /* Configuration Desc. ( 0x02 ) */
0x20, 0x00, /* Total length of Config Tree */ /* BIG End 0x00, 0x20, */
0x01, /* Num Interface( s ) */
0x01, /* Configuration Value */
0x01, /* Index of String Desc. for Config. */
0x60, /* Attributes */
0x00, /* Max Power Consumption ( *2mA ) */
/* Interface 1 Descriptor */
0x09, /* Desc. Size ( 9 bytes ) */
0x04, /* Interface Desc. ( 0x04 ) */
0x00, /* Num Interface( s ) */
0x00, /* Value for alt. settings */
0x02, /* Num Endpoint( s ) on Interface */
0x08, /* Class Code - ( MASS STORAGE CLASS ) */
0x06, /* SubClass Code */
0x50, /* Protocol Code */
0x05, /* Index of String Desc. for Intf. */
/* Endpoint 1 Descriptor */
0x07, /* Desc. Size ( 7 bytes ) */
0x05, /* Endpoint Desc ( 0x05 ) */
0x02, /* Endpoint Address */
0x02, /* Attributes */
0x40, 0x00, /* Max Packet Size */ /* BIG End 0x00, 0x40, */
0x00, /* Polling Interval */
/* Endpoint 2 Descriptor */
0x07, /* Desc. Size ( 7 bytes ) */
0x05, /* Endpoint Desc ( 0x05 ) */
0x82, /* Endpoint Address */
0x02, /* Attributes */
0x40, 0x00, /* Max Packet Size */ /* BIG End 0x00, 0x40, */
0x00 /* Polling Interval */
};
#endif
INT8U dummy_dev_desc[64] = {
0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40
};
void processSetup(void);
CSL_Status CSL_usbfGetHwStatus( CSL_UsbfHandle hUsbf,CSL_UsbfHwStatusQuery query,void *response);
CSL_Status CSL_usbfHwControl(
/** Pointer to the object that holds reference to the
* instance of SSw requested after the open call */
CSL_UsbfHandle hUsbf,
/** The command that indicates the operation to be performed */
CSL_UsbfHwControlCmd cmd,
/** Command argument: Type casted to type mentioned in @a CSL_UsbfHwControlCmd enumeration */
void *cmdArg
);
void processEP0( INT8U endpt_num, INT8U endpt_dir );
void USB_AttachedStateHandler( void )
{ }
void USB_DefaultStateHandler( void )
{ }
void USB_SuspendStateHandler( void )
{
/* Remote Wakeup to bring back from Suspend State */
if (CSL_SOK != CSL_usbfHwControl(hUsbf,CSL_USBF_CMD_INIT_REMOTE_WAKEUP,NULL))
{
OS_DEBUGF(DEV_USB,(" CSL_USBF_CMD_INIT_REMOTE_WAKEUP:cmd failed \r\n"));
}
if (test_result == 2)
test_suspend++;
}
/** ============================================================================
* @func USB_AddressStateHandler
* @desc
* Handles the address state change of the device
*
* =============================================================================
*/
void USB_AddressStateHandler( void )
{
INT16U dmaIntr;
/* Configure Endpoints for Bulk DMA transfer
* TX0_DONE_IE Transmit DMA channel 0 done interrupt enable
* RX0_CNT_IE Receive DMA channel 0 transactions count interrupt enable
* RX0_EOT_IE Receive DMA channel 0 end of transfer interrupt enable
*/
dmaIntr = 0x7;
if (CSL_SOK != CSL_usbfHwControl(hUsbf,CSL_USBF_CMD_ENABLE_DMA_INTERRUPT,&dmaIntr))
{
OS_DEBUGF(DEV_USB,(" CSL_USBF_CMD_ENABLE_DMA_INTERRUPT:cmd failed \r\n"));
}
hUsbf->regs->RXDMA_CFG = 0
| ( 0 << 12 ) /* RX_REQ */
| ( 0 << 8 ) /* 11:8 RXDMA2_EP */
| ( 0 << 4 ) /* 7:4 RXDMA1_EP */
| ( 0 << 0 ) /* 3:0 RXDMA0_EP */
;
hUsbf->regs->TXDMA_CFG = 0
| ( 0 << 12 ) /* TX_REQ */
| ( 0 << 8 ) /* 11:8 TXDMA2_EP */
| ( 0 << 4 ) /* 7:4 TXDMA1_EP */
| ( 0 << 0 ) /* 3:0 TXDMA0_EP */
;
hUsbf->regs->TXDMA0 = 0
| ( 0 << 15 ) /* TXn_EOT */
| ( 0 << 14 ) /* TXn_START */
| ( 0 << 0 ) /* 9:0 TXn_TSC */
;
hUsbf->regs->TXDMA1 = 0
| ( 0 << 15 ) /* TXn_EOT */
| ( 0 << 14 ) /* TXn_START */
| ( 0 << 0 ) /* 9:0 TXn_TSC */
;
hUsbf->regs->TXDMA2 = 0
| ( 0 << 15 ) /* TXn_EOT */
| ( 0 << 14 ) /* TXn_START */
| ( 0 << 0 ) /* 9:0 TXn_TSC */
;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -