单片机
返回首页

fatfs文件系统移植到STM32F10x

2015-10-08 来源:eefocus

//文件系统与SD卡驱动接口文件diskio.c


#include 'diskio.h'
#include 'ffconf.h'
#include
#include 'MMC_SD.h'

 

DSTATUS disk_initialize (
 BYTE drv    
)
{
 int Status;
 switch (drv)
 {
  case 0 :
//    Status = MSD0_Init();
  
   Status = SD_Init();
  
   if(Status==0){
    return RES_OK;
   }else{
    return STA_NOINIT;
   }
  case 1 :
   return RES_OK;  
  case 2 :
   return RES_OK;  
  case 3 :
   return RES_OK;
  default:
   return STA_NOINIT;
 }
}

 


DSTATUS disk_status (
 BYTE drv  
)
{
 switch (drv)
 {
  case 0 :
   return RES_OK;
  case 1 :
   return RES_OK;
  case 2 :
   return RES_OK;
  default:
   return STA_NOINIT;
 }
}

 

 

DRESULT disk_read (
 BYTE drv,  
 BYTE *buff,  
 DWORD sector, 
 BYTE count  
)
{
 int Status;
 if( !count )
   
  return RES_PARERR; 
 }
 switch (drv)
 {
  case 0:
      if(count==1)                 
      {  
    Status =  SD_ReadSingleBlock( sector ,buff );
    if(Status == 0){
     return RES_OK;
    }else{
     return RES_ERROR;
      
      }                                               
      else                        
      { 
    Status = SD_ReadMultiBlock( sector , buff ,count);
    if(Status == 0){
     return RES_OK;
    }else{
     return RES_ERROR;
    }
      }                                               
  case 1:
      if(count==1)                 
      {  
    return RES_OK;   
      }                                               
      else                        
      { 
    return RES_OK;
      }

  default:
   return RES_ERROR;
 }
}

 

 

#if _READONLY == 0
DRESULT disk_write (
 BYTE drv,   
 const BYTE *buff,        
 DWORD sector,  
 BYTE count   
)
{
 int Status;
 if( !count )
   
  return RES_PARERR; 
 }
 switch (drv)
 {
  case 0:
      if(count==1)                 
      {  
    Status = SD_WriteSingleBlock( sector , (uint8_t *)(&buff[0]) );
    if(Status == 0){
     return RES_OK;
    }else{
     return RES_ERROR;
    }
      }                                               
      else                       
      { 
    Status = SD_WriteMultiBlock( sector , (uint8_t *)(&buff[0]) , count );
    if(Status == 0){
     return RES_OK;
    }else{
     return RES_ERROR;
     
      }                                               
  case 1:
      if(count==1)                 
      { 
    return RES_OK;
      }                                               
      else                       
      { 
    return RES_OK;
      }                                               
 
  default:return RES_ERROR;
 }
}
#endif

 

 

DRESULT disk_ioctl (
 BYTE drv,  
 BYTE ctrl,  
 void *buff  
)
{
 if (drv==0)
   
  switch (ctrl)
  {
   case CTRL_SYNC :
    return RES_OK;
     case GET_SECTOR_COUNT :
    *(DWORD*)buff = 4096;
       return RES_OK;
     case GET_SECTOR_SIZE :
    *(WORD*)buff = 512;
       return RES_OK;
     case GET_BLOCK_SIZE :
    *(WORD*)buff = 512;
       return RES_OK; 
     case CTRL_POWER :
    break;
     case CTRL_LOCK :
    break;
     case CTRL_EJECT :
    break;
        
     case MMC_GET_TYPE :
    break;
     case MMC_GET_CSD :
    break;
     case MMC_GET_CID :
    break;
   case MMC_GET_OCR :
    break;
   case MMC_GET_SDSTAT :
    break; 
  }
    }
 else{     
  return RES_PARERR; 
 }
 return RES_PARERR;
}

       
                                                                                                                                                                                                                                               
DWORD get_fattime (void)
{
  
    return 0;
}

进入单片机查看更多内容>>
相关视频
  • RISC-V嵌入式系统开发

  • SOC系统级芯片设计实验

  • 云龙51单片机实训视频教程(王云,字幕版)

  • 2022 Digi-Key KOL 系列: 你见过1GHz主频的单片机吗?Teensy 4.1开发板介绍

  • TI 新一代 C2000™ 微控制器:全方位助力伺服及马达驱动应用

  • MSP430电容触摸技术 - 防水Demo演示

精选电路图
  • 光控音效发生器电路

  • 基于IC555的可变PWM振荡器电路

  • 如何使用LED驱动器LM3915制作振动计

  • 一个简单的立体声平衡指示器电路

  • 电谐波图形均衡器示意图

  • 一种构建12V和230V双直流电源的简单方法

    相关电子头条文章