From 9bc4122e0e4b5e91d97ea19083dc944c1d2dc0d0 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Tue, 10 Nov 2009 22:30:11 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1282 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/io/mmc_spi.c | 92 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) (limited to 'os') diff --git a/os/io/mmc_spi.c b/os/io/mmc_spi.c index 42100bb61..4e9d6e3f5 100644 --- a/os/io/mmc_spi.c +++ b/os/io/mmc_spi.c @@ -395,4 +395,96 @@ bool_t mmcStopSequentialRead(MMCDriver *mmcp) { return result; } +/** + * @brief Starts a sequential write. + * + * @param[in] mmcp pointer to the @p MMCDriver object + * @param[in] startblk first block to write + * + * @return The operation status. + * @retval FALSE the operation was successful. + * @retval TRUE the operation failed. + */ +bool_t mmcStartSequentialWrite(MMCDriver *mmcp, uint32_t startblk) { + + chDbgCheck(mmcp != NULL, "mmcStartSequentialWrite"); + + chSysLock(); + if (mmcp->mmc_state != MMC_READY) { + chSysUnlock(); + return TRUE; + } + mmcp->mmc_state = MMC_WRITING; + chSysUnlock(); + + spiSelect(mmcp->mmc_spip); + send_hdr(mmcp, MMC_CMDWRITEMULTIPLE, startblk << 9); + if (recvr1(mmcp) != 0x00) { + spiUnselect(mmcp->mmc_spip); + chSysLock(); + if (mmcp->mmc_state == MMC_READING) + mmcp->mmc_state = MMC_READY; + chSysUnlock(); + return TRUE; + } + return FALSE; +} + +/** + * @brief Writes a block within a sequential write operation. + * + * @param[in] mmcp pointer to the @p MMCDriver object + * @param[out] buffer pointer to the write buffer + * + * @return The operation status. + * @retval FALSE the operation was successful. + * @retval TRUE the operation failed. + */ +bool_t mmcSequentialWrite(MMCDriver *mmcp, const uint8_t *buffer) { + + chDbgCheck((mmcp != NULL) && (buffer != NULL), "mmcSequentialRead"); + + chSysLock(); + if (mmcp->mmc_state != MMC_WRITING) { + chSysUnlock(); + return TRUE; + } + chSysUnlock(); + + /**/ + + return TRUE; +} + +/** + * @brief Stops a sequential write gracefully. + * + * @param[in] mmcp pointer to the @p MMCDriver object + * + * @return The operation status. + * @retval FALSE the operation was successful. + * @retval TRUE the operation failed. + */ +bool_t mmcStopSequentialWrite(MMCDriver *mmcp) { + static const uint8_t stop[] = {0xFD, 0xFF}; + + chDbgCheck(mmcp != NULL, "mmcStopSequentialWrite"); + + chSysLock(); + if (mmcp->mmc_state != MMC_WRITING) { + chSysUnlock(); + return TRUE; + } + chSysUnlock(); + + spiSend(mmcp->mmc_spip, sizeof(stop), stop); + spiUnselect(mmcp->mmc_spip); + + chSysLock(); + if (mmcp->mmc_state == MMC_WRITING) + mmcp->mmc_state = MMC_READY; + chSysUnlock(); + return TRUE; +} + /** @} */ -- cgit v1.2.3