Koduino
exti.h
1 
20 #ifndef _exti_h_
21 #define _exti_h_
22 
23 #include "types.h"
24 #include "system_clock.h"
25 #include "gpio.h"
26 
27 #ifdef __cplusplus
28 extern "C"{
29 #endif // __cplusplus
30 
31 extern int PWM_IN_EXTI_MAXPERIOD;
32 extern int PWM_IN_EXTI_MINPERIOD;
33 extern int PWM_IN_MAXPERIOD;
34 extern int PWM_IN_MINPERIOD;
35 
36 extern const uint32_t extiLines[];
37 // This function is called by any of the interrupt handlers. It essentially fetches the user function pointer from the array and calls it.
38 #if defined(KODUINO_ISRS_INLINE)
39 static inline void wirishExternalInterruptHandler(uint8_t i) __attribute__((always_inline, unused));
40 #else
41 static inline void wirishExternalInterruptHandler(uint8_t i);
42 #endif
43 static inline void wirishExternalInterruptHandler(uint8_t i) {
44  EXTI_ClearITPendingBit(extiLines[i]);
45  // __disable_irq();
46  EXTIChannel *S = &EXTI_MAP[i];
47  // PWM_IN_EXTI pin?
48  if (S->bPwmIn == 1) {
49 
50  // NEW
51  volatile int currentMs = millis();
52  volatile int currentSubMs = SysTick->LOAD - SysTick->VAL;
53  volatile int delta = (currentMs - S->risingEdgeMs) * SysTick->LOAD + currentSubMs - S->risingEdgeSubMs;
54 
55  if (digitalRead(S->pinName)) {
56  // This was a rising edge
57  S->risingEdgeMs = currentMs;
58  S->risingEdgeSubMs = currentSubMs;
59  S->period = delta;
60  if (delta > PWM_IN_EXTI_MAXPERIOD)
61  S->period = delta - SysTick->LOAD;
62  else if (delta < PWM_IN_EXTI_MINPERIOD)
63  S->period = delta + SysTick->LOAD;
64  } else {
65  // This was a falling edge
66  S->pulsewidth = delta;
67  }
68  } else {
69  // ELSE fetch the user function pointer from the array
70  ISRType handler = S->handler;
71  //Check to see if the user handle is NULL
72  if (handler != 0)
73  handler();
74  }
75  // __enable_irq();
76 }
77 
82 void attachInterruptWithPriority(uint8_t pinName, ISRType ISR, InterruptTrigger mode, uint8_t priority);
83 
94 void attachInterrupt(uint8_t pinName, ISRType ISR, InterruptTrigger mode);
95 
102 void detachInterrupt(uint8_t pinName);
103 
110 void noInterrupts();
111 
116 void interrupts();
117 
118  // end of addtogroup
120 
121 
122 
123 // // PWM Input using EXTI
124 // float pwmIn(uint8_t pinName);
125 
126 // // Private
127 // void pinModePwmIn(uint8_t pinName);
128 // void pwmInClkInit();
129 // uint32_t pwmInTicks();
130 
131 #ifdef __cplusplus
132 } // extern "C"
133 #endif // __cplusplus
134 
135 #endif
void noInterrupts()
Disable external interrupts.
Definition: exti.c:173
Definition: types.h:108
static uint8_t digitalRead(uint8_t pin) __attribute__((always_inline
Read a digital pin.
Definition: gpio.h:57
static uint32_t millis() __attribute__((always_inline
Definition: system_clock.h:50
void detachInterrupt(uint8_t pinName)
Disable an interrupt.
Definition: exti.c:155
void interrupts()
Enable external interrupts.
Definition: exti.c:179
void attachInterrupt(uint8_t pinName, ISRType ISR, InterruptTrigger mode)
Enable an interrupt with default priority.
Definition: exti.c:151