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