NetBurner 3.1
qspiBsp.h
1 /*NB_REVISION*/
2 
3 /*NB_COPYRIGHT*/
4 
5 #ifndef _QSPI_BSP_H_
6 #define _QSPI_BSP_H_
7 
8 /*
9  *****************************************************************************-
10  *
11  * Definitions
12  *
13  *****************************************************************************-
14  */
15 /*
16  * Interrupt controller settings for:
17  * MOD5270
18  * SB70
19  * MOD5213
20  * PK70
21  * MOD5282
22  * MOD5234
23  */
24 /* Interrupt source (vector) */
25 #define QSPI_INTERRUPT_SOURCE (18)
26 
27 /* Interrupt level */
28 #define QSPI_INTERRUPT_LEVEL (2)
29 
30 /* Interrupt level */
31 #define QSPI_INTERRUPT_PRIORITY (7)
32 
33 /*
34  * RAM addresses
35  */
36 #define QSPI_RAM_ENTRIES (16)
37 #define QSPI_RAM_TRANSMIT_START (0x00)
38 #define QSPI_RAM_RECEIVE_START (0x10)
39 #define QSPI_RAM_COMMAND_START (0x20)
40 
41 /*
42  *****************************************************************************-
43  *
44  * Structures
45  *
46  *****************************************************************************-
47  */
48 /*
49  QSPI Mode Register (QMR)
50  mstr - Master mode, must be one
51  dohie - DOUT high impedance or driven when idle?
52  bits - Transfer size 8 through 16 (1000-1111 & 0000 )
53  cpol - Clock polarity (is inactive level)
54  cpha - Clock phase of data capture, 0 leading, 1 falling
55  baud - Baud rate divider 0 disables, 2-255
56 
57  */
58 typedef struct _QmrFields
59 {
60  uint16_t mstr : 1;
61  uint16_t dohie : 1;
62  uint16_t bits : 4;
63  uint16_t cpol : 1;
64  uint16_t cpha : 1;
65  uint16_t baud : 8;
66 
67 } __attribute__((packed)) QmrFields;
68 
69 typedef union _Qmr {
70  QmrFields field;
71  uint16_t content;
72 
73 } __attribute__((packed)) Qmr;
74 
75 /*
76  QSPI Delay Register (QDLYR)
77  spe - Enable
78  qcd - Chip select to valid clock (dsck bit in command RAM)
79  dtl - Delay after transfer (dt bit in command RAM)
80 
81  */
82 typedef struct _QdlyrFields
83 {
84  uint16_t spe : 1;
85  uint16_t qcd : 7;
86  uint16_t dtl : 8;
87 
88 } __attribute__((packed)) QdlyrFields;
89 
90 typedef union _Qdlyr {
91  QdlyrFields field;
92  uint16_t content;
93 
94 } __attribute__((packed)) Qdlyr;
95 
96 /*
97  QSPI Wrap Register (QWR)
98  halt - Halts transfer
99  wren - Wrap around enabled
100  wrto - Wrap around location
101  csiv - Chip select inactive level
102  endqp - End of queue pointer
103  cptqp - Completed queue entry pointer (R)
104  newqp - Start of queue pointer
105 
106  */
107 typedef struct _QwrFields
108 {
109  uint16_t halt : 1;
110  uint16_t wren : 1;
111  uint16_t wrto : 1;
112  uint16_t csiv : 1;
113  uint16_t endqp : 4;
114  uint16_t cptqp : 4;
115  uint16_t newqp : 4;
116 
117 } __attribute__((packed)) QwrFields;
118 
119 typedef union _Qwr {
120  QwrFields field;
121  uint16_t content;
122 
123 } __attribute__((packed)) Qwr;
124 
125 /*
126  QSPI Interrupt Register (QIR)
127  wcefb - Write collision access error enable
128  abrtb - Abort access error enable
129  abrtl - Abort lockout
130  wcefe - Write collision interrupt enable
131  abrte - Abort interrupt enable
132  spife - Finished interrupt enable
133  wcef - Write collision error flag
134  abrt - Abort flag
135  spif - Finished flag
136 
137  */
138 typedef struct _QirFields
139 {
140  uint16_t wcefb : 1;
141  uint16_t abrtb : 1;
142  uint16_t mbz_13 : 1;
143  uint16_t abrtl : 1;
144  uint16_t wcefe : 1;
145  uint16_t abrte : 1;
146  uint16_t mbz_09 : 1;
147  uint16_t spife : 1;
148  uint16_t mbz_04_07 : 4;
149  uint16_t wcef : 1;
150  uint16_t abrt : 1;
151  uint16_t mbz_01 : 1;
152  uint16_t spif : 1;
153 
154 } __attribute__((packed)) QirFields;
155 
156 typedef union _Qir {
157  QirFields field;
158  uint16_t content;
159 
160 } __attribute__((packed)) Qir;
161 
162 /*
163  QSPI Command Register(s) (QCR)
164  cont - Continuous (0-stop, 1-go)
165  bitse - Eight bits or qmr.field.bits
166  dt - Delay after transfer (0-default, 1-qdlyr.dtl)
167  dsck - Chip select to valid clock (0-1/2 clock, 1-qdlyr.qcd)
168  qspi_cs - Chip select mask [3:0]
169 
170  */
171 typedef struct _QcrFields
172 {
173  uint16_t cont : 1;
174  uint16_t bitse : 1;
175  uint16_t dt : 1;
176  uint16_t dsck : 1;
177  uint16_t qspi_cs : 4;
178  uint16_t mbz_00_07 : 8;
179 
180 } __attribute__((packed)) QcrFields;
181 
182 typedef union _Qcr {
183  QcrFields field;
184  uint16_t content;
185 
186 } __attribute__((packed)) Qcr;
187 
188 /*
189  ******************************************************************************
190  *
191  * Routines
192  *
193  ******************************************************************************
194  */
195 
196 /*
197  ******************************************************************************
198 
199  Interrupt service routine (ISR)
200 
201  Parameters:
202  None
203 
204  Return:
205  None
206 
207  Notes:
208  None
209 
210  ******************************************************************************
211  */
212 typedef void(QspiIsr)(void);
213 
214 /*
215  ******************************************************************************
216 
217  Setup QSPI module
218 
219  Parameters:
220  setHighDrive - Drive strength TRUE high, FALSE low
221 
222  Return:
223  0 - OK, all else problems
224 
225  Notes:
226  Set assigned pins QSPI_DOUT, QSPI_DIN, QSPI_CLK and drive strength install
227  BSP Isr.
228 
229  ******************************************************************************
230  */
231 int QspiSetupHardware(BOOL setHighDrive);
232 
233 /*
234  ******************************************************************************
235 
236  Attach chip select to QSPI module
237 
238  Parameters:
239  controlledChipSelects - Chip selects [3:0] respectively
240 
241  Return:
242  0 - OK, all else problems
243 
244  Notes:
245  Driver user can let the module assert/de-assert chip select by attaching
246  or use QspiSelectChip and QspiDeselectChip based on device requirements.
247  The last call to QspiAttachChipSelects/QspiDetachChipSelects is the one
248  controlling.
249 
250  ******************************************************************************
251  */
252 int QspiAttachChipSelects(uint8_t controlledChipSelects);
253 
254 /*
255  ******************************************************************************
256 
257  Detach chip selects from QSPI module set as GPIO pins
258 
259  Parameters:
260  controlledChipSelects - Chip selects [3:0] respectively
261 
262  Return:
263  0 - OK, all else problems
264 
265  Notes:
266  User can assert/de-assert chip select by detaching and calling
267  QspiAssertChipSelects and QspiDeassertChipSelects.
268  The last call to QspiAttachChipSelects/QspiDetachChipSelects is the one
269  controlling.
270 
271  ******************************************************************************
272  */
273 int QspiDetachChipSelects(uint8_t controlledChipSelects);
274 
275 /*
276  ******************************************************************************
277 
278  Asserts chip selects
279 
280  Parameters:
281  controlledChipSelects - Chip selects [3:0] respectively
282  isChipSelectActiveLow - Chips select phase
283  TRUE Active low, inactive high
284  TRUE Active high, inactive low
285 
286 
287  Return:
288  Notes
289 
290  Notes:
291  Driver must call QspiAttachChipSelects/QspiDetachChipSelects.
292 
293  ******************************************************************************
294  */
295 void QspiAssertChipSelects(uint8_t controlledChipSelects, BOOL isChipSelectActiveLow);
296 
297 /*
298  ******************************************************************************
299 
300  Deasserts chip selects
301 
302  Parameters:
303  controlledChipSelects - Chip selects [3:0] respectively
304  isChipSelectActiveLow - Chips select phase
305  TRUE Active low, inactive high
306  TRUE Active high, inactive low
307 
308 
309  Return:
310  Notes
311 
312  Notes:
313  Driver must call QspiAttachChipSelects/QspiDetachChipSelects.
314 
315  ******************************************************************************
316  */
317 void QspiDeassertChipSelects(uint8_t controlledChipSelects, BOOL isChipSelectActiveLow);
318 
319 /*
320  ******************************************************************************
321 
322  Installs interrupt service routine
323 
324  Parameters:
325  isr - "C" interrupt service routine
326 
327  Return:
328  None
329 
330  Notes:
331  None
332 
333  ******************************************************************************
334  */
335 void QspiSetupIsr(QspiIsr isr);
336 
337 /*
338  ******************************************************************************
339 
340  Get baud rate setting
341 
342  Parameters:
343  baudRateInMhz - Baud rate requested in Mhz
344 
345  Return:
346  Lowest near integral setting within processor/module limits.
347 
348  Notes:
349  Base on processor and clock speed.
350 
351  ******************************************************************************
352  */
353 uint8_t QspiGetBaudSetting(unsigned long baudRateInMhz);
354 
355 /*
356  ******************************************************************************
357 
358  Get current baud rate setting
359 
360  Parameters:
361  None
362 
363  Return:
364  Baud rate setting in Mhz
365 
366  Notes:
367  Base on processor and clock speed.
368 
369  ******************************************************************************
370  */
371 unsigned long QspiGetCurrentBaudSetting(void);
372 
373 /*
374  ******************************************************************************
375 
376  Enable module interrupt
377 
378  Parameters:
379  None
380 
381  Return:
382  None
383 
384  Notes:
385  None
386 
387  ******************************************************************************
388  */
389 void QspiEnableIsr(void);
390 
391 /*
392  ******************************************************************************
393 
394  Disable module interrupt
395 
396  Parameters:
397  None
398 
399  Return:
400  None
401 
402  Notes:
403  None
404 
405  ******************************************************************************
406  */
407 void QspiDisableIsr(void);
408 
409 /*
410  ******************************************************************************
411 
412  Get module registers
413 
414  Parameters:
415  None
416 
417  Return:
418  None
419 
420  Notes:
421  None
422 
423  ******************************************************************************
424  */
425 void QspiGetRegisters(volatile uint16_t **qmrPtr,
426  volatile uint16_t **qdlyrPtr,
427  volatile uint16_t **qwrPtr,
428  volatile uint16_t **qirPtr,
429  volatile uint16_t **qarPtr,
430  volatile uint16_t **qdrPtr);
431 
432 #endif /* _QSPI_BSP_H_ */