ChibiOS/RT Architecture - Reference Manual - Guides |
00001 /* 00002 ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010 Giovanni Di Sirio. 00003 00004 This file is part of ChibiOS/RT. 00005 00006 ChibiOS/RT is free software; you can redistribute it and/or modify 00007 it under the terms of the GNU General Public License as published by 00008 the Free Software Foundation; either version 3 of the License, or 00009 (at your option) any later version. 00010 00011 ChibiOS/RT is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 GNU General Public License for more details. 00015 00016 You should have received a copy of the GNU General Public License 00017 along with this program. If not, see <http://www.gnu.org/licenses/>. 00018 00019 --- 00020 00021 A special exception to the GPL can be applied should you wish to distribute 00022 a combined work that includes ChibiOS/RT, without being obliged to provide 00023 the source code for any proprietary components. See the file exception.txt 00024 for full details of how and when the exception can be applied. 00025 */ 00026 00027 /** 00028 * @file mmc_spi.h 00029 * @brief MMC over SPI driver header. 00030 * 00031 * @addtogroup MMC_SPI 00032 * @{ 00033 */ 00034 00035 #ifndef _MMC_SPI_H_ 00036 #define _MMC_SPI_H_ 00037 00038 #if CH_HAL_USE_MMC_SPI || defined(__DOXYGEN__) 00039 00040 /*===========================================================================*/ 00041 /* Driver constants. */ 00042 /*===========================================================================*/ 00043 00044 #define MMC_CMD0_RETRY 10 00045 #define MMC_CMD1_RETRY 100 00046 #define MMC_WAIT_DATA 10000 00047 00048 #define MMC_CMDGOIDLE 0 00049 #define MMC_CMDINIT 1 00050 #define MMC_CMDREADCSD 9 00051 #define MMC_CMDSTOP 12 00052 #define MMC_CMDSETBLOCKLEN 16 00053 #define MMC_CMDREAD 17 00054 #define MMC_CMDREADMULTIPLE 18 00055 #define MMC_CMDWRITE 24 00056 #define MMC_CMDWRITEMULTIPLE 25 00057 00058 /*===========================================================================*/ 00059 /* Driver pre-compile time settings. */ 00060 /*===========================================================================*/ 00061 00062 /** 00063 * @brief Block size for MMC transfers. 00064 */ 00065 #if !defined(MMC_SECTOR_SIZE) || defined(__DOXYGEN__) 00066 #define MMC_SECTOR_SIZE 512 00067 #endif 00068 00069 /** 00070 * @brief Delays insertions. 00071 * @details If enabled this options inserts delays into the MMC waiting 00072 * routines releasing some extra CPU time for the threads with 00073 * lower priority, this may slow down the driver a bit however. 00074 * This option is recommended also if the SPI driver does not 00075 * use a DMA channel and heavily loads the CPU. 00076 */ 00077 #if !defined(MMC_NICE_WAITING) || defined(__DOXYGEN__) 00078 #define MMC_NICE_WAITING TRUE 00079 #endif 00080 00081 /** 00082 * @brief Number of positive insertion queries before generating the 00083 * insertion event. 00084 */ 00085 #if !defined(MMC_POLLING_INTERVAL) || defined(__DOXYGEN__) 00086 #define MMC_POLLING_INTERVAL 10 00087 #endif 00088 00089 /** 00090 * @brief Interval, in milliseconds, between insertion queries. 00091 */ 00092 #if !defined(MMC_POLLING_DELAY) || defined(__DOXYGEN__) 00093 #define MMC_POLLING_DELAY 10 00094 #endif 00095 00096 /*===========================================================================*/ 00097 /* Derived constants and error checks. */ 00098 /*===========================================================================*/ 00099 00100 #if !CH_HAL_USE_SPI || !CH_USE_EVENTS 00101 #error "MMC_SPI driver requires CH_HAL_USE_SPI and CH_USE_EVENTS" 00102 #endif 00103 00104 /*===========================================================================*/ 00105 /* Driver data structures and types. */ 00106 /*===========================================================================*/ 00107 00108 /** 00109 * @brief Driver state machine possible states. 00110 */ 00111 typedef enum { 00112 MMC_UNINIT = 0, /**< @brief Not initialized. */ 00113 MMC_STOP = 1, /**< @brief Stopped. */ 00114 MMC_WAIT = 2, /**< @brief Waiting card. */ 00115 MMC_INSERTED = 3, /**< @brief Card inserted. */ 00116 MMC_READY = 4, /**< @brief Card ready. */ 00117 MMC_READING = 5, /**< @brief Reading. */ 00118 MMC_WRITING = 6 /**< @brief Writing. */ 00119 } mmcstate_t; 00120 00121 /** 00122 * @brief Function used to query some hardware status bits. 00123 * 00124 * @return The status. 00125 */ 00126 typedef bool_t (*mmcquery_t)(void); 00127 00128 /** 00129 * @brief Driver configuration structure. 00130 */ 00131 typedef struct { 00132 00133 } MMCConfig; 00134 00135 /** 00136 * @brief Structure representing a MMC driver. 00137 */ 00138 typedef struct { 00139 /** 00140 * @brief Driver state. 00141 */ 00142 mmcstate_t mmc_state; 00143 /** 00144 * @brief Current configuration data. 00145 */ 00146 const MMCConfig *mmc_config; 00147 /** 00148 * @brief SPI driver associated to this MMC driver. 00149 */ 00150 SPIDriver *mmc_spip; 00151 /** 00152 * @brief SPI low speed configuration used during initialization. 00153 */ 00154 const SPIConfig *mmc_lscfg; 00155 /** 00156 * @brief SPI high speed configuration used during transfers. 00157 */ 00158 const SPIConfig *mmc_hscfg; 00159 /** 00160 * @brief Write protect status query function. 00161 */ 00162 mmcquery_t mmc_is_protected; 00163 /** 00164 * @brief Insertion status query function. 00165 */ 00166 mmcquery_t mmc_is_inserted; 00167 /** 00168 * @brief Card insertion event source. 00169 */ 00170 EventSource mmc_inserted_event; 00171 /** 00172 * @brief Card removal event source. 00173 */ 00174 EventSource mmc_removed_event; 00175 /** 00176 * @brief MMC insertion polling timer. 00177 */ 00178 VirtualTimer mmc_vt; 00179 /** 00180 * @brief Insertion counter. 00181 */ 00182 uint_fast8_t mmc_cnt; 00183 } MMCDriver; 00184 00185 /*===========================================================================*/ 00186 /* Driver macros. */ 00187 /*===========================================================================*/ 00188 00189 /** 00190 * @brief Returns the driver state. 00191 */ 00192 #define mmcGetDriverState(mmcp) ((mmcp)->mmc_state) 00193 00194 /** 00195 * @brief Returns the write protect status. 00196 */ 00197 #define mmcIsWriteProtected(mmcp) ((mmcp)->mmc_is_protected()) 00198 00199 /*===========================================================================*/ 00200 /* External declarations. */ 00201 /*===========================================================================*/ 00202 00203 #ifdef __cplusplus 00204 extern "C" { 00205 #endif 00206 void mmcInit(void); 00207 void mmcObjectInit(MMCDriver *mmcp, SPIDriver *spip, 00208 const SPIConfig *lscfg, const SPIConfig *hscfg, 00209 mmcquery_t is_protected, mmcquery_t is_inserted); 00210 void mmcStart(MMCDriver *mmcp, const MMCConfig *config); 00211 void mmcStop(MMCDriver *mmcp); 00212 bool_t mmcConnect(MMCDriver *mmcp); 00213 bool_t mmcDisconnect(MMCDriver *mmcp); 00214 bool_t mmcStartSequentialRead(MMCDriver *mmcp, uint32_t startblk); 00215 bool_t mmcSequentialRead(MMCDriver *mmcp, uint8_t *buffer); 00216 bool_t mmcStopSequentialRead(MMCDriver *mmcp); 00217 bool_t mmcStartSequentialWrite(MMCDriver *mmcp, uint32_t startblk); 00218 bool_t mmcSequentialWrite(MMCDriver *mmcp, const uint8_t *buffer); 00219 bool_t mmcStopSequentialWrite(MMCDriver *mmcp); 00220 #ifdef __cplusplus 00221 } 00222 #endif 00223 00224 #endif /* CH_HAL_USE_MMC_SPI */ 00225 00226 #endif /* _MMC_SPI_H_ */ 00227 00228 /** @} */