-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathI2C_SCB_IRQ.c
executable file
·406 lines (358 loc) · 12.4 KB
/
I2C_SCB_IRQ.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
/*******************************************************************************
* File Name: I2C_SCB_IRQ.c
* Version 1.70
*
* Description:
* API for controlling the state of an interrupt.
*
*
* Note:
*
********************************************************************************
* Copyright 2008-2015, Cypress Semiconductor Corporation. All rights reserved.
* You may use this file only in accordance with the license, terms, conditions,
* disclaimers, and limitations in the end user license agreement accompanying
* the software package with which this file was provided.
*******************************************************************************/
#include <cydevice_trm.h>
#include <CyLib.h>
#include <I2C_SCB_IRQ.h>
#include "cyapicallbacks.h"
#if !defined(I2C_SCB_IRQ__REMOVED) /* Check for removal by optimization */
/*******************************************************************************
* Place your includes, defines and code here
********************************************************************************/
/* `#START I2C_SCB_IRQ_intc` */
/* `#END` */
extern cyisraddress CyRamVectors[CYINT_IRQ_BASE + CY_NUM_INTERRUPTS];
/* Declared in startup, used to set unused interrupts to. */
CY_ISR_PROTO(IntDefaultHandler);
/*******************************************************************************
* Function Name: I2C_SCB_IRQ_Start
********************************************************************************
*
* Summary:
* Set up the interrupt and enable it. This function disables the interrupt,
* sets the default interrupt vector, sets the priority from the value in the
* Design Wide Resources Interrupt Editor, then enables the interrupt to the
* interrupt controller.
*
* Parameters:
* None
*
* Return:
* None
*
*******************************************************************************/
void I2C_SCB_IRQ_Start(void)
{
/* For all we know the interrupt is active. */
I2C_SCB_IRQ_Disable();
/* Set the ISR to point to the I2C_SCB_IRQ Interrupt. */
I2C_SCB_IRQ_SetVector(&I2C_SCB_IRQ_Interrupt);
/* Set the priority. */
I2C_SCB_IRQ_SetPriority((uint8)I2C_SCB_IRQ_INTC_PRIOR_NUMBER);
/* Enable it. */
I2C_SCB_IRQ_Enable();
}
/*******************************************************************************
* Function Name: I2C_SCB_IRQ_StartEx
********************************************************************************
*
* Summary:
* Sets up the interrupt and enables it. This function disables the interrupt,
* sets the interrupt vector based on the address passed in, sets the priority
* from the value in the Design Wide Resources Interrupt Editor, then enables
* the interrupt to the interrupt controller.
*
* When defining ISR functions, the CY_ISR and CY_ISR_PROTO macros should be
* used to provide consistent definition across compilers:
*
* Function definition example:
* CY_ISR(MyISR)
* {
* }
* Function prototype example:
* CY_ISR_PROTO(MyISR);
*
* Parameters:
* address: Address of the ISR to set in the interrupt vector table.
*
* Return:
* None
*
*******************************************************************************/
void I2C_SCB_IRQ_StartEx(cyisraddress address)
{
/* For all we know the interrupt is active. */
I2C_SCB_IRQ_Disable();
/* Set the ISR to point to the I2C_SCB_IRQ Interrupt. */
I2C_SCB_IRQ_SetVector(address);
/* Set the priority. */
I2C_SCB_IRQ_SetPriority((uint8)I2C_SCB_IRQ_INTC_PRIOR_NUMBER);
/* Enable it. */
I2C_SCB_IRQ_Enable();
}
/*******************************************************************************
* Function Name: I2C_SCB_IRQ_Stop
********************************************************************************
*
* Summary:
* Disables and removes the interrupt.
*
* Parameters:
* None
*
* Return:
* None
*
*******************************************************************************/
void I2C_SCB_IRQ_Stop(void)
{
/* Disable this interrupt. */
I2C_SCB_IRQ_Disable();
/* Set the ISR to point to the passive one. */
I2C_SCB_IRQ_SetVector(&IntDefaultHandler);
}
/*******************************************************************************
* Function Name: I2C_SCB_IRQ_Interrupt
********************************************************************************
*
* Summary:
* The default Interrupt Service Routine for I2C_SCB_IRQ.
*
* Add custom code between the START and END comments to keep the next version
* of this file from over-writing your code.
*
* Note You may use either the default ISR by using this API, or you may define
* your own separate ISR through ISR_StartEx().
*
* Parameters:
* None
*
* Return:
* None
*
*******************************************************************************/
CY_ISR(I2C_SCB_IRQ_Interrupt)
{
#ifdef I2C_SCB_IRQ_INTERRUPT_INTERRUPT_CALLBACK
I2C_SCB_IRQ_Interrupt_InterruptCallback();
#endif /* I2C_SCB_IRQ_INTERRUPT_INTERRUPT_CALLBACK */
/* Place your Interrupt code here. */
/* `#START I2C_SCB_IRQ_Interrupt` */
/* `#END` */
}
/*******************************************************************************
* Function Name: I2C_SCB_IRQ_SetVector
********************************************************************************
*
* Summary:
* Change the ISR vector for the Interrupt. Note calling I2C_SCB_IRQ_Start
* will override any effect this method would have had. To set the vector
* before the component has been started use I2C_SCB_IRQ_StartEx instead.
*
* When defining ISR functions, the CY_ISR and CY_ISR_PROTO macros should be
* used to provide consistent definition across compilers:
*
* Function definition example:
* CY_ISR(MyISR)
* {
* }
*
* Function prototype example:
* CY_ISR_PROTO(MyISR);
*
* Parameters:
* address: Address of the ISR to set in the interrupt vector table.
*
* Return:
* None
*
*******************************************************************************/
void I2C_SCB_IRQ_SetVector(cyisraddress address)
{
CyRamVectors[CYINT_IRQ_BASE + I2C_SCB_IRQ__INTC_NUMBER] = address;
}
/*******************************************************************************
* Function Name: I2C_SCB_IRQ_GetVector
********************************************************************************
*
* Summary:
* Gets the "address" of the current ISR vector for the Interrupt.
*
* Parameters:
* None
*
* Return:
* Address of the ISR in the interrupt vector table.
*
*******************************************************************************/
cyisraddress I2C_SCB_IRQ_GetVector(void)
{
return CyRamVectors[CYINT_IRQ_BASE + I2C_SCB_IRQ__INTC_NUMBER];
}
/*******************************************************************************
* Function Name: I2C_SCB_IRQ_SetPriority
********************************************************************************
*
* Summary:
* Sets the Priority of the Interrupt.
*
* Note calling I2C_SCB_IRQ_Start or I2C_SCB_IRQ_StartEx will
* override any effect this API would have had. This API should only be called
* after I2C_SCB_IRQ_Start or I2C_SCB_IRQ_StartEx has been called.
* To set the initial priority for the component, use the Design-Wide Resources
* Interrupt Editor.
*
* Note This API has no effect on Non-maskable interrupt NMI).
*
* Parameters:
* priority: Priority of the interrupt, 0 being the highest priority
* PSoC 3 and PSoC 5LP: Priority is from 0 to 7.
* PSoC 4: Priority is from 0 to 3.
*
* Return:
* None
*
*******************************************************************************/
void I2C_SCB_IRQ_SetPriority(uint8 priority)
{
uint8 interruptState;
uint32 priorityOffset = ((I2C_SCB_IRQ__INTC_NUMBER % 4u) * 8u) + 6u;
interruptState = CyEnterCriticalSection();
*I2C_SCB_IRQ_INTC_PRIOR = (*I2C_SCB_IRQ_INTC_PRIOR & (uint32)(~I2C_SCB_IRQ__INTC_PRIOR_MASK)) |
((uint32)priority << priorityOffset);
CyExitCriticalSection(interruptState);
}
/*******************************************************************************
* Function Name: I2C_SCB_IRQ_GetPriority
********************************************************************************
*
* Summary:
* Gets the Priority of the Interrupt.
*
* Parameters:
* None
*
* Return:
* Priority of the interrupt, 0 being the highest priority
* PSoC 3 and PSoC 5LP: Priority is from 0 to 7.
* PSoC 4: Priority is from 0 to 3.
*
*******************************************************************************/
uint8 I2C_SCB_IRQ_GetPriority(void)
{
uint32 priority;
uint32 priorityOffset = ((I2C_SCB_IRQ__INTC_NUMBER % 4u) * 8u) + 6u;
priority = (*I2C_SCB_IRQ_INTC_PRIOR & I2C_SCB_IRQ__INTC_PRIOR_MASK) >> priorityOffset;
return (uint8)priority;
}
/*******************************************************************************
* Function Name: I2C_SCB_IRQ_Enable
********************************************************************************
*
* Summary:
* Enables the interrupt to the interrupt controller. Do not call this function
* unless ISR_Start() has been called or the functionality of the ISR_Start()
* function, which sets the vector and the priority, has been called.
*
* Parameters:
* None
*
* Return:
* None
*
*******************************************************************************/
void I2C_SCB_IRQ_Enable(void)
{
/* Enable the general interrupt. */
*I2C_SCB_IRQ_INTC_SET_EN = I2C_SCB_IRQ__INTC_MASK;
}
/*******************************************************************************
* Function Name: I2C_SCB_IRQ_GetState
********************************************************************************
*
* Summary:
* Gets the state (enabled, disabled) of the Interrupt.
*
* Parameters:
* None
*
* Return:
* 1 if enabled, 0 if disabled.
*
*******************************************************************************/
uint8 I2C_SCB_IRQ_GetState(void)
{
/* Get the state of the general interrupt. */
return ((*I2C_SCB_IRQ_INTC_SET_EN & (uint32)I2C_SCB_IRQ__INTC_MASK) != 0u) ? 1u:0u;
}
/*******************************************************************************
* Function Name: I2C_SCB_IRQ_Disable
********************************************************************************
*
* Summary:
* Disables the Interrupt in the interrupt controller.
*
* Parameters:
* None
*
* Return:
* None
*
*******************************************************************************/
void I2C_SCB_IRQ_Disable(void)
{
/* Disable the general interrupt. */
*I2C_SCB_IRQ_INTC_CLR_EN = I2C_SCB_IRQ__INTC_MASK;
}
/*******************************************************************************
* Function Name: I2C_SCB_IRQ_SetPending
********************************************************************************
*
* Summary:
* Causes the Interrupt to enter the pending state, a software method of
* generating the interrupt.
*
* Parameters:
* None
*
* Return:
* None
*
* Side Effects:
* If interrupts are enabled and the interrupt is set up properly, the ISR is
* entered (depending on the priority of this interrupt and other pending
* interrupts).
*
*******************************************************************************/
void I2C_SCB_IRQ_SetPending(void)
{
*I2C_SCB_IRQ_INTC_SET_PD = I2C_SCB_IRQ__INTC_MASK;
}
/*******************************************************************************
* Function Name: I2C_SCB_IRQ_ClearPending
********************************************************************************
*
* Summary:
* Clears a pending interrupt in the interrupt controller.
*
* Note Some interrupt sources are clear-on-read and require the block
* interrupt/status register to be read/cleared with the appropriate block API
* (GPIO, UART, and so on). Otherwise the ISR will continue to remain in
* pending state even though the interrupt itself is cleared using this API.
*
* Parameters:
* None
*
* Return:
* None
*
*******************************************************************************/
void I2C_SCB_IRQ_ClearPending(void)
{
*I2C_SCB_IRQ_INTC_CLR_PD = I2C_SCB_IRQ__INTC_MASK;
}
#endif /* End check for removal by optimization */
/* [] END OF FILE */