ChibiOS/HAL 9.0.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 */
63typedef uint32_t sdcmode_t;
64
65/**
66 * @brief SDC Driver condition flags type.
67 */
68typedef uint32_t sdcflags_t;
69
70/**
71 * @brief Type of a structure representing an SDC driver.
72 */
73typedef struct SDCDriver SDCDriver;
74
75/**
76 * @brief Driver configuration structure.
77 * @note It could be empty on some architectures.
78 */
79typedef 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 */
101
102/**
103 * @brief Structure representing an SDC driver.
104 */
105struct 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__)
143extern SDCDriver SDCD1;
144#endif
145
146#ifdef __cplusplus
147extern "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);
154 void sdc_lld_stop_clk(SDCDriver *sdcp);
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);
172#ifdef __cplusplus
173}
174#endif
175
176#endif /* HAL_USE_SDC == TRUE */
177
178#endif /* HAL_SDC_LLD_H */
179
180/** @} */
#define _mmcsd_block_device_data
MMCSDBlockDevice specific data.
Definition hal_mmcsd.h:255
#define MMCSD_BLOCK_SIZE
Fixed block size for MMC/SD block devices.
Definition hal_mmcsd.h:39
bool sdc_lld_is_write_protected(SDCDriver *sdcp)
void sdc_lld_set_data_clk(SDCDriver *sdcp, sdcbusclk_t clk)
Sets the SDIO clock to data mode (25MHz or less).
bool sdc_lld_sync(SDCDriver *sdcp)
Waits for card idle condition.
void sdc_lld_send_cmd_none(SDCDriver *sdcp, uint8_t cmd, uint32_t arg)
Sends an SDIO command with no response expected.
void sdc_lld_stop_clk(SDCDriver *sdcp)
Stops the SDIO clock.
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.
void sdc_lld_stop(SDCDriver *sdcp)
Deactivates the SDC peripheral.
Definition hal_sdc_lld.c:93
void sdc_lld_start(SDCDriver *sdcp)
Configures and activates the SDC peripheral.
Definition hal_sdc_lld.c:79
bool sdc_lld_read_special(SDCDriver *sdcp, uint8_t *buf, size_t bytes, uint8_t cmd, uint32_t argument)
SDCDriver SDCD1
SDCD1 driver identifier.
Definition hal_sdc_lld.c:41
bool sdc_lld_write(SDCDriver *sdcp, uint32_t startblk, const uint8_t *buf, uint32_t n)
Writes one or more blocks.
uint32_t sdcmode_t
Type of card flags.
Definition hal_sdc_lld.h:63
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.
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.
sdcbusclk_t
Max supported clock.
Definition hal_sdc.h:131
void sdc_lld_start_clk(SDCDriver *sdcp)
Starts the SDIO clock and sets it to init mode (400kHz or less).
void sdc_lld_set_bus_mode(SDCDriver *sdcp, sdcbusmode_t mode)
Switches the bus to 4 bits mode.
void sdc_lld_init(void)
Low level SDC driver initialization.
Definition hal_sdc_lld.c:65
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.
bool sdc_lld_is_card_inserted(SDCDriver *sdcp)
#define _sdc_driver_methods
SDCDriver specific methods.
Definition hal_sdc_lld.h:90
uint32_t sdcflags_t
SDC Driver condition flags type.
Definition hal_sdc_lld.h:68
Driver configuration structure.
Definition hal_sdc_lld.h:79
sdcbusmode_t bus_width
Bus width.
Definition hal_sdc_lld.h:83
Structure representing an SDC driver.
sdcmode_t cardmode
Various flags regarding the mounted card.
_mmcsd_block_device_data const SDCConfig * config
Current configuration data.
uint8_t buf[MMCSD_BLOCK_SIZE]
Buffer for internal operations.
uint32_t rca
Card RCA.
const struct SDCDriverVMT * vmt
Virtual Methods Table.
sdcflags_t errors
Errors flags.
SDCDriver virtual methods table.
Definition hal_sdc_lld.h:98