Added support for v4.2 boards
[SCSI2SD.git] / software / SCSI2SD / v4 / SCSI2SD.cydsn / Generated_Source / PSoC5 / SDCard_INT.c
1 /*******************************************************************************
2 * File Name: SDCard_INT.c
3 * Version 2.40
4 *
5 * Description:
6 *  This file provides all Interrupt Service Routine (ISR) for the SPI Master
7 *  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 #include "SDCard_PVT.h"
20
21 /* User code required at start of ISR */
22 /* `#START SDCard_ISR_START_DEF` */
23
24 /* `#END` */
25
26
27 /*******************************************************************************
28 * Function Name: SDCard_TX_ISR
29 ********************************************************************************
30 *
31 * Summary:
32 *  Interrupt Service Routine for TX portion of the SPI Master.
33 *
34 * Parameters:
35 *  None.
36 *
37 * Return:
38 *  None.
39 *
40 * Global variables:
41 *  SDCard_txBufferWrite - used for the account of the bytes which
42 *  have been written down in the TX software buffer.
43 *  SDCard_txBufferRead - used for the account of the bytes which
44 *  have been read from the TX software buffer, modified when exist data to
45 *  sending and FIFO Not Full.
46 *  SDCard_txBuffer[SDCard_TX_BUFFER_SIZE] - used to store
47 *  data to sending.
48 *  All described above Global variables are used when Software Buffer is used.
49 *
50 *******************************************************************************/
51 CY_ISR(SDCard_TX_ISR)
52 {
53     #if(SDCard_TX_SOFTWARE_BUF_ENABLED)
54         uint8 tmpStatus;
55     #endif /* (SDCard_TX_SOFTWARE_BUF_ENABLED) */
56
57     /* User code required at start of ISR */
58     /* `#START SDCard_TX_ISR_START` */
59
60     /* `#END` */
61
62     #if(SDCard_TX_SOFTWARE_BUF_ENABLED)
63         /* Check if TX data buffer is not empty and there is space in TX FIFO */
64         while(SDCard_txBufferRead != SDCard_txBufferWrite)
65         {
66             tmpStatus = SDCard_GET_STATUS_TX(SDCard_swStatusTx);
67             SDCard_swStatusTx = tmpStatus;
68
69             if(0u != (SDCard_swStatusTx & SDCard_STS_TX_FIFO_NOT_FULL))
70             {
71                 if(0u == SDCard_txBufferFull)
72                 {
73                    SDCard_txBufferRead++;
74
75                     if(SDCard_txBufferRead >= SDCard_TX_BUFFER_SIZE)
76                     {
77                         SDCard_txBufferRead = 0u;
78                     }
79                 }
80                 else
81                 {
82                     SDCard_txBufferFull = 0u;
83                 }
84
85                 /* Move data from the Buffer to the FIFO */
86                 CY_SET_REG8(SDCard_TXDATA_PTR,
87                     SDCard_txBuffer[SDCard_txBufferRead]);
88             }
89             else
90             {
91                 break;
92             }
93         }
94
95         if(SDCard_txBufferRead == SDCard_txBufferWrite)
96         {
97             /* TX Buffer is EMPTY: disable interrupt on TX NOT FULL */
98             SDCard_TX_STATUS_MASK_REG &= ((uint8) ~SDCard_STS_TX_FIFO_NOT_FULL);
99         }
100
101     #endif /* (SDCard_TX_SOFTWARE_BUF_ENABLED) */
102
103     /* User code required at end of ISR (Optional) */
104     /* `#START SDCard_TX_ISR_END` */
105
106     /* `#END` */
107 }
108
109
110 /*******************************************************************************
111 * Function Name: SDCard_RX_ISR
112 ********************************************************************************
113 *
114 * Summary:
115 *  Interrupt Service Routine for RX portion of the SPI Master.
116 *
117 * Parameters:
118 *  None.
119 *
120 * Return:
121 *  None.
122 *
123 * Global variables:
124 *  SDCard_rxBufferWrite - used for the account of the bytes which
125 *  have been written down in the RX software buffer modified when FIFO contains
126 *  new data.
127 *  SDCard_rxBufferRead - used for the account of the bytes which
128 *  have been read from the RX software buffer, modified when overflow occurred.
129 *  SDCard_rxBuffer[SDCard_RX_BUFFER_SIZE] - used to store
130 *  received data, modified when FIFO contains new data.
131 *  All described above Global variables are used when Software Buffer is used.
132 *
133 *******************************************************************************/
134 CY_ISR(SDCard_RX_ISR)
135 {
136     #if(SDCard_RX_SOFTWARE_BUF_ENABLED)
137         uint8 tmpStatus;
138         uint8 rxData;
139     #endif /* (SDCard_RX_SOFTWARE_BUF_ENABLED) */
140
141     /* User code required at start of ISR */
142     /* `#START SDCard_RX_ISR_START` */
143
144     /* `#END` */
145
146     #if(SDCard_RX_SOFTWARE_BUF_ENABLED)
147
148         tmpStatus = SDCard_GET_STATUS_RX(SDCard_swStatusRx);
149         SDCard_swStatusRx = tmpStatus;
150
151         /* Check if RX data FIFO has some data to be moved into the RX Buffer */
152         while(0u != (SDCard_swStatusRx & SDCard_STS_RX_FIFO_NOT_EMPTY))
153         {
154             rxData = CY_GET_REG8(SDCard_RXDATA_PTR);
155
156             /* Set next pointer. */
157             SDCard_rxBufferWrite++;
158             if(SDCard_rxBufferWrite >= SDCard_RX_BUFFER_SIZE)
159             {
160                 SDCard_rxBufferWrite = 0u;
161             }
162
163             if(SDCard_rxBufferWrite == SDCard_rxBufferRead)
164             {
165                 SDCard_rxBufferRead++;
166                 if(SDCard_rxBufferRead >= SDCard_RX_BUFFER_SIZE)
167                 {
168                     SDCard_rxBufferRead = 0u;
169                 }
170
171                 SDCard_rxBufferFull = 1u;
172             }
173
174             /* Move data from the FIFO to the Buffer */
175             SDCard_rxBuffer[SDCard_rxBufferWrite] = rxData;
176
177             tmpStatus = SDCard_GET_STATUS_RX(SDCard_swStatusRx);
178             SDCard_swStatusRx = tmpStatus;
179         }
180
181     #endif /* (SDCard_RX_SOFTWARE_BUF_ENABLED) */
182
183     /* User code required at end of ISR (Optional) */
184     /* `#START SDCard_RX_ISR_END` */
185
186     /* `#END` */
187 }
188
189 /* [] END OF FILE */