My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

sd_mmc_spi_mem.h 5.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. /*****************************************************************************
  2. *
  3. * \file
  4. *
  5. * \brief CTRL_ACCESS interface for SD/MMC card.
  6. *
  7. * Copyright (c) 2014-2015 Atmel Corporation. All rights reserved.
  8. *
  9. * \asf_license_start
  10. *
  11. * \page License
  12. *
  13. * Redistribution and use in source and binary forms, with or without
  14. * modification, are permitted provided that the following conditions are met:
  15. *
  16. * 1. Redistributions of source code must retain the above copyright notice,
  17. * this list of conditions and the following disclaimer.
  18. *
  19. * 2. Redistributions in binary form must reproduce the above copyright notice,
  20. * this list of conditions and the following disclaimer in the documentation
  21. * and/or other materials provided with the distribution.
  22. *
  23. * 3. The name of Atmel may not be used to endorse or promote products derived
  24. * from this software without specific prior written permission.
  25. *
  26. * 4. This software may only be redistributed and used in connection with an
  27. * Atmel microcontroller product.
  28. *
  29. * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
  30. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  31. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
  32. * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR
  33. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  34. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  35. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  36. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  37. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  38. * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  39. * POSSIBILITY OF SUCH DAMAGE.
  40. *
  41. * \asf_license_stop
  42. *
  43. ******************************************************************************/
  44. /*
  45. * Support and FAQ: visit <a href="https://www.atmel.com/design-support/">Atmel Support</a>
  46. */
  47. #ifndef _SD_MMC_SPI_MEM_H_
  48. #define _SD_MMC_SPI_MEM_H_
  49. /**
  50. * \defgroup group_avr32_components_memory_sd_mmc_sd_mmc_spi_mem SD/MMC SPI Memory
  51. *
  52. * \ingroup group_avr32_components_memory_sd_mmc_sd_mmc_spi
  53. *
  54. * \{
  55. */
  56. #include "conf_access.h"
  57. #if SD_MMC_SPI_MEM == DISABLE
  58. #error sd_mmc_spi_mem.h is #included although SD_MMC_SPI_MEM is disabled
  59. #endif
  60. #include "ctrl_access.h"
  61. //_____ D E F I N I T I O N S ______________________________________________
  62. #define SD_MMC_REMOVED 0
  63. #define SD_MMC_INSERTED 1
  64. #define SD_MMC_REMOVING 2
  65. //---- CONTROL FONCTIONS ----
  66. //!
  67. //! @brief This function initializes the hw/sw resources required to drive the SD_MMC_SPI.
  68. //!/
  69. extern void sd_mmc_spi_mem_init(void);
  70. //!
  71. //! @brief This function tests the state of the SD_MMC memory and sends it to the Host.
  72. //! For a PC, this device is seen as a removable media
  73. //! Before indicating any modification of the status of the media (GOOD->NO_PRESENT or vice-versa),
  74. //! the function must return the BUSY data to make the PC accepting the change
  75. //!
  76. //! @return Ctrl_status
  77. //! Media is ready -> CTRL_GOOD
  78. //! Media not present -> CTRL_NO_PRESENT
  79. //! Media has changed -> CTRL_BUSY
  80. //!/
  81. extern Ctrl_status sd_mmc_spi_test_unit_ready(void);
  82. //!
  83. //! @brief This function gives the address of the last valid sector.
  84. //!
  85. //! @param *nb_sector number of sector (sector = 512B). OUT
  86. //!
  87. //! @return Ctrl_status
  88. //! Media ready -> CTRL_GOOD
  89. //! Media not present -> CTRL_NO_PRESENT
  90. //!/
  91. extern Ctrl_status sd_mmc_spi_read_capacity(uint32_t *nb_sector);
  92. /*! \brief Unload/Load the SD/MMC card selected
  93. *
  94. * The START STOP UNIT SCSI optional command allows an application client to
  95. * eject the removable medium on a LUN.
  96. *
  97. * \param unload \c true to unload the medium, \c false to load the medium.
  98. *
  99. * \return \c true if unload/load done success.
  100. */
  101. extern bool sd_mmc_spi_unload(bool unload);
  102. //!
  103. //! @brief This function returns the write protected status of the memory.
  104. //!
  105. //! Only used by memory removal with a HARDWARE SPECIFIC write protected detection
  106. //! ! The user must unplug the memory to change this write protected status,
  107. //! which cannot be for a SD_MMC.
  108. //!
  109. //! @return false -> the memory is not write-protected (always)
  110. //!/
  111. extern bool sd_mmc_spi_wr_protect(void);
  112. //!
  113. //! @brief This function tells if the memory has been removed or not.
  114. //!
  115. //! @return false -> The memory isn't removed
  116. //!
  117. extern bool sd_mmc_spi_removal(void);
  118. //---- ACCESS DATA FONCTIONS ----
  119. #if ACCESS_USB == true
  120. // Standard functions for open in read/write mode the device
  121. //!
  122. //! @brief This function performs a read operation of n sectors from a given address on.
  123. //! (sector = 512B)
  124. //!
  125. //! DATA FLOW is: SD_MMC => USB
  126. //!
  127. //! @param addr Sector address to start the read from
  128. //! @param nb_sector Number of sectors to transfer
  129. //!
  130. //! @return Ctrl_status
  131. //! It is ready -> CTRL_GOOD
  132. //! A error occur -> CTRL_FAIL
  133. //!
  134. extern Ctrl_status sd_mmc_spi_usb_read_10(uint32_t addr, uint16_t nb_sector);
  135. //! This function initializes the SD/MMC memory for a write operation
  136. //!
  137. //! DATA FLOW is: USB => SD_MMC
  138. //!
  139. //! (sector = 512B)
  140. //! @param addr Sector address to start write
  141. //! @param nb_sector Number of sectors to transfer
  142. //!
  143. //! @return Ctrl_status
  144. //! It is ready -> CTRL_GOOD
  145. //! An error occurs -> CTRL_FAIL
  146. //!
  147. extern Ctrl_status sd_mmc_spi_usb_write_10(uint32_t addr, uint16_t nb_sector);
  148. #endif // #if ACCESS_USB == true
  149. /**
  150. * \}
  151. */
  152. #endif // _SD_MMC_SPI_MEM_H_