How many Cogs for multiple objects
oodes
Posts: 131
Hello
If I declare an object 4 times and that object uses a cog do I use up 4 cogs? for example
Fsrw starts a new cog so does use 4 cogs? I am under the impression it uses 4 cogs but when I run the free_cogs object below and increase or decrease sdfat to sdfat[6] or sdfat[2] it always returns the same number of free cogs.
Can anyone clear this up for me?
Thanks
Des
If I declare an object 4 times and that object uses a cog do I use up 4 cogs? for example
OBJ sdfat[4]: "fsrw"
Fsrw starts a new cog so does use 4 cogs? I am under the impression it uses 4 cogs but when I run the free_cogs object below and increase or decrease sdfat to sdfat[6] or sdfat[2] it always returns the same number of free cogs.
PUB free_cogs : free | i, cog[8], jmp_0 jmp_0 := %010111_0001_1111_000000000_000000000 repeat while (cog[free] := cognew(@jmp_0, 0)) => 0 free++ if free repeat i from 0 to free - 1 cogstop(cog[i]) return free
Can anyone clear this up for me?
Thanks
Des
Comments
fsrw is an intermediate level object that uses a low level SPI driver object to actually talk to the SD card and the low level object is the one that uses an additional cog. The .mount method calls the SPI driver's .start method and there's an .unmount method that calls the SPI driver's .stop method. Until you mount an SD card, there are no additional cogs used.
Thanks for getting back to me. I'm calling the .mount method before I run the 'Free_cogs' method. My program wont run unless I have an SD card mounted. I'm aware that the safespi low level object is what starts the cog. But does this object release the cogs when not using them? I'm currently using sdfat[3] to talk to 3 files on the SD card but I need to increase this to 4 however i have no spare cogs and the system gets hung up sometimes.
Des