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