Shop Learn P1 Docs P2 Docs Events
Taqoz Reloaded v2.8 - detecting busy / idle cogs — Parallax Forums

Taqoz Reloaded v2.8 - detecting busy / idle cogs

bob_g4bbybob_g4bby Posts: 386
edited 2023-05-01 10:09 in Forth

It's sometimes useful to know how many cogs are currently available (say) to run some multi-cog dsp code. The following code requires the assembler be present in memory:-

--- checks whether cog n is idle (idle=1) or busy (idle=0)
code COGIDLE                        ( n -- idle )
    cogid a wc
    if_c mov a #0
    if_nc mov a #1
    ret
end

--- displays the status of all cogs
pub COGS?                        ( -- )
    CRLF
    8 0 DO
        I COGIDLE
        ." Cog" I . ." = "
        IF
            ." idle"
        ELSE
            ." busy"
        THEN
        CRLF
    LOOP
;

--- returns the number of cogs that are currently idle
pub COGSIDLE                    ( -- n )
0
8 0 DO
    I COGIDLE +
LOOP
;

Running COGS? will normally result in:-

TAQOZ# COGS? ---
Cog0 = busy
Cog1 = idle
Cog2 = idle
Cog3 = idle
Cog4 = idle
Cog5 = idle
Cog6 = idle
Cog7 = busy
 ok

Taqoz is running in cog 0 with a VGA screen driver running in cog 7. We could launch our dsp code to run in the remaining 6 cogs.

Comments

Sign In or Register to comment.