View Full Version : Faster Data Output: Parameter passing between cogs
01-30-2007, 04:59 AM
I am using the FullDuplex object for outputting data at 230400 baud. Data starts in an assembly-cog (from an A/D chip). Currently this data is managed and processed by some spin code in both PC_Debug and FullDuplex, on its way to the assembly cog associated with FullDuplex. This all works great, but the spin part is slowing me down and some of the data is getting dropped.
My question is: how can parameters be passed between two cogs, each running assembly code, without using spin? Is there some trick with @@ or something like that?
01-30-2007, 05:17 AM
This is easy; use exactly the same techniques used for Spin->Assembly communication. Just use a
main memory buffer, allocated at the spin level, and pass the address of this buffer to both
assembly language cogs that plan to communicate.
01-30-2007, 05:23 AM
Data can be passed from one cog to another the same way it would be passed if one cog were running Spin. You need some kind of common buffer in hub memory and a management scheme that prevents both cogs from problems with simultaneous access to the same variables. If you have one cog generating data and a second cog consuming it, you can use a simple ring buffer and not have to use semaphores (locks). Rather than rewriting the FullDuplexSerial driver, you could add a simple method to the FullDuplexSerial object that just returns the address of the block of data used by the assembly part of the FullDuplexSerial driver. This address would be passed to your new assembly routine when it's started up and you'd have an assembly version of the TX routine in your assembly routine. Note that you couldn't have two cogs trying to transmit at the same time. If that's what you need, you'd have to use the LOCKxxx instructions so only one transmit routine could change the variables at a time.
01-31-2007, 03:41 AM
Thanks Mike and Rokicki
I've give it a go and see what shakes out.