1 /*
2 * Copyright (C) 2016 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #ifndef _EXTI_H_
18 #define _EXTI_H_
19
20 #include <isr.h>
21 #include <stdbool.h>
22 #include <plat/inc/cmsis.h>
23 #include <plat/inc/gpio.h>
24 #include <gpio.h>
25
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29
30 enum ExtiTrigger
31 {
32 EXTI_TRIGGER_RISING = 0,
33 EXTI_TRIGGER_FALLING,
34 EXTI_TRIGGER_BOTH,
35 };
36
37 enum ExtiLine
38 {
39 EXTI_LINE_P0 = 0,
40 EXTI_LINE_P1,
41 EXTI_LINE_P2,
42 EXTI_LINE_P3,
43 EXTI_LINE_P4,
44 EXTI_LINE_P5,
45 EXTI_LINE_P6,
46 EXTI_LINE_P7,
47 EXTI_LINE_P8,
48 EXTI_LINE_P9,
49 EXTI_LINE_P10,
50 EXTI_LINE_P11,
51 EXTI_LINE_P12,
52 EXTI_LINE_P13,
53 EXTI_LINE_P14,
54 EXTI_LINE_P15,
55 EXTI_LINE_PVD = 16,
56 EXTI_LINE_RTC_ALARM = 17,
57 EXTI_LINE_USB_OTG_FS_WKUP = 18,
58 EXTI_LINE_RTC_TAMPER_TS = 21,
59 EXTI_LINE_RTC_WKUP = 22,
60 };
61
62 void extiEnableIntLine(const enum ExtiLine line, enum ExtiTrigger trigger);
63 void extiDisableIntLine(const enum ExtiLine line);
64 bool extiIsPendingLine(const enum ExtiLine line);
65 void extiClearPendingLine(const enum ExtiLine line);
66
67 int extiChainIsr(IRQn_Type n, struct ChainedIsr *isr);
68 int extiUnchainIsr(IRQn_Type n, struct ChainedIsr *isr);
69 int extiUnchainAll(uint32_t tid);
70
extiEnableIntGpio(const struct Gpio * __restrict gpioHandle,enum ExtiTrigger trigger)71 static inline void extiEnableIntGpio(const struct Gpio *__restrict gpioHandle, enum ExtiTrigger trigger)
72 {
73 if (gpioHandle) {
74 uint32_t gpioNum = (uint32_t)gpioHandle - GPIO_HANDLE_OFFSET;
75 extiEnableIntLine(gpioNum & GPIO_PIN_MASK, trigger);
76 }
77 }
extiDisableIntGpio(const struct Gpio * __restrict gpioHandle)78 static inline void extiDisableIntGpio(const struct Gpio *__restrict gpioHandle)
79 {
80 if (gpioHandle) {
81 uint32_t gpioNum = (uint32_t)gpioHandle - GPIO_HANDLE_OFFSET;
82 extiDisableIntLine(gpioNum & GPIO_PIN_MASK);
83 }
84 }
extiIsPendingGpio(const struct Gpio * __restrict gpioHandle)85 static inline bool extiIsPendingGpio(const struct Gpio *__restrict gpioHandle)
86 {
87 if (gpioHandle) {
88 uint32_t gpioNum = (uint32_t)gpioHandle - GPIO_HANDLE_OFFSET;
89 return extiIsPendingLine(gpioNum & GPIO_PIN_MASK);
90 }
91 return false;
92 }
extiClearPendingGpio(const struct Gpio * __restrict gpioHandle)93 static inline void extiClearPendingGpio(const struct Gpio *__restrict gpioHandle)
94 {
95 if (gpioHandle) {
96 uint32_t gpioNum = (uint32_t)gpioHandle - GPIO_HANDLE_OFFSET;
97 extiClearPendingLine(gpioNum & GPIO_PIN_MASK);
98 }
99 }
100
101 #ifdef __cplusplus
102 }
103 #endif
104
105 #endif
106