PageRenderTime 55ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/firmware/LPCUSBlib_DisplayLink/fatfs/src/fs_usb.c

https://gitlab.com/feliperey4/Interfaz_Grafica_HDMI_EDUCIAA
C | 182 lines | 94 code | 35 blank | 53 comment | 17 complexity | 8be78215c654460d824e9d70df29e324 MD5 | raw file
  1. /*
  2. * @brief USB Mass Storage Chan FATFS simple abstraction layer
  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. #include "fsusb_cfg.h"
  32. #include "board.h"
  33. #include "chip.h"
  34. /*****************************************************************************
  35. * Private types/enumerations/variables
  36. ****************************************************************************/
  37. /* Disk Status */
  38. static volatile DSTATUS Stat = STA_NOINIT;
  39. /* 100Hz decrement timer stopped at zero (disk_timerproc()) */
  40. static volatile WORD Timer2;
  41. static DISK_HANDLE_T *hDisk;
  42. /*****************************************************************************
  43. * Public types/enumerations/variables
  44. ****************************************************************************/
  45. /*****************************************************************************
  46. * Private functions
  47. ****************************************************************************/
  48. /*****************************************************************************
  49. * Public functions
  50. ****************************************************************************/
  51. /* Initialize Disk Drive */
  52. DSTATUS disk_initialize(BYTE drv)
  53. {
  54. if (drv) {
  55. return STA_NOINIT; /* Supports only single drive */
  56. }
  57. /* if (Stat & STA_NODISK) return Stat; *//* No card in the socket */
  58. if (Stat != STA_NOINIT) {
  59. return Stat; /* card is already enumerated */
  60. }
  61. #if !_FS_READONLY
  62. FSUSB_InitRealTimeClock();
  63. #endif
  64. /* Initialize the Card Data Strucutre */
  65. hDisk = FSUSB_DiskInit();
  66. /* Reset */
  67. Stat = STA_NOINIT;
  68. FSUSB_DiskInsertWait(hDisk); /* Wait for card to be inserted */
  69. /* Enumerate the card once detected. Note this function may block for a little while. */
  70. if (!FSUSB_DiskAcquire(hDisk)) {
  71. DEBUGOUT("Disk Enumeration failed...\r\n");
  72. return Stat;
  73. }
  74. Stat &= ~STA_NOINIT;
  75. return Stat;
  76. }
  77. /* Disk Drive miscellaneous Functions */
  78. DRESULT disk_ioctl(BYTE drv, BYTE ctrl, void *buff)
  79. {
  80. DRESULT res;
  81. if (drv) {
  82. return RES_PARERR;
  83. }
  84. if (Stat & STA_NOINIT) {
  85. return RES_NOTRDY;
  86. }
  87. res = RES_ERROR;
  88. switch (ctrl) {
  89. case CTRL_SYNC: /* Make sure that no pending write process */
  90. if (FSUSB_DiskReadyWait(hDisk, 50)) {
  91. res = RES_OK;
  92. }
  93. break;
  94. case GET_SECTOR_COUNT: /* Get number of sectors on the disk (DWORD) */
  95. *(DWORD *) buff = FSUSB_DiskGetSectorCnt(hDisk);
  96. res = RES_OK;
  97. break;
  98. case GET_SECTOR_SIZE: /* Get R/W sector size (WORD) */
  99. *(WORD *) buff = FSUSB_DiskGetSectorSz(hDisk);
  100. res = RES_OK;
  101. break;
  102. case GET_BLOCK_SIZE:/* Get erase block size in unit of sector (DWORD) */
  103. *(DWORD *) buff = FSUSB_DiskGetBlockSz(hDisk);
  104. res = RES_OK;
  105. break;
  106. default:
  107. res = RES_PARERR;
  108. break;
  109. }
  110. return res;
  111. }
  112. /* Read Sector(s) */
  113. DRESULT disk_read(BYTE drv, BYTE *buff, DWORD sector, BYTE count)
  114. {
  115. if (drv || !count) {
  116. return RES_PARERR;
  117. }
  118. if (Stat & STA_NOINIT) {
  119. return RES_NOTRDY;
  120. }
  121. if (FSUSB_DiskReadSectors(hDisk, buff, sector, count)) {
  122. return RES_OK;
  123. }
  124. return RES_ERROR;
  125. }
  126. /* Get Disk Status */
  127. DSTATUS disk_status(BYTE drv)
  128. {
  129. if (drv) {
  130. return STA_NOINIT; /* Supports only single drive */
  131. }
  132. return Stat;
  133. }
  134. /* Write Sector(s) */
  135. DRESULT disk_write(BYTE drv, const BYTE *buff, DWORD sector, BYTE count)
  136. {
  137. if (drv || !count) {
  138. return RES_PARERR;
  139. }
  140. if (Stat & STA_NOINIT) {
  141. return RES_NOTRDY;
  142. }
  143. if (FSUSB_DiskWriteSectors(hDisk, (void *) buff, sector, count)) {
  144. return RES_OK;
  145. }
  146. return RES_ERROR;
  147. }