Skip to content

Commit

Permalink
Merge pull request #124 from mikehamer/update_exti
Browse files Browse the repository at this point in the history
Enables all EXTI handlers to use callbacks
  • Loading branch information
ataffanel authored Jun 22, 2016
2 parents 81c6437 + 92a4a1a commit 3c2080d
Show file tree
Hide file tree
Showing 8 changed files with 189 additions and 29 deletions.
10 changes: 10 additions & 0 deletions src/config/nvicconf.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,5 +84,15 @@
#define NVIC_RADIO_PRI 11
#define NVIC_ADC_PRI 12
#define NVIC_CPPM_PRI 14
#define NVIC_SYSLINK_PRI 5

// Priorities for external interrupts
#define EXTI0_PRI NVIC_LOW_PRI
#define EXTI1_PRI NVIC_LOW_PRI
#define EXTI2_PRI NVIC_LOW_PRI
#define EXTI3_PRI NVIC_LOW_PRI
#define EXTI4_PRI NVIC_SYSLINK_PRI // this serves the syslink UART
#define EXTI9_5_PRI NVIC_LOW_PRI
#define EXTI15_10_PRI NVIC_MID_PRI // this serves the decks and sensors

#endif /* NVIC_CONF_H_ */
2 changes: 1 addition & 1 deletion src/deck/drivers/src/dwm1000.c
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ static void spiRead(dwDevice_t* dev, const void *header, size_t headerLength,
xSemaphoreGive(spiSemaphore);
}

void __attribute__((used)) EXTI15_10_IRQHandler(void)
void __attribute__((used)) EXTI11_Callback(void)
{
portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;

Expand Down
17 changes: 16 additions & 1 deletion src/drivers/interface/exti.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,22 @@
void extiInit();
bool extiTest();

inline void extiInterruptHandler(void);
void EXTI0_Callback(void);
void EXTI1_Callback(void);
void EXTI2_Callback(void);
void EXTI3_Callback(void);
void EXTI4_Callback(void);
void EXTI5_Callback(void);
void EXTI6_Callback(void);
void EXTI7_Callback(void);
void EXTI8_Callback(void);
void EXTI9_Callback(void);
void EXTI10_Callback(void);
void EXTI11_Callback(void);
void EXTI12_Callback(void);
void EXTI13_Callback(void);
void EXTI14_Callback(void);
void EXTI15_Callback(void);

#endif /* __EXTI_H__ */

165 changes: 148 additions & 17 deletions src/drivers/src/exti.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,31 +27,65 @@

#include "stm32fxxx.h"

#include "exti.h"
#include "nvicconf.h"
#include "nrf24l01.h"

#ifdef PLATFORM_CF1
#define RADIO_GPIO_IRQ_LINE EXTI_Line9
#define RADIO_IRQ_CHANNEL EXTI9_5_IRQn
#else
#define RADIO_GPIO_IRQ_LINE EXTI_Line10
#define RADIO_IRQ_CHANNEL EXTI15_10_IRQn
#endif

static bool isInit;

/* Interruption initialisation */
void extiInit()
{
static NVIC_InitTypeDef NVIC_InitStructure;

if (isInit)
return;

NVIC_InitTypeDef NVIC_InitStructure;
#ifdef PLATFORM_CF2
// This is required for the EXTI interrupt configuration since EXTI
// lines are set via the SYSCFG peripheral; eg.
// SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOC, EXTI_PinSource13);

// On the CF1, the equivalent command is:
// GPIO_EXTILineConfig(GPIO_PortSourceGPIOC, GPIO_PinSource9);
// which only requires the relevant GPIO clock to be enabled.

RCC_AHB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
#endif

// Here we enable all EXTI interrupt handlers to save conflicting
// reinitialization code for the 9_5 and 15_10 handlers. Note that
// the individual EXTI interrupts still need to be enabled.

NVIC_InitStructure.NVIC_IRQChannel = RADIO_IRQ_CHANNEL;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = NVIC_RADIO_PRI;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = EXTI0_PRI;
NVIC_InitStructure.NVIC_IRQChannel = EXTI0_IRQn;
NVIC_Init(&NVIC_InitStructure);

NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = EXTI1_PRI;
NVIC_InitStructure.NVIC_IRQChannel = EXTI1_IRQn;
NVIC_Init(&NVIC_InitStructure);

NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = EXTI2_PRI;
NVIC_InitStructure.NVIC_IRQChannel = EXTI2_IRQn;
NVIC_Init(&NVIC_InitStructure);

NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = EXTI3_PRI;
NVIC_InitStructure.NVIC_IRQChannel = EXTI3_IRQn;
NVIC_Init(&NVIC_InitStructure);

NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = EXTI4_PRI;
NVIC_InitStructure.NVIC_IRQChannel = EXTI4_IRQn;
NVIC_Init(&NVIC_InitStructure);

NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = EXTI9_5_PRI;
NVIC_InitStructure.NVIC_IRQChannel = EXTI9_5_IRQn;
NVIC_Init(&NVIC_InitStructure);

NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = EXTI15_10_PRI;
NVIC_InitStructure.NVIC_IRQChannel = EXTI15_10_IRQn;
NVIC_Init(&NVIC_InitStructure);

isInit = true;
Expand All @@ -62,13 +96,110 @@ bool extiTest(void)
return isInit;
}

#ifdef PLATFORM_CF1
void __attribute__((used)) EXTI0_IRQHandler(void)
{
EXTI_ClearITPendingBit(EXTI_Line0);
EXTI0_Callback();
}

void __attribute__((used)) EXTI1_IRQHandler(void)
{
EXTI_ClearITPendingBit(EXTI_Line1);
EXTI1_Callback();
}

void __attribute__((used)) EXTI2_IRQHandler(void)
{
EXTI_ClearITPendingBit(EXTI_Line2);
EXTI2_Callback();
}

void __attribute__((used)) EXTI3_IRQHandler(void)
{
EXTI_ClearITPendingBit(EXTI_Line3);
EXTI3_Callback();
}

void __attribute__((used)) EXTI4_IRQHandler(void)
{
EXTI_ClearITPendingBit(EXTI_Line4);
EXTI4_Callback();
}

void __attribute__((used)) EXTI9_5_IRQHandler(void)
{
if (EXTI_GetITStatus(RADIO_GPIO_IRQ_LINE) == SET)
{
EXTI_ClearITPendingBit(RADIO_GPIO_IRQ_LINE);
nrfIsr();
if (EXTI_GetITStatus(EXTI_Line5) == SET) {
EXTI_ClearITPendingBit(EXTI_Line5);
EXTI5_Callback();
}

if (EXTI_GetITStatus(EXTI_Line6) == SET) {
EXTI_ClearITPendingBit(EXTI_Line6);
EXTI6_Callback();
}

if (EXTI_GetITStatus(EXTI_Line7) == SET) {
EXTI_ClearITPendingBit(EXTI_Line7);
EXTI7_Callback();
}

if (EXTI_GetITStatus(EXTI_Line8) == SET) {
EXTI_ClearITPendingBit(EXTI_Line8);
EXTI8_Callback();
}

if (EXTI_GetITStatus(EXTI_Line9) == SET) {
EXTI_ClearITPendingBit(EXTI_Line9);
EXTI9_Callback();
}
}
#endif

void __attribute__((used)) EXTI15_10_IRQHandler(void)
{
if (EXTI_GetITStatus(EXTI_Line10) == SET) {
EXTI_ClearITPendingBit(EXTI_Line10);
EXTI10_Callback();
}

if (EXTI_GetITStatus(EXTI_Line11) == SET) {
EXTI_ClearITPendingBit(EXTI_Line11);
EXTI11_Callback();
}

if (EXTI_GetITStatus(EXTI_Line12) == SET) {
EXTI_ClearITPendingBit(EXTI_Line12);
EXTI12_Callback();
}

if (EXTI_GetITStatus(EXTI_Line13) == SET) {
EXTI_ClearITPendingBit(EXTI_Line13);
EXTI13_Callback();
}

if (EXTI_GetITStatus(EXTI_Line14) == SET) {
EXTI_ClearITPendingBit(EXTI_Line14);
EXTI14_Callback();
}

if (EXTI_GetITStatus(EXTI_Line15) == SET) {
EXTI_ClearITPendingBit(EXTI_Line15);
EXTI15_Callback();
}
}

void __attribute__((weak)) EXTI0_Callback(void) { }
void __attribute__((weak)) EXTI1_Callback(void) { }
void __attribute__((weak)) EXTI2_Callback(void) { }
void __attribute__((weak)) EXTI3_Callback(void) { }
void __attribute__((weak)) EXTI4_Callback(void) { }
void __attribute__((weak)) EXTI5_Callback(void) { }
void __attribute__((weak)) EXTI6_Callback(void) { }
void __attribute__((weak)) EXTI7_Callback(void) { }
void __attribute__((weak)) EXTI8_Callback(void) { }
void __attribute__((weak)) EXTI9_Callback(void) { }
void __attribute__((weak)) EXTI10_Callback(void) { }
void __attribute__((weak)) EXTI11_Callback(void) { }
void __attribute__((weak)) EXTI12_Callback(void) { }
void __attribute__((weak)) EXTI13_Callback(void) { }
void __attribute__((weak)) EXTI14_Callback(void) { }
void __attribute__((weak)) EXTI15_Callback(void) { }
12 changes: 4 additions & 8 deletions src/drivers/src/nrf24l01.c
Original file line number Diff line number Diff line change
Expand Up @@ -279,14 +279,13 @@ unsigned char nrfReadRX(char *buffer, int len)
return status;
}

/* Interrupt service routine, call the interrupt callback
*/
void nrfIsr()
/* Interrupt service routine, call the interrupt callback */
void __attribute__((used)) EXTI9_Callback(void)
{
if (interruptCb)
{
interruptCb();

return;
}
}

void nrfSetInterruptCallback(void (*cb)(void))
Expand Down Expand Up @@ -355,9 +354,6 @@ void nrfInit(void)
if (isInit)
return;

/* Enable the EXTI interrupt router */
extiInit();

/* Enable SPI and GPIO clocks */
RCC_APB2PeriphClockCmd(RADIO_GPIO_SPI_CLK | RADIO_GPIO_CS_PERIF |
RADIO_GPIO_CE_PERIF | RADIO_GPIO_IRQ_PERIF, ENABLE);
Expand Down
4 changes: 2 additions & 2 deletions src/drivers/src/uart_syslink.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ void uartslkInit(void)

// Configure Rx buffer not empty interrupt
NVIC_InitStructure.NVIC_IRQChannel = UARTSLK_IRQ;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = NVIC_HIGH_PRI;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = NVIC_SYSLINK_PRI;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
Expand Down Expand Up @@ -368,7 +368,7 @@ void uartslkTxenFlowctrlIsr()
}
}

void __attribute__((used)) EXTI4_IRQHandler(void)
void __attribute__((used)) EXTI4_Callback(void)
{
uartslkTxenFlowctrlIsr();
}
Expand Down
4 changes: 4 additions & 0 deletions src/platform/cf1/platform_cf1.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
*/

/* Project includes */
#include "exti.h"
#include "nvic.h"

// TODO: Implement!
Expand All @@ -33,6 +34,9 @@ int platformInit(void)
//Low level init: Clock and Interrupt controller
nvicInit();

//EXTI interrupts
extiInit();

return 0;
}

4 changes: 4 additions & 0 deletions src/platform/cf2/platform_cf2.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

/* Personal configs */
/* Project includes */
#include "exti.h"
#include "nvic.h"

// TODO: Implement!
Expand All @@ -34,6 +35,9 @@ int platformInit(void)
//Low level init: Clock and Interrupt controller
nvicInit();

//EXTI interrupts
extiInit();

return 0;
}

0 comments on commit 3c2080d

Please sign in to comment.