synth/arm/timer.h

62 lines
1.3 KiB
C
Raw Permalink Normal View History

2022-05-17 03:56:25 +00:00
#pragma once
struct TimerControl {
union {
struct {
2022-05-17 17:17:56 +00:00
uint32_t MDT0 : 1;
uint32_t UDT0 : 1;
2022-05-17 03:56:25 +00:00
uint32_t GENT0 : 1;
uint32_t CAPT0 : 1;
uint32_t ARHT0 : 1;
uint32_t LOAD0 : 1;
uint32_t ENIT0 : 1;
2022-05-17 17:17:56 +00:00
uint32_t ENT0 : 1;
2022-05-17 03:56:25 +00:00
uint32_t T0INT : 1;
uint32_t PWMA0 : 1;
uint32_t ENALL : 1;
2022-05-17 17:17:56 +00:00
uint32_t CASC : 1;
2022-05-17 03:56:25 +00:00
uint32_t reserved : 20;
};
uint32_t raw;
};
};
struct Timer {
volatile TimerControl TCSR0;
volatile uint32_t TLR0;
volatile uint32_t TCR0;
uint32_t _reserved;
volatile TimerControl TCSR1;
volatile uint32_t TLR1;
volatile uint32_t TCR1;
void EnableT1() {
TCSR1.ARHT0 = 1;
TCSR1.ENT0 = 1;
}
2022-05-17 17:17:56 +00:00
uint32_t GetT1Ticks() { return TCR1; }
2022-05-17 03:56:25 +00:00
void SetupAsWdt(uint32_t timeout_ticks) {
TLR0 = timeout_ticks;
2022-05-17 17:17:56 +00:00
TCSR0.LOAD0 = 1; // reset counter
TCSR0.UDT0 = 1; // count backwards from the load value
TCSR0.ENIT0 = 1; // enable interrupt
2022-05-17 03:56:25 +00:00
2022-05-17 17:17:56 +00:00
TCSR0.LOAD0 = 0; // allow counter to run
TCSR0.ENT0 = 1; // enable timer
2022-05-17 03:56:25 +00:00
}
void Pet() {
TCSR0.ENT0 = 0;
TCSR0.LOAD0 = 1;
TCSR0.LOAD0 = 0;
TCSR0.ENT0 = 1;
}
};
2022-05-17 17:17:56 +00:00
#define timer0 ((Timer*)0x40002000)