Taqoz Reloaded v2.8 - detecting busy / idle cogs
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
Thank you! That is useful!
Christof
Hi, combined that with what I have had:
: .cogs ( -- ) \ print the words running in cogs 8 0 do crlf i . space i cogidle if ." idle" else i task w@ ?dup if cfa>nfa .nfa else ." code" then then loop ;That's better!