Quentin Mettraux
/
MAVErIC_TEST
Working Maveric
Diff: SDBlockDevice.h
- Revision:
- 6:ef95300898b2
- Parent:
- 0:bdca5e4773dd
- Child:
- 9:b6a9d1c44ed9
--- a/SDBlockDevice.h Thu May 11 15:57:07 2017 +0000 +++ b/SDBlockDevice.h Tue May 30 21:11:54 2017 +0000 @@ -28,6 +28,7 @@ #include "BlockDevice.h" #include "mbed.h" + /** Access an SD Card using SPI * * @code @@ -126,29 +127,24 @@ */ virtual void debug(bool dbg); -protected: - class SPI_HS : public SPI { - public: - SPI_HS(PinName mosi, PinName miso, PinName sclk, PinName ssel=NC) : SPI(mosi, miso, sclk, ssel) {} - - virtual int write(int value) { - aquire(); - int ret = spi_master_write(&_spi, value); - return ret; - } - protected: - virtual void aquire(void) { - if (_owner != this) { - spi_format(&_spi, _bits, _mode, 0); - spi_frequency(&_spi, _hz); - _owner = this; - } - } - }; +private: int _cmd(int cmd, int arg); int _cmdx(int cmd, int arg); int _cmd8(); int _cmd58(); + + /* Move the SDCard into the SPI Mode idle state + * + * The card is transitioned from SDCard mode to SPI mode by sending the + * CMD0 (GO_IDLE_STATE) command with CS asserted. See the notes in the + * "SPI Startup" section of the comments at the head of the + * implementation file for further details and specification references. + * + * @return -1 if an error occurred e.g. a valid response was not + * received. Otherwise R1_IDLE_STATE (0x1), the successful + * response from CMD0. + */ + int _go_idle_state(); int _initialise_card(); int _initialise_card_v1(); int _initialise_card_v2(); @@ -161,15 +157,16 @@ uint32_t _init_sck; uint32_t _transfer_sck; - SPI_HS _spi; + SPI _spi; DigitalOut _cs; unsigned _block_size; bool _is_initialized; bool _dbg; - Mutex _lock; + mutable Mutex _lock; }; #endif /* DEVICE_SPI */ #endif /* MBED_SD_BLOCK_DEVICE_H */ +