|
Simone: a game of visual memory and speed
|
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... | |
Header for the portable functions os the Simone board game.
| bool port_simone_get_timeout_status | ( | void | ) |
Get the timer timeout status of the Simone game.
| 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_hwstruct.
✅ 2. Configure the timer that controls the duration of the different events of the game by calling the_timer_simone_setup()function.
| void port_simone_set_timeout_status | ( | bool | status | ) |
Set the status of the timer timeout status of the Simone game.
| status |
| 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
CENbit in theCR1register.
✅ 2. Reset the counter by writing 0 to theCNTregister.
✅ 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 thestm32f4_keyboard.cfile 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 theUGbit in theEGRregister.
✅ 6. Clear the pending interrupt flag generated when doing the update event by clearing theUIFbit in theSRregister.
✅ 7. Now enable the update interrupt by setting theUIEbit in theDIERregister.
✅ 8. Reset the flag of thesimone_hwstruct 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 theCENbit in theCR1register.
| duration_ms |
| 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.