-
Notifications
You must be signed in to change notification settings - Fork 0
/
interrupt_if.c
132 lines (112 loc) · 3.65 KB
/
interrupt_if.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
#include <stdlib.h>
#include "hw_types.h"
#include "hw_ints.h"
#include "rom.h"
#include "rom_map.h"
#include "gpio.h"
#include "interrupt.h"
#include "pin.h"
#include "hw_memmap.h"
#ifdef SL_PLATFORM_MULTI_THREADED /* If OS-based application */
#include "osi.h"
#endif
#include "interrupt_if.h"
#define IRQ0_GPIO_BASE GPIOA0_BASE //GPIOA2_BASE
#define IRQ0_GPIO_PIN GPIO_PIN_6 //GPIO_PIN_6
#define IRQ0_INT INT_GPIOA0 //INT_GPIOA2
#define IRQ1_GPIO_BASE GPIOA1_BASE //GPIOA1_BASE
#define IRQ1_GPIO_PIN GPIO_PIN_5 //GPIO_PIN_5
#define IRQ1_INT INT_GPIOA1 //INT_GPIOA1
P_INT_HANDLER IRQ0_InterruptHdl;
P_INT_HANDLER IRQ1_InterruptHdl;
void IRQ0_IntHandler()
{
unsigned long ulPinState = GPIOIntStatus(IRQ0_GPIO_BASE,1);
if(ulPinState & IRQ0_GPIO_PIN)
{
Interrupt_Disable(IRQ0_IO);
Interrupt_Disable(IRQ1_IO);
Interrupt_Enable(IRQ0_IO);
Interrupt_Enable(IRQ1_IO);
IRQ0_InterruptHdl();
}
}
void IRQ1_IntHandler()
{
unsigned long ulPinState = GPIOIntStatus(IRQ1_GPIO_BASE,1);
if(ulPinState & IRQ1_GPIO_PIN)
{
Interrupt_Disable(IRQ0_IO);
Interrupt_Disable(IRQ1_IO);
Interrupt_Enable(IRQ0_IO);
Interrupt_Enable(IRQ1_IO);
IRQ1_InterruptHdl();
}
}
void Interrupt_IF_Init(P_INT_HANDLER s_IRQ0_InterruptHdl,P_INT_HANDLER s_IRQ1_InterruptHdl )
{
if(s_IRQ1_InterruptHdl != NULL)
{
// Set Interrupt Type for GPIO
MAP_GPIOIntTypeSet(IRQ1_GPIO_BASE,IRQ1_GPIO_PIN,GPIO_FALLING_EDGE);
IRQ1_InterruptHdl = s_IRQ1_InterruptHdl;
// Register Interrupt handler
#if defined(USE_TIRTOS) || defined(USE_FREERTOS) || defined(SL_PLATFORM_MULTI_THREADED)
osi_InterruptRegister(IRQ1_INT,(P_OSI_INTR_ENTRY)IRQ1_IntHandler, \
INT_PRIORITY_LVL_1);
#else
MAP_IntPrioritySet(IRQ1_INT, INT_PRIORITY_LVL_1);
MAP_GPIOIntRegister(IRQ1_GPIO_BASE, IRQ1_IntHandler);
#endif
MAP_GPIOIntClear(IRQ1_GPIO_BASE,IRQ1_GPIO_PIN);
MAP_GPIOIntEnable(IRQ1_GPIO_BASE,GPIO_INT_PIN_5);
}
if(s_IRQ0_InterruptHdl != NULL)
{
// Set Interrupt Type for GPIO
MAP_GPIOIntTypeSet(IRQ0_GPIO_BASE,IRQ0_GPIO_PIN,GPIO_FALLING_EDGE);
IRQ0_InterruptHdl = s_IRQ0_InterruptHdl;
// Register Interrupt handler
#if defined(USE_TIRTOS) || defined(USE_FREERTOS) || defined(SL_PLATFORM_MULTI_THREADED)
osi_InterruptRegister(IRQ0_INT,(P_OSI_INTR_ENTRY)IRQ0_IntHandler, \
INT_PRIORITY_LVL_1);
#else
MAP_IntPrioritySet(IRQ0_INT, INT_PRIORITY_LVL_1);
MAP_GPIOIntRegister(IRQ0_GPIO_BASE, IRQ0_IntHandler);
#endif
MAP_GPIOIntClear(IRQ0_GPIO_BASE,IRQ0_GPIO_PIN);
MAP_GPIOIntEnable(IRQ0_GPIO_BASE,GPIO_INT_PIN_6);
}
}
void Interrupt_Enable(unsigned char ucInterrupt)
{
if(ucInterrupt & IRQ0_IO)
{
MAP_GPIOIntClear(IRQ0_GPIO_BASE,IRQ0_GPIO_PIN);
MAP_IntPendClear(IRQ0_INT);
MAP_IntEnable(IRQ0_INT);
MAP_GPIOIntEnable(IRQ0_GPIO_BASE,IRQ0_GPIO_PIN);
}
if(ucInterrupt & IRQ1_IO)
{
MAP_GPIOIntClear(IRQ1_GPIO_BASE,IRQ1_GPIO_PIN);
MAP_IntPendClear(IRQ1_INT);
MAP_IntEnable(IRQ1_INT);
MAP_GPIOIntEnable(IRQ1_GPIO_BASE,IRQ1_GPIO_PIN);
}
}
void Interrupt_Disable(unsigned char ucInterrupt)
{
if(ucInterrupt & IRQ0_IO)
{
MAP_GPIOIntDisable(IRQ0_GPIO_BASE,IRQ0_GPIO_PIN);
MAP_GPIOIntClear(IRQ0_GPIO_BASE,IRQ0_GPIO_PIN);
MAP_IntDisable(IRQ0_INT);
}
if(ucInterrupt & IRQ1_IO)
{
MAP_GPIOIntDisable(IRQ1_GPIO_BASE,IRQ1_GPIO_PIN);
MAP_GPIOIntClear(IRQ1_GPIO_BASE,IRQ1_GPIO_PIN);
MAP_IntDisable(IRQ1_INT);
}
}