NetBurner 3.1
sdioBus.h
1 /*NB_REVISION*/
2 
3 /*NB_COPYRIGHT*/
4 
5 #ifndef _SDIOBUS_H_
6 #define _SDIOBUS_H_
7 
8 /*
9  ******************************************************************************
10  *
11  * Debugging
12  *
13  ******************************************************************************
14  */
15 /* Library debugging switch */
16 #define SDIO_BUS_DEBUG (1)
17 
18 #ifdef SDIO_BUS_DEBUG
19 #define SDIO_DEBUG_IPRINTF(...) \
20  { \
21  iprintf("%s:%d", __FUNCTION__, __LINE__); \
22  iprintf(__VA_ARGS__); \
23  iprintf("\r\n"); \
24  }
25 #else /* #ifdef SDIO_BUS_DEBUG */
26 #define SDIO_DEBUG_IPRINTF(...) ((void)0)
27 #endif /* #ifdef SDIO_BUS_DEBUG */
28 
29 /*
30  ******************************************************************************
31  *
32  * Runtime Library Definitions
33  *
34  ******************************************************************************
35  */
36 /* Bus type */
37 #define SDIO_SPI_BUS (1)
38 
39 /*
40  ******************************************************************************
41  *
42  * Typedefs
43  *
44  ******************************************************************************
45  */
46 /*
47  ******************************************************************************
48 
49  Controller interrupt service routine (ISR)
50 
51  Parameters:
52  None
53 
54  Return:
55  None
56 
57  Notes:
58  None
59 
60  ******************************************************************************
61  */
62 extern "C" typedef void (*SdioInterruptService)(void);
63 
64 /*
65  ******************************************************************************
66  *
67  * SDIO Bus Base Class
68  *
69  ******************************************************************************
70  */
71 class SdioBus
72 {
73  public:
74  /*** Constructor ***/
75  SdioBus(uint32_t speed, uint32_t connectTimeout, uint32_t responseTimeout);
76 
77  /*** Destructor ***/
78  virtual ~SdioBus();
79 
80  /*** Methods ***/
81  /* Attach to bus */
82  virtual BOOL attachBus(void) = 0;
83 
84  /* Acquire bus */
85  virtual BOOL acquireBus(void) = 0;
86 
87  /* Release bus */
88  virtual void releaseBus(void) = 0;
89 
90  /* Select card on bus */
91  virtual void selectCard(void) = 0;
92 
93  /* Release card */
94  virtual void releaseCard(void) = 0;
95 
96  /* Send command */
97  virtual BOOL sendCommand(SdioCommand &command) = 0;
98 
99  /* Receive response */
100  virtual BOOL receiveResponse(SdioResponse &response, BOOL idle = TRUE) = 0;
101 
102  /* Send data */
103  virtual BOOL sendData(const puint8_t dataPtr, ssize_t dataLength) = 0;
104 
105  /* Receive data */
106  virtual BOOL receiveData(puint8_t dataPtr, ssize_t dataLength) = 0;
107 
108  /* Idle bus */
109  virtual void idleBus(void) = 0;
110 
111  /* Execute extended command (e.g. CMD53) */
112  virtual BOOL executeExtendedCommand(SdioCommand &command,
113  SdioResponse &response,
114  BOOL writeData,
115  puint8_t dataPtr,
116  ssize_t dataLength) = 0;
117 
118  /*** Accessors ***/
119  /* Bus speed in Hz */
120  uint32_t getSpeed(void);
121 
122  /* Connect timeout */
123  uint32_t getConnectTimeout(void);
124 
125  /* Connect timeout */
126  uint32_t getResponseTimeout(void);
127 
128  /* Valid ? */
129  BOOL isValid(void);
130 
131  protected:
132  /* None */
133 
134  private:
135  /*** Methods ***/
136  /* None */
137 
138  /*** Data Members ***/
139  /* Bus speed in Hz */
140  uint32_t __speed;
141 
142  /* Connect timeouts in ticks */
143  uint32_t __connectTimeout;
144 
145  /* Response timeouts in ticks */
146  uint32_t __responseTimeout;
147 
148  /* Valid? */
149  BOOL __valid;
150 };
151 
152 /*
153  ******************************************************************************
154  *
155  * SDIO Bus SPI Mode
156  *
157  ******************************************************************************
158  */
159 class SdioBusSpiMode : public SdioBus
160 {
161  public:
162  /*** Constructor ***/
163  SdioBusSpiMode(uint32_t speed,
164  uint32_t connectTimeout,
165  uint32_t responseTimeout,
166  ssize_t idleByteCount,
167  uint16_t idleFillValue,
168  int chipSelectMask,
169  NetDeviceSelectDetail chipSelectDetail);
170 
171  /*** Destructor ***/
172  ~SdioBusSpiMode();
173 
174  /*** Methods ***/
175  /* Attach to bus */
176  BOOL attachBus(void);
177 
178  /* Acquire bus */
179  BOOL acquireBus(void);
180 
181  /* Release bus */
182  void releaseBus(void);
183 
184  /* Select card on bus */
185  void selectCard(void);
186 
187  /* Release card */
188  void releaseCard(void);
189 
190  /* Send command */
191  BOOL sendCommand(SdioCommand &command);
192 
193  /* Receive response */
194  BOOL receiveResponse(SdioResponse &response, BOOL idleBus = TRUE);
195 
196  /* Send data */
197  BOOL sendData(const puint8_t dataPtr, ssize_t dataLength);
198 
199  /* Receive data */
200  BOOL receiveData(puint8_t dataPtr, ssize_t dataLength);
201 
202  /* Idle bus */
203  void idleBus(void);
204 
205  /* Execute extended command (e.g. CMD53) */
206  BOOL executeExtendedCommand(SdioCommand &command, SdioResponse &response, BOOL writeData, puint8_t dataPtr, ssize_t dataLength);
207 
208  protected:
209  /* None */
210 
211  private:
212  /*** Methods ***/
213  /* Wait for and the get data received token */
214  uint8_t waitForDataReceived(void);
215 
216  /* Waits for data start token */
217  BOOL waitForData(void);
218 
219  /*** Data Members ***/
220  /* SPI setting handle*/
221  int __spiSetting;
222 
223  /* SPI chip select mask */
224  int __chipSelectMask;
225 
226  /* SPI chip select detail */
227  NetDeviceSelectDetail __chipSelectDetail;
228 
229  /* SPI chip select mask */
230  int __chipSelectPin;
231 
232  /* Bytes to idle bus */
233  ssize_t __idleByteCount;
234 
235  /* Value used to idle bus */
236  uint16_t __idleFillValue;
237 };
238 
239 #endif /* _SDIOBUS_H_ */