source: trunk/hal/tsar_mips32/drivers/soclib_sdc.h @ 550

Last change on this file since 550 was 550, checked in by nicolas.van.phan@…, 3 years ago

Add SD card driver in kernel

File size: 4.8 KB
Line 
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 <chdev.h>
13#include <soclib_spi.h>
14#include <hard_config.h>
15
16///////////////////////////////////////////////////////////////////////////////
17// SD card structure definition
18///////////////////////////////////////////////////////////////////////////////
19struct sdcard_dev
20{ 
21    // SPI controller pointer
22    struct spi_dev * spi;
23
24    // block length of the SDCARD
25    unsigned int block_length;
26
27    // access pointer representing the offset in bytes used to read or write in
28    // the SDCARD. This driver is for cards SDSD, therefore this offset must be
29    // multiple of the block length
30    unsigned int access_pointer;
31
32    // slave ID. This ID represents the number of the slave select signal used
33    // in the hardware platform (SPI channel)
34    int slave_id;
35
36    // is the card high capacity ?
37    int sdhc;
38};
39
40///////////////////////////////////////////////////////////////////////////////
41// This function initializes the SPI controller and call sdc_open to
42// initialize  the SD card
43// - channel: channel to initialize (only channel 0 supported)
44// Returns 0 if success, other value if failure
45///////////////////////////////////////////////////////////////////////////////
46// unsigned int _sdc_init();
47extern void soclib_sdc_init( chdev_t* chdev );
48
49///////////////////////////////////////////////////////////////////////////////
50// Transfer data between the block device and a memory buffer.
51// - use_irq   : not used, as DMA is not supported yet
52// - to_mem    : to memory if non zero
53// - lba       : first block index on the block device
54// - buf_vaddr : base address of the memory buffer
55// - count     : number of blocks to be transfered.
56// Returns 0 if success, > 0 if error.
57///////////////////////////////////////////////////////////////////////////////
58extern void soclib_sdc_cmd( xptr_t thread_xp );
59
60///////////////////////////////////////////////////////////////////////////////
61// This ISR handles the IRQ generated by a SDC controler
62///////////////////////////////////////////////////////////////////////////////
63extern void soclib_sdc_isr( chdev_t* chdev );
64
65///////////////////////////////////////////////////////////////////////////////
66// SD card constants
67///////////////////////////////////////////////////////////////////////////////
68
69// Number of retries after an unacknowledge command
70#define SDCARD_COMMAND_TIMEOUT  100
71
72// This command is a simple SD commmand
73#define SDCARD_CMD              0
74
75// This is an application specific command
76#define SDCARD_ACMD             1
77
78// The transmition is done in the negative edge of the clock
79#define SDCARD_TX_NEGEDGE       0
80
81// The transmition is done in the positive edge of the clock
82#define SDCARD_TX_POSEDGE       1
83
84// The reception is done in the negative edge of the clock
85#define SDCARD_RX_NEGEDGE       0
86
87// The reception is done in the positive edge of the clock
88#define SDCARD_RX_POSEDGE       1
89
90///////////////////////////////////////////////////////////////////////////////
91// SD card macros
92///////////////////////////////////////////////////////////////////////////////
93
94///////////////////////////////////////////////////////////////////////////////
95//   SDCARD_CHECK_R1_VALID()
96// This macro checks if the SD card response is valid
97// - x: SD card response
98// Returns 1 if valid and 0 otherwise
99///////////////////////////////////////////////////////////////////////////////
100#define SDCARD_CHECK_R1_VALID(x)    (~x & SDCARD_R1_RSP_VALID) ? 1 : 0
101
102///////////////////////////////////////////////////////////////////////////////
103//   SDCARD_CHECK_R1_ERROR()
104// This macro checks if there is an error in SD card response
105// - x: SD card response
106// Returns 1 if error and 0 otherwise
107///////////////////////////////////////////////////////////////////////////////
108#define SDCARD_CHECK_R1_ERROR(x)    ( x & 0x7E)                ? 1 : 0
109
110// SD card response 1 (R1) format constants
111#define SDCARD_R1_IN_IDLE_STATE     ( 1 << 0 ) // R1 bit 0
112#define SDCARD_R1_ERASE_RESET       ( 1 << 1 ) // R1 bit 1
113#define SDCARD_R1_ILLEGAL_CMD       ( 1 << 2 ) // R1 bit 2
114#define SDCARD_R1_COM_CRC_ERR       ( 1 << 3 ) // R1 bit 3
115#define SDCARD_R1_ERASE_SEQ_ERR     ( 1 << 4 ) // R1 bit 4
116#define SDCARD_R1_ADDRESS_ERR       ( 1 << 5 ) // R1 bit 5
117#define SDCARD_R1_PARAMETER_ERR     ( 1 << 6 ) // R1 bit 6
118#define SDCARD_R1_RSP_VALID         ( 1 << 7 ) // R1 bit 7
119
120#endif
121
122// Local Variables:
123// tab-width: 4
124// c-basic-offset: 4
125// c-file-offsets:((innamespace . 0)(inline-open . 0))
126// indent-tabs-mode: nil
127// End:
128// vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
Note: See TracBrowser for help on using the repository browser.