1 | /* ---------------------------------------------------------------------------- */ |
---|
2 | /* Atmel Microcontroller Software Support */ |
---|
3 | /* SAM Software Package License */ |
---|
4 | /* ---------------------------------------------------------------------------- */ |
---|
5 | /* Copyright (c) 2015, Atmel Corporation */ |
---|
6 | /* */ |
---|
7 | /* All rights reserved. */ |
---|
8 | /* */ |
---|
9 | /* Redistribution and use in source and binary forms, with or without */ |
---|
10 | /* modification, are permitted provided that the following condition is met: */ |
---|
11 | /* */ |
---|
12 | /* - Redistributions of source code must retain the above copyright notice, */ |
---|
13 | /* this list of conditions and the disclaimer below. */ |
---|
14 | /* */ |
---|
15 | /* Atmel's name may not be used to endorse or promote products derived from */ |
---|
16 | /* this software without specific prior written permission. */ |
---|
17 | /* */ |
---|
18 | /* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR */ |
---|
19 | /* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */ |
---|
20 | /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE */ |
---|
21 | /* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, */ |
---|
22 | /* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT */ |
---|
23 | /* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, */ |
---|
24 | /* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF */ |
---|
25 | /* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING */ |
---|
26 | /* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, */ |
---|
27 | /* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ |
---|
28 | /* ---------------------------------------------------------------------------- */ |
---|
29 | |
---|
30 | /** \file */ |
---|
31 | |
---|
32 | /** |
---|
33 | * \ingroup sdmmc_hal |
---|
34 | * \addtogroup mcid_module MCI Driver (HAL for SD/MMC Lib) |
---|
35 | * |
---|
36 | * \section Purpose |
---|
37 | * |
---|
38 | * This driver implements SD(IO)/MMC command operations and MCI configuration |
---|
39 | * routines to perform SD(IO)/MMC access. It's used for upper layer |
---|
40 | * (\ref libsdmmc_module "SD/MMC driver") to perform SD/MMC operations. |
---|
41 | * |
---|
42 | * \section Usage |
---|
43 | * |
---|
44 | * -# MCID_Init(): Initializes a MCI driver instance and the underlying |
---|
45 | * peripheral. |
---|
46 | * -# MCID_SendCmd(): Starts a MCI transfer which described by |
---|
47 | * \ref sSdmmcCommand. |
---|
48 | * -# MCID_CancelCmd(): Cancel a pending command. |
---|
49 | * -# MCID_IsCmdCompleted(): Check if MCI transfer is finished. |
---|
50 | * -# MCID_Handler(): Interrupt handler which is called by ISR handler. |
---|
51 | * -# MCID_IOCtrl(): IO control function to report HW attributes to upper |
---|
52 | * layer driver and modify HW settings (such as clock |
---|
53 | * frequency, High-speed support, etc. See |
---|
54 | * \ref sdmmc_ioctrls). |
---|
55 | * |
---|
56 | * \sa \ref dmad_module "DMA Driver", \ref hsmci_module "HSMCI", |
---|
57 | * \ref libsdmmc_module "SD/MMC Library" |
---|
58 | * |
---|
59 | * Related files:\n |
---|
60 | * \ref mcid.h\n |
---|
61 | * \ref mcid_dma.c.\n |
---|
62 | */ |
---|
63 | |
---|
64 | #ifndef MCID_H |
---|
65 | #define MCID_H |
---|
66 | /** \addtogroup mcid_module |
---|
67 | *@{ |
---|
68 | */ |
---|
69 | |
---|
70 | /*---------------------------------------------------------------------------- |
---|
71 | * Headers |
---|
72 | *----------------------------------------------------------------------------*/ |
---|
73 | |
---|
74 | #include "chip.h" |
---|
75 | |
---|
76 | #include <stdint.h> |
---|
77 | #include <stdio.h> |
---|
78 | |
---|
79 | /** \addtogroup mcid_defines MCI Driver Defines |
---|
80 | * @{*/ |
---|
81 | |
---|
82 | /*---------------------------------------------------------------------------- |
---|
83 | * Constants |
---|
84 | *----------------------------------------------------------------------------*/ |
---|
85 | |
---|
86 | /** MCI States */ |
---|
87 | #define MCID_IDLE 0 /**< Idle */ |
---|
88 | #define MCID_LOCKED 1 /**< Locked for specific slot */ |
---|
89 | #define MCID_CMD 2 /**< Processing the command */ |
---|
90 | #define MCID_ERROR 3 /**< Command error */ |
---|
91 | |
---|
92 | /** MCI Initialize clock 400K Hz */ |
---|
93 | #define MCI_INITIAL_SPEED 400000 |
---|
94 | |
---|
95 | /** @}*/ |
---|
96 | |
---|
97 | /*---------------------------------------------------------------------------- |
---|
98 | * Types |
---|
99 | *----------------------------------------------------------------------------*/ |
---|
100 | /** \addtogroup mcid_structs MCI Driver Data Structs |
---|
101 | * @{ |
---|
102 | */ |
---|
103 | #ifdef __cplusplus |
---|
104 | extern "C" { |
---|
105 | #endif |
---|
106 | |
---|
107 | /** |
---|
108 | * \brief MCI Driver |
---|
109 | */ |
---|
110 | typedef struct _Mcid { |
---|
111 | /** Pointer to a MCI peripheral. */ |
---|
112 | Hsmci *pMciHw; |
---|
113 | /** Pointer to a DMA driver */ |
---|
114 | sXdmad *pXdmad; |
---|
115 | /** Pointer to currently executing command. */ |
---|
116 | void *pCmd; |
---|
117 | /** MCK source, Hz */ |
---|
118 | uint32_t dwMck; |
---|
119 | /** DMA transfer channel */ |
---|
120 | uint32_t dwDmaCh; |
---|
121 | /** DMA transferred data index (bytes) */ |
---|
122 | uint32_t dwXfrNdx; |
---|
123 | /** DMA transfer size (bytes) */ |
---|
124 | uint32_t dwXSize; |
---|
125 | /** MCI peripheral identifier. */ |
---|
126 | uint8_t bID; |
---|
127 | /** Polling mode */ |
---|
128 | uint8_t bPolling; |
---|
129 | /** Reserved */ |
---|
130 | uint8_t reserved; |
---|
131 | /** state. */ |
---|
132 | volatile uint8_t bState; |
---|
133 | } sMcid; |
---|
134 | |
---|
135 | /** @}*/ |
---|
136 | /*---------------------------------------------------------------------------- |
---|
137 | * Exported functions |
---|
138 | *----------------------------------------------------------------------------*/ |
---|
139 | /** \addtogroup mcid_functions MCI Driver Functions |
---|
140 | @{*/ |
---|
141 | extern void MCID_Init(sMcid *pMcid, |
---|
142 | Hsmci *pMci, uint8_t bID, uint32_t dwMck, |
---|
143 | sXdmad *pXdmad, |
---|
144 | uint8_t bPolling); |
---|
145 | |
---|
146 | extern void MCID_Reset(sMcid *pMcid); |
---|
147 | |
---|
148 | extern void MCID_SetSlot(Hsmci *pMci, uint8_t slot); |
---|
149 | |
---|
150 | extern uint32_t MCID_Lock(sMcid *pMcid, uint8_t bSlot); |
---|
151 | |
---|
152 | extern uint32_t MCID_Release(sMcid *pMcid); |
---|
153 | |
---|
154 | extern void MCID_Handler(sMcid *pMcid); |
---|
155 | |
---|
156 | extern uint32_t MCID_SendCmd(sMcid *pMcid, void *pCmd); |
---|
157 | |
---|
158 | extern uint32_t MCID_CancelCmd(sMcid *pMcid); |
---|
159 | |
---|
160 | extern uint32_t MCID_IsCmdCompleted(sMcid *pMcid); |
---|
161 | |
---|
162 | extern uint32_t MCID_IOCtrl(sMcid *pMcid, uint32_t bCtl, uint32_t param); |
---|
163 | |
---|
164 | #ifdef __cplusplus |
---|
165 | } |
---|
166 | #endif |
---|
167 | /** @}*/ |
---|
168 | /**@}*/ |
---|
169 | #endif //#ifndef HSMCID_H |
---|
170 | |
---|