OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [freertos-6.1.1/] [Demo/] [CORTEX_AT91SAM3U256_IAR/] [AT91Lib/] [peripherals/] [mci/] [mci_hs.h] - Blame information for rev 580

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 580 jeremybenn
/* ----------------------------------------------------------------------------
2
 *         ATMEL Microcontroller Software Support
3
 * ----------------------------------------------------------------------------
4
 * Copyright (c) 2008, Atmel Corporation
5
 *
6
 * All rights reserved.
7
 *
8
 * Redistribution and use in source and binary forms, with or without
9
 * modification, are permitted provided that the following conditions are met:
10
 *
11
 * - Redistributions of source code must retain the above copyright notice,
12
 * this list of conditions and the disclaimer below.
13
 *
14
 * Atmel's name may not be used to endorse or promote products derived from
15
 * this software without specific prior written permission.
16
 *
17
 * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
18
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
20
 * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
21
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
23
 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
24
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
25
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
26
 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
 * ----------------------------------------------------------------------------
28
 */
29
 
30
//------------------------------------------------------------------------------
31
/// \page "mci"
32
///
33
/// !Purpose
34
///  
35
/// mci-interface driver
36
///
37
/// !Usage
38
///
39
/// -# MCI_Init: Initializes a MCI driver instance and the underlying peripheral.
40
/// -# MCI_SetSpeed : Configure the  MCI CLKDIV in the MCI_MR register.
41
/// -# MCI_SendCommand: Starts a MCI  transfer.
42
/// -# MCI_Handler : Interrupt handler which is called by ISR handler.
43
/// -# MCI_SetBusWidth : Configure the  MCI SDCBUS in the MCI_SDCR register.
44
//------------------------------------------------------------------------------
45
 
46
 
47
#ifndef MCI_HS_H
48
#define MCI_HS_H
49
 
50
//------------------------------------------------------------------------------
51
//         Headers
52
//------------------------------------------------------------------------------
53
 
54
#include <board.h>
55
 
56
//------------------------------------------------------------------------------
57
//         Constants
58
//------------------------------------------------------------------------------
59
 
60
/// Transfer is pending.
61
#define MCI_STATUS_PENDING      1
62
/// Transfer has been aborted because an error occured.
63
#define MCI_STATUS_ERROR        2
64
/// Card did not answer command.
65
#define MCI_STATUS_NORESPONSE   3
66
 
67
/// MCI driver is currently in use.
68
#define MCI_ERROR_LOCK    1
69
 
70
/// MCI configuration with 1-bit data bus on slot A (for MMC cards).
71
#define MCI_MMC_SLOTA           (AT91C_MCI_SCDSEL_SLOTA | AT91C_MCI_SCDBUS_1BIT)
72
/// MCI configuration with 4-bit data bus on slot A (for SD cards).
73
#define MCI_SD_SLOTA            (AT91C_MCI_SCDSEL_SLOTA | AT91C_MCI_SCDBUS_4BITS)
74
#ifdef AT91C_MCI_SCDBUS_8BITS
75
/// MCI configuration with 1-bit data bus on slot A (for MMC cards).
76
#define MCI_MMC4_SLOTA          (AT91C_MCI_SCDSEL_SLOTA | AT91C_MCI_SCDBUS_8BITS)
77
#endif
78
#ifdef AT91C_MCI_SCDSEL_SLOTB
79
/// MCI configuration with 1-bit data bus on slot B (for MMC cards).
80
#define MCI_MMC_SLOTB           (AT91C_MCI_SCDSEL_SLOTB | AT91C_MCI_SCDBUS_1BIT)
81
/// MCI configuration with 4-bit data bus on slot B (for SD cards).
82
#define MCI_SD_SLOTB            (AT91C_MCI_SCDSEL_SLOTB | AT91C_MCI_SCDBUS_4BITS)
83
#ifdef AT91C_MCI_SCDBUS_8BITS
84
/// MCI configuration with 1-bit data bus on slot A (for MMC cards).
85
#define MCI_MMC4_SLOTB          (AT91C_MCI_SCDSEL_SLOTB | AT91C_MCI_SCDBUS_8BITS)
86
#endif
87
#else
88
#define MCI_MMC_SLOTB           MCI_MMC_SLOTA
89
#define MCI_SD_SLOTB            MCI_SD_SLOTA
90
#endif
91
 
92
/// Start new data transfer
93
#define MCI_NEW_TRANSFER        0
94
/// Continue data transfer
95
#define MCI_CONTINUE_TRANSFER   1
96
/// Stop data transfer
97
#define MCI_STOP_TRANSFER       2
98
 
99
/// MCI SD Bus Width 1-bit
100
#define MCI_SDCBUS_1BIT (0 << 7)
101
/// MCI SD Bus Width 4-bit
102
#define MCI_SDCBUS_4BIT (1 << 7)
103
/// MCI SD Bus Width 8-bit
104
#define MCI_SDCBUS_8BIT (3 << 6)
105
 
106
/// The MCI Clock Speed after initialize (400K)
107
#define MCI_INITIAL_SPEED       400000
108
 
109
/// MCI using DMA?
110
#define MCI_DMA_ENABLE          1
111
 
112
//------------------------------------------------------------------------------
113
//         Types
114
//------------------------------------------------------------------------------
115
 
116
/// MCI end-of-transfer callback function.
117
typedef void (*MciCallback)(unsigned char status, void *pCommand);
118
 
119
//------------------------------------------------------------------------------
120
/// MCI Transfer Request prepared by the application upper layer. This structure
121
/// is sent to the MCI_SendCommand function to start the transfer. At the end of
122
/// the transfer, the callback is invoked by the interrupt handler.
123
//------------------------------------------------------------------------------
124
typedef struct _MciCmd {
125
 
126
    /// Command code.
127
    unsigned int cmd;
128
    /// Command argument.
129
    unsigned int arg;
130
    /// Data buffer.
131
    unsigned char *pData;
132
    /// Size of data block in bytes.
133
    unsigned short blockSize;
134
    /// Number of blocks to be transfered
135
    unsigned short nbBlock;
136
    /// Response buffer.
137
    unsigned int  *pResp;
138
    /// Optional user-provided callback function.
139
    MciCallback callback;
140
    /// Optional argument to the callback function.
141
    void *pArg;
142
    /// SD card response type.
143
    unsigned char  resType;
144
    /// Indicate if there is data transfer
145
    unsigned char dataTran;
146
    /// Indicate if continue to transfer data
147
    unsigned char tranType;
148
    /// Indicates if the command is a read operation.
149
    unsigned char isRead;
150
 
151
    /// Command status.
152
    volatile int status;
153
} MciCmd;
154
 
155
//------------------------------------------------------------------------------
156
/// MCI driver structure. Holds the internal state of the MCI driver and
157
/// prevents parallel access to a MCI peripheral.
158
//------------------------------------------------------------------------------
159
typedef struct {
160
 
161
    /// Pointer to a MCI peripheral.
162
    AT91S_MCI *pMciHw;
163
    /// Pointer to currently executing command.
164
    MciCmd *pCommand;
165
    /// MCI peripheral identifier.
166
    unsigned char mciId;
167
    /// MCI HW mode
168
    unsigned char mciMode;
169
    /// Mutex.
170
    volatile char semaphore;
171
} Mci;
172
 
173
//------------------------------------------------------------------------------
174
//         Global functions
175
//------------------------------------------------------------------------------
176
 
177
extern void MCI_Init(
178
    Mci *pMci,
179
    AT91PS_MCI pMciHw,
180
    unsigned char mciId,
181
    unsigned int mode);
182
extern unsigned int MCI_GetSpeed(Mci *pMci, unsigned int *mciDiv);
183
 
184
extern unsigned int MCI_SetSpeed(Mci *pMci,
185
                                 unsigned int mciSpeed,
186
                                 unsigned int mciLimit);
187
 
188
extern unsigned char MCI_SendCommand(Mci *pMci, MciCmd *pMciCmd);
189
 
190
extern void MCI_Handler(Mci *pMci);
191
 
192
extern unsigned char MCI_IsTxComplete(MciCmd *pMciCmd);
193
 
194
extern unsigned char MCI_CheckBusy(Mci *pMci);
195
 
196
extern void MCI_Close(Mci *pMci);
197
 
198
extern void MCI_EnableHsMode(Mci * pMci, unsigned char hsEnable);
199
 
200
extern void MCI_SetBusWidth(Mci *pMci, unsigned char busWidth);
201
 
202
extern unsigned int MCI_FifoTransfer(Mci * pMci, MciCmd * pCommand);
203
 
204
#endif //#ifndef MCI_HS_H
205
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.