1

implement demo

This commit is contained in:
2022-05-23 09:12:08 +02:00
parent 4f94ccdc99
commit 0537f6dd45
2 changed files with 23 additions and 12 deletions

View File

@ -8,21 +8,16 @@
* Autor: Michael Schoettner, HHU, 15.8.2016 * * Autor: Michael Schoettner, HHU, 15.8.2016 *
*****************************************************************************/ *****************************************************************************/
#include "kernel/Globals.h"
#include "user/CoroutineDemo.h" #include "user/CoroutineDemo.h"
#include "kernel/Globals.h"
#include "user/CoroutineLoop.h" #include "user/CoroutineLoop.h"
// Stacks (koennen alternative auch per 'new' alloziert werden)
static unsigned int stack[3][1024];
/***************************************************************************** /*****************************************************************************
* Methode: CoroutineDemo::main * * Methode: CoroutineDemo::main *
*---------------------------------------------------------------------------* *---------------------------------------------------------------------------*
* Beschreibung: main-Methode der Anwendung. * * Beschreibung: main-Methode der Anwendung. *
*****************************************************************************/ *****************************************************************************/
void CoroutineDemo::main () { void CoroutineDemo::main() {
/* /*
* Hier muss Code eingefuegt werden * Hier muss Code eingefuegt werden
@ -30,5 +25,15 @@ void CoroutineDemo::main () {
* Die 3 Koroutinen einrichten, verketten und die 1. starten * Die 3 Koroutinen einrichten, verketten und die 1. starten
* *
*/ */
unsigned int(*stack)[1024] = new unsigned int[3][1024];
CoroutineLoop corout1(stack[0] + 1024, 0);
CoroutineLoop corout2(stack[1] + 1024, 1);
CoroutineLoop corout3(stack[2] + 1024, 2);
corout1.setNext(&corout2);
corout2.setNext(&corout3);
corout3.setNext(&corout1);
corout1.start();
} }

View File

@ -6,7 +6,7 @@
* Beschreibung: Loop ist eine Koroutine, die nichts weiter tut als einen * * Beschreibung: Loop ist eine Koroutine, die nichts weiter tut als einen *
* Zaehler hochzuzaehlen und diesen auf dem Bildschirm * * Zaehler hochzuzaehlen und diesen auf dem Bildschirm *
* anzuzeigen und dann auf die naechste Korotuine umzu- * * anzuzeigen und dann auf die naechste Korotuine umzu- *
* schalten. * * schalten. *
* * * *
* Autor: Olaf Spinczyk, TU Dortmund * * Autor: Olaf Spinczyk, TU Dortmund *
*****************************************************************************/ *****************************************************************************/
@ -14,14 +14,20 @@
#include "user/CoroutineLoop.h" #include "user/CoroutineLoop.h"
#include "kernel/Globals.h" #include "kernel/Globals.h"
/***************************************************************************** /*****************************************************************************
* Methode: CoroutineLoop::run * * Methode: CoroutineLoop::run *
*---------------------------------------------------------------------------* *---------------------------------------------------------------------------*
* Beschreibung: Einstiegsfunktion der Koroutine. * * Beschreibung: Einstiegsfunktion der Koroutine. *
*****************************************************************************/ *****************************************************************************/
void CoroutineLoop::run () { void CoroutineLoop::run() {
/* Hier muss Code eingefuegt werden */ /* Hier muss Code eingefuegt werden */
int i = 0;
while (true) {
kout.setpos(0, 20 + this->id);
kout << "Corout[" << this->id << "]: " << i++ << endl;
this->switchToNext();
}
} }