ChibiOS/HAL 9.0.0
hal_mmc_spi.h
Go to the documentation of this file.
1/*
2 ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15*/
16
17/**
18 * @file hal_mmc_spi.h
19 * @brief MMC over SPI driver header.
20 *
21 * @addtogroup MMC_SPI
22 * @{
23 */
24
25#ifndef HAL_MMC_SPI_H
26#define HAL_MMC_SPI_H
27
28#if (HAL_USE_MMC_SPI == TRUE) || defined(__DOXYGEN__)
29
30/*===========================================================================*/
31/* Driver constants. */
32/*===========================================================================*/
33
34#define MMC_CMD0_RETRY 10U
35#define MMC_CMD1_RETRY 100U
36#define MMC_ACMD41_RETRY 100U
37#define MMC_WAIT_DATA 10000U
38
39/**
40 * @brief Size of the buffer to be supplied to the driver.
41 * @note The buffer is meant to be non-cacheable on platforms with
42 * data cache.
43 */
44#define MMC_BUFFER_SIZE 16U
45
46/*===========================================================================*/
47/* Driver pre-compile time settings. */
48/*===========================================================================*/
49
50/**
51 * @name MMC_SPI configuration options
52 * @{
53 */
54/**
55 * @brief Timeout before assuming a failure while waiting for card idle.
56 * @note Time is in milliseconds.
57 */
58#if !defined(MMC_IDLE_TIMEOUT_MS) || defined(__DOXYGEN__)
59#define MMC_IDLE_TIMEOUT_MS 1000
60#endif
61
62/**
63 * @brief Mutual exclusion on the SPI bus.
64 */
65#if !defined(MMC_USE_MUTUAL_EXCLUSION) || defined(__DOXYGEN__)
66#define MMC_USE_MUTUAL_EXCLUSION TRUE
67#endif
68/** @} */
69
70/*===========================================================================*/
71/* Derived constants and error checks. */
72/*===========================================================================*/
73
74#if (HAL_USE_SPI == FALSE) || (SPI_USE_WAIT == FALSE)
75#error "MMC_SPI driver requires HAL_USE_SPI and SPI_USE_WAIT"
76#endif
77
78#if (MMC_USE_MUTUAL_EXCLUSION == TRUE) && (SPI_USE_MUTUAL_EXCLUSION == FALSE)
79#error "MMC_USE_MUTUAL_EXCLUSION requires SPI_USE_MUTUAL_EXCLUSION"
80#endif
81
82/*===========================================================================*/
83/* Driver data structures and types. */
84/*===========================================================================*/
85
86/**
87 * @brief Type of a MMC/SD over SPI driver configuration structure.
88 */
89typedef struct {
90 /**
91 * @brief SPI driver associated to this MMC driver.
92 */
94 /**
95 * @brief SPI low speed configuration used during initialization.
96 */
98 /**
99 * @brief SPI high speed configuration used during transfers.
100 */
103
104/**
105 * @brief Legacy name for compatibility.
106 * @deprecated
107 */
109
110/**
111 * @brief @p MMCDriver specific methods.
112 */
113#define __mmc_driver_methods \
114 _mmcsd_block_device_methods
115
116/**
117 * @extends MMCSDBlockDeviceVMT
118 *
119 * @brief @p MMCDriver virtual methods table.
120 */
124
125/**
126 * @extends MMCSDBlockDevice
127 *
128 * @brief Structure representing a MMC/SD over SPI driver.
129 */
130typedef struct {
131 /**
132 * @brief Virtual Methods Table.
133 */
134 const struct mmc_spi_driver_vmt *vmt;
136 /**
137 * @brief Current configuration data.
138 */
140 /**
141 * @brief Addresses use blocks instead of bytes.
142 */
144 /**
145 * @brief Pointer to an un-cacheable buffer of size @p MMC_BUFFER_SIZE.
146 */
147 uint8_t *buffer;
149
150/**
151 * @brief Legacy name for compatibility.
152 * @deprecated
153 */
155
156/*===========================================================================*/
157/* Driver macros. */
158/*===========================================================================*/
159
160/**
161 * @name Macro Functions
162 * @{
163 */
164/**
165 * @brief Returns the card insertion status.
166 * @note This macro wraps a low level function named
167 * @p sdc_lld_is_card_inserted(), this function must be
168 * provided by the application because it is not part of the
169 * SDC driver.
170 *
171 * @param[in] mmcp pointer to the @p MMCDriver object
172 * @return The card state.
173 * @retval false card not inserted.
174 * @retval true card inserted.
175 *
176 * @api
177 */
178#define mmcIsCardInserted(mmcp) mmc_lld_is_card_inserted(mmcp)
179
180/**
181 * @brief Returns the write protect status.
182 *
183 * @param[in] mmcp pointer to the @p MMCDriver object
184 * @return The card state.
185 * @retval false card not inserted.
186 * @retval true card inserted.
187 *
188 * @api
189 */
190#define mmcIsWriteProtected(mmcp) mmc_lld_is_write_protected(mmcp)
191/** @} */
192
193/*===========================================================================*/
194/* External declarations. */
195/*===========================================================================*/
196
197#ifdef __cplusplus
198extern "C" {
199#endif
200 void mmcInit(void);
201 void mmcObjectInit(MMCDriver *mmcp, uint8_t *buffer);
202 msg_t mmcStart(MMCDriver *mmcp, const MMCConfig *config);
203 void mmcStop(MMCDriver *mmcp);
204 bool mmcConnect(MMCDriver *mmcp);
205 bool mmcDisconnect(MMCDriver *mmcp);
206 bool mmcStartSequentialRead(MMCDriver *mmcp, uint32_t startblk);
207 bool mmcSequentialRead(MMCDriver *mmcp, uint8_t *buffer);
209 bool mmcStartSequentialWrite(MMCDriver *mmcp, uint32_t startblk);
210 bool mmcSequentialWrite(MMCDriver *mmcp, const uint8_t *buffer);
212 bool mmcSync(MMCDriver *mmcp);
213 bool mmcGetInfo(MMCDriver *mmcp, BlockDeviceInfo *bdip);
214 bool mmcErase(MMCDriver *mmcp, uint32_t startblk, uint32_t endblk);
217#ifdef __cplusplus
218}
219#endif
220
221#endif /* HAL_USE_MMC_SPI == TRUE */
222
223#endif /* HAL_MMC_SPI_H */
224
225/** @} */
bool mmcStartSequentialWrite(MMCDriver *mmcp, uint32_t startblk)
Starts a sequential write.
bool mmcDisconnect(MMCDriver *mmcp)
Brings the driver in a state safe for card removal.
void mmcStop(MMCDriver *mmcp)
Disables the MMC peripheral.
bool mmcGetInfo(MMCDriver *mmcp, BlockDeviceInfo *bdip)
Returns the media info.
void mmcInit(void)
MMC over SPI driver initialization.
bool mmcStartSequentialRead(MMCDriver *mmcp, uint32_t startblk)
Starts a sequential read.
bool mmcSync(MMCDriver *mmcp)
Waits for card idle condition.
bool mmc_lld_is_card_inserted(MMCDriver *mmcp)
bool mmc_lld_is_write_protected(MMCDriver *mmcp)
#define __mmc_driver_methods
MMCDriver specific methods.
bool mmcSequentialRead(MMCDriver *mmcp, uint8_t *buffer)
Reads a block within a sequential read operation.
bool mmcSequentialWrite(MMCDriver *mmcp, const uint8_t *buffer)
Writes a block within a sequential write operation.
msg_t mmcStart(MMCDriver *mmcp, const MMCConfig *config)
Configures and activates the MMC peripheral.
void mmcObjectInit(MMCDriver *mmcp, uint8_t *buffer)
Initializes an instance.
bool mmcStopSequentialRead(MMCDriver *mmcp)
Stops a sequential read gracefully.
mmc_spi_config_t MMCConfig
Legacy name for compatibility.
mmc_spi_driver_t MMCDriver
Legacy name for compatibility.
bool mmcErase(MMCDriver *mmcp, uint32_t startblk, uint32_t endblk)
Erases blocks.
bool mmcStopSequentialWrite(MMCDriver *mmcp)
Stops a sequential write gracefully.
bool mmcConnect(MMCDriver *mmcp)
Performs the initialization procedure on the inserted card.
#define _mmcsd_block_device_data
MMCSDBlockDevice specific data.
Definition hal_mmcsd.h:255
int32_t msg_t
Type of a message.
Definition osal.h:159
struct hal_spi_config SPIConfig
Type of a SPI driver configuration structure.
Definition hal_spi_v1.h:121
struct hal_spi_driver SPIDriver
Type of a structure representing an SPI driver.
Definition hal_spi_v1.h:117
Block device info.
Definition hal_ioblock.h:55
Type of a MMC/SD over SPI driver configuration structure.
Definition hal_mmc_spi.h:89
const SPIConfig * lscfg
SPI low speed configuration used during initialization.
Definition hal_mmc_spi.h:97
const SPIConfig * hscfg
SPI high speed configuration used during transfers.
SPIDriver * spip
SPI driver associated to this MMC driver.
Definition hal_mmc_spi.h:93
Structure representing a MMC/SD over SPI driver.
uint8_t * buffer
Pointer to an un-cacheable buffer of size MMC_BUFFER_SIZE.
const struct mmc_spi_driver_vmt * vmt
Virtual Methods Table.
bool block_addresses
Addresses use blocks instead of bytes.
_mmcsd_block_device_data const mmc_spi_config_t * config
Current configuration data.
MMCDriver virtual methods table.