Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
arduino-nRF5
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
xpstem
arduino-nRF5
Commits
5a400abf
Commit
5a400abf
authored
Mar 17, 2016
by
Sandeep Mistry
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Functional attachInterrupt/deattachInterrupt for change, falling, rising
parent
b8aa8a73
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
76 additions
and
105 deletions
+76
-105
cores/nRF52/WInterrupts.c
cores/nRF52/WInterrupts.c
+76
-105
No files found.
cores/nRF52/WInterrupts.c
View file @
5a400abf
...
...
@@ -16,36 +16,28 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <nrf_gpiote.h>
#include "Arduino.h"
#include "wiring_private.h"
#include <string.h>
// static voidFuncPtr callbacksInt[EXTERNAL_NUM_INTERRUPTS];
// /* Configure I/O interrupt sources */
// static void __initialize()
// {
// memset(callbacksInt, 0, sizeof(callbacksInt));
// NVIC_DisableIRQ(EIC_IRQn);
// NVIC_ClearPendingIRQ(EIC_IRQn);
// NVIC_SetPriority(EIC_IRQn, 0);
// NVIC_EnableIRQ(EIC_IRQn);
static
voidFuncPtr
callbacksInt
[
NUMBER_OF_GPIO_TE
];
static
int8_t
channelMap
[
NUMBER_OF_GPIO_TE
];
static
int
enabled
=
0
;
// // Enable GCLK for IEC (External Interrupt Controller)
// GCLK->CLKCTRL.reg = (uint16_t) (GCLK_CLKCTRL_CLKEN | GCLK_CLKCTRL_GEN_GCLK0 | GCLK_CLKCTRL_ID(GCM_EIC));
// /* Shall we do that?
// // Do a software reset on EIC
// EIC->CTRL.SWRST.bit = 1 ;
// while ((EIC->CTRL.SWRST.bit == 1) && (EIC->STATUS.SYNCBUSY.bit == 1)) { }
// */
/* Configure I/O interrupt sources */
static
void
__initialize
()
{
memset
(
callbacksInt
,
0
,
sizeof
(
callbacksInt
));
memset
(
channelMap
,
-
1
,
sizeof
(
channelMap
));
// // Enable EIC
// EIC->CTRL.bit.ENABLE = 1;
// while (EIC->STATUS.bit.SYNCBUSY == 1) { }
// }
NVIC_DisableIRQ
(
GPIOTE_IRQn
);
NVIC_ClearPendingIRQ
(
GPIOTE_IRQn
);
NVIC_SetPriority
(
GPIOTE_IRQn
,
1
);
NVIC_EnableIRQ
(
GPIOTE_IRQn
);
}
/*
* \brief Specifies a named Interrupt Service Routine (ISR) to call when an interrupt occurs.
...
...
@@ -53,62 +45,42 @@
*/
void
attachInterrupt
(
uint32_t
pin
,
voidFuncPtr
callback
,
uint32_t
mode
)
{
// static int enabled = 0;
// uint32_t config;
// uint32_t pos;
// EExt_Interrupts in = digitalPinToInterrupt(pin);
// if (in == NOT_AN_INTERRUPT || in == EXTERNAL_INT_NMI)
// return;
// if (!enabled) {
// __initialize();
// enabled = 1;
// }
// // Enable wakeup capability on pin in case being used during sleep
// EIC->WAKEUP.reg |= (1 << in);
// // Assign pin to EIC
// pinPeripheral(pin, PIO_EXTINT);
// // Assign callback to interrupt
// callbacksInt[in] = callback;
// // Look for right CONFIG register to be addressed
// if (in > EXTERNAL_INT_7) {
// config = 1;
// } else {
// config = 0;
// }
// // Configure the interrupt mode
// pos = (in - (8 * config)) << 2;
// switch (mode)
// {
// case LOW:
// EIC->CONFIG[config].reg |= EIC_CONFIG_SENSE0_LOW_Val << pos;
// break;
// case HIGH:
// EIC->CONFIG[config].reg |= EIC_CONFIG_SENSE0_HIGH_Val << pos;
// break;
// case CHANGE:
// EIC->CONFIG[config].reg |= EIC_CONFIG_SENSE0_BOTH_Val << pos;
// break;
// case FALLING:
// EIC->CONFIG[config].reg |= EIC_CONFIG_SENSE0_FALL_Val << pos;
// break;
// case RISING:
// EIC->CONFIG[config].reg |= EIC_CONFIG_SENSE0_RISE_Val << pos;
// break;
// }
// // Enable the interrupt
// EIC->INTENSET.reg = EIC_INTENSET_EXTINT(1 << in);
if
(
!
enabled
)
{
__initialize
();
enabled
=
1
;
}
nrf_gpiote_polarity_t
polarity
;
switch
(
mode
)
{
case
CHANGE
:
polarity
=
NRF_GPIOTE_POLARITY_TOGGLE
;
break
;
case
FALLING
:
polarity
=
NRF_GPIOTE_POLARITY_HITOLO
;
break
;
case
RISING
:
polarity
=
NRF_GPIOTE_POLARITY_LOTOHI
;
break
;
default:
return
;
}
for
(
int
ch
=
0
;
ch
<
NUMBER_OF_GPIO_TE
;
ch
++
)
{
if
(
channelMap
[
ch
]
==
-
1
||
(
uint32_t
)
channelMap
[
ch
]
==
pin
)
{
channelMap
[
ch
]
=
pin
;
callbacksInt
[
ch
]
=
callback
;
nrf_gpiote_event_configure
(
ch
,
pin
,
polarity
);
nrf_gpiote_event_enable
(
ch
);
nrf_gpiote_int_enable
(
1
<<
ch
);
break
;
}
}
}
/*
...
...
@@ -116,33 +88,32 @@ void attachInterrupt(uint32_t pin, voidFuncPtr callback, uint32_t mode)
*/
void
detachInterrupt
(
uint32_t
pin
)
{
// EExt_Interrupts in = digitalPinToInterrupt(pin);
// if (in == NOT_AN_INTERRUPT || in == EXTERNAL_INT_NMI)
// return;
for
(
int
ch
=
0
;
ch
<
NUMBER_OF_GPIO_TE
;
ch
++
)
{
if
((
uint32_t
)
channelMap
[
ch
]
==
pin
)
{
channelMap
[
ch
]
=
-
1
;
callbacksInt
[
ch
]
=
NULL
;
// EIC->INTENCLR.reg = EIC_INTENCLR_EXTINT(1 << in);
nrf_gpiote_event_disable
(
ch
);
nrf_gpiote_int_disable
(
1
<<
ch
);
// // Disable wakeup capability on pin during sleep
// EIC->WAKEUP.reg &= ~(1 << in);
break
;
}
}
}
// /*
// * External Interrupt Controller NVIC Interrupt Handler
// */
// void EIC_Handler(void)
// {
// // Test the 16 normal interrupts
// for (uint32_t i=EXTERNAL_INT_0; i<=EXTERNAL_INT_15; i++)
// {
// if ((EIC->INTFLAG.reg & (1 << i)) != 0)
// {
// // Call the callback function if assigned
// if (callbacksInt[i]) {
// callbacksInt[i]();
// }
// // Clear the interrupt
// EIC->INTFLAG.reg = 1 << i;
// }
// }
// }
void
GPIOTE_IRQHandler
()
{
nrf_gpiote_events_t
event
=
NRF_GPIOTE_EVENTS_IN_0
;
for
(
int
ch
=
0
;
ch
<
NUMBER_OF_GPIO_TE
;
ch
++
)
{
if
(
nrf_gpiote_event_is_set
(
event
)
&&
nrf_gpiote_int_is_enabled
(
1
<<
ch
))
{
if
(
channelMap
[
ch
]
!=
-
1
&&
callbacksInt
[
ch
])
{
callbacksInt
[
ch
]();
}
nrf_gpiote_event_clear
(
event
);
}
event
=
(
nrf_gpiote_events_t
)((
uint32_t
)
event
+
4
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment