Skip to content

Commit

Permalink
Merge pull request #247 from WoNd3RBoY/loco-pin-switch
Browse files Browse the repository at this point in the history
LOCO deck alternative pins for IRQ and RESET
  • Loading branch information
ataffanel authored Aug 14, 2017
2 parents 3a4996d + 7c0d0e3 commit 56c6915
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 20 deletions.
64 changes: 44 additions & 20 deletions src/deck/drivers/src/locodeck.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,26 @@

#define CS_PIN DECK_GPIO_IO1

// LOCO deck alternative IRQ and RESET pins(IO_2, IO_3) instead of default (RX1, TX1), leaving UART1 free for use
#ifdef LOCODECK_USE_ALT_PINS
#define GPIO_PIN_IRQ GPIO_Pin_5
#define GPIO_PIN_RESET GPIO_Pin_4
#define GPIO_PORT GPIOB
#define EXTI_PortSource EXTI_PortSourceGPIOB
#define EXTI_PinSource EXTI_PinSource5
#define EXTI_LineN EXTI_Line5
#define EXTI_IRQChannel EXTI9_5_IRQn
#else
#define GPIO_PIN_IRQ GPIO_Pin_11
#define GPIO_PIN_RESET GPIO_Pin_10
#define GPIO_PORT GPIOC
#define EXTI_PortSource EXTI_PortSourceGPIOC
#define EXTI_PinSource EXTI_PinSource11
#define EXTI_LineN EXTI_Line11
#define EXTI_IRQChannel EXTI15_10_IRQn
#endif


#if LPS_TDOA_ENABLE
#define RX_TIMEOUT 10000
#else
Expand Down Expand Up @@ -181,7 +201,7 @@ static void uwbTask(void* parameters)
if (xSemaphoreTake(irqSemaphore, timeout/portTICK_PERIOD_MS)) {
do{
dwHandleInterrupt(dwm);
} while(digitalRead(DECK_GPIO_RX1) != 0);
} while(digitalRead(GPIO_PIN_IRQ) != 0);
} else {
timeout = algorithm->onEvent(dwm, eventTimeout);
}
Expand Down Expand Up @@ -240,19 +260,23 @@ static void spiRead(dwDevice_t* dev, const void *header, size_t headerLength,
spiEndTransaction();
}

void __attribute__((used)) EXTI11_Callback(void)
{
portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
#if LOCODECK_USE_ALT_PINS
void __attribute__((used)) EXTI5_Callback(void)
#else
void __attribute__((used)) EXTI11_Callback(void)
#endif
{
portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;

NVIC_ClearPendingIRQ(EXTI15_10_IRQn);
EXTI_ClearITPendingBit(EXTI_Line11);
NVIC_ClearPendingIRQ(EXTI_IRQChannel);
EXTI_ClearITPendingBit(EXTI_LineN);

//To unlock RadioTask
xSemaphoreGiveFromISR(irqSemaphore, &xHigherPriorityTaskWoken);
//To unlock RadioTask
xSemaphoreGiveFromISR(irqSemaphore, &xHigherPriorityTaskWoken);

if(xHigherPriorityTaskWoken)
portYIELD();
}
if(xHigherPriorityTaskWoken)
portYIELD();
}

static void spiSetSpeed(dwDevice_t* dev, dwSpiSpeed_t speed)
{
Expand Down Expand Up @@ -290,33 +314,33 @@ static void dwm1000Init(DeckInfo *info)

// Init IRQ input
bzero(&GPIO_InitStructure, sizeof(GPIO_InitStructure));
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
GPIO_InitStructure.GPIO_Pin = GPIO_PIN_IRQ;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
//GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN;
GPIO_Init(GPIOC, &GPIO_InitStructure);
GPIO_Init(GPIO_PORT, &GPIO_InitStructure);

SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOC, EXTI_PinSource11);
SYSCFG_EXTILineConfig(EXTI_PortSource, EXTI_PinSource);

EXTI_InitStructure.EXTI_Line = EXTI_Line11;
EXTI_InitStructure.EXTI_Line = EXTI_LineN;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);

// Init reset output
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Pin = GPIO_PIN_RESET;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOC, &GPIO_InitStructure);
GPIO_Init(GPIO_PORT, &GPIO_InitStructure);

// Init CS pin
pinMode(CS_PIN, OUTPUT);

// Reset the DW1000 chip
GPIO_WriteBit(GPIOC, GPIO_Pin_10, 0);
GPIO_WriteBit(GPIO_PORT, GPIO_PIN_RESET, 0);
vTaskDelay(M2T(10));
GPIO_WriteBit(GPIOC, GPIO_Pin_10, 1);
GPIO_WriteBit(GPIO_PORT, GPIO_PIN_RESET, 1);
vTaskDelay(M2T(10));

// Initialize the driver
Expand Down Expand Up @@ -350,7 +374,7 @@ static void dwm1000Init(DeckInfo *info)
dwCommitConfiguration(dwm);

// Enable interrupt
NVIC_InitStructure.NVIC_IRQChannel = EXTI15_10_IRQn;
NVIC_InitStructure.NVIC_IRQChannel = EXTI_IRQChannel;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = NVIC_LOW_PRI;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
Expand Down
3 changes: 3 additions & 0 deletions tools/make/config.mk.example
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,6 @@

## Set number of anchor in LocoPositioningSystem
# CFLAGS += -DLOCODECK_NR_OF_ANCHORS=8

## Set alternative pins for LOCO deck (IRQ=IO_2, RESET=IO_3, default are RX1 and TX1)
# CFLAGS += -DLOCODECK_USE_ALT_PINS

0 comments on commit 56c6915

Please sign in to comment.