aboutsummaryrefslogtreecommitdiffstats
path: root/os/hal/include
diff options
context:
space:
mode:
authorgdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2012-05-09 17:00:03 +0000
committergdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2012-05-09 17:00:03 +0000
commit7f87eee586adf22f28b1687ef92051065a0a5ee5 (patch)
treea3d199558c7671e31e9ebac4f79f8f4596e2493e /os/hal/include
parent8f8b7f2c69575736da9004c8dc45c770b0f08c48 (diff)
downloadChibiOS-7f87eee586adf22f28b1687ef92051065a0a5ee5.tar.gz
ChibiOS-7f87eee586adf22f28b1687ef92051065a0a5ee5.tar.bz2
ChibiOS-7f87eee586adf22f28b1687ef92051065a0a5ee5.zip
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@4178 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'os/hal/include')
-rw-r--r--os/hal/include/hal.h7
-rw-r--r--os/hal/include/io_block.h8
-rw-r--r--os/hal/include/mmc_spi.h31
-rw-r--r--os/hal/include/mmcsd.h160
-rw-r--r--os/hal/include/sdc.h3
5 files changed, 187 insertions, 22 deletions
diff --git a/os/hal/include/hal.h b/os/hal/include/hal.h
index 4e5bf0b24..d8de4d936 100644
--- a/os/hal/include/hal.h
+++ b/os/hal/include/hal.h
@@ -34,9 +34,14 @@
#include "hal_lld.h"
+/* Abstract interfaces.*/
#include "io_channel.h"
#include "io_block.h"
+/* Shared headers.*/
+#include "mmcsd.h"
+
+/* Layered drivers.*/
#include "tm.h"
#include "pal.h"
#include "adc.h"
@@ -53,6 +58,8 @@
#include "spi.h"
#include "uart.h"
#include "usb.h"
+
+/* Complex drivers.*/
#include "mmc_spi.h"
#include "serial_usb.h"
diff --git a/os/hal/include/io_block.h b/os/hal/include/io_block.h
index b12ae4588..2e47eb10a 100644
--- a/os/hal/include/io_block.h
+++ b/os/hal/include/io_block.h
@@ -192,6 +192,10 @@ typedef struct {
*
* @param[in] ip pointer to a @p BaseBlockDevice or derived class
*
+ * @return The operation status.
+ * @retval FALSE operation succeeded.
+ * @retval TRUE operation failed.
+ *
* @api
*/
#define blkSync(ip) ((ip)->vmt->sync(ip))
@@ -202,6 +206,10 @@ typedef struct {
* @param[in] ip pointer to a @p BaseBlockDevice or derived class
* @param[out] bdip pointer to a @p BlockDeviceInfo structure
*
+ * @return The operation status.
+ * @retval FALSE operation succeeded.
+ * @retval TRUE operation failed.
+ *
* @api
*/
#define blkGetInfo(ip, bdip) ((ip)->vmt->get_info(ip, bdip))
diff --git a/os/hal/include/mmc_spi.h b/os/hal/include/mmc_spi.h
index 1d624aeff..fd2850576 100644
--- a/os/hal/include/mmc_spi.h
+++ b/os/hal/include/mmc_spi.h
@@ -40,20 +40,6 @@
#define MMC_ACMD41_RETRY 100
#define MMC_WAIT_DATA 10000
-#define MMC_CMDGOIDLE 0
-#define MMC_CMDINIT 1
-#define MMC_CMDINTERFACE_CONDITION 8
-#define MMC_CMDREADCSD 9
-#define MMC_CMDSTOP 12
-#define MMC_CMDSETBLOCKLEN 16
-#define MMC_CMDREAD 17
-#define MMC_CMDREADMULTIPLE 18
-#define MMC_CMDWRITE 24
-#define MMC_CMDWRITEMULTIPLE 25
-#define MMC_CMDAPP 55
-#define MMC_CMDREADOCR 58
-#define MMC_ACMDOPCONDITION 41
-
/*===========================================================================*/
/* Driver pre-compile time settings. */
/*===========================================================================*/
@@ -63,13 +49,6 @@
* @{
*/
/**
- * @brief Block size for MMC transfers.
- */
-#if !defined(MMC_SECTOR_SIZE) || defined(__DOXYGEN__)
-#define MMC_SECTOR_SIZE 512
-#endif
-
-/**
* @brief Delays insertions.
* @details If enabled this options inserts delays into the MMC waiting
* routines releasing some extra CPU time for the threads with
@@ -138,10 +117,16 @@ typedef struct {
} MMCConfig;
/**
- * @brief Structure representing a MMC driver.
+ * @extends MMCSDBlockDevice
+ *
+ * @brief Structure representing a MMC/SD over SPI driver.
*/
typedef struct {
/**
+ * @brief Virtual Methods Table.
+ */
+ const struct MMCSDBlockDeviceVMT *vmt;
+ /**
* @brief Driver state.
*/
mmcstate_t state;
@@ -243,6 +228,8 @@ extern "C" {
bool_t mmcStartSequentialWrite(MMCDriver *mmcp, uint32_t startblk);
bool_t mmcSequentialWrite(MMCDriver *mmcp, const uint8_t *buffer);
bool_t mmcStopSequentialWrite(MMCDriver *mmcp);
+ bool_t mmcSync(MMCDriver *mmcp);
+ bool_t mmcGetInfo(MMCDriver *mmcp, BlockDeviceInfo *bdip);
#ifdef __cplusplus
}
#endif
diff --git a/os/hal/include/mmcsd.h b/os/hal/include/mmcsd.h
new file mode 100644
index 000000000..fbea45245
--- /dev/null
+++ b/os/hal/include/mmcsd.h
@@ -0,0 +1,160 @@
+/*
+ ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010,
+ 2011,2012 Giovanni Di Sirio.
+
+ This file is part of ChibiOS/RT.
+
+ ChibiOS/RT is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ ChibiOS/RT is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+/**
+ * @file mmcsd.h
+ * @brief MMC/SD cards header.
+ *
+ * @addtogroup MMCSD
+ * @{
+ */
+
+#ifndef _MMCSD_H_
+#define _MMCSD_H_
+
+#if HAL_USE_MMC_SPI || HAL_USE_SDC || defined(__DOXYGEN__)
+
+/*===========================================================================*/
+/* Driver constants. */
+/*===========================================================================*/
+
+/**
+ * @brief Fixed block size for MMC/SD block devices.
+ */
+#define SDMMC_BLOCK_SIZE 512
+
+/**
+ * @brief Mask of error bits in R1 responses.
+ */
+#define SDMMC_R1_ERROR_MASK 0xFDFFE008
+
+/**
+ * @brief Fixed pattern for CMD8.
+ */
+#define SDMMC_CMD8_PATTERN 0x000001AA
+
+/**
+ * @name SD/MMC status conditions
+ * @{
+ */
+#define SDMMC_STS_IDLE 0
+#define SDMMC_STS_READY 1
+#define SDMMC_STS_IDENT 2
+#define SDMMC_STS_STBY 3
+#define SDMMC_STS_TRAN 4
+#define SDMMC_STS_DATA 5
+#define SDMMC_STS_RCV 6
+#define SDMMC_STS_PRG 7
+#define SDMMC_STS_DIS 8
+/** @} */
+
+/**
+ * @name SD/MMC commands
+ * @{
+ */
+#define SDMMC_CMD_GO_IDLE_STATE 0
+#define SDMMC_CMD_INIT 1
+#define SDMMC_CMD_ALL_SEND_CID 2
+#define SDMMC_CMD_SEND_RELATIVE_ADDR 3
+#define SDMMC_CMD_SET_BUS_WIDTH 6
+#define SDMMC_CMD_SEL_DESEL_CARD 7
+#define SDMMC_CMD_SEND_IF_COND 8
+#define SDMMC_CMD_SEND_CSD 9
+#define SDMMC_CMD_STOP_TRANSMISSION 12
+#define SDMMC_CMD_SEND_STATUS 13
+#define SDMMC_CMD_SET_BLOCKLEN 16
+#define SDMMC_CMD_READ_SINGLE_BLOCK 17
+#define SDMMC_CMD_READ_MULTIPLE_BLOCK 18
+#define SDMMC_CMD_SET_BLOCK_COUNT 23
+#define SDMMC_CMD_WRITE_BLOCK 24
+#define SDMMC_CMD_WRITE_MULTIPLE_BLOCK 25
+#define SDMMC_CMD_APP_OP_COND 41
+#define SDMMC_CMD_LOCK_UNLOCK 42
+#define SDMMC_CMD_APP_CMD 55
+#define SDMMC_CMD_READ_OCR 58
+/** @} */
+
+/*===========================================================================*/
+/* Driver pre-compile time settings. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Derived constants and error checks. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Driver data structures and types. */
+/*===========================================================================*/
+
+/**
+ * @brief @p MMCSDBlockDevice specific methods.
+ */
+#define _mmcsd_block_device_methods \
+ _base_block_device_methods
+
+/**
+ * @brief @p MMCSDBlockDevice specific data.
+ * @note It is empty because @p MMCSDBlockDevice is only an interface
+ * without implementation.
+ */
+#define _mmcsd_block_device_data \
+ _base_block_device_data
+
+/**
+ * @extends BaseBlockDeviceVMT
+ *
+ * @brief @p MMCSDBlockDevice virtual methods table.
+ */
+struct MMCSDBlockDeviceVMT {
+ _base_block_device_methods
+};
+
+/**
+ * @extends BaseBlockDevice
+ *
+ * @brief MCC/SD block device class.
+ * @details This class represents a, block-accessible, MMC/SD device.
+ */
+typedef struct {
+ /** @brief Virtual Methods Table.*/
+ const struct MMCSDBlockDeviceVMT *vmt;
+ _mmcsd_block_device_data
+} MMCSDBlockDevice;
+
+/*===========================================================================*/
+/* Driver macros. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* External declarations. */
+/*===========================================================================*/
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* HAL_USE_MMC_SPI || HAL_USE_MMC_SDC*/
+
+#endif /* _MMCSD_H_ */
+
+/** @} */
diff --git a/os/hal/include/sdc.h b/os/hal/include/sdc.h
index 82b083125..20c15c211 100644
--- a/os/hal/include/sdc.h
+++ b/os/hal/include/sdc.h
@@ -102,6 +102,7 @@
#define SDC_STARTBIT_ERROR 64 /**< @brief Start bit not detected.*/
#define SDC_OVERFLOW_ERROR 128 /**< @brief Card overflow error. */
#define SDC_UNHANDLED_ERROR 0xFFFFFFFF
+/** @} */
/*===========================================================================*/
/* Driver pre-compile time settings. */
@@ -332,6 +333,8 @@ extern "C" {
bool_t sdcWrite(SDCDriver *sdcp, uint32_t startblk,
const uint8_t *buffer, uint32_t n);
sdcflags_t sdcGetAndClearErrors(SDCDriver *sdcp);
+ bool_t sdcSync(SDCDriver *sdcp);
+ bool_t sdcGetInfo(SDCDriver *sdcp, BlockDeviceInfo *bdip);
bool_t _sdc_wait_for_transfer_state(SDCDriver *sdcp);
#ifdef __cplusplus
}