ChibiOS/HAL  6.1.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 Working area for memory consuming operations.
82  * @note It is mandatory for detecting MMC cards bigger than 2GB else it
83  * can be @p NULL.
84  * @note Memory pointed by this buffer is only used by @p sdcConnect(),
85  * afterward it can be reused for other purposes.
86  */
87  uint8_t *scratchpad;
88  /**
89  * @brief Bus width.
90  */
92  /* End of the mandatory fields.*/
93 } SDCConfig;
94 
95 /**
96  * @brief @p SDCDriver specific methods.
97  */
98 #define _sdc_driver_methods \
99  _mmcsd_block_device_methods
100 
101 /**
102  * @extends MMCSDBlockDeviceVMT
103  *
104  * @brief @p SDCDriver virtual methods table.
105  */
106 struct SDCDriverVMT {
108 };
109 
110 /**
111  * @brief Structure representing an SDC driver.
112  */
113 struct SDCDriver {
114  /**
115  * @brief Virtual Methods Table.
116  */
117  const struct SDCDriverVMT *vmt;
119  /**
120  * @brief Current configuration data.
121  */
123  /**
124  * @brief Various flags regarding the mounted card.
125  */
127  /**
128  * @brief Errors flags.
129  */
131  /**
132  * @brief Card RCA.
133  */
134  uint32_t rca;
135  /* End of the mandatory fields.*/
136 };
137 
138 /*===========================================================================*/
139 /* Driver macros. */
140 /*===========================================================================*/
141 
142 /*===========================================================================*/
143 /* External declarations. */
144 /*===========================================================================*/
145 
146 #if (PLATFORM_SDC_USE_SDC1 == TRUE) && !defined(__DOXYGEN__)
147 extern SDCDriver SDCD1;
148 #endif
149 
150 #ifdef __cplusplus
151 extern "C" {
152 #endif
153  void sdc_lld_init(void);
154  void sdc_lld_start(SDCDriver *sdcp);
155  void sdc_lld_stop(SDCDriver *sdcp);
156  void sdc_lld_start_clk(SDCDriver *sdcp);
157  void sdc_lld_set_data_clk(SDCDriver *sdcp, sdcbusclk_t clk);
158  void sdc_lld_stop_clk(SDCDriver *sdcp);
159  void sdc_lld_set_bus_mode(SDCDriver *sdcp, sdcbusmode_t mode);
160  void sdc_lld_send_cmd_none(SDCDriver *sdcp, uint8_t cmd, uint32_t arg);
161  bool sdc_lld_send_cmd_short(SDCDriver *sdcp, uint8_t cmd, uint32_t arg,
162  uint32_t *resp);
163  bool sdc_lld_send_cmd_short_crc(SDCDriver *sdcp, uint8_t cmd, uint32_t arg,
164  uint32_t *resp);
165  bool sdc_lld_send_cmd_long_crc(SDCDriver *sdcp, uint8_t cmd, uint32_t arg,
166  uint32_t *resp);
167  bool sdc_lld_read_special(SDCDriver *sdcp, uint8_t *buf, size_t bytes,
168  uint8_t cmd, uint32_t argument);
169  bool sdc_lld_read(SDCDriver *sdcp, uint32_t startblk,
170  uint8_t *buf, uint32_t n);
171  bool sdc_lld_write(SDCDriver *sdcp, uint32_t startblk,
172  const uint8_t *buf, uint32_t n);
173  bool sdc_lld_sync(SDCDriver *sdcp);
174  bool sdc_lld_is_card_inserted(SDCDriver *sdcp);
175  bool sdc_lld_is_write_protected(SDCDriver *sdcp);
176 #ifdef __cplusplus
177 }
178 #endif
179 
180 #endif /* HAL_USE_SDC == TRUE */
181 
182 #endif /* HAL_SDC_LLD_H */
183 
184 /** @} */
bool sdc_lld_sync(SDCDriver *sdcp)
Waits for card idle condition.
Definition: hal_sdc_lld.c:319
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
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
#define _sdc_driver_methods
SDCDriver specific methods.
Definition: hal_sdc_lld.h:98
const struct SDCDriverVMT * vmt
Virtual Methods Table.
Definition: hal_sdc_lld.h:117
#define _mmcsd_block_device_data
MMCSDBlockDevice specific data.
Definition: hal_mmcsd.h:258
sdcbusmode_t bus_width
Bus width.
Definition: hal_sdc_lld.h:91
uint32_t sdcmode_t
Type of card flags.
Definition: hal_sdc_lld.h:63
uint32_t rca
Card RCA.
Definition: hal_sdc_lld.h:134
void sdc_lld_stop_clk(SDCDriver *sdcp)
Stops the SDIO clock.
Definition: hal_sdc_lld.c:133
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
void sdc_lld_start(SDCDriver *sdcp)
Configures and activates the SDC peripheral.
Definition: hal_sdc_lld.c:79
SDCDriver SDCD1
SDCD1 driver identifier.
Definition: hal_sdc_lld.c:41
void sdc_lld_init(void)
Low level SDC driver initialization.
Definition: hal_sdc_lld.c:65
SDCDriver virtual methods table.
Definition: hal_sdc_lld.h:106
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
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
sdcflags_t errors
Errors flags.
Definition: hal_sdc_lld.h:130
sdcmode_t cardmode
Various flags regarding the mounted card.
Definition: hal_sdc_lld.h:126
sdcbusclk_t
Max supported clock.
Definition: hal_sdc.h:131
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
sdcbusmode_t
Type of SDIO bus mode.
Definition: hal_sdc.h:122
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
uint32_t sdcflags_t
SDC Driver condition flags type.
Definition: hal_sdc_lld.h:68
Structure representing an SDC driver.
Definition: hal_sdc_lld.h:113
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
_mmcsd_block_device_data const SDCConfig * config
Current configuration data.
Definition: hal_sdc_lld.h:122
void sdc_lld_set_bus_mode(SDCDriver *sdcp, sdcbusmode_t mode)
Switches the bus to 4 bits mode.
Definition: hal_sdc_lld.c:146
void sdc_lld_stop(SDCDriver *sdcp)
Deactivates the SDC peripheral.
Definition: hal_sdc_lld.c:93
uint8_t * scratchpad
Working area for memory consuming operations.
Definition: hal_sdc_lld.h:87
Driver configuration structure.
Definition: hal_sdc_lld.h:79