1 /* ----------------------------------------------------------------------------
\r
2 * ATMEL Microcontroller Software Support
\r
3 * ----------------------------------------------------------------------------
\r
4 * Copyright (c) 2008, Atmel Corporation
\r
6 * All rights reserved.
\r
8 * Redistribution and use in source and binary forms, with or without
\r
9 * modification, are permitted provided that the following conditions are met:
\r
11 * - Redistributions of source code must retain the above copyright notice,
\r
12 * this list of conditions and the disclaimer below.
\r
14 * Atmel's name may not be used to endorse or promote products derived from
\r
15 * this software without specific prior written permission.
\r
17 * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
\r
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
\r
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
\r
20 * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
\r
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
\r
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
\r
23 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
\r
24 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
\r
25 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
\r
26 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\r
27 * ----------------------------------------------------------------------------
\r
30 //------------------------------------------------------------------------------
\r
35 /// mci-interface driver
\r
39 /// -# MCI_Init: Initializes a MCI driver instance and the underlying peripheral.
\r
40 /// -# MCI_SetSpeed : Configure the MCI CLKDIV in the MCI_MR register.
\r
41 /// -# MCI_SendCommand: Starts a MCI transfer.
\r
42 /// -# MCI_Handler : Interrupt handler which is called by ISR handler.
\r
43 /// -# MCI_SetBusWidth : Configure the MCI SDCBUS in the MCI_SDCR register.
\r
44 //------------------------------------------------------------------------------
\r
50 //------------------------------------------------------------------------------
\r
52 //------------------------------------------------------------------------------
\r
56 //------------------------------------------------------------------------------
\r
58 //------------------------------------------------------------------------------
\r
60 /// Transfer is pending.
\r
61 #define MCI_STATUS_PENDING 1
\r
62 /// Transfer has been aborted because an error occured.
\r
63 #define MCI_STATUS_ERROR 2
\r
64 /// Card did not answer command.
\r
65 #define MCI_STATUS_NORESPONSE 3
\r
67 /// MCI driver is currently in use.
\r
68 #define MCI_ERROR_LOCK 1
\r
70 /// MCI configuration with 1-bit data bus on slot A (for MMC cards).
\r
71 #define MCI_MMC_SLOTA 0
\r
72 /// MCI configuration with 1-bit data bus on slot B (for MMC cards).
\r
73 #define MCI_MMC_SLOTB 1
\r
74 /// MCI configuration with 4-bit data bus on slot A (for SD cards).
\r
75 #define MCI_SD_SLOTA AT91C_MCI_SCDBUS
\r
76 /// MCI configuration with 4-bit data bus on slot B (for SD cards).
\r
77 #define MCI_SD_SLOTB (AT91C_MCI_SCDBUS | 1)
\r
79 /// Start new data transfer
\r
80 #define MCI_NEW_TRANSFER 0
\r
81 /// Continue data transfer
\r
82 #define MCI_CONTINUE_TRANSFER 1
\r
84 /// MCI SD Bus Width 1-bit
\r
85 #define MCI_SDCBUS_1BIT (0 << 7)
\r
86 /// MCI SD Bus Width 4-bit
\r
87 #define MCI_SDCBUS_4BIT (1 << 7)
\r
89 //------------------------------------------------------------------------------
\r
91 //------------------------------------------------------------------------------
\r
93 /// MCI end-of-transfer callback function.
\r
94 typedef void (*MciCallback)(unsigned char status, void *pCommand);
\r
96 //------------------------------------------------------------------------------
\r
97 /// MCI Transfer Request prepared by the application upper layer. This structure
\r
98 /// is sent to the MCI_SendCommand function to start the transfer. At the end of
\r
99 /// the transfer, the callback is invoked by the interrupt handler.
\r
100 //------------------------------------------------------------------------------
\r
101 typedef struct _MciCmd {
\r
103 /// Command status.
\r
104 volatile char status;
\r
107 /// Command argument.
\r
110 unsigned char *pData;
\r
111 /// Size of data buffer in bytes.
\r
112 unsigned short blockSize;
\r
113 /// Number of blocks to be transfered
\r
114 unsigned short nbBlock;
\r
115 /// Indicate if continue to transfer data
\r
116 unsigned char conTrans;
\r
117 /// Indicates if the command is a read operation.
\r
118 unsigned char isRead;
\r
119 /// Response buffer.
\r
120 unsigned int *pResp;
\r
121 /// SD card response type.
\r
122 unsigned char resType;
\r
123 /// Optional user-provided callback function.
\r
124 MciCallback callback;
\r
125 /// Optional argument to the callback function.
\r
130 //------------------------------------------------------------------------------
\r
131 /// MCI driver structure. Holds the internal state of the MCI driver and
\r
132 /// prevents parallel access to a MCI peripheral.
\r
133 //------------------------------------------------------------------------------
\r
136 /// Pointer to a MCI peripheral.
\r
138 /// MCI peripheral identifier.
\r
139 unsigned char mciId;
\r
140 /// Pointer to currently executing command.
\r
143 volatile char semaphore;
\r
147 //------------------------------------------------------------------------------
\r
148 // Global functions
\r
149 //------------------------------------------------------------------------------
\r
151 extern void MCI_Init(
\r
154 unsigned char mciId,
\r
155 unsigned int mode);
\r
157 extern void MCI_SetSpeed(Mci *pMci, unsigned int mciSpeed);
\r
159 extern unsigned char MCI_SendCommand(Mci *pMci, MciCmd *pMciCmd);
\r
161 extern void MCI_Handler(Mci *pMci);
\r
163 extern unsigned char MCI_IsTxComplete(MciCmd *pMciCmd);
\r
165 extern unsigned char MCI_CheckBusy(Mci *pMci);
\r
167 extern void MCI_Close(Mci *pMci);
\r
169 extern void MCI_SetBusWidth(Mci *pMci, unsigned char busWidth);
\r
171 #endif //#ifndef MCI_H
\r