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_DIVIDE_CONFIGURATION, getClockDiv(divide));
|
||||||
LAPIC::write(TIMER_INITIAL_COUNTER, counter);
|
LAPIC::write(TIMER_INITIAL_COUNTER, counter);
|
||||||
}
|
}
|
||||||
|
uint64_t time_tick;
|
||||||
bool setup(uint32_t us) {
|
|
||||||
uint64_t timer_ticks = (static_cast<uint64_t>(ticks()) * us) / 1000ULL;
|
|
||||||
|
|
||||||
uint8_t divisor = 1;
|
uint8_t dividender;
|
||||||
while (timer_ticks > UINT32_MAX) {
|
|
||||||
|
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.
|
// While timer_ticks is to large to fit in 32bits.
|
||||||
timer_ticks >>= 1;
|
time_tick >>= 1;
|
||||||
divisor <<= 1;
|
dividender <<= 1;
|
||||||
}
|
}
|
||||||
if (divisor > 128)
|
if (dividender > 128)
|
||||||
return false; // Timer interval is to large.
|
return false; // Timer interval is to large.
|
||||||
|
|
||||||
// Setup Masked interrupts to effectively disable the timer.
|
// Setup Masked interrupts to effectively disable the timer.
|
||||||
set(static_cast<uint32_t>(timer_ticks), divisor, Core::Interrupt::TIMER, true, true);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -156,15 +158,15 @@ uint32_t interval() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void activate() {
|
void activate() {
|
||||||
uint32_t timer_ticks = LAPIC::read(TIMER_INITIAL_COUNTER);
|
|
||||||
// Disable Counter to avoid spouriose interrupts.
|
// Disable Counter to avoid spouriose interrupts.
|
||||||
LAPIC::write(TIMER_INITIAL_COUNTER, 0);
|
LAPIC::write(TIMER_INITIAL_COUNTER, 0);
|
||||||
|
set(static_cast<uint32_t>(time_tick), dividender, Core::Interrupt::TIMER, true, true);
|
||||||
|
|
||||||
// Activate Timer interrupts.
|
// Activate Timer interrupts.
|
||||||
setMasked(false);
|
setMasked(false);
|
||||||
|
|
||||||
// enable counter with correct value.
|
// enable counter with correct value.
|
||||||
LAPIC::write(TIMER_INITIAL_COUNTER, timer_ticks);
|
LAPIC::write(TIMER_INITIAL_COUNTER, time_tick);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setMasked(bool masked) {
|
void setMasked(bool masked) {
|
||||||
|
|||||||
1
main.cc
1
main.cc
@@ -150,7 +150,6 @@ extern "C" int main_ap() {
|
|||||||
<< static_cast<int>(LAPIC::getID()) << " in main_ap()" << endl;
|
<< static_cast<int>(LAPIC::getID()) << " in main_ap()" << endl;
|
||||||
|
|
||||||
|
|
||||||
LAPIC::Timer::setup(1000000);
|
|
||||||
Core::Interrupt::enable();
|
Core::Interrupt::enable();
|
||||||
LAPIC::Timer::activate();
|
LAPIC::Timer::activate();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user