基于MCU的U盘源码实现flash的windos文件系统
#include "d12ci.h"
#include "main.h"
//#include "44b.h"
extern EPPFLAGS bEPPflags;
void outportdata(unsigned char val)
{
DISABLE;
D12_DATA=val;
ENABLE;
}
void outportcmd(unsigned char val)
{
DISABLE;
D12_COMMAND=val;
ENABLE;
}
unsigned char inportb(void)
{
unsigned char c;
DISABLE;
c = D12_DATA;
ENABLE;
return c;
}
void D12_SetAddressEnable(unsigned char bAddress, unsigned char bEnable)
{
if(bEPPflags.bits.in_isr == 0)
DISABLE;
outportcmd(0xD0);
if(bEnable)
bAddress |= 0x80;
outportdata(bAddress);
if(bEPPflags.bits.in_isr == 0)
ENABLE;
// Uart_Printf("E D12_SetAddressEnable\n");
}
void D12_SetEndpointEnable(unsigned char bEnable)
{
if(bEPPflags.bits.in_isr == 0)
DISABLE;
outportcmd(0xD8);
if(bEnable)
outportdata(1);
else
outportdata(0);
if(bEPPflags.bits.in_isr == 0)
ENABLE;
// Uart_Printf("E D12_SetEndpointEnable\n");
}
void D12_SetMode(unsigned char bConfig, unsigned char bClkDiv)
{
if(bEPPflags.bits.in_isr == 0)
DISABLE;
outportcmd(0xF3);
outportdata(bConfig);
outportdata(bClkDiv);
if(bEPPflags.bits.in_isr == 0)
ENABLE;
// Uart_Printf("E D12_SetMode\n");
}
void D12_SetDMA(unsigned char bMode)
{
if(bEPPflags.bits.in_isr == 0)
DISABLE;
outportcmd(0xFB);
outportdata(bMode);
if(bEPPflags.bits.in_isr == 0)
ENABLE;
// Uart_Printf("E D12_SetDMA\n");
}
/*
unsigned char D12_GetDMA(void)
{
outportcmd(0xFB);
return(inportb());
}
*/
/*
unsigned char D12_ReadEndpointStatus(unsigned char bEndp)
{
unsigned char c;
if(bEPPflags.bits.in_isr == 0)
DISABLE;
outportcmd(0x80 + bEndp);
c = inportb();
if(bEPPflags.bits.in_isr == 0)
ENABLE;
return c;
}
*/
void D12_SetEndpointStatus(unsigned char bEndp, unsigned char bStalled)
{
if(bEPPflags.bits.in_isr == 0)
DISABLE;
outportcmd(0x40 + bEndp);
outportdata(bStalled);
if(bEPPflags.bits.in_isr == 0)
ENABLE;
// Uart_Printf("E D12_SetEndpointStatus\n");
}
/*
void D12_SendResume(void)
{
outportcmd(0xF6);
}
*/
unsigned char D12_WriteEndpoint(unsigned char endp, unsigned char len, unsigned char * buf)
{
unsigned char i;
if(bEPPflags.bits.in_isr == 0)
DISABLE;
//---------------------
outportcmd(endp); //选择端点
inportb(); //读入满/空状态
outportcmd(0xF0); //写缓冲区命令
outportdata(0);
outportdata(len);
for(i=0; i
outportcmd(0xFA); //驶购冲区有效
//--------------------------------
if(bEPPflags.bits.in_isr == 0)
ENABLE;
// Uart_Printf("E D12_WriteEndpoint\n");
return len;
}
void D12_AcknowledgeEndpoint(unsigned char endp)
{
outportcmd( endp); //选择端点
outportcmd(0xF1); //应答设置
if(endp == 0)
outportcmd(0xF2); //缓冲区清零
// Uart_Printf("E D12_AcknowledgeEndpoint%d\n",endp);
}
unsigned short D12_ReadInterruptRegister(void)
{
unsigned char b1;
unsigned int j;
//outportb(D12_COMMAND, 0xF4);
outportcmd(0xF4);
b1 = inportb();
j = inportb();
j <<= 8;
j += b1;
// if(j) Uart_Printf("E D12_ReadInterruptRegister:%x\n",j);//printf the intterrupt number if it's not zero.
return j;
}
unsigned char D12_ReadLastTransactionStatus(unsigned char bEndp)
{
//outportb(D12_COMMAND, 0x40 + bEndp);
outportcmd(0x40 + bEndp);
// Uart_Printf("E D12_ReadLastTransactionStatus\n");
return inportb();
}
unsigned char D12_ReadEndpoint(unsigned char endp, unsigned char len, unsigned char * buf)
{
unsigned char i, j;
if(bEPPflags.bits.in_isr == 0)
DISABLE;
//--------------------------------
outportcmd(endp); //选择端点
if((inportb() & D12_FULLEMPTY) == 0) { //如果缓冲区为空,则返回
if(bEPPflags.bits.in_isr == 0)
ENABLE;
return 0;
}
outportcmd(0xF0); //读缓冲区
j = inportb();
j = inportb();
if(j > len)
j = len;
for(i=0; i
outportcmd(0xF2); //缓冲区清空
//-------------------------------
if(bEPPflags.bits.in_isr == 0)
ENABLE;
// Uart_Printf("E D12_ReadEndpoint:%d,%d character read\n",endp,j);
return j;
}
unsigned char D12_SelectEndpoint(unsigned char bEndp)
{
unsigned char c;
if(bEPPflags.bits.in_isr == 0)
DISABLE;
outportcmd(bEndp);
c = inportb();
if(bEPPflags.bits.in_isr == 0)
ENABLE;
// Uart_Printf("E D12_SelectEndpoint\n");
return c;
}
非常好我支持^.^
(0) 0%
不好我反对
(0) 0%