drv_sdcard.h 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /***************************************************************************//**
  2. * @file drv_sdcard.h
  3. * @brief Memory card driver (SPI mode) of RT-Thread RTOS for using EFM32
  4. * USART module
  5. * COPYRIGHT (C) 2011, RT-Thread Development Team
  6. * @author onelife
  7. * @version 0.4 beta
  8. *******************************************************************************
  9. * @section License
  10. * The license and distribution terms for this file may be found in the file
  11. * LICENSE in this distribution or at http://www.rt-thread.org/license/LICENSE
  12. *******************************************************************************
  13. * @section Change Logs
  14. * Date Author Notes
  15. * 2011-05-13 onelife Initial creation for using EFM32 USART module
  16. * 2011-07-07 onelife Modify initialization function to return error code
  17. ******************************************************************************/
  18. #ifndef __DEV_SDCARD_H__
  19. #define __DEV_SDCARD_H__
  20. /* Includes ------------------------------------------------------------------*/
  21. /* Exported types ------------------------------------------------------------*/
  22. /* Exported constants --------------------------------------------------------*/
  23. /* Exported macro ------------------------------------------------------------*/
  24. #define EFM32_SDCLK_LOW (100000)
  25. #define EFM32_SDCLK_HIGH (EFM32_HFXO_FREQUENCY/2)
  26. #define SD_SPEED_LOW (0)
  27. #define SD_SPEED_HIGH (1)
  28. #define SD_WAIT_PERIOD (RT_TICK_PER_SECOND)
  29. #define SD_SECTOR_SIZE_SHIFT (9)
  30. #define SD_SECTOR_SIZE (1 << SD_SECTOR_SIZE_SHIFT)
  31. #define SD_BLOCK_SIZE_CSD (16)
  32. #define SD_BLOCK_SIZE_CID (16)
  33. #define SD_BLOCK_SIZE_OCR (4)
  34. #define SD_BLOCK_SIZE_SDSTAT (64)
  35. /* Card type definitions (CardType) */
  36. #define CT_MMC (0x01)
  37. #define CT_SD1 (0x02)
  38. #define CT_SD2 (0x04)
  39. #define CT_SDC (CT_SD1|CT_SD2)
  40. #define CT_BLOCK (0x08)
  41. /* Definitions for MMC/SDC command */
  42. #define CMD0 (0) /* GO_IDLE_STATE */
  43. #define CMD1 (1) /* SEND_OP_COND */
  44. #define ACMD41 (41|0x80) /* SEND_OP_COND (SDC) */
  45. #define CMD8 (8) /* SEND_IF_COND */
  46. #define CMD9 (9) /* SEND_CSD */
  47. #define CMD10 (10) /* SEND_CID */
  48. #define CMD12 (12) /* STOP_TRANSMISSION */
  49. #define ACMD13 (13|0x80) /* SD_STATUS (SDC) */
  50. #define CMD16 (16) /* SET_BLOCKLEN */
  51. #define CMD17 (17) /* READ_SINGLE_BLOCK */
  52. #define CMD18 (18) /* READ_MULTIPLE_BLOCK */
  53. #define CMD23 (23) /* SET_BLOCK_COUNT */
  54. #define ACMD23 (23|0x80) /* SET_WR_BLK_ERASE_COUNT (SDC) */
  55. #define CMD24 (24) /* WRITE_BLOCK */
  56. #define CMD25 (25) /* WRITE_MULTIPLE_BLOCK */
  57. #define CMD41 (41) /* SEND_OP_COND (ACMD) */
  58. #define CMD55 (55) /* APP_CMD */
  59. #define CMD58 (58) /* READ_OCR */
  60. /* Exported functions ------------------------------------------------------- */
  61. rt_err_t efm_spiSd_init(void);
  62. void efm_spiSd_deinit(void);
  63. #endif /* __DEV_SDCARD_H__ */