source: soft/giet_vm/giet_drivers/sdc_driver.h @ 552

Last change on this file since 552 was 545, checked in by alain, 9 years ago

Cosmetic

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