21o6
25-08-2007, 01:56 PM
hi :D
i forgot about this, because i didn't need it, but remembered it today and thought i could release it. :D
i am talking about a unit called talk.pp, which handles the FIFO-communication between the processors.
first, you have to call InitTalk; on both processors.
then, you can (but do not have to) syncronize, by using
repeat until Told^ = $2106;
on one of the processors.
the processor waiting for the Sync-Signal is awaiting the code
Tell^ := $2106;
being executed on the other processor.
syncronizing made my life more easy, because when you get out of sync with telling/listening it will pretty probably blow up your program.
did so for me, at least. :D
so, you see, sharing Data is as simple as telling the told. :)
the FIFO-queue is 16x32bit wide, which means you can Tell^ any longint (the unit uses a longint, but you can change that of course) 16 times before the queue is full ... and if the Told^ is not listened to, this will definitely happen. :)
If you're waiting for something to be told, you can also use Listen4Told (: Boolean), which turns True if there is something to listen to.
Wait4Told; basically does the same, but stalls the cpu (= a repeat-loop) until there is something to listen to. I never tested for speed-differences between listening to the register (= Listen4Told) or polling the value (= Told^) ... have fun with that on your own :D
oh yeah ... forgot. Checking the queue can be done by CheckSync (: Boolean), which gives a False when the Queue is full. So True means your in-sync.
I have included a test-program dual.pp* in the archive. You can experiment with the timing and i really encourage you to do so, so you get a feeling for this. avoiding syncronization speeds up your code dramatically :)
Please note a few things:
.) when listening to Told^ when nobody said something (the queue is empty *g*), you will listen to garbage.
.) altough the example-program works fine in no$gba, you can not 100% rely on the emulator when it comes to timing this stuff.
.) the example code will lose values (=get out of sync), given the line
Repeat Until CheckSync = True; in dual.pp7 is commented out.
This happens because you need to be silent
when nobody is able to listen,
because there's already enough said.
got that? :D
The Archive with the whole source and 2 nds-files can be found at my blog (http://21o6.blogspot.com) (shameless ad ;), or directly here (http://members.chello.at/thedoc/talk.rar).
i hope you have fun with this and please tell me your thoughts and everything :D the code can be optimized, but i don't need the cycles yet, so i'll leave that up to you.
using {$INLINE ON} (http://www.freepascal.org/docs-html/prog/progsu31.html#x38-360001.1.31) and the appropriate inline; could also help.
hope i didn't forget anything. :)
i forgot about this, because i didn't need it, but remembered it today and thought i could release it. :D
i am talking about a unit called talk.pp, which handles the FIFO-communication between the processors.
first, you have to call InitTalk; on both processors.
then, you can (but do not have to) syncronize, by using
repeat until Told^ = $2106;
on one of the processors.
the processor waiting for the Sync-Signal is awaiting the code
Tell^ := $2106;
being executed on the other processor.
syncronizing made my life more easy, because when you get out of sync with telling/listening it will pretty probably blow up your program.
did so for me, at least. :D
so, you see, sharing Data is as simple as telling the told. :)
the FIFO-queue is 16x32bit wide, which means you can Tell^ any longint (the unit uses a longint, but you can change that of course) 16 times before the queue is full ... and if the Told^ is not listened to, this will definitely happen. :)
If you're waiting for something to be told, you can also use Listen4Told (: Boolean), which turns True if there is something to listen to.
Wait4Told; basically does the same, but stalls the cpu (= a repeat-loop) until there is something to listen to. I never tested for speed-differences between listening to the register (= Listen4Told) or polling the value (= Told^) ... have fun with that on your own :D
oh yeah ... forgot. Checking the queue can be done by CheckSync (: Boolean), which gives a False when the Queue is full. So True means your in-sync.
I have included a test-program dual.pp* in the archive. You can experiment with the timing and i really encourage you to do so, so you get a feeling for this. avoiding syncronization speeds up your code dramatically :)
Please note a few things:
.) when listening to Told^ when nobody said something (the queue is empty *g*), you will listen to garbage.
.) altough the example-program works fine in no$gba, you can not 100% rely on the emulator when it comes to timing this stuff.
.) the example code will lose values (=get out of sync), given the line
Repeat Until CheckSync = True; in dual.pp7 is commented out.
This happens because you need to be silent
when nobody is able to listen,
because there's already enough said.
got that? :D
The Archive with the whole source and 2 nds-files can be found at my blog (http://21o6.blogspot.com) (shameless ad ;), or directly here (http://members.chello.at/thedoc/talk.rar).
i hope you have fun with this and please tell me your thoughts and everything :D the code can be optimized, but i don't need the cycles yet, so i'll leave that up to you.
using {$INLINE ON} (http://www.freepascal.org/docs-html/prog/progsu31.html#x38-360001.1.31) and the appropriate inline; could also help.
hope i didn't forget anything. :)