MAX32665 SDK Documentation  0.2
Software Development Kit Overview and API Documentation
sdhc.h
1 
6 /* ****************************************************************************
7  * Copyright (C) 2017 Maxim Integrated Products, Inc., All Rights Reserved.
8  *
9  * Permission is hereby granted, free of charge, to any person obtaining a
10  * copy of this software and associated documentation files (the "Software"),
11  * to deal in the Software without restriction, including without limitation
12  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13  * and/or sell copies of the Software, and to permit persons to whom the
14  * Software is furnished to do so, subject to the following conditions:
15  *
16  * The above copyright notice and this permission notice shall be included
17  * in all copies or substantial portions of the Software.
18  *
19  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
22  * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
23  * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
24  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25  * OTHER DEALINGS IN THE SOFTWARE.
26  *
27  * Except as contained in this notice, the name of Maxim Integrated
28  * Products, Inc. shall not be used except as stated in the Maxim Integrated
29  * Products, Inc. Branding Policy.
30  *
31  * The mere transfer of this software does not imply any licenses
32  * of trade secrets, proprietary technology, copyrights, patents,
33  * trademarks, maskwork rights, or any other form of intellectual
34  * property whatsoever. Maxim Integrated Products, Inc. retains all
35  * ownership rights.
36  *
37  * $Date: 2019-02-28 13:54:56 -0600 (Thu, 28 Feb 2019) $
38  * $Revision: 41324 $
39  *
40  *************************************************************************** */
41 
42 /* Define to prevent redundant inclusion */
43 #ifndef _SDHC_H_
44 #define _SDHC_H_
45 
46 /* **** Includes **** */
47 #include "mxc_config.h"
48 #include "sdhc_regs.h"
49 
50 #ifdef __cplusplus
51 extern "C" {
52 #endif
53 
60 /* **** Definitions **** */
61 #define SDHC_Bus_Voltage_1_8 5
62 #define SDHC_Bus_Voltage_3_0 6
63 #define SDHC_Bus_Voltage_3_3 7
64 
65 #define SDHC_DIRECTION_CFG 0
66 #define SDHC_DIRECTION_READ 1
67 #define SDHC_DIRECTION_WRITE 2
68 
69 typedef struct {
70  unsigned int bus_voltage;
71  unsigned int block_gap;
72  unsigned int clk_div;
73 } sdhc_cfg_t ;
74 
86 typedef void (*sdhc_callback_fn)( int error_code);
87 
88 typedef struct {
89  uint32_t sdma;
90  uint32_t block_size;
91  uint32_t block_count;
92  uint32_t arg_1;
93  unsigned int dma;
94  unsigned int direction;
95  uint32_t command;
96  uint32_t host_control_1;
97  sdhc_callback_fn callback;
99 
100 /* **** Function Prototypes **** */
101 
110 int SDHC_Init(const sdhc_cfg_t *cfg, const sys_cfg_sdhc_t *sys_cfg);
111 
117 int SDHC_Shutdown(void);
118 
122 void SDHC_PowerUp(void);
123 
127 void SDHC_PowerDown(void);
128 
136 void SDHC_Set_Clock_Config(unsigned int clk_div);
137 
145 unsigned int SDHC_Get_Clock_Config(void);
146 
155 int SDHC_SendCommand(sdhc_cmd_cfg_t* sd_cmd_cfg);
164 int SDHC_SendCommandAsync(sdhc_cmd_cfg_t* sd_cmd_cfg);
165 
176 void SDHC_Handler(void);
177 
183 int SDHC_Card_Inserted(void);
184 
190 void SDHC_ClearFlags(uint32_t mask);
191 
198 unsigned SDHC_GetFlags(void);
199 
204 void SDHC_Reset(void);
205 
210 void SDHC_Reset_CMD_DAT(void);
211 
217 int SDHC_Card_Busy(void);
218 
224 unsigned int SDHC_Get_Host_Cn_1(void);
225 
232 uint32_t SDHC_Get_Response32(void);
233 
240 uint32_t SDHC_Get_Response32_Auto(void);
241 
248 void SDHC_Get_Response128(unsigned char *response);
249 
252 #ifdef __cplusplus
253 }
254 #endif
255 
256 #endif /* _SDHC_H_ */
void SDHC_ClearFlags(uint32_t mask)
Clear interrupt flags.
unsigned int dma
DMA enable bit.
Definition: sdhc.h:93
void SDHC_Reset(void)
Resets SDHC back to default settings.
void SDHC_Set_Clock_Config(unsigned int clk_div)
Set clock divider.
Definition: sdhc.h:88
int SDHC_SendCommandAsync(sdhc_cmd_cfg_t *sd_cmd_cfg)
Send SDHC command Async.
unsigned int clk_div
Divider for SD clock.
Definition: sdhc.h:72
int SDHC_Shutdown(void)
Shutdown SDHC module.
void SDHC_PowerDown(void)
Disable SDHC Bus Power.
int SDHC_Card_Busy(void)
Check if Card is busy.
uint32_t command
Command to be issued on bus (CMD0, CMD1, ...)
Definition: sdhc.h:95
uint32_t block_size
Size of transfer block in bytes.
Definition: sdhc.h:90
uint32_t sdma
SDMA register for read or write transaction.
Definition: sdhc.h:89
void SDHC_Reset_CMD_DAT(void)
Abort any command or data transaction in progress on controller.
unsigned SDHC_GetFlags(void)
Get interrupt flags.
uint32_t SDHC_Get_Response32(void)
Read a 32-bit command response.
void SDHC_Get_Response128(unsigned char *response)
Read a 128-bit command response.
unsigned int bus_voltage
Use constants above for 1.8V, 3.0V, 3.3V.
Definition: sdhc.h:70
uint32_t SDHC_Get_Response32_Auto(void)
Read a 32-bit command response for Auto commands.
uint32_t host_control_1
Host control register 1 to be assigned before command is issued.
Definition: sdhc.h:96
unsigned int direction
Direction of transfer.
Definition: sdhc.h:94
uint32_t arg_1
Argument 1 holds the arguments for the commands sent to the card.
Definition: sdhc.h:92
int SDHC_SendCommand(sdhc_cmd_cfg_t *sd_cmd_cfg)
Send Command, blocking.
unsigned int block_gap
Set block gap register default is 0.
Definition: sdhc.h:71
int SDHC_Init(const sdhc_cfg_t *cfg, const sys_cfg_sdhc_t *sys_cfg)
Initialize and enable SDHC module.
unsigned int SDHC_Get_Clock_Config(void)
Get clock divider.
unsigned int SDHC_Get_Host_Cn_1(void)
Retrieve host control 1 register.
uint32_t block_count
Number of blocks to transfer.
Definition: sdhc.h:91
Definition: sdhc.h:69
int SDHC_Card_Inserted(void)
See if card is inserted.
void SDHC_PowerUp(void)
Enable SDHC Bus Power.