Simone: a game of visual memory and speed
port_simone.h File Reference

Header for the portable functions os the Simone board game. More...

#include <stdint.h>
#include <stdbool.h>

Functions

void port_simone_init (void)
 Initialize the Simone game port. More...
 
void port_simone_set_timer_timeout (uint32_t duration_ms)
 Configure the timer timeout for the Simone game. More...
 
void port_simone_stop_timer (void)
 Stop the timer of the Simone game. More...
 
bool port_simone_get_timeout_status (void)
 Get the timer timeout status of the Simone game. More...
 
void port_simone_set_timeout_status (bool status)
 Set the status of the timer timeout status of the Simone game. More...
 

Detailed Description

Header for the portable functions os the Simone board game.

Author
Sistemas Digitales II
Date
2026-01-01

Function Documentation

◆ port_simone_get_timeout_status()

bool port_simone_get_timeout_status ( void  )

Get the timer timeout status of the Simone game.

Returns
true
false

◆ port_simone_init()

void port_simone_init ( void  )

Initialize the Simone game port.

This function initializes the HW associated to the Simone game, such as the timer that controls the duration of the different events of the game. It is called from the fsm_simone_init() function to initialize the HW dependencies of the Simone FSM.

TODO alumnos:

✅ 1. Reset the flag of the simone_hw struct.
✅ 2. Configure the timer that controls the duration of the different events of the game by calling the _timer_simone_setup() function.

◆ port_simone_set_timeout_status()

void port_simone_set_timeout_status ( bool  status)

Set the status of the timer timeout status of the Simone game.

Parameters
status

◆ port_simone_set_timer_timeout()

void port_simone_set_timer_timeout ( uint32_t  duration_ms)

Configure the timer timeout for the Simone game.

This function is called to configure the timer that controls the duration of the different events of the game. The duration of the timeout is received as a parameter in milliseconds. When the timer expires, an interrupt is generated and the flag of the simone_hw struct is set to indicate that the time has expired.

TODO alumnos: ✅ 1. Disable the timer by clearing the CEN bit in the CR1 register.
✅ 2. Reset the counter by writing 0 to the CNT register.
✅ 3. Compute the values of the prescaler (PSC) and the auto-reload register (ARR) to match the duration in milliseconds. Use any of the two options explained in the stm32f4_keyboard.c file to compute the values of the prescaler and the auto-reload register.
✅ 4. Load the values of the prescaler and the auto-reload register in the corresponding registers.
✅ 5. The values of the prescaler and the auto-reload register are currently in the preload registers. To load them into the active registers we need an update event. We can do this manually by setting the UG bit in the EGR register.
✅ 6. Clear the pending interrupt flag generated when doing the update event by clearing the UIF bit in the SR register.
✅ 7. Now enable the update interrupt by setting the UIE bit in the DIER register.
✅ 8. Reset the flag of the simone_hw struct to indicate that the time has not expired yet. Important! This must be done after enabling the interrupt to avoid a race condition.
✅ 9. Enable the timer by setting the CEN bit in the CR1 register.

Parameters
duration_ms

◆ port_simone_stop_timer()

void port_simone_stop_timer ( void  )

Stop the timer of the Simone game.

This function is called to stop the timer of the Simone game when the game is over or when the player has won.