Urbanite: Parking aid system
|
Header for the portable functions to interact with the HW of the ultrasound sensors. The functions must be implemented in the platform-specific code. More...
#include <stdint.h>
#include <stdbool.h>
Macros | |
#define | PORT_REAR_PARKING_SENSOR_ID 0 |
#define | PORT_PARKING_SENSOR_TRIGGER_UP_US 10 |
#define | PORT_PARKING_SENSOR_TIMEOUT_MS |
#define | SPEED_OF_SOUND_MS 343 |
Functions | |
void | port_ultrasound_init (uint32_t ultrasound_id) |
Configure the HW specifications of a given ultrasound sensor. More... | |
void | port_ultrasound_start_measurement (uint32_t ultrasound_id) |
Start a new measurement of the ultrasound sensor. More... | |
void | port_ultrasound_stop_trigger_timer (uint32_t ultrasound_id) |
Stop the timer that controls the trigger signal. More... | |
void | port_ultrasound_stop_echo_timer (uint32_t ultrasound_id) |
Stop the timer that controls the echo signal. More... | |
void | port_ultrasound_start_new_measurement_timer (void) |
Start the timer that controls the new measurement. More... | |
void | port_ultrasound_stop_new_measurement_timer (void) |
Stop the timer that controls the new measurement. More... | |
void | port_ultrasound_reset_echo_ticks (uint32_t ultrasound_id) |
Reset the time ticks of the echo signal. More... | |
void | port_ultrasound_stop_ultrasound (uint32_t ultrasound_id) |
Stop all the timers of the ultrasound sensor and reset the echo ticks. More... | |
bool | port_ultrasound_get_trigger_ready (uint32_t ultrasound_id) |
Get the readiness of the trigger signal. More... | |
void | port_ultrasound_set_trigger_ready (uint32_t ultrasound_id, bool trigger_ready) |
Set the readiness of the trigger signal. More... | |
bool | port_ultrasound_get_trigger_end (uint32_t ultrasound_id) |
Get the status of the trigger signal. More... | |
void | port_ultrasound_set_trigger_end (uint32_t ultrasound_id, bool trigger_end) |
Set the status of the trigger signal. More... | |
uint32_t | port_ultrasound_get_echo_init_tick (uint32_t ultrasound_id) |
Get the time tick when the init of echo signal was received. More... | |
void | port_ultrasound_set_echo_init_tick (uint32_t ultrasound_id, uint32_t echo_init_tick) |
Set the time tick when the init of echo signal was received. More... | |
uint32_t | port_ultrasound_get_echo_end_tick (uint32_t ultrasound_id) |
Get the time tick when the end of echo signal was received. More... | |
void | port_ultrasound_set_echo_end_tick (uint32_t ultrasound_id, uint32_t echo_end_tick) |
Set the time tick when the end of echo signal was received. More... | |
bool | port_ultrasound_get_echo_received (uint32_t ultrasound_id) |
Get the status of the echo signal. More... | |
void | port_ultrasound_set_echo_received (uint32_t ultrasound_id, bool echo_received) |
Set the status of the echo signal. More... | |
uint32_t | port_ultrasound_get_echo_overflows (uint32_t ultrasound_id) |
Get the number of overflows of the echo signal timer. More... | |
void | port_ultrasound_set_echo_overflows (uint32_t ultrasound_id, uint32_t echo_overflows) |
Set the number of overflows of the echo signal timer. More... | |
Header for the portable functions to interact with the HW of the ultrasound sensors. The functions must be implemented in the platform-specific code.
#define PORT_PARKING_SENSOR_TIMEOUT_MS |
Time in ms to wait for the next measurement
#define PORT_PARKING_SENSOR_TRIGGER_UP_US 10 |
Duration in microseconds of the trigger signal
#define PORT_REAR_PARKING_SENSOR_ID 0 |
Rear parking sensor identifier
#define SPEED_OF_SOUND_MS 343 |
Speed of sound in air in m/s
uint32_t port_ultrasound_get_echo_end_tick | ( | uint32_t | ultrasound_id | ) |
Get the time tick when the end of echo signal was received.
TODO alumnos:
✅ 1. Return the value of the field
echo_end_tick
.
ultrasound_id | Ultrasound ID. This index is used to select the element of the ultrasound_arr[] array |
uint32_t port_ultrasound_get_echo_init_tick | ( | uint32_t | ultrasound_id | ) |
Get the time tick when the init of echo signal was received.
TODO alumnos:
✅ 1. Return the value of the field
echo_init_tick
.
ultrasound_id | Ultrasound ID. This index is used to select the element of the ultrasound_arr[] array |
uint32_t port_ultrasound_get_echo_overflows | ( | uint32_t | ultrasound_id | ) |
Get the number of overflows of the echo signal timer.
This function returns the number of overflows of the echo signal timer. It is used to calculate the real time elapsed in the echo signal.
TODO alumnos:
✅ 1. Return the value of the field
echo_overflows
.
ultrasound_id | Ultrasound ID. This index is used to select the element of the ultrasound_arr[] array |
bool port_ultrasound_get_echo_received | ( | uint32_t | ultrasound_id | ) |
Get the status of the echo signal.
This function returns the status of the echo signal. It will be true
if the echo signal has been received (both the init and end ticks).
TODO alumnos:
✅ 1. Return the value of the field
echo_received
.
ultrasound_id | Ultrasound ID. This index is used to select the element of the ultrasound_arr[] array |
bool port_ultrasound_get_trigger_end | ( | uint32_t | ultrasound_id | ) |
Get the status of the trigger signal.
This function returns the status of the trigger signal. It will be true
if the time to trigger the ultrasound sensor has finished.
TODO alumnos:
✅ 1. Return the value of the field
trigger_end
.
ultrasound_id | Ultrasound ID. This index is used to select the element of the ultrasound_arr[] array |
bool port_ultrasound_get_trigger_ready | ( | uint32_t | ultrasound_id | ) |
Get the readiness of the trigger signal.
This function returns the status of readiness the trigger signal. If it is true, the ultrasound sensor is ready to start a new measurement.
TODO alumnos:
✅ 1. Return the value of the field
trigger_ready
.
ultrasound_id | Ultrasound ID. This index is used to select the element of the ultrasound_arr[] array |
void port_ultrasound_init | ( | uint32_t | ultrasound_id | ) |
Configure the HW specifications of a given ultrasound sensor.
Assuming we are using an STM32F4-based platform, this function must call the following functions:
TODO alumnos:
✅ 1. Initialize the fields of the ultrasound struct. Set the variables related to ticks to 0 and the flags to false but the trigger_ready to true.
✅ 2. Configure the trigger pin as output and no pull up neither pull down connection.
✅ 3. Configure the echo pin as alternate function and no pull up neither pull down connection.
✅ 4. Configure the alternate function of the echo pin.
✅ 5. Call the 3 private functions that configure the timers of the trigger, echo and new measurement.
ultrasound_id | Ultrasound ID. This index is used to select the element of the ultrasound_arr[] array |
void port_ultrasound_reset_echo_ticks | ( | uint32_t | ultrasound_id | ) |
Reset the time ticks of the echo signal.
This function resets the time ticks of the echo signal once the distance has been calculated.
TODO alumnos:
✅ 1. Reset the time ticks of the echo signal, and the overflows. Also, reset the flag
echo_received
.
ultrasound_id | Ultrasound ID. This index is used to select the element of the ultrasound_arr[] array |
void port_ultrasound_set_echo_end_tick | ( | uint32_t | ultrasound_id, |
uint32_t | echo_end_tick | ||
) |
Set the time tick when the end of echo signal was received.
This function sets the time tick when the end of echo signal was received. It is called by the ISR of the input capture of the echo signal.
TODO alumnos:
✅ 1. Set the value of the field
echo_end_tick
with the received value.
ultrasound_id | Ultrasound ID. This index is used to select the element of the ultrasound_arr[] array |
echo_end_tick | Time tick when the end of echo signal was received. |
void port_ultrasound_set_echo_init_tick | ( | uint32_t | ultrasound_id, |
uint32_t | echo_init_tick | ||
) |
Set the time tick when the init of echo signal was received.
This function sets the time tick when the init of echo signal was received. It is called by the ISR of the input capture of the echo signal.
TODO alumnos:
✅ 1. Set the value of the field
echo_init_tick
with the received value.
ultrasound_id | Ultrasound ID. This index is used to select the element of the ultrasound_arr[] array |
echo_init_tick | Time tick when the init of echo signal was received. |
void port_ultrasound_set_echo_overflows | ( | uint32_t | ultrasound_id, |
uint32_t | echo_overflows | ||
) |
Set the number of overflows of the echo signal timer.
This function sets the number of overflows of the echo signal timer. It is called by the ISR of the input capture of the echo signal when an overflow occurs to increment the number of overflows.
TODO alumnos:
✅ 1. Set the value of the field
echo_overflows
with the received value.
ultrasound_id | Ultrasound ID. This index is used to select the element of the ultrasound_arr[] array |
echo_overflows | Number of overflows of the echo signal timer. |
void port_ultrasound_set_echo_received | ( | uint32_t | ultrasound_id, |
bool | echo_received | ||
) |
Set the status of the echo signal.
This function sets the status of the echo signal. The ISR of the input capture of the echo signal calls this function to set the status of the echo signal when both the init and end ticks have been received.
TODO alumnos:
✅ 1. Set the value of the field
echo_received
with the received value.
ultrasound_id | Ultrasound ID. This index is used to select the element of the ultrasound_arr[] array |
echo_received | Status of the echo signal. |
void port_ultrasound_set_trigger_end | ( | uint32_t | ultrasound_id, |
bool | trigger_end | ||
) |
Set the status of the trigger signal.
This function sets the status of the trigger signal. It will be true
to indicate that the time to trigger the ultrasound sensor has finished and the trigger signal is low.
TODO alumnos:
✅ 1. Set the value of the field
trigger_end
with the received value.
ultrasound_id | Ultrasound ID. This index is used to select the element of the ultrasound_arr[] array |
trigger_end | Status of the trigger signal. |
void port_ultrasound_set_trigger_ready | ( | uint32_t | ultrasound_id, |
bool | trigger_ready | ||
) |
Set the readiness of the trigger signal.
This function sets the status of readiness of the trigger signal. If it is true, the ultrasound sensor will ready to start a new measurement.
TODO alumnos:
✅ 1. Set the value of the field
trigger_ready
with the received value.
ultrasound_id | Ultrasound ID. This index is used to select the element of the ultrasound_arr[] array |
trigger_ready | Status of the trigger signal. |
void port_ultrasound_start_measurement | ( | uint32_t | ultrasound_id | ) |
Start a new measurement of the ultrasound sensor.
This function prepares the timer of the trigger and the timer of the echo signal to start a new measurement. It also enables the timer that controls the new measurement.
TODO alumnos:
✅ 1. Reset the flag
trigger_ready
to indicate that a new measurement has started.
✅ 2. Reset the counters (CNT
) of the trigger timer, the echo timer, and the new measurement timer. Enclose the configuration of the trigger and echo timers within a conditional statement.
✅ 3. Set the trigger pin to high. You can use theBSRR
or call thestm32f4_system_gpio_write()
function.
✅ 4. Enable the timers interrupts in the NVIC using theNVIC_EnableIRQ()
function and theTIMx_IRQn
interrupts.
✅ 5. Enable the timers of the new measurement, the trigger timer, and the echo timer (registerCR1
of the timers). Enclose the configuration of the trigger and echo timer within a conditional statement.
ultrasound_id | Ultrasound ID. This index is used to select the element of the ultrasound_arr[] array |
void port_ultrasound_start_new_measurement_timer | ( | void | ) |
Start the timer that controls the new measurement.
This function starts the timer that controls the new measurement.
TODO alumnos:
✅ 1. Enable the interrupt of the new measurement timer in the NVIC.
✅ 2. Enable the new measurement timer (registerCR1
of the timer).
void port_ultrasound_stop_echo_timer | ( | uint32_t | ultrasound_id | ) |
Stop the timer that controls the echo signal.
This function stops the timer that controls the echo signal because the echo signal has been received.
TODO alumnos:
✅ 1. Disable the echo timer (register
CR1
of the timer). Enclose the configuration of the echo timer within a conditional statement.
ultrasound_id | Ultrasound ID. This index is used to select the element of the ultrasound_arr[] array |
void port_ultrasound_stop_new_measurement_timer | ( | void | ) |
Stop the timer that controls the new measurement.
This function stops the timer that controls the new measurement.
TODO alumnos:
✅ 1. Disable the new measurement timer (register
CR1
of the timer).
void port_ultrasound_stop_trigger_timer | ( | uint32_t | ultrasound_id | ) |
Stop the timer that controls the trigger signal.
This function stops the timer that controls the trigger signal because the time to trigger the ultrasound sensor has finished. It also sets the trigger signal to low.
TODO alumnos:
✅ 1. Set the trigger pin to low. You can use the
BSRR
or call thestm32f4_system_gpio_write()
function.
✅ 2. Disable the trigger timer (registerCR1
of the timer).
ultrasound_id | Ultrasound ID. This index is used to select the element of the ultrasound_arr[] array |
void port_ultrasound_stop_ultrasound | ( | uint32_t | ultrasound_id | ) |
Stop all the timers of the ultrasound sensor and reset the echo ticks.
This function calls the functions to stop the trigger and echo timers and to reset the echo ticks.
TODO alumnos:
✅ 1. Call all the 4 functions to stop the trigger timer, the echo timer, the new measurement timer, and to reset the echo ticks.