mirror of
https://github.com/Polprzewodnikowy/SummerCart64.git
synced 2024-11-30 01:04:13 +01:00
421d0438f3
This PR completely removes `task.c / task.h` from `sw/controller` STM32 code. Additionally, these changes were implemented: - Updated IPL3 - Added new diagnostic data (voltage and temperature) readout commands for USB and N64 - Fixed some issues with FlashRAM save type - Joybus timings were relaxed to accommodate communication with unsynchronized master controller (like _Datel Game Killer_, thanks @RWeick) - N64 embedded test program now waits for release of button press to proceed - Fixed issue where, in rare circumstances, I2C peripheral in STM32 would get locked-up on power-up - LED blinking behavior on SD card access was changed - LED blink duration on save writeback has been extended - Minor fixes through the entire of hardware abstraction layer for STM32 code - Primer now correctly detects issues with I2C bus during first time programming - `primer.py` script gives more meaningful error messages - Fixed bug where RTC time was always written on N64FlashcartMenu boot - sc64deployer now displays "Diagnostic data" instead of "MCU stack usage"
57 lines
1.2 KiB
C
57 lines
1.2 KiB
C
#include "hw.h"
|
|
#include "timer.h"
|
|
|
|
|
|
#define TIMER_PERIOD_MS (25)
|
|
|
|
|
|
typedef struct {
|
|
volatile bool pending;
|
|
volatile bool running;
|
|
volatile uint32_t value;
|
|
} timer_t;
|
|
|
|
static timer_t timer[__TIMER_ID_COUNT];
|
|
|
|
|
|
static void timer_update (void) {
|
|
for (timer_id_t id = 0; id < __TIMER_ID_COUNT; id++) {
|
|
if (timer[id].value > 0) {
|
|
timer[id].value -= 1;
|
|
}
|
|
if (timer[id].pending) {
|
|
timer[id].pending = false;
|
|
} else if (timer[id].value == 0) {
|
|
timer[id].running = false;
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
void timer_countdown_start (timer_id_t id, uint32_t value_ms) {
|
|
hw_enter_critical();
|
|
if (value_ms > 0) {
|
|
timer[id].pending = true;
|
|
timer[id].running = true;
|
|
timer[id].value = ((value_ms + (TIMER_PERIOD_MS - 1)) / TIMER_PERIOD_MS);
|
|
}
|
|
hw_exit_critical();
|
|
}
|
|
|
|
void timer_countdown_abort (timer_id_t id) {
|
|
hw_enter_critical();
|
|
timer[id].pending = false;
|
|
timer[id].running = false;
|
|
timer[id].value = 0;
|
|
hw_exit_critical();
|
|
}
|
|
|
|
bool timer_countdown_elapsed (timer_id_t id) {
|
|
return (!timer[id].running);
|
|
}
|
|
|
|
|
|
void timer_init (void) {
|
|
hw_systick_config(TIMER_PERIOD_MS, timer_update);
|
|
}
|