Add second SPI master for 5.2 board
[SCSI2SD.git] / software / SCSI2SD / v5.2 / SCSI2SD.cydsn / Generated_Source / PSoC5 / NOR_SPI_INT.c
1 /*******************************************************************************
2 * File Name: NOR_SPI_INT.c
3 * Version 2.50
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-2015, 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 "NOR_SPI_PVT.h"
20
21
22 /* User code required at start of ISR */
23 /* `#START NOR_SPI_ISR_START_DEF` */
24
25 /* `#END` */
26
27
28 /*******************************************************************************
29 * Function Name: NOR_SPI_TX_ISR
30 ********************************************************************************
31 *
32 * Summary:
33 *  Interrupt Service Routine for TX portion of the SPI Master.
34 *
35 * Parameters:
36 *  None.
37 *
38 * Return:
39 *  None.
40 *
41 * Global variables:
42 *  NOR_SPI_txBufferWrite - used for the account of the bytes which
43 *  have been written down in the TX software buffer.
44 *  NOR_SPI_txBufferRead - used for the account of the bytes which
45 *  have been read from the TX software buffer, modified when exist data to
46 *  sending and FIFO Not Full.
47 *  NOR_SPI_txBuffer[NOR_SPI_TX_BUFFER_SIZE] - used to store
48 *  data to sending.
49 *  All described above Global variables are used when Software Buffer is used.
50 *
51 *******************************************************************************/
52 CY_ISR(NOR_SPI_TX_ISR)
53 {
54     #if(NOR_SPI_TX_SOFTWARE_BUF_ENABLED)
55         uint8 tmpStatus;
56     #endif /* (NOR_SPI_TX_SOFTWARE_BUF_ENABLED) */
57
58     #ifdef NOR_SPI_TX_ISR_ENTRY_CALLBACK
59         NOR_SPI_TX_ISR_EntryCallback();
60     #endif /* NOR_SPI_TX_ISR_ENTRY_CALLBACK */
61
62     /* User code required at start of ISR */
63     /* `#START NOR_SPI_TX_ISR_START` */
64
65     /* `#END` */
66     
67     #if(NOR_SPI_TX_SOFTWARE_BUF_ENABLED)
68         /* Check if TX data buffer is not empty and there is space in TX FIFO */
69         while(NOR_SPI_txBufferRead != NOR_SPI_txBufferWrite)
70         {
71             tmpStatus = NOR_SPI_GET_STATUS_TX(NOR_SPI_swStatusTx);
72             NOR_SPI_swStatusTx = tmpStatus;
73
74             if(0u != (NOR_SPI_swStatusTx & NOR_SPI_STS_TX_FIFO_NOT_FULL))
75             {
76                 if(0u == NOR_SPI_txBufferFull)
77                 {
78                    NOR_SPI_txBufferRead++;
79
80                     if(NOR_SPI_txBufferRead >= NOR_SPI_TX_BUFFER_SIZE)
81                     {
82                         NOR_SPI_txBufferRead = 0u;
83                     }
84                 }
85                 else
86                 {
87                     NOR_SPI_txBufferFull = 0u;
88                 }
89
90                 /* Put data element into the TX FIFO */
91                 CY_SET_REG8(NOR_SPI_TXDATA_PTR, 
92                                              NOR_SPI_txBuffer[NOR_SPI_txBufferRead]);
93             }
94             else
95             {
96                 break;
97             }
98         }
99
100         if(NOR_SPI_txBufferRead == NOR_SPI_txBufferWrite)
101         {
102             /* TX Buffer is EMPTY: disable interrupt on TX NOT FULL */
103             NOR_SPI_TX_STATUS_MASK_REG &= ((uint8) ~NOR_SPI_STS_TX_FIFO_NOT_FULL);
104         }
105
106     #endif /* (NOR_SPI_TX_SOFTWARE_BUF_ENABLED) */
107
108     /* User code required at end of ISR (Optional) */
109     /* `#START NOR_SPI_TX_ISR_END` */
110
111     /* `#END` */
112     
113     #ifdef NOR_SPI_TX_ISR_EXIT_CALLBACK
114         NOR_SPI_TX_ISR_ExitCallback();
115     #endif /* NOR_SPI_TX_ISR_EXIT_CALLBACK */
116 }
117
118
119 /*******************************************************************************
120 * Function Name: NOR_SPI_RX_ISR
121 ********************************************************************************
122 *
123 * Summary:
124 *  Interrupt Service Routine for RX portion of the SPI Master.
125 *
126 * Parameters:
127 *  None.
128 *
129 * Return:
130 *  None.
131 *
132 * Global variables:
133 *  NOR_SPI_rxBufferWrite - used for the account of the bytes which
134 *  have been written down in the RX software buffer modified when FIFO contains
135 *  new data.
136 *  NOR_SPI_rxBufferRead - used for the account of the bytes which
137 *  have been read from the RX software buffer, modified when overflow occurred.
138 *  NOR_SPI_rxBuffer[NOR_SPI_RX_BUFFER_SIZE] - used to store
139 *  received data, modified when FIFO contains new data.
140 *  All described above Global variables are used when Software Buffer is used.
141 *
142 *******************************************************************************/
143 CY_ISR(NOR_SPI_RX_ISR)
144 {
145     #if(NOR_SPI_RX_SOFTWARE_BUF_ENABLED)
146         uint8 tmpStatus;
147         uint8 rxData;
148     #endif /* (NOR_SPI_RX_SOFTWARE_BUF_ENABLED) */
149
150     #ifdef NOR_SPI_RX_ISR_ENTRY_CALLBACK
151         NOR_SPI_RX_ISR_EntryCallback();
152     #endif /* NOR_SPI_RX_ISR_ENTRY_CALLBACK */
153
154     /* User code required at start of ISR */
155     /* `#START NOR_SPI_RX_ISR_START` */
156
157     /* `#END` */
158     
159     #if(NOR_SPI_RX_SOFTWARE_BUF_ENABLED)
160
161         tmpStatus = NOR_SPI_GET_STATUS_RX(NOR_SPI_swStatusRx);
162         NOR_SPI_swStatusRx = tmpStatus;
163
164         /* Check if RX data FIFO has some data to be moved into the RX Buffer */
165         while(0u != (NOR_SPI_swStatusRx & NOR_SPI_STS_RX_FIFO_NOT_EMPTY))
166         {
167             rxData = CY_GET_REG8(NOR_SPI_RXDATA_PTR);
168
169             /* Set next pointer. */
170             NOR_SPI_rxBufferWrite++;
171             if(NOR_SPI_rxBufferWrite >= NOR_SPI_RX_BUFFER_SIZE)
172             {
173                 NOR_SPI_rxBufferWrite = 0u;
174             }
175
176             if(NOR_SPI_rxBufferWrite == NOR_SPI_rxBufferRead)
177             {
178                 NOR_SPI_rxBufferRead++;
179                 if(NOR_SPI_rxBufferRead >= NOR_SPI_RX_BUFFER_SIZE)
180                 {
181                     NOR_SPI_rxBufferRead = 0u;
182                 }
183
184                 NOR_SPI_rxBufferFull = 1u;
185             }
186
187             /* Move data from the FIFO to the Buffer */
188             NOR_SPI_rxBuffer[NOR_SPI_rxBufferWrite] = rxData;
189
190             tmpStatus = NOR_SPI_GET_STATUS_RX(NOR_SPI_swStatusRx);
191             NOR_SPI_swStatusRx = tmpStatus;
192         }
193
194     #endif /* (NOR_SPI_RX_SOFTWARE_BUF_ENABLED) */
195
196     /* User code required at end of ISR (Optional) */
197     /* `#START NOR_SPI_RX_ISR_END` */
198
199     /* `#END` */
200     
201     #ifdef NOR_SPI_RX_ISR_EXIT_CALLBACK
202         NOR_SPI_RX_ISR_ExitCallback();
203     #endif /* NOR_SPI_RX_ISR_EXIT_CALLBACK */
204 }
205
206 /* [] END OF FILE */