diskio.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /* sd2snes - SD card based universal cartridge for the SNES
  2. Copyright (C) 2009-2010 Maximilian Rehkopf <otakon@gmx.net>
  3. This file was adapted from sd2iec, written by Ingo Korb.
  4. Original copyright header follows:
  5. */
  6. /* sd2iec - SD/MMC to Commodore serial bus interface/controller
  7. Copyright (C) 2007-2009 Ingo Korb <ingo@akana.de>
  8. Inspiration and low-level SD/MMC access based on code from MMC2IEC
  9. by Lars Pontoppidan et al., see sdcard.c|h and config.h.
  10. FAT filesystem access based on code from ChaN and Jim Brain, see ff.c|h.
  11. This program is free software; you can redistribute it and/or modify
  12. it under the terms of the GNU General Public License as published by
  13. the Free Software Foundation; version 2 of the License only.
  14. This program is distributed in the hope that it will be useful,
  15. but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. GNU General Public License for more details.
  18. You should have received a copy of the GNU General Public License
  19. along with this program; if not, write to the Free Software
  20. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. diskio.h: Definitions for the disk access routines
  22. Based on diskio.h from FatFS by ChaN, see ff.c for
  23. for full copyright details.
  24. */
  25. #ifndef DISKIO_H
  26. #define DISKIO_H
  27. #include "integer.h"
  28. /* Status of Disk Functions */
  29. typedef BYTE DSTATUS;
  30. /* Disk Status Bits (DSTATUS) */
  31. #define STA_NOINIT 0x01 /* Drive not initialized */
  32. #define STA_NODISK 0x02 /* No medium in the drive */
  33. #define STA_PROTECT 0x04 /* Write protected */
  34. /* Results of Disk Functions */
  35. typedef enum {
  36. RES_OK = 0, /* 0: Successful */
  37. RES_ERROR, /* 1: R/W Error */
  38. RES_WRPRT, /* 2: Write Protected */
  39. RES_NOTRDY, /* 3: Not Ready */
  40. RES_PARERR /* 4: Invalid Parameter */
  41. } DRESULT;
  42. /**
  43. * struct diskinfo0_t - disk info data structure for page 0
  44. * @validbytes : Number of valid bytes in this struct
  45. * @maxpage : Highest diskinfo page supported
  46. * @disktype : type of the disk (DISK_TYPE_* values)
  47. * @sectorsize : sector size divided by 256
  48. * @sectorcount: number of sectors on the disk
  49. *
  50. * This is the struct returned in the data buffer when disk_getinfo
  51. * is called with page=0.
  52. */
  53. typedef struct {
  54. uint8_t validbytes;
  55. uint8_t maxpage;
  56. uint8_t disktype;
  57. uint8_t sectorsize; /* divided by 256 */
  58. uint32_t sectorcount; /* 2 TB should be enough... (512 byte sectors) */
  59. } diskinfo0_t;
  60. /*---------------------------------------*/
  61. /* Prototypes for disk control functions */
  62. DSTATUS disk_initialize (BYTE);
  63. DSTATUS disk_status (BYTE);
  64. DRESULT disk_read (BYTE, BYTE*, DWORD, BYTE);
  65. DRESULT disk_write (BYTE, const BYTE*, DWORD, BYTE);
  66. #define disk_ioctl(a,b,c) RES_OK
  67. DRESULT disk_getinfo(BYTE drv, BYTE page, void *buffer);
  68. void disk_init(void);
  69. uint8_t SD_SPI_OFFLOAD;
  70. /* Will be set to DISK_ERROR if any access on the card fails */
  71. enum diskstates { DISK_CHANGED = 0, DISK_REMOVED, DISK_OK, DISK_ERROR };
  72. extern volatile enum diskstates disk_state;
  73. /* Disk type - part of the external API except for ATA2! */
  74. #define DISK_TYPE_ATA 0
  75. #define DISK_TYPE_ATA2 1
  76. #define DISK_TYPE_SD 2
  77. #define DISK_TYPE_DF 3
  78. #define DISK_TYPE_NONE 7
  79. #ifdef NEED_DISKMUX
  80. /* Disk mux configuration */
  81. extern uint32_t drive_config;
  82. uint32_t get_default_driveconfig(void);
  83. # define set_map_drive(drv,val) (drive_config = \
  84. (drive_config & (0xffffffff - (0x0f << (drv * 4)))) \
  85. | (val << (drv * 4)))
  86. # define map_drive(drv) ((drive_config >> (4 * drv)) & 0x0f)
  87. # define set_drive_config(config) drive_config = config
  88. /* Number of bits used for the drive, the disk type */
  89. /* uses the remainder (4 bits per entry). */
  90. # define DRIVE_BITS 1
  91. /* Calculate mask from the shift value */
  92. # define DRIVE_MASK ((1 << DRIVE_BITS)-1)
  93. #else // NEED_DISKMUX
  94. # define set_map_drive(drv,val) do {} while(0)
  95. # define map_drive(drv) (drv)
  96. # define set_drive_config(conf) do {} while(0)
  97. # define get_default_driveconfig() 0
  98. #endif // NEED_DISKMUX
  99. #endif