1 /* ----------------------------------------------------------------------------
\r
2 * ATMEL Microcontroller Software Support - ROUSSET -
\r
3 * ----------------------------------------------------------------------------
\r
4 * Copyright (c) 2006, 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 * - Redistributions in binary form must reproduce the above copyright notice,
\r
15 * this list of conditions and the disclaimer below in the documentation and/or
\r
16 * other materials provided with the distribution.
\r
18 * Atmel's name may not be used to endorse or promote products derived from
\r
19 * this software without specific prior written permission.
\r
21 * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
\r
22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
\r
23 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
\r
24 * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
\r
25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
\r
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
\r
27 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
\r
28 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
\r
29 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
\r
30 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\r
31 * ----------------------------------------------------------------------------
\r
37 //------------------------------------------------------------------------------
\r
39 //------------------------------------------------------------------------------
\r
43 //------------------------------------------------------------------------------
\r
45 //------------------------------------------------------------------------------
\r
47 /// Transfer is pending.
\r
48 #define MCI_STATUS_PENDING 1
\r
49 /// Transfer has been aborted because an error occured.
\r
50 #define MCI_STATUS_ERROR 2
\r
51 /// Card did not answer command.
\r
52 #define MCI_STATUS_NORESPONSE 3
\r
54 /// MCI driver is currently in use.
\r
55 #define MCI_ERROR_LOCK 1
\r
57 /// MCI configuration with 1-bit data bus on slot A (for MMC cards).
\r
58 #define MCI_MMC_SLOTA 0
\r
59 /// MCI configuration with 1-bit data bus on slot B (for MMC cards).
\r
60 #define MCI_MMC_SLOTB 1
\r
61 /// MCI configuration with 4-bit data bus on slot A (for SD cards).
\r
62 #define MCI_SD_SLOTA AT91C_MCI_SCDBUS
\r
63 /// MCI configuration with 4-bit data bus on slot B (for SD cards).
\r
64 #define MCI_SD_SLOTB (AT91C_MCI_SCDBUS | 1)
\r
66 /// Start new data transfer
\r
67 #define MCI_NEW_TRANSFER 0
\r
68 /// Continue data transfer
\r
69 #define MCI_CONTINUE_TRANSFER 1
\r
71 /// MCI SD Bus Width 1-bit
\r
72 #define MCI_SDCBUS_1BIT (0 << 7)
\r
73 /// MCI SD Bus Width 4-bit
\r
74 #define MCI_SDCBUS_4BIT (1 << 7)
\r
76 //------------------------------------------------------------------------------
\r
78 //------------------------------------------------------------------------------
\r
80 /// MCI end-of-transfer callback function.
\r
81 typedef void (*MciCallback)(unsigned char status, void *pCommand);
\r
83 //------------------------------------------------------------------------------
\r
84 /// MCI Transfer Request prepared by the application upper layer. This structure
\r
85 /// is sent to the MCI_SendCommand function to start the transfer. At the end of
\r
86 /// the transfer, the callback is invoked by the interrupt handler.
\r
87 //------------------------------------------------------------------------------
\r
88 typedef struct _MciCmd {
\r
91 volatile char status;
\r
94 /// Command argument.
\r
97 unsigned char *pData;
\r
98 /// Size of data buffer in bytes.
\r
99 unsigned short blockSize;
\r
100 /// Number of blocks to be transfered
\r
101 unsigned short nbBlock;
\r
102 /// Indicate if continue to transfer data
\r
103 unsigned char conTrans;
\r
104 /// Indicates if the command is a read operation.
\r
105 unsigned char isRead;
\r
106 /// Response buffer.
\r
107 unsigned int *pResp;
\r
108 /// Size of SD card response in bytes.
\r
109 unsigned char resSize;
\r
110 /// Optional user-provided callback function.
\r
111 MciCallback callback;
\r
112 /// Optional argument to the callback function.
\r
117 //------------------------------------------------------------------------------
\r
118 /// MCI driver structure. Holds the internal state of the MCI driver and
\r
119 /// prevents parallel access to a MCI peripheral.
\r
120 //------------------------------------------------------------------------------
\r
123 /// Pointer to a MCI peripheral.
\r
125 /// MCI peripheral identifier.
\r
126 unsigned char mciId;
\r
127 /// Pointer to currently executing command.
\r
130 volatile char semaphore;
\r
134 //------------------------------------------------------------------------------
\r
135 // Global functions
\r
136 //------------------------------------------------------------------------------
\r
138 extern void MCI_Init(
\r
141 unsigned char mciId,
\r
142 unsigned int mode);
\r
144 extern void MCI_SetSpeed(Mci *pMci, unsigned int mciSpeed);
\r
146 extern unsigned char MCI_SendCommand(Mci *pMci, MciCmd *pMciCmd);
\r
148 extern void MCI_Handler(Mci *pMci);
\r
150 extern unsigned char MCI_IsTxComplete(MciCmd *pMciCmd);
\r
152 extern unsigned char MCI_CheckBusy(Mci *pMci);
\r
154 extern void MCI_Close(Mci *pMci);
\r
156 extern void MCI_SetBusWidth(Mci *pMci, unsigned char busWidth);
\r
158 #endif //#ifndef MCI_H
\r