/*
 * LPLD_Disk_Read
 * 读磁盘的一个或多个扇区
 * 
 * 参数:
 *    drv--物理磁盘号,只能为0
 *    buff--数据读出所存的地址指针
 *    sector--扇区起始号
 *    count--所读的扇区数
 *
 * 输出:
 *    RES_OK--成功
 *    RES_ERROR--读/写错误
 *    RES_WRPRT--写保护
 *    RES_NOTRDY--未准备好
 *    RES_PARERR--参数错误
 *    RES_NONRSPNS--未响应 
 */
DRESULT LPLD_Disk_Read(uint8 drv, uint8* buff, uint32 sector, uint8 count)
{
  if(drv || (count == 0))
    return RES_PARERR;

  return LPLD_SDHC_ReadBlocks(buff, sector, count);
}
Пример #2
0
void main (void)
{
  uint32 i;	
  //读写数据数组
  uint8  sdhc_dat_buffer1[BUFFER_SIZE];    
  //SD卡操作返回值
  SDHCRES sd_state;    
  
  //关中断
  DisableInterrupts;                                      
  
  //SDHC初始化
  sd_state = (SDHCRES)LPLD_SDHC_InitCard();  
  
  //开中断
  EnableInterrupts;			                            
  
  //判断SD卡操作状态
  if (SDHCRES_OK == sd_state)
  {
    printf("\r\nSD init success.\r\n");
    //读(多)扇区操作,并返回SD操作状态
    sd_state = LPLD_SDHC_ReadBlocks(sdhc_dat_buffer1, 0, BLOCK_LEN);
  }
  else
  {
    printf("\r\nSD init failure.\r\n");
  }
  
  //判断SD卡操作状态
  if (SDHCRES_OK == sd_state)
  {
    printf("Read disk success.\r\n");
    printf("SD data: \r\n");
    //若读成功,打印该扇区内容
    for(i = 0;i < BUFFER_SIZE;i++) 
    {
      printf("%02X ", sdhc_dat_buffer1[i]);
    }  
    printf("\r\n");
  }
  else
  {
    printf("Read disk failed.\n\r");
  }
  
  
  //判断SD卡操作状态
  if (SDHCRES_OK == sd_state)
  {
    printf("Update data success.\r\n");
    //更新数据数组,自加1
    for (i = 0; i < BUFFER_SIZE; i++)
    {
      sdhc_dat_buffer1[i] ++;
    }
    //写(多)扇区操作,并返回SD操作状态
    sd_state = LPLD_SDHC_WriteBlocks(sdhc_dat_buffer1, 0, BLOCK_LEN);  
  }
  
  //判断SD卡操作状态
  if (SDHCRES_OK == sd_state)
  {
    printf("Write Disk success.\r\n");
    //再次读(多)扇区操作,并返回SD操作状态
    sd_state = LPLD_SDHC_ReadBlocks(sdhc_dat_buffer1, 0, BLOCK_LEN);
  }
  else
  {
    printf("Write Disk failure.\r\n");
  }
  
  //判断SD卡操作状态
  if (SDHCRES_OK == sd_state)
  {
    printf("Read disk success.\r\n");
    printf("SD data: \r\n");
    //若读成功,打印该扇区内容
    for(i = 0;i < BUFFER_SIZE;i++) 
    {
      printf("%02X ", sdhc_dat_buffer1[i]);
    }
    printf("\r\n");
  }
  else
  {
    printf("Read disk failure.\r\n");
  }
  
  while(1)
  {
    
  } 
}