1 | /////////////////////////////////////////////////////////////////////////////////// |
---|
2 | // File : sdc_driver.h |
---|
3 | // Date : 31/08/2012 |
---|
4 | // Author : cesar fuguet |
---|
5 | // Copyright (c) UPMC-LIP6 |
---|
6 | /////////////////////////////////////////////////////////////////////////////////// |
---|
7 | |
---|
8 | #ifndef _GIET_SDC_DRIVER_H_ |
---|
9 | #define _GIET_SDC_DRIVER_H_ |
---|
10 | |
---|
11 | |
---|
12 | #include <soclib_spi.h> |
---|
13 | #include <hard_config.h> |
---|
14 | |
---|
15 | /////////////////////////////////////////////////////////////////////////////// |
---|
16 | // SD card structure definition |
---|
17 | /////////////////////////////////////////////////////////////////////////////// |
---|
18 | struct sdcard_dev |
---|
19 | { |
---|
20 | // SPI controller pointer |
---|
21 | struct spi_dev * spi; |
---|
22 | |
---|
23 | // block length of the SDCARD |
---|
24 | unsigned int block_length; |
---|
25 | |
---|
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 |
---|
29 | unsigned int access_pointer; |
---|
30 | |
---|
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; |
---|
34 | |
---|
35 | // is the card high capacity ? |
---|
36 | int sdhc; |
---|
37 | }; |
---|
38 | |
---|
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 | /////////////////////////////////////////////////////////////////////////////// |
---|
45 | unsigned int _sdc_init(); |
---|
46 | |
---|
47 | /////////////////////////////////////////////////////////////////////////////// |
---|
48 | // Transfer data between the block device and a memory buffer. |
---|
49 | // - use_irq : not used, as DMA is not supported yet |
---|
50 | // - to_mem : to memory if non zero |
---|
51 | // - lba : first block index on the block device |
---|
52 | // - buf_vaddr : base address of the memory buffer |
---|
53 | // - count : number of blocks to be transfered. |
---|
54 | // Returns 0 if success, > 0 if error. |
---|
55 | /////////////////////////////////////////////////////////////////////////////// |
---|
56 | unsigned int _sdc_access( unsigned int use_irq, |
---|
57 | unsigned int to_mem, |
---|
58 | unsigned int lba, |
---|
59 | unsigned long long buf_vaddr, |
---|
60 | unsigned int count); |
---|
61 | |
---|
62 | /////////////////////////////////////////////////////////////////////////////// |
---|
63 | // This ISR handles the IRQ generated by a SDC controler |
---|
64 | /////////////////////////////////////////////////////////////////////////////// |
---|
65 | void _sdc_isr( unsigned int irq_type, |
---|
66 | unsigned int irq_id, |
---|
67 | unsigned int channel ); |
---|
68 | |
---|
69 | /////////////////////////////////////////////////////////////////////////////// |
---|
70 | // SD card constants |
---|
71 | /////////////////////////////////////////////////////////////////////////////// |
---|
72 | |
---|
73 | // Number of retries after an unacknowledge command |
---|
74 | #define SDCARD_COMMAND_TIMEOUT 100 |
---|
75 | |
---|
76 | // This command is a simple SD commmand |
---|
77 | #define SDCARD_CMD 0 |
---|
78 | |
---|
79 | // This is an application specific command |
---|
80 | #define SDCARD_ACMD 1 |
---|
81 | |
---|
82 | // The transmition is done in the negative edge of the clock |
---|
83 | #define SDCARD_TX_NEGEDGE 0 |
---|
84 | |
---|
85 | // The transmition is done in the positive edge of the clock |
---|
86 | #define SDCARD_TX_POSEDGE 1 |
---|
87 | |
---|
88 | // The reception is done in the negative edge of the clock |
---|
89 | #define SDCARD_RX_NEGEDGE 0 |
---|
90 | |
---|
91 | // The reception is done in the positive edge of the clock |
---|
92 | #define SDCARD_RX_POSEDGE 1 |
---|
93 | |
---|
94 | /////////////////////////////////////////////////////////////////////////////// |
---|
95 | // SD card macros |
---|
96 | /////////////////////////////////////////////////////////////////////////////// |
---|
97 | |
---|
98 | /////////////////////////////////////////////////////////////////////////////// |
---|
99 | // SDCARD_CHECK_R1_VALID() |
---|
100 | // This macro checks if the SD card response is valid |
---|
101 | // - x: SD card response |
---|
102 | // Returns 1 if valid and 0 otherwise |
---|
103 | /////////////////////////////////////////////////////////////////////////////// |
---|
104 | #define SDCARD_CHECK_R1_VALID(x) (~x & SDCARD_R1_RSP_VALID) ? 1 : 0 |
---|
105 | |
---|
106 | /////////////////////////////////////////////////////////////////////////////// |
---|
107 | // SDCARD_CHECK_R1_ERROR() |
---|
108 | // This macro checks if there is an error in SD card response |
---|
109 | // - x: SD card response |
---|
110 | // Returns 1 if error and 0 otherwise |
---|
111 | /////////////////////////////////////////////////////////////////////////////// |
---|
112 | #define SDCARD_CHECK_R1_ERROR(x) ( x & 0x7E) ? 1 : 0 |
---|
113 | |
---|
114 | // SD card response 1 (R1) format constants |
---|
115 | #define SDCARD_R1_IN_IDLE_STATE ( 1 << 0 ) // R1 bit 0 |
---|
116 | #define SDCARD_R1_ERASE_RESET ( 1 << 1 ) // R1 bit 1 |
---|
117 | #define SDCARD_R1_ILLEGAL_CMD ( 1 << 2 ) // R1 bit 2 |
---|
118 | #define SDCARD_R1_COM_CRC_ERR ( 1 << 3 ) // R1 bit 3 |
---|
119 | #define SDCARD_R1_ERASE_SEQ_ERR ( 1 << 4 ) // R1 bit 4 |
---|
120 | #define SDCARD_R1_ADDRESS_ERR ( 1 << 5 ) // R1 bit 5 |
---|
121 | #define SDCARD_R1_PARAMETER_ERR ( 1 << 6 ) // R1 bit 6 |
---|
122 | #define SDCARD_R1_RSP_VALID ( 1 << 7 ) // R1 bit 7 |
---|
123 | |
---|
124 | #endif |
---|
125 | |
---|
126 | // Local Variables: |
---|
127 | // tab-width: 4 |
---|
128 | // c-basic-offset: 4 |
---|
129 | // c-file-offsets:((innamespace . 0)(inline-open . 0)) |
---|
130 | // indent-tabs-mode: nil |
---|
131 | // End: |
---|
132 | // vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 |
---|