[284] | 1 | /////////////////////////////////////////////////////////////////////////////////// |
---|
| 2 | // File : sdc_driver.h |
---|
| 3 | // Date : 31/08/2012 |
---|
| 4 | // Author : cesar fuguet |
---|
| 5 | // Copyright (c) UPMC-LIP6 |
---|
| 6 | /////////////////////////////////////////////////////////////////////////////////// |
---|
[437] | 7 | |
---|
[284] | 8 | #ifndef _GIET_SDC_DRIVER_H_ |
---|
| 9 | #define _GIET_SDC_DRIVER_H_ |
---|
[283] | 10 | |
---|
| 11 | #include <ioc_driver.h> |
---|
| 12 | #include <spi_driver.h> |
---|
| 13 | #include <mapping_info.h> |
---|
| 14 | |
---|
[284] | 15 | /////////////////////////////////////////////////////////////////////////////// |
---|
| 16 | // SD card structure definition |
---|
| 17 | /////////////////////////////////////////////////////////////////////////////// |
---|
[283] | 18 | struct sdcard_dev |
---|
| 19 | { |
---|
[284] | 20 | // SPI controller pointer |
---|
[283] | 21 | struct spi_dev * spi; |
---|
| 22 | |
---|
[284] | 23 | // block length of the SDCARD |
---|
[283] | 24 | unsigned int block_length; |
---|
| 25 | |
---|
[284] | 26 | // access pointer representing the offset in bytes used to read or write in |
---|
| 27 | // the SDCARD. This driver is for cards SDSD, therefore this offset must be |
---|
| 28 | // multiple of the block length |
---|
[283] | 29 | unsigned int access_pointer; |
---|
| 30 | |
---|
[284] | 31 | // slave ID. This ID represents the number of the slave select signal used |
---|
| 32 | // in the hardware platform (SPI channel) |
---|
| 33 | int slave_id; |
---|
[283] | 34 | |
---|
[284] | 35 | // is the card high capacity ? |
---|
[283] | 36 | int sdhc; |
---|
| 37 | }; |
---|
| 38 | |
---|
[437] | 39 | /////////////////////////////////////////////////////////////////////////////// |
---|
| 40 | // This function initializes the SPI controller and call sdc_open to |
---|
| 41 | // initialize the SD card |
---|
| 42 | // - channel: channel to initialize (only channel 0 supported) |
---|
| 43 | // Returns 0 if success, other value if failure |
---|
| 44 | /////////////////////////////////////////////////////////////////////////////// |
---|
[295] | 45 | unsigned int _sdc_init(); |
---|
[283] | 46 | |
---|
[437] | 47 | /////////////////////////////////////////////////////////////////////////////// |
---|
| 48 | // Transfer data from the block device to a memory buffer. |
---|
| 49 | // - mode : BOOT / KERNEL / USER |
---|
| 50 | // - lba : first block index on the block device |
---|
| 51 | // - buffer : base address of the memory buffer (must be word aligned) |
---|
| 52 | // - count : number of blocks to be transfered. |
---|
| 53 | // Returns 0 if success, > 0 if error. |
---|
| 54 | /////////////////////////////////////////////////////////////////////////////// |
---|
[283] | 55 | unsigned int _sdc_read( unsigned int mode, |
---|
| 56 | unsigned int lba, |
---|
| 57 | paddr_t buffer, |
---|
| 58 | unsigned int count); |
---|
| 59 | |
---|
| 60 | |
---|
[437] | 61 | /////////////////////////////////////////////////////////////////////////////// |
---|
| 62 | // Transfer data from memory buffer to SD card device. |
---|
| 63 | // - mode : BOOT / KERNEL / USER |
---|
| 64 | // - lba : destination first block index on the SD card |
---|
| 65 | // - buffer : base address of the memory buffer (must be word aligned) |
---|
| 66 | // - count : number of blocks to be transfered. |
---|
| 67 | // Returns 0 if success, > 0 if error. |
---|
| 68 | // WARNING: The _sdc_write() is not implemented yet. |
---|
| 69 | /////////////////////////////////////////////////////////////////////////////// |
---|
[283] | 70 | unsigned int _sdc_write( unsigned int mode, |
---|
| 71 | unsigned int lba, |
---|
| 72 | paddr_t buffer, |
---|
| 73 | unsigned int count); |
---|
| 74 | |
---|
[437] | 75 | /////////////////////////////////////////////////////////////////////////////// |
---|
| 76 | // This function should not be called for the SDC card. |
---|
| 77 | /////////////////////////////////////////////////////////////////////////////// |
---|
[295] | 78 | unsigned int _sdc_get_status(); |
---|
| 79 | |
---|
[437] | 80 | /////////////////////////////////////////////////////////////////////////////// |
---|
| 81 | // Returns the block size in bytes of the SD card. |
---|
| 82 | /////////////////////////////////////////////////////////////////////////////// |
---|
[283] | 83 | unsigned int _sdc_get_block_size(); |
---|
| 84 | |
---|
| 85 | |
---|
[284] | 86 | /////////////////////////////////////////////////////////////////////////////// |
---|
| 87 | // SD card constants |
---|
| 88 | /////////////////////////////////////////////////////////////////////////////// |
---|
[283] | 89 | |
---|
[284] | 90 | // Number of retries after an unacknowledge command |
---|
| 91 | #define SDCARD_COMMAND_TIMEOUT 100 |
---|
[283] | 92 | |
---|
[284] | 93 | // This command is a simple SD commmand |
---|
| 94 | #define SDCARD_CMD 0 |
---|
[283] | 95 | |
---|
[284] | 96 | // This is an application specific command |
---|
| 97 | #define SDCARD_ACMD 1 |
---|
[283] | 98 | |
---|
[284] | 99 | // The transmition is done in the negative edge of the clock |
---|
| 100 | #define SDCARD_TX_NEGEDGE 0 |
---|
[283] | 101 | |
---|
[284] | 102 | // The transmition is done in the positive edge of the clock |
---|
| 103 | #define SDCARD_TX_POSEDGE 1 |
---|
[283] | 104 | |
---|
[284] | 105 | // The reception is done in the negative edge of the clock |
---|
| 106 | #define SDCARD_RX_NEGEDGE 0 |
---|
[283] | 107 | |
---|
[284] | 108 | // The reception is done in the positive edge of the clock |
---|
| 109 | #define SDCARD_RX_POSEDGE 1 |
---|
[283] | 110 | |
---|
[284] | 111 | /////////////////////////////////////////////////////////////////////////////// |
---|
| 112 | // SD card macros |
---|
| 113 | /////////////////////////////////////////////////////////////////////////////// |
---|
[283] | 114 | |
---|
[284] | 115 | /////////////////////////////////////////////////////////////////////////////// |
---|
| 116 | // SDCARD_CHECK_R1_VALID() |
---|
| 117 | // This macro checks if the SD card response is valid |
---|
| 118 | // - x: SD card response |
---|
| 119 | // Returns 1 if valid and 0 otherwise |
---|
| 120 | /////////////////////////////////////////////////////////////////////////////// |
---|
[283] | 121 | #define SDCARD_CHECK_R1_VALID(x) (~x & SDCARD_R1_RSP_VALID) ? 1 : 0 |
---|
| 122 | |
---|
[284] | 123 | /////////////////////////////////////////////////////////////////////////////// |
---|
| 124 | // SDCARD_CHECK_R1_ERROR() |
---|
| 125 | // This macro checks if there is an error in SD card response |
---|
| 126 | // - x: SD card response |
---|
| 127 | // Returns 1 if error and 0 otherwise |
---|
| 128 | /////////////////////////////////////////////////////////////////////////////// |
---|
[283] | 129 | #define SDCARD_CHECK_R1_ERROR(x) ( x & 0x7E) ? 1 : 0 |
---|
| 130 | |
---|
[284] | 131 | // SD card response 1 (R1) format constants |
---|
| 132 | #define SDCARD_R1_IN_IDLE_STATE ( 1 << 0 ) // R1 bit 0 |
---|
| 133 | #define SDCARD_R1_ERASE_RESET ( 1 << 1 ) // R1 bit 1 |
---|
| 134 | #define SDCARD_R1_ILLEGAL_CMD ( 1 << 2 ) // R1 bit 2 |
---|
| 135 | #define SDCARD_R1_COM_CRC_ERR ( 1 << 3 ) // R1 bit 3 |
---|
| 136 | #define SDCARD_R1_ERASE_SEQ_ERR ( 1 << 4 ) // R1 bit 4 |
---|
| 137 | #define SDCARD_R1_ADDRESS_ERR ( 1 << 5 ) // R1 bit 5 |
---|
| 138 | #define SDCARD_R1_PARAMETER_ERR ( 1 << 6 ) // R1 bit 6 |
---|
| 139 | #define SDCARD_R1_RSP_VALID ( 1 << 7 ) // R1 bit 7 |
---|
[283] | 140 | |
---|
| 141 | #endif |
---|
| 142 | |
---|
[284] | 143 | // Local Variables: |
---|
| 144 | // tab-width: 4 |
---|
| 145 | // c-basic-offset: 4 |
---|
| 146 | // c-file-offsets:((innamespace . 0)(inline-open . 0)) |
---|
| 147 | // indent-tabs-mode: nil |
---|
| 148 | // End: |
---|
| 149 | // vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 |
---|