]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/mci/mci.h
Add FreeRTOS-Plus directory.
[freertos] / FreeRTOS / Demo / CORTEX_AT91SAM3U256_IAR / AT91Lib / peripherals / mci / mci.h
1 /* ----------------------------------------------------------------------------\r
2  *         ATMEL Microcontroller Software Support\r
3  * ----------------------------------------------------------------------------\r
4  * Copyright (c) 2008, 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  * Atmel's name may not be used to endorse or promote products derived from\r
15  * this software without specific prior written permission.\r
16  *\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
28  */\r
29 \r
30 //------------------------------------------------------------------------------\r
31 /// \page "mci"\r
32 ///\r
33 /// !Purpose\r
34 ///  \r
35 /// mci-interface driver\r
36 ///\r
37 /// !Usage\r
38 ///\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
45 \r
46 \r
47 #ifndef MCI_H\r
48 #define MCI_H\r
49 \r
50 //------------------------------------------------------------------------------\r
51 //         Headers\r
52 //------------------------------------------------------------------------------\r
53 \r
54 #include <board.h>\r
55 \r
56 //------------------------------------------------------------------------------\r
57 //         Constants\r
58 //------------------------------------------------------------------------------\r
59 \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
66 \r
67 /// MCI driver is currently in use.\r
68 #define MCI_ERROR_LOCK    1\r
69 \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
78 \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
83 \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
88 \r
89 //------------------------------------------------------------------------------\r
90 //         Types\r
91 //------------------------------------------------------------------------------\r
92 \r
93 /// MCI end-of-transfer callback function.\r
94 typedef void (*MciCallback)(unsigned char status, void *pCommand);\r
95 \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
102 \r
103     /// Command status.\r
104         volatile char status;\r
105     /// Command code.\r
106         unsigned int cmd;\r
107     /// Command argument.\r
108         unsigned int arg;\r
109     /// Data buffer.\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
126         void *pArg;\r
127 \r
128 } MciCmd;\r
129 \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
134 typedef struct {\r
135 \r
136     /// Pointer to a MCI peripheral.\r
137         AT91S_MCI *pMciHw;\r
138     /// MCI peripheral identifier.\r
139     unsigned char mciId;\r
140     /// Pointer to currently executing command.\r
141         MciCmd *pCommand;\r
142         /// Mutex.\r
143         volatile char semaphore;\r
144 \r
145 } Mci;\r
146 \r
147 //------------------------------------------------------------------------------\r
148 //         Global functions\r
149 //------------------------------------------------------------------------------\r
150 \r
151 extern void MCI_Init(\r
152     Mci *pMci,\r
153     AT91PS_MCI pMciHw,\r
154     unsigned char mciId,\r
155     unsigned int mode);\r
156 \r
157 extern void MCI_SetSpeed(Mci *pMci, unsigned int mciSpeed);\r
158 \r
159 extern unsigned char MCI_SendCommand(Mci *pMci, MciCmd *pMciCmd);\r
160 \r
161 extern void MCI_Handler(Mci *pMci);\r
162 \r
163 extern unsigned char MCI_IsTxComplete(MciCmd *pMciCmd);\r
164 \r
165 extern unsigned char MCI_CheckBusy(Mci *pMci);\r
166 \r
167 extern void MCI_Close(Mci *pMci);\r
168 \r
169 extern void MCI_SetBusWidth(Mci *pMci, unsigned char busWidth);\r
170 \r
171 #endif //#ifndef MCI_H\r
172 \r