初级会员

- 积分
- 66
- 金钱
- 66
- 注册时间
- 2018-8-2
- 在线时间
- 15 小时
|

楼主 |
发表于 2019-9-17 10:14:22
|
显示全部楼层
本帖最后由 GUOJITONGJIFAN 于 2019-9-17 10:16 编辑
#define STORAGE_LUN_NBR 3
const int8_t STORAGE_Inquirydata[] = {
/* LUN 0 */
0x00,
0x80,
0x02,
0x02,
(USBD_STD_INQUIRY_LENGTH - 4),
0x00,
0x00,
0x00,
/* Vendor Identification */
'A', 'L', 'I', 'E', 'N', 'T', 'E', 'K', ' ',//9×Ö½ú
/* Product Identification */
'S', 'P', 'I', ' ', 'F', 'l', 'a', 's', 'h',//15×Ö½ú
' ','D', 'i', 's', 'k', ' ',
/* Product Revision Level */
'1', '.', '0', ' ', //
/* LUN 1 */
0x00,
0x80,
0x02,
0x02,
(USBD_STD_INQUIRY_LENGTH - 4),
0x00,
0x00,
0x00,
/* Vendor Identification */
'A', 'L', 'I', 'E', 'N', 'T', 'E', 'K',' ', //9×Ö½ú
/* Product Identification */
'N', 'A', 'N', 'D', ' ', 'F', 'l', 'a', 's', 'h',//15×Ö½ú
' ','D', 'i', 's', 'k',
/* Product Revision Level */
'1', '.', '0' ,' ', //4×Ö½ú
/* LUN 2 */
0x00,
0x80,
0x02,
0x02,
(USBD_STD_INQUIRY_LENGTH - 4),
0x00,
0x00,
0x00,
/* Vendor Identification */
'A', 'L', 'I', 'E', 'N', 'T', 'E', 'K',' ',
/* Product Identification */
'S', 'D', ' ', 'F', 'l', 'a', 's', 'h', ' ',
'D', 'i', 's', 'k', ' ', ' ',
/* Product Revision Level */
'1', '.', '0' ,' ',
};
int8_t STORAGE_Init (uint8_t lun);
int8_t STORAGE_GetCapacity (uint8_t lun,uint32_t *block_num,uint32_t *block_size);
int8_t STORAGE_IsReady (uint8_t lun);
int8_t STORAGE_IsWriteProtected (uint8_t lun);
int8_t STORAGE_Read (uint8_t lun,uint8_t *buf,uint32_t blk_addr,uint16_t blk_len);
int8_t STORAGE_Write (uint8_t lun,uint8_t *buf,uint32_t blk_addr,uint16_t blk_len);
int8_t STORAGE_GetMaxLun (void);
//USB Device óû§»Øμ÷oˉêy½ó¿ú
USBD_STORAGE_cb_TypeDef USBD_MICRO_SDIO_fops =
{
STORAGE_Init,
STORAGE_GetCapacity,
STORAGE_IsReady,
STORAGE_IsWriteProtected,
STORAGE_Read,
STORAGE_Write,
STORAGE_GetMaxLun,
(int8_t *)STORAGE_Inquirydata,
};
USBD_STORAGE_cb_TypeDef *USBD_STORAGE_fops=&USBD_MICRO_SDIO_fops;
int8_t STORAGE_Init (uint8_t lun)
{
u8 res=0;
switch(lun)
{
// case 0://SPI FLASH
// W25QXX_Init();
// break;
// case 1://NAND FLASH
// res=FTL_Init();
// break;
case 0://SD¿¨
res=SD_Init();
break;
}
return res;
}
int8_t STORAGE_GetCapacity (uint8_t lun, uint32_t *block_num, uint32_t *block_size)
{
switch(lun)
{
// case 0://SPI FLASH
// *block_size=512;
// *block_num=1024*1024*25/512; //
// break;
// case 1://NAND FLASH
// *block_size=512;
// *block_num=nand_dev.valid_blocknum*nand_dev.block_pagenum*nand_dev.page_mainsize/512;
// break;
case 0://SD¿¨
*block_size=512;
*block_num=SDCardInfo.CardCapacity/512;
break;
}
return 0;
}
int8_t STORAGE_IsReady (uint8_t lun)
{
USB_STATUS_REG|=0X10;//±ê¼ÇÂÖÑˉ
return 0;
}
int8_t STORAGE_IsWriteProtected (uint8_t lun)
{
return 0;
}
int8_t STORAGE_Read (uint8_t lun,uint8_t *buf,uint32_t blk_addr,uint16_t blk_len)
{
int8_t res=0;
USB_STATUS_REG|=0X02;//±ê¼ÇÕyÔú¶áêy¾Y
switch(lun)
{
// case 0://SPI FLASH
// W25QXX_Read(buf,blk_addr*512,blk_len*512);
// break;
// case 1://NAND FLASH
// res=FTL_ReadSectors(buf,blk_addr,512,blk_len);
// break;
case 0://SD¿¨
res=SD_ReadDisk(buf,blk_addr,blk_len);
break;
}
if(res)
{
USB_STATUS_REG|=0X08;//¶á′íÎó!
}
return res;
}
int8_t STORAGE_Write (uint8_t lun,uint8_t *buf,uint32_t blk_addr,uint16_t blk_len)
{
int8_t res=0;
USB_STATUS_REG|=0X01;//±ê¼ÇÕyÔúD′êy¾Y
switch(lun)
{
// case 0://SPI FLASH
// W25QXX_Write(buf,blk_addr*512,blk_len*512);
// break;
// case 1://NAND FLASH
// res=FTL_WriteSectors(buf,blk_addr,512,blk_len);
// break;
case 0://SD¿¨
res=SD_WriteDisk(buf,blk_addr,blk_len);
break;
}
if(res)
{
USB_STATUS_REG|=0X04;//D′′íÎó!
}
return res;
}
int8_t STORAGE_GetMaxLun (void)
{
if(SDCardInfo.CardCapacity)return STORAGE_LUN_NBR-1;
else return STORAGE_LUN_NBR-2;
}
|
|