1

implement + enable demos

This commit is contained in:
2022-07-04 21:24:35 +02:00
parent 7ab5fdb361
commit 1ae227ae33
7 changed files with 110 additions and 4 deletions

View File

@ -16,6 +16,8 @@
#include "user/CoopThreadDemo.h"
#include "user/HelloWorldThread.h"
#include "user/VBEdemo.h"
#include "user/PCSPKdemo.h"
#include "user/PreemptiveThreadDemo.h"
int main() {
kout.clear();
@ -28,7 +30,7 @@ int main() {
// Startmeldung
if constexpr (!DEBUG) {
kout << "HHUos 0.8\n"
kout << "HHUos 0.9\n"
<< "=========\n"
<< "Unterstuetzte Funktionen:\n"
<< " - Bildschirmausgaben\n"
@ -38,7 +40,8 @@ int main() {
<< " - Tastatureingaben per Interrupt\n"
<< " - Kooperative Threads\n"
<< " - VESA Graphics Mode\n"
<< " - Paging\n"
<< " - Einfaches Paging\n"
<< " - Preemptive Threads\n"
<< endl;
}
@ -74,8 +77,8 @@ int main() {
// scheduler.ready(new HelloWorldThread());
// scheduler.ready(new CoopThreadDemo());
// scheduler.ready(new VBEdemo()); // Switch to VESA graphics mode
// pcspk.tetris();
scheduler.ready(new PCSPKdemo());
scheduler.ready(new PreemptiveThreadDemo());
// Scheduler starten (schedule() erzeugt den Idle-Thread)
scheduler.schedule();

6
c_os/user/PCSPKdemo.cc Normal file
View File

@ -0,0 +1,6 @@
#include "user/PCSPKdemo.h"
void PCSPKdemo::run() {
pcspk.tetris();
scheduler.exit();
}

19
c_os/user/PCSPKdemo.h Normal file
View File

@ -0,0 +1,19 @@
#ifndef __PCSPKdemo_INCLUDE_H_
#define __PCSPKdemo_INCLUDE_H_
#include "kernel/Globals.h"
#include "kernel/threads/Thread.h"
class PCSPKdemo : public Thread {
private:
PCSPKdemo(const PCSPKdemo& copy) = delete;
public:
PCSPKdemo() {
kout << "Initialized PCSPKdemo" << endl;
}
void run() override;
};
#endif

View File

@ -0,0 +1,17 @@
#include "user/PreemptiveLoopThread.h"
void PreemptiveLoopThread::run() {
/* Hier muss Code eingefuegt werden */
int cnt = 0;
while (true) {
// Basic synchronization by disabling PIT interrupts
cpu.disable_int();
kout.setpos(55, this->id);
kout << this->id << ": " << dec << cnt++ << endl;
cpu.enable_int();
}
}

View File

@ -0,0 +1,22 @@
#ifndef __pre_loopthread_include__
#define __pre_loopthread_include__
#include "kernel/threads/Thread.h"
#include "kernel/Globals.h"
class PreemptiveLoopThread : public Thread {
private:
int id;
PreemptiveLoopThread(const PreemptiveLoopThread& copy) = delete; // Verhindere Kopieren
public:
// Gibt der Loop einen Stack und eine Id.
PreemptiveLoopThread(int i) : id(i) {}
// Zaehlt einen Zaehler hoch und gibt ihn auf dem Bildschirm aus.
void run() override;
};
#endif

View File

@ -0,0 +1,18 @@
#include "user/PreemptiveThreadDemo.h"
void PreemptiveThreadDemo::run() {
kout << "Allocating LoopThread A" << endl;
Thread* cntA = new PreemptiveLoopThread(0);
kout << "Allocating LoopThread B" << endl;
Thread* cntB = new PreemptiveLoopThread(1);
kout << "Allocating LoopThread C" << endl;
Thread* cntC = new PreemptiveLoopThread(2);
kout << "Adding threads to ready queue" << endl;
scheduler.ready(cntA);
scheduler.ready(cntB);
scheduler.ready(cntC);
kout << "Exiting main thread" << endl;
scheduler.exit();
}

View File

@ -0,0 +1,21 @@
#ifndef __preemptive_thread_include__
#define __preemptive_thread_include__
#include "kernel/Globals.h"
#include "kernel/threads/Thread.h"
#include "user/PreemptiveLoopThread.h"
class PreemptiveThreadDemo : public Thread {
private:
PreemptiveThreadDemo(const PreemptiveThreadDemo& copy) = delete; // Verhindere Kopieren
public:
PreemptiveThreadDemo() {
kout << "Initialized PreemptiveThreadDemo" << endl;
}
// Thread-Startmethode
void run() override;
};
#endif