ChibiOS  21.6.0
hal_sdc_lld.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_sdc_lld.h
19  * @brief PLATFORM SDC subsystem low level driver header.
20  *
21  * @addtogroup SDC
22  * @{
23  */
24 
25 #ifndef HAL_SDC_LLD_H
26 #define HAL_SDC_LLD_H
27 
28 #if (HAL_USE_SDC == TRUE) || defined(__DOXYGEN__)
29 
30 /*===========================================================================*/
31 /* Driver constants. */
32 /*===========================================================================*/
33 
34 /*===========================================================================*/
35 /* Driver pre-compile time settings. */
36 /*===========================================================================*/
37 
38 /**
39  * @name PLATFORM configuration options
40  * @{
41  */
42 /**
43  * @brief PWMD1 driver enable switch.
44  * @details If set to @p TRUE the support for PWM1 is included.
45  * @note The default is @p FALSE.
46  */
47 #if !defined(PLATFORM_SDC_USE_SDC1) || defined(__DOXYGEN__)
48 #define PLATFORM_SDC_USE_SDC1 FALSE
49 #endif
50 /** @} */
51 
52 /*===========================================================================*/
53 /* Derived constants and error checks. */
54 /*===========================================================================*/
55 
56 /*===========================================================================*/
57 /* Driver data structures and types. */
58 /*===========================================================================*/
59 
60 /**
61  * @brief Type of card flags.
62  */
63 typedef uint32_t sdcmode_t;
64 
65 /**
66  * @brief SDC Driver condition flags type.
67  */
68 typedef uint32_t sdcflags_t;
69 
70 /**
71  * @brief Type of a structure representing an SDC driver.
72  */
73 typedef struct SDCDriver SDCDriver;
74 
75 /**
76  * @brief Driver configuration structure.
77  * @note It could be empty on some architectures.
78  */
79 typedef struct {
80  /**
81  * @brief Bus width.
82  */
84  /* End of the mandatory fields.*/
85 } SDCConfig;
86 
87 /**
88  * @brief @p SDCDriver specific methods.
89  */
90 #define _sdc_driver_methods \
91  _mmcsd_block_device_methods
92 
93 /**
94  * @extends MMCSDBlockDeviceVMT
95  *
96  * @brief @p SDCDriver virtual methods table.
97  */
98 struct SDCDriverVMT {
100 };
101 
102 /**
103  * @brief Structure representing an SDC driver.
104  */
105 struct SDCDriver {
106  /**
107  * @brief Virtual Methods Table.
108  */
109  const struct SDCDriverVMT *vmt;
111  /**
112  * @brief Current configuration data.
113  */
115  /**
116  * @brief Various flags regarding the mounted card.
117  */
119  /**
120  * @brief Errors flags.
121  */
123  /**
124  * @brief Card RCA.
125  */
126  uint32_t rca;
127  /**
128  * @brief Buffer for internal operations.
129  */
131  /* End of the mandatory fields.*/
132 };
133 
134 /*===========================================================================*/
135 /* Driver macros. */
136 /*===========================================================================*/
137 
138 /*===========================================================================*/
139 /* External declarations. */
140 /*===========================================================================*/
141 
142 #if (PLATFORM_SDC_USE_SDC1 == TRUE) && !defined(__DOXYGEN__)
143 extern SDCDriver SDCD1;
144 #endif
145 
146 #ifdef __cplusplus
147 extern "C" {
148 #endif
149  void sdc_lld_init(void);
150  void sdc_lld_start(SDCDriver *sdcp);
151  void sdc_lld_stop(SDCDriver *sdcp);
152  void sdc_lld_start_clk(SDCDriver *sdcp);
153  void sdc_lld_set_data_clk(SDCDriver *sdcp, sdcbusclk_t clk);
154  void sdc_lld_stop_clk(SDCDriver *sdcp);
155  void sdc_lld_set_bus_mode(SDCDriver *sdcp, sdcbusmode_t mode);
156  void sdc_lld_send_cmd_none(SDCDriver *sdcp, uint8_t cmd, uint32_t arg);
157  bool sdc_lld_send_cmd_short(SDCDriver *sdcp, uint8_t cmd, uint32_t arg,
158  uint32_t *resp);
159  bool sdc_lld_send_cmd_short_crc(SDCDriver *sdcp, uint8_t cmd, uint32_t arg,
160  uint32_t *resp);
161  bool sdc_lld_send_cmd_long_crc(SDCDriver *sdcp, uint8_t cmd, uint32_t arg,
162  uint32_t *resp);
163  bool sdc_lld_read_special(SDCDriver *sdcp, uint8_t *buf, size_t bytes,
164  uint8_t cmd, uint32_t argument);
165  bool sdc_lld_read(SDCDriver *sdcp, uint32_t startblk,
166  uint8_t *buf, uint32_t n);
167  bool sdc_lld_write(SDCDriver *sdcp, uint32_t startblk,
168  const uint8_t *buf, uint32_t n);
169  bool sdc_lld_sync(SDCDriver *sdcp);
170  bool sdc_lld_is_card_inserted(SDCDriver *sdcp);
171  bool sdc_lld_is_write_protected(SDCDriver *sdcp);
172 #ifdef __cplusplus
173 }
174 #endif
175 
176 #endif /* HAL_USE_SDC == TRUE */
177 
178 #endif /* HAL_SDC_LLD_H */
179 
180 /** @} */
sdc_lld_send_cmd_short_crc
bool sdc_lld_send_cmd_short_crc(SDCDriver *sdcp, uint8_t cmd, uint32_t arg, uint32_t *resp)
Sends an SDIO command with a short response expected and CRC.
Definition: hal_sdc_lld.c:222
SDCDriverVMT
SDCDriver virtual methods table.
Definition: hal_sdc_lld.h:98
SDCDriver::vmt
const struct SDCDriverVMT * vmt
Virtual Methods Table.
Definition: hal_sdc_lld.h:109
sdc_lld_start_clk
void sdc_lld_start_clk(SDCDriver *sdcp)
Starts the SDIO clock and sets it to init mode (400kHz or less).
Definition: hal_sdc_lld.c:107
sdc_lld_init
void sdc_lld_init(void)
Low level SDC driver initialization.
Definition: hal_sdc_lld.c:65
sdc_lld_start
void sdc_lld_start(SDCDriver *sdcp)
Configures and activates the SDC peripheral.
Definition: hal_sdc_lld.c:79
sdcbusmode_t
sdcbusmode_t
Type of SDIO bus mode.
Definition: hal_sdc.h:122
sdc_lld_send_cmd_long_crc
bool sdc_lld_send_cmd_long_crc(SDCDriver *sdcp, uint8_t cmd, uint32_t arg, uint32_t *resp)
Sends an SDIO command with a long response expected and CRC.
Definition: hal_sdc_lld.c:247
MMCSD_BLOCK_SIZE
#define MMCSD_BLOCK_SIZE
Fixed block size for MMC/SD block devices.
Definition: hal_mmcsd.h:39
SDCDriver::buf
uint8_t buf[MMCSD_BLOCK_SIZE]
Buffer for internal operations.
Definition: hal_sdc_lld.h:130
sdc_lld_read
bool sdc_lld_read(SDCDriver *sdcp, uint32_t startblk, uint8_t *buf, uint32_t n)
Reads one or more blocks.
Definition: hal_sdc_lld.c:272
sdc_lld_sync
bool sdc_lld_sync(SDCDriver *sdcp)
Waits for card idle condition.
Definition: hal_sdc_lld.c:319
SDCDriver::rca
uint32_t rca
Card RCA.
Definition: hal_sdc_lld.h:126
sdc_lld_stop
void sdc_lld_stop(SDCDriver *sdcp)
Deactivates the SDC peripheral.
Definition: hal_sdc_lld.c:93
SDCConfig::bus_width
sdcbusmode_t bus_width
Bus width.
Definition: hal_sdc_lld.h:83
sdc_lld_send_cmd_none
void sdc_lld_send_cmd_none(SDCDriver *sdcp, uint8_t cmd, uint32_t arg)
Sends an SDIO command with no response expected.
Definition: hal_sdc_lld.c:175
SDCConfig
Driver configuration structure.
Definition: hal_sdc_lld.h:79
SDCDriver
Structure representing an SDC driver.
Definition: hal_sdc_lld.h:105
sdcmode_t
uint32_t sdcmode_t
Type of card flags.
Definition: hal_sdc_lld.h:63
sdc_lld_set_bus_mode
void sdc_lld_set_bus_mode(SDCDriver *sdcp, sdcbusmode_t mode)
Switches the bus to 4 bits mode.
Definition: hal_sdc_lld.c:146
sdcflags_t
uint32_t sdcflags_t
SDC Driver condition flags type.
Definition: hal_sdc_lld.h:68
_mmcsd_block_device_data
#define _mmcsd_block_device_data
MMCSDBlockDevice specific data.
Definition: hal_mmcsd.h:254
SDCDriver::errors
sdcflags_t errors
Errors flags.
Definition: hal_sdc_lld.h:122
SDCDriver::cardmode
sdcmode_t cardmode
Various flags regarding the mounted card.
Definition: hal_sdc_lld.h:118
sdc_lld_stop_clk
void sdc_lld_stop_clk(SDCDriver *sdcp)
Stops the SDIO clock.
Definition: hal_sdc_lld.c:133
sdc_lld_write
bool sdc_lld_write(SDCDriver *sdcp, uint32_t startblk, const uint8_t *buf, uint32_t n)
Writes one or more blocks.
Definition: hal_sdc_lld.c:297
SDCDriver::config
const _mmcsd_block_device_data SDCConfig * config
Current configuration data.
Definition: hal_sdc_lld.h:114
sdc_lld_send_cmd_short
bool sdc_lld_send_cmd_short(SDCDriver *sdcp, uint8_t cmd, uint32_t arg, uint32_t *resp)
Sends an SDIO command with a short response expected.
Definition: hal_sdc_lld.c:197
SDCD1
SDCDriver SDCD1
SDCD1 driver identifier.
Definition: hal_sdc_lld.c:41
_sdc_driver_methods
#define _sdc_driver_methods
SDCDriver specific methods.
Definition: hal_sdc_lld.h:90
sdcbusclk_t
sdcbusclk_t
Max supported clock.
Definition: hal_sdc.h:131
sdc_lld_set_data_clk
void sdc_lld_set_data_clk(SDCDriver *sdcp, sdcbusclk_t clk)
Sets the SDIO clock to data mode (25MHz or less).
Definition: hal_sdc_lld.c:120