summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/machine/spi_sdcard.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/devices/machine/spi_sdcard.h')
-rw-r--r--src/devices/machine/spi_sdcard.h91
1 files changed, 41 insertions, 50 deletions
diff --git a/src/devices/machine/spi_sdcard.h b/src/devices/machine/spi_sdcard.h
index 0d8a7cbdc7f..8eb9ec90d34 100644
--- a/src/devices/machine/spi_sdcard.h
+++ b/src/devices/machine/spi_sdcard.h
@@ -7,13 +7,22 @@
#include "imagedev/harddriv.h"
+#include <vector>
+
+
class spi_sdcard_device : public device_t
{
public:
+ spi_sdcard_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock = 0);
+ virtual ~spi_sdcard_device();
+
+ void set_prefer_sd() { m_preferred_type = SD_TYPE_V2; }
+ void set_prefer_sdhc() { m_preferred_type = SD_TYPE_HC; }
+
// SPI 4-wire interface
auto spi_miso_callback() { return write_miso.bind(); }
void spi_clock_w(int state);
- void spi_ss_w(int state) { m_ss = state; }
+ void spi_ss_w(int state);
void spi_mosi_w(int state) { m_in_bit = state; }
bool get_card_present() { return m_image->exists(); }
@@ -21,76 +30,58 @@ public:
devcb_write_line write_miso;
protected:
- enum sd_type : u8
- {
- SD_TYPE_V2 = 0,
- SD_TYPE_HC
- };
-
- spi_sdcard_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, uint32_t clock);
+ spi_sdcard_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, u32 clock);
- virtual void device_start() override;
- virtual void device_reset() override;
- virtual void device_add_mconfig(machine_config &config) override;
+ virtual void device_start() override ATTR_COLD;
+ virtual void device_add_mconfig(machine_config &config) override ATTR_COLD;
required_device<harddisk_image_device> m_image;
- sd_type m_type;
-
private:
- enum sd_state : u8
+ enum sd_type : u8
{
- //REF Table 4-1:Overview of Card States vs. Operation Mode
- SD_STATE_IDLE = 0,
- SD_STATE_READY,
- SD_STATE_IDENT,
- SD_STATE_STBY,
- SD_STATE_TRAN,
- SD_STATE_DATA,
- SD_STATE_DATA_MULTI, // synthetical state for this implementation
- SD_STATE_RCV,
- SD_STATE_PRG,
- SD_STATE_DIS,
- SD_STATE_INA,
-
- //FIXME Existing states which must be revisited
- SD_STATE_WRITE_WAITFE,
- SD_STATE_WRITE_DATA
+ SD_TYPE_V2,
+ SD_TYPE_HC
};
- sd_state m_state;
+
+ enum sd_state : u8;
// MMFS for Acorn machines expect dummy byte before response
- static constexpr int SPI_DELAY_RESPONSE = 1;
+ static constexpr u8 SPI_DELAY_RESPONSE = 1;
+
+ std::error_condition image_loaded(device_image_interface &image);
+ void image_unloaded(device_image_interface &image);
- void send_data(u16 count, sd_state new_state);
+ void send_data(u16 count, sd_state new_state, u8 delay = SPI_DELAY_RESPONSE);
void do_command();
void change_state(sd_state new_state);
void latch_in();
void shift_out();
- u8 m_data[520], m_cmd[6];
+ // configuration
+ sd_type m_preferred_type;
+
+ // mounted image info
+ std::vector<u8> m_sectorbuf;
+ u16 m_blksize;
+ sd_type m_type;
+ u8 m_csd[16];
- int m_ss, m_in_bit, m_clk_state;
+ // live state
+ std::unique_ptr<u8 []> m_data;
+ u8 m_cmd[6];
+ sd_state m_state;
+ u8 m_ss, m_in_bit, m_clk_state;
u8 m_in_latch, m_out_latch, m_cur_bit;
- u16 m_out_count, m_out_ptr, m_write_ptr, m_blksize;
+ u8 m_out_delay;
+ u16 m_out_count, m_out_ptr, m_write_ptr;
+ u16 m_xferblk;
u32 m_blknext;
+ bool m_crc_off;
bool m_bACMD;
};
-class spi_sdcard_sdhc_device : public spi_sdcard_device
-{
-public:
- spi_sdcard_sdhc_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock);
-};
-
-class spi_sdcard_sdv2_device : public spi_sdcard_device
-{
-public:
- spi_sdcard_sdv2_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock);
-};
-
-DECLARE_DEVICE_TYPE(SPI_SDCARD, spi_sdcard_sdhc_device)
-DECLARE_DEVICE_TYPE(SPI_SDCARDV2, spi_sdcard_sdv2_device)
+DECLARE_DEVICE_TYPE(SPI_SDCARD, spi_sdcard_device)
#endif // MAME_MACHINE_SPI_SDCARD_H