Unterschiede

Hier werden die Unterschiede zwischen zwei Versionen angezeigt.

Link zu dieser Vergleichsansicht

Beide Seiten der vorigen Revision Vorhergehende Überarbeitung
Nächste Überarbeitung
Vorhergehende Überarbeitung
forth:fgforth:multitasking [2020/11/11 12:28] – [Multitasking] volkerpforth:fgforth:multitasking [2020/11/18 12:58] (aktuell) – [Multitasking] volkerp
Zeile 1: Zeile 1:
 ====== Multitasking ====== ====== Multitasking ======
  
-das Paket MTASK erlaubt kooperatives Multitaskting.+das Paket MTASK erlaubt kooperatives Multitasking
  
 Laden mit Laden mit
Zeile 7: Zeile 7:
   1 5 THRU   1 5 THRU
  
-Glossar +**Glossar** 
-<code> + 
-(PAUSE)   ( -- ) +MULTI   ( -- )\\ 
-RESTART   ( -- ) +Aktiviert das Multitasking 
-6 CONSTANT INT# + 
-LOCAL   ( base adr -- adr' +SINGLE   ( -- ) \\ 
-@LINK   ( -- adr ) +Stoppt Multitasking, der aktuelle Task bleibt aktiv 
-!LINK   ( adr -- ) + 
-SLEEP   adr -- ) +TASK: size -- )\\ 
-WAKE    ( adr -- ) +erzeugt einen neuen Task und initialisiert die User-Variablen\\ 
-STOP    ( -- ) +size ist der Speicherplatz für User-Variablen und den lokalen Stack. Hinter TASK: folgt der Taskname.\\ 
-SINGLE   ( -- )  +Beispiel:  
-MULTI   ( -- ) +  1000 TASK: COUNTER1 
-TASK:  size -- )  + 
-SET-TASK   ( IP Task -- ) +ACTIVATE task -- )\\ 
-ACTIVATE   ( Task -- ) Activate a Task +Aktiviert einen Task. ACTIVATE darf nur in Colon-Definitionen genutzt werden. Hinter ACTIVATE folgt der im Task auszuführende Code.\\ 
-BACKGROUND:   ( -- )   Create a Background task+Beispiel:  
 +<code>  COUNT!   COUNTER1 ACTIVATE  
 +    BEGIN PAUSE 1 COUNTS +!  AGAIN ; 
 </code> </code>
  
-aus L/P-F83-Doku: +SLEEP   ( task -- )\\ 
-<code> +Versetzt den Task in den Ruhezustand
-Multitasking low level +
-(PAUSE)   (S -- ) +
-    Puts a task to sleep by storing the IP and the RP on the +
-    parameter stack.  It then saves the pointer to the +
-    parameter stack in the user area and jumps to the code +
-    pointed at by USER+3, switching tasks. +
-RESTART     (S -- ) +
-    Sets the user pointer to point to a new user area and +
-    restores the parameter stack that was previously saved +
-    in the USER area.  Then pops the RP and IP off of the +
-    stack and resumes execution.   The inverse of PAUSE. +
-  +
-Initialize current User area to a single task.+
  
-Manipulate Tasks +WAKE   ( task -- )\\ 
-LOCAL  Map a User variable from the current task to another task +Reaktiviert den Task aus dem Ruhezustand
-@LINK  Return a pointer the the next tasks entry point +
-!LINK  Set the link field of the current task (perhaps relative) +
-SLEEP  makes a task pause indefinitely. +
-WAKE  lets a task start again. +
-STOP  makes a task pause indefinitely. +
-SINGLE  removes the multi-tasker's scheduler/dispatcher loop. +
-MULTI +
-   installs the multi-tasker's scheduler/dispatcher loop. +
-   By patching the appropriate INT vector and enabling PAUSE.+
  
-MULTI starts the multi-tasker loop running. SINGLE stops it. +STOP  ( -- )\\ 
-Then type XXX WAKE to start the XXX task. +Versetzt den aktuellen Task in den Ruhezustand
-To put the XXX on hold, use  XXX SLEEP +
-To restart it, use XXX WAKE+
  
-In general, executing the name of a task leaves the address of +BACKGROUND:   ( -- )\\ 
-its user area on the stackWords like sleep and wake use that +DefinitionswortAlternative zu ACTIVATE zum Erzeugen eines Tasks. Hinter BACKGROUND: folgt der Taskname und danach der auszuführende Code.\\ 
-address.+Der Task wird jedoch nicht gleich gestartet, sondern muss mit WAKE aktiviert werden.\\ 
 +Beispiel:  
 +  BACKGROUND: COUNTER2  BEGIN       
 +   PAUSE 1 COUNTS +!  AGAIN ;   
 +  COUNTER2 WAKE 
  
-Activate a Task +PAUSE ( -- )\
-TASK:  Name, initializeand allocate a new task. +Weiterschalten zum nächsten Task.\\ 
-  Copy the USER Area point to where he pointed. +Damit kooperatives Multitasking überhaupt funktioniertmuss in jedem Task regelmäßig PAUSE aufgerufen werdenMit PAUSE wird der nächste Task aktiv. 
-  He points to me. +In allen Basis-I/O-Worten ist PAUSE bereits enthalten ( (KEY), (CONSOLE), (PRINT), BUFFER, BLOCK ) und damit indirekt in (EMIT), (CR), "." etc., so dann man in interaktiven Tasks PAUSE nicht direkt einfügen muss
-  Set initial stack pointers. +Bei Tasks ohne I/O muss dagegen PAUSE in den Taskschleifen explizit stehen.
-  Set dictionary pointer. +
-  Make task ready to execute. Allocate task in host dictionary+
-SET-TASK  assigns an existing task to the code at ip. +
-  Get top of stack of the task to be used. +
-  Put IP and RP values on its stack. +
-  Set its saved stack pointer. +
-  +
-ACTIVATE  assigns an existing task to the following code, +
-  and makes it ready to execute.+
  
-\ Create a Background Task  
-BACKGROUND: 
-  Create a new task of default size. Initialize it to execute 
-  the following code. 
  
-Examples: +===== Literatur ===== 
- The task named counter executes an infinite loop, so STOP is not + 
- requiredNote that you MUST use PAUSE, or no other tasks will +  * https://www.bradrodriguez.com/papers/mtasking.html 
- be executedPAUSE is built in to all words which do I/Oso +  * C.H. Thing "Inside F83" http://forth.org/OffeteStore/1003_InsideF83.pdf 
- tasks which do I/O ( like spooler ) do not need to use PAUSE +  * R. ZechForth 83 
- explicitly.+  * http://www.forth.org/fd/FD-V05N4.pdf ff.
  
-</code> 
  
 ===== Beispiel ===== ===== Beispiel =====
Zeile 105: Zeile 73:
 SINGLE SINGLE
 </code> </code>
 +
 +===== Funktionsweise =====
 +
 +Das Multitasking-System basiert auf dem des Laxen/Perry-F83 und wurde geringfügig ans FG FORTH83 angepasst.
 +Die Beschreibung zur Funktionsweise und Nutzung des Multitasking-Systems entspricht daher der Dokumentation in C.H. Thing "Inside F83"
 +(http://forth.org/OffeteStore/1003_InsideF83.pdf).
 +
 +Abweichungen: 
 +  * Beim Z80 wird statt INT80 der RST30 (RST 6) genutzt.
 +  * instruction pointer ist Register BC
 +  * return stack pointer ist Register IY
 +
 +Das F83 ist bereits von vornherein auf Multitasking vorbereitet. Ein kooperatives Multitasking muss beim Taskwechsel so nur 4 Register sichern/restaurieren: SP (parameter stack pinter), RP (return stack pointer), IP (interpreter pointer) und UP (user area pointer). Das erledigen die Worte PAUSE und RESTART.
 +
 +Jeder Task hat seinen eigenen User-Variablen-Bereich. Mit den User-Variablen ENTRY und LINK wird eine geschlossene Taskkette (round-robin-Task list) aufgebaut.
 +Je nach Zustand des Task steht hier ein Sprung zum nächsten Task (wenn der Task im Ruhezustand ist) oder mittels RST 30 wird das Wort RESTART ausgeführt, dass den Task reaktiviert. Der Task wird dann bis zum nächsten PAUSE abgearbeitet, dann ist der folgende Task an der Reihe.
 +
 +{{:forth:fgforth:mtask_fgforth.jpg?400|}}\\ Bild nach „Inside F83“, leicht modifiziert
  
  • forth/fgforth/multitasking.1605097688.txt.gz
  • Zuletzt geändert: 2020/11/11 12:28
  • von volkerp