• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/cmsis.h>
23 #include <plat/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 
71 int extiSetMaxLatency(struct ChainedIsr *isr, uint32_t maxLatencyNs);
72 
extiEnableIntGpio(const struct Gpio * __restrict gpioHandle,enum ExtiTrigger trigger)73 static inline void extiEnableIntGpio(const struct Gpio *__restrict gpioHandle, enum ExtiTrigger trigger)
74 {
75     if (gpioHandle) {
76         uint32_t gpioNum = (uint32_t)gpioHandle - GPIO_HANDLE_OFFSET;
77         extiEnableIntLine(gpioNum & GPIO_PIN_MASK, trigger);
78     }
79 }
extiDisableIntGpio(const struct Gpio * __restrict gpioHandle)80 static inline void extiDisableIntGpio(const struct Gpio *__restrict gpioHandle)
81 {
82     if (gpioHandle) {
83         uint32_t gpioNum = (uint32_t)gpioHandle - GPIO_HANDLE_OFFSET;
84         extiDisableIntLine(gpioNum & GPIO_PIN_MASK);
85     }
86 }
extiIsPendingGpio(const struct Gpio * __restrict gpioHandle)87 static inline bool extiIsPendingGpio(const struct Gpio *__restrict gpioHandle)
88 {
89     if (gpioHandle) {
90         uint32_t gpioNum = (uint32_t)gpioHandle - GPIO_HANDLE_OFFSET;
91         return extiIsPendingLine(gpioNum & GPIO_PIN_MASK);
92     }
93     return false;
94 }
extiClearPendingGpio(const struct Gpio * __restrict gpioHandle)95 static inline void extiClearPendingGpio(const struct Gpio *__restrict gpioHandle)
96 {
97     if (gpioHandle) {
98         uint32_t gpioNum = (uint32_t)gpioHandle - GPIO_HANDLE_OFFSET;
99         extiClearPendingLine(gpioNum & GPIO_PIN_MASK);
100     }
101 }
102 
103 #ifdef __cplusplus
104 }
105 #endif
106 
107 #endif
108