|
Simone: a game of visual memory and speed
|
Portable functions to interact with the Simone FSM library. All portable functions must be implemented in this file. More...
#include <stdio.h>#include <stdbool.h>#include <stdint.h>#include <math.h>#include "port_simone.h"#include "port_system.h"#include "stm32f4_system.h"#include "stm32f4_simone.h"Functions | |
| static void | _timer_simone_setup () |
| Configure the timer that controls the duration of the note. 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... | |
| void | port_simone_init () |
| Initialize the Simone game port. More... | |
Variables | |
| stm32f4_simone_hw_t | simone_hw |
| Array of elements that represents the HW characteristics of the RGB LED of the RGB light systems connected to the STM32F4 platform. More... | |
Portable functions to interact with the Simone FSM library. All portable functions must be implemented in this file.
|
static |
Configure the timer that controls the duration of the note.
This function is called by the port_simone_init() public function to configure the timer that controls the duration of the different events of the game.
TODO alumnos:
✅ 1. Enable the clock source of the timer
💡 To know if the source clock isAPB1orAPB2, check the clock tree in the datasheet (Figure 3. STM32F446xC/E block diagram)
✅ 2. Disable the counter (registerCR1) and enable the autoreload preaload (bitARPE)
✅ 3. Clean the Update Interrupt flag (registerSR)
✅ 4. Enable the Update Interrupt (registerDIER)
✅ 5. Set the priority and the subpriority of the interrupt
✅ 6. Enable the interrupt in the NVIC
| buzzer_id |
| 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.
| stm32f4_simone_hw_t simone_hw |
Array of elements that represents the HW characteristics of the RGB LED of the RGB light systems connected to the STM32F4 platform.
Element that represents the HW characteristics of the Simone game connected to the STM32F4 platform to manage the timers.
stm32f4_rgb_light.h. It represents an array of RGB lights.