]> git.sur5r.net Git - freertos/blob - Demo/Common/drivers/Atmel/at91lib/peripherals/mci/mci.h
Atmel provided hardware specifics.
[freertos] / Demo / Common / drivers / Atmel / at91lib / peripherals / mci / mci.h
1 /* ----------------------------------------------------------------------------\r
2  *         ATMEL Microcontroller Software Support  -  ROUSSET  -\r
3  * ----------------------------------------------------------------------------\r
4  * Copyright (c) 2006, Atmel Corporation\r
5 \r
6  * All rights reserved.\r
7  *\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
10  *\r
11  * - Redistributions of source code must retain the above copyright notice,\r
12  * this list of conditions and the disclaimer below.\r
13  *\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
17  *\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
20  *\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
32  */\r
33 \r
34 #ifndef MCI_H\r
35 #define MCI_H\r
36 \r
37 //------------------------------------------------------------------------------\r
38 //         Headers\r
39 //------------------------------------------------------------------------------\r
40 \r
41 #include <board.h>\r
42 \r
43 //------------------------------------------------------------------------------\r
44 //         Constants\r
45 //------------------------------------------------------------------------------\r
46 \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
53 \r
54 /// MCI driver is currently in use.\r
55 #define MCI_ERROR_LOCK    1\r
56 \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
65 \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
70 \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
75 \r
76 //------------------------------------------------------------------------------\r
77 //         Types\r
78 //------------------------------------------------------------------------------\r
79 \r
80 /// MCI end-of-transfer callback function.\r
81 typedef void (*MciCallback)(unsigned char status, void *pCommand);\r
82 \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
89 \r
90     /// Command status.\r
91         volatile char status;\r
92     /// Command code.\r
93         unsigned int cmd;\r
94     /// Command argument.\r
95         unsigned int arg;\r
96     /// Data buffer.\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
113         void *pArg;\r
114 \r
115 } MciCmd;\r
116 \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
121 typedef struct {\r
122 \r
123     /// Pointer to a MCI peripheral.\r
124         AT91S_MCI *pMciHw;\r
125     /// MCI peripheral identifier.\r
126     unsigned char mciId;\r
127     /// Pointer to currently executing command.\r
128         MciCmd *pCommand;\r
129         /// Mutex.\r
130         volatile char semaphore;\r
131 \r
132 } Mci;\r
133 \r
134 //------------------------------------------------------------------------------\r
135 //         Global functions\r
136 //------------------------------------------------------------------------------\r
137 \r
138 extern void MCI_Init(\r
139     Mci *pMci,\r
140     AT91PS_MCI pMciHw,\r
141     unsigned char mciId,\r
142     unsigned int mode);\r
143 \r
144 extern void MCI_SetSpeed(Mci *pMci, unsigned int mciSpeed);\r
145 \r
146 extern unsigned char MCI_SendCommand(Mci *pMci, MciCmd *pMciCmd);\r
147 \r
148 extern void MCI_Handler(Mci *pMci);\r
149 \r
150 extern unsigned char MCI_IsTxComplete(MciCmd *pMciCmd);\r
151 \r
152 extern unsigned char MCI_CheckBusy(Mci *pMci);\r
153 \r
154 extern void MCI_Close(Mci *pMci);\r
155 \r
156 extern void MCI_SetBusWidth(Mci *pMci, unsigned char busWidth);\r
157 \r
158 #endif //#ifndef MCI_H\r
159 \r