LPCOpen Platform
v1.03
LPCOpen Platform for NXP LPC Microcontrollers
Main Page
Modules
Data Structures
Files
Related Pages
File List
Globals
All
Data Structures
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Macros
Groups
Pages
sdc_001.c
Go to the documentation of this file.
1
/*
2
* @brief SD Card Interface registers and control functions
3
*
4
* @note
5
* Copyright(C) NXP Semiconductors, 2012
6
* All rights reserved.
7
*
8
* @par
9
* Software that is described herein is for illustrative purposes only
10
* which provides customers with programming information regarding the
11
* LPC products. This software is supplied "AS IS" without any warranties of
12
* any kind, and NXP Semiconductors and its licensor disclaim any and
13
* all warranties, express or implied, including all implied warranties of
14
* merchantability, fitness for a particular purpose and non-infringement of
15
* intellectual property rights. NXP Semiconductors assumes no responsibility
16
* or liability for the use of the software, conveys no license or rights under any
17
* patent, copyright, mask work right, or any other intellectual property rights in
18
* or to any products. NXP Semiconductors reserves the right to make changes
19
* in the software without notification. NXP Semiconductors also makes no
20
* representation or warranty that such application will be suitable for the
21
* specified use without further testing or modification.
22
*
23
* @par
24
* Permission to use, copy, modify, and distribute this software and its
25
* documentation is hereby granted, under NXP Semiconductors' and its
26
* licensor's relevant copyrights in the software, without fee, provided that it
27
* is used in conjunction with NXP Semiconductors microcontrollers. This
28
* copyright, permission, and disclaimer notice must appear in all copies of
29
* this code.
30
*/
31
32
#include "
sdc_001.h
"
33
34
/*****************************************************************************
35
* Private types/enumerations/variables
36
****************************************************************************/
37
38
static
void
writeDelay
(
void
)
39
{
40
volatile
uint8_t i;
41
for
( i = 0; i < 0x10; i++ ) {
/* delay 3MCLK + 2PCLK */
42
}
43
}
44
45
/*****************************************************************************
46
* Public types/enumerations/variables
47
****************************************************************************/
48
49
/*****************************************************************************
50
* Private functions
51
****************************************************************************/
52
53
/*****************************************************************************
54
* Public functions
55
****************************************************************************/
56
57
/* Set power state of SDC peripheral */
58
void
IP_SDC_PowerControl
(
IP_SDC_001_T
*pSDC,
IP_SDC_001_PWR_CTRL_T
pwrMode,
uint32_t
flag)
59
{
60
pSDC->
POWER
=
SDC_PWR_CTRL
(pwrMode) | flag;
61
writeDelay
();
62
}
63
64
/* Set clock divider for SDC peripheral */
65
void
IP_SDC_SetClockDiv
(
IP_SDC_001_T
*pSDC, uint8_t div)
66
{
67
uint32_t
temp;
68
temp = (pSDC->
CLOCK
& (~
SDC_CLOCK_CLKDIV_BITMASK
));
69
pSDC->
CLOCK
= temp | (
SDC_CLOCK_CLKDIV
(div));
70
writeDelay
();
71
}
72
73
/* Clock control for SDC peripheral*/
74
void
IP_SDC_ClockControl
(
IP_SDC_001_T
*pSDC,
IP_SDC_001_CLOCK_CTRL_T
ctrlType,
75
FunctionalState
NewState)
76
{
77
if
(NewState) {
78
pSDC->
CLOCK
|= (1 << ctrlType);
79
}
80
else
{
81
pSDC->
CLOCK
&= (~(1 << ctrlType));
82
}
83
writeDelay
();
84
}
85
86
/* Initialize SDC peripheral */
87
void
IP_SDC_Init
(
IP_SDC_001_T
*pSDC)
88
{
89
/* Disable SD_CLK */
90
IP_SDC_ClockControl
(pSDC,
SDC_CLOCK_ENABLE
,
DISABLE
);
91
92
/* Power-off */
93
IP_SDC_PowerControl
(pSDC,
SDC_POWER_OFF
, 0);
94
writeDelay
();
95
96
/* Disable all interrupts */
97
pSDC->
MASK0
= 0;
98
99
/*Setting for timeout problem */
100
pSDC->
DATATIMER
= 0x1FFFFFFF;
101
102
pSDC->
COMMAND
= 0;
103
writeDelay
();
104
105
pSDC->
DATACTRL
= 0;
106
writeDelay
();
107
108
/* clear all pending interrupts */
109
pSDC->
CLEAR
=
SDC_CLEAR_ALL
;
110
}
111
112
/* Set Command Info */
113
void
IP_SDC_SetCommand
(
IP_SDC_001_T
*pSDC,
uint32_t
Cmd,
uint32_t
Arg)
114
{
115
/* Clear status register */
116
pSDC->
CLEAR
=
SDC_CLEAR_ALL
;
117
118
/* Set the argument first, finally command */
119
pSDC->
ARGUMENT
= Arg;
120
121
/* Write command value, enable the command */
122
pSDC->
COMMAND
= Cmd |
SDC_COMMAND_ENABLE
;
123
124
writeDelay
();
125
}
126
127
/* Reset Command Info */
128
void
IP_SDC_ResetCommand
(
IP_SDC_001_T
*pSDC)
129
{
130
pSDC->
CLEAR
=
SDC_CLEAR_ALL
;
131
132
pSDC->
ARGUMENT
= 0xFFFFFFFF;
133
134
pSDC->
COMMAND
= 0;
135
136
writeDelay
();
137
}
138
139
/* Get Command response */
140
void
IP_SDC_GetResp
(
IP_SDC_001_T
*pSDC,
IP_SDC_001_RESP_T
*pResp)
141
{
142
uint8_t i;
143
pResp->
CmdIndex
=
SDC_RESPCOMMAND_VAL
(pSDC->
RESPCMD
);
144
for
(i = 0; i <
SDC_CARDSTATUS_BYTENUM
; i++) {
145
pResp->
Data
[i] = pSDC->
RESPONSE
[i];
146
}
147
}
148
149
/* Setup Data Transfer Information */
150
void
IP_SDC_SetDataTransfer
(
IP_SDC_001_T
*pSDC,
IP_SDC_001_DATA_TRANSFER_T
*pTransfer)
151
{
152
uint32_t
DataCtrl = 0;
153
pSDC->
DATATIMER
= pTransfer->
Timeout
;
154
pSDC->
DATALENGTH
= pTransfer->
BlockNum
*
SDC_DATACTRL_BLOCKSIZE_VAL
(pTransfer->
BlockSize
);
155
DataCtrl =
SDC_DATACTRL_ENABLE
;
156
DataCtrl |= ((
uint32_t
)pTransfer->
Dir
) | ((
uint32_t
)pTransfer->
Mode
) |
SDC_DATACTRL_BLOCKSIZE
(pTransfer->
BlockSize
);
157
if
(pTransfer->
DMAUsed
) {
158
DataCtrl |=
SDC_DATACTRL_DMA_ENABLE
;
159
}
160
pSDC->
DATACTRL
= DataCtrl;
161
writeDelay
();
162
}
163
164
/* Write data to FIFO */
165
void
IP_SDC_WriteFIFO
(
IP_SDC_001_T
*pSDC,
uint32_t
*pSrc,
bool
bFirstHalf)
166
{
167
uint8_t
start
= 0, end = 7;
168
if
(!bFirstHalf) {
169
start += 8;
170
end += 8;
171
}
172
for
(; start <= end; start++) {
173
pSDC->
FIFO
[
start
] = *pSrc;
174
pSrc++;
175
}
176
}
177
178
/* Read data from FIFO */
179
void
IP_SDC_ReadFIFO
(
IP_SDC_001_T
*pSDC,
uint32_t
*pDst,
bool
bFirstHalf)
180
{
181
uint8_t
start
= 0, end = 7;
182
183
if
(!bFirstHalf) {
184
start += 8;
185
end += 8;
186
}
187
for
(; start <= end; start++) {
188
*pDst = pSDC->
FIFO
[
start
];
189
pDst++;
190
}
191
}
192
software
lpc_core
lpc_ip
sdc_001.c
Generated on Fri May 10 2013 10:42:19 for LPCOpen Platform by
1.8.2