From 0537f6dd459b56c450ec639bec7af3d3086da25a Mon Sep 17 00:00:00 2001 From: Christoph Urlacher Date: Mon, 23 May 2022 09:12:08 +0200 Subject: [PATCH] implement demo --- c_os/user/CoroutineDemo.cc | 19 ++++++++++++------- c_os/user/CoroutineLoop.cc | 16 +++++++++++----- 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/c_os/user/CoroutineDemo.cc b/c_os/user/CoroutineDemo.cc index 5a4e08d..b2ea8dc 100755 --- a/c_os/user/CoroutineDemo.cc +++ b/c_os/user/CoroutineDemo.cc @@ -8,21 +8,16 @@ * Autor: Michael Schoettner, HHU, 15.8.2016 * *****************************************************************************/ -#include "kernel/Globals.h" #include "user/CoroutineDemo.h" +#include "kernel/Globals.h" #include "user/CoroutineLoop.h" - -// Stacks (koennen alternative auch per 'new' alloziert werden) -static unsigned int stack[3][1024]; - - /***************************************************************************** * Methode: CoroutineDemo::main * *---------------------------------------------------------------------------* * Beschreibung: main-Methode der Anwendung. * *****************************************************************************/ -void CoroutineDemo::main () { +void CoroutineDemo::main() { /* * Hier muss Code eingefuegt werden @@ -30,5 +25,15 @@ void CoroutineDemo::main () { * 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(); } diff --git a/c_os/user/CoroutineLoop.cc b/c_os/user/CoroutineLoop.cc index a92f744..48889aa 100755 --- a/c_os/user/CoroutineLoop.cc +++ b/c_os/user/CoroutineLoop.cc @@ -6,7 +6,7 @@ * Beschreibung: Loop ist eine Koroutine, die nichts weiter tut als einen * * Zaehler hochzuzaehlen und diesen auf dem Bildschirm * * anzuzeigen und dann auf die naechste Korotuine umzu- * - * schalten. * + * schalten. * * * * Autor: Olaf Spinczyk, TU Dortmund * *****************************************************************************/ @@ -14,14 +14,20 @@ #include "user/CoroutineLoop.h" #include "kernel/Globals.h" - /***************************************************************************** * Methode: CoroutineLoop::run * *---------------------------------------------------------------------------* * 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(); + } }