User Tools

Site Tools


en:pfw:multi_tasker

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
en:pfw:multi_tasker [2025-02-27 10:56] – [Cooperative multitasker] willemen:pfw:multi_tasker [2025-03-14 13:30] (current) – [Contributions] willem
Line 196: Line 196:
 ==== Implementation specific and example ==== ==== Implementation specific and example ====
  
-This part is system specific (noForth t) and it's just an sample implementation:\\+This part is system specific (noForth t) and it's just sample implementation:\\
 <code forth> <code forth>
 \ Redefine teminal I/O and MS to include multitasker \ Redefine teminal I/O and MS to include multitasker
Line 273: Line 273:
 **Primitives for noForth t on the RP2040** **Primitives for noForth t on the RP2040**
  
-Note that it is code directly from the noForth t metacompiler listing. So +Note that this is code directly from the noForth t metacompiler listing.\\ 
-take there there are some meta specific words in it like ''>box'' & ''tp>'' etc.+So take there there are some meta specific words in it like ''>box'', ''box>'' & ''tp>''.\\ 
 <code forth> <code forth>
 code PAUSE      ( -- ) \ 29 machine cycles, is 0.232 microsec. at 125 MHz code PAUSE      ( -- ) \ 29 machine cycles, is 0.232 microsec. at 125 MHz
-    { ip sp tos } push,     \ 4 - Save Forth environment+    { ip sp tos } push,     \ 4 - Save tasks Forth environment
     sun TP mov,             \ 1 - TCB address to SUN     sun TP mov,             \ 1 - TCB address to SUN
     day rp mov,             \ 1 - RP to DAY     day rp mov,             \ 1 - RP to DAY
-    day  sun 0C #) str,     \ 2 - DAY to RP+    day  sun 0C #) str,     \ 2 - DAY TRP !
     begin, >box     begin, >box
     begin,                  \ An inactive task takes 7 cycles extra = 0.056 µs     begin,                  \ An inactive task takes 7 cycles extra = 0.056 µs
Line 288: Line 289:
     =? no until,            \ 2 - Not zero?     =? no until,            \ 2 - Not zero?
     TP sun mov,             \ 1 - Next link address = new TCB     TP sun mov,             \ 1 - Next link address = new TCB
-    day  sun 0C #) ldr,     \ 2 - RP @ to DAY+    day  sun 0C #) ldr,     \ 2 - TRP @ to DAY
     rp day mov,             \ 1 - DAY to RP     rp day mov,             \ 1 - DAY to RP
-    { ip sp tos } pop,      \ 4 - Restore Forth environment+    { ip sp tos } pop,      \ 4 - Restore tasks Forth environment
     begin, >box     begin, >box
     next,                   \ 6     next,                   \ 6
Line 296: Line 297:
  
 code STOP   ( -- ) code STOP   ( -- )
-    tp> ,+    tp> ,  ( Address of main TCB )
 code> code>
-    w  w ) ldr,             \ 2 - main to W+    w  w ) ldr,             \ 2 - main TCB to W
     sun TP mov,             \ 1 - Task to DAY     sun TP mov,             \ 1 - Task to DAY
     sun w cmp,              \ 1 - main = task?     sun w cmp,              \ 1 - main = task?
Line 306: Line 307:
     { ip sp tos } push,     \ 4 - Save this tasks Forth environment     { ip sp tos } push,     \ 4 - Save this tasks Forth environment
     w rp mov,               \ 1 - RP to W     w rp mov,               \ 1 - RP to W
-    w  sun 0C #) str,       \ 2 - W to RP+    w  sun 0C #) str,       \ 2 - W to TRP
   box> again,               \ 2 - Switch to next task   box> again,               \ 2 - Switch to next task
 end-code end-code
  
 code SLEEP  ( task -- ) code SLEEP  ( task -- )
-    tp> ,+    tp> ,  ( Address of main TCB )
 code> code>
-    w  w ) ldr,             \ 2 - main to W+    w  w ) ldr,             \ 2 - main TCB to W
     tos w cmp,              \ 1 - main = task?     tos w cmp,              \ 1 - main = task?
     =? no if, >box          \ 2 - No = continue, yes = ready     =? no if, >box          \ 2 - No = continue, yes = ready
Line 334: Line 335:
     { ip sp } push,         \ Save noForth registers     { ip sp } push,         \ Save noForth registers
     moon rp mov,            \ Save RP     moon rp mov,            \ Save RP
-    ip sun mov,             Ip to IP +    ip sun mov,             IP from stack to IP 
-    day tos 20 #) ldr,      \ Read R0 to DAY +    day tos 20 #) ldr,      \ Read TR0 to DAY 
-    rp day mov,             \ Use R0 as tasks RP +    rp day mov,             \ Use TR0 as tasks RP 
-    sp tos 24 #) ldr,       Set SP to S0+    sp tos 24 #) ldr,       Use TS0 as tasks SP
     { ip sp tos hop } push, \ Initialise tasks return stack     { ip sp tos hop } push, \ Initialise tasks return stack
     day rp mov,             \ Copy RP to DAY     day rp mov,             \ Copy RP to DAY
-    day  tos 0C #) str,     \ Set tasks RP too+    day  tos 0C #) str,     \ Set tasks TRP too
     rp moon mov,            \ Restore noForth registers     rp moon mov,            \ Restore noForth registers
     { ip sp } pop,     { ip sp } pop,
en/pfw/multi_tasker.1740650214.txt.gz · Last modified: 2025-02-27 10:56 by willem