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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [freertos-6.1.1/] [Demo/] [Common/] [drivers/] [ST/] [STM32F10xFWLib/] [src/] [stm32f10x_sdio.c] - Blame information for rev 608

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 608 jeremybenn
/**
2
  ******************************************************************************
3
  * @file  stm32f10x_sdio.c
4
  * @author  MCD Application Team
5
  * @version  V3.0.0
6
  * @date  04/06/2009
7
  * @brief  This file provides all the SDIO firmware functions.
8
  ******************************************************************************
9
  * @copy
10
  *
11
  * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
12
  * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
13
  * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
14
  * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
15
  * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
16
  * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
17
  *
18
  * <h2><center>&copy; COPYRIGHT 2009 STMicroelectronics</center></h2>
19
  */
20
 
21
/* Includes ------------------------------------------------------------------*/
22
#include "stm32f10x_sdio.h"
23
#include "stm32f10x_rcc.h"
24
 
25
/** @addtogroup StdPeriph_Driver
26
  * @{
27
  */
28
 
29
/** @defgroup SDIO
30
  * @brief SDIO driver modules
31
  * @{
32
  */
33
 
34
/** @defgroup SDIO_Private_TypesDefinitions
35
  * @{
36
  */
37
 
38
/* ------------ SDIO registers bit address in the alias region ----------- */
39
#define SDIO_OFFSET                (SDIO_BASE - PERIPH_BASE)
40
 
41
/* --- CLKCR Register ---*/
42
 
43
/* Alias word address of CLKEN bit */
44
#define CLKCR_OFFSET              (SDIO_OFFSET + 0x04)
45
#define CLKEN_BitNumber           0x08
46
#define CLKCR_CLKEN_BB            (PERIPH_BB_BASE + (CLKCR_OFFSET * 32) + (CLKEN_BitNumber * 4))
47
 
48
/* --- CMD Register ---*/
49
 
50
/* Alias word address of SDIOSUSPEND bit */
51
#define CMD_OFFSET                (SDIO_OFFSET + 0x0C)
52
#define SDIOSUSPEND_BitNumber     0x0B
53
#define CMD_SDIOSUSPEND_BB        (PERIPH_BB_BASE + (CMD_OFFSET * 32) + (SDIOSUSPEND_BitNumber * 4))
54
 
55
/* Alias word address of ENCMDCOMPL bit */
56
#define ENCMDCOMPL_BitNumber      0x0C
57
#define CMD_ENCMDCOMPL_BB         (PERIPH_BB_BASE + (CMD_OFFSET * 32) + (ENCMDCOMPL_BitNumber * 4))
58
 
59
/* Alias word address of NIEN bit */
60
#define NIEN_BitNumber            0x0D
61
#define CMD_NIEN_BB               (PERIPH_BB_BASE + (CMD_OFFSET * 32) + (NIEN_BitNumber * 4))
62
 
63
/* Alias word address of ATACMD bit */
64
#define ATACMD_BitNumber          0x0E
65
#define CMD_ATACMD_BB             (PERIPH_BB_BASE + (CMD_OFFSET * 32) + (ATACMD_BitNumber * 4))
66
 
67
/* --- DCTRL Register ---*/
68
 
69
/* Alias word address of DMAEN bit */
70
#define DCTRL_OFFSET              (SDIO_OFFSET + 0x2C)
71
#define DMAEN_BitNumber           0x03
72
#define DCTRL_DMAEN_BB            (PERIPH_BB_BASE + (DCTRL_OFFSET * 32) + (DMAEN_BitNumber * 4))
73
 
74
/* Alias word address of RWSTART bit */
75
#define RWSTART_BitNumber         0x08
76
#define DCTRL_RWSTART_BB          (PERIPH_BB_BASE + (DCTRL_OFFSET * 32) + (RWSTART_BitNumber * 4))
77
 
78
/* Alias word address of RWSTOP bit */
79
#define RWSTOP_BitNumber          0x09
80
#define DCTRL_RWSTOP_BB           (PERIPH_BB_BASE + (DCTRL_OFFSET * 32) + (RWSTOP_BitNumber * 4))
81
 
82
/* Alias word address of RWMOD bit */
83
#define RWMOD_BitNumber           0x0A
84
#define DCTRL_RWMOD_BB            (PERIPH_BB_BASE + (DCTRL_OFFSET * 32) + (RWMOD_BitNumber * 4))
85
 
86
/* Alias word address of SDIOEN bit */
87
#define SDIOEN_BitNumber          0x0B
88
#define DCTRL_SDIOEN_BB           (PERIPH_BB_BASE + (DCTRL_OFFSET * 32) + (SDIOEN_BitNumber * 4))
89
 
90
/* ---------------------- SDIO registers bit mask ------------------------ */
91
 
92
/* --- CLKCR Register ---*/
93
 
94
/* CLKCR register clear mask */
95
#define CLKCR_CLEAR_MASK         ((uint32_t)0xFFFF8100) 
96
 
97
/* --- PWRCTRL Register ---*/
98
 
99
/* SDIO PWRCTRL Mask */
100
#define PWR_PWRCTRL_MASK         ((uint32_t)0xFFFFFFFC)
101
 
102
/* --- DCTRL Register ---*/
103
 
104
/* SDIO DCTRL Clear Mask */
105
#define DCTRL_CLEAR_MASK         ((uint32_t)0xFFFFFF08)
106
 
107
/* --- CMD Register ---*/
108
 
109
/* CMD Register clear mask */
110
#define CMD_CLEAR_MASK           ((uint32_t)0xFFFFF800)
111
 
112
/* SDIO RESP Registers Address */
113
#define SDIO_RESP_ADDR           ((uint32_t)(SDIO_BASE + 0x14))
114
 
115
/**
116
  * @}
117
  */
118
 
119
/** @defgroup SDIO_Private_Defines
120
  * @{
121
  */
122
 
123
/**
124
  * @}
125
  */
126
 
127
/** @defgroup SDIO_Private_Macros
128
  * @{
129
  */
130
 
131
/**
132
  * @}
133
  */
134
 
135
/** @defgroup SDIO_Private_Variables
136
  * @{
137
  */
138
 
139
/**
140
  * @}
141
  */
142
 
143
/** @defgroup SDIO_Private_FunctionPrototypes
144
  * @{
145
  */
146
 
147
/**
148
  * @}
149
  */
150
 
151
/** @defgroup SDIO_Private_Functions
152
  * @{
153
  */
154
 
155
/**
156
  * @brief  Deinitializes the SDIO peripheral registers to their default
157
  *   reset values.
158
  * @param  None
159
  * @retval : None
160
  */
161
void SDIO_DeInit(void)
162
{
163
  SDIO->POWER = 0x00000000;
164
  SDIO->CLKCR = 0x00000000;
165
  SDIO->ARG = 0x00000000;
166
  SDIO->CMD = 0x00000000;
167
  SDIO->DTIMER = 0x00000000;
168
  SDIO->DLEN = 0x00000000;
169
  SDIO->DCTRL = 0x00000000;
170
  SDIO->ICR = 0x00C007FF;
171
  SDIO->MASK = 0x00000000;
172
}
173
 
174
/**
175
  * @brief  Initializes the SDIO peripheral according to the specified
176
  *   parameters in the SDIO_InitStruct.
177
  * @param SDIO_InitStruct : pointer to a SDIO_InitTypeDef structure
178
  *   that contains the configuration information for the SDIO
179
  *   peripheral.
180
  * @retval : None
181
  */
182
void SDIO_Init(SDIO_InitTypeDef* SDIO_InitStruct)
183
{
184
  uint32_t tmpreg = 0;
185
 
186
  /* Check the parameters */
187
  assert_param(IS_SDIO_CLOCK_EDGE(SDIO_InitStruct->SDIO_ClockEdge));
188
  assert_param(IS_SDIO_CLOCK_BYPASS(SDIO_InitStruct->SDIO_ClockBypass));
189
  assert_param(IS_SDIO_CLOCK_POWER_SAVE(SDIO_InitStruct->SDIO_ClockPowerSave));
190
  assert_param(IS_SDIO_BUS_WIDE(SDIO_InitStruct->SDIO_BusWide));
191
  assert_param(IS_SDIO_HARDWARE_FLOW_CONTROL(SDIO_InitStruct->SDIO_HardwareFlowControl));
192
 
193
/*---------------------------- SDIO CLKCR Configuration ------------------------*/
194
  /* Get the SDIO CLKCR value */
195
  tmpreg = SDIO->CLKCR;
196
 
197
  /* Clear CLKDIV, PWRSAV, BYPASS, WIDBUS, NEGEDGE, HWFC_EN bits */
198
  tmpreg &= CLKCR_CLEAR_MASK;
199
 
200
  /* Set CLKDIV bits according to SDIO_ClockDiv value */
201
  /* Set PWRSAV bit according to SDIO_ClockPowerSave value */
202
  /* Set BYPASS bit according to SDIO_ClockBypass value */
203
  /* Set WIDBUS bits according to SDIO_BusWide value */
204
  /* Set NEGEDGE bits according to SDIO_ClockEdge value */
205
  /* Set HWFC_EN bits according to SDIO_HardwareFlowControl value */
206
  tmpreg |= (SDIO_InitStruct->SDIO_ClockDiv  | SDIO_InitStruct->SDIO_ClockPowerSave |
207
             SDIO_InitStruct->SDIO_ClockBypass | SDIO_InitStruct->SDIO_BusWide |
208
             SDIO_InitStruct->SDIO_ClockEdge | SDIO_InitStruct->SDIO_HardwareFlowControl);
209
 
210
  /* Write to SDIO CLKCR */
211
  SDIO->CLKCR = tmpreg;
212
}
213
 
214
/**
215
  * @brief  Fills each SDIO_InitStruct member with its default value.
216
  * @param SDIO_InitStruct: pointer to an SDIO_InitTypeDef structure which
217
  *   will be initialized.
218
  * @retval : None
219
  */
220
void SDIO_StructInit(SDIO_InitTypeDef* SDIO_InitStruct)
221
{
222
  /* SDIO_InitStruct members default value */
223
  SDIO_InitStruct->SDIO_ClockDiv = 0x00;
224
  SDIO_InitStruct->SDIO_ClockEdge = SDIO_ClockEdge_Rising;
225
  SDIO_InitStruct->SDIO_ClockBypass = SDIO_ClockBypass_Disable;
226
  SDIO_InitStruct->SDIO_ClockPowerSave = SDIO_ClockPowerSave_Disable;
227
  SDIO_InitStruct->SDIO_BusWide = SDIO_BusWide_1b;
228
  SDIO_InitStruct->SDIO_HardwareFlowControl = SDIO_HardwareFlowControl_Disable;
229
}
230
 
231
/**
232
  * @brief  Enables or disables the SDIO Clock.
233
  * @param NewState: new state of the SDIO Clock.
234
  *   This parameter can be: ENABLE or DISABLE.
235
  * @retval : None
236
  */
237
void SDIO_ClockCmd(FunctionalState NewState)
238
{
239
  /* Check the parameters */
240
  assert_param(IS_FUNCTIONAL_STATE(NewState));
241
 
242
  *(__IO uint32_t *) CLKCR_CLKEN_BB = (uint32_t)NewState;
243
}
244
 
245
/**
246
  * @brief  Sets the power status of the controller.
247
  * @param SDIO_PowerState: new state of the Power state.
248
  *   This parameter can be one of the following values:
249
  * @arg SDIO_PowerState_OFF
250
  * @arg SDIO_PowerState_ON
251
  * @retval : None
252
  */
253
void SDIO_SetPowerState(uint32_t SDIO_PowerState)
254
{
255
  /* Check the parameters */
256
  assert_param(IS_SDIO_POWER_STATE(SDIO_PowerState));
257
 
258
  SDIO->POWER &= PWR_PWRCTRL_MASK;
259
  SDIO->POWER |= SDIO_PowerState;
260
}
261
 
262
/**
263
  * @brief  Gets the power status of the controller.
264
  * @param  None
265
  * @retval : Power status of the controller. The returned value can
266
  *   be one of the following:
267
  * - 0x00: Power OFF
268
  * - 0x02: Power UP
269
  * - 0x03: Power ON
270
  */
271
uint32_t SDIO_GetPowerState(void)
272
{
273
  return (SDIO->POWER & (~PWR_PWRCTRL_MASK));
274
}
275
 
276
/**
277
  * @brief  Enables or disables the SDIO interrupts.
278
  * @param SDIO_IT: specifies the SDIO interrupt sources to be
279
  *   enabled or disabled.
280
  *   This parameter can be one or a combination of the following values:
281
  * @arg SDIO_IT_CCRCFAIL: Command response received (CRC check failed) interrupt
282
  * @arg SDIO_IT_DCRCFAIL: Data block sent/received (CRC check failed) interrupt
283
  * @arg SDIO_IT_CTIMEOUT: Command response timeout interrupt
284
  * @arg SDIO_IT_DTIMEOUT: Data timeout interrupt
285
  * @arg SDIO_IT_TXUNDERR: Transmit FIFO underrun error interrupt
286
  * @arg SDIO_IT_RXOVERR:  Received FIFO overrun error interrupt
287
  * @arg SDIO_IT_CMDREND:  Command response received (CRC check passed) interrupt
288
  * @arg SDIO_IT_CMDSENT:  Command sent (no response required) interrupt
289
  * @arg SDIO_IT_DATAEND:  Data end (data counter, SDIDCOUNT, is zero) interrupt
290
  * @arg SDIO_IT_STBITERR: Start bit not detected on all data signals in wide
291
  *                        bus mode interrupt
292
  * @arg SDIO_IT_DBCKEND:  Data block sent/received (CRC check passed) interrupt
293
  * @arg SDIO_IT_CMDACT:   Command transfer in progress interrupt
294
  * @arg SDIO_IT_TXACT:    Data transmit in progress interrupt
295
  * @arg SDIO_IT_RXACT:    Data receive in progress interrupt
296
  * @arg SDIO_IT_TXFIFOHE: Transmit FIFO Half Empty interrupt
297
  * @arg SDIO_IT_RXFIFOHF: Receive FIFO Half Full interrupt
298
  * @arg SDIO_IT_TXFIFOF:  Transmit FIFO full interrupt
299
  * @arg SDIO_IT_RXFIFOF:  Receive FIFO full interrupt
300
  * @arg SDIO_IT_TXFIFOE:  Transmit FIFO empty interrupt
301
  * @arg SDIO_IT_RXFIFOE:  Receive FIFO empty interrupt
302
  * @arg SDIO_IT_TXDAVL:   Data available in transmit FIFO interrupt
303
  * @arg SDIO_IT_RXDAVL:   Data available in receive FIFO interrupt
304
  * @arg SDIO_IT_SDIOIT:   SD I/O interrupt received interrupt
305
  * @arg SDIO_IT_CEATAEND: CE-ATA command completion signal received for CMD61
306
  *                        interrupt
307
  * @param NewState: new state of the specified SDIO interrupts.
308
  *   This parameter can be: ENABLE or DISABLE.
309
  * @retval : None
310
  */
311
void SDIO_ITConfig(uint32_t SDIO_IT, FunctionalState NewState)
312
{
313
  /* Check the parameters */
314
  assert_param(IS_SDIO_IT(SDIO_IT));
315
  assert_param(IS_FUNCTIONAL_STATE(NewState));
316
 
317
  if (NewState != DISABLE)
318
  {
319
    /* Enable the SDIO interrupts */
320
    SDIO->MASK |= SDIO_IT;
321
  }
322
  else
323
  {
324
    /* Disable the SDIO interrupts */
325
    SDIO->MASK &= ~SDIO_IT;
326
  }
327
}
328
 
329
/**
330
  * @brief  Enables or disables the SDIO DMA request.
331
  * @param NewState: new state of the selected SDIO DMA request.
332
  *   This parameter can be: ENABLE or DISABLE.
333
  * @retval : None
334
  */
335
void SDIO_DMACmd(FunctionalState NewState)
336
{
337
  /* Check the parameters */
338
  assert_param(IS_FUNCTIONAL_STATE(NewState));
339
 
340
  *(__IO uint32_t *) DCTRL_DMAEN_BB = (uint32_t)NewState;
341
}
342
 
343
/**
344
  * @brief  Initializes the SDIO Command according to the specified
345
  *   parameters in the SDIO_CmdInitStruct and send the command.
346
  * @param SDIO_CmdInitStruct : pointer to a SDIO_CmdInitTypeDef
347
  *   structure that contains the configuration information
348
  *   for the SDIO command.
349
  * @retval : None
350
  */
351
void SDIO_SendCommand(SDIO_CmdInitTypeDef *SDIO_CmdInitStruct)
352
{
353
  uint32_t tmpreg = 0;
354
 
355
  /* Check the parameters */
356
  assert_param(IS_SDIO_CMD_INDEX(SDIO_CmdInitStruct->SDIO_CmdIndex));
357
  assert_param(IS_SDIO_RESPONSE(SDIO_CmdInitStruct->SDIO_Response));
358
  assert_param(IS_SDIO_WAIT(SDIO_CmdInitStruct->SDIO_Wait));
359
  assert_param(IS_SDIO_CPSM(SDIO_CmdInitStruct->SDIO_CPSM));
360
 
361
/*---------------------------- SDIO ARG Configuration ------------------------*/
362
  /* Set the SDIO Argument value */
363
  SDIO->ARG = SDIO_CmdInitStruct->SDIO_Argument;
364
 
365
/*---------------------------- SDIO CMD Configuration ------------------------*/
366
  /* Get the SDIO CMD value */
367
  tmpreg = SDIO->CMD;
368
  /* Clear CMDINDEX, WAITRESP, WAITINT, WAITPEND, CPSMEN bits */
369
  tmpreg &= CMD_CLEAR_MASK;
370
  /* Set CMDINDEX bits according to SDIO_CmdIndex value */
371
  /* Set WAITRESP bits according to SDIO_Response value */
372
  /* Set WAITINT and WAITPEND bits according to SDIO_Wait value */
373
  /* Set CPSMEN bits according to SDIO_CPSM value */
374
  tmpreg |= (uint32_t)SDIO_CmdInitStruct->SDIO_CmdIndex | SDIO_CmdInitStruct->SDIO_Response
375
           | SDIO_CmdInitStruct->SDIO_Wait | SDIO_CmdInitStruct->SDIO_CPSM;
376
 
377
  /* Write to SDIO CMD */
378
  SDIO->CMD = tmpreg;
379
}
380
 
381
/**
382
  * @brief  Fills each SDIO_CmdInitStruct member with its default value.
383
  * @param SDIO_CmdInitStruct: pointer to an SDIO_CmdInitTypeDef
384
  *   structure which will be initialized.
385
  * @retval : None
386
  */
387
void SDIO_CmdStructInit(SDIO_CmdInitTypeDef* SDIO_CmdInitStruct)
388
{
389
  /* SDIO_CmdInitStruct members default value */
390
  SDIO_CmdInitStruct->SDIO_Argument = 0x00;
391
  SDIO_CmdInitStruct->SDIO_CmdIndex = 0x00;
392
  SDIO_CmdInitStruct->SDIO_Response = SDIO_Response_No;
393
  SDIO_CmdInitStruct->SDIO_Wait = SDIO_Wait_No;
394
  SDIO_CmdInitStruct->SDIO_CPSM = SDIO_CPSM_Disable;
395
}
396
 
397
/**
398
  * @brief  Returns command index of last command for which response
399
  *   received.
400
  * @param  None
401
  * @retval : Returns the command index of the last command response received.
402
  */
403
uint8_t SDIO_GetCommandResponse(void)
404
{
405
  return (uint8_t)(SDIO->RESPCMD);
406
}
407
 
408
/**
409
  * @brief  Returns response received from the card for the last command.
410
  * @param SDIO_RESP: Specifies the SDIO response register.
411
  *   This parameter can be one of the following values:
412
  * @arg SDIO_RESP1: Response Register 1
413
  * @arg SDIO_RESP2: Response Register 2
414
  * @arg SDIO_RESP3: Response Register 3
415
  * @arg SDIO_RESP4: Response Register 4
416
  * @retval : The Corresponding response register value.
417
  */
418
uint32_t SDIO_GetResponse(uint32_t SDIO_RESP)
419
{
420
  /* Check the parameters */
421
  assert_param(IS_SDIO_RESP(SDIO_RESP));
422
 
423
  return (*(__IO uint32_t *)(SDIO_RESP_ADDR + SDIO_RESP));
424
}
425
 
426
/**
427
  * @brief  Initializes the SDIO data path according to the specified
428
  *   parameters in the SDIO_DataInitStruct.
429
  * @param SDIO_DataInitStruct : pointer to a SDIO_DataInitTypeDef
430
  *   structure that contains the configuration information
431
  *   for the SDIO command.
432
  * @retval : None
433
  */
434
void SDIO_DataConfig(SDIO_DataInitTypeDef* SDIO_DataInitStruct)
435
{
436
  uint32_t tmpreg = 0;
437
 
438
  /* Check the parameters */
439
  assert_param(IS_SDIO_DATA_LENGTH(SDIO_DataInitStruct->SDIO_DataLength));
440
  assert_param(IS_SDIO_BLOCK_SIZE(SDIO_DataInitStruct->SDIO_DataBlockSize));
441
  assert_param(IS_SDIO_TRANSFER_DIR(SDIO_DataInitStruct->SDIO_TransferDir));
442
  assert_param(IS_SDIO_TRANSFER_MODE(SDIO_DataInitStruct->SDIO_TransferMode));
443
  assert_param(IS_SDIO_DPSM(SDIO_DataInitStruct->SDIO_DPSM));
444
 
445
/*---------------------------- SDIO DTIMER Configuration ---------------------*/
446
  /* Set the SDIO Data TimeOut value */
447
  SDIO->DTIMER = SDIO_DataInitStruct->SDIO_DataTimeOut;
448
 
449
/*---------------------------- SDIO DLEN Configuration -----------------------*/
450
  /* Set the SDIO DataLength value */
451
  SDIO->DLEN = SDIO_DataInitStruct->SDIO_DataLength;
452
 
453
/*---------------------------- SDIO DCTRL Configuration ----------------------*/
454
  /* Get the SDIO DCTRL value */
455
  tmpreg = SDIO->DCTRL;
456
  /* Clear DEN, DTMODE, DTDIR and DBCKSIZE bits */
457
  tmpreg &= DCTRL_CLEAR_MASK;
458
  /* Set DEN bit according to SDIO_DPSM value */
459
  /* Set DTMODE bit according to SDIO_TransferMode value */
460
  /* Set DTDIR bit according to SDIO_TransferDir value */
461
  /* Set DBCKSIZE bits according to SDIO_DataBlockSize value */
462
  tmpreg |= (uint32_t)SDIO_DataInitStruct->SDIO_DataBlockSize | SDIO_DataInitStruct->SDIO_TransferDir
463
           | SDIO_DataInitStruct->SDIO_TransferMode | SDIO_DataInitStruct->SDIO_DPSM;
464
 
465
  /* Write to SDIO DCTRL */
466
  SDIO->DCTRL = tmpreg;
467
}
468
 
469
/**
470
  * @brief  Fills each SDIO_DataInitStruct member with its default value.
471
  * @param SDIO_DataInitStruct: pointer to an SDIO_DataInitTypeDef
472
  *   structure which will be initialized.
473
  * @retval : None
474
  */
475
void SDIO_DataStructInit(SDIO_DataInitTypeDef* SDIO_DataInitStruct)
476
{
477
  /* SDIO_DataInitStruct members default value */
478
  SDIO_DataInitStruct->SDIO_DataTimeOut = 0xFFFFFFFF;
479
  SDIO_DataInitStruct->SDIO_DataLength = 0x00;
480
  SDIO_DataInitStruct->SDIO_DataBlockSize = SDIO_DataBlockSize_1b;
481
  SDIO_DataInitStruct->SDIO_TransferDir = SDIO_TransferDir_ToCard;
482
  SDIO_DataInitStruct->SDIO_TransferMode = SDIO_TransferMode_Block;
483
  SDIO_DataInitStruct->SDIO_DPSM = SDIO_DPSM_Disable;
484
}
485
 
486
/**
487
  * @brief  Returns number of remaining data bytes to be transferred.
488
  * @param  None
489
  * @retval : Number of remaining data bytes to be transferred
490
  */
491
uint32_t SDIO_GetDataCounter(void)
492
{
493
  return SDIO->DCOUNT;
494
}
495
 
496
/**
497
  * @brief  Read one data word from Rx FIFO.
498
  * @param  None
499
  * @retval : Data received
500
  */
501
uint32_t SDIO_ReadData(void)
502
{
503
  return SDIO->FIFO;
504
}
505
 
506
/**
507
  * @brief  Write one data word to Tx FIFO.
508
  * @param Data: 32-bit data word to write.
509
  * @retval : None
510
  */
511
void SDIO_WriteData(uint32_t Data)
512
{
513
  SDIO->FIFO = Data;
514
}
515
 
516
/**
517
  * @brief  Returns the number of words left to be written to or read
518
  *   from FIFO.
519
  * @param  None
520
  * @retval : Remaining number of words.
521
  */
522
uint32_t SDIO_GetFIFOCount(void)
523
{
524
  return SDIO->FIFOCNT;
525
}
526
 
527
/**
528
  * @brief  Starts the SD I/O Read Wait operation.
529
  * @param NewState: new state of the Start SDIO Read Wait operation.
530
  *   This parameter can be: ENABLE or DISABLE.
531
  * @retval : None
532
  */
533
void SDIO_StartSDIOReadWait(FunctionalState NewState)
534
{
535
  /* Check the parameters */
536
  assert_param(IS_FUNCTIONAL_STATE(NewState));
537
 
538
  *(__IO uint32_t *) DCTRL_RWSTART_BB = (uint32_t) NewState;
539
}
540
 
541
/**
542
  * @brief  Stops the SD I/O Read Wait operation.
543
  * @param NewState: new state of the Stop SDIO Read Wait operation.
544
  *   This parameter can be: ENABLE or DISABLE.
545
  * @retval : None
546
  */
547
void SDIO_StopSDIOReadWait(FunctionalState NewState)
548
{
549
  /* Check the parameters */
550
  assert_param(IS_FUNCTIONAL_STATE(NewState));
551
 
552
  *(__IO uint32_t *) DCTRL_RWSTOP_BB = (uint32_t) NewState;
553
}
554
 
555
/**
556
  * @brief  Sets one of the two options of inserting read wait interval.
557
  * @param SDIO_ReadWaitMode: SD I/O Read Wait operation mode.
558
  *   This parametre can be:
559
  * @arg SDIO_ReadWaitMode_CLK: Read Wait control by stopping SDIOCLK
560
  * @arg SDIO_ReadWaitMode_DATA2: Read Wait control using SDIO_DATA2
561
  * @retval : None
562
  */
563
void SDIO_SetSDIOReadWaitMode(uint32_t SDIO_ReadWaitMode)
564
{
565
  /* Check the parameters */
566
  assert_param(IS_SDIO_READWAIT_MODE(SDIO_ReadWaitMode));
567
 
568
  *(__IO uint32_t *) DCTRL_RWMOD_BB = SDIO_ReadWaitMode;
569
}
570
 
571
/**
572
  * @brief  Enables or disables the SD I/O Mode Operation.
573
  * @param NewState: new state of SDIO specific operation.
574
  *   This parameter can be: ENABLE or DISABLE.
575
  * @retval : None
576
  */
577
void SDIO_SetSDIOOperation(FunctionalState NewState)
578
{
579
  /* Check the parameters */
580
  assert_param(IS_FUNCTIONAL_STATE(NewState));
581
 
582
  *(__IO uint32_t *) DCTRL_SDIOEN_BB = (uint32_t)NewState;
583
}
584
 
585
/**
586
  * @brief  Enables or disables the SD I/O Mode suspend command sending.
587
  * @param NewState: new state of the SD I/O Mode suspend command.
588
  *   This parameter can be: ENABLE or DISABLE.
589
  * @retval : None
590
  */
591
void SDIO_SendSDIOSuspendCmd(FunctionalState NewState)
592
{
593
  /* Check the parameters */
594
  assert_param(IS_FUNCTIONAL_STATE(NewState));
595
 
596
  *(__IO uint32_t *) CMD_SDIOSUSPEND_BB = (uint32_t)NewState;
597
}
598
 
599
/**
600
  * @brief  Enables or disables the command completion signal.
601
  * @param NewState: new state of command completion signal.
602
  *   This parameter can be: ENABLE or DISABLE.
603
  * @retval : None
604
  */
605
void SDIO_CommandCompletionCmd(FunctionalState NewState)
606
{
607
  /* Check the parameters */
608
  assert_param(IS_FUNCTIONAL_STATE(NewState));
609
 
610
  *(__IO uint32_t *) CMD_ENCMDCOMPL_BB = (uint32_t)NewState;
611
}
612
 
613
/**
614
  * @brief  Enables or disables the CE-ATA interrupt.
615
  * @param NewState: new state of CE-ATA interrupt.
616
  *   This parameter can be: ENABLE or DISABLE.
617
  * @retval : None
618
  */
619
void SDIO_CEATAITCmd(FunctionalState NewState)
620
{
621
  /* Check the parameters */
622
  assert_param(IS_FUNCTIONAL_STATE(NewState));
623
 
624
  *(__IO uint32_t *) CMD_NIEN_BB = (uint32_t)((~((uint32_t)NewState)) & ((uint32_t)0x1));
625
}
626
 
627
/**
628
  * @brief  Sends CE-ATA command (CMD61).
629
  * @param NewState: new state of CE-ATA command.
630
  *   This parameter can be: ENABLE or DISABLE.
631
  * @retval : None
632
  */
633
void SDIO_SendCEATACmd(FunctionalState NewState)
634
{
635
  /* Check the parameters */
636
  assert_param(IS_FUNCTIONAL_STATE(NewState));
637
 
638
  *(__IO uint32_t *) CMD_ATACMD_BB = (uint32_t)NewState;
639
}
640
 
641
/**
642
  * @brief  Checks whether the specified SDIO flag is set or not.
643
  * @param SDIO_FLAG: specifies the flag to check.
644
  *   This parameter can be one of the following values:
645
  * @arg SDIO_FLAG_CCRCFAIL: Command response received (CRC check failed)
646
  * @arg SDIO_FLAG_DCRCFAIL: Data block sent/received (CRC check failed)
647
  * @arg SDIO_FLAG_CTIMEOUT: Command response timeout
648
  * @arg SDIO_FLAG_DTIMEOUT: Data timeout
649
  * @arg SDIO_FLAG_TXUNDERR: Transmit FIFO underrun error
650
  * @arg SDIO_FLAG_RXOVERR:  Received FIFO overrun error
651
  * @arg SDIO_FLAG_CMDREND:  Command response received (CRC check passed)
652
  * @arg SDIO_FLAG_CMDSENT:  Command sent (no response required)
653
  * @arg SDIO_FLAG_DATAEND:  Data end (data counter, SDIDCOUNT, is zero)
654
  * @arg SDIO_FLAG_STBITERR: Start bit not detected on all data signals in wide
655
  *                          bus mode.
656
  * @arg SDIO_FLAG_DBCKEND:  Data block sent/received (CRC check passed)
657
  * @arg SDIO_FLAG_CMDACT:   Command transfer in progress
658
  * @arg SDIO_FLAG_TXACT:    Data transmit in progress
659
  * @arg SDIO_FLAG_RXACT:    Data receive in progress
660
  * @arg SDIO_FLAG_TXFIFOHE: Transmit FIFO Half Empty
661
  * @arg SDIO_FLAG_RXFIFOHF: Receive FIFO Half Full
662
  * @arg SDIO_FLAG_TXFIFOF:  Transmit FIFO full
663
  * @arg SDIO_FLAG_RXFIFOF:  Receive FIFO full
664
  * @arg SDIO_FLAG_TXFIFOE:  Transmit FIFO empty
665
  * @arg SDIO_FLAG_RXFIFOE:  Receive FIFO empty
666
  * @arg SDIO_FLAG_TXDAVL:   Data available in transmit FIFO
667
  * @arg SDIO_FLAG_RXDAVL:   Data available in receive FIFO
668
  * @arg SDIO_FLAG_SDIOIT:   SD I/O interrupt received
669
  * @arg SDIO_FLAG_CEATAEND: CE-ATA command completion signal received for CMD61
670
  * @retval : The new state of SDIO_FLAG (SET or RESET).
671
  */
672
FlagStatus SDIO_GetFlagStatus(uint32_t SDIO_FLAG)
673
{
674
  FlagStatus bitstatus = RESET;
675
 
676
  /* Check the parameters */
677
  assert_param(IS_SDIO_FLAG(SDIO_FLAG));
678
 
679
  if ((SDIO->STA & SDIO_FLAG) != (uint32_t)RESET)
680
  {
681
    bitstatus = SET;
682
  }
683
  else
684
  {
685
    bitstatus = RESET;
686
  }
687
  return bitstatus;
688
}
689
 
690
/**
691
  * @brief  Clears the SDIO's pending flags.
692
  * @param SDIO_FLAG: specifies the flag to clear.
693
  *   This parameter can be one or a combination of the following values:
694
  * @arg SDIO_FLAG_CCRCFAIL: Command response received (CRC check failed)
695
  * @arg SDIO_FLAG_DCRCFAIL: Data block sent/received (CRC check failed)
696
  * @arg SDIO_FLAG_CTIMEOUT: Command response timeout
697
  * @arg SDIO_FLAG_DTIMEOUT: Data timeout
698
  * @arg SDIO_FLAG_TXUNDERR: Transmit FIFO underrun error
699
  * @arg SDIO_FLAG_RXOVERR:  Received FIFO overrun error
700
  * @arg SDIO_FLAG_CMDREND:  Command response received (CRC check passed)
701
  * @arg SDIO_FLAG_CMDSENT:  Command sent (no response required)
702
  * @arg SDIO_FLAG_DATAEND:  Data end (data counter, SDIDCOUNT, is zero)
703
  * @arg SDIO_FLAG_STBITERR: Start bit not detected on all data signals in wide
704
  *                          bus mode
705
  * @arg SDIO_FLAG_DBCKEND:  Data block sent/received (CRC check passed)
706
  * @arg SDIO_FLAG_SDIOIT:   SD I/O interrupt received
707
  * @arg SDIO_FLAG_CEATAEND: CE-ATA command completion signal received for CMD61
708
  * @retval : None
709
  */
710
void SDIO_ClearFlag(uint32_t SDIO_FLAG)
711
{
712
  /* Check the parameters */
713
  assert_param(IS_SDIO_CLEAR_FLAG(SDIO_FLAG));
714
 
715
  SDIO->ICR = SDIO_FLAG;
716
}
717
 
718
/**
719
  * @brief  Checks whether the specified SDIO interrupt has occurred or not.
720
  * @param SDIO_IT: specifies the SDIO interrupt source to check.
721
  *   This parameter can be one of the following values:
722
  * @arg SDIO_IT_CCRCFAIL: Command response received (CRC check failed) interrupt
723
  * @arg SDIO_IT_DCRCFAIL: Data block sent/received (CRC check failed) interrupt
724
  * @arg SDIO_IT_CTIMEOUT: Command response timeout interrupt
725
  * @arg SDIO_IT_DTIMEOUT: Data timeout interrupt
726
  * @arg SDIO_IT_TXUNDERR: Transmit FIFO underrun error interrupt
727
  * @arg SDIO_IT_RXOVERR:  Received FIFO overrun error interrupt
728
  * @arg SDIO_IT_CMDREND:  Command response received (CRC check passed) interrupt
729
  * @arg SDIO_IT_CMDSENT:  Command sent (no response required) interrupt
730
  * @arg SDIO_IT_DATAEND:  Data end (data counter, SDIDCOUNT, is zero) interrupt
731
  * @arg SDIO_IT_STBITERR: Start bit not detected on all data signals in wide
732
  *                        bus mode interrupt
733
  * @arg SDIO_IT_DBCKEND:  Data block sent/received (CRC check passed) interrupt
734
  * @arg SDIO_IT_CMDACT:   Command transfer in progress interrupt
735
  * @arg SDIO_IT_TXACT:    Data transmit in progress interrupt
736
  * @arg SDIO_IT_RXACT:    Data receive in progress interrupt
737
  * @arg SDIO_IT_TXFIFOHE: Transmit FIFO Half Empty interrupt
738
  * @arg SDIO_IT_RXFIFOHF: Receive FIFO Half Full interrupt
739
  * @arg SDIO_IT_TXFIFOF:  Transmit FIFO full interrupt
740
  * @arg SDIO_IT_RXFIFOF:  Receive FIFO full interrupt
741
  * @arg SDIO_IT_TXFIFOE:  Transmit FIFO empty interrupt
742
  * @arg SDIO_IT_RXFIFOE:  Receive FIFO empty interrupt
743
  * @arg SDIO_IT_TXDAVL:   Data available in transmit FIFO interrupt
744
  * @arg SDIO_IT_RXDAVL:   Data available in receive FIFO interrupt
745
  * @arg SDIO_IT_SDIOIT:   SD I/O interrupt received interrupt
746
  * @arg SDIO_IT_CEATAEND: CE-ATA command completion signal received for CMD61
747
  *                        interrupt
748
  * @retval : The new state of SDIO_IT (SET or RESET).
749
  */
750
ITStatus SDIO_GetITStatus(uint32_t SDIO_IT)
751
{
752
  ITStatus bitstatus = RESET;
753
 
754
  /* Check the parameters */
755
  assert_param(IS_SDIO_GET_IT(SDIO_IT));
756
  if ((SDIO->STA & SDIO_IT) != (uint32_t)RESET)
757
  {
758
    bitstatus = SET;
759
  }
760
  else
761
  {
762
    bitstatus = RESET;
763
  }
764
  return bitstatus;
765
}
766
 
767
/**
768
  * @brief  Clears the SDIO’s interrupt pending bits.
769
  * @param SDIO_IT: specifies the interrupt pending bit to clear.
770
  *   This parameter can be one or a combination of the following values:
771
  * @arg SDIO_IT_CCRCFAIL: Command response received (CRC check failed) interrupt
772
  * @arg SDIO_IT_DCRCFAIL: Data block sent/received (CRC check failed) interrupt
773
  * @arg SDIO_IT_CTIMEOUT: Command response timeout interrupt
774
  * @arg SDIO_IT_DTIMEOUT: Data timeout interrupt
775
  * @arg SDIO_IT_TXUNDERR: Transmit FIFO underrun error interrupt
776
  * @arg SDIO_IT_RXOVERR:  Received FIFO overrun error interrupt
777
  * @arg SDIO_IT_CMDREND:  Command response received (CRC check passed) interrupt
778
  * @arg SDIO_IT_CMDSENT:  Command sent (no response required) interrupt
779
  * @arg SDIO_IT_DATAEND:  Data end (data counter, SDIDCOUNT, is zero) interrupt
780
  * @arg SDIO_IT_STBITERR: Start bit not detected on all data signals in wide
781
  *                        bus mode interrupt
782
  * @arg SDIO_IT_SDIOIT:   SD I/O interrupt received interrupt
783
  * @arg SDIO_IT_CEATAEND: CE-ATA command completion signal received for CMD61
784
  * @retval : None
785
  */
786
void SDIO_ClearITPendingBit(uint32_t SDIO_IT)
787
{
788
  /* Check the parameters */
789
  assert_param(IS_SDIO_CLEAR_IT(SDIO_IT));
790
 
791
  SDIO->ICR = SDIO_IT;
792
}
793
 
794
/**
795
  * @}
796
  */
797
 
798
/**
799
  * @}
800
  */
801
 
802
/**
803
  * @}
804
  */
805
 
806
/******************* (C) COPYRIGHT 2009 STMicroelectronics *****END OF FILE****/

powered by: WebSVN 2.1.0

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