Urbanite: Parking aid system
interr.c File Reference

Interrupt service routines for the STM32F4 platform. More...

#include "port_system.h"
#include "stm32f4_system.h"
#include "port_button.h"
#include "port_ultrasound.h"
#include "stm32f4_button.h"
#include "stm32f4_ultrasound.h"

Functions

void SysTick_Handler (void)
 Interrupt service routine for the System tick timer (SysTick). More...
 
void EXTI15_10_IRQHandler (void)
 This function handles Px10-Px15 global interrupts. More...
 
void TIM2_IRQHandler (void)
 Interrupt service routine for the TIM2 timer. More...
 
void TIM3_IRQHandler (void)
 Interrupt service routine for the TIM3 timer. More...
 
void TIM5_IRQHandler (void)
 Interrupt service routine for the TIM5 timer. More...
 

Detailed Description

Interrupt service routines for the STM32F4 platform.

Author
SDG2. Román Cárdenas (r.car.nosp@m.dena.nosp@m.s@upm.nosp@m..es) and Josué Pagán (j.pag.nosp@m.an@u.nosp@m.pm.es)
Date
2025-12-01

Function Documentation

◆ EXTI15_10_IRQHandler()

void EXTI15_10_IRQHandler ( void  )

This function handles Px10-Px15 global interrupts.

First, this function identifies the line/ pin which has raised the interruption. Then, perform the desired action. Before leaving it cleans the interrupt pending register.

TODO alumnos Version 1

✅ 1. Retrieve the values of the GPIO of the user button using the PORT_PARKING_BUTTON_ID index to get the port and pin from the buttons_arr using its getter function port_button_get_value().
✅ 2. If the value is true means that the button as been released, therefore set the field flag_pressed to false
✅ 3. If the value is false means that the button as been pressed, therefore set the field flag_pressed to true
✅ 4. Clean the corresponding bit of the PR register
    💡 Recommendation: use the macro BIT_POS_TO_MASK
    💡 To clean an interrupt in the Pending Register (PR) we must write '1' in the corresponding bit. Look at the example in section "Ejemplo de interrupción externa" of the reference book. You can also find this out by consulting the reference manual STM32F446xx Advanced ARM-based 32-bit MCUs (See section "10.3.6 Pending register (EXTI_PR)")

TODO alumnos Version 4

✅ 1. Call the function port_system_systick_resume() to resume the systick timer at the beginning of the ISR

◆ SysTick_Handler()

void SysTick_Handler ( void  )

Interrupt service routine for the System tick timer (SysTick).

Note
This ISR is called when the SysTick timer generates an interrupt. The program flow jumps to this ISR and increments the tick counter by one millisecond.

TO-DO alumnos

✅ 1. Increment the System tick counter msTicks in 1 count. To do so, use the function port_system_get_millis() and port_system_set_millis().

Warning
The variable msTicks must be declared volatile! Just because it is modified by a call of an ISR, in order to avoid race conditions . Added to the definition after static.

◆ TIM2_IRQHandler()

void TIM2_IRQHandler ( void  )

Interrupt service routine for the TIM2 timer.

This timer controls the duration of the echo signal of the ultrasound sensor by means of the input capture mode.

The timer can interrupt in two cases:

  1. When the echo signal has not been received and the ARR register overflows. In this case, the echo_overflows counter is incremented.
  2. When the echo signal has been received. In this case, the echo_init_tick and echo_end_tick are updated.
Note
Follow the example of the section Ejemplo: captura de entrada (input capture) of the Libro de Fundamentos to manage the ISR correctly.

TODO alumnos

✅ 1. Check if the UIF flag is set. If so, this means that the ARR register has overflowed. In this case:
nbsp;    Increment the echo_overflows counter. To do this, use the functions port_ultrasound_set_echo_overflows() and port_ultrasound_get_echo_overflows() with the corresponding ultrasound ID and the incremented value.
     Remember to clear the UIF flag.
✅ 2. Check if the CCxIF flag is set. If so, this means that the input capture event has occurred.      Read the value of the CCRx register to get the current tick. Reading CCRx also clears the CCxIF bit, and it is not necessary to do it later.
     If both the echo_init_tick and echo_end_tick are 0, this means that the echo signal has not started yet. In this case, update the echo_init_tick with the current tick.
     Otherwise, update the echo_end_tick with the current tick and set the echo_received flag to true.
    💡 Use the port functions port_ultrasound_get_echo_xxx and port_ultrasound_set_echo_xxx.

◆ TIM3_IRQHandler()

void TIM3_IRQHandler ( void  )

Interrupt service routine for the TIM3 timer.

This timer controls the duration of the trigger signal of the ultrasound sensor. When the interrupt occurs it means that the time of the trigger signal has expired and must be lowered.

TODO alumnos

✅ 1. Clear the interrupt flag UIF in the status register SR.
✅ 2. Call the function port_ultrasound_set_trigger_end() to set the flag that indicates that the time of the trigger signal has expired.

◆ TIM5_IRQHandler()

void TIM5_IRQHandler ( void  )

Interrupt service routine for the TIM5 timer.

This timer controls the duration of the measurements of the ultrasound sensor. When the interrupt occurs it means that the time of the a measurement has expired and a new measurement can be started.

TODO alumnos

✅ 1. Clear the interrupt flag UIF in the status register SR.
✅ 2. Call the function port_ultrasound_set_trigger_ready() to set the flag that indicates that a new measurement can be started.