/*********************************************************************
*
* Microchip USB C18 Firmware - MSD Version 1.0
*
*********************************************************************
* FileName: msd.c
* Dependencies: See INCLUDES section below
* Processor: PIC18
* Compiler: C18 2.40
* Company: Microchip Technology, Inc.
*
* Software License Agreement
*
* The software supplied herewith by Microchip Technology Incorporated
* (the Company) for its PICmicro® Microcontroller is intended and
* supplied to you, the Companys customer, for use solely and
* exclusively on Microchip PICmicro Microcontroller products. The
* software is owned by the Company and/or its supplier, and is
* protected under applicable copyright laws. All rights are reserved.
* Any use in violation of the foregoing restrictions may subject the
* user to criminal sanctions under applicable laws, as well as to
* civil liability for the breach of the terms and conditions of this
* license.
*
* THIS SOFTWARE IS PROVIDED IN AN AS IS CONDITION. NO WARRANTIES,
* WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED
* TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE COMPANY SHALL NOT,
* IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR
* CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
*
* Author Date Comment
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* Gurinder Singh 05/31/05 Original.
********************************************************************/
/** I N C L U D E S **************************************************/
#include <p18cxxx.h>
#include "system\typedefs.h"
#include "system\usb\usb.h"
#include<string.h>
#ifdef USB_USE_MSD
/** V A R I A B L E S ************************************************/
#pragma udata
byte MSD_State; // Takes values MSD_WAIT, MSD_DATA_IN or MSD_DATA_OUT
USB_MSD_CBW gblCBW;
byte gblCBWLength;
SDCSTATE gblFlag;
RequestSenseResponse gblSenseData;
byte *ptrNextData;
/*
* Number of Blocks and Block Length are global because
* for every READ_10 and WRITE_10 command need to verify if the last LBA
* is less than gblNumBLKS
*/
DWORD gblNumBLKS=0x00,gblBLKLen=0x00;
/* Standard Response to INQUIRY command stored in ROM */
const rom InquiryResponse inq_resp = {
0x00, // peripheral device is connected, direct access block device
0x80, // removable
0x04, // version = 00=> does not conform to any standard, 4=> SPC-2
0x02, // response is in format specified by SPC-2
0x20, // n-4 = 36-4=32= 0x20
0x00, // sccs etc.
0x00, // bque=1 and cmdque=0,indicates simple queueing 00 is obsolete,
// but as in case of other device, we are just using 00
0x00, // 00 obsolete, 0x80 for basic task queueing
"Microchp", // this is the T10 assigned Vendor ID
"Mass Storage ",
"0001"
};
/** P R I V A T E P R O T O T Y P E S ***************************************/
void MSDCommandHandler(void);
void MSDInquiryHandler(void);
void MSDReadCapacityHandler(void);
void MSDReadHandler(void);
void MSDWriteHandler(void);
void MSDModeSenseHandler(void);
void MSDMediumRemovalHandler(void);
void MSDRequestSenseHandler(void);
void MSDTestUnitReadyHandler(void);
void MSDVerifyHandler(void);
void MSDStopStartHandler(void);
byte IsMeaningfulCBW(void);
byte IsValidCBW(void);
void PrepareCSWData(void);
void SendData(byte*, byte);
void SendCSW(void);
void ResetSenseData(void);
void MSDDataIn(void);
void MSDDataOut(void);
extern SDC_Error MediaInitialize(SDCSTATE*);
extern void SocketInitialize(void);
extern SDC_Error SectorRead(dword, byte*);
extern SDC_Error SectorWrite(dword, byte*);
extern SDC_Error CSDRead(void);
extern int DetectSDCard (void);
extern byte IsWriteProtected(void);
/** D E C L A R A T I O N S **************************************************/
#pragma code
/** C L A S S S P E C I F I C R E Q ****************************************/
/******************************************************************************
* Function: void USBCheckMSDRequest(void)
*
* PreCondition: None
*
* Input: None
*
* Output: None
*
* Side Effects: None
*
* Overview: This routine handles the standard RESET and GET_MAX_LUN
* command requests received on the control endpoint EP0
*
* Note: None
*****************************************************************************/
void USBCheckMSDRequest(void)
{
switch(SetupPkt.bRequest)
{
case MSD_RESET:
ctrl_trf_session_owner = MUID_MSD;
mDisableEP1to15(); // See usbdrv.h
if (UEP1bits.EPSTALL==1) {
UEP1bits.EPSTALL = 0;
MSDInitEP();
}
UIRbits.STALLIF = 0;
break;
case GET_MAX_LUN:
ctrl_trf_session_owner = MUID_MSD;
CtrlTrfData._byte[0] = MAX_LUN;
wCount._word = 1;
pSrc.bRam = (unsigned char*)&CtrlTrfData;
usb_stat.ctrl_trf_mem = _RAM;
break;
} //end switch(SetupPkt.bRequest)
}
/******************************************************************************
* Function: void ProcessIO(void)
*
* PreCondition: MSDInitEP() and SDCardInit() have beed called.
* MSDInitEP() is called from USBStdSetCfgHandler(void)(usb9.c)
* SDCardInit() is called from InitializeSystem() in main.c
*
* Input: None
*
* Output: None
*
* Side Effects: None
*
* Overview: This routine is called in continuous loop from main.c
* All the Bulk Transport Commands on EndPoint 1 are
* handled here. MSD_State holds the current state of the
* Mass Storage Module.
* In MSD_WAIT State - Wait for a Command Block Wrapper (CBW)
* on EP1. If a valid and meaningful CBW is received,
* depending on the command received MSD_State is changed to
* MSD_DATA_IN if data is to be sent to host (for all commands
* other than WRITE_10)
* MSD_DATA_OUT if host is expected to send data (only in case
* of WRITE_10). At the end of Data Transfer Command Status
* Wrapper (CSW) is sent by calling SendCSW()
*
* Note: None
*****************************************************************************/
void ProcessIO(void)
{
byte i;
dword size;
if (MSD_State==MSD_DATA_IN) {
/* Send Data to Host */
if(gblCBW.dCBWDataTransferLength==0)
{
/* Finished sending the data send the Status */
/* SendCSW() send the csw and sets the state to wait */
SendCSW();
if ((msd_csw.bCSWStatus==0x00)&&(gblCBW.CBWCB[0]==INQUIRY)) {
/* Turn on the MSD LED when we have successfully*/
/*responded to the INQUIRY Command */
STMSDLED=1;
}
}
else
{
/* Still have data to Send */
MSDDataIn();
}
return;
}
if (MSD_State==MSD_DATA_OUT) {
/* Receive data from Host*/
if(gblCBW.dCBWDataTransferLength==0) {
/* Finished receiving the data prepare and send the status */
if ((msd_csw.bCSWStatus==0x00)&&(msd_csw.dCSWDataResidue!=0))
msd_csw.bCSWStatus=0x02;
SendCSW(); // sends the csw and sets the state to wait
}
/*
* Note that MSD_DATA_OUT State is reached only for the WRITE_10 COMMAND
* Also note that this code is reached in MSD_DATA_OUT State only after
* we have read the required amount of data from the host
* This procsssing is done in WriteCommandHandler because we have
* limited buffer space. We read from host in 64Bytes chunks
* (size of MSD_BD_OUT), fill the msd_buffer(512B) and write the
* data into the SDCard
*/
没有合适的资源?快使用搜索试试~ 我知道了~
MSD.rar_MSD-880_msd_sd usb_usb msd
共41个文件
h:15个
o:9个
c:8个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 56 浏览量
2022-09-20
14:11:14
上传
评论
收藏 262KB RAR 举报
温馨提示
usb slaver for sd card
资源详情
资源评论
资源推荐
收起资源包目录
MSD.rar (41个子文件)
www.pudn.com.txt 218B
MSD
18f4550.lkr 1KB
MassStorage.mcw 173KB
main.c 5KB
io_cfg.h 5KB
_output
usbctrltrf.o 17KB
MassStorage.cod 77KB
MassStorage.hex 24KB
MassStorage.lst 1.27MB
usbdrv.o 11KB
fileio.o 319KB
msd.o 64KB
MassStorage.cof 150KB
main.o 4KB
usbmmap.o 10KB
sdcard.o 47KB
usbdsc.o 4KB
usb9.o 14KB
system
sdcard
sdcard.c 25KB
sdcard.h 8KB
usb
usb9
usb9.c 11KB
usb9.h 4KB
class
msd
msd.c 36KB
msd.h 13KB
usbdrv
usbdrv.c 23KB
usbdrv.h 9KB
usb_compile_time_validation.h 3KB
usbmmap.h 7KB
usbctrltrf
usbctrltrf.c 19KB
usbctrltrf.h 3KB
usbmmap.c 12KB
usb.h 2KB
usbdefs
usbdefs_std_dsc.h 6KB
usbdefs_ep0_buff.h 7KB
Compiler.h 11KB
typedefs.h 7KB
MassStorage.mcp 2KB
usb9.i 59KB
autofiles
usbdsc.h 3KB
usbdsc.c 11KB
usbcfg.h 4KB
共 41 条
- 1
御道御小黑
- 粉丝: 58
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0