Merge PCB updates
[SCSI2SD.git] / software / SCSI2SD / v4 / SCSI2SD.cydsn / Generated_Source / PSoC5 / SDCard.h
1 /*******************************************************************************
2 * File Name: SDCard.h
3 * Version 2.40
4 *
5 * Description:
6 *  Contains the function prototypes, constants and register definition
7 *  of the SPI Master Component.
8 *
9 * Note:
10 *  None
11 *
12 ********************************************************************************
13 * Copyright 2008-2012, Cypress Semiconductor Corporation.  All rights reserved.
14 * You may use this file only in accordance with the license, terms, conditions,
15 * disclaimers, and limitations in the end user license agreement accompanying
16 * the software package with which this file was provided.
17 *******************************************************************************/
18
19 #if !defined(CY_SPIM_SDCard_H)
20 #define CY_SPIM_SDCard_H
21
22 #include "cytypes.h"
23 #include "cyfitter.h"
24 #include "CyLib.h"
25
26 /* Check to see if required defines such as CY_PSOC5A are available */
27 /* They are defined starting with cy_boot v3.0 */
28 #if !defined (CY_PSOC5A)
29     #error Component SPI_Master_v2_40 requires cy_boot v3.0 or later
30 #endif /* (CY_PSOC5A) */
31
32
33 /***************************************
34 *   Conditional Compilation Parameters
35 ***************************************/
36
37 #define SDCard_INTERNAL_CLOCK             (0u)
38
39 #if(0u != SDCard_INTERNAL_CLOCK)
40     #include "SDCard_IntClock.h"
41 #endif /* (0u != SDCard_INTERNAL_CLOCK) */
42
43 #define SDCard_MODE                       (1u)
44 #define SDCard_DATA_WIDTH                 (8u)
45 #define SDCard_MODE_USE_ZERO              (1u)
46 #define SDCard_BIDIRECTIONAL_MODE         (0u)
47
48 /* Internal interrupt handling */
49 #define SDCard_TX_BUFFER_SIZE             (4u)
50 #define SDCard_RX_BUFFER_SIZE             (4u)
51 #define SDCard_INTERNAL_TX_INT_ENABLED    (0u)
52 #define SDCard_INTERNAL_RX_INT_ENABLED    (0u)
53
54 #define SDCard_SINGLE_REG_SIZE            (8u)
55 #define SDCard_USE_SECOND_DATAPATH        (SDCard_DATA_WIDTH > SDCard_SINGLE_REG_SIZE)
56
57 #define SDCard_FIFO_SIZE                  (4u)
58 #define SDCard_TX_SOFTWARE_BUF_ENABLED    ((0u != SDCard_INTERNAL_TX_INT_ENABLED) && \
59                                                      (SDCard_TX_BUFFER_SIZE > SDCard_FIFO_SIZE))
60
61 #define SDCard_RX_SOFTWARE_BUF_ENABLED    ((0u != SDCard_INTERNAL_RX_INT_ENABLED) && \
62                                                      (SDCard_RX_BUFFER_SIZE > SDCard_FIFO_SIZE))
63
64
65 /***************************************
66 *        Data Struct Definition
67 ***************************************/
68
69 /* Sleep Mode API Support */
70 typedef struct
71 {
72     uint8 enableState;
73     uint8 cntrPeriod;
74     #if(CY_UDB_V0)
75         uint8 saveSrTxIntMask;
76         uint8 saveSrRxIntMask;
77     #endif /* (CY_UDB_V0) */
78
79 } SDCard_BACKUP_STRUCT;
80
81
82 /***************************************
83 *        Function Prototypes
84 ***************************************/
85
86 void  SDCard_Init(void)                           ;
87 void  SDCard_Enable(void)                         ;
88 void  SDCard_Start(void)                          ;
89 void  SDCard_Stop(void)                           ;
90
91 void  SDCard_EnableTxInt(void)                    ;
92 void  SDCard_EnableRxInt(void)                    ;
93 void  SDCard_DisableTxInt(void)                   ;
94 void  SDCard_DisableRxInt(void)                   ;
95
96 void  SDCard_Sleep(void)                          ;
97 void  SDCard_Wakeup(void)                         ;
98 void  SDCard_SaveConfig(void)                     ;
99 void  SDCard_RestoreConfig(void)                  ;
100
101 void  SDCard_SetTxInterruptMode(uint8 intSrc)     ;
102 void  SDCard_SetRxInterruptMode(uint8 intSrc)     ;
103 uint8 SDCard_ReadTxStatus(void)                   ;
104 uint8 SDCard_ReadRxStatus(void)                   ;
105 void  SDCard_WriteTxData(uint8 txData)  \
106                                                             ;
107 uint8 SDCard_ReadRxData(void) \
108                                                             ;
109 uint8 SDCard_GetRxBufferSize(void)                ;
110 uint8 SDCard_GetTxBufferSize(void)                ;
111 void  SDCard_ClearRxBuffer(void)                  ;
112 void  SDCard_ClearTxBuffer(void)                  ;
113 void  SDCard_ClearFIFO(void)                              ;
114 void  SDCard_PutArray(const uint8 buffer[], uint8 byteCount) \
115                                                             ;
116
117 #if(0u != SDCard_BIDIRECTIONAL_MODE)
118     void  SDCard_TxEnable(void)                   ;
119     void  SDCard_TxDisable(void)                  ;
120 #endif /* (0u != SDCard_BIDIRECTIONAL_MODE) */
121
122 CY_ISR_PROTO(SDCard_TX_ISR);
123 CY_ISR_PROTO(SDCard_RX_ISR);
124
125
126 /**********************************
127 *   Variable with external linkage
128 **********************************/
129
130 extern uint8 SDCard_initVar;
131
132
133 /***************************************
134 *           API Constants
135 ***************************************/
136
137 #define SDCard_TX_ISR_NUMBER     ((uint8) (SDCard_TxInternalInterrupt__INTC_NUMBER))
138 #define SDCard_RX_ISR_NUMBER     ((uint8) (SDCard_RxInternalInterrupt__INTC_NUMBER))
139
140 #define SDCard_TX_ISR_PRIORITY   ((uint8) (SDCard_TxInternalInterrupt__INTC_PRIOR_NUM))
141 #define SDCard_RX_ISR_PRIORITY   ((uint8) (SDCard_RxInternalInterrupt__INTC_PRIOR_NUM))
142
143
144 /***************************************
145 *    Initial Parameter Constants
146 ***************************************/
147
148 #define SDCard_INT_ON_SPI_DONE    ((uint8) (0u   << SDCard_STS_SPI_DONE_SHIFT))
149 #define SDCard_INT_ON_TX_EMPTY    ((uint8) (0u   << SDCard_STS_TX_FIFO_EMPTY_SHIFT))
150 #define SDCard_INT_ON_TX_NOT_FULL ((uint8) (1u << \
151                                                                            SDCard_STS_TX_FIFO_NOT_FULL_SHIFT))
152 #define SDCard_INT_ON_BYTE_COMP   ((uint8) (0u  << SDCard_STS_BYTE_COMPLETE_SHIFT))
153 #define SDCard_INT_ON_SPI_IDLE    ((uint8) (0u   << SDCard_STS_SPI_IDLE_SHIFT))
154
155 /* Disable TX_NOT_FULL if software buffer is used */
156 #define SDCard_INT_ON_TX_NOT_FULL_DEF ((SDCard_TX_SOFTWARE_BUF_ENABLED) ? \
157                                                                         (0u) : (SDCard_INT_ON_TX_NOT_FULL))
158
159 /* TX interrupt mask */
160 #define SDCard_TX_INIT_INTERRUPTS_MASK    (SDCard_INT_ON_SPI_DONE  | \
161                                                      SDCard_INT_ON_TX_EMPTY  | \
162                                                      SDCard_INT_ON_TX_NOT_FULL_DEF | \
163                                                      SDCard_INT_ON_BYTE_COMP | \
164                                                      SDCard_INT_ON_SPI_IDLE)
165
166 #define SDCard_INT_ON_RX_FULL         ((uint8) (0u << \
167                                                                           SDCard_STS_RX_FIFO_FULL_SHIFT))
168 #define SDCard_INT_ON_RX_NOT_EMPTY    ((uint8) (1u << \
169                                                                           SDCard_STS_RX_FIFO_NOT_EMPTY_SHIFT))
170 #define SDCard_INT_ON_RX_OVER         ((uint8) (0u << \
171                                                                           SDCard_STS_RX_FIFO_OVERRUN_SHIFT))
172
173 /* RX interrupt mask */
174 #define SDCard_RX_INIT_INTERRUPTS_MASK    (SDCard_INT_ON_RX_FULL      | \
175                                                      SDCard_INT_ON_RX_NOT_EMPTY | \
176                                                      SDCard_INT_ON_RX_OVER)
177 /* Nubmer of bits to receive/transmit */
178 #define SDCard_BITCTR_INIT            (((uint8) (SDCard_DATA_WIDTH << 1u)) - 1u)
179
180
181 /***************************************
182 *             Registers
183 ***************************************/
184
185 #if(CY_PSOC3 || CY_PSOC5)
186     #define SDCard_TXDATA_REG (* (reg8 *) \
187                                                 SDCard_BSPIM_sR8_Dp_u0__F0_REG)
188     #define SDCard_TXDATA_PTR (  (reg8 *) \
189                                                 SDCard_BSPIM_sR8_Dp_u0__F0_REG)
190     #define SDCard_RXDATA_REG (* (reg8 *) \
191                                                 SDCard_BSPIM_sR8_Dp_u0__F1_REG)
192     #define SDCard_RXDATA_PTR (  (reg8 *) \
193                                                 SDCard_BSPIM_sR8_Dp_u0__F1_REG)
194 #else   /* PSOC4 */
195     #if(SDCard_USE_SECOND_DATAPATH)
196         #define SDCard_TXDATA_REG (* (reg16 *) \
197                                           SDCard_BSPIM_sR8_Dp_u0__16BIT_F0_REG)
198         #define SDCard_TXDATA_PTR (  (reg16 *) \
199                                           SDCard_BSPIM_sR8_Dp_u0__16BIT_F0_REG)
200         #define SDCard_RXDATA_REG (* (reg16 *) \
201                                           SDCard_BSPIM_sR8_Dp_u0__16BIT_F1_REG)
202         #define SDCard_RXDATA_PTR         (  (reg16 *) \
203                                           SDCard_BSPIM_sR8_Dp_u0__16BIT_F1_REG)
204     #else
205         #define SDCard_TXDATA_REG (* (reg8 *) \
206                                                 SDCard_BSPIM_sR8_Dp_u0__F0_REG)
207         #define SDCard_TXDATA_PTR (  (reg8 *) \
208                                                 SDCard_BSPIM_sR8_Dp_u0__F0_REG)
209         #define SDCard_RXDATA_REG (* (reg8 *) \
210                                                 SDCard_BSPIM_sR8_Dp_u0__F1_REG)
211         #define SDCard_RXDATA_PTR (  (reg8 *) \
212                                                 SDCard_BSPIM_sR8_Dp_u0__F1_REG)
213     #endif /* (SDCard_USE_SECOND_DATAPATH) */
214 #endif     /* (CY_PSOC3 || CY_PSOC5) */
215
216 #define SDCard_AUX_CONTROL_DP0_REG (* (reg8 *) \
217                                         SDCard_BSPIM_sR8_Dp_u0__DP_AUX_CTL_REG)
218 #define SDCard_AUX_CONTROL_DP0_PTR (  (reg8 *) \
219                                         SDCard_BSPIM_sR8_Dp_u0__DP_AUX_CTL_REG)
220
221 #if(SDCard_USE_SECOND_DATAPATH)
222     #define SDCard_AUX_CONTROL_DP1_REG  (* (reg8 *) \
223                                         SDCard_BSPIM_sR8_Dp_u1__DP_AUX_CTL_REG)
224     #define SDCard_AUX_CONTROL_DP1_PTR  (  (reg8 *) \
225                                         SDCard_BSPIM_sR8_Dp_u1__DP_AUX_CTL_REG)
226 #endif /* (SDCard_USE_SECOND_DATAPATH) */
227
228 #define SDCard_COUNTER_PERIOD_REG     (* (reg8 *) SDCard_BSPIM_BitCounter__PERIOD_REG)
229 #define SDCard_COUNTER_PERIOD_PTR     (  (reg8 *) SDCard_BSPIM_BitCounter__PERIOD_REG)
230 #define SDCard_COUNTER_CONTROL_REG    (* (reg8 *) SDCard_BSPIM_BitCounter__CONTROL_AUX_CTL_REG)
231 #define SDCard_COUNTER_CONTROL_PTR    (  (reg8 *) SDCard_BSPIM_BitCounter__CONTROL_AUX_CTL_REG)
232
233 #define SDCard_TX_STATUS_REG          (* (reg8 *) SDCard_BSPIM_TxStsReg__STATUS_REG)
234 #define SDCard_TX_STATUS_PTR          (  (reg8 *) SDCard_BSPIM_TxStsReg__STATUS_REG)
235 #define SDCard_RX_STATUS_REG          (* (reg8 *) SDCard_BSPIM_RxStsReg__STATUS_REG)
236 #define SDCard_RX_STATUS_PTR          (  (reg8 *) SDCard_BSPIM_RxStsReg__STATUS_REG)
237
238 #define SDCard_CONTROL_REG            (* (reg8 *) \
239                                       SDCard_BSPIM_BidirMode_SyncCtl_CtrlReg__CONTROL_REG)
240 #define SDCard_CONTROL_PTR            (  (reg8 *) \
241                                       SDCard_BSPIM_BidirMode_SyncCtl_CtrlReg__CONTROL_REG)
242
243 #define SDCard_TX_STATUS_MASK_REG     (* (reg8 *) SDCard_BSPIM_TxStsReg__MASK_REG)
244 #define SDCard_TX_STATUS_MASK_PTR     (  (reg8 *) SDCard_BSPIM_TxStsReg__MASK_REG)
245 #define SDCard_RX_STATUS_MASK_REG     (* (reg8 *) SDCard_BSPIM_RxStsReg__MASK_REG)
246 #define SDCard_RX_STATUS_MASK_PTR     (  (reg8 *) SDCard_BSPIM_RxStsReg__MASK_REG)
247
248 #define SDCard_TX_STATUS_ACTL_REG     (* (reg8 *) SDCard_BSPIM_TxStsReg__STATUS_AUX_CTL_REG)
249 #define SDCard_TX_STATUS_ACTL_PTR     (  (reg8 *) SDCard_BSPIM_TxStsReg__STATUS_AUX_CTL_REG)
250 #define SDCard_RX_STATUS_ACTL_REG     (* (reg8 *) SDCard_BSPIM_RxStsReg__STATUS_AUX_CTL_REG)
251 #define SDCard_RX_STATUS_ACTL_PTR     (  (reg8 *) SDCard_BSPIM_RxStsReg__STATUS_AUX_CTL_REG)
252
253 #if(SDCard_USE_SECOND_DATAPATH)
254     #define SDCard_AUX_CONTROLDP1     (SDCard_AUX_CONTROL_DP1_REG)
255 #endif /* (SDCard_USE_SECOND_DATAPATH) */
256
257
258 /***************************************
259 *       Register Constants
260 ***************************************/
261
262 /* Status Register Definitions */
263 #define SDCard_STS_SPI_DONE_SHIFT             (0x00u)
264 #define SDCard_STS_TX_FIFO_EMPTY_SHIFT        (0x01u)
265 #define SDCard_STS_TX_FIFO_NOT_FULL_SHIFT     (0x02u)
266 #define SDCard_STS_BYTE_COMPLETE_SHIFT        (0x03u)
267 #define SDCard_STS_SPI_IDLE_SHIFT             (0x04u)
268 #define SDCard_STS_RX_FIFO_FULL_SHIFT         (0x04u)
269 #define SDCard_STS_RX_FIFO_NOT_EMPTY_SHIFT    (0x05u)
270 #define SDCard_STS_RX_FIFO_OVERRUN_SHIFT      (0x06u)
271
272 #define SDCard_STS_SPI_DONE           ((uint8) (0x01u << SDCard_STS_SPI_DONE_SHIFT))
273 #define SDCard_STS_TX_FIFO_EMPTY      ((uint8) (0x01u << SDCard_STS_TX_FIFO_EMPTY_SHIFT))
274 #define SDCard_STS_TX_FIFO_NOT_FULL   ((uint8) (0x01u << SDCard_STS_TX_FIFO_NOT_FULL_SHIFT))
275 #define SDCard_STS_BYTE_COMPLETE      ((uint8) (0x01u << SDCard_STS_BYTE_COMPLETE_SHIFT))
276 #define SDCard_STS_SPI_IDLE           ((uint8) (0x01u << SDCard_STS_SPI_IDLE_SHIFT))
277 #define SDCard_STS_RX_FIFO_FULL       ((uint8) (0x01u << SDCard_STS_RX_FIFO_FULL_SHIFT))
278 #define SDCard_STS_RX_FIFO_NOT_EMPTY  ((uint8) (0x01u << SDCard_STS_RX_FIFO_NOT_EMPTY_SHIFT))
279 #define SDCard_STS_RX_FIFO_OVERRUN    ((uint8) (0x01u << SDCard_STS_RX_FIFO_OVERRUN_SHIFT))
280
281 /* TX and RX masks for clear on read bits */
282 #define SDCard_TX_STS_CLR_ON_RD_BYTES_MASK    (0x09u)
283 #define SDCard_RX_STS_CLR_ON_RD_BYTES_MASK    (0x40u)
284
285 /* StatusI Register Interrupt Enable Control Bits */
286 /* As defined by the Register map for the AUX Control Register */
287 #define SDCard_INT_ENABLE     (0x10u) /* Enable interrupt from statusi */
288 #define SDCard_TX_FIFO_CLR    (0x01u) /* F0 - TX FIFO */
289 #define SDCard_RX_FIFO_CLR    (0x02u) /* F1 - RX FIFO */
290 #define SDCard_FIFO_CLR       (SDCard_TX_FIFO_CLR | SDCard_RX_FIFO_CLR)
291
292 /* Bit Counter (7-bit) Control Register Bit Definitions */
293 /* As defined by the Register map for the AUX Control Register */
294 #define SDCard_CNTR_ENABLE    (0x20u) /* Enable CNT7 */
295
296 /* Bi-Directional mode control bit */
297 #define SDCard_CTRL_TX_SIGNAL_EN  (0x01u)
298
299 /* Datapath Auxillary Control Register definitions */
300 #define SDCard_AUX_CTRL_FIFO0_CLR         (0x01u)
301 #define SDCard_AUX_CTRL_FIFO1_CLR         (0x02u)
302 #define SDCard_AUX_CTRL_FIFO0_LVL         (0x04u)
303 #define SDCard_AUX_CTRL_FIFO1_LVL         (0x08u)
304 #define SDCard_STATUS_ACTL_INT_EN_MASK    (0x10u)
305
306 /* Component disabled */
307 #define SDCard_DISABLED   (0u)
308
309
310 /***************************************
311 *       Macros
312 ***************************************/
313
314 /* Returns true if componentn enabled */
315 #define SDCard_IS_ENABLED (0u != (SDCard_TX_STATUS_ACTL_REG & SDCard_INT_ENABLE))
316
317 /* Retuns TX status register */
318 #define SDCard_GET_STATUS_TX(swTxSts) ( (uint8)(SDCard_TX_STATUS_REG | \
319                                                           ((swTxSts) & SDCard_TX_STS_CLR_ON_RD_BYTES_MASK)) )
320 /* Retuns RX status register */
321 #define SDCard_GET_STATUS_RX(swRxSts) ( (uint8)(SDCard_RX_STATUS_REG | \
322                                                           ((swRxSts) & SDCard_RX_STS_CLR_ON_RD_BYTES_MASK)) )
323
324
325 /***************************************
326 *       Obsolete definitions
327 ***************************************/
328
329 /* Following definitions are for version compatibility.
330 *  They are obsolete in SPIM v2_30.
331 *  Please do not use it in new projects
332 */
333
334 #define SDCard_WriteByte   SDCard_WriteTxData
335 #define SDCard_ReadByte    SDCard_ReadRxData
336 void  SDCard_SetInterruptMode(uint8 intSrc)       ;
337 uint8 SDCard_ReadStatus(void)                     ;
338 void  SDCard_EnableInt(void)                      ;
339 void  SDCard_DisableInt(void)                     ;
340
341 /* Obsolete register names. Not to be used in new designs */
342 #define SDCard_TXDATA                 (SDCard_TXDATA_REG)
343 #define SDCard_RXDATA                 (SDCard_RXDATA_REG)
344 #define SDCard_AUX_CONTROLDP0         (SDCard_AUX_CONTROL_DP0_REG)
345 #define SDCard_TXBUFFERREAD           (SDCard_txBufferRead)
346 #define SDCard_TXBUFFERWRITE          (SDCard_txBufferWrite)
347 #define SDCard_RXBUFFERREAD           (SDCard_rxBufferRead)
348 #define SDCard_RXBUFFERWRITE          (SDCard_rxBufferWrite)
349
350 #define SDCard_COUNTER_PERIOD         (SDCard_COUNTER_PERIOD_REG)
351 #define SDCard_COUNTER_CONTROL        (SDCard_COUNTER_CONTROL_REG)
352 #define SDCard_STATUS                 (SDCard_TX_STATUS_REG)
353 #define SDCard_CONTROL                (SDCard_CONTROL_REG)
354 #define SDCard_STATUS_MASK            (SDCard_TX_STATUS_MASK_REG)
355 #define SDCard_STATUS_ACTL            (SDCard_TX_STATUS_ACTL_REG)
356
357 #define SDCard_INIT_INTERRUPTS_MASK  (SDCard_INT_ON_SPI_DONE     | \
358                                                 SDCard_INT_ON_TX_EMPTY     | \
359                                                 SDCard_INT_ON_TX_NOT_FULL_DEF  | \
360                                                 SDCard_INT_ON_RX_FULL      | \
361                                                 SDCard_INT_ON_RX_NOT_EMPTY | \
362                                                 SDCard_INT_ON_RX_OVER      | \
363                                                 SDCard_INT_ON_BYTE_COMP)
364                                                 
365 /* Following definitions are for version Compatibility.
366 *  They are obsolete in SPIM v2_40.
367 *  Please do not use it in new projects
368 */
369
370 #define SDCard_DataWidth                  (SDCard_DATA_WIDTH)
371 #define SDCard_InternalClockUsed          (SDCard_INTERNAL_CLOCK)
372 #define SDCard_InternalTxInterruptEnabled (SDCard_INTERNAL_TX_INT_ENABLED)
373 #define SDCard_InternalRxInterruptEnabled (SDCard_INTERNAL_RX_INT_ENABLED)
374 #define SDCard_ModeUseZero                (SDCard_MODE_USE_ZERO)
375 #define SDCard_BidirectionalMode          (SDCard_BIDIRECTIONAL_MODE)
376 #define SDCard_Mode                       (SDCard_MODE)
377 #define SDCard_DATAWIDHT                  (SDCard_DATA_WIDTH)
378 #define SDCard_InternalInterruptEnabled   (0u)
379
380 #define SDCard_TXBUFFERSIZE   (SDCard_TX_BUFFER_SIZE)
381 #define SDCard_RXBUFFERSIZE   (SDCard_RX_BUFFER_SIZE)
382
383 #define SDCard_TXBUFFER       SDCard_txBuffer
384 #define SDCard_RXBUFFER       SDCard_rxBuffer
385
386 #endif /* (CY_SPIM_SDCard_H) */
387
388
389 /* [] END OF FILE */