Merge branch 'test2' of gitlab.ibr.cs.tu-bs.de:vss/teaching/ss25/v_bsb1/Gruppe_018 into test2
This commit is contained in:
@@ -129,21 +129,23 @@ void set(uint32_t counter, uint8_t divide, uint8_t vector, bool periodic,
|
||||
LAPIC::write(TIMER_DIVIDE_CONFIGURATION, getClockDiv(divide));
|
||||
LAPIC::write(TIMER_INITIAL_COUNTER, counter);
|
||||
}
|
||||
|
||||
bool setup(uint32_t us) {
|
||||
uint64_t timer_ticks = (static_cast<uint64_t>(ticks()) * us) / 1000ULL;
|
||||
uint64_t time_tick;
|
||||
|
||||
uint8_t divisor = 1;
|
||||
while (timer_ticks > UINT32_MAX) {
|
||||
uint8_t dividender;
|
||||
|
||||
bool setup(uint32_t us) {
|
||||
time_tick = (static_cast<uint64_t>(ticks()) * us) / 1000ULL;
|
||||
|
||||
dividender = 1;
|
||||
while (time_tick > UINT32_MAX) {
|
||||
// While timer_ticks is to large to fit in 32bits.
|
||||
timer_ticks >>= 1;
|
||||
divisor <<= 1;
|
||||
time_tick >>= 1;
|
||||
dividender <<= 1;
|
||||
}
|
||||
if (divisor > 128)
|
||||
if (dividender > 128)
|
||||
return false; // Timer interval is to large.
|
||||
|
||||
// Setup Masked interrupts to effectively disable the timer.
|
||||
set(static_cast<uint32_t>(timer_ticks), divisor, Core::Interrupt::TIMER, true, true);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -156,15 +158,15 @@ uint32_t interval() {
|
||||
}
|
||||
|
||||
void activate() {
|
||||
uint32_t timer_ticks = LAPIC::read(TIMER_INITIAL_COUNTER);
|
||||
// Disable Counter to avoid spouriose interrupts.
|
||||
LAPIC::write(TIMER_INITIAL_COUNTER, 0);
|
||||
set(static_cast<uint32_t>(time_tick), dividender, Core::Interrupt::TIMER, true, true);
|
||||
|
||||
// Activate Timer interrupts.
|
||||
setMasked(false);
|
||||
|
||||
// enable counter with correct value.
|
||||
LAPIC::write(TIMER_INITIAL_COUNTER, timer_ticks);
|
||||
LAPIC::write(TIMER_INITIAL_COUNTER, time_tick);
|
||||
}
|
||||
|
||||
void setMasked(bool masked) {
|
||||
|
||||
Reference in New Issue
Block a user