diskio.h 4.0 KB

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