Skip to content

Commit

Permalink
Re-enable IRQ from 10 to 14
Browse files Browse the repository at this point in the history
  • Loading branch information
facchinm committed Oct 11, 2024
1 parent 555d7b4 commit 805b033
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 13 deletions.
2 changes: 2 additions & 0 deletions include/gpio.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,6 @@ void gpio_enable_irq(uint16_t pin);
void gpio_disable_irq(uint16_t pin);
void gpio_set_handler(uint16_t pin);

void gpio_handle_irq();

#endif /* GPIO_H */
16 changes: 8 additions & 8 deletions src/gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,12 @@ static void MX_GPIO_Init(void) {
__HAL_RCC_GPIOG_CLK_ENABLE();
}

static void handle_irq() {
void gpio_handle_irq() {
uint32_t pr = EXTI->PR1;
uint8_t index = 0;
while (pr != 0) {
if (pr & 0x1) {
dbg_printf("handle_irq: index = %d (%x)\n", index, 1<<index);
dbg_printf("gpio_handle_irq: index = %d (%x)\n", index, 1<<index);
/* Set the flag variable which leads to a transmission
* of a interrupt event within gpio_handle_data.
*/
Expand Down Expand Up @@ -153,17 +153,17 @@ void gpio_enable_irq(uint16_t pin) {
void gpio_set_handler(uint16_t pin)
{
if (pin == GPIO_PIN_0) {
NVIC_SetVector(EXTI0_IRQn, (uint32_t)&handle_irq);
NVIC_SetVector(EXTI0_IRQn, (uint32_t)&gpio_handle_irq);
} else if (pin == GPIO_PIN_1) {
NVIC_SetVector(EXTI1_IRQn, (uint32_t)&handle_irq);
NVIC_SetVector(EXTI1_IRQn, (uint32_t)&gpio_handle_irq);
} else if (pin == GPIO_PIN_2) {
NVIC_SetVector(EXTI2_IRQn, (uint32_t)&handle_irq);
NVIC_SetVector(EXTI2_IRQn, (uint32_t)&gpio_handle_irq);
} else if (pin == GPIO_PIN_3) {
NVIC_SetVector(EXTI3_IRQn, (uint32_t)&handle_irq);
NVIC_SetVector(EXTI3_IRQn, (uint32_t)&gpio_handle_irq);
} else if (pin == GPIO_PIN_4) {
NVIC_SetVector(EXTI4_IRQn, (uint32_t)&handle_irq);
NVIC_SetVector(EXTI4_IRQn, (uint32_t)&gpio_handle_irq);
} else if (pin >= GPIO_PIN_5 && pin <= GPIO_PIN_9) {
NVIC_SetVector(EXTI9_5_IRQn, (uint32_t)&handle_irq);
NVIC_SetVector(EXTI9_5_IRQn, (uint32_t)&gpio_handle_irq);
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/gpio_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ int gpio_handler(uint8_t const opcode, uint8_t const * data, uint16_t const size
case IRQ_TYPE:
GPIO_InitStruct.Pin = GPIO_pinmap[index].pin;

if (GPIO_InitStruct.Pin > GPIO_PIN_9) {
// IRQs from 10 to 15 are exclusively used by SPI
if (GPIO_InitStruct.Pin == GPIO_PIN_15) {
// IRQ15 is used for SPI
return 0;
}

Expand Down Expand Up @@ -139,7 +139,7 @@ int gpio_handler(uint8_t const opcode, uint8_t const * data, uint16_t const size
case IRQ_ACK:
dbg_printf("GPIO%d: IRQ_ACK %d\n", index, value);
/* Re-enable the interrupt that was disabled within
* handle_irq to prevent firing of another interrupt
* gpio_handle_irq to prevent firing of another interrupt
* until this one has been signaled to the application.
*/
gpio_enable_irq(GPIO_pinmap[index].pin);
Expand Down
8 changes: 6 additions & 2 deletions src/system.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
#include <string.h>
#include "rpc.h"
#include "spi.h"
#include "gpio.h"
#include "stm32h7xx_ll_exti.h"

/**************************************************************************************
* GLOBAL VARIABLES
Expand Down Expand Up @@ -219,7 +221,7 @@ int get_available_enqueue() {
int enqueue_packet(uint8_t const peripheral, uint8_t const opcode, uint16_t const size, void * data)
{
/* Enter critical section: Since this function is called both from inside
* interrupt context (handle_irq/gpio.c) as well as from normal execution
* interrupt context (gpio_handle_irq/gpio.c) as well as from normal execution
* context it is necessary not only to blindly re-enable interrupts, but
* to store the current interrupt situation and restore it at the end of
* the critical section.
Expand Down Expand Up @@ -347,10 +349,12 @@ void dma_load() {

void EXTI15_10_IRQHandler(void)
{
if (HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_15) == GPIO_PIN_SET) {
if (HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_15) == GPIO_PIN_SET && LL_EXTI_ReadFlag_0_31(LL_EXTI_LINE_15)) {
HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_15);
spi_end();
dma_load();
} else {
gpio_handle_irq();
}
}

Expand Down

0 comments on commit 805b033

Please sign in to comment.