Urbanite: Parking aid system
|
Header for fsm_ultrasound.c file. More...
#include <stdint.h>
#include <stdbool.h>
#include "fsm.h"
Macros | |
#define | FSM_ULTRASOUND_NUM_MEASUREMENTS 5 |
Typedefs | |
typedef struct fsm_ultrasound_t | fsm_ultrasound_t |
Structure to define the ultrasound FSM. | |
Enumerations | |
enum | FSM_ULTRASOUND { WAIT_START = 0, TRIGGER_START, WAIT_ECHO_START, WAIT_ECHO_END, SET_DISTANCE } |
Enumerator for the ultrasound finite state machine. More... | |
Functions | |
fsm_ultrasound_t * | fsm_ultrasound_new (uint32_t ultrasound_id) |
Create a new ultrasound FSM. More... | |
void | fsm_ultrasound_destroy (fsm_ultrasound_t *p_fsm) |
Destroy an ultrasound FSM. More... | |
uint32_t | fsm_ultrasound_get_distance (fsm_ultrasound_t *p_fsm) |
Return the distance of the last object detected by the ultrasound sensor.a64l. More... | |
void | fsm_ultrasound_fire (fsm_ultrasound_t *p_fsm) |
Fire the ultrasound FSM. More... | |
bool | fsm_ultrasound_get_status (fsm_ultrasound_t *p_fsm) |
Get the status of the ultrasound transceiver FSM. More... | |
void | fsm_ultrasound_set_status (fsm_ultrasound_t *p_fsm, bool status) |
Set the status of the ultrasound sensor. true means that the ultrasound sensor is active and a distance measurement must be performed. false means that the ultrasound sensor is inactive. More... | |
bool | fsm_ultrasound_get_ready (fsm_ultrasound_t *p_fsm) |
Get the ready flag of the trigger signal in the ultrasound HW. More... | |
bool | fsm_ultrasound_get_new_measurement_ready (fsm_ultrasound_t *p_fsm) |
Return the flag that indicates if a new measurement is ready. More... | |
void | fsm_ultrasound_stop (fsm_ultrasound_t *p_fsm) |
Stop the ultrasound sensor. More... | |
void | fsm_ultrasound_start (fsm_ultrasound_t *p_fsm) |
Start the ultrasound sensor. More... | |
fsm_t * | fsm_ultrasound_get_inner_fsm (fsm_ultrasound_t *p_fsm) |
Get the inner FSM of the ultrasound. More... | |
uint32_t | fsm_ultrasound_get_state (fsm_ultrasound_t *p_fsm) |
Get the state of the ultrasound FSM. More... | |
void | fsm_ultrasound_set_state (fsm_ultrasound_t *p_fsm, int8_t state) |
Set the state of the ultrasound FSM. More... | |
bool | fsm_ultrasound_check_activity (fsm_ultrasound_t *p_fsm) |
Check if the ultrasound sensor is doing a distance measurement. More... | |
Header for fsm_ultrasound.c file.
#define FSM_ULTRASOUND_NUM_MEASUREMENTS 5 |
Number of measurements to store in the array
enum FSM_ULTRASOUND |
Enumerator for the ultrasound finite state machine.
This enumerator defines the different states that the ultrasound finite state machine can be in. Each state represents a specific condition or step in the ultrasound distance measurement process.
bool fsm_ultrasound_check_activity | ( | fsm_ultrasound_t * | p_fsm | ) |
Check if the ultrasound sensor is doing a distance measurement.
The ultrasound sensor is always inactive because all the transitions are due to HW interrupts.
TODO alumnos Version 4:
✅ 1. Return
false
always.
p_fsm | Pointer to an fsm_ultrasound_t struct. |
void fsm_ultrasound_destroy | ( | fsm_ultrasound_t * | p_fsm | ) |
Destroy an ultrasound FSM.
This function destroys an ultrasound transceiver FSM and frees the memory.
TODO alumnos:
✅ 1. Implement this function analogously to the
fsm_button_destroy()
function.
p_fsm | Pointer to an fsm_ultrasound_t struct. |
void fsm_ultrasound_fire | ( | fsm_ultrasound_t * | p_fsm | ) |
Fire the ultrasound FSM.
This function is used to fire the ultrasound FSM. It is used to check the transitions and execute the actions of the ultrasound FSM.
TODO alumnos:
✅ 1. Call function
fsm_fire()
with the received pointer tofsm_t
p_fsm | Pointer to an fsm_ultrasound_t struct. |
uint32_t fsm_ultrasound_get_distance | ( | fsm_ultrasound_t * | p_fsm | ) |
Return the distance of the last object detected by the ultrasound sensor.a64l.
The function also resets the field new_measurement
to indicate that the distance has been read.
TODO alumnos:
✅ 1. Retrieve and return the field
distance_cm
.
✅ 2. Reset the fieldnew_measurement
.
p_fsm | Pointer to an fsm_ultrasound_t struct. |
fsm_t* fsm_ultrasound_get_inner_fsm | ( | fsm_ultrasound_t * | p_fsm | ) |
Get the inner FSM of the ultrasound.
This function returns the inner FSM of the ultrasound.
💡 This function is important because the struct is private and external functions such as those of the unit tests cannot access the inner FSM directly.
TODO alumnos:
✅ 1. Return the address of the
f
field of the struct.
p_fsm | Pointer to an fsm_ultrasound_t struct. |
bool fsm_ultrasound_get_new_measurement_ready | ( | fsm_ultrasound_t * | p_fsm | ) |
Return the flag that indicates if a new measurement is ready.
TODO alumnos:
✅ 1. Retrieve and return the field
new_measurement
.
p_fsm | Pointer to the ultrasound FSM. |
bool fsm_ultrasound_get_ready | ( | fsm_ultrasound_t * | p_fsm | ) |
Get the ready flag of the trigger signal in the ultrasound HW.
This function returns the ready flag of trigger signal in the ultrasound HW. This function might be used for testing and debugging purposes.
TODO alumnos:
✅ 1. Call function
port_ultrasound_get_trigger_ready()
with the ultrasound ID and return the result.
p_fsm | Pointer to an fsm_ultrasound_t struct. |
port
indicates that the trigger signal is ready to start a new measurement. port
indicates that the trigger signal is not ready to start a new measurement. uint32_t fsm_ultrasound_get_state | ( | fsm_ultrasound_t * | p_fsm | ) |
Get the state of the ultrasound FSM.
This function returns the current state of the ultrasound FSM.
💡 This function is important because the struct is private and external functions such as those of the unit tests cannot access the state of the FSM directly.
TODO alumnos:
✅ 1. Retrieve and return the field
current_state
of the FSM (fieldf
of the struct).
p_fsm | Pointer to an fsm_ultrasound_t struct. |
bool fsm_ultrasound_get_status | ( | fsm_ultrasound_t * | p_fsm | ) |
Get the status of the ultrasound transceiver FSM.
This function returns the status of the ultrasound. This function might be used for testing and debugging purposes.
TODO alumnos:
✅ 1. Retrieve and return the field
status
.
p_fsm | Pointer to an fsm_ultrasound_t struct. |
fsm_ultrasound_t* fsm_ultrasound_new | ( | uint32_t | ultrasound_id | ) |
Create a new ultrasound FSM.
This function creates a new ultrasound transceiver FSM with the given ultrasound ID.
ultrasound_id | Ultrasound ID. Must be unique. |
void fsm_ultrasound_set_state | ( | fsm_ultrasound_t * | p_fsm, |
int8_t | state | ||
) |
Set the state of the ultrasound FSM.
This function sets the current state of the ultrasound FSM.
💡 This function is important because the struct is private and external functions such as those of the unit tests cannot access the state of the FSM directly.
p_fsm | Pointer to an fsm_ultrasound_t struct. |
state | New state of the ultrasound FSM. |
void fsm_ultrasound_set_status | ( | fsm_ultrasound_t * | p_fsm, |
bool | status | ||
) |
Set the status of the ultrasound sensor. true
means that the ultrasound sensor is active and a distance measurement must be performed. false
means that the ultrasound sensor is inactive.
TODO alumnos:
✅ 1. Update the field
status
with the received value
p_fsm | Pointer to an fsm_ultrasound_t struct. |
status | Status of the ultrasound sensor. |
void fsm_ultrasound_start | ( | fsm_ultrasound_t * | p_fsm | ) |
Start the ultrasound sensor.
This function starts the ultrasound sensor by indicating to the port
to start the ultrasound sensor (to reset all timer ticks) and to set the status of the ultrasound sensor to active.
TODO alumnos:
✅ 1. Set the field
status
.
✅ 2. Reset the fielddistance_idx
.
✅ 3. Reset the fielddistance_cm
.
✅ 4. Call functionport_ultrasound_reset_echo_ticks()
with the right parameters.
✅ 5. Call functionport_ultrasound_set_trigger_ready()
with the right parameters to indicate that the ultrasound sensor is ready to start a new measurement.
✅ 6. Call functionport_ultrasound_start_new_measurement_timer()
to force the new measurement timer to start to provoke the first interrupt.
p_fsm | Pointer to an fsm_ultrasound_t struct. |
void fsm_ultrasound_stop | ( | fsm_ultrasound_t * | p_fsm | ) |
Stop the ultrasound sensor.
This function stops the ultrasound sensor by indicating to the port
to stop the ultrasound sensor (to reset all timer ticks) and to set the status of the ultrasound sensor to inactive.
TODO alumnos:
✅ 1. Reset the field
status
.
✅ 2. Call functionport_ultrasound_stop_ultrasound()
with the right parameters.
p_fsm | Pointer to an fsm_ultrasound_t struct. |