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

Last change on this file since 663 was 619, checked in by alain, 6 years ago

1) Fix a bug in KSH : after the "load" command,

the [ksh] prompt is now printed after completion
of the loaded application.

2) Fix a bug in vmm_handle_cow() : the copy-on-write

use now a hal_remote_memcpy() to replicate the page content.


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///////////////////////////////////////////////////////////////////////////////
19typedef struct 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}
39sdcard_dev_t;
40
41///////////////////////////////////////////////////////////////////////////////
42// This function initializes the SPI controller and call sdc_open to
43// initialize  the SD card
44// - channel: channel to initialize (only channel 0 supported)
45// Returns 0 if success, other value if failure
46///////////////////////////////////////////////////////////////////////////////
47// unsigned int _sdc_init();
48extern void soclib_sdc_init( chdev_t* chdev );
49
50///////////////////////////////////////////////////////////////////////////////
51// Transfer data between the block device and a memory buffer.
52// - use_irq   : not used, as DMA is not supported yet
53// - to_mem    : to memory if non zero
54// - lba       : first block index on the block device
55// - buf_vaddr : base address of the memory buffer
56// - count     : number of blocks to be transfered.
57// Returns 0 if success, > 0 if error.
58///////////////////////////////////////////////////////////////////////////////
59extern void soclib_sdc_cmd( xptr_t thread_xp );
60
61///////////////////////////////////////////////////////////////////////////////
62// This ISR handles the IRQ generated by a SDC controler
63///////////////////////////////////////////////////////////////////////////////
64extern void soclib_sdc_isr( chdev_t* chdev );
65
66///////////////////////////////////////////////////////////////////////////////
67// SD card constants
68///////////////////////////////////////////////////////////////////////////////
69
70// Number of retries after an unacknowledge command
71#define SDCARD_COMMAND_TIMEOUT  100
72
73// This command is a simple SD commmand
74#define SDCARD_CMD              0
75
76// This is an application specific command
77#define SDCARD_ACMD             1
78
79// The transmition is done in the negative edge of the clock
80#define SDCARD_TX_NEGEDGE       0
81
82// The transmition is done in the positive edge of the clock
83#define SDCARD_TX_POSEDGE       1
84
85// The reception is done in the negative edge of the clock
86#define SDCARD_RX_NEGEDGE       0
87
88// The reception is done in the positive edge of the clock
89#define SDCARD_RX_POSEDGE       1
90
91///////////////////////////////////////////////////////////////////////////////
92// SD card macros
93///////////////////////////////////////////////////////////////////////////////
94
95///////////////////////////////////////////////////////////////////////////////
96//   SDCARD_CHECK_R1_VALID()
97// This macro checks if the SD card response is valid
98// - x: SD card response
99// Returns 1 if valid and 0 otherwise
100///////////////////////////////////////////////////////////////////////////////
101#define SDCARD_CHECK_R1_VALID(x)    (~x & SDCARD_R1_RSP_VALID) ? 1 : 0
102
103///////////////////////////////////////////////////////////////////////////////
104//   SDCARD_CHECK_R1_ERROR()
105// This macro checks if there is an error in SD card response
106// - x: SD card response
107// Returns 1 if error and 0 otherwise
108///////////////////////////////////////////////////////////////////////////////
109#define SDCARD_CHECK_R1_ERROR(x)    ( x & 0x7E)                ? 1 : 0
110
111// SD card response 1 (R1) format constants
112#define SDCARD_R1_IN_IDLE_STATE     ( 1 << 0 ) // R1 bit 0
113#define SDCARD_R1_ERASE_RESET       ( 1 << 1 ) // R1 bit 1
114#define SDCARD_R1_ILLEGAL_CMD       ( 1 << 2 ) // R1 bit 2
115#define SDCARD_R1_COM_CRC_ERR       ( 1 << 3 ) // R1 bit 3
116#define SDCARD_R1_ERASE_SEQ_ERR     ( 1 << 4 ) // R1 bit 4
117#define SDCARD_R1_ADDRESS_ERR       ( 1 << 5 ) // R1 bit 5
118#define SDCARD_R1_PARAMETER_ERR     ( 1 << 6 ) // R1 bit 6
119#define SDCARD_R1_RSP_VALID         ( 1 << 7 ) // R1 bit 7
120
121#endif
122
123// Local Variables:
124// tab-width: 4
125// c-basic-offset: 4
126// c-file-offsets:((innamespace . 0)(inline-open . 0))
127// indent-tabs-mode: nil
128// End:
129// vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
Note: See TracBrowser for help on using the repository browser.