DRESULT disk_read ( BYTE pdrv, /* Physical drive nmuber to identify the drive */ BYTE *buff, /* Data buffer to store read data */ DWORD sector, /* Sector address in LBA */ UINT count /* Number of sectors to read */ ) { switch (pdrv) { #if HAL_USE_MMC_SPI case MMC: if (blkGetDriverState(&MMCD1) != BLK_READY) return RES_NOTRDY; if (mmcStartSequentialRead(&MMCD1, sector)) return RES_ERROR; while (count > 0) { if (mmcSequentialRead(&MMCD1, buff)) return RES_ERROR; buff += MMCSD_BLOCK_SIZE; count--; } if (mmcStopSequentialRead(&MMCD1)) return RES_ERROR; return RES_OK; #else case SDC: if (blkGetDriverState(&SDCD1) != BLK_READY) return RES_NOTRDY; if (sdcRead(&SDCD1, sector, buff, count)) return RES_ERROR; return RES_OK; #endif } return RES_PARERR; }
DRESULT disk_readp ( BYTE* buff, /* [OUT] Pointer to the read buffer */ DWORD sector, /* [IN] Sector number */ UINT offset, /* [IN] Byte offset in the sector to start to read */ UINT count /* [IN] Number of bytes to read */ ) { if (sector != sectpos) { #if HAL_USE_MMC_SPI if (blkGetDriverState(&MMCD1) != BLK_READY) return RES_NOTRDY; if (mmcStartSequentialRead(&MMCD1, sector)) return RES_ERROR; if (mmcSequentialRead(&MMCD1, sectBuf)) return RES_ERROR; if (mmcStopSequentialRead(&MMCD1)) return RES_ERROR; #else if (blkGetDriverState(&SDCD1) != BLK_READY) return RES_NOTRDY; if (sdcRead(&SDCD1, sector, sectBuf, 1)) return RES_ERROR; #endif sectpos = sector; } memcpy(buff, sectBuf + offset, count); return RES_OK; }
DRESULT disk_read ( BYTE drv, /* Physical drive nmuber (0..) */ BYTE *buff, /* Data buffer to store read data */ DWORD sector, /* Sector address (LBA) */ BYTE count /* Number of sectors to read (1..255) */ ) { switch (drv) { #if HAL_USE_MMC_SPI case MMC: if (mmcGetDriverState(&MMCD1) != MMC_READY) return RES_NOTRDY; if (mmcStartSequentialRead(&MMCD1, sector)) return RES_ERROR; while (count > 0) { if (mmcSequentialRead(&MMCD1, buff)) return RES_ERROR; buff += MMC_SECTOR_SIZE; count--; } if (mmcStopSequentialRead(&MMCD1)) return RES_ERROR; return RES_OK; #else case SDC: if (sdcGetDriverState(&SDCD1) != SDC_ACTIVE) return RES_NOTRDY; if (sdcRead(&SDCD1, sector, buff, count)) return RES_ERROR; return RES_OK; #endif } return RES_PARERR; }
static int spi_bread(struct ext4_blockdev *bdev, void *buf, uint64_t blk_id, uint32_t blk_cnt) { (void)bdev; uint64_t v = tim_get_us(); if (mmcStartSequentialRead(&MMCD1, blk_id) != HAL_SUCCESS) return EIO; while (blk_cnt) { if (mmcSequentialRead(&MMCD1, buf) != HAL_SUCCESS) return EIO; buf += SPI_BLOCK_SIZE; blk_cnt--; } if (mmcStopSequentialRead(&MMCD1) != HAL_SUCCESS) return EIO; io_timings.acc_bread += tim_get_us() - v; io_timings.cnt_bread++; io_timings.av_bread = io_timings.acc_bread / io_timings.cnt_bread; return EOK; }
static int spi_open(struct ext4_blockdev *bdev) { (void)bdev; static uint8_t mbr[512]; struct part_tab_entry *part0; if (mmcConnect(&MMCD1) != HAL_SUCCESS) return EIO; if (mmcStartSequentialRead(&MMCD1, 0) != HAL_SUCCESS) return EIO; if (mmcSequentialRead(&MMCD1, mbr) != HAL_SUCCESS) return EIO; if (mmcStopSequentialRead(&MMCD1) != HAL_SUCCESS) return EIO; part0 = (struct part_tab_entry *)(mbr + MBR_PART_TABLE_OFF); part_offset = part0->first_lba; _spi.ph_bcnt = MMCD1.capacity * SPI_BLOCK_SIZE; return EOK; }
static bool_t mmc_read(void *instance, uint32_t startblk, uint8_t *buffer, uint32_t n) { if (mmcStartSequentialRead((MMCDriver *)instance, startblk)) return CH_FAILED; while (n > 0) { if (mmcSequentialRead((MMCDriver *)instance, buffer)) return CH_FAILED; buffer += MMCSD_BLOCK_SIZE; n--; } if (mmcStopSequentialRead((MMCDriver *)instance)) return CH_FAILED; return CH_SUCCESS; }
bool_t mmc_read(void *instance, uint32_t startblk, uint8_t *buffer, uint32_t n) { if (mmcStartSequentialRead((MMCDriver *)instance, startblk)) return TRUE; while (n > 0) { if (mmcSequentialRead((MMCDriver *)instance, buffer)) return TRUE; buffer += MMCSD_BLOCK_SIZE; n--; } if (mmcStopSequentialRead((MMCDriver *)instance)) return TRUE; return FALSE; }