Exemplo n.º 1
0
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;
}
Exemplo n.º 2
0
DSTATUS disk_initialize (
  BYTE pdrv       /* Physical drive nmuber to identify the drive */
)
{
  DSTATUS stat;

  switch (pdrv) {
#if HAL_USE_MMC_SPI
  case MMC:
    stat = 0;
    /* It is initialized externally, just reads the status.*/
    if (blkGetDriverState(&MMCD1) != BLK_READY)
      stat |= STA_NOINIT;
    if (mmcIsWriteProtected(&MMCD1))
      stat |= STA_PROTECT;
    return stat;
#else
  case SDC:
    stat = 0;
    /* It is initialized externally, just reads the status.*/
    if (blkGetDriverState(&SDCD1) != BLK_READY)
      stat |= STA_NOINIT;
    if (sdcIsWriteProtected(&SDCD1))
      stat |= STA_PROTECT;
    return stat;
#endif
  }
  return STA_NOINIT;
}
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;
}
DSTATUS disk_initialize (void) {
#if HAL_USE_MMC_SPI
    /* It is initialized externally, just reads the status.*/
    if (blkGetDriverState(&MMCD1) != BLK_READY)
    	return STA_NOINIT;
#else
    /* It is initialized externally, just reads the status.*/
    if (blkGetDriverState(&SDCD1) != BLK_READY)
    	return STA_NOINIT;
#endif
    // All good
	return 0;
}
Exemplo n.º 5
0
/**
 * @brief   Insertion monitor timer callback function.
 *
 * @param[in] p         pointer to the @p BaseBlockDevice object
 *
 * @notapi
 */
static void tmrfunc(void *p) {
  BaseBlockDevice *bbdp = p;

  /* The presence check is performed only while the driver is not in a
     transfer state because it is often performed by changing the mode of
     the pin connected to the CS/D3 contact of the card, this could disturb
     the transfer.*/
  blkstate_t state = blkGetDriverState(bbdp);
  chSysLockFromIsr();
  if ((state != BLK_READING) && (state != BLK_WRITING)) {
    /* Safe to perform the check.*/
    if (cnt > 0) {
      if (blkIsInserted(bbdp)) {
        if (--cnt == 0) {
          chEvtBroadcastI(&inserted_event);
        }
      }
      else
        cnt = POLLING_INTERVAL;
    }
    else {
      if (!blkIsInserted(bbdp)) {
        cnt = POLLING_INTERVAL;
        chEvtBroadcastI(&removed_event);
      }
    }
  }
  chVTSetI(&tmr, MS2ST(POLLING_DELAY), tmrfunc, bbdp);
  chSysUnlockFromIsr();
}
Exemplo n.º 6
0
msg_t flash_connect(void)
{
	if (blkGetDriverState(&FLASHD1) != BLK_ACTIVE) {
		if (blkConnect(&FLASHD1) != HAL_SUCCESS) {
			alert_component(ALS_FLASH, AL_FAIL);
			debug_printf(DP_FAIL, "FLASH connection failed");
			return MSG_RESET;
		}

		sst25InitPartitionTable(&FLASHD1, init_parts);
	}

	alert_component(ALS_FLASH, AL_NORMAL);
	return MSG_OK;
}
Exemplo n.º 7
0
//-----------------------------------------------------------------------------
// just checks up on the current status, and if there's no card, makes sure
// on_remove() is called
static uint8_t
sd_card_status(void)
{
	uint8_t ret = KB_OK;
	blkstate_t state = blkGetDriverState(&SDCD1);
	if ((state != BLK_READING) && (state != BLK_WRITING))
	{
		if (!sdc_lld_is_card_inserted(&SDCD1))
		{
			on_remove();
			logger_state = LS_WAIT_FOR_SD;
		}
	}
	return ret;
}