-
Notifications
You must be signed in to change notification settings - Fork 2
/
IRQhandler.cpp
69 lines (59 loc) · 1.96 KB
/
IRQhandler.cpp
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
/*
* File: IRQhandler.cpp
* Author: Michele Liscio
* Author: Andrea Cirigliano
*
* Created on January 12, 2015, 2:38 PM
*/
#include "IRQhandler.h"
#include <miosix.h>
#include <miosix/kernel/scheduler/scheduler.h>
using namespace miosix;
typedef Gpio<GPIOE_BASE, 0> int1Signal;
static Thread *waiting=0;
void __attribute__((naked)) EXTI0_IRQHandler()
{
saveContext();
asm volatile("bl _Z16EXTI0HandlerImplv");
restoreContext();
}
void __attribute__((used)) EXTI0HandlerImpl()
{
/* is set by HW when the selected edge event arrives on the external interrupt line. It's cleared writing 1 */
EXTI->PR=EXTI_PR_PR0;
if(waiting==0) return;
waiting->IRQwakeup();
if(waiting->IRQgetPriority()>Thread::IRQgetCurrentThread()->IRQgetPriority())
Scheduler::IRQfindNextThread();
waiting=0;
}
/**
* @brief configures the interrupt in line 0 for the accelerometer;
*/
void IRQhandler::configureAccInterrupt()
{
RCC->AHB1ENR |= RCC_AHB1ENR_GPIOEEN; //enable GPIOE clock
int1Signal::mode(Mode::INPUT); //create interrupt on rising edge of the accelerometer interrupt
RCC->APB2ENR |= RCC_APB2ENR_SYSCFGEN; // system configuration controller clock enable
SYSCFG->EXTICR[0] = SYSCFG_EXTICR1_EXTI0_PE; //use PE0 for EXTI_Line0
EXTI->IMR |= EXTI_IMR_MR0; //interrupt request from line 0 is not masked
EXTI->RTSR |= EXTI_RTSR_TR0; //rising trigger enabled
/* enables a device-specific interrupt in the NVIC interrupt controller;
EXTI0_IRQn = 6 : EXTI Line0 Interrupt = STM32 specific Interrupt Number */
NVIC_EnableIRQ(EXTI0_IRQn);
NVIC_SetPriority(EXTI0_IRQn,15); //low priority
}
/**
* @brief puts the current thread in wait condition until the interrupt is received;
*/
void IRQhandler::waitForInt1()
{
FastInterruptDisableLock dLock;
waiting=Thread::IRQgetCurrentThread();
while(waiting)
{
Thread::IRQwait();
FastInterruptEnableLock eLock(dLock);
Thread::yield();
}
}