summaryrefslogtreecommitdiffstats
path: root/bsps/arm/atsam/include/libchip/include/mcid.h
blob: 385f7ad29d8956b5ec162976f3a4ee14b09f3aed (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
/* ---------------------------------------------------------------------------- */
/*                  Atmel Microcontroller Software Support                      */
/*                       SAM Software Package License                           */
/* ---------------------------------------------------------------------------- */
/* Copyright (c) 2015, Atmel Corporation                                        */
/*                                                                              */
/* All rights reserved.                                                         */
/*                                                                              */
/* Redistribution and use in source and binary forms, with or without           */
/* modification, are permitted provided that the following condition is met:    */
/*                                                                              */
/* - Redistributions of source code must retain the above copyright notice,     */
/* this list of conditions and the disclaimer below.                            */
/*                                                                              */
/* Atmel's name may not be used to endorse or promote products derived from     */
/* this software without specific prior written permission.                     */
/*                                                                              */
/* DISCLAIMER:  THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR   */
/* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE   */
/* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,      */
/* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT */
/* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,  */
/* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF    */
/* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING         */
/* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, */
/* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.                           */
/* ---------------------------------------------------------------------------- */

/** \file */

/**
 * \ingroup sdmmc_hal
 * \addtogroup mcid_module MCI Driver (HAL for SD/MMC Lib)
 *
 * \section Purpose
 *
 * This driver implements SD(IO)/MMC command operations and MCI configuration
 * routines to perform SD(IO)/MMC access. It's used for upper layer
 * (\ref libsdmmc_module "SD/MMC driver") to perform SD/MMC operations.
 *
 * \section Usage
 *
 * -# MCID_Init(): Initializes a MCI driver instance and the underlying
 *                 peripheral.
 * -# MCID_SendCmd(): Starts a MCI transfer which described by
 *                    \ref sSdmmcCommand.
 * -# MCID_CancelCmd(): Cancel a pending command.
 * -# MCID_IsCmdCompleted(): Check if MCI transfer is finished.
 * -# MCID_Handler(): Interrupt handler which is called by ISR handler.
 * -# MCID_IOCtrl(): IO control function to report HW attributes to upper
 *                   layer driver and modify HW settings (such as clock
 *                   frequency, High-speed support, etc. See
 *                   \ref sdmmc_ioctrls).
 *
 * \sa \ref dmad_module "DMA Driver", \ref hsmci_module "HSMCI",
 *     \ref libsdmmc_module "SD/MMC Library"
 *
 * Related files:\n
 * \ref mcid.h\n
 * \ref mcid_dma.c.\n
 */

#ifndef MCID_H
#define MCID_H
/** \addtogroup mcid_module
 *@{
 */

/*----------------------------------------------------------------------------
 *         Headers
 *----------------------------------------------------------------------------*/

#include "chip.h"

#include <stdint.h>
#include <stdio.h>

/** \addtogroup mcid_defines MCI Driver Defines
 *      @{*/

/*----------------------------------------------------------------------------
 *         Constants
 *----------------------------------------------------------------------------*/

/** MCI States */
#define MCID_IDLE   0       /**< Idle */
#define MCID_LOCKED 1       /**< Locked for specific slot */
#define MCID_CMD    2       /**< Processing the command */
#define MCID_ERROR  3       /**< Command error */

/** MCI Initialize clock 400K Hz */
#define MCI_INITIAL_SPEED   400000

/**     @}*/

/*----------------------------------------------------------------------------
 *         Types
 *----------------------------------------------------------------------------*/
/** \addtogroup mcid_structs MCI Driver Data Structs
 *      @{
 */
#ifdef __cplusplus
extern "C" {
#endif

/**
 *  \brief MCI Driver
 */
typedef struct _Mcid {
	/** Pointer to a MCI peripheral. */
	Hsmci         *pMciHw;
	/** Pointer to a DMA driver */
	sXdmad         *pXdmad;
	/** Pointer to currently executing command. */
	void          *pCmd;
	/** MCK source, Hz */
	uint32_t       dwMck;
	/** DMA transfer channel */
	uint32_t       dwDmaCh;
	/** DMA transferred data index (bytes) */
	uint32_t       dwXfrNdx;
	/** DMA transfer size (bytes) */
	uint32_t       dwXSize;
	/** MCI peripheral identifier. */
	uint8_t        bID;
	/** Polling mode */
	uint8_t        bPolling;
	/** Reserved */
	uint8_t        reserved;
	/** state. */
	volatile uint8_t bState;
} sMcid;

/**     @}*/
/*----------------------------------------------------------------------------
 *         Exported functions
 *----------------------------------------------------------------------------*/
/** \addtogroup mcid_functions MCI Driver Functions
        @{*/
extern void MCID_Init(sMcid *pMcid,
					  Hsmci *pMci, uint8_t bID, uint32_t dwMck,
					  sXdmad *pXdmad,
					  uint8_t bPolling);

extern void MCID_Reset(sMcid *pMcid);

extern void MCID_SetSlot(Hsmci *pMci, uint8_t slot);

extern uint32_t MCID_Lock(sMcid *pMcid, uint8_t bSlot);

extern uint32_t MCID_Release(sMcid *pMcid);

extern void MCID_Handler(sMcid *pMcid);

extern uint32_t MCID_SendCmd(sMcid *pMcid, void *pCmd);

extern uint32_t MCID_CancelCmd(sMcid *pMcid);

extern uint32_t MCID_IsCmdCompleted(sMcid *pMcid);

extern uint32_t MCID_IOCtrl(sMcid *pMcid, uint32_t bCtl, uint32_t param);

#ifdef __cplusplus
}
#endif
/**     @}*/
/**@}*/
#endif //#ifndef HSMCID_H