Пример #1
0
static int spi_bwrite(struct ext4_blockdev *bdev, const void *buf,
		      uint64_t blk_id, uint32_t blk_cnt)
{
	(void)bdev;
	uint64_t v = tim_get_us();

	if (mmcStartSequentialWrite(&MMCD1, blk_id) != HAL_SUCCESS)
		return EIO;

	while (blk_cnt) {
		if (mmcSequentialWrite(&MMCD1, buf) != HAL_SUCCESS)
			return EIO;

		buf += SPI_BLOCK_SIZE;
		blk_cnt--;
	}

	if (mmcStopSequentialWrite(&MMCD1) != HAL_SUCCESS)
		return EIO;

	io_timings.acc_bwrite += tim_get_us() - v;
	io_timings.cnt_bwrite++;
	io_timings.av_bwrite = io_timings.acc_bwrite / io_timings.cnt_bwrite;

	return EOK;
}
Пример #2
0
static bool_t mmc_write(void *instance, uint32_t startblk,
                 const uint8_t *buffer, uint32_t n) {

  if (mmcStartSequentialWrite((MMCDriver *)instance, startblk))
      return CH_FAILED;
  while (n > 0) {
      if (mmcSequentialWrite((MMCDriver *)instance, buffer))
          return CH_FAILED;
      buffer += MMCSD_BLOCK_SIZE;
      n--;
  }
  if (mmcStopSequentialWrite((MMCDriver *)instance))
      return CH_FAILED;
  return CH_SUCCESS;
}
Пример #3
0
bool_t mmc_write(void *instance, uint32_t startblk,
                 const uint8_t *buffer, uint32_t n) {

  if (mmcStartSequentialWrite((MMCDriver *)instance, startblk))
      return TRUE;
  while (n > 0) {
      if (mmcSequentialWrite((MMCDriver *)instance, buffer))
          return TRUE;
      buffer += MMCSD_BLOCK_SIZE;
      n--;
  }
  if (mmcStopSequentialWrite((MMCDriver *)instance))
      return TRUE;
  return FALSE;
}
Пример #4
0
DRESULT disk_write (
  BYTE pdrv,      /* Physical drive nmuber to identify the drive */
  const BYTE *buff, /* Data to be written */
  DWORD sector,   /* Sector address in LBA */
  UINT count      /* Number of sectors to write */
)
{
  switch (pdrv) {
#if HAL_USE_MMC_SPI
  case MMC:
    if (blkGetDriverState(&MMCD1) != BLK_READY)
        return RES_NOTRDY;
    if (mmcIsWriteProtected(&MMCD1))
        return RES_WRPRT;
    if (mmcStartSequentialWrite(&MMCD1, sector))
        return RES_ERROR;
    while (count > 0) {
        if (mmcSequentialWrite(&MMCD1, buff))
            return RES_ERROR;
        buff += MMCSD_BLOCK_SIZE;
        count--;
    }
    if (mmcStopSequentialWrite(&MMCD1))
        return RES_ERROR;
    return RES_OK;
#else
  case SDC:
    if (blkGetDriverState(&SDCD1) != BLK_READY)
      return RES_NOTRDY;
    if (sdcWrite(&SDCD1, sector, buff, count))
      return RES_ERROR;
    return RES_OK;
#endif
  }
  return RES_PARERR;
}
Пример #5
0
DRESULT disk_write (
    BYTE drv,            /* Physical drive nmuber (0..) */
    const BYTE *buff,    /* Data to be written */
    DWORD sector,        /* Sector address (LBA) */
    BYTE count            /* Number of sectors to write (1..255) */
)
{
  switch (drv) {
#if HAL_USE_MMC_SPI
  case MMC:
    if (mmcGetDriverState(&MMCD1) != MMC_READY)
        return RES_NOTRDY;
    if (mmcIsWriteProtected(&MMCD1))
        return RES_WRPRT;
    if (mmcStartSequentialWrite(&MMCD1, sector))
        return RES_ERROR;
    while (count > 0) {
        if (mmcSequentialWrite(&MMCD1, buff))
            return RES_ERROR;
        buff += MMC_SECTOR_SIZE;
        count--;
    }
    if (mmcStopSequentialWrite(&MMCD1))
        return RES_ERROR;
    return RES_OK;
#else
  case SDC:
    if (sdcGetDriverState(&SDCD1) != SDC_ACTIVE)
      return RES_NOTRDY;
    if (sdcWrite(&SDCD1, sector, buff, count))
      return RES_ERROR;
    return RES_OK;
#endif
  }
  return RES_PARERR;
}