Skip to content

Commit

Permalink
Merge pull request #338 from wheremyfoodat/y2r
Browse files Browse the repository at this point in the history
Better KTimer implementation
  • Loading branch information
wheremyfoodat authored Nov 11, 2023
2 parents 7537759 + 1f7fc22 commit 11f42f8
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
1 change: 1 addition & 0 deletions include/kernel/kernel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class Kernel {
std::vector<KernelObject> objects;
std::vector<Handle> portHandles;
std::vector<Handle> mutexHandles;
std::vector<Handle> timerHandles;

// Thread indices, sorted by priority
std::vector<int> threadIndices;
Expand Down
1 change: 1 addition & 0 deletions src/core/kernel/kernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ void Kernel::reset() {
}
objects.clear();
mutexHandles.clear();
timerHandles.clear();
portHandles.clear();
threadIndices.clear();
serviceManager.reset();
Expand Down
10 changes: 7 additions & 3 deletions src/core/kernel/timers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Handle Kernel::makeTimer(ResetType type) {
Helpers::panic("Created pulse timer");
}

// timerHandles.push_back(ret);
timerHandles.push_back(ret);
return ret;
}

Expand Down Expand Up @@ -51,6 +51,10 @@ void Kernel::signalTimer(Handle timerHandle, Timer* timer) {
case ResetType::Pulse: Helpers::panic("Signalled pulsing timer"); break;
}
}

if (timer->interval == 0) {
cancelTimer(timer);
}
}

void Kernel::svcCreateTimer() {
Expand All @@ -70,8 +74,8 @@ void Kernel::svcCreateTimer() {
void Kernel::svcSetTimer() {
Handle handle = regs[0];
// TODO: Is this actually s64 or u64? 3DBrew says s64, but u64 makes more sense
const s64 initial = s64(u64(regs[1]) | (u64(regs[2]) << 32));
const s64 interval = s64(u64(regs[3]) | (u64(regs[4]) << 32));
const s64 initial = s64(u64(regs[2]) | (u64(regs[3]) << 32));
const s64 interval = s64(u64(regs[1]) | (u64(regs[4]) << 32));
logSVC("SetTimer (handle = %X, initial delay = %llX, interval delay = %llX)\n", handle, initial, interval);

KernelObject* object = getObject(handle, KernelObjectType::Timer);
Expand Down

0 comments on commit 11f42f8

Please sign in to comment.